class EpiphanyHandler(deskbar.interfaces.Module): def __init__(self, watched_file, callback): deskbar.interfaces.Module.__init__(self) self.watched_file = watched_file self.watch_callback = callback def initialize(self): global favicon_cache if favicon_cache == None: favicon_cache = EpiphanyFaviconCacheParser().get_cache() if not hasattr(self, 'watcher'): self.watcher = FileWatcher() self.watcher.connect('changed', lambda watcher, f: self.watch_callback()) self.watcher.add(self.watched_file) def stop(self): if hasattr(self, 'watcher'): self.watcher.remove(self.watched_file) del self.watcher
class FileFolderHandler(deskbar.interfaces.Module): INFOS = {'icon': deskbar.core.Utils.load_icon(gtk.STOCK_OPEN), "name": _("Files, Folders and Places"), "description": _("View your files, folders, bookmarks, drives, network places by name"), "version": VERSION} def __init__(self): deskbar.interfaces.Module.__init__(self) self._locations = {} self._volume_monitor = gio.volume_monitor_get() def initialize(self): # Gtk Bookmarks -- if not hasattr(self, 'watcher'): self.watcher = FileWatcher() self.watcher.connect('changed', lambda watcher, f: self._scan_bookmarks_files()) self.watcher.add(GTK_BOOKMARKS_FILE) self._scan_bookmarks_files() def stop(self): self.watcher.remove(GTK_BOOKMARKS_FILE) def query(self, query): result = [] result += self._query_filefolder(query, False) result += self._query_filefolder(query, True) # Gtk Bookmarks lquery = query.lower() for bmk, (name, loc) in self._locations.items(): if bmk.startswith(lquery): gtk_bookmark_match = GtkBookmarkMatch(name, loc, priority=self.get_priority()) result.append(gtk_bookmark_match) # Mounts for mount in self._volume_monitor.get_mounts(): if not mount.get_name().lower().startswith(lquery): continue uri = mount.get_root() if uri != None: icon = "drive-harddisk" vol_match = VolumeMatch (mount.get_name(), uri.get_path(), icon, priority=self.get_priority()) result.append (vol_match) self._emit_query_ready(query, result) def _query_filefolder(self, query, is_file): completions, prefix, relative = filesystem_possible_completions(query, is_file) if is_file: return [FileMatch(join(prefix, basename(completion)), "file://"+completion, priority=self.get_priority()) for completion in completions] else: return [FolderMatch(join(prefix, basename(completion)), "file://"+completion, priority=self.get_priority()) for completion in completions] def _scan_bookmarks_files(self): if not isfile(GTK_BOOKMARKS_FILE): return for line in file(GTK_BOOKMARKS_FILE): line = line.strip() # First column is url, second the label cols = line.split(" ", 1) try: uri = urllib.unquote(cols[0]) gfile = gio.File(uri=uri) # We can only check if file exists for local files if gfile.get_uri_scheme() == "file": file_exists = gfile.query_exists() else: file_exists = True if file_exists: name = gfile.get_basename() if len(cols) > 1: display_name = cols[1] else: display_name = name self._locations[name.lower()] = (display_name, gfile.get_uri()) self._locations[display_name.lower()] = (display_name, gfile.get_uri()) except Exception, msg: LOGGER.exception(msg)
class FileFolderHandler(deskbar.interfaces.Module): INFOS = { 'icon': deskbar.core.Utils.load_icon(gtk.STOCK_OPEN), "name": _("Files, Folders and Places"), "description": _("View your files, folders, bookmarks, drives, network places by name" ), "version": VERSION } def __init__(self): deskbar.interfaces.Module.__init__(self) self._locations = {} self._volume_monitor = gio.volume_monitor_get() def initialize(self): # Gtk Bookmarks -- if not hasattr(self, 'watcher'): self.watcher = FileWatcher() self.watcher.connect( 'changed', lambda watcher, f: self._scan_bookmarks_files()) self.watcher.add(GTK_BOOKMARKS_FILE) self._scan_bookmarks_files() def stop(self): self.watcher.remove(GTK_BOOKMARKS_FILE) def query(self, query): result = [] result += self._query_filefolder(query, False) result += self._query_filefolder(query, True) # Gtk Bookmarks lquery = query.lower() for bmk, (name, loc) in self._locations.items(): if bmk.startswith(lquery): gtk_bookmark_match = GtkBookmarkMatch( name, loc, priority=self.get_priority()) result.append(gtk_bookmark_match) # Mounts for mount in self._volume_monitor.get_mounts(): if not mount.get_name().lower().startswith(lquery): continue uri = mount.get_root() if uri != None: icon = "drive-harddisk" vol_match = VolumeMatch(mount.get_name(), uri.get_path(), icon, priority=self.get_priority()) result.append(vol_match) self._emit_query_ready(query, result) def _query_filefolder(self, query, is_file): completions, prefix, relative = filesystem_possible_completions( query, is_file) if is_file: return [ FileMatch(join(prefix, basename(completion)), "file://" + completion, priority=self.get_priority()) for completion in completions ] else: return [ FolderMatch(join(prefix, basename(completion)), "file://" + completion, priority=self.get_priority()) for completion in completions ] def _scan_bookmarks_files(self): if not isfile(GTK_BOOKMARKS_FILE): return for line in file(GTK_BOOKMARKS_FILE): line = line.strip() # First column is url, second the label cols = line.split(" ", 1) try: uri = urllib.unquote(cols[0]) gfile = gio.File(uri=uri) # We can only check if file exists for local files if gfile.get_uri_scheme() == "file": file_exists = gfile.query_exists() else: file_exists = True if file_exists: name = gfile.get_basename() if len(cols) > 1: display_name = cols[1] else: display_name = name self._locations[name.lower()] = (display_name, gfile.get_uri()) self._locations[display_name.lower()] = (display_name, gfile.get_uri()) except Exception, msg: LOGGER.exception(msg)