1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[PasswordManager] Small cleanups + offer plugins to add new backends.

This commit is contained in:
nowrep 2013-05-15 20:05:45 +02:00
parent ac90002b6f
commit f8ee9a4b9c
6 changed files with 68 additions and 7 deletions

View File

@ -44,6 +44,11 @@ AutoFill::AutoFill(QObject* parent)
loadSettings(); loadSettings();
} }
PasswordManager* AutoFill::passwordManager() const
{
return m_manager;
}
void AutoFill::loadSettings() void AutoFill::loadSettings()
{ {
Settings settings; Settings settings;
@ -127,6 +132,7 @@ void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
entry.host = PasswordManager::createHost(url); entry.host = PasswordManager::createHost(url);
entry.username = formData.username; entry.username = formData.username;
entry.password = formData.password; entry.password = formData.password;
entry.data = formData.postData;
m_manager->addEntry(entry); m_manager->addEntry(entry);
} }

View File

@ -37,6 +37,7 @@ class QT_QUPZILLA_EXPORT AutoFill : public QObject
public: public:
explicit AutoFill(QObject* parent = 0); explicit AutoFill(QObject* parent = 0);
PasswordManager* passwordManager() const;
void loadSettings(); void loadSettings();
bool isStored(const QUrl &url); bool isStored(const QUrl &url);

View File

@ -36,7 +36,7 @@ public:
virtual void removeEntry(const PasswordEntry &entry) = 0; virtual void removeEntry(const PasswordEntry &entry) = 0;
virtual void removeAll() = 0; virtual void removeAll() = 0;
void setActive(bool active); virtual void setActive(bool active);
bool isActive() const; bool isActive() const;
private: private:

View File

@ -22,10 +22,42 @@
#include <QVector> #include <QVector>
static const int passwordEntryVersion = 1;
QDataStream &operator <<(QDataStream &stream, const PasswordEntry &tab)
{
stream << passwordEntryVersion;
stream << tab.host;
stream << tab.id;
stream << tab.username;
stream << tab.password;
stream << tab.data;
return stream;
}
QDataStream &operator >>(QDataStream &stream, PasswordEntry &tab)
{
int version;
stream >> version;
if (version != passwordEntryVersion) {
return stream;
}
stream >> tab.host;
stream >> tab.id;
stream >> tab.username;
stream >> tab.password;
stream >> tab.data;
return stream;
}
PasswordManager::PasswordManager(QObject* parent) PasswordManager::PasswordManager(QObject* parent)
: QObject(parent) : QObject(parent)
, m_backend(0)
, m_loaded(false) , m_loaded(false)
, m_backend(0)
, m_databaseBackend(new DatabasePasswordBackend) , m_databaseBackend(new DatabasePasswordBackend)
{ {
m_backends["database"] = m_databaseBackend; m_backends["database"] = m_databaseBackend;
@ -123,3 +155,4 @@ PasswordManager::~PasswordManager()
{ {
delete m_databaseBackend; delete m_databaseBackend;
} }

View File

@ -27,7 +27,7 @@
class PasswordBackend; class PasswordBackend;
class DatabasePasswordBackend; class DatabasePasswordBackend;
struct PasswordEntry { struct QT_QUPZILLA_EXPORT PasswordEntry {
QVariant id; QVariant id;
QString host; QString host;
QString username; QString username;
@ -37,6 +37,13 @@ struct PasswordEntry {
bool isValid() const { bool isValid() const {
return !password.isEmpty(); return !password.isEmpty();
} }
bool operator==(const PasswordEntry &other) const {
return id == other.id;
}
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const PasswordEntry &tab);
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, PasswordEntry &tab);
}; };
class QT_QUPZILLA_EXPORT PasswordManager : public QObject class QT_QUPZILLA_EXPORT PasswordManager : public QObject
@ -66,9 +73,9 @@ public:
private: private:
void ensureLoaded(); void ensureLoaded();
PasswordBackend* m_backend;
bool m_loaded; bool m_loaded;
PasswordBackend* m_backend;
DatabasePasswordBackend* m_databaseBackend; DatabasePasswordBackend* m_databaseBackend;
QHash<QString, PasswordBackend*> m_backends; QHash<QString, PasswordBackend*> m_backends;
}; };

View File

@ -79,8 +79,22 @@ private:
QList<PluginInterface*> m_keyReleaseHandlers; QList<PluginInterface*> m_keyReleaseHandlers;
}; };
#define QZ_REGISTER_EVENT_HANDLER(Type) mApp->plugins()->registerAppEventHandler(Type, this); #include "mainapplication.h"
#define QZ_REGISTER_SCHEME_HANDLER(Scheme, Object) mApp->networkManager()->registerSchemeHandler(Scheme, Object); #include "networkmanager.h"
#define QZ_UNREGISTER_SCHEME_HANDLER(Scheme, Object) mApp->networkManager()->unregisterSchemeHandler(Scheme, Object); #include "autofill.h"
#include "passwordmanager.h"
#define QZ_REGISTER_EVENT_HANDLER(Type) \
mApp->plugins()->registerAppEventHandler(Type, this);
#define QZ_REGISTER_SCHEME_HANDLER(Scheme, Object) \
mApp->networkManager()->registerSchemeHandler(Scheme, Object);
#define QZ_UNREGISTER_SCHEME_HANDLER(Scheme, Object) \
mApp->networkManager()->unregisterSchemeHandler(Scheme, Object);
#define QZ_REGISTER_PASSWORD_BACKEND(Name, Object) \
mApp->autoFill()->passwordManager()->registerBackend(Name, Object);
#define QZ_UNREGISTER_PASSWORD_BACKEND(Object) \
mApp->autoFill()->passwordManager()->unregisterBackend(Object);
#endif // PLUGINPROXY_H #endif // PLUGINPROXY_H