Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/cpsection/smolt/view.py
blob: 0fb573f00f8f21689952b81484a918e0dfd97914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright (C) 2010 Sebastian Dziallas
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

import os
import gtk
from gettext import gettext as _

from sugar.graphics import style
from jarabe.controlpanel.sectionview import SectionView

CLASS = 'smolt'
ICON = 'module-smolt'
TITLE = _('Hardware Profile')

class smolt(SectionView):
    def __init__(self, model, alerts=None):
        SectionView.__init__(self)

        self._model = model

        self.set_border_width(style.DEFAULT_SPACING * 2)
        self.set_spacing(style.DEFAULT_SPACING)
        self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)

        scrollwindow = gtk.ScrolledWindow()
        scrollwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        self.pack_start(scrollwindow, expand=True)
        scrollwindow.show()

        self._vbox = gtk.VBox()
        scrollwindow.add_with_viewport(self._vbox)
        self._vbox.show()
        self.add(scrollwindow)

        self._smolt_submit_profile_handler = None
        self._smolt_delete_profile_handler = None

        label_smolt = gtk.Label(_('Hardware Profile'))
        label_smolt.set_alignment(0, 0)
        self._vbox.pack_start(label_smolt, expand=False)
        label_smolt.show()
        box_smolt = gtk.VBox()
        box_smolt.set_border_width(style.DEFAULT_SPACING * 2)
        box_smolt.set_spacing(style.DEFAULT_SPACING)

        smolt_info = gtk.Label(_("We invite you to create a hardware profile for your computer. "
                                 "Doing so helps software developers to diagnose possible problems. "
                                 "You can submit and then delete your profile by pressing the buttons below. "))
        smolt_info.set_alignment(0, 0)
        smolt_info.set_line_wrap(True)
        smolt_info.show()
        box_smolt.pack_start(smolt_info, expand=False)

        box_submit_profile = gtk.HBox(spacing=style.DEFAULT_SPACING)
        self._submit_profile_button = gtk.Button()
        self._submit_profile_button.set_label(_('Submit Profile'))
        box_submit_profile.pack_start(self._submit_profile_button, expand=False)
        self._submit_profile_button.show()
        box_smolt.pack_start(box_submit_profile, expand=False)
        box_submit_profile.show()

        if os.path.exists(os.getenv("HOME") + '/.smolt/uuiddb.cfg'):
            box_delete_profile = gtk.HBox(spacing=style.DEFAULT_SPACING)
            self._delete_profile_button = gtk.Button()
            self._delete_profile_button.set_label(_('Delete Profile'))
            box_delete_profile.pack_start(self._delete_profile_button, expand=False)
            self._delete_profile_button.show()
            box_smolt.pack_start(box_delete_profile, expand=False)
            box_delete_profile.show()

        box_profile = gtk.HBox(spacing=style.DEFAULT_SPACING)
        label_profile = gtk.Label(_('Profile:'))
        label_profile.set_alignment(1, 0)
        label_profile.modify_fg(gtk.STATE_NORMAL, 
                              style.COLOR_SELECTION_GREY.get_gdk_color())
        box_profile.pack_start(label_profile, expand=False)
        self._group.add_widget(label_profile)
        label_profile.show()
        label_profile_url = gtk.Label(self._model.get_profile_url())
        label_profile_url.set_alignment(0, 0)
        box_profile.pack_start(label_profile_url, expand=False)
        label_profile_url.show()
        box_smolt.pack_start(box_profile, expand=False)
        box_profile.show()

        self._vbox.pack_start(box_smolt, expand=False)
        box_smolt.show()

        self._setup_submit()
        self._setup_policy()

        if os.path.exists(os.getenv("HOME") + '/.smolt/uuiddb.cfg'):
            self._setup_delete()

    def _setup_submit(self):
        self._smolt_submit_profile_handler =  \
                self._submit_profile_button.connect( \
                        'clicked', self.smolt_submit_profile_cb)

    def smolt_submit_profile_cb(self, widget):
        self._model.submit_profile()

    def _setup_delete(self):
        self._smolt_delete_profile_handler =  \
                self._delete_profile_button.connect( \
                        'clicked', self.smolt_delete_profile_cb)

    def smolt_delete_profile_cb(self, widget):
        self._model.delete_profile()

    def _setup_policy(self):
        separator_policy = gtk.HSeparator()
        self._vbox.pack_start(separator_policy, expand=False)
        separator_policy.show()

        vbox_policy = gtk.VBox()
        vbox_policy.set_border_width(style.DEFAULT_SPACING * 2)
        vbox_policy.set_spacing(style.DEFAULT_SPACING)

        expander = gtk.Expander(_("Privacy Policy"))
        expander.connect("notify::expanded", self.policy_expander_cb)
        expander.show()
        vbox_policy.pack_start(expander, expand=True)

        self._vbox.pack_start(vbox_policy, expand=True)
        vbox_policy.show()

    def policy_expander_cb(self, expander, param_spec):
        if expander.get_expanded():
            view_policy = gtk.TextView()
            view_policy.set_editable(False)
            view_policy.get_buffer().set_text(self._model.get_policy())
            view_policy.show()
            expander.add(view_policy)