File indexing completed on 2024-04-14 04:01:46
0001 /* 0002 * jabbergroupmembercontact.cpp - Regular Kopete Jabber protocol contact 0003 * 0004 * Copyright (c) 2002-2004 by Till Gerken <till@tantalo.net> 0005 * 0006 * Kopete (c) by the Kopete developers <kopete-devel@kde.org> 0007 * 0008 * ************************************************************************* 0009 * * * 0010 * * This program is free software; you can redistribute it and/or modify * 0011 * * it under the terms of the GNU General Public License as published by * 0012 * * the Free Software Foundation; either either version 2 0013 of the License, or (at your option) any later version.of the License, or * 0014 * * (at your option) any later version. * 0015 * * * 0016 * ************************************************************************* 0017 */ 0018 0019 #include "jabbergroupmembercontact.h" 0020 #include "jabber_protocol_debug.h" 0021 0022 #include <KLocalizedString> 0023 #include <KFileDialog> 0024 #include "jabberprotocol.h" 0025 #include "jabberaccount.h" 0026 #include "jabberfiletransfer.h" 0027 #include "jabbergroupchatmanager.h" 0028 #include "jabberchatsession.h" 0029 #include "jabbercontactpool.h" 0030 #include "kopetemetacontact.h" 0031 0032 /** 0033 * JabberGroupMemberContact constructor 0034 */ 0035 JabberGroupMemberContact::JabberGroupMemberContact (const XMPP::RosterItem &rosterItem, 0036 JabberAccount *account, Kopete::MetaContact * mc) 0037 : JabberBaseContact ( rosterItem, account, mc) 0038 { 0039 0040 mc->setDisplayName ( rosterItem.jid().resource() ); 0041 setNickName ( rosterItem.jid().resource() ); 0042 0043 setFileCapable ( true ); 0044 0045 mManager = 0; 0046 0047 } 0048 0049 /** 0050 * JabberGroupMemberContact destructor 0051 */ 0052 JabberGroupMemberContact::~JabberGroupMemberContact () 0053 { 0054 if(mManager) 0055 { 0056 mManager->deleteLater(); 0057 } 0058 } 0059 0060 QList<QAction *> *JabberGroupMemberContact::customContextMenuActions () 0061 { 0062 0063 return 0; 0064 0065 } 0066 0067 Kopete::ChatSession *JabberGroupMemberContact::manager ( Kopete::Contact::CanCreateFlags canCreate ) 0068 { 0069 0070 if ( mManager ) 0071 return mManager; 0072 0073 if ( !mManager && !canCreate ) 0074 return 0; 0075 0076 Kopete::ContactPtrList chatMembers; 0077 chatMembers.append ( this ); 0078 0079 /* 0080 * FIXME: We might have to use the groupchat contact here instead of 0081 * the global myself() instance for a correct representation. 0082 */ 0083 mManager = new JabberChatSession ( protocol(), static_cast<JabberBaseContact *>(account()->myself()), chatMembers ); 0084 connect ( mManager, SIGNAL (destroyed(QObject*)), this, SLOT (slotChatSessionDeleted()) ); 0085 0086 return mManager; 0087 0088 } 0089 0090 void JabberGroupMemberContact::slotChatSessionDeleted () 0091 { 0092 0093 mManager = 0; 0094 0095 } 0096 0097 void JabberGroupMemberContact::handleIncomingMessage ( const XMPP::Message &message ) 0098 { 0099 // message type is always chat in a groupchat 0100 QString viewType = "kopete_chatwindow"; 0101 Kopete::Message *newMessage = 0L; 0102 0103 qCDebug(JABBER_PROTOCOL_LOG) << "Received Message Type:" << message.type (); 0104 0105 /** 0106 * Don't display empty messages, these were most likely just carrying 0107 * event notifications or other payload. 0108 */ 0109 if ( message.body().isEmpty () ) 0110 return; 0111 0112 Kopete::ChatSession *kmm = manager( Kopete::Contact::CanCreate ); 0113 if(!kmm) 0114 return; 0115 Kopete::ContactPtrList contactList = kmm->members(); 0116 0117 // check for errors 0118 if ( message.type () == "error" ) 0119 { 0120 newMessage = new Kopete::Message( this, contactList ); 0121 newMessage->setTimestamp( message.timeStamp() ); 0122 newMessage->setPlainBody( i18n("Your message could not be delivered: \"%1\", Reason: \"%2\"", 0123 message.body (), message.error().text ) ); 0124 newMessage->setSubject( message.subject() ); 0125 newMessage->setDirection( Kopete::Message::Inbound ); 0126 newMessage->setRequestedPlugin( viewType ); 0127 } 0128 else 0129 { 0130 // retrieve and reformat body 0131 QString body = message.body (); 0132 0133 if( !message.xencrypted().isEmpty () ) 0134 { 0135 body = QString ("-----BEGIN PGP MESSAGE-----\n\n") + message.xencrypted () + QString ("\n-----END PGP MESSAGE-----\n"); 0136 } 0137 0138 // convert XMPP::Message into Kopete::Message 0139 newMessage = new Kopete::Message ( this, contactList ); 0140 newMessage->setTimestamp( message.timeStamp() ); 0141 newMessage->setPlainBody( body ); 0142 newMessage->setDirection( Kopete::Message::Inbound ); 0143 newMessage->setRequestedPlugin( viewType ); 0144 } 0145 0146 // append message to manager 0147 kmm->appendMessage ( *newMessage ); 0148 0149 delete newMessage; 0150 0151 } 0152 0153 void JabberGroupMemberContact::sendFile ( const KUrl &sourceURL, const QString &/*fileName*/, uint /*fileSize*/ ) 0154 { 0155 QString filePath; 0156 0157 // if the file location is null, then get it from a file open dialog 0158 if ( !sourceURL.isValid () ) 0159 filePath = KFileDialog::getOpenFileName( KUrl(), "*", 0L, i18n ( "Kopete File Transfer" ) ); 0160 else 0161 filePath = sourceURL.path(KUrl::RemoveTrailingSlash); 0162 0163 QFile file ( filePath ); 0164 0165 if ( file.exists () ) 0166 { 0167 // send the file 0168 new JabberFileTransfer ( account (), this, filePath ); 0169 } 0170 0171 } 0172 0173 #include "moc_jabbergroupmembercontact.cpp"