libkcal

resourcecalendar.h

Go to the documentation of this file.
00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 1998 Preston Brown <pbrown@kde.org>
00005     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00006     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00007     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Library General Public
00011     License as published by the Free Software Foundation; either
00012     version 2 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Library General Public License for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with this library; see the file COPYING.LIB.  If not, write to
00021     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022     Boston, MA 02110-1301, USA.
00023 */
00024 
00025 #ifndef KCAL_RESOURCECALENDAR_H
00026 #define KCAL_RESOURCECALENDAR_H
00027 
00028 #include <qstring.h>
00029 #include <qdatetime.h>
00030 #include <qptrlist.h>
00031 
00032 #include <kconfig.h>
00033 
00034 #include "alarm.h"
00035 #include "todo.h"
00036 #include "event.h"
00037 #include "journal.h"
00038 #include "calendar.h"
00039 
00040 #include <kresources/resource.h>
00041 #include <kresources/manager.h>
00042 #include <kabc/lock.h>
00043 #include <kdepimmacros.h>
00044 
00045 namespace KCal {
00046 
00047 class CalFormat;
00048 
00056 class LIBKCAL_EXPORT ResourceCalendar : public KRES::Resource
00057 {
00058     Q_OBJECT
00059   public:
00060     ResourceCalendar( const KConfig * );
00061     virtual ~ResourceCalendar();
00062 
00063     void setResolveConflict( bool b);
00064 
00065     virtual void writeConfig( KConfig* config );
00066 
00071     virtual QString infoText() const;
00072 
00092     bool load();
00093 
00111     bool save( Incidence *incidence = 0 );
00112 
00117     virtual bool isSaving() { return false; }
00118 
00122     virtual KABC::Lock *lock() = 0;
00123 
00127     virtual bool addIncidence( Incidence * );
00128 
00132     virtual bool deleteIncidence( Incidence * );
00133 
00138     Incidence *incidence( const QString &uid );
00139 
00143     virtual bool addEvent( Event *event ) = 0;
00144 
00148     virtual bool deleteEvent( Event * ) = 0;
00149 
00153     virtual Event *event( const QString &uid ) = 0;
00154 
00159     virtual Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
00160 
00165     virtual Event::List rawEventsForDate( const QDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
00166 
00170     virtual Event::List rawEventsForDate( const QDateTime &qdt ) = 0;
00171 
00176     virtual Event::List rawEvents( const QDate &start, const QDate &end,
00177                                    bool inclusive = false ) = 0;
00178 
00198     virtual bool setValue( const QString &key, const QString &value );
00199 
00200   signals:
00207     void resourceChanged( ResourceCalendar * );
00208 
00213     void resourceLoaded( ResourceCalendar * );
00218     void resourceSaved( ResourceCalendar * );
00219 
00223     void resourceLoadError( ResourceCalendar *, const QString &error );
00227     void resourceSaveError( ResourceCalendar *, const QString &error );
00228 
00232     void signalSubresourceAdded( ResourceCalendar *, const QString& type,
00233                                  const QString& subresource, const QString& label );
00234 
00238     void signalSubresourceRemoved( ResourceCalendar *, const QString &,
00239                                    const QString & );
00240 
00241   public:
00245     virtual bool addTodo( Todo *todo ) = 0;
00249     virtual bool deleteTodo( Todo * ) = 0;
00255     virtual Todo *todo( const QString &uid ) = 0;
00259     virtual Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
00263     virtual Todo::List rawTodosForDate( const QDate &date ) = 0;
00264 
00265 
00269     virtual bool addJournal( Journal * ) = 0;
00270 
00274     virtual bool deleteJournal( Journal * ) = 0;
00275 
00279     virtual Journal *journal( const QString &uid ) = 0;
00283     virtual Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
00287     virtual Journal::List rawJournalsForDate( const QDate &date ) = 0;
00288 
00292     virtual Alarm::List alarms( const QDateTime &from,
00293                                 const QDateTime &to ) = 0;
00294 
00298     virtual Alarm::List alarmsTo( const QDateTime &to ) = 0;
00299 
00300 
00302     Incidence::List rawIncidences();
00303 
00307     virtual void setTimeZoneId( const QString &timeZoneId ) = 0;
00308 
00314     virtual QStringList subresources() const { return QStringList(); }
00315 
00319     virtual bool canHaveSubresources() const { return false; }
00320 
00324     virtual bool subresourceActive( const QString& ) const { return true; }
00325 
00329     virtual const QString labelForSubresource( const QString& resource ) const
00330     {
00331        // the resource identifier is a sane fallback
00332        return resource;
00333     };
00334 
00341     virtual QString subresourceIdentifier( Incidence *incidence )
00342     { Q_UNUSED( incidence ); return QString(); }
00343 
00344 
00345 
00349     virtual bool removeSubresource( const QString& resource );
00350 
00355     virtual bool addSubresource( const QString& resource, const QString& parent );
00356 
00361     virtual QString subresourceType( const QString &resource );
00362 
00363   public slots:
00367     virtual void setSubresourceActive( const QString &, bool active );
00368 
00369   protected:
00370 
00371     bool mResolveConflict;
00375     virtual bool doLoad() = 0;
00379     virtual bool doSave() = 0;
00380 
00385     virtual bool doSave( Incidence * );
00386 
00390     virtual void addInfoText( QString & ) const {};
00391 
00395     void loadError( const QString &errorMessage = QString::null );
00399     void saveError( const QString &errorMessage = QString::null );
00400 
00401   private:
00402     bool mReceivedLoadError;
00403     bool mReceivedSaveError;
00404 
00405     class Private;
00406     Private *d;
00407 };
00408 
00409 typedef KRES::Manager<ResourceCalendar> CalendarResourceManager;
00410 
00411 }
00412 
00413 #endif