konsolekalendarchange.cpp
Go to the documentation of this file.
00001 /******************************************************************************* 00002 * konsolekalendarchange.cpp * 00003 * * 00004 * KonsoleKalendar is a command line interface to KDE calendars * 00005 * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * 00006 * Copyright (C) 2003-2005 Allen Winter <winter@kde.org> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00021 * * 00022 * As a special exception, permission is given to link this program * 00023 * with any edition of TQt, and distribute the resulting executable, * 00024 * without including the source code for TQt in the source distribution. * 00025 * * 00026 ******************************************************************************/ 00033 #include <stdlib.h> 00034 #include <iostream> 00035 00036 #include <kdebug.h> 00037 #include <tdelocale.h> 00038 00039 #include "konsolekalendarchange.h" 00040 00041 using namespace KCal; 00042 using namespace std; 00043 00044 KonsoleKalendarChange::KonsoleKalendarChange( KonsoleKalendarVariables *vars ) 00045 { 00046 m_variables = vars; 00047 } 00048 00049 KonsoleKalendarChange::~KonsoleKalendarChange() 00050 { 00051 } 00052 00053 bool KonsoleKalendarChange::changeEvent() 00054 { 00055 bool status = false; 00056 00057 kdDebug() << "konsolekalendarchange.cpp::changeEvent()" << endl; 00058 00059 /* 00060 * Retrieve event on the basis of the unique string ID 00061 */ 00062 Event *event = m_variables->getCalendar()->event( m_variables->getUID() ); 00063 if ( event ) { 00064 if ( m_variables->isDryRun() ) { 00065 cout << i18n( "Change Event <Dry Run>:" ).local8Bit().data() 00066 << endl; 00067 printSpecs( event ); 00068 00069 cout << i18n( "To Event <Dry Run>:" ).local8Bit().data() 00070 << endl; 00071 printSpecs(); 00072 } else { 00073 kdDebug() << "konsolekalendarchange.cpp:changeEvent() : " 00074 << m_variables->getUID().local8Bit() 00075 << endl; 00076 00077 if ( m_variables->isVerbose() ) { 00078 cout << i18n( "Change Event <Verbose>:" ).local8Bit().data() 00079 << endl; 00080 printSpecs( event ); 00081 00082 cout << i18n( "To Event <Dry Run>:" ).local8Bit().data() 00083 << endl; 00084 printSpecs(); 00085 } 00086 00087 if ( m_variables->isStartDateTime() ) { 00088 event->setDtStart( m_variables->getStartDateTime() ); 00089 } 00090 00091 if ( m_variables->isEndDateTime() ) { 00092 event->setDtEnd( m_variables->getEndDateTime() ); 00093 } 00094 00095 event->setFloats( m_variables->getFloating() ); 00096 00097 if ( m_variables->isSummary() ) { 00098 event->setSummary( m_variables->getSummary() ); 00099 } 00100 00101 if ( m_variables->isDescription() ) { 00102 event->setDescription( m_variables->getDescription() ); 00103 } 00104 00105 if ( m_variables->isLocation() ) { 00106 event->setLocation( m_variables->getLocation() ); 00107 } 00108 00109 if ( m_variables->getCalendar()->addEvent( event ) ) { 00110 cout << i18n( "Success: \"%1\" changed" ) 00111 .arg( event->summary() ).local8Bit().data() 00112 << endl; 00113 00114 m_variables->getCalendar()->save(); 00115 status = true; 00116 } else { 00117 cout << i18n( "Failure: \"%1\" not changed" ) 00118 .arg( event->summary() ).local8Bit().data() 00119 << endl; 00120 } 00121 } 00122 } 00123 00124 kdDebug() << "konsolekalendarchange.cpp::changeEvent() | Done " << endl; 00125 return status; 00126 } 00127 00128 void KonsoleKalendarChange::printSpecs( Event *event ) 00129 { 00130 cout << i18n( " UID: %1" ). 00131 arg( event->uid() ).local8Bit().data() 00132 << endl; 00133 00134 cout << i18n( " What: %1" ). 00135 arg( event->summary() ).local8Bit().data() 00136 << endl; 00137 00138 cout << i18n( " Begin: %1" ). 00139 arg( event->dtStart().toString( Qt::TextDate ) ).local8Bit().data() 00140 << endl; 00141 00142 cout << i18n( " End: %1" ). 00143 arg( event->dtEnd().toString( Qt::TextDate ) ).local8Bit().data() 00144 << endl; 00145 00146 cout << i18n( " Desc: %1" ). 00147 arg( event->description() ).local8Bit().data() 00148 << endl; 00149 00150 cout << i18n( " Location: %1" ). 00151 arg( event->location() ).local8Bit().data() 00152 << endl; 00153 } 00154 00155 void KonsoleKalendarChange::printSpecs() 00156 { 00157 cout << i18n( " UID: %1" ). 00158 arg( m_variables->getUID() ).local8Bit().data() 00159 << endl; 00160 00161 cout << i18n( " What: %1" ). 00162 arg( m_variables->getSummary() ).local8Bit().data() 00163 << endl; 00164 00165 cout << i18n( " Begin: %1" ). 00166 arg( m_variables->getStartDateTime().toString( Qt::TextDate ) ).local8Bit().data() 00167 << endl; 00168 00169 cout << i18n( " End: %1" ). 00170 arg( m_variables->getEndDateTime().toString( Qt::TextDate ) ).local8Bit().data() 00171 << endl; 00172 00173 cout << i18n( " Desc: %1" ). 00174 arg( m_variables->getDescription() ).local8Bit().data() 00175 << endl; 00176 00177 cout << i18n( " Location: %1" ). 00178 arg( m_variables->getLocation() ).local8Bit().data() 00179 << endl; 00180 }