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