示例#1
0
    def _create_widgets(self):

        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

        #Password
        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()
        self.password_entry.set_activates_default(True)

        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))

        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)

        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)

        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))

        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                              _("settings"))

        #Container
        self.hbox = HIGHBox(False, 2)
        self.table = HIGTable(8, 4, False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)

        #tab orders
        self.orders = [
            self.username_entry, self.password_entry, self.register_button,
            self.forgot_password
        ]
    def _create_widgets(self):
        self.category_label = HIGHintSectionLabel(
            _("Category (optional)"),
            _("If you know in which section of the program "
              "is the bug, please, select it from the choosebox. "
              "If you don't know what section to choose, leave it blank."))
        self.category_list = gtk.ListStore(str, str)
        self.category_combo = gtk.ComboBoxEntry(self.category_list, 0)

        self.email_label = HIGHintSectionLabel(
            _("Email"),
            _("Please inform a valid e-mail address from "
              "where you can be reached to be notified when the bug gets "
              "fixed. Not used for other purposes."))
        self.email_entry = gtk.Entry()

        self.summary_label = HIGHintSectionLabel(
            _("Summary"),
            _("This should be a quick description of the issue. "
              "Try to be clear and concise."))
        self.summary_entry = gtk.Entry()

        self.description_label = HIGHintSectionLabel(
            _("Description"),
            _("This is where you should write about the bug, "
              "describing it as clear as possible and giving as many "
              "informations as you can and how to reproduce the bug."))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_icon = gtk.Image()
        self.bug_text = gtk.Label(
            _("This Bug Report dialog allows you "
              "to easily tell us about a problem that you may have found on "
              "Open Monitor. Doing so, you help us to help you, by fixing and "
              "improving Open Monitor faster than usual."))

        if self.crashreport:
            # Create a button to show details
            self.show_details = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                               _("Show Details"))

        self.hbox = HIGHBox()
        self.table = HIGTable()
示例#3
0
    def _create_widgets(self):
        
        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

        #Password
        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()
        self.password_entry.set_activates_default(True)
        
        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))
        
        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)
        
        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)
        
        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))
        
        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("settings"))
        
        #Container
        self.hbox = HIGHBox(False,2)
        self.table = HIGTable(8,4,False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
        
        #tab orders
        self.orders = [self.username_entry, self.password_entry, self.register_button, self.forgot_password]
示例#4
0
 def __create_widgets(self):
     # Main widgets
     self.hpaned = gtk.HPaned()
     self.add(self.hpaned)
     
     self.vbox = HIGVBox()
     self.btn_box  = gtk.HButtonBox()
     self.btn_box1 = gtk.HButtonBox()
     self.btn_box2 = gtk.HButtonBox()
     
     self.ok_button = gtk.Button(stock=gtk.STOCK_OK)
     self.ok_button.connect('clicked', lambda x: self.clicked_ok())
     self.help_button   = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("help"))
     self.help_button.connect('clicked', lambda x: self.help_direct())
     #self.apply_button = gtk.Button(stock=gtk.STOCK_APPLY)
     #self.apply_button.connect('clicked', lambda x: self.save_preference())
     self.cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
     self.cancel_button.connect('clicked', lambda x: self.destroy())
     # notebook
     self.notebook = gtk.Notebook()
     # General Preference page
     self.general_page = GeneralPage()
     self.notebook.append_page(self.general_page, gtk.Label(_("General")))
     # Peer Info Page
     self.peer_page = PeerInfoPage()
     self.notebook.append_page(self.peer_page, gtk.Label(_("PeerInfo")))
     # Tests page
     self.test_page = TestPage()
     self.notebook.append_page(self.test_page, gtk.Label(_("Tests")))
     # Feedback page
     self.feedback_page = FeedbackPage()
     self.notebook.append_page(self.feedback_page, gtk.Label(_("Feedback")))
     # Update page
     self.update_page = UpdatePage()
     self.notebook.append_page(self.update_page, gtk.Label(_("Update")))
     # Advanced Page
     self.advanced_page = AdvancedPage()
     self.notebook.append_page(self.advanced_page, gtk.Label(_("Advanced")))        
示例#5
0
    def _create_widgets(self):
        self.category_label = HIGHintSectionLabel(_("Category (optional)"),
            _("If you know in which section of the program "
            "is the bug, please, select it from the choosebox. "
            "If you don't know what section to choose, leave it blank."))
        self.category_list = gtk.ListStore(str, str)
        self.category_combo = gtk.ComboBoxEntry(self.category_list, 0)

        self.email_label = HIGHintSectionLabel(_("Email"),
            _("Please inform a valid e-mail address from "
            "where you can be reached to be notified when the bug gets "
            "fixed. Not used for other purposes."))
        self.email_entry = gtk.Entry()

        self.summary_label = HIGHintSectionLabel(_("Summary"),
            _("This should be a quick description of the issue. "
            "Try to be clear and concise."))
        self.summary_entry = gtk.Entry()

        self.description_label = HIGHintSectionLabel(_("Description"),
            _("This is where you should write about the bug, "
            "describing it as clear as possible and giving as many "
            "informations as you can and how to reproduce the bug."))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_icon = gtk.Image()
        self.bug_text = gtk.Label(_("This Bug Report dialog allows you "
            "to easily tell us about a problem that you may have found on "
            "Umit. Doing so, you help us to help you, by fixing and "
            "improving Umit faster than usual."))
        
        if self.crashreport:
            # Create a button to show details 
            self.show_details = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                           _("Show Details"))

        self.hbox = HIGHBox()
        self.table = HIGTable()
示例#6
0
class LoginDialog(HIGDialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, title=_('Open Monitor 2012')):
        """Constructor"""
        HIGDialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL,
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_default_response(gtk.RESPONSE_ACCEPT)
        self.set_keep_above(True)
        self.set_size_request(480, 240)
        self.set_border_width(2)

        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

    def _create_widgets(self):
        
        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

        #Password
        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()
        self.password_entry.set_activates_default(True)
        
        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))
        
        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)
        
        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)
        
        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))
        
        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("settings"))
        
        #Container
        self.hbox = HIGHBox(False,2)
        self.table = HIGTable(8,4,False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
        
        #tab orders
        self.orders = [self.username_entry, self.password_entry, self.register_button, self.forgot_password]

    def _pack_widgets(self):

        self.hbox.set_border_width(8)
        
        self.table.set_focus_chain(self.orders)
        
        self.table.attach(self.logo_image,0,7,0,5,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.username_label,0,1,5,6,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.username_entry,1,5,5,6,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0)
        self.table.attach(self.password_label,0,1,6,7,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.password_entry,1,5,6,7,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0) 
        self.table.attach(self.register_button,5,6,5,6,gtk.FILL,gtk.FILL,0,0)  
        self.table.attach(self.forgot_password,5,6,6,7,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.auto_login_checkbtn,1,3,7,8,gtk.FILL,gtk.FILL,0,0)   
 
        self.hbox._pack_expand_fill(self.table)
        self.vbox.pack_start(self.hbox, False, False)                                  

        spaceholder1 = hig_box_space_holder()
        spaceholder2 = hig_box_space_holder()
        spaceholder3 = hig_box_space_holder()
        self.action_area.pack_end(spaceholder1)
        self.action_area.pack_end(spaceholder2)
        self.action_area.pack_end(spaceholder3)
        self.action_area.pack_end(self.settings_button)
        self.action_area.reorder_child(self.settings_button, 0)
        self.action_area.reorder_child(spaceholder1, 1)        
        self.action_area.reorder_child(spaceholder2, 2)
        self.action_area.reorder_child(spaceholder3, 2)
        
    def _connect_widgets(self):
        self.connect('response', self.check_response)
        self.register_button.connect('clicked', self._register)
        self.forgot_password.connect('clicked', self._forgot_password)
        self.settings_button.connect('clicked', self._settings)

    def _register(self, widget):
        #registration_form = RegistrationDialog()
        #registration_form.show_all()
        webbrowser.open(theApp.aggregator.base_url + "/accounts/register/")

    def _forgot_password(self, widget):
        webbrowser.open(theApp.aggregator.base_url + "/accounts/password/reset/")

    def check_response(self, widget, response_id):
        #There should collect the error information: help the user to check problem
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            username = self.username_entry.get_text()
            password = self.password_entry.get_text()
            save_login = self.auto_login_checkbtn.get_active()
            
            #Bug in this: If the user go to this window, the theApp.peer_info cannot is_registered
            
            #if not theApp.peer_info.is_registered:
            defer_ = theApp.login(username, password, save_login)   
            #    defer_ = theApp.register_agent(username, password)
            #    defer_.addCallback(
            #        lambda x: theApp.login(username, password, save_login))
            #else:
            #    defer_ = theApp.login(username, password, save_login)
            self.destroy()
            theApp.gtk_main.login_dlg = None
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            self.destroy()
            theApp.gtk_main.login_dlg = None
            
    def _settings(self,widget):
        '''
        configure settings: Server IP/Port: popup a new window
        '''
        settings_form = SettingsDialog()
        settings_form.show_all()
示例#7
0
class PreferenceWindow(HIGWindow):
    """
    User Preference
    """
    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title(_('OpenMonitor Preferences'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
                
        self.__create_widgets()
        self.__pack_widgets()
        self.load_preference()

    def __create_widgets(self):
        # Main widgets
        self.hpaned = gtk.HPaned()
        self.add(self.hpaned)
        
        self.vbox = HIGVBox()
        self.btn_box  = gtk.HButtonBox()
        self.btn_box1 = gtk.HButtonBox()
        self.btn_box2 = gtk.HButtonBox()
        
        self.ok_button = gtk.Button(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', lambda x: self.clicked_ok())
        self.help_button   = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("help"))
        self.help_button.connect('clicked', lambda x: self.help_direct())
        #self.apply_button = gtk.Button(stock=gtk.STOCK_APPLY)
        #self.apply_button.connect('clicked', lambda x: self.save_preference())
        self.cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.cancel_button.connect('clicked', lambda x: self.destroy())
        # notebook
        self.notebook = gtk.Notebook()
        # General Preference page
        self.general_page = GeneralPage()
        self.notebook.append_page(self.general_page, gtk.Label(_("General")))
        # Peer Info Page
        self.peer_page = PeerInfoPage()
        self.notebook.append_page(self.peer_page, gtk.Label(_("PeerInfo")))
        # Tests page
        self.test_page = TestPage()
        self.notebook.append_page(self.test_page, gtk.Label(_("Tests")))
        # Feedback page
        self.feedback_page = FeedbackPage()
        self.notebook.append_page(self.feedback_page, gtk.Label(_("Feedback")))
        # Update page
        self.update_page = UpdatePage()
        self.notebook.append_page(self.update_page, gtk.Label(_("Update")))
        # Advanced Page
        self.advanced_page = AdvancedPage()
        self.notebook.append_page(self.advanced_page, gtk.Label(_("Advanced")))        
        

    def __pack_widgets(self):
        # Search Notebook
        self.vbox._pack_expand_fill(self.notebook)

        self.btn_box.set_layout(gtk.BUTTONBOX_EDGE)
        self.btn_box.set_spacing(3)
        
        self.btn_box.pack_start(self.btn_box1) 
        self.btn_box.pack_end(self.btn_box2)
        
        self.btn_box1.set_layout(gtk.BUTTONBOX_START)
        self.btn_box1.set_spacing(3)
        self.btn_box1.pack_start(self.help_button)
        
        self.btn_box2.set_layout(gtk.BUTTONBOX_END)
        self.btn_box2.set_spacing(3)
        self.btn_box2.pack_end(self.ok_button) 
        #self.btn_box.pack_start(self.apply_button)
        self.btn_box2.pack_end(self.cancel_button)
        
        
        self.vbox.pack_start(self.btn_box)

        self.notebook.set_border_width(1)
        self.vbox.set_border_width(12)

        self.hpaned.pack1(self.vbox, True, False)


    def clicked_ok(self):
        self.save_preference()
        self.destroy()

    def save_preference(self):
        """"""        
        self.save_peer()
        self.save_general()
        self.save_tests()
        self.save_updates()
        self.save_advanced()

    def load_preference(self):
        """"""
        self.load_peer()
        self.load_general()
        self.load_tests()
        self.load_updates()
        self.load_advanced()

    def save_peer(self):
        """"""
        user_email = self.peer_page.email_entry.get_text()
        if user_email != '': # and is valid
            theApp.peer_info.Email = user_email

        aggregator_url = self.peer_page.cloudagg_entry.get_text()
        theApp.aggregator.base_url = aggregator_url
        if aggregator_url != None and aggregator_url != "":
            g_config.set('network', 'aggregator_url', aggregator_url)
            g_db_helper.set_value('config','aggregator_url', aggregator_url)
        
        longitude_text = self.peer_page.longitude_entry.get_text()
        if longitude_text != "":
            g_config.set('Location', 'longitude', str(longitude_text))
        
        latitude_text = self.peer_page.latitude_entry.get_text()
        if latitude_text != "":
            g_config.set('Location', 'latitude', str(latitude_text))        
    
    def save_general(self):
        """"""
        startup_on_boot = self.general_page.startup_check.get_active()
        self.general_page.startup_set(startup_on_boot)
        g_config.set('application', 'startup_on_boot', str(startup_on_boot))

        disable_notifications = self.general_page.notification_check.get_active()
        g_config.set('application', 'disable_notifications', str(disable_notifications))
        
        auto_login = self.general_page.login_ckeck.get_active()        
        g_config.set('application', 'auto_login_swittch', str(auto_login))
    
    def load_general(self):
        """"""
        startup_on_boot = g_config.getboolean('application', 'startup_on_boot')
        if startup_on_boot:
            self.general_page.startup_check.set_active(True)
        else:
            self.general_page.startup_check.set_active(False)
        
        disable_notifications = g_config.getboolean('application', 'disable_notifications')
        if disable_notifications:
            self.general_page.notification_check.set_active(True)
        else:
            self.general_page.notification_check.set_active(False)
        
        #auto_login = g_config.getboolean('application', 'auto_login_swittch')
        auto_login = False
        if auto_login:
            self.general_page.login_ckeck.set_active(True)
        else:
            self.general_page.login_ckeck.set_active(False)        
    
    def save_advanced(self):
        """"""
        task_assign_text = self.advanced_page.task_assign_entry.get_text()
        if task_assign_text != "":
             g_config.set('Timer', 'task_assign_timer', str(task_assign_text))
             theApp.task_assgin_lc.stop()
             theApp.task_assgin_lc.start(float(task_assign_text))
             
        task_scheduler_text = self.advanced_page.task_scheduler_entry.get_text()
        if task_scheduler_text != "":
             g_config.set('Timer', 'task_scheduler_timer', str(task_scheduler_text))
             theApp.task_run_lc.stop()
             theApp.task_run_lc.start(float(task_scheduler_text))
             
        report_uploade_text = self.advanced_page.report_uploader_entry.get_text()
        if report_uploade_text != "":
             g_config.set('Timer', 'send_report_timer', str(report_uploade_text))
             theApp.report_proc_lc.stop()
             theApp.report_proc_lc.start(float(report_uploade_text))
             
        test_fetch_text = self.advanced_page.test_fetch_entry.get_text()
        if test_fetch_text != "":
             g_config.set('Timer', 'test_fetch_timer', str(test_fetch_text))
             theApp.test_sets_fetch_lc.stop()
             theApp.test_sets_fetch_lc.start(float(test_fetch_text))     
             
        language_text  = self.advanced_page.language_entry.get_active_text()
        if language_text != "" and language_text != None :
            g_config.set('Language', 'current_language',language_text)   
                 
    def load_advanced(self):
        """"""
        task_assign_text = g_config.get("Timer","task_assign_timer")
        self.advanced_page.task_assign_entry.set_text(task_assign_text)

        task_scheduler_text = g_config.get("Timer","task_scheduler_timer")
        self.advanced_page.task_scheduler_entry.set_text(task_scheduler_text)        

        report_uploade_text = g_config.get("Timer","send_report_timer")
        self.advanced_page.report_uploader_entry.set_text(report_uploade_text)        
        
        test_fetch_text = g_config.get("Timer","test_fetch_timer")
        self.advanced_page.test_fetch_entry.set_text(test_fetch_text)   
    
        language_text = g_config.get("Language","current_language")
        #self.advanced_page.language_entry.set_text_column(1)
        
    def load_peer(self):
        """"""
        self.peer_page.peerid_label2.set_text(str(theApp.peer_info.ID))
        self.peer_page.email_entry.set_text(theApp.peer_info.Email)
        self.peer_page.cloudagg_entry.set_text(theApp.aggregator.base_url)
        self.peer_page.test_version_label2.set_text(str(theApp.test_sets.current_test_version))


        longitude_text  = g_config.get('Location', 'longitude')
        latitude_text  = g_config.get('Location', 'latitude')
                
        self.peer_page.longitude_entry.set_text(longitude_text)
        self.peer_page.latitude_entry.set_text(latitude_text)
                
    def save_updates(self):
        """"""
        auto_update = self.update_page.update_check.get_active()
        g_config.set('application', 'auto_update', str(auto_update))
        
        update_time  = self.update_page.update_time_entry.get_active_text()
        if update_time != "" and update_time != None :
            g_config.set('update', 'update_time',update_time)
        
        update_method = self.update_page.update_method_entry.get_active_text()
        if update_method != "" and update_method != None :
            g_config.set('update', 'update_method',update_method)   
            
        update_detect = self.update_page.update_switch_check.get_active()
        g_config.set('update', 'update_detect',str(update_detect))

    def load_updates(self):
        """"""
        auto_update = g_config.getboolean('application', 'auto_update')
        if auto_update:
            self.update_page.update_check.set_active(True)
        else:
            self.update_page.update_check.set_active(False)
        
        update_time  = g_config.get('update', 'update_time')
        if update_time != "" and update_time != None: 
            self.update_page.update_time_entry.set_text_column(update_time_str[update_time])
        update_method = g_config.get('update', 'update_method')
        if update_method != "" and update_method != None:    
            self.update_page.update_method_entry.set_text_column(update_method_str[update_method])
        
        update_detect = g_config.getboolean('update', 'update_detect')
        if update_detect:
            self.update_page.update_switch_check.set_active(True)
        else:
            self.update_page.update_switch_check.set_active(False)
        
    def save_tests(self):
        """"""
        #The test should be stored into the DB
        SELECTED_TESTS = [ r[0] for r in self.test_page.subbox.\
                           tree_view_selected_tests.treestore ]

        if ALL_TESTS[0] not in SELECTED_TESTS:
            SELECTED_TESTS.append(ALL_TESTS[0])
            
        g_db_helper.set_value('config','selected_tests', SELECTED_TESTS)

        auto_update_test = self.test_page.checkbtn.get_active()
        g_config.set('application', 'auto_update_test', str(auto_update_test))
 
        load_http_throttled_test = self.test_page.checkbtn_throttled.get_active()
        g_config.set('application', 'load_http_throttled_test',str(load_http_throttled_test))     
          
  
    def load_tests(self):
        """"""
        ts = self.test_page.subbox.tree_view_installed_tests.treestore
        for tname in ALL_TESTS:
            ts.append(None, [tname])

        #SELECTED_TESTS = g_config.get('application', 'selected_tests')
        #Here, we use datebase to store the selected test
        SELECTED_TESTS = g_db_helper.get_value('config','selected_tests')
        
        if SELECTED_TESTS:
            ts = self.test_page.subbox.tree_view_selected_tests.treestore
            for tname in SELECTED_TESTS:
                ts.append(None, [tname])

        auto_update_test = g_config.getboolean('application', 'auto_update_test')
        if auto_update_test:
            self.test_page.checkbtn.set_active(True)
        else:
            self.test_page.checkbtn.set_active(False)
            
        load_http_throttled_test = g_config.getboolean('application', 'load_http_throttled_test')
        if load_http_throttled_test:
            self.test_page.checkbtn_throttled.set_active(True)
        else:
            self.test_page.checkbtn_throttled.set_active(False)        
   
    def help_direct(self):
        """"""
        import webbrowser
        url = "http://www.openmonitor.org/faq/"
        webbrowser.open(url)             
class BugReport(HIGDialog):
    def __init__(self, title=_('Bug Report'), summary=None, description=None,
                 category=None, crashreport=False, description_dialog=None,
                 reuse_mainloop=True):
        HIGDialog.__init__(self, title=title,
            buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
                gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        # If reuse_mainloop is true, then dialogs created inside this dialog
        # will not start another mainloop.
        self._reuse_mainloop = reuse_mainloop

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.crashreport = crashreport
        self.description_dialog = description_dialog
        self._create_widgets()
        self._set_category_list()
        self._pack_widgets()
        self._connect_widgets()
        self.summary = summary or ''
        self.description_report = description
        if self.crashreport:
            self.description = _("CrashReport automatically created")
        else:
            if self.description_dialog is None:
                self.description = description or ''
            else:
                self.description = description_dialog or ''
        self.category = category or ''

    def _set_category_list(self):
        # Obtained at bug tracker page source code
        # The following two lines are commented due to component deprecation
        #self.category_list.append(["umitCore","umitCore"])
        #self.category_list.append(["umitGUI","umitGUI"])
        self.category_list.append(["Umit","Umit"])
        self.category_list.append(["CrashReport","CrashReport"])
        self.category_list.append(["Documentation", "Documentation"])
        self.category_list.append(["UmitWeb","UmitWeb"])
        self.category_list.append(["InterfaceEditor", "InterfaceEditor"])
        self.category_list.append(["NetworkInventory", "NetworkInventory"])
        self.category_list.append(["website","website"])

    def _create_widgets(self):
        self.category_label = HIGHintSectionLabel(_("Category (optional)"),
            _("If you know in which section of the program "
            "is the bug, please, select it from the choosebox. "
            "If you don't know what section to choose, leave it blank."))
        self.category_list = gtk.ListStore(str, str)
        self.category_combo = gtk.ComboBoxEntry(self.category_list, 0)

        self.email_label = HIGHintSectionLabel(_("Email"),
            _("Please inform a valid e-mail address from "
            "where you can be reached to be notified when the bug gets "
            "fixed. Not used for other purposes."))
        self.email_entry = gtk.Entry()

        self.summary_label = HIGHintSectionLabel(_("Summary"),
            _("This should be a quick description of the issue. "
            "Try to be clear and concise."))
        self.summary_entry = gtk.Entry()

        self.description_label = HIGHintSectionLabel(_("Description"),
            _("This is where you should write about the bug, "
            "describing it as clear as possible and giving as many "
            "informations as you can and how to reproduce the bug."))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_icon = gtk.Image()
        self.bug_text = gtk.Label(_("This Bug Report dialog allows you "
            "to easily tell us about a problem that you may have found on "
            "Umit. Doing so, you help us to help you, by fixing and "
            "improving Umit faster than usual."))
        
        if self.crashreport:
            # Create a button to show details 
            self.show_details = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                           _("Show Details"))

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.description_scrolled.add(self.description_text)
        self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, 
            gtk.POLICY_AUTOMATIC)
        self.description_scrolled.set_size_request(400, 150)
        self.description_text.set_wrap_mode(gtk.WRAP_WORD)

        self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, 
            gtk.ICON_SIZE_DIALOG)
        self.bug_icon.set_padding(10, 0)
        self.bug_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        
        nextpos = (0, 1)
        if not self.crashreport:
            self.table.attach_label(self.category_label, 0, 1, 0, 1)
            self.table.attach_entry(self.category_combo, 1, 2, 0, 1)
            nextpos = (1, 2)

        self.table.attach_label(self.email_label, 0, 1, *nextpos)
        self.table.attach_entry(self.email_entry, 1, 2, *nextpos)

        nextpos = (2, 3)
        if not self.crashreport:
            self.table.attach_label(self.summary_label, 0, 1, 2, 3)
            self.table.attach_entry(self.summary_entry, 1, 2, 2, 3)
            nextpos = (3, 4)

        self.table.attach_label(self.description_label, 0, 2, *nextpos)
        nextpos = nextpos[0] + 1, nextpos[1] + 1
        self.table.attach_entry(self.description_scrolled, 0, 2, *nextpos)

        self.hbox._pack_noexpand_nofill(self.bug_icon)
        self.hbox._pack_expand_fill(self.bug_text)

        self.vbox.pack_start(self.hbox, False, False)
        self.vbox.pack_start(self.table)
       
        # Just need because in crash report some aditional 
        # information will be show 
        if self.crashreport:
            # Add a button to action-area
            spaceholder = hig_box_space_holder()
            self.action_area.pack_end(spaceholder)
            self.action_area.pack_end(self.show_details)
            # Put "Show details" to left side respecting HIG
            self.action_area.reorder_child(self.show_details,0)
            self.action_area.reorder_child(spaceholder, 1)
        
        
        
    def _connect_widgets(self):
        self.connect('response', self.check_response)
        if self.crashreport:
            self.show_details.connect('clicked',
                                      self._show_details)
        
    def _show_details(self, widget):
        # Create info necessary
        desc = [ self.email,
                 self.summary,
                 self.description_report,
                 self.description,
                 self.category] 
        # Create another dialog to show details
        details = BugReportDescription(*desc)
        details.show_all()
        details.run()
        details.destroy()
        
        
    def check_response(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            self.send_report()
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            # there are tree possibilities to being here:
            # 1) user clicked on 'x' button
            # 2) user clicked on 'cancel' button
            # 3) report was sent successfully and now we can destroy this
            self.destroy()

    def send_report(self):
        """Prepare dialog to send a bug report and then call _send_report."""
        # set cursor to busy cursor (supposing it will take some time
        # to submit the report)
        self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))

        # disable dialog controls
        for child in self.vbox.get_children():
            child.set_sensitive(False)

        # attempt sending report
        gobject.idle_add(self._send_report)

    def restore_state(self):
        """Restore dialog state, just like it was before calling
        send_report."""
        self.window.set_cursor(None)
        for child in self.vbox.get_children():
            child.set_sensitive(True)

    def _send_report(self):
        if self.summary == "" or self.description == "" or self.email == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                message_format=_("Bug report is incomplete!"),
                secondary_text=_("The bug report is incomplete. "
                    "You must inform a description that explains clearly "
                    "what is happening and a valid e-mail, so you can be "
                    "contacted when the bug gets fixed."))
            run_dialog(self._reuse_mainloop, cancel_dialog)
            return self.restore_state()

        bug_register = BugRegister()

        bug_register.component = self.category
        bug_register.summary = self.summary
        if self.description_report is not None:
            bug_register.details = self.description_report
        else:
            bug_register.details = self.description.replace("\n", "[[BR]]")
        bug_register.reporter = self.email

        bug_page = None
        try:
            bug_page = bug_register.report()
            assert bug_page
        except:
            import traceback
            traceback.print_exc()
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                message_format=_("Bug not reported!"),
                secondary_text=_("The bug description could not be "
                    "reported. This problem may be caused by the lack "
                    "of Internet access or indisponibility of the bug "
                    "tracker server. Please, verify your internet access, "
                    "and then try to report the bug once again."))
            run_dialog(self._reuse_mainloop, cancel_dialog)
            return self.restore_state()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                message_format=_("Bug sucessfully reported!"),
                secondary_text=_("The bug description was sucessfully "
                    "reported. A web page with detailed description about "
                    "this report will be opened in your default web browser "
                    "now."))
            run_dialog(self._reuse_mainloop, ok_dialog,
                    show_report, # callback
                    self._reuse_mainloop, bug_page) # args

        # report sent successfully
        self.response(gtk.RESPONSE_DELETE_EVENT)

    def get_category(self):
        return self.category_combo.child.get_text()

    def set_category(self, category):
        self.category_combo.child.set_text(category)

    def get_summary(self):
        return self.summary_entry.get_text()

    def set_summary(self, summary):
        self.summary_entry.set_text(summary)
    def get_description(self):
        buff = self.description_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())
    def set_description(self, description):
        self.description_text.get_buffer().set_text(description)

    def get_email(self):
        return self.email_entry.get_text()

    def set_email(self, email):
        self.email_entry.set_text(email)


    category = property(get_category, set_category)
    summary = property(get_summary, set_summary)
    description = property(get_description, set_description)
    email = property(get_email, set_email)