From 47f175743ada27a031c9496a2bd1890c74464b27 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 20:11:02 +0100 Subject: remove non-resources --- akonadish/syntax_modules/akonadi_remove.cpp | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp index 01e4ead..5e11af3 100644 --- a/akonadish/syntax_modules/akonadi_remove.cpp +++ b/akonadish/syntax_modules/akonadi_remove.cpp @@ -39,6 +39,40 @@ namespace AkonadiRemove { +bool remove(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A type is required"), "akonadicreate/02"); + return false; + } + + if (args.count() < 2) { + state.printError(QObject::tr("A resource ID is required to remove items"), "akonadicreate/03"); + return false; + } + + if (args.count() < 3) { + state.printError(QObject::tr("An object ID is required to remove items"), "akonadicreate/03"); + return false; + } + + auto type = args[0]; + auto resourceId = args[1]; + auto identifier = args[2]; + + auto &store = AkonadishUtils::getStore(type); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(resourceId.toUtf8(), identifier.toUtf8()); + + auto result = store.remove(*object).exec(); + result.waitForFinished(); + if (result.errorCode()) { + state.printError(QObject::tr("An error occurred while removing %1 from %1: %2").arg(identifier).arg(resourceId).arg(result.errorMessage()), + "akonaid_create_" + QString::number(result.errorCode())); + } + + return true; +} + bool resource(const QStringList &args, State &state) { if (args.isEmpty()) { -- cgit v1.2.3