[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bksecretservice=5D_secretsync=3A_We_now_have_sync_da?=
From:       Valentin Rusu <kde () rusu ! info>
Date:       2011-02-13 12:24:39
Message-ID: 20110213122439.2FE0DA60FC () git ! kde ! org
[Download RAW message or body]

Git commit 3335132ef211c0b343e1958ee09e43f297c07eb7 by Valentin Rusu.
Committed on 27/12/2010 at 22:45.
Pushed by vrusu into branch 'master'.

We now have sync daemon skeleton

M  +8    -4    secretsync/CMakeLists.txt     
D  +0    -50   secretsync/computerdata.h     
M  +2    -2    secretsync/computersyncjob.cpp     
M  +2    -2    secretsync/computersyncjob.h     
M  +10   -4    secretsync/kcm/addcomputerdialog.cpp     
M  +14   -12   secretsync/kcm/addcomputerdialog.h     
M  +46   -8    secretsync/kcm/addcomputerwidget.ui     
M  +41   -71   secretsync/kcm/configwidget.cpp     
M  +8    -13   secretsync/kcm/configwidget.h     
M  +35   -50   secretsync/kcm/configwidget.ui     
M  +24   -1    secretsync/kcm/kcm_ksecretsync.kcfg     
M  +30   -8    secretsync/kcm/kcsecretsyncmodule.cpp     
M  +2    -0    secretsync/kcm/ksecretsynccfg.kcfgc     
D  +0    -109  secretsync/ksecretsync.cpp     
D  +0    -56   secretsync/ksecretsync.h     
A  +114  -0    secretsync/ksecretsyncwindow.cpp         [License: GPL (v2/3)]
A  +58   -0    secretsync/ksecretsyncwindow.h         [License: GPL (v2/3)]
M  +2    -2    secretsync/main.cpp     
M  +3    -3    secretsync/statuswidget.ui     
M  +94   -38   secretsync/syncdaemon.cpp     
M  +14   -16   secretsync/syncdaemon.h     
A  +141  -0    secretsync/syncmodel.cpp         [License: GPL (v2/3)]
A  +69   -0    secretsync/syncmodel.h         [License: GPL (v2/3)]
A  +72   -0    secretsync/syncserverjob.cpp         [License: GPL (v2/3)]
A  +51   -0    secretsync/syncserverjob.h         [License: GPL (v2/3)]
A  +22   -0    secretsync/tests/CMakeLists.txt         [License: UNKNOWN]  *
A  +68   -0    secretsync/tests/sslconnectiontest.cpp         [License: GPL (v2/3)]
A  +46   -0    secretsync/tests/sslconnectiontest.h         [License: GPL (v2/3)]

The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.


http://commits.kde.org/ksecretservice/3335132ef211c0b343e1958ee09e43f297c07eb7

diff --git a/secretsync/CMakeLists.txt b/secretsync/CMakeLists.txt
index e4d9d3c..b84e34d 100644
--- a/secretsync/CMakeLists.txt
+++ b/secretsync/CMakeLists.txt
@@ -1,9 +1,6 @@
 PROJECT (ksecretsync)
 
 FIND_PACKAGE (QCA2 REQUIRED)
-FIND_PACKAGE (DBus REQUIRED)
-
-add_definitions(${DBUS_DEFINITIONS})
 
 include(MacroLibrary)
 include(KDE4Defaults)
@@ -21,15 +18,22 @@ INCLUDE_DIRECTORIES (
 #
 add_subdirectory(icons)
 add_subdirectory(kcm)
+add_subdirectory(tests)
 
 SET( ksecretsync_SRCS 
     statuswidget.cpp 
     syncdaemon.cpp 
     syncjob.cpp 
     computersyncjob.cpp 
-    ksecretsync.cpp 
+    ksecretsyncwindow.cpp 
     trayicon.cpp
     main.cpp
+    syncmodel.cpp
+    syncserverjob.cpp
+)
+
+kde4_add_kcfg_files(ksecretsync_SRCS
+     kcm/ksecretsynccfg.kcfgc
 )
 
 KDE4_ADD_UI_FILES ( ksecretsync_SRCS
diff --git a/secretsync/computerdata.h b/secretsync/computerdata.h
deleted file mode 100644
index df979c7..0000000
--- a/secretsync/computerdata.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2010, Valentin Rusu <kde@rusu.info>
- *
- * 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 COMPUTERDATA_H
-#define COMPUTERDATA_H
-
-#include <QDateTime>
-#include <QStringList>
-
-/**
- * Information structure used to manage synchronization with a given computer
- * KSecretSync use one ComputerData for each known computer
- */
-struct ComputerData
-{
-    enum SyncStatus {
-        SYNC_STATUS_NONE,           /// computer data has just been loaded or \
                created and no sync has been tried
-        SYNC_STATUS_PENDING,        /// a sync job was started on this item
-        SYNC_STATUS_DONE,           /// the last sync operation finished \
                successfully
-        SYNC_STATUS_UNREACHABLE,    /// the computer is not reachable
-        SYNC_STATUS_CONFLICTING,    /// the target computer has a conflicting item
-        SYNC_STATUS_ERROR           /// an error occurred during last sync operation
-    };
-    
-    QString     _computerName;
-    QString     _computerAddress;
-    QTime       _lastSyncTime;
-    SyncStatus  _lastSyncStatus;
-    QString     _lastSyncError;
-    QStringList _conflictingItems;
-};
-
-#endif // COMPUTERDATA_H
diff --git a/secretsync/computersyncjob.cpp b/secretsync/computersyncjob.cpp
index bf323d6..bc88845 100644
--- a/secretsync/computersyncjob.cpp
+++ b/secretsync/computersyncjob.cpp
@@ -19,9 +19,9 @@
  */
 
 #include "computersyncjob.h"
-#include "computerdata.h"
+#include "syncmodel.h"
 
-ComputerSyncJob::ComputerSyncJob(QObject* parent, ComputerData& computerData, \
SyncLogger* logger):  +ComputerSyncJob::ComputerSyncJob(QObject* parent, \
ComputerData* computerData, SyncLogger* logger):   KJob(parent), _logger(logger), \
_computerData(computerData)  {
 
diff --git a/secretsync/computersyncjob.h b/secretsync/computersyncjob.h
index 6a25c2c..588b70b 100644
--- a/secretsync/computersyncjob.h
+++ b/secretsync/computersyncjob.h
@@ -30,12 +30,12 @@ class ComputerSyncJob : public KJob
 {
     Q_OBJECT
 public:
-    ComputerSyncJob(QObject* parent, ComputerData& , SyncLogger* logger );
+    ComputerSyncJob(QObject* parent, ComputerData* , SyncLogger* logger );
     virtual void start();
     
 private:
     SyncLogger      *_logger;
-    ComputerData    &_computerData;
+    ComputerData    *_computerData;
 };
 
 #endif // COMPUTERSYNCJOB_H
diff --git a/secretsync/kcm/addcomputerdialog.cpp \
b/secretsync/kcm/addcomputerdialog.cpp index a0468a5..aa8fa45 100644
--- a/secretsync/kcm/addcomputerdialog.cpp
+++ b/secretsync/kcm/addcomputerdialog.cpp
@@ -27,10 +27,12 @@ AddComputerDialog::AddComputerDialog(QWidget* parent, Qt::WFlags \
flags):  {
     setCaption( i18n("Add computer") );
     setButtons( KDialog::Ok | KDialog::Cancel );
-    AddComputerDialogWidget* widget = new AddComputerDialogWidget(this);
-    setMainWidget( widget );
-    connect( widget->_computerName, SIGNAL(textChanged(const QString&)), \
SLOT(computerNameChanged(const QString&)) ); +    _widget = new \
AddComputerDialogWidget(this); +    setMainWidget( _widget );
+    connect( _widget->_computerName, SIGNAL(textChanged(const QString&)), \
SLOT(computerNameChanged(const QString&)) );  enableButtonOk(false);
+    _widget->setFocus();
+    // TODO: add more port validation to this dialog to complete the existing input \
mask validation  }
 
 void AddComputerDialog::computerNameChanged(const QString& computerName )
@@ -40,7 +42,11 @@ void AddComputerDialog::computerNameChanged(const QString& \
computerName )  }
     else
         enableButtonOk(false);
-    _computerName = computerName;
+}
+
+QString AddComputerDialog::computerName() const
+{
+    return QString("%1:%2").arg( _widget->_computerName->text() ).arg( \
_widget->_port->text() );  }
 
 
diff --git a/secretsync/kcm/addcomputerdialog.h b/secretsync/kcm/addcomputerdialog.h
index 1d96bb3..b7f021e 100644
--- a/secretsync/kcm/addcomputerdialog.h
+++ b/secretsync/kcm/addcomputerdialog.h
@@ -24,27 +24,29 @@
 #include <ui_addcomputerwidget.h>
 #include <kdialog.h>
 
+class AddComputerDialogWidget : public QWidget, public Ui_AddComputerWidget
+{
+    Q_OBJECT
+public:
+    AddComputerDialogWidget( QWidget* parent ) : QWidget( parent ) {
+        setupUi(this);
+    }
+    friend class AddComputerDialog;
+};
+
 class AddComputerDialog : public KDialog
 {
     Q_OBJECT
 public:
     explicit AddComputerDialog(QWidget* parent = 0, Qt::WFlags flags = 0);
+
+    QString computerName() const;
     
 private Q_SLOTS:
     void computerNameChanged( const QString& );
     
-public:
-    QString _computerName;
-};
-
-class AddComputerDialogWidget : public QWidget, public Ui_AddComputerWidget
-{
-    Q_OBJECT
-public:
-    AddComputerDialogWidget( QWidget* parent ) : QWidget( parent ) {
-        setupUi(this);
-    }
-    friend class AddComputerDialog;
+private:
+    AddComputerDialogWidget *_widget;
 };
 
 
diff --git a/secretsync/kcm/addcomputerwidget.ui \
b/secretsync/kcm/addcomputerwidget.ui index 1e9035f..8cf7e83 100644
--- a/secretsync/kcm/addcomputerwidget.ui
+++ b/secretsync/kcm/addcomputerwidget.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>52</height>
+    <width>289</width>
+    <height>68</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -15,14 +15,52 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QLabel" name="label">
-     <property name="text">
-      <string>Enter computer name or IP address:</string>
-     </property>
-    </widget>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Remote computer name:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="_computerName">
+       <property name="toolTip">
+        <string>Enter computer name or IP address here</string>
+       </property>
+       <property name="whatsThis">
+        <string>KSecretSync needs to know the remote computer name in order to sync \
with it</string> +       </property>
+      </widget>
+     </item>
+    </layout>
    </item>
    <item>
-    <widget class="QLineEdit" name="_computerName"/>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Remote port number:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="_port">
+       <property name="toolTip">
+        <string>Enter remote port number here</string>
+       </property>
+       <property name="whatsThis">
+        <string>The remote KSecretSync daemon uses a port to listen for sync \
requests. Please entre that port number here.</string> +       </property>
+       <property name="inputMask">
+        <string>dDDD; </string>
+       </property>
+       <property name="text">
+        <string>8383</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
    </item>
    <item>
     <spacer name="verticalSpacer">
diff --git a/secretsync/kcm/configwidget.cpp b/secretsync/kcm/configwidget.cpp
index 244602a..eb64515 100644
--- a/secretsync/kcm/configwidget.cpp
+++ b/secretsync/kcm/configwidget.cpp
@@ -19,50 +19,43 @@
  */
 
 #include "configwidget.h"
-#include "ksecretsync.h"
 #include "addcomputerdialog.h"
-#include "computersyncjob.h"
-#include "syncjob.h"
-#include "configconstants.h"
+#include "ksecretsynccfg.h"
 
-#include <qevent.h>
 #include <kaction.h>
 #include <klocalizedstring.h>
 #include <kmessagebox.h>
-#include <QListWidget>
-#include <QListWidgetItem>
+#include <QTableView>
 #include <QTimer>
 #include <QCheckBox>
-#include <KStandardDirs>
+#include <kstandarddirs.h>
 #include <kconfig.h>
 #include <ksharedconfig.h>
 #include <kdebug.h>
 #include <QStandardItemModel>
-
+#include <QListWidgetItem>
+#include <QListWidget>
+#include <kconfigdialogmanager.h>
+#include <kdebug.h>
 
 ConfigWidget::ConfigWidget(QWidget* parent, Qt::WindowFlags f): 
     QWidget(parent, f),
-    _mainWindow( parent ),
-    _saveTimer(0)
+    _mainWindow( parent )
 {
     setupUi( this );
     _findComputerBtn->setVisible( false );
     _announceComputerBtn->setVisible( false );
     
     createActions();
-    
-    loadSettings();
 }
 
 ConfigWidget::~ConfigWidget()
 {
-    // FIXME: should we wait for pending timeout signals ?
-    delete _saveTimer;
 }
 
 void ConfigWidget::createActions()
 {
-    Q_ASSERT( _mainWindow != 0 );
+//     Q_ASSERT( _mainWindow != 0 );
     
     connect( _addComputerBtn, SIGNAL(clicked()), this, SLOT(onAddComputer()));
     connect( _deleteComputerBtn, SIGNAL(clicked()), this, SLOT(onDeleteComputer()));
@@ -72,8 +65,14 @@ void ConfigWidget::onAddComputer()
 {
     AddComputerDialog dlg( this );
     if ( dlg.exec() == QDialog::Accepted ) {
-        // TODO: check if entered computer name was not already configured
-        _computerList->addItem( dlg._computerName );
+        QString computerName = dlg.computerName();
+        if ( _computerList->findItems( computerName, Qt::MatchExactly ).count() >0 ) \
{ +            KMessageBox::error( this, i18n("The computer '%1' is already present \
into the computer list", computerName ) ); +        }
+        else {
+            _computerList->addItem( computerName );
+            emit computerListChanged();
+        }
     }
 }
 
@@ -84,81 +83,52 @@ void ConfigWidget::onDeleteComputer()
                                         _computerList->currentItem()->text() ) );
         if ( KMessageBox::questionYesNo( this, message ) == KMessageBox::Yes ) {
             delete _computerList->takeItem( _computerList->currentRow() );
+            emit computerListChanged();
         }
     }
 }
 
-void ConfigWidget::saveGeneralSettings()
+void ConfigWidget::load(KSecretSyncCfg* settings)
 {
-    saveSettingsLater();
-}
-
-void ConfigWidget::saveSettingsLater()
-{
-    if ( _saveTimer == 0 ) {
-        _saveTimer = new QTimer(this);
-        _saveTimer->setSingleShot(true);
-        connect( _saveTimer, SIGNAL(timeout()), SLOT(onSaveTimer()) );
-        _saveTimer->setInterval( SAVE_TIMER_INTERVAL );
+    kDebug() << "ConfigWidget::load";
+    _computerList->clear();
+    foreach ( QString computerName, settings->computerList() ) {
+        _computerList->addItem( computerName );
     }
-    
-    _saveTimer->start();
 }
 
-void ConfigWidget::onSaveTimer()
+void ConfigWidget::save(KSecretSyncCfg* settings)
 {
-    kDebug() << "onSaveTimer";
-    KSharedConfigPtr config = KGlobal::config();
-    KConfigGroup mainGroup( config, "main" );
-    
-    mainGroup.writeEntry(MAIN_ENABLE_SYNC_ENTRY, _enableSync->isChecked());
-    mainGroup.writeEntry(MAIN_SYNC_INTERVAL, _intervalSpinBox->value());
-    mainGroup.writeEntry(MAIN_CURRENT_TAB, _tabs->currentIndex());
-    
-    mainGroup.sync();
+    kDebug() << "ConfigWidget::save";
+
+    QStringList computerList;
+    if ( _computerList->count() >0 ) {
+        for ( int r = 0; r < _computerList->count(); r++ ) {
+            QListWidgetItem* item = _computerList->item( r );
+            computerList.append( item->text() );
+        }
+    }
+    KCoreConfigSkeleton::ItemStringList *computerListItem = 
+            dynamic_cast< KCoreConfigSkeleton::ItemStringList*>( settings->findItem( \
QLatin1String("computerList") ) ); +    Q_ASSERT( computerListItem != 0);
+    computerListItem->setValue( computerList );
+    settings->writeConfig();
 }
 
-void ConfigWidget::loadSettings()
+void ConfigWidget::defaults()
 {
-    KSharedConfigPtr config = KGlobal::config();
-    KConfigGroup mainGroup( config, "main" );
-
-    int currentTab = mainGroup.readEntry<int>(MAIN_CURRENT_TAB, 0);
-    _tabs->setCurrentIndex( currentTab );
-    
-    bool enableSync = mainGroup.readEntry<bool>(MAIN_ENABLE_SYNC_ENTRY, false);
-    _enableSync->setChecked( enableSync );
-    enableSyncToggled( enableSync );
-    
-    int syncInterval = mainGroup.readEntry<int>(MAIN_SYNC_INTERVAL, \
                MIN_SYNC_INTERVAL );
-    if ( syncInterval < MIN_SYNC_INTERVAL ) {
-        kDebug() << "Fixing too short syncInterval from " << syncInterval << " to " \
                << MIN_SYNC_INTERVAL;
-        syncInterval = MIN_SYNC_INTERVAL;
-    }
-    _intervalSpinBox->setValue( syncInterval );
+    _computerList->clear();
 }
 
 void ConfigWidget::enableSyncToggled(bool syncEnabled)
 {
-    _saveGeneralChangesBtn->setEnabled( true );
-    _intervalSpinBox->setEnabled( syncEnabled );
+    kcfg_syncInterval->setEnabled( syncEnabled );
     _intervalLabel->setEnabled( syncEnabled );
     _intervalUnits->setEnabled( syncEnabled );
 }
 
 void ConfigWidget::onSynchIntervalChanged(int )
 {
-    _saveGeneralChangesBtn->setEnabled(true);
-}
-
-void ConfigWidget::createLogEntry(const QString& )
-{
-    // TODO: implement logging
-}
-
-void ConfigWidget::onTabChanged(int tabIndex)
-{
-    // TODO: react to tab changes
 }
 
 #include "configwidget.moc"
diff --git a/secretsync/kcm/configwidget.h b/secretsync/kcm/configwidget.h
index d88ff93..fa669ee 100644
--- a/secretsync/kcm/configwidget.h
+++ b/secretsync/kcm/configwidget.h
@@ -21,42 +21,37 @@
 #ifndef CONFIGWIDGET_H
 #define CONFIGWIDGET_H
 
-#include <QWidget>
-
 #include <ui_configwidget.h>
-#include <synclogger.h>
+
+#include <QWidget>
 
 class QTimer;
+class KSecretSyncCfg;
 
-class ConfigWidget : public QWidget, public Ui_ConfigWidget, public SyncLogger
+class ConfigWidget : public QWidget, public Ui_ConfigWidget
 {
     Q_OBJECT
 public:
     explicit ConfigWidget(QWidget* parent, Qt::WindowFlags f = 0);
     virtual ~ConfigWidget();
-    
-    virtual void createLogEntry( const QString& );
-    
+    void load(KSecretSyncCfg*);
+    void save(KSecretSyncCfg*);
+    void defaults();
+
 protected Q_SLOTS:
     void onAddComputer();
     void onDeleteComputer();
-    void onSaveTimer();
     void enableSyncToggled( bool );
-    void saveGeneralSettings();
     void onSynchIntervalChanged( int );
-    void onTabChanged(int);
     
 Q_SIGNALS:
     void computerListChanged();
     
 private:
     void createActions();
-    void saveSettingsLater();
-    void loadSettings();
     
 private:
     QWidget *_mainWindow;
-    QTimer      *_saveTimer;
 };
 
 #endif // CONFIGWIDGET_H
diff --git a/secretsync/kcm/configwidget.ui b/secretsync/kcm/configwidget.ui
index 0f85241..b77af84 100644
--- a/secretsync/kcm/configwidget.ui
+++ b/secretsync/kcm/configwidget.ui
@@ -10,6 +10,12 @@
     <height>300</height>
    </rect>
   </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
@@ -27,7 +33,7 @@
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_3">
          <item>
-          <widget class="QCheckBox" name="_enableSync">
+          <widget class="QCheckBox" name="kcfg_enableSync">
            <property name="text">
             <string>&amp;Enable auto synchronization</string>
            </property>
@@ -58,7 +64,7 @@
           </widget>
          </item>
          <item>
-          <widget class="KIntSpinBox" name="_intervalSpinBox">
+          <widget class="KIntSpinBox" name="kcfg_syncInterval">
            <property name="minimum">
             <number>1</number>
            </property>
@@ -86,7 +92,7 @@
           </widget>
          </item>
          <item>
-          <widget class="KIntSpinBox" name="_logSize">
+          <widget class="KIntSpinBox" name="kcfg_logSize">
            <property name="accelerated">
             <bool>true</bool>
            </property>
@@ -105,20 +111,17 @@
         </layout>
        </item>
        <item>
-        <spacer name="verticalSpacer_2">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>166</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_6">
+        <layout class="QHBoxLayout" name="horizontalLayout_4">
+         <item>
+          <widget class="QLabel" name="label_4">
+           <property name="text">
+            <string>Listening port:</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QLineEdit" name="kcfg_listeningPort"/>
+         </item>
          <item>
           <spacer name="horizontalSpacer_2">
            <property name="orientation">
@@ -132,18 +135,21 @@
            </property>
           </spacer>
          </item>
-         <item>
-          <widget class="KPushButton" name="_saveGeneralChangesBtn">
-           <property name="enabled">
-            <bool>false</bool>
-           </property>
-           <property name="text">
-            <string>&amp;Save changes</string>
-           </property>
-          </widget>
-         </item>
         </layout>
        </item>
+       <item>
+        <spacer name="verticalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>166</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="_computersTab">
@@ -240,32 +246,11 @@
    <extends>QSpinBox</extends>
    <header>knuminput.h</header>
   </customwidget>
-  <customwidget>
-   <class>KPushButton</class>
-   <extends>QPushButton</extends>
-   <header>kpushbutton.h</header>
-  </customwidget>
  </customwidgets>
  <resources/>
  <connections>
   <connection>
-   <sender>_saveGeneralChangesBtn</sender>
-   <signal>clicked()</signal>
-   <receiver>ConfigWidget</receiver>
-   <slot>saveGeneralSettings()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>102</x>
-     <y>53</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>368</x>
-     <y>32</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>_enableSync</sender>
+   <sender>kcfg_enableSync</sender>
    <signal>toggled(bool)</signal>
    <receiver>ConfigWidget</receiver>
    <slot>enableSyncToggled(bool)</slot>
@@ -281,7 +266,7 @@
    </hints>
   </connection>
   <connection>
-   <sender>_intervalSpinBox</sender>
+   <sender>kcfg_syncInterval</sender>
    <signal>valueChanged(int)</signal>
    <receiver>ConfigWidget</receiver>
    <slot>onSynchIntervalChanged(int)</slot>
diff --git a/secretsync/kcm/kcm_ksecretsync.kcfg \
b/secretsync/kcm/kcm_ksecretsync.kcfg index fb2e7cd..21260d3 100644
--- a/secretsync/kcm/kcm_ksecretsync.kcfg
+++ b/secretsync/kcm/kcm_ksecretsync.kcfg
@@ -3,24 +3,47 @@
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
                           http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
-  <kcfgfile name="ksecretsync"/>
+  <kcfgfile name="ksecretsyncrc"/>
   <include>kglobalsettings.h</include>
   <group name="main">
     <entry name="enableSync" type="Bool">
       <label>Enable KSecretSync component.</label>
+      <whatsthis>This option toggles the enabled state of the secret synchronization \
feature.</whatsthis> +      <tooltip>Toggle the synchronization feature on and \
off</tooltip>  <default>false</default>
     </entry>
     <entry name="syncInterval" type="Int">
       <label>Time frame between sync attempts, in minutes.</label>
+      <whatsthis></whatsthis>
+      <tooltip></tooltip>
       <default>10</default>
     </entry>
     <entry name="currentTab" type="Int">
       <label>Index of the last selected tab in the GUI.</label>
+      <whatsthis></whatsthis>
+      <tooltip></tooltip>
       <default>0</default>
     </entry>
     <entry name="computerCount" type="Int">
       <label>User declared peer computers count.</label>
+      <whatsthis></whatsthis>
+      <tooltip></tooltip>
       <default>0</default>
     </entry>
+    <entry name="computerList" type="StringList">
+        <label>Defined computers</label>
+    </entry>
+    <entry name="logSize" type="Int">
+      <label>Maximum log size (Mb)</label>
+      <whatsthis></whatsthis>
+      <tooltip>Configure maximum log size here</tooltip>
+      <default>1</default>
+    </entry>
+    <entry name="listeningPort" type="Int">
+        <label>Listening port:</label>
+        <whatsthis>Enter the port number KSecretSync should use on this computer to \
listen for peer computers</whatsthis> +        <tooltip>Enter a port number \
here</tooltip> +        <default>8383</default>
+    </entry>
   </group>
 </kcfg>
diff --git a/secretsync/kcm/kcsecretsyncmodule.cpp \
b/secretsync/kcm/kcsecretsyncmodule.cpp index 745c64c..248d877 100644
--- a/secretsync/kcm/kcsecretsyncmodule.cpp
+++ b/secretsync/kcm/kcsecretsyncmodule.cpp
@@ -20,9 +20,11 @@
 
 #include "kcsecretsyncmodule.h"
 #include "configwidget.h"
+#include "ksecretsynccfg.h"
 
 #include <kgenericfactory.h>
 #include <kaboutdata.h>
+#include <kconfigdialog.h>
 
 K_PLUGIN_FACTORY(KSecretSyncFactory, registerPlugin<KCSecretSyncModule>();)
 K_EXPORT_PLUGIN(KSecretSyncFactory("kcm_ksecretsync"))
@@ -57,32 +59,52 @@ KCSecretSyncModule::KCSecretSyncModule(QWidget* parent, const \
QVariantList& args  setAboutData( aboutdata );
     setButtons( KCModule::Apply | KCModule::Help);
     
-    _configWidget = new ConfigWidget( this );
-    connect( _configWidget->_enableSync, SIGNAL(toggled(bool)), this, \
                SLOT(configChanged()) );
-    connect( _configWidget->_intervalSpinBox, SIGNAL(valueChanged(int)), this, \
SLOT(configChanged()) ); +    QVBoxLayout *topLayout = new QVBoxLayout(this);
+    topLayout->setSpacing(KDialog::spacingHint());
+    topLayout->setMargin(0);   
+    
+    _configWidget = new ConfigWidget(0);
+    topLayout->addWidget( _configWidget );
+    
+    
+    connect( _configWidget->kcfg_enableSync, SIGNAL(toggled(bool)), this, \
SLOT(configChanged()) ); +    connect( _configWidget->kcfg_syncInterval, \
                SIGNAL(valueChanged(int)), this, SLOT(configChanged()) );
     connect( _configWidget, SIGNAL(computerListChanged()), this, \
SLOT(configChanged()) );  
     // TODO: use D-Bus to check if the daemon is running and to hide the 'run' \
                button here
-}
-
-void KCSecretSyncModule::configChanged()
-{
-    emit changed(true);
+    
+    
+    addConfig( KSecretSyncCfg::self(), this );
 }
 
 void KCSecretSyncModule::load()
 {
+    kDebug() << "KCSecretSyncModule::load";
+    _configWidget->load( KSecretSyncCfg::self() );
     KCModule::load();
 }
 
 void KCSecretSyncModule::save()
 {
+    kDebug() << "KCSecretSyncModule::save";
+    _configWidget->save( KSecretSyncCfg::self() );
     KCModule::save();
+    // changes will be saved automatically by KConfigXT
+    // TODO: figure out how to notify main application about configuration changes
 }
 
 void KCSecretSyncModule::defaults()
 {
+    kDebug() << "KCSecretSyncModule::defaults";
     KCModule::defaults();
+    _configWidget->defaults();
+    // defaults will be automatically loaded here by KConfigXT
+}
+
+void KCSecretSyncModule::configChanged()
+{
+    emit changed(true);
 }
 
+
 #include "kcsecretsyncmodule.moc"
diff --git a/secretsync/kcm/ksecretsynccfg.kcfgc \
b/secretsync/kcm/ksecretsynccfg.kcfgc index 09cdb3b..17dde9b 100644
--- a/secretsync/kcm/ksecretsynccfg.kcfgc
+++ b/secretsync/kcm/ksecretsynccfg.kcfgc
@@ -1,2 +1,4 @@
 File=kcm_ksecretsync.kcfg
 ClassName=KSecretSyncCfg
+Singleton=true
+SetUserTexts=true
diff --git a/secretsync/ksecretsync.cpp b/secretsync/ksecretsync.cpp
deleted file mode 100644
index d42c3cc..0000000
--- a/secretsync/ksecretsync.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2010, Valentin Rusu <kde@rusu.info>
- *
- * 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/>.
- */
-
-#include "ksecretsync.h"
-#include "trayicon.h"
-#include "statuswidget.h"
-#include "syncdaemon.h"
-
-#include <kconfig.h>
-#include <klocalizedstring.h>
-#include <kaction.h>
-#include <kactioncollection.h>
-#include <kmessagebox.h>
-#include <ktoolinvocation.h>
-#include <QStandardItemModel>
-
-KSecretSync::KSecretSync(QWidget* parent, Qt::WindowFlags f): 
-    KXmlGuiWindow(parent, f)
-{
-    createGUI( QLatin1String( "ksecretsync.rc" ) );
-
-    _trayIcon = new TrayIcon( this );
-    
-    _syncDaemon = new SyncDaemon( this );
-    
-    _statusWidget = new StatusWidget( this );
-    setCentralWidget( _statusWidget );
-    _statusWidget->_computersView->setModel( _syncDaemon->computerList() );
-    connect( _statusWidget->_configureBtn, SIGNAL(clicked()), this, \
                SLOT(onConfigure()));
-    connect( _statusWidget->_computersView, SIGNAL(doubleClicked(QModelIndex)), \
                this, SLOT(onComputerDoubleClicked(QModelIndex)));
-    
-    
-    KAction *action;
-    action = createAction( QLatin1String("ksecretsync synchronize now") );
-    action->setText( i18n("&Synchronize now") );
-    action->setIcon( KIcon( QLatin1String( "view-refresh" ) ) );
-    connect( action, SIGNAL(triggered(bool)), this, SLOT(onSynchronizeNow(bool)));
-    _trayIcon->addAction( action );
-    
-    action = createAction( QLatin1String("ksecretsync configure") );
-    action->setText( i18n("&Configure...") );
-    action->setIcon( KIcon( QLatin1String( "run-build-configure") ) );
-    connect( action, SIGNAL(triggered(bool)), this, SLOT(onConfigure(bool)));
-    _trayIcon->addAction( action );
-}
-
-KSecretSync::~KSecretSync()
-{
-}
-
-void KSecretSync::closeEvent(QCloseEvent* event)
-{
-    delete _syncDaemon;
-    delete _trayIcon;
-    KMainWindow::closeEvent( event );
-}
-
-KAction *KSecretSync::createAction( const QLatin1String &description )
-{
-    KAction* action = actionCollection()->addAction( description );
-    if ( _trayIcon )
-        _trayIcon->addAction( action );
-    return action;
-}
-
-void KSecretSync::createLogEntry(const QString& )
-{
-    // TODO: create log entry here
-}
-
-void KSecretSync::onSynchronizeNow(bool )
-{
-    // TODO: implement this
-    KMessageBox::information( this, i18n( "This function is not yet implemented" ) \
                );
-}
-
-void KSecretSync::onConfigure(bool )
-{
-    KToolInvocation::startServiceByDesktopName( QLatin1String( "ksecretsync" ));    
-}
-
-void KSecretSync::onComputerDoubleClicked(QModelIndex )
-{
-    if ( _syncDaemon->hasComputers() ) {
-        // TODO: what should we do when a computer is double clicked ?
-    }
-    else {
-        onConfigure();
-    }
-}
-
-#include "ksecretsync.moc"
diff --git a/secretsync/ksecretsync.h b/secretsync/ksecretsync.h
deleted file mode 100644
index 9c930c8..0000000
--- a/secretsync/ksecretsync.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2010, Valentin Rusu <kde@rusu.info>
- *
- * 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 KSECRETSYNC_H
-#define KSECRETSYNC_H
-
-#include <kxmlguiwindow.h>
-
-class SyncDaemon;
-class StatusWidget;
-class TrayIcon;
-class KAction;
-class QModelIndex;
-
-class KSecretSync : public KXmlGuiWindow
-{
-    Q_OBJECT
-public:
-    explicit KSecretSync(QWidget* parent = 0, Qt::WindowFlags f = 0);
-    virtual ~KSecretSync();
-    KAction* createAction(const QLatin1String &description);
-    
-    void createLogEntry( const QString& );
-
-protected Q_SLOTS:
-    void onSynchronizeNow( bool =false );
-    void onConfigure( bool =false );
-    void onComputerDoubleClicked(QModelIndex);
-    
-protected:
-    virtual void closeEvent( QCloseEvent* );
-        
-private:
-    SyncDaemon      *_syncDaemon;
-    TrayIcon        *_trayIcon;
-    StatusWidget    *_statusWidget;
-};
-
-#endif // KSECRETSYNC_H
diff --git a/secretsync/ksecretsyncwindow.cpp b/secretsync/ksecretsyncwindow.cpp
new file mode 100644
index 0000000..3274278
--- /dev/null
+++ b/secretsync/ksecretsyncwindow.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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/>.
+ */
+
+#include "ksecretsyncwindow.h"
+#include "trayicon.h"
+#include "statuswidget.h"
+#include "syncdaemon.h"
+#include "syncmodel.h"
+
+#include <kconfig.h>
+#include <klocalizedstring.h>
+#include <kaction.h>
+#include <kactioncollection.h>
+#include <kmessagebox.h>
+#include <ktoolinvocation.h>
+#include <QStandardItemModel>
+
+KSecretSyncWindow::KSecretSyncWindow(QWidget* parent, Qt::WindowFlags f): 
+    KXmlGuiWindow(parent, f)
+{
+    createGUI( QLatin1String( "ksecretsync.rc" ) );
+
+    _trayIcon = new TrayIcon( this );
+    
+    _syncModel = new SyncModel;
+    _syncDaemon = new SyncDaemon( this, _syncModel );
+    
+    _statusWidget = new StatusWidget( this );
+    setCentralWidget( _statusWidget );
+    _statusWidget->_computersView->setModel( _syncModel );
+    
+    connect( _statusWidget->_configureBtn, SIGNAL(clicked()), this, \
SLOT(onConfigure())); +    connect( _statusWidget->_computersView, \
SIGNAL(doubleClicked(QModelIndex)), this, \
SLOT(onComputerDoubleClicked(QModelIndex))); +    // TODO: connect to the status LED \
doubleClicked signal and allow enable state toggle from it +    
+    KAction *action;
+    action = createAction( QLatin1String("ksecretsync synchronize now") );
+    action->setText( i18n("&Synchronize now") );
+    action->setIcon( KIcon( QLatin1String( "view-refresh" ) ) );
+    connect( action, SIGNAL(triggered(bool)), this, SLOT(onSynchronizeNow(bool)));
+    _trayIcon->addAction( action );
+    
+    action = createAction( QLatin1String("ksecretsync configure") );
+    action->setText( i18n("&Configure...") );
+    action->setIcon( KIcon( QLatin1String( "run-build-configure") ) );
+    connect( action, SIGNAL(triggered(bool)), this, SLOT(onConfigure(bool)));
+    _trayIcon->addAction( action );
+}
+
+KSecretSyncWindow::~KSecretSyncWindow()
+{
+    delete _syncDaemon;
+    delete _syncModel;
+}
+
+void KSecretSyncWindow::closeEvent(QCloseEvent* event)
+{
+    delete _syncDaemon;
+    delete _trayIcon;
+    KMainWindow::closeEvent( event );
+}
+
+KAction *KSecretSyncWindow::createAction( const QLatin1String &description )
+{
+    KAction* action = actionCollection()->addAction( description );
+    if ( _trayIcon )
+        _trayIcon->addAction( action );
+    return action;
+}
+
+void KSecretSyncWindow::createLogEntry(const QString& )
+{
+    // TODO: create log entry here
+}
+
+void KSecretSyncWindow::onSynchronizeNow(bool )
+{
+    // TODO: implement this
+    KMessageBox::information( this, i18n( "This function is not yet implemented" ) \
); +}
+
+void KSecretSyncWindow::onConfigure(bool )
+{
+    KToolInvocation::startServiceByDesktopName( QLatin1String( "ksecretsync" ));    
+}
+
+void KSecretSyncWindow::onComputerDoubleClicked(QModelIndex )
+{
+    if ( _syncModel->hasComputers() ) {
+        // TODO: what should we do when a computer is double clicked ?
+    }
+    else {
+        onConfigure();
+    }
+}
+
+#include "ksecretsyncwindow.moc"
diff --git a/secretsync/ksecretsyncwindow.h b/secretsync/ksecretsyncwindow.h
new file mode 100644
index 0000000..3ecef89
--- /dev/null
+++ b/secretsync/ksecretsyncwindow.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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 KSECRETSYNC_H
+#define KSECRETSYNC_H
+
+#include <kxmlguiwindow.h>
+
+class SyncModel;
+class SyncDaemon;
+class StatusWidget;
+class TrayIcon;
+class KAction;
+class QModelIndex;
+
+class KSecretSyncWindow : public KXmlGuiWindow
+{
+    Q_OBJECT
+public:
+    explicit KSecretSyncWindow(QWidget* parent = 0, Qt::WindowFlags f = 0);
+    virtual ~KSecretSyncWindow();
+    KAction* createAction(const QLatin1String &description);
+    
+    void createLogEntry( const QString& );
+
+protected Q_SLOTS:
+    void onSynchronizeNow( bool =false );
+    void onConfigure( bool =false );
+    void onComputerDoubleClicked(QModelIndex);
+    
+protected:
+    virtual void closeEvent( QCloseEvent* );
+        
+private:
+    SyncModel       *_syncModel;
+    SyncDaemon      *_syncDaemon;
+    TrayIcon        *_trayIcon;
+    StatusWidget    *_statusWidget;
+};
+
+#endif // KSECRETSYNC_H
diff --git a/secretsync/main.cpp b/secretsync/main.cpp
index 0c3f050..0c5257f 100644
--- a/secretsync/main.cpp
+++ b/secretsync/main.cpp
@@ -29,7 +29,7 @@
 #include <kstandarddirs.h>
 #include <QtCrypto/QtCrypto>
 
-#include "ksecretsync.h"
+#include "ksecretsyncwindow.h"
 
 /**
  * This is the main entry of the ksecretsync tool
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    KSecretSync mainWindow;
+    KSecretSyncWindow mainWindow;
     mainWindow.setCaption(i18n("KSecretSync"));
     
     // KGlobal::dirs()->addResourceType("kwallet", QLatin1String( \
                "share/apps/kwallet" ));
diff --git a/secretsync/statuswidget.ui b/secretsync/statuswidget.ui
index 45d9c43..50d2934 100644
--- a/secretsync/statuswidget.ui
+++ b/secretsync/statuswidget.ui
@@ -59,16 +59,16 @@
         </widget>
        </item>
        <item>
-        <widget class="QTreeView" name="_computersView">
+        <widget class="QTableView" name="_computersView">
          <property name="editTriggers">
           <set>QAbstractItemView::NoEditTriggers</set>
          </property>
          <property name="showDropIndicator" stdset="0">
           <bool>false</bool>
          </property>
-         <property name="rootIsDecorated">
+         <attribute name="verticalHeaderVisible">
           <bool>false</bool>
-         </property>
+         </attribute>
         </widget>
        </item>
        <item>
diff --git a/secretsync/syncdaemon.cpp b/secretsync/syncdaemon.cpp
index fe0a577..bf4b15d 100644
--- a/secretsync/syncdaemon.cpp
+++ b/secretsync/syncdaemon.cpp
@@ -22,7 +22,8 @@
 #include "syncjob.h"
 #include "computersyncjob.h"
 #include "configconstants.h"
-#include "computerdata.h"
+#include "ksecretsynccfg.h"
+#include "syncserverjob.h"
 
 #include <kglobal.h>
 #include <kdebug.h>
@@ -32,49 +33,46 @@
 #include <kicon.h>
 #include <QTimer>
 #include <QStandardItemModel>
+#include <kdebug.h>
+#include <QtNetwork/QSslSocket>
+#include <stdio.h>
+#include <stdlib.h>
+
+SyncDaemon* SyncDaemon::_instance = 0;
 
-SyncDaemon::SyncDaemon(QObject* parent) : 
-    QObject(parent),
-    _syncTimer(0)
+SyncDaemon::SyncDaemon(QObject* parent, SyncModel* model) : 
+    QTcpServer(parent),
+    _syncTimer(0),
+    _model( model )
 {
-    _computerList = new QStandardItemModel(0, 3, this);
+    Q_ASSERT( model != 0 );
+    Q_ASSERT( _instance == 0);
+    _instance = this;
+    
+    qInstallMsgHandler( qMsgHandler );
     
     _syncTimer = new QTimer( this );
     connect( _syncTimer, SIGNAL(timeout()), SLOT(onSyncTimer()) );
 
-    configChanged();
+    if ( KSecretSyncCfg::enableSync() ){
+        int syncInterval = KSecretSyncCfg::syncInterval() * 60000; // the sync \
interval is configured in minutes +        kDebug() << "SyncDaemon started sync; \
syncInterval = " << syncInterval; +        _syncTimer->setInterval( syncInterval );
+        _syncTimer->start();
+    }
+    else {
+        kDebug() << "SyncDaemon sync is currently disabled";
+    }
+    
+    startListening();
 }
 
 SyncDaemon::~SyncDaemon()
 {
-    delete _computerList;
+    // FIXME: should we wait for sync interval expire here ?
+    delete _syncTimer;
 }
 
-void SyncDaemon::configChanged()
-{
-    KSharedConfigPtr config = KGlobal::config();
-    KConfigGroup mainGroup( config, "main" );
-
-    Q_ASSERT(_syncTimer!=0);
-    _syncTimer->stop();
-    int syncInterval = mainGroup.readEntry<int>(MAIN_SYNC_INTERVAL, \
                MIN_SYNC_INTERVAL );
-    _syncTimer->setInterval( syncInterval * 60000 );
-    _syncTimer->start();
-    
-    int computerCount = mainGroup.readEntry<int>(MAIN_COMPUTER_COUNT, 0);
-    if ( computerCount ) {
-        _hasComputers = true;
-        // TODO: load computers here
-    }
-    else {
-        _hasComputers = false;
-        QStandardItem *noComputersItem = new QStandardItem( KIcon( \
                QLatin1String("dialog-cancel") ), 
-                                                            i18n("no computers \
                defined") );
-        noComputersItem->setWhatsThis( i18n("This item is present because no \
computers are defined. Click this item to open the settings module and to add a \
                computer") );
-        noComputersItem->setToolTip( i18n("Double click this item to open the \
                configuration module") );
-        _computerList->appendRow( noComputersItem );
-    }
-}
 
 void SyncDaemon::onSyncTimer()
 {
@@ -83,20 +81,78 @@ void SyncDaemon::onSyncTimer()
 
 void SyncDaemon::startSync()
 {
+    // FIXME: should we create a log entry instead? pitfall: create too many log \
entries  kDebug() << "startSync";
-    if (!_hasComputers)
+    if (!_model->hasComputers())
         return;
     
     SyncJob *syncJob = new SyncJob;
-    for (int r =0; r < _computerList->rowCount(); ++r ) {
-        QStandardItem *computerItem = _computerList->item(r);
-        Q_ASSERT(computerItem != 0);
-        new ComputerSyncJob( syncJob, _computerData[ computerItem->text() ], this );
+    for (int r =0; r < _model->rowCount(); ++r ) {
+        new ComputerSyncJob( syncJob, _model->computerData( r ), this );
     }
+    
     syncJob->start();
 }
 
-void SyncDaemon::createLogEntry(const QString& )
+void SyncDaemon::startListening()
+{
+    // TODO: implemente listening host address specifying here, e.g. allow user \
specify which card to bind to +    if ( listen( QHostAddress::Any, \
KSecretSyncCfg::listeningPort() ) ) { +        createLogEntry( i18n("started \
listening on the network") ); +    }
+    else {
+        createLogEntry( i18n("start listening failed : %1", errorString() ) );
+    }
+}
+
+void SyncDaemon::incomingConnection( int incomingSocket )
+{
+    createLogEntry( i18n("incoming connection") );
+    QSslSocket *listeningSocket = new QSslSocket;
+    if ( listeningSocket->setSocketDescriptor( incomingSocket ) ) {
+        createLogEntry( i18n("launching server job with new socket descriptor %1", \
incomingSocket) ); +        addPendingConnection( listeningSocket );
+        // NOTE: SSL encryption is setup by the SyncServerJob
+        SyncServerJob *serverJob = new SyncServerJob( this, listeningSocket );
+        serverJob->start();
+    }
+    else {
+        createLogEntry( i18n("cannot set SSL socket descriptor. Aborting \
connection") ); +        delete listeningSocket;
+    }
+}
+
+void SyncDaemon::qMsgHandler(QtMsgType type, const char* msg)
+{
+    if ( _instance ) {
+        QString message;
+        switch ( type ) {
+            case QtDebugMsg:
+                message = "QtDebug";
+                break;
+            case QtWarningMsg:
+                message = "QtWarning";
+                break;
+            case QtCriticalMsg:
+                message = "QtCritical";
+                break;
+            case QtFatalMsg:
+                message = "QtFatal";
+                break;
+            default:
+                message = "QtMsg UNKNOWN";
+        }
+        message += ": ";
+        message += msg;
+//        _instance->createLogEntry( message );
+        fprintf( stderr, "%s\n", qPrintable( message ) );
+    }
+}
+
+void SyncDaemon::createLogEntry(const QString& message )
 {
+    kDebug() << message;
     // TODO: implement this by forwarding message to the logger
 }
+
+#include "syncdaemon.moc"
diff --git a/secretsync/syncdaemon.h b/secretsync/syncdaemon.h
index d3e47d8..c761898 100644
--- a/secretsync/syncdaemon.h
+++ b/secretsync/syncdaemon.h
@@ -21,40 +21,38 @@
 #ifndef SYNCDAEMON_H
 #define SYNCDAEMON_H
 
-#include "computerdata.h"
+#include "syncmodel.h"
 #include "synclogger.h"
 
-#include <QObject>
+#include <QtNetwork/QTcpServer>
 #include <QMap>
 
 class QTimer;
-class QStandardItemModel;
+class QSslSocket;
 
-
-class SyncDaemon : public QObject, public SyncLogger
+class SyncDaemon : public QTcpServer, public SyncLogger
 {
     Q_OBJECT
 public:
-    explicit SyncDaemon(QObject* parent = 0);
+    SyncDaemon(QObject* parent, SyncModel* model);
     virtual ~SyncDaemon();
 
-    QStandardItemModel* computerList() const { return _computerList; }
-    bool hasComputers() const { return _hasComputers; }
-    
+    virtual void createLogEntry( const QString& );
+   
 protected Q_SLOTS:
     void onSyncTimer();
-    void configChanged();
     
 protected:
     void startSync();
-    virtual void createLogEntry( const QString& );
+    void startListening();
+    virtual void incomingConnection( int );
+    static void qMsgHandler( QtMsgType type, const char* msg );
     
 private:
-    bool                        _syncEnabled;
-    QTimer                      *_syncTimer;
-    QStandardItemModel          *_computerList;
-    QMap<QString, ComputerData> _computerData;
-    bool                        _hasComputers;
+    static SyncDaemon  *_instance;
+    bool        _syncEnabled;
+    QTimer      *_syncTimer;
+    SyncModel   *_model;
 };
 
 #endif // SYNCDAEMON_H
diff --git a/secretsync/syncmodel.cpp b/secretsync/syncmodel.cpp
new file mode 100644
index 0000000..2234f93
--- /dev/null
+++ b/secretsync/syncmodel.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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/>.
+ */
+
+
+#include "syncmodel.h"
+#include "kcm/ksecretsynccfg.h"
+
+#include <QVariant>
+#include <QMap>
+#include "klocalizedstring.h"
+
+ComputerData::ComputerData( const QString& computerName ) : 
+        _lastSyncStatus( SYNC_STATUS_NONE ) {
+    QStringList nameParts = computerName.split(':');
+    Q_ASSERT( nameParts.count() ==2 );
+    Q_ASSERT( !nameParts[1].isEmpty() );
+    _computerName = nameParts[0];
+    _remotPort = nameParts[1].toInt();
+}
+
+class ComputerDataDisplayItem : public QStandardItem {
+public:
+    ComputerDataDisplayItem( ComputerData* data, int column) : _computerData( data \
), _column( column ) {} +
+    virtual QVariant data( int role = Qt::UserRole +1 ) const {
+        if ( role == Qt::DisplayRole )
+            return QVariant( text() );
+        return QStandardItem::data( role );
+    }
+    QString text() const
+    {
+        static const char *statusStrings[] = {
+            "waiting for sync", //SYNC_STATUS_NONE,           /// computer data has \
just been loaded or created and no sync has been tried +            "sync pending", \
//SYNC_STATUS_PENDING,        /// a sync job was started on this item +            \
"sync done",    //SYNC_STATUS_DONE,           /// the last sync operation finished \
successfully +            "unreachable",  //SYNC_STATUS_UNREACHABLE,    /// the \
computer is not reachable +            "conflict",     //SYNC_STATUS_CONFLICTING,    \
/// the target computer has a conflicting item +            "error",  \
//SYNC_STATUS_ERROR           /// an error occurred during last sync operation +      \
}; +        //TODO: implement text items caching below
+        switch ( _column ) {
+            case 0:
+                return _computerData->_computerName;
+            case 1:
+                return statusStrings[ _computerData->_lastSyncStatus ];
+            case 2:
+                return _computerData->_lastSyncTime.toString();
+            case 3:
+                return _computerData->_remoteIP;
+        }
+        Q_ASSERT(0); // should never reach here - check list column count matches \
this method +        return "ERROR";
+    }
+    // TODO: add custom icons to reflect the computer sync status
+private:
+    ComputerData    *_computerData;
+    int             _column;
+};
+
+class NoComputerDefinedItem : public QStandardItem {
+public:
+    NoComputerDefinedItem() {
+        setText( i18n("No computer defined") );
+        setData( i18n("Double click here to configure KSecretSync"), Qt::ToolTipRole \
); +    }
+};
+
+SyncModel::SyncModel() :
+    QStandardItemModel()
+{
+    setColumnCount( 4 ); // computer name, sync status, last sync time, remote IP
+
+    // TODO: add 5th column with status message for current computer
+    
+    QStringList horizontalLabels;
+    horizontalLabels.append( i18n("Computer") );
+    horizontalLabels.append( i18n("Sync status") );
+    horizontalLabels.append( i18n("Last sync time") );
+    horizontalLabels.append( i18n("Remote IP") );
+    setHorizontalHeaderLabels( horizontalLabels );
+
+    if ( KSecretSyncCfg::computerList().count() >0 ) {
+        foreach( QString computerName, KSecretSyncCfg::computerList() ) {
+            ComputerData *computerData = new ComputerData( computerName );
+            QList< QStandardItem* > itemList;
+            itemList.append( new ComputerDataDisplayItem( computerData, 0 ));
+            itemList.append( new ComputerDataDisplayItem( computerData, 1 ));
+            itemList.append( new ComputerDataDisplayItem( computerData, 2 ));
+            itemList.append( new ComputerDataDisplayItem( computerData, 3 ));
+            appendRow( itemList );
+        }
+    }
+    else {
+        appendRow( new NoComputerDefinedItem() );
+    }
+}
+
+SyncModel::~SyncModel()
+{
+
+}
+
+bool SyncModel::hasComputers() const
+{
+    bool hasComputers = false;
+    if ( rowCount() > 0 ) {
+    
+        QStandardItem *firstItem = item( 0, 0 );
+        if ( dynamic_cast< NoComputerDefinedItem* > ( firstItem ) ) {
+            hasComputers = false; 
+        }
+        else {
+            hasComputers = true;
+        }
+    }
+    return hasComputers;
+}
+
+ComputerData* SyncModel::computerData(int index)
+{
+    return data( createIndex( index, 0 ) ).value< ComputerData* > (); 
+}
+
+#include "syncmodel.moc"
diff --git a/secretsync/syncmodel.h b/secretsync/syncmodel.h
new file mode 100644
index 0000000..f0ef109
--- /dev/null
+++ b/secretsync/syncmodel.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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 SYNCMODEL_H
+#define SYNCMODEL_H
+
+#include <QDateTime>
+#include <QStringList>
+#include <QStandardItemModel>
+
+/**
+ * Information structure used to manage synchronization with a given computer
+ * KSecretSync use one ComputerData for each known computer
+ */
+struct ComputerData
+{
+    enum SyncStatus {
+        SYNC_STATUS_NONE,           /// computer data has just been loaded or \
created and no sync has been tried +        SYNC_STATUS_PENDING,        /// a sync \
job was started on this item +        SYNC_STATUS_DONE,           /// the last sync \
operation finished successfully +        SYNC_STATUS_UNREACHABLE,    /// the computer \
is not reachable +        SYNC_STATUS_CONFLICTING,    /// the target computer has a \
conflicting item +        SYNC_STATUS_ERROR           /// an error occurred during \
last sync operation +    };
+    
+    explicit ComputerData( const QString& computerName );
+    
+    QString     _computerName;
+    QString     _computerAddress;
+    QTime       _lastSyncTime;
+    SyncStatus  _lastSyncStatus;
+    QString     _lastSyncError;
+    QStringList _conflictingItems;
+    QString     _remoteIP;
+    QString     _remotPort;
+};
+
+Q_DECLARE_METATYPE( ComputerData* )
+
+
+class SyncModel : public QStandardItemModel {
+    Q_OBJECT
+public:
+    SyncModel();
+    virtual ~SyncModel();
+    bool hasComputers() const;
+    
+    ComputerData* computerData( int index );
+    
+};
+
+#endif // SYNCMODEL_H
diff --git a/secretsync/syncserverjob.cpp b/secretsync/syncserverjob.cpp
new file mode 100644
index 0000000..df370e6
--- /dev/null
+++ b/secretsync/syncserverjob.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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/>.
+ */
+
+#include "syncserverjob.h"
+#include "syncdaemon.h"
+
+#include <QtNetwork/QSslSocket>
+#include <kdebug.h>
+
+SyncServerJob::SyncServerJob(SyncDaemon* daemon, QSslSocket* socket) :
+    _socket( socket ), _daemon( daemon )
+{
+    Q_ASSERT( socket != NULL );
+    connect( socket, SIGNAL( stateChanged(QAbstractSocket::SocketState)) , SLOT( \
onSocketStateChanged(QAbstractSocket::SocketState) ) ); +    connect( socket, SIGNAL( \
encrypted() ), SLOT( onSocketEncrypted() ) ); +    connect( socket, SIGNAL( \
sslErrors(QList<QSslError>) ), SLOT( onSslErrors(QList<QSslError>) ) ); +}
+
+SyncServerJob::~SyncServerJob()
+{
+    delete _socket;
+}
+
+void SyncServerJob::start()
+{
+    kDebug() << "starting server sync job";
+    _socket->startServerEncryption();
+}
+
+QString SyncServerJob::errorString() const
+{
+    return KJob::errorString();
+}
+
+void SyncServerJob::onSocketStateChanged( QAbstractSocket::SocketState state )
+{
+    kDebug() << "onSocketStateChanged " << state;
+}
+
+void SyncServerJob::onSslErrors( QList< QSslError > errorList )
+{
+    foreach( QSslError error, errorList ) {
+        _daemon->createLogEntry( error.errorString() );
+    }
+}
+
+void SyncServerJob::onSocketEncrypted()
+{
+    kDebug() << "onSocketEncrypted";
+    if ( _socket->waitForReadyRead(-1) ) {
+        
+    }
+}
+
+#include "syncserverjob.moc"
diff --git a/secretsync/syncserverjob.h b/secretsync/syncserverjob.h
new file mode 100644
index 0000000..b701e76
--- /dev/null
+++ b/secretsync/syncserverjob.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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 SYNCSERVERJOB_H
+#define SYNCSERVERJOB_H
+
+#include <kjob.h>
+#include <QtNetwork/QSslError>
+#include <QtNetwork/QAbstractSocket>
+
+class QSslSocket;
+class SyncDaemon;
+
+class SyncServerJob : public KJob
+{
+    Q_OBJECT
+public:
+    SyncServerJob( SyncDaemon* daemon, QSslSocket* socket);
+    virtual ~SyncServerJob();
+    
+    virtual void start();
+    virtual QString errorString() const;
+    
+protected Q_SLOTS:
+    void onSocketStateChanged(QAbstractSocket::SocketState);
+    void onSocketEncrypted();
+    void onSslErrors(QList<QSslError>);
+    
+private:
+    QSslSocket  *_socket;
+    SyncDaemon  *_daemon;
+};
+
+#endif // SYNCSERVERJOB_H
diff --git a/secretsync/tests/CMakeLists.txt b/secretsync/tests/CMakeLists.txt
new file mode 100644
index 0000000..3ff5238
--- /dev/null
+++ b/secretsync/tests/CMakeLists.txt
@@ -0,0 +1,22 @@
+#INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR})
+
+SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
+
+INCLUDE_DIRECTORIES (
+   ${KDE4_INCLUDES}
+   ${QCA2_INCLUDE_DIR}
+   ${CMAKE_SOURCE_DIR}
+   ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+KDE4_ADD_EXECUTABLE (ksecretsync_test 
+    sslconnectiontest.cpp
+)
+
+TARGET_LINK_LIBRARIES (ksecretsync_test
+    ${QT_QTTEST_LIBRARIES}
+    ${QT_QTNETWORK_LIBRARIES}
+    ${KDE4_KDEUI_LIBS}
+)
+
+ADD_TEST (KSecretSyncTest ksecretsync_test)
diff --git a/secretsync/tests/sslconnectiontest.cpp \
b/secretsync/tests/sslconnectiontest.cpp new file mode 100644
index 0000000..61370a0
--- /dev/null
+++ b/secretsync/tests/sslconnectiontest.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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/>.
+ */
+
+#include "sslconnectiontest.h"
+
+#include <QtTest/QTest>
+#include <qprocess.h>
+#include <QtNetwork/QSslSocket>
+#include <QtTest/QSignalSpy>
+#include <QTimer>
+#include <kdebug.h>
+#include <qtest_kde.h>
+
+QTEST_KDEMAIN( SslConnectionTest, NoGUI )
+
+SslConnectionTest::SslConnectionTest()
+{
+
+}
+
+void SslConnectionTest::initTestCase()
+{
+/*    QString program = "../ksecretsync";
+    QStringList arguments;
+    arguments << "--nofork";
+    _daemonProcess = new QProcess(this);
+    _daemonProcess->start( program, arguments );
+    QVERIFY( _daemonProcess->waitForStarted() );*/
+}
+
+void SslConnectionTest::testSslConnection()
+{
+    QSslSocket* socket = new QSslSocket(this);
+    QSignalSpy encryptedSpy( socket, SIGNAL( encrypted() ) );
+    QVERIFY( encryptedSpy.isValid() );
+    
+    socket->connectToHostEncrypted( "zamox.rusu.info", 8383 );
+    if ( !socket->waitForEncrypted( 6000 ) ) {
+        kDebug() << socket->errorString();
+        QVERIFY( false );
+    }
+    
+    socket->close();
+    delete socket;
+}
+
+void SslConnectionTest::cleanupTestCase()
+{
+/*    if ( _daemonProcess )
+        _daemonProcess->close();*/
+}
diff --git a/secretsync/tests/sslconnectiontest.h \
b/secretsync/tests/sslconnectiontest.h new file mode 100644
index 0000000..7084dda
--- /dev/null
+++ b/secretsync/tests/sslconnectiontest.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2010, Valentin Rusu <kde@rusu.info>
+ *
+ * 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 SSLCONNECTIONTEST_H
+#define SSLCONNECTIONTEST_H
+
+#include <QObject>
+
+class QProcess;
+
+class SslConnectionTest : public QObject
+{
+    Q_OBJECT
+public:
+    SslConnectionTest();
+    
+private Q_SLOTS:
+    void initTestCase();
+
+    void testSslConnection();
+    
+    // cleanup
+    void cleanupTestCase();
+    
+private:
+    QProcess*   _daemonProcess;
+};
+
+#endif // SSLCONNECTIONTEST_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic