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
00053 FreeBusyManager *KOGroupware::mFreeBusyManager = 0;
00054
00055 KOGroupware *KOGroupware::mInstance = 0;
00056
00057 KOGroupware *KOGroupware::create( CalendarView *view,
00058 KCal::Calendar *calendar )
00059 {
00060 if( !mInstance )
00061 mInstance = new KOGroupware( view, calendar );
00062 return mInstance;
00063 }
00064
00065 KOGroupware *KOGroupware::instance()
00066 {
00067
00068 Q_ASSERT( mInstance );
00069 return mInstance;
00070 }
00071
00072
00073 KOGroupware::KOGroupware( CalendarView* view, KCal::Calendar* calendar )
00074 : QObject( 0, "kmgroupware_instance" )
00075 {
00076 mView = view;
00077 mCalendar = calendar;
00078
00079
00080 KDirWatch* watcher = KDirWatch::self();
00081 watcher->addDir( locateLocal( "data", "korganizer/income.accepted/" ) );
00082 watcher->addDir( locateLocal( "data", "korganizer/income.cancel/" ) );
00083 watcher->addDir( locateLocal( "data", "korganizer/income.reply/" ) );
00084 connect( watcher, SIGNAL( dirty( const QString& ) ),
00085 this, SLOT( incomingDirChanged( const QString& ) ) );
00086
00087 incomingDirChanged( locateLocal( "data", "korganizer/income.accepted/" ) );
00088 incomingDirChanged( locateLocal( "data", "korganizer/income.cancel/" ) );
00089 incomingDirChanged( locateLocal( "data", "korganizer/income.reply/" ) );
00090 }
00091
00092 FreeBusyManager *KOGroupware::freeBusyManager()
00093 {
00094 if ( !mFreeBusyManager ) {
00095 mFreeBusyManager = new FreeBusyManager( this, "freebusymanager" );
00096 mFreeBusyManager->setCalendar( mCalendar );
00097 connect( mCalendar, SIGNAL( calendarChanged() ),
00098 mFreeBusyManager, SLOT( slotPerhapsUploadFB() ) );
00099 }
00100
00101 return mFreeBusyManager;
00102 }
00103
00104 void KOGroupware::incomingDirChanged( const QString& path )
00105 {
00106 const QString incomingDirName = locateLocal( "data","korganizer/" )
00107 + "income.";
00108 if ( !path.startsWith( incomingDirName ) ) {
00109 kdDebug(5850) << "incomingDirChanged: Wrong dir " << path << endl;
00110 return;
00111 }
00112 QString action = path.mid( incomingDirName.length() );
00113 while ( action.length() > 0 && action[ action.length()-1 ] == '/' )
00114
00115 action.truncate( action.length()-1 );
00116
00117
00118 QDir dir( path );
00119 QStringList files = dir.entryList( QDir::Files );
00120 if ( files.count() == 0 )
00121
00122 return;
00123
00124
00125 QFile f( path + "/" + files[0] );
00126 if (!f.open(IO_ReadOnly)) {
00127 kdError(5850) << "Can't open file '" << files[0] << "'" << endl;
00128 return;
00129 }
00130 QTextStream t(&f);
00131 t.setEncoding( QTextStream::UnicodeUTF8 );
00132 QString receiver = KPIM::getEmailAddr( t.readLine() );
00133 QString iCal = t.read();
00134
00135 ScheduleMessage *message = mFormat.parseScheduleMessage( mCalendar, iCal );
00136 if ( !message ) {
00137 QString errorMessage;
00138 if (mFormat.exception())
00139 errorMessage = "\nError message: " + mFormat.exception()->message();
00140 kdDebug(5850) << "MailScheduler::retrieveTransactions() Error parsing"
00141 << errorMessage << endl;
00142 f.close();
00143 return;
00144 } else
00145 f.remove();
00146
00147 KCal::Scheduler::Method method =
00148 static_cast<KCal::Scheduler::Method>( message->method() );
00149 KCal::ScheduleMessage::Status status = message->status();
00150 KCal::Incidence* incidence =
00151 dynamic_cast<KCal::Incidence*>( message->event() );
00152 KCal::MailScheduler scheduler( mCalendar );
00153 if ( action.startsWith( "accepted" ) ) {
00154
00155 KCal::Attendee::List attendees = incidence->attendees();
00156 KCal::Attendee::List::ConstIterator it;
00157 for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00158 if( (*it)->email() == receiver ) {
00159 (*it)->setStatus( KCal::Attendee::Accepted );
00160 break;
00161 }
00162 }
00163 scheduler.acceptTransaction( incidence, method, status );
00164 } else if ( action.startsWith( "cancel" ) )
00165
00166 mCalendar->deleteIncidence( incidence );
00167 else if ( action.startsWith( "reply" ) )
00168 scheduler.acceptTransaction( incidence, method, status );
00169 else
00170 kdError(5850) << "Unknown incoming action " << action << endl;
00171 mView->updateView();
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 bool KOGroupware::sendICalMessage( QWidget* parent,
00181 KCal::Scheduler::Method method,
00182 Incidence* incidence, bool isDeleting )
00183 {
00184 bool isOrganizer = KOPrefs::instance()->thatIsMe( incidence->organizer().email() );
00185
00186 int rc = 0;
00187 if( isOrganizer ) {
00188
00189 bool otherPeople = false;
00190 Attendee::List attendees = incidence->attendees();
00191 Attendee::List::ConstIterator it;
00192 for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00193
00194 if ( !KOPrefs::instance()->thatIsMe( (*it)->email() ) ) {
00195 otherPeople = true;
00196 break;
00197 }
00198 }
00199 if( !otherPeople )
00200
00201 return true;
00202
00203 QString type;
00204 if( incidence->type() == "Event") type = i18n("event");
00205 else if( incidence->type() == "Todo" ) type = i18n("task");
00206 else if( incidence->type() == "Journal" ) type = i18n("journal entry");
00207 else type = incidence->type();
00208 QString txt = i18n( "This %1 includes other people. "
00209 "Should email be sent out to the attendees?" )
00210 .arg( type );
00211 rc = KMessageBox::questionYesNoCancel( parent, txt,
00212 i18n("Group scheduling email") );
00213 } else if( incidence->type() == "Todo" ) {
00214 if( method == Scheduler::Request )
00215
00216 method = Scheduler::Reply;
00217
00218
00219 QString txt = i18n( "Do you want to send a status update to the "
00220 "organizer of this task?");
00221 rc = KMessageBox::questionYesNo( parent, txt );
00222 } else if( incidence->type() == "Event" ) {
00223
00224
00225
00226 QString txt;
00227 if( isDeleting )
00228 txt = i18n( "You are not the organizer of this event. "
00229 "Deleting it will bring your calendar out of sync "
00230 "with the organizers calendar. Do you really want "
00231 "to delete it?" );
00232 else
00233 txt = i18n( "You are not the organizer of this event. "
00234 "Editing it will bring your calendar out of sync "
00235 "with the organizers calendar. Do you really want "
00236 "to edit it?" );
00237 rc = KMessageBox::questionYesNo( parent, txt );
00238 return ( rc == KMessageBox::Yes );
00239 } else {
00240 qFatal( "Some unimplemented thing happened" );
00241 }
00242
00243 if( rc == KMessageBox::Yes ) {
00244
00245
00246 if( incidence->summary().isEmpty() )
00247 incidence->setSummary( i18n("<No summary given>") );
00248
00249
00250 KCal::MailScheduler scheduler( mCalendar );
00251 scheduler.performTransaction( incidence, method );
00252
00253 return true;
00254 } else if( rc == KMessageBox::No )
00255 return true;
00256 else
00257 return false;
00258 }
00259
00260
00261 #include "kogroupware.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.