~ubuntu-branches/ubuntu/saucy/kopete/saucy-updates

« back to all changes in this revision

Viewing changes to .pc/kubuntu_no_break_api.diff/protocols/skype/skypeprotocol.cpp

  • Committer: Package Import Robot
  • Author(s): Howard Chan, Michał Zając, Howard Chan
  • Date: 2013-06-28 18:19:57 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130628181957-oe71prbd9qv1ygop
Tags: 4:4.10.90-0ubuntu1
[ Michał Zając ]
* New upstream beta release

[ Howard Chan ]
* Delete the API patch since it's included in upstream now.
* Fix control file to make -dbg depend on main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
4
 
 
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.
8
 
 
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.
13
 
 
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.
18
 
 
19
 
*/
20
 
#include "skypeprotocol.h"
21
 
#include "skypeeditaccount.h"
22
 
#include "skypeaccount.h"
23
 
#include "skypeaddcontact.h"
24
 
#include "skypecontact.h"
25
 
 
26
 
#include <kopeteonlinestatusmanager.h>
27
 
#include <kgenericfactory.h>
28
 
#include <qstring.h>
29
 
#include <qstringlist.h>
30
 
#include <kdebug.h>
31
 
#include <kaction.h>
32
 
#include <kactioncollection.h>
33
 
#include <kshortcut.h>
34
 
#include <kopetecontactlist.h>
35
 
#include <kopetemetacontact.h>
36
 
 
37
 
K_PLUGIN_FACTORY( SkypeProtocolFactory, registerPlugin<SkypeProtocol>(); )
38
 
K_EXPORT_PLUGIN( SkypeProtocolFactory( "kopete_skype" ) )
39
 
 
40
 
SkypeProtocol *SkypeProtocol::s_protocol = 0L;
41
 
 
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");
47
 
}
48
 
 
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";
53
 
                return;
54
 
        }
55
 
        SkypeProtocol::protocol()->account()->SkypeActionHandler(url.url());
56
 
}
57
 
 
58
 
class SkypeProtocolPrivate {
59
 
        private:
60
 
        public:
61
 
                ///The "call contact" action
62
 
                KAction *callContactAction;
63
 
                ///Pointer to the account
64
 
                SkypeAccount *account;
65
 
                ///Constructor
66
 
                SkypeProtocolPrivate() {
67
 
                        account = 0L;//no account yet
68
 
                        callContactAction = 0L;
69
 
                }
70
 
                ///Url handler
71
 
                SkypeProtocolHandler *handler;
72
 
};
73
 
 
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())
93
 
 
94
 
{
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);
100
 
 
101
 
        setXMLFile("skypeui.rc");
102
 
 
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()));
107
 
 
108
 
        actionCollection()->addAction("callSkypeContact", d->callContactAction);
109
 
 
110
 
        d->handler = new SkypeProtocolHandler;
111
 
 
112
 
        updateCallActionStatus();
113
 
        connect(Kopete::ContactList::self(), SIGNAL(metaContactSelected(bool)), this, SLOT(updateCallActionStatus()));
114
 
 
115
 
        s_protocol = this;
116
 
}
117
 
 
118
 
SkypeProtocol::~SkypeProtocol() {
119
 
        kDebug(SKYPE_DEBUG_GLOBAL);
120
 
        //release the memory
121
 
        delete d->handler;
122
 
        delete d;
123
 
        d = 0L;
124
 
}
125
 
 
126
 
Kopete::Account *SkypeProtocol::createNewAccount(const QString & accountID) {
127
 
        kDebug(SKYPE_DEBUG_GLOBAL);
128
 
        //just create one
129
 
        return new SkypeAccount(this, accountID);
130
 
}
131
 
 
132
 
AddContactPage *SkypeProtocol::createAddContactWidget(QWidget *parent, Kopete::Account *account) {
133
 
        kDebug(SKYPE_DEBUG_GLOBAL);
134
 
        return new SkypeAddContact(this, parent, (SkypeAccount *)account, 0L);
135
 
}
136
 
 
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
140
 
}
141
 
 
142
 
void SkypeProtocol::registerAccount(SkypeAccount *account) {
143
 
        kDebug(SKYPE_DEBUG_GLOBAL);
144
 
 
145
 
        d->account = account;
146
 
}
147
 
 
148
 
void SkypeProtocol::unregisterAccount() {
149
 
        kDebug(SKYPE_DEBUG_GLOBAL);
150
 
 
151
 
        if (d)
152
 
                d->account = 0L;//forget everything about the account
153
 
}
154
 
 
155
 
bool SkypeProtocol::hasAccount() const {
156
 
        kDebug(SKYPE_DEBUG_GLOBAL);
157
 
 
158
 
        return (d->account);
159
 
}
160
 
 
161
 
SkypeAccount * SkypeProtocol::account() {
162
 
        kDebug(SKYPE_DEBUG_GLOBAL);
163
 
        return d->account;
164
 
}
165
 
 
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();
168
 
 
169
 
        QString contactID = serializedData["contactId"].toLower();//get the contact ID
170
 
        QString accountId = serializedData["accountId"];
171
 
 
172
 
        if (!d->account) {
173
 
                kDebug(SKYPE_DEBUG_GLOBAL) << "Account does not exists, skiping contact creation";//write error for debugging
174
 
                return 0L;//create nothing
175
 
        }
176
 
 
177
 
        if (d->account->contact(contactID)) {
178
 
                kDebug(SKYPE_DEBUG_GLOBAL) << "Contact" << contactID << "exists in contact list, skipping contact creation";
179
 
                return 0L;
180
 
        }
181
 
 
182
 
        return new SkypeContact(d->account, contactID, metaContact);//create the contact
183
 
}
184
 
 
185
 
void SkypeProtocol::updateCallActionStatus() {
186
 
        kDebug(SKYPE_DEBUG_GLOBAL);
187
 
 
188
 
        bool enab = false;
189
 
 
190
 
        if ((Kopete::ContactList::self()->selectedMetaContacts().count() != 1) && ((!d->account) || (!d->account->ableMultiCall()))) {
191
 
                d->callContactAction->setEnabled(false);
192
 
                return;
193
 
        }
194
 
 
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()) {
203
 
                                        enab = true;
204
 
                                        goto OUTSIDE;
205
 
                                }
206
 
                        }
207
 
                }
208
 
        }
209
 
        OUTSIDE:
210
 
        d->callContactAction->setEnabled(enab);
211
 
}
212
 
 
213
 
void SkypeProtocol::callContacts() {
214
 
        kDebug(SKYPE_DEBUG_GLOBAL);
215
 
 
216
 
        QString list;
217
 
 
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()) {
225
 
                                        if (!list.isEmpty())
226
 
                                                list += ", ";
227
 
                                        list += thisCont->contactId();
228
 
                                }
229
 
                        }
230
 
                }
231
 
        }
232
 
 
233
 
        if (!list.isEmpty()) {
234
 
                d->account->makeCall(list);
235
 
        }
236
 
}
237
 
 
238
 
SkypeProtocol *SkypeProtocol::protocol()
239
 
{
240
 
        return s_protocol;
241
 
}
242
 
 
243
 
#include "skypeprotocol.moc"