File: Server_Win.py

package info (click to toggle)
xpn 1.2.6-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,500 kB
  • ctags: 1,685
  • sloc: python: 12,693; xml: 206; makefile: 16; sh: 1
file content (149 lines) | stat: -rw-r--r-- 6,674 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import gtk
import ConfigParser
import os
from xpn_src.UserDir import get_wdir
from xpn_src.Dialogs import Dialog_OK

class NNTPServer_Win:
    def show(self):
        self.win.show_all()
    
    def delete_event(self,widget,event,data=None):
        return False

    def destroy(self,obj):
        self.win.destroy()

    def change_auth_status(self,obj):
        status=self.server_auth_checkbutton.get_active()
        self.server_username.set_sensitive(status)
        self.server_password.set_sensitive(status)
        self.username_label.set_sensitive(status)
        self.password_label.set_sensitive(status)

    def change_ssl_status(self,checkbutton):
        status=checkbutton.get_active()
        if status:
            self.port_entry.set_text("563")
        else:
            self.port_entry.set_text("119")

    def save_configs(self,button):
        cp=ConfigParser.ConfigParser()
        cp.read(os.path.join(get_wdir(),"dats","servers.txt"))
        server_name=self.server_entry.get_text()
        if server_name!="":
            try: cp.add_section(server_name)
            except: pass
            cp.set(server_name,"server",server_name)
            cp.set(server_name,"port",self.port_entry.get_text())
            cp.set(server_name,"nntp_use_ssl",str(self.server_use_ssl_checkbutton.get_active()))
            if self.server_auth_checkbutton.get_active():
                cp.set(server_name,"auth","True")
                cp.set(server_name,"username",self.server_username.get_text())
                cp.set(server_name,"password",self.server_password.get_text())
            else:
                cp.set(server_name,"auth","False")
                cp.set(server_name,"username","")
                cp.set(server_name,"password","")
            cp.write(file(os.path.join(get_wdir(),"dats","servers.txt"),"w"))
            self.win.destroy()
            self.config_win.refresh_server_list()
        else:
            d=Dialog_OK(_("Please set the Server Name"))

    def load_configs(self,server_to_load):
        cp=ConfigParser.ConfigParser()
        cp.read(os.path.join(get_wdir(),"dats","servers.txt"))
        self.server_entry.set_text(cp.get(server_to_load,"server"))
        self.port_entry.set_text(cp.get(server_to_load,"port"))
        if cp.get(server_to_load,"nntp_use_ssl")=="True":
            self.server_use_ssl_checkbutton.set_active(True)
        else:
            self.server_use_ssl_checkbutton.set_active(False)
        if cp.get(server_to_load,"auth")=="True":
            self.server_auth_checkbutton.set_active(True)
        else:
            self.server_auth_checkbutton.set_active(False)
            self.server_username.set_sensitive(False)
            self.server_password.set_sensitive(False)
            self.username_label.set_sensitive(False)
            self.password_label.set_sensitive(False)
        self.server_username.set_text(cp.get(server_to_load,"username"))
        self.server_password.set_text(cp.get(server_to_load,"password"))



    def __init__(self,config_win,server_to_load=None):
        self.config_win=config_win
        self.win=gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.win.connect("delete_event",self.delete_event)
        self.win.set_title(_("Server Settings"))
        self.win.set_icon(gtk.gdk.pixbuf_new_from_file("pixmaps/conf.xpm"))
        self.win.set_position(gtk.WIN_POS_CENTER)

        server_label=gtk.Label()
        server_label.set_markup("<b>"+_("NNTP Server")+"</b>")
        server_label.set_alignment(0,0.5)
        server_vbox=gtk.VBox()
        server_vbox.set_border_width(4)
        server_vbox.pack_start(server_label,False,True,4)
        server_table=gtk.Table(4,2,False)
        server_table.set_border_width(8)

        self.server_entry=gtk.Entry()
        self.port_entry=gtk.Entry()
        self.port_entry.set_text("119")
        self.server_username=gtk.Entry()
        self.server_password=gtk.Entry()
        self.server_password.set_visibility(False)
        self.server_auth_checkbutton=gtk.CheckButton(_("Server requires authentication"))
        self.server_auth_checkbutton.connect("clicked",self.change_auth_status)
        self.server_use_ssl_checkbutton=gtk.CheckButton(_("Use SSL (Secure Socket Layer)"))
        self.server_use_ssl_checkbutton.connect("clicked",self.change_ssl_status)
        try: from socket import ssl
        except: self.server_use_ssl_checkbutton.set_sensitive(False)

        address_label=gtk.Label(_("NNTP Server Address"))
        port_label=gtk.Label(_("Port Number"))
        address_label.set_alignment(0,0.5)
        port_label.set_alignment(0,0.5)        
        self.username_label=gtk.Label(_("Username"))
        self.username_label.set_alignment(0,0.5)
        self.password_label=gtk.Label(_("Password"))
        self.password_label.set_alignment(0,0.5)
        
        server_table.attach(address_label,0,1,0,1,gtk.EXPAND|gtk.FILL,gtk.FILL,18)
        server_table.attach(port_label,0,1,1,2,gtk.EXPAND|gtk.FILL,gtk.FILL,18)
        server_table.attach(self.username_label,0,1,4,5,gtk.EXPAND|gtk.FILL,gtk.FILL,18)
        server_table.attach(self.password_label,0,1,5,6,gtk.EXPAND|gtk.FILL,gtk.FILL,18)

        server_table.attach(self.server_entry,1,2,0,1,gtk.EXPAND|gtk.FILL,gtk.FILL)
        server_table.attach(self.port_entry,1,2,1,2,gtk.EXPAND|gtk.FILL,gtk.FILL)
        server_table.attach(self.server_use_ssl_checkbutton,1,2,2,3,gtk.EXPAND|gtk.FILL,gtk.FILL)
        server_table.attach(self.server_auth_checkbutton,1,2,3,4,gtk.EXPAND|gtk.FILL,gtk.FILL)
        server_table.attach(self.server_username,1,2,4,5,gtk.EXPAND|gtk.FILL,gtk.FILL)
        server_table.attach(self.server_password,1,2,5,6,gtk.EXPAND|gtk.FILL,gtk.FILL)

        self.change_auth_status(None)
        
        #buttons hbox
        buttons_hbox=gtk.HBox()

        #cancel_button
        self.cancel_button=gtk.Button(None,gtk.STOCK_CANCEL)
        self.cancel_button.set_tooltip_text(_("Close window. Discard changes"))
        self.cancel_button.connect("clicked",self.destroy)
        buttons_hbox.pack_start(self.cancel_button,True,True,0)
        #ok_button
        self.ok_button=gtk.Button(None,gtk.STOCK_OK)
        self.ok_button.connect("clicked",self.save_configs)
        self.ok_button.set_tooltip_text(_("Close window and save settings"))
        buttons_hbox.pack_start(self.ok_button,True,True,0)
        self.ok_button.set_border_width(5)
        self.cancel_button.set_border_width(5)

        server_vbox.pack_start(server_table,False,False)
        server_vbox.pack_start(buttons_hbox,False,False,0)
        self.win.add(server_vbox)
        if server_to_load: self.load_configs(server_to_load)