From c2bbd9066ae8b6902d51b8d9782702252eec5d95 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 9 Dec 2011 15:29:56 +0100 Subject: Sync improvements, last bunch! Improved code division (it will be super easy now adding a new handler) Added a new config UI (QWizard based) --- src/sync/ftpsynchandler.cpp | 83 +++++++++++------ src/sync/ftpsynchandler.h | 8 +- src/sync/settings_sync.ui | 163 --------------------------------- src/sync/sync_check.ui | 152 +++++++++++++++++++++++++++++++ src/sync/sync_data.ui | 74 +++++++++++++++ src/sync/sync_ftp_settings.ui | 105 ++++++++++++++++++++++ src/sync/sync_host_type.ui | 57 ++++++++++++ src/sync/syncassistant.cpp | 48 ++++++++++ src/sync/syncassistant.h | 51 +++++++++++ src/sync/synccheckwidget.cpp | 179 +++++++++++++++++++++++++++++++++++++ src/sync/synccheckwidget.h | 53 +++++++++++ src/sync/syncdatawidget.cpp | 92 +++++++++++++++++++ src/sync/syncdatawidget.h | 64 +++++++++++++ src/sync/syncftpsettingswidget.cpp | 63 +++++++++++++ src/sync/syncftpsettingswidget.h | 51 +++++++++++ src/sync/synchandler.cpp | 41 +++++++++ src/sync/synchandler.h | 19 ++-- src/sync/synchosttypewidget.cpp | 64 +++++++++++++ src/sync/synchosttypewidget.h | 51 +++++++++++ src/sync/syncmanager.cpp | 35 +++----- src/sync/syncmanager.h | 8 +- src/sync/syncwidget.cpp | 124 ------------------------- src/sync/syncwidget.h | 65 -------------- 23 files changed, 1235 insertions(+), 415 deletions(-) delete mode 100644 src/sync/settings_sync.ui create mode 100644 src/sync/sync_check.ui create mode 100644 src/sync/sync_data.ui create mode 100644 src/sync/sync_ftp_settings.ui create mode 100644 src/sync/sync_host_type.ui create mode 100644 src/sync/syncassistant.cpp create mode 100644 src/sync/syncassistant.h create mode 100644 src/sync/synccheckwidget.cpp create mode 100644 src/sync/synccheckwidget.h create mode 100644 src/sync/syncdatawidget.cpp create mode 100644 src/sync/syncdatawidget.h create mode 100644 src/sync/syncftpsettingswidget.cpp create mode 100644 src/sync/syncftpsettingswidget.h create mode 100644 src/sync/synchandler.cpp create mode 100644 src/sync/synchosttypewidget.cpp create mode 100644 src/sync/synchosttypewidget.h delete mode 100644 src/sync/syncwidget.cpp delete mode 100644 src/sync/syncwidget.h (limited to 'src/sync') diff --git a/src/sync/ftpsynchandler.cpp b/src/sync/ftpsynchandler.cpp index e5170964..cfa0c4b5 100644 --- a/src/sync/ftpsynchandler.cpp +++ b/src/sync/ftpsynchandler.cpp @@ -36,18 +36,22 @@ #include #include -#include FTPSyncHandler::FTPSyncHandler(QObject *parent) : SyncHandler(parent) - , _firstTimeSynced(false) { } -void FTPSyncHandler::firstTimeSync() +void FTPSyncHandler::initialLoadAndCheck() { + if (!ReKonfig::syncEnabled()) + { + _firstTimeSynced = false; + return; + } + // Bookmarks if (ReKonfig::syncBookmarks()) { @@ -66,8 +70,6 @@ void FTPSyncHandler::firstTimeSync() KIO::StatJob *job = KIO::stat(_remoteBookmarksUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksStatFinished(KJob *))); - - _firstTimeSynced = true; } // History @@ -88,8 +90,6 @@ void FTPSyncHandler::firstTimeSync() KIO::StatJob *job = KIO::stat(_remoteHistoryUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistoryStatFinished(KJob *))); - - _firstTimeSynced = true; } // Passwords @@ -110,8 +110,6 @@ void FTPSyncHandler::firstTimeSync() KIO::StatJob *job = KIO::stat(_remotePasswordsUrl, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsStatFinished(KJob *))); - - _firstTimeSynced = true; } } @@ -122,11 +120,7 @@ bool FTPSyncHandler::syncRelativeEnabled(bool check) return false; if (!_firstTimeSynced) - { - kDebug() << "need to sync for the first time..."; - firstTimeSync(); return false; - } return check; } @@ -151,13 +145,26 @@ 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 *))); + if (job->error() == KIO::ERR_DOES_NOT_EXIST) + { + KIO::Job *job = KIO::file_copy(_localBookmarksUrl, _remoteBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); + + emit syncStatus(Rekonq::Bookmarks, true, i18n("Remote bookmarks file does NOT exists. Exporting local copy...")); + _firstTimeSynced = true; + } + else + { + emit syncStatus(Rekonq::Bookmarks, false, job->errorString()); + } } else { KIO::Job *job = KIO::file_copy(_remoteBookmarksUrl, _localBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *))); + + emit syncStatus(Rekonq::Bookmarks, true, i18n("Remote bookmarks file exists! Syncing local copy...")); + _firstTimeSynced = true; } } @@ -166,13 +173,11 @@ void FTPSyncHandler::onBookmarksSyncFinished(KJob *job) { if (job->error()) { - job->uiDelegate()->showErrorMessage(); + emit syncStatus(Rekonq::Bookmarks, false, job->errorString()); emit syncBookmarksFinished(false); return; } - QDateTime now = QDateTime::currentDateTime(); - ReKonfig::setLastSyncDateTime(now); emit syncBookmarksFinished(true); } @@ -196,13 +201,26 @@ 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 *))); + if (job->error() == KIO::ERR_DOES_NOT_EXIST) + { + KIO::Job *job = KIO::file_copy(_localHistoryUrl, _remoteHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); + + emit syncStatus(Rekonq::History, true, i18n("Remote history file does NOT exists. Exporting local copy...")); + _firstTimeSynced = true; + } + else + { + emit syncStatus(Rekonq::History, false, job->errorString()); + } } else { KIO::Job *job = KIO::file_copy(_remoteHistoryUrl, _localHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *))); + + emit syncStatus(Rekonq::History, true, i18n("Remote history file exists! Syncing local copy...")); + _firstTimeSynced = true; } } @@ -211,13 +229,11 @@ void FTPSyncHandler::onHistorySyncFinished(KJob *job) { if (job->error()) { - job->uiDelegate()->showErrorMessage(); + emit syncStatus(Rekonq::History, false, job->errorString()); emit syncHistoryFinished(false); return; } - QDateTime now = QDateTime::currentDateTime(); - ReKonfig::setLastSyncDateTime(now); emit syncHistoryFinished(true); } @@ -241,13 +257,26 @@ 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 *))); + if (job->error() == KIO::ERR_DOES_NOT_EXIST) + { + KIO::Job *job = KIO::file_copy(_localPasswordsUrl, _remotePasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); + + emit syncStatus(Rekonq::Passwords, true, i18n("Remote passwords file does NOT exists. Exporting local copy...")); + _firstTimeSynced = true; + } + else + { + emit syncStatus(Rekonq::Passwords, false, job->errorString()); + } } else { KIO::Job *job = KIO::file_copy(_remotePasswordsUrl, _localPasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite); connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *))); + + emit syncStatus(Rekonq::Passwords, true, i18n("Remote passwords file exists! Syncing local copy...")); + _firstTimeSynced = true; } } @@ -256,12 +285,10 @@ void FTPSyncHandler::onPasswordsSyncFinished(KJob *job) { if (job->error()) { - job->uiDelegate()->showErrorMessage(); + emit syncStatus(Rekonq::Passwords, false, job->errorString()); 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 index 2620e89d..2cb1227a 100644 --- a/src/sync/ftpsynchandler.h +++ b/src/sync/ftpsynchandler.h @@ -41,7 +41,7 @@ class KJob; class FTPSyncHandler : public SyncHandler { Q_OBJECT - + public: FTPSyncHandler(QObject *parent = 0); @@ -49,8 +49,8 @@ public: void syncBookmarks(); void syncPasswords(); - void firstTimeSync(); - + void initialLoadAndCheck(); + private Q_SLOTS: void onBookmarksSyncFinished(KJob *); void onBookmarksStatFinished(KJob *); @@ -77,8 +77,6 @@ private: QUrl _remotePasswordsUrl; KUrl _localPasswordsUrl; - - bool _firstTimeSynced; }; #endif // FTP_SYNC_HANDLER_H diff --git a/src/sync/settings_sync.ui b/src/sync/settings_sync.ui deleted file mode 100644 index 8f6e4387..00000000 --- a/src/sync/settings_sync.ui +++ /dev/null @@ -1,163 +0,0 @@ - - - Sync - - - - 0 - 0 - 378 - 369 - - - - - 300 - 0 - - - - - - - Activate sync - - - - - - - sync - - - - - - bookmarks - - - - - - - history - - - - - - - passwords - - - - - - - - - - remote host settings - - - - - - Server: - - - - - - - - - - Username: - - - - - - - - - - Password: - - - - - - - - - - - - - Path: - - - - - - - - - - Port: - - - - - - - - - - - - Last sync: NEVER - - - - - - - Sync now! - - - - - - - - - Qt::Vertical - - - - 20 - 50 - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - KIntNumInput - QWidget -
knuminput.h
-
-
- - -
diff --git a/src/sync/sync_check.ui b/src/sync/sync_check.ui new file mode 100644 index 00000000..dcd7aee7 --- /dev/null +++ b/src/sync/sync_check.ui @@ -0,0 +1,152 @@ + + + SyncCheck + + + + 0 + 0 + 645 + 464 + + + + Form + + + + + + data + + + + + + sync handler + + + + + + + TextLabel + + + + + + + Host + + + + + + + TextLabel + + + + + + + + + + check + + + + + + Bookmarks + + + + + + + true + + + + + + + + + + History + + + + + + + + + + + + + + true + + + + + + + + + + Passwords + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 154 + + + + + + + + + diff --git a/src/sync/sync_data.ui b/src/sync/sync_data.ui new file mode 100644 index 00000000..53b98057 --- /dev/null +++ b/src/sync/sync_data.ui @@ -0,0 +1,74 @@ + + + SyncData + + + + 0 + 0 + 378 + 369 + + + + + 300 + 0 + + + + + + + Activate sync + + + + + + + sync + + + + + + bookmarks + + + + + + + history + + + + + + + passwords + + + + + + + + + + Qt::Vertical + + + + 20 + 50 + + + + + + + + + diff --git a/src/sync/sync_ftp_settings.ui b/src/sync/sync_ftp_settings.ui new file mode 100644 index 00000000..a6a7e3af --- /dev/null +++ b/src/sync/sync_ftp_settings.ui @@ -0,0 +1,105 @@ + + + SyncFTPSettings + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + remote FTP host settings + + + + + + Server: + + + + + + + + + + Username: + + + + + + + + + + Password: + + + + + + + + + + + + + Path: + + + + + + + + + + Port: + + + + + + + + + + Qt::Vertical + + + + 20 + 124 + + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+ + KIntNumInput + QWidget +
knuminput.h
+
+
+ + +
diff --git a/src/sync/sync_host_type.ui b/src/sync/sync_host_type.ui new file mode 100644 index 00000000..76815cb7 --- /dev/null +++ b/src/sync/sync_host_type.ui @@ -0,0 +1,57 @@ + + + SyncHostType + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + sync host type + + + + + + FTP + + + + + + + /dev/null + + + + + + + + + + Qt::Vertical + + + + 20 + 204 + + + + + + + + + diff --git a/src/sync/syncassistant.cpp b/src/sync/syncassistant.cpp new file mode 100644 index 00000000..8688d7bc --- /dev/null +++ b/src/sync/syncassistant.cpp @@ -0,0 +1,48 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "syncassistant.h" +#include "syncassistant.moc" + +// Local Includes +#include "synccheckwidget.h" +#include "syncdatawidget.h" +#include "synchosttypewidget.h" + +#include "syncftpsettingswidget.h" + + +SyncAssistant::SyncAssistant(QWidget *parent) + : QWizard(parent) +{ + setWindowTitle(i18n("sync assistant")); + + setPage(Page_Data, new SyncDataWidget(this)); + setPage(Page_Type, new SyncHostTypeWidget(this)); + setPage(Page_FTP_Settings, new SyncFTPSettingsWidget(this)); + setPage(Page_Check, new SyncCheckWidget(this)); +} diff --git a/src/sync/syncassistant.h b/src/sync/syncassistant.h new file mode 100644 index 00000000..01b9647f --- /dev/null +++ b/src/sync/syncassistant.h @@ -0,0 +1,51 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef SYNC_ASSISTANT_H +#define SYNC_ASSISTANT_H + + +// KDE Includes +#include + + +class SyncAssistant : public QWizard +{ + Q_OBJECT + +public: + enum + { + Page_Data, + Page_Type, + Page_FTP_Settings, + Page_Check + }; + + SyncAssistant(QWidget *parent = 0); +}; + +#endif diff --git a/src/sync/synccheckwidget.cpp b/src/sync/synccheckwidget.cpp new file mode 100644 index 00000000..92cce8a8 --- /dev/null +++ b/src/sync/synccheckwidget.cpp @@ -0,0 +1,179 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "synccheckwidget.h" +#include "synccheckwidget.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "syncassistant.h" +#include "syncmanager.h" + +#include "application.h" + +// KDE Includes +#include +#include + +// Qt Includes +#include + + +SyncCheckWidget::SyncCheckWidget(QWidget *parent) + : QWizardPage(parent) +{ + setupUi(this); +} + + +void SyncCheckWidget::initializePage() +{ + // set initial values + if (ReKonfig::syncType() == 0) + { + syncLabel->setText(i18n("FTP")); + hostLabel->setText(ReKonfig::syncHost()); + } + else + { + syncLabel->setText(i18n("No sync")); + hostLabel->setText(i18n("none")); + } + + bkMsgLabel->setText(QString()); + hsMsgLabel->setText(QString()); + psMsgLabel->setText(QString()); + + KIcon notSyncedIcon(QL1S("dialog-cancel")); + + if (!ReKonfig::syncEnabled()) + { + bkLabel->setPixmap(notSyncedIcon.pixmap(16)); + hsLabel->setPixmap(notSyncedIcon.pixmap(16)); + psLabel->setPixmap(notSyncedIcon.pixmap(16)); + return; + } + + QString loadingGitPath = KStandardDirs::locate("appdata" , "pics/loading.mng"); + + // bookmarks + if (ReKonfig::syncBookmarks()) + { + QMovie *movie = new QMovie(loadingGitPath, QByteArray(), bkLabel); + movie->setSpeed(50); + bkLabel->setMovie(movie); + movie->start(); + } + else + { + bkLabel->setPixmap(notSyncedIcon.pixmap(16)); + } + + // history + if (ReKonfig::syncHistory()) + { + QMovie *movie = new QMovie(loadingGitPath, QByteArray(), hsLabel); + movie->setSpeed(50); + hsLabel->setMovie(movie); + movie->start(); + } + else + { + hsLabel->setPixmap(notSyncedIcon.pixmap(16)); + } + + // passwords + if (ReKonfig::syncPasswords()) + { + QMovie *movie = new QMovie(loadingGitPath, QByteArray(), psLabel); + movie->setSpeed(50); + psLabel->setMovie(movie); + movie->start(); + } + else + { + psLabel->setPixmap(notSyncedIcon.pixmap(16)); + } + + // Now, load syncManager settings... + rApp->syncManager()->loadSettings(); + + SyncHandler *h = rApp->syncManager()->handler(); + connect(h, SIGNAL(syncStatus(Rekonq::SyncData, bool, QString)), this, SLOT(updateWidget(Rekonq::SyncData, bool, QString))); +} + + +void SyncCheckWidget::updateWidget(Rekonq::SyncData type, bool done, QString msg) +{ + KIcon doneIcon(QL1S("dialog-ok-apply")); + KIcon failIcon(QL1S("edit-delete")); + + switch (type) + { + case Rekonq::Bookmarks: + if (done) + { + bkLabel->setPixmap(doneIcon.pixmap(16)); + } + else + { + bkLabel->setPixmap(failIcon.pixmap(16)); + } + bkMsgLabel->setText(msg); + break; + + case Rekonq::History: + if (done) + { + hsLabel->setPixmap(doneIcon.pixmap(16)); + } + else + { + hsLabel->setPixmap(failIcon.pixmap(16)); + } + hsMsgLabel->setText(msg); + break; + + case Rekonq::Passwords: + if (done) + { + psLabel->setPixmap(doneIcon.pixmap(16)); + } + else + { + psLabel->setPixmap(failIcon.pixmap(16)); + } + psMsgLabel->setText(msg); + break; + + default: + // nothing to do here... + break; + }; +} diff --git a/src/sync/synccheckwidget.h b/src/sync/synccheckwidget.h new file mode 100644 index 00000000..5cec1591 --- /dev/null +++ b/src/sync/synccheckwidget.h @@ -0,0 +1,53 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef SYNC_CHECK_WIDGET_H +#define SYNC_CHECK_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_sync_check.h" + +// Qt Includes +#include + + +class SyncCheckWidget : public QWizardPage, private Ui::SyncCheck +{ + Q_OBJECT + +public: + SyncCheckWidget(QWidget *parent = 0); + void initializePage(); + +private Q_SLOTS: + void updateWidget(Rekonq::SyncData, bool, QString); +}; + +#endif // SYNC_CHECK_WIDGET_H diff --git a/src/sync/syncdatawidget.cpp b/src/sync/syncdatawidget.cpp new file mode 100644 index 00000000..8b6ca8e3 --- /dev/null +++ b/src/sync/syncdatawidget.cpp @@ -0,0 +1,92 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "syncdatawidget.h" +#include "syncdatawidget.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "syncmanager.h" +#include "syncassistant.h" + + +SyncDataWidget::SyncDataWidget(QWidget *parent) + : QWizardPage(parent) + , _changed(false) +{ + setupUi(this); + + kcfg_syncEnabled->setChecked(ReKonfig::syncEnabled()); + + kcfg_syncBookmarks->setChecked(ReKonfig::syncBookmarks()); + kcfg_syncHistory->setChecked(ReKonfig::syncHistory()); + kcfg_syncPasswords->setChecked(ReKonfig::syncPasswords()); + + bool isSyncEnabled = ReKonfig::syncEnabled(); + enablewidgets(isSyncEnabled); + + connect(kcfg_syncEnabled, SIGNAL(clicked()), this, SLOT(hasChanged())); +} + + +bool SyncDataWidget::changed() +{ + return _changed; +} + + +void SyncDataWidget::hasChanged() +{ + enablewidgets(kcfg_syncEnabled->isChecked()); + + _changed = true; + emit changed(true); +} + + +void SyncDataWidget::enablewidgets(bool b) +{ + syncGroupBox->setEnabled(b); +} + + +int SyncDataWidget::nextId() const +{ + // save + ReKonfig::setSyncEnabled(kcfg_syncEnabled->isChecked()); + + ReKonfig::setSyncBookmarks(kcfg_syncBookmarks->isChecked()); + ReKonfig::setSyncHistory(kcfg_syncHistory->isChecked()); + ReKonfig::setSyncPasswords(kcfg_syncPasswords->isChecked()); + + if (ReKonfig::syncEnabled()) + return SyncAssistant::Page_Type; + else + return SyncAssistant::Page_Check; +} diff --git a/src/sync/syncdatawidget.h b/src/sync/syncdatawidget.h new file mode 100644 index 00000000..30d1ae34 --- /dev/null +++ b/src/sync/syncdatawidget.h @@ -0,0 +1,64 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef SYNC_DATA_WIDGET_H +#define SYNC_DATA_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_sync_data.h" + +// Qt Includes +#include + + +class SyncDataWidget : public QWizardPage, private Ui::SyncData +{ + Q_OBJECT + +public: + SyncDataWidget(QWidget *parent = 0); + + int nextId() const; + + bool changed(); + +Q_SIGNALS: + void changed(bool); + +private Q_SLOTS: + void hasChanged(); + +private: + void enablewidgets(bool); + + bool _changed; +}; + +#endif // SYNC_WIDGET_H diff --git a/src/sync/syncftpsettingswidget.cpp b/src/sync/syncftpsettingswidget.cpp new file mode 100644 index 00000000..31660843 --- /dev/null +++ b/src/sync/syncftpsettingswidget.cpp @@ -0,0 +1,63 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "syncftpsettingswidget.h" +#include "syncftpsettingswidget.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "syncassistant.h" + + +SyncFTPSettingsWidget::SyncFTPSettingsWidget(QWidget *parent) + : QWizardPage(parent) +{ + setupUi(this); + + kcfg_syncHost->setText(ReKonfig::syncHost()); + kcfg_syncUser->setText(ReKonfig::syncUser()); + kcfg_syncPass->setText(ReKonfig::syncPass()); + kcfg_syncPath->setText(ReKonfig::syncPath()); + kcfg_syncPort->setValue(ReKonfig::syncPort()); + + kcfg_syncPass->setPasswordMode(true); +} + + +int SyncFTPSettingsWidget::nextId() const +{ + // save + ReKonfig::setSyncHost(kcfg_syncHost->text()); + ReKonfig::setSyncUser(kcfg_syncUser->text()); + ReKonfig::setSyncPass(kcfg_syncPass->text()); + ReKonfig::setSyncPath(kcfg_syncPath->text()); + ReKonfig::setSyncPort(kcfg_syncPort->value()); + + return SyncAssistant::Page_Check; +} diff --git a/src/sync/syncftpsettingswidget.h b/src/sync/syncftpsettingswidget.h new file mode 100644 index 00000000..d067eef4 --- /dev/null +++ b/src/sync/syncftpsettingswidget.h @@ -0,0 +1,51 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef SYNC_FTP_SETTINGS_WIDGET_H +#define SYNC_FTP_SETTINGS_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_sync_ftp_settings.h" + +// Qt Includes +#include + + +class SyncFTPSettingsWidget : public QWizardPage, private Ui::SyncFTPSettings +{ + Q_OBJECT + +public: + SyncFTPSettingsWidget(QWidget *parent = 0); + + int nextId() const; +}; + +#endif // SYNC_FTP_SETTINGS_WIDGET_H diff --git a/src/sync/synchandler.cpp b/src/sync/synchandler.cpp new file mode 100644 index 00000000..759af064 --- /dev/null +++ b/src/sync/synchandler.cpp @@ -0,0 +1,41 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "synchandler.h" +#include "synchandler.moc" + + +SyncHandler::SyncHandler(QObject *parent) + : QObject(parent) + , _firstTimeSynced(false) +{ +} + + +SyncHandler::~SyncHandler() +{ +} diff --git a/src/sync/synchandler.h b/src/sync/synchandler.h index 30873fa5..32266d7c 100644 --- a/src/sync/synchandler.h +++ b/src/sync/synchandler.h @@ -37,16 +37,25 @@ class SyncHandler : public QObject { - + Q_OBJECT + public: - SyncHandler(QObject *parent = 0) : QObject(parent) {} - virtual ~SyncHandler() {} - + SyncHandler(QObject *parent = 0); + virtual ~SyncHandler(); + virtual void syncHistory() = 0; virtual void syncBookmarks() = 0; virtual void syncPasswords() = 0; - virtual void firstTimeSync() = 0; + virtual void initialLoadAndCheck() = 0; + +Q_SIGNALS: + void syncStatus(Rekonq::SyncData type, bool syncDone, QString message); + +protected: + bool _firstTimeSynced; + + }; #endif // SYNC_HANDLER_H diff --git a/src/sync/synchosttypewidget.cpp b/src/sync/synchosttypewidget.cpp new file mode 100644 index 00000000..0810182e --- /dev/null +++ b/src/sync/synchosttypewidget.cpp @@ -0,0 +1,64 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "synchosttypewidget.h" +#include "synchosttypewidget.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "syncassistant.h" + + +SyncHostTypeWidget::SyncHostTypeWidget(QWidget *parent) + : QWizardPage(parent) +{ + setupUi(this); + + if (ReKonfig::syncType() == 0) + ftpRadioButton->setChecked(true); + else + nullRadioButton->setChecked(true); +} + + +int SyncHostTypeWidget::nextId() const +{ + // save + if (ftpRadioButton->isChecked()) + { + ReKonfig::setSyncType(0); + return SyncAssistant::Page_FTP_Settings; + } + else + { + ReKonfig::setSyncType(1); + return SyncAssistant::Page_Check; + } + +} diff --git a/src/sync/synchosttypewidget.h b/src/sync/synchosttypewidget.h new file mode 100644 index 00000000..66408825 --- /dev/null +++ b/src/sync/synchosttypewidget.h @@ -0,0 +1,51 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef SYNC_HOST_TYPE_WIDGET_H +#define SYNC_HOST_TYPE_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_sync_host_type.h" + +// Qt Includes +#include + + +class SyncHostTypeWidget : public QWizardPage, private Ui::SyncHostType +{ + Q_OBJECT + +public: + SyncHostTypeWidget(QWidget *parent = 0); + + int nextId() const; +}; + +#endif // SYNC_HOST_TYPE_WIDGET_H diff --git a/src/sync/syncmanager.cpp b/src/sync/syncmanager.cpp index 41a60179..efd0ffd3 100644 --- a/src/sync/syncmanager.cpp +++ b/src/sync/syncmanager.cpp @@ -35,7 +35,8 @@ #include "application.h" #include "bookmarkmanager.h" #include "historymanager.h" -#include "syncwidget.h" + +#include "syncassistant.h" #include "ftpsynchandler.h" // KDE Includes @@ -63,7 +64,16 @@ void SyncManager::loadSettings() { if (ReKonfig::syncEnabled()) { - resetSyncer(); + // reset syncer + if (_syncImplementation.isNull()) + { + // actually we have just FTP handler... + _syncImplementation = new FTPSyncHandler(this); + } + + _syncImplementation.data()->initialLoadAndCheck(); + + // --- Connect syncmanager to bookmarks & history manager // bookmarks ReKonfig::syncBookmarks() @@ -92,32 +102,13 @@ void SyncManager::loadSettings() void SyncManager::showSettings() { - QPointer dialog = new KDialog(); - dialog->setCaption(i18nc("@title:window", "Sync Settings")); - dialog->setButtons(KDialog::Ok | KDialog::Cancel); - - SyncWidget widget; - dialog->setMainWidget(&widget); - connect(dialog, SIGNAL(okClicked()), &widget, SLOT(save())); - connect(dialog, SIGNAL(okClicked()), this, SLOT(loadSettings())); + QPointer dialog = new SyncAssistant(); dialog->exec(); dialog->deleteLater(); } -void SyncManager::resetSyncer() -{ - if (_syncImplementation.isNull()) - { - // actually we have just FTP handler... - _syncImplementation = new FTPSyncHandler(this); - } - - _syncImplementation.data()->firstTimeSync(); -} - - // --------------------------------------------------------------------------------------- diff --git a/src/sync/syncmanager.h b/src/sync/syncmanager.h index 98536603..cd7dbefa 100644 --- a/src/sync/syncmanager.h +++ b/src/sync/syncmanager.h @@ -46,15 +46,17 @@ class REKONQ_TESTS_EXPORT SyncManager : public QObject public: SyncManager(QObject *parent = 0); ~SyncManager(); - - void resetSyncer(); + + SyncHandler *handler() const + { + return _syncImplementation.data(); + }; public Q_SLOTS: void syncBookmarks(); void syncHistory(); void syncPasswords(); -private Q_SLOTS: void loadSettings(); void showSettings(); diff --git a/src/sync/syncwidget.cpp b/src/sync/syncwidget.cpp deleted file mode 100644 index f1e79da6..00000000 --- a/src/sync/syncwidget.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011 by Andrea Diamantini -* -* -* 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 . -* -* ============================================================ */ - - -// Self Includes -#include "syncwidget.h" -#include "syncwidget.moc" - -// Auto Includes -#include "rekonq.h" - -// Local Includes -#include "syncmanager.h" -#include "application.h" - - -SyncWidget::SyncWidget(QWidget *parent) - : QWidget(parent) - , _changed(false) -{ - setupUi(this); - - kcfg_syncEnabled->setChecked(ReKonfig::syncEnabled()); - - kcfg_syncBookmarks->setChecked(ReKonfig::syncBookmarks()); - kcfg_syncHistory->setChecked(ReKonfig::syncHistory()); - kcfg_syncPasswords->setChecked(ReKonfig::syncPasswords()); - - kcfg_syncHost->setText(ReKonfig::syncHost()); - kcfg_syncUser->setText(ReKonfig::syncUser()); - kcfg_syncPass->setText(ReKonfig::syncPass()); - kcfg_syncPath->setText(ReKonfig::syncPath()); - kcfg_syncPort->setValue(ReKonfig::syncPort()); - - bool isSyncEnabled = ReKonfig::syncEnabled(); - enablewidgets(isSyncEnabled); - - kcfg_syncPass->setPasswordMode(true); - - connect(kcfg_syncEnabled, SIGNAL(clicked()), this, SLOT(hasChanged())); - connect(syncNowButton, SIGNAL(clicked()), this, SLOT(syncNow())); - - setSyncLabel(ReKonfig::lastSyncDateTime()); -} - - -void SyncWidget::save() -{ - ReKonfig::setSyncEnabled(kcfg_syncEnabled->isChecked()); - - ReKonfig::setSyncBookmarks(kcfg_syncBookmarks->isChecked()); - ReKonfig::setSyncHistory(kcfg_syncHistory->isChecked()); - ReKonfig::setSyncPasswords(kcfg_syncPasswords->isChecked()); - - ReKonfig::setSyncHost(kcfg_syncHost->text()); - ReKonfig::setSyncUser(kcfg_syncUser->text()); - ReKonfig::setSyncPass(kcfg_syncPass->text()); - ReKonfig::setSyncPath(kcfg_syncPath->text()); - ReKonfig::setSyncPort(kcfg_syncPort->value()); - - rApp->syncManager()->resetSyncer(); -} - - -bool SyncWidget::changed() -{ - return _changed; -} - - -void SyncWidget::hasChanged() -{ - enablewidgets(kcfg_syncEnabled->isChecked()); - - _changed = true; - emit changed(true); -} - - -void SyncWidget::enablewidgets(bool b) -{ - syncGroupBox->setEnabled(b); - ownCloudGroupBox->setEnabled(b); - syncNowButton->setEnabled(b); -} - - -void SyncWidget::setSyncLabel(const QDateTime &dt) -{ - if (dt.isNull()) - lastSyncTimeLabel->setText(i18n("Last Sync: NEVER!")); - else - lastSyncTimeLabel->setText(i18n("Last Sync: %1", dt.toString(Qt::DefaultLocaleShortDate))); -} - - -void SyncWidget::syncNow() -{ - rApp->syncManager()->resetSyncer(); - - // TODO do something in the sync UI... -} diff --git a/src/sync/syncwidget.h b/src/sync/syncwidget.h deleted file mode 100644 index 8621eae1..00000000 --- a/src/sync/syncwidget.h +++ /dev/null @@ -1,65 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011 by Andrea Diamantini -* -* -* 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 . -* -* ============================================================ */ - - -#ifndef SYNC_WIDGET_H -#define SYNC_WIDGET_H - - -// Rekonq Includes -#include "rekonq_defines.h" - -// Ui Includes -#include "ui_settings_sync.h" - -// Qt Includes -#include - - -class SyncWidget : public QWidget, private Ui::Sync -{ - Q_OBJECT - -public: - SyncWidget(QWidget *parent = 0); - - bool changed(); - -Q_SIGNALS: - void changed(bool); - -private Q_SLOTS: - void save(); - void hasChanged(); - void syncNow(); - -private: - void enablewidgets(bool); - void setSyncLabel(const QDateTime &); - - bool _changed; -}; - -#endif // SYNC_WIDGET_H -- cgit v1.2.1