konsolekalendaradd.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <iostream>
00021
00022 #include <qdatetime.h>
00023
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026
00027 #include <libkcal/calendarlocal.h>
00028 #include <libkcal/calendar.h>
00029 #include <libkcal/event.h>
00030
00031 #include "konsolekalendar.h"
00032 #include "konsolekalendaradd.h"
00033
00034 using namespace KCal;
00035 using namespace std;
00036
00037 KonsoleKalendarAdd::KonsoleKalendarAdd( KonsoleKalendarVariables *variables )
00038 {
00039 m_variables = variables;
00040
00041 }
00042
00043 KonsoleKalendarAdd::~KonsoleKalendarAdd()
00044 {
00045
00046 }
00047
00052 bool KonsoleKalendarAdd::addEvent()
00053 {
00054 kdDebug() << "konsolekalendaradd.cpp::addEvent() | Add stuff " << endl;
00055
00056 if( !m_variables->isDescription() && m_variables->isSummary() ) {
00057
00058 m_variables->setDescription( m_variables->getSummary() );
00059 }
00060
00061 if( m_variables->isDryRun() ) {
00062 cout << i18n("Insert Event <Dry Run>:").local8Bit() << endl;
00063 printSpecs();
00064 } else {
00065 Event *event = new Event();
00066
00067 if( m_variables->isVerbose() ) {
00068 cout << i18n("Insert Event <Verbose>:").local8Bit() << endl;
00069 printSpecs();
00070 }
00071
00072 event->setDtStart( m_variables->getStartDateTime() );
00073 event->setDtEnd( m_variables->getEndDateTime() );
00074 event->setSummary( m_variables->getSummary() );
00075 event->setFloats( m_variables->getFloating() );
00076 event->setDescription( m_variables->getDescription() );
00077
00078 if( m_variables->getCalendar()->addEvent( event ) ) {
00079 cout << i18n("Success: \"").local8Bit()
00080 << m_variables->getSummary().local8Bit() << i18n("\" inserted").local8Bit() << endl;
00081 } else {
00082 cout << i18n("Failure: \"").local8Bit()
00083 << m_variables->getSummary().local8Bit() << i18n("\" not inserted").local8Bit() << endl;
00084 }
00085
00086 if( !m_variables->isCalendarResources() ){
00087 m_variables->getCalendar()->save( m_variables->getCalendarFile() );
00088 } else {
00089 m_variables->getCalendar()->save();
00090 }
00091 delete event;
00092 }
00093
00094 kdDebug() << "konsolekalendaradd.cpp::addEvent() | Done " << endl;
00095 return true;
00096 }
00097
00098 bool KonsoleKalendarAdd::addImportedCalendar()
00099 {
00100
00101 CalendarLocal importCalendar;
00102
00103 if( !importCalendar.load( m_variables->getImportFile() ) ){
00104 kdDebug() << "konsolekalendaradd.cpp::importCalendar() | Can't open file: " << m_variables->getImportFile() << endl;
00105 return false;
00106 } else {
00107 kdDebug() << "konsolekalendaradd.cpp::importCalendar() | Successfully opened file: " << m_variables->getImportFile() << endl;
00108 }
00109
00110 Event::List eventList( importCalendar.rawEvents() );
00111 Event *singleEvent;
00112
00113 if( eventList.count() ) {
00114
00115 Event::List::ConstIterator it;
00116 for( it = eventList.begin(); it != eventList.end(); ++it ) {
00117 singleEvent = *it;
00118
00119 m_variables->getCalendar()->addEvent( singleEvent );
00120 kdDebug() << "konsolekalendaradd.cpp::importCalendar() | Event imported" << endl;
00121
00122 }
00123
00124 }
00125
00126 importCalendar.close();
00127
00128 if( !m_variables->isCalendarResources() ){
00129 m_variables->getCalendar()->save( m_variables->getCalendarFile() );
00130 } else {
00131 m_variables->getCalendar()->save();
00132 }
00133
00134 return true;
00135 }
00136
00137 void KonsoleKalendarAdd::printSpecs()
00138 {
00139 cout << i18n(" What: ").local8Bit() << m_variables->getSummary().local8Bit() << endl;
00140 cout << i18n(" Begin: ").local8Bit() << m_variables->getStartDateTime().toString(Qt::TextDate).local8Bit() << endl;
00141 cout << i18n(" End: ").local8Bit() << m_variables->getEndDateTime().toString(Qt::TextDate).local8Bit() << endl;
00142 if( m_variables->getFloating() == true ) {
00143 cout << i18n(" No Time Associated with Event").local8Bit() << endl;
00144 }
00145 cout << i18n(" Desc: ").local8Bit() << m_variables->getDescription().local8Bit() << endl;
00146 }
This file is part of the documentation for konsolekalendar Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Mar 6 17:18:34 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003