35 #include <calendarsupport/kcalprefs.h>
38 #include <kstandarddirs.h>
39 #include <ksystemtimezone.h>
42 #include <KCalCore/Event>
43 #include <Akonadi/Calendar/IncidenceChanger>
44 #include <Akonadi/Collection>
46 #include <QtCore/QDateTime>
47 #include <QtCore/QObject>
53 using namespace KCalCore;
73 kDebug() <<
"konsolekalendaradd.cpp::addEvent()";
75 if ( m_variables->isDryRun() ) {
76 cout << i18n(
"Insert Event <Dry Run>:" ).toLocal8Bit().data()
80 if ( m_variables->isVerbose() ) {
81 cout << i18n(
"Insert Event <Verbose>:" ).toLocal8Bit().data()
86 Event::Ptr
event = Event::Ptr(
new Event() );
88 KDateTime::Spec timeSpec = m_variables->getCalendar()->timeSpec();
89 event->setDtStart( KDateTime( m_variables->getStartDateTime(), timeSpec ) );
90 event->setDtEnd( KDateTime( m_variables->getEndDateTime(), timeSpec ) );
91 event->setSummary( m_variables->getSummary() );
92 event->setAllDay( m_variables->getFloating() );
93 event->setDescription( m_variables->getDescription() );
94 event->setLocation( m_variables->getLocation() );
96 Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar();
98 QObject::connect(calendar.data(), SIGNAL(createFinished(
bool,QString)),
102 Q_ASSERT(calendar->incidence(event->uid()) == 0 );
103 if (!m_variables->allowGui()) {
104 Akonadi::IncidenceChanger *changer = calendar->incidenceChanger();
105 changer->setShowDialogsOnError(
false);
106 Akonadi::Collection collection = m_variables->collectionId() != -1 ? Akonadi::Collection(m_variables->collectionId())
107 : Akonadi::Collection(CalendarSupport::KCalPrefs::instance()->defaultCalendarId());
109 if (!collection.isValid()) {
110 cout << i18n(
"Calendar is invalid. Please specify one with --calendar").toLocal8Bit().data() <<
"\n";
113 changer->setDefaultCollection(collection);
114 changer->setDestinationPolicy(Akonadi::IncidenceChanger::DestinationPolicyNeverAsk);
116 calendar->addEvent(event);
118 kDebug() <<
"Creation took " << t.elapsed() <<
"ms.";
119 status = calendar->incidence(event->uid()) != 0;
121 cout << i18n(
"Success: \"%1\" inserted",
122 m_variables->getSummary() ).toLocal8Bit().data()
126 cout << i18n(
"Failure: \"%1\" not inserted",
127 m_variables->getSummary() ).toLocal8Bit().data()
133 kDebug() <<
"konsolekalendaradd.cpp::addEvent() | Done";
167 void KonsoleKalendarAdd::printSpecs()
169 cout << i18n(
" What: %1",
170 m_variables->getSummary() ).toLocal8Bit().data()
173 cout << i18n(
" Begin: %1",
174 m_variables->getStartDateTime().toString( Qt::TextDate ) ).toLocal8Bit().data()
177 cout << i18n(
" End: %1",
178 m_variables->getEndDateTime().toString( Qt::TextDate ) ).toLocal8Bit().data()
181 if ( m_variables->getFloating() == true ) {
182 cout << i18n(
" No Time Associated with Event" ).toLocal8Bit().data()
186 cout << i18n(
" Desc: %1",
187 m_variables->getDescription() ).toLocal8Bit().data()
190 cout << i18n(
" Location: %1",
191 m_variables->getLocation() ).toLocal8Bit().data()
KonsoleKalendarAdd(KonsoleKalendarVariables *vars)
Constructs a KonsoleKalendarAdd object from command line arguments.
Provides the KonsoleKalendarAdd class definition.
This class provides all the variables for the program.
bool addImportedCalendar()
Imports calendar file to current Calendar.
bool addEvent()
Add the Event.
~KonsoleKalendarAdd()
Destructor.