[rigo] notify user when connectivity is absent (via Entropy Web Services)

This commit is contained in:
Fabio Erculiani
2012-02-29 10:22:31 +01:00
parent 095038425a
commit bfa9215295
3 changed files with 58 additions and 6 deletions
+8 -1
View File
@@ -78,7 +78,14 @@ class EntropyWebService(object):
return None
try:
available = webserv.service_available()
# we cannot rely on local cache because the
# network availability may have changed.
# even tho, we should check this every time
# we're asked to return from get().
# Moreover, using local cache without Internet
# connectivity would result in a crazy amount
# of requests floating around the process.
available = webserv.service_available(cache=False)
except WebService.WebServiceException:
available = False
+16 -2
View File
@@ -20,7 +20,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
"""
import subprocess
from gi.repository import Gtk, GLib, GObject
from gi.repository import Gtk, GLib, GObject, Pango
from rigo.utils import build_register_url, open_url
@@ -29,7 +29,6 @@ from entropy.services.client import WebService
from entropy.misc import ParallelTask
class NotificationBox(Gtk.HBox):
"""
@@ -87,6 +86,7 @@ class NotificationBox(Gtk.HBox):
if self._message_widget is None:
label = Gtk.Label()
label.set_markup(self._message)
label.set_line_wrap_mode(Pango.WrapMode.WORD)
# make it css-able
label.set_property("expand", True)
label.set_alignment(0.02, 0.50)
@@ -323,3 +323,17 @@ class LoginNotificationBox(NotificationBox):
Register button click event.
"""
open_url(build_register_url())
class ConnectivityNotificationBox(NotificationBox):
def __init__(self):
msg = _("Cannot connect to Entropy Web Services, "
"are you connected to the <b>interweb</b>?")
NotificationBox.__init__(self, msg,
tooltip=_("Don't ask me..."),
message_type=Gtk.MessageType.ERROR,
context_id="ConnectivityNotificationBox")
self.add_destroy_button(_("_Of course not"))
+34 -3
View File
@@ -43,7 +43,7 @@ from rigo.models.application import Application, ApplicationMetadata
from rigo.ui.gtk3.widgets.apptreeview import AppTreeView
from rigo.ui.gtk3.widgets.notifications import NotificationBox, \
RepositoriesUpdateNotificationBox, UpdatesNotificationBox, \
LoginNotificationBox
LoginNotificationBox, ConnectivityNotificationBox
from rigo.ui.gtk3.widgets.welcome import WelcomeBox
from rigo.ui.gtk3.widgets.stars import ReactiveStar
from rigo.ui.gtk3.widgets.comments import CommentBox
@@ -185,9 +185,10 @@ class NotificationViewController(GObject.Object):
but also accepts external NotificationBox instances as well.
"""
def __init__(self, entropy_client, avc, notification_box):
def __init__(self, entropy_client, entropy_ws, avc, notification_box):
GObject.Object.__init__(self)
self._entropy = entropy_client
self._entropy_ws = entropy_ws
self._avc = avc
self._box = notification_box
self._updates = None
@@ -196,6 +197,13 @@ class NotificationViewController(GObject.Object):
def setup(self):
GLib.timeout_add(3000, self._calculate_updates)
GLib.idle_add(self._check_connectivity)
def _check_connectivity(self):
th = ParallelTask(self.__check_connectivity)
th.daemon = True
th.name = "CheckConnectivity"
th.start()
def _calculate_updates(self):
th = ParallelTask(self.__calculate_updates)
@@ -203,6 +211,21 @@ class NotificationViewController(GObject.Object):
th.name = "CalculateUpdates"
th.start()
def __check_connectivity(self):
"""
Execute connectivity check basing on Entropy
Web Services availability.
"""
repositories = self._entropy.repositories()
available = False
for repository_id in repositories:
if self._entropy_ws.get(repository_id) is not None:
available = True
break
if not available:
GLib.idle_add(self._notify_connectivity_issues)
def __order_updates(self, updates):
"""
Order updates using PN.
@@ -223,6 +246,13 @@ class NotificationViewController(GObject.Object):
self._security_updates = self._entropy.calculate_security_updates()
GLib.idle_add(self._notify_updates_safe)
def _notify_connectivity_issues(self):
"""
Cannot connect to Entropy Web Services.
"""
box = ConnectivityNotificationBox()
self.append(box)
def _notify_updates_safe(self):
"""
Add NotificationBox signaling the user that updates
@@ -1170,7 +1200,8 @@ class Rigo(Gtk.Application):
self._avc.connect("view-filled", self._on_view_filled)
self._nc = NotificationViewController(
self._entropy, self._avc, self._notification)
self._entropy, self._entropy_ws,
self._avc, self._notification)
self._app_view_c.set_notification_controller(self._nc)
def _on_view_cleared(self, *args):