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/winpopup/wpcontact.cpp | 189 ++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 kopete/protocols/winpopup/wpcontact.cpp (limited to 'kopete/protocols/winpopup/wpcontact.cpp') diff --git a/kopete/protocols/winpopup/wpcontact.cpp b/kopete/protocols/winpopup/wpcontact.cpp new file mode 100644 index 00000000..7cf2529c --- /dev/null +++ b/kopete/protocols/winpopup/wpcontact.cpp @@ -0,0 +1,189 @@ +/*************************************************************************** + wpcontact.cpp - description + ------------------- + begin : Fri Apr 12 2002 + copyright : (C) 2002 by Gav Wood + email : gav@kde.org + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// Qt Includes +#include + +// KDE Includes +#include + +// Kopete Includes + +// Local Includes +#include "wpcontact.h" +#include "wpaccount.h" + +WPContact::WPContact(Kopete::Account *account, const QString &newHostName, const QString &nickName, Kopete::MetaContact *metaContact) + : Kopete::Contact(account, newHostName, metaContact) +{ +// kdDebug(14170) << "WPContact::WPContact(, " << newHostName << ", " << nickName << ", )" << endl; + kdDebug(14170) << "WPContact::WPContact: " << this << endl; + + QString theNickName = nickName; + + if (theNickName.isEmpty()) { + // Construct nickname from hostname with first letter to upper. GF + theNickName = newHostName.lower(); + theNickName = theNickName.replace(0, 1, theNickName[0].upper()); + } + + setNickName(theNickName); + myWasConnected = false; + + + m_manager = 0; + m_infoDialog = 0; + + // Initialise and start the periodical checking for contact's status + setOnlineStatus(static_cast(protocol())->WPOffline); + + connect(&checkStatus, SIGNAL(timeout()), this, SLOT(slotCheckStatus())); + checkStatus.start(1000, false); +} + +QPtrList * WPContact::customContextMenuActions() +{ + //myActionCollection = new KActionCollection(parent); + return 0; +} + +void WPContact::serialize(QMap &serializedData, QMap &addressBookData) +{ +// kdDebug(14170) << "WP::serialize(...)" << endl; + + Kopete::Contact::serialize(serializedData, addressBookData); +} + +Kopete::ChatSession* WPContact::manager( Kopete::Contact::CanCreateFlags /*canCreate*/ ) // TODO: use the parameter as canCreate +{ + if (m_manager == 0) { + // Set up the message managers + QPtrList singleContact; + singleContact.append(this); + + m_manager = Kopete::ChatSessionManager::self()->create( account()->myself(), singleContact, protocol() ); + + connect(m_manager, SIGNAL(messageSent(Kopete::Message &, Kopete::ChatSession *)), this, SLOT(slotSendMessage(Kopete::Message &))); + connect(m_manager, SIGNAL(messageSent(Kopete::Message &, Kopete::ChatSession *)), m_manager, SLOT(appendMessage(Kopete::Message &))); + connect(m_manager, SIGNAL(destroyed()), this, SLOT(slotChatSessionDestroyed())); + } + + return m_manager; +} + +/* +bool WPContact::isOnline() const +{ + kdDebug(14170) << "[WPContact::isOnline()]" << endl; + return onlineStatus().status() != Kopete::OnlineStatus::Offline && onlineStatus().status() != Kopete::OnlineStatus::Unknown; +} +*/ + +bool WPContact::isReachable() +{ +// kdDebug(14170) << "[WPContact::isReachable()]" << endl; + return onlineStatus().status() != Kopete::OnlineStatus::Offline && onlineStatus().status() != Kopete::OnlineStatus::Unknown; +} + +void WPContact::slotChatSessionDestroyed() +{ + m_manager = 0; +} + +void WPContact::slotUserInfo() +{ + kdDebug( 14170 ) << k_funcinfo << endl; + + if (!m_infoDialog) { + m_infoDialog = new WPUserInfo( this, static_cast( account() ) ); + if (!m_infoDialog) return; + connect( m_infoDialog, SIGNAL( closing() ), this, SLOT( slotCloseUserInfoDialog() ) ); + m_infoDialog->show(); + } else { + m_infoDialog->raise(); + } +} + +void WPContact::slotCloseUserInfoDialog() +{ + m_infoDialog->delayedDestruct(); + m_infoDialog = 0; +} + +/* +void deleteContact() +{ +// deleteLater(); +} +*/ + +void WPContact::slotCheckStatus() +{ + bool oldWasConnected = myWasConnected; + bool newIsOnline = false; + + myWasConnected = protocol() != 0 && account() != 0; + WPAccount *acct = dynamic_cast(account()); + if (acct) newIsOnline = acct->checkHost(contactId()); + + if(newIsOnline != isOnline() || myWasConnected != oldWasConnected) { + Kopete::OnlineStatus tmpStatus = WPProtocol::protocol()->WPOffline; + if (myWasConnected && newIsOnline) { + tmpStatus = WPProtocol::protocol()->WPOnline; + } + setOnlineStatus(tmpStatus); + } +} + +void WPContact::slotNewMessage(const QString &Body, const QDateTime &Arrival) +{ + kdDebug(14170) << "WPContact::slotNewMessage(" << Body << ", " << Arrival.toString() << ")" << endl; + + QPtrList contactList; + contactList.append(account()->myself()); + + QRegExp subj("^Subject: ([^\n]*)\n(.*)$"); + Kopete::Message msg; + + if(subj.search(Body) == -1) { + msg = Kopete::Message(this, contactList, Body, Kopete::Message::Inbound); + } else { + msg = Kopete::Message(this, contactList, subj.cap(2), subj.cap(1), Kopete::Message::Inbound); + } + + manager(Kopete::Contact::CannotCreate)->appendMessage(msg); +} + +void WPContact::slotSendMessage( Kopete::Message& message ) +{ +// kdDebug(14170) << "WPContact::slotSendMessage()" << endl; + // Warning: this could crash + kdDebug(14170) << message.to().first() << " is " << dynamic_cast( message.to().first() )->contactId() << endl; + + QString Message = (!message.subject().isEmpty() ? "Subject: " + message.subject() + "\n" : QString("")) + message.plainBody(); + WPAccount *acct = dynamic_cast(account()); + WPContact *contact = dynamic_cast( message.to().first() ); + if (acct && contact) { + acct->slotSendMessage( Message, contact->contactId() ); + m_manager->messageSucceeded(); + } +} + +#include "wpcontact.moc" + +// vim: set noet ts=4 sts=4 sw=4: +// kate: tab-width 4; indent-width 4; replace-trailing-space-save on; -- cgit v1.2.1