korganizer Library API Documentation

mailscheduler.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 //
00021 // MailScheduler - Mail implementation of iTIP methods
00022 //
00023 
00024 #include <qdir.h>
00025 #include <qfile.h>
00026 
00027 #include <kstandarddirs.h>
00028 #include <kdebug.h>
00029 
00030 #include <libkcal/event.h>
00031 #include <libkcal/icalformat.h>
00032 
00033 #include "komailclient.h"
00034 
00035 #include "mailscheduler.h"
00036 
00037 
00038 using namespace KCal;
00039 
00040 MailScheduler::MailScheduler(Calendar *calendar)
00041   : IMIPScheduler(calendar)
00042 {
00043 }
00044 
00045 MailScheduler::~MailScheduler()
00046 {
00047 }
00048 
00049 bool MailScheduler::publish (IncidenceBase *incidence,const QString &recipients)
00050 {
00051   QString messageText = mFormat->createScheduleMessage(incidence,
00052                                                        Scheduler::Publish);
00053   KOMailClient mailer;
00054   //  kdDebug () << "MailScheduler::publish to " << recipients << endl;
00055   return mailer.mailTo(incidence,recipients,messageText);
00056 }
00057 
00058 bool MailScheduler::performTransaction(IncidenceBase *incidence,Method method,const QString &recipients)
00059 {
00060   QString messageText = mFormat->createScheduleMessage(incidence,method);
00061 
00062   KOMailClient mailer;
00063 //  kdDebug () << "MailScheduler::performTransaction"  << endl;
00064   if (method==Request || method==Cancel || method==Add || method==Declinecounter) {
00065     return mailer.mailTo(incidence,recipients,messageText);
00066   }
00067   else {
00068     return mailer.mailTo(incidence,recipients,messageText);
00069   }
00070 }
00071 
00072 bool MailScheduler::performTransaction(IncidenceBase *incidence,Method method)
00073 {
00074   QString messageText = mFormat->createScheduleMessage(incidence,method);
00075 
00076   KOMailClient mailer;
00077 //  kdDebug () << "MailScheduler::performTransaction"  << endl;
00078   if (method==Request || method==Cancel || method==Add || method==Declinecounter) {
00079     return mailer.mailAttendees(incidence,messageText);
00080   }
00081   else {
00082     return mailer.mailOrganizer(incidence,messageText);
00083   }
00084 }
00085 
00086 QPtrList<ScheduleMessage> MailScheduler::retrieveTransactions()
00087 {
00088   QString incomingDirName = locateLocal("appdata","income");
00089   kdDebug() << "MailScheduler::retrieveTransactions: dir: " << incomingDirName
00090             << endl;
00091 
00092   QPtrList<ScheduleMessage> messageList;
00093 
00094   QDir incomingDir(incomingDirName);
00095   QStringList incoming = incomingDir.entryList(QDir::Files);
00096   QStringList::ConstIterator it;
00097   for(it = incoming.begin(); it != incoming.end(); ++it) {
00098     kdDebug() << "-- File: " << (*it) << endl;
00099 
00100     QFile f(incomingDirName + "/" + (*it));
00101     bool inserted = false;
00102     QMap<IncidenceBase*, QString>::Iterator iter;
00103     for ( iter = mEventMap.begin(); iter != mEventMap.end(); ++iter ) {
00104       if (iter.data() == incomingDirName + "/" + (*it)) inserted = true;
00105     }
00106     if (!inserted) {
00107     if (!f.open(IO_ReadOnly)) {
00108       kdDebug() << "MailScheduler::retrieveTransactions(): Can't open file'"
00109                 << (*it) << "'" << endl;
00110     } else {
00111       QTextStream t(&f);
00112       QString messageString = t.read();
00113       ScheduleMessage *message = mFormat->parseScheduleMessage( mCalendar,
00114                                                                 messageString );
00115       if (message) {
00116         kdDebug() << "MailScheduler::retrieveTransactions: got message '"
00117                   << (*it) << "'" << endl;
00118         messageList.append(message);
00119         mEventMap[message->event()]=incomingDirName + "/" + (*it);
00120       } else {
00121         QString errorMessage;
00122         if (mFormat->exception()) {
00123           errorMessage = mFormat->exception()->message();
00124         }
00125         kdDebug() << "MailScheduler::retrieveTransactions() Error parsing "
00126                      "message: " << errorMessage << endl;
00127       }
00128       f.close();
00129     }
00130     }
00131   }
00132   return messageList;
00133 }
00134 
00135 bool MailScheduler::deleteTransaction(IncidenceBase *incidence)
00136 {
00137   QFile f( mEventMap[incidence] );
00138   mEventMap.remove(incidence);
00139   if ( !f.exists() ) return false;
00140   else
00141     return f.remove();
00142 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:32 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001