~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kalarm/resources/alarmresource.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
/* @file alarmresource.h - base class for a KAlarm alarm calendar resource */
25
25
 
26
26
#include "kalarm_resources_export.h"
27
 
#include "kcalendar.h"
 
27
#include "kacalendar.h"
28
28
 
29
29
#include <kcal/resourcecached.h>
30
30
#include <QMap>
41
41
/** Base class for a KAlarm alarm calendar resource. */
42
42
class KALARM_RESOURCES_EXPORT AlarmResource : public KCal::ResourceCached
43
43
{
44
 
                Q_OBJECT
45
 
        public:
46
 
                /** Type of alarms held in this calendar resource. */
47
 
                enum Type {
48
 
                        INVALID  = 0,
49
 
                        ACTIVE   = 0x01,    // active alarms
50
 
                        ARCHIVED = 0x02,    // archived alarms
51
 
                        TEMPLATE = 0x04     // alarm templates
52
 
                };
53
 
                /** Whether the fix function should convert old format KAlarm calendars. */
54
 
                enum FixFunc { PROMPT, PROMPT_PART, CONVERT, NO_CONVERT };
55
 
 
56
 
                AlarmResource();
57
 
                explicit AlarmResource(const KConfigGroup&);
58
 
                explicit AlarmResource(Type);
59
 
                ~AlarmResource();
60
 
                virtual void writeConfig(KConfigGroup&);
61
 
                virtual QString infoText() const;
62
 
                KABC::Lock*  lock()                      { return mLock; }
63
 
 
64
 
                /** Return which type of alarms the resource can contain. */
65
 
                Type     alarmType() const               { return mType; }
66
 
 
67
 
                /** Return which type of alarms the resource can contain. */
68
 
                KCalEvent::Status kcalEventType() const;
69
 
 
70
 
                /** Set the type of alarms which the resource can contain. */
71
 
                void     setAlarmType(Type type)         { mType = type; }
72
 
 
73
 
                /** Return whether the resource contains only alarms of the wrong type. */
74
 
                bool     isWrongAlarmType() const        { return mWrongAlarmType; }
75
 
 
76
 
                /** Check whether the alarm types in a calendar correspond with
77
 
                 *  the resource's alarm type.
78
 
                 *  Reply = true if at least 1 alarm is the right type.
79
 
                 */
80
 
                bool checkAlarmTypes(KCal::CalendarLocal&) const;
81
 
 
82
 
                /** Set whether the application has a GUI. This determines whether error or
83
 
                 *  progress messages are displayed. */
84
 
                static void setNoGui(bool noGui)         { mNoGui = noGui; }
85
 
                static bool hasGui()                     { return !mNoGui; }
86
 
 
87
 
                /** Return the location(s) of the resource (URL, file path, etc.) */
88
 
                virtual QStringList location() const = 0;
89
 
 
90
 
                /** Return the type of the resource (URL, file, etc.)
91
 
                 *  for display purposes. */
92
 
                virtual QString displayType() const = 0;
93
 
 
94
 
                /** Return the location of the resource (URL, file path, etc.)
95
 
                 *  for display purposes. */
96
 
                virtual QString displayLocation() const = 0;
97
 
 
98
 
                /** Change the resource's location. The resource will be reloaded if active. */
99
 
                virtual bool setLocation(const QString& locn, const QString& locn2 = QString()) = 0;
100
 
                /** Return whether the resource is the standard resource for its alarm type. */
101
 
                bool     standardResource() const        { return mStandard; }
102
 
 
103
 
                /** Set or clear the resource as the standard resource for its alarm type. */
104
 
                void     setStandardResource(bool std)   { mStandard = std; }
105
 
 
106
 
                void     setEnabled(bool enable);
107
 
                bool     isEnabled() const               { return !mWrongAlarmType && isActive(); }
108
 
 
109
 
                /** Return whether the resource can be written to now,
110
 
                 *  i.e. it's active, read-write and in the current KAlarm format. */
111
 
                bool     writable() const                { return isEnabled() && !readOnly(); }
112
 
 
113
 
                /** Return whether the event can be written to now, i.e. the resource is
114
 
                 *  active and read-write, and the event is in the current KAlarm format. */
115
 
                bool     writable(const KCal::Event*) const;
116
 
 
117
 
                /** Return whether the resource is cached, i.e. whether it is downloaded
118
 
                 *  and stored locally in a cache file. */
119
 
                virtual bool cached() const              { return false; }
120
 
 
121
 
                /** Return whether the resource is read-only, either because it's marked as
122
 
                 *  read-only, or because it's active but not in the current KAlarm format. */
123
 
                virtual bool readOnly() const;
124
 
                virtual void setReadOnly(bool);
125
 
 
126
 
                /** Return the colour used to display alarms belonging to this resource.
127
 
                 *  @return display colour, or invalid if none specified */
128
 
                QColor   colour() const                  { return mColour; }
129
 
 
130
 
                /** Set the colour used to display alarms belonging to this resource.
131
 
                 *  @param color display colour, or invalid to use the default colour */
132
 
                void     setColour(const QColor& color);
133
 
                /** Start a batch of configuration changes.
134
 
                 *  The changes will be stored up until applyReconfig() is called. */
135
 
                virtual void startReconfig();
136
 
 
137
 
                /** Apply the batch of configuration changes since startReconfig() was called. */
138
 
                virtual void applyReconfig();
139
 
 
140
 
                /** Load the resource.
141
 
                 *  If it's a cached resource, load() uses the default action to either refresh
142
 
                 *  the cache file first or not.
143
 
                 *  If loading succeeds, the loaded() signal is emitted on completion (but is
144
 
                 *  not emitted if false is returned). This allows AlarmResources to process
145
 
                 *  the load.
146
 
                 *  Loading is not performed if the resource is disabled.
147
 
                 *  @return true if loading succeeded at least partially, false if it failed
148
 
                 *          completely
149
 
                 */
150
 
                bool load(CacheAction a)  { return KCal::ResourceCached::load(a); }
151
 
 
152
 
                /** Return whether the resource has fully loaded. */
153
 
                bool     isLoaded() const                { return mLoaded; }
154
 
 
155
 
                /** Return whether the resource is in the process of loading. */
156
 
                bool     isLoading() const               { return mLoading; }
157
 
 
158
 
                /** Save the resource and then close it.
159
 
                 *  It will be closed even if saving fails. */
160
 
                bool saveAndClose(CacheAction, KCal::Incidence* = 0);
161
 
                bool saveAndClose(KCal::Incidence* incidence = 0)  { return saveAndClose(DefaultCache, incidence); }
162
 
 
163
 
                /** Set a function to write the application ID into a calendar. */
164
 
                static void setCalIDFunction(void (*f)(CalendarLocal&))    { mCalIDFunction = f; }
165
 
                /** Set a function to create KAlarm event instances.
166
 
                 *  When the function is called, the CalendarLocal parameter is
167
 
                 *  set to null to indicate that the resource is about to be reloaded. */
168
 
                static void setCustomEventFunction(void (*f)(AlarmResource*, CalendarLocal*))   { mCustomEventFunction = f; }
169
 
                /** Set a function to fix the calendar once it has been loaded. */
170
 
                static void setFixFunction(KCalendar::Status (*f)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType))
171
 
                                                         { mFixFunction = f; }
172
 
                /** Return whether the resource is in a different format from the
173
 
                 *  current KAlarm format, in which case it cannot be written to.
174
 
                 *  Note that readOnly() takes account of both incompatible() and
175
 
                 *  KCal::ResourceCached::readOnly().
176
 
                 */
177
 
                KCalendar::Status compatibility() const  { return mCompatibility; }
178
 
                KCalendar::Status compatibility(const KCal::Event*) const;
179
 
 
180
 
                virtual void showProgress(bool)  {}
181
 
 
182
 
                static int debugArea()               { return mDebugArea; }
183
 
                static void setDebugArea(int area)   { mDebugArea = area; }
 
44
        Q_OBJECT
 
45
    public:
 
46
        /** Whether the fix function should convert old format KAlarm calendars. */
 
47
        enum FixFunc { PROMPT, PROMPT_PART, CONVERT, NO_CONVERT };
 
48
 
 
49
        AlarmResource();
 
50
        explicit AlarmResource(const KConfigGroup&);
 
51
        explicit AlarmResource(KAlarm::CalEvent::Type);
 
52
        ~AlarmResource();
 
53
        virtual void writeConfig(KConfigGroup&);
 
54
        virtual QString infoText() const;
 
55
        KABC::Lock*  lock()                      { return mLock; }
 
56
 
 
57
        /** Return which type of alarms the resource can contain. */
 
58
        KAlarm::CalEvent::Type alarmType() const               { return mType; }
 
59
 
 
60
        /** Set the type of alarms which the resource can contain. */
 
61
        void     setAlarmType(KAlarm::CalEvent::Type type)     { mType = type; }
 
62
 
 
63
        /** Return whether the resource contains only alarms of the wrong type. */
 
64
        bool     isWrongAlarmType() const        { return mWrongAlarmType; }
 
65
 
 
66
        /** Check whether the alarm types in a calendar correspond with
 
67
         *  the resource's alarm type.
 
68
         *  Reply = true if at least 1 alarm is the right type.
 
69
         */
 
70
        bool checkAlarmTypes(KCal::CalendarLocal&) const;
 
71
 
 
72
        /** Set whether the application has a GUI. This determines whether error or
 
73
         *  progress messages are displayed. */
 
74
        static void setNoGui(bool noGui)         { mNoGui = noGui; }
 
75
        static bool hasGui()                     { return !mNoGui; }
 
76
 
 
77
        /** Return the location(s) of the resource (URL, file path, etc.) */
 
78
        virtual QStringList location() const = 0;
 
79
 
 
80
        /** Return the type of the resource (URL, file, etc.)
 
81
         *  for display purposes. */
 
82
        virtual QString displayType() const = 0;
 
83
 
 
84
        /** Return the location of the resource (URL, file path, etc.)
 
85
         *  for display purposes. */
 
86
        virtual QString displayLocation() const = 0;
 
87
 
 
88
        /** Change the resource's location. The resource will be reloaded if active. */
 
89
        virtual bool setLocation(const QString& locn, const QString& locn2 = QString()) = 0;
 
90
        /** Return whether the resource is the standard resource for its alarm type. */
 
91
        bool     standardResource() const        { return mStandard; }
 
92
 
 
93
        /** Set or clear the resource as the standard resource for its alarm type. */
 
94
        void     setStandardResource(bool std)   { mStandard = std; }
 
95
 
 
96
        void     setEnabled(bool enable);
 
97
        bool     isEnabled() const               { return !mWrongAlarmType && isActive(); }
 
98
 
 
99
        /** Return whether the resource can be written to now,
 
100
         *  i.e. it's active, read-write and in the current KAlarm format. */
 
101
        bool     writable() const                { return isEnabled() && !readOnly(); }
 
102
 
 
103
        /** Return whether the event can be written to now, i.e. the resource is
 
104
         *  active and read-write, and the event is in the current KAlarm format. */
 
105
        bool     writable(const KCal::Event*) const;
 
106
 
 
107
        /** Return whether the resource is cached, i.e. whether it is downloaded
 
108
         *  and stored locally in a cache file. */
 
109
        virtual bool cached() const              { return false; }
 
110
 
 
111
        /** Return whether the resource is read-only, either because it's marked as
 
112
         *  read-only, or because it's active but not in the current KAlarm format. */
 
113
        virtual bool readOnly() const;
 
114
        virtual void setReadOnly(bool);
 
115
 
 
116
        /** Return the colour used to display alarms belonging to this resource.
 
117
         *  @return display colour, or invalid if none specified */
 
118
        QColor   colour() const                  { return mColour; }
 
119
 
 
120
        /** Set the colour used to display alarms belonging to this resource.
 
121
         *  @param color display colour, or invalid to use the default colour */
 
122
        void     setColour(const QColor& color);
 
123
        /** Start a batch of configuration changes.
 
124
         *  The changes will be stored up until applyReconfig() is called. */
 
125
        virtual void startReconfig();
 
126
 
 
127
        /** Apply the batch of configuration changes since startReconfig() was called. */
 
128
        virtual void applyReconfig();
 
129
 
 
130
        /** Load the resource.
 
131
         *  If it's a cached resource, load() uses the default action to either refresh
 
132
         *  the cache file first or not.
 
133
         *  If loading succeeds, the loaded() signal is emitted on completion (but is
 
134
         *  not emitted if false is returned). This allows AlarmResources to process
 
135
         *  the load.
 
136
         *  Loading is not performed if the resource is disabled.
 
137
         *  @return true if loading succeeded at least partially, false if it failed
 
138
         *          completely
 
139
         */
 
140
        bool load(CacheAction a)  { return KCal::ResourceCached::load(a); }
 
141
 
 
142
        /** Return whether the resource has fully loaded. */
 
143
        bool     isLoaded() const                { return mLoaded; }
 
144
 
 
145
        /** Return whether the resource is in the process of loading. */
 
146
        bool     isLoading() const               { return mLoading; }
 
147
 
 
148
        /** Save the resource and then close it.
 
149
         *  It will be closed even if saving fails. */
 
150
        bool saveAndClose(CacheAction, KCal::Incidence* = 0);
 
151
        bool saveAndClose(KCal::Incidence* incidence = 0)  { return saveAndClose(DefaultCache, incidence); }
 
152
 
 
153
        /** Set a function to write the application ID into a calendar. */
 
154
        static void setCalIDFunction(void (*f)(CalendarLocal&))    { mCalIDFunction = f; }
 
155
        /** Set a function to create KAlarm event instances.
 
156
         *  When the function is called, the CalendarLocal parameter is
 
157
         *  set to null to indicate that the resource is about to be reloaded. */
 
158
        static void setCustomEventFunction(void (*f)(AlarmResource*, CalendarLocal*))   { mCustomEventFunction = f; }
 
159
        /** Set a function to fix the calendar once it has been loaded. */
 
160
        static void setFixFunction(KAlarm::Calendar::Compat (*f)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType))
 
161
                                                 { mFixFunction = f; }
 
162
        /** Return whether the resource is in a different format from the
 
163
         *  current KAlarm format, in which case it cannot be written to.
 
164
         *  Note that readOnly() takes account of both incompatible() and
 
165
         *  KCal::ResourceCached::readOnly().
 
166
         */
 
167
        KAlarm::Calendar::Compat compatibility() const  { return mCompatibility; }
 
168
        KAlarm::Calendar::Compat compatibility(const KCal::Event*) const;
 
169
 
 
170
        virtual void showProgress(bool)  {}
 
171
 
 
172
        static int debugArea()               { return mDebugArea; }
 
173
        static void setDebugArea(int area)   { mDebugArea = area; }
184
174
 
185
175
#ifndef NDEBUG
186
 
                QByteArray typeName() const;
 
176
        QByteArray typeName() const;
187
177
#endif
188
178
 
189
 
        public slots:
190
 
                virtual void cancelDownload(bool /*disable*/ = false)  {}
191
 
 
192
 
        signals:
193
 
                /** Signal that the resource is about to close or reload.
194
 
                 *  This signal warns that all events are about to be deleted. */
195
 
                void invalidate(AlarmResource*);
196
 
                /** Signal that loading of the resource has completed, whether
197
 
                 *  successfully or not.
198
 
                 *  This signal is always emitted after a resource is loaded. */
199
 
                void loaded(AlarmResource*);
200
 
                /** Emitted after attempting to save the resource, whether successfully or not.
201
 
                 *  Not emitted if no attempt was made to save it (e.g. if the resource
202
 
                 *  is closed or read-only or there is nothing to save, or if save()
203
 
                 *  returned false).
204
 
                 */
205
 
                void resourceSaved(AlarmResource*);
206
 
                /** Emitted during download for remote resources. */
207
 
                void downloading(AlarmResource*, unsigned long percent);
208
 
                /** Signal that a remote resource download has completed, and the cache file has been updated. */
209
 
                void cacheDownloaded(AlarmResource*);
210
 
                /** Signal that the resource's read-only status has changed. */
211
 
                void readOnlyChanged(AlarmResource*);
212
 
                /** Signal that the resource's wrong alarm type status has changed. */
213
 
                void wrongAlarmTypeChanged(AlarmResource*);
214
 
                /** Signal that the resource's active status has changed. */
215
 
                void enabledChanged(AlarmResource*);
216
 
                /** Signal that the resource's location has changed. */
217
 
                void locationChanged(AlarmResource*);
218
 
                /** Signal that the resource cannot be set read-write since its format is incompatible. */
219
 
                void notWritable(AlarmResource*);
220
 
                /** Signal that the display colour has changed. */
221
 
                void colourChanged(AlarmResource*);
222
 
 
223
 
        protected:
224
 
                virtual void      doClose();
225
 
                bool              closeAfterSave() const    { return mCloseAfterSave; }
226
 
                void              setCompatibility(KCalendar::Status c)    { mCompatibility = c; }
227
 
                void              checkCompatibility(const QString&);
228
 
                KCalendar::Status checkCompatibility(KCal::CalendarLocal&, const QString& filename, FixFunc, bool* wrongType = 0);
229
 
                void              setWrongAlarmType(bool wrongType, bool emitSignal = true);
230
 
                void              updateCustomEvents(bool useCalendar = true);
231
 
                virtual void      enableResource(bool enable) = 0;
232
 
                void              lock(const QString& path);
233
 
 
234
 
                static void              (*mCalIDFunction)(CalendarLocal&);
235
 
                static KCalendar::Status (*mFixFunction)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType);
236
 
 
237
 
        private:
238
 
                void        init();
239
 
 
240
 
                static int  mDebugArea;       // area for kDebug() output
241
 
                static bool mNoGui;           // application has no GUI, so don't display messages
242
 
                static void              (*mCustomEventFunction)(AlarmResource*, CalendarLocal*);
243
 
 
244
 
                KABC::Lock* mLock;
245
 
                Type        mType;            // type of alarm held in this resource
246
 
                QColor      mColour;          // background colour for displaying this resource
247
 
                bool        mStandard;        // this is the standard resource for this mWriteType
248
 
                bool        mNewReadOnly;     // new read-only status (while mReconfiguring = 1)
249
 
                bool        mOldReadOnly;     // old read-only status (when startReconfig() called)
250
 
                bool        mCloseAfterSave;  // resource is to be closed once save() is complete
251
 
                bool        mWrongAlarmType;  // calendar contains only alarms of the wrong type
252
 
                KCalendar::Status mCompatibility; // whether resource is in compatible format
253
 
        protected:
254
 
                typedef QMap<const KCal::Event*, KCalendar::Status>  CompatibilityMap;
255
 
                CompatibilityMap  mCompatibilityMap;   // whether individual events are in compatible format
256
 
                short       mReconfiguring;   // a batch of config changes is in progress
257
 
                bool        mLoaded;          // true if resource has finished loading
258
 
                bool        mLoading;         // true if resource is currently loading
259
 
 
260
 
        private:
261
 
                using KCal::ResourceCached::load;   // prevent "hidden" warning
 
179
    public slots:
 
180
        virtual void cancelDownload(bool /*disable*/ = false)  {}
 
181
 
 
182
    signals:
 
183
        /** Signal that the resource is about to close or reload.
 
184
         *  This signal warns that all events are about to be deleted. */
 
185
        void invalidate(AlarmResource*);
 
186
        /** Signal that loading of the resource has completed, whether
 
187
         *  successfully or not.
 
188
         *  This signal is always emitted after a resource is loaded. */
 
189
        void loaded(AlarmResource*);
 
190
        /** Emitted after attempting to save the resource, whether successfully or not.
 
191
         *  Not emitted if no attempt was made to save it (e.g. if the resource
 
192
         *  is closed or read-only or there is nothing to save, or if save()
 
193
         *  returned false).
 
194
         */
 
195
        void resourceSaved(AlarmResource*);
 
196
        /** Emitted during download for remote resources. */
 
197
        void downloading(AlarmResource*, unsigned long percent);
 
198
        /** Signal that a remote resource download has completed, and the cache file has been updated. */
 
199
        void cacheDownloaded(AlarmResource*);
 
200
        /** Signal that the resource's read-only status has changed. */
 
201
        void readOnlyChanged(AlarmResource*);
 
202
        /** Signal that the resource's wrong alarm type status has changed. */
 
203
        void wrongAlarmTypeChanged(AlarmResource*);
 
204
        /** Signal that the resource's active status has changed. */
 
205
        void enabledChanged(AlarmResource*);
 
206
        /** Signal that the resource's location has changed. */
 
207
        void locationChanged(AlarmResource*);
 
208
        /** Signal that the resource cannot be set read-write since its format is incompatible. */
 
209
        void notWritable(AlarmResource*);
 
210
        /** Signal that the display colour has changed. */
 
211
        void colourChanged(AlarmResource*);
 
212
 
 
213
    protected:
 
214
        virtual void      doClose();
 
215
        bool              closeAfterSave() const    { return mCloseAfterSave; }
 
216
        void              setCompatibility(KAlarm::Calendar::Compat c)    { mCompatibility = c; }
 
217
        void              checkCompatibility(const QString&);
 
218
        KAlarm::Calendar::Compat checkCompatibility(KCal::CalendarLocal&, const QString& filename, FixFunc, bool* wrongType = 0);
 
219
        void              setWrongAlarmType(bool wrongType, bool emitSignal = true);
 
220
        void              updateCustomEvents(bool useCalendar = true);
 
221
        virtual void      enableResource(bool enable) = 0;
 
222
        void              lock(const QString& path);
 
223
 
 
224
        static void                     (*mCalIDFunction)(CalendarLocal&);
 
225
        static KAlarm::Calendar::Compat (*mFixFunction)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType);
 
226
 
 
227
    private:
 
228
        void        init();
 
229
 
 
230
        static int  mDebugArea;       // area for kDebug() output
 
231
        static bool mNoGui;           // application has no GUI, so don't display messages
 
232
        static void              (*mCustomEventFunction)(AlarmResource*, CalendarLocal*);
 
233
 
 
234
        KABC::Lock* mLock;
 
235
        KAlarm::CalEvent::Type mType; // type of alarm held in this resource
 
236
        QColor      mColour;          // background colour for displaying this resource
 
237
        bool        mStandard;        // this is the standard resource for this mWriteType
 
238
        bool        mNewReadOnly;     // new read-only status (while mReconfiguring = 1)
 
239
        bool        mOldReadOnly;     // old read-only status (when startReconfig() called)
 
240
        bool        mCloseAfterSave;  // resource is to be closed once save() is complete
 
241
        bool        mWrongAlarmType;  // calendar contains only alarms of the wrong type
 
242
        KAlarm::Calendar::Compat mCompatibility; // whether resource is in compatible format
 
243
 
 
244
    protected:
 
245
        typedef QMap<const KCal::Event*, KAlarm::Calendar::Compat>  CompatibilityMap;
 
246
        CompatibilityMap  mCompatibilityMap;   // whether individual events are in compatible format
 
247
        short       mReconfiguring;   // a batch of config changes is in progress
 
248
        bool        mLoaded;          // true if resource has finished loading
 
249
        bool        mLoading;         // true if resource is currently loading
 
250
 
 
251
    private:
 
252
        using KCal::ResourceCached::load;   // prevent "hidden" warning
262
253
};
263
254
 
264
255
typedef KRES::Manager<AlarmResource> AlarmResourceManager;
265
256
 
266
257
#endif
 
258
 
 
259
// vim: et sw=4: