When minimized to system tray do not display the no internet connection error as a dialog box, instead use a system tray notification

This commit is contained in:
Kovid Goyal 2011-12-11 10:27:27 +05:30
parent da24adb1cc
commit 2b328e6ff0
2 changed files with 22 additions and 10 deletions

View File

@ -419,6 +419,13 @@ class Scheduler(QObject):
QObject.__init__(self, parent) QObject.__init__(self, parent)
self.internet_connection_failed = False self.internet_connection_failed = False
self._parent = parent self._parent = parent
self.no_internet_msg = _('Cannot download news as no internet connection '
'is active')
self.no_internet_dialog = d = error_dialog(self._parent,
self.no_internet_msg, _('No internet connection'),
show_copy_button=False)
d.setModal(False)
self.recipe_model = RecipeModel() self.recipe_model = RecipeModel()
self.db = db self.db = db
self.lock = QMutex(QMutex.Recursive) self.lock = QMutex(QMutex.Recursive)
@ -523,7 +530,6 @@ class Scheduler(QObject):
finally: finally:
self.lock.unlock() self.lock.unlock()
def download_clicked(self, urn): def download_clicked(self, urn):
if urn is not None: if urn is not None:
return self.download(urn) return self.download(urn)
@ -534,18 +540,24 @@ class Scheduler(QObject):
def download_all_scheduled(self): def download_all_scheduled(self):
self.download_clicked(None) self.download_clicked(None)
def download(self, urn): def has_internet_connection(self):
self.lock.lock()
if not internet_connected(): if not internet_connected():
if not self.internet_connection_failed: if not self.internet_connection_failed:
self.internet_connection_failed = True self.internet_connection_failed = True
d = error_dialog(self._parent, _('No internet connection'), if self._parent.is_minimized_to_tray:
_('Cannot download news as no internet connection ' self._parent.status_bar.show_message(self.no_internet_msg, 5000)
'is active')) elif not self.no_internet_dialog.isVisible():
d.setModal(False) self.no_internet_dialog.show()
d.show()
return False return False
self.internet_connection_failed = False self.internet_connection_failed = False
if self.no_internet_dialog.isVisible():
self.no_internet_dialog.hide()
return True
def download(self, urn):
self.lock.lock()
if not self.has_internet_connection():
return 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:

View File

@ -723,10 +723,10 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.write_settings() self.write_settings()
if self.system_tray_icon.isVisible(): if self.system_tray_icon.isVisible():
if not dynamic['systray_msg'] and not isosx: if not dynamic['systray_msg'] and not isosx:
info_dialog(self, 'calibre', 'calibre '+\ info_dialog(self, 'calibre', 'calibre '+ \
_('will keep running in the system tray. To close it, ' _('will keep running in the system tray. To close it, '
'choose <b>Quit</b> in the context menu of the ' 'choose <b>Quit</b> in the context menu of the '
'system tray.')).exec_() 'system tray.'), show_copy_button=False).exec_()
dynamic['systray_msg'] = True dynamic['systray_msg'] = True
self.hide_windows() self.hide_windows()
e.ignore() e.ignore()