korganizer

freebusymanager.h

00001 /*
00002   This file is part of the Groupware/KOrganizer integration.
00003 
00004   Requires the Qt and KDE widget libraries, available at no cost at
00005   http://www.trolltech.com and http://www.kde.org respectively
00006 
00007   Copyright (c) 2002-2004 Klarälvdalens Datakonsult AB
00008         <info@klaralvdalens-datakonsult.se>
00009 
00010   This program is free software; you can redistribute it and/or modify
00011   it under the terms of the GNU General Public License as published by
00012   the Free Software Foundation; either version 2 of the License, or
00013   (at your option) any later version.
00014 
00015   This program is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018   GNU General Public License for more details.
00019 
00020   You should have received a copy of the GNU General Public License
00021   along with this program; if not, write to the Free Software
00022   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023   MA  02110-1301, USA.
00024 
00025   In addition, as a special exception, the copyright holders give
00026   permission to link the code of this program with any edition of
00027   the Qt library by Trolltech AS, Norway (or with modified versions
00028   of Qt that use the same license as Qt), and distribute linked
00029   combinations including the two.  You must obey the GNU General
00030   Public License in all respects for all of the code used other than
00031   Qt.  If you modify this file, you may extend this exception to
00032   your version of the file, but you are not obligated to do so.  If
00033   you do not wish to do so, delete this exception statement from
00034   your version.
00035 */
00036 #ifndef FREEBUSYMANAGER_H
00037 #define FREEBUSYMANAGER_H
00038 
00039 #include <kurl.h>
00040 #include <libkcal/icalformat.h>
00041 #include <libkcal/freebusycache.h>
00042 #include <qstring.h>
00043 #include <qobject.h>
00044 
00045 namespace KIO { class Job; }
00046 namespace KCal {
00047 class Calendar;
00048 class FreeBusy;
00049 }
00050 class FreeBusyManager;
00051 
00055 class FreeBusyDownloadJob : public QObject
00056 {
00057     Q_OBJECT
00058   public:
00059     FreeBusyDownloadJob( const QString &email, const KURL &url,
00060                    FreeBusyManager *manager, const char *name = 0 );
00061 
00062     virtual ~FreeBusyDownloadJob();
00063 
00064   protected slots:
00065     void slotResult( KIO::Job * );
00066     void slotData(  KIO::Job *, const QByteArray &data );
00067 
00068   signals:
00069     void freeBusyDownloaded( KCal::FreeBusy *, const QString& email );
00070     void freeBusyDownloadError( const QString& email );
00071 
00072   private:
00073     FreeBusyManager *mManager;
00074     QString mEmail;
00075 
00076     QCString mFreeBusyData;
00077 };
00078 
00079 class FreeBusyManager : public QObject, public KCal::FreeBusyCache
00080 {
00081     Q_OBJECT
00082   public:
00083     FreeBusyManager( QObject *parent, const char *name );
00084 
00085     void setCalendar( KCal::Calendar * );
00086 
00088     void publishFreeBusy();
00089 
00098     bool retrieveFreeBusy( const QString &email, bool forceDownload );
00099 
00100     void cancelRetrieval();
00101 
00102     KCal::FreeBusy *iCalToFreeBusy( const QCString &data );
00103 
00107     KCal::FreeBusy *loadFreeBusy( const QString &email );
00111     bool saveFreeBusy( KCal::FreeBusy *freebusy, const KCal::Person &person );
00112 //    bool saveFreeBusy( KCal::FreeBusy *, const QString &email );
00113 
00117     KURL freeBusyUrl( const QString &email );
00118 
00122     QString freeBusyDir();
00123 
00128     void setBrokenUrl( bool isBroken );
00129 
00130   public slots:
00131     // When something changed in the calendar, we get this called
00132     void slotPerhapsUploadFB();
00133 
00134   signals:
00138     void freeBusyRetrieved( KCal::FreeBusy *, const QString &email );
00139 
00140   protected:
00141     void timerEvent( QTimerEvent* );
00142 
00146     QString ownerFreeBusyAsString();
00147 
00151     KCal::FreeBusy *ownerFreeBusy();
00152 
00156     QString freeBusyToIcal( KCal::FreeBusy * );
00157 
00158   protected slots:
00159     bool processRetrieveQueue();
00160 
00161   private slots:
00162     void slotUploadFreeBusyResult( KIO::Job * );
00163     void slotFreeBusyDownloadError( const QString& email );
00164 
00165   private:
00166     KCal::Calendar *mCalendar;
00167     KCal::ICalFormat mFormat;
00168 
00169     QStringList mRetrieveQueue;
00170 
00171     // Free/Busy uploading
00172     QDateTime mNextUploadTime;
00173     int mTimerID;
00174     bool mUploadingFreeBusy;
00175     bool mBrokenUrl;
00176 
00177 };
00178 
00179 #endif