Просмотр исходного кода

Add a sitecopy backend to mirall, some GUI cleanups

Klaas Freitag 14 лет назад
Родитель
Сommit
83613f4576

+ 1 - 0
CMakeLists.txt

@@ -1,3 +1,4 @@
+
 cmake_minimum_required(VERSION 2.8)
 project(mirall)
 set(PACKAGE "mirall")

+ 4 - 0
src/CMakeLists.txt

@@ -6,6 +6,8 @@ include(${QT_USE_FILE})
 set(mirall_UI
 mirall/folderwizardsourcepage.ui
 mirall/folderwizardtargetpage.ui
+mirall/folderwizardnetworkpage.ui
+mirall/folderwizardowncloudpage.ui
 )
 qt4_wrap_ui(mirall_UI_SRCS ${mirall_UI})
 
@@ -21,6 +23,8 @@ mirall/networklocation.cpp
 mirall/temporarydir.cpp
 mirall/syncresult.cpp
 mirall/unisonfolder.cpp
+mirall/sitecopyfolder.cpp
+mirall/sitecopyconfig.cpp
 )
 if(CSYNC_FOUND)
   set(mirall_SRCS

+ 32 - 7
src/mirall/application.cpp

@@ -28,6 +28,9 @@
 #include "mirall/folderwizard.h"
 #include "mirall/networklocation.h"
 #include "mirall/unisonfolder.h"
+#include "mirall/sitecopyfolder.h"
+#include "mirall/sitecopyconfig.h"
+
 #ifdef WITH_CSYNC
 #include "mirall/csyncfolder.h"
 #endif
@@ -133,8 +136,7 @@ void Application::slotAddFolder()
 
         if (_folderWizard->field("local?").toBool()) {
             settings.setValue("backend:csync/secondPath", _folderWizard->field("targetLocalFolder"));
-        }
-        else if (_folderWizard->field("remote?").toBool()) {
+        } else if (_folderWizard->field("remote?").toBool()) {
             settings.setValue("backend:csync/secondPath", _folderWizard->field("targetURLFolder"));
             bool onlyOnline = _folderWizard->field("onlyOnline?").toBool();
             settings.setValue("folder/onlyOnline", onlyOnline);
@@ -146,9 +148,22 @@ void Application::slotAddFolder()
                     settings.setValue("folder/onlyOnline", true);
                 }
             }
-        }
-        else
-        {
+        } else if( _folderWizard->field("OC?").toBool()) {
+            settings.setValue("folder/backend", "sitecopy");
+            settings.setValue("backend:sitecopy/targetPath", _folderWizard->field("targetOCFolder"));
+
+            settings.setValue("backend:sitecopy/url",    _folderWizard->field("OCUrl"));
+            settings.setValue("backend:sitecopy/user",   _folderWizard->field("OCUser"));
+            settings.setValue("backend:sitecopy/passwd", _folderWizard->field("OCPasswd"));
+
+            qDebug() << "Now writing sitecopy config " << _folderWizard->field("OCSiteAlias").toString(); ;
+            SitecopyConfig scConfig;
+            scConfig.writeSiteConfig( _folderWizard->field("sourceFolder").toString(), /* local path */
+                                      _folderWizard->field("OCSiteAlias").toString(),  /* site alias */
+                                      _folderWizard->field("OCUrl").toString(),        /* site URL   */
+                                      _folderWizard->field("OCUser").toString(),
+                                      _folderWizard->field("OCPasswd").toString() );
+        } else {
             qWarning() << "* Folder not local and note remote?";
             return;
         }
@@ -180,9 +195,10 @@ void Application::setupFolderFromConfigFile(const QString &file) {
 
     qDebug() << "  ` -> setting up:" << file;
     QSettings settings(folderConfigPath() + "/" + file, QSettings::IniFormat);
+    qDebug() << "    -> file path: " + settings.fileName();
 
     if (!settings.contains("folder/path")) {
-        qWarning() << "    `->" << file << "is not a valid folder configuration";
+        qWarning() << "   `->" << file << "is not a valid folder configuration";
         return;
     }
 
@@ -197,7 +213,16 @@ void Application::setupFolderFromConfigFile(const QString &file) {
 
     QVariant backend = settings.value("folder/backend");
     if (!backend.isNull()) {
-        if (backend.toString() == "unison") {
+        if( backend.toString() == "sitecopy") {
+
+            SiteCopyFolder *scf = new SiteCopyFolder( file,
+                                                      path.toString(),
+                                                      QString(),
+                                                      this);
+            folder = scf;
+
+        }
+        else if (backend.toString() == "unison") {
             folder = new UnisonFolder(file,
                                       path.toString(),
                                       settings.value("backend:unison/secondPath").toString(),

+ 1 - 1
src/mirall/folder.cpp

@@ -24,7 +24,7 @@
 #include "mirall/folder.h"
 #include "mirall/folderwatcher.h"
 
-#define DEFAULT_POLL_INTERVAL_SEC 60
+#define DEFAULT_POLL_INTERVAL_SEC 10
 
 namespace Mirall {
 

+ 59 - 11
src/mirall/folderwizard.cpp

@@ -20,6 +20,8 @@
 #include <QValidator>
 #include <QWizardPage>
 
+#include <stdlib.h>
+
 #include "mirall/folderwizard.h"
 
 namespace Mirall
@@ -62,12 +64,10 @@ FolderWizardTargetPage::FolderWizardTargetPage()
 
     registerField("local?", _ui.localFolderRadioBtn);
     registerField("remote?", _ui.urlFolderRadioBtn);
-
+    registerField("OC?", _ui.OCRadioBtn);
     registerField("targetLocalFolder", _ui.localFolder2LineEdit);
     registerField("targetURLFolder", _ui.urlFolderLineEdit);
-
-    registerField("onlyOnline?", _ui.checkBoxOnlyOnline);
-    registerField("onlyThisLAN?", _ui.checkBoxOnlyThisLAN);
+    registerField("targetOCFolder", _ui.OCFolderLineEdit);
 }
 
 FolderWizardTargetPage::~FolderWizardTargetPage()
@@ -78,10 +78,11 @@ bool FolderWizardTargetPage::isComplete() const
 {
     if (_ui.localFolderRadioBtn->isChecked()) {
         return QFileInfo(_ui.localFolder2LineEdit->text()).isDir();
-    }
-    else if (_ui.urlFolderRadioBtn->isChecked()) {
+    } else if (_ui.urlFolderRadioBtn->isChecked()) {
         QUrl url(_ui.urlFolderLineEdit->text());
         return url.isValid() && (url.scheme() == "sftp" || url.scheme() == "smb");
+    } else if( _ui.OCRadioBtn->isChecked()) {
+        return true;
     }
     return false;
 }
@@ -127,11 +128,9 @@ void FolderWizardTargetPage::slotToggleItems()
 
     enabled = _ui.urlFolderRadioBtn->isChecked();
     _ui.urlFolderLineEdit->setEnabled(enabled);
-    _ui.checkBoxOnlyOnline->setEnabled(enabled);
-    _ui.checkBoxOnlyThisLAN->setEnabled(enabled);
 
-    _ui.checkBoxOnlyThisLAN->setEnabled(_ui.checkBoxOnlyOnline->isEnabled() &&
-                                        _ui.checkBoxOnlyOnline->isChecked());
+    enabled = _ui.OCRadioBtn->isChecked();
+    _ui.OCFolderLineEdit->setEnabled(enabled);
 }
 
 void FolderWizardTargetPage::on_localFolder2ChooseBtn_clicked()
@@ -144,6 +143,53 @@ void FolderWizardTargetPage::on_localFolder2ChooseBtn_clicked()
     }
 }
 
+FolderWizardNetworkPage::FolderWizardNetworkPage()
+{
+    _ui.setupUi(this);
+    registerField("onlyNetwork*", _ui.checkBoxOnlyOnline);
+    registerField("onlyLocalNetwork*", _ui.checkBoxOnlyThisLAN );
+}
+
+FolderWizardNetworkPage::~FolderWizardNetworkPage()
+{
+}
+
+bool FolderWizardNetworkPage::isComplete() const
+{
+    return true;
+}
+
+FolderWizardOwncloudPage::FolderWizardOwncloudPage()
+{
+    _ui.setupUi(this);
+    registerField("OCUrl*",       _ui.lineEditOCUrl);
+    registerField("OCUser*",      _ui.lineEditOCUser );
+    registerField("OCPasswd",     _ui.lineEditOCPasswd);
+    registerField("OCSiteAlias*", _ui.lineEditOCAlias);
+}
+
+FolderWizardOwncloudPage::~FolderWizardOwncloudPage()
+{
+}
+
+void FolderWizardOwncloudPage::initializePage()
+{
+    _ui.lineEditOCAlias->setText( "Owncloud" );
+    _ui.lineEditOCUrl->setText( "http://localhost/owncloud" );
+    QString user( getenv("USER"));
+    _ui.lineEditOCUser->setText( user );
+}
+
+bool FolderWizardOwncloudPage::isComplete() const
+{
+
+    bool hasAlias = !(_ui.lineEditOCAlias->text().isEmpty());
+    QUrl u( _ui.lineEditOCUrl->text() );
+    bool hasUrl   = u.isValid();
+
+    return hasAlias && hasUrl;
+}
+
 /**
  * Folder wizard itself
  */
@@ -153,8 +199,10 @@ FolderWizard::FolderWizard(QWidget *parent)
 {
     setPage(Page_Source, new FolderWizardSourcePage());
     setPage(Page_Target, new FolderWizardTargetPage());
+    setPage(Page_Network, new FolderWizardNetworkPage());
+    setPage(Page_Owncloud, new FolderWizardOwncloudPage());
 }
 
-}
+} // end namespace
 
 #include "folderwizard.moc"

+ 37 - 1
src/mirall/folderwizard.h

@@ -19,6 +19,9 @@
 
 #include "ui_folderwizardsourcepage.h"
 #include "ui_folderwizardtargetpage.h"
+#include "ui_folderwizardnetworkpage.h"
+#include "ui_folderwizardowncloudpage.h"
+
 
 namespace Mirall {
 
@@ -72,6 +75,37 @@ private:
     Ui_FolderWizardTargetPage _ui;
 };
 
+class FolderWizardNetworkPage : public QWizardPage
+{
+    Q_OBJECT
+public:
+    FolderWizardNetworkPage();
+    ~FolderWizardNetworkPage();
+
+    virtual bool isComplete() const;
+
+protected slots:
+
+private:
+    Ui_FolderWizardNetworkPage _ui;
+};
+
+class FolderWizardOwncloudPage : public QWizardPage
+{
+    Q_OBJECT
+public:
+    FolderWizardOwncloudPage();
+    ~FolderWizardOwncloudPage();
+
+    virtual bool isComplete() const;
+    void initializePage();
+
+protected slots:
+
+private:
+    Ui_FolderWizardOwncloudPage _ui;
+
+};
 
 /**
  * Available fields registered:
@@ -91,7 +125,9 @@ public:
 
     enum {
         Page_Source,
-        Page_Target
+        Page_Target,
+        Page_Network,
+        Page_Owncloud
     };
 
     FolderWizard(QWidget *parent = 0L);

+ 71 - 0
src/mirall/folderwizardnetworkpage.ui

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FolderWizardNetworkPage</class>
+ <widget class="QWidget" name="FolderWizardNetworkPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>435</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout_2">
+   <item row="0" column="0">
+    <widget class="QLabel" name="label_2">
+     <property name="font">
+      <font>
+       <pointsize>14</pointsize>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Network Settings</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Set networking options:</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <widget class="QCheckBox" name="checkBoxOnlyOnline">
+        <property name="text">
+         <string>Only enable if network is available</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QCheckBox" name="checkBoxOnlyThisLAN">
+        <property name="text">
+         <string>restrict to this local network</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>172</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 101 - 0
src/mirall/folderwizardowncloudpage.ui

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FolderWizardOwncloudPage</class>
+ <widget class="QWidget" name="FolderWizardOwncloudPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>435</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout_2">
+   <item row="2" column="0">
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Owncloud Settings</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="lineEditOCUrl"/>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>URL:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="label_3">
+        <property name="text">
+         <string>User:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QLineEdit" name="lineEditOCUser"/>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="label_4">
+        <property name="text">
+         <string>Password:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <widget class="QLineEdit" name="lineEditOCPasswd">
+        <property name="echoMode">
+         <enum>QLineEdit::Password</enum>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="lineEditOCAlias"/>
+      </item>
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_5">
+        <property name="text">
+         <string>Alias:</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>172</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="0" column="0">
+    <widget class="QLabel" name="label_2">
+     <property name="font">
+      <font>
+       <pointsize>14</pointsize>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Owncloud</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 56 - 55
src/mirall/folderwizardsourcepage.ui

@@ -6,79 +6,80 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>300</height>
+    <width>423</width>
+    <height>226</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <widget class="QLabel" name="label_2">
+  <layout class="QGridLayout" name="gridLayout_2">
+   <item row="0" column="0">
+    <widget class="QLabel" name="label_3">
+     <property name="font">
+      <font>
+       <pointsize>14</pointsize>
+      </font>
+     </property>
      <property name="text">
-      <string>Please give this folder an alias:</string>
+      <string>Local Syncronisation Source</string>
      </property>
     </widget>
    </item>
-   <item>
-    <widget class="QLineEdit" name="aliasLineEdit">
-     <property name="placeholderText">
-      <string>Music</string>
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Pick a folder on your computer to backup/synchronize:</string>
      </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QLineEdit" name="localFolderLineEdit">
+          <property name="placeholderText">
+           <string>/home/local1</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="localFolderChooseBtn">
+          <property name="text">
+           <string>&amp;Choose...</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item row="1" column="0">
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QLabel" name="label_2">
+          <property name="text">
+           <string>Directory alias name:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="aliasLineEdit">
+          <property name="placeholderText">
+           <string>Music</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
     </widget>
    </item>
-   <item>
-    <widget class="QLabel" name="label">
-     <property name="text">
-      <string>Which folder in your computer you want to backup/synchronize?</string>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_2">
-     <item>
-      <widget class="QLineEdit" name="localFolderLineEdit">
-       <property name="placeholderText">
-        <string>/home/local1</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="localFolderChooseBtn">
-       <property name="text">
-        <string>&amp;Choose...</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <spacer name="horizontalSpacer">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
-   </item>
-   <item>
+   <item row="2" column="0">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
      <property name="sizeHint" stdset="0">
       <size>
-       <width>20</width>
-       <height>234</height>
+       <width>349</width>
+       <height>83</height>
       </size>
      </property>
     </spacer>

+ 144 - 174
src/mirall/folderwizardtargetpage.ui

@@ -6,20 +6,27 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>300</height>
+    <width>431</width>
+    <height>292</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
+  <layout class="QGridLayout" name="gridLayout_3">
+   <item row="0" column="0">
     <layout class="QHBoxLayout" name="horizontalLayout_12">
      <item>
       <widget class="QLabel" name="label_3">
+       <property name="font">
+        <font>
+         <pointsize>14</pointsize>
+         <weight>50</weight>
+         <bold>false</bold>
+        </font>
+       </property>
        <property name="text">
-        <string>Sync with:</string>
+        <string>Syncronisation Target</string>
        </property>
       </widget>
      </item>
@@ -38,178 +45,141 @@
      </item>
     </layout>
    </item>
-   <item>
-    <widget class="QRadioButton" name="localFolderRadioBtn">
-     <property name="text">
-      <string>Another local folder</string>
-     </property>
-     <property name="checked">
-      <bool>true</bool>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_11">
-     <item>
-      <spacer name="horizontalSpacer_4">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType">
-        <enum>QSizePolicy::Fixed</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>17</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="localFolder2LineEdit">
-       <property name="placeholderText">
-        <string>/home/local2</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="localFolder2ChooseBtn">
-       <property name="text">
-        <string>C&amp;hoose..</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <widget class="QRadioButton" name="urlFolderRadioBtn">
-     <property name="text">
-      <string>Remote folder (URL)</string>
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Pick a place where the data should go to:</string>
      </property>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <item row="0" column="0">
+       <layout class="QGridLayout" name="gridLayout">
+        <item row="0" column="0" colspan="2">
+         <widget class="QRadioButton" name="localFolderRadioBtn">
+          <property name="text">
+           <string>Another local folder</string>
+          </property>
+          <property name="checked">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="0">
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeType">
+           <enum>QSizePolicy::Fixed</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>22</width>
+            <height>13</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item row="1" column="1">
+         <widget class="QLabel" name="label">
+          <property name="text">
+           <string>Folder name:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="2">
+         <widget class="QLineEdit" name="localFolder2LineEdit">
+          <property name="placeholderText">
+           <string>/home/local2</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="3">
+         <widget class="QPushButton" name="localFolder2ChooseBtn">
+          <property name="text">
+           <string>C&amp;hoose..</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0" colspan="2">
+         <widget class="QRadioButton" name="urlFolderRadioBtn">
+          <property name="text">
+           <string>Remote folder (URL)</string>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="0">
+         <spacer name="horizontalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeType">
+           <enum>QSizePolicy::Fixed</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>22</width>
+            <height>13</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item row="3" column="1">
+         <widget class="QLabel" name="label_2">
+          <property name="text">
+           <string>URL:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="2">
+         <widget class="QLineEdit" name="urlFolderLineEdit">
+          <property name="placeholderText">
+           <string>scp://john@host.com//myfolder</string>
+          </property>
+         </widget>
+        </item>
+        <item row="4" column="0" colspan="2">
+         <widget class="QRadioButton" name="OCRadioBtn">
+          <property name="text">
+           <string>to Owncloud</string>
+          </property>
+         </widget>
+        </item>
+        <item row="5" column="0">
+         <spacer name="horizontalSpacer_3">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeType">
+           <enum>QSizePolicy::Fixed</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>22</width>
+            <height>13</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item row="5" column="1">
+         <widget class="QLabel" name="label_4">
+          <property name="text">
+           <string>Folder on Owncloud:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="5" column="2">
+         <widget class="QLineEdit" name="OCFolderLineEdit">
+          <property name="placeholderText">
+           <string>Sync</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
     </widget>
    </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_10">
-     <item>
-      <spacer name="horizontalSpacer_15">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType">
-        <enum>QSizePolicy::Fixed</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>17</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="urlFolderLineEdit">
-       <property name="placeholderText">
-        <string>scp://john@host.com//myfolder</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer name="horizontalSpacer_16">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_9">
-     <item>
-      <spacer name="horizontalSpacer_13">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType">
-        <enum>QSizePolicy::Fixed</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>17</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QCheckBox" name="checkBoxOnlyOnline">
-       <property name="text">
-        <string>Sync only when the computer is connected to the network</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer name="horizontalSpacer_14">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_8">
-     <item>
-      <spacer name="horizontalSpacer_11">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType">
-        <enum>QSizePolicy::Fixed</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>38</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QCheckBox" name="checkBoxOnlyThisLAN">
-       <property name="text">
-        <string>Only when connected to this local network</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer name="horizontalSpacer_12">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
-   </item>
-   <item>
+   <item row="2" column="0">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>

+ 144 - 0
src/mirall/sitecopyconfig.cpp

@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@kde.org>
+ *
+ * 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) any later version.
+ *
+ * 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.
+ */
+
+#include "sitecopyconfig.h"
+
+namespace Mirall {
+
+SitecopyConfig::SitecopyConfig()
+{
+
+}
+
+void SitecopyConfig::writeSiteConfig( const QString& localPath,
+                                      const QString& siteAlias, const QString& url,
+                                      const QString& user, const QString& passwd )
+{
+  parseSiteConfig( );
+  // now all configured sites are in the hash mSites.
+  foreach( QString site, mSites.keys() ) {
+    qDebug() << "Known site: " << site;
+  }
+
+  // check if there is already a cloudia site.
+  QHash<QString, QString> cloudiaDefs;
+
+  if( mSites.contains( siteAlias ) ) {
+    cloudiaDefs = mSites[siteAlias];
+  }
+  QUrl ocUrl( url );
+  QString host = ocUrl.host();
+  QString path = ocUrl.path();
+  qDebug() << "Split url, host: " << host << " and path: " << path;
+  // FIXME: Check if user settings are overwritten
+  cloudiaDefs["server"]   = host;
+  cloudiaDefs["protocol"] = "webdav";
+  cloudiaDefs["local"]    = localPath;
+  cloudiaDefs["remote"]   =  path + "/files/webdav.php";
+  cloudiaDefs["password"] = passwd;
+
+  // QString user( getenv("USER"));
+  cloudiaDefs["username"] = user;
+  mSites.insert( siteAlias, cloudiaDefs );
+
+  qDebug() << "** Now Writing!";
+
+  QFile configFile( QDir::homePath() + "/.sitecopyrc" );
+  if( !configFile.open( QIODevice::WriteOnly | QIODevice::Text )) {
+    qDebug() << "Failed to open config file to write.";
+  }
+  QTextStream out(&configFile);
+
+  foreach( QString site, mSites.keys() ) {
+    QHash<QString, QString> configs = mSites[site];
+    qDebug() << "Writing site: <" << site << ">";
+    out << "site " << site << '\n';
+    foreach( QString configKey, configs.keys() ) {
+      out << "  " << configKey << " " << configs[configKey] << '\n';
+      qDebug() << "  Setting: " << configKey << ": " << configs[configKey];
+    }
+     out << '\n';
+   }
+   configFile.close();
+   configFile.setPermissions( QFile::ReadOwner | QFile::WriteOwner );
+
+   // check if the .sitecopy dir is there, if not, create
+   if( !QFile::exists( QDir::homePath() + "/.sitecopy" ) ) {
+     QDir home( QDir::homePath() );
+     if( home.mkdir( ".sitecopy" ) ) {
+       QFile::setPermissions( QDir::homePath() + "/.sitecopy",
+                              QFile::ReadOwner | QFile::WriteOwner | QFile::ExeUser );
+     }
+   }
+ }
+
+bool SitecopyConfig::parseSiteConfig( )
+{
+  QFile configFile( QDir::homePath() + "/.sitecopyrc" );
+  if( ! configFile.exists() ) {
+    qDebug() << "No site config file. Create one!";
+    return false;
+  }
+  if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text))
+    return false;
+
+  while (!configFile.atEnd()) {
+    QByteArray line = configFile.readLine();
+    processConfigLine( line.simplified() );
+  }
+  if( ! mCurrSiteName.isEmpty() ) {
+      mSites.insert(mCurrSiteName, mCurrSite);
+  } else {
+      qDebug() << "ERR: No current Site name found";
+      return false;
+  }
+  qDebug() << "The end of parsing.";
+  return true;
+}
+
+void SitecopyConfig::processConfigLine( const QString& line )
+{
+  if( line.isEmpty() ) return;
+  QStringList li = line.split( QRegExp( "\\s+") );
+  if( li.size() < 2 ) {
+      qDebug() << "Unable to parse line, return: " << line;
+      return;
+  }
+  const QString key = li[0];
+  const QString val = li[1];
+  qDebug() << "Key: " << key << ", Value " << val;
+
+  if( key == QString::fromLatin1("site") && !val.isEmpty() ) {
+    qDebug() << "Found site " << val;
+    if( !mCurrSiteName.isEmpty() && !mCurrSite.isEmpty() ) {
+      // save to the sites hash first
+      mSites.insert( mCurrSiteName, mCurrSite );
+      mCurrSite.clear();
+    }
+    if( !val.isEmpty() ) {
+        mCurrSiteName = val;
+        // new site entry.
+        if( mSites.contains( val ) ) {
+            mCurrSite = mSites[val];
+        }
+    } else {
+        qDebug() << "Found empty site name, can not parse, fix manually!";
+        mCurrSiteName.clear();
+    }
+  } else {
+    mCurrSite.insert( key, val );
+  }
+}
+
+}

+ 40 - 0
src/mirall/sitecopyconfig.h

@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@kde.org>
+ *
+ * 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) any later version.
+ *
+ * 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.
+ */
+#ifndef SITECOPYCONFIG_H
+#define SITECOPYCONFIG_H
+
+#include <QtCore>
+
+namespace Mirall {
+class SitecopyConfig
+{
+public:
+    SitecopyConfig();
+
+    void writeSiteConfig( const QString& localPath, const QString& siteAlias,
+                          const QString& host, const QString& user,
+                          const QString& passwd );
+    bool parseSiteConfig();
+
+private:
+    void processConfigLine( const QString& );
+
+    QHash<QString, QHash<QString, QString> > mSites;
+    QHash<QString, QString>                  mCurrSite;
+    QHash<QString, QStringList>              mChangesHash;
+    QString mCurrSiteName;
+};
+};
+
+#endif // SITECOPYCONFIG_H

+ 236 - 0
src/mirall/sitecopyfolder.cpp

@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@kde.org>
+ *
+ * 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) any later version.
+ *
+ * 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.
+ */
+
+#include <QDebug>
+#include <QDir>
+#include <QMutexLocker>
+#include <QStringList>
+#include <QTextStream>
+#include <QTextCodec>
+
+#include "mirall/sitecopyfolder.h"
+
+
+namespace Mirall {
+
+    SiteCopyFolder::SiteCopyFolder(const QString &alias,
+                               const QString &path,
+                               const QString &secondPath,
+                               QObject *parent)
+      : Folder(alias, path, parent),
+      _SiteCopy(new QProcess(this)),
+      _syncCount(0)
+{
+    QObject::connect(_SiteCopy, SIGNAL(readyReadStandardOutput()),
+                     SLOT(slotReadyReadStandardOutput()));
+
+    QObject::connect(_SiteCopy, SIGNAL(readyReadStandardError()),
+                     SLOT(slotReadyReadStandardError()));
+
+    QObject::connect(_SiteCopy, SIGNAL(stateChanged(QProcess::ProcessState)),
+                     SLOT(slotStateChanged(QProcess::ProcessState)));
+
+    QObject::connect(_SiteCopy, SIGNAL(error(QProcess::ProcessError)),
+                     SLOT(slotError(QProcess::ProcessError)));
+
+    QObject::connect(_SiteCopy, SIGNAL(started()),
+                     SLOT(slotStarted()));
+
+    QObject::connect(_SiteCopy, SIGNAL(finished(int, QProcess::ExitStatus)),
+                     SLOT(slotFinished(int, QProcess::ExitStatus)));
+}
+
+SiteCopyFolder::~SiteCopyFolder()
+{
+}
+
+bool SiteCopyFolder::isBusy() const
+{
+    return (_SiteCopy->state() != QProcess::NotRunning);
+}
+
+void SiteCopyFolder::startSync(const QStringList &pathList)
+{
+    QMutexLocker locker(&_syncMutex);
+
+    emit syncStarted();
+    qDebug() << "PATHLIST: " << pathList;
+
+    startSiteCopy( "--fetch", Status );
+}
+
+
+void SiteCopyFolder::startSiteCopy( const QString& command, SiteCopyState nextState )
+{
+  if( _SiteCopy->state() == QProcess::Running ) {
+    qDebug() << "Process currently running - come back later.";
+    return;
+  }
+
+  if( alias().isEmpty() ) {
+      qDebug() << "Site name not set, can not perform commands!";
+      return;
+  }
+
+  QString programm = "/usr/bin/sitecopy";
+  QStringList args;
+  args << command << alias();
+  qDebug() << "** staring command " << command;
+  mNextStep  = nextState;
+  _lastOutput.clear();
+
+  _SiteCopy->start( programm, args );
+}
+
+void SiteCopyFolder::slotStarted()
+{
+    qDebug() << "    * SiteCopy process started ( PID " << _SiteCopy->pid() << ")";
+    _syncCount++;
+
+    //qDebug() << _SiteCopy->readAllStandardOutput();;
+}
+
+void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+    qDebug() << "    * SiteCopy process finished with status" << exitCode;
+
+    if( exitCode == -1 ) {
+        qDebug() << "Configuration Error, stop processing.";
+        emit( syncFinished( SyncResult( SyncResult::Error )));
+    }
+
+    if( mNextStep == Sync ) {
+      startSiteCopy( "--sync", Finish ); // sync local with cloud data.
+    } else if( mNextStep == Update ) {
+      startSiteCopy( "--update", Finish ); // update from owncloud
+    } else if( mNextStep == Finish ) {
+      qDebug() << "Finished!";
+
+      emit syncFinished((exitCode == -1 ) ?
+                        SyncResult(SyncResult::Error)
+                        : SyncResult(SyncResult::Success));
+      // mLocalChangesSeen = false;
+    } else if( mNextStep == Status ) {
+      startSiteCopy( "--flatlist", DisplayStatus );
+    } else if( mNextStep == DisplayStatus ) {
+        if( exitCode == 1 ) {
+            qDebug() << "Exit-Code: Sync Needed!";
+            analyzeStatus();
+            startSiteCopy( "--update", Status );
+        } else if( exitCode == 0 ) {
+            qDebug() << "No update needed, remote is in sync.";
+            // No update needed
+            emit syncFinished( SyncResult( SyncResult::Success ) );
+        } else {
+            qDebug() << "Got an invalid exit code " << exitCode;
+            emit syncFinished( SyncResult( SyncResult::Error ) );
+        }
+    }
+
+    _lastOutput.clear();
+}
+
+void SiteCopyFolder::analyzeStatus()
+{
+  QString out( _lastOutput );
+  qDebug() << "Output: " << out;
+
+  mChangesHash.clear();
+
+  QStringList items;
+  QString action;
+
+  QStringList li = out.split(QChar('\n'));
+  foreach( QString l, li ) {
+    if( l.startsWith( "sectstart|") ) {
+      action = l.mid(10);
+      qDebug() << "starting to parse " << action;
+    }
+    if( l.startsWith( "sectend|")) {
+      action = l.mid(8);
+      mChangesHash.insert( action, items );
+      items.clear();
+    }
+    if( l.startsWith( "item|" )) {
+      QString item = l.mid(5);
+      items << item;
+    }
+
+    if( l.startsWith("siteend") ) {
+#if 0
+      if( l.endsWith("unchanged") ) {
+        // we are synced and don't do anything
+        // emit statusChange( Unchanged );
+          // FIXME: Bug handling
+          emit syncFinished( SyncResult(SyncResult::Success) );
+      } else if( l.endsWith("changed")) {
+          startSiteCopy( "--update", Status );
+
+        if( mLocalChangesSeen ) {
+          // emit statusChange( SyncToNeeded );
+        } else {
+          // emit statusChange( SyncFromNeeded );
+        }
+
+      }
+#endif
+    }
+  }
+}
+
+void SiteCopyFolder::slotReadyReadStandardOutput()
+{
+    QByteArray arr = _SiteCopy->readAllStandardOutput();
+
+    if( mNextStep == Finish ) {
+        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
+        // render the output to status line
+        QString string = codec->toUnicode( arr );
+        int pos = string.indexOf( QChar('\n'));
+        if( pos > -1 ) {
+            QString newLine = string.mid( 1+pos );
+            _StatusString = newLine;
+        } else {
+            // no newline, append to the status string
+            _StatusString.append( string );
+        }
+        emit statusString( _StatusString );
+
+    } else if( mNextStep == DisplayStatus ) {
+        _lastOutput += arr;
+    }
+
+//    QTextStream stream(&_lastOutput);
+//    stream << _SiteCopy->readAllStandardOutput();;
+}
+
+void SiteCopyFolder::slotReadyReadStandardError()
+{
+    QTextStream stream(&_lastOutput);
+    stream << _SiteCopy->readAllStandardError();;
+}
+
+void SiteCopyFolder::slotStateChanged(QProcess::ProcessState state)
+{
+    //qDebug() << "changed: " << state;
+}
+
+void SiteCopyFolder::slotError(QProcess::ProcessError error)
+{
+    //qDebug() << "error: " << error;
+}
+
+} // ns
+
+#include "sitecopyfolder.moc"

+ 71 - 0
src/mirall/sitecopyfolder.h

@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@kde.org>
+ *
+ * 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) any later version.
+ *
+ * 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.
+ */
+
+#ifndef MIRALL_SiteCopyFOLDER_H
+#define MIRALL_SiteCopyFOLDER_H
+
+#include <QMutex>
+#include <QProcess>
+#include <QStringList>
+
+#include "mirall/folder.h"
+
+class QProcess;
+
+namespace Mirall {
+
+class SiteCopyFolder : public Folder
+{
+    Q_OBJECT
+public:
+    enum SiteCopyState { Sync, Update, Finish, Status, DisplayStatus };
+
+    SiteCopyFolder(const QString &alias,
+                   const QString &path,
+                   const QString &secondPath, QObject *parent = 0L);
+    virtual ~SiteCopyFolder();
+
+    virtual void startSync(const QStringList &pathList);
+
+    virtual bool isBusy() const;
+
+signals:
+    void statusString( const QString& );
+
+protected slots:
+    void slotReadyReadStandardOutput();
+    void slotReadyReadStandardError();
+    void slotStateChanged(QProcess::ProcessState);
+    void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
+    void slotStarted();
+    void slotError(QProcess::ProcessError);
+
+    void startSiteCopy( const QString&, SiteCopyState );
+    void analyzeStatus();
+
+private:
+    QMutex _syncMutex;
+    QProcess *_SiteCopy;
+    int _syncCount;
+
+    QByteArray _lastOutput;
+    QString _StatusString;
+    SiteCopyState mNextStep;
+    QHash<QString, QStringList>              mChangesHash;
+
+};
+
+}
+
+#endif

+ 6 - 0
src/mirall/statusdialog.cpp

@@ -0,0 +1,6 @@
+#include "statusdialog.h"
+
+StatusDialog::StatusDialog(QWidget *parent) :
+    QDialog(parent)
+{
+}

+ 18 - 0
src/mirall/statusdialog.h

@@ -0,0 +1,18 @@
+#ifndef STATUSDIALOG_H
+#define STATUSDIALOG_H
+
+#include <QDialog>
+
+class StatusDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit StatusDialog(QWidget *parent = 0);
+
+signals:
+
+public slots:
+
+};
+
+#endif // STATUSDIALOG_H