From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- korganizer/mailscheduler.cpp | 192 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 korganizer/mailscheduler.cpp (limited to 'korganizer/mailscheduler.cpp') diff --git a/korganizer/mailscheduler.cpp b/korganizer/mailscheduler.cpp new file mode 100644 index 00000000..bbd3daee --- /dev/null +++ b/korganizer/mailscheduler.cpp @@ -0,0 +1,192 @@ +/* + This file is part of KOrganizer. + + Copyright (c) 2001 Cornelius Schumacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "komailclient.h" +#include "incidencechanger.h" + +#include "mailscheduler.h" + + +using namespace KCal; + +MailScheduler::MailScheduler( Calendar *calendar ) + : IMIPScheduler( calendar ) +{ +} + +MailScheduler::~MailScheduler() +{ +} + +bool MailScheduler::publish( IncidenceBase *incidence, + const QString &recipients ) +{ + QString messageText = mFormat->createScheduleMessage( incidence, + Scheduler::Publish ); + KOMailClient mailer; + return mailer.mailTo( incidence, recipients, messageText ); +} + +bool MailScheduler::performTransaction( IncidenceBase *incidence, + Method method, + const QString &recipients ) +{ + QString messageText = mFormat->createScheduleMessage( incidence, method ); + + KOMailClient mailer; + return mailer.mailTo( incidence, recipients, messageText ); +} + +bool MailScheduler::performTransaction( IncidenceBase *incidence, + Method method ) +{ + QString messageText = mFormat->createScheduleMessage( incidence, method ); + + KOMailClient mailer; + bool status; + if ( method == Request || + method == Cancel || + method == Add || + method == Declinecounter ) { + status = mailer.mailAttendees( incidence, messageText ); + } else { + QString subject; + Incidence *inc = dynamic_cast( incidence ); + if ( inc && method == Counter ) + subject = i18n( "Counter proposal: %1" ).arg( inc->summary() ); + status = mailer.mailOrganizer( incidence, messageText, subject ); + } + return status; +} + +QPtrList MailScheduler::retrieveTransactions() +{ + QString incomingDirName = locateLocal( "data", "korganizer/income" ); + kdDebug(5850) << "MailScheduler::retrieveTransactions: dir: " + << incomingDirName << endl; + + QPtrList messageList; + + QDir incomingDir( incomingDirName ); + QStringList incoming = incomingDir.entryList( QDir::Files ); + QStringList::ConstIterator it; + for( it = incoming.begin(); it != incoming.end(); ++it ) { + kdDebug(5850) << "-- File: " << (*it) << endl; + + QFile f( incomingDirName + "/" + (*it) ); + bool inserted = false; + QMap::Iterator iter; + for ( iter = mEventMap.begin(); iter != mEventMap.end(); ++iter ) { + if ( iter.data() == incomingDirName + "/" + (*it) ) + inserted = true; + } + if ( !inserted ) { + if ( !f.open( IO_ReadOnly ) ) { + kdDebug(5850) + << "MailScheduler::retrieveTransactions(): Can't open file'" + << (*it) << "'" << endl; + } else { + QTextStream t( &f ); + t.setEncoding( QTextStream::Latin1 ); + QString messageString = t.read(); + messageString.replace( QRegExp( "\n[ \t]"), "" ); + messageString = QString::fromUtf8( messageString.latin1() ); + ScheduleMessage *mess = mFormat->parseScheduleMessage( mCalendar, + messageString ); + if ( mess) { + kdDebug(5850) + << "MailScheduler::retrieveTransactions: got message '" + << (*it) << "'" << endl; + messageList.append( mess ); + mEventMap[ mess->event() ] = incomingDirName + "/" + (*it); + } else { + QString errorMessage; + if ( mFormat->exception() ) { + errorMessage = mFormat->exception()->message(); + } + kdDebug(5850) + << "MailScheduler::retrieveTransactions() Error parsing message: " + << errorMessage << endl; + } + f.close(); + } + } + } + return messageList; +} + +bool MailScheduler::deleteTransaction( IncidenceBase *incidence ) +{ + bool status; + QFile f( mEventMap[incidence] ); + mEventMap.remove( incidence ); + if ( !f.exists() ) { + status = false; + } else { + status = f.remove(); + } + return status; +} + +QString MailScheduler::freeBusyDir() +{ + return locateLocal( "data", "korganizer/freebusy" ); +} + +bool MailScheduler::acceptCounterProposal( Incidence *incidence ) +{ + if ( !incidence ) + return false; + + Incidence *exInc = mCalendar->incidence( incidence->uid() ); + if ( !exInc ) + exInc = mCalendar->incidenceFromSchedulingID( incidence->uid() ); + incidence->setRevision( incidence->revision() + 1 ); + if ( exInc ) { + incidence->setRevision( QMAX( incidence->revision(), exInc->revision() + 1 ) ); + // some stuff we don't want to change, just to be safe + incidence->setSchedulingID( exInc->schedulingID() ); + incidence->setUid( exInc->uid() ); + + mCalendar->beginChange( exInc ); + IncidenceChanger::assignIncidence( exInc, incidence ); + exInc->updated(); + mCalendar->endChange( exInc ); + } else { + mCalendar->addIncidence( incidence ); + } + return true; +} -- cgit v1.2.3