File indexing completed on 2024-05-12 05:10:36

0001 /******************************************************************************
0002  * konsolekalendar.h                                                          *
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 #pragma once
0013 
0014 #include "konsolekalendarvariables.h"
0015 
0016 #include <Akonadi/FetchJobCalendar>
0017 #include <KCalendarCore/Event>
0018 
0019 #include <QDateTime>
0020 
0021 class QTextStream;
0022 
0023 /**
0024  * @file konsolekalendar.h
0025  * Provides the KonsoleKalendar class definition.
0026  */
0027 
0028 /**
0029  * @brief
0030  * The base class of the project.
0031  * @author Tuukka Pasanen
0032  */
0033 class KonsoleKalendar
0034 {
0035 public:
0036     /**
0037      * Constructs a KonsoleKalendar object from command line arguments.
0038      *
0039      * @param variables is a pointer to a #KonsoleKalendarVariables object
0040      * containing all the command line arguments.
0041      */
0042     explicit KonsoleKalendar(KonsoleKalendarVariables *variables);
0043 
0044     /**
0045      * Destructor
0046      */
0047     ~KonsoleKalendar();
0048 
0049     /**
0050      * Visualize what we need.
0051      */
0052     bool showInstance();
0053 
0054     /**
0055      * Imports calendar file
0056      */
0057     bool importCalendar();
0058 
0059     /**
0060      * Add event to calendar
0061      */
0062     bool addEvent();
0063 
0064     /**
0065      * Change event
0066      */
0067     bool changeEvent();
0068 
0069     /**
0070      * Delete event
0071      */
0072     bool deleteEvent();
0073 
0074     /**
0075      * Detect if event already exists
0076      *
0077      * @param  startdate Starting date
0078      * @param  enddate   Ending date
0079      * @param  summary   Which summary event should have have
0080      */
0081     bool isEvent(const QDateTime &startdate, const QDateTime &enddate, const QString &summary);
0082 
0083     /**
0084      * Creates calendar file (If it doesn't exists)
0085      */
0086     bool createCalendar();
0087 
0088     /**
0089      * Prints the available calendars.
0090      */
0091     bool printCalendarList();
0092 
0093 private:
0094     /**
0095      * Print event specs for dryrun and verbose options
0096      */
0097     void printSpecs();
0098 
0099     /**
0100      * Creates an akonadi resource of type ical.
0101      */
0102     bool createAkonadiResource(const QString &icalFileUri);
0103 
0104     /**
0105      * Prints event list in many formats
0106      *
0107      * @param ts is the #QTextStream to be printed
0108      * @param eventList which event we should print
0109      * @param dt is the date to use when printing the event for recurring events
0110      */
0111     bool printEventList(QTextStream *ts, KCalendarCore::Event::List *eventList, QDate dt);
0112 
0113     /**
0114      * Prints a single event in many formats
0115      *
0116      * @param ts is the #QTextStream to be printed
0117      * @param event which we should print
0118      * @param dt is the date to use when printing the event for recurring events
0119      */
0120     bool printEvent(QTextStream *ts, const KCalendarCore::Event::Ptr &event, QDate dt);
0121 
0122     /**
0123      * Variables that changes stuff in program
0124      */
0125     KonsoleKalendarVariables *m_variables = nullptr;
0126 
0127     /**
0128      * Calendar file itself
0129      */
0130     Akonadi::FetchJobCalendar::Ptr m_calendar;
0131 
0132     /**
0133      * This is useful if we like to have same day events to same system
0134      */
0135     QDate m_saveDate;
0136 };