mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 17:37:36 +03:00
Reorganized the password manager in order to implement other support for
Gnome Keyring, OS X key chain and something for windows.
This commit is contained in:
parent
e0965f2b5c
commit
a4a8fa10d5
8 changed files with 209 additions and 79 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "OwnCloudSync.h"
|
||||
#include "sqlite3_util.h"
|
||||
#include "QWebDAV.h"
|
||||
#include "OwnPasswordManager.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QtSql/QSqlDatabase>
|
||||
|
@ -35,12 +36,10 @@
|
|||
#include <QTableWidgetItem>
|
||||
#include <QComboBox>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <kwallet.h>
|
||||
#endif
|
||||
|
||||
OwnCloudSync::OwnCloudSync(QString name, WId id,QSet<QString> *globalFilters)
|
||||
: mAccountName(name),mWinId(id),mGlobalFilters(globalFilters)
|
||||
OwnCloudSync::OwnCloudSync(QString name, OwnPasswordManager *passwordManager,
|
||||
QSet<QString> *globalFilters)
|
||||
: mAccountName(name),mPasswordManager(passwordManager),
|
||||
mGlobalFilters(globalFilters)
|
||||
{
|
||||
mBusy = false;
|
||||
mIsPaused = false;
|
||||
|
@ -48,7 +47,6 @@ OwnCloudSync::OwnCloudSync(QString name, WId id,QSet<QString> *globalFilters)
|
|||
// Set the pointers so we can delete them without worrying :)
|
||||
mSyncTimer = 0;
|
||||
mFileWatcher = 0;
|
||||
mWallet = 0;
|
||||
|
||||
mHardStop = false;
|
||||
mIsFirstRun = true;
|
||||
|
@ -114,11 +112,8 @@ OwnCloudSync::OwnCloudSync(QString name, WId id,QSet<QString> *globalFilters)
|
|||
readConfigFromDB();
|
||||
//ui->buttonSave->setDisabled(true);
|
||||
syncDebug() << "Checking configuration!";
|
||||
#ifdef Q_OS_LINUX
|
||||
// Wait until the password is set
|
||||
#else
|
||||
mPassword = mPasswordManager->getPassword(mAccountName);
|
||||
initialize();
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
createDataBase(); // Create the database in memory
|
||||
|
@ -128,15 +123,6 @@ OwnCloudSync::OwnCloudSync(QString name, WId id,QSet<QString> *globalFilters)
|
|||
connect(mSaveDBTimer, SIGNAL(timeout()), this, SLOT(saveDBToFile()));
|
||||
mSaveDBTimer->start(370000);
|
||||
updateStatus();
|
||||
|
||||
// Now the password management
|
||||
#ifdef Q_OS_LINUX
|
||||
mWallet= KWallet::Wallet::openWallet(
|
||||
KWallet::Wallet::NetworkWallet(),
|
||||
mWinId,KWallet::Wallet::Asynchronous);
|
||||
connect(mWallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool)));
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void OwnCloudSync::setSaveDBTime(qint64 seconds)
|
||||
|
@ -1260,9 +1246,7 @@ void OwnCloudSync::saveDBToFile()
|
|||
} else {
|
||||
syncDebug() << "Failed to save DB to file!";
|
||||
}
|
||||
#ifdef Q_OS_LINUX
|
||||
saveWalletPassword();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void OwnCloudSync::loadDBFromFile()
|
||||
|
@ -1619,44 +1603,6 @@ bool OwnCloudSync::needsSync()
|
|||
return mNeedsSync;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
void OwnCloudSync::requestPassword()
|
||||
{
|
||||
QMap<QString,QString> map;
|
||||
mWallet->readMap(mAccountName,map);
|
||||
if(map.size()) {
|
||||
mPassword = map[mAccountName];
|
||||
initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void OwnCloudSync::walletOpened(bool ok)
|
||||
{
|
||||
if( (ok && (mWallet->hasFolder("owncloud_sync"))
|
||||
|| mWallet->createFolder("owncloud_sync"))
|
||||
&& mWallet->setFolder("owncloud_sync")) {
|
||||
//emit toLog("Wallet opened!");
|
||||
//syncDebug() << "Wallet opened!" <<
|
||||
// KWallet::Wallet::FormDataFolder() ;
|
||||
if (mReadPassword ) {
|
||||
requestPassword();
|
||||
}
|
||||
} else {
|
||||
syncDebug() << "Error opening wallet";
|
||||
}
|
||||
}
|
||||
|
||||
void OwnCloudSync::saveWalletPassword()
|
||||
{
|
||||
QMap<QString,QString> map;
|
||||
map[mAccountName] = mPassword;
|
||||
if( mWallet )
|
||||
mWallet->writeMap(mAccountName,map);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QString OwnCloudSync::stringRemoveBasePath(QString path, QString base)
|
||||
{
|
||||
if( base != "/" ) {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef OWNCLOUDSYNC_H
|
||||
#define OWNCLOUDSYNC_H
|
||||
|
||||
#include "SyncGlobal.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "QWebDAV.h"
|
||||
#include <QSqlDatabase>
|
||||
|
@ -31,17 +33,15 @@
|
|||
class QTimer;
|
||||
class QFileSystemWatcher;
|
||||
class QNetworkReply;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <kwallet.h>
|
||||
#endif
|
||||
class OwnPasswordManager;
|
||||
|
||||
class OwnCloudSync : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OwnCloudSync(QString name, WId id, QSet<QString> *globalFilters);
|
||||
explicit OwnCloudSync(QString name, OwnPasswordManager *passwordManager,
|
||||
QSet<QString> *globalFilters);
|
||||
~OwnCloudSync();
|
||||
void initialize(QString host, QString user, QString pass, QString remote,
|
||||
QString local, qint64 time);
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
WId mWinId;
|
||||
OwnPasswordManager *mPasswordManager;
|
||||
QWebDAV *mWebdav;
|
||||
bool mIsEnabled;
|
||||
bool mAllowedToSync;
|
||||
|
@ -152,11 +152,6 @@ private:
|
|||
QString mAccountName;
|
||||
SyncPosition mLastSyncAborted;
|
||||
SyncPosition mSyncPosition;
|
||||
#ifdef Q_OS_LINUX
|
||||
KWallet::Wallet *mWallet;
|
||||
void saveWalletPassword();
|
||||
void requestPassword();
|
||||
#endif
|
||||
bool mReadPassword;
|
||||
bool mIsPaused;
|
||||
|
||||
|
@ -221,10 +216,6 @@ public slots:
|
|||
void loadDBFromFile();
|
||||
void requestTimedout();
|
||||
void serverDirectoryCreated(QString name);
|
||||
|
||||
//#ifdef Q_OS_LINUX
|
||||
void walletOpened(bool);
|
||||
//#endif
|
||||
};
|
||||
|
||||
#endif // OWNCLOUDSYNC_H
|
||||
|
|
107
owncloud_sync_qt/OwnPasswordManager.cpp
Normal file
107
owncloud_sync_qt/OwnPasswordManager.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
#include "OwnPasswordManager.h"
|
||||
|
||||
OwnPasswordManager::OwnPasswordManager(QObject *parent, WId winID )
|
||||
: QObject(parent)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
mKWallet= KWallet::Wallet::openWallet(
|
||||
KWallet::Wallet::NetworkWallet(),
|
||||
winID,KWallet::Wallet::Asynchronous);
|
||||
connect(mKWallet, SIGNAL(walletOpened(bool)),
|
||||
this,SLOT(slotKWalletOpened(bool)));
|
||||
#endif // OCS_USE_KWALLET
|
||||
|
||||
#endif // Q_OS_LINUX
|
||||
}
|
||||
|
||||
void OwnPasswordManager::savePassword(QString name, QString pass)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
QMap<QString,QString> map;
|
||||
map[name] = pass;
|
||||
if( mKWallet )
|
||||
mKWallet->writeMap(name,map);
|
||||
#endif
|
||||
|
||||
#if defined(OCS_USE_GNOME_KEYRING)
|
||||
#endif
|
||||
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
#ifdef Q_OS_MAC_OS_X
|
||||
#endif // Q_OS_MAC_OS_X
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#endif // Q_OS_WIN
|
||||
}
|
||||
|
||||
QString OwnPasswordManager::getPassword(QString name)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
QMap<QString,QString> map;
|
||||
mKWallet->readMap(name,map);
|
||||
if(map.size()) {
|
||||
return map[name];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OCS_USE_GNOME_KEYRING)
|
||||
#endif
|
||||
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
#ifdef Q_OS_MAC_OS_X
|
||||
#endif // Q_OS_MAC_OS_X
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#endif // Q_OS_WIN
|
||||
return QString("");
|
||||
}
|
||||
|
||||
void OwnPasswordManager::slotKWalletOpened(bool ok)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
kwalletOpened(ok);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
void OwnPasswordManager::kwalletOpened(bool ok)
|
||||
{
|
||||
if( ok && (mKWallet->hasFolder("owncloud_sync")
|
||||
|| mKWallet->createFolder("owncloud_sync"))
|
||||
&& mKWallet->setFolder("owncloud_sync") ){
|
||||
emit managerReady();
|
||||
//emit toLog("Wallet opened!");
|
||||
//syncDebug() << "Wallet opened!" <<
|
||||
// KWallet::Wallet::FormDataFolder() ;
|
||||
//if (mReadPassword ) {
|
||||
// requestPassword();
|
||||
//}
|
||||
} else {
|
||||
syncDebug() << "Error opening wallet";
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OCS_USE_KWALLET
|
||||
|
||||
#if defined(OCS_USE_GNOME_KEYRING)
|
||||
#endif // OCS_USE_GNOME_KEYRING
|
||||
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
#ifdef Q_OS_MAC_OS_X
|
||||
#endif // Q_OS_MAC_OS_X
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#endif // Q_OS_WIN
|
62
owncloud_sync_qt/OwnPasswordManager.h
Normal file
62
owncloud_sync_qt/OwnPasswordManager.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
#ifndef OWNPASSWORDMANAGER_H
|
||||
#define OWNPASSWORDMANAGER_H
|
||||
|
||||
#include "SyncGlobal.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QObject>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
// We have two choices for linux (kwallet,gnome keyring or I suppose, none)
|
||||
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
#include <kwallet.h>
|
||||
#endif
|
||||
|
||||
#if defined(OCS_USE_GNOME_KEYRING)
|
||||
#endif
|
||||
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
#ifdef Q_OS_MAC_OS_X
|
||||
#endif // Q_OS_MAC_OS_X
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
class OwnPasswordManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OwnPasswordManager(QObject *parent = 0, WId winId = 0);
|
||||
void savePassword(QString name, QString pass);
|
||||
QString getPassword(QString name);
|
||||
|
||||
private:
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
#if defined(OCS_USE_KWALLET)
|
||||
KWallet::Wallet *mKWallet;
|
||||
void kwalletOpened(bool);
|
||||
#endif
|
||||
|
||||
#if defined(OCS_USE_GNOME_KEYRING)
|
||||
#endif
|
||||
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
#ifdef Q_OS_MAC_OS_X
|
||||
#endif // Q_OS_MAC_OS_X
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
public slots:
|
||||
void slotKWalletOpened(bool);
|
||||
|
||||
signals:
|
||||
void managerReady();
|
||||
|
||||
};
|
||||
|
||||
#endif // OWNPASSWORDMANAGER_H
|
|
@ -44,6 +44,7 @@ public:
|
|||
qint64 writeData(const char* data, qint64 length){
|
||||
qDebug() << data;
|
||||
emit debugMessage(QString(data));
|
||||
return 0;
|
||||
}
|
||||
|
||||
signals:
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "sqlite3_util.h"
|
||||
#include "QWebDAV.h"
|
||||
#include "OwnCloudSync.h"
|
||||
#include "OwnPasswordManager.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QtSql/QSqlDatabase>
|
||||
|
@ -51,6 +52,7 @@ SyncWindow::SyncWindow(QWidget *parent) :
|
|||
QMainWindow(parent),
|
||||
ui(new Ui::SyncWindow)
|
||||
{
|
||||
hide();
|
||||
mSharedFilters = new QSet<QString>();
|
||||
mIncludedFilters = g_GetIncludedFilterList();
|
||||
mQuitAction = false;
|
||||
|
@ -110,7 +112,17 @@ SyncWindow::SyncWindow(QWidget *parent) :
|
|||
importGlobalFilters(true);
|
||||
updateSharedFilterList();
|
||||
|
||||
// Get the password manager
|
||||
mPasswordManager = new OwnPasswordManager(this,winId());
|
||||
connect(mPasswordManager,SIGNAL(managerReady()),
|
||||
this,SLOT(passwordManagerReady()));
|
||||
}
|
||||
|
||||
void SyncWindow::passwordManagerReady()
|
||||
{
|
||||
// Look for accounts that already exist
|
||||
QDir configDir(mConfigDirectory);
|
||||
configDir.mkpath(mConfigDirectory);
|
||||
QStringList filters;
|
||||
filters << "*.db";
|
||||
QStringList files = configDir.entryList(filters);
|
||||
|
@ -223,7 +235,8 @@ void SyncWindow::systemTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
|||
|
||||
OwnCloudSync* SyncWindow::addAccount(QString name)
|
||||
{
|
||||
OwnCloudSync *account = new OwnCloudSync(name,winId(),mSharedFilters);
|
||||
OwnCloudSync *account = new OwnCloudSync(name,mPasswordManager,
|
||||
mSharedFilters);
|
||||
mAccounts.append(account);
|
||||
mAccountNames.append(name);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <QModelIndex>
|
||||
#include <QItemSelection>
|
||||
|
||||
class OwnPasswordManager;
|
||||
class QTimer;
|
||||
class OwnCloudSync;
|
||||
class QSignalMapper;
|
||||
|
@ -103,6 +104,8 @@ private:
|
|||
QIcon mDefaultConflictIcon;
|
||||
QIcon mSyncConflictIcon;
|
||||
|
||||
OwnPasswordManager *mPasswordManager;
|
||||
|
||||
void processNextStep();
|
||||
void saveLogs();
|
||||
void rebuildAccountsTable();
|
||||
|
@ -134,6 +137,7 @@ public slots:
|
|||
void slotAccountsSignalMapper(int row);
|
||||
void processDebugMessage(const QString msg);
|
||||
void includedFilterListItemChanged(QListWidgetItem* item);
|
||||
void passwordManagerReady();
|
||||
|
||||
// GUI related slots
|
||||
void on_buttonSave_clicked();
|
||||
|
|
|
@ -21,13 +21,15 @@ SOURCES += main.cpp\
|
|||
sqlite3_util.cpp \
|
||||
SyncWindow.cpp \
|
||||
qwebdav/QWebDAV.cpp \
|
||||
OwnCloudSync.cpp
|
||||
OwnCloudSync.cpp \
|
||||
OwnPasswordManager.cpp
|
||||
|
||||
HEADERS += sqlite3_util.h \
|
||||
SyncWindow.h \
|
||||
qwebdav/QWebDAV.h \
|
||||
OwnCloudSync.h \
|
||||
SyncGlobal.h
|
||||
SyncGlobal.h \
|
||||
OwnPasswordManager.h
|
||||
|
||||
FORMS += SyncWindow.ui
|
||||
INCLUDEPATH += qwebdav/
|
||||
|
@ -88,3 +90,7 @@ OTHER_FILES += \
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue