Exemplo n.º 1
0
    def download_thumbnail(self, danbooru_item):
        """Retrieve a thumbnail for a specific Danbooru item.

        KIO.storedGet is used for asyncrhonous download. Jobs are scheduled
        to prevent server overload.

        :param danbooru_item: An instance of
                              :class:`DanbooruItem <danbooru.api.containers.DanbooruItem>`

        """

        image_url = kdecore.KUrl(danbooru_item.preview_url)
        flags = KIO.JobFlags(KIO.HideProgressInfo)

        pixmap = QtGui.QPixmap()
        name = image_url.fileName()

        # No need to download if in cache

        if self.cache is not None:
            if self.cache.find(name, pixmap):
                danbooru_item.pixmap = pixmap
                self.postRetrieved.emit(danbooru_item)
                return

        job = KIO.storedGet(image_url, KIO.NoReload, flags)
        job.setProperty("danbooru_item", QtCore.QVariant(danbooru_item))

        # Schedule: we don't want to overload servers
        KIO.Scheduler.setJobPriority(job, 1)
        job.result.connect(self.__slot_download_thumbnail)
Exemplo n.º 2
0
    def all_tags(self):
        """Fetch all the current tags."""

        parameters = dict(limit=0, order="name")
        flags = KIO.JobFlags(KIO.HideProgressInfo)

        request_url = utils.danbooru_request_url(self.url, TAG_URL, parameters,
                                                 self.username, self.password)

        job = KIO.storedGet(request_url, KIO.Reload, flags)
        job.result.connect(self.__slot_download_all_tags)