• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

KonsoleKalendar

  • sources
  • kde-4.12
  • kdepim
  • console
  • konsolekalendar
konsolekalendaradd.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * konsolekalendaradd.cpp *
3  * *
4  * KonsoleKalendar is a command line interface to KDE calendars *
5  * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> *
6  * Copyright (C) 2003-2005 Allen Winter <winter@kde.org> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21  * *
22  * As a special exception, permission is given to link this program *
23  * with any edition of Qt, and distribute the resulting executable, *
24  * without including the source code for Qt in the source distribution. *
25  * *
26  ******************************************************************************/
33 #include "konsolekalendaradd.h"
34 
35 #include <calendarsupport/kcalprefs.h>
36 
37 #include <kdebug.h>
38 #include <kstandarddirs.h>
39 #include <ksystemtimezone.h>
40 #include <klocale.h>
41 
42 #include <KCalCore/Event>
43 #include <Akonadi/Calendar/IncidenceChanger>
44 #include <Akonadi/Collection>
45 
46 #include <QtCore/QDateTime>
47 #include <QtCore/QObject>
48 #include <QEventLoop>
49 
50 #include <stdlib.h>
51 #include <iostream>
52 
53 using namespace KCalCore;
54 using namespace std;
55 
56 KonsoleKalendarAdd::KonsoleKalendarAdd( KonsoleKalendarVariables *vars )
57 {
58  m_variables = vars;
59 }
60 
61 KonsoleKalendarAdd::~KonsoleKalendarAdd()
62 {
63 }
64 
69 bool KonsoleKalendarAdd::addEvent()
70 {
71  bool status = true;
72 
73  kDebug() << "konsolekalendaradd.cpp::addEvent()";
74 
75  if ( m_variables->isDryRun() ) {
76  cout << i18n( "Insert Event &lt;Dry Run&gt;:" ).toLocal8Bit().data()
77  << endl;
78  printSpecs();
79  } else {
80  if ( m_variables->isVerbose() ) {
81  cout << i18n( "Insert Event &lt;Verbose&gt;:" ).toLocal8Bit().data()
82  << endl;
83  printSpecs();
84  }
85 
86  Event::Ptr event = Event::Ptr( new Event() );
87 
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() );
95 
96  Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar();
97  QEventLoop loop;
98  QObject::connect(calendar.data(), SIGNAL(createFinished(bool,QString)),
99  &loop, SLOT(quit()));
100  QElapsedTimer t;
101  t.start();
102  Q_ASSERT(calendar->incidence(event->uid()) == 0 ); // can't exist yet
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());
108 
109  if (!collection.isValid()) {
110  cout << i18n("Calendar is invalid. Please specify one with --calendar").toLocal8Bit().data() << "\n";
111  }
112 
113  changer->setDefaultCollection(collection);
114  changer->setDestinationPolicy(Akonadi::IncidenceChanger::DestinationPolicyNeverAsk);
115  }
116  calendar->addEvent(event);
117  loop.exec();
118  kDebug() << "Creation took " << t.elapsed() << "ms.";
119  status = calendar->incidence(event->uid()) != 0;
120  if ( status ) {
121  cout << i18n( "Success: \"%1\" inserted",
122  m_variables->getSummary() ).toLocal8Bit().data()
123  << endl;
124 
125  } else {
126  cout << i18n( "Failure: \"%1\" not inserted",
127  m_variables->getSummary() ).toLocal8Bit().data()
128  << endl;
129  status = false;
130  }
131  }
132 
133  kDebug() << "konsolekalendaradd.cpp::addEvent() | Done";
134  return status;
135 }
136 
137 bool KonsoleKalendarAdd::addImportedCalendar()
138 {
139 
140 // If --file specified, then import into that file
141 // else, import into the standard calendar
142 /*
143  * TODO_SERGIO
144  QString fileName;
145  if ( m_variables->getCalendarFile().isEmpty() ) {
146  fileName = KStandardDirs::locateLocal( "data", "korganizer/std.ics" );
147  } else {
148  fileName = m_variables->getCalendarFile();
149  }
150 
151  CalendarLocal *cal = new CalendarLocal( KSystemTimeZones::local() );
152  if ( !cal->load( fileName ) ||
153  !cal->load( m_variables->getImportFile() ) ||
154  !cal->save( fileName ) ) {
155  kDebug() << "konsolekalendaradd.cpp::importCalendar() |"
156  << "Can't import file:"
157  << m_variables->getImportFile();
158  return false;
159  }
160  kDebug() << "konsolekalendaradd.cpp::importCalendar() |"
161  << "Successfully imported file:"
162  << m_variables->getImportFile();
163  */
164  return true;
165 }
166 
167 void KonsoleKalendarAdd::printSpecs()
168 {
169  cout << i18n( " What: %1",
170  m_variables->getSummary() ).toLocal8Bit().data()
171  << endl;
172 
173  cout << i18n( " Begin: %1",
174  m_variables->getStartDateTime().toString( Qt::TextDate ) ).toLocal8Bit().data()
175  << endl;
176 
177  cout << i18n( " End: %1",
178  m_variables->getEndDateTime().toString( Qt::TextDate ) ).toLocal8Bit().data()
179  << endl;
180 
181  if ( m_variables->getFloating() == true ) {
182  cout << i18n( " No Time Associated with Event" ).toLocal8Bit().data()
183  << endl;
184  }
185 
186  cout << i18n( " Desc: %1",
187  m_variables->getDescription() ).toLocal8Bit().data()
188  << endl;
189 
190  cout << i18n( " Location: %1",
191  m_variables->getLocation() ).toLocal8Bit().data()
192  << endl;
193 }
KonsoleKalendarAdd::KonsoleKalendarAdd
KonsoleKalendarAdd(KonsoleKalendarVariables *vars)
Constructs a KonsoleKalendarAdd object from command line arguments.
Definition: konsolekalendaradd.cpp:56
konsolekalendaradd.h
Provides the KonsoleKalendarAdd class definition.
KonsoleKalendarVariables
This class provides all the variables for the program.
Definition: konsolekalendarvariables.h:73
KonsoleKalendarAdd::addImportedCalendar
bool addImportedCalendar()
Imports calendar file to current Calendar.
Definition: konsolekalendaradd.cpp:137
KonsoleKalendarAdd::addEvent
bool addEvent()
Add the Event.
Definition: konsolekalendaradd.cpp:69
KonsoleKalendarAdd::~KonsoleKalendarAdd
~KonsoleKalendarAdd()
Destructor.
Definition: konsolekalendaradd.cpp:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KonsoleKalendar

Skip menu "KonsoleKalendar"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal