Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / client-api / src / include / windows / vocl / WinItem.h
index d452dfe..e7a9969 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "base/fscapi.h"
 #include "base/Log.h"
+#include "vocl/VObject.h"
 #include <string>
 #include <list>
 #include <map>
@@ -51,15 +52,25 @@ using namespace std;
 
 
 // Versions supported:
-#define VCARD_VERSION                       L"2.1"
-#define VCALENDAR_VERSION                   L"1.0"
+#define VCARD_VERSION                       TEXT("2.1")
+#define VCALENDAR_VERSION                   TEXT("1.0")
+#define VNOTE_VERSION                       TEXT("1.1")
+#define SIF_VERSION                         TEXT("1.1")
+
 
 // Error messages:
 #define ERR_ITEM_VOBJ_PARSE                 "VConverter: error occurred parsing the item data."
 #define ERR_ITEM_VOBJ_WRONG_TYPE            "Error: wrong vobject type \"%ls\" (\"%ls\" expected)"
 #define ERR_ITEM_VOBJ_TYPE_NOTFOUND         "Error: vobject type not specified (\"%ls\" expected)"
+#define ERR_SIFFIELDS_NULL                  "Parsing error: sifFields must be initialized before parsing data."
 #define INFO_ITEM_VOBJ_WRONG_VERSION        "Warning! Wrong vobject version \"%ls\" (\"%ls\" expected)"
 #define INFO_ITEM_VOBJ_VERSION_NOTFOUND     "Warning! VObject version not specified (\"%ls\" expected)"
+#include "base/globalsdef.h"
+
+BEGIN_NAMESPACE
+
+
+typedef map<wstring,wstring>::iterator      mapIterator;
 
 
 /**
@@ -72,18 +83,27 @@ using namespace std;
 class WinItem {
 
 private:
+
+    /// A dummy bad string "<NULL>", used by methods that return a reference
+    /// to an internal property value, when the property is missing.
     static wstring badString;
 
 
+protected:
+
+    /// The table used to calculate the crc.
+    static unsigned long crc32Table[256];
+
+
 public:
     
     /**
      * Map <propertyName, propertyValue> of props exchanged.
-     * - Client to Server: contains props supported by Client, should be filled
-     *                     by Client calling setProperty() for each property.
+     * - Client to Server: contains props supported by Client, MUST be filled by Client 
+     *                     calling setProperty() for each property, before calling toString().
      * - Server to Client: contains props parsed from vCard/vCalendar, it's automatically
-     *                     filled by parsers of derived classes. Client should call getProperty()
-     *                     for each property he wants to retrieve.
+     *                     filled by parsers of derived classes. Client SHOULD call getProperty()
+     *                     for each property he wants to retrieve, after calling parse().
     */
     map<wstring,wstring> propertyMap;
 
@@ -97,6 +117,9 @@ public:
     /// Returns the size of propertyMap;
     int getPropertyMapSize();
 
+    /// Returns a reference to the internal propertyMap.
+    map<wstring,wstring>& getPropertyMap();
+
 
     /**
      * Sets a property value of name 'propertyName'.
@@ -108,6 +131,16 @@ public:
     void setProperty(const wstring propertyName, const wstring propertyValue);
 
     /**
+     * Sets a integer property value of name 'propertyName'.
+     * Like 'setProperty', but the input value is integer and it's formatted
+     * into a string.
+     * @param  propertyName   the name of property to set
+     * @param  propertyValue  the integer value of property to set
+     */
+    void setIntProperty(const wstring propertyName, const int intValue);
+
+
+    /**
      * Gets a property value from its name.
      * Retrieves the value from the propertyMap. If property is not
      * found, returns false.
@@ -131,6 +164,17 @@ public:
      */
     wstring& getPropertyRef(const wstring propertyName, bool* found);
 
+    /**
+     * Gets a property value from its name, and convert into a integer value.
+     * Retrieves the value from the propertyMap. If property is not
+     * found or not correctly converted into int, returns false.
+     * @param  propertyName   the name of property to retrieve
+     * @param  propertyValue  [IN-OUT] the value of property, integer value
+     * @return                true if property found, false if not found or wrong format
+     */
+    bool getIntProperty(const wstring propertyName, int* intValue);
+
+
     void removeElement(wstring key);
 
     /// Reset the propertyMap (clear all rows).
@@ -139,13 +183,53 @@ public:
     /// Reset all fields values of the propertyMap (only values).
     void resetAllValues();
 
+
+    /**
+     * Format and return a string from the propertyMap.
+     * Not supported properties are ignored and so not formatted 
+     * as they don't have a correspondence in propertyMap.
+     * @return  the string formatted, reference to internal wstring
+     */
+    virtual wstring& toString() = 0;
+
+    /**
+     * Parse a string and fills the propertyMap.
+     * The map is cleared and will contain only found properties
+     * at the end of the parsing.
+     * @param dataString  input vCard string to be parsed
+     * @return            0 if no errors
+     */
+    virtual int parse(const wstring dataString) = 0;
+
+
     /**
     * Return the crc value of the internal map with all values.
-    * It uses only the values of the map not the key
+    * It uses only the values of the map not the key.
+    * Can be overrided by derived classes if other properties are involved
+    * (e.g. Events have recucurrence props and exceptions)
     */
-    long getCRC();
+    virtual long getCRC();
+
+    /**
+     * Utility to safe-retrieve the property value inside VObject 'vo'.
+     * @param vo           : VObject to read from
+     * @param propertyName : the property name requested
+     * @return               the property value (NULL if not found)
+     */
+    WCHAR* getVObjectPropertyValue(VObject* vo, const WCHAR* propertyName);
+
+
+    /**
+     * Util function that returns the name of the item, usually the "Subject" property.
+     * It should be implemented by derived classes to return a desired value.
+     * If property doesn't exist, returns "<NULL>"
+     */
+    virtual wstring& getName();
 };
 
+
+END_NAMESPACE
+
 /** @} */
 /** @endcond */
 #endif