summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-11-11 01:17:14 +0100
committerAndrea Diamantini <adjam7@gmail.com>2011-12-12 16:40:28 +0100
commit9ba3dec3e263b6d8a039092a976ae0cc4f625c87 (patch)
treea222be9af259ab589c6ddbc861d84bc1a8a8ee2d /src
parent(really) fix handling of overwrite, by KIO delegating it (diff)
downloadrekonq-9ba3dec3e263b6d8a039092a976ae0cc4f625c87.tar.xz
Sync feature, first bits
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/application.cpp18
-rw-r--r--src/application.h3
-rw-r--r--src/rekonq.kcfg28
-rw-r--r--src/sync/settings_sync.ui132
-rw-r--r--src/sync/syncmanager.cpp278
-rw-r--r--src/sync/syncmanager.h85
-rw-r--r--src/sync/syncwidget.cpp101
-rw-r--r--src/sync/syncwidget.h65
9 files changed, 715 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ea33df82..f8a6124a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -92,6 +92,9 @@ SET( rekonq_KDEINIT_SRCS
useragent/useragentinfo.cpp
useragent/useragentmanager.cpp
useragent/useragentwidget.cpp
+ #----------------------------------------
+ sync/syncmanager.cpp
+ sync/syncwidget.cpp
)
@@ -105,6 +108,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS
sslinfo.ui
webappcreation.ui
useragent/useragentsettings.ui
+ sync/settings_sync.ui
)
KDE4_ADD_KCFG_FILES( rekonq_KDEINIT_SRCS rekonq.kcfgc )
@@ -119,6 +123,7 @@ INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/history
${CMAKE_CURRENT_SOURCE_DIR}/opensearch
${CMAKE_CURRENT_SOURCE_DIR}/settings
+ ${CMAKE_CURRENT_SOURCE_DIR}/sync
${CMAKE_CURRENT_SOURCE_DIR}/urlbar
${CMAKE_CURRENT_SOURCE_DIR}/useragent
${CMAKE_CURRENT_BINARY_DIR}
diff --git a/src/application.cpp b/src/application.cpp
index 9dd98a49..768f25a2 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -47,6 +47,7 @@
#include "mainwindow.h"
#include "opensearchmanager.h"
#include "sessionmanager.h"
+#include "syncmanager.h"
#include "stackedurlbar.h"
#include "tabbar.h"
#include "urlbar.h"
@@ -150,6 +151,13 @@ Application::~Application()
m_userAgentManager.clear();
}
+ if (!m_syncManager.isNull())
+ {
+ kDebug() << "deleting sync manager";
+ delete m_syncManager.data();
+ m_syncManager.clear();
+ }
+
// TODO:
// add a check to NOT close rekonq
// until last download is finished
@@ -403,6 +411,16 @@ UserAgentManager *Application::userAgentManager()
}
+SyncManager *Application::syncManager()
+{
+ if (m_syncManager.isNull())
+ {
+ m_syncManager = new SyncManager(instance());
+ }
+ return m_syncManager.data();
+}
+
+
void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
{
if (url.isEmpty())
diff --git a/src/application.h b/src/application.h
index 27b46e92..6a67ca61 100644
--- a/src/application.h
+++ b/src/application.h
@@ -53,6 +53,7 @@ class MainWindow;
class OpenSearchManager;
class SessionManager;
class UserAgentManager;
+class SyncManager;
class KAction;
@@ -96,6 +97,7 @@ public:
IconManager *iconManager();
DownloadManager *downloadManager();
UserAgentManager *userAgentManager();
+ SyncManager *syncManager();
KAction *privateBrowsingAction()
{
@@ -142,6 +144,7 @@ private:
QWeakPointer<IconManager> m_iconManager;
QWeakPointer<DownloadManager> m_downloadManager;
QWeakPointer<UserAgentManager> m_userAgentManager;
+ QWeakPointer<SyncManager> m_syncManager;
MainWindowList m_mainWindows;
diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg
index 73a82efc..c84265e0 100644
--- a/src/rekonq.kcfg
+++ b/src/rekonq.kcfg
@@ -256,4 +256,32 @@
</entry>
</group>
+<!-- Sync Settings -->
+<group name="Sync">
+ <entry name="syncEnabled" type="Bool">
+ <default>false</default>
+ </entry>
+ <entry name="syncBookmarks" type="Bool">
+ <default>false</default>
+ </entry>
+ <entry name="syncHistory" type="Bool">
+ <default>false</default>
+ </entry>
+ <entry name="syncPasswords" type="Bool">
+ <default>false</default>
+ </entry>
+ <entry name="syncHost" type="String">
+ <default></default>
+ </entry>
+ <entry name="syncUser" type="String">
+ <default></default>
+ </entry>
+ <entry name="syncPass" type="String">
+ <default></default>
+ </entry>
+ <entry name="lastSyncDateTime" type="DateTime">
+ <default></default>
+ </entry>
+</group>
+
</kcfg>
diff --git a/src/sync/settings_sync.ui b/src/sync/settings_sync.ui
new file mode 100644
index 00000000..35415f53
--- /dev/null
+++ b/src/sync/settings_sync.ui
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Sync</class>
+ <widget class="QWidget" name="Sync">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>633</width>
+ <height>551</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="kcfg_syncEnabled">
+ <property name="text">
+ <string>Activate sync</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="syncGroupBox">
+ <property name="title">
+ <string>sync</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QCheckBox" name="kcfg_syncBookmarks">
+ <property name="text">
+ <string>bookmarks</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="kcfg_syncHistory">
+ <property name="text">
+ <string>history</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="kcfg_syncPasswords">
+ <property name="text">
+ <string>passwords</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="ownCloudGroupBox">
+ <property name="title">
+ <string>ownCloud settings</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>host:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="KLineEdit" name="kcfg_syncHost"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>username:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="KLineEdit" name="kcfg_syncUser"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="KLineEdit" name="kcfg_syncPass"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="lastSyncTimeLabel">
+ <property name="text">
+ <string>Last sync: NEVER</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="syncNowButton">
+ <property name="text">
+ <string>Sync now!</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>289</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/sync/syncmanager.cpp b/src/sync/syncmanager.cpp
new file mode 100644
index 00000000..cf3f2df7
--- /dev/null
+++ b/src/sync/syncmanager.cpp
@@ -0,0 +1,278 @@
+/* ============================================================
+*
+* 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 "syncmanager.h"
+#include "syncmanager.moc"
+
+// Auto Includes
+#include "rekonq.h"
+
+// KDE Includes
+#include <KStandardDirs>
+#include <KMessageBox>
+#include <klocalizedstring.h>
+
+#include <KIO/Job>
+#include <KIO/JobUiDelegate>
+
+
+SyncManager::SyncManager(QObject *parent)
+ : QObject(parent)
+ , _firstTimeSynced(false)
+{
+ if (ReKonfig::syncEnabled())
+ {
+ // sync every minute
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(sync()));
+ timer->start(60 * 1000);
+ }
+}
+
+
+SyncManager::~SyncManager()
+{
+ sync();
+}
+
+
+void SyncManager::firstTimeSync()
+{
+ // Bookmarks
+ if (ReKonfig::syncBookmarks())
+ {
+ _remoteBookmarksUrl = QUrl(ReKonfig::syncHost());
+ _remoteBookmarksUrl.setUserName(ReKonfig::syncUser());
+ _remoteBookmarksUrl.setPassword(ReKonfig::syncPass());
+ _remoteBookmarksUrl.setPath(QL1S("/data/") + ReKonfig::syncUser() + QL1S("/files/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(ReKonfig::syncHost());
+ _remoteHistoryUrl.setUserName(ReKonfig::syncUser());
+ _remoteHistoryUrl.setPassword(ReKonfig::syncPass());
+ _remoteHistoryUrl.setPath(QL1S("/data/") + ReKonfig::syncUser() + QL1S("/files/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(ReKonfig::syncHost());
+ _remotePasswordsUrl.setUserName(ReKonfig::syncUser());
+ _remotePasswordsUrl.setPassword(ReKonfig::syncPass());
+ _remotePasswordsUrl.setPath(QL1S("/data/") + ReKonfig::syncUser() + QL1S("/files/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;
+ }
+}
+
+
+void SyncManager::sync()
+{
+ kDebug() << "syncing now...";
+
+ if (!ReKonfig::syncEnabled())
+ return;
+
+ if (!_firstTimeSynced)
+ {
+ kDebug() << "need to sync for the first time...";
+ firstTimeSync();
+ return;
+ }
+
+ // Bookmarks
+ if (ReKonfig::syncBookmarks())
+ {
+ KIO::Job *job = KIO::file_copy(_localBookmarksUrl, _remoteBookmarksUrl, -1, KIO::HideProgressInfo | KIO::Overwrite);
+ connect(job, SIGNAL(finished(KJob *)), this, SLOT(onBookmarksSyncFinished(KJob *)));
+ }
+
+ // History
+ if (ReKonfig::syncHistory())
+ {
+ KIO::Job *job = KIO::file_copy(_localHistoryUrl, _remoteHistoryUrl, -1, KIO::HideProgressInfo | KIO::Overwrite);
+ connect(job, SIGNAL(finished(KJob *)), this, SLOT(onHistorySyncFinished(KJob *)));
+ }
+
+ // Passwords
+ if (ReKonfig::syncPasswords())
+ {
+ KIO::Job *job = KIO::file_copy(_localPasswordsUrl, _remotePasswordsUrl, -1, KIO::HideProgressInfo | KIO::Overwrite);
+ connect(job, SIGNAL(finished(KJob *)), this, SLOT(onPasswordsSyncFinished(KJob *)));
+ }
+}
+
+
+// ---------------------------------------------------------------------------------------
+
+
+void SyncManager::onBookmarksStatFinished(KJob *job)
+{
+ if (job->error() ||
+ KMessageBox::questionYesNo(0,
+ i18n("A remote bookmarks file has just present in your remote server."),
+ i18n("Server notification"),
+ KGuiItem(i18n("Overwrite it")),
+ KGuiItem(i18n("Copy it locally"))
+ )
+ )
+ {
+ 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);
+}
+
+
+// ---------------------------------------------------------------------------------------
+
+
+void SyncManager::onHistoryStatFinished(KJob *job)
+{
+ if (job->error() ||
+ KMessageBox::questionYesNo(0,
+ i18n("A remote history file has just present in your remote server."),
+ i18n("Server notification"),
+ KGuiItem(i18n("Overwrite it")),
+ KGuiItem(i18n("Copy it locally"))
+ )
+ )
+ {
+ 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::onPasswordsStatFinished(KJob *job)
+{
+ if (job->error() ||
+ KMessageBox::questionYesNo(0,
+ i18n("A remote passwords file has just present in your remote server."),
+ i18n("Server notification"),
+ KGuiItem(i18n("Overwrite it")),
+ KGuiItem(i18n("Copy it locally"))
+ )
+ )
+ {
+ 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);
+}
diff --git a/src/sync/syncmanager.h b/src/sync/syncmanager.h
new file mode 100644
index 00000000..3a78191f
--- /dev/null
+++ b/src/sync/syncmanager.h
@@ -0,0 +1,85 @@
+/* ============================================================
+*
+* 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_MANAGER_H
+#define SYNC_MANAGER_H
+
+
+// Rekonq Includes
+#include "rekonq_defines.h"
+
+// Qt Includes
+#include <QObject>
+
+// KDE Includes
+#include <KUrl>
+
+// Forward Declarations
+class KJob;
+
+
+class REKONQ_TESTS_EXPORT SyncManager : public QObject
+{
+ Q_OBJECT
+
+public:
+ SyncManager(QObject *parent = 0);
+ ~SyncManager();
+
+ void firstTimeSync();
+
+public Q_SLOTS:
+ void sync();
+
+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 _firstTimeSynced;
+
+ QUrl _remoteBookmarksUrl;
+ KUrl _localBookmarksUrl;
+
+ QUrl _remoteHistoryUrl;
+ KUrl _localHistoryUrl;
+
+ QUrl _remotePasswordsUrl;
+ KUrl _localPasswordsUrl;
+};
+
+#endif // SYNC_MANAGER_H
diff --git a/src/sync/syncwidget.cpp b/src/sync/syncwidget.cpp
new file mode 100644
index 00000000..c5295c93
--- /dev/null
+++ b/src/sync/syncwidget.cpp
@@ -0,0 +1,101 @@
+/* ============================================================
+*
+* 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 "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);
+
+ 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()
+{
+ rApp->syncManager()->firstTimeSync();
+}
+
+
+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()->firstTimeSync();
+
+ // TODO do something in the sync UI...
+}
+
diff --git a/src/sync/syncwidget.h b/src/sync/syncwidget.h
new file mode 100644
index 00000000..0e1d57ff
--- /dev/null
+++ b/src/sync/syncwidget.h
@@ -0,0 +1,65 @@
+/* ============================================================
+*
+* 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_WIDGET_H
+#define SYNC_WIDGET_H
+
+
+// Rekonq Includes
+#include "rekonq_defines.h"
+
+// Ui Includes
+#include "ui_settings_sync.h"
+
+// Qt Includes
+#include <QtGui/QWidget>
+
+
+class SyncWidget : public QWidget, private Ui::Sync
+{
+ Q_OBJECT
+
+public:
+ SyncWidget(QWidget *parent = 0);
+
+ void save();
+ bool changed();
+
+Q_SIGNALS:
+ void changed(bool);
+
+private Q_SLOTS:
+ void hasChanged();
+ void syncNow();
+
+private:
+ void enablewidgets(bool);
+ void setSyncLabel(const QDateTime &);
+
+ bool _changed;
+};
+
+#endif // SYNC_WIDGET_H