Пример #1
0
    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()
Пример #2
0
 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)
Пример #3
0
    def initialize(self):
        if not hasattr(self, 'watcher'):
            self.watcher = FileWatcher()
            self.watcher.connect('changed',
                                 lambda watcher, f: self._parse_bookmarks())

        # We do some gym to get the effectively parsed files
        parsed_file = self._parse_bookmarks()
        if parsed_file != None:
            self.watcher.add(parsed_file)
Пример #4
0
 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()
Пример #5
0
 def initialize(self):
     if not hasattr(self, 'watcher'):
         self.watcher = FileWatcher()
         self.watcher.connect('changed', lambda watcher, f: self._parse_bookmarks())
     
     # We do some gym to get the effectively parsed files
     parsed_file = self._parse_bookmarks()
     if parsed_file != None:
         self.watcher.add(parsed_file)
Пример #6
0
 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)
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
class MozillaBookmarksHandler(deskbar.interfaces.Module):
    
    INFOS = {'icon': deskbar.core.Utils.load_icon("stock_bookmark"),
             "name": _("Web Bookmarks (Mozilla)"),
             "description": _("Open your web bookmarks by name"),
             "version": VERSION}
    
    def __init__(self):
        deskbar.interfaces.Module.__init__(self)
        self._bookmarks = None
    
    def initialize(self):
        if not hasattr(self, 'watcher'):
            self.watcher = FileWatcher()
            self.watcher.connect('changed', lambda watcher, f: self._parse_bookmarks())
        
        # We do some gym to get the effectively parsed files
        parsed_file = self._parse_bookmarks()
        if parsed_file != None:
            self.watcher.add(parsed_file)
        
    def _parse_bookmarks(self):
        self._bookmarks, parsed_file, self._shortcuts_to_smart_bookmarks_map = MozillaBookmarksParser(self).get_indexer()
        return parsed_file
    
    def stop(self):
        self.watcher.remove_all()
        
    def query(self, query):
        # First, check the smart bookmarks, or "keywords", where
        # "wp Foo" takes you to the wikipedia entry for Foo.
        matches = self.query_smart_bookmarks(query, deskbar.DEFAULT_RESULTS_PER_HANDLER)
        if matches == None:
            # If none of the smart bookmarks matched as a prefix,
            # then we'll just look up all bookmarks.
            matches = self._bookmarks.look_up(query)[:deskbar.DEFAULT_RESULTS_PER_HANDLER]
        self.set_priority_for_matches( matches )
        self._emit_query_ready(query, matches )
    
    def query_smart_bookmarks(self, query, max):
        # if one of the smart bookmarks' shortcuts matches as a prefix,
        # then only return that bookmark
        x = query.find(" ")
        if x != -1:
            prefix = query[:x]
            try:
                b = self._shortcuts_to_smart_bookmarks_map[prefix]
                text = query[x+1:]
                return [BrowserSmartMatch(b.get_name(), b.url, prefix, b, pixbuf=b.get_icon())]
            except KeyError:
                # Probably from the b = ... line.  Getting here
                # means that there is no such shortcut.
                pass
        return None
    
    @staticmethod
    def has_requirements():
        if is_preferred_browser("mozilla"):
            return True
        elif is_preferred_browser("firefox") or is_preferred_browser("iceweasel"):
            if MozillaBookmarksHandler.has_firefox_version():
                return True
            
            MozillaBookmarksHandler.INSTRUCTIONS = \
                _("Firefox version must be at least %s and less than %s") % (MIN_FF_VERSION_STRING, MAX_FF_VERSION_STRING)
            return False
        else:
            MozillaBookmarksHandler.INSTRUCTIONS = _("Mozilla/Firefox is not your preferred browser.")
            return False
        
    @staticmethod
    def has_firefox_version():
        version = get_firefox_version()
        if version != None:
            return (version >= MIN_FF_VERSION and version < MAX_FF_VERSION)
        return False
Пример #12
0
class MozillaBookmarksHandler(deskbar.interfaces.Module):

    INFOS = {
        'icon': deskbar.core.Utils.load_icon("stock_bookmark"),
        "name": _("Web Bookmarks (Mozilla)"),
        "description": _("Open your web bookmarks by name"),
        "version": VERSION
    }

    def __init__(self):
        deskbar.interfaces.Module.__init__(self)
        self._bookmarks = None

    def initialize(self):
        if not hasattr(self, 'watcher'):
            self.watcher = FileWatcher()
            self.watcher.connect('changed',
                                 lambda watcher, f: self._parse_bookmarks())

        # We do some gym to get the effectively parsed files
        parsed_file = self._parse_bookmarks()
        if parsed_file != None:
            self.watcher.add(parsed_file)

    def _parse_bookmarks(self):
        self._bookmarks, parsed_file, self._shortcuts_to_smart_bookmarks_map = MozillaBookmarksParser(
            self).get_indexer()
        return parsed_file

    def stop(self):
        self.watcher.remove_all()

    def query(self, query):
        # First, check the smart bookmarks, or "keywords", where
        # "wp Foo" takes you to the wikipedia entry for Foo.
        matches = self.query_smart_bookmarks(
            query, deskbar.DEFAULT_RESULTS_PER_HANDLER)
        if matches == None:
            # If none of the smart bookmarks matched as a prefix,
            # then we'll just look up all bookmarks.
            matches = self._bookmarks.look_up(
                query)[:deskbar.DEFAULT_RESULTS_PER_HANDLER]
        self.set_priority_for_matches(matches)
        self._emit_query_ready(query, matches)

    def query_smart_bookmarks(self, query, max):
        # if one of the smart bookmarks' shortcuts matches as a prefix,
        # then only return that bookmark
        x = query.find(" ")
        if x != -1:
            prefix = query[:x]
            try:
                b = self._shortcuts_to_smart_bookmarks_map[prefix]
                text = query[x + 1:]
                return [
                    BrowserSmartMatch(b.get_name(),
                                      b.url,
                                      prefix,
                                      b,
                                      pixbuf=b.get_icon())
                ]
            except KeyError:
                # Probably from the b = ... line.  Getting here
                # means that there is no such shortcut.
                pass
        return None

    @staticmethod
    def has_requirements():
        if is_preferred_browser("mozilla"):
            return True
        elif is_preferred_browser("firefox") or is_preferred_browser(
                "iceweasel"):
            if MozillaBookmarksHandler.has_firefox_version():
                return True

            MozillaBookmarksHandler.INSTRUCTIONS = \
                _("Firefox version must be at least %s and less than %s") % (MIN_FF_VERSION_STRING, MAX_FF_VERSION_STRING)
            return False
        else:
            MozillaBookmarksHandler.INSTRUCTIONS = _(
                "Mozilla/Firefox is not your preferred browser.")
            return False

    @staticmethod
    def has_firefox_version():
        version = get_firefox_version()
        if version != None:
            return (version >= MIN_FF_VERSION and version < MAX_FF_VERSION)
        return False