1 /*
2     meanwhileprotocol.cpp - the meanwhile protocol
3 
4     Copyright (c) 2003-2004 by Sivaram Gottimukkala  <suppandi@gmail.com>
5 
6     Kopete    (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
7 
8     *************************************************************************
9     *                                                                       *
10     * This program is free software; you can redistribute it and/or modify  *
11     * it under the terms of the GNU General Public License as published by  *
12     * the Free Software Foundation; either version 2 of the License, or     *
13     * (at your option) any later version.                                   *
14     *                                                                       *
15     *************************************************************************
16 */
17 #include "meanwhileprotocol.h"
18 #include "meanwhileaddcontactpage.h"
19 #include "meanwhileeditaccountwidget.h"
20 #include "meanwhileaccount.h"
21 #include <kpluginfactory.h>
22 #include "kopeteaccountmanager.h"
23 #include "kopeteglobal.h"
24 #include "kopeteonlinestatusmanager.h"
25 
26 #include <meanwhile/mw_common.h>
27 
K_PLUGIN_FACTORY(MeanwhileProtocolFactory,registerPlugin<MeanwhileProtocol> ();)28 K_PLUGIN_FACTORY( MeanwhileProtocolFactory, registerPlugin<MeanwhileProtocol>(); )
29 K_EXPORT_PLUGIN( MeanwhileProtocolFactory( "kopete_meanwhile" ) )
30 
31 MeanwhileProtocol::MeanwhileProtocol(QObject* parent, const QVariantList &/*args*/)
32 : Kopete::Protocol(MeanwhileProtocolFactory::componentData(), parent),
33 
34     statusOffline(Kopete::OnlineStatus::Offline, 25, this, 0, QStringList(),
35             i18n("Offline"), i18n("Offline"),
36             Kopete::OnlineStatusManager::Offline,
37 	    Kopete::OnlineStatusManager::DisabledIfOffline),
38 
39     statusOnline(Kopete::OnlineStatus::Online, 25, this, mwStatus_ACTIVE,
40             QStringList(), i18n("Online"), i18n("Online"),
41             Kopete::OnlineStatusManager::Online, 0),
42 
43     statusAway(Kopete::OnlineStatus::Away, 20, this, mwStatus_AWAY,
44             QStringList(QLatin1String("meanwhile_away")), i18n("Away"), i18n("Away"),
45             Kopete::OnlineStatusManager::Away,
46 	    Kopete::OnlineStatusManager::HasStatusMessage),
47 
48     statusBusy(Kopete::OnlineStatus::Busy, 25, this, mwStatus_BUSY,
49             QStringList(QLatin1String("meanwhile_dnd")), i18n("Busy"), i18n("Busy"),
50           Kopete::OnlineStatusManager::Busy,
51 	  Kopete::OnlineStatusManager::HasStatusMessage),
52 
53     statusIdle(Kopete::OnlineStatus::Away, 30, this, mwStatus_AWAY,
54             QStringList(QLatin1String("meanwhile_idle")), i18n("Idle"), i18n("Idle"),
55             Kopete::OnlineStatusManager::Idle, 0),
56 
57     statusAccountOffline(Kopete::OnlineStatus::Offline, 0, this, 0,
58             QStringList(), i18n("Account Offline"))
59 
60     /* ### TODO
61     statusMessage(QString::fromLatin1("statusMessage"),
62         i18n("Status Message"), QString(), false, true),
63 
64     awayMessage(Kopete::Global::Properties::self()->awayMessage())
65     */
66 {
67     HERE;
68 
69     addAddressBookField("messaging/meanwhile", Kopete::Plugin::MakeIndexField);
70 }
71 
~MeanwhileProtocol()72 MeanwhileProtocol::~MeanwhileProtocol()
73 {
74 }
75 
createAddContactWidget(QWidget * parent,Kopete::Account * account)76 AddContactPage * MeanwhileProtocol::createAddContactWidget(QWidget *parent,
77         Kopete::Account *account )
78 {
79 	return new MeanwhileAddContactPage(parent, account);
80 }
81 
createEditAccountWidget(Kopete::Account * account,QWidget * parent)82 KopeteEditAccountWidget * MeanwhileProtocol::createEditAccountWidget(
83         Kopete::Account *account, QWidget *parent )
84 {
85 	return new MeanwhileEditAccountWidget(parent, account, this);
86 }
87 
createNewAccount(const QString & accountId)88 Kopete::Account *MeanwhileProtocol::createNewAccount(const QString &accountId)
89 {
90 	return new MeanwhileAccount(this, accountId);
91 }
92 
deserializeContact(Kopete::MetaContact * metaContact,const QMap<QString,QString> & serializedData,const QMap<QString,QString> &)93 Kopete::Contact *MeanwhileProtocol::deserializeContact(
94                             Kopete::MetaContact *metaContact,
95                             const QMap<QString,
96                             QString> &serializedData,
97                             const QMap<QString, QString> & /* addressBookData */ )
98 {
99     QString contactId = serializedData[ "contactId" ];
100     QString accountId = serializedData[ "accountId" ];
101     Kopete::Contact::NameType nameType = Kopete::Contact::nameTypeFromString(serializedData[ "preferredNameType" ]);
102 
103     MeanwhileAccount *theAccount =
104             static_cast<MeanwhileAccount*>(
105                             Kopete::AccountManager::self()->
106                                     findAccount(pluginId(), accountId));
107 
108     if(!theAccount)
109     {
110         return 0;
111     }
112 
113     theAccount->addContact(contactId, metaContact, Kopete::Account::DontChangeKABC);
114 
115     Kopete::Contact *c = theAccount->contacts().value(contactId);
116     if (!c)
117         return 0;
118 
119     c->setPreferredNameType(nameType);
120     return c;
121 }
122 
accountOfflineStatus()123 const Kopete::OnlineStatus MeanwhileProtocol::accountOfflineStatus()
124 {
125     return statusAccountOffline;
126 }
127 
lookupStatus(Kopete::OnlineStatusManager::Categories cats)128 const Kopete::OnlineStatus MeanwhileProtocol::lookupStatus(
129             Kopete::OnlineStatusManager::Categories cats)
130 {
131     return Kopete::OnlineStatusManager::self()->onlineStatus(this, cats);
132 }
133 #include "meanwhileprotocol.moc"
134