[brubru] better sound file managment, Fixes #5016

This commit is contained in:
Yann Leboulanger 2009-05-10 19:32:57 +00:00
parent 23c6c708cd
commit fd01f7aa4d
7 changed files with 71 additions and 16 deletions

View File

@ -1,5 +1,5 @@
AC_INIT([Gajim - A Jabber Instant Messager],
[0.12.1.4-svn],[http://trac.gajim.org/],[gajim])
[0.12.1.5-svn],[http://trac.gajim.org/],[gajim])
AC_PREREQ([2.59])
AC_CONFIG_HEADER(config.h)

View File

@ -457,15 +457,15 @@ class Config:
}
soundevents_default = {
'first_message_received': [ True, '../data/sounds/message1.wav' ],
'next_message_received_focused': [ True, '../data/sounds/message2.wav' ],
'next_message_received_unfocused': [ True, '../data/sounds/message2.wav' ],
'contact_connected': [ True, '../data/sounds/connected.wav' ],
'contact_disconnected': [ True, '../data/sounds/disconnected.wav' ],
'message_sent': [ True, '../data/sounds/sent.wav' ],
'muc_message_highlight': [ True, '../data/sounds/gc_message1.wav', _('Sound to play when a group chat message contains one of the words in muc_highlight_words, or when a group chat message contains your nickname.')],
'muc_message_received': [ False, '../data/sounds/gc_message2.wav', _('Sound to play when any MUC message arrives.') ],
'gmail_received': [ False, '../data/sounds/message1.wav' ],
'first_message_received': [ True, 'message1.wav' ],
'next_message_received_focused': [ True, 'message2.wav' ],
'next_message_received_unfocused': [ True, 'message2.wav' ],
'contact_connected': [ True, 'connected.wav' ],
'contact_disconnected': [ True, 'disconnected.wav' ],
'message_sent': [ True, 'sent.wav' ],
'muc_message_highlight': [ True, 'gc_message1.wav', _('Sound to play when a group chat message contains one of the words in muc_highlight_words, or when a group chat message contains your nickname.')],
'muc_message_received': [ False, 'gc_message2.wav', _('Sound to play when any MUC message arrives.') ],
'gmail_received': [ False, 'message1.wav' ],
}
themes_default = {

View File

@ -27,7 +27,7 @@ docdir = '../'
datadir = '../'
localedir = '../po'
version = '0.12.1.4-svn'
version = '0.12.1.5-svn'
import sys, os.path
for base in ('.', 'common'):

View File

@ -773,11 +773,52 @@ def play_sound(event):
path_to_soundfile = gajim.config.get_per('soundevents', event, 'path')
play_sound_file(path_to_soundfile)
def check_soundfile_path(file,
dirs=(gajim.gajimpaths.root, gajim.DATA_DIR)):
'''Check if the sound file exists.
:param file: the file to check, absolute or relative to 'dirs' path
:param dirs: list of knows paths to fallback if the file doesn't exists
(eg: ~/.gajim/sounds/, DATADIR/sounds...).
:return the path to file or None if it doesn't exists.'''
if not file:
return None
elif os.path.exists(file):
return file
for d in dirs:
d = os.path.join(d, 'sounds', file)
if os.path.exists(d):
return d
return None
def strip_soundfile_path(file,
dirs=(gajim.gajimpaths.root, gajim.DATA_DIR),
abs=True):
'''Remove knowns paths from a sound file:
Filechooser returns absolute path. If path is a known fallback path, we remove it.
So config have no hardcoded path to DATA_DIR and text in textfield is shorther.
param: file: the filename to strip.
param: dirs: list of knowns paths from which the filename should be stripped.
param: abs: force absolute path on dirs
'''
if not file:
return None
name = os.path.basename(file)
for d in dirs:
d = os.path.join(d, 'sounds', name)
if abs:
d = os.path.abspath(d)
if file == d:
return name
return file
def play_sound_file(path_to_soundfile):
if path_to_soundfile == 'beep':
exec_command('beep')
return
if path_to_soundfile is None or not os.path.exists(path_to_soundfile):
path_to_soundfile = check_soundfile_path(path_to_soundfile)
if path_to_soundfile is None:
return
if sys.platform == 'darwin':
try:

View File

@ -30,6 +30,7 @@ import os
import locale
import re
from common import gajim
from common import helpers
import exceptions
try:
@ -195,6 +196,8 @@ class OptionsParser:
self.update_config_to_01213()
if old < [0, 12, 1, 4] and new >= [0, 12, 1, 4]:
self.update_config_to_01214()
if old < [0, 12, 1, 5] and new >= [0, 12, 1, 5]:
self.update_config_to_01215()
gajim.logger.init_vars()
gajim.config.set('version', new_version)
@ -657,4 +660,15 @@ class OptionsParser:
self.old_values['last_status_msg_' + status])
gajim.config.set('version', '0.12.1.4')
def update_config_to_01215(self):
'''Remove hardcoded ../data/sounds from config'''
dirs = ('../data', gajim.gajimpaths.root, gajim.DATA_DIR)
for evt in gajim.config.get_per('soundevents'):
path = gajim.config.get_per('soundevents', evt ,'path')
# absolute and relative passes are necessary
path = helpers.strip_soundfile_path(path, dirs, abs=False)
path = helpers.strip_soundfile_path(path, dirs, abs=True)
gajim.config.set_per('soundevents', evt, 'path', path)
gajim.config.set('version', '0.12.1.5')
# vim: se ts=3:

View File

@ -3647,6 +3647,7 @@ class ManageSoundsWindow:
return
directory = os.path.dirname(path_to_snd_file)
gajim.config.set('last_sounds_dir', directory)
path_to_snd_file = helpers.strip_soundfile_path(path_to_snd_file)
self.xml.get_widget('sounds_entry').set_text(path_to_snd_file)
model[iter_][2] = path_to_snd_file # set new path to sounds_model
@ -3654,12 +3655,8 @@ class ManageSoundsWindow:
def on_cancel(widget):
self.dialog.destroy()
model, iter_ = self.sound_tree.get_selection().get_selected()
model[iter_][2] = ''
model[iter_][0] = False
path_to_snd_file = model[iter_][2].decode('utf-8')
path_to_snd_file = os.path.join(os.getcwd(), path_to_snd_file)
self.dialog = dialogs.SoundChooserDialog(path_to_snd_file, on_ok,
on_cancel)

View File

@ -3165,7 +3165,10 @@ class SoundChooserDialog(FileChooserDialog):
self.add_filter(filter_)
self.set_filter(filter_)
path_to_snd_file = helpers.check_soundfile_path(path_to_snd_file)
if path_to_snd_file:
# set_filename accept only absolute path
path_to_snd_file = os.path.abspath(path_to_snd_file)
self.set_filename(path_to_snd_file)
class ImageChooserDialog(FileChooserDialog):