diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-25 20:03:49 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-25 20:03:49 +0100 |
commit | 7e548fbe071d3978a9659cedeb5fbbc183985bc3 (patch) | |
tree | 77bd5914956b2fdd8a0b636e0427b29017b4ad3e | |
parent | 8648ce60eda891404231d7e484de5c2a2a3efd35 (diff) | |
download | sink-7e548fbe071d3978a9659cedeb5fbbc183985bc3.tar.gz sink-7e548fbe071d3978a9659cedeb5fbbc183985bc3.zip |
crete other items
-rw-r--r-- | akonadish/syntax_modules/akonadi_create.cpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/akonadish/syntax_modules/akonadi_create.cpp b/akonadish/syntax_modules/akonadi_create.cpp index 025cd58..377219a 100644 --- a/akonadish/syntax_modules/akonadi_create.cpp +++ b/akonadish/syntax_modules/akonadi_create.cpp | |||
@@ -39,34 +39,45 @@ | |||
39 | namespace AkonadiCreate | 39 | namespace AkonadiCreate |
40 | { | 40 | { |
41 | 41 | ||
42 | /* | 42 | bool create(const QStringList &allArgs, State &state) |
43 | { | 43 | { |
44 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 44 | if (allArgs.isEmpty()) { |
45 | auto &store = getStore(type); | 45 | state.printError(QObject::tr("A type is required"), "akonadicreate/02"); |
46 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; | 46 | return false; |
47 | if (type == "resource") { | 47 | } |
48 | auto resourceType = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 48 | |
49 | object = store.getObject(""); | 49 | if (allArgs.count() < 2) { |
50 | object->setProperty("type", resourceType); | 50 | state.printError(QObject::tr("A resource ID is required to create items"), "akonadicreate/03"); |
51 | } else { | 51 | return false; |
52 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
53 | object = store.getObject(resource); | ||
54 | } | 52 | } |
55 | auto map = consumeMap(args); | 53 | |
54 | auto args = allArgs; | ||
55 | auto type = args.takeFirst(); | ||
56 | auto &store = AkonadishUtils::getStore(type); | ||
57 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; | ||
58 | auto resource = args.takeFirst().toLatin1(); | ||
59 | object = store.getObject(resource); | ||
60 | |||
61 | auto map = AkonadishUtils::keyValueMapFromArgs(args); | ||
56 | for (auto i = map.begin(); i != map.end(); ++i) { | 62 | for (auto i = map.begin(); i != map.end(); ++i) { |
57 | object->setProperty(i.key().toLatin1(), i.value()); | 63 | object->setProperty(i.key().toLatin1(), i.value()); |
58 | } | 64 | } |
65 | |||
59 | auto result = store.create(*object).exec(); | 66 | auto result = store.create(*object).exec(); |
60 | result.waitForFinished(); | 67 | result.waitForFinished(); |
61 | if (result.errorCode()) { | 68 | if (result.errorCode()) { |
62 | std::cout << "An error occurred while creating the entity: " << result.errorMessage().toStdString(); | 69 | state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), |
70 | "akonaid_create_e" + QString::number(result.errorCode())); | ||
63 | } | 71 | } |
72 | |||
73 | return true; | ||
64 | } | 74 | } |
65 | */ | 75 | |
66 | bool resource(const QStringList &args, State &state) | 76 | bool resource(const QStringList &args, State &state) |
67 | { | 77 | { |
68 | if (args.isEmpty()) { | 78 | if (args.isEmpty()) { |
69 | state.printError(QObject::tr("A resource can not be created without a type"), "akonadicreate/01"); | 79 | state.printError(QObject::tr("A resource can not be created without a type"), "akonadicreate/01"); |
80 | return false; | ||
70 | } | 81 | } |
71 | 82 | ||
72 | auto &store = AkonadishUtils::getStore("resource"); | 83 | auto &store = AkonadishUtils::getStore("resource"); |
@@ -84,7 +95,7 @@ bool resource(const QStringList &args, State &state) | |||
84 | result.waitForFinished(); | 95 | result.waitForFinished(); |
85 | if (result.errorCode()) { | 96 | if (result.errorCode()) { |
86 | state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), | 97 | state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), |
87 | "akonaid_create_" + QString::number(result.errorCode())); | 98 | "akonaid_create_e" + QString::number(result.errorCode())); |
88 | } | 99 | } |
89 | 100 | ||
90 | return true; | 101 | return true; |
@@ -95,8 +106,8 @@ Syntax::List syntax() | |||
95 | { | 106 | { |
96 | Syntax::List syntax; | 107 | Syntax::List syntax; |
97 | 108 | ||
98 | Syntax create("create");//, QString(), &AkonadiCreate::resource, Syntax::EventDriven); | 109 | Syntax create("create", QObject::tr("Create items in a resource"), &AkonadiCreate::create); |
99 | create.children << Syntax("resource", QObject::tr("Creates a new resource"), &AkonadiCreate::resource);//, Syntax::EventDriven); | 110 | create.children << Syntax("resource", QObject::tr("Creates a new resource"), &AkonadiCreate::resource); |
100 | 111 | ||
101 | syntax << create; | 112 | syntax << create; |
102 | return syntax; | 113 | return syntax; |