Popup an error message if a news download is aborted because of no active internet connection. Minor fixes.

This commit is contained in:
Kovid Goyal 2010-03-30 21:29:40 +05:30
parent 91a75aa0c9
commit 5e2a1b3f81
3 changed files with 36 additions and 14 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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)