mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add tags to downloaded items.
This commit is contained in:
parent
7036d1acc1
commit
498b79e6d5
@ -23,6 +23,7 @@ class FeedbooksStore(StorePlugin):
|
||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||
d = WebStoreDialog(gui, 'http://m.feedbooks.com/', parent, detail_item)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(self.name + ',' + _('store'))
|
||||
d = d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
|
@ -23,6 +23,7 @@ class GutenbergStore(StorePlugin):
|
||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||
d = WebStoreDialog(gui, 'http://m.gutenberg.org/', parent, detail_item)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(self.name + ',' + _('store'))
|
||||
d = d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
|
@ -24,6 +24,7 @@ class ManyBooksStore(StorePlugin):
|
||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||
d = WebStoreDialog(gui, 'http://manybooks.net/', parent, detail_item)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(self.name + ',' + _('store'))
|
||||
d = d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
|
@ -55,8 +55,48 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>307</x>
|
||||
<y>524</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>307</x>
|
||||
<y>272</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>307</x>
|
||||
<y>524</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>307</x>
|
||||
<y>272</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
@ -24,6 +24,7 @@ class SmashwordsStore(StorePlugin):
|
||||
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||
d = WebStoreDialog(gui, 'http://www.smashwords.com/?ref=usernone', parent, detail_item)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(self.name + ',' + _('store'))
|
||||
d = d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
|
@ -18,6 +18,7 @@ class NPWebView(QWebView):
|
||||
def __init__(self, *args):
|
||||
QWebView.__init__(self, *args)
|
||||
self.gui = None
|
||||
self.tags = ''
|
||||
|
||||
self.setPage(NPWebPage())
|
||||
self.page().networkAccessManager().setCookieJar(QNetworkCookieJar())
|
||||
@ -35,6 +36,9 @@ class NPWebView(QWebView):
|
||||
def set_gui(self, gui):
|
||||
self.gui = gui
|
||||
|
||||
def set_tags(self, tags):
|
||||
self.tags = tags
|
||||
|
||||
def start_download(self, request):
|
||||
if not self.gui:
|
||||
return
|
||||
@ -56,7 +60,7 @@ class NPWebView(QWebView):
|
||||
if name:
|
||||
self.gui.download_from_store(url, cj, name, False)
|
||||
else:
|
||||
self.gui.download_from_store(url, cj)
|
||||
self.gui.download_from_store(url, cj, tags=self.tags)
|
||||
|
||||
def ignore_ssl_errors(self, reply, errors):
|
||||
reply.ignoreSslErrors(errors)
|
||||
|
@ -30,6 +30,9 @@ class WebStoreDialog(QDialog, Ui_Dialog):
|
||||
|
||||
self.go_home(detail_item=detail_item)
|
||||
|
||||
def set_tags(self, tags):
|
||||
self.view.set_tags(tags)
|
||||
|
||||
def load_started(self):
|
||||
self.progress.setValue(0)
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="4">
|
||||
<item row="0" column="0" colspan="5">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
@ -72,6 +72,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QPushButton" name="close">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@ -87,5 +94,22 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>close</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>917</x>
|
||||
<y>635</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>480</x>
|
||||
<y>327</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
@ -21,13 +21,13 @@ from calibre.utils.ipc.job import BaseJob
|
||||
|
||||
class StoreDownloadJob(BaseJob):
|
||||
|
||||
def __init__(self, callback, description, job_manager, db, cookie_jar, url='', save_as_loc='', add_to_lib=True):
|
||||
def __init__(self, callback, description, job_manager, db, cookie_jar, url='', save_as_loc='', add_to_lib=True, tags=[]):
|
||||
BaseJob.__init__(self, description)
|
||||
self.exception = None
|
||||
self.job_manager = job_manager
|
||||
self.db = db
|
||||
self.cookie_jar = cookie_jar
|
||||
self.args = (url, save_as_loc, add_to_lib)
|
||||
self.args = (url, save_as_loc, add_to_lib, tags)
|
||||
self.tmp_file_name = ''
|
||||
self.callback = callback
|
||||
self.log_path = None
|
||||
@ -122,7 +122,7 @@ class StoreDownloader(Thread):
|
||||
traceback.print_exc()
|
||||
|
||||
def _download(self, job):
|
||||
url, save_loc, add_to_lib = job.args
|
||||
url, save_loc, add_to_lib, tags = job.args
|
||||
if not url:
|
||||
raise Exception(_('No file specified to download.'))
|
||||
if not save_loc and not add_to_lib:
|
||||
@ -140,7 +140,7 @@ class StoreDownloader(Thread):
|
||||
job.tmp_file_name = tf.name
|
||||
|
||||
def _add(self, job):
|
||||
url, save_loc, add_to_lib = job.args
|
||||
url, save_loc, add_to_lib, tags = job.args
|
||||
if not add_to_lib and job.tmp_file_name:
|
||||
return
|
||||
ext = os.path.splitext(job.tmp_file_name)[1][1:].lower()
|
||||
@ -152,19 +152,20 @@ class StoreDownloader(Thread):
|
||||
from calibre.ebooks.metadata.meta import get_metadata
|
||||
with open(job.tmp_file_name) as f:
|
||||
mi = get_metadata(f, ext)
|
||||
mi.tags.extend(tags)
|
||||
|
||||
job.db.add_books([job.tmp_file_name], [ext], [mi])
|
||||
|
||||
def _save_as(self, job):
|
||||
url, save_loc, add_to_lib = job.args
|
||||
url, save_loc, add_to_lib, tags = job.args
|
||||
if not save_loc and job.tmp_file_name:
|
||||
return
|
||||
|
||||
shutil.copy(job.tmp_file_name, save_loc)
|
||||
|
||||
def download_from_store(self, callback, db, cookie_jar, url='', save_as_loc='', add_to_lib=True):
|
||||
def download_from_store(self, callback, db, cookie_jar, url='', save_as_loc='', add_to_lib=True, tags=[]):
|
||||
description = _('Downloading %s') % url
|
||||
job = StoreDownloadJob(callback, description, self.job_manager, db, cookie_jar, url, save_as_loc, add_to_lib)
|
||||
job = StoreDownloadJob(callback, description, self.job_manager, db, cookie_jar, url, save_as_loc, add_to_lib, tags)
|
||||
self.job_manager.add_job(job)
|
||||
self.jobs.put(job)
|
||||
|
||||
@ -174,10 +175,13 @@ class StoreDownloadMixin(object):
|
||||
def __init__(self):
|
||||
self.store_downloader = StoreDownloader(self.job_manager)
|
||||
|
||||
def download_from_store(self, url='', cookie_jar=CookieJar(), save_as_loc='', add_to_lib=True):
|
||||
def download_from_store(self, url='', cookie_jar=CookieJar(), save_as_loc='', add_to_lib=True, tags=[]):
|
||||
if not self.store_downloader.is_alive():
|
||||
self.store_downloader.start()
|
||||
self.store_downloader.download_from_store(Dispatcher(self.downloaded_from_store), self.library_view.model().db, cookie_jar, url, save_as_loc, add_to_lib)
|
||||
if tags:
|
||||
if isinstance(tags, basestring):
|
||||
tags = tags.split(',')
|
||||
self.store_downloader.download_from_store(Dispatcher(self.downloaded_from_store), self.library_view.model().db, cookie_jar, url, save_as_loc, add_to_lib, tags)
|
||||
self.status_bar.show_message(_('Downloading') + ' ' + url, 3000)
|
||||
|
||||
def downloaded_from_store(self, job):
|
||||
|
Loading…
x
Reference in New Issue
Block a user