Example #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)
Example #2
0
    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])
Example #3
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)    
Example #4
0
    icon_view_vframe.add(icon_view_hframe)

    icon_files = map(
        lambda index: os.path.join(os.path.dirname(__file__), "cover/%s.jpg" %
                                   (index)), range(1, 33))
    # icon_items = map(lambda icon_file_path: IconItem(icon_file_path, 96, 96), icon_files * 100)
    only_one_icon_items = []
    # only_one_icon_items.append(icon_items[0])
    # icon_view.add_items(icon_items)

    tab_4_box.pack_start(icon_view_vframe, True, True)

    # Tab 5.
    button_box = gtk.VBox()
    check_button = CheckButton(label_text="Check Button")
    radio_button_1 = RadioButton("Radio Button1")
    radio_button_2 = RadioButton("Radio Button2")
    button_box.pack_start(check_button, False, False, 4)
    button_box.pack_start(radio_button_1, False, False, 4)
    button_box.pack_start(radio_button_2, False, False, 4)
    tab_5_box.pack_start(button_box, False, False)

    # Breadcrumb
    bread = Bread(["Root", None], show_entry=True, show_others=False)
    bread.connect(
        "entry-changed",
        lambda w, p: bread.change_node(0, [(i, [(None, "test", None)])
                                           for i in p.split("/")[1:]]))
    bread.set_size(100, -1)

    tab_5_box.pack_start(bread, False, False)
Example #5
0
 def __create_widget(self):
     '''create gtk widget'''
     title_item_font_size = TITLE_FONT_SIZE
     option_item_font_size = CONTENT_FONT_SIZE
     # image init
     self.image_widgets["custom"] = ImageBox(
         app_theme.get_pixbuf("%s/pad_l%s.png" %
                              (MODULE_NAME, self.has_touchpad_icon)))
     self.image_widgets["speed"] = ImageBox(
         app_theme.get_pixbuf("%s/pointer%s.png" %
                              (MODULE_NAME, self.has_touchpad_icon)))
     self.image_widgets["double"] = ImageBox(
         app_theme.get_pixbuf("%s/double-click%s.png" %
                              (MODULE_NAME, self.has_touchpad_icon)))
     self.image_widgets["drag"] = ImageBox(
         app_theme.get_pixbuf("%s/drag%s.png" %
                              (MODULE_NAME, self.has_touchpad_icon)))
     self.image_widgets["double_test_1"] = app_theme.get_pixbuf(
         "%s/smiley00%s.png" % (MODULE_NAME, self.has_touchpad_icon))
     self.image_widgets["double_test_2"] = app_theme.get_pixbuf(
         "%s/smiley01.png" % (MODULE_NAME))
     # label init
     self.label_widgets["custom"] = Label(
         _("Custom"),
         app_theme.get_color("globalTitleForeground"),
         text_size=title_item_font_size,
         enable_select=False,
         enable_double_click=False)
     self.label_widgets["pointer_speed"] = Label(
         _("Pointer Speed"),
         app_theme.get_color("globalTitleForeground"),
         text_size=title_item_font_size,
         enable_select=False,
         enable_double_click=False)
     self.label_widgets["acceleration"] = Label(
         _("Acceleration"),
         text_size=option_item_font_size,
         text_x_align=ALIGN_END,
         enable_select=False,
         enable_double_click=False,
         fixed_width=STANDARD_LINE)
     self.label_widgets["sensitivity"] = Label(
         _("Sensitivity"),
         text_size=option_item_font_size,
         text_x_align=ALIGN_END,
         enable_select=False,
         enable_double_click=False,
         fixed_width=STANDARD_LINE)
     self.label_widgets["double_click"] = Label(
         _("Double-click"),
         app_theme.get_color("globalTitleForeground"),
         text_size=title_item_font_size,
         enable_select=False,
         enable_double_click=False)
     self.label_widgets["click_rate"] = Label(
         _("Frequency"),
         text_size=option_item_font_size,
         text_x_align=ALIGN_END,
         enable_select=False,
         enable_double_click=False,
         fixed_width=STANDARD_LINE)
     self.label_widgets["double_test"] = Label(
         _("Double-click on the smiley face to test your settings."),
         label_width=HSCALEBAR_WIDTH,
         wrap_width=HSCALEBAR_WIDTH,
         enable_select=False,
         enable_double_click=False)
     self.label_widgets["drag_drop"] = Label(
         _("Drag and Drop"),
         app_theme.get_color("globalTitleForeground"),
         text_size=title_item_font_size,
         enable_select=False,
         enable_double_click=False)
     self.label_widgets["drag_threshold"] = Label(
         _("Drag threshold"),
         text_size=option_item_font_size,
         text_x_align=ALIGN_END,
         enable_select=False,
         enable_double_click=False,
         fixed_width=STANDARD_LINE)
     self.label_widgets["relevant"] = Label(_("Relevant Settings"),
                                            text_size=title_item_font_size,
                                            enable_select=False,
                                            enable_double_click=False,
                                            fixed_width=180)
     # button init
     self.button_widgets["right_hand_radio"] = RadioButton(
         _("Right-handed"), padding_x=10)
     self.button_widgets["left_hand_radio"] = RadioButton(_("Left-handed"),
                                                          padding_x=10)
     self.button_widgets["double_test"] = gtk.EventBox()
     # relevant settings button
     self.button_widgets["keyboard_setting"] = Label(
         "<u>%s</u>" % _("Keyboard Settings"),
         DynamicColor(GOTO_FG_COLOR),
         text_size=option_item_font_size,
         enable_select=False,
         enable_double_click=False,
         fixed_width=180)
     self.button_widgets["mouse_setting"] = Label(
         "<u>%s</u>" % _("Mouse Settings"),
         DynamicColor(GOTO_FG_COLOR),
         text_size=option_item_font_size,
         enable_select=False,
         enable_double_click=False,
         fixed_width=180)
     self.button_widgets["set_to_default"] = Button(_("Reset"))
     # container init
     self.container_widgets["main_vbox"] = gtk.VBox(False)
     self.container_widgets["statusbar"] = StatusBar()
     self.container_widgets["main_swindow"] = ScrolledWindow()
     self.container_widgets["main_hbox"] = gtk.HBox(False)
     self.container_widgets["left_vbox"] = gtk.VBox(False)
     self.container_widgets["right_vbox"] = gtk.VBox(False)
     self.container_widgets["custom_main_vbox"] = gtk.VBox(False)  # custom
     self.container_widgets["custom_label_hbox"] = gtk.HBox(False)
     self.container_widgets["custom_button_hbox"] = gtk.HBox(False)
     self.container_widgets["pointer_speed_main_vbox"] = gtk.VBox(
         False)  # pointer speed
     self.container_widgets["pointer_speed_label_hbox"] = gtk.HBox(False)
     self.container_widgets["pointer_speed_table"] = gtk.Table(2, 4, False)
     self.container_widgets["double_click_main_vbox"] = gtk.VBox(
         False)  # double click
     self.container_widgets["double_click_label_hbox"] = gtk.HBox(False)
     self.container_widgets["double_click_table"] = gtk.Table(2, 4, False)
     self.container_widgets["drag_threshold_main_vbox"] = gtk.VBox(
         False)  # mouse wheel
     self.container_widgets["drag_threshold_label_hbox"] = gtk.HBox(False)
     self.container_widgets["drag_threshold_table"] = gtk.Table(1, 4, False)
     # alignment init
     self.alignment_widgets["left"] = gtk.Alignment()
     self.alignment_widgets["right"] = gtk.Alignment()
     self.alignment_widgets["custom_label"] = gtk.Alignment()  # custom
     self.alignment_widgets["custom_button"] = gtk.Alignment()
     self.alignment_widgets["pointer_speed_label"] = gtk.Alignment(
     )  # pointer speed
     self.alignment_widgets["pointer_speed_table"] = gtk.Alignment()
     self.alignment_widgets["double_click_label"] = gtk.Alignment(
     )  # double click
     self.alignment_widgets["double_click_table"] = gtk.Alignment()
     self.alignment_widgets["drag_threshold_label"] = gtk.Alignment(
     )  # mouse wheel
     self.alignment_widgets["drag_threshold_table"] = gtk.Alignment()
     self.alignment_widgets["keyboard_setting"] = gtk.Alignment()
     self.alignment_widgets["mouse_setting"] = gtk.Alignment()
     # adjust init
     self.adjust_widgets["pointer_speed_accel"] = gtk.Adjustment(
         1.0, 1.0, 10.0, 1, 2)
     self.adjust_widgets["pointer_speed_sensitiv"] = gtk.Adjustment(
         1, 1, 10, 1, 2)
     self.adjust_widgets["double_click_rate"] = gtk.Adjustment(
         100, 100, 1000, 100, 200)
     self.adjust_widgets["drag_threshold_time"] = gtk.Adjustment(
         1, 1, 10, 1, 2)
     # scale init
     self.scale_widgets["pointer_speed_accel"] = HScalebar(value_min=1.0,
                                                           value_max=10.0)
     self.scale_widgets["pointer_speed_sensitiv"] = HScalebar(value_min=1,
                                                              value_max=10)
     self.scale_widgets["double_click_rate"] = HScalebar(value_min=100,
                                                         value_max=1000)
     self.scale_widgets["drag_threshold_time"] = HScalebar(value_min=1,
                                                           value_max=10)
    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")
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")
    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")
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")