Exemplo n.º 1
0
 def is_interesting(self, sysfs_path, props):
     #there is no media-player-info support for the apple iphone, so instead 
     #we have to look for the correct model name instead.
     if "Apple" in props.get("ID_VENDOR", "") and "iPhone" in props.get("ID_MODEL", ""):
         #also have to check the iPhone has a valid serial, as that is used
         #with gvfs to generate the uuid of the moint
         self._print_device(self.gudev.query_by_sysfs_path(sysfs_path))
         if props.get("ID_SERIAL_SHORT"):
             uuid = "afc://%s/" % props["ID_SERIAL_SHORT"]
             for m in gio.volume_monitor_get().get_mounts():
                 root = m.get_root()
                 uri = root.get_uri()
                 if uuid == uri:
                     #check that gvfs has mounted the volume at the expected location
                     #FIXME: this is not very nice, as it depends on an implementation
                     #detail of gvfs-afc backend. It would be best if there was some UUID
                     #that was present in udev and guarenteed to be present in all gio mounts
                     #but experimentation tells me there is no such uuid, it returns None
                     props[PROPS_KEY_MOUNT] = root.get_path()
                     props[PROPS_KEY_NAME]  = m.get_name()
                     props[PROPS_KEY_ICON]  = "phone"
                     return True
             log.warning("iPhone not mounted by gvfs")
         else:
             log.critical("iPhone missing ID_SERIAL_SHORT udev property")
     return False
Exemplo n.º 2
0
 def is_interesting(self, sysfs_path, props):
     #FIXME:
     #
     # THIS ONLY WORKS DURING PROBE. NO IDEA WHY.
     # When called in response to a Udev added event, gioVolumeMonitor does
     # not return the newly added volumes. There appears to be some sort of
     # race condition
     #
     #just like rhythmbox, we let media-player-info do the matching, and
     #instead just check if it has told us that the media player uses the
     #ipod storage protocol
     access_protocols = self.get_mpi_access_protocol(props)
     if "ipod" in access_protocols.split(";"):
         uuid = props.get("ID_FS_UUID")
         for vol in gio.volume_monitor_get().get_volumes():
             #is this the disk corresponding to the ipod
             #FIXME: we should be able to do gio.VolumeMonitor.get_volume_for_uuid()
             #but that doesnt work
             if vol.get_identifier('uuid') == uuid:
                 #now check it is mounted
                 mount = vol.get_mount()
                 if mount:
                     f = mount.get_root()
                     props[PROPS_KEY_MOUNT] = f.get_path()
                     props[PROPS_KEY_NAME]  = "%s's %s" % (mount.get_name(), props.get("ID_MODEL", "iPod"))
                     props[PROPS_KEY_ICON]  = self.get_mpi_icon(props, fallback="multimedia-player-apple-ipod")
                     return True
                 else:
                     log.warn("ipod not mounted")
         log.warn("could not find volume with udev ID_FS_UUID: %s" % uuid)
     return False
Exemplo n.º 3
0
 def is_interesting(self, sysfs_path, props):
     #there is no media-player-info support for the apple iphone, so instead 
     #we have to look for the correct model name instead.
     if "Apple" in props.get("ID_VENDOR", "") and "iPhone" in props.get("ID_MODEL", ""):
         #also have to check the iPhone has a valid serial, as that is used
         #with gvfs to generate the uuid of the moint
         self._print_device(self.gudev.query_by_sysfs_path(sysfs_path))
         if props.get("ID_SERIAL_SHORT"):
             uuid = "afc://%s/" % props["ID_SERIAL_SHORT"]
             for m in gio.volume_monitor_get().get_mounts():
                 root = m.get_root()
                 uri = root.get_uri()
                 if uuid == uri:
                     #check that gvfs has mounted the volume at the expected location
                     #FIXME: this is not very nice, as it depends on an implementation
                     #detail of gvfs-afc backend. It would be best if there was some UUID
                     #that was present in udev and guarenteed to be present in all gio mounts
                     #but experimentation tells me there is no such uuid, it returns None
                     props[PROPS_KEY_MOUNT] = root.get_path()
                     props[PROPS_KEY_NAME]  = m.get_name()
                     props[PROPS_KEY_ICON]  = "phone"
                     return True
             log.warning("iPhone not mounted by gvfs")
         else:
             log.critical("iPhone missing ID_SERIAL_SHORT udev property")
     return False
Exemplo n.º 4
0
 def is_interesting(self, sysfs_path, props):
     #FIXME:
     #
     # THIS ONLY WORKS DURING PROBE. NO IDEA WHY.
     # When called in response to a Udev added event, gioVolumeMonitor does
     # not return the newly added volumes. There appears to be some sort of
     # race condition
     #
     #just like rhythmbox, we let media-player-info do the matching, and
     #instead just check if it has told us that the media player uses the
     #ipod storage protocol
     access_protocols = self.get_mpi_access_protocol(props)
     if "ipod" in access_protocols.split(";"):
         uuid = props.get("ID_FS_UUID")
         for vol in gio.volume_monitor_get().get_volumes():
             #is this the disk corresponding to the ipod
             #FIXME: we should be able to do gio.VolumeMonitor.get_volume_for_uuid()
             #but that doesnt work
             if vol.get_identifier('uuid') == uuid:
                 #now check it is mounted
                 mount = vol.get_mount()
                 if mount:
                     f = mount.get_root()
                     props[PROPS_KEY_MOUNT] = f.get_path()
                     props[PROPS_KEY_NAME]  = "%s's %s" % (mount.get_name(), props.get("ID_MODEL", "iPod"))
                     props[PROPS_KEY_ICON]  = self.get_mpi_icon(props, fallback="multimedia-player-apple-ipod")
                     return True
                 else:
                     log.warn("ipod not mounted")
         log.warn("could not find volume with udev ID_FS_UUID: %s" % uuid)
     return False
Exemplo n.º 5
0
    def __init__(self, **kwargs):
        SimpleFactory.SimpleFactory.__init__(self, **kwargs)
        self._volumes = {}
        self._categories = {}

        self._vm = gio.volume_monitor_get()
        self._vm.connect("mount-added", self._volume_mounted_cb)
        self._vm.connect("mount-removed", self._volume_unmounted_cb)
Exemplo n.º 6
0
    def __init__(self, **kwargs):
        SimpleFactory.SimpleFactory.__init__(self, **kwargs)
        self._volumes = {}
        self._categories = {}

        self._vm = gio.volume_monitor_get()
        self._vm.connect("mount-added",self._volume_mounted_cb)
        self._vm.connect("mount-removed",self._volume_unmounted_cb)
Exemplo n.º 7
0
    def start_tracking(self):
        volume_monitor = gio.volume_monitor_get()
        volume_monitor.connect('drive-connected', self._drive_connected)
        volume_monitor.connect('drive-changed', self._drive_changed)
        volume_monitor.connect('mount-added', self._mount_added)
        volume_monitor.connect('drive-disconnected', self._drive_disconnected)

        for drive in volume_monitor.get_connected_drives():
            self._drive_connected(volume_monitor, drive)
Exemplo n.º 8
0
    def _set_up_volumes(self):
        self._set_up_documents_button()

        volume_monitor = gio.volume_monitor_get()
        self._mount_added_hid = volume_monitor.connect('mount-added',
                                                       self.__mount_added_cb)
        self._mount_removed_hid = volume_monitor.connect('mount-removed',
            self.__mount_removed_cb)

        for mount in volume_monitor.get_mounts():
            self._add_button(mount)
Exemplo n.º 9
0
    def _set_up_volumes(self):
        self._set_up_documents_button()

        volume_monitor = gio.volume_monitor_get()
        self._mount_added_hid = volume_monitor.connect('mount-added',
                                                       self.__mount_added_cb)
        self._mount_removed_hid = volume_monitor.connect(
            'mount-removed', self.__mount_removed_cb)

        for mount in volume_monitor.get_mounts():
            self._add_button(mount)
Exemplo n.º 10
0
    def __init__(self):

        gobject.GObject.__init__(self)

        self.unidades = {}
        self.demonio_unidades = gio.volume_monitor_get()

        self.demonio_unidades.connect('mount-added', self.__emit_update)
        self.demonio_unidades.connect('mount-removed', self.__emit_update)

        self.__set_unidades()
Exemplo n.º 11
0
def _setup_volumes(tray):
    volume_monitor = gio.volume_monitor_get()

    for volume in volume_monitor.get_volumes():
        _mount(volume, tray)

    for mount in volume_monitor.get_mounts():
        _add_device(mount, tray)

    volume_monitor.connect('volume-added', _volume_added_cb, tray)
    volume_monitor.connect('mount-added', _mount_added_cb, tray)
    volume_monitor.connect('mount-removed', _mount_removed_cb, tray)
Exemplo n.º 12
0
	def __init__(self):
		gobject.GObject.__init__ (self)
		if not os.path.isdir(Globals.AutoStartDirectory):
			os.system('mkdir %s' % Globals.AutoStartDirectory)
		self.notifier = utils.Notifier()
		self.menuparser = MenuParser.MenuParser()
		self.menuparser.connect('menu-changed',self.MenuChanged)
		self.AppsFile = None
		self.SetFile = None
		self.menucache = {}
		self.nonMenuitems = '<Bookmarks>','<AuxiliaryFunctions>','<RecentItems>','<RecentApps>','<WebBookmarks>','<Favorites>','<Shutdown>'

		if Globals.OnlyShowFavs: 
			self.BaseMenu = '<Favorites>'
			self.menuparser.CacheApplications = None
			self.menuparser.CacheSettings = None
		elif Globals.OnlyShowRecentApps: 
			self.BaseMenu = '<RecentApps>'
			self.menuparser.CacheApplications = None
			self.menuparser.CacheSettings = None
		else:
			self.menuparser.ParseMenus()
			self.BaseMenu = self.menuparser.CacheApplications
		if isgio:
			self.monitor=gio.volume_monitor_get()
			self.monitor.connect("drive-changed",self.on_drive_changed)
			self.allgio =  gio.app_info_get_all()
		else:self.allgio = None
		self.Launcher = Launcher.Launcher()
		self.recent_manager = gtk.recent_manager_get_default()
		self.recent_manager.connect("changed", self.onRecentChanged)
		self.recents_changed = True
		self.recents = None
		self.ItemComments = {}
		self.Menu = self.BaseMenu
		self.PrevMenu = []
		self.searchresults = 0
		##### Load IconFactory##################################
		self.IconFactory = IconFactory.IconFactory()
		##### Load webbookmarks##################################
		try:
			self.webbookmarker = bookmarks.BookmarksMenu().getBookmarks()
		except:
			self.webbookmarker = None
		##### Construct the menu###########################
		self.menuitems = 'settings','places','auxiliary','recent','recentapps','webbookmarks','favorites','shutdown','all'
		for item in self.menuitems:
			#print 'Loading item to memory: ',item
			self.Restart(item)
		gc.collect()
Exemplo n.º 13
0
    def _find_media(self):
        """Fill the combo box with available storage media.

        Also sets up a callback to keep the list current.
        """
        try:
            import gio
        except ImportError:
            return self._find_media_hal()

        volume_monitor = gio.volume_monitor_get()
        volume_monitor.connect('mount-added', self._gio_mount_added_cb)
        volume_monitor.connect('mount-removed', self._gio_mount_removed_cb)
        for mount in volume_monitor.get_mounts():
            self._gio_mount_added_cb(volume_monitor, mount)
Exemplo n.º 14
0
    def start_tracking(self):
        volume_monitor = gio.volume_monitor_get()
        volume_monitor.connect('drive-connected', self._drive_connected)
        volume_monitor.connect('volume-added', self._volume_added)
        volume_monitor.connect('volume-changed', self._volume_changed)
        volume_monitor.connect('mount-added', self._mount_added)
        volume_monitor.connect('volume-removed', self._volume_removed)
        volume_monitor.connect('drive-disconnected', self._drive_disconnected)

        for drive in volume_monitor.get_connected_drives():
            self._drive_connected(volume_monitor, drive)
            volumes = drive.get_volumes()
            if volumes:
                for volume in volumes:
                    self._volume_added(volume_monitor, volume)
Exemplo n.º 15
0
def get_gnome_drive(self, dev):
    try:
        monitor = gio.volume_monitor_get()
        for drive in monitor.get_volumes():
            if 'unix-device' in drive.enumerate_identifiers():
                if drive.get_identifier('unix-device') == dev:
                    name = drive.get_name()
                    icon = drive.get_icon().get_names()[0]
                    return (name, icon)
        for drive in monitor.get_connected_drives():
            if 'unix-device' in drive.enumerate_identifiers():
                if drive.get_identifier('unix-device') == dev:
                    name = drive.get_name()
                    icon = drive.get_icon().get_names()[0]
                    return (name, icon)
    except Exception:
        logging.exception('Could not determine GNOME drive:')
    return ('', '')
Exemplo n.º 16
0
 def __init__(self):
     _gtk.VBox.__init__(self)
     self.builder = _gtk.Builder()
     self.builder.add_from_file(
         _os.path.join(_os.environ["FILEMANAGER_PATH"], "widget.builder"))
     self.area = self.builder.get_object("Area")
     self.file_area = self.builder.get_object("FileArea")
     self.file_view = self.builder.get_object("FileView")
     self.file_view.connect("item-activated", self._item_activated)
     self.file_view.connect("button-press-event", self._handler_click)
     self.file_model = self.builder.get_object("FileModel")
     self.path_label = self.builder.get_object("Path")
     self.search_entry = self.builder.get_object("FileNameEntry")
     self.search_entry.connect("activate", self._searchentry_callback)
     self.search_entry.connect("icon-press", self._searchentry_callback)
     self.completion = _gtk.EntryCompletion()
     self.completion.set_model(self.file_model)
     self.search_entry.set_completion(self.completion)
     pixbufcell = _gtk.CellRendererPixbuf()
     self.completion.pack_start(pixbufcell)
     self.completion.add_attribute(pixbufcell, 'pixbuf', 0)
     self.completion.add_attribute(pixbufcell, 'icon-name', 1)
     self.completion.set_text_column(3)
     self.pack_start(self.area, True, True, 0)
     self.area.show_all()
     self.bookmarks = self.builder.get_object("Bookmarks")
     self.bookmarks.connect("row-activated", self.bookmark_item_activated)
     bookmarks_column = self.builder.get_object("BookmarksColumn")
     bookmarks_column.set_title(_("Bookmarks"))
     self.bookmarks_model = self.builder.get_object("BookmarksStore")
     self.bookmarks_manager = bookmarks.BookmarksManager()
     self.bookmarks_manager.connect("update-bookmarks",
                                    self.update_bookmarks)
     self.load_bookmarks()
     self.mounts = self.builder.get_object("Mounts")
     mounts_column = self.builder.get_object("MountsColumn")
     mounts_column.set_title(_("Mounts"))
     self.mounts.connect("row-activated", self.mount_item_activated)
     self.mounts_model = self.mounts.get_model()
     self.volume_monitor = _gio.volume_monitor_get()
     self.volume_monitor.connect("mount-added", self.mount_update)
     self.volume_monitor.connect("mount-changed", self.mount_update)
     self.volume_monitor.connect("mount-removed", self.mount_update)
     self.load_mounts()
Exemplo n.º 17
0
	def __init__(self):
		_gtk.VBox.__init__(self)
		self.builder = _gtk.Builder()
		self.builder.add_from_file(_os.path.join(_os.environ["FILEMANAGER_PATH"], "widget.builder"))
		self.area = self.builder.get_object("Area")
		self.file_area = self.builder.get_object("FileArea")
		self.file_view = self.builder.get_object("FileView")
		self.file_view.connect("item-activated", self._item_activated)
		self.file_view.connect("button-press-event", self._handler_click)
		self.file_model = self.builder.get_object("FileModel")
		self.path_label = self.builder.get_object("Path")
		self.search_entry = self.builder.get_object("FileNameEntry")
		self.search_entry.connect("activate", self._searchentry_callback)
		self.search_entry.connect("icon-press", self._searchentry_callback)
		self.completion = _gtk.EntryCompletion()
		self.completion.set_model(self.file_model)
		self.search_entry.set_completion(self.completion)
		pixbufcell = _gtk.CellRendererPixbuf()
		self.completion.pack_start(pixbufcell)
		self.completion.add_attribute(pixbufcell, 'pixbuf', 0)
		self.completion.add_attribute(pixbufcell, 'icon-name', 1)
		self.completion.set_text_column(3)
		self.pack_start(self.area, True, True, 0)
		self.area.show_all()
		self.bookmarks = self.builder.get_object("Bookmarks")
		self.bookmarks.connect("row-activated", self.bookmark_item_activated)
		bookmarks_column = self.builder.get_object("BookmarksColumn")
		bookmarks_column.set_title(_("Bookmarks"))
		self.bookmarks_model = self.builder.get_object("BookmarksStore")
		self.bookmarks_manager = bookmarks.BookmarksManager()
		self.bookmarks_manager.connect("update-bookmarks", self.update_bookmarks)
		self.load_bookmarks()
		self.mounts = self.builder.get_object("Mounts")
		mounts_column = self.builder.get_object("MountsColumn")
		mounts_column.set_title(_("Mounts"))
		self.mounts.connect("row-activated", self.mount_item_activated)
		self.mounts_model = self.mounts.get_model()
		self.volume_monitor = _gio.volume_monitor_get()
		self.volume_monitor.connect("mount-added", self.mount_update)
		self.volume_monitor.connect("mount-changed", self.mount_update)
		self.volume_monitor.connect("mount-removed", self.mount_update)
		self.load_mounts()
Exemplo n.º 18
0
    def _refresh_copy_palette(self):
        palette = self._copy.get_palette()

        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)
            menu_item.destroy()

        clipboard_menu = ClipboardMenu(self._metadata)
        clipboard_menu.set_image(
            Icon(icon_name='toolbar-edit', icon_size=gtk.ICON_SIZE_MENU))
        clipboard_menu.connect('volume-error', self.__volume_error_cb)
        palette.menu.append(clipboard_menu)
        clipboard_menu.show()

        if self._metadata['mountpoint'] != '/':
            client = gconf.client_get_default()
            color = XoColor(client.get_string('/desktop/sugar/user/color'))
            journal_menu = VolumeMenu(self._metadata, _('Journal'), '/')
            journal_menu.set_image(
                Icon(icon_name='activity-journal',
                     xo_color=color,
                     icon_size=gtk.ICON_SIZE_MENU))
            journal_menu.connect('volume-error', self.__volume_error_cb)
            palette.menu.append(journal_menu)
            journal_menu.show()

        volume_monitor = gio.volume_monitor_get()
        icon_theme = gtk.icon_theme_get_default()
        for mount in volume_monitor.get_mounts():
            if self._metadata['mountpoint'] == mount.get_root().get_path():
                continue
            volume_menu = VolumeMenu(self._metadata, mount.get_name(),
                                     mount.get_root().get_path())
            for name in mount.get_icon().props.names:
                if icon_theme.has_icon(name):
                    volume_menu.set_image(
                        Icon(icon_name=name, icon_size=gtk.ICON_SIZE_MENU))
                    break
            volume_menu.connect('volume-error', self.__volume_error_cb)
            palette.menu.append(volume_menu)
            volume_menu.show()
Exemplo n.º 19
0
    def _refresh_copy_palette(self):
        palette = self._copy.get_palette()

        for menu_item in palette.menu.get_children():
            palette.menu.remove(menu_item)
            menu_item.destroy()

        clipboard_menu = ClipboardMenu(self._metadata)
        clipboard_menu.set_image(Icon(icon_name='toolbar-edit',
                                      icon_size=gtk.ICON_SIZE_MENU))
        clipboard_menu.connect('volume-error', self.__volume_error_cb)
        palette.menu.append(clipboard_menu)
        clipboard_menu.show()

        if self._metadata['mountpoint'] != '/':
            client = gconf.client_get_default()
            color = XoColor(client.get_string('/desktop/sugar/user/color'))
            journal_menu = VolumeMenu(self._metadata, _('Journal'), '/')
            journal_menu.set_image(Icon(icon_name='activity-journal',
                                        xo_color=color,
                                        icon_size=gtk.ICON_SIZE_MENU))
            journal_menu.connect('volume-error', self.__volume_error_cb)
            palette.menu.append(journal_menu)
            journal_menu.show()

        volume_monitor = gio.volume_monitor_get()
        icon_theme = gtk.icon_theme_get_default()
        for mount in volume_monitor.get_mounts():
            if self._metadata['mountpoint'] == mount.get_root().get_path():
                continue
            volume_menu = VolumeMenu(self._metadata, mount.get_name(),
                                     mount.get_root().get_path())
            for name in mount.get_icon().props.names:
                if icon_theme.has_icon(name):
                    volume_menu.set_image(Icon(icon_name=name,
                                               icon_size=gtk.ICON_SIZE_MENU))
                    break
            volume_menu.connect('volume-error', self.__volume_error_cb)
            palette.menu.append(volume_menu)
            volume_menu.show()
	def file_menu(self, widget, uri, menu):
		copy = gtk.MenuItem(_("Copy"))
		copy.connect("activate", self.copy_file, uri)
		copy.show()
		menu.append(copy)
		delete = gtk.MenuItem(_("Delete"))
		delete.connect("activate", self.delete_file, uri)
		delete.show()
		menu.append(delete)
		send_to = gtk.MenuItem(_("Send to"))
		send_to_menu = gtk.Menu()
		volume_monitor = gio.volume_monitor_get()
		for mount in volume_monitor.get_mounts():
			item = gtk.MenuItem(mount.get_name())
			item.show()
			item.connect("activate", self.send_file_to, uri, mount.get_root().get_path())
			send_to_menu.append(item)
		send_to.set_submenu(send_to_menu)
		send_to_menu.show()
		menu.append(send_to)
		send_to.show()
		return True
Exemplo n.º 21
0
    def __init__(self, metadata):
        gobject.GObject.__init__(self)

        self._metadata = metadata

        clipboard_menu = ClipboardMenu(self._metadata)
        clipboard_menu.set_image(Icon(icon_name='toolbar-edit',
                                      icon_size=gtk.ICON_SIZE_MENU))
        clipboard_menu.connect('volume-error', self.__volume_error_cb)
        self.append(clipboard_menu)
        clipboard_menu.show()

        if self._metadata['mountpoint'] != '/':
            client = gconf.client_get_default()
            color = XoColor(client.get_string('/desktop/sugar/user/color'))
            journal_menu = VolumeMenu(self._metadata, _('Journal'), '/')
            journal_menu.set_image(Icon(icon_name='activity-journal',
                                        xo_color=color,
                                        icon_size=gtk.ICON_SIZE_MENU))
            journal_menu.connect('volume-error', self.__volume_error_cb)
            self.append(journal_menu)
            journal_menu.show()

        volume_monitor = gio.volume_monitor_get()
        icon_theme = gtk.icon_theme_get_default()
        for mount in volume_monitor.get_mounts():
            if self._metadata['mountpoint'] == mount.get_root().get_path():
                continue
            volume_menu = VolumeMenu(self._metadata, mount.get_name(),
                                   mount.get_root().get_path())
            for name in mount.get_icon().props.names:
                if icon_theme.has_icon(name):
                    volume_menu.set_image(Icon(icon_name=name,
                                               icon_size=gtk.ICON_SIZE_MENU))
                    break
            volume_menu.connect('volume-error', self.__volume_error_cb)
            self.append(volume_menu)
            volume_menu.show()
Exemplo n.º 22
0
 def __init__(self):
     deskbar.interfaces.Module.__init__(self)
     self._locations = {}
     self._volume_monitor = gio.volume_monitor_get()
Exemplo n.º 23
0
 def __init__(self):
     conduit.platform.VolumeMonitor.__init__(self)
     self._vm = gio.volume_monitor_get()
     self._vm.connect("mount-added", self._mounted_cb)
     self._vm.connect("mount-removed", self._unmounted_cb)
Exemplo n.º 24
0
def test_monitor_information():
    monitor = gio.volume_monitor_get()
    assert isinstance(monitor.get_connected_drives(), list)
Exemplo n.º 25
0
 def __destroy_cb(self, widget):
     volume_monitor = gio.volume_monitor_get()
     volume_monitor.disconnect(self._mount_added_hid)
     volume_monitor.disconnect(self._mount_removed_hid)
Exemplo n.º 26
0
    def _setup_monitor(self):
        # Disconnect any previously registered signal
        # handlers
        if self._fm:
            self._fm.disconnect(self._fmID)
            self._fm = None

        useVolMonitor = False

        # We always compare against masterKey to validate
        # an rsync backup device.
        self._masterKey = self.smfInst.get_target_key()
        self._baseTargetDir = None
        online = False

        self._masterTargetDir = self.smfInst.get_target_dir()

        if self._validate_rsync_target(self._masterTargetDir) == True:
            self._baseTargetDir = self._masterTargetDir
            online = True

        if self._vm == None:
            self._vm = gio.volume_monitor_get()

        # If located, see if it's also managed by the volume monitor.
        # Or just try to find it otherwise.
        mounts = self._vm.get_mounts()
        for mount in mounts:
            root = mount.get_root()
            path = root.get_path()
            if self._baseTargetDir != None and \
                path == self._baseTargetDir:
                # Means the directory we found is gio monitored,
                # so just monitor it using gio.VolumeMonitor.
                useVolMonitor = True
                break
            elif self._validate_rsync_target(path) == True:
                # Found it but not where we expected it to be so override
                # the target path defined by SMF for now.
                useVolMonitor = True
                self._baseTargetDir = path
                online = True
                break

        if self._baseTargetDir == None:
            # Means we didn't find it, and we don't know where to expect
            # it either - via a hotpluggable device or other nfs/zfs etc.
            # We need to hedge our bets and monitor for both.
            self._setup_file_monitor(self._masterTargetDir)
            self._setup_volume_monitor()
        else:
            # Found it
            if useVolMonitor == True:
                # Looks like a removable device. Use gio.VolumeMonitor
                # as the preferred monitoring mechanism.
                self._setup_volume_monitor()
            else:
                # Found it on a static mount point like a zfs or nfs
                # mount point.
                # Can't use gio.VolumeMonitor so use a gio.File monitor
                # instead.
                self._setup_file_monitor(self._masterTargetDir)

        # Finally, update the UI menu state
        self._lock.acquire()
        self._targetDirAvail = online
        self._update_menu_state()
        self._lock.release()
Exemplo n.º 27
0
	def get_items(self):
		vm = gio.volume_monitor_get()
		# get_mounts gets all mounted removable media
		return (Volume(v) for v in vm.get_mounts())
Exemplo n.º 28
0
 def is_valid(self):
     vm = gio.volume_monitor_get()
     return any(self.volume == v for v in vm.get_mounts())
Exemplo n.º 29
0
    def create_places_submenu(self, parent_menu):
        item = self.append_menu_item(parent_menu, _("Places"), "folder", None)

        menu = gtk.Menu()
        item.set_submenu(menu)

        user_path = os.path.expanduser("~/")

        home_item = self.append_menu_item(menu, _("Home Folder"), "user-home", _("Open your personal folder"))
        home_item.connect("activate", self.open_folder_cb, "file://%s" % user_path)

        # Add Desktop
        desktop_path = glib.get_user_special_dir(glib.USER_DIRECTORY_DESKTOP)
        if desktop_path != user_path:
            label = glib.filename_display_basename(desktop_path)
            desktop_item = self.append_menu_item(menu, label, "user-desktop", _("Open the contents of your desktop in a folder"))
            desktop_item.connect("activate", self.open_folder_cb, "file://%s" % desktop_path)

        """ Bookmarks """
        self.places_menu = menu
        self.bookmarks_items = []
        self.append_bookmarks()

        # Monitor bookmarks file for changes
        bookmarks_file = os.path.expanduser("~/.gtk-bookmarks")
        self.__bookmarks_monitor = gio.File(bookmarks_file).monitor_file()  # keep a reference to avoid getting it garbage collected
        def bookmarks_changed_cb(monitor, file, other_file, event):
            if event == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
                with self.__rebuild_lock:
                    self.append_bookmarks()
                    # Refresh menu to re-initialize the widget
                    self.places_menu.show_all()
        self.__bookmarks_monitor.connect("changed", bookmarks_changed_cb)

        menu.append(gtk.SeparatorMenuItem())

        """ Devices """
        added = False
        added |= self.append_awn_desktop(menu, "nautilus-computer")
        added |= self.append_awn_desktop(menu, "nautilus-cd-burner")

        # Set up volumes and mounts monitor
        self.__volumes_mounts_monitor = gio.volume_monitor_get()

        self.__volumes_index = len(self.places_menu) - len(self.bookmarks_items)
        self.volume_items = []
        self.append_volumes()
        # TODO if added is False and no volumes, then their are two separators

        if added:
            menu.append(gtk.SeparatorMenuItem())

        added = False
        added |= self.append_awn_desktop(menu, "network-scheme")

        self.__mounts_index = len(self.places_menu) - len(self.volume_items) - len(self.bookmarks_items)
        self.mount_items = []
        self.append_mounts()
        # TODO if added is False and no mounts, then there are two separators

        # Connect signals after having initialized volumes and mounts
        for signal in ("volume-added", "volume-changed", "volume-removed", "mount-added", "mount-changed", "mount-removed"):
            self.__volumes_mounts_monitor.connect(signal, self.refresh_volumes_mounts_cb)

        ncs_exists = os.path.exists(commands.getoutput("which nautilus-connect-server"))
        if ncs_exists:
            connect_item = self.append_menu_item(menu, _("Connect to Server..."), "applications-internet", _("Connect to a remote computer or shared disk"))
            connect_item.connect("activate", lambda w: subprocess.Popen("nautilus-connect-server"))
        added |= ncs_exists

        if added:
            menu.append(gtk.SeparatorMenuItem())

        self.append_awn_desktop(menu, "mate-search-tool")

        """ Recent Documents """
        self.create_documents_submenu(menu)
    # use nautilus translations
    # TODO: custom translations with new strings
    gettext.bindtextdomain("nautilus", "/usr/share/locale")
    gettext.bind_textdomain_codeset("nautilus", "UTF-8")
    gettext.textdomain("nautilus")
    
    
    app = gnome.program_init ("secure-nautilus-autorun", __version__,
                               gnome.libgnome_module_info_get(), sys.argv, []);


    if len(sys.argv)!=2:
        sys.exit(0)

    # instantiate monitor so we get the "unmounted" signal properly
    monitor = gio.volume_monitor_get()
    if not monitor:
        sys.exit(-1)
    
    file = gio.File(sys.argv[1])
    if not file:
        sys.exit(-2)

    mount = file.find_enclosing_mount()
    if not mount:
        sys.exit(-3)
    
    
    present_autorun_for_software_dialog (mount)
    
Exemplo n.º 31
0
 def __init__(self):
     deskbar.interfaces.Module.__init__(self)
     self._locations = {}
     self._volume_monitor = gio.volume_monitor_get()
Exemplo n.º 32
0
 def __init__(self):
     gobject.GObject.__init__(self)
     self.vm = gio.volume_monitor_get()
     self.vm.connect("mount-added", self.mount_added)
     self.vm.connect("mount-removed", self.mount_removed)
Exemplo n.º 33
0
    def _setup_monitor(self):
        # Disconnect any previously registered signal
        # handlers
        if self._fm:
            self._fm.disconnect(self._fmID)
            self._fm = None

        useVolMonitor = False        

        # We always compare against masterKey to validate
        # an rsync backup device.
        self._masterKey = self.smfInst.get_target_key()
        self._baseTargetDir = None
        online = False

        self._masterTargetDir = self.smfInst.get_target_dir()

        if self._validate_rsync_target(self._masterTargetDir) == True:
            self._baseTargetDir = self._masterTargetDir
            online = True

        if self._vm == None:
            self._vm = gio.volume_monitor_get()

        # If located, see if it's also managed by the volume monitor.
        # Or just try to find it otherwise.
        mounts = self._vm.get_mounts()
        for mount in mounts:
            root = mount.get_root()
            path = root.get_path()
            if self._baseTargetDir != None and \
                path == self._baseTargetDir:
                # Means the directory we found is gio monitored,
                # so just monitor it using gio.VolumeMonitor.
                useVolMonitor = True
                break
            elif self._validate_rsync_target(path) == True:
                # Found it but not where we expected it to be so override
                # the target path defined by SMF for now.
                useVolMonitor = True
                self._baseTargetDir = path
                online = True
                break

        if self._baseTargetDir == None:
            # Means we didn't find it, and we don't know where to expect
            # it either - via a hotpluggable device or other nfs/zfs etc.
            # We need to hedge our bets and monitor for both.
            self._setup_file_monitor(self._masterTargetDir)
            self._setup_volume_monitor()
        else:
            # Found it
            if useVolMonitor == True:
                # Looks like a removable device. Use gio.VolumeMonitor
                # as the preferred monitoring mechanism.
                self._setup_volume_monitor()
            else:
                # Found it on a static mount point like a zfs or nfs
                # mount point.
                # Can't use gio.VolumeMonitor so use a gio.File monitor
                # instead.
                self._setup_file_monitor(self._masterTargetDir)

        # Finally, update the UI menu state
        self._lock.acquire()
        self._targetDirAvail = online
        self._update_menu_state()
        self._lock.release()
Exemplo n.º 34
0
 def setUp(self):
     self.monitor = gio.volume_monitor_get()
Exemplo n.º 35
0
Arquivo: io.py Projeto: eephyne/picty
 def __init__(self):
     gobject.GObject.__init__(self)
     self.vm=gio.volume_monitor_get()
     self.vm.connect("mount-added",self.mount_added)
     self.vm.connect("mount-removed",self.mount_removed)
Exemplo n.º 36
0
    def MountRemoved(self, volume_monitor, mount):
        print('mount {} was removed'.format(mount.get_name()))
        #PrintMountInfo( mount )


gobject.threads_init()

if __name__ == '__main__':
    #Test
    f = gio.File('smb://homepc/cartoons')
    print('scheme of {} is {}'.format(f.get_parse_name(), f.get_uri_scheme()))
    print('f.has_uri_scheme( smb )={}'.format(f.has_uri_scheme('smb')))
    #import sys; sys.exit(1)

    monitor = gio.volume_monitor_get()
    h = Handler()
    monitor.connect("mount-added", h.MountAdded)
    monitor.connect("mount-removed", h.MountRemoved)

    print('--------------')
    print('Drives:')
    ds = monitor.get_connected_drives()
    for d in ds:
        pprint.pprint(d)

    print('--------------')
    print('Volumes:')
    vs = monitor.get_volumes()
    for v in vs:
        pprint.pprint(v)
Exemplo n.º 37
0
 def __destroy_cb(self, widget):
     volume_monitor = gio.volume_monitor_get()
     volume_monitor.disconnect(self._mount_added_hid)
     volume_monitor.disconnect(self._mount_removed_hid)
Exemplo n.º 38
0
 def GetMounts():
     monitor = gio.volume_monitor_get()
     mos = monitor.get_mounts()
     return [
         m for m in mos if (not MountDetector.IsAudioCd(m) or m.can_eject())
     ]
Exemplo n.º 39
0
  def __init__(self, uid, panel_id):
    #AWN Applet Configuration
    awn.Applet.__init__(self, 'file-browser-launcher', uid, panel_id)

    self.icon_box = awn.IconBox(self)
    self.add(self.icon_box)
    self.icon = awn.ThemedIcon()
    self.icon.set_tooltip_text(_("File Browser Launcher"))
    self.icon.set_size(self.get_size())
    self.dialog = awn.Dialog(self.icon, self)

    #AwnConfigClient instance
    self.client = awn.config_get_default_for_applet(self)

    #Get the default icon theme
    self.theme = gtk.icon_theme_get_default()
    self.icons[24] = {}
    try:
      self.icons[24]['folder'] = self.theme.load_icon('folder', 24, 0)
    except:
      self.icons[24]['folder'] = None

    #Docklet...
    self.mode = self.client.get_int(group, 'mode')
    self.client.notify_add(group, 'mode', self.update_mode)

    if self.mode == 2:
      self.docklet_visible = True
      self.update_docklet(False)

    else:
      self.icon_box.add(self.icon)

    #Set the icon
    self.icon.set_info_simple('file-browser-launcher', uid, 'folder')

    if gio:
      #This part (and other progress overlay code) adapted from
      #mhr3's 'Dropper' applet
      #Set the progress overlay
      self.timer_overlay = awn.OverlayProgressCircle()
      self.timer_overlay.props.active = False
      self.timer_overlay.props.apply_effects = False
      self.icon.add_overlay(self.timer_overlay)
    else:
      #Read fstab for mounting info
      #(It it assumed that fstab won't change after the applet is started)
      self.fstab2 = open('/etc/fstab', 'r')
      self.fstab = self.fstab2.read().split('\n')
      self.fstab2.close()

    #Check if nautilus-connect-server is installed
    if os.path.exists('/usr/bin/nautilus-connect-server') or os.path.exists \
      ('/usr/local/bin/nautilus-connect-server'):
      self.nautilus_connect_server = True
    else:
      self.nautilus_connect_server = False

    if os.path.exists('/usr/share/applications/nautilus-computer.desktop') or \
      os.path.exists('/usr/local/share/applications/nautilus-computer.desktop'):
      self.nautilus_computer = True
    else:
      self.nautilus_computer = False

    def trash_count_cb(*args):
      if self.show_trash:
        if gio:
          self.do_gio_places()
        else:
          self.add_places()

    self.trash = vfs.Trash.get_default()
    self.trash.connect('file-count-changed', trash_count_cb)

    #Make the dialog, will only be shown when approiate
    #Make all the things needed for a treeview for the homefolder, root dir, bookmarks, and mounted drives
    self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, gtk.gdk.Pixbuf, str, int)

    #Renderers
    renderer0 = gtk.CellRendererPixbuf()
    renderer1 = gtk.CellRendererText()
    self.eject_render = gtk.CellRendererPixbuf()
    self.eject_render.set_property("mode", gtk.CELL_RENDERER_MODE_ACTIVATABLE)

    #Add renderers to column
    column = gtk.TreeViewColumn('0')
    column.pack_start(renderer0, False)
    column.add_attribute(renderer0, 'pixbuf', 0)
    column.pack_start(renderer1, True)
    column.add_attribute(renderer1, 'markup', 1)
    column.pack_start(self.eject_render, False)
    column.add_attribute(self.eject_render, 'pixbuf', 2)

    #TreeView
    self.treeview = gtk.TreeView(self.liststore)
    self.treeview.set_hover_selection(True)
    self.treeview.set_headers_visible(False)
    self.treeview.append_column(column)
    self.treeview.set_no_show_all(True)
    self.treeview.connect('button-press-event', self.treeview_clicked)

    self.vbox = gtk.VBox()
    self.vbox.pack_start(self.treeview)

    if gio:
      self.monitor = gio.volume_monitor_get()
      for signal in ('volume-added', 'volume-changed', 'volume-removed', 'mount-added',
        'mount-changed', 'mount-removed'):
        self.monitor.connect(signal, self.do_gio_places)

      for key in ('show_computer', 'show_home', 'show_filesystem', 'show_local', 'show_network',
        'show_connect', 'show_trash', 'show_bookmarks'):
        self.client.notify_add(group, key, self.do_gio_places)

      self.do_gio_places()

      #(From YAMA by Onox)
      #Monitor bookmarks file for changes
      bookmarks_file = os.path.expanduser("~/.gtk-bookmarks")

      #keep a reference to avoid getting it garbage collected
      self.__bookmarks_monitor = gio.File(bookmarks_file).monitor_file()

      def bookmarks_changed_cb(monitor, file, other_file, event):
        if event in (gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT, gio.FILE_MONITOR_EVENT_CREATED,
          gio.FILE_MONITOR_EVENT_DELETED):
          #Refresh menu to re-initialize the widget
          self.do_gio_places()

      self.__bookmarks_monitor.connect("changed", bookmarks_changed_cb)

    #Entry widget for displaying the path to open
    self.entry = gtk.Entry()
    self.entry.set_text(os.environ['HOME'])
    self.entry.connect('key-release-event', self.detect_enter)
    self.entry.show()

    #Open button to run the file browser
    self.enter = gtk.Button(stock=gtk.STOCK_OPEN)
    self.enter.connect('clicked', self.launch_fb)
    self.enter.show()

    #HBox to put the two together
    entry_hbox = gtk.HBox()
    entry_hbox.pack_start(self.entry)
    entry_hbox.pack_start(self.enter, False)

    #And add the HBox to the vbox and add the vbox to the dialog
    self.vbox.pack_end(entry_hbox)
    self.dialog.add(self.vbox)

    #Connect to signals
    self.icon.connect('clicked', self.icon_clicked)
    self.icon.connect('middle-clicked', self.icon_clicked)
    self.icon.connect('context-menu-popup', self.show_context_menu)
    self.connect('size-changed', self.size_changed)
    self.dialog.connect('focus-out-event', self.dialog_focus_out)
    self.theme.connect('changed', self.icon_theme_changed)

    if gio:
      #Allow the user to drag&drop a file/folder onto the applet. After
      #a short delay, show the dialog, and allow the file/folder to be dropped
      #on any place in the TreeView (other than root, Connect to Server..., and
      #maybe unmounted places). The move the file/folder and (if successful)
      #open the place in the file browser
      #The Applet icon - just open the dialog after a short delay
      self.icon.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION, \
        [("text/uri-list", 0, 0)], \
        gtk.gdk.ACTION_COPY)
      self.icon.connect('drag-data-received', self.applet_drag_data_received)
      self.icon.connect('drag-motion', self.applet_drag_motion)
      self.icon.connect('drag-leave', self.applet_drag_leave)

      #The TreeView - drop the file to move it to the folder
      self.treeview.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION, \
        [("text/uri-list", 0, 0)], \
        gtk.gdk.ACTION_MOVE)
      self.treeview.connect('drag-data-received', self.treeview_drag_data_received)
      self.treeview.connect('drag-motion', self.treeview_drag_motion)
      self.treeview.connect('drag-leave', self.treeview_drag_leave)

    elif self.mode == 2:
      self.add_places()
Exemplo n.º 40
0
 def __init__(self, MountAddedCallback=None, MountRemovedCallback=None):
     monitor = gio.volume_monitor_get()
     self._MountAddedCallback = MountAddedCallback
     self._MountRemovedCallback = MountRemovedCallback
     monitor.connect("mount-added", self.MountAdded)
     monitor.connect("mount-removed", self.MountRemoved)
Exemplo n.º 41
0
	def is_valid(self):
		vm = gio.volume_monitor_get()
		return any(self.volume == v for v in vm.get_mounts())
Exemplo n.º 42
0
 def get_items(self):
     vm = gio.volume_monitor_get()
     # get_mounts gets all mounted removable media
     return (Volume(v) for v in vm.get_mounts())
Exemplo n.º 43
0
    def create_places_submenu(self, parent_menu):
        item = self.append_menu_item(parent_menu, _("Places"), "folder", None)

        menu = gtk.Menu()
        item.set_submenu(menu)

        user_path = os.path.expanduser("~/")

        home_item = self.append_menu_item(menu, _("Home Folder"), "user-home", _("Open your personal folder"))
        home_item.connect("activate", self.open_folder_cb, "file://%s" % user_path)

        # Add Desktop
        desktop_path = glib.get_user_special_dir(glib.USER_DIRECTORY_DESKTOP)
        if desktop_path != user_path:
            label = glib.filename_display_basename(desktop_path)
            desktop_item = self.append_menu_item(menu, label, "user-desktop", _("Open the contents of your desktop in a folder"))
            desktop_item.connect("activate", self.open_folder_cb, "file://%s" % desktop_path)

        """ Bookmarks """
        self.places_menu = menu
        self.bookmarks_items = []
        self.append_bookmarks()

        # Monitor bookmarks file for changes
        bookmarks_file = os.path.expanduser("~/.gtk-bookmarks")
        self.__bookmarks_monitor = gio.File(bookmarks_file).monitor_file()  # keep a reference to avoid getting it garbage collected
        def bookmarks_changed_cb(monitor, file, other_file, event):
            if event == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
                with self.__rebuild_lock:
                    self.append_bookmarks()
                    # Refresh menu to re-initialize the widget
                    self.places_menu.show_all()
        self.__bookmarks_monitor.connect("changed", bookmarks_changed_cb)

        menu.append(gtk.SeparatorMenuItem())

        """ Devices """
        added = False
        added |= self.append_awn_desktop(menu, "nautilus-computer")
        added |= self.append_awn_desktop(menu, "nautilus-cd-burner")

        # Set up volumes and mounts monitor
        self.__volumes_mounts_monitor = gio.volume_monitor_get()

        self.__volumes_index = len(self.places_menu) - len(self.bookmarks_items)
        self.volume_items = []
        self.append_volumes()
        # TODO if added is False and no volumes, then their are two separators

        if added:
            menu.append(gtk.SeparatorMenuItem())

        added = False
        added |= self.append_awn_desktop(menu, "network-scheme")

        self.__mounts_index = len(self.places_menu) - len(self.volume_items) - len(self.bookmarks_items)
        self.mount_items = []
        self.append_mounts()
        # TODO if added is False and no mounts, then there are two separators

        # Connect signals after having initialized volumes and mounts
        for signal in ("volume-added", "volume-changed", "volume-removed", "mount-added", "mount-changed", "mount-removed"):
            self.__volumes_mounts_monitor.connect(signal, self.refresh_volumes_mounts_cb)

        ncs_exists = os.path.exists(commands.getoutput("which nautilus-connect-server"))
        if ncs_exists:
            connect_item = self.append_menu_item(menu, _("Connect to Server..."), "applications-internet", _("Connect to a remote computer or shared disk"))
            connect_item.connect("activate", lambda w: subprocess.Popen("nautilus-connect-server"))
        added |= ncs_exists

        if added:
            menu.append(gtk.SeparatorMenuItem())

        self.append_awn_desktop(menu, "gnome-search-tool")

        """ Recent Documents """
        self.create_documents_submenu(menu)
Exemplo n.º 44
0
 def setUp(self):
     self.monitor = gio.volume_monitor_get()