summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-06-13 15:00:37 +0200
committerGuido Günther <agx@sigxcpu.org>2011-12-27 11:19:47 +0100
commit08274f34113d87940e949a1a77f9c51e16c70847 (patch)
tree8a99164884e9884302daf57eaf16e7b798bf987c
parent5822451c4fde1935185f543a4bf563404ecadea7 (diff)
Use Infobar instead of modal dialogs
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/ppm-modem-request.ui64
-rw-r--r--src/ppm.ui10
-rw-r--r--src/ppm/modemproxy.py3
-rwxr-xr-xsrc/prepaid-manager-applet.py181
5 files changed, 138 insertions, 121 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 234ed71..355848b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,5 @@
data/org.gnome.PrepaidManager.gschema.xml.in.in
[type: gettext/glade]src/ppm.ui
-[type: gettext/glade]src/ppm-modem-request.ui
[type: gettext/glade]src/ppm-provider-assistant.ui
src/prepaid-manager-applet.desktop.in
src/prepaid-manager-applet.py
diff --git a/src/ppm-modem-request.ui b/src/ppm-modem-request.ui
deleted file mode 100644
index a876ca6..0000000
--- a/src/ppm-modem-request.ui
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0"?>
-<interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy project-wide -->
- <object class="GtkDialog" id="ppm_modem_request">
- <property name="border_width">5</property>
- <property name="title" translatable="yes">Prepaid Manager</property>
- <property name="resizable">False</property>
- <property name="modal">True</property>
- <property name="destroy_with_parent">True</property>
- <property name="type_hint">dialog</property>
- <property name="skip_taskbar_hint">True</property>
- <property name="skip_pager_hint">True</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox1">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkLabel" id="label_processing">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Sending request to modem</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">10</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkProgressBar" id="progressbar">
- <property name="visible">True</property>
- <property name="show_text">True</property>
- <property name="text" translatable="yes">Waiting for reply...</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">10</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area1">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- </object>
-</interface>
diff --git a/src/ppm.ui b/src/ppm.ui
index bbc05b7..67dda93 100644
--- a/src/ppm.ui
+++ b/src/ppm.ui
@@ -5,7 +5,7 @@
<property name="can_focus">False</property>
<signal name="delete-event" handler="on_delete" swapped="no"/>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkVBox" id="vbox_main">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -13,7 +13,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkMenuItem" id="menu_filee">
+ <object class="GtkMenuItem" id="menu_item_file">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
@@ -72,6 +72,9 @@
</packing>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -369,7 +372,8 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="pack_type">end</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
diff --git a/src/ppm/modemproxy.py b/src/ppm/modemproxy.py
index c9a7662..fddea25 100644
--- a/src/ppm/modemproxy.py
+++ b/src/ppm/modemproxy.py
@@ -49,9 +49,10 @@ class ModemManagerProxy(GObject.GObject):
MM_DBUS_TIMEOUT = 5000
__gsignals__ = {
- # Emitted when we got the new account balance from the provider
+ # Emitted when a request to MM starts
'request-started': (GObject.SignalFlags.RUN_FIRST, None,
[object]),
+ # Emitted when a request has finished
'request-finished': (GObject.SignalFlags.RUN_FIRST, None,
[object]),
}
diff --git a/src/prepaid-manager-applet.py b/src/prepaid-manager-applet.py
index 682e170..50b28ab 100755
--- a/src/prepaid-manager-applet.py
+++ b/src/prepaid-manager-applet.py
@@ -144,7 +144,9 @@ class PPMController(GObject.GObject):
return self.account
def init_account_and_provider(self):
- """Fetch the imsi deduce account and provider information"""
+ """Fetch the imsi and deduce account and provider information"""
+
+ logging.debug("Fetching account information")
try:
self.imsi = self.mm.get_imsi()
except ModemError as me:
@@ -156,12 +158,9 @@ class PPMController(GObject.GObject):
self.view.show_modem_error(me.msg)
return False
- logging.info("modem not enabled")
- if self.view.show_modem_enable() != Gtk.ResponseType.YES:
- return False
- else:
- self.mm.modem_enable(reply_func=self.init_account_and_provider)
- return True
+ logging.info("modem not enabled.")
+ self.view.show_modem_enable()
+ return False
try:
account = self._get_account_from_accountdb(self.imsi)
@@ -183,7 +182,7 @@ class PPMController(GObject.GObject):
return False
def setup(self):
- logging.debug("Setting up")
+ logging.debug("Setting up")
self.mm = ModemManagerProxy()
self._connect_mm_signals()
@@ -194,11 +193,19 @@ class PPMController(GObject.GObject):
logging.debug("Using modem %s" % modem)
self.mm.set_modem(modem)
GObject.timeout_add(500, self.init_account_and_provider)
- else:
- self.view.show_error("No modem found.")
- self.quit()
+ else:
+ self.view.show_no_modem_found()
return False
+ def schedule_setup(self):
+ """Schedule another run of setup"""
+ GObject.timeout_add(1, self.setup)
+
+ def enable_modem(self):
+ """Enable the modem"""
+ self.mm.modem_enable(reply_func=self.on_modem_enable,
+ error_func=self.on_modem_error)
+
def quit(self):
"""Clean up"""
logging.debug("Quitting...")
@@ -229,6 +236,15 @@ class PPMController(GObject.GObject):
reply = var.unpack()[0]
self.view.update_top_up_information(reply)
+ def on_modem_enable(self, var, user_data):
+ """Callback for succesful MM enable modem call"""
+ GObject.timeout_add(500, self.init_account_and_provider)
+
+ def on_modem_enable_error(self, e):
+ """Callback for failed MM enable modem call"""
+ self.on_modem_error(e)
+ GObject.timeout_add(500, self.init_account_and_provider)
+
def on_modem_error(self, e):
self.view.show_modem_error(e.msg)
logging.error(e.msg)
@@ -302,11 +318,16 @@ class PPMDialog(GObject.GObject, PPMObject):
license_type = Gtk.License.GPL_3_0)
def _init_subdialogs(self):
+ """Init dialogs shown from the main window"""
self.provider_info_missing_dialog = PPMProviderInfoMissingDialog(self)
self.provider_assistant = PPMProviderAssistant(self)
- self.modem_response = PPMModemResponse(self)
self._init_about_dialog()
+ def _init_infobars(self):
+ self.enable_modem_info_bar = PPMEnableModemInfoBar(self)
+ self.modem_response_info_bar = PPMModemResponseInfoBar(self)
+ self.no_modem_found_info_bar = PPMNoModemFoundInfoBar(self)
+
def _setup_ui(self):
self.dialog = self.builder.get_object("ppm_dialog")
self._add_elements("label_balance_provider_name",
@@ -316,7 +337,9 @@ class PPMDialog(GObject.GObject, PPMObject):
"label_balance_from",
"entry_code",
"button_top_up",
- "label_top_up_reply")
+ "label_top_up_reply",
+ "vbox_main")
+ self._init_infobars()
self._init_subdialogs()
def __init__(self, controller):
@@ -329,10 +352,16 @@ class PPMDialog(GObject.GObject, PPMObject):
self._setup_ui()
self.dialog.show()
+
def close(self):
self.dialog.hide()
self.dialog.destroy()
+ @property
+ def info_bar_container(self):
+ """The widget that contains the main info bar"""
+ return self.vbox_main
+
def get_top_up_code(self):
return self.entry_code.get_text().strip()
@@ -363,7 +392,7 @@ class PPMDialog(GObject.GObject, PPMObject):
if self.entry_code.get_text():
self.button_top_up.set_sensitive(True)
else:
- self.button_top_up.set_sensitive(False)
+ self.button_top_up.set_sensitive(False)
def update_provider_name(self, provider_name):
self.label_balance_provider_name.set_text(provider_name)
@@ -401,20 +430,15 @@ class PPMDialog(GObject.GObject, PPMObject):
dialog.hide()
def show_modem_enable(self):
- """Show dialog that asks if we should enable the modem"""
- dialog = Gtk.MessageDialog(parent=self.dialog,
- flags=Gtk.DialogFlags.MODAL |
- Gtk.DialogFlags.DESTROY_WITH_PARENT,
- message_type=Gtk.MessageType.QUESTION,
- buttons=Gtk.ButtonsType.YES_NO)
- dialog.set_markup(_("Enable Modem?"))
- ret = dialog.run()
- dialog.hide()
- return ret
+ self.enable_modem_info_bar.show()
def show_provider_assistant(self, providers=None):
self.provider_assistant.show(providers)
+ def show_no_modem_found(self):
+ """Show the 'no modem found' info bar"""
+ self.no_modem_found_info_bar.show()
+
def show_error(self, msg):
"""show generic error"""
logging.debug(msg)
@@ -428,14 +452,92 @@ class PPMDialog(GObject.GObject, PPMObject):
error.hide()
def show_modem_response(self):
- self.modem_response.show()
+ self.modem_response_info_bar.show()
def close_modem_response(self):
- self.modem_response.close()
+ self.modem_response_info_bar.hide()
GObject.type_register(PPMDialog)
+
+class PPMInfoBar(object):
+ def __init__(self, view):
+ self.view = view
+ self.controller = view.controller
+ self.info_bar = Gtk.InfoBar()
+
+ def show(self):
+ self.view.info_bar_container.add(self.info_bar)
+ self.info_bar.show_all()
+
+ def hide(self):
+ self.info_bar.hide()
+ self.view.info_bar_container.remove(self.info_bar)
+ self.view.dialog.resize(1, 1)
+
+
+class PPMEnableModemInfoBar(PPMInfoBar):
+ """Info bar attached to the main window"""
+
+ def __init__(self, view):
+ PPMInfoBar.__init__(self, view)
+ self.info_bar.add_button(_("Enable"), Gtk.ResponseType.OK)
+ self.info_bar.set_message_type(Gtk.MessageType.WARNING)
+ self.msg_label = Gtk.Label(_("Modem not enabled"))
+ content_area = self.info_bar.get_content_area()
+ content_area.add(self.msg_label)
+ self.msg_label.show()
+ self.info_bar.connect("response", self.on_enable_clicked)
+
+ def on_enable_clicked(self, info_bar, response_id):
+ self.hide()
+ self.controller.enable_modem()
+
+
+class PPMModemResponseInfoBar(PPMInfoBar):
+ """Info bar used when waiting for a modem response"""
+ def __init__(self, view):
+ PPMInfoBar.__init__(self, view)
+ self.info_bar.set_message_type(Gtk.MessageType.INFO)
+ self.progressbar = Gtk.ProgressBar(text=_("Awaiting modem response..."))
+ self.progressbar.set_show_text(True)
+ content_area = self.info_bar.get_content_area()
+ content_area.add(self.progressbar)
+
+ def show(self):
+ logging.debug("Awaiting modem resonse")
+ self.timer = GObject.timeout_add(50, self.do_progress,
+ priority=GLib.PRIORITY_HIGH)
+ PPMInfoBar.show(self)
+
+ def hide(self):
+ if self.timer:
+ GObject.source_remove(self.timer)
+ self.timer = None
+ PPMInfoBar.hide(self)
+
+ def do_progress(self):
+ self.progressbar.pulse()
+ return True
+
+
+class PPMNoModemFoundInfoBar(PPMInfoBar):
+ def __init__(self, container):
+ PPMInfoBar.__init__(self, container)
+ self.info_bar.set_message_type(Gtk.MessageType.WARNING)
+ self.msg_label = Gtk.Label(_("No modem found."))
+ content_area = self.info_bar.get_content_area()
+ content_area.add(self.msg_label)
+ self.info_bar.add_button(_("Try again"), Gtk.ResponseType.OK)
+ self.info_bar.connect("response", self.on_try_again_clicked)
+
+ def on_try_again_clicked(self, info_bar, response_id):
+ logging.debug("Rescheduling modem setup")
+ self.hide()
+ self.controller.schedule_setup()
+
+
class PPMProviderAssistant(PPMObject):
PAGE_INTRO, PAGE_COUNTRIES, PAGE_PROVIDERS, PAGE_CONFIRM = range(0, 4)
@@ -611,31 +713,6 @@ class PPMProviderInfoMissingDialog(object):
self._run(msg)
-class PPMModemResponse(PPMObject):
- """Dialog shown while waiting for a response from the modem"""
- def __init__(self, main_dialog):
- PPMObject.__init__(self, main_dialog, "ppm-modem-request")
- self.dialog = self.builder.get_object("ppm_modem_request")
- self._add_elements("progressbar")
- self.dialog.set_transient_for(main_dialog.dialog)
- self.timer = None
-
- def show(self):
- self.timer = GObject.timeout_add(50, self.do_progress,
- priority=GLib.PRIORITY_HIGH)
- self.dialog.show()
-
- def close(self):
- if self.timer:
- GObject.source_remove(self.timer)
- self.timer = None
- self.dialog.hide()
-
- def do_progress(self):
- self.progressbar.pulse()
- return True
-
-
def setup_i18n():
locale.setlocale(locale.LC_ALL, '')
gettext.install(ppm.gettext_app, ppm.gettext_dir)
@@ -685,7 +762,7 @@ def main(args):
controller = PPMController()
main_dialog = PPMDialog(controller)
- GObject.timeout_add(1, controller.setup)
+ controller.schedule_setup()
Gtk.main()