summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-09-19 10:38:26 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-09-19 10:38:26 (GMT)
commit3333595d5f0912dacefb56581ce3d09c88dcd092 (patch)
treecd6946f232bd5994a18d03f02b4f62712e6e4e90
parentdccb00af60856a9157dd1e0b2a27533f965a3d62 (diff)
downloadlibkolabxml-3333595d5f0912dacefb56581ce3d09c88dcd092.tar.gz
Snippets format.
-rw-r--r--schemas/kolabformat.xsd24
-rw-r--r--src/containers/kolabconfiguration.cpp13
-rw-r--r--src/containers/kolabconfiguration.h52
-rw-r--r--src/kolabconversions.h39
-rw-r--r--tests/bindingstest.cpp29
-rw-r--r--tests/bindingstest.h1
6 files changed, 156 insertions, 2 deletions
diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index 0e8c8d8..f65c96e 100644
--- a/schemas/kolabformat.xsd
+++ b/schemas/kolabformat.xsd
@@ -101,6 +101,7 @@
<xs:restriction base="xs:token">
<xs:enumeration value="dictionary"/>
<xs:enumeration value="categorycolor"/>
+ <xs:enumeration value="snippets"/>
</xs:restriction>
</xs:simpleType>
@@ -117,6 +118,26 @@
<xs:element name="categorycolor" type="CategoryColor"/>
+ <xs:simpleType name="textformatType">
+ <xs:restriction base="xs:token">
+ <xs:enumeration value="PLAIN"/>
+ <xs:enumeration value="HTML"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:element name="textformat" type="textformatType" />
+
+ <xs:complexType name="Snippet" mixed="true" >
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="text" type="xs:string"/>
+ <xs:element name="textformat" type="textformatType"/>
+ <xs:element name="shortcut" type="xs:string" minOccurs="0"/>
+ </xs:sequence>
+ <xs:attribute name="color" type="xs:string" />
+ </xs:complexType>
+
+ <xs:element name="snippet" type="Snippet"/>
<xs:complexType name="Configuration">
<xs:complexContent mixed="false">
@@ -132,6 +153,9 @@
<xs:element name="e" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<!-- Categorycolor -->
<xs:element name="categorycolor" type="CategoryColor" minOccurs="0" maxOccurs="unbounded"/>
+ <!-- Snippets -->
+ <xs:element name="name" type="xs:string" minOccurs="0"/>
+ <xs:element name="snippet" type="Snippet" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
diff --git a/src/containers/kolabconfiguration.cpp b/src/containers/kolabconfiguration.cpp
index 2129371..afe8a7d 100644
--- a/src/containers/kolabconfiguration.cpp
+++ b/src/containers/kolabconfiguration.cpp
@@ -24,6 +24,7 @@ struct Configuration::Private {
std::vector<CategoryColor> categoryColor;
Dictionary dictionary;
+ SnippetsCollection snippets;
ConfigurationType type;
std::string uid;
cDateTime created;
@@ -49,6 +50,13 @@ Configuration::Configuration(const Dictionary &dict)
d->type = TypeDictionary;
}
+Configuration::Configuration(const SnippetsCollection &snippets)
+: d(new Configuration::Private)
+{
+ d->snippets = snippets;
+ d->type = TypeSnippet;
+}
+
Configuration::Configuration(const Configuration &other)
: d(new Configuration::Private)
{
@@ -116,6 +124,9 @@ Dictionary Configuration::dictionary() const
return d->dictionary;
}
-
+SnippetsCollection Configuration::snippets() const
+{
+ return d->snippets;
+}
} //Namespace
diff --git a/src/containers/kolabconfiguration.h b/src/containers/kolabconfiguration.h
index d29ff1e..330167c 100644
--- a/src/containers/kolabconfiguration.h
+++ b/src/containers/kolabconfiguration.h
@@ -62,11 +62,59 @@ private:
std::vector<CategoryColor> mSubcategories;
};
+struct Snippet {
+ enum TextType {
+ Plain,
+ HTML
+ };
+
+ Snippet(): mTextType(Plain) {}
+ Snippet(const std::string &name, const std::string &text): mName(name), mText(text), mTextType(Plain) {}
+
+ bool operator==(const Snippet &other) const {
+ return mName == other.mName && mText == other.mText && mTextType == other.mTextType && mShortcut == other.mShortcut;
+ }
+
+ std::string name() const { return mName; }
+ std::string text() const { return mText; }
+
+ void setTextType(TextType type) { mTextType = type; }
+ TextType textType() const { return mTextType; }
+
+ void setShortCut(const std::string &shortcut) { mShortcut = shortcut; }
+ std::string shortCut() const { return mShortcut; }
+
+private:
+ std::string mName;
+ std::string mText;
+ TextType mTextType;
+ std::string mShortcut;
+};
+
+struct SnippetsCollection {
+ SnippetsCollection() {}
+ SnippetsCollection(const std::string &name): mName(name) {}
+
+ bool operator==(const SnippetsCollection &other) const {
+ return mName == other.mName && mSnippets == other.mSnippets;
+ }
+
+ std::string name() const { return mName; }
+
+ void setSnippets(const std::vector<Snippet> &snippets) { mSnippets = snippets; }
+ std::vector<Snippet> snippets() const { return mSnippets; }
+
+private:
+ std::string mName;
+ std::vector<Snippet> mSnippets;
+};
+
class Configuration {
public:
Configuration();
Configuration(const std::vector<CategoryColor> &);
Configuration(const Dictionary &);
+ Configuration(const SnippetsCollection &);
Configuration(const Configuration &);
~Configuration();
void operator=(const Configuration &);
@@ -85,11 +133,13 @@ public:
enum ConfigurationType {
Invalid,
TypeDictionary,
- TypeCategoryColor
+ TypeCategoryColor,
+ TypeSnippet
};
ConfigurationType type() const;
std::vector<CategoryColor> categoryColor() const;
Dictionary dictionary() const;
+ SnippetsCollection snippets() const;
private:
struct Private;
boost::scoped_ptr<Private> d;
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index f4ae321..fc511d0 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -127,6 +127,8 @@ KolabXSD::Configuration::type_type getConfiguratinoType(Kolab::Configuration::Co
return KolabXSD::Configuration::type_type::dictionary;
case Kolab::Configuration::TypeCategoryColor:
return KolabXSD::Configuration::type_type::categorycolor;
+ case Kolab::Configuration::TypeSnippet:
+ return KolabXSD::Configuration::type_type::snippets;
default:
CRITICAL("Invalid configuration type");
}
@@ -171,6 +173,22 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
case Kolab::Configuration::TypeCategoryColor:
writeColors(n.categorycolor(), note.categoryColor());
break;
+ case Kolab::Configuration::TypeSnippet: {
+ const Kolab::SnippetsCollection &snippets = note.snippets();
+ n.name(snippets.name());
+ BOOST_FOREACH(const Kolab::Snippet &s, snippets.snippets()) {
+ KolabXSD::Snippet::textformat_type type = KolabXSD::Snippet::textformat_type::PLAIN;
+ if (s.textType() == Snippet::HTML) {
+ type = KolabXSD::Snippet::textformat_type::HTML;
+ }
+ KolabXSD::Configuration::snippet_type snippet(s.name(), s.text(), type);
+ if (!s.shortCut().empty()) {
+ snippet.shortcut(s.shortCut());
+ }
+ n.snippet().push_back(snippet);
+ }
+ }
+ break;
default:
CRITICAL("Invalid configuration type");
return std::string();
@@ -476,6 +494,27 @@ boost::shared_ptr<Kolab::Configuration> deserializeObject <Kolab::Configuration>
n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(dict));
} else if (configuration->type() == KolabXSD::ConfigurationType::categorycolor) {
n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(readColors(configuration->categorycolor())));
+ } else if (configuration->type() == KolabXSD::ConfigurationType::snippets) {
+ std::string name;
+ if (configuration->name()) {
+ name = *configuration->name();
+ }
+ SnippetsCollection collection(name);
+
+ std::vector<Snippet> snippets;
+ BOOST_FOREACH (const KolabXSD::Configuration::snippet_type &entry, configuration->snippet()) {
+ Snippet snippet(entry.name(), entry.text());
+ if (entry.textformat() == KolabXSD::textformatType::HTML) {
+ snippet.setTextType(Snippet::HTML);
+ }
+ if (entry.shortcut()) {
+ snippet.setShortCut(*entry.shortcut());
+ }
+ snippets.push_back(snippet);
+ }
+ collection.setSnippets(snippets);
+
+ n = boost::shared_ptr<Kolab::Configuration>(new Kolab::Configuration(collection));
} else {
CRITICAL("No valid configuration type");
}
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 2e77be5..b742ac5 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -75,6 +75,35 @@ void BindingsTest::dictionaryConfigurationCompletness()
QCOMPARE(re.dictionary(), dict);
}
+void BindingsTest::snippetConfigurationCompletness()
+{
+ std::vector<Kolab::Snippet> list;
+ Kolab::Snippet snippet1("name1", "text1");
+ snippet1.setShortCut("shrtct1");
+ list.push_back(snippet1);
+ Kolab::Snippet snippet2("name1", "text1");
+ snippet2.setTextType(Kolab::Snippet::HTML);
+ list.push_back(snippet2);
+
+ Kolab::SnippetsCollection snippets("collectionname");
+ snippets.setSnippets(list);
+
+ Kolab::Configuration configuration(snippets);
+ 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::TypeSnippet);
+ QCOMPARE(re.snippets(), snippets);
+}
void BindingsTest::noteCompletness()
{
diff --git a/tests/bindingstest.h b/tests/bindingstest.h
index a920818..18a33a7 100644
--- a/tests/bindingstest.h
+++ b/tests/bindingstest.h
@@ -24,6 +24,7 @@ class BindingsTest : public QObject
//Kolabformat
void categorycolorConfigurationCompletness();
void dictionaryConfigurationCompletness();
+ void snippetConfigurationCompletness();
void noteCompletness();
void fileCompletness();
void eventCompletness();