Branch 'libkolabxml-1.0' - 3 commits - schemas/kolabformat.xsd src/containers src/csharp src/java src/kolabconversions.h tests/bindingstest.cpp tests/bindingstest.h

Christian Mollekopf mollekopf at kolabsys.com
Fri Oct 3 14:08:27 CEST 2014


 schemas/kolabformat.xsd               |   17 +++++++++++
 src/containers/kolabconfiguration.cpp |   13 ++++++++
 src/containers/kolabconfiguration.h   |   51 +++++++++++++++++++++++++++++++++-
 src/csharp/CMakeLists.txt             |    1 
 src/java/CMakeLists.txt               |    1 
 src/kolabconversions.h                |   37 ++++++++++++++++++++++++
 tests/bindingstest.cpp                |   26 +++++++++++++++++
 tests/bindingstest.h                  |    1 
 8 files changed, 146 insertions(+), 1 deletion(-)

New commits:
commit 134ce6cd8f8d969e5c4aba5ca31f603e9660160c
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Oct 3 12:20:07 2014 +0200

    Implemented host, port, username, password filedriver settings.

diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index 9ff933f..a8a4b62 100644
--- a/schemas/kolabformat.xsd
+++ b/schemas/kolabformat.xsd
@@ -139,6 +139,17 @@
   </xs:complexType>
 
   <xs:element name="snippet" type="Snippet"/>
+
+  <xs:complexType name="FileDriverSettings" mixed="true" >
+    <xs:sequence>
+      <xs:element name="host" type="xs:string" minOccurs="0"/>
+      <xs:element name="port" type="xs:integer" minOccurs="0"/>
+      <xs:element name="username" type="xs:string" minOccurs="0"/>
+      <xs:element name="password" type="xs:string" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="settings" type="FileDriverSettings"/>
   
   <xs:complexType name="Configuration">
     <xs:complexContent mixed="false">
@@ -161,7 +172,7 @@
           <xs:element name="driver" type="xs:string" minOccurs="0"/>
           <xs:element name="title" type="xs:string" minOccurs="0"/>
           <xs:element name="enabled" type="xs:boolean" minOccurs="0"/>
-          <xs:element name="settings" type="xs:string" minOccurs="0"/>
+          <xs:element name="settings" type="FileDriverSettings" minOccurs="0"/>
         </xs:sequence>
       </xs:extension>
     </xs:complexContent>
diff --git a/src/containers/kolabconfiguration.h b/src/containers/kolabconfiguration.h
index 6a27be6..cd36800 100644
--- a/src/containers/kolabconfiguration.h
+++ b/src/containers/kolabconfiguration.h
@@ -117,7 +117,10 @@ struct FileDriver {
         return mDriver == other.mDriver
             && mTitle == other.mTitle
             && mEnabled == other.mEnabled
-            && mSettings == other.mSettings;
+            && mHost == other.mHost
+            && mPort == other.mPort
+            && mUsername == other.mUsername
+            && mPassword == other.mPassword;
     }
 
     void setDriver(const std::string &driver) { mDriver = driver; }
@@ -129,14 +132,26 @@ struct FileDriver {
     void setEnabled(bool enabled) { mEnabled = enabled; }
     bool enabled() const { return mEnabled; }
 
-    void setSettings(const std::string &settings) { mSettings = settings; }
-    std::string settings() const { return mSettings; }
+    void setHost(const std::string &host) { mHost = host; }
+    std::string host() const { return mHost; }
+
+    void setPort(int port) { mPort = port; }
+    int port() const { return mPort; }
+
+    void setUsername(const std::string &username) { mUsername = username; }
+    std::string username() const { return mUsername; }
+
+    void setPassword(const std::string &password) { mPassword = password; }
+    std::string password() const { return mPassword; }
 
 private:
     std::string mDriver;
     std::string mTitle;
     bool mEnabled;
-    std::string mSettings;
+    std::string mHost;
+    int mPort;
+    std::string mUsername;
+    std::string mPassword;
 };
 
 class Configuration {
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 20e91c1..c30c788 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -196,7 +196,13 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
                 n.driver(fileDriver.driver());
                 n.title(fileDriver.title());
                 n.enabled(fileDriver.enabled());
-                n.settings(fileDriver.settings());
+
+                KolabXSD::FileDriverSettings settings;
+                settings.host(fileDriver.host());
+                settings.port(fileDriver.port());
+                settings.username(fileDriver.username());
+                settings.password(fileDriver.password());
+                n.settings(settings);
             }
                 break;
             default:
@@ -536,7 +542,14 @@ boost::shared_ptr<Kolab::Configuration> deserializeObject <Kolab::Configuration>
             }
             Kolab::FileDriver fileDriver(driver, title);
             fileDriver.setEnabled(*configuration->enabled());
-            fileDriver.setSettings(*configuration->settings());
+            if (configuration->settings()) {
+                fileDriver.setHost(*configuration->settings()->host());
+                fileDriver.setPort(convertToInt(*configuration->settings()->port()));
+                fileDriver.setUsername(*configuration->settings()->username());
+                fileDriver.setPassword(*configuration->settings()->password());
+            } else {
+                CRITICAL("Settings are missing");
+            }
 
             n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(fileDriver));
         } else {
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index ed7f203..6a53e26 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -109,7 +109,10 @@ void BindingsTest::fileDriverConfigurationCompletness()
 {
     Kolab::FileDriver fileDriver("driver", "title");
     fileDriver.setEnabled(false);
-    fileDriver.setSettings("settings");
+    fileDriver.setHost("host");
+    fileDriver.setPort(9);
+    fileDriver.setUsername("username");
+    fileDriver.setPassword("password");
 
     Kolab::Configuration configuration(fileDriver);
     configuration.setUid("uid");


commit 4ab87f15600989a707809fd9442e5866ef71973f
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Oct 3 14:02:00 2014 +0200

    Fixed FileDriver bindings.
    
    Conflicts:
    	src/csharp/CMakeLists.txt
    	src/java/CMakeLists.txt

diff --git a/src/csharp/CMakeLists.txt b/src/csharp/CMakeLists.txt
index 21f7796..58b514a 100644
--- a/src/csharp/CMakeLists.txt
+++ b/src/csharp/CMakeLists.txt
@@ -33,6 +33,7 @@ set(KOLAB_SWIG_CSHARP_FILES
         ${CMAKE_CURRENT_BINARY_DIR}/Email.cs
         ${CMAKE_CURRENT_BINARY_DIR}/Event.cs
         ${CMAKE_CURRENT_BINARY_DIR}/File.cs
+        ${CMAKE_CURRENT_BINARY_DIR}/FileDriver.cs
         ${CMAKE_CURRENT_BINARY_DIR}/Geo.cs
         ${CMAKE_CURRENT_BINARY_DIR}/Journal.cs
         ${CMAKE_CURRENT_BINARY_DIR}/Key.cs
diff --git a/src/java/CMakeLists.txt b/src/java/CMakeLists.txt
index 1326983..edd4d47 100644
--- a/src/java/CMakeLists.txt
+++ b/src/java/CMakeLists.txt
@@ -23,6 +23,7 @@ set(KOLAB_SWIG_JAVA_FILES
         ${CMAKE_CURRENT_BINARY_DIR}/Duration.java
         ${CMAKE_CURRENT_BINARY_DIR}/ErrorSeverity.java
         ${CMAKE_CURRENT_BINARY_DIR}/Event.java
+        ${CMAKE_CURRENT_BINARY_DIR}/FileDriver.java
         ${CMAKE_CURRENT_BINARY_DIR}/Geo.java
         ${CMAKE_CURRENT_BINARY_DIR}/Journal.java
         ${CMAKE_CURRENT_BINARY_DIR}/Key.java


commit 67b9e58b437b4d69322c3aaf56d57176916ed931
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Oct 3 14:01:39 2014 +0200

    Added support for the FileDriver Configuration object.
    
    Conflicts:
    	schemas/kolabformat.xsd
    	src/containers/kolabconfiguration.cpp
    	src/containers/kolabconfiguration.h
    	src/kolabconversions.h
    	tests/bindingstest.cpp
    	tests/bindingstest.h

diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index d12134b..9ff933f 100644
--- a/schemas/kolabformat.xsd
+++ b/schemas/kolabformat.xsd
@@ -102,6 +102,7 @@
       <xs:enumeration value="dictionary"/>
       <xs:enumeration value="categorycolor"/>
       <xs:enumeration value="snippets"/>
+      <xs:enumeration value="file_driver"/>
     </xs:restriction>
   </xs:simpleType>
 
@@ -156,6 +157,11 @@
           <!-- Snippets -->
           <xs:element name="name" type="xs:string" minOccurs="0"/>
           <xs:element name="snippet" type="Snippet" minOccurs="0" maxOccurs="unbounded"/>
+          <!-- FileDriver -->
+          <xs:element name="driver" type="xs:string" minOccurs="0"/>
+          <xs:element name="title" type="xs:string" minOccurs="0"/>
+          <xs:element name="enabled" type="xs:boolean" minOccurs="0"/>
+          <xs:element name="settings" type="xs:string" minOccurs="0"/>
         </xs:sequence>
       </xs:extension>
     </xs:complexContent>
diff --git a/src/containers/kolabconfiguration.cpp b/src/containers/kolabconfiguration.cpp
index afe8a7d..e71c209 100644
--- a/src/containers/kolabconfiguration.cpp
+++ b/src/containers/kolabconfiguration.cpp
@@ -25,6 +25,7 @@ struct Configuration::Private {
     std::vector<CategoryColor> categoryColor;
     Dictionary dictionary;
     SnippetsCollection snippets;
+    FileDriver fileDriver;
     ConfigurationType type;
     std::string uid;
     cDateTime created;
@@ -57,6 +58,13 @@ Configuration::Configuration(const SnippetsCollection &snippets)
     d->type = TypeSnippet;
 }
 
+Configuration::Configuration(const FileDriver &fileDriver)
+:   d(new Configuration::Private)
+{
+    d->fileDriver = fileDriver;
+    d->type = TypeFileDriver;
+}
+
 Configuration::Configuration(const Configuration &other)
 :   d(new Configuration::Private)
 {
@@ -129,4 +137,9 @@ SnippetsCollection Configuration::snippets() const
     return d->snippets;
 }
 
+FileDriver Configuration::fileDriver() const
+{
+    return d->fileDriver;
+}
+
 } //Namespace
diff --git a/src/containers/kolabconfiguration.h b/src/containers/kolabconfiguration.h
index 330167c..6a27be6 100644
--- a/src/containers/kolabconfiguration.h
+++ b/src/containers/kolabconfiguration.h
@@ -109,12 +109,43 @@ private:
     std::vector<Snippet> mSnippets;
 };
 
+struct FileDriver {
+    FileDriver(): mEnabled(false) {}
+    FileDriver(const std::string &driver, const std::string &title): mDriver(driver), mTitle(title), mEnabled(true) {}
+
+    bool operator==(const FileDriver &other) const {
+        return mDriver == other.mDriver
+            && mTitle == other.mTitle
+            && mEnabled == other.mEnabled
+            && mSettings == other.mSettings;
+    }
+
+    void setDriver(const std::string &driver) { mDriver = driver; }
+    std::string driver() const { return mDriver; }
+
+    void setTitle(const std::string &title) { mTitle = title; }
+    std::string title() const { return mTitle; }
+
+    void setEnabled(bool enabled) { mEnabled = enabled; }
+    bool enabled() const { return mEnabled; }
+
+    void setSettings(const std::string &settings) { mSettings = settings; }
+    std::string settings() const { return mSettings; }
+
+private:
+    std::string mDriver;
+    std::string mTitle;
+    bool mEnabled;
+    std::string mSettings;
+};
+
 class Configuration {
 public:
     Configuration();
     Configuration(const std::vector<CategoryColor> &);
     Configuration(const Dictionary &);
     Configuration(const SnippetsCollection &);
+    Configuration(const FileDriver &);
     Configuration(const Configuration &);
     ~Configuration();
     void operator=(const Configuration &);
@@ -134,12 +165,15 @@ public:
         Invalid,
         TypeDictionary,
         TypeCategoryColor,
-        TypeSnippet
+        TypeSnippet,
+        TypeFileDriver
     };
     ConfigurationType type() const;
     std::vector<CategoryColor> categoryColor() const;
     Dictionary dictionary() const;
     SnippetsCollection snippets() const;
+    FileDriver fileDriver() const;
+
 private:
     struct Private;
     boost::scoped_ptr<Private> d;
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 39afc05..20e91c1 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -129,6 +129,8 @@ KolabXSD::Configuration::type_type getConfiguratinoType(Kolab::Configuration::Co
             return KolabXSD::Configuration::type_type::categorycolor;
         case Kolab::Configuration::TypeSnippet:
             return KolabXSD::Configuration::type_type::snippets;
+        case Kolab::Configuration::TypeFileDriver:
+            return KolabXSD::Configuration::type_type::file_driver;
         default:
             CRITICAL("Invalid configuration type");
     }
@@ -189,6 +191,14 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
                 }
             }
                 break;
+            case Kolab::Configuration::TypeFileDriver: {
+                const Kolab::FileDriver &fileDriver = configuration.fileDriver();
+                n.driver(fileDriver.driver());
+                n.title(fileDriver.title());
+                n.enabled(fileDriver.enabled());
+                n.settings(fileDriver.settings());
+            }
+                break;
             default:
                 CRITICAL("Invalid configuration type");
                 return std::string();
@@ -515,6 +525,20 @@ boost::shared_ptr<Kolab::Configuration> deserializeObject <Kolab::Configuration>
             collection.setSnippets(snippets);
 
             n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(collection));
+        } else if (configuration->type() == KolabXSD::ConfigurationType::file_driver) {
+            std::string driver;
+            if (configuration->driver()) {
+                driver = *configuration->driver();
+            }
+            std::string title;
+            if (configuration->title()) {
+                title = *configuration->title();
+            }
+            Kolab::FileDriver fileDriver(driver, title);
+            fileDriver.setEnabled(*configuration->enabled());
+            fileDriver.setSettings(*configuration->settings());
+
+            n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(fileDriver));
         } else {
             CRITICAL("No valid configuration type");
         }
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 2aad2b9..ed7f203 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -105,6 +105,29 @@ void BindingsTest::snippetConfigurationCompletness()
     QCOMPARE(re.snippets(), snippets);
 }
 
+void BindingsTest::fileDriverConfigurationCompletness()
+{
+    Kolab::FileDriver fileDriver("driver", "title");
+    fileDriver.setEnabled(false);
+    fileDriver.setSettings("settings");
+
+    Kolab::Configuration configuration(fileDriver);
+    configuration.setUid("uid");
+    configuration.setCreated(Kolab::cDateTime(2006,1,6,12,0,0,true)); //UTC
+    configuration.setLastModified(Kolab::cDateTime(2006,1,6,12,0,0,true)); //UTC
+
+    const std::string &result = Kolab::writeConfiguration(configuration);
+    QCOMPARE(Kolab::error(), Kolab::NoError);
+//     std::cout << result << std::endl;
+    const Kolab::Configuration &re = Kolab::readConfiguration(result, false);
+    QCOMPARE(Kolab::error(), Kolab::NoError);
+    QCOMPARE(re.uid(), configuration.uid());
+    QCOMPARE(re.created(), configuration.created());
+    QCOMPARE(re.lastModified(), configuration.lastModified());
+    QCOMPARE(re.type(), Kolab::Configuration::TypeFileDriver);
+    QCOMPARE(re.fileDriver(), fileDriver);
+}
+
 void BindingsTest::noteCompletness()
 {
     Kolab::Note note;
diff --git a/tests/bindingstest.h b/tests/bindingstest.h
index 18a33a7..2d85a72 100644
--- a/tests/bindingstest.h
+++ b/tests/bindingstest.h
@@ -25,6 +25,7 @@ class BindingsTest : public QObject
     void categorycolorConfigurationCompletness();
     void dictionaryConfigurationCompletness();
     void snippetConfigurationCompletness();
+    void fileDriverConfigurationCompletness();
     void noteCompletness();
     void fileCompletness();
     void eventCompletness();




More information about the commits mailing list