From 5e2a1b3f81f2e2bc601945e4ed3db9bfefa76d4f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Mar 2010 21:29:40 +0530 Subject: [PATCH] Popup an error message if a news download is aborted because of no active internet connection. Minor fixes. --- src/calibre/gui2/dialogs/scheduler.py | 13 ++++++++++-- src/calibre/gui2/library.py | 8 +++++--- src/calibre/web/feeds/news.py | 29 ++++++++++++++++++--------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/calibre/gui2/dialogs/scheduler.py b/src/calibre/gui2/dialogs/scheduler.py index d11344207f..2fd26cffa1 100644 --- a/src/calibre/gui2/dialogs/scheduler.py +++ b/src/calibre/gui2/dialogs/scheduler.py @@ -205,6 +205,7 @@ class Scheduler(QObject): def __init__(self, parent, db): QObject.__init__(self, parent) + self.internet_connection_failed = False self._parent = parent self.recipe_model = RecipeModel(db) self.lock = QMutex(QMutex.Recursive) @@ -305,9 +306,17 @@ class Scheduler(QObject): self.download(urn) def download(self, urn): - if not internet_connected(): - return self.lock.lock() + if not internet_connected(): + if not self.internet_connection_failed: + self.internet_connection_failed = True + d = error_dialog(self._parent, _('No internet connection'), + _('Cannot download news as no internet connection ' + 'is active')) + d.setModal(False) + d.show() + return + self.internet_connection_failed = False doit = urn not in self.download_queue self.lock.unlock() if doit: diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index 75e3411fdf..7da75c9017 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -35,6 +35,7 @@ class LibraryDelegate(QItemDelegate): def __init__(self, parent): QItemDelegate.__init__(self, parent) + self._parent = parent self.star_path = QPainterPath() self.star_path.moveTo(90, 50) for i in range(1, 5): @@ -65,7 +66,8 @@ class LibraryDelegate(QItemDelegate): painter.save() if hasattr(QStyle, 'CE_ItemViewItem'): - QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, painter) + QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, + painter, self._parent) elif option.state & QStyle.State_Selected: painter.fillRect(option.rect, option.palette.highlight()) self.drawFocus(painter, option, option.rect) @@ -82,8 +84,8 @@ class LibraryDelegate(QItemDelegate): draw_star() painter.translate(-self.SIZE, 0) i += 1 - except Exception, e: - traceback.print_exc(e) + except: + traceback.print_exc() painter.restore() def createEditor(self, parent, option, index): diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index 2a09fc261b..0149e4a700 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -28,6 +28,12 @@ from calibre.utils.threadpool import WorkRequest, ThreadPool, NoResultsPending from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.date import now as nowf +class LoginFailed(ValueError): + pass + +class DownloadDenied(ValueError): + pass + class BasicNewsRecipe(Recipe): ''' Abstract base class that contains logic needed in all feed fetchers. @@ -1359,9 +1365,6 @@ class AutomaticNewsRecipe(BasicNewsRecipe): self.web2disk_options.keep_only_tags = [] return BasicNewsRecipe.fetch_embedded_article(self, article, dir, f, a, num_of_feeds) -class LoginFailed(ValueError): - pass - class CalibrePeriodical(BasicNewsRecipe): #: Set this to the slug for the calibre periodical @@ -1380,18 +1383,26 @@ class CalibrePeriodical(BasicNewsRecipe): raw = br.submit().read() if 'href="/my-account"' not in raw: raise LoginFailed( - 'Failed to log in, check your username and password for' - ' the calibre Periodicals service.') + _('Failed to log in, check your username and password for' + ' the calibre Periodicals service.')) return br def download(self): import cStringIO self.log('Fetching downloaded recipe') - raw = self.browser.open_novisit( - 'http://news.calibre-ebook.com/subscribed_files/%s/0/temp.downloaded_recipe' - % self.calibre_periodicals_slug - ).read() + try: + raw = self.browser.open_novisit( + 'http://news.calibre-ebook.com/subscribed_files/%s/0/temp.downloaded_recipe' + % self.calibre_periodicals_slug + ).read() + except Exception, e: + if hasattr(e, 'getcode') and e.getcode() == 403: + raise DownloadDenied( + _('You do not have permission to download this issue.' + ' Either your subscription has expired or you have' + ' exceeded the maximum allowed downloads for today.')) + raise f = cStringIO.StringIO(raw) from calibre.utils.zipfile import ZipFile zf = ZipFile(f)