def download(self, result):

        """Trigger the download of the image to a user-supplied directory."""

        start_name = kdecore.KUrl(self.url_to_file).fileName()
        start_url = kdecore.KUrl("kfiledialog:///danbooru/%s" %
                                 unicode(start_name))

        # Get the mimetype to be passed to the save dialog
        mimetype_job = kio.KIO.mimetype(kdecore.KUrl(self.url_to_file),
                                        kio.KIO.HideProgressInfo)

        # Small enough to be synchronous
        if kio.KIO.NetAccess.synchronousRun(mimetype_job, self):
            mimetype = mimetype_job.mimetype()

        caption = kdecore.i18n("Save image file")

        enable_previews = kio.KFileDialog.ShowInlinePreview
        confirm_overwrite = kio.KFileDialog.ConfirmOverwrite
        options = kio.KFileDialog.Option(enable_previews | confirm_overwrite)

        filename = kio.KFileDialog.getSaveFileName(start_url,
            mimetype, self, caption, options)

        if not filename:
            return

        download_url = kdecore.KUrl(self.url_to_file)
        filename = kdecore.KUrl(filename)
        download_job = kio.KIO.file_copy(download_url, filename, -1)
        download_job.result.connect(self.download_slot)
Пример #2
0
 def update_data(self):
     if pool == 10:  # p2pool
         self.data_url = kdecore.KUrl(url[self.pool])
     else:
         self.data_url = kdecore.KUrl(url[self.pool] + str(self.APIkey) +
                                      url2[self.pool])
     job = kio.KIO.storedGet(self.data_url, kio.KIO.NoReload,
                             kio.KIO.HideProgressInfo)
     job.result.connect(self.update_values)
Пример #3
0
    def setup_urls(self, urls):

        self.danbooruUrlComboBox.clear()

        if urls is not None:
            for index, item in enumerate(urls):
                self.danbooruUrlComboBox.insertUrl(index, kdecore.KUrl(item))
Пример #4
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)
    def view(self):

        """Display the image using the user's default image viewer."""

        # Garbage collection ensues if we don't keep a reference around
        self.display = kio.KRun(kdecore.KUrl(self.url_to_file), self, 0,
                                False, True, '')

        if self.display.hasError():

            messagewidget = kdeui.KMessageWidget(self)
            messagewidget.setMessageType(kdeui.KMessageWidget.Error)
            text = kdecore.i18n("An error occurred while "
                                "downloading the image.")
            messagewidget.setText(text)
    def __init__(self, danbooru_post, parent=None):

        super(DanbooruPostWidget, self).__init__(parent)

        self.data = danbooru_post

        self.url_label = kdeui.KUrlLabel()
        self.__text_label = QtGui.QLabel()
        self.url_to_file = self.data.file_url

        label_text = self.label_text()

        self.url_label.setUrl(self.data.file_url)
        self.url_label.setPixmap(self.data.pixmap)

        full_url = kdecore.KUrl(self.data.file_url).fileName()
        self.url_label.setUseTips(True)
        self.url_label.setAlignment(QtCore.Qt.AlignCenter)
        self.url_label.setTipText(full_url)

        self.layout = QtGui.QVBoxLayout(self)
        self.layout.addStretch()
        self.layout.addWidget(self.url_label)

        if label_text is not None:
            self.__text_label.setText(label_text)
            self.layout.addWidget(self.__text_label)

        self.checkbox = QtGui.QCheckBox()
        self.checkbox.setChecked(False)
        self.checkbox.setText(kdecore.i18n("Select"))

        # Remove the accelerator, we don't want it
        kdeui.KAcceleratorManager.setNoAccel(self.checkbox)

        self.checkbox.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                    QtGui.QSizePolicy.Fixed)
        self.layout.addWidget(self.checkbox)

        # FIXME: Hack to make sure there's enough space around the image,
        # so that things to do not look as cramped

        self.layout.setSpacing(6)
        self.setup_actions()
Пример #7
0
def danbooru_request_url(board_url,
                         api_url,
                         parameters=None,
                         username=None,
                         password=None):
    """Create an appropriately-encoded Danbooru URL.

    The processing follows the "normal" way of encoding URLs, minus
    for the plus sign("+") which is kept literal as otherwise it wouldn't be
    understood by the Danbooru API.

    :param board_url: The base URL for generation
    :param api_url: The specific API path
    :param parameters: a dictionary holding the parameters to be added

    :return: A properly encoded Danbooru URL

    """

    danbooru_url = kdecore.KUrl(board_url)
    danbooru_url.addPath(api_url)

    if parameters is not None:

        if sys.version_info.major > 2:
            iterator = parameters.items()
        else:
            iterator = parameters.iteritems()

        for key, value in iterator:

            if key == "tags":
                # By adding a plus to tags, we already encoded them
                danbooru_url.addEncodedQueryItem(key, value)

            danbooru_url.addQueryItem(key, unicode(value))

    if username is not None and password is not None:
        danbooru_url.setUserName(username)
        danbooru_url.setPassword(password)

    return danbooru_url
    def download_slot(self, job):

        "Slot called by the KJob handling the download."

        if job.error():
            messagewidget = kdeui.KMessageWidget(self)
            messagewidget.setMessageType(kdeui.KMessageWidget.Error)
            text = job.errorText()
            messagewidget.setText(text)

            return

        download_name = job.destUrl().toLocalFile()

        # Grab a reference to the view
        parent_widget = self.parent().parent()

        blacklist = parent_widget.preferences.tag_blacklist
        tagging = parent_widget.preferences.nepomuk_enabled

        if tagging:
            # Get the URL of the board for Nepomuk tagging
            board_name = kdecore.KUrl(parent_widget.api_data.url)