konsolekalendar

konsolekalendarchange.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 * konsolekalendarchange.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 <kdebug.h>
37#include <tdelocale.h>
38
40
41using namespace KCal;
42using namespace std;
43
44KonsoleKalendarChange::KonsoleKalendarChange( KonsoleKalendarVariables *vars )
45{
46 m_variables = vars;
47}
48
50{
51}
52
54{
55 bool status = false;
56
57 kdDebug() << "konsolekalendarchange.cpp::changeEvent()" << endl;
58
59 /*
60 * Retrieve event on the basis of the unique string ID
61 */
62 Event *event = m_variables->getCalendar()->event( m_variables->getUID() );
63 if ( event ) {
64 if ( m_variables->isDryRun() ) {
65 cout << i18n( "Change Event <Dry Run>:" ).local8Bit().data()
66 << endl;
67 printSpecs( event );
68
69 cout << i18n( "To Event <Dry Run>:" ).local8Bit().data()
70 << endl;
71 printSpecs();
72 } else {
73 kdDebug() << "konsolekalendarchange.cpp:changeEvent() : "
74 << m_variables->getUID().local8Bit()
75 << endl;
76
77 if ( m_variables->isVerbose() ) {
78 cout << i18n( "Change Event <Verbose>:" ).local8Bit().data()
79 << endl;
80 printSpecs( event );
81
82 cout << i18n( "To Event <Dry Run>:" ).local8Bit().data()
83 << endl;
84 printSpecs();
85 }
86
87 if ( m_variables->isStartDateTime() ) {
88 event->setDtStart( m_variables->getStartDateTime() );
89 }
90
91 if ( m_variables->isEndDateTime() ) {
92 event->setDtEnd( m_variables->getEndDateTime() );
93 }
94
95 event->setFloats( m_variables->getFloating() );
96
97 if ( m_variables->isSummary() ) {
98 event->setSummary( m_variables->getSummary() );
99 }
100
101 if ( m_variables->isDescription() ) {
102 event->setDescription( m_variables->getDescription() );
103 }
104
105 if ( m_variables->isLocation() ) {
106 event->setLocation( m_variables->getLocation() );
107 }
108
109 if ( m_variables->getCalendar()->addEvent( event ) ) {
110 cout << i18n( "Success: \"%1\" changed" )
111 .arg( event->summary() ).local8Bit().data()
112 << endl;
113
114 m_variables->getCalendar()->save();
115 status = true;
116 } else {
117 cout << i18n( "Failure: \"%1\" not changed" )
118 .arg( event->summary() ).local8Bit().data()
119 << endl;
120 }
121 }
122 }
123
124 kdDebug() << "konsolekalendarchange.cpp::changeEvent() | Done " << endl;
125 return status;
126}
127
128void KonsoleKalendarChange::printSpecs( Event *event )
129{
130 cout << i18n( " UID: %1" ).
131 arg( event->uid() ).local8Bit().data()
132 << endl;
133
134 cout << i18n( " What: %1" ).
135 arg( event->summary() ).local8Bit().data()
136 << endl;
137
138 cout << i18n( " Begin: %1" ).
139 arg( event->dtStart().toString( TQt::TextDate ) ).local8Bit().data()
140 << endl;
141
142 cout << i18n( " End: %1" ).
143 arg( event->dtEnd().toString( TQt::TextDate ) ).local8Bit().data()
144 << endl;
145
146 cout << i18n( " Desc: %1" ).
147 arg( event->description() ).local8Bit().data()
148 << endl;
149
150 cout << i18n( " Location: %1" ).
151 arg( event->location() ).local8Bit().data()
152 << endl;
153}
154
155void KonsoleKalendarChange::printSpecs()
156{
157 cout << i18n( " UID: %1" ).
158 arg( m_variables->getUID() ).local8Bit().data()
159 << endl;
160
161 cout << i18n( " What: %1" ).
162 arg( m_variables->getSummary() ).local8Bit().data()
163 << endl;
164
165 cout << i18n( " Begin: %1" ).
166 arg( m_variables->getStartDateTime().toString( TQt::TextDate ) ).local8Bit().data()
167 << endl;
168
169 cout << i18n( " End: %1" ).
170 arg( m_variables->getEndDateTime().toString( TQt::TextDate ) ).local8Bit().data()
171 << endl;
172
173 cout << i18n( " Desc: %1" ).
174 arg( m_variables->getDescription() ).local8Bit().data()
175 << endl;
176
177 cout << i18n( " Location: %1" ).
178 arg( m_variables->getLocation() ).local8Bit().data()
179 << endl;
180}
bool changeEvent()
Modify the Event.
This class provides all the variables for the program.
bool getFloating()
Return if Event is floating.
bool isStartDateTime()
Is there start date?
bool isDryRun()
Is this program only in testing mode?
TQString getDescription()
Return description.
bool isDescription()
Is there an event description?
bool isVerbose()
Should program be more verbose?
TQDateTime getStartDateTime()
Get start date.
bool isLocation()
Is there event location information available?
TQString getLocation()
Return location information.
bool isSummary()
Is there an event summary?
TQDateTime getEndDateTime()
Get end date.
TQString getUID()
Get UID, the unique tag for VCard entry.
CalendarResources * getCalendar()
Get global calendar resources.
Provides the KonsoleKalendarChange class definition.