Factor out the shared parts of the agent action manager setup.
[kdepim.git] / kalarm / resources / resourcelocaldir.h
blob683d5ef2d5f50ee31b54f10140545bf180e9c57d
1 /*
2 * resourcelocaldir.h - KAlarm local directory alarm calendar resource
3 * Program: kalarm
4 * Copyright © 2006-2011 by David Jarvie <djarvie@kde.org>
5 * Based on resourcelocaldir.h in libkcal,
6 * Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef RESOURCELOCALDIR_H
24 #define RESOURCELOCALDIR_H
26 /* @file resourcelocaldir.h - KAlarm local directory alarm calendar resource */
28 #include "alarmresource.h"
30 #include <kurl.h>
31 #include <kdirwatch.h>
32 #include <QMap>
33 #include <QList>
35 namespace KCal {
36 class Incidence;
40 /** A KAlarm calendar resource stored in a directory as one file per alarm. */
41 class KALARM_RESOURCES_EXPORT KAResourceLocalDir : public AlarmResource
43 Q_OBJECT
44 public:
45 KAResourceLocalDir();
46 /** Create resource from configuration information stored in a KConfig object. */
47 explicit KAResourceLocalDir(const KConfigGroup&);
48 /** Create resource for directory named @p dirName. */
49 KAResourceLocalDir(CalEvent::Type, const QString& dirName);
50 virtual ~KAResourceLocalDir();
52 const KUrl& url() const { return mURL; }
53 QString dirName() const;
54 bool setDirName(const KUrl&);
55 virtual QString displayType() const;
56 virtual QString displayLocation() const;
57 virtual QStringList location() const { return QStringList(dirName()); }
58 virtual bool setLocation(const QString& dirName, const QString& = QString());
59 virtual bool readOnly() const;
60 virtual void setReadOnly(bool);
61 virtual bool addEvent(KCal::Event*);
62 virtual bool deleteEvent(KCal::Event*);
63 virtual void writeConfig(KConfigGroup&);
64 virtual void startReconfig();
65 virtual void applyReconfig();
67 // Override unused virtual functions
68 virtual KCal::Todo::List rawTodos(KCal::TodoSortField = KCal::TodoSortUnsorted, KCal::SortDirection = KCal::SortDirectionAscending) { return KCal::Todo::List(); }
69 virtual KCal::Journal::List rawJournals(KCal::JournalSortField = KCal::JournalSortUnsorted, KCal::SortDirection = KCal::SortDirectionAscending) { return KCal::Journal::List(); }
71 protected:
72 virtual bool doOpen();
73 /** Load the resource. If 'syncCache' is true, all files in the directory
74 * are reloaded. If 'syncCache' is false, only changed files are reloaded. */
75 virtual bool doLoad(bool syncCache);
77 virtual bool doSave(bool syncCache);
78 bool doSave(bool syncCache, KCal::Incidence*);
79 virtual void enableResource(bool enable);
81 private slots:
82 void slotUpdated(const QString& filepath);
84 private:
85 void init();
86 bool loadFile(const QString& fileName, const QString& id, bool readOnly, FixFunc& prompt);
87 bool deleteIncidenceFile(KCal::Incidence *incidence);
88 // Inherited virtual methods which are not used by derived classes
89 using ResourceCalendar::doLoad;
90 virtual bool doSave() { return false; }
91 virtual bool doSave(KCal::Incidence*) { return false; }
93 KUrl mURL;
94 KUrl mNewURL; // new directory to be applied by applyReconfig()
95 KDirWatch mDirWatch;
96 typedef QMap<QString, QDateTime> ModifiedMap;
97 ModifiedMap mLastModified;
98 QList<KCal::Incidence*> mDeletedIncidences;
99 bool mDirReadOnly; // directory is read-only
102 #endif
104 // vim: et sw=4: