Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/rpms/sugar/0155-sdxo-1592-PART-2-Incorporating-Age-Page-at-boot-up.patch
blob: 44d58d5ac61b3a45028519460cf4f92fdb5dc623 (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
148
149
150
151
152
153
154
155
From bc0718f0b8e089bf344e98f789e6d7a68c39e97a Mon Sep 17 00:00:00 2001
From: Ajay Garg <ajay@activitycentral.com>
Date: Thu, 20 Sep 2012 00:56:53 +0530
Subject: [PATCH 2/2] sdxo#1592 [PART-2]: Incorporating "Age"-Page-at-boot-up.
Organization: Sugar Labs Foundation
Signed-off-by: Ajay Garg <ajay@activitycentral.com>
---
 src/jarabe/intro/window.py |   75 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/src/jarabe/intro/window.py b/src/jarabe/intro/window.py
index a6a2a29..daa0c72 100644
--- a/src/jarabe/intro/window.py
+++ b/src/jarabe/intro/window.py
@@ -36,12 +36,29 @@ from jarabe.intro import colorpicker
 _BACKGROUND_COLOR = style.COLOR_WHITE
 
 
-def create_profile(name, color=None):
+def create_profile(name, age, color=None):
     if not color:
         color = XoColor()
 
     client = gconf.client_get_default()
     client.set_string('/desktop/sugar/user/nick', name)
+
+    # Algorithm to generate the timestamp of the birthday of the
+    # XO-user ::
+    #
+    # timestamp = current_timestamp - [age * (365 * 24 * 60 * 60)]
+    #
+    # Note that, this timestamp may actually (in worst-case) be
+    # off-target by 1 year, but that is ok, since we want an
+    # "approximate" age of the XO-user (for statistics-collection).
+    import time
+    current_timestamp = time.time()
+    xo_user_age_as_timestamp = int(age) * 365 * 24 * 60 * 60
+
+    approx_timestamp_at_user_birthday = current_timestamp - xo_user_age_as_timestamp
+    client.set_int('/desktop/sugar/user/birth_timestamp', int(approx_timestamp_at_user_birthday))
+    # Done.
+
     client.set_string('/desktop/sugar/user/color', color.to_string())
     client.suggest_sync()
 
@@ -89,6 +106,42 @@ class _Page(gtk.VBox):
         pass
 
 
+class _AgePage(_Page):
+    def __init__(self, intro):
+        _Page.__init__(self)
+        self._intro = intro
+
+        alignment = gtk.Alignment(0.5, 0.5, 0, 0)
+        self.pack_start(alignment, expand=True, fill=True)
+
+        hbox = gtk.HBox(spacing=style.DEFAULT_SPACING)
+        alignment.add(hbox)
+
+        label = gtk.Label(_('Age:'))
+        hbox.pack_start(label, expand=False)
+
+        adjustment = gtk.Adjustment(0, 0, 1000, 1, 0, 0)
+        self._entry = gtk.SpinButton(adjustment)
+        self._entry.props.editable = False
+        self._entry.connect('notify::text', self._text_changed_cb)
+        self._entry.set_max_length(15)
+        hbox.pack_start(self._entry, expand=False)
+
+        label = gtk.Label(_('years'))
+        hbox.pack_start(label, expand=False)
+
+
+    def _text_changed_cb(self, entry, pspec):
+        valid = int(entry.props.text) > 0
+        self.set_valid(valid)
+
+    def get_age(self):
+        return self._entry.props.text
+
+    def activate(self):
+        self._entry.grab_focus()
+
+
 class _NamePage(_Page):
     def __init__(self, intro):
         _Page.__init__(self)
@@ -146,13 +199,15 @@ class _ColorPage(_Page):
 class _IntroBox(gtk.VBox):
     __gsignals__ = {
         'done': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                 ([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
+                 ([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
     }
 
     PAGE_NAME = 0
-    PAGE_COLOR = 1
+    PAGE_AGE = 1
+    PAGE_COLOR = 2
 
     PAGE_FIRST = PAGE_NAME
+    PAGE_SECOND = PAGE_AGE
     PAGE_LAST = PAGE_COLOR
 
     def __init__(self):
@@ -161,6 +216,7 @@ class _IntroBox(gtk.VBox):
 
         self._page = self.PAGE_NAME
         self._name_page = _NamePage(self)
+        self._age_page = _AgePage(self)
         self._color_page = _ColorPage()
         self._current_page = None
         self._next_button = None
@@ -183,6 +239,8 @@ class _IntroBox(gtk.VBox):
 
         if self._page == self.PAGE_NAME:
             self._current_page = self._name_page
+        if self._page == self.PAGE_AGE:
+            self._current_page = self._age_page
         elif self._page == self.PAGE_COLOR:
             self._current_page = self._color_page
 
@@ -251,9 +309,10 @@ class _IntroBox(gtk.VBox):
 
     def done(self):
         name = self._name_page.get_name()
+        age = self._age_page.get_age()
         color = self._color_page.get_color()
 
-        self.emit('done', name, color)
+        self.emit('done', name, age, color)
 
 
 class IntroWindow(gtk.Window):
@@ -272,12 +331,12 @@ class IntroWindow(gtk.Window):
         self._intro_box.show()
         self.connect('key-press-event', self.__key_press_cb)
 
-    def _done_cb(self, box, name, color):
+    def _done_cb(self, box, name, age, color):
         self.hide()
-        gobject.idle_add(self._create_profile_cb, name, color)
+        gobject.idle_add(self._create_profile_cb, name, age, color)
 
-    def _create_profile_cb(self, name, color):
-        create_profile(name, color)
+    def _create_profile_cb(self, name, age, color):
+        create_profile(name, age, color)
         gtk.main_quit()
 
         return False
-- 
1.7.4.4