Commit 7c15dd23 authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Add/Remove akonadi account should be finished now

parent 301ec497
......@@ -24,7 +24,7 @@ include(KDE4Defaults)
include(MacroOptionalAddSubdirectory)
MESSAGE(WARNING ${LIBKFACEBOOK_INCLUDE_DIR})
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES} ${LIBKGOOGLE_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ${TELEPATHY_QT4_INCLUDE_DIR} ${KTP_INCLUDE_DIR})
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ${KDE4_INCLUDES} ${LIBKGOOGLE_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ${TELEPATHY_QT4_INCLUDE_DIR} ${KTP_INCLUDE_DIR})
add_subdirectory(src)
add_subdirectory(icons)
\ No newline at end of file
......@@ -25,6 +25,7 @@ set(webaccounts_SRCS
facebook/foauth.cpp
facebook/fservices.cpp
jobs/fcreatechat.cpp
jobs/fcreatepim.cpp
)
qt4_add_dbus_interface(webaccounts_SRCS
......@@ -39,6 +40,10 @@ qt4_add_dbus_interface(webaccounts_SRCS
jobs/org.kde.Akonadi.GoogleContacts.Settings.xml
google_contact_settings
)
qt4_add_dbus_interface(webaccounts_SRCS
jobs/org.kde.Akonadi.Facebook.Settings.xml
facebook_settings
)
qt4_automoc(${webaccounts_SRCS})
......
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "fcreatepim.h"
#include "facebook_settings.h"
#include <akonadi/agenttype.h>
#include <akonadi/agentmanager.h>
#include <akonadi/agentinstancecreatejob.h>
#include <KWallet/Wallet>
using namespace KWallet;
using namespace Akonadi;
FCreatePIM::FCreatePIM(KConfigGroup group, QObject* parent)
: KJob(parent)
, m_config(group)
{
}
FCreatePIM::~FCreatePIM()
{
}
void FCreatePIM::start()
{
QMetaObject::invokeMethod(this, "createResource", Qt::QueuedConnection);
}
void FCreatePIM::createResource()
{
const AgentType type = AgentManager::self()->type( "akonadi_facebook_resource");
AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type, this );
connect( job, SIGNAL(result(KJob*)), SLOT(instanceCreateResult(KJob*)) );
job->start();
}
void FCreatePIM::instanceCreateResult(KJob* job)
{
QByteArray accessToken;
Wallet *wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Synchronous);
wallet->setFolder("WebAccounts");
if (wallet->readEntry("facebookAccessToken", accessToken) != 0) {
qWarning("Can't open wallet");
setError(-1);
m_config.group("services").writeEntry("PIM", -1);
emitResult();
return;
}
AgentInstance agent = qobject_cast<AgentInstanceCreateJob*>( job )->instance();
agent.setName(m_config.name() + " Facebook");
QString service = "org.freedesktop.Akonadi.Resource." + agent.identifier();
KConfigGroup privates(&m_config, "private");
privates.writeEntry("facebookResource", service);
org::kde::Akonadi::Facebook::Settings *settings = new org::kde::Akonadi::Facebook::Settings(service, "/Settings", QDBusConnection::sessionBus());
settings->setAccessToken(accessToken);
settings->setUserName(m_config.name());
settings->writeConfig();
agent.synchronize();
m_config.group("services").writeEntry("PIM", 1);
emitResult();
}
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#ifndef F_CREATEPIM_U
#define F_CREATEPIM_U
#include <KJob>
#include <KConfigGroup>
class FCreatePIM : public KJob
{
Q_OBJECT
public:
explicit FCreatePIM(KConfigGroup group, QObject* parent = 0);
virtual ~FCreatePIM();
virtual void start();
private Q_SLOTS:
void createResource();
void instanceCreateResult(KJob* job);
private:
KConfigGroup m_config;
};
#endif //F_CREATEPIM_U
\ No newline at end of file
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#ifndef F_REMOVE_CHAT_H
#define F_REMOVE_CHAT_H
#include <TelepathyQt/AccountManager>
#include <KDE/KJob>
#include <kconfiggroup.h>
namespace Tp {
class PendingOperation;
}
class FRemoveChat : public KJob
{
Q_OBJECT
public:
explicit FRemoveChat(KConfigGroup group, QObject* parent);
virtual ~FRemoveChat();
virtual void start();
private Q_SLOTS:
void removeResource();
void onAccountManagerReady(Tp::PendingOperation *op);
private:
KConfigGroup m_config;
Tp::AccountManagerPtr m_manager;
};
#endif //F_REMOVE_CHAT_H
\ No newline at end of file
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.Akonadi.Facebook.Settings">
<method name="writeConfig"/>
<method name="accessToken">
<arg direction="out" type="s"/>
</method>
<method name="setAccessToken">
<arg direction="in" identifier="value" type="s"/>
</method>
<method name="userName">
<arg direction="out" type="s"/>
</method>
<method name="setUserName">
<arg direction="in" identifier="value" type="s"/>
</method>
<method name="lowerLimit">
<arg direction="out" type="s"/>
</method>
<method name="setLowerLimit">
<arg direction="in" identifier="value" type="s"/>
</method>
</interface>
</node>
\ No newline at end of file
......@@ -32,6 +32,7 @@
#include "jobs/removeakonadiresource.h"
#include "jobs/fcreatechat.h"
#include "jobs/fcreatepim.h"
#include <QDebug>
......@@ -131,7 +132,7 @@ void WebAccounts::rmBtnClicked()
if (type == "google") {
removeGoogleAccount(group);
} else if(type == "facebook") {
removeFacebookACcount(group);
}
removeAccountIfPossible(accName, type);
......@@ -322,11 +323,27 @@ void WebAccounts::createFacebookAccount(KConfigGroup group)
FCreateChat *create = new FCreateChat(group, this);
create->start();
}
if (services.readEntry("PIM", 0) == 2) {
FCreatePIM *create = new FCreatePIM(group, this);
create->start();
}
}
void WebAccounts::removeFacebookACcount(KConfigGroup group)
{
KConfigGroup services = group.group("services");
if (services.readEntry("Chat", 0) == 1) {
RemoveChat *removeChat = new RemoveChat(group, this);
connect(removeChat, SIGNAL(finished(KJob*)), this, SLOT(serviceRemoved(KJob*)));
removeChat->start();
}
if (services.readEntry("PIM", 0) == 1) {
RemoveAkonadiResource *removeContact = new RemoveAkonadiResource("facebookResource", group, this);
connect(removeContact, SIGNAL(finished(KJob*)), this, SLOT(serviceRemoved(KJob*)));
removeContact->start();
}
}
#include "webaccounts.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment