38 #include <tqdatetime.h>
40 #include <tqtextstream.h>
43 #include <tdelocale.h>
45 #include <libkcal/calendarlocal.h>
46 #include <libkcal/resourcecalendar.h>
47 #include <libkcal/calendarresources.h>
48 #include <libkcal/calendar.h>
49 #include <libkcal/event.h>
50 #include <libkcal/htmlexport.h>
51 #include <libtdepim/kpimprefs.h>
64 m_variables = variables;
75 kdDebug() <<
"konsolecalendar.cpp::importCalendar() | importing now!"
83 CalendarLocal newCalendar( KPimPrefs::timezone() );
85 if ( m_variables->isDryRun() ) {
86 cout << i18n(
"Create Calendar <Dry Run>: %1" ).
87 arg( m_variables->getCalendarFile() ).local8Bit().data()
90 kdDebug() <<
"konsolekalendar.cpp::createCalendar() | "
91 <<
"Creating calendar file: "
92 << m_variables->getCalendarFile().local8Bit().data()
95 if ( m_variables->isVerbose() ) {
96 cout << i18n(
"Create Calendar <Verbose>: %1" ).
97 arg( m_variables->getCalendarFile() ).local8Bit().data()
101 if ( newCalendar.save( m_variables->getCalendarFile() ) ) {
116 if ( m_variables->isDryRun() ) {
117 cout << i18n(
"View Events <Dry Run>:" ).local8Bit().data()
122 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
123 <<
"open export file"
126 if ( m_variables->isExportFile() ) {
127 f.setName( m_variables->getExportFile() );
128 if ( !f.open( IO_WriteOnly ) ) {
130 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
131 <<
"unable to open export file "
132 << m_variables->getExportFile()
136 f.open( IO_WriteOnly, stdout );
140 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
141 <<
"opened successful"
144 if ( m_variables->isVerbose() ) {
145 cout << i18n(
"View Event <Verbose>:" ).local8Bit().data()
150 TQTextStream ts( &f );
155 if ( m_variables->getAll() ) {
156 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
157 <<
"view all events sorted list"
160 Event::List sortedList =
161 m_variables->getCalendar()->events( EventSortStartDate );
162 if( sortedList.count() > 0 )
164 TQDate dt, firstdate, lastdate;
165 firstdate = sortedList.first()->dtStart().date();
166 lastdate = sortedList.last()->dtStart().date();
167 for ( dt = firstdate;
168 dt <= lastdate && status !=
false;
169 dt = dt.addDays(1) ) {
171 m_variables->getCalendar()->events( dt,
173 SortDirectionAscending );
174 status = printEventList( &ts, &events, dt );
178 }
else if ( m_variables->isUID() ) {
179 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
180 <<
"view events by uid list"
183 event = m_variables->getCalendar()->event( m_variables->getUID() );
186 status = printEvent ( &ts, event, event->dtStart().date() );
188 }
else if ( m_variables->isNext() ) {
189 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
190 <<
"Show next activity in calendar"
193 TQDateTime datetime = m_variables->getStartDateTime();
194 datetime = datetime.addDays( 720 );
197 for ( dt = m_variables->getStartDateTime().date();
198 dt <= datetime.date();
199 dt = dt.addDays(1) ) {
201 m_variables->getCalendar()->events( dt,
203 SortDirectionAscending );
205 if ( events.count() > 0 ) {
206 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
207 <<
"Got the next event"
209 printEvent( &ts, events.first(), dt );
214 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
215 <<
"view raw events within date range list"
219 for ( dt = m_variables->getStartDateTime().date();
220 dt <= m_variables->getEndDateTime().date() && status !=
false;
221 dt = dt.addDays(1) ) {
223 m_variables->getCalendar()->events( dt,
225 SortDirectionAscending );
226 status = printEventList( &ts, &events, dt );
230 TQDate firstdate, lastdate;
231 if ( m_variables->getAll() ) {
232 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
233 <<
"HTML view all events sorted list"
237 Event::List *events =
238 new Event::List ( m_variables->getCalendar()->rawEvents(
240 SortDirectionAscending ) );
241 firstdate = events->first()->dtStart().date();
242 lastdate = events->last()->dtStart().date();
243 }
else if ( m_variables->isUID() ) {
245 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
246 <<
"HTML view events by uid list" << endl;
247 cout << i18n(
"Sorry, export to HTML by UID is not supported yet")
248 .local8Bit().data() << endl;
251 kdDebug() <<
"konsolekalendar.cpp::showInstance() | "
252 <<
"HTML view raw events within date range list"
254 firstdate = m_variables->getStartDateTime().date();
255 lastdate = m_variables->getEndDateTime().date();
258 HTMLExportSettings htmlSettings(
"Konsolekalendar" );
261 htmlSettings.setCreditName(
"KonsoleKalendar" );
262 htmlSettings.setCreditURL(
"http://pim.kde.org/components/konsolekalendar.php" );
264 htmlSettings.setExcludePrivate(
true );
265 htmlSettings.setExcludeConfidential(
true );
267 htmlSettings.setEventView(
false );
268 htmlSettings.setMonthView(
false );
270 title = i18n(
"Events:" );
271 htmlSettings.setMonthView(
true );
273 if ( firstdate == lastdate ) {
274 title = i18n(
"Events: %1" )
275 .arg( firstdate.toString( TQt::TextDate ) );
277 title = i18n(
"Events: %1 - %2" )
278 .arg( firstdate.toString( TQt::TextDate ) )
279 .arg( lastdate.toString( TQt::TextDate ) );
281 htmlSettings.setEventView(
true );
283 htmlSettings.setEventTitle( title );
284 htmlSettings.setEventAttendees(
true );
290 htmlSettings.setTodoListTitle( title );
291 htmlSettings.setTodoView(
false );
296 htmlSettings.setDateStart( TQDateTime( firstdate ) );
297 htmlSettings.setDateEnd( TQDateTime( lastdate ) ) ;
299 KCal::HtmlExport *Export;
300 Export =
new HtmlExport( m_variables->getCalendar(), &htmlSettings );
301 status = Export->save( &ts );
310 bool KonsoleKalendar::printEventList( TQTextStream *ts,
311 Event::List *eventList, TQDate date )
315 if ( eventList->count() ) {
317 Event::List::ConstIterator it;
319 for ( it = eventList->begin();
320 it != eventList->end() && status !=
false;
324 status = printEvent( ts, singleEvent, date );
331 bool KonsoleKalendar::printEvent( TQTextStream *ts, Event *event, TQDate dt )
338 switch ( m_variables->getExportType() ) {
341 kdDebug() <<
"konsolekalendar.cpp::printEvent() | "
349 <<
"konsolekalendar.cpp::printEvent() | "
350 <<
"TEXT-SHORT export"
352 if ( dt.daysTo( m_saveDate ) ) {
364 kdDebug() <<
"konsolekalendar.cpp::printEvent() | "
376 kdDebug() <<
"konsolecalendar.cpp::addEvent() | "
380 kdDebug() <<
"konsolecalendar.cpp::addEvent() | "
381 <<
"Adding Event now!"
389 kdDebug() <<
"konsolecalendar.cpp::changeEvent() | "
393 kdDebug() <<
"konsolecalendar.cpp::changeEvent() | "
394 <<
"Changing Event now!"
401 kdDebug() <<
"konsolecalendar.cpp::deleteEvent() | "
405 kdDebug() <<
"konsolecalendar.cpp::deleteEvent() | "
406 <<
"Deleting Event now!"
412 TQDateTime enddate, TQString summary )
417 Event::List::ConstIterator it;
421 Event::List eventList( m_variables->getCalendar()->
422 rawEventsForDate( startdate.date(),
424 SortDirectionAscending ) );
425 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
427 if ( event->dtEnd() == enddate && event->summary() == summary ) {
435 void KonsoleKalendar::printSpecs()
437 cout << i18n(
" What: %1" ).
438 arg( m_variables->getSummary() ).local8Bit().data()
441 cout << i18n(
" Begin: %1" ).
442 arg( m_variables->getStartDateTime().toString( TQt::TextDate ) ).local8Bit().data()
445 cout << i18n(
" End: %1" ).
446 arg( m_variables->getEndDateTime().toString( TQt::TextDate ) ).local8Bit().data()
449 if ( m_variables->getFloating() ==
true ) {
450 cout << i18n(
" No Time Associated with Event" ).local8Bit().data()
454 cout << i18n(
" Desc: %1" ).
455 arg( m_variables->getDescription() ).local8Bit().data()
458 cout << i18n(
" Location: %1" ).
459 arg( m_variables->getLocation() ).local8Bit().data()
Class to manage the Event insertion capability.
bool addEvent()
Add the Event.
bool addImportedCalendar()
Imports calendar file to current Calendar.
Class to manage the Event modification capability.
bool changeEvent()
Modify the Event.
Class to manage the Event removal capability.
bool deleteEvent()
Delete the Event.
Class to manage the Export functionality.
bool exportAsTxtShort(TQTextStream *ts, Event *event, TQDate date, bool sameday)
Export the Event in Short Text Mode.
bool exportAsCSV(TQTextStream *ts, Event *event, TQDate date)
Export the Event in Comma-Separated Values (CSV) Mode.
bool exportAsTxt(TQTextStream *ts, Event *event, TQDate date)
Export the Event in Text Mode.
This class provides all the variables for the program.
bool changeEvent()
Change event.
bool addEvent()
Add event to calendar.
bool createCalendar()
Creates calendar file (If it doesn't exists)
KonsoleKalendar(KonsoleKalendarVariables *variables)
Constructs a KonsoleKalendar object from command line arguments.
~KonsoleKalendar()
Destructor.
bool isEvent(TQDateTime startdate, TQDateTime enddate, TQString summary)
Detect if event already exists.
bool deleteEvent()
Delete event.
bool importCalendar()
Imports calendar file.
bool showInstance()
Visualize what we need.
Provides the KonsoleKalendar class definition.
Provides the KonsoleKalendarAdd class definition.
Provides the KonsoleKalendarChange class definition.
Provides the KonsoleKalendarDelete class definition.
Provides the KonsoleKalendarExports class definition.
@ ExportTypeCSV
Export Comma-Separated Values.
@ ExportTypeTextShort
Export as compact text.
@ ExportTypeMonthHTML
Export HTML for the time span on month boundaries.
@ ExportTypeHTML
Export HTML for the specified time span.