9 class AccountEditor(rox
.Dialog
):
12 def __init__(self
, account
):
13 rox
.Dialog
.__init
__(self
)
14 self
.set_title(_('Account Editor'))
15 self
.set_size_request(300, -1)
16 self
.account
= account
17 self
.table
= gtk
.Table(2, 4)
18 self
.vbox
.add(self
.table
)
19 self
.add_str(_('Name: '), 'name', account
.name
)
20 self
.add_num(_('Poll Time (minutes): '), 'polltime',
21 account
.polltime
, min = 0.1, max = 1440.0,
22 step
= 0.1, page
= 1, digits
= 1)
23 self
.add_button(gtk
.STOCK_OK
, gtk
.RESPONSE_OK
)
24 self
.set_default_response(gtk
.RESPONSE_OK
)
26 def add_row(self
, label
, widget
):
28 self
.table
.attach(gtk
.Label(label
), 0, 1, n
, n
+1, 0, 0)
29 self
.table
.attach(widget
, 1, 2, n
, n
+1, gtk
.EXPAND|gtk
.FILL
, 0)
32 def add_num(self
, label
, name
, value
, min=1, max=65535, step
=1, page
=10, digits
=0):
33 entry
= gtk
.SpinButton()
34 entry
.set_range(min, max)
35 entry
.set_increments(step
, page
)
36 entry
.set_digits(digits
)
37 entry
.set_value(value
)
38 entry
.connect('value-changed', self
.set_num
, name
)
39 self
.add_row(label
, entry
)
41 def set_num(self
, widget
, name
):
42 if widget
.get_digits() == 0:
43 self
.account
.__dict
__[name
] = widget
.get_value_as_int()
45 self
.account
.__dict
__[name
] = widget
.get_value()
47 def add_str(self
, label
, name
, value
, visible
=True):
50 entry
.set_visibility(visible
)
51 entry
.connect('changed', self
.set_str
, name
)
52 self
.add_row(label
, entry
)
54 def set_str(self
, widget
, name
):
55 self
.account
.__dict
__[name
] = widget
.get_text()
57 def add_list(self
, label
, name
, value
):
58 string
= ','.join(value
)
60 entry
.set_text(string
)
61 entry
.connect('changed', self
.set_list
, name
)
62 self
.add_row(label
, entry
)
64 def set_list(self
, widget
, name
):
65 string
= widget
.get_text()
66 self
.account
.__dict
__[name
] = string
.split(',')
68 def add_bool(self
, label
, name
, value
, text
=None):
69 item
= gtk
.CheckButton(label
=text
)
70 item
.set_active(value
)
71 item
.connect('toggled', self
.set_bool
, name
)
72 self
.add_row(label
, item
)
74 def set_bool(self
, widget
, name
):
75 self
.account
.__dict
__[name
] = widget
.get_active()
77 class MBOXEditor(AccountEditor
):
78 def __init__(self
, account
):
79 AccountEditor
.__init
__(self
, account
)
80 self
.set_title(_('MBOX Account Editor'))
81 self
.add_str(_('Path: '), 'filename', account
.filename
)
84 class IMAPEditor(AccountEditor
):
85 def __init__(self
, account
):
86 AccountEditor
.__init
__(self
, account
)
87 self
.set_title(_('IMAP Account Editor'))
88 self
.add_str(_('Server: '), 'server', account
.server
)
89 self
.add_num(_('Port: '), 'port', account
.port
, 1, 65535, 1, 100)
90 self
.add_str(_('Username: '), 'username', account
.username
)
91 self
.add_str(_('Password: '), 'password', account
.password
, False)
92 self
.add_list(_('Folders: '), 'folders', account
.folders
)
93 self
.add_bool(_('SSL: '), 'ssl', account
.ssl
)
96 class POPEditor(AccountEditor
):
97 def __init__(self
, account
):
98 AccountEditor
.__init
__(self
, account
)
99 self
.set_title(_('POP Account Editor'))
100 self
.add_str(_('Server: '), 'server', account
.server
)
101 self
.add_num(_('Port: '), 'port', account
.port
, 1, 65535, 1, 100)
102 self
.add_str(_('Username: '), 'username', account
.username
)
103 self
.add_str(_('Password: '), 'password', account
.password
, False)
104 self
.add_bool(_('SSL: '), 'ssl', account
.ssl
)
105 self
.add_bool(_('APOP: '), 'apop', account
.apop
)
109 class AccountList(rox
.Dialog
):
110 def __init__(self
, accounts
):
111 rox
.Dialog
.__init
__(self
)
112 self
.set_title(_('Postal: Account Editor'))
115 self
.vbox
.pack_start(hbox
)
116 swin
= gtk
.ScrolledWindow()
117 swin
.set_size_request(-1, 200)
118 hbox
.pack_start(swin
)
120 self
.accts
= gtk
.ListStore(str, str, object)
122 for acct
in accounts
:
123 row
= self
.accts
.append()
124 self
.accts
.set(row
, 0, acct
.name
, 1, acct
.protocol
, 2, acct
)
126 view
= gtk
.TreeView(self
.accts
)
127 view
.append_column(gtk
.TreeViewColumn(_('Name'), gtk
.CellRendererText(), text
=0))
128 view
.append_column(gtk
.TreeViewColumn(_('Type'), gtk
.CellRendererText(), text
=1))
129 view
.connect('row-activated', self
.select_row
)
133 self
.accounts
= accounts
135 def response(self
, resp
):
144 self
.emit_stop_by_name('response')
147 self
.connect('response', response
)
148 self
.add_button(gtk
.STOCK_ADD
, ADD
)
149 self
.add_button(gtk
.STOCK_DELETE
, DELETE
)
150 self
.add_button(gtk
.STOCK_EDIT
, EDIT
)
151 self
.add_button(gtk
.STOCK_CLOSE
, gtk
.RESPONSE_CANCEL
)
152 self
.set_default_response(gtk
.RESPONSE_CANCEL
)
155 self
.action_area
.show_all()
157 def select_row(self
, list, path
, *stuff
):
158 model
= list.get_model()
159 row
= model
.get_iter(path
)
160 account
= model
.get_value(row
, 2)
161 self
.edit_account(account
)
165 items
.append(Menu
.Action(_('IMAP'), 'add_account', None, None, ('IMAP',)))
166 items
.append(Menu
.Action(_('POP'), 'add_account', None, None, ('POP',)))
167 items
.append(Menu
.Action(_('MBOX'), 'add_account', None, None, ('MBOX',)))
168 menu
= Menu
.Menu('choose', items
)
169 menu
.attach(self
, self
)
170 menu
.popup(self
, None)
172 def add_account(self
, account_type
):
173 if account_type
== 'IMAP':
175 account
= imap_check
.IMAPChecker()
176 elif account_type
== 'POP':
178 account
= pop_check
.POPChecker()
179 elif account_type
== 'MBOX':
181 account
= mbox_check
.MBOXChecker()
184 self
.edit_account(account
)
185 self
.accts
.append([account
.name
, account
.protocol
, account
])
186 self
.accounts
.append(account
)
189 model
, row
= self
.view
.get_selection().get_selected()
190 path
= model
.get_path(row
)
192 del self
.accounts
[path
[0]]
195 model
, row
= self
.view
.get_selection().get_selected()
196 account
= model
.get_value(row
, 2)
197 self
.edit_account(account
)
198 model
.set(row
, 0, account
.name
, 1, account
.protocol
, 2, account
)
200 def edit_account(self
, account
):
201 if account
.protocol
== 'IMAP':
202 dlg
= IMAPEditor(account
)
203 elif account
.protocol
== 'MBOX':
204 dlg
= MBOXEditor(account
)
205 elif account
.protocol
== 'POP':
206 dlg
= POPEditor(account
)
209 dlg
.set_transient_for(self
)