def batch_download(self, ok): "Download images in batch." selected_items = self.thumbnailarea.selected_images() if not selected_items: return start_url = KUrl("kfiledialog:///danbooru") caption = i18n("Select a directory to save the images to") directory = KFileDialog.getExistingDirectoryUrl( start_url, self, caption) if directory.isEmpty(): return for item in selected_items: file_url = item.url_label.url() tags = item.data.tags # Make a local copy to append paths as addPath works in-place destination = KUrl(directory) file_name = KUrl(file_url).fileName() destination.addPath(file_name) job = KIO.file_copy(KUrl(file_url), destination, -1) job.setProperty("tags", QVariant(tags)) job.result.connect(self.batch_download_slot)
def get_linter(linter_name, callback): """tries to retrieve a linter and calls `callback` on it on success""" if linter_name in LINTERS: callback(LINTERS[linter_name]) return if linter_name not in NEEDS_LICENSE: showError(i18nc('@info:status', 'No acceptable linter named %1!', linter_name)) return license, objname, url = NEEDS_LICENSE[linter_name] cache_path = p.join(CACHE_DIR, linter_name + '.js') def success(): """store newly created linter and “return” it""" LINTERS[linter_name] = JSModule(JS_ENGINE, cache_path, objname) callback(LINTERS[linter_name]) if p.exists(cache_path): success() return # the user doesn’t have the file. ask to accept its license if not license_accepted(license): return download = KIO.file_copy(KUrl(url), KUrl.fromPath(cache_path)) @download.result.connect def _call(job): if job.error(): showError(i18nc('@info:status', 'Download failed')) else: success() download.start()
def batch_download(self, ok): "Download images in batch." selected_items = self.thumbnailarea.selected_images() if not selected_items: return start_url = KUrl("kfiledialog:///danbooru") caption = i18n("Select a directory to save the images to") directory = KFileDialog.getExistingDirectoryUrl(start_url, self, caption) if directory.isEmpty(): return for item in selected_items: file_url = item.url_label.url() tags = item.data.tags # Make a local copy to append paths as addPath works in-place destination = KUrl(directory) file_name = KUrl(file_url).fileName() destination.addPath(file_name) job = KIO.file_copy(KUrl(file_url), destination, -1) job.setProperty("tags", QVariant(tags)) job.result.connect(self.batch_download_slot)