This repository has been archived by the owner on May 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PasswordManager] Added KWallet backend plugin.
When building with KDE integration (KDE build flag), this plugin will now be built. Closes #592
- Loading branch information
Showing
10 changed files
with
376 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 183 additions & 0 deletions
183
src/plugins/KWalletPasswords/kwalletpasswordbackend.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/kwp"> | ||
<file>data/icon.png</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.