diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-11-22 18:38:16 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-12-12 16:40:29 +0100 |
commit | adce8459b83cd7494dbc4c552c5079dc22e68a54 (patch) | |
tree | cf42b18b0a783a9fe7b5ae0b97eb3c2dba842aad /src/sync | |
parent | here we are, rekonq ftp remote sync done! (diff) | |
download | rekonq-adce8459b83cd7494dbc4c552c5079dc22e68a54.tar.xz |
Clean out ftp code to easily add in the future new sync implementations
Diffstat (limited to 'src/sync')
-rw-r--r-- | src/sync/ftpsynchandler.cpp | 267 | ||||
-rw-r--r-- | src/sync/ftpsynchandler.h | 84 | ||||
-rw-r--r-- | src/sync/synchandler.h | 52 | ||||
-rw-r--r-- | src/sync/syncmanager.cpp | 224 | ||||
-rw-r--r-- | src/sync/syncmanager.h | 42 | ||||
-rw-r--r-- | src/sync/syncwidget.cpp | 4 |
6 files changed, 435 insertions, 238 deletions
diff --git a/src/sync/ftpsynchandler.cpp b/src/sync/ftpsynchandler.cpp new file mode 100644 index 00000000..e5170964 --- /dev/null +++ b/src/sync/ftpsynchandler.cpp @@ -0,0 +1,267 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini <adjam7 at gmail dot 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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/>. +* +* ============================================================ */ + + +// Self Includes +#include "ftpsynchandler.h" +#include "ftpsynchandler.moc" + +// Auto Includes +#include "rekonq.h" + +// KDE Includes +#include <KStandardDirs> +#include <klocalizedstring.h> + +#include <KIO/Job> +#include <KIO/JobUiDelegate> + + +FTPSyncHandler::FTPSyncHandler(QObject *parent) + : SyncHandler(parent) + , _firstTimeSynced(false) +{ +} + + +void FTPSyncHandler::firstTimeSync() +{ + // Bookmarks + if (ReKonfig::syncBookmarks()) + { + _remoteBookmarksUrl = QUrl(); + _remoteBookmarksUrl.setHost(ReKonfig::syncHost()); + _remoteBookmarksUrl.setScheme("ftp"); + _remoteBookmarksUrl.setUserName(ReKonfig::syncUser()); + _remoteBookmarksUrl.setPassword(ReKonfig::syncPass()); + _remoteBookmarksUrl.setPort(ReKonfig::syncPort()); + _remoteBookmarksUrl.setPath(ReKonfig::syncPath() + QL1S("/bookmarks.xml")); + kDebug() << "REMOTE BK URL: " << _remoteBookmarksUrl; + + const QString bookmarksFilePath = KStandardDirs::locateLocal("data", QL1S("konqueror/bookmarks.xml")); + _localBookmarksUrl = KUrl(bookmarksFilePath); + kDebug() << "LOCAL BK URL: " << _localBookmarksUrl; + + KIO::StatJob *job = KIO::stat(_remoteBookmarksUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksStatFinished(KJob *))); + + _firstTimeSynced = true; + } + + // History + if (ReKonfig::syncHistory()) + { + _remoteHistoryUrl = QUrl(); + _remoteHistoryUrl.setHost(ReKonfig::syncHost()); + _remoteHistoryUrl.setScheme("ftp"); + _remoteHistoryUrl.setUserName(ReKonfig::syncUser()); + _remoteHistoryUrl.setPassword(ReKonfig::syncPass()); + _remoteHistoryUrl.setPort(ReKonfig::syncPort()); + _remoteHistoryUrl.setPath(ReKonfig::syncPath() + QL1S("/history")); + kDebug() << "REMOTE HISTORY URL: " << _remoteHistoryUrl; + + const QString historyFilePath = KStandardDirs::locateLocal("appdata", "history"); + _localHistoryUrl = KUrl(historyFilePath); + kDebug() << "LOCAL HISTORY URL: " << _localHistoryUrl; + + KIO::StatJob *job = KIO::stat(_remoteHistoryUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistoryStatFinished(KJob *))); + + _firstTimeSynced = true; + } + + // Passwords + if (ReKonfig::syncPasswords()) + { + _remotePasswordsUrl = QUrl(); + _remotePasswordsUrl.setHost(ReKonfig::syncHost()); + _remotePasswordsUrl.setScheme("ftp"); + _remotePasswordsUrl.setUserName(ReKonfig::syncUser()); + _remotePasswordsUrl.setPassword(ReKonfig::syncPass()); + _remotePasswordsUrl.setPort(ReKonfig::syncPort()); + _remotePasswordsUrl.setPath(ReKonfig::syncPath() + QL1S("/kdewallet.kwl")); + kDebug() << "REMOTE PSWD URL: " << _remotePasswordsUrl; + + const QString passwordsFilePath = KStandardDirs::locateLocal("data", QL1S("kwallet/kdewallet.kwl")); + _localPasswordsUrl = KUrl(passwordsFilePath); + kDebug() << "LOCAL PSWD URL: " << _localPasswordsUrl; + + KIO::StatJob *job = KIO::stat(_remotePasswordsUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsStatFinished(KJob *))); + + _firstTimeSynced = true; + } +} + + +bool FTPSyncHandler::syncRelativeEnabled(bool check) +{ + if (!ReKonfig::syncEnabled()) + return false; + + if (!_firstTimeSynced) + { + kDebug() << "need to sync for the first time..."; + firstTimeSync(); + return false; + } + + return check; +} + + +// --------------------------------------------------------------------------------------- + + +void FTPSyncHandler::syncBookmarks() +{ + kDebug() << "syncing now..."; + + if (!syncRelativeEnabled(ReKonfig::syncBookmarks())) + return; + + KIO::Job *job = KIO::file_copy(_localBookmarksUrl, _remoteBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); +} + + +void FTPSyncHandler::onBookmarksStatFinished(KJob *job) +{ + if (job->error()) + { + KIO::Job *job = KIO::file_copy(_localBookmarksUrl, _remoteBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); + } + else + { + KIO::Job *job = KIO::file_copy(_remoteBookmarksUrl, _localBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); + } +} + + +void FTPSyncHandler::onBookmarksSyncFinished(KJob *job) +{ + if (job->error()) + { + job->uiDelegate()->showErrorMessage(); + emit syncBookmarksFinished(false); + return; + } + + QDateTime now = QDateTime::currentDateTime(); + ReKonfig::setLastSyncDateTime(now); + emit syncBookmarksFinished(true); +} + + +// --------------------------------------------------------------------------------------- + + +void FTPSyncHandler::syncHistory() +{ + kDebug() << "syncing now..."; + + if (!syncRelativeEnabled(ReKonfig::syncHistory())) + return; + + KIO::Job *job = KIO::file_copy(_localHistoryUrl, _remoteHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); +} + + +void FTPSyncHandler::onHistoryStatFinished(KJob *job) +{ + if (job->error()) + { + KIO::Job *job = KIO::file_copy(_localHistoryUrl, _remoteHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); + } + else + { + KIO::Job *job = KIO::file_copy(_remoteHistoryUrl, _localHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); + } +} + + +void FTPSyncHandler::onHistorySyncFinished(KJob *job) +{ + if (job->error()) + { + job->uiDelegate()->showErrorMessage(); + emit syncHistoryFinished(false); + return; + } + + QDateTime now = QDateTime::currentDateTime(); + ReKonfig::setLastSyncDateTime(now); + emit syncHistoryFinished(true); +} + + +// --------------------------------------------------------------------------------------- + + +void FTPSyncHandler::syncPasswords() +{ + kDebug() << "syncing now..."; + + if (!syncRelativeEnabled(ReKonfig::syncPasswords())) + return; + + KIO::Job *job = KIO::file_copy(_localPasswordsUrl, _remotePasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); +} + + +void FTPSyncHandler::onPasswordsStatFinished(KJob *job) +{ + if (job->error()) + { + KIO::Job *job = KIO::file_copy(_localPasswordsUrl, _remotePasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); + } + else + { + KIO::Job *job = KIO::file_copy(_remotePasswordsUrl, _localPasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); + } +} + + +void FTPSyncHandler::onPasswordsSyncFinished(KJob *job) +{ + if (job->error()) + { + job->uiDelegate()->showErrorMessage(); + emit syncPasswordsFinished(false); + return; + } + + QDateTime now = QDateTime::currentDateTime(); + ReKonfig::setLastSyncDateTime(now); + emit syncPasswordsFinished(true); +} diff --git a/src/sync/ftpsynchandler.h b/src/sync/ftpsynchandler.h new file mode 100644 index 00000000..2620e89d --- /dev/null +++ b/src/sync/ftpsynchandler.h @@ -0,0 +1,84 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini <adjam7 at gmail dot 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 FTP_SYNC_HANDLER_H +#define FTP_SYNC_HANDLER_H + + +// Local Includes +#include "synchandler.h" + +// KDE Includes +#include <KUrl> + +// Forward Declarations +class KJob; + + +class FTPSyncHandler : public SyncHandler +{ + Q_OBJECT + +public: + FTPSyncHandler(QObject *parent = 0); + + void syncHistory(); + void syncBookmarks(); + void syncPasswords(); + + void firstTimeSync(); + +private Q_SLOTS: + void onBookmarksSyncFinished(KJob *); + void onBookmarksStatFinished(KJob *); + + void onHistorySyncFinished(KJob *); + void onHistoryStatFinished(KJob *); + + void onPasswordsSyncFinished(KJob *); + void onPasswordsStatFinished(KJob *); + +Q_SIGNALS: + void syncBookmarksFinished(bool); + void syncHistoryFinished(bool); + void syncPasswordsFinished(bool); + +private: + bool syncRelativeEnabled(bool); + + QUrl _remoteBookmarksUrl; + KUrl _localBookmarksUrl; + + QUrl _remoteHistoryUrl; + KUrl _localHistoryUrl; + + QUrl _remotePasswordsUrl; + KUrl _localPasswordsUrl; + + bool _firstTimeSynced; +}; + +#endif // FTP_SYNC_HANDLER_H diff --git a/src/sync/synchandler.h b/src/sync/synchandler.h new file mode 100644 index 00000000..30873fa5 --- /dev/null +++ b/src/sync/synchandler.h @@ -0,0 +1,52 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini <adjam7 at gmail dot 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 SYNC_HANDLER_H +#define SYNC_HANDLER_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Qt Includes +#include <QObject> + + +class SyncHandler : public QObject +{ + +public: + SyncHandler(QObject *parent = 0) : QObject(parent) {} + virtual ~SyncHandler() {} + + virtual void syncHistory() = 0; + virtual void syncBookmarks() = 0; + virtual void syncPasswords() = 0; + + virtual void firstTimeSync() = 0; +}; + +#endif // SYNC_HANDLER_H diff --git a/src/sync/syncmanager.cpp b/src/sync/syncmanager.cpp index b1da8c00..41a60179 100644 --- a/src/sync/syncmanager.cpp +++ b/src/sync/syncmanager.cpp @@ -36,28 +36,34 @@ #include "bookmarkmanager.h" #include "historymanager.h" #include "syncwidget.h" +#include "ftpsynchandler.h" // KDE Includes -#include <KStandardDirs> #include <klocalizedstring.h> -#include <KIO/Job> -#include <KIO/JobUiDelegate> - SyncManager::SyncManager(QObject *parent) : QObject(parent) - , _firstTimeSynced(false) { loadSettings(); } +SyncManager::~SyncManager() +{ + if (!_syncImplementation.isNull()) + { + delete _syncImplementation.data(); + _syncImplementation.clear(); + } +} + + void SyncManager::loadSettings() { if (ReKonfig::syncEnabled()) { - firstTimeSync(); + resetSyncer(); // bookmarks ReKonfig::syncBookmarks() @@ -70,6 +76,8 @@ void SyncManager::loadSettings() ? connect(rApp->historyManager(), SIGNAL(historySaved()), this, SLOT(syncHistory())) : disconnect(rApp->historyManager(), SIGNAL(historySaved()), this, SLOT(syncHistory())) ; + + // NOTE: password sync will be called just on save } else { @@ -98,89 +106,15 @@ void SyncManager::showSettings() } -void SyncManager::firstTimeSync() +void SyncManager::resetSyncer() { - // Bookmarks - if (ReKonfig::syncBookmarks()) + if (_syncImplementation.isNull()) { - _remoteBookmarksUrl = QUrl(); - _remoteBookmarksUrl.setHost(ReKonfig::syncHost()); - _remoteBookmarksUrl.setScheme("ftp"); - _remoteBookmarksUrl.setUserName(ReKonfig::syncUser()); - _remoteBookmarksUrl.setPassword(ReKonfig::syncPass()); - _remoteBookmarksUrl.setPort(ReKonfig::syncPort()); - _remoteBookmarksUrl.setPath(ReKonfig::syncPath() + QL1S("/bookmarks.xml")); - kDebug() << "REMOTE BK URL: " << _remoteBookmarksUrl; - - const QString bookmarksFilePath = KStandardDirs::locateLocal("data", QL1S("konqueror/bookmarks.xml")); - _localBookmarksUrl = KUrl(bookmarksFilePath); - kDebug() << "LOCAL BK URL: " << _localBookmarksUrl; - - KIO::StatJob *job = KIO::stat(_remoteBookmarksUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksStatFinished(KJob *))); - - _firstTimeSynced = true; + // actually we have just FTP handler... + _syncImplementation = new FTPSyncHandler(this); } - // History - if (ReKonfig::syncHistory()) - { - _remoteHistoryUrl = QUrl(); - _remoteHistoryUrl.setHost(ReKonfig::syncHost()); - _remoteHistoryUrl.setScheme("ftp"); - _remoteHistoryUrl.setUserName(ReKonfig::syncUser()); - _remoteHistoryUrl.setPassword(ReKonfig::syncPass()); - _remoteHistoryUrl.setPort(ReKonfig::syncPort()); - _remoteHistoryUrl.setPath(ReKonfig::syncPath() + QL1S("/history")); - kDebug() << "REMOTE HISTORY URL: " << _remoteHistoryUrl; - - const QString historyFilePath = KStandardDirs::locateLocal("appdata", "history"); - _localHistoryUrl = KUrl(historyFilePath); - kDebug() << "LOCAL HISTORY URL: " << _localHistoryUrl; - - KIO::StatJob *job = KIO::stat(_remoteHistoryUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistoryStatFinished(KJob *))); - - _firstTimeSynced = true; - } - - // Passwords - if (ReKonfig::syncPasswords()) - { - _remotePasswordsUrl = QUrl(); - _remotePasswordsUrl.setHost(ReKonfig::syncHost()); - _remotePasswordsUrl.setScheme("ftp"); - _remotePasswordsUrl.setUserName(ReKonfig::syncUser()); - _remotePasswordsUrl.setPassword(ReKonfig::syncPass()); - _remotePasswordsUrl.setPort(ReKonfig::syncPort()); - _remotePasswordsUrl.setPath(ReKonfig::syncPath() + QL1S("/kdewallet.kwl")); - kDebug() << "REMOTE PSWD URL: " << _remotePasswordsUrl; - - const QString passwordsFilePath = KStandardDirs::locateLocal("data", QL1S("kwallet/kdewallet.kwl")); - _localPasswordsUrl = KUrl(passwordsFilePath); - kDebug() << "LOCAL PSWD URL: " << _localPasswordsUrl; - - KIO::StatJob *job = KIO::stat(_remotePasswordsUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsStatFinished(KJob *))); - - _firstTimeSynced = true; - } -} - - -bool SyncManager::syncRelativeEnabled(bool check) -{ - if (!ReKonfig::syncEnabled()) - return false; - - if (!_firstTimeSynced) - { - kDebug() << "need to sync for the first time..."; - firstTimeSync(); - return false; - } - - return check; + _syncImplementation.data()->firstTimeSync(); } @@ -189,131 +123,17 @@ bool SyncManager::syncRelativeEnabled(bool check) void SyncManager::syncBookmarks() { - kDebug() << "syncing now..."; - - if (!syncRelativeEnabled(ReKonfig::syncBookmarks())) - return; - - KIO::Job *job = KIO::file_copy(_localBookmarksUrl, _remoteBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); -} - - -void SyncManager::onBookmarksStatFinished(KJob *job) -{ - if (job->error()) - { - KIO::Job *job = KIO::file_copy(_localBookmarksUrl, _remoteBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); - } - else - { - KIO::Job *job = KIO::file_copy(_remoteBookmarksUrl, _localBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); - } -} - - -void SyncManager::onBookmarksSyncFinished(KJob *job) -{ - if (job->error()) - { - job->uiDelegate()->showErrorMessage(); - emit syncBookmarksFinished(false); - return; - } - - QDateTime now = QDateTime::currentDateTime(); - ReKonfig::setLastSyncDateTime(now); - emit syncBookmarksFinished(true); + _syncImplementation.data()->syncBookmarks(); } -// --------------------------------------------------------------------------------------- - - void SyncManager::syncHistory() { - kDebug() << "syncing now..."; - - if (!syncRelativeEnabled(ReKonfig::syncHistory())) - return; - - KIO::Job *job = KIO::file_copy(_localHistoryUrl, _remoteHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); + _syncImplementation.data()->syncHistory(); } -void SyncManager::onHistoryStatFinished(KJob *job) -{ - if (job->error()) - { - KIO::Job *job = KIO::file_copy(_localHistoryUrl, _remoteHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); - } - else - { - KIO::Job *job = KIO::file_copy(_remoteHistoryUrl, _localHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); - } -} - - -void SyncManager::onHistorySyncFinished(KJob *job) -{ - if (job->error()) - { - job->uiDelegate()->showErrorMessage(); - emit syncHistoryFinished(false); - return; - } - - QDateTime now = QDateTime::currentDateTime(); - ReKonfig::setLastSyncDateTime(now); - emit syncHistoryFinished(true); -} - - -// --------------------------------------------------------------------------------------- - - void SyncManager::syncPasswords() { - kDebug() << "syncing now..."; - - if (!syncRelativeEnabled(ReKonfig::syncPasswords())) - return; - - KIO::Job *job = KIO::file_copy(_localPasswordsUrl, _remotePasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); -} - - -void SyncManager::onPasswordsStatFinished(KJob *job) -{ - if (job->error()) - { - KIO::Job *job = KIO::file_copy(_localPasswordsUrl, _remotePasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); - } - else - { - KIO::Job *job = KIO::file_copy(_remotePasswordsUrl, _localPasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); - connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); - } -} - - -void SyncManager::onPasswordsSyncFinished(KJob *job) -{ - if (job->error()) - { - job->uiDelegate()->showErrorMessage(); - emit syncPasswordsFinished(false); - return; - } - - QDateTime now = QDateTime::currentDateTime(); - ReKonfig::setLastSyncDateTime(now); - emit syncPasswordsFinished(true); + _syncImplementation.data()->syncPasswords(); } diff --git a/src/sync/syncmanager.h b/src/sync/syncmanager.h index 82fd3551..98536603 100644 --- a/src/sync/syncmanager.h +++ b/src/sync/syncmanager.h @@ -31,14 +31,12 @@ // Rekonq Includes #include "rekonq_defines.h" +// Local Includes +#include "synchandler.h" + // Qt Includes #include <QObject> - -// KDE Includes -#include <KUrl> - -// Forward Declarations -class KJob; +#include <QWeakPointer> class REKONQ_TESTS_EXPORT SyncManager : public QObject @@ -47,8 +45,9 @@ class REKONQ_TESTS_EXPORT SyncManager : public QObject public: SyncManager(QObject *parent = 0); - - void firstTimeSync(); + ~SyncManager(); + + void resetSyncer(); public Q_SLOTS: void syncBookmarks(); @@ -59,33 +58,8 @@ private Q_SLOTS: void loadSettings(); void showSettings(); - void onBookmarksSyncFinished(KJob *); - void onBookmarksStatFinished(KJob *); - - void onHistorySyncFinished(KJob *); - void onHistoryStatFinished(KJob *); - - void onPasswordsSyncFinished(KJob *); - void onPasswordsStatFinished(KJob *); - -Q_SIGNALS: - void syncBookmarksFinished(bool); - void syncHistoryFinished(bool); - void syncPasswordsFinished(bool); - private: - bool syncRelativeEnabled(bool); - - bool _firstTimeSynced; - - QUrl _remoteBookmarksUrl; - KUrl _localBookmarksUrl; - - QUrl _remoteHistoryUrl; - KUrl _localHistoryUrl; - - QUrl _remotePasswordsUrl; - KUrl _localPasswordsUrl; + QWeakPointer<SyncHandler> _syncImplementation; }; #endif // SYNC_MANAGER_H diff --git a/src/sync/syncwidget.cpp b/src/sync/syncwidget.cpp index a7adfd3d..f1e79da6 100644 --- a/src/sync/syncwidget.cpp +++ b/src/sync/syncwidget.cpp @@ -80,7 +80,7 @@ void SyncWidget::save() ReKonfig::setSyncPath(kcfg_syncPath->text()); ReKonfig::setSyncPort(kcfg_syncPort->value()); - rApp->syncManager()->firstTimeSync(); + rApp->syncManager()->resetSyncer(); } @@ -118,7 +118,7 @@ void SyncWidget::setSyncLabel(const QDateTime &dt) void SyncWidget::syncNow() { - rApp->syncManager()->firstTimeSync(); + rApp->syncManager()->resetSyncer(); // TODO do something in the sync UI... } |