summaryrefslogtreecommitdiff
path: root/gio/src/mount.hg
blob: dceaf99838e1caef66ac45985e63c254e6975a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* Copyright (C) 2007 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

//#include <giomm/drive.h>
//#include <giomm/file.h>
//#include <giomm/volume.h>
#include <glibmm/interface.h>
#include <giomm/asyncresult.h>
#include <giomm/cancellable.h>
#include <giomm/mountoperation.h>
#include <giomm/icon.h>


_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/interface_p.h)

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GMountIface GMountIface;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

namespace Gio
{


class GIOMM_API File;
class GIOMM_API Drive;
class GIOMM_API Volume;

/** The Mount interface represents user-visible mounts.
 * Mount is a "mounted" filesystem that you can access. Mounted is in quotes because it's not the same as a unix mount:
 * it might be a gvfs mount, but you can still access the files on it if you use GIO. It might or might not be related to a volume object.
 *
 * Unmounting a Mount instance is an asynchronous operation. For more information about asynchronous operations, see AsyncReady.
 * To unmount a Mount instance, first call unmount(). The callback slot will be called when the operation has resolved (either with success or failure),
 * and a AsyncReady structure will be passed to the callback. That callback should then call unmount_finish() with the AsyncReady data to see if the operation was completed successfully.
 *
 * @ingroup Streams
 *
 * @newin{2,16}
 */
class GIOMM_API Mount : public Glib::Interface
{
  _CLASS_INTERFACE(Mount, GMount, G_MOUNT, GMountIface, , , GIOMM_API)

public:
  _WRAP_ENUM(UnmountFlags, GMountUnmountFlags, NO_GTYPE, decl_prefix GIOMM_API)
  _WRAP_ENUM(MountFlags, GMountMountFlags, NO_GTYPE, decl_prefix GIOMM_API)

  _WRAP_METHOD(Glib::RefPtr<File> get_root(), g_mount_get_root, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const File> get_root() const, g_mount_get_root, refreturn, constversion)

  _WRAP_METHOD(std::string get_name() const, g_mount_get_name)

  _WRAP_METHOD(Glib::RefPtr<Icon> get_icon(), g_mount_get_icon, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Icon> get_icon() const, g_mount_get_icon, refreturn, constversion)

  _WRAP_METHOD(Glib::RefPtr<Icon> get_symbolic_icon(), g_mount_get_symbolic_icon, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Icon> get_symbolic_icon() const, g_mount_get_symbolic_icon, refreturn, constversion)

  _WRAP_METHOD(std::string get_uuid() const, g_mount_get_uuid)

  _WRAP_METHOD(Glib::RefPtr<Volume> get_volume(), g_mount_get_volume, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Volume> get_volume() const, g_mount_get_volume, refreturn, constversion)

  _WRAP_METHOD(Glib::RefPtr<Drive> get_drive(), g_mount_get_drive, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Drive> get_drive() const, g_mount_get_drive, refreturn, constversion)

  _WRAP_METHOD(bool can_unmount() const, g_mount_can_unmount)
  _WRAP_METHOD(bool can_eject() const, g_mount_can_eject)

  void unmount(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, UnmountFlags flags = UnmountFlags::NONE);
  void unmount(const SlotAsyncReady& slot, UnmountFlags flags = UnmountFlags::NONE);
  void unmount(UnmountFlags flags = UnmountFlags::NONE);
  void unmount(const Glib::RefPtr<MountOperation>& mount_operation, UnmountFlags flags = UnmountFlags::NONE);
  void unmount(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, UnmountFlags flags = UnmountFlags::NONE);
  void unmount(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, UnmountFlags flags = UnmountFlags::NONE);
  _IGNORE(g_mount_unmount)
  _IGNORE(g_mount_unmount_with_operation)

  _WRAP_METHOD(bool unmount_finish(const Glib::RefPtr<AsyncResult>& result), g_mount_unmount_with_operation_finish, errthrow)
  _IGNORE(g_mount_unmount_finish)

  /** Remounts a mount.
   * This is an asynchronous operation, and is finished by calling mount_finish() with the AsyncResult data returned in the callback slot.
   *
   * Remounting is useful when some setting affecting the operation of the volume has been changed, as this may need a remount
   * to take affect. While this is semantically equivalent with unmounting and then remounting, not all backends might need to
   * actually be unmounted.
   *
   * @param operation A mount operation.
   * @param slot A callback which will be called when the operation is completed or canceled.
   * @param cancellable A cancellable object which can be used to cancel the operation.
   * @param flags Flags affecting the operation.
   */
  void remount(const Glib::RefPtr<MountOperation>& operation, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, MountFlags flags = MountFlags::NONE);

  /** Remounts a mount.
   * This is an asynchronous operation, and is finished by calling mount_finish() with the AsyncResult data returned in the callback slot.
   *
   * Remounting is useful when some setting affecting the operation of the volume has been changed, as this may need a remount
   * to take affect. While this is semantically equivalent with unmounting and then remounting, not all backends might need to
   * actually be unmounted.
   *
   * @param operation A mount operation.
   * @param slot A callback which will be called when the operation is completed or canceled.
   * @param flags Flags affecting the operation.
   */
  void remount(const Glib::RefPtr<MountOperation>& operation, const SlotAsyncReady& slot, MountFlags flags = MountFlags::NONE);

  /** Remounts a mount.
   *
   * Remounting is useful when some setting affecting the operation of the volume has been changed, as this may need a remount
   * to take affect. While this is semantically equivalent with unmounting and then remounting, not all backends might need to
   * actually be unmounted.
   *
   * @param operation A mount operation.
   * @param flags Flags affecting the operation.
   */
  void remount(const Glib::RefPtr<MountOperation>& operation, MountFlags flags = MountFlags::NONE);

  /** Remounts a mount, without user interaction.
   *
   * Remounting is useful when some setting affecting the operation of the volume has been changed, as this may need a remount
   * to take affect. While this is semantically equivalent with unmounting and then remounting, not all backends might need to
   * actually be unmounted.
   *
   * @param flags Flags affecting the operation.
   */
  void remount(MountFlags flags = MountFlags::NONE);
  _IGNORE(g_mount_remount)


  _WRAP_METHOD(bool remount_finish(const Glib::RefPtr<AsyncResult>& result), g_mount_remount_finish, errthrow)

  void eject(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, UnmountFlags flags = UnmountFlags::NONE);
  void eject(const SlotAsyncReady& slot, UnmountFlags flags = UnmountFlags::NONE);
  void eject(UnmountFlags flags = UnmountFlags::NONE);
  void eject(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, UnmountFlags flags = UnmountFlags::NONE);
  void eject(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, UnmountFlags flags = UnmountFlags::NONE);
  void eject(const Glib::RefPtr<MountOperation>& mount_operation, UnmountFlags flags = UnmountFlags::NONE);
  _IGNORE(g_mount_eject)
  _IGNORE(g_mount_eject_with_operation)

  _WRAP_METHOD(bool eject_finish(const Glib::RefPtr<AsyncResult>& result), g_mount_eject_with_operation_finish, errthrow)
  _IGNORE(g_mount_eject_finish)



  /** Tries to guess the type of content stored on the mount.
   * Returns one or more textual identifiers of well-known content types (typically
   * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
   * memory cards. See the <a href="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</a> specification for more on x-content types.
   *
   * This is an asynchronous operation, and is finished by calling
   * guess_content_type_finish().
   *
   * @param slot A callback which will be called when the operation is completed or canceled.
   * @param cancellable A cancellable object which can be used to cancel the operation.
   * @param force_rescan Whether to force a rescan of the content. Otherwise a cached result will be used if available.
   *
   * @newin{2,18}
   */
  void guess_content_type(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, bool force_rescan = true);

  /** Tries to guess the type of content stored on the mount.
   * Returns one or more textual identifiers of well-known content types (typically
   * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
   * memory cards. See the <a href="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</a> specification for more on x-content types.
   *
   * This is an asynchronous operation, and is finished by calling
   * guess_content_type_finish().
   *
   * @param slot A callback which will be called when the operation is completed or canceled.
   * @param force_rescan Whether to force a rescan of the content. Otherwise a cached result will be used if available.
   *
   * @newin{2,18}
   */
  void guess_content_type(const SlotAsyncReady& slot, bool force_rescan = true);

  /** Tries to guess the type of content stored on the mount.
   * Returns one or more textual identifiers of well-known content types (typically
   * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
   * memory cards. See the <a href="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</a> specification for more on x-content types.
   *
   * @param force_rescan Whether to force a rescan of the content. Otherwise a cached result will be used if available.
   *
   * @newin{2,18}
   */
  void guess_content_type(bool force_rescan = true);
  _IGNORE(g_mount_guess_content_type)

  void guess_content_type_sync(const Glib::RefPtr<Cancellable>& cancellable, bool force_rescan = true);
  void guess_content_type_sync(bool force_rescan = true);
  _IGNORE(g_mount_guess_content_type_sync)

  #m4 _CONVERSION(`gchar**',`std::vector<Glib::ustring>',`Glib::ArrayHandler<Glib::ustring>::array_to_vector($3, Glib::OWNERSHIP_DEEP)')

  /** Finishes guessing content types of the Mount.
   * If any errors occurred during the operation, an exception will be thrown.
   * In particular, you may get a Gio::Error::NOT_SUPPORTED if the mount
   * does not support content guessing.
   *
   * @newin{2,18}
   *
   * @param result An AsyncResult.
   * @return An array of content types.
   * @throw Glib::Error
   */
  _WRAP_METHOD(std::vector<Glib::ustring> guess_content_type_finish(const Glib::RefPtr<AsyncResult>& result), g_mount_guess_content_type_finish, errthrow)

  _WRAP_METHOD(bool is_shadowed() const, g_mount_is_shadowed)
  _WRAP_METHOD(void shadow(), g_mount_shadow)
  _WRAP_METHOD(void unshadow(), g_mount_unshadow)

  _WRAP_METHOD(Glib::RefPtr<File> get_default_location() const, g_mount_get_default_location)

  _WRAP_METHOD(Glib::ustring get_sort_key() const, g_mount_get_sort_key)

  _WRAP_SIGNAL(void changed(), changed)
  _WRAP_SIGNAL(void unmounted(), unmounted)
  _WRAP_SIGNAL(void pre_unmount(), pre_unmount)

  //There are no properties.
};

} // namespace Gio

namespace Glib
{

//Pre-declare this so we can use it in TypeTrait:
GIOMM_API
Glib::RefPtr<Gio::Mount> wrap(GMount* object, bool take_copy);

namespace Container_Helpers
{

/** This specialization of TypeTraits exists
 * because the default use of Glib::wrap(GObject*),
 * instead of a specific Glib::wrap(GSomeInterface*),
 * would not return a wrapper for an interface.
 */
template <>
struct TypeTraits< Glib::RefPtr<Gio::Mount> >
{
  using CppType = Glib::RefPtr<Gio::Mount>;
  using CType = GMount*;
  using CTypeNonConst = GMount*;

  static CType   to_c_type      (const CppType& item)
  { return Glib::unwrap (item); }

  static CppType to_cpp_type    (const CType& item)
  {
    //Use a specific Glib::wrap() function,
    //because CType has the specific type (not just GObject):
    return Glib::wrap(item, true /* take_copy */);
  }

  static void    release_c_type (CType item)
  {
    GLIBMM_DEBUG_UNREFERENCE(nullptr, item);
    g_object_unref(item);
  }
};

} // Container_Helpers
} // Glib