konsolekalendar

konsolekalendaradd.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * konsolekalendaradd.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 <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 // If --file specified, then import into that file
00115 // else, import into the standard calendar
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 }