2006-03-15 13:59:01 +01:00
# -*- coding: utf-8 -*-
2008-08-15 05:20:23 +02:00
## src/dialogs.py
2004-05-15 18:50:38 +02:00
##
2008-08-15 05:20:23 +02:00
## Copyright (C) 2003-2005 Vincent Hanquez <tab AT snarc.org>
## Copyright (C) 2003-2008 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2005 Alex Mauer <hawke AT hawkesnest.net>
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
## Travis Shirk <travis AT pobox.com>
## Copyright (C) 2005-2008 Nikos Kouremenos <kourem AT gmail.com>
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
## Julien Pivotto <roidelapluie AT gmail.com>
## Stephan Erb <steve-e AT h3c.de>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
2004-05-15 18:50:38 +02:00
##
2007-12-12 09:44:46 +01:00
## This file is part of Gajim.
##
## Gajim is free software; you can redistribute it and/or modify
2004-05-15 18:50:38 +02:00
## it under the terms of the GNU General Public License as published
2007-12-12 09:44:46 +01:00
## by the Free Software Foundation; version 3 only.
2004-05-15 18:50:38 +02:00
##
2007-12-12 09:44:46 +01:00
## Gajim is distributed in the hope that it will be useful,
2004-05-15 18:50:38 +02:00
## but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-08-15 05:20:23 +02:00
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2004-05-15 18:50:38 +02:00
## GNU General Public License for more details.
##
2007-12-12 09:44:46 +01:00
## You should have received a copy of the GNU General Public License
2008-08-15 05:20:23 +02:00
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
2007-12-12 09:44:46 +01:00
##
2004-05-15 18:50:38 +02:00
import gtk
2005-03-01 14:46:22 +01:00
import gobject
2005-05-17 19:37:50 +02:00
import os
2009-09-25 19:32:13 +02:00
from weakref import WeakValueDictionary
2005-05-20 17:58:23 +02:00
2005-07-21 23:42:53 +02:00
import gtkgui_helpers
2005-11-13 21:25:04 +01:00
import vcard
2005-12-12 10:12:29 +01:00
import conversation_textview
2006-11-18 21:52:28 +01:00
import message_control
2007-12-12 09:44:46 +01:00
import dataforms_widget
from random import randrange
2008-07-23 00:20:51 +02:00
from common import pep
2005-07-21 23:39:47 +02:00
2005-11-30 23:22:22 +01:00
try :
import gtkspell
HAS_GTK_SPELL = True
2009-02-12 23:15:18 +01:00
except ImportError :
2005-11-30 23:22:22 +01:00
HAS_GTK_SPELL = False
2006-03-24 19:49:47 +01:00
# those imports are not used in this file, but in files that 'import dialogs'
2006-03-24 19:48:26 +01:00
# so they can do dialog.GajimThemesWindow() for example
2005-08-15 01:52:12 +02:00
from filetransfers_window import FileTransfersWindow
2005-06-10 00:29:06 +02:00
from gajim_themes_window import GajimThemesWindow
2009-10-17 20:28:38 +02:00
from advanced_configuration_window import AdvancedConfigurationWindow
2006-03-24 19:48:26 +01:00
2005-04-14 09:05:10 +02:00
from common import gajim
2005-06-06 13:53:07 +02:00
from common import helpers
2007-12-12 09:44:46 +01:00
from common import dataforms
2006-11-18 21:52:28 +01:00
from common . exceptions import GajimGeneralException
2004-05-15 18:50:38 +02:00
2005-06-10 23:14:16 +02:00
class EditGroupsDialog :
2005-04-18 14:17:43 +02:00
''' Class for the edit group dialog window '''
2006-09-13 18:47:58 +02:00
def __init__ ( self , list_ ) :
''' list_ is a list of (contact, account) tuples '''
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' edit_groups_dialog.glade ' )
2005-03-17 18:41:09 +01:00
self . dialog = self . xml . get_widget ( ' edit_groups_dialog ' )
2006-09-13 18:47:58 +02:00
self . dialog . set_transient_for ( gajim . interface . roster . window )
self . list_ = list_
2005-04-17 23:31:18 +02:00
self . changes_made = False
2008-10-12 22:32:24 +02:00
self . treeview = self . xml . get_widget ( ' groups_treeview ' )
2006-09-13 18:47:58 +02:00
if len ( list_ ) == 1 :
contact = list_ [ 0 ] [ 0 ]
self . xml . get_widget ( ' nickname_label ' ) . set_markup (
2007-06-03 12:04:20 +02:00
_ ( ' Contact name: <i> %s </i> ' ) % contact . get_shown_name ( ) )
2006-09-13 18:47:58 +02:00
self . xml . get_widget ( ' jid_label ' ) . set_markup (
2006-11-21 01:26:51 +01:00
_ ( ' Jabber ID: <i> %s </i> ' ) % contact . jid )
2006-09-13 18:47:58 +02:00
else :
self . xml . get_widget ( ' nickname_label ' ) . set_no_show_all ( True )
self . xml . get_widget ( ' nickname_label ' ) . hide ( )
self . xml . get_widget ( ' jid_label ' ) . set_no_show_all ( True )
self . xml . get_widget ( ' jid_label ' ) . hide ( )
2005-03-17 18:41:09 +01:00
self . xml . signal_autoconnect ( self )
self . init_list ( )
2005-07-23 00:32:45 +02:00
self . dialog . show_all ( )
2005-04-17 23:31:18 +02:00
if self . changes_made :
2006-09-13 18:47:58 +02:00
for ( contact , account ) in self . list_ :
gajim . connections [ account ] . update_contact ( contact . jid , contact . name ,
2009-06-21 21:27:51 +02:00
contact . groups )
2005-03-17 18:41:09 +01:00
2005-07-23 00:32:45 +02:00
def on_edit_groups_dialog_response ( self , widget , response_id ) :
if response_id == gtk . RESPONSE_CLOSE :
self . dialog . destroy ( )
2006-03-29 22:26:20 +02:00
def remove_group ( self , group ) :
2006-09-13 18:47:58 +02:00
''' remove group group from all contacts and all their brothers '''
for ( contact , account ) in self . list_ :
2008-04-20 16:01:04 +02:00
gajim . interface . roster . remove_contact_from_groups ( contact . jid , account , [ group ] )
# FIXME: Ugly workaround.
gajim . interface . roster . draw_group ( _ ( ' General ' ) , account )
2006-03-29 22:26:20 +02:00
def add_group ( self , group ) :
2006-09-13 18:47:58 +02:00
''' add group group to all contacts and all their brothers '''
for ( contact , account ) in self . list_ :
2008-04-20 16:01:04 +02:00
gajim . interface . roster . add_contact_to_groups ( contact . jid , account , [ group ] )
2008-12-03 22:56:12 +01:00
2008-04-20 16:01:04 +02:00
# FIXME: Ugly workaround. Maybe we haven't been in any group (defaults to General)
gajim . interface . roster . draw_group ( _ ( ' General ' ) , account )
2005-03-17 18:41:09 +01:00
def on_add_button_clicked ( self , widget ) :
2005-08-26 02:52:44 +02:00
group = self . xml . get_widget ( ' group_entry ' ) . get_text ( ) . decode ( ' utf-8 ' )
2005-03-17 18:41:09 +01:00
if not group :
return
2006-11-18 21:52:28 +01:00
# Do not allow special groups
if group in helpers . special_groups :
return
2005-03-17 18:41:09 +01:00
# check if it already exists
2008-10-12 22:32:24 +02:00
model = self . treeview . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = model . get_iter_root ( )
while iter_ :
if model . get_value ( iter_ , 0 ) . decode ( ' utf-8 ' ) == group :
2005-03-17 18:41:09 +01:00
return
2008-12-03 18:16:04 +01:00
iter_ = model . iter_next ( iter_ )
2005-05-23 19:21:05 +02:00
self . changes_made = True
2006-09-13 18:47:58 +02:00
model . append ( ( group , True , False ) )
2006-03-29 22:26:20 +02:00
self . add_group ( group )
2006-05-14 18:19:04 +02:00
self . init_list ( ) # Re-draw list to sort new item
2005-03-17 18:41:09 +01:00
def group_toggled_cb ( self , cell , path ) :
2005-04-17 23:31:18 +02:00
self . changes_made = True
2008-10-12 22:32:24 +02:00
model = self . treeview . get_model ( )
2006-09-13 18:47:58 +02:00
if model [ path ] [ 2 ] :
model [ path ] [ 2 ] = False
model [ path ] [ 1 ] = True
else :
model [ path ] [ 1 ] = not model [ path ] [ 1 ]
2006-03-29 22:26:20 +02:00
group = model [ path ] [ 0 ] . decode ( ' utf-8 ' )
if model [ path ] [ 1 ] :
self . add_group ( group )
else :
self . remove_group ( group )
2005-03-17 18:41:09 +01:00
def init_list ( self ) :
2006-09-13 18:47:58 +02:00
store = gtk . ListStore ( str , bool , bool )
2008-10-12 22:32:24 +02:00
self . treeview . set_model ( store )
for column in self . treeview . get_columns ( ) :
# Clear treeview when re-drawing
self . treeview . remove_column ( column )
2006-09-13 18:47:58 +02:00
accounts = [ ]
# Store groups in a list so we can sort them and the number of contacts in
# it
groups = { }
for ( contact , account ) in self . list_ :
if account not in accounts :
accounts . append ( account )
for g in gajim . groups [ account ] . keys ( ) :
if g in groups :
continue
groups [ g ] = 0
2008-04-20 16:01:04 +02:00
c_groups = contact . groups
for g in c_groups :
2006-09-13 18:47:58 +02:00
groups [ g ] + = 1
2006-11-18 21:52:28 +01:00
group_list = [ ]
# Remove special groups if they are empty
for group in groups :
if group not in helpers . special_groups or groups [ group ] > 0 :
group_list . append ( group )
2008-01-22 17:06:16 +01:00
group_list . sort ( )
2006-09-13 18:47:58 +02:00
for group in group_list :
2008-12-03 18:16:04 +01:00
iter_ = store . append ( )
store . set ( iter_ , 0 , group ) # Group name
2006-09-13 18:47:58 +02:00
if groups [ group ] == 0 :
2008-12-03 18:16:04 +01:00
store . set ( iter_ , 1 , False )
2006-09-13 18:47:58 +02:00
else :
2008-12-03 18:16:04 +01:00
store . set ( iter_ , 1 , True )
2006-09-13 18:47:58 +02:00
if groups [ group ] == len ( self . list_ ) :
# all contacts are in this group
2008-12-03 18:16:04 +01:00
store . set ( iter_ , 2 , False )
2006-09-13 18:47:58 +02:00
else :
2008-12-03 18:16:04 +01:00
store . set ( iter_ , 2 , True )
2005-03-17 18:41:09 +01:00
column = gtk . TreeViewColumn ( _ ( ' Group ' ) )
2005-08-29 02:01:43 +02:00
column . set_expand ( True )
2008-10-12 22:32:24 +02:00
self . treeview . append_column ( column )
2005-03-17 18:41:09 +01:00
renderer = gtk . CellRendererText ( )
column . pack_start ( renderer )
2008-09-03 13:25:27 +02:00
column . set_attributes ( renderer , text = 0 )
2007-01-15 11:34:53 +01:00
2005-03-17 18:41:09 +01:00
column = gtk . TreeViewColumn ( _ ( ' In the group ' ) )
2005-08-29 02:01:43 +02:00
column . set_expand ( False )
2008-10-12 22:32:24 +02:00
self . treeview . append_column ( column )
2005-03-17 18:41:09 +01:00
renderer = gtk . CellRendererToggle ( )
column . pack_start ( renderer )
renderer . set_property ( ' activatable ' , True )
renderer . connect ( ' toggled ' , self . group_toggled_cb )
2008-09-03 13:25:27 +02:00
column . set_attributes ( renderer , active = 1 , inconsistent = 2 )
2005-03-17 18:41:09 +01:00
2005-06-10 23:14:16 +02:00
class PassphraseDialog :
2005-04-18 14:17:43 +02:00
''' Class for Passphrase dialog '''
2008-07-31 08:14:48 +02:00
def __init__ ( self , titletext , labeltext , checkbuttontext = None ,
2009-06-21 21:27:51 +02:00
ok_handler = None , cancel_handler = None ) :
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' passphrase_dialog.glade ' )
2005-03-02 11:46:12 +01:00
self . window = self . xml . get_widget ( ' passphrase_dialog ' )
self . passphrase_entry = self . xml . get_widget ( ' passphrase_entry ' )
self . passphrase = - 1
2005-06-03 12:28:53 +02:00
self . window . set_title ( titletext )
2005-03-02 13:38:33 +01:00
self . xml . get_widget ( ' message_label ' ) . set_text ( labeltext )
2007-12-12 09:44:46 +01:00
self . ok = False
self . cancel_handler = cancel_handler
2008-07-31 08:14:48 +02:00
self . ok_handler = ok_handler
okbutton = self . xml . get_widget ( ' ok_button ' )
okbutton . connect ( ' clicked ' , self . on_okbutton_clicked )
cancelbutton = self . xml . get_widget ( ' cancel_button ' )
cancelbutton . connect ( ' clicked ' , self . on_cancelbutton_clicked )
2007-12-12 09:44:46 +01:00
2005-03-02 11:46:12 +01:00
self . xml . signal_autoconnect ( self )
2009-04-05 20:35:59 +02:00
self . window . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
2005-04-04 17:51:29 +02:00
self . window . show_all ( )
2008-01-22 17:06:16 +01:00
2007-12-12 09:44:46 +01:00
self . check = bool ( checkbuttontext )
checkbutton = self . xml . get_widget ( ' save_passphrase_checkbutton ' )
if self . check :
checkbutton . set_label ( checkbuttontext )
else :
checkbutton . hide ( )
2008-01-22 17:06:16 +01:00
2007-12-12 09:44:46 +01:00
def on_okbutton_clicked ( self , widget ) :
2008-07-31 08:14:48 +02:00
if not self . ok_handler :
return
2007-12-12 09:44:46 +01:00
passph = self . passphrase_entry . get_text ( ) . decode ( ' utf-8 ' )
if self . check :
checked = self . xml . get_widget ( ' save_passphrase_checkbutton ' ) . \
2009-06-21 21:27:51 +02:00
get_active ( )
2007-12-12 09:44:46 +01:00
else :
checked = False
self . ok = True
self . window . destroy ( )
if isinstance ( self . ok_handler , tuple ) :
self . ok_handler [ 0 ] ( passph , checked , * self . ok_handler [ 1 : ] )
else :
self . ok_handler ( passph , checked )
def on_cancelbutton_clicked ( self , widget ) :
self . window . destroy ( )
def on_passphrase_dialog_destroy ( self , widget ) :
if self . cancel_handler and not self . ok :
self . cancel_handler ( )
2004-05-15 18:50:38 +02:00
2005-06-08 15:45:30 +02:00
class ChooseGPGKeyDialog :
2005-04-18 14:17:43 +02:00
''' Class for GPG key dialog '''
2008-08-08 12:26:11 +02:00
def __init__ ( self , title_text , prompt_text , secret_keys , on_response ,
2009-06-21 03:43:57 +02:00
selected = None ) :
2008-08-08 12:26:11 +02:00
''' secret_keys : { keyID: userName, ...} '''
self . on_response = on_response
2006-05-02 17:53:25 +02:00
xml = gtkgui_helpers . get_glade ( ' choose_gpg_key_dialog.glade ' )
2005-03-02 12:46:51 +01:00
self . window = xml . get_widget ( ' choose_gpg_key_dialog ' )
2005-06-08 15:45:30 +02:00
self . window . set_title ( title_text )
2005-03-02 12:46:51 +01:00
self . keys_treeview = xml . get_widget ( ' keys_treeview ' )
2005-06-08 15:45:30 +02:00
prompt_label = xml . get_widget ( ' prompt_label ' )
prompt_label . set_text ( prompt_text )
2005-06-18 15:48:43 +02:00
model = gtk . ListStore ( str , str )
2006-09-13 18:47:58 +02:00
model . set_sort_func ( 1 , self . sort_keys )
2005-10-22 10:52:13 +02:00
model . set_sort_column_id ( 1 , gtk . SORT_ASCENDING )
2005-03-02 12:46:51 +01:00
self . keys_treeview . set_model ( model )
2004-10-10 20:44:38 +02:00
#columns
renderer = gtk . CellRendererText ( )
2007-12-12 09:44:46 +01:00
col = self . keys_treeview . insert_column_with_attributes ( - 1 , _ ( ' KeyID ' ) ,
2009-06-21 21:27:51 +02:00
renderer , text = 0 )
2007-12-12 09:44:46 +01:00
col . set_sort_column_id ( 0 )
2004-10-10 20:44:38 +02:00
renderer = gtk . CellRendererText ( )
2007-12-12 09:44:46 +01:00
col = self . keys_treeview . insert_column_with_attributes ( - 1 ,
2009-06-21 21:27:51 +02:00
_ ( ' Contact name ' ) , renderer , text = 1 )
2007-12-12 09:44:46 +01:00
col . set_sort_column_id ( 1 )
2006-11-18 21:52:28 +01:00
self . keys_treeview . set_search_column ( 1 )
2005-05-29 23:34:01 +02:00
self . fill_tree ( secret_keys , selected )
2008-08-08 12:26:11 +02:00
self . window . connect ( ' response ' , self . on_dialog_response )
2009-04-05 20:35:59 +02:00
self . window . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
2005-04-04 17:51:29 +02:00
self . window . show_all ( )
2006-09-13 18:47:58 +02:00
def sort_keys ( self , model , iter1 , iter2 ) :
value1 = model [ iter1 ] [ 1 ]
value2 = model [ iter2 ] [ 1 ]
if value1 == _ ( ' None ' ) :
return - 1
elif value2 == _ ( ' None ' ) :
return 1
elif value1 < value2 :
return - 1
return 1
2008-08-08 12:26:11 +02:00
def on_dialog_response ( self , dialog , response ) :
2007-12-28 16:13:41 +01:00
selection = self . keys_treeview . get_selection ( )
2008-12-03 18:16:04 +01:00
( model , iter_ ) = selection . get_selected ( )
if iter_ and response == gtk . RESPONSE_OK :
keyID = [ model [ iter_ ] [ 0 ] . decode ( ' utf-8 ' ) ,
2009-06-21 21:27:51 +02:00
model [ iter_ ] [ 1 ] . decode ( ' utf-8 ' ) ]
2005-08-02 18:27:25 +02:00
else :
keyID = None
2008-08-08 12:26:11 +02:00
self . on_response ( keyID )
2005-07-23 00:49:03 +02:00
self . window . destroy ( )
2005-08-02 18:27:25 +02:00
2008-10-11 12:22:04 +02:00
def fill_tree ( self , list_ , selected ) :
2005-07-23 00:49:03 +02:00
model = self . keys_treeview . get_model ( )
2008-10-11 12:22:04 +02:00
for keyID in list_ . keys ( ) :
iter_ = model . append ( ( keyID , list_ [ keyID ] ) )
2005-07-23 00:49:03 +02:00
if keyID == selected :
2008-10-11 12:22:04 +02:00
path = model . get_path ( iter_ )
2005-07-23 00:49:03 +02:00
self . keys_treeview . set_cursor ( path )
2007-03-31 11:09:16 +02:00
class ChangeActivityDialog :
2008-10-24 19:18:10 +02:00
PAGELIST = [ ' doing_chores ' , ' drinking ' , ' eating ' , ' exercising ' , ' grooming ' ,
2009-06-21 21:27:51 +02:00
' having_appointment ' , ' inactive ' , ' relaxing ' , ' talking ' , ' traveling ' ,
' working ' ]
2008-07-28 22:57:56 +02:00
2009-04-12 20:13:37 +02:00
def __init__ ( self , on_response , activity = None , subactivity = None , text = ' ' ) :
self . on_response = on_response
self . activity = activity
self . subactivity = subactivity
self . text = text
2008-07-28 22:57:56 +02:00
self . xml = gtkgui_helpers . get_glade (
' change_activity_dialog.glade ' )
2007-03-31 11:09:16 +02:00
self . window = self . xml . get_widget ( ' change_activity_dialog ' )
self . window . set_transient_for ( gajim . interface . roster . window )
2008-07-28 22:57:56 +02:00
self . checkbutton = self . xml . get_widget ( ' enable_checkbutton ' )
self . notebook = self . xml . get_widget ( ' notebook ' )
2008-04-04 00:50:03 +02:00
self . entry = self . xml . get_widget ( ' description_entry ' )
2007-03-31 11:09:16 +02:00
2008-07-28 22:57:56 +02:00
rbtns = { }
group = None
2008-08-14 16:49:03 +02:00
2008-07-28 22:57:56 +02:00
for category in pep . ACTIVITIES :
item = self . xml . get_widget ( category + ' _image ' )
item . set_from_pixbuf (
2008-07-29 21:42:31 +02:00
gtkgui_helpers . load_activity_icon ( category ) . get_pixbuf ( ) )
2009-10-29 11:35:22 +01:00
item . set_tooltip_text ( pep . ACTIVITIES [ category ] [ ' category ' ] )
2007-03-31 11:09:16 +02:00
2008-07-28 22:57:56 +02:00
vbox = self . xml . get_widget ( category + ' _vbox ' )
2008-08-05 02:51:08 +02:00
vbox . set_border_width ( 5 )
# Other
act = category + ' _other '
if group :
rbtns [ act ] = gtk . RadioButton ( group )
else :
rbtns [ act ] = group = gtk . RadioButton ( )
2008-10-22 16:21:57 +02:00
hbox = gtk . HBox ( False , 5 )
2009-06-21 21:27:51 +02:00
hbox . pack_start ( gtkgui_helpers . load_activity_icon ( category ) , False ,
False , 0 )
2008-08-05 02:51:08 +02:00
lbl = gtk . Label ( ' <b> ' + pep . ACTIVITIES [ category ] [ ' category ' ] + ' </b> ' )
lbl . set_use_markup ( True )
2008-10-22 16:21:57 +02:00
hbox . pack_start ( lbl , False , False , 0 )
rbtns [ act ] . add ( hbox )
2008-08-05 02:51:08 +02:00
rbtns [ act ] . connect ( ' toggled ' , self . on_rbtn_toggled ,
2009-06-21 21:27:51 +02:00
[ category , ' other ' ] )
2008-08-05 02:51:08 +02:00
vbox . pack_start ( rbtns [ act ] , False , False , 0 )
2008-08-14 16:49:03 +02:00
activities = [ ]
2008-07-28 22:57:56 +02:00
for activity in pep . ACTIVITIES [ category ] :
2008-08-14 16:49:03 +02:00
activities . append ( activity )
activities . sort ( )
for activity in activities :
2008-07-29 00:33:20 +02:00
if activity == ' category ' :
continue
2008-07-28 22:57:56 +02:00
act = category + ' _ ' + activity
2007-03-31 11:09:16 +02:00
2008-07-28 22:57:56 +02:00
if group :
rbtns [ act ] = gtk . RadioButton ( group )
else :
rbtns [ act ] = group = gtk . RadioButton ( )
2007-03-31 11:09:16 +02:00
2008-10-22 16:21:57 +02:00
hbox = gtk . HBox ( False , 5 )
hbox . pack_start ( gtkgui_helpers . load_activity_icon ( category ,
2009-06-21 21:27:51 +02:00
activity ) , False , False , 0 )
2008-10-22 16:21:57 +02:00
hbox . pack_start ( gtk . Label ( pep . ACTIVITIES [ category ] [ activity ] ) ,
2009-06-21 21:27:51 +02:00
False , False , 0 )
2008-07-29 21:42:31 +02:00
rbtns [ act ] . connect ( ' toggled ' , self . on_rbtn_toggled ,
2009-06-21 21:27:51 +02:00
[ category , activity ] )
2008-10-22 16:21:57 +02:00
rbtns [ act ] . add ( hbox )
2008-07-28 22:57:56 +02:00
vbox . pack_start ( rbtns [ act ] , False , False , 0 )
2007-03-31 11:09:16 +02:00
2008-07-28 22:57:56 +02:00
2009-04-12 20:13:37 +02:00
if self . activity in pep . ACTIVITIES :
if not self . subactivity in pep . ACTIVITIES [ self . activity ] :
self . subactivity = ' other '
2008-07-28 22:57:56 +02:00
2009-04-12 20:13:37 +02:00
rbtns [ self . activity + ' _ ' + self . subactivity ] . set_active ( True )
2008-07-28 22:57:56 +02:00
self . checkbutton . set_active ( True )
self . notebook . set_sensitive ( True )
self . entry . set_sensitive ( True )
self . notebook . set_current_page (
2009-04-12 20:13:37 +02:00
self . PAGELIST . index ( self . activity ) )
self . entry . set_text ( text )
2008-05-31 00:39:01 +02:00
2009-04-12 20:13:37 +02:00
else :
self . checkbutton . set_active ( False )
2008-05-31 00:39:01 +02:00
2007-03-31 11:09:16 +02:00
self . xml . signal_autoconnect ( self )
2009-04-05 20:35:59 +02:00
self . window . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
2007-03-31 11:09:16 +02:00
self . window . show_all ( )
2008-07-28 22:57:56 +02:00
def on_enable_checkbutton_toggled ( self , widget ) :
self . notebook . set_sensitive ( widget . get_active ( ) )
self . entry . set_sensitive ( widget . get_active ( ) )
2008-05-31 00:39:01 +02:00
2008-07-28 22:57:56 +02:00
def on_rbtn_toggled ( self , widget , data ) :
if widget . get_active ( ) :
self . activity = data [ 0 ]
self . subactivity = data [ 1 ]
2008-04-07 13:17:33 +02:00
2007-03-31 11:09:16 +02:00
def on_ok_button_clicked ( self , widget ) :
2008-07-28 22:57:56 +02:00
'''
Return activity and messsage ( None if no activity selected )
'''
if self . checkbutton . get_active ( ) :
2009-04-12 20:13:37 +02:00
self . on_response ( self . activity , self . subactivity ,
2009-06-21 21:27:51 +02:00
self . entry . get_text ( ) . decode ( ' utf-8 ' ) )
2008-07-28 22:57:56 +02:00
else :
2009-04-12 20:13:37 +02:00
self . on_response ( None , None , ' ' )
2008-07-28 22:57:56 +02:00
self . window . destroy ( )
2007-03-31 11:09:16 +02:00
def on_cancel_button_clicked ( self , widget ) :
self . window . destroy ( )
2007-03-31 00:52:11 +02:00
class ChangeMoodDialog :
2008-07-23 00:20:51 +02:00
COLS = 11
2009-04-12 20:13:37 +02:00
def __init__ ( self , on_response , mood = None , text = ' ' ) :
self . on_response = on_response
self . mood = mood
self . text = text
2007-03-31 00:52:11 +02:00
self . xml = gtkgui_helpers . get_glade ( ' change_mood_dialog.glade ' )
2008-07-23 00:20:51 +02:00
2007-03-31 00:52:11 +02:00
self . window = self . xml . get_widget ( ' change_mood_dialog ' )
self . window . set_transient_for ( gajim . interface . roster . window )
2008-04-04 00:50:03 +02:00
self . window . set_title ( _ ( ' Set Mood ' ) )
2007-03-31 00:52:11 +02:00
2008-07-23 00:20:51 +02:00
table = self . xml . get_widget ( ' mood_icons_table ' )
self . label = self . xml . get_widget ( ' mood_label ' )
2008-04-04 00:50:03 +02:00
self . entry = self . xml . get_widget ( ' description_entry ' )
2007-03-31 09:43:33 +02:00
2008-07-23 00:20:51 +02:00
no_mood_button = self . xml . get_widget ( ' no_mood_button ' )
no_mood_button . set_mode ( False )
no_mood_button . connect ( ' clicked ' ,
2009-06-21 21:27:51 +02:00
self . on_mood_button_clicked , None )
2008-07-23 00:20:51 +02:00
x = 1
y = 0
self . mood_buttons = { }
2008-07-29 21:02:57 +02:00
# Order them first
self . MOODS = [ ]
2008-07-23 00:20:51 +02:00
for mood in pep . MOODS :
2008-07-29 21:02:57 +02:00
self . MOODS . append ( mood )
self . MOODS . sort ( )
for mood in self . MOODS :
self . mood_buttons [ mood ] = gtk . RadioButton ( no_mood_button )
2008-07-23 00:20:51 +02:00
self . mood_buttons [ mood ] . set_mode ( False )
2008-07-29 21:02:57 +02:00
self . mood_buttons [ mood ] . add ( gtkgui_helpers . load_mood_icon ( mood ) )
2008-07-23 00:20:51 +02:00
self . mood_buttons [ mood ] . set_relief ( gtk . RELIEF_NONE )
2009-10-29 11:35:22 +01:00
self . mood_buttons [ mood ] . set_tooltip_text ( pep . MOODS [ mood ] )
2008-07-23 00:20:51 +02:00
self . mood_buttons [ mood ] . connect ( ' clicked ' ,
2009-06-21 21:27:51 +02:00
self . on_mood_button_clicked , mood )
2008-07-29 21:02:57 +02:00
table . attach ( self . mood_buttons [ mood ] , x , x + 1 , y , y + 1 )
2008-12-03 22:56:12 +01:00
2008-07-23 00:20:51 +02:00
# Calculate the next position
x + = 1
if x > = self . COLS :
x = 0
y + = 1
2007-03-31 09:43:33 +02:00
2009-04-12 20:13:37 +02:00
if self . mood in pep . MOODS :
self . mood_buttons [ self . mood ] . set_active ( True )
self . label . set_text ( pep . MOODS [ self . mood ] )
2008-07-29 08:59:14 +02:00
self . entry . set_sensitive ( True )
2009-04-12 20:13:37 +02:00
if self . text :
self . entry . set_text ( self . text )
2008-07-29 08:59:14 +02:00
else :
2009-04-12 20:13:37 +02:00
self . label . set_text ( _ ( ' None ' ) )
self . entry . set_text ( ' ' )
2008-07-29 08:59:14 +02:00
self . entry . set_sensitive ( False )
2008-05-31 00:39:01 +02:00
2007-03-31 10:11:25 +02:00
self . xml . signal_autoconnect ( self )
2009-04-05 20:35:59 +02:00
self . window . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
2007-03-31 10:11:25 +02:00
self . window . show_all ( )
2007-03-31 09:43:33 +02:00
2008-07-23 00:20:51 +02:00
def on_mood_button_clicked ( self , widget , data ) :
if data :
2008-07-29 21:02:57 +02:00
self . label . set_text ( pep . MOODS [ data ] )
2008-07-23 00:20:51 +02:00
self . entry . set_sensitive ( True )
else :
2008-07-23 04:16:09 +02:00
self . label . set_text ( _ ( ' None ' ) )
2008-07-23 00:20:51 +02:00
self . entry . set_text ( ' ' )
self . entry . set_sensitive ( False )
self . mood = data
2007-03-31 10:11:25 +02:00
def on_ok_button_clicked ( self , widget ) :
''' Return mood and messsage (None if no mood selected) '''
2008-07-23 00:20:51 +02:00
message = self . entry . get_text ( ) . decode ( ' utf-8 ' )
2009-04-12 20:13:37 +02:00
self . on_response ( self . mood , message )
2008-07-23 00:20:51 +02:00
self . window . destroy ( )
2007-03-31 00:52:11 +02:00
2007-03-31 10:11:25 +02:00
def on_cancel_button_clicked ( self , widget ) :
self . window . destroy ( )
2007-03-31 00:52:11 +02:00
2009-10-20 11:20:11 +02:00
class TimeoutDialog :
'''
Class designed to be derivated to create timeout ' d dialogs (dialogs that
closes automatically after a timeout )
'''
def __init__ ( self , timeout , on_timeout ) :
self . countdown_left = timeout
self . countdown_enabled = True
self . title_text = ' '
self . on_timeout = on_timeout
def run_timeout ( self ) :
if self . countdown_left > 0 :
self . countdown ( )
gobject . timeout_add_seconds ( 1 , self . countdown )
def on_timeout ( ) :
''' To be implemented in derivated classes '''
pass
def countdown ( self ) :
if self . countdown_enabled :
if self . countdown_left < = 0 :
self . on_timeout ( )
return False
self . dialog . set_title ( ' %s [ %s ] ' % ( self . title_text ,
str ( self . countdown_left ) ) )
self . countdown_left - = 1
return True
else :
self . dialog . set_title ( self . title_text )
return False
class ChangeStatusMessageDialog ( TimeoutDialog ) :
2009-05-01 11:33:50 +02:00
def __init__ ( self , on_response , show = None , show_pep = True ) :
2009-10-20 11:20:11 +02:00
countdown_time = gajim . config . get ( ' change_status_window_timeout ' )
TimeoutDialog . __init__ ( self , countdown_time , self . on_timeout )
2005-06-30 21:23:41 +02:00
self . show = show
2009-05-01 11:33:50 +02:00
self . pep_dict = { }
self . show_pep = show_pep
2008-08-04 15:34:29 +02:00
self . on_response = on_response
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' change_status_message_dialog.glade ' )
2009-10-20 11:20:11 +02:00
self . dialog = self . xml . get_widget ( ' change_status_message_dialog ' )
self . dialog . set_transient_for ( gajim . interface . roster . window )
2009-04-12 20:13:37 +02:00
msg = None
2005-10-09 16:44:52 +02:00
if show :
uf_show = helpers . get_uf_show ( show )
2007-06-03 12:04:20 +02:00
self . title_text = _ ( ' %s Status Message ' ) % uf_show
2009-05-01 11:33:50 +02:00
msg = gajim . config . get_per ( ' statusmsg ' , ' _last_ ' + self . show ,
2009-06-21 03:43:57 +02:00
' message ' )
2009-05-01 11:33:50 +02:00
self . pep_dict [ ' activity ' ] = gajim . config . get_per ( ' statusmsg ' ,
2009-06-21 03:43:57 +02:00
' _last_ ' + self . show , ' activity ' )
2009-05-01 11:33:50 +02:00
self . pep_dict [ ' subactivity ' ] = gajim . config . get_per ( ' statusmsg ' ,
2009-06-21 03:43:57 +02:00
' _last_ ' + self . show , ' subactivity ' )
2009-05-01 11:33:50 +02:00
self . pep_dict [ ' activity_text ' ] = gajim . config . get_per ( ' statusmsg ' ,
2009-06-21 03:43:57 +02:00
' _last_ ' + self . show , ' activity_text ' )
2009-05-01 11:33:50 +02:00
self . pep_dict [ ' mood ' ] = gajim . config . get_per ( ' statusmsg ' ,
2009-06-21 03:43:57 +02:00
' _last_ ' + self . show , ' mood ' )
2009-05-01 11:33:50 +02:00
self . pep_dict [ ' mood_text ' ] = gajim . config . get_per ( ' statusmsg ' ,
2009-06-21 03:43:57 +02:00
' _last_ ' + self . show , ' mood_text ' )
2005-10-09 16:44:52 +02:00
else :
2007-06-03 12:04:20 +02:00
self . title_text = _ ( ' Status Message ' )
2009-10-20 11:20:11 +02:00
self . dialog . set_title ( self . title_text )
2007-01-15 11:34:53 +01:00
2005-04-04 18:46:35 +02:00
message_textview = self . xml . get_widget ( ' message_textview ' )
self . message_buffer = message_textview . get_buffer ( )
2009-10-16 16:20:58 +02:00
self . message_buffer . connect ( ' changed ' , self . on_message_buffer_changed )
2005-06-30 21:23:41 +02:00
if not msg :
msg = ' '
2005-07-02 14:43:36 +02:00
msg = helpers . from_one_line ( msg )
2005-06-30 21:23:41 +02:00
self . message_buffer . set_text ( msg )
2007-01-15 11:34:53 +01:00
2006-03-07 15:02:45 +01:00
# have an empty string selectable, so user can clear msg
2009-04-13 23:00:33 +02:00
self . preset_messages_dict = { ' ' : [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] }
2006-03-07 15:02:45 +01:00
for msg_name in gajim . config . get_per ( ' statusmsg ' ) :
2009-05-01 11:33:50 +02:00
if msg_name . startswith ( ' _last_ ' ) :
continue
2009-04-13 23:00:33 +02:00
opts = [ ]
for opt in [ ' message ' , ' activity ' , ' subactivity ' , ' activity_text ' ,
2009-06-21 03:43:57 +02:00
' mood ' , ' mood_text ' ] :
2009-04-13 23:00:33 +02:00
opts . append ( gajim . config . get_per ( ' statusmsg ' , msg_name , opt ) )
opts [ 0 ] = helpers . from_one_line ( opts [ 0 ] )
self . preset_messages_dict [ msg_name ] = opts
2006-03-07 15:02:45 +01:00
sorted_keys_list = helpers . get_sorted_keys ( self . preset_messages_dict )
2007-01-15 11:34:53 +01:00
2006-03-07 15:02:45 +01:00
self . message_liststore = gtk . ListStore ( str ) # msg_name
self . message_combobox = self . xml . get_widget ( ' message_combobox ' )
self . message_combobox . set_model ( self . message_liststore )
cellrenderertext = gtk . CellRendererText ( )
self . message_combobox . pack_start ( cellrenderertext , True )
self . message_combobox . add_attribute ( cellrenderertext , ' text ' , 0 )
for msg_name in sorted_keys_list :
self . message_liststore . append ( ( msg_name , ) )
2009-04-12 20:13:37 +02:00
2009-05-01 11:33:50 +02:00
if show_pep :
2009-04-12 20:13:37 +02:00
self . draw_activity ( )
self . draw_mood ( )
else :
# remove acvtivity / mood lines
self . xml . get_widget ( ' activity_label ' ) . set_no_show_all ( True )
self . xml . get_widget ( ' activity_button ' ) . set_no_show_all ( True )
self . xml . get_widget ( ' mood_label ' ) . set_no_show_all ( True )
self . xml . get_widget ( ' mood_button ' ) . set_no_show_all ( True )
self . xml . get_widget ( ' activity_label ' ) . hide ( )
self . xml . get_widget ( ' activity_button ' ) . hide ( )
self . xml . get_widget ( ' mood_label ' ) . hide ( )
self . xml . get_widget ( ' mood_button ' ) . hide ( )
2005-04-04 18:46:35 +02:00
self . xml . signal_autoconnect ( self )
2009-10-20 11:20:11 +02:00
self . run_timeout ( )
self . dialog . connect ( ' response ' , self . on_dialog_response )
self . dialog . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
self . dialog . show_all ( )
2005-04-04 18:46:35 +02:00
2009-04-12 20:13:37 +02:00
def draw_activity ( self ) :
''' Set activity button '''
img = self . xml . get_widget ( ' activity_image ' )
label = self . xml . get_widget ( ' activity_button_label ' )
if ' activity ' in self . pep_dict and self . pep_dict [ ' activity ' ] in \
2009-06-21 03:43:57 +02:00
pep . ACTIVITIES :
2009-04-12 20:13:37 +02:00
if ' subactivity ' in self . pep_dict and self . pep_dict [ ' subactivity ' ] in \
2009-06-21 03:43:57 +02:00
pep . ACTIVITIES [ self . pep_dict [ ' activity ' ] ] :
2009-04-12 20:13:37 +02:00
img . set_from_pixbuf ( gtkgui_helpers . load_activity_icon (
self . pep_dict [ ' activity ' ] , self . pep_dict [ ' subactivity ' ] ) . \
2009-06-21 03:43:57 +02:00
get_pixbuf ( ) )
2009-04-12 20:13:37 +02:00
else :
img . set_from_pixbuf ( gtkgui_helpers . load_activity_icon (
self . pep_dict [ ' activity ' ] ) . get_pixbuf ( ) )
2009-10-29 11:35:22 +01:00
# item.set_tooltip_text(pep.ACTIVITIES[category]['category'])
2009-04-12 20:13:37 +02:00
if self . pep_dict [ ' activity_text ' ] :
label . set_text ( self . pep_dict [ ' activity_text ' ] )
2009-06-19 07:20:19 +02:00
else :
label . set_text ( ' ' )
2009-04-12 20:13:37 +02:00
else :
img . set_from_pixbuf ( None )
label . set_text ( ' ' )
def draw_mood ( self ) :
''' Set mood button '''
img = self . xml . get_widget ( ' mood_image ' )
label = self . xml . get_widget ( ' mood_button_label ' )
if self . pep_dict [ ' mood ' ] in pep . MOODS :
img . set_from_pixbuf ( gtkgui_helpers . load_mood_icon (
self . pep_dict [ ' mood ' ] ) . get_pixbuf ( ) )
if self . pep_dict [ ' mood_text ' ] :
label . set_text ( self . pep_dict [ ' mood_text ' ] )
2009-06-19 07:20:19 +02:00
else :
label . set_text ( ' ' )
2009-04-12 20:13:37 +02:00
else :
img . set_from_pixbuf ( None )
label . set_text ( ' ' )
2009-10-20 11:20:11 +02:00
def on_timeout ( self ) :
# Prevent GUI freeze when the combobox menu is opened on close
self . message_combobox . popdown ( )
self . dialog . response ( gtk . RESPONSE_OK )
2007-06-03 12:04:20 +02:00
2008-08-04 15:34:29 +02:00
def on_dialog_response ( self , dialog , response ) :
if response == gtk . RESPONSE_OK :
2005-03-02 13:46:37 +01:00
beg , end = self . message_buffer . get_bounds ( )
2006-03-07 15:02:45 +01:00
message = self . message_buffer . get_text ( beg , end ) . decode ( ' utf-8 ' ) \
2009-10-20 11:20:11 +02:00
. strip ( )
2008-07-30 14:21:47 +02:00
message = helpers . remove_invalid_xml_chars ( message )
2005-07-02 14:43:36 +02:00
msg = helpers . to_one_line ( message )
2005-10-09 16:44:52 +02:00
if self . show :
2009-05-01 11:33:50 +02:00
gajim . config . set_per ( ' statusmsg ' , ' _last_ ' + self . show , ' message ' ,
2009-07-22 08:55:25 +02:00
msg )
2009-05-01 11:33:50 +02:00
if self . show_pep :
gajim . config . set_per ( ' statusmsg ' , ' _last_ ' + self . show ,
2009-07-22 08:55:25 +02:00
' activity ' , self . pep_dict [ ' activity ' ] )
2009-05-01 11:33:50 +02:00
gajim . config . set_per ( ' statusmsg ' , ' _last_ ' + self . show ,
2009-07-22 08:55:25 +02:00
' subactivity ' , self . pep_dict [ ' subactivity ' ] )
2009-05-01 11:33:50 +02:00
gajim . config . set_per ( ' statusmsg ' , ' _last_ ' + self . show ,
2009-07-22 08:55:25 +02:00
' activity_text ' , self . pep_dict [ ' activity_text ' ] )
2009-05-01 11:33:50 +02:00
gajim . config . set_per ( ' statusmsg ' , ' _last_ ' + self . show , ' mood ' ,
2009-07-22 08:55:25 +02:00
self . pep_dict [ ' mood ' ] )
2009-05-01 11:33:50 +02:00
gajim . config . set_per ( ' statusmsg ' , ' _last_ ' + self . show ,
2009-07-22 08:55:25 +02:00
' mood_text ' , self . pep_dict [ ' mood_text ' ] )
2004-05-15 18:50:38 +02:00
else :
2005-10-10 00:24:18 +02:00
message = None # user pressed Cancel button or X wm button
2009-10-20 11:20:11 +02:00
self . dialog . destroy ( )
2009-04-12 20:13:37 +02:00
self . on_response ( message , self . pep_dict )
2004-10-26 00:02:16 +02:00
2006-03-07 15:02:45 +01:00
def on_message_combobox_changed ( self , widget ) :
2007-06-03 12:04:20 +02:00
self . countdown_enabled = False
2004-10-26 00:02:16 +02:00
model = widget . get_model ( )
active = widget . get_active ( )
if active < 0 :
return None
2005-08-26 02:52:44 +02:00
name = model [ active ] [ 0 ] . decode ( ' utf-8 ' )
2009-04-13 23:00:33 +02:00
self . message_buffer . set_text ( self . preset_messages_dict [ name ] [ 0 ] )
self . pep_dict [ ' activity ' ] = self . preset_messages_dict [ name ] [ 1 ]
self . pep_dict [ ' subactivity ' ] = self . preset_messages_dict [ name ] [ 2 ]
self . pep_dict [ ' activity_text ' ] = self . preset_messages_dict [ name ] [ 3 ]
self . pep_dict [ ' mood ' ] = self . preset_messages_dict [ name ] [ 4 ]
self . pep_dict [ ' mood_text ' ] = self . preset_messages_dict [ name ] [ 5 ]
self . draw_activity ( )
self . draw_mood ( )
2007-01-15 11:34:53 +01:00
2005-03-16 02:27:37 +01:00
def on_change_status_message_dialog_key_press_event ( self , widget , event ) :
2007-06-03 12:04:20 +02:00
self . countdown_enabled = False
2005-03-18 02:28:59 +01:00
if event . keyval == gtk . keysyms . Return or \
2009-06-21 03:43:57 +02:00
event . keyval == gtk . keysyms . KP_Enter : # catch CTRL+ENTER
2005-01-08 15:40:08 +01:00
if ( event . state & gtk . gdk . CONTROL_MASK ) :
2009-10-20 11:20:11 +02:00
self . dialog . response ( gtk . RESPONSE_OK )
2007-06-03 12:04:20 +02:00
# Stop the event
return True
2005-04-04 18:46:35 +02:00
2009-10-16 16:20:58 +02:00
def on_message_buffer_changed ( self , widget ) :
self . countdown_enabled = False
self . toggle_sensitiviy_of_save_as_preset ( )
def toggle_sensitiviy_of_save_as_preset ( self ) :
2006-01-26 18:40:11 +01:00
btn = self . xml . get_widget ( ' save_as_preset_button ' )
if self . message_buffer . get_char_count ( ) == 0 :
btn . set_sensitive ( False )
else :
btn . set_sensitive ( True )
2007-01-15 11:34:53 +01:00
2006-03-07 15:02:45 +01:00
def on_save_as_preset_button_clicked ( self , widget ) :
2007-06-03 12:04:20 +02:00
self . countdown_enabled = False
2006-03-07 15:02:45 +01:00
start_iter , finish_iter = self . message_buffer . get_bounds ( )
status_message_to_save_as_preset = self . message_buffer . get_text (
start_iter , finish_iter )
2008-08-07 15:25:25 +02:00
def on_ok ( msg_name ) :
2006-11-28 15:41:14 +01:00
msg_text = status_message_to_save_as_preset . decode ( ' utf-8 ' )
msg_text_1l = helpers . to_one_line ( msg_text )
2006-03-15 17:34:52 +01:00
if not msg_name : # msg_name was ''
2008-08-07 23:59:20 +02:00
msg_name = msg_text_1l . decode ( ' utf-8 ' )
2007-01-15 11:34:53 +01:00
2009-04-13 23:00:33 +02:00
def on_ok2 ( ) :
self . preset_messages_dict [ msg_name ] = [ msg_text , self . pep_dict . get (
' activity ' ) , self . pep_dict . get ( ' subactivity ' ) , self . pep_dict . get (
2009-06-21 03:43:57 +02:00
' activity_text ' ) , self . pep_dict . get ( ' mood ' ) , self . pep_dict . get (
' mood_text ' ) ]
2009-04-13 23:00:33 +02:00
gajim . config . set_per ( ' statusmsg ' , msg_name , ' message ' , msg_text_1l )
gajim . config . set_per ( ' statusmsg ' , msg_name , ' activity ' ,
2009-06-21 03:43:57 +02:00
self . pep_dict . get ( ' activity ' ) )
2009-04-13 23:00:33 +02:00
gajim . config . set_per ( ' statusmsg ' , msg_name , ' subactivity ' ,
2009-06-21 03:43:57 +02:00
self . pep_dict . get ( ' subactivity ' ) )
2009-04-13 23:00:33 +02:00
gajim . config . set_per ( ' statusmsg ' , msg_name , ' activity_text ' ,
2009-06-21 03:43:57 +02:00
self . pep_dict . get ( ' activity_text ' ) )
2009-04-13 23:00:33 +02:00
gajim . config . set_per ( ' statusmsg ' , msg_name , ' mood ' ,
2009-06-21 03:43:57 +02:00
self . pep_dict . get ( ' mood ' ) )
2009-04-13 23:00:33 +02:00
gajim . config . set_per ( ' statusmsg ' , msg_name , ' mood_text ' ,
2009-06-21 03:43:57 +02:00
self . pep_dict . get ( ' mood_text ' ) )
2007-08-09 17:39:18 +02:00
if msg_name in self . preset_messages_dict :
2008-12-02 16:53:23 +01:00
ConfirmationDialog ( _ ( ' Overwrite Status Message? ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' This name is already used. Do you want to overwrite this '
' status message? ' ) , on_response_ok = on_ok2 )
2008-08-06 22:55:40 +02:00
return
gajim . config . add_per ( ' statusmsg ' , msg_name )
2009-04-13 23:00:33 +02:00
on_ok2 ( )
iter_ = self . message_liststore . append ( ( msg_name , ) )
2008-08-06 22:55:40 +02:00
# select in combobox the one we just saved
self . message_combobox . set_active_iter ( iter_ )
2008-08-07 15:25:25 +02:00
InputDialog ( _ ( ' Save as Preset Status Message ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' Please type a name for this status message ' ) , is_modal = False ,
ok_handler = on_ok )
2006-01-26 18:40:11 +01:00
2009-04-12 20:13:37 +02:00
def on_activity_button_clicked ( self , widget ) :
self . countdown_enabled = False
def on_response ( activity , subactivity , text ) :
2009-07-22 08:55:25 +02:00
self . pep_dict [ ' activity ' ] = activity or ' '
self . pep_dict [ ' subactivity ' ] = subactivity or ' '
2009-04-12 20:13:37 +02:00
self . pep_dict [ ' activity_text ' ] = text
self . draw_activity ( )
ChangeActivityDialog ( on_response , self . pep_dict [ ' activity ' ] ,
2009-06-21 03:43:57 +02:00
self . pep_dict [ ' subactivity ' ] , self . pep_dict [ ' activity_text ' ] )
2009-04-12 20:13:37 +02:00
def on_mood_button_clicked ( self , widget ) :
self . countdown_enabled = False
def on_response ( mood , text ) :
2009-07-22 08:55:25 +02:00
self . pep_dict [ ' mood ' ] = mood or ' '
2009-04-12 20:13:37 +02:00
self . pep_dict [ ' mood_text ' ] = text
self . draw_mood ( )
ChangeMoodDialog ( on_response , self . pep_dict [ ' mood ' ] ,
2009-06-21 03:43:57 +02:00
self . pep_dict [ ' mood_text ' ] )
2009-04-12 20:13:37 +02:00
2005-06-10 23:14:16 +02:00
class AddNewContactWindow :
''' Class for AddNewContactWindow '''
2006-11-18 21:52:28 +01:00
uid_labels = { ' jabber ' : _ ( ' Jabber ID: ' ) ,
2009-06-21 03:43:57 +02:00
' aim ' : _ ( ' AIM Address: ' ) ,
' gadu-gadu ' : _ ( ' GG Number: ' ) ,
' icq ' : _ ( ' ICQ Number: ' ) ,
' msn ' : _ ( ' MSN Address: ' ) ,
' yahoo ' : _ ( ' Yahoo! Address: ' ) }
2008-09-03 13:25:27 +02:00
def __init__ ( self , account = None , jid = None , user_nick = None , group = None ) :
2005-04-04 18:46:35 +02:00
self . account = account
2008-04-18 02:02:56 +02:00
if account is None :
2006-05-19 23:13:45 +02:00
# fill accounts with active accounts
accounts = [ ]
for account in gajim . connections . keys ( ) :
if gajim . connections [ account ] . connected > 1 :
accounts . append ( account )
if not accounts :
return
if len ( accounts ) == 1 :
self . account = account
else :
accounts = [ self . account ]
2006-09-13 18:47:58 +02:00
if self . account :
location = gajim . interface . instances [ self . account ]
else :
location = gajim . interface . instances
2008-10-07 22:41:59 +02:00
if ' add_contact ' in location :
2006-09-13 18:47:58 +02:00
location [ ' add_contact ' ] . window . present ( )
# An instance is already opened
return
location [ ' add_contact ' ] = self
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' add_new_contact_window.glade ' )
2007-12-12 09:44:46 +01:00
self . xml . signal_autoconnect ( self )
2005-04-04 18:46:35 +02:00
self . window = self . xml . get_widget ( ' add_new_contact_window ' )
2006-09-13 18:47:58 +02:00
for w in ( ' account_combobox ' , ' account_hbox ' , ' account_label ' ,
2009-06-21 03:43:57 +02:00
' uid_label ' , ' uid_entry ' , ' protocol_combobox ' , ' protocol_jid_combobox ' ,
' protocol_hbox ' , ' nickname_entry ' , ' message_scrolledwindow ' ,
' register_hbox ' , ' subscription_table ' , ' add_button ' ,
' message_textview ' , ' connected_label ' , ' group_comboboxentry ' ,
' auto_authorize_checkbutton ' ) :
2006-09-13 18:47:58 +02:00
self . __dict__ [ w ] = self . xml . get_widget ( w )
2006-05-19 23:13:45 +02:00
if account and len ( gajim . connections ) > = 2 :
2005-06-13 15:19:54 +02:00
prompt_text = \
_ ( ' Please fill in the data of the contact you want to add in account %s ' ) % account
else :
prompt_text = _ ( ' Please fill in the data of the contact you want to add ' )
self . xml . get_widget ( ' prompt_label ' ) . set_text ( prompt_text )
2006-09-13 18:47:58 +02:00
self . agents = { ' jabber ' : [ ] }
# types to which we are not subscribed but account has an agent for it
self . available_types = [ ]
2006-05-19 23:13:45 +02:00
for acct in accounts :
for j in gajim . contacts . get_jid_list ( acct ) :
2006-12-12 15:16:29 +01:00
if gajim . jid_is_transport ( j ) :
2007-06-03 12:04:20 +02:00
type_ = gajim . get_transport_name_from_jid ( j , False )
2007-08-09 17:39:18 +02:00
if not type_ :
continue
2008-10-07 22:41:59 +02:00
if type_ in self . agents :
2006-09-13 18:47:58 +02:00
self . agents [ type_ ] . append ( j )
else :
self . agents [ type_ ] = [ j ]
# Now add the one to which we can register
for acct in accounts :
2007-06-03 12:04:20 +02:00
for type_ in gajim . connections [ acct ] . available_transports :
2006-09-13 18:47:58 +02:00
if type_ in self . agents :
continue
self . agents [ type_ ] = [ ]
2007-06-03 12:04:20 +02:00
for jid_ in gajim . connections [ acct ] . available_transports [ type_ ] :
if not jid_ in self . agents [ type_ ] :
self . agents [ type_ ] . append ( jid_ )
2006-09-13 18:47:58 +02:00
self . available_types . append ( type_ )
liststore = gtk . ListStore ( str )
2008-01-22 17:06:16 +01:00
self . group_comboboxentry . set_model ( liststore )
2007-08-09 17:39:18 +02:00
# Combobox with transport/jabber icons
liststore = gtk . ListStore ( str , gtk . gdk . Pixbuf , str )
cell = gtk . CellRendererPixbuf ( )
self . protocol_combobox . pack_start ( cell , False )
self . protocol_combobox . add_attribute ( cell , ' pixbuf ' , 1 )
cell = gtk . CellRendererText ( )
cell . set_property ( ' xpad ' , 5 )
self . protocol_combobox . pack_start ( cell , True )
self . protocol_combobox . add_attribute ( cell , ' text ' , 0 )
self . protocol_combobox . set_model ( liststore )
2006-09-13 18:47:58 +02:00
uf_type = { ' jabber ' : ' Jabber ' , ' aim ' : ' AIM ' , ' gadu-gadu ' : ' Gadu Gadu ' ,
2009-06-21 03:43:57 +02:00
' icq ' : ' ICQ ' , ' msn ' : ' MSN ' , ' yahoo ' : ' Yahoo ' }
2006-09-13 18:47:58 +02:00
# Jabber as first
2008-04-17 16:17:14 +02:00
img = gajim . interface . jabber_state_images [ ' 16 ' ] [ ' online ' ]
2007-08-09 17:39:18 +02:00
liststore . append ( [ ' Jabber ' , img . get_pixbuf ( ) , ' jabber ' ] )
2006-09-13 18:47:58 +02:00
for type_ in self . agents :
if type_ == ' jabber ' :
continue
2007-08-09 17:39:18 +02:00
imgs = gajim . interface . roster . transports_state_images
img = None
2008-10-07 22:41:59 +02:00
if type_ in imgs [ ' 16 ' ] and ' online ' in imgs [ ' 16 ' ] [ type_ ] :
2007-08-09 17:39:18 +02:00
img = imgs [ ' 16 ' ] [ type_ ] [ ' online ' ]
if type_ in uf_type :
liststore . append ( [ uf_type [ type_ ] , img . get_pixbuf ( ) , type_ ] )
else :
liststore . append ( [ type_ , img . get_pixbuf ( ) , type_ ] )
2005-04-04 18:46:35 +02:00
else :
2007-08-09 17:39:18 +02:00
liststore . append ( [ type_ , img , type_ ] )
2005-05-04 19:44:49 +02:00
self . protocol_combobox . set_active ( 0 )
2006-11-18 21:52:28 +01:00
self . auto_authorize_checkbutton . show ( )
2006-09-13 18:47:58 +02:00
liststore = gtk . ListStore ( str )
self . protocol_jid_combobox . set_model ( liststore )
2005-04-04 18:46:35 +02:00
if jid :
2006-11-18 21:52:28 +01:00
type_ = gajim . get_transport_name_from_jid ( jid )
if not type_ :
type_ = ' jabber '
2006-09-13 18:47:58 +02:00
if type_ == ' jabber ' :
2005-05-04 19:44:49 +02:00
self . uid_entry . set_text ( jid )
2006-09-13 18:47:58 +02:00
else :
2006-11-18 21:52:28 +01:00
uid , transport = gajim . get_name_and_server_from_jid ( jid )
2006-09-13 18:47:58 +02:00
self . uid_entry . set_text ( uid . replace ( ' % ' , ' @ ' , 1 ) )
#set protocol_combobox
model = self . protocol_combobox . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = model . get_iter_first ( )
2006-09-13 18:47:58 +02:00
i = 0
2008-12-03 18:16:04 +01:00
while iter_ :
if model [ iter_ ] [ 2 ] == type_ :
2006-09-13 18:47:58 +02:00
self . protocol_combobox . set_active ( i )
break
2008-12-03 18:16:04 +01:00
iter_ = model . iter_next ( iter_ )
2006-09-13 18:47:58 +02:00
i + = 1
# set protocol_jid_combobox
2006-11-18 21:52:28 +01:00
self . protocol_jid_combobox . set_active ( 0 )
2006-09-13 18:47:58 +02:00
model = self . protocol_jid_combobox . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = model . get_iter_first ( )
2006-09-13 18:47:58 +02:00
i = 0
2008-12-03 18:16:04 +01:00
while iter_ :
if model [ iter_ ] [ 0 ] == transport :
2006-11-18 21:52:28 +01:00
self . protocol_jid_combobox . set_active ( i )
2006-09-13 18:47:58 +02:00
break
2008-12-03 18:16:04 +01:00
iter_ = model . iter_next ( iter_ )
2006-09-13 18:47:58 +02:00
i + = 1
2006-06-01 17:23:38 +02:00
if user_nick :
self . nickname_entry . set_text ( user_nick )
2005-11-07 22:30:35 +01:00
self . nickname_entry . grab_focus ( )
2006-09-13 18:47:58 +02:00
else :
self . uid_entry . grab_focus ( )
2006-05-19 23:13:45 +02:00
group_names = [ ]
for acct in accounts :
for g in gajim . groups [ acct ] . keys ( ) :
if g not in helpers . special_groups and g not in group_names :
group_names . append ( g )
2006-09-13 18:47:58 +02:00
group_names . sort ( )
i = 0
for g in group_names :
self . group_comboboxentry . append_text ( g )
if group == g :
self . group_comboboxentry . set_active ( i )
i + = 1
2007-12-12 09:44:46 +01:00
self . window . show_all ( )
2006-05-19 23:13:45 +02:00
if self . account :
self . account_label . hide ( )
2006-05-20 00:30:23 +02:00
self . account_hbox . hide ( )
2006-05-19 23:13:45 +02:00
else :
liststore = gtk . ListStore ( str , str )
for acct in accounts :
liststore . append ( [ acct , acct ] )
self . account_combobox . set_model ( liststore )
self . account_combobox . set_active ( 0 )
2004-05-15 18:50:38 +02:00
2006-09-13 18:47:58 +02:00
def on_add_new_contact_window_destroy ( self , widget ) :
if self . account :
location = gajim . interface . instances [ self . account ]
else :
location = gajim . interface . instances
del location [ ' add_contact ' ]
def on_register_button_clicked ( self , widget ) :
jid = self . protocol_jid_combobox . get_active_text ( ) . decode ( ' utf-8 ' )
gajim . connections [ self . account ] . request_register_agent_info ( jid )
2005-04-28 15:01:47 +02:00
def on_add_new_contact_window_key_press_event ( self , widget , event ) :
if event . keyval == gtk . keysyms . Escape : # ESCAPE
self . window . destroy ( )
2005-03-01 00:44:52 +01:00
def on_cancel_button_clicked ( self , widget ) :
2005-04-18 14:17:43 +02:00
''' When Cancel button is clicked '''
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2004-05-15 18:50:38 +02:00
2006-09-13 18:47:58 +02:00
def on_add_button_clicked ( self , widget ) :
2005-04-18 14:17:43 +02:00
''' When Subscribe button is clicked '''
2009-08-06 00:01:07 +02:00
jid = self . uid_entry . get_text ( ) . decode ( ' utf-8 ' ) . strip ( )
2005-03-01 00:44:52 +01:00
if not jid :
2004-11-18 20:22:33 +01:00
return
2006-09-13 18:47:58 +02:00
model = self . protocol_combobox . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = self . protocol_combobox . get_active_iter ( )
type_ = model [ iter_ ] [ 2 ]
2006-09-13 18:47:58 +02:00
if type_ != ' jabber ' :
transport = self . protocol_jid_combobox . get_active_text ( ) . decode (
' utf-8 ' )
jid = jid . replace ( ' @ ' , ' % ' ) + ' @ ' + transport
2007-01-15 11:34:53 +01:00
2005-11-03 15:46:56 +01:00
# check if jid is conform to RFC and stringprep it
try :
jid = helpers . parse_jid ( jid )
except helpers . InvalidFormat , s :
2005-11-02 15:54:25 +01:00
pritext = _ ( ' Invalid User ID ' )
2006-04-02 18:11:21 +02:00
ErrorDialog ( pritext , str ( s ) )
2004-11-18 20:22:33 +01:00
return
2005-11-02 13:46:57 +01:00
2006-03-12 21:53:28 +01:00
# No resource in jid
if jid . find ( ' / ' ) > = 0 :
pritext = _ ( ' Invalid User ID ' )
2006-04-02 18:11:21 +02:00
ErrorDialog ( pritext , _ ( ' The user ID must not contain a resource. ' ) )
2006-03-12 21:53:28 +01:00
return
2008-07-31 10:08:54 +02:00
if jid == gajim . get_jid_from_account ( self . account ) :
pritext = _ ( ' Invalid User ID ' )
ErrorDialog ( pritext , _ ( ' You cannot add yourself to your roster. ' ) )
return
2006-09-13 18:47:58 +02:00
nickname = self . nickname_entry . get_text ( ) . decode ( ' utf-8 ' ) or ' '
2006-05-19 23:13:45 +02:00
# get value of account combobox, if account was not specified
if not self . account :
model = self . account_combobox . get_model ( )
index = self . account_combobox . get_active ( )
self . account = model [ index ] [ 1 ]
2005-11-03 15:46:56 +01:00
# Check if jid is already in roster
2006-03-30 19:55:25 +02:00
if jid in gajim . contacts . get_jid_list ( self . account ) :
c = gajim . contacts . get_first_contact_from_jid ( self . account , jid )
if _ ( ' Not in Roster ' ) not in c . groups and c . sub in ( ' both ' , ' to ' ) :
ErrorDialog ( _ ( ' Contact already in roster ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' This contact is already listed in your roster. ' ) )
2006-03-30 19:55:25 +02:00
return
2005-11-02 13:46:57 +01:00
2006-09-13 18:47:58 +02:00
if type_ == ' jabber ' :
message_buffer = self . message_textview . get_buffer ( )
start_iter = message_buffer . get_start_iter ( )
end_iter = message_buffer . get_end_iter ( )
message = message_buffer . get_text ( start_iter , end_iter ) . decode ( ' utf-8 ' )
else :
message = ' '
2005-08-26 02:52:44 +02:00
group = self . group_comboboxentry . child . get_text ( ) . decode ( ' utf-8 ' )
2006-12-27 11:39:03 +01:00
groups = [ ]
if group :
groups = [ group ]
2006-11-18 21:52:28 +01:00
auto_auth = self . auto_authorize_checkbutton . get_active ( )
2005-10-20 13:17:17 +02:00
gajim . interface . roster . req_sub ( self , jid , message , self . account ,
2009-06-21 03:43:57 +02:00
groups = groups , nickname = nickname , auto_auth = auto_auth )
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2005-02-03 23:21:55 +01:00
2005-03-23 14:25:48 +01:00
def on_protocol_combobox_changed ( self , widget ) :
2006-09-13 18:47:58 +02:00
model = widget . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = widget . get_active_iter ( )
type_ = model [ iter_ ] [ 2 ]
2006-09-13 18:47:58 +02:00
model = self . protocol_jid_combobox . get_model ( )
model . clear ( )
if len ( self . agents [ type_ ] ) :
for jid_ in self . agents [ type_ ] :
model . append ( [ jid_ ] )
self . protocol_jid_combobox . set_active ( 0 )
2006-11-18 21:52:28 +01:00
if len ( self . agents [ type_ ] ) > 1 :
2007-12-12 09:44:46 +01:00
self . protocol_jid_combobox . show ( )
2006-09-13 18:47:58 +02:00
else :
2006-11-18 21:52:28 +01:00
self . protocol_jid_combobox . hide ( )
2006-09-13 18:47:58 +02:00
if type_ in self . uid_labels :
self . uid_label . set_text ( self . uid_labels [ type_ ] )
else :
2006-11-18 21:52:28 +01:00
self . uid_label . set_text ( _ ( ' User ID: ' ) )
2006-09-13 18:47:58 +02:00
if type_ == ' jabber ' :
self . message_scrolledwindow . show ( )
else :
self . message_scrolledwindow . hide ( )
if type_ in self . available_types :
2007-12-12 09:44:46 +01:00
self . register_hbox . show ( )
2006-11-18 21:52:28 +01:00
self . auto_authorize_checkbutton . hide ( )
2006-09-13 18:47:58 +02:00
self . connected_label . hide ( )
self . subscription_table . hide ( )
self . add_button . set_sensitive ( False )
else :
self . register_hbox . hide ( )
if type_ != ' jabber ' :
jid = self . protocol_jid_combobox . get_active_text ( )
contact = gajim . contacts . get_first_contact_from_jid ( self . account ,
2009-06-21 03:43:57 +02:00
jid )
2006-09-13 18:47:58 +02:00
if contact . show in ( ' offline ' , ' error ' ) :
self . subscription_table . hide ( )
self . connected_label . show ( )
self . add_button . set_sensitive ( False )
2006-11-18 21:52:28 +01:00
self . auto_authorize_checkbutton . hide ( )
2006-09-13 18:47:58 +02:00
return
2007-12-12 09:44:46 +01:00
self . subscription_table . show ( )
2006-11-18 21:52:28 +01:00
self . auto_authorize_checkbutton . show ( )
2006-09-13 18:47:58 +02:00
self . connected_label . hide ( )
self . add_button . set_sensitive ( True )
def transport_signed_in ( self , jid ) :
if self . protocol_jid_combobox . get_active_text ( ) == jid :
self . register_hbox . hide ( )
self . connected_label . hide ( )
2007-12-12 09:44:46 +01:00
self . subscription_table . show ( )
self . auto_authorize_checkbutton . show ( )
2006-09-13 18:47:58 +02:00
self . add_button . set_sensitive ( True )
def transport_signed_out ( self , jid ) :
if self . protocol_jid_combobox . get_active_text ( ) == jid :
self . subscription_table . hide ( )
2007-12-12 09:44:46 +01:00
self . auto_authorize_checkbutton . hide ( )
2006-09-13 18:47:58 +02:00
self . connected_label . show ( )
self . add_button . set_sensitive ( False )
2004-05-15 18:50:38 +02:00
2005-06-10 01:28:07 +02:00
class AboutDialog :
2005-04-18 14:17:43 +02:00
''' Class for about dialog '''
2005-04-04 18:46:35 +02:00
def __init__ ( self ) :
2005-03-09 22:29:20 +01:00
dlg = gtk . AboutDialog ( )
2006-09-13 18:47:58 +02:00
dlg . set_transient_for ( gajim . interface . roster . window )
2005-03-09 22:29:20 +01:00
dlg . set_name ( ' Gajim ' )
2005-04-16 19:03:21 +02:00
dlg . set_version ( gajim . version )
2009-03-14 13:36:02 +01:00
s = u ' Copyright © 2003-2009 Gajim Team '
2005-03-16 03:16:29 +01:00
dlg . set_copyright ( s )
2008-04-20 22:51:05 +02:00
copying_file_path = self . get_path ( ' COPYING ' )
2006-11-18 21:52:28 +01:00
if copying_file_path :
text = open ( copying_file_path ) . read ( )
dlg . set_license ( text )
2007-01-15 11:34:53 +01:00
2008-01-22 17:06:16 +01:00
dlg . set_comments ( ' %s \n %s %s \n %s %s '
2009-06-21 03:43:57 +02:00
% ( _ ( ' A GTK+ jabber client ' ) , \
_ ( ' GTK+ Version: ' ) , self . tuple2str ( gtk . gtk_version ) , \
_ ( ' PyGTK Version: ' ) , self . tuple2str ( gtk . pygtk_version ) ) )
2006-09-13 18:47:58 +02:00
dlg . set_website ( ' http://www.gajim.org/ ' )
2005-03-18 01:47:50 +01:00
2008-04-20 22:51:05 +02:00
authors_file_path = self . get_path ( ' AUTHORS ' )
2006-11-18 21:52:28 +01:00
if authors_file_path :
authors = [ ]
authors_file = open ( authors_file_path ) . read ( )
authors_file = authors_file . split ( ' \n ' )
for author in authors_file :
if author == ' CURRENT DEVELOPERS: ' :
authors . append ( _ ( ' Current Developers: ' ) )
elif author == ' PAST DEVELOPERS: ' :
authors . append ( ' \n ' + _ ( ' Past Developers: ' ) )
elif author != ' ' : # Real author line
authors . append ( author )
2007-01-15 11:34:53 +01:00
2008-04-20 22:51:05 +02:00
thanks_file_path = self . get_path ( ' THANKS ' )
2006-11-18 21:52:28 +01:00
if thanks_file_path :
authors . append ( ' \n ' + _ ( ' THANKS: ' ) )
2007-01-15 11:34:53 +01:00
2006-11-18 21:52:28 +01:00
text = open ( thanks_file_path ) . read ( )
text_splitted = text . split ( ' \n ' )
text = ' \n ' . join ( text_splitted [ : - 2 ] ) # remove one english sentence
# and add it manually as translatable
text + = ' \n %s \n ' % _ ( ' Last but not least, we would like to thank all '
2009-06-21 03:43:57 +02:00
' the package maintainers. ' )
2006-11-18 21:52:28 +01:00
authors . append ( text )
2007-01-15 11:34:53 +01:00
2006-11-18 21:52:28 +01:00
dlg . set_authors ( authors )
2007-01-15 11:34:53 +01:00
2007-01-17 00:26:38 +01:00
dlg . props . wrap_license = True
2005-06-03 13:41:02 +02:00
2005-09-24 23:50:58 +02:00
pixbuf = gtk . gdk . pixbuf_new_from_file ( os . path . join (
2008-01-22 17:06:16 +01:00
gajim . DATA_DIR , ' pixmaps ' , ' gajim_about.png ' ) )
2005-06-03 13:41:02 +02:00
dlg . set_logo ( pixbuf )
2005-09-24 23:49:28 +02:00
#here you write your name in the form Name FamilyName <someone@somewhere>
2005-08-13 13:17:49 +02:00
dlg . set_translator_credits ( _ ( ' translator-credits ' ) )
2008-12-03 22:56:12 +01:00
2008-04-20 22:51:05 +02:00
thanks_artists_file_path = self . get_path ( ' THANKS.artists ' )
if thanks_artists_file_path :
artists_text = open ( thanks_artists_file_path ) . read ( )
artists = artists_text . split ( ' \n ' )
dlg . set_artists ( artists )
2008-03-23 12:14:50 +01:00
# connect close button to destroy() function
for button in dlg . action_area . get_children ( ) :
if button . get_property ( ' label ' ) == gtk . STOCK_CLOSE :
button . connect ( ' clicked ' , lambda x : dlg . destroy ( ) )
dlg . show_all ( )
2007-01-15 11:34:53 +01:00
2006-04-25 22:38:16 +02:00
def tuple2str ( self , tuple_ ) :
2006-04-12 18:31:35 +02:00
str_ = ' '
2006-04-25 22:38:16 +02:00
for num in tuple_ :
2006-04-12 18:31:35 +02:00
str_ + = str ( num ) + ' . '
return str_ [ 0 : - 1 ] # remove latest .
2004-05-15 18:50:38 +02:00
2008-04-20 22:51:05 +02:00
def get_path ( self , filename ) :
''' where can we find this Credits file ? '''
if os . path . isfile ( os . path . join ( gajim . defs . docdir , filename ) ) :
return os . path . join ( gajim . defs . docdir , filename )
elif os . path . isfile ( ' ../ ' + filename ) :
return ( ' ../ ' + filename )
else :
return None
2005-06-07 03:10:24 +02:00
class Dialog ( gtk . Dialog ) :
2008-09-03 13:25:27 +02:00
def __init__ ( self , parent , title , buttons , default = None ,
2009-06-21 03:43:57 +02:00
on_response_ok = None , on_response_cancel = None ) :
2008-02-15 23:55:21 +01:00
gtk . Dialog . __init__ ( self , title , parent , gtk . DIALOG_DESTROY_WITH_PARENT | gtk . DIALOG_NO_SEPARATOR )
2005-06-07 03:10:24 +02:00
2008-02-15 23:55:21 +01:00
self . user_response_ok = on_response_ok
self . user_response_cancel = on_response_cancel
2005-06-12 19:36:27 +02:00
self . set_border_width ( 6 )
self . vbox . set_spacing ( 12 )
self . set_resizable ( False )
2005-06-07 03:10:24 +02:00
2008-02-15 23:55:21 +01:00
possible_responses = { gtk . STOCK_OK : self . on_response_ok ,
2009-06-21 03:43:57 +02:00
gtk . STOCK_CANCEL : self . on_response_cancel }
2005-06-12 19:36:27 +02:00
for stock , response in buttons :
2008-02-15 23:55:21 +01:00
b = self . add_button ( stock , response )
for response in possible_responses :
if stock == response :
b . connect ( ' clicked ' , possible_responses [ response ] )
break
2005-06-07 03:10:24 +02:00
2005-06-12 19:36:27 +02:00
if default is not None :
self . set_default_response ( default )
else :
self . set_default_response ( buttons [ - 1 ] [ 1 ] )
2005-06-07 03:10:24 +02:00
2008-02-15 23:55:21 +01:00
def on_response_ok ( self , widget ) :
if self . user_response_ok :
if isinstance ( self . user_response_ok , tuple ) :
self . user_response_ok [ 0 ] ( * self . user_response_ok [ 1 : ] )
else :
self . user_response_ok ( )
self . destroy ( )
def on_response_cancel ( self , widget ) :
if self . user_response_cancel :
if isinstance ( self . user_response_cancel , tuple ) :
self . user_response_cancel [ 0 ] ( * self . user_response_ok [ 1 : ] )
else :
self . user_response_cancel ( )
self . destroy ( )
def just_destroy ( self , widget ) :
self . destroy ( )
2005-06-12 19:36:27 +02:00
def get_button ( self , index ) :
buttons = self . action_area . get_children ( )
return index < len ( buttons ) and buttons [ index ] or None
2005-06-07 03:10:24 +02:00
2006-04-07 16:23:21 +02:00
2005-09-09 22:21:14 +02:00
class HigDialog ( gtk . MessageDialog ) :
2008-10-11 12:22:04 +02:00
def __init__ ( self , parent , type_ , buttons , pritext , sectext ,
2009-06-21 03:43:57 +02:00
on_response_ok = None , on_response_cancel = None , on_response_yes = None ,
on_response_no = None ) :
2008-01-22 17:06:16 +01:00
gtk . MessageDialog . __init__ ( self , parent ,
2009-06-21 03:43:57 +02:00
gtk . DIALOG_DESTROY_WITH_PARENT | gtk . DIALOG_MODAL ,
type_ , buttons , message_format = pritext )
2005-09-09 21:42:47 +02:00
2007-12-28 00:33:05 +01:00
self . format_secondary_markup ( sectext )
2005-09-09 21:42:47 +02:00
2006-04-02 18:11:21 +02:00
buttons = self . action_area . get_children ( )
2006-04-07 16:23:21 +02:00
possible_responses = { gtk . STOCK_OK : on_response_ok ,
2009-06-21 03:43:57 +02:00
gtk . STOCK_CANCEL : on_response_cancel , gtk . STOCK_YES : on_response_yes ,
gtk . STOCK_NO : on_response_no }
2006-04-02 18:11:21 +02:00
for b in buttons :
2006-04-07 16:23:21 +02:00
for response in possible_responses :
2006-04-02 18:11:21 +02:00
if b . get_label ( ) == response :
2006-04-07 16:23:21 +02:00
if not possible_responses [ response ] :
2006-04-02 18:11:21 +02:00
b . connect ( ' clicked ' , self . just_destroy )
2006-04-07 16:23:21 +02:00
elif isinstance ( possible_responses [ response ] , tuple ) :
2006-04-08 12:34:47 +02:00
if len ( possible_responses [ response ] ) == 1 :
2006-04-07 16:23:21 +02:00
b . connect ( ' clicked ' , possible_responses [ response ] [ 0 ] )
2006-04-02 18:11:21 +02:00
else :
2006-04-07 16:23:21 +02:00
b . connect ( ' clicked ' , * possible_responses [ response ] )
2006-04-02 18:11:21 +02:00
else :
2006-04-07 16:23:21 +02:00
b . connect ( ' clicked ' , possible_responses [ response ] )
2006-04-02 18:11:21 +02:00
break
2006-04-10 16:45:35 +02:00
2006-04-02 18:11:21 +02:00
def just_destroy ( self , widget ) :
self . destroy ( )
def popup ( self ) :
2006-04-07 16:23:21 +02:00
''' show dialog '''
vb = self . get_children ( ) [ 0 ] . get_children ( ) [ 0 ] # Give focus to top vbox
2006-04-02 18:11:21 +02:00
vb . set_flags ( gtk . CAN_FOCUS )
vb . grab_focus ( )
self . show_all ( )
2006-04-07 16:23:21 +02:00
class FileChooserDialog ( gtk . FileChooserDialog ) :
''' Non-blocking FileChooser Dialog around gtk.FileChooserDialog '''
def __init__ ( self , title_text , action , buttons , default_response ,
2009-06-21 03:43:57 +02:00
select_multiple = False , current_folder = None , on_response_ok = None ,
on_response_cancel = None ) :
2006-04-07 16:23:21 +02:00
2008-09-03 13:25:27 +02:00
gtk . FileChooserDialog . __init__ ( self , title = title_text , action = action ,
2009-06-21 03:43:57 +02:00
buttons = buttons )
2006-04-10 16:45:35 +02:00
2006-04-07 16:23:21 +02:00
self . set_default_response ( default_response )
self . set_select_multiple ( select_multiple )
if current_folder and os . path . isdir ( current_folder ) :
self . set_current_folder ( current_folder )
else :
self . set_current_folder ( helpers . get_documents_path ( ) )
2006-11-18 21:52:28 +01:00
self . response_ok , self . response_cancel = \
on_response_ok , on_response_cancel
# in gtk+-2.10 clicked signal on some of the buttons in a dialog
# is emitted twice, so we cannot rely on 'clicked' signal
self . connect ( ' response ' , self . on_dialog_response )
2006-04-07 16:23:21 +02:00
self . show_all ( )
2006-04-10 16:45:35 +02:00
2006-11-18 21:52:28 +01:00
def on_dialog_response ( self , dialog , response ) :
if response in ( gtk . RESPONSE_CANCEL , gtk . RESPONSE_CLOSE ) :
if self . response_cancel :
if isinstance ( self . response_cancel , tuple ) :
self . response_cancel [ 0 ] ( dialog , * self . response_cancel [ 1 : ] )
else :
self . response_cancel ( dialog )
else :
self . just_destroy ( dialog )
elif response == gtk . RESPONSE_OK :
if self . response_ok :
if isinstance ( self . response_ok , tuple ) :
self . response_ok [ 0 ] ( dialog , * self . response_ok [ 1 : ] )
else :
self . response_ok ( dialog )
else :
self . just_destroy ( dialog )
2007-01-15 11:34:53 +01:00
2006-04-10 16:45:35 +02:00
def just_destroy ( self , widget ) :
self . destroy ( )
2006-04-07 16:23:21 +02:00
2008-05-02 18:15:39 +02:00
class AspellDictError :
2007-06-03 12:04:20 +02:00
def __init__ ( self , lang ) :
ErrorDialog (
_ ( ' Dictionary for lang %s not available ' ) % lang ,
_ ( ' You have to install %s dictionary to use spellchecking, or '
2009-06-21 03:43:57 +02:00
' choose another language by setting the speller_language option. '
' \n \n Highlighting misspelled words feature will not be used ' ) % lang )
2007-06-03 12:04:20 +02:00
gajim . config . set ( ' use_speller ' , False )
2005-09-09 22:21:14 +02:00
class ConfirmationDialog ( HigDialog ) :
2005-10-13 21:44:09 +02:00
''' HIG compliant confirmation dialog. '''
2008-08-06 22:55:40 +02:00
def __init__ ( self , pritext , sectext = ' ' , on_response_ok = None ,
2009-06-21 03:43:57 +02:00
on_response_cancel = None ) :
2007-12-12 09:44:46 +01:00
self . user_response_ok = on_response_ok
self . user_response_cancel = on_response_cancel
2008-01-22 17:06:16 +01:00
HigDialog . __init__ ( self , None ,
2009-06-21 03:43:57 +02:00
gtk . MESSAGE_QUESTION , gtk . BUTTONS_OK_CANCEL , pritext , sectext ,
self . on_response_ok , self . on_response_cancel )
2006-04-02 18:11:21 +02:00
self . popup ( )
2006-04-10 16:45:35 +02:00
2007-12-12 09:44:46 +01:00
def on_response_ok ( self , widget ) :
if self . user_response_ok :
if isinstance ( self . user_response_ok , tuple ) :
self . user_response_ok [ 0 ] ( * self . user_response_ok [ 1 : ] )
else :
self . user_response_ok ( )
self . destroy ( )
def on_response_cancel ( self , widget ) :
if self . user_response_cancel :
if isinstance ( self . user_response_cancel , tuple ) :
self . user_response_cancel [ 0 ] ( * self . user_response_ok [ 1 : ] )
else :
self . user_response_cancel ( )
self . destroy ( )
2006-04-08 19:02:55 +02:00
class NonModalConfirmationDialog ( HigDialog ) :
''' HIG compliant non modal confirmation dialog. '''
2008-09-03 13:25:27 +02:00
def __init__ ( self , pritext , sectext = ' ' , on_response_ok = None ,
2009-06-21 03:43:57 +02:00
on_response_cancel = None ) :
2007-12-12 09:44:46 +01:00
self . user_response_ok = on_response_ok
self . user_response_cancel = on_response_cancel
2008-01-22 17:06:16 +01:00
HigDialog . __init__ ( self , None ,
2009-06-21 03:43:57 +02:00
gtk . MESSAGE_QUESTION , gtk . BUTTONS_OK_CANCEL , pritext , sectext ,
self . on_response_ok , self . on_response_cancel )
2006-04-08 19:02:55 +02:00
self . set_modal ( False )
2006-02-21 12:21:58 +01:00
2007-12-12 09:44:46 +01:00
def on_response_ok ( self , widget ) :
if self . user_response_ok :
if isinstance ( self . user_response_ok , tuple ) :
self . user_response_ok [ 0 ] ( * self . user_response_ok [ 1 : ] )
else :
self . user_response_ok ( )
self . destroy ( )
def on_response_cancel ( self , widget ) :
if self . user_response_cancel :
if isinstance ( self . user_response_cancel , tuple ) :
self . user_response_cancel [ 0 ] ( * self . user_response_cancel [ 1 : ] )
else :
self . user_response_cancel ( )
self . destroy ( )
2005-09-09 22:21:14 +02:00
class WarningDialog ( HigDialog ) :
2005-09-09 21:42:47 +02:00
def __init__ ( self , pritext , sectext = ' ' ) :
2005-10-13 21:44:09 +02:00
''' HIG compliant warning dialog. '''
2008-01-22 17:06:16 +01:00
HigDialog . __init__ ( self , None ,
2009-06-21 03:43:57 +02:00
gtk . MESSAGE_WARNING , gtk . BUTTONS_OK , pritext , sectext )
2007-03-14 14:31:50 +01:00
self . set_modal ( False )
2009-08-28 20:42:48 +02:00
if hasattr ( gajim . interface , ' roster ' ) :
self . set_transient_for ( gajim . interface . roster . window )
2006-04-02 18:11:21 +02:00
self . popup ( )
2005-09-09 21:42:47 +02:00
2005-09-09 22:21:14 +02:00
class InformationDialog ( HigDialog ) :
2005-09-09 21:42:47 +02:00
def __init__ ( self , pritext , sectext = ' ' ) :
2005-10-13 21:44:09 +02:00
''' HIG compliant info dialog. '''
2008-10-02 22:20:15 +02:00
HigDialog . __init__ ( self , None ,
2009-06-21 03:43:57 +02:00
gtk . MESSAGE_INFO , gtk . BUTTONS_OK , pritext , sectext )
2007-03-14 14:31:50 +01:00
self . set_modal ( False )
self . set_transient_for ( gajim . interface . roster . window )
2006-04-02 18:11:21 +02:00
self . popup ( )
2005-09-09 21:42:47 +02:00
2005-09-09 22:21:14 +02:00
class ErrorDialog ( HigDialog ) :
2005-09-09 21:42:47 +02:00
def __init__ ( self , pritext , sectext = ' ' ) :
2005-10-13 21:44:09 +02:00
''' HIG compliant error dialog. '''
2008-01-22 17:06:16 +01:00
HigDialog . __init__ ( self , None ,
2009-06-21 03:43:57 +02:00
gtk . MESSAGE_ERROR , gtk . BUTTONS_OK , pritext , sectext )
2006-04-02 18:11:21 +02:00
self . popup ( )
2005-09-09 21:42:47 +02:00
2006-02-06 22:35:54 +01:00
class YesNoDialog ( HigDialog ) :
2008-02-04 22:38:36 +01:00
def __init__ ( self , pritext , sectext = ' ' , checktext = ' ' , on_response_yes = None ,
2009-06-21 03:43:57 +02:00
on_response_no = None ) :
2006-02-06 22:35:54 +01:00
''' HIG compliant YesNo dialog. '''
2008-01-22 17:06:16 +01:00
self . user_response_yes = on_response_yes
self . user_response_no = on_response_no
HigDialog . __init__ ( self , None ,
2009-06-21 03:43:57 +02:00
gtk . MESSAGE_QUESTION , gtk . BUTTONS_YES_NO , pritext , sectext ,
on_response_yes = self . on_response_yes ,
on_response_no = self . on_response_no )
2008-02-04 22:38:36 +01:00
if checktext :
self . checkbutton = gtk . CheckButton ( checktext )
self . vbox . pack_start ( self . checkbutton , expand = False , fill = True )
else :
self . checkbutton = None
2007-12-12 09:44:46 +01:00
self . set_modal ( False )
2006-04-06 13:04:41 +02:00
self . popup ( )
2006-02-06 22:35:54 +01:00
2008-01-22 17:06:16 +01:00
def on_response_yes ( self , widget ) :
if self . user_response_yes :
if isinstance ( self . user_response_yes , tuple ) :
2008-02-04 22:38:36 +01:00
self . user_response_yes [ 0 ] ( self . is_checked ( ) ,
2009-06-21 03:43:57 +02:00
* self . user_response_yes [ 1 : ] )
2008-01-22 17:06:16 +01:00
else :
2008-02-04 22:38:36 +01:00
self . user_response_yes ( self . is_checked ( ) )
2008-01-22 17:06:16 +01:00
self . destroy ( )
def on_response_no ( self , widget ) :
if self . user_response_no :
if isinstance ( self . user_response_no , tuple ) :
self . user_response_no [ 0 ] ( * self . user_response_no [ 1 : ] )
else :
self . user_response_no ( )
self . destroy ( )
2008-02-04 22:38:36 +01:00
def is_checked ( self ) :
''' Get active state of the checkbutton '''
if not self . checkbutton :
return False
return self . checkbutton . get_active ( )
2008-01-22 17:06:16 +01:00
2005-07-29 19:18:51 +02:00
class ConfirmationDialogCheck ( ConfirmationDialog ) :
''' HIG compliant confirmation dialog with checkbutton. '''
2008-09-03 13:25:27 +02:00
def __init__ ( self , pritext , sectext = ' ' , checktext = ' ' ,
2009-06-21 03:43:57 +02:00
on_response_ok = None , on_response_cancel = None , is_modal = True ) :
2007-12-12 09:44:46 +01:00
self . user_response_ok = on_response_ok
self . user_response_cancel = on_response_cancel
2006-04-02 18:11:21 +02:00
HigDialog . __init__ ( self , None , gtk . MESSAGE_QUESTION ,
2009-06-21 03:43:57 +02:00
gtk . BUTTONS_OK_CANCEL , pritext , sectext , self . on_response_ok ,
self . on_response_cancel )
2005-09-11 16:21:14 +02:00
self . set_default_response ( gtk . RESPONSE_OK )
2006-02-21 12:21:58 +01:00
2005-09-11 20:05:18 +02:00
ok_button = self . action_area . get_children ( ) [ 0 ] # right to left
ok_button . grab_focus ( )
2006-02-21 12:21:58 +01:00
2005-07-29 19:18:51 +02:00
self . checkbutton = gtk . CheckButton ( checktext )
2008-09-03 13:25:27 +02:00
self . vbox . pack_start ( self . checkbutton , expand = False , fill = True )
2007-12-12 09:44:46 +01:00
self . set_modal ( is_modal )
2006-04-04 16:49:56 +02:00
self . popup ( )
2006-02-21 12:21:58 +01:00
2007-12-12 09:44:46 +01:00
# XXX should cancel if somebody closes the dialog
def on_response_ok ( self , widget ) :
if self . user_response_ok :
if isinstance ( self . user_response_ok , tuple ) :
self . user_response_ok [ 0 ] ( self . is_checked ( ) ,
2009-06-21 03:43:57 +02:00
* self . user_response_ok [ 1 : ] )
2007-12-12 09:44:46 +01:00
else :
self . user_response_ok ( self . is_checked ( ) )
self . destroy ( )
def on_response_cancel ( self , widget ) :
if self . user_response_cancel :
if isinstance ( self . user_response_cancel , tuple ) :
2008-08-08 17:19:08 +02:00
self . user_response_cancel [ 0 ] ( self . is_checked ( ) ,
2009-06-21 03:43:57 +02:00
* self . user_response_cancel [ 1 : ] )
2007-12-12 09:44:46 +01:00
else :
2008-08-08 17:19:08 +02:00
self . user_response_cancel ( self . is_checked ( ) )
2007-12-12 09:44:46 +01:00
self . destroy ( )
2005-07-29 19:18:51 +02:00
def is_checked ( self ) :
''' Get active state of the checkbutton '''
return self . checkbutton . get_active ( )
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
2008-02-15 11:11:17 +01:00
class ConfirmationDialogDubbleCheck ( ConfirmationDialog ) :
''' HIG compliant confirmation dialog with 2 checkbuttons. '''
2008-09-03 13:25:27 +02:00
def __init__ ( self , pritext , sectext = ' ' , checktext1 = ' ' , checktext2 = ' ' ,
2009-06-21 03:43:57 +02:00
on_response_ok = None , on_response_cancel = None , is_modal = True ) :
2008-02-15 11:11:17 +01:00
self . user_response_ok = on_response_ok
self . user_response_cancel = on_response_cancel
HigDialog . __init__ ( self , None , gtk . MESSAGE_QUESTION ,
2009-06-21 03:43:57 +02:00
gtk . BUTTONS_OK_CANCEL , pritext , sectext , self . on_response_ok ,
self . on_response_cancel )
2008-02-15 11:11:17 +01:00
self . set_default_response ( gtk . RESPONSE_OK )
ok_button = self . action_area . get_children ( ) [ 0 ] # right to left
ok_button . grab_focus ( )
if checktext1 :
self . checkbutton1 = gtk . CheckButton ( checktext1 )
2008-09-03 13:25:27 +02:00
self . vbox . pack_start ( self . checkbutton1 , expand = False , fill = True )
2008-02-15 11:11:17 +01:00
else :
self . checkbutton1 = None
if checktext2 :
self . checkbutton2 = gtk . CheckButton ( checktext2 )
2008-09-03 13:25:27 +02:00
self . vbox . pack_start ( self . checkbutton2 , expand = False , fill = True )
2008-02-15 11:11:17 +01:00
else :
self . checkbutton2 = None
self . set_modal ( is_modal )
self . popup ( )
# XXX should cancel if somebody closes the dialog
def on_response_ok ( self , widget ) :
if self . user_response_ok :
if isinstance ( self . user_response_ok , tuple ) :
self . user_response_ok [ 0 ] ( self . is_checked ( ) ,
2009-06-21 03:43:57 +02:00
* self . user_response_ok [ 1 : ] )
2008-02-15 11:11:17 +01:00
else :
self . user_response_ok ( self . is_checked ( ) )
self . destroy ( )
def on_response_cancel ( self , widget ) :
if self . user_response_cancel :
if isinstance ( self . user_response_cancel , tuple ) :
self . user_response_cancel [ 0 ] ( * self . user_response_cancel [ 1 : ] )
else :
self . user_response_cancel ( )
self . destroy ( )
def is_checked ( self ) :
''' Get active state of the checkbutton '''
if self . checkbutton1 :
is_checked_1 = self . checkbutton1 . get_active ( )
else :
is_checked_1 = False
if self . checkbutton2 :
is_checked_2 = self . checkbutton2 . get_active ( )
else :
is_checked_2 = False
return [ is_checked_1 , is_checked_2 ]
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
class FTOverwriteConfirmationDialog ( ConfirmationDialog ) :
''' HIG compliant confirmation dialog to overwrite or resume a file transfert '''
2008-08-07 15:27:36 +02:00
def __init__ ( self , pritext , sectext = ' ' , propose_resume = True ,
2009-06-21 03:43:57 +02:00
on_response = None ) :
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
HigDialog . __init__ ( self , None , gtk . MESSAGE_QUESTION , gtk . BUTTONS_CANCEL ,
2009-06-21 03:43:57 +02:00
pritext , sectext )
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
2008-08-07 15:27:36 +02:00
self . on_response = on_response
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
if propose_resume :
b = gtk . Button ( ' ' , gtk . STOCK_REFRESH )
align = b . get_children ( ) [ 0 ]
hbox = align . get_children ( ) [ 0 ]
label = hbox . get_children ( ) [ 1 ]
label . set_text ( ' _Resume ' )
label . set_use_underline ( True )
self . add_action_widget ( b , 100 )
b = gtk . Button ( ' ' , gtk . STOCK_SAVE_AS )
align = b . get_children ( ) [ 0 ]
hbox = align . get_children ( ) [ 0 ]
label = hbox . get_children ( ) [ 1 ]
label . set_text ( ' Re_place ' )
label . set_use_underline ( True )
self . add_action_widget ( b , 200 )
2008-08-07 15:27:36 +02:00
self . connect ( ' response ' , self . on_dialog_response )
self . show_all ( )
2008-08-07 15:25:25 +02:00
2008-08-07 15:27:36 +02:00
def on_dialog_response ( self , dialog , response ) :
if self . on_response :
if isinstance ( self . on_response , tuple ) :
self . on_response [ 0 ] ( response , * self . on_response [ 1 : ] )
2008-08-07 15:25:25 +02:00
else :
2008-08-07 15:27:36 +02:00
self . on_response ( response )
2008-08-07 15:25:25 +02:00
self . destroy ( )
2008-04-18 21:15:03 +02:00
class CommonInputDialog :
2008-04-28 20:19:25 +02:00
''' Common Class for Input dialogs '''
2008-04-18 21:15:03 +02:00
def __init__ ( self , title , label_str , is_modal , ok_handler , cancel_handler ) :
2006-05-08 23:16:38 +02:00
self . dialog = self . xml . get_widget ( ' input_dialog ' )
label = self . xml . get_widget ( ' label ' )
2005-05-14 03:29:53 +02:00
self . dialog . set_title ( title )
2006-01-19 14:52:02 +01:00
label . set_markup ( label_str )
2006-11-19 20:45:43 +01:00
self . cancel_handler = cancel_handler
2009-07-17 09:53:15 +02:00
self . vbox = self . xml . get_widget ( ' vbox ' )
2007-01-15 11:34:53 +01:00
2008-08-07 23:59:20 +02:00
self . ok_handler = ok_handler
okbutton = self . xml . get_widget ( ' okbutton ' )
okbutton . connect ( ' clicked ' , self . on_okbutton_clicked )
cancelbutton = self . xml . get_widget ( ' cancelbutton ' )
cancelbutton . connect ( ' clicked ' , self . on_cancelbutton_clicked )
self . xml . signal_autoconnect ( self )
self . dialog . show_all ( )
2005-07-25 09:47:05 +02:00
2009-07-17 09:53:15 +02:00
def on_input_dialog_delete_event ( self , widget , event ) :
2006-11-19 20:45:43 +01:00
if self . cancel_handler :
self . cancel_handler ( )
def on_okbutton_clicked ( self , widget ) :
2008-04-18 21:15:03 +02:00
user_input = self . get_text ( )
2008-08-07 23:57:19 +02:00
if user_input :
user_input = user_input . decode ( ' utf-8 ' )
2007-08-09 17:39:18 +02:00
self . cancel_handler = None
2005-06-19 01:44:33 +02:00
self . dialog . destroy ( )
2006-11-19 20:45:43 +01:00
if isinstance ( self . ok_handler , tuple ) :
self . ok_handler [ 0 ] ( user_input , * self . ok_handler [ 1 : ] )
else :
self . ok_handler ( user_input )
2007-01-15 11:34:53 +01:00
2006-11-19 20:45:43 +01:00
def on_cancelbutton_clicked ( self , widget ) :
2005-07-25 16:21:01 +02:00
self . dialog . destroy ( )
2005-07-25 09:47:05 +02:00
2008-04-18 21:15:03 +02:00
class InputDialog ( CommonInputDialog ) :
''' Class for Input dialog '''
2008-08-08 00:08:08 +02:00
def __init__ ( self , title , label_str , input_str = None , is_modal = True ,
2009-07-17 09:53:15 +02:00
ok_handler = None , cancel_handler = None ) :
2008-04-18 21:15:03 +02:00
self . xml = gtkgui_helpers . get_glade ( ' input_dialog.glade ' )
CommonInputDialog . __init__ ( self , title , label_str , is_modal , ok_handler ,
2009-07-17 09:53:15 +02:00
cancel_handler )
self . input_entry = self . xml . get_widget ( ' input_entry ' )
if input_str :
self . set_entry ( input_str )
def set_entry ( self , value ) :
self . input_entry . set_text ( value )
self . input_entry . select_region ( 0 , - 1 ) # select all
def get_text ( self ) :
return self . input_entry . get_text ( ) . decode ( ' utf-8 ' )
class InputDialogCheck ( InputDialog ) :
''' Class for Input dialog '''
def __init__ ( self , title , label_str , checktext = ' ' , input_str = None ,
is_modal = True , ok_handler = None , cancel_handler = None ) :
self . xml = gtkgui_helpers . get_glade ( ' input_dialog.glade ' )
InputDialog . __init__ ( self , title , label_str , input_str = input_str ,
is_modal = is_modal , ok_handler = ok_handler ,
cancel_handler = cancel_handler )
2008-04-18 21:15:03 +02:00
self . input_entry = self . xml . get_widget ( ' input_entry ' )
if input_str :
self . input_entry . set_text ( input_str )
self . input_entry . select_region ( 0 , - 1 ) # select all
2009-07-21 00:30:43 +02:00
if checktext :
self . checkbutton = gtk . CheckButton ( checktext )
self . vbox . pack_start ( self . checkbutton , expand = False , fill = True )
self . checkbutton . show ( )
2009-07-17 09:53:15 +02:00
def on_okbutton_clicked ( self , widget ) :
user_input = self . get_text ( )
if user_input :
user_input = user_input . decode ( ' utf-8 ' )
self . cancel_handler = None
self . dialog . destroy ( )
if isinstance ( self . ok_handler , tuple ) :
self . ok_handler [ 0 ] ( user_input , self . is_checked ( ) , * self . ok_handler [ 1 : ] )
else :
self . ok_handler ( user_input , self . is_checked ( ) )
2008-04-18 21:15:03 +02:00
def get_text ( self ) :
return self . input_entry . get_text ( ) . decode ( ' utf-8 ' )
2009-07-17 09:53:15 +02:00
def is_checked ( self ) :
''' Get active state of the checkbutton '''
2009-07-21 00:30:43 +02:00
try :
return self . checkbutton . get_active ( )
except Exception :
# There is no checkbutton
return False
2009-07-17 09:53:15 +02:00
class ChangeNickDialog ( InputDialogCheck ) :
''' Class for changing room nickname in case of conflict '''
2009-07-21 00:30:43 +02:00
def __init__ ( self , account , room_jid , title , prompt , check_text = None ) :
2009-07-17 09:53:15 +02:00
InputDialogCheck . __init__ ( self , title , ' ' , checktext = check_text ,
input_str = ' ' , is_modal = True , ok_handler = None , cancel_handler = None )
2009-07-21 00:30:43 +02:00
self . room_queue = [ ( account , room_jid , prompt ) ]
2009-07-17 09:53:15 +02:00
self . check_next ( )
def on_input_dialog_delete_event ( self , widget , event ) :
self . on_cancelbutton_clicked ( widget )
return True
def setup_dialog ( self ) :
self . gc_control = gajim . interface . msg_win_mgr . get_gc_control (
self . room_jid , self . account )
if not self . gc_control and \
self . room_jid in gajim . interface . minimized_controls [ self . account ] :
self . gc_control = \
gajim . interface . minimized_controls [ self . account ] [ self . room_jid ]
if not self . gc_control :
self . check_next ( )
return
label = self . xml . get_widget ( ' label ' )
2009-07-21 00:30:43 +02:00
label . set_markup ( self . prompt )
2009-07-17 09:53:15 +02:00
self . set_entry ( self . gc_control . nick + \
gajim . config . get ( ' gc_proposed_nick_char ' ) )
def check_next ( self ) :
if len ( self . room_queue ) == 0 :
self . cancel_handler = None
self . dialog . destroy ( )
2009-09-16 16:14:03 +02:00
if ' change_nick_dialog ' in gajim . interface . instances :
del gajim . interface . instances [ ' change_nick_dialog ' ]
2009-07-17 09:53:15 +02:00
return
2009-07-21 00:30:43 +02:00
self . account , self . room_jid , self . prompt = self . room_queue . pop ( 0 )
2009-07-17 09:53:15 +02:00
self . setup_dialog ( )
if gajim . new_room_nick is not None and not gajim . gc_connected [
self . account ] [ self . room_jid ] and self . gc_control . nick != \
gajim . new_room_nick :
self . dialog . hide ( )
self . on_ok ( gajim . new_room_nick , True )
else :
self . dialog . show ( )
def on_okbutton_clicked ( self , widget ) :
nick = self . get_text ( )
if nick :
nick = nick . decode ( ' utf-8 ' )
# send presence to room
try :
nick = helpers . parse_resource ( nick )
except Exception :
# invalid char
dialogs . ErrorDialog ( _ ( ' Invalid nickname ' ) ,
_ ( ' The nickname has not allowed characters. ' ) )
return
self . on_ok ( nick , self . is_checked ( ) )
def on_ok ( self , nick , is_checked ) :
if is_checked :
gajim . new_room_nick = nick
gajim . connections [ self . account ] . join_gc ( nick , self . room_jid , None ,
change_nick = True )
if gajim . gc_connected [ self . account ] [ self . room_jid ] :
# We are changing nick, we will change self.nick when we receive
# presence that inform that it works
self . gc_control . new_nick = nick
else :
# We are connecting, we will not get a changed nick presence so
# change it NOW. We don't already have a nick so it's harmless
self . gc_control . nick = nick
self . check_next ( )
def on_cancelbutton_clicked ( self , widget ) :
self . gc_control . new_nick = ' '
self . check_next ( )
2009-08-05 17:35:27 +02:00
def add_room ( self , account , room_jid , prompt ) :
2009-07-21 00:30:43 +02:00
if ( account , room_jid , prompt ) not in self . room_queue :
self . room_queue . append ( ( account , room_jid , prompt ) )
2009-07-17 09:53:15 +02:00
2008-04-18 21:15:03 +02:00
class InputTextDialog ( CommonInputDialog ) :
2008-04-28 20:19:25 +02:00
''' Class for multilines Input dialog (more place than InputDialog) '''
2008-08-08 00:08:08 +02:00
def __init__ ( self , title , label_str , input_str = None , is_modal = True ,
2009-06-21 03:43:57 +02:00
ok_handler = None , cancel_handler = None ) :
2008-04-18 21:15:03 +02:00
self . xml = gtkgui_helpers . get_glade ( ' input_text_dialog.glade ' )
CommonInputDialog . __init__ ( self , title , label_str , is_modal , ok_handler ,
2009-06-21 03:43:57 +02:00
cancel_handler )
2008-04-18 21:15:03 +02:00
self . input_buffer = self . xml . get_widget ( ' input_textview ' ) . get_buffer ( )
if input_str :
self . input_buffer . set_text ( input_str )
start_iter , end_iter = self . input_buffer . get_bounds ( )
self . input_buffer . select_range ( start_iter , end_iter ) # select all
def get_text ( self ) :
start_iter , end_iter = self . input_buffer . get_bounds ( )
return self . input_buffer . get_text ( start_iter , end_iter ) . decode ( ' utf-8 ' )
2007-03-11 21:14:53 +01:00
class DubbleInputDialog :
''' Class for Dubble Input dialog '''
2008-08-08 00:08:08 +02:00
def __init__ ( self , title , label_str1 , label_str2 , input_str1 = None ,
2009-06-21 03:43:57 +02:00
input_str2 = None , is_modal = True , ok_handler = None , cancel_handler = None ) :
2007-03-11 21:14:53 +01:00
self . xml = gtkgui_helpers . get_glade ( ' dubbleinput_dialog.glade ' )
self . dialog = self . xml . get_widget ( ' dubbleinput_dialog ' )
label1 = self . xml . get_widget ( ' label1 ' )
self . input_entry1 = self . xml . get_widget ( ' input_entry1 ' )
label2 = self . xml . get_widget ( ' label2 ' )
self . input_entry2 = self . xml . get_widget ( ' input_entry2 ' )
self . dialog . set_title ( title )
label1 . set_markup ( label_str1 )
label2 . set_markup ( label_str2 )
self . cancel_handler = cancel_handler
if input_str1 :
self . input_entry1 . set_text ( input_str1 )
self . input_entry1 . select_region ( 0 , - 1 ) # select all
if input_str2 :
self . input_entry2 . set_text ( input_str2 )
self . input_entry2 . select_region ( 0 , - 1 ) # select all
2008-08-11 10:47:06 +02:00
self . dialog . set_modal ( is_modal )
self . ok_handler = ok_handler
okbutton = self . xml . get_widget ( ' okbutton ' )
okbutton . connect ( ' clicked ' , self . on_okbutton_clicked )
cancelbutton = self . xml . get_widget ( ' cancelbutton ' )
cancelbutton . connect ( ' clicked ' , self . on_cancelbutton_clicked )
self . xml . signal_autoconnect ( self )
self . dialog . show_all ( )
2007-03-11 21:14:53 +01:00
def on_dubbleinput_dialog_destroy ( self , widget ) :
2008-08-29 09:37:55 +02:00
if not self . cancel_handler :
2008-08-11 10:47:06 +02:00
return False
if isinstance ( self . cancel_handler , tuple ) :
self . cancel_handler [ 0 ] ( * self . cancel_handler [ 1 : ] )
else :
2007-03-11 21:14:53 +01:00
self . cancel_handler ( )
def on_okbutton_clicked ( self , widget ) :
user_input1 = self . input_entry1 . get_text ( ) . decode ( ' utf-8 ' )
user_input2 = self . input_entry2 . get_text ( ) . decode ( ' utf-8 ' )
self . dialog . destroy ( )
2008-08-29 09:37:55 +02:00
if not self . ok_handler :
2008-08-11 10:47:06 +02:00
return
2007-03-11 21:14:53 +01:00
if isinstance ( self . ok_handler , tuple ) :
self . ok_handler [ 0 ] ( user_input1 , user_input2 , * self . ok_handler [ 1 : ] )
else :
self . ok_handler ( user_input1 , user_input2 )
def on_cancelbutton_clicked ( self , widget ) :
self . dialog . destroy ( )
2008-10-24 14:10:05 +02:00
if not self . cancel_handler :
2008-08-11 10:47:06 +02:00
return
if isinstance ( self . cancel_handler , tuple ) :
self . cancel_handler [ 0 ] ( * self . cancel_handler [ 1 : ] )
else :
self . cancel_handler ( )
2007-03-11 21:14:53 +01:00
2005-06-13 12:48:07 +02:00
class SubscriptionRequestWindow :
2008-08-08 00:08:08 +02:00
def __init__ ( self , jid , text , account , user_nick = None ) :
2006-05-02 17:53:25 +02:00
xml = gtkgui_helpers . get_glade ( ' subscription_request_window.glade ' )
2005-04-12 17:30:09 +02:00
self . window = xml . get_widget ( ' subscription_request_window ' )
2005-04-04 18:46:35 +02:00
self . jid = jid
self . account = account
2006-06-01 17:23:38 +02:00
self . user_nick = user_nick
2005-06-13 15:26:04 +02:00
if len ( gajim . connections ) > = 2 :
2008-08-01 11:30:36 +02:00
prompt_text = \
2009-06-21 03:43:57 +02:00
_ ( ' Subscription request for account %(account)s from %(jid)s ' ) \
% { ' account ' : account , ' jid ' : self . jid }
2005-06-13 15:26:04 +02:00
else :
prompt_text = _ ( ' Subscription request from %s ' ) % self . jid
xml . get_widget ( ' from_label ' ) . set_text ( prompt_text )
2005-04-04 18:46:35 +02:00
xml . get_widget ( ' message_textview ' ) . get_buffer ( ) . set_text ( text )
xml . signal_autoconnect ( self )
self . window . show_all ( )
2006-11-18 21:52:28 +01:00
def prepare_popup_menu ( self ) :
xml = gtkgui_helpers . get_glade ( ' subscription_request_popup_menu.glade ' )
menu = xml . get_widget ( ' subscription_request_popup_menu ' )
xml . signal_autoconnect ( self )
return menu
2005-03-01 15:02:32 +01:00
def on_close_button_clicked ( self , widget ) :
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2007-01-15 11:34:53 +01:00
2005-03-01 15:02:32 +01:00
def on_authorize_button_clicked ( self , widget ) :
2005-05-16 15:56:46 +02:00
''' accept the request '''
2005-04-14 11:38:08 +02:00
gajim . connections [ self . account ] . send_authorization ( self . jid )
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2009-04-08 18:49:09 +02:00
contact = gajim . contacts . get_contact ( self . account , self . jid )
if not contact or _ ( ' Not in Roster ' ) in contact . groups :
2006-06-01 17:23:38 +02:00
AddNewContactWindow ( self . account , self . jid , self . user_nick )
2005-05-18 10:47:38 +02:00
2006-11-18 21:52:28 +01:00
def on_contact_info_activate ( self , widget ) :
2005-05-18 10:47:38 +02:00
''' ask vcard '''
2008-10-07 22:41:59 +02:00
if self . jid in gajim . interface . instances [ self . account ] [ ' infos ' ] :
2005-11-13 16:08:47 +01:00
gajim . interface . instances [ self . account ] [ ' infos ' ] [ self . jid ] . window . present ( )
2005-05-18 10:47:38 +02:00
else :
2009-11-05 22:16:38 +01:00
contact = gajim . contacts . create_contact ( jid = self . jid , account = self . account )
2005-11-13 16:08:47 +01:00
gajim . interface . instances [ self . account ] [ ' infos ' ] [ self . jid ] = \
2009-06-21 03:43:57 +02:00
vcard . VcardWindow ( contact , self . account )
2006-02-20 22:30:45 +01:00
# Remove jabber page
gajim . interface . instances [ self . account ] [ ' infos ' ] [ self . jid ] . xml . \
2009-06-21 03:43:57 +02:00
get_widget ( ' information_notebook ' ) . remove_page ( 0 )
2007-01-15 11:34:53 +01:00
2006-11-18 21:52:28 +01:00
def on_start_chat_activate ( self , widget ) :
''' open chat '''
2008-04-20 20:14:04 +02:00
gajim . interface . new_chat_from_jid ( self . account , self . jid )
2006-11-18 21:52:28 +01:00
2005-03-01 15:02:32 +01:00
def on_deny_button_clicked ( self , widget ) :
2005-04-18 14:17:43 +02:00
''' refuse the request '''
2005-04-14 11:38:08 +02:00
gajim . connections [ self . account ] . refuse_authorization ( self . jid )
2009-02-13 20:35:30 +01:00
contact = gajim . contacts . get_contact ( self . account , self . jid )
if contact and _ ( ' Not in Roster ' ) in contact . get_shown_groups ( ) :
gajim . interface . roster . remove_contact ( self . jid , self . account )
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2005-04-04 18:46:35 +02:00
2006-11-18 21:52:28 +01:00
def on_actions_button_clicked ( self , widget ) :
''' popup action menu '''
menu = self . prepare_popup_menu ( )
menu . show_all ( )
gtkgui_helpers . popup_emoticons_under_button ( menu , widget , self . window . window )
2005-06-10 23:14:16 +02:00
class JoinGroupchatWindow :
2009-09-02 23:45:16 +02:00
def __init__ ( self , account = None , room_jid = ' ' , nick = ' ' , password = ' ' ,
2009-06-21 03:43:57 +02:00
automatic = False ) :
2006-09-13 18:47:58 +02:00
''' automatic is a dict like { ' invities ' : []}
If automatic is not empty , this means room must be automaticaly configured
and when done , invities must be automatically invited '''
2009-10-31 19:35:46 +01:00
2009-09-02 23:45:16 +02:00
if account :
if room_jid != ' ' and room_jid in gajim . gc_connected [ account ] and \
gajim . gc_connected [ account ] [ room_jid ] :
2006-11-18 21:52:28 +01:00
ErrorDialog ( _ ( ' You are already in group chat %s ' ) % room_jid )
raise GajimGeneralException , ' You are already in this group chat '
2009-09-02 23:45:16 +02:00
if nick == ' ' :
nick = gajim . nicks [ account ]
if gajim . connections [ account ] . connected < 2 :
ErrorDialog ( _ ( ' You are not connected to the server ' ) ,
_ ( ' You can not join a group chat unless you are connected. ' ) )
raise GajimGeneralException , ' You must be connected to join a groupchat '
2009-10-31 19:35:46 +01:00
self . xml = gtkgui_helpers . get_glade ( ' join_groupchat_window.glade ' )
account_label = self . xml . get_widget ( ' account_label ' )
account_combobox = self . xml . get_widget ( ' account_combobox ' )
account_label . set_no_show_all ( False )
account_combobox . set_no_show_all ( False )
liststore = gtk . ListStore ( str )
account_combobox . set_model ( liststore )
cell = gtk . CellRendererText ( )
account_combobox . pack_start ( cell , True )
account_combobox . add_attribute ( cell , ' text ' , 0 )
account_combobox . set_active ( - 1 )
# Add accounts, set current as active if it matches 'account'
for acct in [ a for a in gajim . connections if \
gajim . account_is_connected ( a ) ] :
account_combobox . append_text ( acct )
if account and account == acct :
account_combobox . set_active ( liststore . iter_n_children ( None ) - 1 )
2005-04-21 20:53:16 +02:00
self . account = account
2006-09-13 18:47:58 +02:00
self . automatic = automatic
2006-01-18 03:16:49 +01:00
self . _empty_required_widgets = [ ]
2005-04-04 18:46:35 +02:00
self . window = self . xml . get_widget ( ' join_groupchat_window ' )
2006-11-18 21:52:28 +01:00
self . _room_jid_entry = self . xml . get_widget ( ' room_jid_entry ' )
self . _nickname_entry = self . xml . get_widget ( ' nickname_entry ' )
2007-08-09 17:39:18 +02:00
self . _password_entry = self . xml . get_widget ( ' password_entry ' )
2007-01-15 11:34:53 +01:00
2006-11-18 21:52:28 +01:00
self . _room_jid_entry . set_text ( room_jid )
self . _nickname_entry . set_text ( nick )
2007-08-09 17:39:18 +02:00
if password :
self . _password_entry . set_text ( password )
2005-04-04 18:46:35 +02:00
self . xml . signal_autoconnect ( self )
2009-09-02 23:45:16 +02:00
title = None
if account :
# now add us to open windows
gajim . interface . instances [ account ] [ ' join_gc ' ] = self
if len ( gajim . connections ) > 1 :
title = _ ( ' Join Group Chat with account %s ' ) % account
if title is None :
2005-08-02 00:48:58 +02:00
title = _ ( ' Join Group Chat ' )
2005-04-21 20:53:16 +02:00
self . window . set_title ( title )
2005-04-07 00:52:48 +02:00
self . recently_combobox = self . xml . get_widget ( ' recently_combobox ' )
liststore = gtk . ListStore ( str )
self . recently_combobox . set_model ( liststore )
cell = gtk . CellRendererText ( )
self . recently_combobox . pack_start ( cell , True )
self . recently_combobox . add_attribute ( cell , ' text ' , 0 )
2005-04-12 23:09:06 +02:00
self . recently_groupchat = gajim . config . get ( ' recently_groupchat ' ) . split ( )
2005-04-07 00:52:48 +02:00
for g in self . recently_groupchat :
self . recently_combobox . append_text ( g )
2005-11-25 23:28:51 +01:00
if len ( self . recently_groupchat ) == 0 :
self . recently_combobox . set_sensitive ( False )
2006-11-18 21:52:28 +01:00
elif room_jid == ' ' :
2005-06-10 14:31:06 +02:00
self . recently_combobox . set_active ( 0 )
2006-11-18 21:52:28 +01:00
self . _room_jid_entry . select_region ( 0 , - 1 )
elif room_jid != ' ' :
2005-11-25 23:45:58 +01:00
self . xml . get_widget ( ' join_button ' ) . grab_focus ( )
2005-04-07 00:52:48 +02:00
2006-11-18 21:52:28 +01:00
if not self . _room_jid_entry . get_text ( ) :
self . _empty_required_widgets . append ( self . _room_jid_entry )
2006-01-14 22:59:59 +01:00
if not self . _nickname_entry . get_text ( ) :
self . _empty_required_widgets . append ( self . _nickname_entry )
if len ( self . _empty_required_widgets ) :
self . xml . get_widget ( ' join_button ' ) . set_sensitive ( False )
2009-09-02 23:45:16 +02:00
if account and not gajim . connections [ account ] . private_storage_supported :
2009-10-05 15:29:37 +02:00
self . xml . get_widget ( ' bookmark_checkbutton ' ) . set_sensitive ( False )
2007-12-12 09:44:46 +01:00
2005-04-04 17:51:29 +02:00
self . window . show_all ( )
2005-03-02 00:48:05 +01:00
2005-03-02 13:32:44 +01:00
def on_join_groupchat_window_destroy ( self , widget ) :
2005-04-18 14:17:43 +02:00
''' close window '''
2009-09-02 23:45:16 +02:00
if self . account and ' join_gc ' in gajim . interface . instances [ self . account ] :
# remove us from open windows
del gajim . interface . instances [ self . account ] [ ' join_gc ' ]
2005-03-02 00:48:05 +01:00
2005-04-07 11:53:54 +02:00
def on_join_groupchat_window_key_press_event ( self , widget , event ) :
if event . keyval == gtk . keysyms . Escape : # ESCAPE
widget . destroy ( )
2006-01-14 22:59:59 +01:00
def on_required_entry_changed ( self , widget ) :
if not widget . get_text ( ) :
self . _empty_required_widgets . append ( widget )
self . xml . get_widget ( ' join_button ' ) . set_sensitive ( False )
else :
if widget in self . _empty_required_widgets :
self . _empty_required_widgets . remove ( widget )
2009-09-02 23:45:16 +02:00
if len ( self . _empty_required_widgets ) == 0 and self . account :
self . xml . get_widget ( ' join_button ' ) . set_sensitive ( True )
def on_account_combobox_changed ( self , widget ) :
model = widget . get_model ( )
iter_ = widget . get_active_iter ( )
self . account = model [ iter_ ] [ 0 ] . decode ( ' utf-8 ' )
self . on_required_entry_changed ( self . _nickname_entry )
2006-01-14 22:59:59 +01:00
2005-04-07 00:52:48 +02:00
def on_recently_combobox_changed ( self , widget ) :
model = widget . get_model ( )
2006-11-18 21:52:28 +01:00
iter_ = widget . get_active_iter ( )
room_jid = model [ iter_ ] [ 0 ] . decode ( ' utf-8 ' )
self . _room_jid_entry . set_text ( room_jid )
2005-04-07 00:52:48 +02:00
2005-03-04 14:41:48 +01:00
def on_cancel_button_clicked ( self , widget ) :
2005-04-18 14:17:43 +02:00
''' When Cancel button is clicked '''
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2005-03-02 00:48:05 +01:00
2009-10-05 15:29:37 +02:00
def on_bookmark_checkbutton_toggled ( self , widget ) :
auto_join_checkbutton = self . xml . get_widget ( ' auto_join_checkbutton ' )
if widget . get_active ( ) :
auto_join_checkbutton . set_sensitive ( True )
else :
auto_join_checkbutton . set_sensitive ( False )
2005-03-02 13:32:44 +01:00
def on_join_button_clicked ( self , widget ) :
2005-04-18 14:17:43 +02:00
''' When Join button is clicked '''
2009-09-02 23:45:16 +02:00
if not self . account :
ErrorDialog ( _ ( ' Invalid Account ' ) ,
_ ( ' You have to choose an account from which you want to join the '
' groupchat. ' ) )
return
2006-11-18 21:52:28 +01:00
nickname = self . _nickname_entry . get_text ( ) . decode ( ' utf-8 ' )
room_jid = self . _room_jid_entry . get_text ( ) . decode ( ' utf-8 ' )
2007-08-09 17:39:18 +02:00
password = self . _password_entry . get_text ( ) . decode ( ' utf-8 ' )
2008-05-07 12:23:29 +02:00
try :
nickname = helpers . parse_resource ( nickname )
2008-10-11 11:37:13 +02:00
except Exception :
2008-05-07 12:23:29 +02:00
ErrorDialog ( _ ( ' Invalid Nickname ' ) ,
2009-09-02 23:45:16 +02:00
_ ( ' The nickname has not allowed characters. ' ) )
2008-05-07 12:23:29 +02:00
return
2006-11-23 00:21:33 +01:00
user , server , resource = helpers . decompose_jid ( room_jid )
if not user or not server or resource :
ErrorDialog ( _ ( ' Invalid group chat Jabber ID ' ) ,
2009-11-01 12:40:29 +01:00
_ ( ' Please enter the group chat Jabber ID as room@server. ' ) )
2006-11-23 00:21:33 +01:00
return
2006-01-19 20:52:51 +01:00
try :
2006-11-18 21:52:28 +01:00
room_jid = helpers . parse_jid ( room_jid )
2008-10-11 11:37:13 +02:00
except Exception :
2006-11-18 21:52:28 +01:00
ErrorDialog ( _ ( ' Invalid group chat Jabber ID ' ) ,
2009-09-02 23:45:16 +02:00
_ ( ' The group chat Jabber ID has not allowed characters. ' ) )
2006-01-19 20:59:58 +01:00
return
2006-11-18 21:52:28 +01:00
if gajim . interface . msg_win_mgr . has_window ( room_jid , self . account ) :
2009-09-02 23:45:16 +02:00
ctrl = gajim . interface . msg_win_mgr . get_gc_control ( room_jid ,
self . account )
2006-11-18 21:52:28 +01:00
if ctrl . type_id != message_control . TYPE_GC :
ErrorDialog ( _ ( ' This is not a group chat ' ) ,
2009-09-02 23:45:16 +02:00
_ ( ' %s is not the name of a group chat. ' ) % room_jid )
2006-11-18 21:52:28 +01:00
return
if room_jid in self . recently_groupchat :
self . recently_groupchat . remove ( room_jid )
self . recently_groupchat . insert ( 0 , room_jid )
2005-04-07 00:52:48 +02:00
if len ( self . recently_groupchat ) > 10 :
self . recently_groupchat = self . recently_groupchat [ 0 : 10 ]
2006-11-18 21:52:28 +01:00
gajim . config . set ( ' recently_groupchat ' ,
2009-09-02 23:45:16 +02:00
' ' . join ( self . recently_groupchat ) )
2006-09-13 18:47:58 +02:00
2009-10-05 15:29:37 +02:00
if self . xml . get_widget ( ' bookmark_checkbutton ' ) . get_active ( ) :
if self . xml . get_widget ( ' auto_join_checkbutton ' ) . get_active ( ) :
autojoin = ' 1 '
else :
autojoin = ' 0 '
2008-04-20 21:45:09 +02:00
# Add as bookmark, with autojoin and not minimized
name = gajim . get_nick_from_jid ( room_jid )
2009-10-05 15:29:37 +02:00
gajim . interface . add_gc_bookmark ( self . account , name , room_jid , autojoin ,
2009-09-02 23:45:16 +02:00
' 0 ' , password , nickname )
2007-01-02 02:38:58 +01:00
2006-09-13 18:47:58 +02:00
if self . automatic :
2006-11-18 21:52:28 +01:00
gajim . automatic_rooms [ self . account ] [ room_jid ] = self . automatic
2008-04-20 20:14:04 +02:00
gajim . interface . join_gc_room ( self . account , room_jid , nickname , password )
2005-06-13 12:49:48 +02:00
2005-04-12 17:30:09 +02:00
self . window . destroy ( )
2005-03-02 00:48:05 +01:00
2007-06-03 12:04:20 +02:00
class SynchroniseSelectAccountDialog :
def __init__ ( self , account ) :
# 'account' can be None if we are about to create our first one
if not account or gajim . connections [ account ] . connected < 2 :
ErrorDialog ( _ ( ' You are not connected to the server ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' Without a connection, you can not synchronise your contacts. ' ) )
2007-06-03 12:04:20 +02:00
raise GajimGeneralException , ' You are not connected to the server '
self . account = account
self . xml = gtkgui_helpers . get_glade ( ' synchronise_select_account_dialog.glade ' )
self . dialog = self . xml . get_widget ( ' synchronise_select_account_dialog ' )
self . accounts_treeview = self . xml . get_widget ( ' accounts_treeview ' )
model = gtk . ListStore ( str , str , bool )
self . accounts_treeview . set_model ( model )
# columns
renderer = gtk . CellRendererText ( )
self . accounts_treeview . insert_column_with_attributes ( - 1 ,
2009-06-21 03:43:57 +02:00
_ ( ' Name ' ) , renderer , text = 0 )
2007-06-03 12:04:20 +02:00
renderer = gtk . CellRendererText ( )
self . accounts_treeview . insert_column_with_attributes ( - 1 ,
2009-06-21 03:43:57 +02:00
_ ( ' Server ' ) , renderer , text = 1 )
2007-06-03 12:04:20 +02:00
self . xml . signal_autoconnect ( self )
self . init_accounts ( )
self . dialog . show_all ( )
def on_accounts_window_key_press_event ( self , widget , event ) :
if event . keyval == gtk . keysyms . Escape :
self . window . destroy ( )
def init_accounts ( self ) :
''' initialize listStore with existing accounts '''
model = self . accounts_treeview . get_model ( )
model . clear ( )
for remote_account in gajim . connections :
if remote_account == self . account :
# Do not show the account we're sync'ing
continue
2008-12-03 18:16:04 +01:00
iter_ = model . append ( )
model . set ( iter_ , 0 , remote_account , 1 , gajim . get_hostname_from_account (
2007-06-03 12:04:20 +02:00
remote_account ) )
def on_cancel_button_clicked ( self , widget ) :
self . dialog . destroy ( )
def on_ok_button_clicked ( self , widget ) :
sel = self . accounts_treeview . get_selection ( )
2008-12-03 18:16:04 +01:00
( model , iter_ ) = sel . get_selected ( )
if not iter_ :
2007-06-03 12:04:20 +02:00
return
2008-12-03 18:16:04 +01:00
remote_account = model . get_value ( iter_ , 0 ) . decode ( ' utf-8 ' )
2007-12-12 09:44:46 +01:00
2007-06-03 12:04:20 +02:00
if gajim . connections [ remote_account ] . connected < 2 :
ErrorDialog ( _ ( ' This account is not connected to the server ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' You cannot synchronize with an account unless it is connected. ' ) )
2007-06-03 12:04:20 +02:00
return
else :
try :
2008-12-02 16:53:23 +01:00
SynchroniseSelectContactsDialog ( self . account , remote_account )
2007-06-03 12:04:20 +02:00
except GajimGeneralException :
# if we showed ErrorDialog, there will not be dialog instance
return
self . dialog . destroy ( )
class SynchroniseSelectContactsDialog :
def __init__ ( self , account , remote_account ) :
self . local_account = account
self . remote_account = remote_account
self . xml = gtkgui_helpers . get_glade ( ' synchronise_select_contacts_dialog.glade ' )
self . dialog = self . xml . get_widget ( ' synchronise_select_contacts_dialog ' )
self . contacts_treeview = self . xml . get_widget ( ' contacts_treeview ' )
model = gtk . ListStore ( bool , str )
self . contacts_treeview . set_model ( model )
# columns
renderer1 = gtk . CellRendererToggle ( )
renderer1 . set_property ( ' activatable ' , True )
renderer1 . connect ( ' toggled ' , self . toggled_callback )
self . contacts_treeview . insert_column_with_attributes ( - 1 ,
2009-06-21 03:43:57 +02:00
_ ( ' Synchronise ' ) , renderer1 , active = 0 )
2007-06-03 12:04:20 +02:00
renderer2 = gtk . CellRendererText ( )
self . contacts_treeview . insert_column_with_attributes ( - 1 ,
2009-06-21 03:43:57 +02:00
_ ( ' Name ' ) , renderer2 , text = 1 )
2007-06-03 12:04:20 +02:00
self . xml . signal_autoconnect ( self )
self . init_contacts ( )
self . dialog . show_all ( )
def toggled_callback ( self , cell , path ) :
model = self . contacts_treeview . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = model . get_iter ( path )
model [ iter_ ] [ 0 ] = not cell . get_active ( )
2007-06-03 12:04:20 +02:00
def on_contacts_window_key_press_event ( self , widget , event ) :
if event . keyval == gtk . keysyms . Escape :
self . window . destroy ( )
def init_contacts ( self ) :
''' initialize listStore with existing accounts '''
model = self . contacts_treeview . get_model ( )
model . clear ( )
# recover local contacts
local_jid_list = gajim . contacts . get_jid_list ( self . local_account )
remote_jid_list = gajim . contacts . get_jid_list ( self . remote_account )
for remote_jid in remote_jid_list :
if remote_jid not in local_jid_list :
2008-12-03 18:16:04 +01:00
iter_ = model . append ( )
model . set ( iter_ , 0 , True , 1 , remote_jid )
2007-06-03 12:04:20 +02:00
def on_cancel_button_clicked ( self , widget ) :
self . dialog . destroy ( )
def on_ok_button_clicked ( self , widget ) :
model = self . contacts_treeview . get_model ( )
2008-12-03 18:16:04 +01:00
iter_ = model . get_iter_root ( )
while iter_ :
if model [ iter_ ] [ 0 ] :
2007-06-03 12:04:20 +02:00
# it is selected
2008-12-03 18:16:04 +01:00
remote_jid = model [ iter_ ] [ 1 ] . decode ( ' utf-8 ' )
2007-06-03 12:04:20 +02:00
message = ' I \' m synchronizing my contacts from my %s account, could you please add this address to your contact list? ' % \
2009-06-21 03:43:57 +02:00
gajim . get_hostname_from_account ( self . remote_account )
2007-06-03 12:04:20 +02:00
remote_contact = gajim . contacts . get_first_contact_from_jid (
self . remote_account , remote_jid )
# keep same groups and same nickname
gajim . interface . roster . req_sub ( self , remote_jid , message ,
2009-06-21 03:43:57 +02:00
self . local_account , groups = remote_contact . groups ,
nickname = remote_contact . name , auto_auth = True )
2008-12-03 18:16:04 +01:00
iter_ = model . iter_next ( iter_ )
2007-06-03 12:04:20 +02:00
self . dialog . destroy ( )
2006-05-08 23:16:38 +02:00
class NewChatDialog ( InputDialog ) :
2005-10-20 13:17:17 +02:00
def __init__ ( self , account ) :
2005-03-02 00:48:05 +01:00
self . account = account
2007-01-15 11:34:53 +01:00
2005-04-17 21:53:39 +02:00
if len ( gajim . connections ) > 1 :
2005-11-28 17:29:04 +01:00
title = _ ( ' Start Chat with account %s ' ) % account
2005-04-04 18:46:35 +02:00
else :
2005-11-28 17:29:04 +01:00
title = _ ( ' Start Chat ' )
2006-11-18 21:52:28 +01:00
prompt_text = _ ( ' Fill in the nickname or the Jabber ID of the contact you would like \n to send a chat message to: ' )
2008-09-03 13:25:27 +02:00
InputDialog . __init__ ( self , title , prompt_text , is_modal = False )
2007-01-15 11:34:53 +01:00
2006-05-08 23:16:38 +02:00
self . completion_dict = { }
2006-05-08 23:59:09 +02:00
liststore = gtkgui_helpers . get_completion_liststore ( self . input_entry )
2006-05-09 00:44:47 +02:00
self . completion_dict = helpers . get_contact_dict_for_account ( account )
2006-05-08 23:59:09 +02:00
# add all contacts to the model
2008-10-11 11:59:52 +02:00
keys = sorted ( self . completion_dict . keys ( ) )
2006-05-09 15:07:33 +02:00
for jid in keys :
2006-05-08 23:16:38 +02:00
contact = self . completion_dict [ jid ]
2008-04-17 16:17:14 +02:00
img = gajim . interface . jabber_state_images [ ' 16 ' ] [ contact . show ]
2006-05-08 23:16:38 +02:00
liststore . append ( ( img . get_pixbuf ( ) , jid ) )
self . ok_handler = self . new_chat_response
okbutton = self . xml . get_widget ( ' okbutton ' )
okbutton . connect ( ' clicked ' , self . on_okbutton_clicked )
cancelbutton = self . xml . get_widget ( ' cancelbutton ' )
cancelbutton . connect ( ' clicked ' , self . on_cancelbutton_clicked )
self . dialog . show_all ( )
2007-01-15 11:34:53 +01:00
2006-04-18 17:17:07 +02:00
def new_chat_response ( self , jid ) :
2005-07-25 09:47:05 +02:00
''' called when ok button is clicked '''
2005-08-06 21:14:21 +02:00
if gajim . connections [ self . account ] . connected < = 1 :
#if offline or connecting
ErrorDialog ( _ ( ' Connection not available ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' Please make sure you are connected with " %s " . ' ) % self . account )
2005-08-06 21:14:21 +02:00
return
2005-06-20 01:09:15 +02:00
2008-10-07 22:41:59 +02:00
if jid in self . completion_dict :
2006-05-08 23:16:38 +02:00
jid = self . completion_dict [ jid ] . jid
2006-07-17 21:30:53 +02:00
else :
try :
jid = helpers . parse_jid ( jid )
except helpers . InvalidFormat , e :
ErrorDialog ( _ ( ' Invalid JID ' ) , e [ 0 ] )
return
except :
2006-09-13 18:47:58 +02:00
ErrorDialog ( _ ( ' Invalid JID ' ) , _ ( ' Unable to parse " %s " . ' ) % jid )
2006-07-17 21:30:53 +02:00
return
2008-04-20 20:14:04 +02:00
gajim . interface . new_chat_from_jid ( self . account , jid )
2005-03-02 00:48:05 +01:00
2005-06-10 23:14:16 +02:00
class ChangePasswordDialog :
2008-08-06 22:34:36 +02:00
def __init__ ( self , account , on_response ) :
2005-07-18 13:03:53 +02:00
# 'account' can be None if we are about to create our first one
if not account or gajim . connections [ account ] . connected < 2 :
2005-06-10 23:14:16 +02:00
ErrorDialog ( _ ( ' You are not connected to the server ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' Without a connection, you can not change your password. ' ) )
2006-11-18 21:52:28 +01:00
raise GajimGeneralException , ' You are not connected to the server '
2005-03-02 00:48:05 +01:00
self . account = account
2008-08-06 22:34:36 +02:00
self . on_response = on_response
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' change_password_dialog.glade ' )
2005-04-04 18:46:35 +02:00
self . dialog = self . xml . get_widget ( ' change_password_dialog ' )
self . password1_entry = self . xml . get_widget ( ' password1_entry ' )
self . password2_entry = self . xml . get_widget ( ' password2_entry ' )
2008-08-06 22:34:36 +02:00
self . dialog . connect ( ' response ' , self . on_dialog_response )
2005-03-28 03:39:12 +02:00
2005-06-05 12:48:34 +02:00
self . dialog . show_all ( )
2005-03-04 14:10:00 +01:00
2008-08-06 22:34:36 +02:00
def on_dialog_response ( self , dialog , response ) :
if response != gtk . RESPONSE_OK :
dialog . destroy ( )
self . on_response ( None )
return
password1 = self . password1_entry . get_text ( ) . decode ( ' utf-8 ' )
if not password1 :
ErrorDialog ( _ ( ' Invalid password ' ) , _ ( ' You must enter a password. ' ) )
return
password2 = self . password2_entry . get_text ( ) . decode ( ' utf-8 ' )
if password1 != password2 :
ErrorDialog ( _ ( ' Passwords do not match ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' The passwords typed in both fields must be identical. ' ) )
2008-08-06 22:34:36 +02:00
return
dialog . destroy ( )
self . on_response ( password1 )
2005-06-10 00:29:06 +02:00
2005-06-10 20:40:19 +02:00
class PopupNotificationWindow :
2008-08-08 00:08:08 +02:00
def __init__ ( self , event_type , jid , account , msg_type = ' ' ,
2009-06-21 03:43:57 +02:00
path_to_image = None , title = None , text = None ) :
2005-04-12 17:30:09 +02:00
self . account = account
self . jid = jid
2005-07-07 17:41:03 +02:00
self . msg_type = msg_type
2006-04-04 19:46:19 +02:00
2006-05-02 17:53:25 +02:00
xml = gtkgui_helpers . get_glade ( ' popup_notification_window.glade ' )
2005-04-21 23:23:41 +02:00
self . window = xml . get_widget ( ' popup_notification_window ' )
2009-04-27 21:28:53 +02:00
self . window . set_type_hint ( gtk . gdk . WINDOW_TYPE_HINT_TOOLTIP )
2005-04-04 21:27:06 +02:00
close_button = xml . get_widget ( ' close_button ' )
2005-04-06 20:51:54 +02:00
event_type_label = xml . get_widget ( ' event_type_label ' )
event_description_label = xml . get_widget ( ' event_description_label ' )
eventbox = xml . get_widget ( ' eventbox ' )
2006-01-18 21:30:24 +01:00
image = xml . get_widget ( ' notification_image ' )
2006-04-04 19:46:19 +02:00
2006-01-20 18:40:45 +01:00
if not text :
2006-01-20 18:50:01 +01:00
text = gajim . get_name_from_jid ( account , jid ) # default value of text
2006-04-03 09:40:15 +02:00
if not title :
2008-11-29 14:37:06 +01:00
title = ' '
2005-10-11 15:59:41 +02:00
2006-04-03 16:21:51 +02:00
event_type_label . set_markup (
2008-11-29 14:37:06 +01:00
' <span foreground= " black " weight= " bold " > %s </span> ' %
gobject . markup_escape_text ( title ) )
2006-04-03 16:21:51 +02:00
2005-09-05 02:08:52 +02:00
# set colors [ http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html ]
2005-04-06 20:51:54 +02:00
self . window . modify_bg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( ' black ' ) )
2006-04-04 19:46:19 +02:00
2006-01-18 21:30:24 +01:00
# default image
2006-01-20 18:40:45 +01:00
if not path_to_image :
path_to_image = os . path . abspath (
2006-11-18 21:52:28 +01:00
os . path . join ( gajim . DATA_DIR , ' pixmaps ' , ' events ' ,
2009-06-21 03:43:57 +02:00
' chat_msg_recv.png ' ) ) # img to display
2005-10-11 15:59:41 +02:00
2005-06-03 20:40:43 +02:00
if event_type == _ ( ' Contact Signed In ' ) :
2006-04-05 21:57:13 +02:00
bg_color = ' limegreen '
2005-06-03 20:40:43 +02:00
elif event_type == _ ( ' Contact Signed Out ' ) :
2006-04-05 21:57:13 +02:00
bg_color = ' red '
2005-10-27 15:15:03 +02:00
elif event_type in ( _ ( ' New Message ' ) , _ ( ' New Single Message ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' New Private Message ' ) , _ ( ' New E-mail ' ) ) :
2006-04-05 21:57:13 +02:00
bg_color = ' dodgerblue '
2005-08-03 18:53:04 +02:00
elif event_type == _ ( ' File Transfer Request ' ) :
2006-04-05 21:57:13 +02:00
bg_color = ' khaki '
2005-08-07 23:01:21 +02:00
elif event_type == _ ( ' File Transfer Error ' ) :
2006-04-05 21:57:13 +02:00
bg_color = ' firebrick '
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
elif event_type in ( _ ( ' File Transfer Completed ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' File Transfer Stopped ' ) ) :
2006-04-05 21:57:13 +02:00
bg_color = ' yellowgreen '
2006-04-05 18:32:22 +02:00
elif event_type == _ ( ' Groupchat Invitation ' ) :
2006-04-05 21:57:13 +02:00
bg_color = ' tan1 '
2008-01-22 17:06:16 +01:00
elif event_type == _ ( ' Contact Changed Status ' ) :
2006-05-10 22:25:51 +02:00
bg_color = ' thistle2 '
2006-11-18 21:52:28 +01:00
else : # Unknown event! Shouldn't happen but deal with it
2006-04-05 21:57:13 +02:00
bg_color = ' white '
popup_bg_color = gtk . gdk . color_parse ( bg_color )
close_button . modify_bg ( gtk . STATE_NORMAL , popup_bg_color )
eventbox . modify_bg ( gtk . STATE_NORMAL , popup_bg_color )
2008-11-29 14:37:06 +01:00
event_description_label . set_markup ( ' <span foreground= " black " > %s </span> ' %
2009-06-21 03:43:57 +02:00
gobject . markup_escape_text ( text ) )
2007-01-15 11:34:53 +01:00
2006-01-18 21:30:24 +01:00
# set the image
2006-01-20 18:40:45 +01:00
image . set_from_file ( path_to_image )
2007-01-15 11:34:53 +01:00
2005-04-04 18:46:35 +02:00
# position the window to bottom-right of screen
2005-04-12 17:30:09 +02:00
window_width , self . window_height = self . window . get_size ( )
2005-10-20 13:17:17 +02:00
gajim . interface . roster . popups_notification_height + = self . window_height
2006-01-21 22:11:29 +01:00
pos_x = gajim . config . get ( ' notification_position_x ' )
if pos_x < 0 :
pos_x = gtk . gdk . screen_width ( ) - window_width + pos_x + 1
pos_y = gajim . config . get ( ' notification_position_y ' )
if pos_y < 0 :
2008-08-08 00:08:08 +02:00
pos_y = gtk . gdk . screen_height ( ) - \
2009-06-21 03:43:57 +02:00
gajim . interface . roster . popups_notification_height + pos_y + 1
2006-01-21 22:11:29 +01:00
self . window . move ( pos_x , pos_y )
2005-09-23 23:01:42 +02:00
2005-04-04 21:27:06 +02:00
xml . signal_autoconnect ( self )
2005-04-04 17:51:29 +02:00
self . window . show_all ( )
2008-02-14 20:18:07 +01:00
timeout = gajim . config . get ( ' notification_timeout ' )
gobject . timeout_add_seconds ( timeout , self . on_timeout )
2005-04-04 18:46:35 +02:00
2005-04-12 17:30:09 +02:00
def on_close_button_clicked ( self , widget ) :
2005-04-21 23:23:41 +02:00
self . adjust_height_and_move_popup_notification_windows ( )
2005-04-04 21:27:06 +02:00
2005-04-12 17:30:09 +02:00
def on_timeout ( self ) :
2005-04-21 23:23:41 +02:00
self . adjust_height_and_move_popup_notification_windows ( )
2005-09-23 23:01:42 +02:00
2005-04-21 23:23:41 +02:00
def adjust_height_and_move_popup_notification_windows ( self ) :
2005-04-05 17:06:11 +02:00
#remove
2005-10-20 13:17:17 +02:00
gajim . interface . roster . popups_notification_height - = self . window_height
2005-04-04 21:27:06 +02:00
self . window . destroy ( )
2005-09-23 23:01:42 +02:00
2005-10-20 13:17:17 +02:00
if len ( gajim . interface . roster . popup_notification_windows ) > 0 :
2005-04-05 17:06:11 +02:00
# we want to remove the first window added in the list
2008-08-08 00:08:08 +02:00
gajim . interface . roster . popup_notification_windows . pop ( 0 )
2007-01-15 11:34:53 +01:00
2005-04-05 17:06:11 +02:00
# move the rest of popup windows
2005-10-20 13:17:17 +02:00
gajim . interface . roster . popups_notification_height = 0
for window_instance in gajim . interface . roster . popup_notification_windows :
2005-04-05 17:06:11 +02:00
window_width , window_height = window_instance . window . get_size ( )
2005-10-20 13:17:17 +02:00
gajim . interface . roster . popups_notification_height + = window_height
2005-05-19 19:47:40 +02:00
window_instance . window . move ( gtk . gdk . screen_width ( ) - window_width ,
2009-06-21 03:43:57 +02:00
gtk . gdk . screen_height ( ) - \
gajim . interface . roster . popups_notification_height )
2005-04-06 20:51:54 +02:00
2005-04-21 23:23:41 +02:00
def on_popup_notification_window_button_press_event ( self , widget , event ) :
2005-11-26 15:39:27 +01:00
if event . button != 1 :
self . window . destroy ( )
return
2006-04-06 20:13:06 +02:00
gajim . interface . handle_event ( self . account , self . jid , self . msg_type )
2005-04-21 23:23:41 +02:00
self . adjust_height_and_move_popup_notification_windows ( )
2005-07-01 17:15:35 +02:00
2005-07-05 23:35:37 +02:00
class SingleMessageWindow :
''' SingleMessageWindow can send or show a received
2006-03-08 02:27:01 +01:00
singled message depending on action argument which can be ' send '
or ' receive ' .
'''
2007-12-12 09:44:46 +01:00
# Keep a reference on windows so garbage collector don't restroy them
instances = [ ]
def __init__ ( self , account , to = ' ' , action = ' ' , from_whom = ' ' , subject = ' ' ,
2009-06-21 03:43:57 +02:00
message = ' ' , resource = ' ' , session = None , form_node = None ) :
2007-12-12 09:44:46 +01:00
self . instances . append ( self )
2005-07-01 17:15:35 +02:00
self . account = account
2005-07-05 23:35:37 +02:00
self . action = action
self . subject = subject
self . message = message
2005-12-08 15:51:35 +01:00
self . to = to
self . from_whom = from_whom
self . resource = resource
2007-12-12 09:44:46 +01:00
self . session = session
2007-01-15 11:34:53 +01:00
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' single_message_window.glade ' )
2005-07-05 23:35:37 +02:00
self . window = self . xml . get_widget ( ' single_message_window ' )
2005-07-02 17:49:25 +02:00
self . count_chars_label = self . xml . get_widget ( ' count_chars_label ' )
2005-07-05 23:35:37 +02:00
self . from_label = self . xml . get_widget ( ' from_label ' )
self . from_entry = self . xml . get_widget ( ' from_entry ' )
self . to_label = self . xml . get_widget ( ' to_label ' )
2005-07-02 17:49:25 +02:00
self . to_entry = self . xml . get_widget ( ' to_entry ' )
self . subject_entry = self . xml . get_widget ( ' subject_entry ' )
2005-12-12 10:12:29 +01:00
self . message_scrolledwindow = self . xml . get_widget (
' message_scrolledwindow ' )
2005-07-05 23:35:37 +02:00
self . message_textview = self . xml . get_widget ( ' message_textview ' )
self . message_tv_buffer = self . message_textview . get_buffer ( )
2005-12-12 10:12:29 +01:00
self . conversation_scrolledwindow = self . xml . get_widget (
' conversation_scrolledwindow ' )
self . conversation_textview = conversation_textview . ConversationTextview (
account )
2006-04-18 18:08:56 +02:00
self . conversation_textview . tv . show ( )
self . conversation_tv_buffer = self . conversation_textview . tv . get_buffer ( )
2005-12-12 10:12:29 +01:00
self . xml . get_widget ( ' conversation_scrolledwindow ' ) . add (
2006-04-18 18:08:56 +02:00
self . conversation_textview . tv )
2007-12-12 09:44:46 +01:00
self . form_widget = None
2008-08-08 00:08:08 +02:00
parent_box = self . xml . get_widget ( ' conversation_scrolledwindow ' ) . \
2009-06-21 03:43:57 +02:00
get_parent ( )
2007-12-12 09:44:46 +01:00
if form_node :
2008-09-03 13:25:27 +02:00
dataform = dataforms . ExtendForm ( node = form_node )
2007-12-12 09:44:46 +01:00
self . form_widget = dataforms_widget . DataFormWidget ( dataform )
self . form_widget . show_all ( )
parent_box . add ( self . form_widget )
parent_box . child_set_property ( self . form_widget , ' position ' ,
2009-06-21 03:43:57 +02:00
parent_box . child_get_property ( self . xml . get_widget (
' conversation_scrolledwindow ' ) , ' position ' ) )
2007-12-12 09:44:46 +01:00
self . action = ' form '
2005-07-05 23:35:37 +02:00
self . send_button = self . xml . get_widget ( ' send_button ' )
self . reply_button = self . xml . get_widget ( ' reply_button ' )
2005-07-06 01:55:33 +02:00
self . send_and_close_button = self . xml . get_widget ( ' send_and_close_button ' )
2005-12-08 15:51:35 +01:00
self . cancel_button = self . xml . get_widget ( ' cancel_button ' )
self . close_button = self . xml . get_widget ( ' close_button ' )
2005-07-02 17:49:25 +02:00
self . message_tv_buffer . connect ( ' changed ' , self . update_char_counter )
2008-10-11 11:59:52 +02:00
if isinstance ( to , list ) :
2006-11-18 21:52:28 +01:00
jid = ' , ' . join ( [ i [ 0 ] . jid + ' / ' + i [ 0 ] . resource for i in to ] )
self . to_entry . set_text ( jid )
self . to_entry . set_sensitive ( False )
else :
self . to_entry . set_text ( to )
2007-01-15 11:34:53 +01:00
2006-06-16 19:47:47 +02:00
if gajim . config . get ( ' use_speller ' ) and HAS_GTK_SPELL and action == ' send ' :
2005-11-30 23:22:22 +01:00
try :
2006-09-13 18:47:58 +02:00
lang = gajim . config . get ( ' speller_language ' )
2009-01-28 14:16:02 +01:00
if not lang :
lang = gajim . LANG
gtkspell . Spell ( self . conversation_textview . tv , lang )
gtkspell . Spell ( self . message_textview , lang )
2009-03-11 10:17:23 +01:00
except ( gobject . GError , TypeError , RuntimeError , OSError ) :
2007-12-12 09:44:46 +01:00
AspellDictError ( lang )
2007-01-15 11:34:53 +01:00
2005-07-05 23:35:37 +02:00
self . prepare_widgets_for ( self . action )
2005-07-26 17:23:11 +02:00
# set_text(None) raises TypeError exception
if self . subject is None :
self . subject = ' '
2005-07-05 23:35:37 +02:00
self . subject_entry . set_text ( self . subject )
2006-05-09 00:44:47 +02:00
2006-05-09 00:06:42 +02:00
if to == ' ' :
liststore = gtkgui_helpers . get_completion_liststore ( self . to_entry )
2006-05-09 00:44:47 +02:00
self . completion_dict = helpers . get_contact_dict_for_account ( account )
2008-10-11 11:59:52 +02:00
keys = sorted ( self . completion_dict . keys ( ) )
2006-05-09 15:07:33 +02:00
for jid in keys :
2006-05-09 00:06:42 +02:00
contact = self . completion_dict [ jid ]
2008-04-17 16:17:14 +02:00
img = gajim . interface . jabber_state_images [ ' 16 ' ] [ contact . show ]
2006-05-09 00:06:42 +02:00
liststore . append ( ( img . get_pixbuf ( ) , jid ) )
2006-05-09 00:44:47 +02:00
else :
self . completion_dict = { }
2005-07-05 23:35:37 +02:00
self . xml . signal_autoconnect ( self )
2005-10-17 00:08:42 +02:00
2008-01-22 22:08:24 +01:00
# get window position and size from config
gtkgui_helpers . resize_window ( self . window ,
2009-06-21 03:43:57 +02:00
gajim . config . get ( ' single-msg-width ' ) ,
gajim . config . get ( ' single-msg-height ' ) )
2008-01-22 22:08:24 +01:00
gtkgui_helpers . move_window ( self . window ,
2009-06-21 03:43:57 +02:00
gajim . config . get ( ' single-msg-x-position ' ) ,
gajim . config . get ( ' single-msg-y-position ' ) )
2008-01-22 22:08:24 +01:00
2005-07-05 23:35:37 +02:00
self . window . show_all ( )
2007-12-12 09:44:46 +01:00
def on_single_message_window_destroy ( self , widget ) :
self . instances . remove ( self )
2009-09-21 21:22:57 +02:00
c = gajim . contacts . get_contact_with_highest_priority ( self . account ,
self . from_whom )
2009-09-29 13:51:20 +02:00
if not c :
# Groupchat is maybe already destroyed
return
2009-09-21 21:22:57 +02:00
if c . is_groupchat ( ) and not self . from_whom in \
gajim . interface . minimized_controls [ self . account ] and self . action == \
' receive ' and gajim . events . get_nb_roster_events ( self . account ,
self . from_whom , types = [ ' chat ' , ' normal ' ] ) == 0 :
gajim . interface . roster . remove_groupchat ( self . from_whom , self . account )
2007-12-12 09:44:46 +01:00
2005-11-18 00:04:56 +01:00
def set_cursor_to_end ( self ) :
2008-07-19 19:36:21 +02:00
end_iter = self . message_tv_buffer . get_end_iter ( )
self . message_tv_buffer . place_cursor ( end_iter )
2005-11-18 00:04:56 +01:00
2005-10-17 17:57:03 +02:00
def save_pos ( self ) :
2008-01-22 22:08:24 +01:00
# save the window size and position
x , y = self . window . get_position ( )
gajim . config . set ( ' single-msg-x-position ' , x )
gajim . config . set ( ' single-msg-y-position ' , y )
width , height = self . window . get_size ( )
gajim . config . set ( ' single-msg-width ' , width )
gajim . config . set ( ' single-msg-height ' , height )
gajim . interface . save_config ( )
2005-10-17 10:25:05 +02:00
2005-10-17 17:57:03 +02:00
def on_single_message_window_delete_event ( self , window , ev ) :
self . save_pos ( )
2005-07-05 23:35:37 +02:00
def prepare_widgets_for ( self , action ) :
2005-07-01 17:15:35 +02:00
if len ( gajim . connections ) > 1 :
2006-09-13 18:47:58 +02:00
if action == ' send ' :
title = _ ( ' Single Message using account %s ' ) % self . account
else :
title = _ ( ' Single Message in account %s ' ) % self . account
2005-07-01 17:15:35 +02:00
else :
2005-07-05 23:35:37 +02:00
title = _ ( ' Single Message ' )
2005-12-08 15:51:35 +01:00
if action == ' send ' : # prepare UI for Sending
2005-07-05 23:35:37 +02:00
title = _ ( ' Send %s ' ) % title
self . send_button . show ( )
2005-07-06 01:55:33 +02:00
self . send_and_close_button . show ( )
2005-07-05 23:35:37 +02:00
self . to_label . show ( )
self . to_entry . show ( )
self . reply_button . hide ( )
self . from_label . hide ( )
self . from_entry . hide ( )
2005-12-12 10:12:29 +01:00
self . conversation_scrolledwindow . hide ( )
self . message_scrolledwindow . show ( )
2007-01-15 11:34:53 +01:00
2005-12-08 15:51:35 +01:00
if self . message : # we come from a reply?
self . message_textview . grab_focus ( )
self . cancel_button . hide ( )
self . close_button . show ( )
2005-12-12 10:12:29 +01:00
self . message_tv_buffer . set_text ( self . message )
gobject . idle_add ( self . set_cursor_to_end )
2005-12-08 15:51:35 +01:00
else : # we write a new message (not from reply)
self . close_button . hide ( )
if self . to : # do we already have jid?
self . subject_entry . grab_focus ( )
2007-01-15 11:34:53 +01:00
2005-12-08 15:51:35 +01:00
elif action == ' receive ' : # prepare UI for Receiving
2005-07-06 01:55:33 +02:00
title = _ ( ' Received %s ' ) % title
2005-07-05 23:35:37 +02:00
self . reply_button . show ( )
self . from_label . show ( )
self . from_entry . show ( )
self . send_button . hide ( )
2005-07-06 01:55:33 +02:00
self . send_and_close_button . hide ( )
2005-07-05 23:35:37 +02:00
self . to_label . hide ( )
self . to_entry . hide ( )
2005-12-12 10:12:29 +01:00
self . conversation_scrolledwindow . show ( )
self . message_scrolledwindow . hide ( )
if self . message :
self . conversation_textview . print_real_text ( self . message )
2008-01-22 17:06:16 +01:00
fjid = self . from_whom
2005-12-08 15:51:35 +01:00
if self . resource :
fjid + = ' / ' + self . resource # Full jid of sender (with resource)
self . from_entry . set_text ( fjid )
self . from_entry . set_property ( ' editable ' , False )
self . subject_entry . set_property ( ' editable ' , False )
self . reply_button . grab_focus ( )
self . cancel_button . hide ( )
self . close_button . show ( )
2007-12-12 09:44:46 +01:00
elif action == ' form ' : # prepare UI for Receiving
2008-01-22 17:06:16 +01:00
title = _ ( ' Form %s ' ) % title
self . send_button . show ( )
self . send_and_close_button . show ( )
self . to_label . show ( )
self . to_entry . show ( )
self . reply_button . hide ( )
self . from_label . hide ( )
self . from_entry . hide ( )
self . conversation_scrolledwindow . hide ( )
self . message_scrolledwindow . hide ( )
2007-01-15 11:34:53 +01:00
2005-07-05 23:35:37 +02:00
self . window . set_title ( title )
2005-07-01 17:15:35 +02:00
2005-07-02 17:49:25 +02:00
def on_cancel_button_clicked ( self , widget ) :
2005-10-17 17:57:03 +02:00
self . save_pos ( )
2005-07-02 17:49:25 +02:00
self . window . destroy ( )
2005-07-01 17:15:35 +02:00
2005-12-08 15:51:35 +01:00
def on_close_button_clicked ( self , widget ) :
self . save_pos ( )
self . window . destroy ( )
2005-07-02 17:49:25 +02:00
def update_char_counter ( self , widget ) :
characters_no = self . message_tv_buffer . get_char_count ( )
2005-08-26 02:52:44 +02:00
self . count_chars_label . set_text ( unicode ( characters_no ) )
2007-01-15 11:34:53 +01:00
2005-07-06 01:55:33 +02:00
def send_single_message ( self ) :
2005-08-06 21:14:21 +02:00
if gajim . connections [ self . account ] . connected < = 1 :
2005-12-08 15:51:35 +01:00
# if offline or connecting
2005-08-06 21:14:21 +02:00
ErrorDialog ( _ ( ' Connection not available ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' Please make sure you are connected with " %s " . ' ) % self . account )
2005-08-06 21:14:21 +02:00
return
2008-07-08 21:15:54 +02:00
if isinstance ( self . to , list ) :
2006-11-18 21:52:28 +01:00
sender_list = [ i [ 0 ] . jid + ' / ' + i [ 0 ] . resource for i in self . to ]
else :
sender_list = [ self . to_entry . get_text ( ) . decode ( ' utf-8 ' ) ]
2007-02-04 14:01:04 +01:00
2006-11-18 21:52:28 +01:00
for to_whom_jid in sender_list :
2008-10-07 22:41:59 +02:00
if to_whom_jid in self . completion_dict :
2006-11-18 21:52:28 +01:00
to_whom_jid = self . completion_dict [ to_whom_jid ] . jid
2008-12-13 15:43:46 +01:00
try :
to_whom_jid = helpers . parse_jid ( to_whom_jid )
except helpers . InvalidFormat :
ErrorDialog ( _ ( ' Invalid Jabber ID ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' It is not possible to send a message to %s , this JID is not '
' valid. ' ) % to_whom_jid )
2008-12-13 15:43:46 +01:00
return
2008-07-08 21:15:54 +02:00
2006-11-18 21:52:28 +01:00
subject = self . subject_entry . get_text ( ) . decode ( ' utf-8 ' )
begin , end = self . message_tv_buffer . get_bounds ( )
message = self . message_tv_buffer . get_text ( begin , end ) . decode ( ' utf-8 ' )
2008-07-08 21:15:54 +02:00
if ' /announce/ ' in to_whom_jid :
2006-11-18 21:52:28 +01:00
gajim . connections [ self . account ] . send_motd ( to_whom_jid , subject ,
2009-06-21 03:43:57 +02:00
message )
2008-07-08 21:15:54 +02:00
continue
2005-08-06 21:14:21 +02:00
2007-12-12 09:44:46 +01:00
if self . session :
session = self . session
else :
2008-08-08 00:08:08 +02:00
session = gajim . connections [ self . account ] . make_new_session (
to_whom_jid )
2007-12-12 09:44:46 +01:00
if self . form_widget :
form_node = self . form_widget . data_form
else :
form_node = None
2006-11-18 21:52:28 +01:00
# FIXME: allow GPG message some day
gajim . connections [ self . account ] . send_message ( to_whom_jid , message ,
2009-06-21 03:43:57 +02:00
keyID = None , type_ = ' normal ' , subject = subject , session = session ,
form_node = form_node )
2007-01-15 11:34:53 +01:00
2005-07-05 23:57:19 +02:00
self . subject_entry . set_text ( ' ' ) # we sent ok, clear the subject
2005-07-02 17:49:25 +02:00
self . message_tv_buffer . set_text ( ' ' ) # we sent ok, clear the textview
2005-07-04 23:29:22 +02:00
2005-07-06 01:55:33 +02:00
def on_send_button_clicked ( self , widget ) :
self . send_single_message ( )
2005-07-05 23:35:37 +02:00
def on_reply_button_clicked ( self , widget ) :
# we create a new blank window to send and we preset RE: and to jid
self . subject = _ ( ' RE: %s ' ) % self . subject
2006-09-13 18:47:58 +02:00
self . message = _ ( ' %s wrote: \n ' ) % self . from_whom + self . message
2005-11-18 00:04:56 +01:00
# add > at the begining of each line
self . message = self . message . replace ( ' \n ' , ' \n > ' ) + ' \n \n '
2005-07-05 23:57:19 +02:00
self . window . destroy ( )
2008-09-03 13:25:27 +02:00
SingleMessageWindow ( self . account , to = self . from_whom , action = ' send ' ,
2009-06-21 03:43:57 +02:00
from_whom = self . from_whom , subject = self . subject , message = self . message ,
session = self . session )
2005-07-05 23:35:37 +02:00
2005-07-06 01:55:33 +02:00
def on_send_and_close_button_clicked ( self , widget ) :
self . send_single_message ( )
2005-10-17 17:57:03 +02:00
self . save_pos ( )
2005-07-06 01:55:33 +02:00
self . window . destroy ( )
def on_single_message_window_key_press_event ( self , widget , event ) :
if event . keyval == gtk . keysyms . Escape : # ESCAPE
2005-10-17 17:57:03 +02:00
self . save_pos ( )
2005-07-06 01:55:33 +02:00
self . window . destroy ( )
2005-07-04 23:29:22 +02:00
class XMLConsoleWindow :
2005-10-20 13:17:17 +02:00
def __init__ ( self , account ) :
2005-07-04 23:29:22 +02:00
self . account = account
2007-01-15 11:34:53 +01:00
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' xml_console_window.glade ' )
2005-07-04 23:29:22 +02:00
self . window = self . xml . get_widget ( ' xml_console_window ' )
self . input_textview = self . xml . get_widget ( ' input_textview ' )
self . stanzas_log_textview = self . xml . get_widget ( ' stanzas_log_textview ' )
2005-08-06 02:38:24 +02:00
self . input_tv_buffer = self . input_textview . get_buffer ( )
2008-12-03 18:16:04 +01:00
buffer_ = self . stanzas_log_textview . get_buffer ( )
end_iter = buffer_ . get_end_iter ( )
buffer_ . create_mark ( ' end ' , end_iter , False )
2007-01-15 11:34:53 +01:00
2008-12-03 18:16:04 +01:00
self . tagIn = buffer_ . create_tag ( ' incoming ' )
2005-08-06 01:43:28 +02:00
color = gajim . config . get ( ' inmsgcolor ' )
self . tagIn . set_property ( ' foreground ' , color )
2009-04-22 10:43:04 +02:00
self . tagInComment = buffer_ . create_tag ( ' in_comment ' )
self . tagInComment . set_property ( ' foreground ' , color )
2008-12-03 18:16:04 +01:00
self . tagOut = buffer_ . create_tag ( ' outgoing ' )
2005-08-06 01:43:28 +02:00
color = gajim . config . get ( ' outmsgcolor ' )
self . tagOut . set_property ( ' foreground ' , color )
2009-04-22 10:43:04 +02:00
self . tagOutComment = buffer_ . create_tag ( ' out_comment ' )
self . tagOutComment . set_property ( ' foreground ' , color )
2005-08-06 01:43:28 +02:00
2005-08-06 21:14:21 +02:00
self . enabled = False
2005-08-06 01:43:28 +02:00
2005-08-06 02:38:24 +02:00
self . input_textview . modify_text (
2005-08-06 01:43:28 +02:00
gtk . STATE_NORMAL , gtk . gdk . color_parse ( color ) )
2007-01-15 11:34:53 +01:00
2005-07-04 23:29:22 +02:00
if len ( gajim . connections ) > 1 :
2005-07-05 01:18:05 +02:00
title = _ ( ' XML Console for %s ' ) % self . account
2005-07-04 23:29:22 +02:00
else :
title = _ ( ' XML Console ' )
2007-01-15 11:34:53 +01:00
2005-07-04 23:29:22 +02:00
self . window . set_title ( title )
2006-04-05 14:01:21 +02:00
self . window . show_all ( )
2007-01-15 11:34:53 +01:00
2005-07-04 23:29:22 +02:00
self . xml . signal_autoconnect ( self )
2005-08-06 02:38:24 +02:00
def on_xml_console_window_delete_event ( self , widget , event ) :
self . window . hide ( )
return True # do NOT destroy the window
def on_clear_button_clicked ( self , widget ) :
2008-12-03 18:16:04 +01:00
buffer_ = self . stanzas_log_textview . get_buffer ( )
buffer_ . set_text ( ' ' )
2005-08-06 02:38:24 +02:00
def on_enable_checkbutton_toggled ( self , widget ) :
2005-08-06 21:14:21 +02:00
self . enabled = widget . get_active ( )
2005-08-06 02:38:24 +02:00
def scroll_to_end ( self , ) :
parent = self . stanzas_log_textview . get_parent ( )
2008-12-03 18:16:04 +01:00
buffer_ = self . stanzas_log_textview . get_buffer ( )
end_mark = buffer_ . get_mark ( ' end ' )
2006-05-29 20:23:12 +02:00
if not end_mark :
return False
self . stanzas_log_textview . scroll_to_mark ( end_mark , 0 , True , 0 , 1 )
2005-08-06 02:38:24 +02:00
adjustment = parent . get_hadjustment ( )
adjustment . set_value ( 0 )
return False
def print_stanza ( self , stanza , kind ) :
# kind must be 'incoming' or 'outgoing'
2005-08-06 21:14:21 +02:00
if not self . enabled :
2005-08-06 02:38:24 +02:00
return
2007-01-06 15:57:18 +01:00
if not stanza :
return
2005-08-06 02:38:24 +02:00
buffer = self . stanzas_log_textview . get_buffer ( )
at_the_end = False
end_iter = buffer . get_end_iter ( )
end_rect = self . stanzas_log_textview . get_iter_location ( end_iter )
visible_rect = self . stanzas_log_textview . get_visible_rect ( )
if end_rect . y < = ( visible_rect . y + visible_rect . height ) :
at_the_end = True
2005-08-04 22:32:38 +02:00
end_iter = buffer . get_end_iter ( )
2009-04-22 10:43:04 +02:00
if kind == ' incoming ' :
2009-06-15 21:00:14 +02:00
buffer . insert_with_tags_by_name ( end_iter , ' <!-- In --> \n ' ,
2009-06-21 03:43:57 +02:00
' in_comment ' )
2009-04-22 10:43:04 +02:00
elif kind == ' outgoing ' :
2009-06-15 21:00:14 +02:00
buffer . insert_with_tags_by_name ( end_iter , ' <!-- Out --> \n ' ,
2009-06-21 03:43:57 +02:00
' out_comment ' )
2009-04-22 10:43:04 +02:00
end_iter = buffer . get_end_iter ( )
2005-11-14 11:14:55 +01:00
buffer . insert_with_tags_by_name ( end_iter , stanza . replace ( ' >< ' , ' > \n < ' ) + \
2009-06-21 03:43:57 +02:00
' \n \n ' , kind )
2005-08-06 02:38:24 +02:00
if at_the_end :
gobject . idle_add ( self . scroll_to_end )
2005-08-04 22:32:38 +02:00
2005-07-04 23:29:22 +02:00
def on_send_button_clicked ( self , widget ) :
2005-08-06 21:14:21 +02:00
if gajim . connections [ self . account ] . connected < = 1 :
#if offline or connecting
ErrorDialog ( _ ( ' Connection not available ' ) ,
2009-07-22 10:58:49 +02:00
_ ( ' Please make sure you are connected with " %s " . ' ) % self . account )
2005-08-06 21:14:21 +02:00
return
2005-07-04 23:29:22 +02:00
begin_iter , end_iter = self . input_tv_buffer . get_bounds ( )
2008-08-08 00:08:08 +02:00
stanza = self . input_tv_buffer . get_text ( begin_iter , end_iter ) . decode (
' utf-8 ' )
2005-07-04 23:29:22 +02:00
if stanza :
gajim . connections [ self . account ] . send_stanza ( stanza )
self . input_tv_buffer . set_text ( ' ' ) # we sent ok, clear the textview
2007-01-15 11:34:53 +01:00
2005-07-04 23:29:22 +02:00
def on_presence_button_clicked ( self , widget ) :
self . input_tv_buffer . set_text (
2009-07-22 10:58:49 +02:00
' <presence><show></show><status></status><priority></priority> '
' </presence> ' )
2005-07-04 23:29:22 +02:00
def on_iq_button_clicked ( self , widget ) :
self . input_tv_buffer . set_text (
2009-07-22 10:58:49 +02:00
' <iq to= " " type= " " ><query xmlns= " " ></query></iq> ' )
2007-01-15 11:34:53 +01:00
2005-07-04 23:29:22 +02:00
def on_message_button_clicked ( self , widget ) :
self . input_tv_buffer . set_text (
2009-07-22 10:58:49 +02:00
' <message to= " " type= " " ><body></body></message> ' )
2005-07-05 01:18:05 +02:00
def on_expander_activate ( self , widget ) :
if not widget . get_expanded ( ) : # it's the opposite!
# it's expanded!!
self . input_textview . grab_focus ( )
2005-08-15 01:21:57 +02:00
2009-11-16 20:56:51 +01:00
#Action that can be done with an incoming list of contacts
TRANSLATED_ACTION = { ' add ' : _ ( ' add ' ) , ' modify ' : _ ( ' modify ' ) ,
' remove ' : _ ( ' remove ' ) }
2009-06-21 03:43:57 +02:00
class RosterItemExchangeWindow :
''' Windows used when someone send you a exchange contact suggestion '''
2009-07-22 10:58:49 +02:00
def __init__ ( self , account , action , exchange_list , jid_from ,
message_body = None ) :
2009-06-21 03:43:57 +02:00
self . account = account
self . action = action
self . exchange_list = exchange_list
self . message_body = message_body
self . jid_from = jid_from
2009-10-02 17:05:04 +02:00
show_dialog = False
2009-06-21 03:43:57 +02:00
# Connect to glade
self . xml = gtkgui_helpers . get_glade ( ' roster_item_exchange_window.glade ' )
self . window = self . xml . get_widget ( ' roster_item_exchange_window ' )
# Add Widgets.
2009-11-05 22:20:45 +01:00
for widget_to_add in [ ' accept_button_label ' , ' type_label ' ,
2009-07-22 10:58:49 +02:00
' body_scrolledwindow ' , ' body_textview ' , ' items_list_treeview ' ] :
2009-06-21 03:43:57 +02:00
self . __dict__ [ widget_to_add ] = self . xml . get_widget ( widget_to_add )
# Set labels
2009-07-22 10:58:49 +02:00
# self.action can be 'add', 'modify' or 'remove'
2009-11-16 20:56:51 +01:00
self . type_label . set_label (
_ ( ' <b> %(jid)s </b> would like you to <b> %(action)s </b> some contacts '
' in your roster. ' ) % { ' jid ' : jid_from ,
' action ' : TRANSLATED_ACTION [ self . action ] } )
2009-06-21 03:43:57 +02:00
if message_body :
2009-11-16 20:56:51 +01:00
buffer_ = self . body_textview . get_buffer ( )
buffer_ . set_text ( self . message_body )
2009-06-21 03:43:57 +02:00
else :
self . body_scrolledwindow . hide ( )
# Treeview
model = gtk . ListStore ( bool , str , str , str , str )
self . items_list_treeview . set_model ( model )
# columns
renderer1 = gtk . CellRendererToggle ( )
renderer1 . set_property ( ' activatable ' , True )
renderer1 . connect ( ' toggled ' , self . toggled_callback )
2009-07-22 10:58:49 +02:00
if self . action == ' add ' :
title = _ ( ' Add ' )
elif self . action == ' modify ' :
title = _ ( ' Modify ' )
elif self . action == ' delete ' :
title = _ ( ' Delete ' )
self . items_list_treeview . insert_column_with_attributes ( - 1 , title ,
renderer1 , active = 0 )
2009-06-21 03:43:57 +02:00
renderer2 = gtk . CellRendererText ( )
2009-07-22 10:58:49 +02:00
self . items_list_treeview . insert_column_with_attributes ( - 1 , _ ( ' Jabber ID ' ) ,
renderer2 , text = 1 )
2009-06-21 03:43:57 +02:00
renderer3 = gtk . CellRendererText ( )
2009-07-22 10:58:49 +02:00
self . items_list_treeview . insert_column_with_attributes ( - 1 , _ ( ' Name ' ) ,
renderer3 , text = 2 )
2009-06-21 03:43:57 +02:00
renderer4 = gtk . CellRendererText ( )
2009-07-22 10:58:49 +02:00
self . items_list_treeview . insert_column_with_attributes ( - 1 , _ ( ' Groups ' ) ,
renderer4 , text = 3 )
2009-06-21 03:43:57 +02:00
# Init contacts
model = self . items_list_treeview . get_model ( )
model . clear ( )
if action == ' add ' :
for jid in self . exchange_list :
groups = ' '
is_in_roster = True
2009-07-22 10:58:49 +02:00
contact = gajim . contacts . get_contact_with_highest_priority (
2009-06-21 03:43:57 +02:00
self . account , jid )
if not contact :
is_in_roster = False
name = self . exchange_list [ jid ] [ 0 ]
num_list = len ( self . exchange_list [ jid ] [ 1 ] )
current = 0
for group in self . exchange_list [ jid ] [ 1 ] :
current + = 1
if contact and not group in contact . groups :
is_in_roster = False
if current == num_list :
groups = groups + group
else :
groups = groups + group + ' , '
if not is_in_roster :
2009-10-02 17:05:04 +02:00
show_dialog = True
2009-11-16 20:56:51 +01:00
iter_ = model . append ( )
model . set ( iter_ , 0 , True , 1 , jid , 2 , name , 3 , groups )
2009-07-22 10:58:49 +02:00
2009-06-22 20:21:39 +02:00
# Change label for accept_button to action name instead of 'OK'.
2009-11-05 22:20:45 +01:00
self . accept_button_label . set_label ( _ ( ' Add ' ) )
2009-06-21 03:43:57 +02:00
elif action == ' modify ' :
for jid in self . exchange_list :
groups = ' '
is_in_roster = True
is_right = True
2009-07-22 10:58:49 +02:00
contact = gajim . contacts . get_contact_with_highest_priority (
2009-06-21 03:43:57 +02:00
self . account , jid )
name = self . exchange_list [ jid ] [ 0 ]
if not contact :
is_in_roster = False
is_right = False
else :
if name != contact . name :
is_right = False
num_list = len ( self . exchange_list [ jid ] [ 1 ] )
current = 0
for group in self . exchange_list [ jid ] [ 1 ] :
current + = 1
if contact and not group in contact . groups :
is_right = False
if current == num_list :
groups = groups + group
else :
groups = groups + group + ' , '
if not is_right and is_in_roster :
2009-10-02 17:05:04 +02:00
show_dialog = True
2009-11-16 20:56:51 +01:00
iter_ = model . append ( )
model . set ( iter_ , 0 , True , 1 , jid , 2 , name , 3 , groups )
2009-07-22 10:58:49 +02:00
2009-06-22 20:21:39 +02:00
# Change label for accept_button to action name instead of 'OK'.
2009-11-05 22:20:45 +01:00
self . accept_button_label . set_label ( _ ( ' Modify ' ) )
2009-06-21 03:43:57 +02:00
elif action == ' delete ' :
for jid in self . exchange_list :
groups = ' '
is_in_roster = True
2009-07-22 10:58:49 +02:00
contact = gajim . contacts . get_contact_with_highest_priority (
2009-06-21 03:43:57 +02:00
self . account , jid )
name = self . exchange_list [ jid ] [ 0 ]
if not contact :
is_in_roster = False
num_list = len ( self . exchange_list [ jid ] [ 1 ] )
current = 0
for group in self . exchange_list [ jid ] [ 1 ] :
current + = 1
if current == num_list :
groups = groups + group
else :
groups = groups + group + ' , '
2009-07-22 10:48:41 +02:00
if is_in_roster :
2009-10-02 17:05:04 +02:00
show_dialog = True
2009-11-16 20:56:51 +01:00
iter_ = model . append ( )
model . set ( iter_ , 0 , True , 1 , jid , 2 , name , 3 , groups )
2009-07-22 10:58:49 +02:00
2009-06-22 20:21:39 +02:00
# Change label for accept_button to action name instead of 'OK'.
2009-11-05 22:20:45 +01:00
self . accept_button_label . set_label ( _ ( ' Delete ' ) )
2009-06-21 03:43:57 +02:00
2009-10-02 17:05:04 +02:00
if show_dialog :
self . window . show_all ( )
self . xml . signal_autoconnect ( self )
2009-06-21 03:43:57 +02:00
def toggled_callback ( self , cell , path ) :
model = self . items_list_treeview . get_model ( )
2009-11-16 20:56:51 +01:00
iter_ = model . get_iter ( path )
model [ iter_ ] [ 0 ] = not cell . get_active ( )
2009-06-21 03:43:57 +02:00
def on_accept_button_clicked ( self , widget ) :
model = self . items_list_treeview . get_model ( )
2009-11-16 20:56:51 +01:00
iter_ = model . get_iter_root ( )
2009-06-21 03:43:57 +02:00
if self . action == ' add ' :
a = 0
2009-11-16 20:56:51 +01:00
while iter_ :
if model [ iter_ ] [ 0 ] :
2009-06-21 03:43:57 +02:00
a + = 1
# it is selected
2009-11-16 20:56:51 +01:00
#remote_jid = model[iter_][1].decode('utf-8')
2009-07-22 10:58:49 +02:00
message = _ ( ' %s suggested me to add you in my roster. '
% self . jid_from )
2009-06-21 03:43:57 +02:00
# keep same groups and same nickname
2009-11-16 20:56:51 +01:00
groups = model [ iter_ ] [ 3 ] . split ( ' , ' )
2009-06-21 03:43:57 +02:00
if groups == [ ' ' ] :
groups = [ ]
2009-11-16 20:56:51 +01:00
jid = model [ iter_ ] [ 1 ] . decode ( ' utf-8 ' )
2009-07-23 22:57:33 +02:00
if gajim . jid_is_transport ( self . jid_from ) :
gajim . connections [ self . account ] . automatically_added . append (
jid )
gajim . interface . roster . req_sub ( self , jid , message ,
2009-11-16 20:56:51 +01:00
self . account , groups = groups , nickname = model [ iter_ ] [ 2 ] ,
2009-07-22 10:58:49 +02:00
auto_auth = True )
2009-11-16 20:56:51 +01:00
iter_ = model . iter_next ( iter_ )
InformationDialog ( _ ( ' Added %s contacts ' ) % str ( a ) )
2009-06-21 03:43:57 +02:00
elif self . action == ' modify ' :
a = 0
2009-11-16 20:56:51 +01:00
while iter_ :
if model [ iter_ ] [ 0 ] :
2009-06-21 03:43:57 +02:00
a + = 1
# it is selected
2009-11-16 20:56:51 +01:00
jid = model [ iter_ ] [ 1 ] . decode ( ' utf-8 ' )
2009-06-21 03:43:57 +02:00
# keep same groups and same nickname
2009-11-16 20:56:51 +01:00
groups = model [ iter_ ] [ 3 ] . split ( ' , ' )
2009-06-21 03:43:57 +02:00
if groups == [ ' ' ] :
groups = [ ]
for u in gajim . contacts . get_contact ( self . account , jid ) :
2009-11-16 20:56:51 +01:00
u . name = model [ iter_ ] [ 2 ]
2009-07-22 10:58:49 +02:00
gajim . connections [ self . account ] . update_contact ( jid ,
2009-11-16 20:56:51 +01:00
model [ iter_ ] [ 2 ] , groups )
2009-06-21 03:43:57 +02:00
self . draw_contact ( jid , account )
# Update opened chat
ctrl = gajim . interface . msg_win_mgr . get_control ( jid , self . account )
if ctrl :
ctrl . update_ui ( )
2009-07-22 10:58:49 +02:00
win = gajim . interface . msg_win_mgr . get_window ( jid ,
self . account )
2009-06-21 03:43:57 +02:00
win . redraw_tab ( ctrl )
win . show_title ( )
2009-11-16 20:56:51 +01:00
iter_ = model . iter_next ( iter_ )
2009-06-21 03:43:57 +02:00
elif self . action == ' delete ' :
a = 0
2009-11-16 20:56:51 +01:00
while iter_ :
if model [ iter_ ] [ 0 ] :
2009-06-21 03:43:57 +02:00
a + = 1
# it is selected
2009-11-16 20:56:51 +01:00
jid = model [ iter_ ] [ 1 ] . decode ( ' utf-8 ' )
2009-06-21 03:43:57 +02:00
gajim . connections [ self . account ] . unsubscribe ( jid )
2009-07-22 10:48:41 +02:00
gajim . interface . roster . remove_contact ( jid , self . account )
2009-06-21 03:43:57 +02:00
gajim . contacts . remove_jid ( self . account , jid )
2009-11-16 20:56:51 +01:00
iter_ = model . iter_next ( iter_ )
InformationDialog ( _ ( ' Removed %s contacts ' ) % str ( a ) )
2009-06-21 03:43:57 +02:00
self . window . destroy ( )
2009-07-22 10:58:49 +02:00
2009-06-21 03:43:57 +02:00
def on_cancel_button_clicked ( self , widget ) :
self . window . destroy ( )
2009-07-22 10:58:49 +02:00
2009-06-21 03:43:57 +02:00
2006-07-17 21:30:53 +02:00
class PrivacyListWindow :
2006-11-18 21:52:28 +01:00
''' Window that is used for creating NEW or EDITING already there privacy
lists '''
def __init__ ( self , account , privacy_list_name , action ) :
''' action is ' EDIT ' or ' NEW ' depending on if we create a new priv list
or edit an already existing one '''
2006-07-17 21:30:53 +02:00
self . account = account
2006-11-18 21:52:28 +01:00
self . privacy_list_name = privacy_list_name
2006-07-17 21:30:53 +02:00
# Dicts and Default Values
self . active_rule = ' '
self . global_rules = { }
self . list_of_groups = { }
2009-11-24 15:06:04 +01:00
self . max_order = 0
2006-07-17 21:30:53 +02:00
# Default Edit Values
self . edit_rule_type = ' jid '
self . allow_deny = ' allow '
# Connect to glade
2006-11-18 21:52:28 +01:00
self . xml = gtkgui_helpers . get_glade ( ' privacy_list_window.glade ' )
2006-07-17 21:30:53 +02:00
self . window = self . xml . get_widget ( ' privacy_list_edit_window ' )
# Add Widgets
2008-10-11 11:42:59 +02:00
for widget_to_add in ( ' title_hbox ' , ' privacy_lists_title_label ' ,
2009-10-16 15:58:21 +02:00
' list_of_rules_label ' , ' add_edit_rule_label ' , ' delete_open_buttons_hbox ' ,
' privacy_list_active_checkbutton ' , ' privacy_list_default_checkbutton ' ,
' list_of_rules_combobox ' , ' delete_open_buttons_hbox ' ,
' delete_rule_button ' , ' open_rule_button ' , ' edit_allow_radiobutton ' ,
' edit_deny_radiobutton ' , ' edit_type_jabberid_radiobutton ' ,
' edit_type_jabberid_entry ' , ' edit_type_group_radiobutton ' ,
' edit_type_group_combobox ' , ' edit_type_subscription_radiobutton ' ,
' edit_type_subscription_combobox ' , ' edit_type_select_all_radiobutton ' ,
' edit_queries_send_checkbutton ' , ' edit_send_messages_checkbutton ' ,
' edit_view_status_checkbutton ' , ' edit_all_checkbutton ' ,
' edit_order_spinbutton ' , ' new_rule_button ' , ' save_rule_button ' ,
' privacy_list_refresh_button ' , ' privacy_list_close_button ' ,
' edit_send_status_checkbutton ' , ' add_edit_vbox ' ,
' privacy_list_active_checkbutton ' , ' privacy_list_default_checkbutton ' ) :
2006-07-17 21:30:53 +02:00
self . __dict__ [ widget_to_add ] = self . xml . get_widget ( widget_to_add )
self . privacy_lists_title_label . set_label (
_ ( ' Privacy List <b><i> %s </i></b> ' ) % \
2007-01-17 00:26:38 +01:00
gobject . markup_escape_text ( self . privacy_list_name ) )
2006-07-17 21:30:53 +02:00
if len ( gajim . connections ) > 1 :
title = _ ( ' Privacy List for %s ' ) % self . account
else :
title = _ ( ' Privacy List ' )
self . delete_rule_button . set_sensitive ( False )
self . open_rule_button . set_sensitive ( False )
self . privacy_list_active_checkbutton . set_sensitive ( False )
self . privacy_list_default_checkbutton . set_sensitive ( False )
2006-11-18 21:52:28 +01:00
self . list_of_rules_combobox . set_sensitive ( False )
2006-07-17 21:30:53 +02:00
2007-06-03 12:04:20 +02:00
# set jabber id completion
jids_list_store = gtk . ListStore ( gobject . TYPE_STRING )
for jid in gajim . contacts . get_jid_list ( self . account ) :
2008-01-22 17:06:16 +01:00
jids_list_store . append ( [ jid ] )
2007-06-03 12:04:20 +02:00
jid_entry_completion = gtk . EntryCompletion ( )
jid_entry_completion . set_text_column ( 0 )
jid_entry_completion . set_model ( jids_list_store )
jid_entry_completion . set_popup_completion ( True )
2007-08-09 17:39:18 +02:00
self . edit_type_jabberid_entry . set_completion ( jid_entry_completion )
2006-11-18 21:52:28 +01:00
if action == ' EDIT ' :
2006-07-17 21:30:53 +02:00
self . refresh_rules ( )
count = 0
for group in gajim . groups [ self . account ] :
self . list_of_groups [ group ] = count
count + = 1
self . edit_type_group_combobox . append_text ( group )
2008-01-22 17:06:16 +01:00
self . edit_type_group_combobox . set_active ( 0 )
2006-07-17 21:30:53 +02:00
self . window . set_title ( title )
self . window . show_all ( )
self . add_edit_vbox . hide ( )
2006-11-18 21:52:28 +01:00
2006-07-17 21:30:53 +02:00
self . xml . signal_autoconnect ( self )
def on_privacy_list_edit_window_destroy ( self , widget ) :
2006-11-18 21:52:28 +01:00
key_name = ' privacy_list_ %s ' % self . privacy_list_name
if key_name in gajim . interface . instances [ self . account ] :
del gajim . interface . instances [ self . account ] [ key_name ]
2006-07-17 21:30:53 +02:00
def check_active_default ( self , a_d_dict ) :
2006-11-18 21:52:28 +01:00
if a_d_dict [ ' active ' ] == self . privacy_list_name :
2006-07-17 21:30:53 +02:00
self . privacy_list_active_checkbutton . set_active ( True )
else :
self . privacy_list_active_checkbutton . set_active ( False )
2006-11-18 21:52:28 +01:00
if a_d_dict [ ' default ' ] == self . privacy_list_name :
2006-07-17 21:30:53 +02:00
self . privacy_list_default_checkbutton . set_active ( True )
else :
2008-01-22 17:06:16 +01:00
self . privacy_list_default_checkbutton . set_active ( False )
2006-07-17 21:30:53 +02:00
def privacy_list_received ( self , rules ) :
self . list_of_rules_combobox . get_model ( ) . clear ( )
self . global_rules = { }
for rule in rules :
2008-10-07 22:41:59 +02:00
if ' type ' in rule :
2008-08-01 11:30:36 +02:00
text_item = _ ( ' Order: %(order)s , action: %(action)s , type: %(type)s '
2009-10-16 15:58:21 +02:00
' , value: %(value)s ' ) % { ' order ' : rule [ ' order ' ] ,
' action ' : rule [ ' action ' ] , ' type ' : rule [ ' type ' ] ,
' value ' : rule [ ' value ' ] }
2006-07-17 21:30:53 +02:00
else :
2008-08-01 11:30:36 +02:00
text_item = _ ( ' Order: %(order)s , action: %(action)s ' ) % \
2009-10-16 15:58:21 +02:00
{ ' order ' : rule [ ' order ' ] , ' action ' : rule [ ' action ' ] }
2009-11-24 15:06:04 +01:00
if int ( rule [ ' order ' ] ) > self . max_order :
self . max_order = int ( rule [ ' order ' ] )
2006-07-17 21:30:53 +02:00
self . global_rules [ text_item ] = rule
self . list_of_rules_combobox . append_text ( text_item )
if len ( rules ) == 0 :
self . title_hbox . set_sensitive ( False )
self . list_of_rules_combobox . set_sensitive ( False )
self . delete_rule_button . set_sensitive ( False )
self . open_rule_button . set_sensitive ( False )
self . privacy_list_active_checkbutton . set_sensitive ( False )
self . privacy_list_default_checkbutton . set_sensitive ( False )
else :
self . list_of_rules_combobox . set_active ( 0 )
self . title_hbox . set_sensitive ( True )
self . list_of_rules_combobox . set_sensitive ( True )
self . delete_rule_button . set_sensitive ( True )
self . open_rule_button . set_sensitive ( True )
self . privacy_list_active_checkbutton . set_sensitive ( True )
self . privacy_list_default_checkbutton . set_sensitive ( True )
self . reset_fields ( )
gajim . connections [ self . account ] . get_active_default_lists ( )
def refresh_rules ( self ) :
2006-11-18 21:52:28 +01:00
gajim . connections [ self . account ] . get_privacy_list ( self . privacy_list_name )
2006-07-17 21:30:53 +02:00
def on_delete_rule_button_clicked ( self , widget ) :
tags = [ ]
for rule in self . global_rules :
2006-11-18 21:52:28 +01:00
if rule != self . list_of_rules_combobox . get_active_text ( ) :
2006-07-17 21:30:53 +02:00
tags . append ( self . global_rules [ rule ] )
gajim . connections [ self . account ] . set_privacy_list (
2006-11-18 21:52:28 +01:00
self . privacy_list_name , tags )
2006-07-17 21:30:53 +02:00
self . privacy_list_received ( tags )
self . add_edit_vbox . hide ( )
2006-11-18 21:52:28 +01:00
if not tags : # we removed latest rule
if ' privacy_lists ' in gajim . interface . instances [ self . account ] :
win = gajim . interface . instances [ self . account ] [ ' privacy_lists ' ]
win . remove_privacy_list_from_combobox ( self . privacy_list_name )
win . draw_widgets ( )
2006-07-17 21:30:53 +02:00
def on_open_rule_button_clicked ( self , widget ) :
self . add_edit_rule_label . set_label (
2006-11-18 21:52:28 +01:00
_ ( ' <b>Edit a rule</b> ' ) )
2006-07-17 21:30:53 +02:00
active_num = self . list_of_rules_combobox . get_active ( )
if active_num == - 1 :
self . active_rule = ' '
else :
self . active_rule = \
self . list_of_rules_combobox . get_active_text ( ) . decode ( ' utf-8 ' )
if self . active_rule != ' ' :
rule_info = self . global_rules [ self . active_rule ]
self . edit_order_spinbutton . set_value ( int ( rule_info [ ' order ' ] ) )
2008-10-07 22:41:59 +02:00
if ' type ' in rule_info :
2006-07-17 21:30:53 +02:00
if rule_info [ ' type ' ] == ' jid ' :
self . edit_type_jabberid_radiobutton . set_active ( True )
self . edit_type_jabberid_entry . set_text ( rule_info [ ' value ' ] )
elif rule_info [ ' type ' ] == ' group ' :
self . edit_type_group_radiobutton . set_active ( True )
2008-10-07 22:41:59 +02:00
if rule_info [ ' value ' ] in self . list_of_groups :
2006-07-17 21:30:53 +02:00
self . edit_type_group_combobox . set_active (
self . list_of_groups [ rule_info [ ' value ' ] ] )
else :
self . edit_type_group_combobox . set_active ( 0 )
elif rule_info [ ' type ' ] == ' subscription ' :
self . edit_type_subscription_radiobutton . set_active ( True )
sub_value = rule_info [ ' value ' ]
if sub_value == ' none ' :
self . edit_type_subscription_combobox . set_active ( 0 )
elif sub_value == ' both ' :
self . edit_type_subscription_combobox . set_active ( 1 )
elif sub_value == ' from ' :
self . edit_type_subscription_combobox . set_active ( 2 )
elif sub_value == ' to ' :
self . edit_type_subscription_combobox . set_active ( 3 )
else :
self . edit_type_select_all_radiobutton . set_active ( True )
else :
self . edit_type_select_all_radiobutton . set_active ( True )
self . edit_send_messages_checkbutton . set_active ( False )
self . edit_queries_send_checkbutton . set_active ( False )
self . edit_view_status_checkbutton . set_active ( False )
self . edit_send_status_checkbutton . set_active ( False )
2009-10-16 15:58:21 +02:00
self . edit_all_checkbutton . set_active ( False )
if not rule_info [ ' child ' ] :
self . edit_all_checkbutton . set_active ( True )
else :
if ' presence-out ' in rule_info [ ' child ' ] :
2006-07-17 21:30:53 +02:00
self . edit_send_status_checkbutton . set_active ( True )
2009-10-16 15:58:21 +02:00
if ' presence-in ' in rule_info [ ' child ' ] :
2006-07-17 21:30:53 +02:00
self . edit_view_status_checkbutton . set_active ( True )
2009-10-16 15:58:21 +02:00
if ' iq ' in rule_info [ ' child ' ] :
2006-07-17 21:30:53 +02:00
self . edit_queries_send_checkbutton . set_active ( True )
2009-10-16 15:58:21 +02:00
if ' message ' in rule_info [ ' child ' ] :
2006-07-17 21:30:53 +02:00
self . edit_send_messages_checkbutton . set_active ( True )
2006-11-18 21:52:28 +01:00
2006-07-17 21:30:53 +02:00
if rule_info [ ' action ' ] == ' allow ' :
2006-11-18 21:52:28 +01:00
self . edit_allow_radiobutton . set_active ( True )
2006-07-17 21:30:53 +02:00
else :
2006-11-18 21:52:28 +01:00
self . edit_deny_radiobutton . set_active ( True )
2006-07-17 21:30:53 +02:00
self . add_edit_vbox . show ( )
2006-11-18 21:52:28 +01:00
2009-10-16 15:58:21 +02:00
def on_edit_all_checkbutton_toggled ( self , widget ) :
if widget . get_active ( ) :
self . edit_send_messages_checkbutton . set_active ( True )
self . edit_queries_send_checkbutton . set_active ( True )
self . edit_view_status_checkbutton . set_active ( True )
self . edit_send_status_checkbutton . set_active ( True )
self . edit_send_messages_checkbutton . set_sensitive ( False )
self . edit_queries_send_checkbutton . set_sensitive ( False )
self . edit_view_status_checkbutton . set_sensitive ( False )
self . edit_send_status_checkbutton . set_sensitive ( False )
else :
self . edit_send_messages_checkbutton . set_active ( False )
self . edit_queries_send_checkbutton . set_active ( False )
self . edit_view_status_checkbutton . set_active ( False )
self . edit_send_status_checkbutton . set_active ( False )
self . edit_send_messages_checkbutton . set_sensitive ( True )
self . edit_queries_send_checkbutton . set_sensitive ( True )
self . edit_view_status_checkbutton . set_sensitive ( True )
self . edit_send_status_checkbutton . set_sensitive ( True )
2006-07-17 21:30:53 +02:00
def on_privacy_list_active_checkbutton_toggled ( self , widget ) :
if widget . get_active ( ) :
2006-11-18 21:52:28 +01:00
gajim . connections [ self . account ] . set_active_list (
self . privacy_list_name )
2006-07-17 21:30:53 +02:00
else :
gajim . connections [ self . account ] . set_active_list ( None )
def on_privacy_list_default_checkbutton_toggled ( self , widget ) :
if widget . get_active ( ) :
2006-11-18 21:52:28 +01:00
gajim . connections [ self . account ] . set_default_list (
self . privacy_list_name )
2006-07-17 21:30:53 +02:00
else :
gajim . connections [ self . account ] . set_default_list ( None )
def on_new_rule_button_clicked ( self , widget ) :
self . reset_fields ( )
self . add_edit_vbox . show ( )
2006-11-18 21:52:28 +01:00
2006-07-17 21:30:53 +02:00
def reset_fields ( self ) :
self . edit_type_jabberid_entry . set_text ( ' ' )
self . edit_allow_radiobutton . set_active ( True )
self . edit_type_jabberid_radiobutton . set_active ( True )
self . active_rule = ' '
self . edit_send_messages_checkbutton . set_active ( False )
self . edit_queries_send_checkbutton . set_active ( False )
self . edit_view_status_checkbutton . set_active ( False )
self . edit_send_status_checkbutton . set_active ( False )
2009-10-16 15:58:21 +02:00
self . edit_all_checkbutton . set_active ( False )
2009-11-24 15:06:04 +01:00
self . edit_order_spinbutton . set_value ( self . max_order + 1 )
2006-07-17 21:30:53 +02:00
self . edit_type_group_combobox . set_active ( 0 )
self . edit_type_subscription_combobox . set_active ( 0 )
self . add_edit_rule_label . set_label (
_ ( ' <b>Add a rule</b> ' ) )
def get_current_tags ( self ) :
if self . edit_type_jabberid_radiobutton . get_active ( ) :
edit_type = ' jid '
2006-11-18 21:52:28 +01:00
edit_value = self . edit_type_jabberid_entry . get_text ( )
2006-07-17 21:30:53 +02:00
elif self . edit_type_group_radiobutton . get_active ( ) :
edit_type = ' group '
2006-11-18 21:52:28 +01:00
edit_value = self . edit_type_group_combobox . get_active_text ( )
2006-07-17 21:30:53 +02:00
elif self . edit_type_subscription_radiobutton . get_active ( ) :
edit_type = ' subscription '
subs = [ ' none ' , ' both ' , ' from ' , ' to ' ]
edit_value = subs [ self . edit_type_subscription_combobox . get_active ( ) ]
elif self . edit_type_select_all_radiobutton . get_active ( ) :
edit_type = ' '
edit_value = ' '
edit_order = str ( self . edit_order_spinbutton . get_value_as_int ( ) )
if self . edit_allow_radiobutton . get_active ( ) :
edit_deny = ' allow '
else :
edit_deny = ' deny '
child = [ ]
2009-10-16 15:58:21 +02:00
if not self . edit_all_checkbutton . get_active ( ) :
if self . edit_send_messages_checkbutton . get_active ( ) :
child . append ( ' message ' )
if self . edit_queries_send_checkbutton . get_active ( ) :
child . append ( ' iq ' )
if self . edit_send_status_checkbutton . get_active ( ) :
child . append ( ' presence-out ' )
if self . edit_view_status_checkbutton . get_active ( ) :
child . append ( ' presence-in ' )
2006-07-17 21:30:53 +02:00
if edit_type != ' ' :
return { ' order ' : edit_order , ' action ' : edit_deny ,
2009-06-21 03:43:57 +02:00
' type ' : edit_type , ' value ' : edit_value , ' child ' : child }
2006-07-17 21:30:53 +02:00
return { ' order ' : edit_order , ' action ' : edit_deny , ' child ' : child }
def on_save_rule_button_clicked ( self , widget ) :
tags = [ ]
current_tags = self . get_current_tags ( )
2009-11-24 15:06:04 +01:00
if int ( current_tags [ ' order ' ] ) > self . max_order :
self . max_order = int ( current_tags [ ' order ' ] )
2006-07-17 21:30:53 +02:00
if self . active_rule == ' ' :
tags . append ( current_tags )
for rule in self . global_rules :
if rule != self . active_rule :
tags . append ( self . global_rules [ rule ] )
else :
tags . append ( current_tags )
2006-11-18 21:52:28 +01:00
gajim . connections [ self . account ] . set_privacy_list (
self . privacy_list_name , tags )
2007-06-03 12:04:20 +02:00
self . refresh_rules ( )
2006-07-17 21:30:53 +02:00
self . add_edit_vbox . hide ( )
2006-11-18 21:52:28 +01:00
if ' privacy_lists ' in gajim . interface . instances [ self . account ] :
win = gajim . interface . instances [ self . account ] [ ' privacy_lists ' ]
win . add_privacy_list_to_combobox ( self . privacy_list_name )
win . draw_widgets ( )
2006-07-17 21:30:53 +02:00
def on_list_of_rules_combobox_changed ( self , widget ) :
self . add_edit_vbox . hide ( )
def on_edit_type_radiobutton_changed ( self , widget , radiobutton ) :
active_bool = widget . get_active ( )
if active_bool :
self . edit_rule_type = radiobutton
def on_edit_allow_radiobutton_changed ( self , widget , radiobutton ) :
active_bool = widget . get_active ( )
if active_bool :
self . allow_deny = radiobutton
2006-11-18 21:52:28 +01:00
def on_close_button_clicked ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . window . destroy ( )
class PrivacyListsWindow :
2006-11-18 21:52:28 +01:00
''' Window that is the main window for Privacy Lists;
we can list there the privacy lists and ask to create a new one
or edit an already there one '''
2006-07-17 21:30:53 +02:00
def __init__ ( self , account ) :
self . account = account
2008-01-22 17:06:16 +01:00
self . privacy_lists_save = [ ]
2006-07-17 21:30:53 +02:00
2006-11-18 21:52:28 +01:00
self . xml = gtkgui_helpers . get_glade ( ' privacy_lists_window.glade ' )
2006-07-17 21:30:53 +02:00
self . window = self . xml . get_widget ( ' privacy_lists_first_window ' )
2008-10-11 11:42:59 +02:00
for widget_to_add in ( ' list_of_privacy_lists_combobox ' ,
2009-06-21 03:43:57 +02:00
' delete_privacy_list_button ' , ' open_privacy_list_button ' ,
' new_privacy_list_button ' , ' new_privacy_list_entry ' ,
' privacy_lists_refresh_button ' , ' close_privacy_lists_window_button ' ) :
2006-11-18 21:52:28 +01:00
self . __dict__ [ widget_to_add ] = self . xml . get_widget (
2008-01-22 17:06:16 +01:00
widget_to_add )
2006-07-17 21:30:53 +02:00
2006-11-18 21:52:28 +01:00
self . draw_privacy_lists_in_combobox ( [ ] )
2006-07-17 21:30:53 +02:00
self . privacy_lists_refresh ( )
self . enabled = True
if len ( gajim . connections ) > 1 :
title = _ ( ' Privacy Lists for %s ' ) % self . account
else :
title = _ ( ' Privacy Lists ' )
self . window . set_title ( title )
self . window . show_all ( )
self . xml . signal_autoconnect ( self )
def on_privacy_lists_first_window_destroy ( self , widget ) :
2006-11-18 21:52:28 +01:00
if ' privacy_lists ' in gajim . interface . instances [ self . account ] :
2006-07-17 21:30:53 +02:00
del gajim . interface . instances [ self . account ] [ ' privacy_lists ' ]
2006-11-18 21:52:28 +01:00
def remove_privacy_list_from_combobox ( self , privacy_list ) :
if privacy_list not in self . privacy_lists_save :
return
privacy_list_index = self . privacy_lists_save . index ( privacy_list )
self . list_of_privacy_lists_combobox . remove_text ( privacy_list_index )
self . privacy_lists_save . remove ( privacy_list )
def add_privacy_list_to_combobox ( self , privacy_list ) :
if privacy_list in self . privacy_lists_save :
return
self . list_of_privacy_lists_combobox . append_text ( privacy_list )
self . privacy_lists_save . append ( privacy_list )
def draw_privacy_lists_in_combobox ( self , privacy_lists ) :
2006-07-17 21:30:53 +02:00
self . list_of_privacy_lists_combobox . set_active ( - 1 )
self . list_of_privacy_lists_combobox . get_model ( ) . clear ( )
2006-11-18 21:52:28 +01:00
self . privacy_lists_save = [ ]
for add_item in privacy_lists :
self . add_privacy_list_to_combobox ( add_item )
self . draw_widgets ( )
def draw_widgets ( self ) :
if len ( self . privacy_lists_save ) == 0 :
2006-07-17 21:30:53 +02:00
self . list_of_privacy_lists_combobox . set_sensitive ( False )
2006-11-18 21:52:28 +01:00
self . open_privacy_list_button . set_sensitive ( False )
self . delete_privacy_list_button . set_sensitive ( False )
2006-07-17 21:30:53 +02:00
else :
self . list_of_privacy_lists_combobox . set_sensitive ( True )
self . list_of_privacy_lists_combobox . set_active ( 0 )
2006-11-18 21:52:28 +01:00
self . open_privacy_list_button . set_sensitive ( True )
self . delete_privacy_list_button . set_sensitive ( True )
2006-07-17 21:30:53 +02:00
def on_close_button_clicked ( self , widget ) :
self . window . destroy ( )
def on_delete_privacy_list_button_clicked ( self , widget ) :
active_list = self . privacy_lists_save [
self . list_of_privacy_lists_combobox . get_active ( ) ]
gajim . connections [ self . account ] . del_privacy_list ( active_list )
2007-01-15 11:34:53 +01:00
2007-01-11 21:21:53 +01:00
def privacy_list_removed ( self , active_list ) :
2006-07-17 21:30:53 +02:00
self . privacy_lists_save . remove ( active_list )
2006-11-18 21:52:28 +01:00
self . privacy_lists_received ( { ' lists ' : self . privacy_lists_save } )
2006-07-17 21:30:53 +02:00
def privacy_lists_received ( self , lists ) :
if not lists :
return
2006-11-18 21:52:28 +01:00
privacy_lists = [ ]
2006-07-17 21:30:53 +02:00
for privacy_list in lists [ ' lists ' ] :
2006-11-18 21:52:28 +01:00
privacy_lists . append ( privacy_list )
self . draw_privacy_lists_in_combobox ( privacy_lists )
2006-07-17 21:30:53 +02:00
def privacy_lists_refresh ( self ) :
gajim . connections [ self . account ] . get_privacy_lists ( )
def on_new_privacy_list_button_clicked ( self , widget ) :
2006-11-18 21:52:28 +01:00
name = self . new_privacy_list_entry . get_text ( )
if not name :
ErrorDialog ( _ ( ' Invalid List Name ' ) ,
2009-06-21 03:43:57 +02:00
_ ( ' You must enter a name to create a privacy list. ' ) )
2006-11-18 21:52:28 +01:00
return
key_name = ' privacy_list_ %s ' % name
2008-10-07 22:41:59 +02:00
if key_name in gajim . interface . instances [ self . account ] :
2006-11-18 21:52:28 +01:00
gajim . interface . instances [ self . account ] [ key_name ] . window . present ( )
2006-07-17 21:30:53 +02:00
else :
2006-11-18 21:52:28 +01:00
gajim . interface . instances [ self . account ] [ key_name ] = \
2009-06-21 03:43:57 +02:00
PrivacyListWindow ( self . account , name , ' NEW ' )
2006-07-17 21:30:53 +02:00
self . new_privacy_list_entry . set_text ( ' ' )
def on_privacy_lists_refresh_button_clicked ( self , widget ) :
self . privacy_lists_refresh ( )
def on_open_privacy_list_button_clicked ( self , widget ) :
name = self . privacy_lists_save [
self . list_of_privacy_lists_combobox . get_active ( ) ]
2006-11-18 21:52:28 +01:00
key_name = ' privacy_list_ %s ' % name
2008-10-07 22:41:59 +02:00
if key_name in gajim . interface . instances [ self . account ] :
2006-11-18 21:52:28 +01:00
gajim . interface . instances [ self . account ] [ key_name ] . window . present ( )
2006-07-17 21:30:53 +02:00
else :
2006-11-18 21:52:28 +01:00
gajim . interface . instances [ self . account ] [ key_name ] = \
2009-06-21 03:43:57 +02:00
PrivacyListWindow ( self . account , name , ' EDIT ' )
2006-07-17 21:30:53 +02:00
2005-09-11 17:02:22 +02:00
class InvitationReceivedDialog :
2008-07-31 08:23:03 +02:00
def __init__ ( self , account , room_jid , contact_jid , password = None ,
2009-06-21 03:43:57 +02:00
comment = None , is_continued = False ) :
2006-04-02 18:11:21 +02:00
self . room_jid = room_jid
self . account = account
2007-08-09 17:39:18 +02:00
self . password = password
2007-12-12 09:44:46 +01:00
self . is_continued = is_continued
2006-07-17 21:30:53 +02:00
2008-07-19 19:36:21 +02:00
pritext = _ ( ''' You are invited to a groupchat ''' )
2007-01-15 11:34:53 +01:00
#Don't translate $Contact
2007-12-12 09:44:46 +01:00
if is_continued :
2008-07-19 19:36:21 +02:00
sectext = _ ( ' $Contact has invited you to join a discussion ' )
2007-12-12 09:44:46 +01:00
else :
2008-07-19 19:36:21 +02:00
sectext = _ ( ' $Contact has invited you to group chat %(room_jid)s ' ) \
2009-06-21 03:43:57 +02:00
% { ' room_jid ' : room_jid }
2007-01-15 11:34:53 +01:00
contact = gajim . contacts . get_first_contact_from_jid ( account , contact_jid )
2008-07-19 19:36:21 +02:00
contact_text = contact and contact . name or contact_jid
sectext = sectext . replace ( ' $Contact ' , contact_text )
2006-03-10 14:43:20 +01:00
2006-03-10 15:01:57 +01:00
if comment : # only if not None and not ''
2007-12-12 09:44:46 +01:00
comment = gobject . markup_escape_text ( comment )
2008-07-19 19:36:21 +02:00
comment = _ ( ' Comment: %s ' ) % comment
sectext + = ' \n \n %s ' % comment
sectext + = ' \n \n ' + _ ( ' Do you want to accept the invitation? ' )
2008-07-31 08:23:03 +02:00
def on_yes ( checked ) :
2008-07-19 19:36:21 +02:00
try :
if self . is_continued :
gajim . interface . join_gc_room ( self . account , self . room_jid ,
2009-06-21 03:43:57 +02:00
gajim . nicks [ self . account ] , None , is_continued = True )
2008-07-19 19:36:21 +02:00
else :
JoinGroupchatWindow ( self . account , self . room_jid )
except GajimGeneralException :
pass
2007-01-15 11:34:53 +01:00
2008-12-02 16:53:23 +01:00
YesNoDialog ( pritext , sectext , on_response_yes = on_yes )
2008-07-31 08:23:03 +02:00
2005-12-02 17:18:04 +01:00
class ProgressDialog :
2005-12-02 18:16:23 +01:00
def __init__ ( self , title_text , during_text , messages_queue ) :
2005-12-02 17:18:04 +01:00
''' during text is what to show during the procedure,
messages_queue has the message to show
in the textview '''
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' progress_dialog.glade ' )
2005-12-05 12:13:08 +01:00
self . dialog = self . xml . get_widget ( ' progress_dialog ' )
2005-12-02 18:16:23 +01:00
self . label = self . xml . get_widget ( ' label ' )
2005-12-02 17:18:04 +01:00
self . label . set_markup ( ' <big> ' + during_text + ' </big> ' )
2005-12-02 18:16:23 +01:00
self . progressbar = self . xml . get_widget ( ' progressbar ' )
2005-12-05 12:13:08 +01:00
self . dialog . set_title ( title_text )
2006-04-08 00:57:27 +02:00
self . dialog . set_default_size ( 450 , 250 )
2009-04-05 20:35:59 +02:00
self . window . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
2005-12-05 12:13:08 +01:00
self . dialog . show_all ( )
2005-12-02 18:16:23 +01:00
self . xml . signal_autoconnect ( self )
2007-01-15 11:34:53 +01:00
2005-12-02 17:18:04 +01:00
self . update_progressbar_timeout_id = gobject . timeout_add ( 100 ,
2009-06-21 03:43:57 +02:00
self . update_progressbar )
2006-04-08 00:57:27 +02:00
2005-12-02 17:18:04 +01:00
def update_progressbar ( self ) :
2006-04-08 00:57:27 +02:00
if self . dialog :
self . progressbar . pulse ( )
return True # loop forever
return False
2005-12-02 17:18:04 +01:00
def on_progress_dialog_delete_event ( self , widget , event ) :
return True # WM's X button or Escape key should not destroy the window
2006-03-15 18:45:55 +01:00
2006-04-10 19:21:28 +02:00
class SoundChooserDialog ( FileChooserDialog ) :
2008-08-08 00:08:08 +02:00
def __init__ ( self , path_to_snd_file = ' ' , on_response_ok = None ,
2009-06-21 03:43:57 +02:00
on_response_cancel = None ) :
2006-03-15 18:45:55 +01:00
''' optionally accepts path_to_snd_file so it has that as selected '''
2006-04-10 19:21:28 +02:00
def on_ok ( widget , callback ) :
''' check if file exists and call callback '''
path_to_snd_file = self . get_filename ( )
2006-04-12 15:56:30 +02:00
path_to_snd_file = gtkgui_helpers . decode_filechooser_file_paths (
( path_to_snd_file , ) ) [ 0 ]
2006-04-10 19:21:28 +02:00
if os . path . exists ( path_to_snd_file ) :
callback ( widget , path_to_snd_file )
FileChooserDialog . __init__ ( self ,
2009-06-21 03:43:57 +02:00
title_text = _ ( ' Choose Sound ' ) ,
action = gtk . FILE_CHOOSER_ACTION_OPEN ,
buttons = ( gtk . STOCK_CANCEL , gtk . RESPONSE_CANCEL ,
gtk . STOCK_OPEN , gtk . RESPONSE_OK ) ,
default_response = gtk . RESPONSE_OK ,
current_folder = gajim . config . get ( ' last_sounds_dir ' ) ,
on_response_ok = ( on_ok , on_response_ok ) ,
on_response_cancel = on_response_cancel )
2006-03-15 18:45:55 +01:00
2008-12-03 18:16:04 +01:00
filter_ = gtk . FileFilter ( )
filter_ . set_name ( _ ( ' All files ' ) )
filter_ . add_pattern ( ' * ' )
self . add_filter ( filter_ )
2006-03-15 18:45:55 +01:00
2008-12-03 18:16:04 +01:00
filter_ = gtk . FileFilter ( )
filter_ . set_name ( _ ( ' Wav Sounds ' ) )
filter_ . add_pattern ( ' *.wav ' )
self . add_filter ( filter_ )
self . set_filter ( filter_ )
2006-04-10 19:21:28 +02:00
2009-05-10 21:32:57 +02:00
path_to_snd_file = helpers . check_soundfile_path ( path_to_snd_file )
2006-04-10 21:49:24 +02:00
if path_to_snd_file :
2009-05-10 21:32:57 +02:00
# set_filename accept only absolute path
path_to_snd_file = os . path . abspath ( path_to_snd_file )
2006-04-10 21:49:24 +02:00
self . set_filename ( path_to_snd_file )
class ImageChooserDialog ( FileChooserDialog ) :
2008-08-08 00:08:08 +02:00
def __init__ ( self , path_to_file = ' ' , on_response_ok = None ,
2009-06-21 03:43:57 +02:00
on_response_cancel = None ) :
2006-04-10 21:49:24 +02:00
''' optionally accepts path_to_snd_file so it has that as selected '''
def on_ok ( widget , callback ) :
''' check if file exists and call callback '''
path_to_file = self . get_filename ( )
2006-09-13 18:47:58 +02:00
if not path_to_file :
return
2006-04-12 15:56:30 +02:00
path_to_file = gtkgui_helpers . decode_filechooser_file_paths (
( path_to_file , ) ) [ 0 ]
2006-04-10 21:49:24 +02:00
if os . path . exists ( path_to_file ) :
2007-08-09 17:39:18 +02:00
if isinstance ( callback , tuple ) :
callback [ 0 ] ( widget , path_to_file , * callback [ 1 : ] )
else :
callback ( widget , path_to_file )
2006-04-10 21:49:24 +02:00
try :
if os . name == ' nt ' :
path = helpers . get_my_pictures_path ( )
else :
path = os . environ [ ' HOME ' ]
2008-10-11 11:37:13 +02:00
except Exception :
2006-04-10 21:49:24 +02:00
path = ' '
FileChooserDialog . __init__ ( self ,
2009-06-21 03:43:57 +02:00
title_text = _ ( ' Choose Image ' ) ,
action = gtk . FILE_CHOOSER_ACTION_OPEN ,
buttons = ( gtk . STOCK_CANCEL , gtk . RESPONSE_CANCEL ,
gtk . STOCK_OPEN , gtk . RESPONSE_OK ) ,
default_response = gtk . RESPONSE_OK ,
current_folder = path ,
on_response_ok = ( on_ok , on_response_ok ) ,
on_response_cancel = on_response_cancel )
2006-04-10 21:49:24 +02:00
2007-12-12 09:44:46 +01:00
if on_response_cancel :
self . connect ( ' destroy ' , on_response_cancel )
2008-12-03 18:16:04 +01:00
filter_ = gtk . FileFilter ( )
filter_ . set_name ( _ ( ' All files ' ) )
filter_ . add_pattern ( ' * ' )
self . add_filter ( filter_ )
filter_ = gtk . FileFilter ( )
filter_ . set_name ( _ ( ' Images ' ) )
filter_ . add_mime_type ( ' image/png ' )
filter_ . add_mime_type ( ' image/jpeg ' )
filter_ . add_mime_type ( ' image/gif ' )
filter_ . add_mime_type ( ' image/tiff ' )
filter_ . add_mime_type ( ' image/svg+xml ' )
filter_ . add_mime_type ( ' image/x-xpixmap ' ) # xpm
self . add_filter ( filter_ )
self . set_filter ( filter_ )
2006-04-10 21:49:24 +02:00
if path_to_file :
self . set_filename ( path_to_file )
self . set_use_preview_label ( False )
self . set_preview_widget ( gtk . Image ( ) )
self . connect ( ' selection-changed ' , self . update_preview )
def update_preview ( self , widget ) :
path_to_file = widget . get_preview_filename ( )
if path_to_file is None or os . path . isdir ( path_to_file ) :
# nothing to preview or directory
# make sure you clean image do show nothing
widget . get_preview_widget ( ) . set_from_file ( None )
return
try :
pixbuf = gtk . gdk . pixbuf_new_from_file_at_size ( path_to_file , 100 , 100 )
except gobject . GError :
return
widget . get_preview_widget ( ) . set_from_pixbuf ( pixbuf )
2006-03-15 18:45:55 +01:00
2006-11-18 21:52:28 +01:00
class AvatarChooserDialog ( ImageChooserDialog ) :
2008-08-08 00:08:08 +02:00
def __init__ ( self , path_to_file = ' ' , on_response_ok = None ,
2009-06-21 03:43:57 +02:00
on_response_cancel = None , on_response_clear = None ) :
2006-11-18 21:52:28 +01:00
ImageChooserDialog . __init__ ( self , path_to_file , on_response_ok ,
2009-06-21 03:43:57 +02:00
on_response_cancel )
2006-11-18 21:52:28 +01:00
button = gtk . Button ( None , gtk . STOCK_CLEAR )
2007-08-09 17:39:18 +02:00
self . response_clear = on_response_clear
2006-11-18 21:52:28 +01:00
if on_response_clear :
2007-08-09 17:39:18 +02:00
button . connect ( ' clicked ' , self . on_clear )
2006-11-18 21:52:28 +01:00
button . show_all ( )
self . action_area . pack_start ( button )
self . action_area . reorder_child ( button , 0 )
2007-08-09 17:39:18 +02:00
def on_clear ( self , widget ) :
if isinstance ( self . response_clear , tuple ) :
self . response_clear [ 0 ] ( widget , * self . response_clear [ 1 : ] )
else :
self . response_clear ( widget )
2006-03-15 18:45:55 +01:00
class AddSpecialNotificationDialog :
def __init__ ( self , jid ) :
''' jid is the jid for which we want to add special notification
( sound and notification popups ) '''
2006-05-02 17:53:25 +02:00
self . xml = gtkgui_helpers . get_glade ( ' add_special_notification_window.glade ' )
2006-03-15 18:45:55 +01:00
self . window = self . xml . get_widget ( ' add_special_notification_window ' )
self . condition_combobox = self . xml . get_widget ( ' condition_combobox ' )
self . condition_combobox . set_active ( 0 )
self . notification_popup_yes_no_combobox = self . xml . get_widget (
' notification_popup_yes_no_combobox ' )
self . notification_popup_yes_no_combobox . set_active ( 0 )
self . listen_sound_combobox = self . xml . get_widget ( ' listen_sound_combobox ' )
self . listen_sound_combobox . set_active ( 0 )
2006-04-10 19:21:28 +02:00
2006-03-15 18:45:55 +01:00
self . jid = jid
self . xml . get_widget ( ' when_foo_becomes_label ' ) . set_text (
_ ( ' When %s becomes: ' ) % self . jid )
2006-04-10 19:21:28 +02:00
2006-03-15 18:45:55 +01:00
self . window . set_title ( _ ( ' Adding Special Notification for %s ' ) % jid )
self . window . show_all ( )
self . xml . signal_autoconnect ( self )
2006-04-10 19:21:28 +02:00
2006-03-15 18:45:55 +01:00
def on_cancel_button_clicked ( self , widget ) :
self . window . destroy ( )
2006-04-10 19:21:28 +02:00
2006-03-15 18:45:55 +01:00
def on_add_special_notification_window_delete_event ( self , widget , event ) :
self . window . destroy ( )
def on_listen_sound_combobox_changed ( self , widget ) :
active = widget . get_active ( )
if active == 1 : # user selected 'choose sound'
2006-04-10 19:21:28 +02:00
def on_ok ( widget , path_to_snd_file ) :
2008-12-15 22:06:08 +01:00
pass
#print path_to_snd_file
2006-04-10 19:21:28 +02:00
def on_cancel ( widget ) :
2006-03-15 18:45:55 +01:00
widget . set_active ( 0 ) # go back to No Sound
2006-04-10 19:21:28 +02:00
2008-09-03 13:25:27 +02:00
self . dialog = SoundChooserDialog ( on_response_ok = on_ok ,
2009-06-21 03:43:57 +02:00
on_response_cancel = on_cancel )
2006-04-10 19:21:28 +02:00
2006-03-15 18:45:55 +01:00
def on_ok_button_clicked ( self , widget ) :
conditions = ( ' online ' , ' chat ' , ' online_and_chat ' ,
2009-06-21 03:43:57 +02:00
' away ' , ' xa ' , ' away_and_xa ' , ' dnd ' , ' xa_and_dnd ' , ' offline ' )
2006-03-15 18:45:55 +01:00
active = self . condition_combobox . get_active ( )
2006-04-10 19:21:28 +02:00
2006-03-15 18:45:55 +01:00
active_iter = self . listen_sound_combobox . get_active_iter ( )
listen_sound_model = self . listen_sound_combobox . get_model ( )
2006-05-09 02:05:15 +02:00
class AdvancedNotificationsWindow :
2006-07-17 21:30:53 +02:00
events_list = [ ' message_received ' , ' contact_connected ' ,
2009-06-21 03:43:57 +02:00
' contact_disconnected ' , ' contact_change_status ' , ' gc_msg_highlight ' ,
' gc_msg ' , ' ft_request ' , ' ft_started ' , ' ft_finished ' ]
2006-07-17 21:30:53 +02:00
recipient_types_list = [ ' contact ' , ' group ' , ' all ' ]
config_options = [ ' event ' , ' recipient_type ' , ' recipients ' , ' status ' ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' sound ' , ' sound_file ' , ' popup ' , ' auto_open ' ,
' run_command ' , ' command ' , ' systray ' , ' roster ' , ' urgency_hint ' ]
2006-05-09 02:05:15 +02:00
def __init__ ( self ) :
self . xml = gtkgui_helpers . get_glade ( ' advanced_notifications_window.glade ' )
self . window = self . xml . get_widget ( ' advanced_notifications_window ' )
2006-07-17 21:30:53 +02:00
for w in ( ' conditions_treeview ' , ' config_vbox ' , ' event_combobox ' ,
2009-06-21 03:43:57 +02:00
' recipient_type_combobox ' , ' recipient_list_entry ' , ' delete_button ' ,
' status_hbox ' , ' use_sound_cb ' , ' disable_sound_cb ' , ' use_popup_cb ' ,
' disable_popup_cb ' , ' use_auto_open_cb ' , ' disable_auto_open_cb ' ,
' use_systray_cb ' , ' disable_systray_cb ' , ' use_roster_cb ' ,
' disable_roster_cb ' , ' tab_opened_cb ' , ' not_tab_opened_cb ' ,
' sound_entry ' , ' sound_file_hbox ' , ' up_button ' , ' down_button ' ,
' run_command_cb ' , ' command_entry ' , ' urgency_hint_cb ' ) :
2006-07-17 21:30:53 +02:00
self . __dict__ [ w ] = self . xml . get_widget ( w )
2006-05-09 02:05:15 +02:00
# Contains status checkboxes
childs = self . status_hbox . get_children ( )
self . all_status_rb = childs [ 0 ]
self . special_status_rb = childs [ 1 ]
self . online_cb = childs [ 2 ]
self . away_cb = childs [ 3 ]
2006-07-17 21:30:53 +02:00
self . xa_cb = childs [ 4 ]
self . dnd_cb = childs [ 5 ]
2006-05-09 02:05:15 +02:00
self . invisible_cb = childs [ 6 ]
2006-07-17 21:30:53 +02:00
model = gtk . ListStore ( int , str )
model . set_sort_column_id ( 0 , gtk . SORT_ASCENDING )
2006-05-09 02:05:15 +02:00
model . clear ( )
self . conditions_treeview . set_model ( model )
2006-07-17 21:30:53 +02:00
## means number
col = gtk . TreeViewColumn ( _ ( ' # ' ) )
self . conditions_treeview . append_column ( col )
renderer = gtk . CellRendererText ( )
2008-09-03 13:25:27 +02:00
col . pack_start ( renderer , expand = False )
col . set_attributes ( renderer , text = 0 )
2006-07-17 21:30:53 +02:00
2006-05-09 02:05:15 +02:00
col = gtk . TreeViewColumn ( _ ( ' Condition ' ) )
self . conditions_treeview . append_column ( col )
renderer = gtk . CellRendererText ( )
2008-09-03 13:25:27 +02:00
col . pack_start ( renderer , expand = True )
col . set_attributes ( renderer , text = 1 )
2006-07-17 21:30:53 +02:00
self . xml . signal_autoconnect ( self )
# Fill conditions_treeview
num = 0
while gajim . config . get_per ( ' notifications ' , str ( num ) ) :
2008-12-03 18:16:04 +01:00
iter_ = model . append ( ( num , ' ' ) )
path = model . get_path ( iter_ )
2006-07-17 21:30:53 +02:00
self . conditions_treeview . set_cursor ( path )
self . active_num = num
self . initiate_rule_state ( )
self . set_treeview_string ( )
num + = 1
2006-05-09 02:05:15 +02:00
# No rule selected at init time
2006-07-17 21:30:53 +02:00
self . conditions_treeview . get_selection ( ) . unselect_all ( )
self . active_num = - 1
self . config_vbox . set_sensitive ( False )
self . delete_button . set_sensitive ( False )
self . down_button . set_sensitive ( False )
self . up_button . set_sensitive ( False )
self . window . show_all ( )
2008-01-22 17:06:16 +01:00
def initiate_rule_state ( self ) :
''' Set values for all widgets '''
2006-07-17 21:30:53 +02:00
if self . active_num < 0 :
return
# event
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' event ' )
2006-07-17 21:30:53 +02:00
if value :
self . event_combobox . set_active ( self . events_list . index ( value ) )
else :
2006-09-13 18:47:58 +02:00
self . event_combobox . set_active ( - 1 )
2006-07-17 21:30:53 +02:00
# recipient_type
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' recipient_type ' )
2006-07-17 21:30:53 +02:00
if value :
self . recipient_type_combobox . set_active (
self . recipient_types_list . index ( value ) )
else :
2006-09-13 18:47:58 +02:00
self . recipient_type_combobox . set_active ( - 1 )
2006-07-17 21:30:53 +02:00
# recipient
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' recipients ' )
2006-07-17 21:30:53 +02:00
if not value :
value = ' '
self . recipient_list_entry . set_text ( value )
# status
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' status ' )
2006-07-17 21:30:53 +02:00
if value == ' all ' :
self . all_status_rb . set_active ( True )
else :
self . special_status_rb . set_active ( True )
values = value . split ( )
2008-10-11 11:42:59 +02:00
for v in ( ' online ' , ' away ' , ' xa ' , ' dnd ' , ' invisible ' ) :
2006-07-17 21:30:53 +02:00
if v in values :
self . __dict__ [ v + ' _cb ' ] . set_active ( True )
else :
self . __dict__ [ v + ' _cb ' ] . set_active ( False )
2006-05-09 02:05:15 +02:00
self . on_status_radiobutton_toggled ( self . all_status_rb )
2006-07-17 21:30:53 +02:00
# tab_opened
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' )
2006-05-09 19:59:24 +02:00
self . tab_opened_cb . set_active ( True )
2006-07-17 21:30:53 +02:00
self . not_tab_opened_cb . set_active ( True )
if value == ' no ' :
self . tab_opened_cb . set_active ( False )
elif value == ' yes ' :
self . not_tab_opened_cb . set_active ( False )
# sound_file
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' sound_file ' )
2006-07-17 21:30:53 +02:00
self . sound_entry . set_text ( value )
# sound, popup, auto_open, systray, roster
2008-10-11 11:42:59 +02:00
for option in ( ' sound ' , ' popup ' , ' auto_open ' , ' systray ' , ' roster ' ) :
2006-07-17 21:30:53 +02:00
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
option )
2006-07-17 21:30:53 +02:00
if value == ' yes ' :
self . __dict__ [ ' use_ ' + option + ' _cb ' ] . set_active ( True )
else :
self . __dict__ [ ' use_ ' + option + ' _cb ' ] . set_active ( False )
if value == ' no ' :
self . __dict__ [ ' disable_ ' + option + ' _cb ' ] . set_active ( True )
else :
self . __dict__ [ ' disable_ ' + option + ' _cb ' ] . set_active ( False )
# run_command
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' run_command ' )
2006-07-17 21:30:53 +02:00
self . run_command_cb . set_active ( value )
# command
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' command ' )
2006-07-17 21:30:53 +02:00
self . command_entry . set_text ( value )
# urgency_hint
value = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' urgency_hint ' )
2006-07-17 21:30:53 +02:00
self . urgency_hint_cb . set_active ( value )
def set_treeview_string ( self ) :
2008-12-03 18:16:04 +01:00
( model , iter_ ) = self . conditions_treeview . get_selection ( ) . get_selected ( )
if not iter_ :
2006-07-17 21:30:53 +02:00
return
event = self . event_combobox . get_active_text ( )
recipient_type = self . recipient_type_combobox . get_active_text ( )
recipient = ' '
if recipient_type != ' everybody ' :
recipient = self . recipient_list_entry . get_text ( )
if self . all_status_rb . get_active ( ) :
status = ' '
else :
status = _ ( ' when I am ' )
2008-10-11 11:42:59 +02:00
for st in ( ' online ' , ' away ' , ' xa ' , ' dnd ' , ' invisible ' ) :
2006-07-17 21:30:53 +02:00
if self . __dict__ [ st + ' _cb ' ] . get_active ( ) :
status + = helpers . get_uf_show ( st ) + ' '
2008-12-03 18:16:04 +01:00
model [ iter_ ] [ 1 ] = " When %s for %s %s %s " % ( event , recipient_type ,
2009-06-21 03:43:57 +02:00
recipient , status )
2006-07-17 21:30:53 +02:00
def on_conditions_treeview_cursor_changed ( self , widget ) :
2008-12-03 18:16:04 +01:00
( model , iter_ ) = widget . get_selection ( ) . get_selected ( )
if not iter_ :
2006-07-17 21:30:53 +02:00
self . active_num = - 1
return
2008-12-03 18:16:04 +01:00
self . active_num = model [ iter_ ] [ 0 ]
2006-07-17 21:30:53 +02:00
if self . active_num == 0 :
self . up_button . set_sensitive ( False )
else :
self . up_button . set_sensitive ( True )
max = self . conditions_treeview . get_model ( ) . iter_n_children ( None )
if self . active_num == max - 1 :
self . down_button . set_sensitive ( False )
else :
self . down_button . set_sensitive ( True )
self . initiate_rule_state ( )
self . config_vbox . set_sensitive ( True )
self . delete_button . set_sensitive ( True )
def on_new_button_clicked ( self , widget ) :
model = self . conditions_treeview . get_model ( )
num = self . conditions_treeview . get_model ( ) . iter_n_children ( None )
gajim . config . add_per ( ' notifications ' , str ( num ) )
2008-12-03 18:16:04 +01:00
iter_ = model . append ( ( num , ' ' ) )
path = model . get_path ( iter_ )
2006-07-17 21:30:53 +02:00
self . conditions_treeview . set_cursor ( path )
self . active_num = num
self . set_treeview_string ( )
self . config_vbox . set_sensitive ( True )
def on_delete_button_clicked ( self , widget ) :
2008-12-03 18:16:04 +01:00
( model , iter_ ) = self . conditions_treeview . get_selection ( ) . get_selected ( )
if not iter_ :
2006-07-17 21:30:53 +02:00
return
# up all others
2008-12-03 18:16:04 +01:00
iter2 = model . iter_next ( iter_ )
2006-07-17 21:30:53 +02:00
num = self . active_num
while iter2 :
num = model [ iter2 ] [ 0 ]
model [ iter2 ] [ 0 ] = num - 1
for opt in self . config_options :
val = gajim . config . get_per ( ' notifications ' , str ( num ) , opt )
gajim . config . set_per ( ' notifications ' , str ( num - 1 ) , opt , val )
iter2 = model . iter_next ( iter2 )
2008-12-03 18:16:04 +01:00
model . remove ( iter_ )
2006-07-17 21:30:53 +02:00
gajim . config . del_per ( ' notifications ' , str ( num ) ) # delete latest
self . active_num = - 1
self . config_vbox . set_sensitive ( False )
self . delete_button . set_sensitive ( False )
self . up_button . set_sensitive ( False )
self . down_button . set_sensitive ( False )
def on_up_button_clicked ( self , widget ) :
2008-12-03 18:16:04 +01:00
( model , iter_ ) = self . conditions_treeview . get_selection ( ) . \
2009-06-21 03:43:57 +02:00
get_selected ( )
2008-12-03 18:16:04 +01:00
if not iter_ :
2006-07-17 21:30:53 +02:00
return
for opt in self . config_options :
val = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) , opt )
val2 = gajim . config . get_per ( ' notifications ' , str ( self . active_num - 1 ) ,
2009-06-21 03:43:57 +02:00
opt )
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , opt , val2 )
gajim . config . set_per ( ' notifications ' , str ( self . active_num - 1 ) , opt ,
2009-06-21 03:43:57 +02:00
val )
2006-07-17 21:30:53 +02:00
2008-12-03 18:16:04 +01:00
model [ iter_ ] [ 0 ] = self . active_num - 1
2006-07-17 21:30:53 +02:00
# get previous iter
2008-12-03 18:16:04 +01:00
path = model . get_path ( iter_ )
iter_ = model . get_iter ( ( path [ 0 ] - 1 , ) )
model [ iter_ ] [ 0 ] = self . active_num
2006-07-17 21:30:53 +02:00
self . on_conditions_treeview_cursor_changed ( self . conditions_treeview )
def on_down_button_clicked ( self , widget ) :
2008-12-03 18:16:04 +01:00
( model , iter_ ) = self . conditions_treeview . get_selection ( ) . get_selected ( )
if not iter_ :
2006-07-17 21:30:53 +02:00
return
for opt in self . config_options :
val = gajim . config . get_per ( ' notifications ' , str ( self . active_num ) , opt )
val2 = gajim . config . get_per ( ' notifications ' , str ( self . active_num + 1 ) ,
2009-06-21 03:43:57 +02:00
opt )
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , opt , val2 )
gajim . config . set_per ( ' notifications ' , str ( self . active_num + 1 ) , opt ,
2009-06-21 03:43:57 +02:00
val )
2006-07-17 21:30:53 +02:00
2008-12-03 18:16:04 +01:00
model [ iter_ ] [ 0 ] = self . active_num + 1
iter_ = model . iter_next ( iter_ )
model [ iter_ ] [ 0 ] = self . active_num
2006-07-17 21:30:53 +02:00
self . on_conditions_treeview_cursor_changed ( self . conditions_treeview )
def on_event_combobox_changed ( self , widget ) :
if self . active_num < 0 :
return
2006-09-13 18:47:58 +02:00
active = self . event_combobox . get_active ( )
if active == - 1 :
event = ' '
else :
event = self . events_list [ active ]
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , ' event ' ,
2009-06-21 03:43:57 +02:00
event )
2006-07-17 21:30:53 +02:00
self . set_treeview_string ( )
def on_recipient_type_combobox_changed ( self , widget ) :
if self . active_num < 0 :
return
recipient_type = self . recipient_types_list [ self . recipient_type_combobox . \
2009-06-21 03:43:57 +02:00
get_active ( ) ]
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' recipient_type ' , recipient_type )
2006-07-17 21:30:53 +02:00
if recipient_type == ' all ' :
self . recipient_list_entry . hide ( )
else :
self . recipient_list_entry . show ( )
self . set_treeview_string ( )
def on_recipient_list_entry_changed ( self , widget ) :
if self . active_num < 0 :
return
recipients = widget . get_text ( ) . decode ( ' utf-8 ' )
#TODO: do some check
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' recipients ' , recipients )
2006-07-17 21:30:53 +02:00
self . set_treeview_string ( )
def set_status_config ( self ) :
if self . active_num < 0 :
return
status = ' '
2008-10-11 11:42:59 +02:00
for st in ( ' online ' , ' away ' , ' xa ' , ' dnd ' , ' invisible ' ) :
2006-07-17 21:30:53 +02:00
if self . __dict__ [ st + ' _cb ' ] . get_active ( ) :
status + = st + ' '
if status :
status = status [ : - 1 ]
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , ' status ' ,
2009-06-21 03:43:57 +02:00
status )
2006-07-17 21:30:53 +02:00
self . set_treeview_string ( )
2006-05-09 02:05:15 +02:00
def on_status_radiobutton_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
if self . active_num < 0 :
return
2006-05-09 02:05:15 +02:00
if self . all_status_rb . get_active ( ) :
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , ' status ' ,
2009-06-21 03:43:57 +02:00
' all ' )
2006-05-09 02:05:15 +02:00
# 'All status' clicked
2008-10-11 11:42:59 +02:00
for st in ( ' online ' , ' away ' , ' xa ' , ' dnd ' , ' invisible ' ) :
2006-07-17 21:30:53 +02:00
self . __dict__ [ st + ' _cb ' ] . hide ( )
2008-01-22 17:06:16 +01:00
self . special_status_rb . show ( )
2006-05-09 02:05:15 +02:00
else :
2006-07-17 21:30:53 +02:00
self . set_status_config ( )
2006-05-09 02:05:15 +02:00
# 'special status' clicked
2008-10-11 11:42:59 +02:00
for st in ( ' online ' , ' away ' , ' xa ' , ' dnd ' , ' invisible ' ) :
2006-07-17 21:30:53 +02:00
self . __dict__ [ st + ' _cb ' ] . show ( )
2006-05-09 02:05:15 +02:00
self . special_status_rb . hide ( )
2006-07-17 21:30:53 +02:00
self . set_treeview_string ( )
def on_status_cb_toggled ( self , widget ) :
if self . active_num < 0 :
return
self . set_status_config ( )
2006-05-09 19:59:24 +02:00
# tab_opened OR (not xor) not_tab_opened must be active
def on_tab_opened_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
if self . active_num < 0 :
return
if self . tab_opened_cb . get_active ( ) :
if self . not_tab_opened_cb . get_active ( ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' both ' )
2006-07-17 21:30:53 +02:00
else :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' yes ' )
2006-07-17 21:30:53 +02:00
elif not self . not_tab_opened_cb . get_active ( ) :
2006-05-09 19:59:24 +02:00
self . not_tab_opened_cb . set_active ( True )
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' no ' )
2006-07-17 21:30:53 +02:00
2006-05-09 19:59:24 +02:00
def on_not_tab_opened_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
if self . active_num < 0 :
return
if self . not_tab_opened_cb . get_active ( ) :
if self . tab_opened_cb . get_active ( ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' both ' )
2006-07-17 21:30:53 +02:00
else :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' no ' )
2006-07-17 21:30:53 +02:00
elif not self . tab_opened_cb . get_active ( ) :
2006-05-09 19:59:24 +02:00
self . tab_opened_cb . set_active ( True )
2006-07-17 21:30:53 +02:00
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' tab_opened ' , ' yes ' )
2006-07-17 21:30:53 +02:00
def on_use_it_toggled ( self , widget , oposite_widget , option ) :
if widget . get_active ( ) :
if oposite_widget . get_active ( ) :
oposite_widget . set_active ( False )
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , option ,
2009-06-21 03:43:57 +02:00
' yes ' )
2006-07-17 21:30:53 +02:00
elif oposite_widget . get_active ( ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , option ,
2009-06-21 03:43:57 +02:00
' no ' )
2006-07-17 21:30:53 +02:00
else :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , option , ' ' )
def on_disable_it_toggled ( self , widget , oposite_widget , option ) :
if widget . get_active ( ) :
if oposite_widget . get_active ( ) :
oposite_widget . set_active ( False )
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , option ,
2009-06-21 03:43:57 +02:00
' no ' )
2006-07-17 21:30:53 +02:00
elif oposite_widget . get_active ( ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , option ,
2009-06-21 03:43:57 +02:00
' yes ' )
2006-07-17 21:30:53 +02:00
else :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , option , ' ' )
2006-05-09 02:05:15 +02:00
def on_use_sound_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_use_it_toggled ( widget , self . disable_sound_cb , ' sound ' )
if widget . get_active ( ) :
self . sound_file_hbox . set_sensitive ( True )
else :
self . sound_file_hbox . set_sensitive ( False )
2008-08-08 00:08:08 +02:00
def on_browse_for_sounds_button_clicked ( self , widget , data = None ) :
2006-07-17 21:30:53 +02:00
if self . active_num < 0 :
return
def on_ok ( widget , path_to_snd_file ) :
dialog . destroy ( )
if not path_to_snd_file :
path_to_snd_file = ' '
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' sound_file ' , path_to_snd_file )
2006-07-17 21:30:53 +02:00
self . sound_entry . set_text ( path_to_snd_file )
path_to_snd_file = self . sound_entry . get_text ( ) . decode ( ' utf-8 ' )
path_to_snd_file = os . path . join ( os . getcwd ( ) , path_to_snd_file )
dialog = SoundChooserDialog ( path_to_snd_file , on_ok )
def on_play_button_clicked ( self , widget ) :
helpers . play_sound_file ( self . sound_entry . get_text ( ) . decode ( ' utf-8 ' ) )
2006-05-09 02:05:15 +02:00
def on_disable_sound_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_disable_it_toggled ( widget , self . use_sound_cb , ' sound ' )
def on_sound_entry_changed ( self , widget ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' sound_file ' , widget . get_text ( ) . decode ( ' utf-8 ' ) )
2006-07-17 21:30:53 +02:00
2006-05-09 02:05:15 +02:00
def on_use_popup_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_use_it_toggled ( widget , self . disable_popup_cb , ' popup ' )
2006-05-09 02:05:15 +02:00
def on_disable_popup_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_disable_it_toggled ( widget , self . use_popup_cb , ' popup ' )
2006-05-09 02:05:15 +02:00
def on_use_auto_open_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_use_it_toggled ( widget , self . disable_auto_open_cb , ' auto_open ' )
2006-05-09 02:05:15 +02:00
def on_disable_auto_open_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_disable_it_toggled ( widget , self . use_auto_open_cb , ' auto_open ' )
def on_run_command_cb_toggled ( self , widget ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , ' run_command ' ,
2009-06-21 03:43:57 +02:00
widget . get_active ( ) )
2006-07-17 21:30:53 +02:00
if widget . get_active ( ) :
self . command_entry . set_sensitive ( True )
else :
self . command_entry . set_sensitive ( False )
def on_command_entry_changed ( self , widget ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) , ' command ' ,
2009-06-21 03:43:57 +02:00
widget . get_text ( ) . decode ( ' utf-8 ' ) )
2006-07-17 21:30:53 +02:00
2006-05-09 02:05:15 +02:00
def on_use_systray_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_use_it_toggled ( widget , self . disable_systray_cb , ' systray ' )
2006-05-09 02:05:15 +02:00
def on_disable_systray_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_disable_it_toggled ( widget , self . use_systray_cb , ' systray ' )
2006-05-09 19:59:24 +02:00
def on_use_roster_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_use_it_toggled ( widget , self . disable_roster_cb , ' roster ' )
2006-05-09 19:59:24 +02:00
def on_disable_roster_cb_toggled ( self , widget ) :
2006-07-17 21:30:53 +02:00
self . on_disable_it_toggled ( widget , self . use_roster_cb , ' roster ' )
def on_urgency_hint_cb_toggled ( self , widget ) :
gajim . config . set_per ( ' notifications ' , str ( self . active_num ) ,
2009-06-21 03:43:57 +02:00
' uregency_hint ' , widget . get_active ( ) )
2006-07-17 21:30:53 +02:00
2006-05-09 02:05:15 +02:00
def on_close_window ( self , widget ) :
self . window . destroy ( )
2007-12-12 09:44:46 +01:00
class TransformChatToMUC :
# Keep a reference on windows so garbage collector don't restroy them
instances = [ ]
2008-08-08 00:08:08 +02:00
def __init__ ( self , account , jids , preselected = None ) :
2007-12-12 09:44:46 +01:00
''' This window is used to trasform a one-to-one chat to a MUC.
We do 2 things : first select the server and then make a guests list . '''
self . instances . append ( self )
self . account = account
self . auto_jids = jids
self . preselected_jids = preselected
self . xml = gtkgui_helpers . get_glade ( ' chat_to_muc_window.glade ' )
self . window = self . xml . get_widget ( ' chat_to_muc_window ' )
for widget_to_add in ( ' invite_button ' , ' cancel_button ' ,
2009-06-21 03:43:57 +02:00
' server_list_comboboxentry ' , ' guests_treeview ' ,
' server_and_guests_hseparator ' , ' server_select_label ' ) :
2007-12-12 09:44:46 +01:00
self . __dict__ [ widget_to_add ] = self . xml . get_widget ( widget_to_add )
server_list = [ ]
self . servers = gtk . ListStore ( str )
self . server_list_comboboxentry . set_model ( self . servers )
self . server_list_comboboxentry . set_text_column ( 0 )
# get the muc server of our server
if ' jabber ' in gajim . connections [ account ] . muc_jid :
server_list . append ( gajim . connections [ account ] . muc_jid [ ' jabber ' ] )
# add servers or recently joined groupchats
recently_groupchat = gajim . config . get ( ' recently_groupchat ' ) . split ( )
for g in recently_groupchat :
server = gajim . get_server_from_jid ( g )
if server not in server_list and not server . startswith ( ' irc ' ) :
server_list . append ( server )
# add a default server
if not server_list :
server_list . append ( ' conference.jabber.org ' )
for s in server_list :
self . servers . append ( [ s ] )
self . server_list_comboboxentry . set_active ( 0 )
# set treeview
# name, jid
self . store = gtk . ListStore ( gtk . gdk . Pixbuf , str , str )
self . store . set_sort_column_id ( 1 , gtk . SORT_ASCENDING )
self . guests_treeview . set_model ( self . store )
renderer1 = gtk . CellRendererText ( )
renderer2 = gtk . CellRendererPixbuf ( )
column = gtk . TreeViewColumn ( ' Status ' , renderer2 , pixbuf = 0 )
self . guests_treeview . append_column ( column )
column = gtk . TreeViewColumn ( ' Name ' , renderer1 , text = 1 )
self . guests_treeview . append_column ( column )
self . guests_treeview . get_selection ( ) . set_mode ( gtk . SELECTION_MULTIPLE )
2007-12-27 23:28:40 +01:00
# All contacts beside the following can be invited:
# transports, zeroconf contacts, minimized groupchats
2008-12-03 23:07:44 +01:00
def invitable ( contact , contact_transport = None ) :
return ( contact . jid not in self . auto_jids and
2009-06-21 03:43:57 +02:00
contact . jid != gajim . get_jid_from_account ( self . account ) and
contact . jid not in gajim . interface . minimized_controls [ account ] and
not contact . is_transport ( ) and
not contact_transport )
2008-01-22 17:06:16 +01:00
2007-12-12 09:44:46 +01:00
# set jabber id and pseudos
for account in gajim . contacts . get_accounts ( ) :
if gajim . connections [ account ] . is_zeroconf :
continue
for jid in gajim . contacts . get_jid_list ( account ) :
contact = \
2009-06-21 03:43:57 +02:00
gajim . contacts . get_contact_with_highest_priority ( account , jid )
2007-12-12 09:44:46 +01:00
contact_transport = gajim . get_transport_name_from_jid ( jid )
2007-12-27 23:28:40 +01:00
# Add contact if it can be invited
if invitable ( contact , contact_transport ) and \
2009-06-21 03:43:57 +02:00
contact . show not in ( ' offline ' , ' error ' ) :
2008-04-17 16:17:14 +02:00
img = gajim . interface . jabber_state_images [ ' 16 ' ] [ contact . show ]
2007-12-27 23:28:40 +01:00
name = contact . name
if name == ' ' :
name = jid . split ( ' @ ' ) [ 0 ]
2008-12-03 18:16:04 +01:00
iter_ = self . store . append ( [ img . get_pixbuf ( ) , name , jid ] )
2007-12-27 23:28:40 +01:00
# preselect treeview rows
if self . preselected_jids and jid in self . preselected_jids :
2008-12-03 18:16:04 +01:00
path = self . store . get_path ( iter_ )
2007-12-27 23:28:40 +01:00
self . guests_treeview . get_selection ( ) . \
select_path ( path )
2007-12-12 09:44:46 +01:00
# show all
self . window . show_all ( )
self . xml . signal_autoconnect ( self )
def on_chat_to_muc_window_destroy ( self , widget ) :
self . instances . remove ( self )
def on_chat_to_muc_window_key_press_event ( self , widget , event ) :
if event . keyval == gtk . keysyms . Escape : # ESCAPE
self . window . destroy ( )
def on_invite_button_clicked ( self , widget ) :
server = self . server_list_comboboxentry . get_active_text ( )
if server == ' ' :
return
gajim . connections [ self . account ] . check_unique_room_id_support ( server , self )
def unique_room_id_supported ( self , server , room_id ) :
guest_list = [ ]
guests = self . guests_treeview . get_selection ( ) . get_selected_rows ( )
for guest in guests [ 1 ] :
2008-12-03 18:16:04 +01:00
iter_ = self . store . get_iter ( guest )
guest_list . append ( self . store [ iter_ ] [ 2 ] . decode ( ' utf-8 ' ) )
2007-12-12 09:44:46 +01:00
for guest in self . auto_jids :
guest_list . append ( guest )
room_jid = room_id + ' @ ' + server
gajim . automatic_rooms [ self . account ] [ room_jid ] = { }
2008-01-22 17:06:16 +01:00
gajim . automatic_rooms [ self . account ] [ room_jid ] [ ' invities ' ] = guest_list
2007-12-12 09:44:46 +01:00
gajim . automatic_rooms [ self . account ] [ room_jid ] [ ' continue_tag ' ] = True
2008-04-20 20:14:04 +02:00
gajim . interface . join_gc_room ( self . account , room_jid ,
2009-10-31 19:03:03 +01:00
gajim . nicks [ self . account ] , None , is_continued = True )
2007-12-12 09:44:46 +01:00
self . window . destroy ( )
def on_cancel_button_clicked ( self , widget ) :
self . window . destroy ( )
def unique_room_id_error ( self , server ) :
self . unique_room_id_supported ( server ,
2009-10-31 19:03:03 +01:00
gajim . nicks [ self . account ] . lower ( ) . replace ( ' ' , ' ' ) + str ( randrange (
9999999 ) ) )
2008-02-15 23:55:21 +01:00
class DataFormWindow ( Dialog ) :
def __init__ ( self , form , on_response_ok ) :
self . df_response_ok = on_response_ok
Dialog . __init__ ( self , None , ' test ' , [ ( gtk . STOCK_CANCEL ,
2009-06-21 03:43:57 +02:00
gtk . RESPONSE_REJECT ) , ( gtk . STOCK_OK , gtk . RESPONSE_ACCEPT ) ] ,
on_response_ok = self . on_ok )
2008-02-15 23:55:21 +01:00
self . set_resizable ( True )
2008-03-02 22:44:43 +01:00
gtkgui_helpers . resize_window ( self , 600 , 400 )
2008-02-15 23:55:21 +01:00
self . dataform_widget = dataforms_widget . DataFormWidget ( )
2008-09-03 13:25:27 +02:00
self . dataform = dataforms . ExtendForm ( node = form )
2008-02-15 23:55:21 +01:00
self . dataform_widget . set_sensitive ( True )
self . dataform_widget . data_form = self . dataform
self . dataform_widget . show_all ( )
self . vbox . pack_start ( self . dataform_widget )
2008-06-29 06:39:29 +02:00
2008-02-15 23:55:21 +01:00
def on_ok ( self ) :
form = self . dataform_widget . data_form
if isinstance ( self . df_response_ok , tuple ) :
self . df_response_ok [ 0 ] ( form , * self . df_response_ok [ 1 : ] )
else :
self . df_response_ok ( form )
self . destroy ( )
2008-06-29 06:39:29 +02:00
class ESessionInfoWindow :
''' Class for displaying information about a XEP-0116 encrypted session '''
def __init__ ( self , session ) :
self . session = session
self . xml = gtkgui_helpers . get_glade ( ' esession_info_window.glade ' )
self . xml . signal_autoconnect ( self )
2008-08-13 23:25:26 +02:00
self . security_image = self . xml . get_widget ( ' security_image ' )
2008-08-13 23:44:52 +02:00
self . verify_now_button = self . xml . get_widget ( ' verify_now_button ' )
2008-08-28 15:14:54 +02:00
self . button_label = self . xml . get_widget ( ' button_label ' )
2008-08-13 23:30:18 +02:00
self . window = self . xml . get_widget ( ' esession_info_window ' )
2008-06-29 06:39:29 +02:00
self . update_info ( )
2008-08-13 23:25:26 +02:00
2008-06-29 06:39:29 +02:00
self . window . show_all ( )
def update_info ( self ) :
2008-09-01 16:11:28 +02:00
labeltext = _ ( ''' Your chat session with <b> %(jid)s </b> is encrypted. \n \n This session ' s Short Authentication String is <b> %(sas)s </b>. ''' ) % { ' jid ' : self . session . jid , ' sas ' : self . session . sas }
2008-12-03 18:16:04 +01:00
dir_ = os . path . join ( gajim . DATA_DIR , ' pixmaps ' )
2008-06-29 06:39:29 +02:00
if self . session . verified_identity :
labeltext + = ' \n \n ' + _ ( ''' You have already verified this contact ' s identity. ''' )
2008-08-13 23:25:26 +02:00
security_image = ' security-high-big.png '
2008-07-09 04:11:42 +02:00
if self . session . control :
self . session . control . _show_lock_image ( True , ' E2E ' , True ,
2009-06-21 03:43:57 +02:00
self . session . is_loggable ( ) , True )
2008-09-12 07:25:10 +02:00
verification_status = _ ( ''' Contact ' s identity verified ''' )
self . window . set_title ( verification_status )
self . xml . get_widget ( ' verification_status_label ' ) . set_markup (
' <b><span size= " x-large " > ' +
verification_status +
' </span></b> ' )
self . xml . get_widget ( ' dialog-action_area1 ' ) . set_no_show_all ( True )
2008-09-01 16:11:28 +02:00
self . button_label . set_text ( _ ( ' Verify again... ' ) )
2008-08-13 23:25:26 +02:00
else :
2008-08-28 15:14:54 +02:00
if self . session . control :
self . session . control . _show_lock_image ( True , ' E2E ' , True ,
2009-06-21 03:43:57 +02:00
self . session . is_loggable ( ) , False )
2008-09-01 16:11:28 +02:00
labeltext + = ' \n \n ' + _ ( ''' To be certain that <b>only</b> the expected person can read your messages or send you messages, you need to verify their identity by clicking the button below. ''' )
2008-08-13 23:25:26 +02:00
security_image = ' security-low-big.png '
2008-09-12 07:25:10 +02:00
verification_status = _ ( ''' Contact ' s identity NOT verified ''' )
self . window . set_title ( verification_status )
self . xml . get_widget ( ' verification_status_label ' ) . set_markup (
' <b><span size= " x-large " > ' +
verification_status +
' </span></b> ' )
2008-09-01 16:11:28 +02:00
self . button_label . set_text ( _ ( ' Verify... ' ) )
2008-08-13 23:25:26 +02:00
2008-12-03 18:16:04 +01:00
path = os . path . join ( dir_ , security_image )
2008-08-13 23:25:26 +02:00
filename = os . path . abspath ( path )
self . security_image . set_from_file ( filename )
2008-07-09 04:11:42 +02:00
2008-08-28 15:14:54 +02:00
self . xml . get_widget ( ' info_display ' ) . set_markup ( labeltext )
2008-06-29 06:39:29 +02:00
def on_close_button_clicked ( self , widget ) :
self . window . destroy ( )
def on_verify_now_button_clicked ( self , widget ) :
2008-08-28 15:14:54 +02:00
pritext = _ ( ''' Have you verified the contact ' s identity? ''' )
2008-09-01 16:11:28 +02:00
sectext = _ ( ''' To prevent talking to an unknown person, you should speak to <b> %(jid)s </b> directly (in person or on the phone) and verify that they see the same Short Authentication String (SAS) as you. \n \n This session ' s Short Authentication String is <b> %(sas)s </b>. ''' ) % { ' jid ' : self . session . jid , ' sas ' : self . session . sas }
2008-06-29 06:39:29 +02:00
sectext + = ' \n \n ' + _ ( ' Did you talk to the remote contact and verify the SAS? ' )
2008-08-07 15:25:25 +02:00
def on_yes ( checked ) :
2008-06-29 06:39:29 +02:00
self . session . _verified_srs_cb ( )
self . session . verified_identity = True
self . update_info ( )
2008-07-29 21:49:31 +02:00
2008-08-28 15:14:54 +02:00
def on_no ( ) :
self . session . _unverified_srs_cb ( )
self . session . verified_identity = False
self . update_info ( )
YesNoDialog ( pritext , sectext , on_response_yes = on_yes , on_response_no = on_no )
2008-08-07 15:25:25 +02:00
2008-10-02 22:20:15 +02:00
class GPGInfoWindow :
''' Class for displaying information about a XEP-0116 encrypted session '''
def __init__ ( self , control ) :
xml = gtkgui_helpers . get_glade ( ' esession_info_window.glade ' )
security_image = xml . get_widget ( ' security_image ' )
status_label = xml . get_widget ( ' verification_status_label ' )
info_label = xml . get_widget ( ' info_display ' )
verify_now_button = xml . get_widget ( ' verify_now_button ' )
self . window = xml . get_widget ( ' esession_info_window ' )
account = control . account
keyID = control . contact . keyID
error = None
verify_now_button . set_no_show_all ( True )
verify_now_button . hide ( )
2008-10-11 11:32:59 +02:00
if keyID . endswith ( ' MISMATCH ' ) :
2008-10-02 22:20:15 +02:00
verification_status = _ ( ''' Contact ' s identity NOT verified ''' )
info = _ ( ' The contact \' s key ( %s ) <b>does not match</b> the key '
2009-06-21 03:43:57 +02:00
' assigned in Gajim. ' ) % keyID [ : 8 ]
2008-10-02 22:20:15 +02:00
image = ' security-low-big.png '
2008-10-08 22:11:06 +02:00
elif not keyID :
# No key assigned nor a key is used by remote contact
verification_status = _ ( ' No GPG key assigned ' )
info = _ ( ' No GPG key is assigned to this contact. So you cannot '
2009-06-21 03:43:57 +02:00
' encrypt messages. ' )
2008-10-08 22:11:06 +02:00
image = ' security-low-big.png '
2008-10-02 22:20:15 +02:00
else :
2008-12-02 16:53:23 +01:00
error = gajim . connections [ account ] . gpg . encrypt ( ' test ' , [ keyID ] ) [ 1 ]
2008-10-02 22:20:15 +02:00
if error :
verification_status = _ ( ''' Contact ' s identity NOT verified ''' )
2008-10-08 22:11:06 +02:00
info = _ ( ' GPG key is assigned to this contact, but <b>you do not '
2009-06-21 03:43:57 +02:00
' trust his key</b>, so message <b>cannot</b> be encrypted. Use '
' your GPG client to trust this key. ' )
2008-10-02 22:20:15 +02:00
image = ' security-low-big.png '
else :
verification_status = _ ( ''' Contact ' s identity verified ''' )
info = _ ( ' GPG Key is assigned to this contact, and you trust his '
2009-06-21 03:43:57 +02:00
' key, so messages will be encrypted. ' )
2008-10-02 22:20:15 +02:00
image = ' security-high-big.png '
status_label . set_markup ( ' <b><span size= " x-large " > %s </span></b> ' % \
2009-06-21 03:43:57 +02:00
verification_status )
2008-10-02 22:20:15 +02:00
info_label . set_markup ( info )
2008-12-03 18:16:04 +01:00
dir_ = os . path . join ( gajim . DATA_DIR , ' pixmaps ' )
path = os . path . join ( dir_ , image )
2008-10-02 22:20:15 +02:00
filename = os . path . abspath ( path )
security_image . set_from_file ( filename )
xml . signal_autoconnect ( self )
self . window . show_all ( )
def on_close_button_clicked ( self , widget ) :
self . window . destroy ( )
2009-10-29 10:19:58 +01:00
2009-10-20 11:20:11 +02:00
class ResourceConflictDialog ( TimeoutDialog , InputDialog ) :
def __init__ ( self , title , text , resource , ok_handler ) :
TimeoutDialog . __init__ ( self , 15 , self . on_timeout )
InputDialog . __init__ ( self , title , text , input_str = resource ,
is_modal = False , ok_handler = ok_handler )
self . title_text = title
self . run_timeout ( )
def on_timeout ( self ) :
self . on_okbutton_clicked ( None )
2009-10-29 10:19:58 +01:00
2007-08-24 01:42:31 +02:00
class VoIPCallReceivedDialog ( object ) :
2009-09-26 10:29:08 +02:00
instances = { }
def __init__ ( self , account , contact_jid , sid , content_types ) :
self . instances [ ( contact_jid , sid ) ] = self
2007-08-24 01:42:31 +02:00
self . account = account
2009-09-17 14:48:15 +02:00
self . fjid = contact_jid
2007-08-24 01:42:31 +02:00
self . sid = sid
2009-09-26 10:29:08 +02:00
self . content_types = content_types
2009-09-25 19:32:13 +02:00
2007-08-24 01:42:31 +02:00
xml = gtkgui_helpers . get_glade ( ' voip_call_received_dialog.glade ' )
xml . signal_autoconnect ( self )
2009-09-17 14:48:15 +02:00
jid = gajim . get_jid_without_resource ( self . fjid )
contact = gajim . contacts . get_first_contact_from_jid ( account , jid )
2007-08-24 01:42:31 +02:00
if contact and contact . name :
2009-09-26 10:29:08 +02:00
self . contact_text = ' %s ( %s ) ' % ( contact . name , jid )
2007-08-24 01:42:31 +02:00
else :
2009-09-26 10:29:08 +02:00
self . contact_text = contact_jid
2007-08-24 01:42:31 +02:00
2009-09-26 10:29:08 +02:00
self . dialog = xml . get_widget ( ' voip_call_received_messagedialog ' )
self . set_secondary_text ( )
2007-08-24 01:42:31 +02:00
2009-09-26 10:29:08 +02:00
self . dialog . show_all ( )
2007-08-24 01:42:31 +02:00
2009-09-25 19:32:13 +02:00
@classmethod
def get_dialog ( cls , jid , sid ) :
if ( jid , sid ) in cls . instances :
return cls . instances [ ( jid , sid ) ]
else :
return None
2009-09-26 10:29:08 +02:00
def set_secondary_text ( self ) :
if ' audio ' in self . content_types and ' video ' in self . content_types :
types_text = _ ( ' an audio and video ' )
elif ' audio ' in self . content_types :
types_text = _ ( ' an audio ' )
elif ' video ' in self . content_types :
types_text = _ ( ' a video ' )
# do the substitution
self . dialog . set_property ( ' secondary-text ' ,
_ ( ' %(contact)s wants to start %(type)s session with you. Do you want '
' to answer the call? ' ) % { ' contact ' : self . contact_text , ' type ' : types_text } )
def add_contents ( self , content_types ) :
for type_ in content_types :
if type_ not in self . content_types :
2009-09-26 21:55:43 +02:00
self . content_types . add ( type_ )
2009-09-26 10:29:08 +02:00
self . set_secondary_text ( )
def on_voip_call_received_messagedialog_destroy ( self , dialog ) :
if ( self . fjid , self . sid ) in self . instances :
del self . instances [ ( self . fjid , self . sid ) ]
2007-08-24 01:42:31 +02:00
def on_voip_call_received_messagedialog_close ( self , dialog ) :
2009-09-17 14:48:15 +02:00
return self . on_voip_call_received_messagedialog_response ( dialog ,
gtk . RESPONSE_NO )
2007-08-24 01:42:31 +02:00
def on_voip_call_received_messagedialog_response ( self , dialog , response ) :
# we've got response from user, either stop connecting or accept the call
2009-09-19 17:24:59 +02:00
session = gajim . connections [ self . account ] . get_jingle_session ( self . fjid ,
2009-09-17 14:48:15 +02:00
self . sid )
2009-09-26 10:29:08 +02:00
if not session :
return
if response == gtk . RESPONSE_YES :
2009-10-03 22:40:12 +02:00
#TODO: Ensure that ctrl.contact.resource == resource
2009-09-17 14:48:15 +02:00
jid = gajim . get_jid_without_resource ( self . fjid )
resource = gajim . get_resource_from_jid ( self . fjid )
ctrl = gajim . interface . msg_win_mgr . get_control ( self . fjid , self . account )
if not ctrl :
ctrl = gajim . interface . msg_win_mgr . get_control ( jid , self . account )
if not ctrl :
# open chat control
contact = gajim . contacts . get_contact ( self . account , jid , resource )
if not contact :
contact = gajim . contacts . get_contact ( self . account , jid )
if not contact :
return
ctrl = gajim . interface . new_chat ( contact , self . account )
2009-10-03 22:40:12 +02:00
# Chat control opened, update content's status
2009-09-25 19:32:13 +02:00
if session . get_content ( ' audio ' ) :
ctrl . set_audio_state ( ' connecting ' , self . sid )
if session . get_content ( ' video ' ) :
ctrl . set_video_state ( ' connecting ' , self . sid )
2009-10-03 22:40:12 +02:00
# Now, accept the content/sessions.
# This should be done after the chat control is running
if not session . accepted :
session . approve_session ( )
for content in self . content_types :
session . approve_content ( content )
2007-08-24 01:42:31 +02:00
else : # response==gtk.RESPONSE_NO
2009-09-26 12:31:56 +02:00
if not session . accepted :
session . decline_session ( )
else :
for content in self . content_types :
session . reject_content ( content )
2007-08-24 01:42:31 +02:00
dialog . destroy ( )
2009-09-08 12:01:09 +02:00
2009-10-29 10:19:58 +01:00
2008-07-30 14:21:47 +02:00
# vim: se ts=3: