22 #include <QtCore/QStringList>
23 #include <QtCore/QList>
24 #include <QtCore/QLatin1String>
28 #include <kplugininfo.h>
31 #include <kopetecontactlist.h>
32 #include <kopetemetacontact.h>
33 #include <kopetecontact.h>
34 #include <kopeteidentity.h>
35 #include <kopeteidentitymanager.h>
36 #include <kopeteavatarmanager.h>
37 #include <kopeteaccount.h>
38 #include <kopeteaccountmanager.h>
39 #include <kopeteonlinestatus.h>
40 #include <kopetemessage.h>
41 #include <kopetechatsession.h>
42 #include <kopetegroup.h>
43 #include <kopetepluginmanager.h>
44 #include <kopetepicture.h>
45 #include <kopeteviewmanager.h>
46 #include <kopetemessageevent.h>
49 #include "kopeteadaptor.h"
54 setObjectName(
"KopeteDBusInterface");
55 new KopeteAdaptor(
this);
56 QDBusConnection::sessionBus().registerObject(
"/Kopete",
this);
68 foreach(KPluginInfo p, Kopete::PluginManager::self()->availablePlugins(
"Protocols"))
77 return d->
listContact(Kopete::ContactList::self()->metaContacts());
82 QList<Kopete::MetaContact*> completeList =
83 Kopete::ContactList::self()->metaContacts();
84 QList<Kopete::MetaContact*> filteredList;
88 if (filter.toLower() == QLatin1String(
"online"))
92 foreach(contact, completeList)
94 if( contact->isOnline() )
95 filteredList << contact;
98 else if( filter.toLower() == QLatin1String(
"reachable") )
100 foreach(contact, completeList)
102 if( contact->isReachable() )
103 filteredList << contact;
106 else if( filter.toLower() == QLatin1String(
"filecapable") )
108 foreach(contact, completeList)
110 if( contact->canAcceptFiles() )
111 filteredList << contact;
114 else if ( filter.toLower() == QLatin1String(
"away") )
116 foreach(contact, completeList)
118 if( contact->status() == Kopete::OnlineStatus::Away )
120 filteredList << contact;
124 else if ( filter.toLower() == QLatin1String(
"busy") )
126 foreach(contact, completeList)
128 if( contact->status() == Kopete::OnlineStatus::Busy )
130 filteredList << contact;
139 const QString &identityId)
141 Kopete::Identity *identity = 0;
143 if (identityId.isEmpty())
145 identity = Kopete::IdentityManager::self()->defaultIdentity();
149 identity = Kopete::IdentityManager::self()->findIdentity(identityId);
154 identity->setProperty(Kopete::Global::Properties::self()->nickName(),
160 const QString &identityId)
162 Kopete::Identity *identity = 0;
164 if (identityId.isEmpty())
166 identity = Kopete::IdentityManager::self()->defaultIdentity();
170 identity = Kopete::IdentityManager::self()->findIdentity(identityId);
176 Kopete::AvatarManager::AvatarEntry avatarEntry;
177 avatarEntry.name =
"D-Bus Avatar";
178 avatarEntry.path = KUrl(avatarUrl).path();
179 avatarEntry.category = Kopete::AvatarManager::User;
181 avatarEntry = Kopete::AvatarManager::self()->add(avatarEntry);
183 identity->setProperty(Kopete::Global::Properties::self()->photo(),
189 const QString &message,
const QString &identityId)
191 Kopete::Identity *identity = 0;
193 if (identityId.isEmpty())
195 identity = Kopete::IdentityManager::self()->defaultIdentity();
199 identity = Kopete::IdentityManager::self()->findIdentity(identityId);
204 identity->setOnlineStatus(d->
status2Value(status), message);
212 foreach(Kopete::Identity *identity, Kopete::IdentityManager::self()->
identities())
214 result << identity->id();
222 Kopete::Identity * identity =
223 Kopete::IdentityManager::self()->findIdentity(
id);
226 return identity->label();
238 foreach(Kopete::Account *account, Kopete::AccountManager::self()->
accounts())
240 result << account->accountId();
248 Kopete::AccountManager::self()->setOnlineStatus(
249 Kopete::OnlineStatusManager::Online, QString(),
250 Kopete::AccountManager::ConnectIfOffline);
255 Kopete::AccountManager::self()->setOnlineStatus(
256 Kopete::OnlineStatusManager::Offline);
261 Kopete::AccountManager::self()->suspend();
266 Kopete::AccountManager::self()->resume();
270 const QString &message)
272 Kopete::AccountManager::self()->setOnlineStatus(d->
status2Value(status),
278 Kopete::AccountManager::self()->setStatusMessage(message);
282 const QString &message)
285 if (destMetaContact && destMetaContact->isReachable())
287 Kopete::Contact *destContact = destMetaContact->execute();
290 Kopete::Message newMessage(destContact->account()->myself(),
292 newMessage.setPlainBody(message);
293 newMessage.setDirection(Kopete::Message::Outbound);
295 destContact->manager(Kopete::Contact::CanCreate)->sendMessage(
304 if (contact && contact->isReachable())
306 Kopete::Contact *preferredContact = contact->preferredContact();
307 if (preferredContact && preferredContact->account()
308 && preferredContact != preferredContact->account()->myself())
319 return contact->displayName();
328 return contact->isOnline();
334 const QString &
accountId,
const QString &contactId,
335 const QString &displayName,
const QString &groupName)
337 QString protocolId = protocolName;
338 if (!protocolName.contains(
"Protocol"))
340 protocolId += QLatin1String(
"Protocol");
344 Kopete::Account *account = Kopete::AccountManager::self()->findAccount(
345 protocolId, accountId);
352 if (displayName.isEmpty())
354 contactName = contactId;
358 contactName = displayName;
361 if (!groupName.isEmpty())
362 realGroup = Kopete::ContactList::self()->findGroup(groupName);
364 account->addContact(contactId, contactName, realGroup,
365 Kopete::Account::DontChangeKABC);
374 const QString &fileUrl)
377 if (destMetaContact && destMetaContact->isReachable())
379 Kopete::Contact *destContact = destMetaContact->execute();
380 if (destContact && destContact->isFileCapable())
382 destContact->sendFile(KUrl(fileUrl));
390 QString protocolId = protocolName;
391 if (!protocolName.contains(
"Protocol"))
393 protocolId += QLatin1String(
"Protocol");
396 Kopete::Account *account = Kopete::AccountManager::self()->findAccount(
397 protocolId, accountId);
398 return account ? account->isConnected() :
false;
404 QString protocolId = protocolName;
405 if (!protocolName.contains(
"Protocol"))
407 protocolId += QLatin1String(
"Protocol");
410 Kopete::Account *account = Kopete::AccountManager::self()->findAccount(
411 protocolId, accountId);
421 QString protocolId = protocolName;
422 if (!protocolName.contains(
"Protocol"))
424 protocolId += QLatin1String(
"Protocol");
427 Kopete::Account *account = Kopete::AccountManager::self()->findAccount(
428 protocolId, accountId);
431 account->disconnect();
437 QVariantMap properties;
442 properties[
"status"] = Kopete::OnlineStatus::statusTypeToString(
444 properties[
"message_reachable"] = contact->isReachable();
445 properties[
"file_reachable"] = contact->canAcceptFiles();
446 properties[
"display_name"] = contact->displayName();
447 properties[
"id"] = contact->metaContactId().toString();
448 if (contact->photoSource() == Kopete::MetaContact::SourceCustom)
450 properties[
"picture"] = contact->customPhoto().prettyUrl();
454 properties[
"picture"] = contact->picture().path();
456 properties[
"idle_time"] = qulonglong(contact->idleTime());
457 if (contact->preferredContact())
460 properties[
"status_message"]
461 = contact->preferredContact()->statusMessage().message();
464 QStringList messages;
465 foreach(Kopete::Contact *subContact, contact->contacts())
467 QList<Kopete::MessageEvent*> pendingMessages = KopeteViewManager::viewManager()->pendingMessages(subContact);
468 foreach(Kopete::MessageEvent *event, pendingMessages)
470 messages <<
event->message().parsedBody();
473 properties[
"pending_messages"] = messages;
479 #include "kopetedbusinterface.moc"
void disconnect(const QString &protocolName, const QString &accountId)
Disconnect a given account in the given protocol.
QStringList listContact(const QList< Kopete::MetaContact * > &contactList)
void openChat(const QString &contactId)
Open a chat window for the given contact.
bool isConnected(const QString &protocolName, const QString &accountId)
Get information if we are connected to a given account in the given protocol.
bool addContact(const QString &protocolName, const QString &accountId, const QString &contactId, const QString &displayName, const QString &groupName=QString())
Adds a contact with the specified params.
void resume()
Sets the online status of all accounts to the status they had when suspend was called.
void setIdentityNickName(const QString &nickName, const QString &identityId=QString())
Set the nickname for the given identity.
void connectAll()
Connect all accounts.
QStringList contactsByFilter(const QString &filter) const
Get a filered list of contacts based on the filter.
void suspend()
Saves the online status of all accounts and disconnects them.
QStringList identities() const
Get a list of all identities' ID.
void setIdentityOnlineStatus(const QString &status, const QString &message, const QString &identityId=QString())
Set the online status for the given identity.
QStringList contacts() const
Return all contacts.
void setIdentityAvatar(const QString &avatarUrl, const QString &identityId=QString())
Set the avatar for the given identity.
QString labelForIdentity(const QString &id) const
Get UI labels for identities.
Kopete::MetaContact * findContact(const QString &nameOrId)
Tries to locate a meta contact using first the protocol:account:contact triplet, if that fails the me...
void setOnlineStatus(const QString &status, const QString &message=QString())
Change the online status for all accounts.
void setStatusMessage(const QString &message)
Change the status message for all accounts.
KopeteDBusInterface(QObject *parent)
Constructor.
QVariantMap contactProperties(const QString &contactId)
Look up details for a specific contact.
QStringList accounts() const
Get a list of all account's ID.
void connect(const QString &protocolName, const QString &accountId)
Connect a given account in the given protocol.
QStringList protocols() const
Get a list of all protocol names.
void sendFile(const QString &contactId, const QString &fileUrl)
Send a file to the given contact.
void disconnectAll()
Disconnect all accounts.
QString getDisplayName(const QString &contactId)
Retrieve the Display Name from the given contact ID.
bool isContactOnline(const QString &contactId)
Get the Online Status of the contact.
Kopete::OnlineStatusManager::Categories status2Value(const QString &status)
Tracks changes of all metacontacts and reports them via signals.
~KopeteDBusInterface()
Destructor.
void sendMessage(const QString &contactId, const QString &message)
Send a message to the given contact.
void contactChanged(QString contactId)
Contact properties have changed: displayName, avatar, pending messages...