From 309760ab3691d486adf6e1142cef00823d47bdac Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 25 Dec 2011 16:12:01 -0500 Subject: [PATCH] Some restructuring that allows proper compilation on Windows systems. Still not stable on Windows. Need to resolve sqlite3 issues. --- owncloud_sync_qt/OwnCloudSync.cpp | 25 ++++++------------- owncloud_sync_qt/OwnCloudSync.h | 2 +- owncloud_sync_qt/OwnPasswordManager.cpp | 15 ++++++++++- owncloud_sync_qt/OwnPasswordManager.h | 2 ++ owncloud_sync_qt/SyncWindow.cpp | 33 +++++++++++++++++-------- owncloud_sync_qt/SyncWindow.h | 1 + owncloud_sync_qt/owncloud_sync.pro | 2 ++ 7 files changed, 51 insertions(+), 29 deletions(-) diff --git a/owncloud_sync_qt/OwnCloudSync.cpp b/owncloud_sync_qt/OwnCloudSync.cpp index 3b95d73eb..d0180e4fa 100644 --- a/owncloud_sync_qt/OwnCloudSync.cpp +++ b/owncloud_sync_qt/OwnCloudSync.cpp @@ -37,9 +37,10 @@ #include OwnCloudSync::OwnCloudSync(QString name, OwnPasswordManager *passwordManager, - QSet *globalFilters) + QSet *globalFilters, + QString configDir) : mAccountName(name),mPasswordManager(passwordManager), - mGlobalFilters(globalFilters) + mGlobalFilters(globalFilters),mConfigDirectory(configDir) { mBusy = false; mIsPaused = false; @@ -87,21 +88,11 @@ OwnCloudSync::OwnCloudSync(QString name, OwnPasswordManager *passwordManager, // Initialize the Database mDB = QSqlDatabase::addDatabase("QSQLITE",mAccountName); -#ifdef Q_OS_LINUX - // In linux, we will store all databases in - // $HOME/.local/share/data/owncloud_sync - mHomeDirectory = QDir::home().path(); - mConfigDirectory = mHomeDirectory+"/.local/share/data/owncloud_sync"; - QDir configDir(mConfigDirectory); - configDir.mkpath(mConfigDirectory); - QDir logsDir(mConfigDirectory+"/logs"); - logsDir.mkpath(mConfigDirectory+"/logs"); - //mDB.setDatabaseName(mConfigDirectory+"/owncloud_sync.db"); mDB.setDatabaseName(":memory:"); // Use memory for now - mDBFileName = mConfigDirectory+"/"+mAccountName+".db"; -#endif + mDBFileName = QDir::toNativeSeparators(mConfigDirectory+"/")+mAccountName+".db"; + // Find out if the database exists. - QFile dbFile(mConfigDirectory+"/"+mAccountName+".db"); + QFile dbFile(mDBFileName); if( dbFile.exists() ) { if(!mDB.open()) { syncDebug() << "Cannot open database!"; @@ -1163,7 +1154,7 @@ void OwnCloudSync::localDirectoryChanged(QString name) { // Maybe this was caused by us renaming a file, just wait it out while (mFileAccessBusy ) { - sleep(1); + //sleep(1); } // If it was caused by one directory being deleted, then delete it now // and don't scan it! @@ -1576,7 +1567,7 @@ void OwnCloudSync::deleteAccount() // Delete the database mDB.close(); - QFile dbFile(mConfigDirectory+"/"+mAccountName+".db"); + QFile dbFile(mDBFileName); dbFile.remove(); } diff --git a/owncloud_sync_qt/OwnCloudSync.h b/owncloud_sync_qt/OwnCloudSync.h index 06c0a7e22..1be169f0f 100644 --- a/owncloud_sync_qt/OwnCloudSync.h +++ b/owncloud_sync_qt/OwnCloudSync.h @@ -41,7 +41,7 @@ class OwnCloudSync : public QObject public: explicit OwnCloudSync(QString name, OwnPasswordManager *passwordManager, - QSet *globalFilters); + QSet *globalFilters,QString configDir); ~OwnCloudSync(); void initialize(QString host, QString user, QString pass, QString remote, QString local, qint64 time); diff --git a/owncloud_sync_qt/OwnPasswordManager.cpp b/owncloud_sync_qt/OwnPasswordManager.cpp index ea8be1171..ed51472e0 100644 --- a/owncloud_sync_qt/OwnPasswordManager.cpp +++ b/owncloud_sync_qt/OwnPasswordManager.cpp @@ -5,6 +5,7 @@ OwnPasswordManager::OwnPasswordManager(QObject *parent, WId winID ) : QObject(parent) { + mIsReady = false; #ifdef Q_OS_LINUX QProcess p; QStringList args; @@ -32,9 +33,18 @@ OwnPasswordManager::OwnPasswordManager(QObject *parent, WId winID ) } #endif // OCS_USE_KWALLET if(mPasswordManagerLinux != KWALLET ) { + mIsReady = true; emit managerReady(); } #endif // Q_OS_LINUX + +#ifdef Q_OS_MAC_OS_X + mIsReady = true; +#endif // Q_OS_MAC_OS_X + +#ifdef Q_OS_WIN + mIsReady = true; +#endif // Q_OS_WIN } bool OwnPasswordManager::savePassword(QString name, QString pass) @@ -45,8 +55,10 @@ bool OwnPasswordManager::savePassword(QString name, QString pass) if(mPasswordManagerLinux == KWALLET) { QMap map; map[name] = pass; - if( mKWallet ) + if( mKWallet ) { mKWallet->writeMap(name,map); + return true; + } } #endif @@ -107,6 +119,7 @@ void OwnPasswordManager::kwalletOpened(bool ok) if( ok && (mKWallet->hasFolder("owncloud_sync") || mKWallet->createFolder("owncloud_sync")) && mKWallet->setFolder("owncloud_sync") ){ + mIsReady = true; emit managerReady(); //emit toLog("Wallet opened!"); syncDebug() << "Wallet opened!"; diff --git a/owncloud_sync_qt/OwnPasswordManager.h b/owncloud_sync_qt/OwnPasswordManager.h index 7b4087692..e9e060df9 100644 --- a/owncloud_sync_qt/OwnPasswordManager.h +++ b/owncloud_sync_qt/OwnPasswordManager.h @@ -31,8 +31,10 @@ public: OwnPasswordManager(QObject *parent = 0, WId winId = 0); bool savePassword(QString name, QString pass); QString getPassword(QString name); + bool isReady() { return mIsReady; } private: + bool mIsReady; #ifdef Q_OS_LINUX enum PasswordManagerLinux { NONE, diff --git a/owncloud_sync_qt/SyncWindow.cpp b/owncloud_sync_qt/SyncWindow.cpp index 51ce164ea..8a0275f3e 100644 --- a/owncloud_sync_qt/SyncWindow.cpp +++ b/owncloud_sync_qt/SyncWindow.cpp @@ -53,6 +53,7 @@ SyncWindow::SyncWindow(QWidget *parent) : ui(new Ui::SyncWindow) { hide(); + mProcessedPasswordManager = false; mSharedFilters = new QSet(); mIncludedFilters = g_GetIncludedFilterList(); mQuitAction = false; @@ -99,16 +100,20 @@ SyncWindow::SyncWindow(QWidget *parent) : connect(mAccountsSignalMapper, SIGNAL(mapped(int)), this, SLOT(slotAccountsSignalMapper(int))); + mConfigDirectory = QDir::toNativeSeparators(QDir::homePath()); #ifdef Q_OS_LINUX // In linux, we will store all databases in // $HOME/.local/share/data/owncloud_sync - mConfigDirectory = QDir::home().path()+"/.local/share/data/owncloud_sync"; + mConfigDirectory += QDir::toNativeSeparators("/.local/share/data/)"; +#endif +#ifdef Q_OS_WIN + mConfigDirectory += QDir::toNativeSeparators("/AppData/Local/"); +#endif + mConfigDirectory += "owncloud_sync"; QDir configDir(mConfigDirectory); configDir.mkpath(mConfigDirectory); - QDir logsDir(mConfigDirectory+"/logs"); - logsDir.mkpath(mConfigDirectory+"/logs"); -#endif - + QDir logsDir(QDir::toNativeSeparators(mConfigDirectory+"/logs")); + logsDir.mkpath(QDir::toNativeSeparators(mConfigDirectory+"/logs")); importGlobalFilters(true); updateSharedFilterList(); @@ -116,19 +121,25 @@ SyncWindow::SyncWindow(QWidget *parent) : mPasswordManager = new OwnPasswordManager(this,winId()); connect(mPasswordManager,SIGNAL(managerReady()), this,SLOT(passwordManagerReady())); + + // Check if the passwordManager is already ready + if(mPasswordManager->isReady() && !mProcessedPasswordManager) { + passwordManagerReady(); + } } void SyncWindow::passwordManagerReady() { + mProcessedPasswordManager = true; // Look for accounts that already exist QDir configDir(mConfigDirectory); - configDir.mkpath(mConfigDirectory); QStringList filters; filters << "*.db"; QStringList files = configDir.entryList(filters); for( int i = 0; i < files.size(); i++ ) { QString name = files[i].replace(".db",""); addAccount(name); + syncDebug() << "Found account: " << name; } if( files.size() == 0 ) { on_buttonNewAccount_clicked(); @@ -187,10 +198,12 @@ SyncWindow::~SyncWindow() void SyncWindow::saveLogs() { QString name = - QDateTime::currentDateTime().toString("yyyyMMdd:hh:mm:ss.log"); - QFile file(mConfigDirectory+"/logs/"+name); + QDateTime::currentDateTime().toString("yyyyMMdd_hh_mm_ss.log"); + QFile file(QDir::toNativeSeparators(mConfigDirectory+"/logs/"+name)); if( !file.open(QIODevice::WriteOnly)) { - syncDebug() << "Could not open log file for writting!\n"; + syncDebug() << "Could not open log file for writting!" + << QDir::toNativeSeparators(mConfigDirectory+"/logs/"+name) + << file.errorString(); return; } @@ -236,7 +249,7 @@ void SyncWindow::systemTrayActivated(QSystemTrayIcon::ActivationReason reason) OwnCloudSync* SyncWindow::addAccount(QString name) { OwnCloudSync *account = new OwnCloudSync(name,mPasswordManager, - mSharedFilters); + mSharedFilters,mConfigDirectory); mAccounts.append(account); mAccountNames.append(name); diff --git a/owncloud_sync_qt/SyncWindow.h b/owncloud_sync_qt/SyncWindow.h index e831f2348..06677c55e 100644 --- a/owncloud_sync_qt/SyncWindow.h +++ b/owncloud_sync_qt/SyncWindow.h @@ -98,6 +98,7 @@ private: bool mHideOnClose; qint64 mSaveLogCounter; qint64 mSaveDBTime; + bool mProcessedPasswordManager; QIcon mDefaultIcon; QIcon mSyncIcon; diff --git a/owncloud_sync_qt/owncloud_sync.pro b/owncloud_sync_qt/owncloud_sync.pro index b85bd95a7..8761358ec 100644 --- a/owncloud_sync_qt/owncloud_sync.pro +++ b/owncloud_sync_qt/owncloud_sync.pro @@ -70,6 +70,8 @@ unix:!macx:!symbian: LIBS += -L/usr/lib/ -lsqlite3 unix:!macx:!symbian: LIBS += -L/usr/lib/kde4/devel -lkparts -lkdeui -lkdecore } +win32: LIBS += -lsqlite3 + #linux-g++ { #message(On Linux) #}