kogroupware.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "kogroupware.h"
00038 #include "freebusymanager.h"
00039 #include "calendarview.h"
00040 #include "mailscheduler.h"
00041 #include "koprefs.h"
00042 #include <libkdepim/email.h>
00043 #include <libkcal/attendee.h>
00044 #include <libkcal/journal.h>
00045 #include <kdebug.h>
00046 #include <kmessagebox.h>
00047 #include <kstandarddirs.h>
00048 #include <kdirwatch.h>
00049 #include <qfile.h>
00050 #include <qregexp.h>
00051 #include <qdir.h>
00052 #include <qtimer.h>
00053
00054 FreeBusyManager *KOGroupware::mFreeBusyManager = 0;
00055
00056 KOGroupware *KOGroupware::mInstance = 0;
00057
00058 KOGroupware *KOGroupware::create( CalendarView *view,
00059 KCal::CalendarResources *calendar )
00060 {
00061 if( !mInstance )
00062 mInstance = new KOGroupware( view, calendar );
00063 return mInstance;
00064 }
00065
00066 KOGroupware *KOGroupware::instance()
00067 {
00068
00069 Q_ASSERT( mInstance );
00070 return mInstance;
00071 }
00072
00073
00074 KOGroupware::KOGroupware( CalendarView* view, KCal::CalendarResources* cal )
00075 : QObject( 0, "kmgroupware_instance" ), mView( view ), mCalendar( cal )
00076 {
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 slotStartScheduling();
00088 }
00089
00090 FreeBusyManager *KOGroupware::freeBusyManager()
00091 {
00092 if ( !mFreeBusyManager ) {
00093 mFreeBusyManager = new FreeBusyManager( this, "freebusymanager" );
00094 mFreeBusyManager->setCalendar( mCalendar );
00095 connect( mCalendar, SIGNAL( calendarChanged() ),
00096 mFreeBusyManager, SLOT( slotPerhapsUploadFB() ) );
00097 }
00098
00099 return mFreeBusyManager;
00100 }
00101
00102 void KOGroupware::slotStartScheduling()
00103 {
00104
00105 KDirWatch* watcher = KDirWatch::self();
00106 watcher->addDir( locateLocal( "data", "korganizer/income.accepted/" ) );
00107 watcher->addDir( locateLocal( "data", "korganizer/income.tentative/" ) );
00108 watcher->addDir( locateLocal( "data", "korganizer/income.cancel/" ) );
00109 watcher->addDir( locateLocal( "data", "korganizer/income.reply/" ) );
00110 connect( watcher, SIGNAL( dirty( const QString& ) ),
00111 this, SLOT( incomingDirChanged( const QString& ) ) );
00112
00113 incomingDirChanged( locateLocal( "data", "korganizer/income.accepted/" ) );
00114 incomingDirChanged( locateLocal( "data", "korganizer/income.tentative/" ) );
00115 incomingDirChanged( locateLocal( "data", "korganizer/income.cancel/" ) );
00116 incomingDirChanged( locateLocal( "data", "korganizer/income.reply/" ) );
00117 }
00118
00119 void KOGroupware::incomingDirChanged( const QString& path )
00120 {
00121 const QString incomingDirName = locateLocal( "data","korganizer/" )
00122 + "income.";
00123 if ( !path.startsWith( incomingDirName ) ) {
00124
00125 return;
00126 }
00127 QString action = path.mid( incomingDirName.length() );
00128 while ( action.length() > 0 && action[ action.length()-1 ] == '/' )
00129
00130 action.truncate( action.length()-1 );
00131
00132
00133 QDir dir( path );
00134 const QStringList files = dir.entryList( QDir::Files );
00135 if ( files.isEmpty() )
00136
00137 return;
00138
00139
00140 QFile f( path + "/" + files[0] );
00141 if (!f.open(IO_ReadOnly)) {
00142 kdError(5850) << "Can't open file '" << files[0] << "'" << endl;
00143 return;
00144 }
00145 QTextStream t(&f);
00146 t.setEncoding( QTextStream::UnicodeUTF8 );
00147
00148 QString receiver = t.readLine();
00149 if ( receiver == "Receiver Not Searched" )
00150
00151 receiver = QString::null;
00152 else
00153
00154 receiver = KPIM::getEmailAddr( receiver );
00155
00156 QString iCal = t.read();
00157
00158 f.remove();
00159
00160 kdDebug(5850) << "Received this for scheduling (" << action << ")\n"
00161 << "Receiver: " << receiver << "\niCal:\n" << iCal << endl;
00162 ScheduleMessage *message = mFormat.parseScheduleMessage( mCalendar, iCal );
00163 if ( !message ) {
00164 QString errorMessage;
00165 if (mFormat.exception())
00166 errorMessage = i18n( "Error message: %1" ).arg( mFormat.exception()->message() );
00167 kdDebug(5850) << "MailScheduler::retrieveTransactions() Error parsing "
00168 << errorMessage << endl;
00169 KMessageBox::detailedError( mView,
00170 i18n("Error while processing an invitation or update."),
00171 errorMessage );
00172 return;
00173 }
00174
00175 KCal::Scheduler::Method method =
00176 static_cast<KCal::Scheduler::Method>( message->method() );
00177 KCal::ScheduleMessage::Status status = message->status();
00178 KCal::Incidence* incidence =
00179 dynamic_cast<KCal::Incidence*>( message->event() );
00180 KCal::MailScheduler scheduler( mCalendar );
00181 if ( action.startsWith( "accepted" ) || action.startsWith( "tentative" ) ) {
00182
00183
00184 KCal::Attendee::List attendees = incidence->attendees();
00185 KCal::Attendee::List::ConstIterator it;
00186 for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00187 if( (*it)->email() == receiver ) {
00188 if ( action.startsWith( "accepted" ) )
00189 (*it)->setStatus( KCal::Attendee::Accepted );
00190 else
00191 (*it)->setStatus( KCal::Attendee::Tentative );
00192 break;
00193 }
00194 }
00195 scheduler.acceptTransaction( incidence, method, status, receiver );
00196 } else if ( action.startsWith( "cancel" ) )
00197
00198 scheduler.acceptTransaction( incidence, KCal::Scheduler::Cancel, status );
00199 else if ( action.startsWith( "reply" ) )
00200 scheduler.acceptTransaction( incidence, method, status );
00201 else
00202 kdError(5850) << "Unknown incoming action " << action << endl;
00203 mView->updateView();
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 bool KOGroupware::sendICalMessage( QWidget* parent,
00213 KCal::Scheduler::Method method,
00214 Incidence* incidence, bool isDeleting,
00215 bool statusChanged )
00216 {
00217
00218 if( incidence->attendees().isEmpty() )
00219 return true;
00220
00221 bool isOrganizer = KOPrefs::instance()->thatIsMe( incidence->organizer().email() );
00222 int rc = 0;
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 if ( isOrganizer ) {
00238
00239
00240
00241 if ( incidence->attendees().count() > 1
00242 || incidence->attendees().first()->email() != incidence->organizer().email() ) {
00243 QString type;
00244 if( incidence->type() == "Event") type = i18n("event");
00245 else if( incidence->type() == "Todo" ) type = i18n("task");
00246 else if( incidence->type() == "Journal" ) type = i18n("journal entry");
00247 else type = incidence->type();
00248 QString txt = i18n( "This %1 includes other people. "
00249 "Should email be sent out to the attendees?" )
00250 .arg( type );
00251 rc = KMessageBox::questionYesNoCancel( parent, txt,
00252 i18n("Group scheduling email") );
00253 } else {
00254 return true;
00255 }
00256 } else if( incidence->type() == "Todo" ) {
00257 if( method == Scheduler::Request )
00258
00259 method = Scheduler::Reply;
00260
00261
00262 QString txt = i18n( "Do you want to send a status update to the "
00263 "organizer of this task?");
00264 rc = KMessageBox::questionYesNo( parent, txt );
00265 } else if( incidence->type() == "Event" ) {
00266 QString txt;
00267 if ( statusChanged && method == Scheduler::Request ) {
00268 txt = i18n( "Your status as an attendee of this event "
00269 "changed. Do you want to send a status update to the "
00270 "organizer of this event?" );
00271 method = Scheduler::Reply;
00272 rc = KMessageBox::questionYesNo( parent, txt );
00273 } else {
00274 if( isDeleting )
00275 txt = i18n( "You are not the organizer of this event. "
00276 "Deleting it will bring your calendar out of sync "
00277 "with the organizers calendar. Do you really want "
00278 "to delete it?" );
00279 else
00280 txt = i18n( "You are not the organizer of this event. "
00281 "Editing it will bring your calendar out of sync "
00282 "with the organizers calendar. Do you really want "
00283 "to edit it?" );
00284 rc = KMessageBox::questionYesNo( parent, txt );
00285 return ( rc == KMessageBox::Yes );
00286 }
00287 } else {
00288 kdWarning(5850) << "Groupware messages for Journals are not implemented yet!" << endl;
00289 return true;
00290 }
00291 if( rc == KMessageBox::Yes ) {
00292
00293
00294 if( incidence->summary().isEmpty() )
00295 incidence->setSummary( i18n("<No summary given>") );
00296
00297
00298 KCal::MailScheduler scheduler( mCalendar );
00299 scheduler.performTransaction( incidence, method );
00300
00301 return true;
00302 } else if( rc == KMessageBox::No )
00303 return true;
00304 else
00305 return false;
00306 }
00307
00308
00309 #include "kogroupware.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.