korganizer Library API Documentation

mailscheduler.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program 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 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include <qdir.h> 00026 #include <qfile.h> 00027 #include <qregexp.h> 00028 00029 #include <kstandarddirs.h> 00030 #include <kdebug.h> 00031 00032 #include <libkcal/event.h> 00033 #include <libkcal/icalformat.h> 00034 00035 #include "komailclient.h" 00036 00037 #include "mailscheduler.h" 00038 00039 00040 using namespace KCal; 00041 00042 MailScheduler::MailScheduler(Calendar *calendar) 00043 : IMIPScheduler(calendar) 00044 { 00045 } 00046 00047 MailScheduler::~MailScheduler() 00048 { 00049 } 00050 00051 bool MailScheduler::publish (IncidenceBase *incidence,const QString &recipients) 00052 { 00053 QString messageText = mFormat->createScheduleMessage(incidence, 00054 Scheduler::Publish); 00055 KOMailClient mailer; 00056 // kdDebug () << "MailScheduler::publish to " << recipients << endl; 00057 return mailer.mailTo(incidence,recipients,messageText); 00058 } 00059 00060 bool MailScheduler::performTransaction(IncidenceBase *incidence,Method method,const QString &recipients) 00061 { 00062 QString messageText = mFormat->createScheduleMessage(incidence,method); 00063 00064 KOMailClient mailer; 00065 // kdDebug () << "MailScheduler::performTransaction" << endl; 00066 if (method==Request || method==Cancel || method==Add || method==Declinecounter) { 00067 return mailer.mailTo(incidence,recipients,messageText); 00068 } 00069 else { 00070 return mailer.mailTo(incidence,recipients,messageText); 00071 } 00072 } 00073 00074 bool MailScheduler::performTransaction(IncidenceBase *incidence,Method method) 00075 { 00076 QString messageText = mFormat->createScheduleMessage(incidence,method); 00077 00078 KOMailClient mailer; 00079 // kdDebug () << "MailScheduler::performTransaction" << endl; 00080 if (method==Request || method==Cancel || method==Add || method==Declinecounter) { 00081 return mailer.mailAttendees(incidence,messageText); 00082 } 00083 else { 00084 return mailer.mailOrganizer(incidence,messageText); 00085 } 00086 } 00087 00088 QPtrList<ScheduleMessage> MailScheduler::retrieveTransactions() 00089 { 00090 QString incomingDirName = locateLocal("data","korganizer/income"); 00091 kdDebug(5850) << "MailScheduler::retrieveTransactions: dir: " << incomingDirName 00092 << endl; 00093 00094 QPtrList<ScheduleMessage> messageList; 00095 00096 QDir incomingDir(incomingDirName); 00097 QStringList incoming = incomingDir.entryList(QDir::Files); 00098 QStringList::ConstIterator it; 00099 for(it = incoming.begin(); it != incoming.end(); ++it) { 00100 kdDebug(5850) << "-- File: " << (*it) << endl; 00101 00102 QFile f(incomingDirName + "/" + (*it)); 00103 bool inserted = false; 00104 QMap<IncidenceBase*, QString>::Iterator iter; 00105 for ( iter = mEventMap.begin(); iter != mEventMap.end(); ++iter ) { 00106 if (iter.data() == incomingDirName + "/" + (*it)) inserted = true; 00107 } 00108 if (!inserted) { 00109 if (!f.open(IO_ReadOnly)) { 00110 kdDebug(5850) << "MailScheduler::retrieveTransactions(): Can't open file'" 00111 << (*it) << "'" << endl; 00112 } else { 00113 QTextStream t(&f); 00114 t.setEncoding( QTextStream::Latin1 ); 00115 QString messageString = t.read(); 00116 messageString.replace( QRegExp("\n[ \t]"), ""); 00117 messageString = QString::fromUtf8( messageString.latin1() ); 00118 ScheduleMessage *message = mFormat->parseScheduleMessage( mCalendar, 00119 messageString ); 00120 if (message) { 00121 kdDebug(5850) << "MailScheduler::retrieveTransactions: got message '" 00122 << (*it) << "'" << endl; 00123 messageList.append(message); 00124 mEventMap[message->event()]=incomingDirName + "/" + (*it); 00125 } else { 00126 QString errorMessage; 00127 if (mFormat->exception()) { 00128 errorMessage = mFormat->exception()->message(); 00129 } 00130 kdDebug(5850) << "MailScheduler::retrieveTransactions() Error parsing " 00131 "message: " << errorMessage << endl; 00132 } 00133 f.close(); 00134 } 00135 } 00136 } 00137 return messageList; 00138 } 00139 00140 bool MailScheduler::deleteTransaction(IncidenceBase *incidence) 00141 { 00142 QFile f( mEventMap[incidence] ); 00143 mEventMap.remove(incidence); 00144 if ( !f.exists() ) return false; 00145 else 00146 return f.remove(); 00147 } 00148 00149 QString MailScheduler::freeBusyDir() 00150 { 00151 return locateLocal("data","korganizer/freebusy"); 00152 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:57 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003