source: appstream-generator/build/girepo/gio/FileMonitor.d

Last change on this file was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 6.3 KB
RevLine 
[4841]1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.FileMonitor;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.File;
26private import gio.FileIF;
27private import gobject.ObjectG;
28private import gobject.Signals;
29private import std.algorithm;
30
31
32/**
33 * Monitors a file or directory for changes.
34 *
35 * To obtain a #GFileMonitor for a file or directory, use
36 * g_file_monitor(), g_file_monitor_file(), or
37 * g_file_monitor_directory().
38 *
39 * To get informed about changes to the file or directory you are
40 * monitoring, connect to the #GFileMonitor::changed signal. The
41 * signal will be emitted in the
42 * [thread-default main context][g-main-context-push-thread-default]
43 * of the thread that the monitor was created in
44 * (though if the global default main context is blocked, this may
45 * cause notifications to be blocked even if the thread-default
46 * context is still running).
47 */
48public class FileMonitor : ObjectG
49{
50        /** the main Gtk struct */
51        protected GFileMonitor* gFileMonitor;
52
53        /** Get the main Gtk struct */
54        public GFileMonitor* getFileMonitorStruct()
55        {
56                return gFileMonitor;
57        }
58
59        /** the main Gtk struct as a void* */
60        protected override void* getStruct()
61        {
62                return cast(void*)gFileMonitor;
63        }
64
65        protected override void setStruct(GObject* obj)
66        {
67                gFileMonitor = cast(GFileMonitor*)obj;
68                super.setStruct(obj);
69        }
70
71        /**
72         * Sets our main struct and passes it to the parent class.
73         */
74        public this (GFileMonitor* gFileMonitor, bool ownedRef = false)
75        {
76                this.gFileMonitor = gFileMonitor;
77                super(cast(GObject*)gFileMonitor, ownedRef);
78        }
79
80
81        /** */
82        public static GType getType()
83        {
84                return g_file_monitor_get_type();
85        }
86
87        /**
88         * Cancels a file monitor.
89         *
90         * Returns: always %TRUE
91         */
92        public bool cancel()
93        {
94                return g_file_monitor_cancel(gFileMonitor) != 0;
95        }
96
97        /** */
98        public void emitEvent(FileIF child, FileIF otherFile, GFileMonitorEvent eventType)
99        {
100                g_file_monitor_emit_event(gFileMonitor, (child is null) ? null : child.getFileStruct(), (otherFile is null) ? null : otherFile.getFileStruct(), eventType);
101        }
102
103        /**
104         * Returns whether the monitor is canceled.
105         *
106         * Returns: %TRUE if monitor is canceled. %FALSE otherwise.
107         */
108        public bool isCancelled()
109        {
110                return g_file_monitor_is_cancelled(gFileMonitor) != 0;
111        }
112
113        /**
114         * Sets the rate limit to which the @monitor will report
115         * consecutive change events to the same file.
116         *
117         * Params:
118         *     limitMsecs = a non-negative integer with the limit in milliseconds
119         *         to poll for changes
120         */
121        public void setRateLimit(int limitMsecs)
122        {
123                g_file_monitor_set_rate_limit(gFileMonitor, limitMsecs);
124        }
125
126        protected class OnChangedDelegateWrapper
127        {
128                static OnChangedDelegateWrapper[] listeners;
129                void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor) dlg;
130                gulong handlerId;
131               
132                this(void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor) dlg)
133                {
134                        this.dlg = dlg;
135                        this.listeners ~= this;
136                }
137               
138                void remove(OnChangedDelegateWrapper source)
139                {
140                        foreach(index, wrapper; listeners)
141                        {
142                                if (wrapper.handlerId == source.handlerId)
143                                {
144                                        listeners[index] = null;
145                                        listeners = std.algorithm.remove(listeners, index);
146                                        break;
147                                }
148                        }
149                }
150        }
151
152        /**
153         * Emitted when @file has been changed.
154         *
155         * If using %G_FILE_MONITOR_WATCH_RENAMES on a directory monitor, and
156         * the information is available (and if supported by the backend),
157         * @event_type may be %G_FILE_MONITOR_EVENT_RENAMED,
158         * %G_FILE_MONITOR_EVENT_MOVED_IN or %G_FILE_MONITOR_EVENT_MOVED_OUT.
159         *
160         * In all cases @file will be a child of the monitored directory.  For
161         * renames, @file will be the old name and @other_file is the new
162         * name.  For "moved in" events, @file is the name of the file that
163         * appeared and @other_file is the old name that it was moved from (in
164         * another directory).  For "moved out" events, @file is the name of
165         * the file that used to be in this directory and @other_file is the
166         * name of the file at its new location.
167         *
168         * It makes sense to treat %G_FILE_MONITOR_EVENT_MOVED_IN as
169         * equivalent to %G_FILE_MONITOR_EVENT_CREATED and
170         * %G_FILE_MONITOR_EVENT_MOVED_OUT as equivalent to
171         * %G_FILE_MONITOR_EVENT_DELETED, with extra information.
172         * %G_FILE_MONITOR_EVENT_RENAMED is equivalent to a delete/create
173         * pair.  This is exactly how the events will be reported in the case
174         * that the %G_FILE_MONITOR_WATCH_RENAMES flag is not in use.
175         *
176         * If using the deprecated flag %G_FILE_MONITOR_SEND_MOVED flag and @event_type is
177         * #G_FILE_MONITOR_EVENT_MOVED, @file will be set to a #GFile containing the
178         * old path, and @other_file will be set to a #GFile containing the new path.
179         *
180         * In all the other cases, @other_file will be set to #NULL.
181         *
182         * Params:
183         *     file = a #GFile.
184         *     otherFile = a #GFile or #NULL.
185         *     eventType = a #GFileMonitorEvent.
186         */
187        gulong addOnChanged(void delegate(FileIF, FileIF, GFileMonitorEvent, FileMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
188        {
189                auto wrapper = new OnChangedDelegateWrapper(dlg);
190                wrapper.handlerId = Signals.connectData(
191                        this,
192                        "changed",
193                        cast(GCallback)&callBackChanged,
194                        cast(void*)wrapper,
195                        cast(GClosureNotify)&callBackChangedDestroy,
196                        connectFlags);
197                return wrapper.handlerId;
198        }
199       
200        extern(C) static void callBackChanged(GFileMonitor* filemonitorStruct, GFile* file, GFile* otherFile, GFileMonitorEvent eventType, OnChangedDelegateWrapper wrapper)
201        {
202                wrapper.dlg(ObjectG.getDObject!(File, FileIF)(file), ObjectG.getDObject!(File, FileIF)(otherFile), eventType, wrapper.outer);
203        }
204       
205        extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
206        {
207                wrapper.remove(wrapper);
208        }
209}
Note: See TracBrowser for help on using the repository browser.