summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-02-27 10:49:09 (GMT)
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-02-27 10:49:09 (GMT)
commit384482d848390b2400189c178f98d648de737791 (patch)
tree4320cffef09fe2b4df852f6b9437d5886f9743ca
parent22bb499c4b4d59bccf02ba8c5e5f3fe86510e0a8 (diff)
downloadlibkolabxml-384482d848390b2400189c178f98d648de737791.tar.gz
Tag configuration object.
-rw-r--r--schemas/kolabformat.xsd9
-rw-r--r--src/containers/kolabconfiguration.cpp13
-rw-r--r--src/containers/kolabconfiguration.h46
-rw-r--r--src/kolabconversions.h57
-rw-r--r--tests/bindingstest.cpp29
-rw-r--r--tests/bindingstest.h1
6 files changed, 154 insertions, 1 deletions
diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index f65c96e..58af080 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="tag"/>
</xs:restriction>
</xs:simpleType>
@@ -156,6 +157,14 @@
<!-- Snippets -->
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="snippet" type="Snippet" minOccurs="0" maxOccurs="unbounded"/>
+ <!-- Tag -->
+ <!-- xs:element name="name" type="xs:string" minOccurs="0"/ -->
+ <xs:element name="tagType" type="xs:string" minOccurs="0"/>
+ <xs:element name="color" type="xs:string" minOccurs="0"/>
+ <xs:element name="iconName" type="xs:string" minOccurs="0"/>
+ <xs:element name="priority" type="xs:integer" minOccurs="0"/>
+ <xs:element name="parent" type="xs:string" minOccurs="0"/>
+ <xs:element name="member" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
diff --git a/src/containers/kolabconfiguration.cpp b/src/containers/kolabconfiguration.cpp
index afe8a7d..0e777b9 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;
+ Tag tag;
ConfigurationType type;
std::string uid;
cDateTime created;
@@ -57,6 +58,13 @@ Configuration::Configuration(const SnippetsCollection &snippets)
d->type = TypeSnippet;
}
+Configuration::Configuration(const Tag &tag)
+: d(new Configuration::Private)
+{
+ d->tag = tag;
+ d->type = TypeTag;
+}
+
Configuration::Configuration(const Configuration &other)
: d(new Configuration::Private)
{
@@ -129,4 +137,9 @@ SnippetsCollection Configuration::snippets() const
return d->snippets;
}
+Tag Configuration::tag() const
+{
+ return d->tag;
+}
+
} //Namespace
diff --git a/src/containers/kolabconfiguration.h b/src/containers/kolabconfiguration.h
index 330167c..4d38367 100644
--- a/src/containers/kolabconfiguration.h
+++ b/src/containers/kolabconfiguration.h
@@ -109,12 +109,54 @@ private:
std::vector<Snippet> mSnippets;
};
+struct Tag {
+ Tag(){}
+ Tag(const std::string &name, const std::string &type): mName(name), mType(type) {}
+
+ bool operator==(const Tag &other) const {
+ return mName == other.mName &&
+ mType == other.mType &&
+ mColor == other.mColor &&
+ mIconName == other.mIconName &&
+ mParent == other.mParent &&
+ mMembers == other.mMembers;
+ }
+
+ std::string name() const { return mName; }
+ std::string type() const { return mType; }
+
+ void setColor(const std::string &color) { mColor = color; }
+ std::string color() const { return mColor; }
+
+ void setIconName(const std::string &icon) { mIconName = icon; }
+ std::string iconName() const { return mIconName; }
+
+ void setParent(const std::string &parent) { mParent = parent; }
+ std::string parent() const { return mParent; }
+
+ void setPriority(int priority) { mPriority = priority; }
+ int priority() const { return mPriority; }
+
+ void setMembers(const std::vector<std::string> &members) { mMembers = members; }
+ std::vector<std::string> members() const { return mMembers; }
+
+private:
+ std::string mName;
+ std::string mType;
+ std::string mColor;
+ std::string mIconName;
+ std::string mParent;
+ int mPriority;
+ std::vector<std::string> mMembers;
+};
+
class Configuration {
public:
Configuration();
Configuration(const std::vector<CategoryColor> &);
Configuration(const Dictionary &);
Configuration(const SnippetsCollection &);
+ Configuration(const Tag &);
Configuration(const Configuration &);
~Configuration();
void operator=(const Configuration &);
@@ -134,12 +176,14 @@ public:
Invalid,
TypeDictionary,
TypeCategoryColor,
- TypeSnippet
+ TypeSnippet,
+ TypeTag
};
ConfigurationType type() const;
std::vector<CategoryColor> categoryColor() const;
Dictionary dictionary() const;
SnippetsCollection snippets() const;
+ Tag tag() const;
private:
struct Private;
boost::scoped_ptr<Private> d;
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 39afc05..158ee2b 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -45,6 +45,13 @@ const char* const BASE64 = "BASE64";
using namespace Kolab::Utils;
using namespace Kolab::Shared;
+template <typename T>
+std::vector<std::string> toStringList(const xsd::cxx::tree::sequence<T> &s)
+{
+ std::vector<std::string> d;
+ std::copy(s.begin(), s.end(), std::back_inserter(d));
+ return d;
+}
Kolab::Attachment toAttachment(KolabXSD::attachmentPropType aProp)
{
@@ -129,6 +136,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::TypeTag:
+ return KolabXSD::Configuration::type_type::tag;
default:
CRITICAL("Invalid configuration type");
}
@@ -189,6 +198,29 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
}
}
break;
+ case Kolab::Configuration::TypeTag: {
+ const Kolab::Tag &tag = configuration.tag();
+ n.name(tag.name());
+ if (!tag.type().empty()) {
+ n.tagType(tag.type());
+ }
+ if (!tag.color().empty()) {
+ n.color(tag.color());
+ }
+ if (!tag.iconName().empty()) {
+ n.iconName(tag.iconName());
+ }
+ if (!tag.parent().empty()) {
+ n.parent(tag.parent());
+ }
+ if (!tag.priority() != 0) {
+ n.priority(fromInt<KolabXSD::Configuration::priority_type>(tag.priority()));
+ }
+ BOOST_FOREACH(const std::string &s, tag.members()) {
+ n.member().push_back(s);
+ }
+ }
+ break;
default:
CRITICAL("Invalid configuration type");
return std::string();
@@ -515,6 +547,31 @@ 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::tag) {
+ std::string name;
+ if (configuration->name()) {
+ name = *configuration->name();
+ }
+ std::string type;
+ if (configuration->tagType()) {
+ type = *configuration->tagType();
+ }
+ Tag tag(name, type);
+ if (configuration->color()) {
+ tag.setColor(*configuration->color());
+ }
+ if (configuration->iconName()) {
+ tag.setIconName(*configuration->iconName());
+ }
+ if (configuration->parent()) {
+ tag.setParent(*configuration->parent());
+ }
+ if (configuration->priority()) {
+ tag.setPriority(convertToInt(*configuration->priority()));
+ }
+ tag.setMembers(toStringList(configuration->member()));
+
+ n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(tag));
} else {
CRITICAL("No valid configuration type");
}
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index b742ac5..6391666 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -105,6 +105,35 @@ void BindingsTest::snippetConfigurationCompletness()
QCOMPARE(re.snippets(), snippets);
}
+void BindingsTest::tagConfigurationCompletness()
+{
+ Kolab::Tag tag("name1", "type1");
+ tag.setColor("color");
+ tag.setIconName("icon");
+ tag.setParent("parent");
+ tag.setPriority(3);
+ std::vector<std::string> members;
+ members.push_back("member1");
+ members.push_back("member2");
+ tag.setMembers(members);
+
+ Kolab::Configuration configuration(tag);
+ 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::TypeTag);
+ QCOMPARE(re.tag(), tag);
+}
+
void BindingsTest::noteCompletness()
{
Kolab::Note note;
diff --git a/tests/bindingstest.h b/tests/bindingstest.h
index 18a33a7..a262817 100644
--- a/tests/bindingstest.h
+++ b/tests/bindingstest.h
@@ -25,6 +25,7 @@ class BindingsTest : public QObject
void categorycolorConfigurationCompletness();
void dictionaryConfigurationCompletness();
void snippetConfigurationCompletness();
+ void tagConfigurationCompletness();
void noteCompletness();
void fileCompletness();
void eventCompletness();