diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-12-27 00:51:25 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-12-27 11:19:47 +0100 |
commit | 98be3a205405a97954cda18926a2a8d366bfb1e3 (patch) | |
tree | 11500de67107dd48a3a20de8cd92d0eb19164844 | |
parent | 1448c4de0cdebfe68f538da2ea28b81a564e86f5 (diff) |
Fetch length top-up code attribute from providerdb if available
-rw-r--r-- | src/ppm.ui | 13 | ||||
-rw-r--r-- | src/ppm/provider.py | 11 | ||||
-rw-r--r-- | src/ppm/providerdb.py | 8 | ||||
-rwxr-xr-x | src/prepaid-manager-applet.py | 35 |
4 files changed, 51 insertions, 16 deletions
@@ -14,9 +14,9 @@ <property name="can_focus">False</property> <child> <object class="GtkMenuItem" id="menu_item_file"> + <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="use_action_appearance">False</property> <property name="label" translatable="yes">_File</property> <property name="use_underline">True</property> <child type="submenu"> @@ -26,9 +26,9 @@ <child> <object class="GtkImageMenuItem" id="menuitem_quit"> <property name="label">gtk-quit</property> + <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="use_action_appearance">False</property> <property name="use_underline">True</property> <property name="use_stock">True</property> <signal name="activate" handler="on_close_clicked" swapped="no"/> @@ -40,9 +40,9 @@ </child> <child> <object class="GtkMenuItem" id="menuitem_help"> + <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="use_action_appearance">False</property> <property name="label" translatable="yes">_Help</property> <property name="use_underline">True</property> <child type="submenu"> @@ -52,9 +52,9 @@ <child> <object class="GtkImageMenuItem" id="imagemenuitem_about"> <property name="label">gtk-about</property> + <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="use_action_appearance">False</property> <property name="use_underline">True</property> <property name="use_stock">True</property> <signal name="activate" handler="on_about_activated" swapped="no"/> @@ -119,6 +119,7 @@ <child> <object class="GtkButton" id="button_provider_change"> <property name="label" translatable="yes">change</property> + <property name="use_action_appearance">False</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="has_tooltip">True</property> @@ -188,6 +189,7 @@ <child> <object class="GtkButton" id="button_check_balance"> <property name="label" translatable="yes">check</property> + <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -264,6 +266,7 @@ <child> <object class="GtkButton" id="button_provider_change1"> <property name="label" translatable="yes">change</property> + <property name="use_action_appearance">False</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_action_appearance">False</property> @@ -280,6 +283,7 @@ <child> <object class="GtkButton" id="button_top_up"> <property name="label" translatable="yes">top up</property> + <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="sensitive">False</property> <property name="can_focus">True</property> @@ -310,6 +314,7 @@ <property name="tooltip_text" translatable="yes">Enter code to top up credit to your prepaid card.</property> <property name="invisible_char">●</property> <property name="invisible_char_set">True</property> + <property name="placeholder_text">01234567890123</property> <signal name="changed" handler="on_entry_code_insert" swapped="no"/> </object> <packing> diff --git a/src/ppm/provider.py b/src/ppm/provider.py index fbbd911..54bc0fe 100644 --- a/src/ppm/provider.py +++ b/src/ppm/provider.py @@ -62,6 +62,17 @@ class Provider(object): else: return False + def get_top_up_code_length(self): + """The length of the topup code""" + if self.has_top_up_cmd(): + return self.top_up_cmds['ussd'][2] + else: + return 0 + + @property + def top_up_code_length(self): + return self.get_top_up_code_length() + def fetch_balance(self, mm, reply_func=None, error_func=None): if self.has_fetch_balance_cmd(): mm.ussd_initiate (self.fetch_balance_cmds['ussd'], diff --git a/src/ppm/providerdb.py b/src/ppm/providerdb.py index db2bdc9..e2b097d 100644 --- a/src/ppm/providerdb.py +++ b/src/ppm/providerdb.py @@ -90,7 +90,13 @@ class ProviderDB(object): if t.tag == 'ussd': sequence = t.text replacement = t.attrib['replacement'] - provider.add_top_up_cmd({'ussd': [sequence, replacement]}) + try: + length = int(t.attrib['length']) + except KeyError: + length = 0 + provider.add_top_up_cmd({'ussd': [sequence, + replacement, + length]}) if t.tag == 'sms': number = t.text text = t.attrib['text'] diff --git a/src/prepaid-manager-applet.py b/src/prepaid-manager-applet.py index 25ee728..7df63e6 100755 --- a/src/prepaid-manager-applet.py +++ b/src/prepaid-manager-applet.py @@ -90,13 +90,12 @@ class PPMController(GObject.GObject): logging.error("No idea how to top up balance for " "%s in %s.", self.provider.name, self.provider.country) - def set_provider(self, provider=None, - account=None, - country_code=None, name=None): + def set_provider(self, provider=None, account=None, country_code=None, + name=None): """ Change the current provider to provider and inform the view - Input can be a provder, an account or, (name, country_code) + Input can be a provider, an account or (name, country_code) Once finished we know how to access account balance, top up, etc. """ if account: @@ -254,6 +253,7 @@ class PPMController(GObject.GObject): logging.debug("Provider changed to '%s'", provider.name) self.view.update_provider_name(provider.name) + self.view.update_topup_length(provider.top_up_code_length) if self.imsi and not self.account: # We have an imsi and the user told us what provider to use: @@ -345,6 +345,7 @@ class PPMDialog(GObject.GObject, PPMObject): def __init__(self, controller): GObject.GObject.__init__(self) PPMObject.__init__(self, None, "ppm") + self.code_len = 0 self.controller = controller # Register ourself to the controller self.controller.view = self @@ -352,7 +353,6 @@ class PPMDialog(GObject.GObject, PPMObject): self._setup_ui() self.dialog.show() - def close(self): self.dialog.hide() self.dialog.destroy() @@ -388,16 +388,29 @@ class PPMDialog(GObject.GObject, PPMObject): # and communicate the change to the controller raise NotImplementedError - def on_entry_code_insert(self, *args): - if self.entry_code.get_text(): - self.button_top_up.set_sensitive(True) - else: - self.button_top_up.set_sensitive(False) + def on_entry_code_insert(self, entry): + cur_len = entry.get_text_length() + sensitive = True + + if self.code_len > 0: + self.entry_code.set_progress_fraction(float(cur_len) / + self.code_len) + if cur_len != self.code_len: + sensitive = False + self.button_top_up.set_sensitive(sensitive) def update_provider_name(self, provider_name): self.label_balance_provider_name.set_text(provider_name) self.label_topup_provider_name.set_text(provider_name) + def update_topup_length(self, len): + """Adjust GtkEntry to the length of the top up code""" + placeholder = '' + self.code_len = len + if len: + placeholder = "".join([ str(x)[-1] for x in range(1, len+1) ]) + self.entry_code.set_placeholder_text(placeholder) + def update_account_balance_information(self, balance_text, timestamp): self.label_balance_info.set_text(balance_text) self.label_balance_timestamp.set_text(timestamp) @@ -703,7 +716,7 @@ class PPMProviderInfoMissingDialog(object): msg = self.messages['balance_info_missing'] % provider.name self._run(msg) - def top_up_info_missing(self, provider): + def top_upinfo_missing(self, provider): msg = self.messages['top_up_info_missing'] % provider.name self._run(msg) |