gajim-plural/plugins/gtkgui/dialogs.py

429 lines
14 KiB
Python
Raw Normal View History

2004-05-15 18:50:38 +02:00
#!/usr/bin/env python
2004-05-15 18:52:07 +02:00
## plugins/dialogs.py
2004-05-15 18:50:38 +02:00
##
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
2004-06-18 11:25:15 +02:00
## - Vincent Hanquez <tab@snarc.org>
2004-05-15 18:50:38 +02:00
##
## Copyright (C) 2003 Gajim Team
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
import pygtk
pygtk.require('2.0')
import gtk
from gtk import TRUE, FALSE
import gtk.glade,gobject
import string
2004-05-17 01:47:14 +02:00
from common import i18n
_ = i18n._
APP = i18n.APP
gtk.glade.bindtextdomain (APP, i18n.DIR)
gtk.glade.textdomain (APP)
2004-05-15 18:50:38 +02:00
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
class infoUser_Window:
"""Class for user's information window"""
def delete_event(self, widget=None):
"""close window"""
del self.plugin.windows[self.account]['infos'][self.user.jid]
def add_grp_to_user(self, model, path, iter):
"""Insert user to the group in inter"""
self.user.groups.append(model.get_value(iter, 0))
def on_close(self, widget):
"""Save user's informations and update the roster on the Jabber server"""
#update: to know if things have changed to send things
# to server only if changes are done
update = 0
#update user.groups and redraw the user in the roster
old_groups = self.user.groups
self.user.groups = []
model = self.list2.get_model()
model.foreach(self.add_grp_to_user)
for g in old_groups:
if not g in self.user.groups:
update = 1
break
if not update:
for g in self.user.groups:
if not g in old_groups:
update = 1
break
if update:
new_groups = self.user.groups
self.user.groups = old_groups
self.plugin.roster.remove_user(self.user, self.account)
self.user.groups = new_groups
self.plugin.roster.add_user_to_roster(self.user.jid, self.account)
2004-05-15 18:50:38 +02:00
#update user.name if it's not ""
entry_name = self.xml.get_widget('entry_name')
newName = entry_name.get_text()
if newName != self.user.name and newName != '':
2004-05-15 18:50:38 +02:00
update = 1
self.user.name = newName
for i in self.plugin.roster.get_user_iter(self.user.jid, self.account):
self.plugin.roster.tree.get_model().set_value(i, 1, newName)
2004-05-15 18:50:38 +02:00
if update:
self.plugin.send('UPDUSER', self.account, (self.user.jid, \
self.user.name, self.user.groups))
#log history ?
acct = self.plugin.accounts[self.account]
oldlog = 1
no_log_for = []
if acct.has_key('no_log_for'):
no_log_for = acct['no_log_for'].split(' ')
if self.user.jid in no_log_for:
oldlog = 0
log = self.xml.get_widget('chk_log').get_active()
if not log and not self.user.jid in no_log_for:
no_log_for.append(self.user.jid)
if log and self.user.jid in no_log_for:
no_log_for.remove(self.user.jid)
if oldlog != log:
acct['no_log_for'] = string.join(no_log_for, ' ')
self.plugin.accounts[self.account] = acct
self.plugin.send('CONFIG', None, ('accounts', self.plugin.accounts, \
'Gtkgui'))
2004-05-15 18:50:38 +02:00
widget.get_toplevel().destroy()
def add_grp(self, model, path, iter, stors):
"""Transfert the iter from stors[0] to stors[1]"""
i = stors[1].append()
stors[1].set(i, 0, stors[0].get_value(iter, 0))
stors[0].remove(iter)
def on_add(self, widget):
"""When Add button is clicked"""
model = self.list1.get_model()
select = self.list1.get_selection()
select.selected_foreach(self.add_grp, (model, self.list2.get_model()))
def on_remove(self, widget):
"""When Remove button is clicked"""
model = self.list2.get_model()
select = self.list2.get_selection()
select.selected_foreach(self.add_grp, (model, self.list1.get_model()))
def on_new_key_pressed(self, widget, event):
"""If enter is pressed in new group entry, add the group"""
if event.keyval == gtk.keysyms.Return:
entry_new = self.xml.get_widget("entry_new")
model = self.list1.get_model()
txt = entry_new.get_text()
iter = model.append()
model.set(iter, 0, txt)
entry_new.set_text('')
return 1
else:
return 0
def set_value(self, entry_name, value):
try:
self.xml.get_widget(entry_name).set_text(value)
except AttributeError, e:
pass
def set_values(self, vcard):
for i in vcard.keys():
if type(vcard[i]) == type({}):
for j in vcard[i].keys():
self.set_value('entry_'+i+'_'+j, vcard[i][j])
else:
if i == 'DESC':
self.xml.get_widget('textview_DESC').get_buffer().\
set_text(vcard[i], 0)
else:
self.set_value('entry_'+i, vcard[i])
def init_lists(self):
"""Initialize both available and current listStores"""
#list available
store = gtk.ListStore(gobject.TYPE_STRING)
for g in self.plugin.roster.groups[self.account].keys():
if g != 'Agents' and g not in self.user.groups:
iter = store.append()
store.set(iter, 0, g)
self.list1.set_model(store)
column = gtk.TreeViewColumn('Available', gtk.CellRendererText(), text=0)
self.list1.append_column(column)
#list_current
store = gtk.ListStore(gobject.TYPE_STRING)
for g in self.user.groups:
iter = store.append()
store.set(iter, 0, g)
self.list2.set_model(store)
column = gtk.TreeViewColumn('Available', gtk.CellRendererText(), text=0)
self.list2.append_column(column)
def __init__(self, user, plugin, account):
2004-05-17 01:47:14 +02:00
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Info_user', APP)
self.window = self.xml.get_widget("Info_user")
2004-05-15 18:50:38 +02:00
self.plugin = plugin
self.user = user
self.account = account
self.list1 = self.xml.get_widget("treeview_available")
self.list2 = self.xml.get_widget("treeview_current")
self.xml.get_widget('label_name').set_text(user.name)
self.xml.get_widget('label_id').set_text(user.jid)
self.xml.get_widget('label_sub').set_text(user.sub)
if user.ask:
self.xml.get_widget('label_ask').set_text(user.ask)
else:
self.xml.get_widget('label_ask').set_text('None')
2004-05-15 18:50:38 +02:00
self.xml.get_widget('entry_name').set_text(user.name)
acct = self.plugin.accounts[account]
log = 1
if acct.has_key('no_log_for'):
if user.jid in acct['no_log_for'].split(' '):
log = 0
self.xml.get_widget('chk_log').set_active(log)
2004-06-09 22:40:52 +02:00
resources = user.resource + ' (' + str(user.priority) + ')'
2004-05-15 18:50:38 +02:00
if not user.status:
user.status = ''
stats = user.show + ' : ' + user.status
for u in self.plugin.roster.contacts[account][user.jid]:
if u.resource != user.resource:
2004-06-09 22:40:52 +02:00
resources += '\n' + u.resource + ' (' + str(u.priority) + ')'
if not u.status:
u.status = ''
stats += '\n' + u.show + ' : ' + u.status
self.xml.get_widget('label_resource').set_text(resources)
self.xml.get_widget('label_status').set_text(stats)
2004-05-15 18:50:38 +02:00
self.init_lists()
plugin.send('ASK_VCARD', account, self.user.jid)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_close_clicked', self.on_close)
self.xml.signal_connect('on_add_clicked', self.on_add)
self.xml.signal_connect('on_remove_clicked', self.on_remove)
self.xml.signal_connect('on_entry_new_key_press_event', \
self.on_new_key_pressed)
2004-10-07 16:43:59 +02:00
class passphrase_Window:
"""Class for Passphrase Window"""
def run(self):
"""Wait for Ok button to be pressed and return passphrase"""
rep = self.xml.get_widget("Passphrase").run()
if rep == gtk.RESPONSE_OK:
msg = self.entry.get_text()
else:
msg = -1
self.xml.get_widget("Passphrase").destroy()
return msg
def on_key_pressed(self, widget, event):
if event.keyval == gtk.keysyms.Return:
self.xml.get_widget("Passphrase").response(gtk.RESPONSE_OK)
def __init__(self, txt):
2004-10-07 16:43:59 +02:00
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Passphrase', APP)
self.entry = self.xml.get_widget("entry")
self.xml.get_widget("label").set_text(txt)
2004-10-07 16:43:59 +02:00
self.xml.signal_connect('on_Passphrase_key_press_event', \
self.on_key_pressed)
2004-05-15 18:50:38 +02:00
class choose_gpg_Window:
"""Class for Away Message Window"""
def run(self):
"""Wait for Ok button to be pressed and return the selected key"""
rep = self.xml.get_widget("Choose_gpg_key").run()
if rep == gtk.RESPONSE_OK:
selection = self.treeview.get_selection()
(model, iter) = selection.get_selected()
keyID = [model.get_value(iter, 0), model.get_value(iter, 1)]
else:
keyID = -1
self.xml.get_widget("Choose_gpg_key").destroy()
return keyID
def fill_tree(self, list):
model = self.treeview.get_model()
for keyID in list.keys():
model.append((keyID, list[keyID]))
def __init__(self):
#list : {keyID: userName, ...}
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Choose_gpg_key', APP)
self.window = self.xml.get_widget("Choose_gpg_key")
self.treeview = self.xml.get_widget("treeview")
model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.treeview.set_model(model)
#columns
renderer = gtk.CellRendererText()
self.treeview.insert_column_with_attributes(-1, _('KeyID'), renderer, \
text=0)
renderer = gtk.CellRendererText()
self.treeview.insert_column_with_attributes(-1, _('User name'), renderer,\
text=1)
2004-05-15 18:50:38 +02:00
class awayMsg_Window:
"""Class for Away Message Window"""
def on_ok(self):
"""When Ok button is clicked"""
beg, end = self.txtBuffer.get_bounds()
self.msg = self.txtBuffer.get_text(beg, end, 0)
self.xml.get_widget("Away_msg").destroy()
def run(self):
"""Wait for Ok button to be pressed and return away messsage"""
rep = self.xml.get_widget("Away_msg").run()
if rep == gtk.RESPONSE_OK:
beg, end = self.txtBuffer.get_bounds()
msg = self.txtBuffer.get_text(beg, end, 0)
self.plugin.config['last_msg'] = msg
2004-05-15 18:50:38 +02:00
else:
msg = -1
self.xml.get_widget("Away_msg").destroy()
return msg
def on_entry_changed(self, widget, data=None):
model = widget.get_model()
active = widget.get_active()
if active < 0:
return None
name = model[active][0]
self.txtBuffer.set_text(self.values[name])
2004-05-15 18:50:38 +02:00
def __init__(self, plugin):
2004-05-17 01:47:14 +02:00
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Away_msg', APP)
self.plugin = plugin
2004-05-15 18:50:38 +02:00
txt = self.xml.get_widget("textview")
self.txtBuffer = txt.get_buffer()
self.txtBuffer.set_text(self.plugin.config['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]
i += 1
liststore = gtk.ListStore(str, str)
cb = self.xml.get_widget('comboboxentry')
cb.set_model(liststore)
cb.set_text_column(0)
for val in self.values.keys():
cb.append_text(val)
self.xml.signal_connect('on_comboboxentry_changed', self.on_entry_changed)
2004-05-15 18:50:38 +02:00
class addContact_Window:
"""Class for Add user window"""
def delete_event(self, widget):
"""close window"""
del self.plugin.windows['add']
def on_cancel(self, widget):
"""When Cancel button is clicked"""
widget.get_toplevel().destroy()
def on_subscribe(self, widget):
"""When Subscribe button is clicked"""
textview_sub = self.xml.get_widget("textview_sub")
entry_who = self.xml.get_widget('entry_who')
who = entry_who.get_text()
2004-11-18 20:22:33 +01:00
if not who:
return
if who.find('@') < 0:
warning_Window(_("The contact's name must be something like login@hostname"))
return
2004-05-15 18:50:38 +02:00
buf = textview_sub.get_buffer()
start_iter = buf.get_start_iter()
end_iter = buf.get_end_iter()
txt = buf.get_text(start_iter, end_iter, 0)
self.plugin.roster.req_sub(self, who, txt, self.account)
widget.get_toplevel().destroy()
def __init__(self, plugin, account, jid=None):
self.plugin = plugin
self.account = account
2004-05-17 01:47:14 +02:00
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Add', APP)
self.window = self.xml.get_widget('Add')
2004-05-15 18:50:38 +02:00
if jid:
self.xml.get_widget('entry_who').set_text(jid)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_button_sub_clicked', self.on_subscribe)
self.xml.signal_connect('on_cancel_clicked', self.on_cancel)
class warning_Window:
"""Class for warning window : print a warning message"""
def on_close(self, widget):
"""When Close button is clicked"""
widget.get_toplevel().destroy()
def __init__(self, txt):
2004-05-17 01:47:14 +02:00
xml = gtk.glade.XML(GTKGUI_GLADE, 'Warning', APP)
xml.get_widget('label').set_text(txt)
2004-05-15 18:50:38 +02:00
xml.signal_connect('on_close_clicked', self.on_close)
class about_Window:
"""Class for about window"""
def delete_event(self, widget):
"""close window"""
del self.plugin.windows['about']
def on_close(self, widget):
"""When Close button is clicked"""
widget.get_toplevel().destroy()
def __init__(self, plugin):
2004-05-17 01:47:14 +02:00
xml = gtk.glade.XML(GTKGUI_GLADE, 'About', APP)
self.window = xml.get_widget('About')
2004-05-15 18:50:38 +02:00
self.plugin = plugin
xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_close_clicked', self.on_close)
class confirm_Window:
"""Class for confirmation window"""
def wait(self):
out = self.win.run()
self.win.destroy()
return out
def __init__(self, label):
2004-05-17 01:47:14 +02:00
xml = gtk.glade.XML(GTKGUI_GLADE, 'Confirm', APP)
2004-05-15 18:50:38 +02:00
xml.get_widget('label_confirm').set_text(label)
self.win = xml.get_widget('Confirm')
class authorize_Window:
"""Class for authorization window :
window that appears when a user wants to add us to his/her roster"""
def on_close(self, widget):
"""When Close button is clicked"""
widget.get_toplevel().destroy()
def auth(self, widget):
"""Accept the request"""
self.plugin.send('AUTH', self.account, self.jid)
widget.get_toplevel().destroy()
if not self.plugin.roster.contacts[self.account].has_key(self.jid):
addContact_Window(self.plugin, self.account, self.jid)
def deny(self, widget):
"""refuse the request"""
self.plugin.send('DENY', self.account, self.jid)
widget.get_toplevel().destroy()
def __init__(self, plugin, jid, txt, account):
2004-05-17 01:47:14 +02:00
xml = gtk.glade.XML(GTKGUI_GLADE, 'Sub_req', APP)
2004-05-15 18:50:38 +02:00
self.plugin = plugin
self.jid = jid
self.account = account
2004-05-17 01:47:14 +02:00
xml.get_widget('label').set_text(_("Subscription request from %s") % self.jid)
2004-05-15 18:50:38 +02:00
xml.get_widget("textview").get_buffer().set_text(txt)
xml.signal_connect('on_button_auth_clicked', self.auth)
xml.signal_connect('on_button_deny_clicked', self.deny)
xml.signal_connect('on_button_close_clicked', self.on_close)