~landscape/landscape-client/production

« back to all changes in this revision

Viewing changes to landscape/ui/controller/app.py

  • Committer: Tarmac
  • Date: 2016-03-16 22:18:31 UTC
  • mfrom: (2.2.238 staging)
  • Revision ID: landscape-devel@lists.canonical.com-20160316221831-m3ojfadotdbp20w8
Tags: release-39
Merging from staging for production deployment of release-39

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import sys
2
 
 
3
 
from gettext import gettext as _
4
 
 
5
 
from gi.repository import Gio, Gtk, Notify
6
 
 
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
12
 
 
13
 
 
14
 
APPLICATION_ID = "com.canonical.landscape-client.settings.ui"
15
 
NOTIFY_ID = "Landscape management service"
16
 
 
17
 
 
18
 
class SettingsApplicationController(Gtk.Application):
19
 
    """
20
 
    Core application controller for the landscape settings application.
21
 
    """
22
 
 
23
 
    def __init__(self, args=[]):
24
 
        super(SettingsApplicationController, self).__init__(
25
 
            application_id=APPLICATION_ID)
26
 
        self._args = args
27
 
        self.connect("activate", self.setup_ui)
28
 
 
29
 
    def get_config(self):
30
 
        return ConfigurationProxy()
31
 
 
32
 
    def get_uisettings(self):
33
 
        return UISettings(Gio.Settings)
34
 
 
35
 
    def on_notify(self, message):
36
 
        notification = Notify.Notification.new(NOTIFY_ID, message,
37
 
                                               "dialog-information")
38
 
        notification.show()
39
 
 
40
 
    def on_error(self, message):
41
 
        notification = Notify.Notification.new(NOTIFY_ID, message,
42
 
                                               "dialog-information")
43
 
        notification.show()
44
 
 
45
 
    def on_succeed(self, action=None):
46
 
        if action:
47
 
            message = action
48
 
        else:
49
 
            message = _("Success.")
50
 
        notification = Notify.Notification.new(NOTIFY_ID, message,
51
 
                                               "dialog-information")
52
 
        notification.show()
53
 
 
54
 
    def on_fail(self, action=None):
55
 
        if action:
56
 
            message = action
57
 
        else:
58
 
            message = _("Failure.")
59
 
        notification = Notify.Notification.new(NOTIFY_ID, message,
60
 
                                               "dialog-information")
61
 
        notification.show()
62
 
 
63
 
    def setup_ui(self, data=None, asynchronous=True):
64
 
        """
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.
68
 
 
69
 
        @param data: the Gtk callback could pass this, but it is always None in
70
 
        practice.
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
74
 
        synchronously.
75
 
        """
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)
82
 
        if controller.load():
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()
89
 
        else:
90
 
            self.on_fail(action=_("Authentication failed"))
91
 
            sys.stderr.write("Authentication failed.\n")