def pressMenuIcon(self, e): print('ICON!!!', e['name']) #self.changeAttrByName(e['name'], 'icon_name', 'preferences-system-time-symbolic') self.menu.update() mo = Gio.MountOperation() mo.set_anonymous(True) vm = Gio.VolumeMonitor.get() # print(dir(vm)) # print(vm.get_mount_for_uuid(VOLUME_UUID)) # print(vm.get_volume_for_uuid(VOLUME_UUID)) loop = GLib.MainLoop() found = False for v in vm.get_volumes(): name = v.get_name() #print(name) if name == e['name']: mount = v.get_mount() #print(name, v.get_uuid(), v.get_mount(), v.get_drive()) if not mount: v.mount(0, mo, None, self.mount_done_cb, loop) # print(name, v.get_uuid(), v.get_mount(), v.get_drive()) found = True #v.mount(0, mo, None, self.mounted_done_cb, loop) if found: loop.run()
def on_volume_added(vm, volume, _): print("\nVOLUME ADDED") print_volume_identifiers(volume) should_automount = volume.should_automount() print(" should_automount: %s" % should_automount) if should_automount: mount_op = Gio.MountOperation() # TODO: g_signal_connect (op, "ask_password", G_CALLBACK (ask_password_cb), NULL); # TODO: connect to the "aborted" signal? Any others? volume.mount(0, mount_op, None, on_volume_mounted, mount_op)
def _do_mount(self, gfileobj): op = Gio.MountOperation() self.__ask_password_cnt = 0 op.connect('ask-password', self._ask_password_cb) try: gfileobj.mount_enclosing_volume(op, self._mount_done_cb) if self.__mainloop is not None: self.__mainloop.run() except Gio.Error as error: self.__logger.error(get_gio_errmsg(error, "Error in `_do_mount`")) raise exceptions.RemoteMountFailedError(str(error)) except GLib.GError as error: self.__logger.error(str(error)) raise exceptions.RemoteMountFailedError(str(error))
def main(args=None): if args is None: args = sys.argv[1:] local, remote = args Notify.init("dirsync") remote = Gio.file_new_for_uri(remote) def mount_done(*args): watch(local, remote) mount_op = Gio.MountOperation() remote.mount_enclosing_volume(Gio.MountMountFlags.NONE, mount_op, None, mount_done, None) while True: Gtk.main_iteration()
def _mount(self, uri, domain, username, password=None): """Perform actual mounting operation with specified data""" self._show_spinner() def ask_password(operation, message, default_user, default_domain, flags): # configure mount operation operation.set_domain(domain if domain is not None and domain != '' else default_domain) operation.set_username(username if username is not None and username != '' else default_user) if password is not None: # set password to stored one operation.set_password(password) operation.reply(Gio.MountOperationResult.HANDLED) else: # we don't have stored password, ask user to provide one dialog = InputDialog(self._application) dialog.set_title(_('Mount operation')) dialog.set_label(message) dialog.set_password() response = dialog.get_response() if response[0] == Gtk.ResponseType.OK: operation.set_password(response[1]) operation.reply(Gio.MountOperationResult.HANDLED) # create new mount operation object operation = Gio.MountOperation() operation.connect('ask-password', ask_password) # perform mount path = Gio.File.new_for_commandline_arg(uri) path.mount_enclosing_volume(Gio.MountMountFlags.NONE, operation, None, self.__mount_callback, None)
def main(): mo = Gio.MountOperation() mo.set_anonymous(True) vm = Gio.VolumeMonitor.get() # print(dir(vm)) # print(vm.get_mount_for_uuid(VOLUME_UUID)) # print(vm.get_volume_for_uuid(VOLUME_UUID)) loop = GLib.MainLoop() found = False for v in vm.get_volumes(): name = v.get_name() if name == VOLUME_NAME: mount = v.get_mount() print(name, v.get_uuid(), v.get_mount(), v.get_drive()) if not mount: v.mount(0, mo, None, mount_done_cb, loop) # print(name, v.get_uuid(), v.get_mount(), v.get_drive()) found = True if found: loop.run()
def mount_volume(self, button, vol): Gio.Volume.mount(vol, Gio.MountMountFlags.NONE, Gio.MountOperation(), None) self.act_onmount = True
def init(self): mo = Gio.MountOperation() mo.set_anonymous(True) vm = Gio.VolumeMonitor.get() # print(dir(vm)) # print(vm.get_mount_for_uuid(VOLUME_UUID)) # print(vm.get_volume_for_uuid(VOLUME_UUID)) """ loop = GLib.MainLoop() found = False for v in vm.get_volumes(): name = v.get_name() #print(name) print(v.get_path()) if name == 'wblack': mount = v.get_mount() print('select:', mo) #print(name, v.get_uuid(), v.get_mount(), v.get_drive()) if not mount: v.mount(0, mo, None, self.mount_done_cb, loop) # print(name, v.get_uuid(), v.get_mount(), v.get_drive()) found = True v.mount(0, mo, None, self.mounted_done_cb, loop) if found: loop.run() """ ###################### self.listDrive = [] volume_monitor = Gio.VolumeMonitor.get() for volume in vm.get_volumes(): mount = volume.get_mount() if mount is not None: #print(mount.get_default_location().get_path()) #print('1', volume.get_drive().get_icon().get_names()) icon_names = volume.get_drive().get_icon().get_names() icon = None for x in icon_names: if 'usb' not in x and 'symbolic' in x: icon = x break if icon == None: icon = icon_names[0] self.listDrive.append({'name': volume.get_name(), 'path': mount.get_default_location().get_path(), 'uuid': volume.get_uuid(), 'icon_name': icon }) else: #print(volume.get_name()) self.listDrive.append({'name': volume.get_name(), 'path': None, 'uuid': volume.get_uuid(), 'icon_name': None})