def _create_ui(self):
        dname = self.iface.devices(self.package)[self.device]
        new_data = {"name":_("New Profile"),
                    "device_id":self.device,
                    "device_name":dname,
                    "net_mode":"auto",
                    "name_mode":"default"}
        vbox = gtk.VBox(homogeneous=False,
                        spacing=5)
        self.add(vbox)

        self.pf = ProfileFrame(new_data)
        vbox.pack_start(self.pf, expand=False, fill=False)
        self.pf.show()
        if self.package == "wireless_tools":
            new_data["remote"] = self.data["remote"]
            _type = self.data["encryption"]
            self.wf = WirelessFrame(new_data,
                                    self.iface,
                                    package=self.package,
                                    connection="new",
                                    is_new=True,
                                    with_list=False,
                                    select_type=_type)
            vbox.pack_start(self.wf, expand=False, fill=False)
            self.wf.show()

        self.expander = gtk.Expander(_("Other Settings"))
        self.expander.set_expanded(False)
        vbox2 = gtk.VBox()
        self.expander.add(vbox2)
        vbox.pack_start(self.expander, expand=False, fill=False)
        self.expander.show()

        self.nf = NetworkFrame(new_data)
        vbox2.pack_start(self.nf, expand=False, fill=False)
        self.nf.show()

        self.nsf = NameServerFrame(new_data)
        vbox2.pack_start(self.nsf, expand=False, fill=False)
        self.nsf.show()

        vbox2.show()

        buttons = gtk.HBox(homogeneous=False,
                           spacing=6)
        self.save_btn = gtk.Button(_("Save"))
        self.save_and_connect_btn = gtk.Button(_("Save & Connect"))
        self.cancel_btn = gtk.Button(_("Cancel"))
        buttons.pack_end(self.save_and_connect_btn,
                         expand=False, fill=False)
        buttons.pack_end(self.save_btn, expand=False, fill=False)
        buttons.pack_end(self.cancel_btn, expand=False, fill=False)
        buttons.show_all()
        vbox.pack_end(buttons, expand=False, fill=False)
        vbox.show()
    def _create_ui(self):
        self.data = ""
        self._is_new = self._connection == "new"
        if not self._is_new:
            self.data = self.iface.info(self._package,
                                        self._connection)
            self.is_up = self.data["state"][0:2] == "up"
        else:
            dname = self.iface.devices(self._package)[self._device_id]
            self.data = {"name":"",
                         "device_id":self._device_id,
                         "device_name":dname,
                         "net_mode":"auto",
                         "name_mode":"default"}
            self.is_up = False
        vbox = gtk.VBox(homogeneous=False,
                        spacing=6)
        self.add(vbox)

        self.pf = ProfileFrame(self.data)
        vbox.pack_start(self.pf, expand=False, fill=False)

        if self.is_wireless:
            self.wf = WirelessFrame(self.data, self.iface,
                                    package=self._package,
                                    connection=self._connection,
                                    with_list=True,
                                    is_new=self._is_new)
            vbox.pack_start(self.wf, expand=True, fill=True)
            self.wf.show()

        self.nf = NetworkFrame(self.data)
        vbox.pack_start(self.nf, expand=False, fill=False)

        self.nsf = NameServerFrame(self.data)
        vbox.pack_start(self.nsf, expand=False, fill=False)
        self.nsf.show()

        buttons = gtk.HBox(homogeneous=False,
                           spacing=6)
        self.apply_btn = gtk.Button(_("Apply"))
        self.cancel_btn = gtk.Button(_("Cancel"))
        buttons.pack_end(self.apply_btn, expand=False, fill=False)
        buttons.pack_end(self.cancel_btn, expand=False, fill=False)
        buttons.show_all()
        vbox.pack_end(buttons, expand=False, fill=False)
        vbox.show()
class EditWindow(BaseWindow):
    """Edit Window
    """

    def __init__(self, iface, package, connection,
                 device_id=None):
        """init

        Arguments:
        - `iface`: backend.NetworkIface
        - `package`: package name
        - `connection`: connection name (can be 'new')
        """
        self._package = package
        self._connection = connection
        self._device_id = device_id
        self.is_wireless = False
        if self._package == "wireless_tools":
            self.is_wireless = True
        BaseWindow.__init__(self, iface)
    def _set_style(self):
        """sets title and default size
        """
        self.set_title(_("Edit Connection"))
        self.set_modal(True)
        if self.is_wireless:
            self.set_default_size(644, 400)
        else:
            self.set_default_size(483, 300)
    def _create_ui(self):
        self.data = ""
        self._is_new = self._connection == "new"
        if not self._is_new:
            self.data = self.iface.info(self._package,
                                        self._connection)
            self.is_up = self.data["state"][0:2] == "up"
        else:
            dname = self.iface.devices(self._package)[self._device_id]
            self.data = {"name":"",
                         "device_id":self._device_id,
                         "device_name":dname,
                         "net_mode":"auto",
                         "name_mode":"default"}
            self.is_up = False
        vbox = gtk.VBox(homogeneous=False,
                        spacing=6)
        self.add(vbox)

        self.pf = ProfileFrame(self.data)
        vbox.pack_start(self.pf, expand=False, fill=False)

        if self.is_wireless:
            self.wf = WirelessFrame(self.data, self.iface,
                                    package=self._package,
                                    connection=self._connection,
                                    with_list=True,
                                    is_new=self._is_new)
            vbox.pack_start(self.wf, expand=True, fill=True)
            self.wf.show()

        self.nf = NetworkFrame(self.data)
        vbox.pack_start(self.nf, expand=False, fill=False)

        self.nsf = NameServerFrame(self.data)
        vbox.pack_start(self.nsf, expand=False, fill=False)
        self.nsf.show()

        buttons = gtk.HBox(homogeneous=False,
                           spacing=6)
        self.apply_btn = gtk.Button(_("Apply"))
        self.cancel_btn = gtk.Button(_("Cancel"))
        buttons.pack_end(self.apply_btn, expand=False, fill=False)
        buttons.pack_end(self.cancel_btn, expand=False, fill=False)
        buttons.show_all()
        vbox.pack_end(buttons, expand=False, fill=False)
        vbox.show()
    def _listen_signals(self):
        self.apply_btn.connect("clicked", self.apply)
        self.cancel_btn.connect("clicked", self.cancel)
    def cancel(self, widget):
        self.destroy()
    def apply(self, widget):
        data = self.collect_data()
        try:
            self.iface.updateConnection(self._package,
                                        data["name"],
                                        data)
        except Exception, e:
            print "Exception:", unicode(e)
        if not self._is_new:
            if not self.data["name"] == data["name"]:
                self.iface.deleteConnection(self._package,
                                            self.data["name"])
            if self.is_up:
                self.iface.connect(self._package, data["name"])
        self.destroy()
class NewConnectionEditWindow(BaseWindow):
    """New Connection Settings Window"""
    def __init__(self, iface,
                 package, device, data):
        self.package = package
        self.data = data
        self.device = device
        BaseWindow.__init__(self, iface)
    def _set_style(self):
        self.set_title(_("Save Profile"))
        self.set_default_size(483, 300)
    def _create_ui(self):
        dname = self.iface.devices(self.package)[self.device]
        new_data = {"name":_("New Profile"),
                    "device_id":self.device,
                    "device_name":dname,
                    "net_mode":"auto",
                    "name_mode":"default"}
        vbox = gtk.VBox(homogeneous=False,
                        spacing=5)
        self.add(vbox)

        self.pf = ProfileFrame(new_data)
        vbox.pack_start(self.pf, expand=False, fill=False)
        self.pf.show()
        if self.package == "wireless_tools":
            new_data["remote"] = self.data["remote"]
            _type = self.data["encryption"]
            self.wf = WirelessFrame(new_data,
                                    self.iface,
                                    package=self.package,
                                    connection="new",
                                    is_new=True,
                                    with_list=False,
                                    select_type=_type)
            vbox.pack_start(self.wf, expand=False, fill=False)
            self.wf.show()

        self.expander = gtk.Expander(_("Other Settings"))
        self.expander.set_expanded(False)
        vbox2 = gtk.VBox()
        self.expander.add(vbox2)
        vbox.pack_start(self.expander, expand=False, fill=False)
        self.expander.show()

        self.nf = NetworkFrame(new_data)
        vbox2.pack_start(self.nf, expand=False, fill=False)
        self.nf.show()

        self.nsf = NameServerFrame(new_data)
        vbox2.pack_start(self.nsf, expand=False, fill=False)
        self.nsf.show()

        vbox2.show()

        buttons = gtk.HBox(homogeneous=False,
                           spacing=6)
        self.save_btn = gtk.Button(_("Save"))
        self.save_and_connect_btn = gtk.Button(_("Save & Connect"))
        self.cancel_btn = gtk.Button(_("Cancel"))
        buttons.pack_end(self.save_and_connect_btn,
                         expand=False, fill=False)
        buttons.pack_end(self.save_btn, expand=False, fill=False)
        buttons.pack_end(self.cancel_btn, expand=False, fill=False)
        buttons.show_all()
        vbox.pack_end(buttons, expand=False, fill=False)
        vbox.show()
    def _listen_signals(self):
        self.save_and_connect_btn.connect("clicked", self.save, True)
        self.save_btn.connect("clicked", self.save, False)
        self.cancel_btn.connect("clicked", self.cancel)
    def cancel(self, widget):
        self.destroy()
    def save(self, widget, to_connect):
        data = self.collect_data()
        try:
            self.iface.updateConnection(self.package,
                                        data["name"],
                                        data)
        except Exception, e:
            print "Exception:", unicode(e)
        if to_connect:
            self.iface.connect(self.package, data["name"])
        self.destroy()