class MozillaSearchHandler(deskbar.interfaces.Module): INFOS = {'icon': deskbar.core.Utils.load_icon("web-search.png"), "name": _("Web Searches (Mozilla)"), "description": _("Search the web via your browser's search settings"), "version": VERSION} def __init__(self): deskbar.interfaces.Module.__init__(self) self._smart_bookmarks = None def initialize(self): smart_dirs = None if USING_FIREFOX: smart_dirs = [ get_firefox_home_file("searchplugins"), get_firefox_home_file("search"), expanduser("~/.mozilla/searchplugins"), "/usr/local/lib/firefox/searchplugins", "/usr/lib/mozilla-firefox/searchplugins", "/usr/local/lib/mozilla-firefox/searchplugins", "/usr/lib/iceweasel/searchplugins"] + \ glob.glob("/usr/lib*/firefox*/searchplugins") else: smart_dirs = [ get_mozilla_home_file("search"), expanduser("~/.mozilla/searchplugins"), "/usr/lib/mozilla/searchplugins", "/usr/local/lib/mozilla/searchplugins"] if not hasattr(self, 'watcher'): self.watcher = DirWatcher() self.watcher.connect('changed', lambda watcher, f: self._parse_search_engines(smart_dirs)) self.watcher.add(smart_dirs) self._parse_search_engines(smart_dirs) def _parse_search_engines(self, smart_dirs): self._smart_bookmarks = MozillaSmartBookmarksDirParser(smart_dirs).get_smart_bookmarks() self.set_priority_for_matches(self._smart_bookmarks) def stop(self): self.watcher.remove_all() def query(self, query): self.set_priority_for_matches (self._smart_bookmarks) if SHOW_ONLY_PRIMARY and PRIMARY_SEARCH_ENGINE != None: for s in self._smart_bookmarks: if s.get_name() == PRIMARY_SEARCH_ENGINE: self._emit_query_ready(query, [s] ) return self._emit_query_ready(query, self._smart_bookmarks ) else: self._emit_query_ready(query, self._smart_bookmarks ) def has_config(self): return True def show_config(self, parent): _on_handler_preferences(parent) @staticmethod def has_requirements(): if is_preferred_browser("firefox") or is_preferred_browser("iceweasel"): if is_preferred_browser("firefox") and not MozillaBookmarksHandler.has_firefox_version(): MozillaSearchHandler.INSTRUCTIONS = \ _("Firefox version must be at least %s and less than %s") % (MIN_FF_VERSION_STRING, MAX_FF_VERSION_STRING) return False # Correct firefox version or iceweasel MozillaSearchHandler.INSTRUCTIONS = _("You can customize which search engines are offered.") return True elif is_preferred_browser("mozilla"): # TODO - similar functionality for old-school mozilla (not firefox) return True else: MozillaSearchHandler.INSTRUCTIONS = _("Mozilla/Firefox is not your preferred browser.") return False
class MozillaSearchHandler(deskbar.interfaces.Module): INFOS = { 'icon': deskbar.core.Utils.load_icon("web-search.png"), "name": _("Web Searches (Mozilla)"), "description": _("Search the web via your browser's search settings"), "version": VERSION } def __init__(self): deskbar.interfaces.Module.__init__(self) self._smart_bookmarks = None def initialize(self): smart_dirs = None if USING_FIREFOX: smart_dirs = [ get_firefox_home_file("searchplugins"), get_firefox_home_file("search"), expanduser("~/.mozilla/searchplugins"), "/usr/local/lib/firefox/searchplugins", "/usr/lib/mozilla-firefox/searchplugins", "/usr/local/lib/mozilla-firefox/searchplugins", "/usr/lib/iceweasel/searchplugins"] + \ glob.glob("/usr/lib*/firefox*/searchplugins") else: smart_dirs = [ get_mozilla_home_file("search"), expanduser("~/.mozilla/searchplugins"), "/usr/lib/mozilla/searchplugins", "/usr/local/lib/mozilla/searchplugins" ] if not hasattr(self, 'watcher'): self.watcher = DirWatcher() self.watcher.connect( 'changed', lambda watcher, f: self._parse_search_engines(smart_dirs)) self.watcher.add(smart_dirs) self._parse_search_engines(smart_dirs) def _parse_search_engines(self, smart_dirs): self._smart_bookmarks = MozillaSmartBookmarksDirParser( smart_dirs).get_smart_bookmarks() self.set_priority_for_matches(self._smart_bookmarks) def stop(self): self.watcher.remove_all() def query(self, query): self.set_priority_for_matches(self._smart_bookmarks) if SHOW_ONLY_PRIMARY and PRIMARY_SEARCH_ENGINE != None: for s in self._smart_bookmarks: if s.get_name() == PRIMARY_SEARCH_ENGINE: self._emit_query_ready(query, [s]) return self._emit_query_ready(query, self._smart_bookmarks) else: self._emit_query_ready(query, self._smart_bookmarks) def has_config(self): return True def show_config(self, parent): _on_handler_preferences(parent) @staticmethod def has_requirements(): if is_preferred_browser("firefox") or is_preferred_browser( "iceweasel"): if is_preferred_browser( "firefox" ) and not MozillaBookmarksHandler.has_firefox_version(): MozillaSearchHandler.INSTRUCTIONS = \ _("Firefox version must be at least %s and less than %s") % (MIN_FF_VERSION_STRING, MAX_FF_VERSION_STRING) return False # Correct firefox version or iceweasel MozillaSearchHandler.INSTRUCTIONS = _( "You can customize which search engines are offered.") return True elif is_preferred_browser("mozilla"): # TODO - similar functionality for old-school mozilla (not firefox) return True else: MozillaSearchHandler.INSTRUCTIONS = _( "Mozilla/Firefox is not your preferred browser.") return False