Beispiel #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)
Beispiel #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)    
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")