[jim++] sound events show in UI as translatable nice words. [me] refactor the whole thing

This commit is contained in:
Nikos Kouremenos 2006-02-16 15:21:34 +00:00
parent 11fedebb08
commit 967d278541
3 changed files with 50 additions and 33 deletions

View File

@ -408,7 +408,7 @@ def play_sound(event):
if path_to_soundfile == 'beep': if path_to_soundfile == 'beep':
print '\a' # make a speaker beep print '\a' # make a speaker beep
return return
if not os.path.exists(path_to_soundfile): if path_to_soundfile is None or not os.path.exists(path_to_soundfile):
return return
if os.name == 'nt': if os.name == 'nt':
try: try:

View File

@ -299,7 +299,9 @@ class PreferencesWindow:
#sounds treeview #sounds treeview
self.sound_tree = self.xml.get_widget('sounds_treeview') self.sound_tree = self.xml.get_widget('sounds_treeview')
model = gtk.ListStore(str, bool, str)
# active, event ui name, path to sound file, event_config_name
model = gtk.ListStore(bool, str, str, str)
self.sound_tree.set_model(model) self.sound_tree.set_model(model)
col = gtk.TreeViewColumn(_('Active')) col = gtk.TreeViewColumn(_('Active'))
@ -308,13 +310,13 @@ class PreferencesWindow:
renderer.set_property('activatable', True) renderer.set_property('activatable', True)
renderer.connect('toggled', self.sound_toggled_cb) renderer.connect('toggled', self.sound_toggled_cb)
col.pack_start(renderer) col.pack_start(renderer)
col.set_attributes(renderer, active = 1) col.set_attributes(renderer, active = 0)
col = gtk.TreeViewColumn(_('Event')) col = gtk.TreeViewColumn(_('Event'))
self.sound_tree.append_column(col) self.sound_tree.append_column(col)
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
col.pack_start(renderer) col.pack_start(renderer)
col.set_attributes(renderer, text = 0) col.set_attributes(renderer, text = 1)
col = gtk.TreeViewColumn(_('Sound')) col = gtk.TreeViewColumn(_('Sound'))
self.sound_tree.append_column(col) self.sound_tree.append_column(col)
@ -731,9 +733,9 @@ class PreferencesWindow:
self.on_checkbutton_toggled(widget, 'ask_offline_status') self.on_checkbutton_toggled(widget, 'ask_offline_status')
def on_sounds_treemodel_row_changed(self, model, path, iter): def on_sounds_treemodel_row_changed(self, model, path, iter):
sound_event = model.get_value(iter, 0).decode('utf-8') sound_event = model[iter][3].decode('utf-8')
gajim.config.set_per('soundevents', sound_event, 'enabled', gajim.config.set_per('soundevents', sound_event, 'enabled',
bool(model[path][1])) bool(model[path][0]))
gajim.config.set_per('soundevents', sound_event, 'path', gajim.config.set_per('soundevents', sound_event, 'path',
model[iter][2].decode('utf-8')) model[iter][2].decode('utf-8'))
gajim.interface.save_config() gajim.interface.save_config()
@ -883,13 +885,27 @@ class PreferencesWindow:
model[path][1] = not model[path][1] model[path][1] = not model[path][1]
def fill_sound_treeview(self): def fill_sound_treeview(self):
sounds = gajim.config.get_per('soundevents')
model = self.sound_tree.get_model() model = self.sound_tree.get_model()
model.clear() model.clear()
for sound in sounds:
val = gajim.config.get_per('soundevents', sound, 'enabled') # NOTE: sounds_ui_names MUST have all items of
path = gajim.config.get_per('soundevents', sound, 'path') # sounds = gajim.config.get_per('soundevents') as keys
model.append((sound, val, path)) sounds_dict = {
'first_message_received': _('First Message Received'),
'next_message_received': _('Next Message Received'),
'contact_connected': _('Contact Connected'),
'contact_disconnected': _('Contact Disconnected'),
'message_sent': _('Message Sent'),
'muc_message_highlight': _('Group Chat Message Highlight'),
'muc_message_received': _('Group Chat Message Received')
}
for sound_event_config_name, sound_ui_name in sounds_dict.items():
enabled = gajim.config.get_per('soundevents',
sound_event_config_name, 'enabled')
path = gajim.config.get_per('soundevents',
sound_event_config_name, 'path')
model.append((enabled, sound_ui_name, path, sound_event_config_name))
def on_treeview_sounds_cursor_changed(self, widget, data = None): def on_treeview_sounds_cursor_changed(self, widget, data = None):
(model, iter) = self.sound_tree.get_selection().get_selected() (model, iter) = self.sound_tree.get_selection().get_selected()
@ -897,14 +913,14 @@ class PreferencesWindow:
if not iter: if not iter:
sounds_entry.set_text('') sounds_entry.set_text('')
return return
str = model[iter][2] path_to_snd_file = model[iter][2]
sounds_entry.set_text(str) sounds_entry.set_text(path_to_snd_file)
def on_button_sounds_clicked(self, widget, data = None): def on_browse_for_sounds_button_clicked(self, widget, data = None):
(model, iter) = self.sound_tree.get_selection().get_selected() (model, iter) = self.sound_tree.get_selection().get_selected()
if not iter: if not iter:
return return
file = model[iter][2].decode('utf-8') path_to_snd_file = model[iter][2].decode('utf-8')
dialog = gtk.FileChooserDialog(_('Choose Sound'), None, dialog = gtk.FileChooserDialog(_('Choose Sound'), None,
gtk.FILE_CHOOSER_ACTION_OPEN, gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
@ -927,40 +943,41 @@ class PreferencesWindow:
dialog.add_filter(filter) dialog.add_filter(filter)
dialog.set_filter(filter) dialog.set_filter(filter)
file = os.path.join(os.getcwd(), file) path_to_snd_file = os.path.join(os.getcwd(), path_to_snd_file)
dialog.set_filename(file) dialog.set_filename(path_to_snd_file)
file = '' path_to_snd_file = ''
while True: while True:
response = dialog.run() response = dialog.run()
if response != gtk.RESPONSE_OK: if response != gtk.RESPONSE_OK:
break break
file = dialog.get_filename() path_to_snd_file = dialog.get_filename()
try: try:
file = file.decode(sys.getfilesystemencoding()) path_to_snd_file = path_to_snd_file.decode(sys.getfilesystemencoding())
except: except:
pass pass
if os.path.exists(file): if os.path.exists(path_to_snd_file):
break break
dialog.destroy() dialog.destroy()
if file: if path_to_snd_file:
directory = os.path.dirname(file) directory = os.path.dirname(path_to_snd_file)
gajim.config.set('last_sounds_dir', directory) gajim.config.set('last_sounds_dir', directory)
self.xml.get_widget('sounds_entry').set_text(file) self.xml.get_widget('sounds_entry').set_text(path_to_snd_file)
model.set_value(iter, 2, file)
model.set_value(iter, 1, 1) model[iter][2] = path_to_snd_file # set new path to sounds_model
model[iter][0] = True # set the sound to enabled
def on_sounds_entry_changed(self, widget): def on_sounds_entry_changed(self, widget):
path_to_file = widget.get_text() path_to_snd_file = widget.get_text()
model, iter = self.sound_tree.get_selection().get_selected() model, iter = self.sound_tree.get_selection().get_selected()
model.set_value(iter, 2, path_to_file) model[iter][2] = path_to_snd_file # set new path to sounds_model
model.set_value(iter, 1, 1) model[iter][0] = True # set the sound to enabled
def on_play_button_clicked(self, widget): def on_play_button_clicked(self, widget):
model, iter = self.sound_tree.get_selection().get_selected() model, iter = self.sound_tree.get_selection().get_selected()
if not iter: if not iter:
return return
event = model[iter][0] snd_event_config_name = model[iter][3]
helpers.play_sound(event) helpers.play_sound(snd_event_config_name)
def on_open_advanced_editor_button_clicked(self, widget, data = None): def on_open_advanced_editor_button_clicked(self, widget, data = None):
if gajim.interface.instances.has_key('advanced_config'): if gajim.interface.instances.has_key('advanced_config'):

View File

@ -5178,14 +5178,14 @@ Disabled</property>
</child> </child>
<child> <child>
<widget class="GtkButton" id="sounds_button"> <widget class="GtkButton" id="browse_for_sounds_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="label">...</property> <property name="label">...</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property> <property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property> <property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_sounds_clicked" last_modification_time="Wed, 09 Feb 2005 23:29:56 GMT"/> <signal name="clicked" handler="on_browse_for_sounds_button_clicked" last_modification_time="Thu, 16 Feb 2006 14:51:54 GMT"/>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>