1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = GFileMonitor.html 27 * outPack = gio 28 * outFile = FileMonitor 29 * strct = GFileMonitor 30 * realStrct= 31 * ctorStrct= 32 * clss = FileMonitor 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = GObject 38 * implements: 39 * prefixes: 40 * - g_file_monitor_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - gio.File 47 * structWrap: 48 * - GFile* -> File 49 * module aliases: 50 * local aliases: 51 * overrides: 52 */ 53 54 module gio.FileMonitor; 55 56 public import gtkc.giotypes; 57 58 private import gtkc.gio; 59 private import glib.ConstructionException; 60 private import gobject.ObjectG; 61 62 private import gobject.Signals; 63 public import gtkc.gdktypes; 64 65 private import gio.File; 66 67 68 69 private import gobject.ObjectG; 70 71 /** 72 * Description 73 * Monitors a file or directory for changes. 74 * To obtain a GFileMonitor for a file or directory, use 75 * g_file_monitor(), g_file_monitor_file(), or 76 * g_file_monitor_directory(). 77 * To get informed about changes to the file or directory you are 78 * monitoring, connect to the "changed" signal. The 79 * signal will be emitted in the thread-default main 80 * context of the thread that the monitor was created in 81 * (though if the global default main context is blocked, this may 82 * cause notifications to be blocked even if the thread-default 83 * context is still running). 84 */ 85 public class FileMonitor : ObjectG 86 { 87 88 /** the main Gtk struct */ 89 protected GFileMonitor* gFileMonitor; 90 91 92 public GFileMonitor* getFileMonitorStruct() 93 { 94 return gFileMonitor; 95 } 96 97 98 /** the main Gtk struct as a void* */ 99 protected override void* getStruct() 100 { 101 return cast(void*)gFileMonitor; 102 } 103 104 /** 105 * Sets our main struct and passes it to the parent class 106 */ 107 public this (GFileMonitor* gFileMonitor) 108 { 109 super(cast(GObject*)gFileMonitor); 110 this.gFileMonitor = gFileMonitor; 111 } 112 113 protected override void setStruct(GObject* obj) 114 { 115 super.setStruct(obj); 116 gFileMonitor = cast(GFileMonitor*)obj; 117 } 118 119 /** 120 */ 121 int[string] connectedSignals; 122 123 void delegate(File, File, GFileMonitorEvent, FileMonitor)[] onChangedListeners; 124 /** 125 * Emitted when file has been changed. 126 * If using G_FILE_MONITOR_SEND_MOVED flag and event_type is 127 * G_FILE_MONITOR_SEND_MOVED, file will be set to a GFile containing the 128 * old path, and other_file will be set to a GFile containing the new path. 129 * In all the other cases, other_file will be set to NULL. 130 */ 131 void addOnChanged(void delegate(File, File, GFileMonitorEvent, FileMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 132 { 133 if ( !("changed" in connectedSignals) ) 134 { 135 Signals.connectData( 136 getStruct(), 137 "changed", 138 cast(GCallback)&callBackChanged, 139 cast(void*)this, 140 null, 141 connectFlags); 142 connectedSignals["changed"] = 1; 143 } 144 onChangedListeners ~= dlg; 145 } 146 extern(C) static void callBackChanged(GFileMonitor* monitorStruct, GFile* file, GFile* otherFile, GFileMonitorEvent eventType, FileMonitor _fileMonitor) 147 { 148 foreach ( void delegate(File, File, GFileMonitorEvent, FileMonitor) dlg ; _fileMonitor.onChangedListeners ) 149 { 150 dlg(ObjectG.getDObject!(File)(file), ObjectG.getDObject!(File)(otherFile), eventType, _fileMonitor); 151 } 152 } 153 154 155 /** 156 * Cancels a file monitor. 157 * Returns: TRUE if monitor was cancelled. 158 */ 159 public int cancel() 160 { 161 // gboolean g_file_monitor_cancel (GFileMonitor *monitor); 162 return g_file_monitor_cancel(gFileMonitor); 163 } 164 165 /** 166 * Returns whether the monitor is canceled. 167 * Returns: TRUE if monitor is canceled. FALSE otherwise. 168 */ 169 public int isCancelled() 170 { 171 // gboolean g_file_monitor_is_cancelled (GFileMonitor *monitor); 172 return g_file_monitor_is_cancelled(gFileMonitor); 173 } 174 175 /** 176 * Sets the rate limit to which the monitor will report 177 * consecutive change events to the same file. 178 * Params: 179 * limitMsecs = a non-negative integer with the limit in milliseconds 180 * to poll for changes 181 */ 182 public void setRateLimit(int limitMsecs) 183 { 184 // void g_file_monitor_set_rate_limit (GFileMonitor *monitor, gint limit_msecs); 185 g_file_monitor_set_rate_limit(gFileMonitor, limitMsecs); 186 } 187 188 /** 189 * Emits the "changed" signal if a change 190 * has taken place. Should be called from file monitor 191 * implementations only. 192 * The signal will be emitted from an idle handler (in the thread-default main 193 * context). 194 * Params: 195 * child = a GFile. 196 * otherFile = a GFile. 197 * eventType = a set of GFileMonitorEvent flags. 198 */ 199 public void emitEvent(File child, File otherFile, GFileMonitorEvent eventType) 200 { 201 // void g_file_monitor_emit_event (GFileMonitor *monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type); 202 g_file_monitor_emit_event(gFileMonitor, (child is null) ? null : child.getFileStruct(), (otherFile is null) ? null : otherFile.getFileStruct(), eventType); 203 } 204 }