1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[PasswordManager] Added KWallet backend plugin.

When building with KDE integration (KDE build flag), this plugin
will now be built.

Closes #592
This commit is contained in:
nowrep 2013-05-15 21:30:20 +02:00
parent f8ee9a4b9c
commit 95a44ded44
10 changed files with 376 additions and 3 deletions

View File

@ -133,9 +133,9 @@ Available Defines
example: example:
$ export NO_X11="true" $ export NO_X11="true"
KDE For now, it just use better oxygen icons in Preferences. KDE Enable KDE integration.
Nepomuk integration is planned, and it will be enabled with Currently it enables building of KWallet Password plugin,
this define also. which provides support for storing passwords in KWallet.
example: example:
$ export KDE="true" $ export KDE="true"

View File

@ -6,6 +6,7 @@ Version 1.5.0
* added delete action in edit context menu on page * added delete action in edit context menu on page
* added possibility to remove EasyList from AdBlock * added possibility to remove EasyList from AdBlock
* added inline domain completion to urlbar * added inline domain completion to urlbar
* added KWallet password backend plugin
* proxy exceptions now supports wildcards (*, ?) * proxy exceptions now supports wildcards (*, ?)
* cancel upload when trying to upload non-readable files * cancel upload when trying to upload non-readable files
* GreaseMonkey: added support for GM_Settings * GreaseMonkey: added support for GM_Settings

View File

@ -130,6 +130,10 @@ void PasswordManager::unregisterBackend(PasswordBackend* backend)
{ {
const QString &key = m_backends.key(backend); const QString &key = m_backends.key(backend);
m_backends.remove(key); m_backends.remove(key);
if (m_backend == backend) {
m_backend = m_databaseBackend;
}
} }
QString PasswordManager::createHost(const QUrl &url) QString PasswordManager::createHost(const QUrl &url)

View File

@ -0,0 +1,17 @@
include(../../defines.pri)
contains(DEFINES, "KDE") {
TARGET = $$qtLibraryTarget(KWalletPasswords)
SOURCES += kwalletplugin.cpp \
kwalletpasswordbackend.cpp
HEADERS += kwalletplugin.h \
kwalletpasswordbackend.h
RESOURCES += kwalletpasswords.qrc
LIBS += -lkdeui
}
include(../../plugins.pri)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,183 @@
/* ============================================================
* KWalletPasswords - KWallet support plugin for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "kwalletpasswordbackend.h"
#include <QDateTime>
#include <QDebug>
static PasswordEntry decodeEntry(const QByteArray &data)
{
QDataStream stream(data);
PasswordEntry entry;
stream >> entry;
return entry;
}
static QByteArray encodeEntry(const PasswordEntry &entry)
{
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
stream << entry;
return data;
}
KWalletPasswordBackend::KWalletPasswordBackend()
: PasswordBackend()
, m_wallet(0)
{
}
static bool compareEntries(const PasswordEntry &e1, const PasswordEntry &e2)
{
return e1.id.toString() > e2.id.toString();
}
QVector<PasswordEntry> KWalletPasswordBackend::getEntries(const QUrl &url)
{
initialize();
const QString &host = PasswordManager::createHost(url);
QVector<PasswordEntry> list;
foreach (const PasswordEntry &entry, m_allEntries) {
if (entry.host == host) {
list.append(entry);
}
}
// Sort to prefer last updated entries
qSort(list.begin(), list.end(), compareEntries);
return list;
}
QVector<PasswordEntry> KWalletPasswordBackend::getAllEntries()
{
initialize();
return m_allEntries;
}
void KWalletPasswordBackend::addEntry(const PasswordEntry &entry)
{
initialize();
QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t()));
PasswordEntry stored = entry;
stored.id = id;
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
m_allEntries.append(stored);
}
void KWalletPasswordBackend::updateEntry(const PasswordEntry &entry)
{
initialize();
m_wallet->removeEntry(entry.id.toString());
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
int index = m_allEntries.indexOf(entry);
if (index > -1) {
m_allEntries[index] = entry;
}
}
void KWalletPasswordBackend::updateLastUsed(const PasswordEntry &entry)
{
initialize();
QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t()));
PasswordEntry stored = entry;
stored.id = id;
m_wallet->removeEntry(entry.id.toString());
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
int index = m_allEntries.indexOf(entry);
if (index > -1) {
m_allEntries[index] = stored;
}
}
void KWalletPasswordBackend::removeEntry(const PasswordEntry &entry)
{
initialize();
m_wallet->removeEntry(entry.id.toString());
int index = m_allEntries.indexOf(entry);
if (index > -1) {
m_allEntries.remove(index);
}
}
void KWalletPasswordBackend::removeAll()
{
initialize();
m_wallet->removeFolder("QupZilla");
m_wallet->createFolder("QupZilla");
}
void KWalletPasswordBackend::initialize()
{
if (m_wallet) {
return;
}
m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0);
if (!m_wallet) {
qWarning() << "KWalletPasswordBackend::initialize Cannot open wallet!";
return;
}
if (!m_wallet->hasFolder("QupZilla") && !m_wallet->createFolder("QupZilla")) {
qWarning() << "KWalletPasswordBackend::initialize Cannot create folder \"QupZilla\"!";
return;
}
if (!m_wallet->setFolder("QupZilla")) {
qWarning() << "KWalletPasswordBackend::initialize Cannot set folder \"QupZilla\"!";
return;
}
QMap<QString, QByteArray> entries;
if (m_wallet->readEntryList("*", entries) != 0) {
qWarning() << "KWalletPasswordBackend::initialize Cannot read entries!";
return;
}
QMap<QString, QByteArray>::const_iterator i = entries.constBegin();
while (i != entries.constEnd()) {
m_allEntries.append(decodeEntry(i.value()));
++i;
}
}
KWalletPasswordBackend::~KWalletPasswordBackend()
{
delete m_wallet;
}

View File

@ -0,0 +1,50 @@
/* ============================================================
* KWalletPasswords - KWallet support plugin for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef KWALLETPASSWORDBACKEND_H
#define KWALLETPASSWORDBACKEND_H
#include <QVector>
#include <KDE/KWallet/Wallet>
#include "passwordbackends/passwordbackend.h"
#include "passwordmanager.h"
class KWalletPasswordBackend : public PasswordBackend
{
public:
explicit KWalletPasswordBackend();
~KWalletPasswordBackend();
QVector<PasswordEntry> getEntries(const QUrl &url);
QVector<PasswordEntry> getAllEntries();
void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry);
void removeAll();
private:
void initialize();
KWallet::Wallet* m_wallet;
QVector<PasswordEntry> m_allEntries;
};
#endif // KWALLETPASSWORDBACKEND_H

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/kwp">
<file>data/icon.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,66 @@
/* ============================================================
* KWalletPasswords - KWallet support plugin for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "kwalletplugin.h"
#include "kwalletpasswordbackend.h"
#include "pluginproxy.h"
#include "qupzilla.h"
#include <QTranslator>
KWalletPlugin::KWalletPlugin()
: QObject()
, m_backend(0)
{
}
PluginSpec KWalletPlugin::pluginSpec()
{
PluginSpec spec;
spec.name = "KWallet Passwords";
spec.info = "KWallet password backend";
spec.description = "Provides support for storing passwords in KWallet";
spec.version = "0.1.0";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":kwp/data/icon.png");
spec.hasSettings = false;
return spec;
}
void KWalletPlugin::init(const QString &sPath)
{
Q_UNUSED(sPath);
m_backend = new KWalletPasswordBackend;
QZ_REGISTER_PASSWORD_BACKEND("KWallet", m_backend);
}
void KWalletPlugin::unload()
{
QZ_UNREGISTER_PASSWORD_BACKEND(m_backend);
delete m_backend;
}
bool KWalletPlugin::testPlugin()
{
return (QupZilla::VERSION == QLatin1String("1.5.0"));
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(KWalletPasswords, KWalletPlugin)
#endif

View File

@ -0,0 +1,47 @@
/* ============================================================
* KWalletPasswords - KWallet support plugin for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef KWALLETPLUGIN_H
#define KWALLETPLUGIN_H
#include "plugininterface.h"
class KWalletPasswordBackend;
class KWalletPlugin : public QObject, public PluginInterface
{
Q_OBJECT
Q_INTERFACES(PluginInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.KWalletPasswords")
#endif
public:
explicit KWalletPlugin();
PluginSpec pluginSpec();
void init(const QString &sPath);
void unload();
bool testPlugin();
private:
KWalletPasswordBackend* m_backend;
};
#endif // KWALLETPLUGIN_H