コード例 #1
0
ファイル: __init__.py プロジェクト: jchtt/kupfer-adds
	def __init__(self, url, name, pict_count, album_id, thumb, user):
		UrlLeaf.__init__(self, url, name)
		self.album_id = album_id
		self.thumb = thumb
		photos_info = ngettext("one photo", "%(num)s photos",
				int(pict_count)) % {"num": pict_count}
		self.description = ': '.join((user, photos_info))
コード例 #2
0
ファイル: google_search.py プロジェクト: jchtt/kupfer-adds
 def get_items(self):
     try:
         query = urllib.urlencode({'q': self.query})
         if ssl_support.is_supported():
             conn = ssl_support.VerifiedHTTPSConnection(SEARCH_HOST,
                                                        timeout=5)
             self.output_debug("Connected to", SEARCH_HOST, "using SSL")
         else:
             conn = httplib.HTTPConnection(SEARCH_HOST, timeout=5)
         conn.request("GET", SEARCH_PATH + query)
         response = conn.getresponse()
         ctype = response.getheader("content-type", default="")
         parts = ctype.split("charset=", 1)
         encoding = parts[-1] if len(parts) > 1 else "UTF-8"
         search_results = response.read().decode(encoding)
         response.close()
     except (IOError, httplib.HTTPException) as exc:
         raise OperationError(unicode(exc))
     results = json_decoder(search_results)
     data = results['responseData']
     more_results_url = data['cursor']['moreResultsUrl']
     total_results = data['cursor'].get('estimatedResultCount', 0)
     for h in data['results']:
         uq_url = urllib.unquote(h['url'])
         uq_title = _xml_unescape(h['titleNoFormatting'])
         yield UrlLeaf(uq_url, uq_title)
     yield CustomDescriptionUrl(
         more_results_url,
         _('Show More Results For "%s"') % self.query,
         _("%s total found") % total_results)
コード例 #3
0
ファイル: pinboard.py プロジェクト: emareg/kupfer
 def get_items(self):
     token = __kupfer_settings__["token"]
     if token == "":
         return []
     pb = pinboard.Pinboard(token)
     bookmarks = pb.posts.all(start=0, results=100)
     return [UrlLeaf(b.url, b.description) for b in bookmarks]
コード例 #4
0
ファイル: chromium.py プロジェクト: jchtt/kupfer-adds
 def _get_chromium_items(self, fpath):
     """Parse Chromium' bookmarks backups"""
     from kupfer.plugin import chromium_support
     self.output_debug("Parsing", fpath)
     bookmarks = chromium_support.get_bookmarks(fpath)
     for book in bookmarks:
         yield UrlLeaf(book["url"], book["name"])
コード例 #5
0
 def _get_ffx3_bookmarks(self, fpath):
     """Parse Firefox' .json bookmarks backups"""
     from kupfer.plugin import firefox3_support
     self.output_debug("Parsing", fpath)
     bookmarks = firefox3_support.get_bookmarks(fpath)
     for book in bookmarks:
         yield UrlLeaf(book["uri"], book["title"])
コード例 #6
0
ファイル: firefox.py プロジェクト: pstuifzand/kupfer
    def _get_ffx3_bookmarks(self):
        """Query the firefox places bookmark database"""
        profile = __kupfer_settings__["profile"]
        fpath = get_firefox_home_file("places.sqlite", profile)
        if not (fpath and os.path.isfile(fpath)):
            return []

        fpath = fpath.replace("?", "%3f").replace("#", "%23")
        fpath = "file:" + fpath + "?immutable=1&mode=ro"

        for _ in range(2):
            try:
                self.output_debug("Reading bookmarks from", fpath)
                with closing(sqlite3.connect(fpath, timeout=1)) as conn:
                    c = conn.cursor()
                    c.execute(
                        """SELECT moz_places.url, moz_bookmarks.title
                              FROM moz_places, moz_bookmarks
                              WHERE moz_places.id = moz_bookmarks.fk
                                    AND moz_bookmarks.keyword_id IS NULL
                              ORDER BY visit_count DESC
                              LIMIT ?""", (MAX_ITEMS, ))
                    return [UrlLeaf(url, title) for url, title in c]
            except sqlite3.Error as err:
                # Something is wrong with the database
                # wait short time and try again
                self.output_debug("Read bookmarks error:", str(err))
                time.sleep(1)
        self.output_exc()
        return []
コード例 #7
0
class RecentsSource(AppLeafContentMixin, Source, PicklingHelperMixin):
    appleaf_content_id = "abiword"

    def __init__(self, name=None):
        if not name:
            name = _("Abiword Recent Items")
        super(RecentsSource, self).__init__(name)
        self.unpickle_finish()

    def pickle_prepare(self):
        # monitor is not pickleable
        self.monitor = None

    def unpickle_finish(self):
        """Set up change monitor"""
        abifile = self._get_abiword_file()
        if not abifile: return
        gfile = gio.File(abifile)
        self.monitor = gfile.monitor_file(gio.FILE_MONITOR_NONE, None)
        if self.monitor:
            self.monitor.connect("changed", self._changed)

    def _changed(self, monitor, file1, file2, evt_type):
        """Change callback; something changed"""
        if evt_type in (gio.FILE_MONITOR_EVENT_CREATED,
                        gio.FILE_MONITOR_EVENT_DELETED,
                        gio.FILE_MONITOR_EVENT_CHANGED):
            self.mark_for_update()

    def _get_abiword_file(self):
        abifile = os.path.expanduser("~/.AbiSuite/AbiWord.Profile")
        if not os.path.exists(abifile):
            return None
        return abifile

    def get_items(self):
        abifile = self._get_abiword_file()
        if not abifile:
            self.output_debug("Abiword profile not found at", abifile)
            return

        try:
            uris = list(get_abiword_files(abifile))
        except EnvironmentError, exc:
            self.output_error(exc)
            return

        for uri in uris:
            gfile = gio.File(uri)
            if not gfile.query_exists():
                continue

            if gfile.get_path():
                leaf = FileLeaf(gfile.get_path())
            else:
                leaf = UrlLeaf(gfile.get_uri(), gfile.get_basename())
            yield leaf
コード例 #8
0
 def _get_ffx3_bookmarks(self, fpath):
     """Parse Firefox' .json bookmarks backups"""
     from kupfer.plugin import firefox3_support
     self.output_debug("Parsing", fpath)
     bookmarks, tags = firefox3_support.get_bookmarks(fpath)
     for book in bookmarks:
         yield UrlLeaf(book["uri"], book["title"] or book["uri"])
     if __kupfer_settings__['load_tags']:
         for tag, items in tags.iteritems():
             yield Tag(tag, items)
コード例 #9
0
ファイル: openoffice.py プロジェクト: jchtt/kupfer-adds
def _create_history_leaf(path):
	''' Create leaf from file url '''
	if not path:
		return None
	gfile = gio.File(path)
	if not gfile.query_exists():
		None
	if gfile.get_path():
		return FileLeaf(gfile.get_path())
	return UrlLeaf(path, gfile.get_basename())
コード例 #10
0
 def _get_bugs(self):
     """Query the firefox places bookmark database"""
     fpath = os.path.join(BUGS_HOME, Bookmarks)
     if not (fpath and os.path.isfile(fpath)):
         return []
     try:
         c = get_bookmarks(BUGS_HOME, bm_folder)
         return [UrlLeaf(url, title) for url, title in c]
     except:
         # Something is wrong with the database
         return []
コード例 #11
0
ファイル: text.py プロジェクト: emareg/kupfer
    def get_text_items(self, text):
        # Only detect "perfect" URLs
        text = text.strip()
        components = list(urllib.parse.urlparse(text))
        domain = "".join(components[1:])

        # If urlparse parses a scheme (http://), it's an URL
        if len(domain.split()) <= 1 and components[0]:
            url = text
            name = ("".join(components[1:3])).strip("/")
            name = try_unquote_url(name) or url
            yield UrlLeaf(url, name=name)
コード例 #12
0
ファイル: opera.py プロジェクト: jchtt/kupfer-adds
 def get_items(self):
     name = None
     try:
         with codecs.open(self._bookmarks_path, "r", "UTF-8") as bfile:
             for line in bfile:
                 line = line.strip()
                 if line.startswith(u'NAME='):
                     name = line[5:]
                 elif line.startswith(u'URL=') and name:
                     yield UrlLeaf(line[4:], name)
     except EnvironmentError, exc:
         self.output_error(exc)
コード例 #13
0
ファイル: documents.py プロジェクト: cnheider/kupfer
 def _get_places(self, fileloc):
     for line in open(fileloc):
         if not line.strip():
             continue
         items = line.split(None, 1)
         uri = items[0]
         gfile = Gio.File.new_for_uri(uri)
         if len(items) > 1:
             title = items[1].strip()
         else:
             disp = gfile.get_parse_name()
             title = path.basename(disp)
         locpath = gfile.get_path()
         if locpath:
             yield FileLeaf(locpath, title)
         else:
             yield UrlLeaf(gfile.get_uri(), title)
コード例 #14
0
    def _get_ffx3_history(self):
        """Query the firefox places database"""
        max_history_items = 25
        fpath = firefox_support.get_firefox_home_file("places.sqlite")
        if not (fpath and os.path.isfile(fpath)):
            return
        try:
            self.output_debug("Reading history from", fpath)
            with closing(sqlite3.connect(fpath, timeout=1)) as conn:
                c = conn.cursor()
                c.execute(
                    """SELECT DISTINCT(url), title
							 FROM moz_places
							 ORDER BY visit_count DESC
							 LIMIT ?""", (max_history_items, ))
                return [UrlLeaf(url, title) for url, title in c]
        except sqlite3.Error:
            # Something is wrong with the database
            self.output_exc()
コード例 #15
0
ファイル: epiphany.py プロジェクト: jchtt/kupfer-adds
class EpiphanySource(AppLeafContentMixin, Source):
    appleaf_content_id = "epiphany"

    def __init__(self):
        super(EpiphanySource, self).__init__(_("Epiphany Bookmarks"))

    def get_items(self):
        fpath = os.path.expanduser(epiphany_support.EPHY_BOOKMARKS_FILE)
        if not os.path.exists(fpath):
            self.output_debug("Epiphany bookmarks file not found:", fpath)
            return ()

        try:
            bookmarks = list(epiphany_support.parse_epiphany_bookmarks(fpath))
        except EnvironmentError, exc:
            self.output_error(exc)
            return ()

        return (UrlLeaf(href, title) for title, href in bookmarks)
コード例 #16
0
 def _get_ffx3_bookmarks(self):
     """Query the firefox places bookmark database"""
     fpath = get_firefox_home_file("places.sqlite")
     if not (fpath and os.path.isfile(fpath)):
         return []
     try:
         self.output_debug("Reading bookmarks from", fpath)
         with closing(sqlite3.connect(fpath, timeout=1)) as conn:
             c = conn.cursor()
             c.execute(
                 """SELECT moz_places.url, moz_bookmarks.title
                          FROM moz_places, moz_bookmarks
                          WHERE moz_places.id = moz_bookmarks.fk
                             AND moz_bookmarks.keyword_id IS NULL
                          ORDER BY visit_count DESC
                          LIMIT ?""", (MAX_ITEMS, ))
             return [UrlLeaf(url, title) for url, title in c]
     except sqlite3.Error:
         # Something is wrong with the database
         self.output_exc()
         return []
コード例 #17
0
    def _get_items(cls, max_days, for_application_named=None):
        manager = recent_manager_get_default()
        items = manager.get_items()
        item_leaves = []
        for item in items:
            if for_application_named:
                low_apps = [A.lower() for A in item.get_applications()]
                if for_application_named.lower() not in low_apps:
                    continue
            day_age = item.get_age()
            if max_days >= 0 and day_age > max_days:
                continue
            if not item.exists():
                continue

            uri = item.get_uri()
            name = item.get_short_name()
            if item.is_local():
                leaf = FileLeaf(gio.File(uri).get_path())
            else:
                leaf = UrlLeaf(uri, name)
            item_leaves.append((leaf, item.get_modified()))
        for lf, date in sorted(item_leaves, key=lambda t: t[1], reverse=True):
            yield lf
コード例 #18
0
 def activate(self, leaf, iobj):
     try:
         result = iobj.process(leaf.object)
     except ValueError as exc:
         raise OperationError(str(exc))
     return UrlLeaf(result, result)
コード例 #19
0
ファイル: google_search.py プロジェクト: pbx/kupfer
 def __init__(self, obj, title, desc):
     UrlLeaf.__init__(self, obj, title)
     self.description = desc
コード例 #20
0
 def _get_ffx2_bookmarks(self, fpath):
     """Parse Firefox' bookmarks.html"""
     self.output_debug("Parsing", fpath)
     bookmarks = firefox_support.get_bookmarks(fpath)
     for book in bookmarks:
         yield UrlLeaf(book["href"], book["title"])
コード例 #21
0
 def get_items(self):
     for book in self.tag.object:
         yield UrlLeaf(book["uri"], book["title"] or book["uri"])
コード例 #22
0
ファイル: google_search.py プロジェクト: jchtt/kupfer-adds
 def __init__(self, obj, title, desc):
     UrlLeaf.__init__(self, obj, title)
     self.description = desc
コード例 #23
0
ファイル: __init__.py プロジェクト: jchtt/kupfer-adds
	def __init__(self, url, name, thumb=None, albums=None):
		UrlLeaf.__init__(self, url, name)
		# list of user albums [PicasaAlbum]
		self.update_albums(albums)
		self.thumb = thumb
		self.my_albums = False
コード例 #24
0
ファイル: __init__.py プロジェクト: jchtt/kupfer-adds
	def get_thumbnail(self, width, height):
		if self.thumb:
			return icons.get_pixbuf_from_data(self.thumb, width, height)
		return UrlLeaf.get_thumbnail(self, width, height)