moving play_sound and launch_browser_mailer to common/helpers.py
This commit is contained in:
parent
9f7720edfd
commit
99bf5ba99f
|
@ -31,6 +31,7 @@ except:
|
|||
pass
|
||||
|
||||
from common import gajim
|
||||
from common import helpers
|
||||
from common import i18n
|
||||
|
||||
_ = i18n._
|
||||
|
@ -722,7 +723,7 @@ class Chat:
|
|||
|
||||
def visit_url_from_menuitem(self, widget, link):
|
||||
'''basically it filters out the widget instance'''
|
||||
self.plugin.launch_browser_mailer('url', link)
|
||||
helpers.launch_browser_mailer('url', link)
|
||||
|
||||
def on_message_textview_populate_popup(self, textview, menu):
|
||||
self.popup_is_shown = True
|
||||
|
@ -850,7 +851,7 @@ class Chat:
|
|||
return False
|
||||
|
||||
def on_open_link_activate(self, widget, kind, text):
|
||||
self.plugin.launch_browser_mailer(kind, text)
|
||||
helpers.launch_browser_mailer(kind, text)
|
||||
|
||||
def on_copy_link_activate(self, widget, text):
|
||||
clip = gtk.clipboard_get()
|
||||
|
@ -932,7 +933,7 @@ class Chat:
|
|||
self.make_link_menu(event, kind, word)
|
||||
else:
|
||||
#we launch the correct application
|
||||
self.plugin.launch_browser_mailer(kind, word)
|
||||
helpers.launch_browser_mailer(kind, word)
|
||||
|
||||
def detect_and_print_special_text(self, otext, jid, other_tags):
|
||||
textview = self.xmls[jid].get_widget('conversation_textview')
|
||||
|
|
|
@ -21,6 +21,7 @@ import gtk
|
|||
import gtk.glade
|
||||
|
||||
from common import gajim
|
||||
from common import helpers
|
||||
from common import i18n
|
||||
|
||||
_ = i18n._
|
||||
|
@ -50,7 +51,7 @@ class Check_for_new_version_dialog:
|
|||
|
||||
def on_open_download_page_button_clicked(self, widget):
|
||||
url = 'http://www.gajim.org/downloads.php?lang='
|
||||
self.plugin.launch_browser_mailer('url', url)
|
||||
helpers.launch_browser_mailer('url', url)
|
||||
self.window.destroy()
|
||||
|
||||
def check_for_new_version(self):
|
||||
|
|
|
@ -180,3 +180,57 @@ def is_in_path(name_of_command, return_abs_path = False):
|
|||
return abs_path
|
||||
else:
|
||||
return is_in_dir
|
||||
|
||||
def launch_browser_mailer(self, kind, uri):
|
||||
#kind = 'url' or 'mail'
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
os.startfile(uri) # if pywin32 is installed we open
|
||||
except:
|
||||
pass
|
||||
|
||||
else:
|
||||
if kind == 'url' and not\
|
||||
(uri.startswith('http://') or uri.startswith('https://')):
|
||||
uri = 'http://' + uri
|
||||
elif kind == 'mail' and not uri.startswith('mailto:'):
|
||||
uri = 'mailto:' + uri
|
||||
|
||||
if gajim.config.get('openwith') == 'gnome-open':
|
||||
command = 'gnome-open'
|
||||
elif gajim.config.get('openwith') == 'kfmclient exec':
|
||||
command = 'kfmclient exec'
|
||||
elif gajim.config.get('openwith') == 'custom':
|
||||
if kind == 'url':
|
||||
command = gajim.config.get('custombrowser')
|
||||
if kind == 'mail':
|
||||
command = gajim.config.get('custommailapp')
|
||||
if command == '': # if no app is configured
|
||||
return
|
||||
# we add the uri in "" so we have good parsing from shell
|
||||
command = command + ' "' + uri + '" &'
|
||||
try: #FIXME: when we require 2.4+ use subprocess module
|
||||
os.system(command)
|
||||
except:
|
||||
pass
|
||||
|
||||
def play_sound(self, event):
|
||||
if not gajim.config.get('sounds_on'):
|
||||
return
|
||||
path_to_soundfile = gajim.config.get_per('soundevents', event, 'path')
|
||||
if not os.path.exists(path_to_soundfile):
|
||||
return
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
winsound.PlaySound(path_to_soundfile,
|
||||
winsound.SND_FILENAME|winsound.SND_ASYNC)
|
||||
except:
|
||||
pass
|
||||
elif os.name == 'posix':
|
||||
if gajim.config.get('soundplayer') == '':
|
||||
return
|
||||
player = gajim.config.get('soundplayer')
|
||||
# we add the path in "" so we have good parsing from shell
|
||||
command = player + ' "' + path_to_soundfile + '" &'
|
||||
#FIXME: when we require 2.4+ use subprocess module
|
||||
os.system(command)
|
||||
|
|
67
src/gajim.py
67
src/gajim.py
|
@ -50,6 +50,7 @@ import common.sleepy
|
|||
import check_for_new_version
|
||||
from common import gajim
|
||||
from common import connection
|
||||
from common import helpers
|
||||
|
||||
from common import optparser
|
||||
|
||||
|
@ -126,60 +127,6 @@ GTKGUI_GLADE = 'gtkgui.glade'
|
|||
|
||||
|
||||
class Interface:
|
||||
def launch_browser_mailer(self, kind, uri):
|
||||
#kind = 'url' or 'mail'
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
os.startfile(uri) # if pywin32 is installed we open
|
||||
except:
|
||||
pass
|
||||
|
||||
else:
|
||||
if kind == 'url' and not\
|
||||
(uri.startswith('http://') or uri.startswith('https://')):
|
||||
uri = 'http://' + uri
|
||||
elif kind == 'mail' and not uri.startswith('mailto:'):
|
||||
uri = 'mailto:' + uri
|
||||
|
||||
if gajim.config.get('openwith') == 'gnome-open':
|
||||
command = 'gnome-open'
|
||||
elif gajim.config.get('openwith') == 'kfmclient exec':
|
||||
command = 'kfmclient exec'
|
||||
elif gajim.config.get('openwith') == 'custom':
|
||||
if kind == 'url':
|
||||
command = gajim.config.get('custombrowser')
|
||||
if kind == 'mail':
|
||||
command = gajim.config.get('custommailapp')
|
||||
if command == '': # if no app is configured
|
||||
return
|
||||
# we add the uri in "" so we have good parsing from shell
|
||||
command = command + ' "' + uri + '" &'
|
||||
try: #FIXME: when we require 2.4+ use subprocess module
|
||||
os.system(command)
|
||||
except:
|
||||
pass
|
||||
|
||||
def play_sound(self, event):
|
||||
if not gajim.config.get('sounds_on'):
|
||||
return
|
||||
path_to_soundfile = gajim.config.get_per('soundevents', event, 'path')
|
||||
if not os.path.exists(path_to_soundfile):
|
||||
return
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
winsound.PlaySound(path_to_soundfile,
|
||||
winsound.SND_FILENAME|winsound.SND_ASYNC)
|
||||
except:
|
||||
pass
|
||||
elif os.name == 'posix':
|
||||
if gajim.config.get('soundplayer') == '':
|
||||
return
|
||||
player = gajim.config.get('soundplayer')
|
||||
# we add the path in "" so we have good parsing from shell
|
||||
command = player + ' "' + path_to_soundfile + '" &'
|
||||
#FIXME: when we require 2.4+ use subprocess module
|
||||
os.system(command)
|
||||
|
||||
def handle_event_roster(self, account, data):
|
||||
#('ROSTER', account, array)
|
||||
self.roster.fill_contacts_and_groups_dicts(data, account)
|
||||
|
@ -345,7 +292,7 @@ class Interface:
|
|||
if old_show < 2 and new_show > 1:
|
||||
if gajim.config.get_per('soundevents', 'contact_connected',
|
||||
'enabled'):
|
||||
self.play_sound('contact_connected')
|
||||
helpers.play_sound('contact_connected')
|
||||
if not self.windows[account]['chats'].has_key(jid) and \
|
||||
not gajim.awaiting_messages[account].has_key(jid) and \
|
||||
gajim.config.get('notify_on_signin') and \
|
||||
|
@ -371,7 +318,7 @@ class Interface:
|
|||
elif old_show > 1 and new_show < 2:
|
||||
if gajim.config.get_per('soundevents', 'contact_disconnected',
|
||||
'enabled'):
|
||||
self.play_sound('contact_disconnected')
|
||||
helpers.play_sound('contact_disconnected')
|
||||
if not self.windows[account]['chats'].has_key(jid) and \
|
||||
not gajim.awaiting_messages[account].has_key(jid) and \
|
||||
gajim.config.get('notify_on_signout'):
|
||||
|
@ -468,10 +415,10 @@ class Interface:
|
|||
array[4], array[5])
|
||||
if gajim.config.get_per('soundevents', 'first_message_received',
|
||||
'enabled') and first:
|
||||
self.play_sound('first_message_received')
|
||||
helpers.play_sound('first_message_received')
|
||||
if gajim.config.get_per('soundevents', 'next_message_received',
|
||||
'enabled') and not first:
|
||||
self.play_sound('next_message_received')
|
||||
helpers.play_sound('next_message_received')
|
||||
if self.remote and self.remote.is_enabled():
|
||||
self.remote.raise_signal('NewMessage', (account, array))
|
||||
|
||||
|
@ -515,7 +462,7 @@ class Interface:
|
|||
msg = array[1]
|
||||
# do not play sound when standalone chatstate message (eg no msg)
|
||||
if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled'):
|
||||
self.play_sound('message_sent')
|
||||
helpers.play_sound('message_sent')
|
||||
|
||||
def handle_event_subscribe(self, account, array):
|
||||
#('SUBSCRIBE', account, (jid, text))
|
||||
|
@ -948,7 +895,7 @@ class Interface:
|
|||
self.sth_at_sth_dot_sth_re = sre.compile(r'\S+@\S+\.\S*[^\s)?]')
|
||||
|
||||
def on_launch_browser_mailer(self, widget, url, kind):
|
||||
self.launch_browser_mailer(kind, url)
|
||||
helpers.launch_browser_mailer(kind, url)
|
||||
|
||||
def init_regexp(self):
|
||||
#initialize emoticons dictionary
|
||||
|
|
Loading…
Reference in New Issue