mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Popup an error message if a news download is aborted because of no active internet connection. Minor fixes.
This commit is contained in:
parent
91a75aa0c9
commit
5e2a1b3f81
@ -205,6 +205,7 @@ class Scheduler(QObject):
|
|||||||
|
|
||||||
def __init__(self, parent, db):
|
def __init__(self, parent, db):
|
||||||
QObject.__init__(self, parent)
|
QObject.__init__(self, parent)
|
||||||
|
self.internet_connection_failed = False
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
self.recipe_model = RecipeModel(db)
|
self.recipe_model = RecipeModel(db)
|
||||||
self.lock = QMutex(QMutex.Recursive)
|
self.lock = QMutex(QMutex.Recursive)
|
||||||
@ -305,9 +306,17 @@ class Scheduler(QObject):
|
|||||||
self.download(urn)
|
self.download(urn)
|
||||||
|
|
||||||
def download(self, urn):
|
def download(self, urn):
|
||||||
if not internet_connected():
|
|
||||||
return
|
|
||||||
self.lock.lock()
|
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
|
doit = urn not in self.download_queue
|
||||||
self.lock.unlock()
|
self.lock.unlock()
|
||||||
if doit:
|
if doit:
|
||||||
|
@ -35,6 +35,7 @@ class LibraryDelegate(QItemDelegate):
|
|||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QItemDelegate.__init__(self, parent)
|
QItemDelegate.__init__(self, parent)
|
||||||
|
self._parent = parent
|
||||||
self.star_path = QPainterPath()
|
self.star_path = QPainterPath()
|
||||||
self.star_path.moveTo(90, 50)
|
self.star_path.moveTo(90, 50)
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
@ -65,7 +66,8 @@ class LibraryDelegate(QItemDelegate):
|
|||||||
|
|
||||||
painter.save()
|
painter.save()
|
||||||
if hasattr(QStyle, 'CE_ItemViewItem'):
|
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:
|
elif option.state & QStyle.State_Selected:
|
||||||
painter.fillRect(option.rect, option.palette.highlight())
|
painter.fillRect(option.rect, option.palette.highlight())
|
||||||
self.drawFocus(painter, option, option.rect)
|
self.drawFocus(painter, option, option.rect)
|
||||||
@ -82,8 +84,8 @@ class LibraryDelegate(QItemDelegate):
|
|||||||
draw_star()
|
draw_star()
|
||||||
painter.translate(-self.SIZE, 0)
|
painter.translate(-self.SIZE, 0)
|
||||||
i += 1
|
i += 1
|
||||||
except Exception, e:
|
except:
|
||||||
traceback.print_exc(e)
|
traceback.print_exc()
|
||||||
painter.restore()
|
painter.restore()
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
|
@ -28,6 +28,12 @@ from calibre.utils.threadpool import WorkRequest, ThreadPool, NoResultsPending
|
|||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.date import now as nowf
|
from calibre.utils.date import now as nowf
|
||||||
|
|
||||||
|
class LoginFailed(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class DownloadDenied(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
class BasicNewsRecipe(Recipe):
|
class BasicNewsRecipe(Recipe):
|
||||||
'''
|
'''
|
||||||
Abstract base class that contains logic needed in all feed fetchers.
|
Abstract base class that contains logic needed in all feed fetchers.
|
||||||
@ -1359,9 +1365,6 @@ class AutomaticNewsRecipe(BasicNewsRecipe):
|
|||||||
self.web2disk_options.keep_only_tags = []
|
self.web2disk_options.keep_only_tags = []
|
||||||
return BasicNewsRecipe.fetch_embedded_article(self, article, dir, f, a, num_of_feeds)
|
return BasicNewsRecipe.fetch_embedded_article(self, article, dir, f, a, num_of_feeds)
|
||||||
|
|
||||||
class LoginFailed(ValueError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class CalibrePeriodical(BasicNewsRecipe):
|
class CalibrePeriodical(BasicNewsRecipe):
|
||||||
|
|
||||||
#: Set this to the slug for the calibre periodical
|
#: Set this to the slug for the calibre periodical
|
||||||
@ -1380,18 +1383,26 @@ class CalibrePeriodical(BasicNewsRecipe):
|
|||||||
raw = br.submit().read()
|
raw = br.submit().read()
|
||||||
if 'href="/my-account"' not in raw:
|
if 'href="/my-account"' not in raw:
|
||||||
raise LoginFailed(
|
raise LoginFailed(
|
||||||
'Failed to log in, check your username and password for'
|
_('Failed to log in, check your username and password for'
|
||||||
' the calibre Periodicals service.')
|
' the calibre Periodicals service.'))
|
||||||
|
|
||||||
return br
|
return br
|
||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
import cStringIO
|
import cStringIO
|
||||||
self.log('Fetching downloaded recipe')
|
self.log('Fetching downloaded recipe')
|
||||||
raw = self.browser.open_novisit(
|
try:
|
||||||
'http://news.calibre-ebook.com/subscribed_files/%s/0/temp.downloaded_recipe'
|
raw = self.browser.open_novisit(
|
||||||
% self.calibre_periodicals_slug
|
'http://news.calibre-ebook.com/subscribed_files/%s/0/temp.downloaded_recipe'
|
||||||
).read()
|
% 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)
|
f = cStringIO.StringIO(raw)
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
zf = ZipFile(f)
|
zf = ZipFile(f)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user