3 Module setting user preferences.
6 Copyright (c) 2002-2004 Juri Pakaste
7 Copyright (c) 2005-2007 Straw Contributors
9 __license__
= """ GNU General Public License
11 Straw is free software; you can redistribute it and/or modify it under the
12 terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA. """
24 from Constants
import *
25 from gtk
.glade
import XML
26 from os
.path
import join
33 class PreferencesView(MVP
.GladeView
):
34 def _initialize(self
):
35 self
._window
= self
._widget
.get_widget('preferences')
39 self
._controls
[OPTION_WEB_BROWSER_CMD
] = self
._widget
.get_widget("custom_command_web_browser_entry")
40 self
._controls
[OPTION_POLL_FREQUENCY
] = self
._widget
.get_widget("poll_frequency_spin")
41 self
._controls
[OPTION_ITEMS_STORED
] = self
._widget
.get_widget("number_of_items_spin")
42 self
._controls
[OPTION_PROXY_SERVER
] = self
._widget
.get_widget("proxy_server_entry")
43 self
._controls
[OPTION_PROXY_PORT
] = self
._widget
.get_widget("proxy_port_spin")
44 self
._controls
[OPTION_PROXY_AUTH_ACTIVE
] = self
._widget
.get_widget("proxy_auth_active_checkbox")
45 self
._controls
[OPTION_PROXY_AUTH_USERNAME
] = self
._widget
.get_widget("proxy_auth_username_entry")
46 self
._controls
[OPTION_PROXY_AUTH_PASSWORD
] = self
._widget
.get_widget("proxy_auth_password_entry")
48 for option
, control
in self
._controls
.iteritems():
49 name
= control
.get_name()
51 if name
.endswith("_entry"):
52 control
.set_text(Config
.get(option
))
53 elif name
.endswith("_spin"):
54 control
.set_value(float(Config
.get(option
)))
55 elif name
.endswith("_checkbox"):
56 control
.set_active(Config
.get(option
))
58 self
.proxy_type
= Config
.get(OPTION_PROXY_TYPE
)
59 radio
= self
._widget
.get_widget("%s_proxy_type_radio" % self
.proxy_type
)
62 radio
.set_active(True)
64 self
.web_browser_type
= Config
.get(OPTION_WEB_BROWSER_TYPE
)
65 radio
= self
._widget
.get_widget("%s_web_browser_type_radio" % self
.web_browser_type
)
68 radio
.set_active(True)
70 self
._update
_proxy
_inputs
(Config
.get(OPTION_PROXY_TYPE
))
71 self
._update
_web
_browser
_inputs
(Config
.get(OPTION_WEB_BROWSER_TYPE
))
74 for option
, control
in self
._controls
.iteritems():
75 name
= control
.get_name()
77 if name
.endswith("_entry"):
78 Config
.set(option
, control
.get_text())
79 elif name
.endswith("_spin"):
80 Config
.set(option
, control
.get_value())
81 elif name
.endswith("_checkbox"):
82 Config
.set(option
, control
.get_active())
84 Config
.set(OPTION_PROXY_TYPE
, self
.proxy_type
)
85 Config
.set(OPTION_WEB_BROWSER_TYPE
, self
.web_browser_type
)
87 def show(self
, *args
):
88 self
._window
.present()
90 def hide(self
, *args
):
92 self
._window
.destroy()
94 def _on_ok_button_clicked(self
, button
):
98 def _on_cancel_button_clicked(self
, button
):
101 def _on_apply_button_clicked(self
, button
):
104 def on_preferences_delete_event(self
, *args
):
108 def on_close_button_clicked(self
, button
):
111 def _update_proxy_inputs(self
, new_type
):
112 self
.proxy_type
= new_type
113 sensitive
= (self
.proxy_type
== "manual")
115 self
._controls
[OPTION_PROXY_SERVER
].set_sensitive(sensitive
)
116 self
._controls
[OPTION_PROXY_PORT
].set_sensitive(sensitive
)
117 self
._controls
[OPTION_PROXY_AUTH_ACTIVE
].set_sensitive(sensitive
)
118 self
._controls
[OPTION_PROXY_AUTH_USERNAME
].set_sensitive(sensitive
)
119 self
._controls
[OPTION_PROXY_AUTH_PASSWORD
].set_sensitive(sensitive
)
121 def _on_no_proxy_radio_toggled(self
, button
):
122 self
._update
_proxy
_inputs
("none")
124 def _on_gnome_proxy_radio_toggled(self
, button
):
125 self
._update
_proxy
_inputs
("gnome")
127 def _on_manual_proxy_radio_toggled(self
, button
):
128 self
._update
_proxy
_inputs
("manual")
130 def _update_web_browser_inputs(self
, new_type
):
131 self
.web_browser_type
= new_type
132 sensitive
= (self
.web_browser_type
== "custom")
134 self
._controls
[OPTION_WEB_BROWSER_CMD
].set_sensitive(sensitive
)
136 def _on_gnome_web_browser_radio_toggled(self
, button
):
137 self
._update
_web
_browser
_inputs
("gnome")
139 def _on_custom_command_web_browser_entry_toggled(self
, button
):
140 self
._update
_web
_browser
_inputs
("custom")
142 class PreferencesPresenter(MVP
.BasicPresenter
):
146 gladefile
= XML(os
.path
.join(straw
.defs
.STRAW_DATA_DIR
, "preferences.glade"))
147 dialog
= PreferencesPresenter(view
= PreferencesView(gladefile
))