1/* Copyright (C) 2007 The gtkmm Development Team 2 * 3 * This library is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU Lesser General Public 5 * License as published by the Free Software Foundation; either 6 * version 2.1 of the License, or (at your option) any later version. 7 * 8 * This library is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public 14 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17#include <glibmm/listhandle.h> 18#include <giomm/mount.h> 19#include <giomm/icon.h> 20//#include <giomm/volume.h> 21//#include <giomm/mountoperation.h> 22 23_DEFS(giomm,gio) 24_PINCLUDE(glibmm/private/interface_p.h) 25 26 27#ifndef DOXYGEN_SHOULD_SKIP_THIS 28typedef struct _GDriveIface GDriveIface; 29#endif /* DOXYGEN_SHOULD_SKIP_THIS */ 30 31namespace Gio 32{ 33 34_WRAP_ENUM(DriveStartFlags, GDriveStartFlags) 35_WRAP_ENUM(DriveStartStopType, GDriveStartStopType) 36 37/** Virtual File System drive management. 38 * 39 * This represent a piece of hardware connected to the machine. It's generally only created for removable hardware or hardware with removable media. 40 * Gio::Drive is a container class for Gio::Volume objects that stem from the same piece of media. As such, Gio::Drive abstracts a drive with 41 * (or without) removable media and provides operations for querying whether media is available, determing whether media change is automatically 42 * detected and ejecting the media. 43 * 44 * If the Gio::Drive reports that media isn't automatically detected, one can poll for media; typically one should not do this periodically as a 45 * poll for media operation is potententially expensive and may spin up the drive, creating noise. 46 * 47 * @newin{2,16} 48 */ 49class GIOMM_API Drive : public Glib::Interface 50{ 51 _CLASS_INTERFACE(Drive, GDrive, G_DRIVE, GDriveIface, , , GIOMM_API) 52public: 53 54 _WRAP_METHOD(Glib::ustring get_name() const, g_drive_get_name) 55 56 _WRAP_METHOD(Glib::RefPtr<Icon> get_icon(), g_drive_get_icon, refreturn) 57 _WRAP_METHOD(Glib::RefPtr<const Icon> get_icon() const, g_drive_get_icon, refreturn, constversion) 58 59 _WRAP_METHOD(Glib::RefPtr<Icon> get_symbolic_icon(), g_drive_get_symbolic_icon, refreturn) 60 _WRAP_METHOD(Glib::RefPtr<const Icon> get_symbolic_icon() const, g_drive_get_symbolic_icon, refreturn, constversion) 61 62 _WRAP_METHOD(bool has_volumes() const, g_drive_has_volumes) 63 64#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<Volume> >',`$2($3, Glib::OWNERSHIP_DEEP)') 65 _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<Volume> > get_volumes(), g_drive_get_volumes) 66 67 _WRAP_METHOD(bool is_media_removable() const, g_drive_is_media_removable) 68 _WRAP_METHOD(bool is_removable() const, g_drive_is_removable) 69 _WRAP_METHOD(bool has_media() const, g_drive_has_media) 70 _WRAP_METHOD(bool is_media_check_automatic() const, g_drive_is_media_check_automatic) 71 _WRAP_METHOD(bool can_poll_for_media() const, g_drive_can_poll_for_media) 72 _WRAP_METHOD(bool can_eject() const, g_drive_can_eject) 73 74 /** Ejects the drive. 75 * @param slot A callback which will be called when the eject is completed or canceled. 76 * @param flags Flags affecting the unmount if required for eject. 77 * @param cancellable A cancellable object which can be used to cancel the eject. 78 */ 79 void eject(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 80 81 /** Ejects the drive. 82 * @param slot A callback which will be called when the eject is completed. 83 * @param flags Flags affecting the unmount if required for eject. 84 */ 85 void eject(const SlotAsyncReady& slot, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 86 void eject(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 87 void eject(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 88 89 /** Ejects the drive. 90 * @param flags Flags affecting the unmount if required for eject. 91 */ 92 void eject(MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 93 void eject(const Glib::RefPtr<MountOperation>& mount_operation, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 94 _IGNORE(g_drive_eject) 95 _IGNORE(g_drive_eject_with_operation) 96 97 // eject_finish() is deprecated in favor of eject_with_operation_finish(), and 98 // since all of our eject() overloads are implemented by 99 // eject_with_operation(), we implement the _finish() with 100 // eject_with_operation_finish and ignore the deprecated one 101 _WRAP_METHOD(bool eject_finish(const Glib::RefPtr<AsyncResult>& result), 102 g_drive_eject_with_operation_finish, 103 errthrow) 104 _IGNORE (g_drive_eject_finish) 105 106 /** Polls drive to see if media has been inserted or removed. 107 * @param slot A callback which will be called when the poll is completed. 108 * @param cancellable A cancellable object which can be used to cancel the operation. 109 */ 110 void poll_for_media(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable); 111 112 /** Polls drive to see if media has been inserted or removed. 113 * @param slot A callback which will be called when the poll is completed. 114 */ 115 void poll_for_media(const SlotAsyncReady& slot); 116 117 /** Polls drive to see if media has been inserted or removed. 118 */ 119 void poll_for_media(); 120 _IGNORE(g_drive_poll_for_media) 121 122 _WRAP_METHOD(bool poll_for_media_finish(const Glib::RefPtr<AsyncResult>& result), 123 g_drive_poll_for_media_finish, 124 errthrow) 125 126 _WRAP_METHOD(std::string get_identifier(const std::string& kind) const, g_drive_get_identifier) 127 128 #m4 _CONVERSION(`char**',`Glib::StringArrayHandle',`Glib::StringArrayHandle($3, Glib::OWNERSHIP_DEEP)') 129 _WRAP_METHOD(Glib::StringArrayHandle enumerate_identifiers() const, g_drive_enumerate_identifiers) 130 131 /** @newin{2,22} */ 132 void start(const Glib::RefPtr<MountOperation>& mount_operation, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot, DriveStartFlags flags = DRIVE_START_NONE); 133 /** @newin{2,22} */ 134 void start(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, DriveStartFlags flags = DRIVE_START_NONE); 135 _IGNORE(g_drive_start) 136 _WRAP_METHOD(bool start_finish(const Glib::RefPtr<AsyncResult>& result), g_drive_start_finish, errthrow) 137 /** @newin{2,22} */ 138 _WRAP_METHOD(bool can_start() const, g_drive_can_start) 139 /** @newin{2,22} */ 140 _WRAP_METHOD(bool can_start_degraded() const, g_drive_can_start_degraded) 141 142 /** @newin{2,22} */ 143 void stop(const Glib::RefPtr<MountOperation>& mount_operation, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 144 /** @newin{2,22} */ 145 void stop(const Glib::RefPtr<MountOperation>& mount_operation, const SlotAsyncReady& slot, MountUnmountFlags flags = MOUNT_UNMOUNT_NONE); 146 _IGNORE(g_drive_stop) 147 _WRAP_METHOD(bool stop_finish(const Glib::RefPtr<AsyncResult>& result), g_drive_stop_finish, errthrow) 148 /** @newin{2,22} */ 149 _WRAP_METHOD(bool can_stop() const, g_drive_can_stop) 150 151 _WRAP_METHOD(DriveStartStopType get_start_stop_type() const, g_drive_get_start_stop_type) 152 153 _WRAP_METHOD(Glib::ustring get_sort_key() const, g_drive_get_sort_key) 154 155 /** @newin{2,20} 156 */ 157 _WRAP_SIGNAL(void changed(), changed, no_default_handler) 158 159 /** @newin{2,20} 160 */ 161 _WRAP_SIGNAL(void disconnected(), disconnected, no_default_handler) 162 163 /** @newin{2,20} 164 */ 165 _WRAP_SIGNAL(void eject_button(), eject_button, no_default_handler) 166 _WRAP_SIGNAL(void stop_button(), stop_button, no_default_handler) 167 168 //_WRAP_VFUNC(Glib::ustring get_name() const, get_name) 169 //Careful of ref-counting: //_WRAP_VFUNC(Glib::RefPtr<Icon> get_icon() const, get_icon) 170 //_WRAP_VFUNC(bool has_volumes() const, has_volumes) 171}; 172 173} // namespace Gio 174 175namespace Glib 176{ 177 178//Pre-declare this so we can use it in TypeTrait: 179GIOMM_API 180Glib::RefPtr<Gio::Drive> wrap(GDrive* object, bool take_copy); 181 182namespace Container_Helpers 183{ 184 185/** This specialization of TypeTraits exists 186 * because the default use of Glib::wrap(GObject*), 187 * instead of a specific Glib::wrap(GSomeInterface*), 188 * would not return a wrapper for an interface. 189 */ 190template <> 191struct GIOMM_API TypeTraits< Glib::RefPtr<Gio::Drive> > 192{ 193 using CppType = Glib::RefPtr<Gio::Drive>; 194 using CType = GDrive*; 195 using CTypeNonConst = GDrive*; 196 197 static CType to_c_type (const CppType& item) 198 { return Glib::unwrap (item); } 199 200 static CppType to_cpp_type (const CType& item) 201 { 202 //Use a specific Glib::wrap() function, 203 //because CType has the specific type (not just GObject): 204 return Glib::wrap(item, true /* take_copy */); 205 } 206 207 static void release_c_type (CType item) 208 { 209 GLIBMM_DEBUG_UNREFERENCE(nullptr, item); 210 g_object_unref(item); 211 } 212}; 213 214} // Container_Helpers 215} // Glib 216