konsolekalendar

konsolekalendardelete.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * konsolekalendardelete.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 Qt, and distribute the resulting executable,            *
00024  * without including the source code for Qt in the source distribution.        *
00025  *                                                                             *
00026  ******************************************************************************/
00033 #include <stdlib.h>
00034 #include <iostream>
00035 
00036 #include <kdebug.h>
00037 #include <klocale.h>
00038 
00039 #include "konsolekalendardelete.h"
00040 
00041 using namespace KCal;
00042 using namespace std;
00043 
00044 KonsoleKalendarDelete::KonsoleKalendarDelete( KonsoleKalendarVariables *vars )
00045 {
00046   m_variables = vars;
00047 }
00048 
00049 KonsoleKalendarDelete::~KonsoleKalendarDelete()
00050 {
00051 }
00052 
00053 bool KonsoleKalendarDelete::deleteEvent()
00054 {
00055   bool status = false;
00056 
00057   kdDebug() << "konsolekalendardelete.cpp::deleteEvent()" << 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( "Delete Event <Dry Run>:" ).local8Bit()
00066            << endl;
00067       printSpecs( event );
00068     } else {
00069       kdDebug() << "konsolekalendardelete.cpp:deleteEvent() : "
00070                 << m_variables->getUID().local8Bit()
00071                 << endl;
00072 
00073       if ( m_variables->isVerbose() ) {
00074     cout << i18n( "Delete Event <Verbose>:" ).local8Bit()
00075              << endl;
00076     printSpecs( event );
00077       }
00078 
00079       m_variables->getCalendar()->deleteEvent( event );
00080       cout << i18n( "Success: \"%1\" deleted" )
00081         .arg( event->summary() ).local8Bit()
00082            << endl;
00083 
00084       m_variables->getCalendar()->save();
00085       status = true;
00086     }
00087   }
00088 
00089   kdDebug() << "konsolekalendardelete.cpp::deleteEvent() | Done " << endl;
00090   return status;
00091 }
00092 
00093 void KonsoleKalendarDelete::printSpecs( Event *event )
00094 {
00095   cout << i18n( "  UID:   %1" ).
00096     arg( m_variables->getUID() ).local8Bit()
00097        << endl;
00098 
00099   cout << i18n( "  What:  %1" ).
00100     arg( event->summary() ).local8Bit()
00101        << endl;
00102 
00103   cout << i18n( "  Begin: %1" ).
00104     arg( event->dtStart().toString( Qt::TextDate ) ).local8Bit()
00105        << endl;
00106 
00107   cout << i18n( "  End:   %1" ).
00108     arg( event->dtEnd().toString( Qt::TextDate ) ).local8Bit()
00109        << endl;
00110 
00111   cout << i18n( "  Desc:  %1" ).
00112     arg( event->description() ).local8Bit()
00113        << endl;
00114 
00115   cout << i18n( "  Location:  %1" ).
00116     arg( event->location() ).local8Bit()
00117        << endl;
00118 }