Commit 9a6155f8 authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Create a KNetAttach place for ownCloud and save the user/pass into wallet

parent f6a00e73
......@@ -31,6 +31,7 @@ set(webaccounts_SRCS
owncloud/basicinfo.cpp
owncloud/connecting.cpp
owncloud/oservices.cpp
jobs/ocreatefile.cpp
)
qt4_add_dbus_interface(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 "ocreatefile.h"
#include <QWidget>
#include <QApplication>
#include <KGlobal>
#include <KConfig>
#include <KDirNotify>
#include <KStandardDirs>
#include <KWallet/Wallet>
#include <QDebug>
using namespace KWallet;
OCreateFile::OCreateFile(KConfigGroup group, QObject* parent)
: KJob(parent)
, m_config(group)
{
}
OCreateFile::~OCreateFile()
{
}
void OCreateFile::start()
{
QMetaObject::invokeMethod(this, "createNetAttach", Qt::QueuedConnection);
}
void OCreateFile::createNetAttach()
{
KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview");
KUrl url(m_config.readEntry("server", ""));
url.setUser(m_config.name());
url.setScheme("webdav");
url.addPath("files/webdav.php/");
QString path = KGlobal::dirs()->saveLocation("remote_entries");
path += m_config.name() + "ownCloud.desktop";
qDebug() << "Creating knetAttach place";
qDebug() << path;
qDebug() << url.prettyUrl();
KConfig _desktopFile( path, KConfig::SimpleConfig );
KConfigGroup desktopFile(&_desktopFile, "Desktop Entry");
desktopFile.writeEntry("Icon", "owncloud");
desktopFile.writeEntry("Name", url.host());
desktopFile.writeEntry("Type", "Link");
desktopFile.writeEntry("URL", url.prettyUrl());
desktopFile.writeEntry("Charset", url.fileEncoding());
desktopFile.sync();
org::kde::KDirNotify::emitFilesAdded( "remote:/" );
QString walletUrl(url.scheme());
walletUrl.append("-");
walletUrl.append(m_config.name());
walletUrl.append("@");
walletUrl.append(url.host());
walletUrl.append(":-1");//Overwrite the first option
WId windowId = 0;
if (qApp->activeWindow()) {
windowId = qApp->activeWindow()->winId();
}
Wallet *wallet = Wallet::openWallet(Wallet::NetworkWallet(), windowId, Wallet::Synchronous);
if (!wallet->isOpen() || !wallet->isEnabled()) {
return;
}
QMap<QString, QString> info;
info["login"] = m_config.name();
info["password"] = "12344321";
wallet->setFolder("Passwords");
wallet->writeMap(walletUrl, info);
wallet->sync();
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 OCREATEFILE_H
#define OCREATEFILE_H
#include <KJob>
#include <KConfigGroup>
class OCreateFile : public KJob
{
Q_OBJECT
public:
explicit OCreateFile(KConfigGroup group, QObject* parent = 0);
virtual ~OCreateFile();
virtual void start();
private Q_SLOTS:
void createNetAttach();
private:
KConfigGroup m_config;
};
#endif //OCREATEFILE_H
\ No newline at end of file
......@@ -34,6 +34,8 @@
#include "jobs/fcreatechat.h"
#include "jobs/fcreatepim.h"
#include "jobs/ocreatefile.h"
#include <QDebug>
#include <QtGui/QLabel>
......@@ -43,7 +45,7 @@
#include <QtGui/QStackedLayout>
#include <kpluginfactory.h>
#include <boost/graph/graph_concepts.hpp>
#include <kstandarddirs.h>
K_PLUGIN_FACTORY(WebAccountsFactory, registerPlugin<WebAccounts>();)
K_EXPORT_PLUGIN(WebAccountsFactory("webaccounts", "webaccounts"))
......@@ -200,6 +202,8 @@ void WebAccounts::newAccount(const QString& type, const QString& name)
createGoogleAccount(group);
} else if(type == "facebook") {
createFacebookAccount(group);
} else if (type == "owncloud") {
createOwncloudAccount(group);
}
}
......@@ -346,4 +350,13 @@ void WebAccounts::removeFacebookACcount(KConfigGroup group)
}
}
void WebAccounts::createOwncloudAccount(KConfigGroup group)
{
KConfigGroup services = group.group("services");
if (services.readEntry("File", 0) == 2) {
OCreateFile *create = new OCreateFile(group, this);
create->start();
}
}
#include "webaccounts.moc"
......@@ -60,6 +60,8 @@ private:
void createFacebookAccount(KConfigGroup group);
void removeFacebookACcount(KConfigGroup group);
void createOwncloudAccount(KConfigGroup group);
private:
Create *m_create;
QStackedLayout *m_layout;
......
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