libkcal

dummyscheduler.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 //
00023 // DummyScheduler - iMIP implementation of iTIP methods
00024 //
00025 
00026 #include <qfile.h>
00027 #include <qtextstream.h>
00028 
00029 #include <kdebug.h>
00030 #include <kstandarddirs.h>
00031 
00032 #include "event.h"
00033 #include "icalformat.h"
00034 
00035 #include "dummyscheduler.h"
00036 
00037 using namespace KCal;
00038 
00039 DummyScheduler::DummyScheduler(Calendar *calendar)
00040   : Scheduler(calendar)
00041 {
00042 }
00043 
00044 DummyScheduler::~DummyScheduler()
00045 {
00046 }
00047 
00048 bool DummyScheduler::publish (IncidenceBase *incidence,const QString &/*recipients*/)
00049 {
00050   QString messageText = mFormat->createScheduleMessage(incidence,
00051                                                        Scheduler::Publish);
00052 
00053   return saveMessage(messageText);
00054 }
00055 
00056 bool DummyScheduler::performTransaction(IncidenceBase *incidence,Method method,const QString &/*recipients*/)
00057 {
00058   QString messageText = mFormat->createScheduleMessage(incidence,method);
00059 
00060   return saveMessage(messageText);
00061 }
00062 
00063 bool DummyScheduler::performTransaction(IncidenceBase *incidence,Method method)
00064 {
00065   QString messageText = mFormat->createScheduleMessage(incidence,method);
00066 
00067   return saveMessage(messageText);
00068 }
00069 
00070 bool DummyScheduler::saveMessage(const QString &message)
00071 {
00072   QFile f("dummyscheduler.store");
00073   if (f.open(IO_WriteOnly | IO_Append)) {
00074     QTextStream t(&f);
00075     t << message << endl;
00076     f.close();
00077     return true;
00078   } else {
00079     return false;
00080   }
00081 }
00082 
00083 QPtrList<ScheduleMessage> DummyScheduler::retrieveTransactions()
00084 {
00085   QPtrList<ScheduleMessage> messageList;
00086 
00087   QFile f("dummyscheduler.store");
00088   if (!f.open(IO_ReadOnly)) {
00089     kdDebug(5800) << "DummyScheduler::retrieveTransactions(): Can't open file"
00090               << endl;
00091   } else {
00092     QTextStream t(&f);
00093     QString messageString;
00094     QString messageLine = t.readLine();
00095     while (!messageLine.isNull()) {
00096 //      kdDebug(5800) << "++++++++" << messageLine << endl;
00097       messageString += messageLine + "\n";
00098       if (messageLine.find("END:VCALENDAR") >= 0) {
00099         kdDebug(5800) << "---------------" << messageString << endl;
00100         ScheduleMessage *message = mFormat->parseScheduleMessage(mCalendar,
00101                                                                  messageString);
00102         kdDebug(5800) << "--Parsed" << endl;
00103         if (message) {
00104           messageList.append(message);
00105         } else {
00106           QString errorMessage;
00107           if (mFormat->exception()) {
00108             errorMessage = mFormat->exception()->message();
00109           }
00110           kdDebug(5800) << "DummyScheduler::retrieveTransactions() Error parsing "
00111                        "message: " << errorMessage << endl;
00112         }
00113         messageString="";
00114       }
00115       messageLine = t.readLine();
00116     }
00117     f.close();
00118   }
00119 
00120   return messageList;
00121 }
00122 
00123 QString DummyScheduler::freeBusyDir()
00124 {
00125   // the dummy scheduler should never handle freebusy stuff - so it's hardcoded
00126   return QString("");
00127 }