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 TQt, and distribute the resulting executable, *
24 * without including the source code for TQt in the source distribution. *
25 * *
26 ******************************************************************************/
33#include <stdlib.h>
34#include <iostream>
35
36#include <tqdatetime.h>
37#include <tqobject.h>
38
39#include <kdebug.h>
40#include <tdestandarddirs.h>
41#include <tdelocale.h>
42
43#include <libkcal/calendarlocal.h>
44#include <libkcal/calendar.h>
45#include <libkcal/event.h>
46#include <libtdepim/kpimprefs.h>
47
48#include "konsolekalendaradd.h"
49
50using namespace KCal;
51using namespace std;
52
53KonsoleKalendarAdd::KonsoleKalendarAdd( KonsoleKalendarVariables *vars )
54{
55 m_variables = vars;
56}
57
59{
60}
61
67{
68 bool status = true;
69
70 kdDebug() << "konsolekalendaradd.cpp::addEvent()" << endl;
71
72 if ( m_variables->isDryRun() ) {
73 cout << i18n( "Insert Event <Dry Run>:" ).local8Bit().data()
74 << endl;
75 printSpecs();
76 } else {
77 if ( m_variables->isVerbose() ) {
78 cout << i18n( "Insert Event <Verbose>:" ).local8Bit().data()
79 << endl;
80 printSpecs();
81 }
82
83 Event *event = new Event();
84
85 event->setDtStart( m_variables->getStartDateTime() );
86 event->setDtEnd( m_variables->getEndDateTime() );
87 event->setSummary( m_variables->getSummary() );
88 event->setFloats( m_variables->getFloating() );
89 event->setDescription( m_variables->getDescription() );
90 event->setLocation( m_variables->getLocation() );
91
92 if ( m_variables->getCalendar()->addEvent( event ) ) {
93 cout << i18n( "Success: \"%1\" inserted" ).
94 arg( m_variables->getSummary() ).local8Bit().data()
95 << endl;
96
97 m_variables->getCalendar()->save();
98
99 } else {
100 cout << i18n( "Failure: \"%1\" not inserted" ).
101 arg( m_variables->getSummary() ).local8Bit().data()
102 << endl;
103 status = false;
104 }
105 }
106
107 kdDebug() << "konsolekalendaradd.cpp::addEvent() | Done " << endl;
108 return status;
109}
110
112{
113
114// If --file specified, then import into that file
115// else, import into the standard calendar
116
117 TQString fileName;
118 if ( m_variables->getCalendarFile().isEmpty() )
119 fileName = locateLocal( "data", "korganizer/std.ics" );
120 else
121 fileName = m_variables->getCalendarFile();
122
123 CalendarLocal *cal = new CalendarLocal( KPimPrefs::timezone() );
124 if ( !cal->load( fileName ) ||
125 !cal->load( m_variables->getImportFile() ) ||
126 !cal->save( fileName ) ) {
127 kdDebug()
128 << "konsolekalendaradd.cpp::importCalendar() | "
129 << "Can't import file: "
130 << m_variables->getImportFile()
131 << endl;
132 return false;
133 }
134 kdDebug()
135 << "konsolekalendaradd.cpp::importCalendar() | "
136 << "Successfully imported file: "
137 << m_variables->getImportFile()
138 << endl;
139 return true;
140}
141
142void KonsoleKalendarAdd::printSpecs()
143{
144 cout << i18n( " What: %1" ).
145 arg( m_variables->getSummary() ).local8Bit().data()
146 << endl;
147
148 cout << i18n( " Begin: %1" ).
149 arg( m_variables->getStartDateTime().toString( TQt::TextDate ) ).local8Bit().data()
150 << endl;
151
152 cout << i18n( " End: %1" ).
153 arg( m_variables->getEndDateTime().toString( TQt::TextDate ) ).local8Bit().data()
154 << endl;
155
156 if ( m_variables->getFloating() == true ) {
157 cout << i18n( " No Time Associated with Event" ).local8Bit().data()
158 << endl;
159 }
160
161 cout << i18n( " Desc: %1" ).
162 arg( m_variables->getDescription() ).local8Bit().data()
163 << endl;
164
165 cout << i18n( " Location: %1" ).
166 arg( m_variables->getLocation() ).local8Bit().data()
167 << endl;
168}
bool addEvent()
Add the Event.
bool addImportedCalendar()
Imports calendar file to current Calendar.
This class provides all the variables for the program.
bool getFloating()
Return if Event is floating.
bool isDryRun()
Is this program only in testing mode?
TQString getImportFile()
Return import filename.
TQString getCalendarFile()
Returns fullpath to calendar file.
TQString getDescription()
Return description.
bool isVerbose()
Should program be more verbose?
TQDateTime getStartDateTime()
Get start date.
TQString getLocation()
Return location information.
TQDateTime getEndDateTime()
Get end date.
CalendarResources * getCalendar()
Get global calendar resources.
Provides the KonsoleKalendarAdd class definition.