File indexing completed on 2024-05-12 05:10:36
0001 /****************************************************************************** 0002 * konsolekalendardelete.cpp * 0003 * * 0004 * KonsoleKalendar is a command line interface to KDE calendars * 0005 * SPDX-FileCopyrightText: 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * 0006 * SPDX-FileCopyrightText: 2003-2005 Allen Winter <winter@kde.org> * 0007 * * 0008 * SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 * 0009 * * 0010 ******************************************************************************/ 0011 /** 0012 * @file konsolekalendardelete.cpp 0013 * Provides the KonsoleKalendarDelete class definition. 0014 * @author Tuukka Pasanen 0015 * @author Allen Winter 0016 */ 0017 #include "konsolekalendardelete.h" 0018 0019 #include <cstdlib> 0020 #include <iostream> 0021 0022 #include "konsolekalendar_debug.h" 0023 #include <KLocalizedString> 0024 #include <QEventLoop> 0025 0026 using namespace KCalendarCore; 0027 using namespace std; 0028 0029 KonsoleKalendarDelete::KonsoleKalendarDelete(KonsoleKalendarVariables *vars) 0030 { 0031 m_variables = vars; 0032 } 0033 0034 KonsoleKalendarDelete::~KonsoleKalendarDelete() = default; 0035 0036 bool KonsoleKalendarDelete::deleteEvent() 0037 { 0038 bool status = false; 0039 0040 qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendardelete.cpp::deleteEvent()"; 0041 0042 /* 0043 * Retrieve event on the basis of the unique string ID 0044 */ 0045 Event::Ptr event = m_variables->getCalendar()->event(m_variables->getUID()); 0046 if (event) { 0047 if (m_variables->isDryRun()) { 0048 cout << i18n("Delete Event <Dry Run>:").data() << endl; 0049 printSpecs(event); 0050 } else { 0051 qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendardelete.cpp:deleteEvent() :" << m_variables->getUID().data(); 0052 0053 if (m_variables->isVerbose()) { 0054 cout << i18n("Delete Event <Verbose>:").data() << endl; 0055 printSpecs(event); 0056 } 0057 0058 QEventLoop loop; 0059 Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar(); 0060 QObject::connect(calendar.data(), &Akonadi::CalendarBase::deleteFinished, &loop, &QEventLoop::quit); 0061 calendar->deleteEvent(event); 0062 loop.exec(); 0063 qCDebug(KONSOLEKALENDAR_LOG) << "Finished deleting"; 0064 status = calendar->incidence(event->uid()) == nullptr; 0065 0066 if (status) { 0067 cout << i18n("Success: \"%1\" deleted", event->summary()).data() << endl; 0068 } else { 0069 cout << i18n("Error deleting: \"%1\"", event->summary()).data() << endl; 0070 } 0071 } 0072 } 0073 0074 qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendardelete.cpp::deleteEvent() | Done"; 0075 return status; 0076 } 0077 0078 void KonsoleKalendarDelete::printSpecs(const Event::Ptr &event) 0079 { 0080 cout << i18n(" UID: %1", m_variables->getUID()).data() << endl; 0081 0082 cout << i18n(" What: %1", event->summary()).data() << endl; 0083 0084 const auto timeZone = m_variables->getCalendar()->timeZone(); 0085 cout << i18n(" Begin: %1", event->dtStart().toTimeZone(timeZone).toString(Qt::TextDate)).data() << endl; 0086 0087 cout << i18n(" End: %1", event->dtEnd().toTimeZone(timeZone).toString(Qt::TextDate)).data() << endl; 0088 0089 cout << i18n(" Desc: %1", event->description()).data() << endl; 0090 0091 cout << i18n(" Location: %1", event->location()).data() << endl; 0092 }