From 74d45207f783c64975247569d36537d8b5e99658 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 6 Sep 2014 18:52:09 +0530 Subject: [PATCH] Get Books: WHen downloading books show a popup message telling the user that the books will be added to the calibre library automatically, to help new users understand what is happening. The popup message can be disabled. --- src/calibre/gui2/ebook_download.py | 27 ++++++++++++++++++++++++- src/calibre/gui2/store/search/search.py | 2 ++ src/calibre/gui2/store/web_control.py | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/ebook_download.py b/src/calibre/gui2/ebook_download.py index 17402f17b5..6404215fd9 100644 --- a/src/calibre/gui2/ebook_download.py +++ b/src/calibre/gui2/ebook_download.py @@ -14,12 +14,37 @@ from mechanize import MozillaCookieJar from calibre import browser from calibre.constants import __appname__, __version__ from calibre.ebooks import BOOK_EXTENSIONS -from calibre.gui2 import Dispatcher +from calibre.gui2 import Dispatcher, gprefs +from calibre.gui2.dialogs.message_box import MessageBox from calibre.gui2.threaded_jobs import ThreadedJob from calibre.ptempfile import PersistentTemporaryDirectory from calibre.utils.filenames import ascii_filename from calibre.web import get_download_filename_from_response + +class DownloadInfo(MessageBox): + + def __init__(self, filename, parent=None): + MessageBox.__init__( + self, MessageBox.INFO, _('Downloading book'), _( + 'The book {0} will be downloaded and added to your' + ' calibre library automatically.').format(filename), + show_copy_button=False, parent=parent + ) + self.toggle_checkbox.setChecked(True) + self.toggle_checkbox.setVisible(True) + self.toggle_checkbox.setText(_('Show this message again')) + self.toggle_checkbox.toggled.connect(self.show_again_changed) + self.resize_needed.emit() + + def show_again_changed(self): + gprefs.set('show_get_books_download_info', self.toggle_checkbox.isChecked()) + +def show_download_info(filename, parent=None): + if not gprefs.get('show_get_books_download_info', True): + return + DownloadInfo(filename, parent).exec_() + def get_download_filename(response): filename = get_download_filename_from_response(response) filename, ext = os.path.splitext(filename) diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 9ec91aa1dc..737876d67d 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -14,6 +14,7 @@ from PyQt5.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel, from calibre.gui2 import JSONConfig, info_dialog, error_dialog from calibre.gui2.dialogs.choose_format import ChooseFormatDialog +from calibre.gui2.ebook_download import show_download_info from calibre.gui2.progress_indicator import ProgressIndicator from calibre.gui2.store.config.chooser.chooser_widget import StoreChooserWidget from calibre.gui2.store.config.search.search_widget import StoreConfigWidget @@ -393,6 +394,7 @@ class SearchDialog(QDialog, Ui_Dialog): ext = d.format() fname = result.title[:60] + '.' + ext.lower() fname = ascii_filename(fname) + show_download_info(result.title, parent=self) self.gui.download_ebook(result.downloads[ext], filename=fname) def open_store(self, result): diff --git a/src/calibre/gui2/store/web_control.py b/src/calibre/gui2/store/web_control.py index 49f7f5634d..d901747590 100644 --- a/src/calibre/gui2/store/web_control.py +++ b/src/calibre/gui2/store/web_control.py @@ -15,6 +15,7 @@ from PyQt5.QtWebKitWidgets import QWebView, QWebPage from calibre import USER_AGENT, get_proxies from calibre.ebooks import BOOK_EXTENSIONS from calibre.gui2 import choose_save_file +from calibre.gui2.ebook_download import show_download_info from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.filenames import ascii_filename from calibre.web import get_download_filename @@ -91,6 +92,7 @@ class NPWebView(QWebView): if name: self.gui.download_ebook(url, cf, name, name, False) else: + show_download_info(filename, self) self.gui.download_ebook(url, cf, filename, tags=self.tags) def ignore_ssl_errors(self, reply, errors):