Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/deviceicon/feedback.py
blob: dc40a6eeb3154d19da05ef9a42cb0c923a62c3b8 (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
# Copyright (C) Mukesh Gupta <mukeshgupta.2006@gmail.com>
#
# 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 logging
from gettext import gettext as _
import gconf
import gtk
from sugar.graphics import style
from sugar.graphics.tray import TrayIcon
from sugar.graphics.palette import Palette
from sugar.graphics.xocolor import XoColor
from jarabe.model import feedback_collector
from jarabe.view import launcher
from sugar.activity import activityfactory
from jarabe.model import bundleregistry
from sugar.activity.activityhandle import ActivityHandle

_ICON_NAME = 'feedback-icon'

class DeviceView(TrayIcon):
    FRAME_POSITION_RELATIVE = 500
    def __init__(self):
        client = gconf.client_get_default()
        self._color = XoColor(client.get_string('/desktop/sugar/user/color'))
        TrayIcon.__init__(self, icon_name=_ICON_NAME, xo_color=self._color)
        self.create_palette()
            
    def create_palette(self):
        logging.debug('palette created')
        self.palette = BugsPalette(_('Bugs'))
        self.palette.set_group_id('frame')
        return self.palette


class BugsPalette(Palette):  
    
    def __init__(self, primary_text):
        Palette.__init__(self, primary_text)
        self._level = 0        
        self._status_label = gtk.Label()
        self._status_label.show()
        self.vbox = gtk.VBox()        
        self.hbox = gtk.HBox()              
        self.set_content(self.vbox)
        self._bugs_count_text = gtk.Label()
        self.vbox.pack_start(self._bugs_count_text,
         padding = style.DEFAULT_PADDING)                      
        self.vbox.pack_start(self.hbox, padding = style.DEFAULT_PADDING)
        self.vbox.show()        
        self.hbox.pack_start(self._status_label,
         padding = style.DEFAULT_PADDING)
        self.hbox.show()        
        self._open_log_button = gtk.Button("Open Log")
        self._open_log_button.connect("clicked",
         self.__open_log_activity)
        self.hbox.pack_start(self._open_log_button,
         padding = style.DEFAULT_PADDING)        
        self._send_report_button = gtk.Button("Send Report")
        self._send_report_button.connect("clicked", self.__send_bug_report)
        self.hbox.pack_start(self._send_report_button,
         padding = style.DEFAULT_PADDING)       
        self.__get_bug_count()
        self._bugs_count_text.show()
        self._open_log_button.show()
        self._send_report_button.show()        
    
    def popup(self, immediate=False, state=None):
        Palette.popup(self, immediate=immediate, state=state)
        self.__update_bug_palette()
        
        
    def __send_bug_report(self, button):
        feedback_collector.submit()
        
    def __open_log_activity(self, path):
        
        registry = bundleregistry.get_registry()
        bundle = registry.get_bundle('org.laptop.Log')
        activity_id = activityfactory.create_activity_id()
        client = gconf.client_get_default()
        xo_color = XoColor(client.get_string('/desktop/sugar/user/color'))
        launcher.add_launcher(activity_id, bundle.get_icon(), xo_color)
        activityfactory.create(bundle, ActivityHandle(activity_id))
            
    def __get_bug_count(self):
        """This method returns the total error count"""
        bugs_count = 0
        
        
        return bugs_count
    
    def __update_bug_palette(self):        
        bugs_count = self.__get_bug_count()    
        self._open_log_button.set_sensitive(False)
        have_reports, have_errors = feedback_collector.stat()
        #have_reports, have_errors=[True,False]
        if have_errors:
            self._open_log_button.set_sensitive(True)
        else:
            self._open_log_button.set_sensitive(False)
        
                
        if have_reports:
            self._send_report_button.set_sensitive(True)
        else:
            self._send_report_button.set_sensitive(False)
                    
        if bugs_count == 0:        
            self._bugs_count_text.set_label('No Errors')
        else :            
            self._bugs_count_text.set_label(_('Total Errors: %d' %  bugs_count))
 
def setup(tray):
    client = gconf.client_get_default()
    if client.get_bool('/desktop/sugar/feedback/enabled'):
        tray.add_device(DeviceView())