konsolekalendar
konsolekalendaradd.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #include <stdlib.h>
00034 #include <iostream>
00035
00036 #include <qdatetime.h>
00037 #include <qobject.h>
00038
00039 #include <kdebug.h>
00040 #include <kstandarddirs.h>
00041 #include <klocale.h>
00042
00043 #include <libkcal/calendarlocal.h>
00044 #include <libkcal/calendar.h>
00045 #include <libkcal/event.h>
00046 #include <libkdepim/kpimprefs.h>
00047
00048 #include "konsolekalendaradd.h"
00049
00050 using namespace KCal;
00051 using namespace std;
00052
00053 KonsoleKalendarAdd::KonsoleKalendarAdd( KonsoleKalendarVariables *vars )
00054 {
00055 m_variables = vars;
00056 }
00057
00058 KonsoleKalendarAdd::~KonsoleKalendarAdd()
00059 {
00060 }
00061
00066 bool KonsoleKalendarAdd::addEvent()
00067 {
00068 bool status = true;
00069
00070 kdDebug() << "konsolekalendaradd.cpp::addEvent()" << endl;
00071
00072 if ( m_variables->isDryRun() ) {
00073 cout << i18n( "Insert Event <Dry Run>:" ).local8Bit()
00074 << endl;
00075 printSpecs();
00076 } else {
00077 if ( m_variables->isVerbose() ) {
00078 cout << i18n( "Insert Event <Verbose>:" ).local8Bit()
00079 << endl;
00080 printSpecs();
00081 }
00082
00083 Event *event = new Event();
00084
00085 event->setDtStart( m_variables->getStartDateTime() );
00086 event->setDtEnd( m_variables->getEndDateTime() );
00087 event->setSummary( m_variables->getSummary() );
00088 event->setFloats( m_variables->getFloating() );
00089 event->setDescription( m_variables->getDescription() );
00090 event->setLocation( m_variables->getLocation() );
00091
00092 if ( m_variables->getCalendar()->addEvent( event ) ) {
00093 cout << i18n( "Success: \"%1\" inserted" ).
00094 arg( m_variables->getSummary() ).local8Bit()
00095 << endl;
00096
00097 m_variables->getCalendar()->save();
00098
00099 } else {
00100 cout << i18n( "Failure: \"%1\" not inserted" ).
00101 arg( m_variables->getSummary() ).local8Bit()
00102 << endl;
00103 status = false;
00104 }
00105 }
00106
00107 kdDebug() << "konsolekalendaradd.cpp::addEvent() | Done " << endl;
00108 return status;
00109 }
00110
00111 bool KonsoleKalendarAdd::addImportedCalendar()
00112 {
00113
00114
00115
00116
00117 QString fileName;
00118 if ( m_variables->getCalendarFile().isEmpty() )
00119 fileName = locateLocal( "data", "korganizer/std.ics" );
00120 else
00121 fileName = m_variables->getCalendarFile();
00122
00123 CalendarLocal *cal = new CalendarLocal( KPimPrefs::timezone() );
00124 if ( !cal->load( fileName ) ||
00125 !cal->load( m_variables->getImportFile() ) ||
00126 !cal->save( fileName ) ) {
00127 kdDebug()
00128 << "konsolekalendaradd.cpp::importCalendar() | "
00129 << "Can't import file: "
00130 << m_variables->getImportFile()
00131 << endl;
00132 return false;
00133 }
00134 kdDebug()
00135 << "konsolekalendaradd.cpp::importCalendar() | "
00136 << "Successfully imported file: "
00137 << m_variables->getImportFile()
00138 << endl;
00139 return true;
00140 }
00141
00142 void KonsoleKalendarAdd::printSpecs()
00143 {
00144 cout << i18n( " What: %1" ).
00145 arg( m_variables->getSummary() ).local8Bit()
00146 << endl;
00147
00148 cout << i18n( " Begin: %1" ).
00149 arg( m_variables->getStartDateTime().toString( Qt::TextDate ) ).local8Bit()
00150 << endl;
00151
00152 cout << i18n( " End: %1" ).
00153 arg( m_variables->getEndDateTime().toString( Qt::TextDate ) ).local8Bit()
00154 << endl;
00155
00156 if ( m_variables->getFloating() == true ) {
00157 cout << i18n( " No Time Associated with Event" ).local8Bit()
00158 << endl;
00159 }
00160
00161 cout << i18n( " Desc: %1" ).
00162 arg( m_variables->getDescription() ).local8Bit()
00163 << endl;
00164
00165 cout << i18n( " Location: %1" ).
00166 arg( m_variables->getLocation() ).local8Bit()
00167 << endl;
00168 }
|