# -*- coding: utf-8 -*- # This file is part of emesene. # # Emesene is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # emesene is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with emesene; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import gtk from emesenecommon import RESPONSE_DELETE_ALIAS class FormattedDialog ( gtk.Dialog ): def __init__( self, title, parent, message, stockimage, flags, buttons): gtk.Dialog.__init__( self, title, parent, flags, buttons ) self.set_resizable( False ) self.set_has_separator( False ) self.set_border_width( 6 ) self.vbox.set_spacing ( 12 ) label = gtk.Label( '' + message + '\n' ) label.set_alignment( 0.0, 0.5 ) label.set_use_markup( True ) label.set_line_wrap( True ) label.set_selectable( True ) image = gtk.Image() image.set_from_stock( stockimage , gtk.ICON_SIZE_DIALOG ) image.set_alignment( 0.0, 0.5 ) hbox = gtk.HBox() hbox.set_spacing( 12 ) hbox.set_border_width( 6 ) hbox.pack_start( image ) hbox.pack_start( label ) self.vbox.pack_start( hbox ) self.vbox.show_all() class Message( FormattedDialog ): '''This is a simple error dialog''' def __init__( self , parent , message , stock ): FormattedDialog.__init__( self , '' , parent , message, stock, \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \ ( gtk.STOCK_OK, gtk.RESPONSE_ACCEPT ) ) def run( self ): gtk.Dialog.run( self ) self.destroy() class Error( Message ): '''This is a simple error dialog''' def __init__( self , parent , message ): Message.__init__( self , parent , message , gtk.STOCK_DIALOG_ERROR ) class Warning( gtk.Dialog ): '''This is a simple warning dialog''' def __init__( self , parent , message ): Message.__init__( self , parent , message , gtk.STOCK_DIALOG_WARNING ) class Information( Message ): '''This is a simple Information dialog''' def __init__( self , parent , message ): Message.__init__( self , parent , message , gtk.STOCK_DIALOG_INFO ) class Confirm( FormattedDialog ): '''this class represent a Confirmation dialog''' def __init__( self , parent , message, stock_action=gtk.STOCK_OK ): FormattedDialog.__init__( self , '', parent , message, \ gtk.STOCK_DIALOG_WARNING, \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT , \ (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, \ stock_action, gtk.RESPONSE_ACCEPT) ) self.set_default_response( gtk.RESPONSE_REJECT ) def run( self ): option = gtk.Dialog.run( self ) self.destroy() return option class AddBuddy( Confirm ): '''Confirm dialog informing that someone has added you ask if you want to add him to your contact list''' def __init__( self , parent , friend ): Confirm.__init__( self , parent , friend + _( ' has added you.\nDo you want to add him/her to your contact list?' ), gtk.STOCK_ADD ) class Add( gtk.Dialog ): '''this class represent a dialog window which lets you add a something''' def __init__( self , parent , thingToAdd , labelText, stock_action=gtk.STOCK_ADD, alternative=None ): if alternative: altStock, altResponse = alternative gtk.Dialog.__init__( self , thingToAdd , parent , \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT , \ ( altStock, altResponse, \ gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, \ stock_action, gtk.RESPONSE_ACCEPT) ) else: gtk.Dialog.__init__( self , thingToAdd , parent , \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT , \ (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, \ stock_action, gtk.RESPONSE_ACCEPT) ) self.set_geometry_hints( self, 300 ) self.set_resizable( False ) self.set_has_separator( False ) self.set_border_width( 6 ) self.set_default_response( gtk.RESPONSE_ACCEPT ) self.vbox.set_spacing ( 18 ) label = gtk.Label( '' + labelText + '' ) label.set_alignment( 0.0, 0.5 ) label.set_use_markup( True ) label.set_line_wrap( True ) label.set_selectable( True ) self.thing = gtk.Entry() self.thing.connect( 'activate' , self.activate ) vbox = gtk.VBox() vbox.set_spacing( 6 ) vbox.set_border_width( 6 ) vbox.pack_start( label ) vbox.pack_start( self.thing ) self.userVbox = gtk.VBox() self.userVbox.set_spacing( 12 ) self.userVbox.pack_start( vbox ) self.vbox.pack_start( self.userVbox ) self.vbox.show_all() def run( self ): '''runs the dialog and return the string it doesnt make any control''' option = gtk.Dialog.run( self ) if option == gtk.RESPONSE_ACCEPT: text = self.thing.get_text() self.destroy() return text else: self.destroy() return None def activate( self , *args ): self.response( gtk.RESPONSE_ACCEPT ) class AddFriend( Add ): '''a dialog to add a new friend''' def __init__( self , parent, groups, toGroup ): Add.__init__( self , parent , _( 'Add a Friend' ) , _( 'Introduce your friend\'s email:' ) ) label = gtk.Label( '' + _('Add to group:') + '' ) label.set_alignment( 0.0, 0.5 ) label.set_use_markup( True ) label.set_line_wrap( True ) label.set_selectable( True ) self.groupList = gtk.ListStore( str ) self.combo = gtk.ComboBox( self.groupList ) groupCell = gtk.CellRendererText() self.combo.pack_start( groupCell, False ) self.combo.add_attribute( groupCell, 'text', 0 ) self.groupList.append( [ _( 'No group' ) ] ) groups.sort( key= lambda x: x.lower() ) for i in groups: self.groupList.append( [ i ] ) try: self.combo.set_active( groups.index( toGroup ) + 1 ) except: self.combo.set_active( 0 ) alig = gtk.Alignment( 0.0, 0.5, 1.0 ) alig.add( self.combo ) hbox = gtk.HBox() hbox.set_spacing( 12 ) hbox.set_border_width( 6 ) hbox.pack_start( label, False, False ) hbox.pack_start( alig ) self.userVbox.pack_start( hbox ) self.vbox.show_all() def run( self ): '''runs the dialog and return the a list containing the mail and the group it doesnt make any control''' option = gtk.Dialog.run( self ) if option == gtk.RESPONSE_ACCEPT: group = self.combo.get_model().get_value(self.combo.get_active_iter(), 0) if group == _( 'No group' ): group = '' text = self.thing.get_text() self.destroy() return ( text, group ) else: self.destroy() return None class AddGroup( Add ): '''a dialog to add a new group''' def __init__( self , parent ): Add.__init__( self , parent , _( 'Add a Group' ) , _( 'Group name:' ) ) class ChangeNick( Add ): '''a dialog to change the nick''' def __init__( self , parent , oldNick, deleteBut=False ): if deleteBut: Add.__init__( self , parent , _( 'Change Nickname' ) , \ _( 'New nickname:' ), gtk.STOCK_APPLY, ( gtk.STOCK_DELETE, RESPONSE_DELETE_ALIAS ) ) else: Add.__init__( self , parent , _( 'Change Nickname' ) , \ _( 'New nickname:' ), gtk.STOCK_APPLY ) self.thing.set_text( oldNick ) def run( self ): '''runs the dialog and return the string it doesnt make any control''' option = gtk.Dialog.run( self ) if option == gtk.RESPONSE_ACCEPT: text = self.thing.get_text() self.hide() return text elif option == RESPONSE_DELETE_ALIAS: self.destroy() return '' else: self.hide() return None class RenameGroup( Add ): '''a dialog to rename a group''' def __init__( self , parent , oldName ): Add.__init__( self , parent , _( 'Rename Group' ) , \ _( 'New group name:' ), gtk.STOCK_APPLY ) self.thing.set_text( oldName ) class SetAutoReply( Add ): '''a dialog to set the autoreply message''' def __init__( self , parent , currentMessage ): Add.__init__( self , parent , _( 'Set AutoReply' ) , \ _( 'AutoReply message:' ), gtk.STOCK_APPLY ) self.set_geometry_hints( self, 350 ) self.thing.set_text( currentMessage )