1
/* This file is part of the KDE project
2
Copyright (C) 2005 Michal Vaner <michal.vaner@kdemail.net>
3
Copyright (C) 2008-2009 Pali RohƔr <pali.rohar@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#include "skypeprotocol.h"
21
#include "skypeeditaccount.h"
22
#include "skypeaccount.h"
23
#include "skypeaddcontact.h"
24
#include "skypecontact.h"
26
#include <kopeteonlinestatusmanager.h>
27
#include <kgenericfactory.h>
29
#include <qstringlist.h>
32
#include <kactioncollection.h>
33
#include <kshortcut.h>
34
#include <kopetecontactlist.h>
35
#include <kopetemetacontact.h>
37
K_PLUGIN_FACTORY( SkypeProtocolFactory, registerPlugin<SkypeProtocol>(); )
38
K_EXPORT_PLUGIN( SkypeProtocolFactory( "kopete_skype" ) )
40
SkypeProtocol *SkypeProtocol::s_protocol = 0L;
42
SkypeProtocolHandler::SkypeProtocolHandler() : Kopete::MimeTypeHandler(false) {
43
registerAsMimeHandler("x-skype"); //This is still not enought for javascript web buttons checker, we still need skypebuttons netscape plugin
44
registerAsProtocolHandler("callto");
45
registerAsProtocolHandler("skype");
46
registerAsProtocolHandler("tell");
49
void SkypeProtocolHandler::handleURL(const QString &, const KUrl &url) const {
50
kDebug(SKYPE_DEBUG_GLOBAL);
51
if ( ! SkypeProtocol::protocol()->hasAccount() ) {
52
kDebug(SKYPE_DEBUG_GLOBAL) << "No Skype account registred";
55
SkypeProtocol::protocol()->account()->SkypeActionHandler(url.url());
58
class SkypeProtocolPrivate {
61
///The "call contact" action
62
KAction *callContactAction;
63
///Pointer to the account
64
SkypeAccount *account;
66
SkypeProtocolPrivate() {
67
account = 0L;//no account yet
68
callContactAction = 0L;
71
SkypeProtocolHandler *handler;
74
SkypeProtocol::SkypeProtocol(QObject *parent, const QList<QVariant>&) :
75
Kopete::Protocol(SkypeProtocolFactory::componentData(), parent),//create the parent
76
Offline(Kopete::OnlineStatus::Offline, 0, this, 1, QStringList("skype_contact_offline"), i18n("Offline"), i18n("Offline"), Kopete::OnlineStatusManager::Offline),//and online statuses
77
Online(Kopete::OnlineStatus::Online, 1, this, 2, QStringList("skype_contact_online"), i18n("Online"), i18n("Online"), Kopete::OnlineStatusManager::Online),
78
SkypeMe(Kopete::OnlineStatus::Online, 0, this, 3, QStringList("skype_contact_skypeme"), i18n("Skype Me"), i18n("Skype Me"), Kopete::OnlineStatusManager::FreeForChat),
79
Away(Kopete::OnlineStatus::Away, 2, this, 4, QStringList("skype_contact_away"), i18n("Away"), i18n("Away"), Kopete::OnlineStatusManager::Away),
80
NotAvailable(Kopete::OnlineStatus::Away, 1, this, 5, QStringList("skype_contact_not_available"), i18n("Not Available"), i18n("Not Available"), Kopete::OnlineStatusManager::Away),
81
DoNotDisturb(Kopete::OnlineStatus::Busy, 0, this, 6, QStringList("skype_contact_dnd"), i18n("Do Not Disturb"), i18n("Do Not Disturb"), Kopete::OnlineStatusManager::Busy),
82
Invisible(Kopete::OnlineStatus::Invisible, 0, this, 7, QStringList("skype_contact_invisible"), i18n("Invisible"), i18n("Invisible"), Kopete::OnlineStatusManager::Invisible),
83
Connecting(Kopete::OnlineStatus::Connecting, 0, this, 8, QStringList("skype_connecting"), i18n("Connecting")),
84
NotInList(Kopete::OnlineStatus::Unknown, 0, this, 9, QStringList("skype_contact_unknown"), i18n("Not in Skype list")),
85
NoAuth(Kopete::OnlineStatus::Unknown, 0, this, 10, QStringList("skype_contact_unknown"), i18n("Not authorized")),
86
Phone(Kopete::OnlineStatus::Unknown, 3, this, 11, QStringList("skype_contact_skypeout"), i18n("SkypeOut contact")), //Skype Out contact permanently offline TODO: add option for changing
87
/** Contact property templates */
88
propFullName(Kopete::Global::Properties::self()->fullName()),
89
propPrivatePhone(Kopete::Global::Properties::self()->privatePhone()),
90
propPrivateMobilePhone(Kopete::Global::Properties::self()->privateMobilePhone()),
91
propWorkPhone(Kopete::Global::Properties::self()->workPhone()),
92
propLastSeen(Kopete::Global::Properties::self()->lastSeen())
95
kDebug(SKYPE_DEBUG_GLOBAL);
96
//create the d pointer
97
d = new SkypeProtocolPrivate();
98
//add address book field
99
addAddressBookField("messaging/skype", Kopete::Plugin::MakeIndexField);
101
setXMLFile("skypeui.rc");
103
d->callContactAction = new KAction( this );
104
d->callContactAction->setIcon( (KIcon("skype_call") ) );
105
d->callContactAction->setText( i18n ("Call") );
106
connect(d->callContactAction, SIGNAL(triggered(bool)), SLOT(callContacts()));
108
actionCollection()->addAction("callSkypeContact", d->callContactAction);
110
d->handler = new SkypeProtocolHandler;
112
updateCallActionStatus();
113
connect(Kopete::ContactList::self(), SIGNAL(metaContactSelected(bool)), this, SLOT(updateCallActionStatus()));
118
SkypeProtocol::~SkypeProtocol() {
119
kDebug(SKYPE_DEBUG_GLOBAL);
126
Kopete::Account *SkypeProtocol::createNewAccount(const QString & accountID) {
127
kDebug(SKYPE_DEBUG_GLOBAL);
129
return new SkypeAccount(this, accountID);
132
AddContactPage *SkypeProtocol::createAddContactWidget(QWidget *parent, Kopete::Account *account) {
133
kDebug(SKYPE_DEBUG_GLOBAL);
134
return new SkypeAddContact(this, parent, (SkypeAccount *)account, 0L);
137
KopeteEditAccountWidget *SkypeProtocol::createEditAccountWidget(Kopete::Account *account, QWidget *parent) {
138
kDebug(SKYPE_DEBUG_GLOBAL);
139
return new skypeEditAccount(this, account, parent);//create the widget and return it
142
void SkypeProtocol::registerAccount(SkypeAccount *account) {
143
kDebug(SKYPE_DEBUG_GLOBAL);
145
d->account = account;
148
void SkypeProtocol::unregisterAccount() {
149
kDebug(SKYPE_DEBUG_GLOBAL);
152
d->account = 0L;//forget everything about the account
155
bool SkypeProtocol::hasAccount() const {
156
kDebug(SKYPE_DEBUG_GLOBAL);
161
SkypeAccount * SkypeProtocol::account() {
162
kDebug(SKYPE_DEBUG_GLOBAL);
166
Kopete::Contact *SkypeProtocol::deserializeContact(Kopete::MetaContact *metaContact, const QMap<QString, QString> &serializedData, const QMap<QString, QString> &) {
167
kDebug(SKYPE_DEBUG_GLOBAL) << "Name: " << serializedData["contactId"].toLower();
169
QString contactID = serializedData["contactId"].toLower();//get the contact ID
170
QString accountId = serializedData["accountId"];
173
kDebug(SKYPE_DEBUG_GLOBAL) << "Account does not exists, skiping contact creation";//write error for debugging
174
return 0L;//create nothing
177
if (d->account->contact(contactID)) {
178
kDebug(SKYPE_DEBUG_GLOBAL) << "Contact" << contactID << "exists in contact list, skipping contact creation";
182
return new SkypeContact(d->account, contactID, metaContact);//create the contact
185
void SkypeProtocol::updateCallActionStatus() {
186
kDebug(SKYPE_DEBUG_GLOBAL);
190
if ((Kopete::ContactList::self()->selectedMetaContacts().count() != 1) && ((!d->account) || (!d->account->ableMultiCall()))) {
191
d->callContactAction->setEnabled(false);
195
//Run trough all selected contacts and find if there is any skype contact
196
const QList<Kopete::MetaContact*> &selected = Kopete::ContactList::self()->selectedMetaContacts();
197
for (QList<Kopete::MetaContact*>::const_iterator met = selected.begin(); met != selected.end(); ++met) {
198
const QList<Kopete::Contact*> &metaCont = (*met)->contacts();
199
for (QList<Kopete::Contact*>::const_iterator con = metaCont.begin(); con != metaCont.end(); ++con) {
200
if ((*con)->protocol() == this) {//This is skype contact, ask it if it can be called
201
SkypeContact *thisCont = static_cast<SkypeContact *> (*con);
202
if (thisCont->canCall()) {
210
d->callContactAction->setEnabled(enab);
213
void SkypeProtocol::callContacts() {
214
kDebug(SKYPE_DEBUG_GLOBAL);
218
const QList<Kopete::MetaContact*> &selected = Kopete::ContactList::self()->selectedMetaContacts();
219
for (QList<Kopete::MetaContact*>::const_iterator met = selected.begin(); met != selected.end(); ++met) {
220
const QList<Kopete::Contact*> &metaCont = (*met)->contacts();
221
for (QList<Kopete::Contact*>::const_iterator con = metaCont.begin(); con != metaCont.end(); ++con) {
222
if ((*con)->protocol() == this) {//This is skype contact, ask it if it can be called
223
SkypeContact *thisCont = static_cast<SkypeContact *> (*con);
224
if (thisCont->canCall()) {
227
list += thisCont->contactId();
233
if (!list.isEmpty()) {
234
d->account->makeCall(list);
238
SkypeProtocol *SkypeProtocol::protocol()
243
#include "skypeprotocol.moc"