[Merge] ~nteodosio/software-properties:ubuntu/master into software-properties:ubuntu/master
Sebastien Bacher
mp+434360 at code.launchpad.net
Wed Dec 14 14:25:13 UTC 2022
Review: Needs Fixing
Thanks Nathan. I think you don't need to 'import requests' anymore now?
I've also added some notes about strings that don't seem set be translated?
Diff comments:
> diff --git a/softwareproperties/gtk/DialogUaAttach.py b/softwareproperties/gtk/DialogUaAttach.py
> index 4649545..a7caf6d 100644
> --- a/softwareproperties/gtk/DialogUaAttach.py
> +++ b/softwareproperties/gtk/DialogUaAttach.py
> @@ -36,49 +36,126 @@ class DialogUaAttach:
> self.dialog.set_transient_for(parent)
>
> self.attaching = False
> + self.poll = None
> + self.pin_label_box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(0.5, 0.5, 0.5, 0.5))
> +
> + self.start_magic_attach()
>
> def run(self):
> self.dialog.run()
> self.dialog.hide()
>
> - def update_state(self):
> - have_token = self.entry_token.get_text() != ''
> - self.button_attach.set_sensitive(have_token and not self.attaching)
> - self.entry_token.set_sensitive(not self.attaching)
> - if self.attaching:
> - self.spinner.start()
> + def update_state(self, case = None):
> + """
> + fail : called by the attachment callback, and it failed.
> + success: called by the attachment callback, and it succeeded.
> + expired: called by the token polling when the token expires.
> + """
> + if self.token_radio.get_active():
> + self.pin_label.set_opacity(0)
> + icon = self.token_status_icon
> + spinner = self.token_spinner
> + status = self.token_status
> else:
> - self.spinner.stop()
> + self.pin_label.set_text(self.pin)
> + self.pin_label.set_opacity(1)
> + icon = self.pin_status_icon
> + spinner = self.pin_spinner
> + status = self.pin_status
>
> - def attach(self):
> if self.attaching:
> - return
> + spinner.start()
> + else:
> + spinner.stop()
> +
> + self.token_radio.set_sensitive(not self.attaching)
> + self.magic_radio.set_sensitive(not self.attaching)
> + self.token_field.set_sensitive(not self.attaching
> + and self.token_radio.get_active())
>
> - token = self.entry_token.get_text()
> - if token == '':
> + if (case == "fail"):
> + status.set_markup('<span foreground="red">Invalid token</span>')
shouldn't it use _() to set the string as translatable?
> + icon.set_from_icon_name('emblem-unreadable', 1)
> + elif (case == "success"):
> + status.set_markup('<span foreground="green">Valid token</span>')
and that one?
> + icon.set_from_icon_name('emblem-default', 1)
> + self.finish()
> + elif (case == "expired"):
> + status.set_markup('Code expired')
and that one?
> + icon.set_from_icon_name('gtk-dialog-warning', 1)
> + #Only show icons/status if case is set
> + self.token_status_icon.set_visible(False)
> + self.token_status.set_visible(False)
> + self.pin_status_icon.set_visible(False)
> + self.pin_status.set_visible(False)
> + icon.set_visible(case)
> + status.set_visible(case)
> +
> + def attach(self, token):
> + if self.attaching:
> return
>
> self.attaching = True
> - self.label_attach_error.set_text('')
> def on_reply():
> - self.dialog.response(Gtk.ResponseType.OK)
> + self.attaching = False
> + self.update_state("success")
> def on_error(error):
> - # FIXME
> - print(error)
> - self.label_attach_error.set_text(_('Failed to attach. Please try again'))
> self.attaching = False
> - self.update_state()
> + self.update_state("fail")
> self.ua_object.Attach(token, reply_handler=on_reply, error_handler=on_error, dbus_interface='com.canonical.UbuntuAdvantage.Manager', timeout=600)
> self.update_state()
>
> - def on_token_entry_changed(self, entry):
> - self.update_state()
> -
> def on_token_entry_activate(self, entry):
> - self.attach()
> -
> - def on_attach_clicked(self, button):
> - self.attach()
> + token = self.token_field.get_text()
> + if token != '':
> + self.attach(token)
>
> def on_cancel_clicked(self, button):
> + if self.poll:
> + GLib.Thread.unref(self.poll)
> self.dialog.response(Gtk.ResponseType.CANCEL)
> +
> + def on_confirm_clicked(self, button):
> + self.dialog.response(Gtk.ResponseType.OK)
> +
> + def poll_for_magic_token(self):
> + options = MagicAttachWaitOptions(magic_token=self.req_id)
> + try:
> + response = wait(options)
> + contract_token = response.contract_token
> + self.attach(contract_token)
> + except MagicAttachTokenError:
> + self.update_state('expired')
> + finally:
> + self.poll = None
> +
> + def start_magic_attach(self):
> + # Already polling, don't bother the server with a new request.
> + if self.poll != None:
> + return
> +
> + # Request a magic attachment and parse relevants fields from response.
> + # userCode: The pin the user has to type in <ubuntu.com/pro/attach>;
> + # token: Identifies the request (used for polling for it).
> + try:
> + response = initiate()
> + self.pin = response.user_code
> + self.req_id = response.token
> + except Exception as e:
> + print(e)
> + return
> + self.update_state()
> + self.poll = GLib.Thread.new("poll", self.poll_for_magic_token)
> +
> + def on_radio_toggled(self, button):
> + self.update_state()
> +
> + def on_magic_radio_clicked(self, button):
> + self.start_magic_attach()
> +
> + def finish(self):
> + self.token_field.set_sensitive(False)
> + self.magic_radio.set_sensitive(False)
> + self.token_radio.set_sensitive(False)
> + self.confirm.set_sensitive(True)
> + self.cancel.set_sensitive(False)
--
https://code.launchpad.net/~nteodosio/software-properties/+git/software-properties/+merge/434360
Your team Ubuntu Core Development Team is subscribed to branch software-properties:ubuntu/master.
More information about the Ubuntu-reviews
mailing list