6
from lib.common import *
7
from lib.gconfhelper import GconfHelper
8
from lib.accountmanager import *
10
GLADE_FILE = os.path.join(GLADE_BASE_PATH, "preferences_dialog.glade")
13
class PreferencesDialog:
15
self.ignore_signals = True
16
self.account_manager = AccountManager()
18
self.widgets = gtk.glade.XML(GLADE_FILE, domain = "cgmail")
21
"on_display_notif_cb_toggled": self.on_display_notif_toggled,
22
"on_play_snd_cb_toggled" : self.on_play_snd_toggled,
23
"on_autostart_cb_toggled" : self.on_autostart_cb_toggled,
24
"on_gnome_keyring_rb_toggled" : self.on_use_gnome_keyring,
25
"on_always_status_icon_cb_toggled" : self.on_always_status_icon,
26
"on_command_check_toggled" : self.on_command_check,
27
"on_errors_notify_cb_toggled" : self.on_notify_errors,
28
"on_plain_file_rb_toggled" : self.on_use_plain_file,
29
"on_check_interval_sp_value_changed" : self.on_check_interval_changed
32
self.command_entry = self.widgets.get_widget("command_entry")
34
self.widgets.signal_autoconnect(dict)
35
self.dialog = self.widgets.get_widget("dialog")
36
self.gconf_helper = GconfHelper()
38
display_notif_cb = self.widgets.get_widget("display_notif_cb")
39
value = self.gconf_helper.get_key("display_notifications")
40
display_notif_cb.set_active(value)
42
play_snd_cb = self.widgets.get_widget("play_snd_cb")
43
value = self.gconf_helper.get_key("play_sounds_on_new_mails")
44
play_snd_cb.set_active(value)
46
errors_notify_cb = self.widgets.get_widget("errors_notify_cb")
47
value = self.gconf_helper.get_key("notify_errors")
48
errors_notify_cb.set_active(value)
50
command_check = self.widgets.get_widget("command_check")
51
value = self.gconf_helper.get_key("exec_command")
52
command_check.set_active(value)
53
self.command_entry.set_sensitive(value)
55
value = self.gconf_helper.get_key("new_mail_command")
56
self.command_entry.set_text(value)
58
self.gnome_keyring_rb = self.widgets.get_widget("gnome_keyring_rb")
59
self.plain_file_rb = self.widgets.get_widget("plain_file_rb")
60
value = self.gconf_helper.get_key("use_gnome_keyring")
62
self.gnome_keyring_rb.set_active(True)
64
self.plain_file_rb.set_active(True)
66
check_interval_sp = self.widgets.get_widget("check_interval_sp")
67
value = self.gconf_helper.get_key("check_interval")
68
check_interval_sp.set_value(value)
70
self.autostart_file = os.path.expanduser("~/.config/autostart/cgmailservice.desktop")
71
autostart_cb = self.widgets.get_widget("autostart_cb")
72
value = os.path.exists(self.autostart_file)
73
autostart_cb.set_active(value)
75
self.ignore_signals = False
81
result = self.dialog.run()
82
cmd = self.command_entry.get_text()
83
self.gconf_helper.set_key("new_mail_command", cmd)
86
def on_autostart_cb_toggled(self, w):
87
if self.ignore_signals: return
90
if not os.path.exists(self.autostart_file):
92
shutil.copyfile(CGMAIL_AUTOSTART_FILE,
94
os.chmod(self.autostart_file, 0700)
96
print "Warning: cannot write to path", self.autostart_file
98
if os.path.exists(self.autostart_file):
100
os.unlink(self.autostart_file)
102
print "Warning: cannot delete", self.autostart_file
104
def on_command_check(self, w):
105
if self.ignore_signals: return
106
self.command_entry.set_sensitive(w.get_active())
108
self.gconf_helper.set_key("exec_command", True)
109
cmd = self.command_entry.get_text()
110
self.gconf_helper.set_key("new_mail_command", cmd)
112
self.gconf_helper.set_key("exec_command", False)
113
self.gconf_helper.set_key("new_mail_command", "")
115
def on_display_notif_toggled(self, w):
116
if self.ignore_signals: return
119
self.gconf_helper.set_key("display_notifications", True)
121
self.gconf_helper.set_key("display_notifications", False)
123
def on_play_snd_toggled(self, w):
124
if self.ignore_signals: return
127
self.gconf_helper.set_key("play_sounds_on_new_mails", True)
129
self.gconf_helper.set_key("play_sounds_on_new_mails", False)
131
def on_notify_errors(self, w):
132
if self.ignore_signals: return
135
self.gconf_helper.set_key("notify_errors", True)
137
self.gconf_helper.set_key("notify_errors", False)
140
def on_use_gnome_keyring(self, w):
141
if self.ignore_signals: return
145
self.account_manager.set_keyring_default()
146
self.gconf_helper.set_key("use_gnome_keyring", True)
147
except CannotSetDefault:
148
# We can pass here becouse if set_keyring_default
149
# will raise the exception, the set_key method will
151
self.ignore_signals = True
152
self.plain_file_rb.set_active(True)
153
self.ignore_signals = False
155
def on_use_plain_file(self, w):
156
if self.ignore_signals: return
160
self.account_manager.set_xml_default()
161
self.gconf_helper.set_key("use_gnome_keyring", False)
162
except CannotSetDefault:
163
# same as on_use_gnome_keyring
164
self.ignore_signals = True
165
self.gnome_keyring_rb.set_active(True)
166
self.ignore_signals = False
168
def on_always_status_icon(self, w):
169
if self.ignore_signals: return
171
def on_check_interval_changed(self, w):
172
if self.ignore_signals: return
174
value = w.get_value_as_int()
175
self.gconf_helper.set_key("check_interval", value)