new sound management

This commit is contained in:
Yann Leboulanger 2005-02-14 22:30:04 +00:00
parent f29229c12e
commit 0e2552fd96
2 changed files with 63 additions and 33 deletions

View File

@ -243,12 +243,15 @@ class preference_Window:
#sounds
model = self.sound_tree.get_model()
iter = model.get_iter_first()
events = []
while iter:
events.append(model.get_value(iter, 0))
events.append(model.get_value(iter, 1))
path = model.get_path(iter)
if model[path][1]:
self.plugin.config['sound_' + model.get_value(iter, 0)] = 1
else:
self.plugin.config['sound_' + model.get_value(iter, 0)] = 0
self.plugin.config['sound_' + model.get_value(iter, 0) + '_file'] = \
model.get_value(iter, 2)
iter = model.iter_next(iter)
self.plugin.config['sounds'] = string.join(events, '\t')
#autopopup
if self.chk_autopp.get_active():
self.plugin.config['autopopup'] = 1
@ -497,32 +500,39 @@ class preference_Window:
return 0
return 1
def sound_toggled_cb(self, cell, path):
model = self.sound_tree.get_model()
model[path][1] = not model[path][1]
return
def fill_sound_treeview(self):
eventList = ['message']
events = {}
split_line = string.split(self.plugin.config['sounds'], '\t')
for i in range(0, len(split_line)/2):
events[split_line[2*i]] = split_line[2*i+1]
#events = {name : [use_it, file], name2 : [., .], ...}
for key in self.plugin.config.keys():
if key.find('sound_') == 0:
if not self.plugin.config.has_key(key + '_file'):
continue
ev = key.replace('sound_', '')
events[ev] = [self.plugin.config[key], self.plugin.config[key + \
'_file']]
model = self.sound_tree.get_model()
model.clear()
for ev in eventList:
if ev in events:
iter = model.append()
model.set(iter, 0, ev, 1, events[ev])
for ev in events:
iter = model.append((ev, events[ev][0], events[ev][1]))
def on_treeview_sounds_cursor_changed(self, widget, data=None):
(model, iter) = self.sound_tree.get_selection().get_selected()
if not iter:
self.xml.get_widget('entry_sounds').set_text('')
return
str = model.get_value(iter, 1)
str = model.get_value(iter, 2)
self.xml.get_widget('entry_sounds').set_text(str)
def on_button_sounds_clicked(self, widget, data=None):
(model, iter) = self.sound_tree.get_selection().get_selected()
if not iter:
return
file = model.get_value(iter, 1)
file = model.get_value(iter, 2)
dialog = gtk.FileChooserDialog("Choose sound",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
@ -542,7 +552,7 @@ class preference_Window:
file = os.path.join(os.getcwd(), file)
dialog.set_filename(file)
file = ''
file = ''
ok = 0
while(ok == 0):
response = dialog.run()
@ -555,7 +565,8 @@ class preference_Window:
dialog.destroy()
if file:
self.xml.get_widget('entry_sounds').set_text(file)
model.set_value(iter, 1, file)
model.set_value(iter, 2, file)
model.set_value(iter, 1, 1)
def __init__(self, plugin):
"""Initialize Preference window"""
@ -647,18 +658,29 @@ class preference_Window:
#sounds
self.sound_tree = self.xml.get_widget('treeview_sounds')
model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_BOOLEAN, \
gobject.TYPE_STRING)
self.sound_tree.set_model(model)
col = gtk.TreeViewColumn('Active')
self.sound_tree.append_column(col)
renderer = gtk.CellRendererToggle()
renderer.set_property('activatable', True)
renderer.connect("toggled", self.sound_toggled_cb)
col.pack_start(renderer)
col.set_attributes(renderer, active=1)
col = gtk.TreeViewColumn('Event')
self.sound_tree.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text=0)
col = gtk.TreeViewColumn('Sound')
self.sound_tree.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text=1)
col.set_attributes(renderer, text=2)
self.fill_sound_treeview()
#Autopopup

View File

@ -2181,16 +2181,6 @@ class roster_Window:
return 0
return 1
def mkevents(self):
"""initialize events array"""
self.events = {}
split_line = string.split(self.plugin.config['sounds'], '\t')
for i in range(0, len(split_line)/2):
file = split_line[2*i+1]
if not self.sound_is_ok(file):
continue
self.events[split_line[2*i]] = file
def on_show_off(self, widget):
"""when show offline option is changed :
redraw the treeview"""
@ -2355,7 +2345,6 @@ class roster_Window:
self.mkpixbufs()
if self.plugin.config['useemoticons']:
self.mkemoticons()
self.mkevents()
liststore = gtk.ListStore(gobject.TYPE_STRING, gtk.Image)
self.cb = gtk.ComboBox()
@ -2636,12 +2625,15 @@ class plugin:
def play_sound(self, event):
if not self.roster.events.has_key(event):
if not self.config[event]:
return
file = self.config[event + '_file']
if not os.path.exists(file):
return
pid = os.fork()
if pid == 0:
argv = self.config['soundplayer'].split()
argv.append(self.roster.events[event])
argv.append(file)
try:
os.execvp(argv[0], argv)
except:
@ -2742,8 +2734,15 @@ class plugin:
jid = string.split(array[0], '/')[0]
if string.find(jid, "@") <= 0:
jid = string.replace(jid, '@', '')
self.play_sound('message')
first = 0
if not self.windows[account]['chats'].has_key(jid) and \
not self.queues[account].has_key(jid):
first = 1
self.roster.on_message(jid, array[1], array[2], account)
if self.config['sound_first_message_received'] and first:
self.play_sound('sound_first_message_received')
if self.config['sound_next_message_received'] and not first:
self.play_sound('sound_next_message_received')
def handle_event_msgerror(self, account, array):
#('MSGERROR', account, (user, error_code, error_msg, msg, time))
@ -3040,7 +3039,16 @@ class plugin:
'useemoticons': 1,\
'emoticons':':-)\tplugins/gtkgui/emoticons/smile.png\t(@)\tplugins/gtkgui/emoticons/pussy.png\t8)\tplugins/gtkgui/emoticons/coolglasses.png\t:(\tplugins/gtkgui/emoticons/unhappy.png\t:)\tplugins/gtkgui/emoticons/smile.png\t(})\tplugins/gtkgui/emoticons/hugleft.png\t:$\tplugins/gtkgui/emoticons/blush.png\t(Y)\tplugins/gtkgui/emoticons/yes.png\t:-@\tplugins/gtkgui/emoticons/angry.png\t:-D\tplugins/gtkgui/emoticons/biggrin.png\t(U)\tplugins/gtkgui/emoticons/brheart.png\t(F)\tplugins/gtkgui/emoticons/flower.png\t:-[\tplugins/gtkgui/emoticons/bat.png\t:>\tplugins/gtkgui/emoticons/biggrin.png\t(T)\tplugins/gtkgui/emoticons/phone.png\t(l)\tplugins/gtkgui/emoticons/heart.png\t:-S\tplugins/gtkgui/emoticons/frowing.png\t:-P\tplugins/gtkgui/emoticons/tongue.png\t(h)\tplugins/gtkgui/emoticons/coolglasses.png\t(D)\tplugins/gtkgui/emoticons/drink.png\t:-O\tplugins/gtkgui/emoticons/oh.png\t(f)\tplugins/gtkgui/emoticons/flower.png\t(C)\tplugins/gtkgui/emoticons/coffee.png\t:-o\tplugins/gtkgui/emoticons/oh.png\t({)\tplugins/gtkgui/emoticons/hugright.png\t(*)\tplugins/gtkgui/emoticons/star.png\tB-)\tplugins/gtkgui/emoticons/coolglasses.png\t(z)\tplugins/gtkgui/emoticons/boy.png\t:-d\tplugins/gtkgui/emoticons/biggrin.png\t(E)\tplugins/gtkgui/emoticons/mail.png\t(N)\tplugins/gtkgui/emoticons/no.png\t(p)\tplugins/gtkgui/emoticons/photo.png\t(K)\tplugins/gtkgui/emoticons/kiss.png\t(r)\tplugins/gtkgui/emoticons/rainbow.png\t:-|\tplugins/gtkgui/emoticons/stare.png\t:-s\tplugins/gtkgui/emoticons/frowing.png\t:-p\tplugins/gtkgui/emoticons/tongue.png\t(c)\tplugins/gtkgui/emoticons/coffee.png\t(e)\tplugins/gtkgui/emoticons/mail.png\t;-)\tplugins/gtkgui/emoticons/wink.png\t;-(\tplugins/gtkgui/emoticons/cry.png\t(6)\tplugins/gtkgui/emoticons/devil.png\t:o\tplugins/gtkgui/emoticons/oh.png\t(L)\tplugins/gtkgui/emoticons/heart.png\t(w)\tplugins/gtkgui/emoticons/brflower.png\t:d\tplugins/gtkgui/emoticons/biggrin.png\t(Z)\tplugins/gtkgui/emoticons/boy.png\t(u)\tplugins/gtkgui/emoticons/brheart.png\t:|\tplugins/gtkgui/emoticons/stare.png\t(P)\tplugins/gtkgui/emoticons/photo.png\t:O\tplugins/gtkgui/emoticons/oh.png\t(R)\tplugins/gtkgui/emoticons/rainbow.png\t(t)\tplugins/gtkgui/emoticons/phone.png\t(i)\tplugins/gtkgui/emoticons/lamp.png\t;)\tplugins/gtkgui/emoticons/wink.png\t;(\tplugins/gtkgui/emoticons/cry.png\t:p\tplugins/gtkgui/emoticons/tongue.png\t(H)\tplugins/gtkgui/emoticons/coolglasses.png\t:s\tplugins/gtkgui/emoticons/frowing.png\t;\'-(\tplugins/gtkgui/emoticons/cry.png\t:-(\tplugins/gtkgui/emoticons/unhappy.png\t:-)\tplugins/gtkgui/emoticons/smile.png\t(b)\tplugins/gtkgui/emoticons/beer.png\t8-)\tplugins/gtkgui/emoticons/coolglasses.png\t(B)\tplugins/gtkgui/emoticons/beer.png\t(W)\tplugins/gtkgui/emoticons/brflower.png\t:D\tplugins/gtkgui/emoticons/biggrin.png\t(y)\tplugins/gtkgui/emoticons/yes.png\t(8)\tplugins/gtkgui/emoticons/music.png\t:@\tplugins/gtkgui/emoticons/angry.png\tB)\tplugins/gtkgui/emoticons/coolglasses.png\t:-$\tplugins/gtkgui/emoticons/blush.png\t:\'(\tplugins/gtkgui/emoticons/cry.png\t(n)\tplugins/gtkgui/emoticons/no.png\t(k)\tplugins/gtkgui/emoticons/kiss.png\t:->\tplugins/gtkgui/emoticons/biggrin.png\t:[\tplugins/gtkgui/emoticons/bat.png\t(I)\tplugins/gtkgui/emoticons/lamp.png\t:P\tplugins/gtkgui/emoticons/tongue.png\t(%)\tplugins/gtkgui/emoticons/cuffs.png\t(d)\tplugins/gtkgui/emoticons/drink.png\t:S\tplugins/gtkgui/emoticons/frowing.png',\
'soundplayer': 'play',\
'sounds': 'message\tsounds/message.wav',\
'sound_first_message_received': 1,\
'sound_first_message_received_file': 'sounds/message1.wav',\
'sound_next_message_received': 0,\
'sound_next_message_received_file': 'sounds/message2.wav',\
'sound_contact_connected': 1,\
'sound_contact_connected_file': 'sounds/connected.wav',\
'sound_contact_disconnected': 1,\
'sound_contact_disconnected_file': 'sounds/disconnected.wav',\
'sound_message_sent': 1,\
'sound_message_sent_file': 'sounds/sent.wav',\
'x-position': 0,\
'y-position': 0,\
'width': 150,\