2 meanwhileaccount.cpp - a meanwhile account
4 Copyright (c) 2003-2004 by Sivaram Gottimukkala <suppandi@gmail.com>
5 Copyright (c) 2005 by Jeremy Kerr <jk@ozlabs.org>
7 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 *************************************************************************
19 #include "meanwhileprotocol.h"
20 #include "meanwhileplugin.h"
21 #include "meanwhileaccount.h"
22 #include "meanwhilecontact.h"
23 #include "meanwhilesession.h"
24 #include "kopetechatsession.h"
25 #include "kopetecontactlist.h"
26 #include "kopetepassword.h"
29 #include <kactionmenu.h>
32 #include <kconfigbase.h>
33 #include <kinputdialog.h>
34 #include <kmessagebox.h>
36 MeanwhileAccount::MeanwhileAccount(
37 MeanwhileProtocol
*parent
,
38 const QString
&accountID
)
39 : Kopete::PasswordedAccount(parent
, accountID
)
42 m_meanwhileId
= accountID
;
44 setMyself(new MeanwhileContact(m_meanwhileId
, m_meanwhileId
, this,
45 Kopete::ContactList::self()->myself()));
46 setOnlineStatus(parent
->statusOffline
);
47 infoPlugin
= new MeanwhilePlugin();
50 MeanwhileAccount::~MeanwhileAccount()
56 void MeanwhileAccount::setPlugin(MeanwhilePlugin
*plugin
)
62 bool MeanwhileAccount::createContact(
63 const QString
& contactId
,
64 Kopete::MetaContact
* parentContact
)
66 MeanwhileContact
* newContact
= new MeanwhileContact(contactId
,
67 parentContact
->displayName(), this, parentContact
);
69 MeanwhileProtocol
*p
= static_cast<MeanwhileProtocol
*>(protocol());
71 if ((newContact
!= 0L) && (m_session
!= 0L)
72 && (myself()->onlineStatus() !=
74 m_session
->addContact(newContact
);
76 return newContact
!= 0L;
79 void MeanwhileAccount::connectWithPassword(const QString
&password
)
81 if (password
.isEmpty()) {
82 disconnect(Kopete::Account::Manual
);
86 if (m_session
== 0L) {
87 m_session
= new MeanwhileSession(this);
88 if (m_session
== 0L) {
89 mwDebug() << "session creation failed" << endl
;
93 QObject::connect(m_session
,
94 SIGNAL(sessionStateChange(Kopete::OnlineStatus
)),
95 this, SLOT(slotSessionStateChange(Kopete::OnlineStatus
)));
96 QObject::connect(m_session
,
97 SIGNAL(serverNotification(const QString
&)),
98 this, SLOT(slotServerNotification(const QString
&)));
102 if (m_session
== 0L) {
103 mwDebug() << "No memory for session" << endl
;
107 // void connect(QString host, int port, QString account, QString password);
110 if (!m_session
->isConnected() && !m_session
->isConnecting())
111 m_session
->connect(password
);
113 m_session
->setStatus(initialStatus());
116 void MeanwhileAccount::disconnect()
121 void MeanwhileAccount::disconnect(Kopete::Account::DisconnectReason reason
)
126 MeanwhileProtocol
*p
= static_cast<MeanwhileProtocol
*>(protocol());
127 setAllContactsStatus(p
->statusOffline
);
128 disconnected(reason
);
129 emit
isConnectedChanged();
135 void MeanwhileAccount::fillActionMenu( KActionMenu
*actionMenu
)
137 Kopete::Account::fillActionMenu( actionMenu
);
139 actionMenu
->menu()->addSeparator();
142 actionMenu
->insert(new KAction(i18n("&Change Status Message"), QString(), 0,
143 this, SLOT(meanwhileChangeStatus()), this,
144 "meanwhileChangeStatus"));
145 //infoPlugin->addCustomMenus(theMenu);
149 QString
MeanwhileAccount::getServerName()
151 return configGroup()->readEntry("Server");
154 int MeanwhileAccount::getServerPort()
156 return configGroup()->readEntry("Port").toInt();
159 void MeanwhileAccount::setServerName(const QString
&server
)
161 configGroup()->writeEntry("Server", server
);
164 void MeanwhileAccount::setServerPort(int port
)
166 configGroup()->writeEntry("Port", port
);
169 void MeanwhileAccount::setClientID(int client
, int major
, int minor
)
171 configGroup()->writeEntry("clientID", client
);
172 configGroup()->writeEntry("clientVersionMajor", major
);
173 configGroup()->writeEntry("clientVersionMinor", minor
);
176 void MeanwhileAccount::resetClientID()
178 configGroup()->deleteEntry("clientID");
179 configGroup()->deleteEntry("clientVersionMajor");
180 configGroup()->deleteEntry("clientVersionMinor");
183 bool MeanwhileAccount::getClientIDParams(int *clientID
,
184 int *verMajor
, int *verMinor
)
186 bool custom_id
= configGroup()->hasKey("clientID");
188 MeanwhileSession::getDefaultClientIDParams(clientID
, verMajor
, verMinor
);
191 *clientID
= configGroup()->readEntry("clientID", *clientID
);
192 *verMajor
= configGroup()->readEntry("clientVersionMajor", *verMinor
);
193 *verMinor
= configGroup()->readEntry("clientVersionMinor", *verMinor
);
199 void MeanwhileAccount::setForceLogin(bool force
)
201 configGroup()->writeEntry("forceLogin", force
);
204 bool MeanwhileAccount::getForceLogin()
206 return configGroup()->readEntry("forceLogin", false);
209 void MeanwhileAccount::slotServerNotification(const QString
&mesg
)
211 KMessageBox::queuedMessageBox(0, KMessageBox::Error
, mesg
,
212 i18n("Meanwhile Plugin: Message from server"), KMessageBox::Notify
);
215 QString
MeanwhileAccount::meanwhileId() const
217 return m_meanwhileId
;
220 void MeanwhileAccount::setAway(bool away
, const QString
&reason
)
222 MeanwhileProtocol
*p
= static_cast<MeanwhileProtocol
*>(protocol());
223 setOnlineStatus(away
? p
->statusIdle
: p
->statusOnline
, reason
);
226 void MeanwhileAccount::setStatusMessage(const Kopete::StatusMessage
&statusMessage
)
231 void MeanwhileAccount::setOnlineStatus(const Kopete::OnlineStatus
&status
,
232 const Kopete::StatusMessage
&reason
, const OnlineStatusOptions
& options
)
235 Kopete::OnlineStatus oldstatus
= myself()->onlineStatus();
237 mwDebug() << "From: " << oldstatus
.description() << "(" <<
238 oldstatus
.internalStatus() << "):" << oldstatus
.isDefinitelyOnline()
240 mwDebug() << "To: " << status
.description() << "(" <<
241 status
.internalStatus() << "):" << status
.isDefinitelyOnline() << endl
;
243 if (oldstatus
== status
)
246 if (!oldstatus
.isDefinitelyOnline() && status
.isDefinitelyOnline()) {
249 } else if (oldstatus
.isDefinitelyOnline() && !status
.isDefinitelyOnline()) {
250 disconnect(Kopete::Account::Manual
);
252 } else if (m_session
)
253 /* todo: check session state? */
254 m_session
->setStatus(status
, reason
);
257 mwDebug() << "Trying to set status, but no session exists" << endl
;
259 /* we should set this on the callback below */
260 //myself()->setOnlineStatus(status);
263 void MeanwhileAccount::syncContactsToServer()
266 m_session
->syncContactsToServer();
269 void MeanwhileAccount::slotSessionStateChange(Kopete::OnlineStatus status
)
272 Kopete::OnlineStatus oldstatus
= myself()->onlineStatus();
273 myself()->setOnlineStatus(status
);
275 if (status
.isDefinitelyOnline() != oldstatus
.isDefinitelyOnline()) {
276 if (status
.isDefinitelyOnline())
277 m_session
->addContacts(contacts());
278 emit
isConnectedChanged();
282 MeanwhileSession
*MeanwhileAccount::session()
287 #include "meanwhileaccount.moc"