From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/sms/smscontact.cpp | 142 ++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 kopete/protocols/sms/smscontact.cpp (limited to 'kopete/protocols/sms/smscontact.cpp') diff --git a/kopete/protocols/sms/smscontact.cpp b/kopete/protocols/sms/smscontact.cpp new file mode 100644 index 00000000..d220b380 --- /dev/null +++ b/kopete/protocols/sms/smscontact.cpp @@ -0,0 +1,142 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lärkäng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#undef KDE_NO_COMPAT +#include +#include +#include +#include +#include + +#include "kopetechatsessionmanager.h" +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" + +#include "smscontact.h" +#include "smsprotocol.h" +#include "smsservice.h" +#include "smsaccount.h" +#include "smsuserpreferences.h" + +SMSContact::SMSContact( Kopete::Account* _account, const QString &phoneNumber, + const QString &displayName, Kopete::MetaContact *parent ) +: Kopete::Contact( _account, phoneNumber, parent ), m_phoneNumber( phoneNumber ) +{ +// kdWarning( 14160 ) << k_funcinfo << " this = " << this << ", phone = " << phoneNumber << endl; + setNickName( displayName ); + + m_msgManager = 0L; + m_actionPrefs = 0L; + + if( account()->isConnected() ) + setOnlineStatus( SMSProtocol::protocol()->SMSOnline ); +} + +void SMSContact::slotSendingSuccess(const Kopete::Message &msg) +{ + manager(Kopete::Contact::CanCreate)->messageSucceeded(); + manager(Kopete::Contact::CanCreate)->appendMessage((Kopete::Message &)msg); +} + +void SMSContact::slotSendingFailure(const Kopete::Message &/*msg*/, const QString &error) +{ + KMessageBox::detailedError(Kopete::UI::Global::mainWidget(), i18n("Something went wrong when sending message."), error, + i18n("Could Not Send Message")); +// manager()->messageFailed(); + // TODO: swap for failed as above. show it anyway for now to allow closing of window. + manager(Kopete::Contact::CanCreate)->messageSucceeded(); +} + +void SMSContact::serialize( QMap &serializedData, + QMap & /* addressBookData */ ) +{ + // Contact id and display name are already set for us + if (m_phoneNumber != contactId()) + serializedData[ "contactId" ] = m_phoneNumber; +} + +Kopete::ChatSession* SMSContact::manager( Kopete::Contact::CanCreateFlags canCreate ) +{ + if ( m_msgManager || canCreate != Kopete::Contact::CanCreate ) + { + return m_msgManager; + } + else + { + QPtrList contacts; + contacts.append(this); + m_msgManager = Kopete::ChatSessionManager::self()->create(account()->myself(), contacts, protocol()); + connect(m_msgManager, SIGNAL(messageSent(Kopete::Message&, Kopete::ChatSession*)), + account(), SLOT(slotSendMessage(Kopete::Message&))); + connect(m_msgManager, SIGNAL(destroyed()), this, SLOT(slotChatSessionDestroyed())); + return m_msgManager; + } +} + +void SMSContact::slotChatSessionDestroyed() +{ + m_msgManager = 0L; +} + + +void SMSContact::slotUserInfo() +{ +} + +void SMSContact::deleteContact() +{ + deleteLater(); +} + +const QString SMSContact::qualifiedNumber() +{ + QString number = m_phoneNumber; + dynamic_cast(account())->translateNumber(number); + return number; +} + +const QString &SMSContact::phoneNumber() +{ + return m_phoneNumber; +} + +void SMSContact::setPhoneNumber( const QString phoneNumber ) +{ + deleteLater(); + new SMSContact(account(), phoneNumber, nickName(), metaContact()); +} + +QPtrList* SMSContact::customContextMenuActions() +{ + QPtrList *m_actionCollection = new QPtrList(); + if( !m_actionPrefs ) + m_actionPrefs = new KAction(i18n("&Contact Settings"), 0, this, SLOT(userPrefs()), this, "userPrefs"); + + m_actionCollection->append( m_actionPrefs ); + + return m_actionCollection; +} + +void SMSContact::userPrefs() +{ + SMSUserPreferences* p = new SMSUserPreferences( this ); + p->show(); +} + +#include "smscontact.moc" + +// vim: set noet ts=4 sts=4 sw=4: + -- cgit v1.2.1