source: appstream-generator/build/girepo/gio/VolumeT.d @ 4841

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

Initial release

File size: 16.4 KB
Line 
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.VolumeT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import gio.AsyncResultIF;
26public  import gio.Cancellable;
27public  import gio.Drive;
28public  import gio.DriveIF;
29public  import gio.File;
30public  import gio.FileIF;
31public  import gio.Icon;
32public  import gio.IconIF;
33public  import gio.Mount;
34public  import gio.MountIF;
35public  import gio.MountOperation;
36public  import glib.ErrorG;
37public  import glib.GException;
38public  import glib.Str;
39public  import gobject.ObjectG;
40public  import gobject.Signals;
41public  import std.algorithm;
42
43
44/**
45 * The #GVolume interface represents user-visible objects that can be
46 * mounted. Note, when porting from GnomeVFS, #GVolume is the moral
47 * equivalent of #GnomeVFSDrive.
48 *
49 * Mounting a #GVolume instance is an asynchronous operation. For more
50 * information about asynchronous operations, see #GAsyncResult and
51 * #GTask. To mount a #GVolume, first call g_volume_mount() with (at
52 * least) the #GVolume instance, optionally a #GMountOperation object
53 * and a #GAsyncReadyCallback.
54 *
55 * Typically, one will only want to pass %NULL for the
56 * #GMountOperation if automounting all volumes when a desktop session
57 * starts since it's not desirable to put up a lot of dialogs asking
58 * for credentials.
59 *
60 * The callback will be fired when the operation has resolved (either
61 * with success or failure), and a #GAsyncReady structure will be
62 * passed to the callback.  That callback should then call
63 * g_volume_mount_finish() with the #GVolume instance and the
64 * #GAsyncReady data to see if the operation was completed
65 * successfully.  If an @error is present when g_volume_mount_finish()
66 * is called, then it will be filled with any error information.
67 *
68 * ## Volume Identifiers # {#volume-identifier}
69 *
70 * It is sometimes necessary to directly access the underlying
71 * operating system object behind a volume (e.g. for passing a volume
72 * to an application via the commandline). For this purpose, GIO
73 * allows to obtain an 'identifier' for the volume. There can be
74 * different kinds of identifiers, such as Hal UDIs, filesystem labels,
75 * traditional Unix devices (e.g. `/dev/sda2`), UUIDs. GIO uses predefined
76 * strings as names for the different kinds of identifiers:
77 * #G_VOLUME_IDENTIFIER_KIND_HAL_UDI, #G_VOLUME_IDENTIFIER_KIND_LABEL, etc.
78 * Use g_volume_get_identifier() to obtain an identifier for a volume.
79 *
80 *
81 * Note that #G_VOLUME_IDENTIFIER_KIND_HAL_UDI will only be available
82 * when the gvfs hal volume monitor is in use. Other volume monitors
83 * will generally be able to provide the #G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE
84 * identifier, which can be used to obtain a hal device by means of
85 * libhal_manager_find_device_string_match().
86 */
87public template VolumeT(TStruct)
88{
89        /** Get the main Gtk struct */
90        public GVolume* getVolumeStruct()
91        {
92                return cast(GVolume*)getStruct();
93        }
94
95
96        /**
97         * Checks if a volume can be ejected.
98         *
99         * Returns: %TRUE if the @volume can be ejected. %FALSE otherwise
100         */
101        public bool canEject()
102        {
103                return g_volume_can_eject(getVolumeStruct()) != 0;
104        }
105
106        /**
107         * Checks if a volume can be mounted.
108         *
109         * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise
110         */
111        public bool canMount()
112        {
113                return g_volume_can_mount(getVolumeStruct()) != 0;
114        }
115
116        /**
117         * Ejects a volume. This is an asynchronous operation, and is
118         * finished by calling g_volume_eject_finish() with the @volume
119         * and #GAsyncResult returned in the @callback.
120         *
121         * Deprecated: Use g_volume_eject_with_operation() instead.
122         *
123         * Params:
124         *     flags = flags affecting the unmount if required for eject
125         *     cancellable = optional #GCancellable object, %NULL to ignore
126         *     callback = a #GAsyncReadyCallback, or %NULL
127         *     userData = user data that gets passed to @callback
128         */
129        public void eject(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
130        {
131                g_volume_eject(getVolumeStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
132        }
133
134        /**
135         * Finishes ejecting a volume. If any errors occurred during the operation,
136         * @error will be set to contain the errors and %FALSE will be returned.
137         *
138         * Deprecated: Use g_volume_eject_with_operation_finish() instead.
139         *
140         * Params:
141         *     result = a #GAsyncResult
142         *
143         * Returns: %TRUE, %FALSE if operation failed
144         *
145         * Throws: GException on failure.
146         */
147        public bool ejectFinish(AsyncResultIF result)
148        {
149                GError* err = null;
150               
151                auto p = g_volume_eject_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
152               
153                if (err !is null)
154                {
155                        throw new GException( new ErrorG(err) );
156                }
157               
158                return p;
159        }
160
161        /**
162         * Ejects a volume. This is an asynchronous operation, and is
163         * finished by calling g_volume_eject_with_operation_finish() with the @volume
164         * and #GAsyncResult data returned in the @callback.
165         *
166         * Params:
167         *     flags = flags affecting the unmount if required for eject
168         *     mountOperation = a #GMountOperation or %NULL to
169         *         avoid user interaction
170         *     cancellable = optional #GCancellable object, %NULL to ignore
171         *     callback = a #GAsyncReadyCallback, or %NULL
172         *     userData = user data passed to @callback
173         *
174         * Since: 2.22
175         */
176        public void ejectWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
177        {
178                g_volume_eject_with_operation(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
179        }
180
181        /**
182         * Finishes ejecting a volume. If any errors occurred during the operation,
183         * @error will be set to contain the errors and %FALSE will be returned.
184         *
185         * Params:
186         *     result = a #GAsyncResult
187         *
188         * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise
189         *
190         * Since: 2.22
191         *
192         * Throws: GException on failure.
193         */
194        public bool ejectWithOperationFinish(AsyncResultIF result)
195        {
196                GError* err = null;
197               
198                auto p = g_volume_eject_with_operation_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
199               
200                if (err !is null)
201                {
202                        throw new GException( new ErrorG(err) );
203                }
204               
205                return p;
206        }
207
208        /**
209         * Gets the kinds of [identifiers][volume-identifier] that @volume has.
210         * Use g_volume_get_identifier() to obtain the identifiers themselves.
211         *
212         * Returns: a %NULL-terminated array
213         *     of strings containing kinds of identifiers. Use g_strfreev() to free.
214         */
215        public string[] enumerateIdentifiers()
216        {
217                auto retStr = g_volume_enumerate_identifiers(getVolumeStruct());
218               
219                scope(exit) Str.freeStringArray(retStr);
220                return Str.toStringArray(retStr);
221        }
222
223        /**
224         * Gets the activation root for a #GVolume if it is known ahead of
225         * mount time. Returns %NULL otherwise. If not %NULL and if @volume
226         * is mounted, then the result of g_mount_get_root() on the
227         * #GMount object obtained from g_volume_get_mount() will always
228         * either be equal or a prefix of what this function returns. In
229         * other words, in code
230         *
231         * |[<!-- language="C" -->
232         * GMount *mount;
233         * GFile *mount_root
234         * GFile *volume_activation_root;
235         *
236         * mount = g_volume_get_mount (volume); // mounted, so never NULL
237         * mount_root = g_mount_get_root (mount);
238         * volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL
239         * ]|
240         * then the expression
241         * |[<!-- language="C" -->
242         * (g_file_has_prefix (volume_activation_root, mount_root) ||
243         * g_file_equal (volume_activation_root, mount_root))
244         * ]|
245         * will always be %TRUE.
246         *
247         * Activation roots are typically used in #GVolumeMonitor
248         * implementations to find the underlying mount to shadow, see
249         * g_mount_is_shadowed() for more details.
250         *
251         * Returns: the activation root of @volume
252         *     or %NULL. Use g_object_unref() to free.
253         *
254         * Since: 2.18
255         */
256        public FileIF getActivationRoot()
257        {
258                auto p = g_volume_get_activation_root(getVolumeStruct());
259               
260                if(p is null)
261                {
262                        return null;
263                }
264               
265                return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p, true);
266        }
267
268        /**
269         * Gets the drive for the @volume.
270         *
271         * Returns: a #GDrive or %NULL if @volume is not
272         *     associated with a drive. The returned object should be unreffed
273         *     with g_object_unref() when no longer needed.
274         */
275        public DriveIF getDrive()
276        {
277                auto p = g_volume_get_drive(getVolumeStruct());
278               
279                if(p is null)
280                {
281                        return null;
282                }
283               
284                return ObjectG.getDObject!(Drive, DriveIF)(cast(GDrive*) p, true);
285        }
286
287        /**
288         * Gets the icon for @volume.
289         *
290         * Returns: a #GIcon.
291         *     The returned object should be unreffed with g_object_unref()
292         *     when no longer needed.
293         */
294        public IconIF getIcon()
295        {
296                auto p = g_volume_get_icon(getVolumeStruct());
297               
298                if(p is null)
299                {
300                        return null;
301                }
302               
303                return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true);
304        }
305
306        /**
307         * Gets the identifier of the given kind for @volume.
308         * See the [introduction][volume-identifier] for more
309         * information about volume identifiers.
310         *
311         * Params:
312         *     kind = the kind of identifier to return
313         *
314         * Returns: a newly allocated string containing the
315         *     requested identfier, or %NULL if the #GVolume
316         *     doesn't have this kind of identifier
317         */
318        public string getIdentifier(string kind)
319        {
320                auto retStr = g_volume_get_identifier(getVolumeStruct(), Str.toStringz(kind));
321               
322                scope(exit) Str.freeString(retStr);
323                return Str.toString(retStr);
324        }
325
326        /**
327         * Gets the mount for the @volume.
328         *
329         * Returns: a #GMount or %NULL if @volume isn't mounted.
330         *     The returned object should be unreffed with g_object_unref()
331         *     when no longer needed.
332         */
333        public MountIF getMount()
334        {
335                auto p = g_volume_get_mount(getVolumeStruct());
336               
337                if(p is null)
338                {
339                        return null;
340                }
341               
342                return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p, true);
343        }
344
345        /**
346         * Gets the name of @volume.
347         *
348         * Returns: the name for the given @volume. The returned string should
349         *     be freed with g_free() when no longer needed.
350         */
351        public string getName()
352        {
353                auto retStr = g_volume_get_name(getVolumeStruct());
354               
355                scope(exit) Str.freeString(retStr);
356                return Str.toString(retStr);
357        }
358
359        /**
360         * Gets the sort key for @volume, if any.
361         *
362         * Returns: Sorting key for @volume or %NULL if no such key is available
363         *
364         * Since: 2.32
365         */
366        public string getSortKey()
367        {
368                return Str.toString(g_volume_get_sort_key(getVolumeStruct()));
369        }
370
371        /**
372         * Gets the symbolic icon for @volume.
373         *
374         * Returns: a #GIcon.
375         *     The returned object should be unreffed with g_object_unref()
376         *     when no longer needed.
377         *
378         * Since: 2.34
379         */
380        public IconIF getSymbolicIcon()
381        {
382                auto p = g_volume_get_symbolic_icon(getVolumeStruct());
383               
384                if(p is null)
385                {
386                        return null;
387                }
388               
389                return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true);
390        }
391
392        /**
393         * Gets the UUID for the @volume. The reference is typically based on
394         * the file system UUID for the volume in question and should be
395         * considered an opaque string. Returns %NULL if there is no UUID
396         * available.
397         *
398         * Returns: the UUID for @volume or %NULL if no UUID can be computed.
399         *     The returned string should be freed with g_free()
400         *     when no longer needed.
401         */
402        public string getUuid()
403        {
404                auto retStr = g_volume_get_uuid(getVolumeStruct());
405               
406                scope(exit) Str.freeString(retStr);
407                return Str.toString(retStr);
408        }
409
410        /**
411         * Mounts a volume. This is an asynchronous operation, and is
412         * finished by calling g_volume_mount_finish() with the @volume
413         * and #GAsyncResult returned in the @callback.
414         *
415         * Params:
416         *     flags = flags affecting the operation
417         *     mountOperation = a #GMountOperation or %NULL to avoid user interaction
418         *     cancellable = optional #GCancellable object, %NULL to ignore
419         *     callback = a #GAsyncReadyCallback, or %NULL
420         *     userData = user data that gets passed to @callback
421         */
422        public void mount(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
423        {
424                g_volume_mount(getVolumeStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
425        }
426
427        /**
428         * Finishes mounting a volume. If any errors occurred during the operation,
429         * @error will be set to contain the errors and %FALSE will be returned.
430         *
431         * If the mount operation succeeded, g_volume_get_mount() on @volume
432         * is guaranteed to return the mount right after calling this
433         * function; there's no need to listen for the 'mount-added' signal on
434         * #GVolumeMonitor.
435         *
436         * Params:
437         *     result = a #GAsyncResult
438         *
439         * Returns: %TRUE, %FALSE if operation failed
440         *
441         * Throws: GException on failure.
442         */
443        public bool mountFinish(AsyncResultIF result)
444        {
445                GError* err = null;
446               
447                auto p = g_volume_mount_finish(getVolumeStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
448               
449                if (err !is null)
450                {
451                        throw new GException( new ErrorG(err) );
452                }
453               
454                return p;
455        }
456
457        /**
458         * Returns whether the volume should be automatically mounted.
459         *
460         * Returns: %TRUE if the volume should be automatically mounted
461         */
462        public bool shouldAutomount()
463        {
464                return g_volume_should_automount(getVolumeStruct()) != 0;
465        }
466
467        protected class OnChangedDelegateWrapper
468        {
469                static OnChangedDelegateWrapper[] listeners;
470                void delegate(VolumeIF) dlg;
471                gulong handlerId;
472               
473                this(void delegate(VolumeIF) dlg)
474                {
475                        this.dlg = dlg;
476                        this.listeners ~= this;
477                }
478               
479                void remove(OnChangedDelegateWrapper source)
480                {
481                        foreach(index, wrapper; listeners)
482                        {
483                                if (wrapper.handlerId == source.handlerId)
484                                {
485                                        listeners[index] = null;
486                                        listeners = std.algorithm.remove(listeners, index);
487                                        break;
488                                }
489                        }
490                }
491        }
492
493        /**
494         * Emitted when the volume has been changed.
495         */
496        gulong addOnChanged(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
497        {
498                auto wrapper = new OnChangedDelegateWrapper(dlg);
499                wrapper.handlerId = Signals.connectData(
500                        this,
501                        "changed",
502                        cast(GCallback)&callBackChanged,
503                        cast(void*)wrapper,
504                        cast(GClosureNotify)&callBackChangedDestroy,
505                        connectFlags);
506                return wrapper.handlerId;
507        }
508       
509        extern(C) static void callBackChanged(GVolume* volumeStruct, OnChangedDelegateWrapper wrapper)
510        {
511                wrapper.dlg(wrapper.outer);
512        }
513       
514        extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
515        {
516                wrapper.remove(wrapper);
517        }
518
519        protected class OnRemovedDelegateWrapper
520        {
521                static OnRemovedDelegateWrapper[] listeners;
522                void delegate(VolumeIF) dlg;
523                gulong handlerId;
524               
525                this(void delegate(VolumeIF) dlg)
526                {
527                        this.dlg = dlg;
528                        this.listeners ~= this;
529                }
530               
531                void remove(OnRemovedDelegateWrapper source)
532                {
533                        foreach(index, wrapper; listeners)
534                        {
535                                if (wrapper.handlerId == source.handlerId)
536                                {
537                                        listeners[index] = null;
538                                        listeners = std.algorithm.remove(listeners, index);
539                                        break;
540                                }
541                        }
542                }
543        }
544
545        /**
546         * This signal is emitted when the #GVolume have been removed. If
547         * the recipient is holding references to the object they should
548         * release them so the object can be finalized.
549         */
550        gulong addOnRemoved(void delegate(VolumeIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
551        {
552                auto wrapper = new OnRemovedDelegateWrapper(dlg);
553                wrapper.handlerId = Signals.connectData(
554                        this,
555                        "removed",
556                        cast(GCallback)&callBackRemoved,
557                        cast(void*)wrapper,
558                        cast(GClosureNotify)&callBackRemovedDestroy,
559                        connectFlags);
560                return wrapper.handlerId;
561        }
562       
563        extern(C) static void callBackRemoved(GVolume* volumeStruct, OnRemovedDelegateWrapper wrapper)
564        {
565                wrapper.dlg(wrapper.outer);
566        }
567       
568        extern(C) static void callBackRemovedDestroy(OnRemovedDelegateWrapper wrapper, GClosure* closure)
569        {
570                wrapper.remove(wrapper);
571        }
572}
Note: See TracBrowser for help on using the repository browser.