diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-25 18:27:55 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-25 18:27:55 +0100 |
commit | 02ebb2bd3c9a5d4fe224c239b2ea10e7db12ebc6 (patch) | |
tree | 5d815562653b8c0d3fcfaa23e32950fd59d48717 /akonadish/syntax_modules | |
parent | a90342d5fb92092e1d1715eae7f66f33d5b4a66c (diff) | |
download | sink-02ebb2bd3c9a5d4fe224c239b2ea10e7db12ebc6.tar.gz sink-02ebb2bd3c9a5d4fe224c239b2ea10e7db12ebc6.zip |
create resource
Diffstat (limited to 'akonadish/syntax_modules')
-rw-r--r-- | akonadish/syntax_modules/akonadi_create.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/akonadish/syntax_modules/akonadi_create.cpp b/akonadish/syntax_modules/akonadi_create.cpp new file mode 100644 index 0000000..025cd58 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_create.cpp | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include <QCoreApplication> | ||
21 | #include <QDebug> | ||
22 | #include <QObject> // tr() | ||
23 | #include <QModelIndex> | ||
24 | #include <QTime> | ||
25 | |||
26 | #include "common/resource.h" | ||
27 | #include "common/storage.h" | ||
28 | #include "common/domain/event.h" | ||
29 | #include "common/domain/folder.h" | ||
30 | #include "common/resourceconfig.h" | ||
31 | #include "common/log.h" | ||
32 | #include "common/storage.h" | ||
33 | #include "common/definitions.h" | ||
34 | |||
35 | #include "akonadish_utils.h" | ||
36 | #include "state.h" | ||
37 | #include "syntaxtree.h" | ||
38 | |||
39 | namespace AkonadiCreate | ||
40 | { | ||
41 | |||
42 | /* | ||
43 | { | ||
44 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
45 | auto &store = getStore(type); | ||
46 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; | ||
47 | if (type == "resource") { | ||
48 | auto resourceType = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
49 | object = store.getObject(""); | ||
50 | object->setProperty("type", resourceType); | ||
51 | } else { | ||
52 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
53 | object = store.getObject(resource); | ||
54 | } | ||
55 | auto map = consumeMap(args); | ||
56 | for (auto i = map.begin(); i != map.end(); ++i) { | ||
57 | object->setProperty(i.key().toLatin1(), i.value()); | ||
58 | } | ||
59 | auto result = store.create(*object).exec(); | ||
60 | result.waitForFinished(); | ||
61 | if (result.errorCode()) { | ||
62 | std::cout << "An error occurred while creating the entity: " << result.errorMessage().toStdString(); | ||
63 | } | ||
64 | } | ||
65 | */ | ||
66 | bool resource(const QStringList &args, State &state) | ||
67 | { | ||
68 | if (args.isEmpty()) { | ||
69 | state.printError(QObject::tr("A resource can not be created without a type"), "akonadicreate/01"); | ||
70 | } | ||
71 | |||
72 | auto &store = AkonadishUtils::getStore("resource"); | ||
73 | |||
74 | auto resourceType = args.at(0); | ||
75 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(""); | ||
76 | object->setProperty("type", resourceType); | ||
77 | |||
78 | auto map = AkonadishUtils::keyValueMapFromArgs(args); | ||
79 | for (auto i = map.begin(); i != map.end(); ++i) { | ||
80 | object->setProperty(i.key().toLatin1(), i.value()); | ||
81 | } | ||
82 | |||
83 | auto result = store.create(*object).exec(); | ||
84 | result.waitForFinished(); | ||
85 | if (result.errorCode()) { | ||
86 | state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), | ||
87 | "akonaid_create_" + QString::number(result.errorCode())); | ||
88 | } | ||
89 | |||
90 | return true; | ||
91 | } | ||
92 | |||
93 | |||
94 | Syntax::List syntax() | ||
95 | { | ||
96 | Syntax::List syntax; | ||
97 | |||
98 | Syntax create("create");//, QString(), &AkonadiCreate::resource, Syntax::EventDriven); | ||
99 | create.children << Syntax("resource", QObject::tr("Creates a new resource"), &AkonadiCreate::resource);//, Syntax::EventDriven); | ||
100 | |||
101 | syntax << create; | ||
102 | return syntax; | ||
103 | } | ||
104 | |||
105 | REGISTER_SYNTAX(AkonadiCreate) | ||
106 | |||
107 | } | ||