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 module gio.FileMonitor; 26 27 private import gio.FileIF; 28 private import gio.c.functions; 29 public import gio.c.types; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import std.algorithm; 33 34 35 /** 36 * Monitors a file or directory for changes. 37 * 38 * To obtain a #GFileMonitor for a file or directory, use 39 * g_file_monitor(), g_file_monitor_file(), or 40 * g_file_monitor_directory(). 41 * 42 * To get informed about changes to the file or directory you are 43 * monitoring, connect to the #GFileMonitor::changed signal. The 44 * signal will be emitted in the 45 * [thread-default main context][g-main-context-push-thread-default] 46 * of the thread that the monitor was created in 47 * (though if the global default main context is blocked, this may 48 * cause notifications to be blocked even if the thread-default 49 * context is still running). 50 */ 51 public class FileMonitor : ObjectG 52 { 53 /** the main Gtk struct */ 54 protected GFileMonitor* gFileMonitor; 55 56 /** Get the main Gtk struct */ 57 public GFileMonitor* getFileMonitorStruct(bool transferOwnership = false) 58 { 59 if (transferOwnership) 60 ownedRef = false; 61 return gFileMonitor; 62 } 63 64 /** the main Gtk struct as a void* */ 65 protected override void* getStruct() 66 { 67 return cast(void*)gFileMonitor; 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GFileMonitor* gFileMonitor, bool ownedRef = false) 74 { 75 this.gFileMonitor = gFileMonitor; 76 super(cast(GObject*)gFileMonitor, ownedRef); 77 } 78 79 80 /** */ 81 public static GType getType() 82 { 83 return g_file_monitor_get_type(); 84 } 85 86 /** 87 * Cancels a file monitor. 88 * 89 * Returns: always %TRUE 90 */ 91 public bool cancel() 92 { 93 return g_file_monitor_cancel(gFileMonitor) != 0; 94 } 95 96 /** 97 * Emits the #GFileMonitor::changed signal if a change 98 * has taken place. Should be called from file monitor 99 * implementations only. 100 * 101 * Implementations are responsible to call this method from the 102 * [thread-default main context][g-main-context-push-thread-default] of the 103 * thread that the monitor was created in. 104 * 105 * Params: 106 * child = a #GFile. 107 * otherFile = a #GFile. 108 * eventType = a set of #GFileMonitorEvent flags. 109 */ 110 public void emitEvent(FileIF child, FileIF otherFile, GFileMonitorEvent eventType) 111 { 112 g_file_monitor_emit_event(gFileMonitor, (child is null) ? null : child.getFileStruct(), (otherFile is null) ? null : otherFile.getFileStruct(), eventType); 113 } 114 115 /** 116 * Returns whether the monitor is canceled. 117 * 118 * Returns: %TRUE if monitor is canceled. %FALSE otherwise. 119 */ 120 public bool isCancelled() 121 { 122 return g_file_monitor_is_cancelled(gFileMonitor) != 0; 123 } 124 125 /** 126 * Sets the rate limit to which the @monitor will report 127 * consecutive change events to the same file. 128 * 129 * Params: 130 * limitMsecs = a non-negative integer with the limit in milliseconds 131 * to poll for changes 132 */ 133 public void setRateLimit(int limitMsecs) 134 { 135 g_file_monitor_set_rate_limit(gFileMonitor, limitMsecs); 136 } 137 138 /** 139 * Emitted when @file has been changed. 140 * 141 * If using %G_FILE_MONITOR_WATCH_MOVES on a directory monitor, and 142 * the information is available (and if supported by the backend), 143 * @event_type may be %G_FILE_MONITOR_EVENT_RENAMED, 144 * %G_FILE_MONITOR_EVENT_MOVED_IN or %G_FILE_MONITOR_EVENT_MOVED_OUT. 145 * 146 * In all cases @file will be a child of the monitored directory. For 147 * renames, @file will be the old name and @other_file is the new 148 * name. For "moved in" events, @file is the name of the file that 149 * appeared and @other_file is the old name that it was moved from (in 150 * another directory). For "moved out" events, @file is the name of 151 * the file that used to be in this directory and @other_file is the 152 * name of the file at its new location. 153 * 154 * It makes sense to treat %G_FILE_MONITOR_EVENT_MOVED_IN as 155 * equivalent to %G_FILE_MONITOR_EVENT_CREATED and 156 * %G_FILE_MONITOR_EVENT_MOVED_OUT as equivalent to 157 * %G_FILE_MONITOR_EVENT_DELETED, with extra information. 158 * %G_FILE_MONITOR_EVENT_RENAMED is equivalent to a delete/create 159 * pair. This is exactly how the events will be reported in the case 160 * that the %G_FILE_MONITOR_WATCH_MOVES flag is not in use. 161 * 162 * If using the deprecated flag %G_FILE_MONITOR_SEND_MOVED flag and @event_type is 163 * #G_FILE_MONITOR_EVENT_MOVED, @file will be set to a #GFile containing the 164 * old path, and @other_file will be set to a #GFile containing the new path. 165 * 166 * In all the other cases, @other_file will be set to #NULL. 167 * 168 * Params: 169 * file = a #GFile. 170 * otherFile = a #GFile or #NULL. 171 * eventType = a #GFileMonitorEvent. 172 */ 173 gulong addOnChanged(void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 174 { 175 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 176 } 177 }