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 
87 	public static GType getType()
88 	{
89 		return g_file_monitor_get_type();
90 	}
91 
92 	/**
93 	 * Cancels a file monitor.
94 	 *
95 	 * Return: %TRUE if monitor was cancelled.
96 	 */
97 	public bool cancel()
98 	{
99 		return g_file_monitor_cancel(gFileMonitor) != 0;
100 	}
101 
102 	/**
103 	 * Emits the #GFileMonitor::changed signal if a change
104 	 * has taken place. Should be called from file monitor
105 	 * implementations only.
106 	 *
107 	 * The signal will be emitted from an idle handler (in the
108 	 * [thread-default main context][g-main-context-push-thread-default]).
109 	 *
110 	 * Params:
111 	 *     child = a #GFile.
112 	 *     otherFile = a #GFile.
113 	 *     eventType = a set of #GFileMonitorEvent flags.
114 	 */
115 	public void emitEvent(FileIF child, FileIF otherFile, GFileMonitorEvent eventType)
116 	{
117 		g_file_monitor_emit_event(gFileMonitor, (child is null) ? null : child.getFileStruct(), (otherFile is null) ? null : otherFile.getFileStruct(), eventType);
118 	}
119 
120 	/**
121 	 * Returns whether the monitor is canceled.
122 	 *
123 	 * Return: %TRUE if monitor is canceled. %FALSE otherwise.
124 	 */
125 	public bool isCancelled()
126 	{
127 		return g_file_monitor_is_cancelled(gFileMonitor) != 0;
128 	}
129 
130 	/**
131 	 * Sets the rate limit to which the @monitor will report
132 	 * consecutive change events to the same file.
133 	 *
134 	 * Params:
135 	 *     limitMsecs = a non-negative integer with the limit in milliseconds
136 	 *         to poll for changes
137 	 */
138 	public void setRateLimit(int limitMsecs)
139 	{
140 		g_file_monitor_set_rate_limit(gFileMonitor, limitMsecs);
141 	}
142 
143 	int[string] connectedSignals;
144 
145 	void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor)[] onChangedListeners;
146 	/**
147 	 * Emitted when @file has been changed.
148 	 *
149 	 * If using #G_FILE_MONITOR_SEND_MOVED flag and @event_type is
150 	 * #G_FILE_MONITOR_EVENT_MOVED, @file will be set to a #GFile containing the
151 	 * old path, and @other_file will be set to a #GFile containing the new path.
152 	 *
153 	 * In all the other cases, @other_file will be set to #NULL.
154 	 *
155 	 * Params:
156 	 *     file = a #GFile.
157 	 *     otherFile = a #GFile or #NULL.
158 	 *     eventType = a #GFileMonitorEvent.
159 	 */
160 	void addOnChanged(void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
161 	{
162 		if ( "changed" !in connectedSignals )
163 		{
164 			Signals.connectData(
165 				this,
166 				"changed",
167 				cast(GCallback)&callBackChanged,
168 				cast(void*)this,
169 				null,
170 				connectFlags);
171 			connectedSignals["changed"] = 1;
172 		}
173 		onChangedListeners ~= dlg;
174 	}
175 	extern(C) static void callBackChanged(GFileMonitor* filemonitorStruct, GFile* file, GFile* otherFile, GFileMonitorEvent eventType, FileMonitor _filemonitor)
176 	{
177 		foreach ( void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor) dlg; _filemonitor.onChangedListeners )
178 		{
179 			dlg(ObjectG.getDObject!(File, FileIF)(file), ObjectG.getDObject!(File, FileIF)(otherFile), eventType, _filemonitor);
180 		}
181 	}
182 }