libkpimexchange Library API Documentation

exchangecalendar.cpp

00001 /* 00002 This file is part of libkpimexchange. 00003 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 00004 00005 This library is free software; you can redistribute it and/or modify it 00006 under the terms of the GNU Library General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or (at your 00008 option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, but WITHOUT 00011 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00018 02111-1307, USA. 00019 */ 00020 00021 #include <stdlib.h> 00022 00023 #include <qdatetime.h> 00024 #include <qstring.h> 00025 #include <qptrlist.h> 00026 00027 #include <kdebug.h> 00028 00029 #include <libkcal/calendarlocal.h> 00030 #include <libkcal/calendar.h> 00031 #include <libkcal/journal.h> 00032 00033 #include "dateset.h" 00034 #include "exchangeaccount.h" 00035 #include "exchangeclient.h" 00036 00037 #include "exchangecalendar.h" 00038 00039 using namespace KCal; 00040 using namespace KPIM; 00041 00042 ExchangeCalendar::ExchangeCalendar( KPIM::ExchangeAccount* account ) 00043 : Calendar() 00044 { 00045 init( account ); 00046 mCache = new CalendarLocal(); 00047 } 00048 00049 ExchangeCalendar::ExchangeCalendar( KPIM::ExchangeAccount* account, const QString &timeZoneId) 00050 : Calendar(timeZoneId) 00051 { 00052 init( account ); 00053 mCache = new CalendarLocal( timeZoneId ); 00054 } 00055 00056 void ExchangeCalendar::init( KPIM::ExchangeAccount* account ) 00057 { 00058 kdDebug() << "ExchangeCalendar::init()" << endl; 00059 mAccount = account; 00060 mClient = new ExchangeClient( account ); 00061 mDates = new DateSet(); 00062 00063 mEventDates = new QMap<Event,QDateTime>(); 00064 mCacheDates = new QMap<QDate, QDateTime>(); 00065 00066 mCachedSeconds = 600; // After 5 minutes, reread from server 00067 // mOldestDate = 0L; 00068 // mNewestDate = 0L; 00069 } 00070 00071 00072 ExchangeCalendar::~ExchangeCalendar() 00073 { 00074 kdDebug() << "Destructing ExchangeCalendar" << endl; 00075 close(); 00076 // delete mNewestDate; 00077 // delete mOldestDate; 00078 delete mDates; 00079 delete mClient; 00080 delete mEventDates; 00081 delete mCacheDates; 00082 delete mCache; 00083 } 00084 00085 00086 bool ExchangeCalendar::load( const QString &fileName ) 00087 { 00088 // return mCache->load( fileName ); 00089 return true; 00090 } 00091 00092 bool ExchangeCalendar::save( const QString &fileName, CalFormat *format ) 00093 { 00094 return mCache->save( fileName, format ); 00095 } 00096 00097 void ExchangeCalendar::close() 00098 { 00099 mCache->close(); 00100 setModified( false ); 00101 } 00102 00103 00104 void ExchangeCalendar::addEvent(Event *anEvent) 00105 { 00106 kdDebug() << "ExchangeCalendar::addEvent" << endl; 00107 mCache->addEvent( anEvent ); 00108 insertEvent(anEvent); 00109 00110 anEvent->registerObserver( this ); 00111 00112 setModified( true ); 00113 } 00114 00115 // probably not really efficient, but...it works for now. 00116 void ExchangeCalendar::deleteEvent(Event *event) 00117 { 00118 kdDebug(5800) << "ExchangeCalendar::deleteEvent" << endl; 00119 mCache->deleteEvent( event ); 00120 setModified( true ); 00121 } 00122 00123 00124 Event *ExchangeCalendar::event( const QString &uid ) 00125 { 00126 kdDebug(5800) << "ExchangeCalendar::event(): " << uid << endl; 00127 00128 return mCache->event( uid ); 00129 } 00130 00131 void ExchangeCalendar::addTodo(Todo *todo) 00132 { 00133 mCache->addTodo( todo ); 00134 00135 todo->registerObserver( this ); 00136 00137 setModified( true ); 00138 } 00139 00140 void ExchangeCalendar::deleteTodo(Todo *todo) 00141 { 00142 mCache->deleteTodo( todo ); 00143 00144 setModified( true ); 00145 } 00146 00147 QPtrList<Todo> ExchangeCalendar::rawTodos() const 00148 { 00149 return mCache->rawTodos(); 00150 } 00151 00152 Todo *ExchangeCalendar::todo( const QString &uid ) 00153 { 00154 return mCache->todo( uid ); 00155 } 00156 00157 QPtrList<Todo> ExchangeCalendar::todos( const QDate &date ) 00158 { 00159 return mCache->todos( date ); 00160 } 00161 00162 Alarm::List ExchangeCalendar::alarmsTo( const QDateTime &to ) 00163 { 00164 return mCache->alarmsTo( to ); 00165 } 00166 00167 Alarm::List ExchangeCalendar::alarms( const QDateTime &from, const QDateTime &to ) 00168 { 00169 kdDebug(5800) << "ExchangeCalendar::alarms(" << from.toString() << " - " << to.toString() << ")\n"; 00170 return mCache->alarms( from, to ); 00171 } 00172 00173 /****************************** PROTECTED METHODS ****************************/ 00174 00175 // after changes are made to an event, this should be called. 00176 void ExchangeCalendar::update(IncidenceBase *incidence) 00177 { 00178 setModified( true ); 00179 } 00180 00181 // this function will take a VEvent and insert it into the event 00182 // dictionary for the ExchangeCalendar. If there is no list of events for that 00183 // particular location in the dictionary, a new one will be created. 00184 void ExchangeCalendar::insertEvent(const Event *anEvent) 00185 { 00186 kdDebug() << "ExchangeCalendar::insertEvent" << endl; 00187 00188 } 00189 00190 // taking a QDate, this function will look for an eventlist in the dict 00191 // with that date attached - 00192 QPtrList<Event> ExchangeCalendar::rawEventsForDate(const QDate &qd, bool sorted) 00193 { 00194 kdDebug() << "ExchangeCalendar::rawEventsForDate(" << qd.toString() << "," << sorted << ")" << endl; 00195 00196 // If the events for this date are not in the cache, or if they are old, 00197 // get them again 00198 QDateTime now = QDateTime::currentDateTime(); 00199 // kdDebug() << "Now is " << now.toString() << endl; 00200 // kdDebug() << "mDates: " << mDates << endl; 00201 // kdDebug() << "mDates->contains(qd) is " << mDates->contains( qd ) << endl; 00202 QDate start = QDate( qd.year(), qd.month(), 1 ); // First day of month 00203 if ( !mDates->contains( start ) || (*mCacheDates)[start].secsTo( now ) > mCachedSeconds ) { 00204 kdDebug() << "Reading events for month of " << start.toString() << endl; 00205 QDate end = start.addMonths( 1 ).addDays( -1 ); // Last day of month 00206 mClient->downloadSynchronous( mCache, start, end, true ); // Show progress dialog 00207 mDates->add( start ); 00208 mCacheDates->insert( start, now ); 00209 } 00210 00211 // Events are safely in the cache now, return them from cache 00212 QPtrList<Event> events = mCache->rawEventsForDate( qd, sorted ); 00213 kdDebug() << "Found " << events.count() << " events." << endl; 00214 return events; 00215 00216 /* 00217 if (!sorted) { 00218 return eventList; 00219 } 00220 00221 // kdDebug(5800) << "Sorting events for date\n" << endl; 00222 // now, we have to sort it based on getDtStart.time() 00223 QPtrList<Event> eventListSorted; 00224 for (anEvent = eventList.first(); anEvent; anEvent = eventList.next()) { 00225 if (!eventListSorted.isEmpty() && 00226 anEvent->dtStart().time() < eventListSorted.at(0)->dtStart().time()) { 00227 eventListSorted.insert(0,anEvent); 00228 goto nextToInsert; 00229 } 00230 for (i = 0; (uint) i+1 < eventListSorted.count(); i++) { 00231 if (anEvent->dtStart().time() > eventListSorted.at(i)->dtStart().time() && 00232 anEvent->dtStart().time() <= eventListSorted.at(i+1)->dtStart().time()) { 00233 eventListSorted.insert(i+1,anEvent); 00234 goto nextToInsert; 00235 } 00236 } 00237 eventListSorted.append(anEvent); 00238 nextToInsert: 00239 continue; 00240 } 00241 return eventListSorted; 00242 */ 00243 } 00244 00245 00246 QPtrList<Event> ExchangeCalendar::rawEvents( const QDate &start, const QDate &end, 00247 bool inclusive ) 00248 { 00249 kdDebug() << "ExchangeCalendar::rawEvents(start,end,inclusive)" << endl; 00250 return mCache->rawEvents( start, end, inclusive ); 00251 } 00252 00253 QPtrList<Event> ExchangeCalendar::rawEventsForDate(const QDateTime &qdt) 00254 { 00255 kdDebug() << "ExchangeCalendar::rawEventsForDate(qdt)" << endl; 00256 return rawEventsForDate( qdt.date() ); 00257 } 00258 00259 QPtrList<Event> ExchangeCalendar::rawEvents() 00260 { 00261 kdDebug() << "ExchangeCalendar::rawEvents()" << endl; 00262 return mCache->rawEvents(); 00263 } 00264 00265 void ExchangeCalendar::addJournal(Journal *journal) 00266 { 00267 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 00268 mCache->addJournal( journal ); 00269 00270 journal->registerObserver( this ); 00271 00272 setModified( true ); 00273 } 00274 00275 Journal *ExchangeCalendar::journal(const QDate &date) 00276 { 00277 // kdDebug(5800) << "ExchangeCalendar::journal() " << date.toString() << endl; 00278 return mCache->journal( date ); 00279 } 00280 00281 Journal *ExchangeCalendar::journal(const QString &uid) 00282 { 00283 return mCache->journal( uid ); 00284 } 00285 00286 QPtrList<Journal> ExchangeCalendar::journals() 00287 { 00288 return mCache->journals(); 00289 }
KDE Logo
This file is part of the documentation for libkpimexchange Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:09 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003