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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 // 00021 // MailScheduler - Mail implementation of iTIP methods 00022 // 00023 00024 #include <qdir.h> 00025 #include <qfile.h> 00026 #include <qregexp.h> 00027 00028 #include <kstandarddirs.h> 00029 #include <kdebug.h> 00030 00031 #include <libkcal/event.h> 00032 #include <libkcal/icalformat.h> 00033 00034 #include "komailclient.h" 00035 00036 #include "mailscheduler.h" 00037 00038 00039 using namespace KCal; 00040 00041 MailScheduler::MailScheduler(Calendar *calendar) 00042 : IMIPScheduler(calendar) 00043 { 00044 } 00045 00046 MailScheduler::~MailScheduler() 00047 { 00048 } 00049 00050 bool MailScheduler::publish (IncidenceBase *incidence,const QString &recipients) 00051 { 00052 QString messageText = mFormat->createScheduleMessage(incidence, 00053 Scheduler::Publish); 00054 KOMailClient mailer; 00055 // kdDebug () << "MailScheduler::publish to " << recipients << endl; 00056 return mailer.mailTo(incidence,recipients,messageText); 00057 } 00058 00059 bool MailScheduler::performTransaction(IncidenceBase *incidence,Method method,const QString &recipients) 00060 { 00061 QString messageText = mFormat->createScheduleMessage(incidence,method); 00062 00063 KOMailClient mailer; 00064 // kdDebug () << "MailScheduler::performTransaction" << endl; 00065 if (method==Request || method==Cancel || method==Add || method==Declinecounter) { 00066 return mailer.mailTo(incidence,recipients,messageText); 00067 } 00068 else { 00069 return mailer.mailTo(incidence,recipients,messageText); 00070 } 00071 } 00072 00073 bool MailScheduler::performTransaction(IncidenceBase *incidence,Method method) 00074 { 00075 QString messageText = mFormat->createScheduleMessage(incidence,method); 00076 00077 KOMailClient mailer; 00078 // kdDebug () << "MailScheduler::performTransaction" << endl; 00079 if (method==Request || method==Cancel || method==Add || method==Declinecounter) { 00080 return mailer.mailAttendees(incidence,messageText); 00081 } 00082 else { 00083 return mailer.mailOrganizer(incidence,messageText); 00084 } 00085 } 00086 00087 QPtrList<ScheduleMessage> MailScheduler::retrieveTransactions() 00088 { 00089 QString incomingDirName = locateLocal("data","korganizer/income"); 00090 kdDebug(5850) << "MailScheduler::retrieveTransactions: dir: " << incomingDirName 00091 << endl; 00092 00093 QPtrList<ScheduleMessage> messageList; 00094 00095 QDir incomingDir(incomingDirName); 00096 QStringList incoming = incomingDir.entryList(QDir::Files); 00097 QStringList::ConstIterator it; 00098 for(it = incoming.begin(); it != incoming.end(); ++it) { 00099 kdDebug(5850) << "-- File: " << (*it) << endl; 00100 00101 QFile f(incomingDirName + "/" + (*it)); 00102 bool inserted = false; 00103 QMap<IncidenceBase*, QString>::Iterator iter; 00104 for ( iter = mEventMap.begin(); iter != mEventMap.end(); ++iter ) { 00105 if (iter.data() == incomingDirName + "/" + (*it)) inserted = true; 00106 } 00107 if (!inserted) { 00108 if (!f.open(IO_ReadOnly)) { 00109 kdDebug(5850) << "MailScheduler::retrieveTransactions(): Can't open file'" 00110 << (*it) << "'" << endl; 00111 } else { 00112 QTextStream t(&f); 00113 t.setEncoding( QTextStream::Latin1 ); 00114 QString messageString = t.read(); 00115 messageString.replace( QRegExp("\n[ \t]"), ""); 00116 messageString = QString::fromUtf8( messageString.latin1() ); 00117 ScheduleMessage *message = mFormat->parseScheduleMessage( mCalendar, 00118 messageString ); 00119 if (message) { 00120 kdDebug(5850) << "MailScheduler::retrieveTransactions: got message '" 00121 << (*it) << "'" << endl; 00122 messageList.append(message); 00123 mEventMap[message->event()]=incomingDirName + "/" + (*it); 00124 } else { 00125 QString errorMessage; 00126 if (mFormat->exception()) { 00127 errorMessage = mFormat->exception()->message(); 00128 } 00129 kdDebug(5850) << "MailScheduler::retrieveTransactions() Error parsing " 00130 "message: " << errorMessage << endl; 00131 } 00132 f.close(); 00133 } 00134 } 00135 } 00136 return messageList; 00137 } 00138 00139 bool MailScheduler::deleteTransaction(IncidenceBase *incidence) 00140 { 00141 QFile f( mEventMap[incidence] ); 00142 mEventMap.remove(incidence); 00143 if ( !f.exists() ) return false; 00144 else 00145 return f.remove(); 00146 } 00147 00148 QString MailScheduler::freeBusyDir() 00149 { 00150 return locateLocal("data","korganizer/freebusy"); 00151 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003