3
from gettext import gettext as _
5
from gi.repository import Gio, Gtk, Notify
7
from landscape.ui.model.configuration.proxy import ConfigurationProxy
8
from landscape.ui.model.configuration.state import ConfigurationModel
9
from landscape.ui.model.configuration.uisettings import UISettings
10
from landscape.ui.view.configuration import ClientSettingsDialog
11
from landscape.ui.controller.configuration import ConfigController
14
APPLICATION_ID = "com.canonical.landscape-client.settings.ui"
15
NOTIFY_ID = "Landscape management service"
18
class SettingsApplicationController(Gtk.Application):
20
Core application controller for the landscape settings application.
23
def __init__(self, args=[]):
24
super(SettingsApplicationController, self).__init__(
25
application_id=APPLICATION_ID)
27
self.connect("activate", self.setup_ui)
30
return ConfigurationProxy()
32
def get_uisettings(self):
33
return UISettings(Gio.Settings)
35
def on_notify(self, message):
36
notification = Notify.Notification.new(NOTIFY_ID, message,
40
def on_error(self, message):
41
notification = Notify.Notification.new(NOTIFY_ID, message,
45
def on_succeed(self, action=None):
49
message = _("Success.")
50
notification = Notify.Notification.new(NOTIFY_ID, message,
54
def on_fail(self, action=None):
58
message = _("Failure.")
59
notification = Notify.Notification.new(NOTIFY_ID, message,
63
def setup_ui(self, data=None, asynchronous=True):
65
L{setup_ui} wires the model to the L{ConfigurationController} and then
66
invokes the view with the controller. When the dialog exits
67
appropriate termination is triggered.
69
@param data: the Gtk callback could pass this, but it is always None in
71
@param asynchronous: a parameter passed through to
72
L{ConfigurationController.exit}, it indicates whether the exit method
73
should be called asynchronously. Is makes testing easier to use it
76
Notify.init(NOTIFY_ID)
77
config = self.get_config()
78
uisettings = self.get_uisettings()
79
model = ConfigurationModel(proxy=config, proxy_loadargs=self._args,
80
uisettings=uisettings)
81
controller = ConfigController(model)
83
self.settings_dialog = ClientSettingsDialog(controller)
84
if self.settings_dialog.run() == Gtk.ResponseType.OK:
85
controller.persist(self.on_notify, self.on_error,
86
self.on_succeed, self.on_fail)
87
controller.exit(asynchronous=asynchronous)
88
self.settings_dialog.destroy()
90
self.on_fail(action=_("Authentication failed"))
91
sys.stderr.write("Authentication failed.\n")