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 * Monitors a file or directory for changes. 73 * 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 * 78 * To get informed about changes to the file or directory you are 79 * monitoring, connect to the "changed" signal. The 80 * signal will be emitted in the thread-default main 81 * context of the thread that the monitor was created in 82 * (though if the global default main context is blocked, this may 83 * cause notifications to be blocked even if the thread-default 84 * context is still running). 85 */ 86 public class FileMonitor : ObjectG 87 { 88 89 /** the main Gtk struct */ 90 protected GFileMonitor* gFileMonitor; 91 92 93 public GFileMonitor* getFileMonitorStruct() 94 { 95 return gFileMonitor; 96 } 97 98 99 /** the main Gtk struct as a void* */ 100 protected override void* getStruct() 101 { 102 return cast(void*)gFileMonitor; 103 } 104 105 /** 106 * Sets our main struct and passes it to the parent class 107 */ 108 public this (GFileMonitor* gFileMonitor) 109 { 110 super(cast(GObject*)gFileMonitor); 111 this.gFileMonitor = gFileMonitor; 112 } 113 114 protected override void setStruct(GObject* obj) 115 { 116 super.setStruct(obj); 117 gFileMonitor = cast(GFileMonitor*)obj; 118 } 119 120 /** 121 */ 122 int[string] connectedSignals; 123 124 void delegate(File, File, GFileMonitorEvent, FileMonitor)[] onChangedListeners; 125 /** 126 * Emitted when file has been changed. 127 * If using G_FILE_MONITOR_SEND_MOVED flag and event_type is 128 * G_FILE_MONITOR_EVENT_MOVED, file will be set to a GFile containing the 129 * old path, and other_file will be set to a GFile containing the new path. 130 * In all the other cases, other_file will be set to NULL. 131 */ 132 void addOnChanged(void delegate(File, File, GFileMonitorEvent, FileMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 133 { 134 if ( !("changed" in connectedSignals) ) 135 { 136 Signals.connectData( 137 getStruct(), 138 "changed", 139 cast(GCallback)&callBackChanged, 140 cast(void*)this, 141 null, 142 connectFlags); 143 connectedSignals["changed"] = 1; 144 } 145 onChangedListeners ~= dlg; 146 } 147 extern(C) static void callBackChanged(GFileMonitor* monitorStruct, GFile* file, GFile* otherFile, GFileMonitorEvent eventType, FileMonitor _fileMonitor) 148 { 149 foreach ( void delegate(File, File, GFileMonitorEvent, FileMonitor) dlg ; _fileMonitor.onChangedListeners ) 150 { 151 dlg(ObjectG.getDObject!(File)(file), ObjectG.getDObject!(File)(otherFile), eventType, _fileMonitor); 152 } 153 } 154 155 156 /** 157 * Cancels a file monitor. 158 * Returns: TRUE if monitor was cancelled. 159 */ 160 public int cancel() 161 { 162 // gboolean g_file_monitor_cancel (GFileMonitor *monitor); 163 return g_file_monitor_cancel(gFileMonitor); 164 } 165 166 /** 167 * Returns whether the monitor is canceled. 168 * Returns: TRUE if monitor is canceled. FALSE otherwise. 169 */ 170 public int isCancelled() 171 { 172 // gboolean g_file_monitor_is_cancelled (GFileMonitor *monitor); 173 return g_file_monitor_is_cancelled(gFileMonitor); 174 } 175 176 /** 177 * Sets the rate limit to which the monitor will report 178 * consecutive change events to the same file. 179 * Params: 180 * limitMsecs = a non-negative integer with the limit in milliseconds 181 * to poll for changes 182 */ 183 public void setRateLimit(int limitMsecs) 184 { 185 // void g_file_monitor_set_rate_limit (GFileMonitor *monitor, gint limit_msecs); 186 g_file_monitor_set_rate_limit(gFileMonitor, limitMsecs); 187 } 188 189 /** 190 * Emits the "changed" signal if a change 191 * has taken place. Should be called from file monitor 192 * implementations only. 193 * The signal will be emitted from an idle handler (in the thread-default main 194 * context). 195 * Params: 196 * child = a GFile. 197 * otherFile = a GFile. 198 * eventType = a set of GFileMonitorEvent flags. 199 */ 200 public void emitEvent(File child, File otherFile, GFileMonitorEvent eventType) 201 { 202 // void g_file_monitor_emit_event (GFileMonitor *monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type); 203 g_file_monitor_emit_event(gFileMonitor, (child is null) ? null : child.getFileStruct(), (otherFile is null) ? null : otherFile.getFileStruct(), eventType); 204 } 205 }