예제 #1
0
class QuitDialog(DialogBox):
    def __init__(self, confirm_callback=None):
        DialogBox.__init__(
            self,
            title=_("Close"),
            default_width=360,
            default_height=145,
            mask_type=DIALOG_MASK_SINGLE_PAGE,
        )

        self.confirm_callback = confirm_callback
        radio_group = gtk.HBox(spacing=50)
        self.minimize_radio = RadioButton(_("Minimize to tray"))
        self.minimize_radio.set_active(True)
        self.quit_radio = RadioButton(_("Quit"))

        radio_group.pack_start(self.minimize_radio, False, True)
        radio_group.pack_start(self.quit_radio, False, True)
        self.remembar_button = CheckButton(_("Don't prompt again"))
        self.remembar_button.set_active(True)

        radio_group_align = gtk.Alignment()
        radio_group_align.set_padding(30, 0, 10, 0)
        radio_group_align.add(radio_group)

        confirm_button = Button(_("OK"))
        confirm_button.connect("clicked", self.on_confirm_button_clicked)

        cancel_button = Button(_("Cancel"))
        cancel_button.connect("clicked", self.on_cancel_button_clicked)

        # Connect widgets.
        self.body_box.pack_start(radio_group_align, False, True)
        self.left_button_box.set_buttons([
            self.remembar_button,
        ])
        self.right_button_box.set_buttons([confirm_button, cancel_button])

    def on_confirm_button_clicked(self, widget):
        self.change_quit_status()
        if self.confirm_callback != None:
            self.confirm_callback()
        self.destroy()

    def on_cancel_button_clicked(self, widget):
        self.destroy()

    def change_quit_status(self):
        status = "false"
        if self.minimize_radio.get_active():
            status = "true"
        elif self.quit_radio.get_active():
            status = "false"
        config.set("setting", "close_to_tray", status)

        if self.remembar_button.get_active():
            status = "true"
        else:
            status = "false"
        config.set("setting", "close_remember", status)
예제 #2
0
class QuitDialog(DialogBox):        
    
    def __init__(self, confirm_callback=None):
        DialogBox.__init__(self, 
                           title=_("Close"),
                           default_width=360,
                           default_height=145,
                           mask_type=DIALOG_MASK_SINGLE_PAGE,
                           )
        
        self.confirm_callback = confirm_callback
        radio_group = gtk.HBox(spacing=50)
        self.minimize_radio = RadioButton(_("Minimize to tray"))
        self.minimize_radio.set_active(True)
        self.quit_radio = RadioButton(_("Quit"))
        
        radio_group.pack_start(self.minimize_radio, False, True)
        radio_group.pack_start(self.quit_radio, False, True)
        self.remembar_button = CheckButton(_("Don't prompt again"))
        self.remembar_button.set_active(True)
        
        radio_group_align = gtk.Alignment()
        radio_group_align.set_padding(30, 0, 10, 0)
        radio_group_align.add(radio_group)
                
        confirm_button = Button(_("OK"))
        confirm_button.connect("clicked", self.on_confirm_button_clicked)

        cancel_button = Button(_("Cancel"))
        cancel_button.connect("clicked", self.on_cancel_button_clicked)        
        
        # Connect widgets.
        self.body_box.pack_start(radio_group_align, False, True)
        self.left_button_box.set_buttons([self.remembar_button,])
        self.right_button_box.set_buttons([confirm_button, cancel_button])
        
    def on_confirm_button_clicked(self, widget):    
        self.change_quit_status()
        if self.confirm_callback != None:
            self.confirm_callback()
        self.destroy()    
    
    def on_cancel_button_clicked(self, widget):
        self.destroy()
        
    def change_quit_status(self):    
        status = "false"
        if self.minimize_radio.get_active():
            status = "true"
        elif self.quit_radio.get_active():    
            status = "false"
        config.set("setting", "close_to_tray", status)
        
        if self.remembar_button.get_active():
            status = "true"
        else:    
            status = "false"
        config.set("setting", "close_remember", status)    
예제 #3
0
 def get_user_info(self, weibo):
     '''get weibo user info'''
     info = weibo.get_user_name()
     gtk.gdk.threads_enter()
     #self.get_user_error_text = ""
     weibo_hbox = weibo.get_box()
     hbox = gtk.HBox(False)
     vbox = gtk.VBox(False)
     weibo_hbox.pack_start(vbox, False, False)
     vbox.pack_start(hbox)
     #print weibo.t_type, info
     if info:
         self.is_get_user_info[weibo] = 1
         label = Label(text=info, label_width=70, enable_select=False)
         check = CheckButton()
         #check = gtk.CheckButton()
         check.connect("toggled", self.weibo_check_toggle, weibo)
         check.set_active(True)
         check_vbox = gtk.VBox(False)
         check_align = gtk.Alignment(0.5, 0.5, 0, 0)
         check_align.add(check_vbox)
         check_vbox.pack_start(check, False, False)
         button = ImageButton(
             app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
             app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
             app_theme.get_pixbuf("share/" + weibo.t_type + ".png"))
         utils.set_clickable_cursor(button)
         button.connect("enter-notify-event", self.show_tooltip, _("Click to switch user"))
         hbox.pack_start(check_align, False, False)
         hbox.pack_start(button, False, False, 5)
         hbox.pack_start(label, False, False)
     else:
         self.is_get_user_info[weibo] = 0
         check = CheckButton()
         #check = gtk.CheckButton()
         check.set_sensitive(False)
         check_vbox = gtk.VBox(False)
         check_align = gtk.Alignment(0.5, 0.5, 0, 0)
         check_align.add(check_vbox)
         check_vbox.pack_start(check, False, False)
         button = ImageButton(
             app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
             app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
             app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"))
         utils.set_clickable_cursor(button)
         button.connect("enter-notify-event", self.show_tooltip, _("Click to login"))
         hbox.pack_start(check_align, False, False)
         hbox.pack_start(button, False, False, 5)
         # curl time out
         info_error = weibo.get_curl_error()
         if info_error:
             #self.get_user_error_text += "%s:%s." % (weibo.t_type, _(info_error))
             hbox.pack_start(
                 Label(text="(%s)" % _(info_error), label_width=70,enable_select=False,
                 text_color = app_theme.get_color("left_char_num1")), False, False)
         
     button.connect("clicked", self.weibo_login, weibo)
     self.__weibo_check_button_list.append(check)
     self.__weibo_image_button_list.append(button)
     gtk.gdk.threads_leave()
     return weibo_hbox
예제 #4
0
    def get_user_info(self, weibo):
        '''get weibo user info'''
        info = weibo.get_user_name()
        gtk.gdk.threads_enter()
        #self.get_user_error_text = ""
        weibo_hbox = weibo.get_box()
        hbox = gtk.HBox(False)
        vbox = gtk.VBox(False)
        weibo_hbox.pack_start(vbox, False, False)
        vbox.pack_start(hbox)
        #print weibo.t_type, info
        if info:
            self.is_get_user_info[weibo] = 1
            label = Label(text=info, label_width=70, enable_select=False)
            check = CheckButton()
            #check = gtk.CheckButton()
            check.connect("toggled", self.weibo_check_toggle, weibo)
            check.set_active(True)
            check_vbox = gtk.VBox(False)
            check_align = gtk.Alignment(0.5, 0.5, 0, 0)
            check_align.add(check_vbox)
            check_vbox.pack_start(check, False, False)
            button = ImageButton(
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + ".png"))
            utils.set_clickable_cursor(button)
            button.connect("enter-notify-event", self.show_tooltip, _("Click to switch user"))
            hbox.pack_start(check_align, False, False)
            hbox.pack_start(button, False, False, 5)
            hbox.pack_start(label, False, False)
        else:
            self.is_get_user_info[weibo] = 0
            check = CheckButton()
            #check = gtk.CheckButton()
            check.set_sensitive(False)
            check_vbox = gtk.VBox(False)
            check_align = gtk.Alignment(0.5, 0.5, 0, 0)
            check_align.add(check_vbox)
            check_vbox.pack_start(check, False, False)
            button = ImageButton(
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"),
                app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"))
            utils.set_clickable_cursor(button)
            button.connect("enter-notify-event", self.show_tooltip, _("Click to login"))
            hbox.pack_start(check_align, False, False)
            hbox.pack_start(button, False, False, 5)
            # curl time out
            info_error = weibo.get_curl_error()
            if info_error:
                #self.get_user_error_text += "%s:%s." % (weibo.t_type, _(info_error))
                hbox.pack_start(
                    Label(text="(%s)" % _(info_error), label_width=70,enable_select=False,
                    text_color = ui_theme.get_color("category_item")), False, False)

        button.connect("clicked", self.weibo_login, weibo)
        self.__weibo_check_button_list.append(check)
        self.__weibo_image_button_list.append(button)
        gtk.gdk.threads_leave()
        return weibo_hbox
예제 #5
0
class MirrorsBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.current_mirror_item = None

        self.select_best_mirror_button_texts = {
                "normal": _("Select the best mirror"),
                "wait": _("Waiting"),
                "success": _("Successfully")
                }

        self.main_box.pack_start(self.create_mirror_select_table(), True, True)
        self.main_box.pack_start(self.create_source_update_frequency_table(), False, True)
        self.mirror_test_obj = None

        global_event.register_event("mirror-test-finished", self.finish_mirror_test)
        global_event.register_event("cancel-mirror-test", self.cancel_mirror_test)
        global_event.register_event("mirror-backend-changed", self.mirror_changed_handler)

    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Refresh package lists"))

        # auto update check button
        self.is_auto_update_button = CheckButton(label_text=_('Upgrade automatically'))
        self.is_auto_update_button.connect('released', self.change_auto_update)
        self.is_auto_update_button.set_active(utils.is_auto_update())

        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(dir_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        return main_table

    def change_auto_update(self, widget, data=None):
        widget_active = widget.get_active()
        self.update_spin.set_sensitive(widget_active)
        self.update_label.set_sensitive(widget_active)
        self.hour_lablel.set_sensitive(widget_active)

        utils.set_auto_update(widget_active)

        daemon_running = is_dbus_name_exists(DSC_UPDATE_DAEMON_NAME)
        if widget_active and not daemon_running:
            dsc_daemon_path = os.path.join(get_parent_dir(__file__, 2), 'update_data/apt/dsc-daemon.py')
            subprocess.Popen(['python', dsc_daemon_path], stderr=subprocess.STDOUT, shell=False)
        elif not widget_active and daemon_running:
            session = dbus.SessionBus()
            dbus_obj = session.get_object(DSC_UPDATE_DAEMON_NAME, DSC_UPDATE_DAEMON_PATH)
            iface = dbus.Interface(dbus_obj, DSC_UPDATE_DAEMON_NAME)
            iface.quit()

    def select_best_mirror(self, widget):
        widget.set_label(self.select_best_mirror_button_texts["wait"])
        widget.set_sensitive(False)
        global_event.emit("toggle-waiting-dialog", True)
        utils.ThreadMethod(self.change_to_nearest_mirror_thread, (widget, )).start()

    def cancel_mirror_test(self):
        if self.mirror_test_obj:
            self.mirror_test_obj.cancel()
            self.mirror_test_obj = None
            self.finish_mirror_test("")

    def change_to_nearest_mirror_thread(self, widget):
        from mirror_speed.ip_detect import get_nearest_mirrors
        hostnames = get_nearest_mirrors()
        self.mirror_test_obj = MirrorTest(hostnames)
        hostname = self.mirror_test_obj.run()
        for mirror in self.mirrors_list:
            if mirror.hostname == hostname:
                global_event.emit("mirror-test-finished", mirror)
                break

    def finish_mirror_test(self, mirror):
        for item in self.mirror_view.visible_items:
            if item.mirror == mirror:
                self.mirror_view.visible_item(item)
        self.select_best_mirror_button.set_sensitive(True)
        self.select_best_mirror_button.set_label(self.select_best_mirror_button_texts["normal"])

    def create_mirror_select_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        mirror_select_title = Label(_("Select mirror"))
        self.select_best_mirror_button = Button(self.select_best_mirror_button_texts["normal"])
        self.select_best_mirror_button.connect("clicked", self.select_best_mirror)

        self.mirrors_dir = os.path.join(get_parent_dir(__file__, 2), 'mirrors')
        self.current_mirror_hostname = utils.get_current_mirror_hostname()
        self.mirror_items = self.get_mirror_items()
        self.mirror_view = TreeView(self.mirror_items,
                                enable_drag_drop=False,
                                enable_multiple_select=False,
                                mask_bound_height=0,
                             )
        self.mirror_view.set_expand_column(1)
        self.mirror_view.set_size_request(-1, 280)
        self.mirror_view.draw_mask = self.mirror_treeview_draw_mask

        main_table.attach(mirror_select_title, 0, 1, 0, 1, yoptions=gtk.FILL)
        main_table.attach(self.select_best_mirror_button, 1, 2, 0, 1, xoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, xoptions=gtk.FILL)
        main_table.attach(self.mirror_view, 0, 2, 2, 3, xoptions=gtk.FILL)


        return main_table

    def mirror_changed_handler(self, mirror):
        item = None
        for i in self.mirror_view.visible_items:
            if i.mirror == mirror:
                item = i
                break
        if item:
            self.current_mirror_item = item
            for i in self.mirror_items:
                if i != item and i.radio_button.active == True:
                    i.radio_button.active = False
                elif i == item:
                    i.radio_button.active = True
            self.mirror_view.queue_draw()
            self.mirror_view.visible_item(item)

    def mirror_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgba(1, 1, 1, 0.5)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_mirror_items(self):
        items = []
        self.mirrors_list = get_mirrors()
        for m in self.mirrors_list:
            item = MirrorItem(m, self.mirror_clicked_callback)
            if m.hostname == self.current_mirror_hostname:
                item.radio_button.active = True
                self.current_mirror_item = item
            items.append(item)

        items.sort(key=lambda item:item.mirror.priority)
        return items

    def mirror_clicked_callback(self, item):
        if item != self.current_mirror_item:
            global_event.emit('start-change-mirror', item.mirror)
예제 #6
0
class GeneralBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.main_box.pack_start(self.create_uninstall_box(), False, True)
        self.main_box.pack_start(self.create_download_dir_table(), False, True)

    def create_uninstall_box(self):
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        uninstall_title_label = Label(_("On uninstalling the software"))

        # mini_check_button
        self.delete_check_button = CheckButton(_("Delete configuration files"))
        self.delete_check_button.set_active(get_purg_flag())
        self.delete_check_button.connect("toggled", lambda w: set_purge_flag(self.delete_check_button.get_active()))

        main_table.attach(uninstall_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.delete_check_button, 0, 1, 2, 3, yoptions=gtk.FILL)

        return main_table

    def create_download_dir_table(self):
        main_table = gtk.Table(4, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Download settings"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        download_number_label = Label(_('Maximum number of download tasks: '))
        self.download_number_comobox = ComboBox(
                items = [(str(i+1), i+1) for i in range(10)],
                select_index = int(get_download_number())-1,
                )
        self.download_number_comobox.connect("item-selected", self.download_number_comobox_changed)
        download_number_hbox = gtk.HBox(spacing=5)
        download_number_hbox.pack_start(download_number_label, False, False)
        download_number_hbox.pack_start(self.download_number_comobox, False, False)

        change_download_dir_label = Label(_("Download directory: "))
        self.dir_entry = InputEntry()
        self.dir_entry.set_text(get_software_download_dir())
        self.dir_entry.set_editable(False)
        self.dir_entry.set_size(200, 25)

        modify_button = Button(_("Change"))
        modify_button.connect("clicked", self.change_download_save_dir)
        download_dir_hbox = gtk.HBox(spacing=5)
        download_dir_hbox.pack_start(change_download_dir_label, False, False)
        download_dir_hbox.pack_start(self.dir_entry, False, False)
        download_dir_hbox.pack_start(modify_button, False, False)

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xoptions=gtk.FILL)
        return main_table

    def download_number_comobox_changed(self, widget, name, value, index):
        set_download_number(value)
        global_event.emit('max-download-number-changed', value)

    def change_download_save_dir(self, widget):
        local_dir = FolderChooseDialog(False).run()
        if local_dir:
            local_dir = os.path.expanduser(local_dir)
            if local_dir != get_software_download_dir():
                self.dir_entry.set_editable(True)
                self.dir_entry.set_text(local_dir)
                self.dir_entry.set_editable(False)
                set_software_download_dir(local_dir)
                global_event.emit('download-directory-changed')
class DscPreferenceDialog(PreferenceDialog):
    def __init__(self):
        PreferenceDialog.__init__(self, 566, 488)

        self.current_mirror_item = None
        self.normal_settings = gtk.VBox()
        self.normal_settings.set_spacing(TABLE_ROW_SPACING)
        self.normal_settings.pack_start(self.create_uninstall_box(), False, True)
        self.normal_settings.pack_start(self.create_download_dir_table(), False, True)

        self.normal_settings_align = gtk.Alignment(0, 0, 1, 1)
        self.normal_settings_align.set_padding(padding_left=5, padding_right=5, padding_top=25, padding_bottom=10)
        self.normal_settings_align.add(self.normal_settings)

        self.mirror_settings = gtk.VBox()
        self.mirror_settings.set_app_paintable(True)
        self.mirror_settings.connect("expose-event", self.mirror_settings_align_expose)
        self.mirror_settings.set_spacing(TABLE_ROW_SPACING)
        self.mirror_settings.pack_start(self.create_mirror_select_table(), False, True)
        self.mirror_settings.pack_start(self.create_source_update_frequency_table(), False, True)

        self.mirror_settings_inner_align = gtk.Alignment(0.5, 0.5, 1, 1)
        self.mirror_settings_inner_align.set_padding(padding_top=25, padding_bottom=10, padding_left=0, padding_right=0)
        self.mirror_settings_inner_align.add(self.mirror_settings)

        self.mirror_settings_scrolled_win = ScrolledWindow()
        self.mirror_settings_scrolled_win.add_child(self.mirror_settings_inner_align)

        self.mirror_settings_align = gtk.Alignment(0, 0, 1, 1)
        self.mirror_settings_align.set_padding(padding_left=0, padding_right=0, padding_top=0, padding_bottom=3)
        self.mirror_settings_align.add(self.mirror_settings_scrolled_win)

        self.set_preference_items([
            (_("General"), self.normal_settings_align),
            (_("Mirrors"), self.mirror_settings_align),
            (_("About"), AboutBox()),
            ])
        
    def mirror_settings_align_expose(self, widget, event=None):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # draw backgound
        cr.rectangle(*rect)
        #cr.set_source_rgb(*color_hex_to_cairo("#ff0000"))
        cr.set_source_rgba(1, 1, 1, 0)
        cr.fill()

    def mirror_select_action(self, repo_urls):
        self.data_manager.change_source_list(repo_urls, reply_handler=handle_dbus_reply, error_handler=handle_dbus_error)

    def create_mirror_select_table(self):
        vbox = gtk.VBox()
        vbox.set_size_request(423, -1)
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Select mirror"))
        dir_title_label.set_size_request(423, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 10, 0)
        label_align.add(dir_title_label)

        self.mirrors_dir = os.path.join(get_parent_dir(__file__, 2), 'mirrors')
        self.current_mirror_hostname = utils.get_current_mirror_hostname()
        self.mirror_items = self.get_mirror_items()
        self.mirror_view = TreeView(self.mirror_items,
                                enable_drag_drop=False,
                                enable_multiple_select=False,
                                #mask_bound_height=0,
                             )
        self.mirror_view.set_expand_column(1)
        self.mirror_view.set_size_request(-1, len(self.mirror_view.visible_items) * self.mirror_view.visible_items[0].get_height())
        self.mirror_view.draw_mask = self.mirror_treeview_draw_mask
        #self.display_current_mirror()

        self.mirror_test_progressbar = ProgressBar()

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        
        title = _("Select best mirror")
        info_message = _("Please wait. The process will take 30 seconds or more depending on your network connection")
        self.select_best_mirror_dialog = WaitingDialog(title, info_message, self.cancel_mirror_test)
        global_event.register_event("mirror-changed", self.mirror_changed_handler)
        global_event.register_event("update-list-finish", self.update_list_finish_handler)

        vbox.pack_start(main_table, False, False)
        vbox.pack_start(self.mirror_view, False, False)

        return vbox

    def cancel_mirror_test(self, widget):
        try:
            self.mirror_test.terminated = True
            gobject.source_remove(self.update_status_id)
        except:
            pass
        self.select_best_mirror_dialog.hide_all()

    def update_list_finish_handler(self):
        self.select_best_mirror_dialog.hide_all()

    def mirror_changed_handler(self, item):
        for i in self.mirror_items:
            if i != item and i.radio_button.active == True:
                i.radio_button.active = False
            elif i == item:
                i.radio_button.active = True
        self.mirror_view.queue_draw()
    
    def test_mirror_action(self, widget):
        self.select_best_mirror_dialog.set_transient_for(self)
        self.select_best_mirror_dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.select_best_mirror_dialog.show_all()
        distro = aptsources.distro.get_distro()
        #distro.get_sources(SourcesList())
        pipe = os.popen("dpkg --print-architecture")
        arch = pipe.read().strip()
        test_file = "dists/%s/Contents-%s.gz" % \
                    (
                    distro.codename,
                    #"quantal",
                    arch,
                    )

        self.mirror_test = MirrorTest(self.mirrors_list, test_file)
        self.mirror_test.start()

        # now run the tests in a background thread, and update the UI on each event
        self.update_status_id = gtk.timeout_add(100, self.update_progress)

    def update_progress(self):
        if self.mirror_test.running:
            return True
        else:
            time.sleep(1)
            if self.mirror_test.best != None:
                for item in self.mirror_items:
                    if item.mirror == self.mirror_test.best[1]:
                        print item.mirror.get_repo_urls()
                        self.mirror_clicked_callback(item)
            else:
                self.select_best_mirror_dialog.loading_widget.hide_all()
                self.select_best_mirror_dialog.info_message_label.set_text(_("Test for downloading mirror failed. Please check your network connection."))
                self.select_best_mirror_dialog.close_button.set_label(_("Close"))
            return False

    def mirror_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgba(1, 1, 1, 0.9)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_mirror_items(self):
        items = []
        self.mirrors_list = []
        for ini_file in os.listdir(self.mirrors_dir):
            m = Mirror(os.path.join(self.mirrors_dir, ini_file))
            item = MirrorItem(m, self.mirror_clicked_callback)
            if m.hostname == self.current_mirror_hostname:
                item.radio_button.active = True
                self.current_mirror_item = item
            self.mirrors_list.append(m)
            items.append(item)
        
        items.sort(key=lambda x:x.mirror.priority)
        
        return items

    def mirror_clicked_callback(self, item):
        if item != self.current_mirror_item:
            self.current_mirror_item = item
            global_event.emit('change-mirror', item)
            self.hide_all()

    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Update applications lists"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        self.is_auto_update_button = CheckButton(label_text=_('Update automatically'))
        self.is_auto_update_button.connect('toggled', self.change_auto_update)
        
        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xpadding=10, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)

        if is_auto_update():
            self.is_auto_update_button.set_active(True)
        else:
            self.is_auto_update_button.toggled()

        return main_table

    def create_download_dir_table(self):    
        main_table = gtk.Table(4, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Download settings"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        download_number_label = Label(_('Max download task number: '))
        self.download_number_comobox = ComboBox(
                items = [(str(i+1), i+1) for i in range(10)],
                select_index = int(get_download_number())-1,
                )
        self.download_number_comobox.connect("item-selected", self.download_number_comobox_changed)
        download_number_hbox = gtk.HBox(spacing=5)
        download_number_hbox.pack_start(download_number_label, False, False)
        download_number_hbox.pack_start(self.download_number_comobox, False, False)
        
        change_download_dir_label = Label(_("Download directory: "))
        self.dir_entry = InputEntry()
        self.dir_entry.set_text(get_software_download_dir())
        self.dir_entry.set_editable(False)
        self.dir_entry.set_size(200, 25)
        
        modify_button = Button(_("Change"))
        modify_button.connect("clicked", self.change_download_save_dir)
        download_dir_hbox = gtk.HBox(spacing=5)
        download_dir_hbox.pack_start(change_download_dir_label, False, False)
        download_dir_hbox.pack_start(self.dir_entry, False, False)
        download_dir_hbox.pack_start(modify_button, False, False)
        
        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xpadding=10, xoptions=gtk.FILL)
        return main_table

    def create_uninstall_box(self):
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        uninstall_title_label = Label(_("On uninstall software"))
        uninstall_title_label.set_size_request(350, 12)
        
        # mini_check_button

        self.delete_check_button = CheckButton(_("Delete configuration files"))
        self.delete_check_button.set_active(get_purg_flag())
        self.delete_check_button.connect("toggled", lambda w: set_purge_flag(self.delete_check_button.get_active()))
        
        main_table.attach(uninstall_title_label, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.delete_check_button, 0, 1, 2, 3, yoptions=gtk.FILL)
        
        return main_table

    def change_download_save_dir(self, widget):
        local_dir = WinDir(False).run()
        if local_dir:
            local_dir = os.path.expanduser(local_dir)
            if local_dir != get_software_download_dir():
                self.dir_entry.set_editable(True)        
                self.dir_entry.set_text(local_dir)
                self.dir_entry.set_editable(False)
                set_software_download_dir(local_dir)
                global_event.emit('download-directory-changed')

    def download_number_comobox_changed(self, widget, name, value, index):
        set_download_number(value)
        global_event.emit('max-download-number-changed', value)

    def change_auto_update(self, widget, data=None):
        self.update_spin.set_sensitive(widget.get_active())
        set_auto_update(widget.get_active())
        self.update_label.set_sensitive(widget.get_active())
        self.hour_lablel.set_sensitive(widget.get_active())
        dsc_daemon_path = os.path.join(get_parent_dir(__file__, 2), 'update_data/apt/dsc-daemon.py')
        if widget.get_active():
            subprocess.Popen(['python', dsc_daemon_path], stderr=subprocess.STDOUT, shell=False)
예제 #8
0
class Broadband(gtk.VBox):
    ENTRY_WIDTH = 222
    LEFT_PADDING = 210
    def __init__(self, connection, set_button_callback, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Broadband")
        self.connection = connection        
        self.set_button = set_button_callback
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        # Init widgets
        self.table = gtk.Table(12, 4, False)
        
        #self.label_basic = Label(_("Basic"), text_size = TITLE_FONT_SIZE)
        self.label_basic = TitleBar(None, _("Basic"))
        self.label_number = Label(_("Code:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_username = Label(_("Username:"******"Password:"******"Show password"), padding_x=0)
        self.button_to_region = Button(_("Regions setting"))


        #self.table = gtk.Table(6, 4, False)
        self.label_advanced = TitleBar(None,_("Advanced"))
        self.label_apn = Label(_("APN:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_network = Label(_("Network ID:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_type = Label(_("Type:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_pin = Label(_("PIN:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)

        self.apn = InputEntry()
        self.network_id = InputEntry()
        self.network_type = ComboBox([("Any", None),
                                      ("3G", 0),
                                      ("2G", 1),
                                      ("Prefer 3G", 2),
                                      ("Prefer 2G", 3)],
                                      fixed_width=self.ENTRY_WIDTH)
        self.roam_check = CheckButton(_("Allow roaming if home network is not available"), padding_x=0)
        self.pin = InputEntry()
        
        
        # Connect signals
        self.number.entry.connect("changed", self.save_settings_by, "number")
        self.username.entry.connect("changed", self.save_settings_by, "username")
        self.password.entry.connect("changed", self.save_settings_by, "password")
        self.apn.entry.connect("changed", self.save_settings_by, "apn")
        self.network_id.entry.connect("changed", self.save_settings_by, "network_id")
        self.network_type.connect("item-selected", self.network_type_selected)

        self.password_show.connect("toggled", self.password_show_toggled)
        self.roam_check.connect("toggled", self.roam_check_toggled)


        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        self.pack_start(table_align)

        # wrap with alignment
        
        # Refesh
        self.refresh()

    def password_show_toggled(self, widget):
        if widget.get_active():
            self.password.show_password(True)
        else:
            self.password.show_password(False)

    def init_table(self, network_type):
        #container_remove_all(self.table)
        if self.table.get_children() != []:
            pass
        else:
            #self.table.attach(self.label_basic, 0,2 ,0, 1)
            self.table.attach(style.wrap_with_align(self.label_number, width=self.LEFT_PADDING), 0, 1, 1, 2)
            self.table.attach(style.wrap_with_align(self.label_username, width=self.LEFT_PADDING), 0, 1, 2, 3)
            self.table.attach(style.wrap_with_align(self.label_password, width=self.LEFT_PADDING), 0, 1, 3, 4)

            self.table.attach(style.wrap_with_align(self.number), 1, 2, 1, 2)
            self.table.attach(style.wrap_with_align(self.username), 1, 2, 2, 3)
            self.table.attach(style.wrap_with_align(self.password), 1, 2, 3, 4)
            self.table.attach(style.wrap_with_align(self.password_show, align="left"), 1, 2, 4, 5)

            def to_region(widget):
                region = slider.get_page_by_name("region")
                region.init(self.connection)
                #region.need_new_connection =False
                slider._slide_to_page("region", "none")

            if network_type == "gsm":
                self.button_to_region.connect("clicked", to_region)
                self.table.attach(style.wrap_with_align(self.button_to_region), 1,2,5,6)
                self.table.attach(self.label_advanced, 0, 2, 6, 7)
                self.table.attach(style.wrap_with_align(self.label_apn), 0, 1 , 7, 8)
                self.table.attach(style.wrap_with_align(self.label_network), 0, 1, 8, 9)
                self.table.attach(style.wrap_with_align(self.label_type), 0, 1, 9, 10)
                self.table.attach(style.wrap_with_align(self.label_pin), 0, 1, 11, 12)

                self.table.attach(style.wrap_with_align(self.apn), 1, 2, 7, 8)
                self.table.attach(style.wrap_with_align(self.network_id), 1, 2, 8, 9)
                self.table.attach(style.wrap_with_align(self.network_type), 1, 2, 9, 10)
                self.table.attach(style.wrap_with_align(self.roam_check, align="left"), 1, 2, 10, 11)
                self.table.attach(style.wrap_with_align(self.pin), 1, 2, 11, 12)
            #TODO ui change
            #style.set_table_items(self.table, 'entry')
            entry_list = ["number", "username", "password",
                          "apn", "network_id", "pin"]
            for entry in entry_list:
                widget = getattr(self, entry)
                widget.entry.set_size_request(self.ENTRY_WIDTH, 22)

            style.set_table(self.table)
        self.table.show_all()

    def refresh(self):
        # get_settings
        mobile_type = self.connection.get_setting("connection").type
        self.broadband_setting = self.connection.get_setting(mobile_type)
        number = self.broadband_setting.number
        username = self.broadband_setting.username

        password = self.broadband_setting.password

        if password == None:
            try:
                (setting_name, method) = self.connection.guess_secret_info() 
                password = nm_module.secret_agent.agent_get_secrets(self.connection.object_path,
                                                        setting_name,
                                                        method)
            except:
                password = ""

        # both
        self.number.set_text(number)
        self.username.set_text(username)
        self.password.entry.set_text(password)

        if  mobile_type == "gsm":
            apn = self.broadband_setting.apn
            network_id = self.broadband_setting.network_id
            network_type = self.broadband_setting.network_type
            home_only = self.broadband_setting.home_only
            
            # gsm
            self.apn.set_text(apn)
            self.network_id.set_text(network_id)
            if network_type:
                self.network_type.set_select_index(network_type + 1)
            else:
                self.network_type.set_select_index(0)

            self.roam_check.set_active(home_only is None)

        self.init_table(mobile_type)
        
        ## retrieve wired info

    def set_new_values(self, new_dict, type):
        params = new_dict[type]

        for key, value in params.iteritems():
            setattr(self.broadband_setting, key, value)
        self.refresh()

    def save_settings_by(self, widget, text, attr):
        if text == "":
            delattr(self.broadband_setting, attr)
        else:
            setattr(self.broadband_setting, attr, text)
        self.set_button("save", True)

    def network_type_selected(self, widget, content, value, index):
        if value == None:
            del self.broadband_setting.network_type
        else:
            self.broadband_setting.network_type = value

    def roam_check_toggled(self, widget):
        if widget.get_active():
            del self.broadband_setting.home_only
        else:
            self.broadband_setting.home_only = 1

    def expose_bg(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb( 1, 1, 1) 
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
class PPTPConf(gtk.VBox):
    ENTRY_WIDTH = 222
    LEFT_PADDING = 210

    def __init__(self,
                 connection,
                 module_frame,
                 set_button_callback=None,
                 settings_obj=None):
        gtk.VBox.__init__(self)
        self.connection = connection
        self.tab_name = _("PPTP")
        self.module_frame = module_frame
        self.set_button = set_button_callback
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.vpn_setting = self.connection.get_setting("vpn")

        # UI

        pptp_table = gtk.Table(7, 4, False)

        name_label = Label(_("Connection Name:"),
                           enable_select=False,
                           enable_double_click=False)
        name_label.set_can_focus(False)
        gateway_label = Label(_("Gateway:"),
                              enable_select=False,
                              enable_double_click=False)
        gateway_label.set_can_focus(False)
        user_label = Label(_("Username:"******"Password:"******"NT Domain:"),
                                enable_select=False,
                                enable_double_click=False)
        nt_domain_label.set_can_focus(False)
        # Radio Button
        self.pptp_radio = RadioButton(_("PPTP"))
        self.l2tp_radio = RadioButton(_("L2TP"))
        radio_box = gtk.HBox(spacing=30)
        radio_box.pack_start(self.pptp_radio, True, True)
        radio_box.pack_start(self.l2tp_radio, True, True)
        #pack labels
        pptp_table.attach(style.wrap_with_align(radio_box, align="left"), 2, 4,
                          0, 1)
        pptp_table.attach(
            style.wrap_with_align(name_label, width=self.LEFT_PADDING), 0, 2,
            1, 2)
        pptp_table.attach(
            style.wrap_with_align(gateway_label, width=self.LEFT_PADDING), 0,
            2, 2, 3)
        pptp_table.attach(
            style.wrap_with_align(user_label, width=self.LEFT_PADDING), 0, 2,
            3, 4)
        pptp_table.attach(
            style.wrap_with_align(password_label, width=self.LEFT_PADDING), 0,
            2, 4, 5)
        #pptp_table.attach(style.wrap_with_align(nt_domain_label), 0, 2, 5, 6)

        # entries
        self.name_entry = InputEntry()
        self.name_entry.set_size(self.ENTRY_WIDTH, 22)

        self.gateway_entry = InputEntry()
        self.gateway_entry.set_size(self.ENTRY_WIDTH, 22)
        self.user_entry = InputEntry()
        self.user_entry.set_size(self.ENTRY_WIDTH, 22)
        # FIXME should change to new_entry PasswordEntry
        self.password_entry = PasswordEntry()
        self.password_entry.set_size(self.ENTRY_WIDTH, 22)
        self.password_show = CheckButton(_("Show Password"), padding_x=0)
        self.password_show.set_active(False)
        self.password_show.connect("toggled", self.show_password)
        self.nt_domain_entry = InputEntry()
        self.nt_domain_entry.set_size(self.ENTRY_WIDTH, 22)

        #pack entries
        pptp_table.attach(style.wrap_with_align(self.name_entry, align="left"),
                          2, 4, 1, 2)
        pptp_table.attach(
            style.wrap_with_align(self.gateway_entry, align="left"), 2, 4, 2,
            3)
        pptp_table.attach(style.wrap_with_align(self.user_entry, align="left"),
                          2, 4, 3, 4)
        pptp_table.attach(
            style.wrap_with_align(self.password_entry, align="left"), 2, 4, 4,
            5)
        pptp_table.attach(
            style.wrap_with_align(self.password_show, align="left"), 2, 4, 5,
            6)
        #pptp_table.attach(style.wrap_with_align(self.nt_domain_entry), 2, 4, 5, 6)
        # Advance setting button
        #advanced_button = Button(_("Advanced Setting"))
        #advanced_button.connect("clicked", self.advanced_button_click)

        #pptp_table.attach(style.wrap_with_align(advanced_button), 3, 4, 6, 7)
        self.service_type = self.vpn_setting.service_type.split(".")[-1]
        if self.service_type == "l2tp":
            self.l2tp_radio.set_active(True)
        else:
            self.pptp_radio.set_active(True)
        self.pptp_radio.connect("toggled", self.radio_toggled, "pptp")
        self.l2tp_radio.connect("toggled", self.radio_toggled, "l2tp")
        # set signals

        #align = style.set_box_with_align(pptp_table, "text")
        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(pptp_table)
        #style.set_table_items(pptp_table, "entry")
        style.draw_background_color(self)
        style.set_table(pptp_table)
        self.add(table_align)
        self.show_all()
        self.refresh()
        self.name_entry.entry.connect("changed", self.entry_changed, "name")
        self.gateway_entry.entry.connect("changed", self.entry_changed,
                                         "gateway")
        self.user_entry.entry.connect("changed", self.entry_changed, "user")
        self.password_entry.entry.connect("changed", self.entry_changed,
                                          "password")
        self.nt_domain_entry.entry.connect("changed", self.entry_changed,
                                           "domain")

        #if self.connection.check_setting_finish():
        #print "in vpn"
        #Dispatcher.set_button("save", True)
        #else:
        #print "in vpn"
        #Dispatcher.set_button("save", False)
        ##############
        #is_valid = self.connection.check_setting_finish()
        #self.settings_obj.vpn_is_valid = is_valid
        #self.settings_obj.set_button("save", is_valid)

    def refresh(self):
        #print ">>>",self.vpn_setting.data
        #print self.vpn_setting.data
        name = self.connection.get_setting("connection").id
        gateway = self.vpn_setting.get_data_item("gateway")
        user = self.vpn_setting.get_data_item("user")
        domain = self.vpn_setting.get_data_item("domain")

        if type(self.connection) == NMRemoteConnection:
            self.name_entry.set_text(name)

        if gateway:
            self.gateway_entry.set_text(gateway)
        if user:
            self.user_entry.set_text(user)

        (setting_name, method) = self.connection.guess_secret_info()
        try:
            password = nm_module.secret_agent.agent_get_secrets(
                self.connection.object_path, setting_name, method)
            if password is None:
                #self.password_entry.entry.set_text("")
                self.password_entry.entry.set_text("")
            else:
                #self.password_entry.entry.set_text(password)
                self.password_entry.entry.set_text(password)
                self.vpn_setting.set_secret_item("password", password)
        except:
            pass

        if domain:
            self.nt_domain_entry.set_text(domain)

    def save_setting(self):
        pass

    def show_password(self, widget):
        if widget.get_active():
            self.password_entry.show_password(True)
        else:
            self.password_entry.show_password(False)

    def entry_changed(self, widget, content, item):
        text = content
        if item == "name":
            self.connection.get_setting("connection").id = content

        if text:
            if item == "password":
                self.vpn_setting.set_secret_item(item, text)
            elif item != "name":
                self.vpn_setting.set_data_item(item, text)

        else:
            if item == "password":
                self.vpn_setting.set_secret_item(item, "")
            else:
                self.vpn_setting.delete_data_item(item)

        #if self.connection.check_setting_finish():
        #Dispatcher.set_button("save", True)
        #else:
        #Dispatcher.set_button("save", False)
        ##############
        is_valid = self.connection.check_setting_finish()
        self.settings_obj.vpn_is_valid = is_valid
        self.settings_obj.set_button("save", is_valid)

    def radio_toggled(self, widget, service_type):
        if widget.get_active():
            self.vpn_setting.service_type = "org.freedesktop.NetworkManager." + service_type
            self.service_type = service_type

        if self.connection.check_setting_finish():
            Dispatcher.set_button("save", True)
        else:
            Dispatcher.set_button("save", False)
            self.refresh()

        Dispatcher.emit("vpn-type-change", self.connection)

    def advanced_button_click(self, widget):
        ppp = PPPConf(self.module_frame, Dispatcher.set_button)
        ppp.refresh(self.connection)
        Dispatcher.send_submodule_crumb(3, _("Advanced"))
        nm_module.slider.slide_to_page(ppp, "none")
class PPTPConf(gtk.VBox):
    ENTRY_WIDTH = 222
    LEFT_PADDING = 210
    def __init__(self, connection, module_frame, set_button_callback=None, settings_obj=None):
        gtk.VBox.__init__(self)
        self.connection = connection
        self.tab_name = _("PPTP")
        self.module_frame = module_frame
        self.set_button = set_button_callback
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.vpn_setting = self.connection.get_setting("vpn")

        # UI

        pptp_table = gtk.Table(7, 4, False)

        name_label = Label(_("Connection Name:"),
                               enable_select=False,
                               enable_double_click=False)
        name_label.set_can_focus(False)
        gateway_label = Label(_("Gateway:"),
                               enable_select=False,
                               enable_double_click=False)
        gateway_label.set_can_focus(False)
        user_label = Label(_("Username:"******"Password:"******"NT Domain:"),
                               enable_select=False,
                               enable_double_click=False)
        nt_domain_label.set_can_focus(False)
        # Radio Button
        self.pptp_radio = RadioButton(_("PPTP"))
        self.l2tp_radio = RadioButton(_("L2TP"))
        radio_box = gtk.HBox(spacing=30)
        radio_box.pack_start(self.pptp_radio, True, True)
        radio_box.pack_start(self.l2tp_radio, True, True)
        #pack labels
        pptp_table.attach(style.wrap_with_align(radio_box, align="left"), 2,4, 0, 1)
        pptp_table.attach(style.wrap_with_align(name_label, width=self.LEFT_PADDING), 0, 2, 1, 2)
        pptp_table.attach(style.wrap_with_align(gateway_label, width=self.LEFT_PADDING), 0, 2 , 2, 3)
        pptp_table.attach(style.wrap_with_align(user_label, width=self.LEFT_PADDING), 0, 2, 3, 4)
        pptp_table.attach(style.wrap_with_align(password_label, width=self.LEFT_PADDING), 0, 2, 4, 5)
        #pptp_table.attach(style.wrap_with_align(nt_domain_label), 0, 2, 5, 6)

        # entries
        self.name_entry = InputEntry()
        self.name_entry.set_size(self.ENTRY_WIDTH, 22)

        self.gateway_entry = InputEntry()
        self.gateway_entry.set_size(self.ENTRY_WIDTH,22)
        self.user_entry = InputEntry()
        self.user_entry.set_size(self.ENTRY_WIDTH, 22)
        # FIXME should change to new_entry PasswordEntry
        self.password_entry = PasswordEntry()
        self.password_entry.set_size(self.ENTRY_WIDTH, 22)
        self.password_show = CheckButton(_("Show Password"), padding_x=0)
        self.password_show.set_active(False)
        self.password_show.connect("toggled", self.show_password)
        self.nt_domain_entry = InputEntry()
        self.nt_domain_entry.set_size(self.ENTRY_WIDTH, 22)

        #pack entries
        pptp_table.attach(style.wrap_with_align(self.name_entry, align="left"), 2, 4, 1, 2)
        pptp_table.attach(style.wrap_with_align(self.gateway_entry, align="left"), 2, 4, 2, 3)
        pptp_table.attach(style.wrap_with_align(self.user_entry, align="left"), 2, 4, 3, 4)
        pptp_table.attach(style.wrap_with_align(self.password_entry, align="left"), 2, 4, 4, 5)
        pptp_table.attach(style.wrap_with_align(self.password_show, align="left"), 2, 4, 5, 6)
        #pptp_table.attach(style.wrap_with_align(self.nt_domain_entry), 2, 4, 5, 6)
        # Advance setting button
        #advanced_button = Button(_("Advanced Setting"))
        #advanced_button.connect("clicked", self.advanced_button_click)

        #pptp_table.attach(style.wrap_with_align(advanced_button), 3, 4, 6, 7)
        self.service_type = self.vpn_setting.service_type.split(".")[-1]
        if self.service_type == "l2tp":
            self.l2tp_radio.set_active(True)
        else:
            self.pptp_radio.set_active(True)
        self.pptp_radio.connect("toggled",self.radio_toggled, "pptp")
        self.l2tp_radio.connect("toggled",self.radio_toggled, "l2tp")
        # set signals

        #align = style.set_box_with_align(pptp_table, "text")
        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(pptp_table)
        #style.set_table_items(pptp_table, "entry")
        style.draw_background_color(self)
        style.set_table(pptp_table)
        self.add(table_align)
        self.show_all()
        self.refresh()
        self.name_entry.entry.connect("changed", self.entry_changed, "name")
        self.gateway_entry.entry.connect("changed", self.entry_changed, "gateway")
        self.user_entry.entry.connect("changed", self.entry_changed, "user")
        self.password_entry.entry.connect("changed", self.entry_changed, "password")
        self.nt_domain_entry.entry.connect("changed", self.entry_changed, "domain")

        #if self.connection.check_setting_finish():
            #print "in vpn"
            #Dispatcher.set_button("save", True)
        #else:
            #print "in vpn"
            #Dispatcher.set_button("save", False)
        ##############
        #is_valid = self.connection.check_setting_finish()
        #self.settings_obj.vpn_is_valid = is_valid
        #self.settings_obj.set_button("save", is_valid)

    def refresh(self):
        #print ">>>",self.vpn_setting.data
        #print self.vpn_setting.data
        name = self.connection.get_setting("connection").id
        gateway = self.vpn_setting.get_data_item("gateway")
        user = self.vpn_setting.get_data_item("user")
        domain = self.vpn_setting.get_data_item("domain")

        if type(self.connection) == NMRemoteConnection:
            self.name_entry.set_text(name)

        if gateway:
            self.gateway_entry.set_text(gateway)
        if user:
            self.user_entry.set_text(user)

        (setting_name, method) = self.connection.guess_secret_info() 
        try:
            password = nm_module.secret_agent.agent_get_secrets(self.connection.object_path,
                                                    setting_name,
                                                    method)
            if password is None:
                #self.password_entry.entry.set_text("")
                self.password_entry.entry.set_text("")
            else:
                #self.password_entry.entry.set_text(password)
                self.password_entry.entry.set_text(password)
                self.vpn_setting.set_secret_item("password", password)
        except:
            pass

        if domain:
            self.nt_domain_entry.set_text(domain)
                
    def save_setting(self):
        pass

    def show_password(self, widget):
        if widget.get_active():
            self.password_entry.show_password(True)
        else:
            self.password_entry.show_password(False)


    def entry_changed(self, widget, content, item):
        text = content
        if item == "name":
            self.connection.get_setting("connection").id = content

        if text:
            if item == "password":
                self.vpn_setting.set_secret_item(item, text)
            elif item != "name":
                self.vpn_setting.set_data_item(item, text)
            
        else:
            if item == "password":
                self.vpn_setting.set_secret_item(item, "")
            else:
                self.vpn_setting.delete_data_item(item)

        #if self.connection.check_setting_finish():
            #Dispatcher.set_button("save", True)
        #else:
            #Dispatcher.set_button("save", False)
        ##############
        is_valid = self.connection.check_setting_finish()
        self.settings_obj.vpn_is_valid = is_valid
        self.settings_obj.set_button("save", is_valid)
    
    def radio_toggled(self, widget, service_type):
        if widget.get_active():
            self.vpn_setting.service_type = "org.freedesktop.NetworkManager." + service_type
            self.service_type = service_type

        if self.connection.check_setting_finish():
            Dispatcher.set_button("save", True)
        else:
            Dispatcher.set_button("save", False)
            self.refresh()

        Dispatcher.emit("vpn-type-change", self.connection)
            

    def advanced_button_click(self, widget):
        ppp = PPPConf(self.module_frame, Dispatcher.set_button)
        ppp.refresh(self.connection)
        Dispatcher.send_submodule_crumb(3, _("Advanced"))
        nm_module.slider.slide_to_page(ppp, "none")
예제 #11
0
class MirrorsBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.current_mirror_item = None

        self.select_best_mirror_button_texts = {
                "normal": _("Select the best mirror"),
                "wait": _("Waiting"),
                "success": _("Successfully")
                }

        self.main_box.pack_start(self.create_mirror_select_table(), True, True)
        self.main_box.pack_start(self.create_source_update_frequency_table(), False, True)
        self.mirror_test_obj = None

        global_event.register_event("mirror-test-finished", self.finish_mirror_test)
        global_event.register_event("cancel-mirror-test", self.cancel_mirror_test)
        global_event.register_event("mirror-backend-changed", self.mirror_changed_handler)

    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Refresh package lists"))

        # auto update check button
        self.is_auto_update_button = CheckButton(label_text=_('Upgrade automatically'))
        self.is_auto_update_button.connect('released', self.change_auto_update)
        self.is_auto_update_button.set_active(utils.is_auto_update())

        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(dir_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        return main_table

    def change_auto_update(self, widget, data=None):
        widget_active = widget.get_active()
        self.update_spin.set_sensitive(widget_active)
        self.update_label.set_sensitive(widget_active)
        self.hour_lablel.set_sensitive(widget_active)

        utils.set_auto_update(widget_active)

        daemon_running = is_dbus_name_exists(DSC_UPDATE_DAEMON_NAME)
        if widget_active and not daemon_running:
            dsc_daemon_path = os.path.join(get_parent_dir(__file__, 2), 'update_data/apt/dsc-daemon.py')
            subprocess.Popen(['python', dsc_daemon_path], stderr=subprocess.STDOUT, shell=False)
        elif not widget_active and daemon_running:
            session = dbus.SessionBus()
            dbus_obj = session.get_object(DSC_UPDATE_DAEMON_NAME, DSC_UPDATE_DAEMON_PATH)
            iface = dbus.Interface(dbus_obj, DSC_UPDATE_DAEMON_NAME)
            iface.quit()

    def select_best_mirror(self, widget):
        widget.set_label(self.select_best_mirror_button_texts["wait"])
        widget.set_sensitive(False)
        global_event.emit("toggle-waiting-dialog", True)
        utils.ThreadMethod(self.change_to_nearest_mirror_thread, (widget, )).start()

    def cancel_mirror_test(self):
        if self.mirror_test_obj:
            self.mirror_test_obj.cancel()
            self.mirror_test_obj = None
            self.finish_mirror_test("")

    def change_to_nearest_mirror_thread(self, widget):
        best_mirror = get_best_mirror()
        global_event.emit("mirror-test-finished", best_mirror)

    def finish_mirror_test(self, mirror):
        for item in self.mirror_view.visible_items:
            if item.mirror == mirror:
                self.mirror_view.visible_item(item)
        self.select_best_mirror_button.set_sensitive(True)
        self.select_best_mirror_button.set_label(self.select_best_mirror_button_texts["normal"])

    def create_mirror_select_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        mirror_select_title = Label(_("Select mirror"))
        self.select_best_mirror_button = Button(self.select_best_mirror_button_texts["normal"])
        self.select_best_mirror_button.connect("clicked", self.select_best_mirror)

        self.mirrors_dir = os.path.join(get_parent_dir(__file__, 2), 'mirrors')
        self.current_mirror_hostname = utils.get_current_mirror_hostname()
        self.mirror_items = self.get_mirror_items()
        self.mirror_view = TreeView(self.mirror_items,
                                enable_drag_drop=False,
                                enable_multiple_select=False,
                                mask_bound_height=0,
                             )
        self.mirror_view.set_expand_column(1)
        self.mirror_view.set_size_request(-1, 280)
        self.mirror_view.draw_mask = self.mirror_treeview_draw_mask

        main_table.attach(mirror_select_title, 0, 1, 0, 1, yoptions=gtk.FILL)
        main_table.attach(self.select_best_mirror_button, 1, 2, 0, 1, xoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, xoptions=gtk.FILL)
        main_table.attach(self.mirror_view, 0, 2, 2, 3, xoptions=gtk.FILL)


        return main_table

    def mirror_changed_handler(self, mirror):
        item = None
        for i in self.mirror_view.visible_items:
            if i.mirror == mirror:
                item = i
                break
        if item:
            self.current_mirror_item = item
            for i in self.mirror_items:
                if i != item and i.radio_button.active == True:
                    i.radio_button.active = False
                elif i == item:
                    i.radio_button.active = True
            self.mirror_view.queue_draw()
            self.mirror_view.visible_item(item)

    def mirror_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgba(1, 1, 1, 0.5)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_mirror_items(self):
        items = []
        for m in all_mirrors:
            item = MirrorItem(m, self.mirror_clicked_callback)
            if m.hostname == self.current_mirror_hostname:
                item.radio_button.active = True
                self.current_mirror_item = item
            items.append(item)
        return items

    def mirror_clicked_callback(self, item):
        if item != self.current_mirror_item:
            global_event.emit('start-change-mirror', item.mirror)
예제 #12
0
class GeneralBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.main_box.pack_start(self.create_uninstall_box(), False, True)
        self.main_box.pack_start(self.create_download_dir_table(), False, True)

    def create_uninstall_box(self):
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        uninstall_title_label = Label(_("On uninstalling the software"))

        # mini_check_button
        self.delete_check_button = CheckButton(_("Delete configuration files"))
        self.delete_check_button.set_active(get_purg_flag())
        self.delete_check_button.connect("toggled", lambda w: set_purge_flag(self.delete_check_button.get_active()))

        main_table.attach(uninstall_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.delete_check_button, 0, 1, 2, 3, yoptions=gtk.FILL)

        return main_table

    def create_download_dir_table(self):
        main_table = gtk.Table(4, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Download settings"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        download_number_label = Label(_('Maximum number of download tasks: '))
        self.download_number_comobox = ComboBox(
                items = [(str(i+1), i+1) for i in range(10)],
                select_index = int(get_download_number())-1,
                )
        self.download_number_comobox.connect("item-selected", self.download_number_comobox_changed)
        download_number_hbox = gtk.HBox(spacing=5)
        download_number_hbox.pack_start(download_number_label, False, False)
        download_number_hbox.pack_start(self.download_number_comobox, False, False)

        change_download_dir_label = Label(_("Download directory: "))
        self.dir_entry = InputEntry()
        self.dir_entry.set_text(get_software_download_dir())
        self.dir_entry.set_editable(False)
        self.dir_entry.set_size(200, 25)

        modify_button = Button(_("Change"))
        modify_button.connect("clicked", self.change_download_save_dir)
        download_dir_hbox = gtk.HBox(spacing=5)
        download_dir_hbox.pack_start(change_download_dir_label, False, False)
        download_dir_hbox.pack_start(self.dir_entry, False, False)
        download_dir_hbox.pack_start(modify_button, False, False)

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xoptions=gtk.FILL)
        return main_table

    def download_number_comobox_changed(self, widget, name, value, index):
        set_download_number(value)
        global_event.emit('max-download-number-changed', value)

    def change_download_save_dir(self, widget):
        local_dir = FolderChooseDialog(False).run()
        if local_dir:
            local_dir = os.path.expanduser(local_dir)
            if local_dir != get_software_download_dir():
                self.dir_entry.set_editable(True)
                self.dir_entry.set_text(local_dir)
                self.dir_entry.set_editable(False)
                set_software_download_dir(local_dir)
                global_event.emit('download-directory-changed')