konsolekalendar Library API Documentation

konsolekalendaradd.cpp

00001 /***************************************************************************
00002         konsolekalendaradd.cpp  -  description
00003            -------------------
00004     begin                : Sun May 25 2003
00005     copyright            : (C) 2002-2003 by Tuukka Pasanen
00006     copyright            : (C) 2003 by Allen Winter
00007     email                : illuusio@mailcity.com
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
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     // If no description is provided, use the summary for the description
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     } // else
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   if ( ! m_variables->getCalendar()->load( m_variables->getImportFile() ) ) {
00101     kdDebug()
00102       << "konsolekalendaradd.cpp::importCalendar() | "
00103       << "Can't import file: "
00104       << m_variables->getImportFile() << endl;
00105     return false;
00106   } else {
00107     kdDebug()
00108       << "konsolekalendaradd.cpp::importCalendar() | "
00109       << "Successfully imported file: "
00110       << m_variables->getImportFile() << endl;
00111   }
00112 
00113   if( !m_variables->isCalendarResources() ){
00114     m_variables->getCalendar()->save( m_variables->getCalendarFile() );
00115   } else {
00116     m_variables->getCalendar()->save();
00117   }
00118 
00119   return true;
00120 }
00121 
00122 void KonsoleKalendarAdd::printSpecs()
00123 {
00124   cout << i18n("  What:  ").local8Bit() << m_variables->getSummary().local8Bit() << endl;
00125   cout << i18n("  Begin: ").local8Bit() << m_variables->getStartDateTime().toString(Qt::TextDate).local8Bit() << endl;
00126   cout << i18n("  End:   ").local8Bit() << m_variables->getEndDateTime().toString(Qt::TextDate).local8Bit() << endl;
00127   if( m_variables->getFloating() == true ) {
00128     cout << i18n("  No Time Associated with Event").local8Bit() << endl;
00129   }
00130   cout << i18n("  Desc:  ").local8Bit() << m_variables->getDescription().local8Bit() << endl;
00131 }
KDE Logo
This file is part of the documentation for konsolekalendar Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:15 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003