configuration is now in common/config

currently gajim cannot be accessed from every where, even with global gajim :(
This commit is contained in:
Yann Leboulanger 2005-04-12 21:09:06 +00:00
parent aaf349f140
commit aa861b907a
11 changed files with 150 additions and 434 deletions

View File

@ -33,7 +33,7 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Chat:
"""Class for chat/groupchat windows"""
@ -58,15 +58,15 @@ class Chat:
def update_tags(self):
for jid in self.tagIn:
self.tagIn[jid].set_property("foreground", \
self.plugin.config['inmsgcolor'])
self.tagOut[jid].set_property("foreground", \
self.plugin.config['outmsgcolor'])
self.tagStatus[jid].set_property("foreground", \
self.plugin.config['statusmsgcolor'])
self.tagIn[jid].set_property('foreground', \
gajim.config.get('inmsgcolor'))
self.tagOut[jid].set_property('foreground', \
gajim.config.get('outmsgcolor'))
self.tagStatus[jid].set_property('foreground', \
gajim.config.get('statusmsgcolor'))
def update_print_time(self):
if self.plugin.config['print_time'] != 'sometimes':
if gajim.config.get('print_time') != 'sometimes':
list_jid = self.print_time_timeout_id.keys()
for jid in list_jid:
gobject.source_remove(self.print_time_timeout_id[jid])
@ -85,9 +85,9 @@ class Chat:
unread += self.nb_unread[jid]
start = ""
if unread > 1:
start = "[" + str(unread) + "] "
start = '[' + str(unread) + '] '
elif unread == 1:
start = "* "
start = '* '
chat = self.names[jid]
if len(self.xmls) > 1: # if more than one tabs in the same window
if self.widget_name == 'tabbed_chat_window':
@ -105,9 +105,9 @@ class Chat:
"""redraw the label of the tab"""
start = ''
if self.nb_unread[jid] > 1:
start = "[" + str(self.nb_unread[jid]) + "] "
start = '[' + str(self.nb_unread[jid]) + '] '
elif self.nb_unread[jid] == 1:
start = "* "
start = '* '
child = self.childs[jid]
tab_label = self.notebook.get_tab_label(child).get_children()[0]
tab_label.set_text(start + self.names[jid])
@ -134,8 +134,7 @@ class Chat:
return active_jid
def on_close_button_clicked(self, button, jid):
"""When close button is pressed :
close a tab"""
"""When close button is pressed : close a tab"""
self.remove_tab(jid)
def on_chat_window_focus_in_event(self, widget, event):
@ -219,13 +218,13 @@ class Chat:
conversation_buffer.create_mark('end', end_iter, False)
self.tagIn[jid] = conversation_buffer.create_tag('incoming')
color = self.plugin.config['inmsgcolor']
color = gajim.config.get('inmsgcolor')
self.tagIn[jid].set_property('foreground', color)
self.tagOut[jid] = conversation_buffer.create_tag('outgoing')
color = self.plugin.config['outmsgcolor']
color = gajim.config.get('outmsgcolor')
self.tagOut[jid].set_property('foreground', color)
self.tagStatus[jid] = conversation_buffer.create_tag('status')
color = self.plugin.config['statusmsgcolor']
color = gajim.config.get('statusmsgcolor')
self.tagStatus[jid].set_property('foreground', color)
tag = conversation_buffer.create_tag('time_sometimes')
@ -405,7 +404,7 @@ class Chat:
def print_time_timeout(self, jid):
if not jid in self.xmls.keys():
return 0
if self.plugin.config['print_time'] == 'sometimes':
if gajim.config.get('print_time') == 'sometimes':
conversation_textview = self.xmls[jid].\
get_widget('conversation_textview')
conversation_buffer = conversation_textview.get_buffer()
@ -487,7 +486,7 @@ class Chat:
index = 0
# basic: links + mail + formatting is always checked (we like that)
if self.plugin.config['useemoticons']: # search for emoticons & urls
if gajim.config.get('useemoticons'): # search for emoticons & urls
iterator = self.plugin.emot_and_basic_re.finditer(otext)
else: # search for just urls + mail + formatting
iterator = self.plugin.basic_pattern_re.finditer(otext)
@ -593,11 +592,11 @@ class Chat:
text = ''
if conversation_buffer.get_char_count() > 0:
conversation_buffer.insert(end_iter, '\n')
if self.plugin.config['print_time'] == 'always':
if gajim.config.get('print_time') == 'always':
if not tim:
tim = time.localtime()
self.before_time_symbols = self.plugin.config['before_time']
self.after_time_symbols = self.plugin.config['after_time']
self.before_time_symbols = gajim.config.get('before_time')
self.after_time_symbols = gajim.config.get('after_time')
format = self.before_time_symbols + '%H:%M:%S' + self.after_time_symbols
tim_format = time.strftime(format, tim)
conversation_buffer.insert(end_iter, tim_format + ' ')
@ -614,8 +613,8 @@ class Chat:
tags = other_tags_for_name[:] #create a new list
tags.append(kind)
if name and not print_all_special:
self.before_nickname_symbols = self.plugin.config['before_nickname']
self.after_nickname_symbols = self.plugin.config['after_nickname']
self.before_nickname_symbols = gajim.config.get('before_nickname')
self.after_nickname_symbols = gajim.config.get('after_nickname')
format = self.before_nickname_symbols + name\
+ self.after_nickname_symbols + ' '
self.print_with_tag_list(conversation_buffer, format, end_iter, tags)

0
src/common/__init__.py Normal file
View File

View File

@ -1,4 +1,4 @@
## Core/connection.py
## common/connection.py
##
## Gajim Team:
## - Yann Le Boulanger <asterix@lagaule.org>
@ -86,13 +86,12 @@ class connection:
def __init__(self, name = None):
# dict of function to be calledfor each event
self.handlers = {'ROSTER': [], 'WARNING': [], 'ERROR': [], 'STATUS': [], \
'NOTIFY': [], 'MSG': [], 'MSGERROR': [], 'SUBSCRIBED': [], \
'UNSUBSCRIBED': [], 'SUBSCRIBE': [], 'AGENTS': [], 'AGENT_INFO': [], \
'AGENT_INFO_ITEMS': [], 'AGENT_INFO_INFO': [], 'REG_AGENT_INFO': [], \
'QUIT': [], 'ACC_OK': [], 'CONFIG': [], 'MYVCARD': [], 'OS_INFO': [], \
'VCARD': [], 'LOG_NB_LINE': [], 'LOG_LINE': [], 'VISUAL': [], \
'NOTIFY': [], 'MSG': [], 'MSGERROR': [], 'MSGSENT': [] , \
'SUBSCRIBED': [], 'UNSUBSCRIBED': [], 'SUBSCRIBE': [], \
'AGENT_INFO': [], 'AGENT_INFO_ITEMS': [], 'AGENT_INFO_INFO': [], \
'QUIT': [], 'ACC_OK': [], 'MYVCARD': [], 'OS_INFO': [], 'VCARD': [], \
'GC_MSG': [], 'GC_SUBJECT': [], 'BAD_PASSPHRASE': [], \
'GPG_SECRETE_KEYS': [], 'ROSTER_INFO': [], 'MSGSENT': []}
'ROSTER_INFO': []}
self.name = name
self.connected = 0 # offline
self.connection = None # Jabber.py instance

View File

@ -31,7 +31,7 @@ gtk.glade.textdomain (APP)
from dialogs import *
import gtkgui
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Preferences_window:
@ -1213,9 +1213,13 @@ class Account_modification_window:
self.plugin.send('ASK_VCARD', self.account, jid)
def on_gpg_choose_button_clicked(self, widget, data=None):
w = choose_gpg_key_dialog()
self.plugin.windows['gpg_keys'] = w
self.plugin.send('GPG_SECRETE_KEYS', None, ())
#FIXME:
secret_keys = connection.ask_gpg_secrete_keys()
if not secret_keys:
Error_dialog(_('error contacting %s') % service)
return
secret_keys['None'] = 'None'
w = choose_gpg_key_dialog(secret_keys)
keyID = w.run()
if keyID == -1:
return
@ -1796,7 +1800,12 @@ class Service_discovery_window:
if not iter :
return
service = model.get_value(iter, 1)
self.plugin.send('REG_AGENT_INFO', self.account, service)
#FIXME:
infos = connection.ask_register_agent_info(service)
if not infos.has_key('instructions'):
Error_dialog(_('error contacting %s') % service)
else:
Service_registration_window(service, infos, self.plugin, self.account)
self.window.destroy()
def on_services_treeview_cursor_changed(self, widget):

View File

@ -27,9 +27,8 @@ gtk.glade.bindtextdomain (APP, i18n.DIR)
gtk.glade.textdomain (APP)
import gtkgui
import version
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Vcard_information_window:
"""Class for user's information window"""
@ -363,7 +362,7 @@ class choose_gpg_key_dialog:
for keyID in list.keys():
model.append((keyID, list[keyID]))
def __init__(self):
def __init__(self, secret_keys):
#list : {keyID: userName, ...}
xml = gtk.glade.XML(GTKGUI_GLADE, 'choose_gpg_key_dialog', APP)
self.window = xml.get_widget('choose_gpg_key_dialog')
@ -377,6 +376,7 @@ class choose_gpg_key_dialog:
renderer = gtk.CellRendererText()
self.keys_treeview.insert_column_with_attributes(-1, _('User name'), \
renderer, text=1)
self.fill_tree(secret_keys)
self.window.show_all()
@ -389,12 +389,12 @@ class Change_status_message_dialog:
self.autoconnect = autoconnect
message_textview = self.xml.get_widget('message_textview')
self.message_buffer = message_textview.get_buffer()
self.message_buffer.set_text(self.plugin.config['last_msg'])
self.message_buffer.set_text(gajim.config.get('last_msg'))
self.values = {'':''}
i = 0
while self.plugin.config.has_key('msg%s_name' % i):
self.values[self.plugin.config['msg%s_name' % i]] = \
self.plugin.config['msg%s' % i]
while gajim.config.exist('msg%s_name' % i):
self.values[gajim.config.get('msg%s_name' % i)] = \
gajim.config.get('msg%s' % i)
i += 1
liststore = gtk.ListStore(str, str)
message_comboboxentry = self.xml.get_widget('message_comboboxentry')
@ -413,7 +413,7 @@ class Change_status_message_dialog:
if rep == gtk.RESPONSE_OK:
beg, end = self.message_buffer.get_bounds()
message = self.message_buffer.get_text(beg, end, 0)
self.plugin.config['last_msg'] = message
gajim.config.set('last_msg', message)
else:
message = -1
self.window.destroy()
@ -565,7 +565,7 @@ class About_dialog:
dlg = gtk.AboutDialog()
dlg.set_name('Gajim')
dlg.set_version(version.version)
dlg.set_version(gajim.version.version)
s = u'Copyright \xa9 2003-2005 Gajim Team'
dlg.set_copyright(s)
text = open('COPYING').read()
@ -683,7 +683,7 @@ class Join_groupchat_window:
cell = gtk.CellRendererText()
self.recently_combobox.pack_start(cell, True)
self.recently_combobox.add_attribute(cell, 'text', 0)
self.recently_groupchat = self.plugin.config['recently_groupchat'].split()
self.recently_groupchat = gajim.config.get('recently_groupchat').split()
for g in self.recently_groupchat:
self.recently_combobox.append_text(g)
@ -720,8 +720,7 @@ class Join_groupchat_window:
self.recently_groupchat.insert(0, jid)
if len(self.recently_groupchat) > 10:
self.recently_groupchat = self.recently_groupchat[0:10]
self.plugin.config['recently_groupchat'] = \
' '.join(self.recently_groupchat)
gajim.config.set('recently_groupchat', ' '.join(self.recently_groupchat))
self.plugin.roster.new_group(jid, nickname, self.account)
self.plugin.send('GC_JOIN', self.account, (nickname, room, server, \
password))

View File

@ -34,7 +34,7 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Groupchat_window(Chat):
"""Class for Groupchat window"""

View File

@ -1,4 +1,4 @@
## plugins/gtkgui.py
## gtkgui.py
##
## Gajim Team:
## - Yann Le Boulanger <asterix@lagaule.org>
@ -16,41 +16,7 @@
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
if __name__ == "__main__":
import getopt, pickle, sys, socket
try: # Import Psyco if available
import psyco
psyco.full()
except ImportError:
pass
try:
opts, args = getopt.getopt(sys.argv[1:], "p:h", ["help"])
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
port = 8255
for o, a in opts:
if o == '-p':
port = a
if o in ("-h", "--help"):
usage()
sys.exit()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(('', 8255))
except:
#TODO: use i18n
print "unable to connect to localhost on port ", port
else:
evp = pickle.dumps(('EXEC_PLUGIN', '', 'gtkgui'))
sock.send('<'+evp+'>')
sock.close()
sys.exit()
import pygtk
pygtk.require('2.0')
import gtk
@ -58,10 +24,9 @@ import gtk.glade
import pango
import gobject
import os
import time
import sys
import Queue
import sre
global gajim
import common.gajim as gajim
import common.sleepy
try:
@ -72,8 +37,8 @@ except ImportError:
class CellRendererImage(gtk.GenericCellRenderer):
__gproperties__ = {
"image": (gobject.TYPE_OBJECT, "Image",
"Image", gobject.PARAM_READWRITE),
'image': (gobject.TYPE_OBJECT, 'Image',
'Image', gobject.PARAM_READWRITE),
}
def __init__(self):
@ -115,8 +80,8 @@ class CellRendererImage(gtk.GenericCellRenderer):
pix_rect.x += cell_area.x
pix_rect.y += cell_area.y
pix_rect.width -= 2 * self.get_property("xpad")
pix_rect.height -= 2 * self.get_property("ypad")
pix_rect.width -= 2 * self.get_property('xpad')
pix_rect.height -= 2 * self.get_property('ypad')
draw_rect = cell_area.intersect(pix_rect)
draw_rect = expose_area.intersect(draw_rect)
@ -150,15 +115,15 @@ class CellRendererImage(gtk.GenericCellRenderer):
return 0, 0, 0, 0
pixbuf_width = pix.get_width()
pixbuf_height = pix.get_height()
calc_width = self.get_property("xpad") * 2 + pixbuf_width
calc_height = self.get_property("ypad") * 2 + pixbuf_height
calc_width = self.get_property('xpad') * 2 + pixbuf_width
calc_height = self.get_property('ypad') * 2 + pixbuf_height
x_offset = 0
y_offset = 0
if cell_area and pixbuf_width > 0 and pixbuf_height > 0:
x_offset = self.get_property("xalign") * (cell_area.width - \
calc_width - self.get_property("xpad"))
y_offset = self.get_property("yalign") * (cell_area.height - \
calc_height - self.get_property("ypad"))
x_offset = self.get_property('xalign') * (cell_area.width - \
calc_width - self.get_property('xpad'))
y_offset = self.get_property('yalign') * (cell_area.height - \
calc_height - self.get_property('ypad'))
return x_offset, y_offset, calc_width, calc_height
gobject.type_register(CellRendererImage)
@ -205,63 +170,24 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
def usage():
#TODO: use i18n
print 'usage :', sys.argv[0], ' [OPTION]'
print ' -p\tport on which the sock plugin listen'
print ' -h, --help\tdisplay this help and exit'
GTKGUI_GLADE='gtkgui.glade'
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
class plugin:
"""Class called by the core in a new thread"""
class accounts:
"""Class where are stored the accounts and users in them"""
def __init__(self):
self.__accounts = {}
def add_account(self, account, users=()):
#users must be like (user1, user2)
self.__accounts[account] = users
def add_user_to_account(self, account, user):
if self.__accounts.has_key(account):
self.__accounts[account].append(user)
else :
return 1
def get_accounts(self):
return self.__accounts.keys();
def get_users(self, account):
if self.__accounts.has_key(account):
return self.__accounts[account]
else :
return None
def which_account(self, user):
for a in self.__accounts.keys():
if user in self.__accounts[a]:
return a
return None
class interface:
def launch_browser_mailer(self, kind, url):
#kind = 'url' or 'mail'
if self.config['openwith'] == 'gnome-open':
if gajim.config.get('openwith') == 'gnome-open':
app = 'gnome-open'
args = ['gnome-open']
args.append(url)
elif self.config['openwith'] == 'kfmclient exec':
elif gajim.config.get('openwith') == 'kfmclient exec':
app = 'kfmclient'
args = ['kfmclient', 'exec']
elif self.config['openwith'] == 'custom':
elif gajim.config.get('openwith') == 'custom':
if kind == 'url':
conf = self.config['custombrowser']
conf = gajim.config.get('custombrowser')
if kind == 'mail':
conf = self.config['custommailapp']
conf = gajim.config.get('custommailapp')
if conf == '': # if no app is configured
return
args = conf.split()
@ -280,44 +206,24 @@ class plugin:
return 0
def play_sound(self, event):
if not self.config['sounds_on']:
if not gajim.config.get('sounds_on'):
return
path_to_soundfile = self.config[event + '_file']
path_to_soundfile = gajim.config.get(event + '_file')
if not os.path.exists(path_to_soundfile):
return
if os.name == 'nt':
winsound.PlaySound(path_to_soundfile, \
winsound.SND_FILENAME|winsound.SND_ASYNC)
elif os.name == 'posix':
if self.config['soundplayer'] == '':
if gajim.config.get('soundplayer') == '':
return
argv = self.config['soundplayer'].split()
argv = gajim.config.get('soundplayer').split()
argv.append(path_to_soundfile)
pid = os.spawnvp(os.P_NOWAIT, argv[0], argv)
pidp, r = os.waitpid(pid, os.WNOHANG)
if pidp == 0:
gobject.timeout_add(10000, self.play_timeout, pid)
def send(self, event, account, data):
self.queueOUT.put((event, account, data))
def wait(self, what):
"""Wait for a message from Core"""
#TODO: timeout
temp_q = Queue.Queue(50)
while 1:
if not self.queueIN.empty():
ev = self.queueIN.get()
if ev[0] == what and ev[2][0] == 'GtkGui':
#Restore messages
while not temp_q.empty():
ev2 = temp_q.get()
self.queueIN.put(ev2)
return ev[2][1]
else:
#Save messages
temp_q.put(ev)
def handle_event_roster(self, account, data):
#('ROSTER', account, (state, array))
statuss = ['offline', 'online', 'away', 'xa', 'dnd', 'invisible']
@ -500,11 +406,6 @@ class plugin:
def handle_event_unsubscribed(self, account, jid):
Information_dialog(_("You are now unsubscribed by %s") % jid)
def handle_event_agents(self, account, agents):
#('AGENTS', account, agents)
if self.windows[account].has_key('disco'):
self.windows[account]['disco'].agents(agents)
def handle_event_agent_info(self, account, array):
#('AGENT_INFO', account, (agent, identities, features, items))
if self.windows[account].has_key('disco'):
@ -522,13 +423,6 @@ class plugin:
self.windows[account]['disco'].agent_info_info(array[0], array[1], \
array[2])
def handle_event_reg_agent_info(self, account, array):
#('REG_AGENTS_INFO', account, (agent, infos))
if not array[1].has_key('instructions'):
Error_dialog(_("error contacting %s") % array[0])
else:
Service_registration_window(array[0], array[1], self, account)
def handle_event_acc_ok(self, account, array):
#('ACC_OK', account, (hostname, login, pasword, name, resource, prio,
#use_proxy, proxyhost, proxyport))
@ -559,11 +453,6 @@ class plugin:
def handle_event_quit(self, p1, p2):
self.roster.on_quit() # SUCH FUNCTION DOES NOT EXIST!!
def save_config(self):
hidden_lines = self.config['hiddenlines'].split('\t')
self.config['hiddenlines'] = '\t'.join(hidden_lines)
self.send('CONFIG', None, ('GtkGui', self.config, 'GtkGui'))
def handle_event_myvcard(self, account, array):
nick = ''
if array.has_key('NICKNAME'):
@ -581,22 +470,6 @@ class plugin:
self.windows[account]['infos'][array[0]].set_os_info(array[1], \
array[2])
def handle_event_log_nb_line(self, account, array):
#('LOG_NB_LINE', account, (jid, nb_line))
if self.windows['logs'].has_key(array[0]):
self.windows['logs'][array[0]].set_nb_line(array[1])
begin = 0
if array[1] > 50:
begin = array[1] - 50
self.send('LOG_GET_RANGE', None, (array[0], begin, array[1]))
def handle_event_log_line(self, account, array):
#('LOG_LINE', account, (jid, num_line, date, type, data))
# if type = 'recv' or 'sent' data = [msg]
# else type = jid and data = [status, away_msg]
if self.windows['logs'].has_key(array[0]):
self.windows['logs'][array[0]].new_line(array[1:])
def handle_event_gc_msg(self, account, array):
#('GC_MSG', account, (jid, msg, time))
jids = array[0].split('/')
@ -626,11 +499,6 @@ class plugin:
def handle_event_bad_passphrase(self, account, array):
Warning_dialog(_("Your GPG passphrase is wrong, so you are connected without your GPG key."))
def handle_event_gpg_secrete_keys(self, account, keys):
keys['None'] = 'None'
if self.windows.has_key('gpg_keys'):
self.windows['gpg_keys'].fill_tree(keys)
def handle_event_roster_info(self, account, array):
#('ROSTER_INFO', account, (jid, name, sub, ask, groups))
jid = array[0]
@ -652,68 +520,6 @@ class plugin:
user.groups = array[4]
self.roster.redraw_jid(jid, account)
def read_queue(self):
"""Read queue from the core and execute commands from it"""
while self.queueIN.empty() == 0:
ev = self.queueIN.get()
if ev[0] == 'ROSTER':
self.handle_event_roster(ev[1], ev[2])
elif ev[0] == 'WARNING':
self.handle_event_warning(ev[1], ev[2])
elif ev[0] == 'ERROR':
self.handle_event_error(ev[1], ev[2])
elif ev[0] == 'STATUS':
self.handle_event_status(ev[1], ev[2])
elif ev[0] == 'NOTIFY':
self.handle_event_notify(ev[1], ev[2])
elif ev[0] == 'MSG':
self.handle_event_msg(ev[1], ev[2])
elif ev[0] == 'MSGERROR':
self.handle_event_msgerror(ev[1], ev[2])
elif ev[0] == 'MSGSENT':
self.handle_event_msgsent(ev[1], ev[2])
elif ev[0] == 'SUBSCRIBE':
self.handle_event_subscribe(ev[1], ev[2])
elif ev[0] == 'SUBSCRIBED':
self.handle_event_subscribed(ev[1], ev[2])
elif ev[0] == 'UNSUBSCRIBED':
self.handle_event_unsubscribed(ev[1], ev[2])
elif ev[0] == 'AGENTS':
self.handle_event_agents(ev[1], ev[2])
elif ev[0] == 'AGENT_INFO':
self.handle_event_agent_info(ev[1], ev[2])
elif ev[0] == 'AGENT_INFO_ITEMS':
self.handle_event_agent_info_items(ev[1], ev[2])
elif ev[0] == 'AGENT_INFO_INFO':
self.handle_event_agent_info_info(ev[1], ev[2])
elif ev[0] == 'REG_AGENT_INFO':
self.handle_event_reg_agent_info(ev[1], ev[2])
elif ev[0] == 'ACC_OK':
self.handle_event_acc_ok(ev[1], ev[2])
elif ev[0] == 'QUIT':
self.handle_event_quit(ev[1], ev[2])
elif ev[0] == 'MYVCARD':
self.handle_event_myvcard(ev[1], ev[2])
elif ev[0] == 'OS_INFO':
self.handle_event_os_info(ev[1], ev[2])
elif ev[0] == 'VCARD':
self.handle_event_vcard(ev[1], ev[2])
elif ev[0] == 'LOG_NB_LINE':
self.handle_event_log_nb_line(ev[1], ev[2])
elif ev[0] == 'LOG_LINE':
self.handle_event_log_line(ev[1], ev[2])
elif ev[0] == 'GC_MSG':
self.handle_event_gc_msg(ev[1], ev[2])
elif ev[0] == 'GC_SUBJECT':
self.handle_event_gc_subject(ev[1], ev[2])
elif ev[0] == 'BAD_PASSPHRASE':
self.handle_event_bad_passphrase(ev[1], ev[2])
elif ev[0] == 'GPG_SECRETE_KEYS':
self.handle_event_gpg_secrete_keys(ev[1], ev[2])
elif ev[0] == 'ROSTER_INFO':
self.handle_event_roster_info(ev[1], ev[2])
return 1
def read_sleepy(self):
"""Check if we are idle"""
if not self.sleeper.poll():
@ -847,117 +653,25 @@ class plugin:
# update regular expressions
self.make_regexps()
def __init__(self, quIN, quOUT):
gtk.gdk.threads_init()
def __init__(self):
if gtk.pygtk_version >= (2, 6, 0):
gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')
gtk.about_dialog_set_url_hook(self.on_launch_browser_mailer, 'url')
self.queueIN = quIN
self.queueOUT = quOUT
self.send('REG_MESSAGE', 'gtkgui', ['ROSTER', 'WARNING', 'ERROR', \
'STATUS', 'NOTIFY', 'MSG', 'MSGERROR', 'SUBSCRIBED', 'UNSUBSCRIBED', \
'SUBSCRIBE', 'AGENTS', 'AGENT_INFO', 'AGENT_INFO_ITEMS', \
'AGENT_INFO_INFO', 'REG_AGENT_INFO', 'QUIT', 'ACC_OK', 'CONFIG', \
'MYVCARD', 'OS_INFO', 'VCARD', 'LOG_NB_LINE', 'LOG_LINE', 'VISUAL', \
'GC_MSG', 'GC_SUBJECT', 'BAD_PASSPHRASE', 'GPG_SECRETE_KEYS', \
'ROSTER_INFO', 'MSGSENT'])
self.default_config = {'autopopup':0,\
'autopopupaway':0,\
'ignore_unknown_contacts':0,\
'showoffline':0,\
'autoaway':1,\
'autoawaytime':10,\
'autoxa':1,\
'autoxatime':20,\
'ask_online_status':0,\
'ask_offline_status':0,\
'last_msg':'',\
'msg0_name':'Nap',\
'msg0':'I\'m taking a nap.',\
'msg1_name':'Brb',\
'msg1':'Back in some minutes.',\
'msg2_name':'Eating',\
'msg2':'I\'m eating, so leave me a message.',\
'msg3_name':'Movie',\
'msg3':'I\'m watching a movie.',\
'msg4_name':'Working',\
'msg4':'I\'m working.',\
'trayicon':1,\
'iconset':'sun',\
'inmsgcolor':'#ff0000',\
'outmsgcolor': '#0000ff',\
'statusmsgcolor':'#1eaa1e',\
'hiddenlines':'',\
'accounttextcolor': '#ffffff',\
#ff0000
'accountbgcolor': '#94aa8c',\
#9fdfff
'accountfont': 'Sans Bold 10',\
'grouptextcolor': '#0000ff',\
'groupbgcolor': '#eff3e7',\
#ffffff
'groupfont': 'Sans Italic 10',\
'usertextcolor': '#000000',\
'userbgcolor': '#ffffff',\
'userfont': 'Sans 10',\
'saveposition': 1,\
'mergeaccounts': 0,\
'usetabbedchat': 1,\
'print_time': 'always',\
'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:-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(C)\tplugins/gtkgui/emoticons/coffee.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(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;-)\tplugins/gtkgui/emoticons/wink.png\t;-(\tplugins/gtkgui/emoticons/cry.png\t(6)\tplugins/gtkgui/emoticons/devil.png\t(L)\tplugins/gtkgui/emoticons/heart.png\t(W)\tplugins/gtkgui/emoticons/brflower.png\t:|\tplugins/gtkgui/emoticons/stare.png\t:O\tplugins/gtkgui/emoticons/oh.png\t;)\tplugins/gtkgui/emoticons/wink.png\t;(\tplugins/gtkgui/emoticons/cry.png\t:S\tplugins/gtkgui/emoticons/frowing.png\t;\'-(\tplugins/gtkgui/emoticons/cry.png\t:-(\tplugins/gtkgui/emoticons/unhappy.png\t8-)\tplugins/gtkgui/emoticons/coolglasses.png\t(B)\tplugins/gtkgui/emoticons/beer.png\t:D\tplugins/gtkgui/emoticons/biggrin.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:->\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(S)\tplugins/gtkgui/emoticons/moon.png',\
'sounds_on': 1,\
'soundplayer': 'play',\
'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',\
'openwith': 'gnome-open',\
'custombrowser' : 'firefox',\
'custommailapp' : 'mozilla-thunderbird -compose',\
'x-position': 0,\
'y-position': 0,\
'width': 150,\
'height': 400,\
'latest_disco_addresses': '',\
'recently_groupchat': '',\
'before_time': '[',\
'after_time': ']',\
'before_nickname': '<',\
'after_nickname': '>',\
'do_not_send_os_info': 0,\
}
self.send('ASK_CONFIG', None, ('GtkGui', 'GtkGui', self.default_config))
self.config = self.wait('CONFIG')
self.send('ASK_CONFIG', None, ('GtkGui', 'accounts'))
self.accounts = self.wait('CONFIG')
self.windows = {'logs':{}}
self.queues = {}
self.connected = {}
self.nicks = {}
self.sleeper_state = {} #whether we pass auto away / xa or not
for a in self.accounts.keys():
for a in gajim.connections:
self.windows[a] = {'infos': {}, 'chats': {}, 'gc': {}}
self.queues[a] = {}
self.connected[a] = 0 #0->offline 1->connecting 2->online 3->away
#4->xa 5->dnd 6->invisible
self.nicks[a] = self.accounts[a]['name']
self.nicks[a] = gajim.config.get_per('accounts', a, 'name')
self.sleeper_state[a] = 0 #0:don't use sleeper for this account
#1:online and use sleeper
#2:autoaway and use sleeper
#3:autoxa and use sleeper
self.send('ASK_ROSTER', a, self.queueIN)
iconset = self.config['iconset']
if not iconset:
iconset = 'sun'
path = 'plugins/gtkgui/iconsets/' + iconset + '/'
iconset = gajim.config.get('iconset')
path = 'data/iconsets/' + iconset + '/'
files = [path + 'online.gif', path + 'online.png', path + 'online.xpm']
pix = None
for fname in files:
@ -967,11 +681,10 @@ class plugin:
if pix:
gtk.window_set_default_icon(pix)
self.roster = Roster_window(self)
gobject.timeout_add(100, self.read_queue)
gobject.timeout_add(100, self.read_sleepy)
self.sleeper = common.sleepy.Sleepy( \
self.config['autoawaytime']*60, \
self.config['autoxatime']*60)
gajim.config.get('autoawaytime')*60, \
gajim.config.get('autoxatime')*60)
self.systray_enabled = False
try:
import egg.trayicon as trayicon # use gnomepythonextras trayicon
@ -979,8 +692,6 @@ class plugin:
try:
import trayicon # use yann's
except: # user doesn't have trayicon capabilities
self.config['trayicon'] = 0
self.send('CONFIG', None, ('GtkGui', self.config, 'GtkGui'))
self.systray_capabilities = False
else:
self.systray_capabilities = True
@ -988,20 +699,25 @@ class plugin:
else:
self.systray_capabilities = True
self.systray = Systray(self)
if self.config['trayicon']:
if self.systray_capabilities:
self.show_systray()
self.init_regexp()
# get instances for windows/dialogs that will show_all()/hide()
self.windows['preferences'] = Preferences_window(self)
self.windows['add_remove_emoticons_window'] = \
Add_remove_emoticons_window(self)
Add_remove_emoticons_window(self)
self.windows['roster'] = self.roster
gtk.gdk.threads_enter()
gobject.timeout_add(100, self.autoconnect)
gtk.main()
gtk.gdk.threads_leave()
print _('plugin gtkgui loaded')
if __name__ == '__main__':
try: # Import Psyco if available
import psyco
psyco.full()
except ImportError:
pass
interface()
gtk.main()

View File

@ -28,7 +28,7 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class history_window:
"""Class for bowser agent window:
@ -148,13 +148,13 @@ class history_window:
self.latest_button = xml.get_widget('latest_button')
xml.signal_autoconnect(self)
tagIn = self.history_buffer.create_tag('incoming')
color = self.plugin.config['inmsgcolor']
color = gajim.config.get('inmsgcolor')
tagIn.set_property('foreground', color)
tagOut = self.history_buffer.create_tag('outgoing')
color = self.plugin.config['outmsgcolor']
color = gajim.config.get('outmsgcolor')
tagOut.set_property('foreground', color)
tagStatus = self.history_buffer.create_tag('status')
color = self.plugin.config['statusmsgcolor']
color = gajim.config.get('statusmsgcolor')
tagStatus.set_property('foreground', color)
self.window.show_all()
self.plugin.send('LOG_NB_LINE', None, jid)

View File

@ -39,7 +39,7 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Roster_window:
"""Class for main window of gtkgui plugin"""
@ -120,7 +120,7 @@ class Roster_window:
def add_user_to_roster(self, jid, account):
"""Add a user to the roster and add groups if they aren't in roster"""
showOffline = self.plugin.config['showoffline']
showOffline = gajim.config.get('showoffline')
if not self.contacts[account].has_key(jid):
return
users = self.contacts[account][jid]
@ -148,7 +148,8 @@ class Roster_window:
self.groups[account][g] = {'expand': False}
else:
self.groups[account][g] = {'expand': True}
if not account in self.hidden_lines and not self.plugin.config['mergeaccounts']:
if not account in self.hidden_lines and not gajim.config.get(\
'mergeaccounts'):
self.tree.expand_row((model.get_path(iterG)[0]), False)
typestr = 'user'
@ -365,7 +366,7 @@ class Roster_window:
def chg_user_status(self, user, show, status, account):
"""When a user change his status"""
showOffline = self.plugin.config['showoffline']
showOffline = gajim.config.get('showoffline')
model = self.tree.get_model()
luser = self.contacts[account][user.jid]
user.show = show
@ -721,7 +722,7 @@ class Roster_window:
if self.plugin.accounts[account].has_key('keyid'):
keyid = self.plugin.accounts[account]['keyid']
if keyid and self.plugin.connected[account] < 2 and \
self.plugin.config['usegpg']:
gajim.config.get('usegpg'):
if save_gpg_pass:
passphrase = self.plugin.accounts[account]['gpgpassword']
else:
@ -749,9 +750,8 @@ class Roster_window:
self.plugin.sleeper_state[account] = 0
def get_status_message(self, status, autoconnect = 0):
if (status == 'online' and not self.plugin.config['ask_online_status']) \
or (status == 'offline' and not \
self.plugin.config['ask_offline_status']):
if (status == 'online' and not gajim.config.get('ask_online_status')) or \
(status == 'offline' and not gajim.config.get('ask_offline_status')):
return status
dlg = Change_status_message_dialog(self.plugin, status, autoconnect)
message = dlg.run()
@ -829,7 +829,7 @@ class Roster_window:
self.update_status_comboxbox()
def new_chat(self, user, account):
if self.plugin.config['usetabbedchat']:
if gajim.config.get('usetabbedchat'):
if not self.plugin.windows[account]['chats'].has_key('tabbed'):
self.plugin.windows[account]['chats']['tabbed'] = \
Tabbed_chat_window(user, self.plugin, account)
@ -845,7 +845,7 @@ class Roster_window:
Tabbed_chat_window(user, self.plugin, account)
def new_group(self, jid, nick, account):
if self.plugin.config['usetabbedchat']:
if gajim.config.get('usetabbedchat'):
if not self.plugin.windows[account]['gc'].has_key('tabbed'):
self.plugin.windows[account]['gc']['tabbed'] = \
Groupchat_window(jid, nick, self.plugin, account)
@ -871,8 +871,8 @@ class Roster_window:
path = self.tree.get_model().get_path(iters[0])
else:
path = None
autopopup = self.plugin.config['autopopup']
autopopupaway = self.plugin.config['autopopupaway']
autopopup = gajim.config.get('autopopup')
autopopupaway = gajim.config.get('autopopupaway')
if (autopopup == 0 or ( not autopopupaway and \
self.plugin.connected[account] > 2)) and not \
self.plugin.windows[account]['chats'].has_key(jid):
@ -964,16 +964,17 @@ class Roster_window:
def quit_gtkgui_plugin(self):
"""When we quit the gtk plugin :
tell that to the core and exit gtk"""
if self.plugin.config.has_key('saveposition'):
if self.plugin.config['saveposition']:
self.plugin.config['x-position'], self.plugin.config['y-position']=\
self.window.get_position()
self.plugin.config['width'], self.plugin.config['height'] = \
self.window.get_size()
if gajim.config.exist('saveposition'):
if gajim.config.get('saveposition'):
x, y = self.window.get_position()
gajim.config.set('x-position', x)
gajim.config.set('y-position', y)
width, height = self.window.get_size()
gajim.config.set('width', width)
gajim.config.set('height', height)
self.plugin.save_config()
self.plugin.send('QUIT', None, ('gtkgui', 1))
print _("plugin gtkgui stopped")
self.close_all(self.plugin.windows)
if self.plugin.systray_enabled:
self.plugin.hide_systray()
@ -1010,7 +1011,7 @@ class Roster_window:
self.tree.expand_row(path, False)
else:
if self.plugin.windows[account]['chats'].has_key(jid):
if self.plugin.config['usetabbedchat']:
if gajim.config.get('usetabbedchat'):
self.plugin.windows[account]['chats'][jid].active_tab(jid)
self.plugin.windows[account]['chats'][jid].window.present()
elif self.contacts[account].has_key(jid):
@ -1103,7 +1104,7 @@ class Roster_window:
def mkpixbufs(self):
"""initialise pixbufs array"""
iconset = self.plugin.config['iconset']
iconset = gajim.config.get('iconset')
if not iconset:
iconset = 'sun'
self.path = 'plugins/gtkgui/iconsets/' + iconset + '/'
@ -1161,19 +1162,18 @@ class Roster_window:
def on_show_offline_contacts_menuitem_activate(self, widget):
"""when show offline option is changed:
redraw the treeview"""
self.plugin.config['showoffline'] = 1 - self.plugin.config['showoffline']
self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config, 'GtkGui'))
gajim.config.set('showoffline', 1 - gajim.config.get('showoffline'))
self.draw_roster()
def iconCellDataFunc(self, column, renderer, model, iter, data=None):
"""When a row is added, set properties for icon renderer"""
if model.get_value(iter, 2) == 'account':
renderer.set_property('cell-background', \
self.plugin.config['accountbgcolor'])
gajim.config.get('accountbgcolor'))
renderer.set_property('xalign', 0)
elif model.get_value(iter, 2) == 'group':
renderer.set_property('cell-background', \
self.plugin.config['groupbgcolor'])
gajim.config.get('groupbgcolor'))
renderer.set_property('xalign', 0.5)
else:
jid = model.get_value(iter, 3)
@ -1184,7 +1184,7 @@ class Roster_window:
renderer.set_property('cell-background', '#ab6161')
else:
renderer.set_property('cell-background', \
self.plugin.config['userbgcolor'])
gajim.config.get('userbgcolor'))
renderer.set_property('xalign', 1)
renderer.set_property('width', 20)
@ -1192,31 +1192,31 @@ class Roster_window:
"""When a row is added, set properties for name renderer"""
if model.get_value(iter, 2) == 'account':
renderer.set_property('foreground', \
self.plugin.config['accounttextcolor'])
gajim.config.get('accounttextcolor'))
renderer.set_property('cell-background', \
self.plugin.config['accountbgcolor'])
renderer.set_property('font', self.plugin.config['accountfont'])
gajim.config.get('accountbgcolor'))
renderer.set_property('font', gajim.config.get('accountfont'))
renderer.set_property('xpad', 0)
elif model.get_value(iter, 2) == 'group':
renderer.set_property('foreground', \
self.plugin.config['grouptextcolor'])
gajim.config.get('grouptextcolor'))
renderer.set_property('cell-background', \
self.plugin.config['groupbgcolor'])
renderer.set_property('font', self.plugin.config['groupfont'])
gajim.config.get('groupbgcolor'))
renderer.set_property('font', gajim.config.get('groupfont'))
renderer.set_property('xpad', 4)
else:
jid = model.get_value(iter, 3)
account = model.get_value(iter, 4)
renderer.set_property('foreground', \
self.plugin.config['usertextcolor'])
gajim.config.get('usertextcolor'))
if jid in self.newly_added[account]:
renderer.set_property('cell-background', '#adc3c6')
elif jid in self.to_be_removed[account]:
renderer.set_property('cell-background', '#ab6161')
else:
renderer.set_property('cell-background', \
self.plugin.config['userbgcolor'])
renderer.set_property('font', self.plugin.config['userfont'])
gajim.config.get('userbgcolor'))
renderer.set_property('font', gajim.config.get('userfont'))
renderer.set_property('xpad', 8)
def compareIters(self, model, iter1, iter2, data = None):
@ -1249,7 +1249,7 @@ class Roster_window:
def drag_data_received_data(self, treeview, context, x, y, selection, info,
etime):
merge = 0
if self.plugin.config['mergeaccounts']:
if gajim.config.get('mergeaccounts'):
merge = 1
model = treeview.get_model()
data = selection.data
@ -1325,18 +1325,12 @@ class Roster_window:
self.join_gc_handler_id = False
self.new_message_menuitem_handler_id = False
self.regroup = 0
if self.plugin.config.has_key('mergeaccounts'):
self.regroup = self.plugin.config['mergeaccounts']
if self.plugin.config.has_key('saveposition'):
if self.plugin.config['saveposition']:
if self.plugin.config.has_key('x-position') and \
self.plugin.config.has_key('y-position'):
self.window.move(self.plugin.config['x-position'], \
self.plugin.config['y-position'])
if self.plugin.config.has_key('width') and \
self.plugin.config.has_key('height'):
self.window.resize(self.plugin.config['width'], \
self.plugin.config['height'])
self.regroup = gajim.config.get('mergeaccounts')
if gajim.config.get('saveposition'):
self.window.move(gajim.config.get('x-position'), \
gajim.config.get('y-position'))
self.window.resize(gajim.config.get('width'), \
gajim.config.get('height'))
self.window.show_all()
self.groups = {}
self.contacts = {}
@ -1380,7 +1374,7 @@ class Roster_window:
self.status_combobox.set_model(liststore)
self.status_combobox.set_active(5)
showOffline = self.plugin.config['showoffline']
showOffline = gajim.config.get('showoffline')
self.xml.get_widget('show_offline_contacts_menuitem').set_active(showOffline)
#columns
@ -1420,7 +1414,7 @@ class Roster_window:
self.id_signal_cb = self.status_combobox.connect('changed',\
self.on_status_combobox_changed)
self.hidden_lines = self.plugin.config['hiddenlines'].split('\t')
self.hidden_lines = gajim.config.get('hiddenlines').split('\t')
self.draw_roster()
if len(self.plugin.accounts) == 0: # if no account
self.plugin.windows['account_modification'] = \

View File

@ -28,7 +28,7 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Systray:
"""Class for icon in the systray"""

View File

@ -34,7 +34,7 @@ APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
GTKGUI_GLADE='gtkgui.glade'
class Tabbed_chat_window(Chat):
"""Class for tabbed chat window"""
@ -144,7 +144,7 @@ class Tabbed_chat_window(Chat):
if self.plugin.queues[self.account].has_key(user.jid):
self.read_queue(user.jid)
if self.plugin.config['print_time'] == 'sometimes':
if gajim.config.get('print_time') == 'sometimes':
self.print_time_timeout(user.jid)
self.print_time_timeout_id[user.jid] = gobject.timeout_add(300000, \
self.print_time_timeout, user.jid)
@ -211,7 +211,7 @@ class Tabbed_chat_window(Chat):
self.plugin.roster.redraw_jid(jid, self.account)
if self.plugin.systray_enabled:
self.plugin.systray.remove_jid(jid, self.account)
showOffline = self.plugin.config['showoffline']
showOffline = gajim.config.get('showoffline')
if (user.show == 'offline' or user.show == 'error') and \
not showOffline:
if len(self.plugin.roster.contacts[self.account][jid]) == 1: