~ubuntu-branches/ubuntu/lucid/kdepim-runtime/lucid

« back to all changes in this revision

Viewing changes to resources/ical/icalresourcebase.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-12-03 15:38:40 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20091203153840-x5fxfsfby0czyqu6
Tags: 4:4.3.80-0ubuntu1
* New upstream beta release:
  - Refresh all patches
  - Bump build-depend versions
  - Remove build-depend on libknotificationitem-dev, it's part of
    kdelibs5-dev now
  - Add build-depend on shared-desktop-ontologies for nepomuk support
  - Add build-depend on libstreamanalyzer-dev for strigi support
  - Add build-depend on libx11-dev to prevent FTBFS
  - Update various .install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2006 Till Adam <adam@kde.org>
 
3
    Copyright (c) 2009 David Jarvie <djarvie@kde.org>
 
4
 
 
5
    This library is free software; you can redistribute it and/or modify it
 
6
    under the terms of the GNU Library General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or (at your
 
8
    option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful, but WITHOUT
 
11
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
13
    License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to the
 
17
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
    02110-1301, USA.
 
19
*/
 
20
 
 
21
#ifndef ICALRESOURCEBASE_H
 
22
#define ICALRESOURCEBASE_H
 
23
 
 
24
#include "singlefileresource.h"
 
25
#include "settings.h"
 
26
 
 
27
namespace KCal {
 
28
  class CalendarLocal;
 
29
}
 
30
 
 
31
class ICalResourceBase : public Akonadi::SingleFileResource<Settings>
 
32
{
 
33
  Q_OBJECT
 
34
 
 
35
  public:
 
36
    /**
 
37
     * @param fileTypeDescription filter descriptor for the calendar file type,
 
38
     *                            to display for the '*.ics *.ical' filter.
 
39
     */
 
40
    ICalResourceBase( const QString &id, const QString &fileTypeDescription );
 
41
    ~ICalResourceBase();
 
42
 
 
43
  public Q_SLOTS:
 
44
    virtual void configure( WId windowId );
 
45
 
 
46
  protected Q_SLOTS:
 
47
    bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
 
48
    void retrieveItems( const Akonadi::Collection &col );
 
49
 
 
50
  protected:
 
51
    enum CheckType { CheckForAdded, CheckForChanged };
 
52
 
 
53
    void initialise( const QStringList &mimeTypes, const QString &icon );
 
54
    bool readFromFile( const QString &fileName );
 
55
    bool writeToFile( const QString &fileName );
 
56
    virtual void aboutToQuit();
 
57
 
 
58
    /**
 
59
     * Retrieve an incidence from the calendar, and set it into a new item's payload.
 
60
     * Retrieval of the item should be signalled by calling @p itemRetrieved().
 
61
     * @param item the incidence ID to retrieve is provided by @c item.remoteId()
 
62
     * @return true if item retrieved, false if not.
 
63
     */
 
64
    virtual bool doRetrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0;
 
65
 
 
66
    /**
 
67
     * Retrieve all incidences from the calendar, and set each into a new item's payload.
 
68
     * Retrieval of the items should be signalled by calling @p itemsRetrieved().
 
69
     */
 
70
    virtual void doRetrieveItems( const Akonadi::Collection &col ) = 0;
 
71
 
 
72
    /**
 
73
     * To be called at the start of derived class implementations of itemAdded()
 
74
     * or itemChanged() to verify that required conditions are true.
 
75
     * @param type the type of change to perform the checks for.
 
76
     * @return true if all checks are successful, and processing can continue;
 
77
     *         false if a check failed, in which case itemAdded() or itemChanged()
 
78
     *               should stop processing.
 
79
     */
 
80
    template <typename PayloadPtr> bool checkItemAddedChanged( const Akonadi::Item &item, CheckType type );
 
81
 
 
82
    virtual void itemRemoved( const Akonadi::Item &item );
 
83
 
 
84
    /** Return the local calendar. */
 
85
    KCal::CalendarLocal *calendar() const;
 
86
 
 
87
  private:
 
88
    KCal::CalendarLocal *mCalendar;
 
89
    const QString mFileDescription;
 
90
};
 
91
 
 
92
template <typename PayloadPtr>
 
93
bool ICalResourceBase::checkItemAddedChanged( const Akonadi::Item &item, CheckType type )
 
94
{
 
95
  if ( !mCalendar ) {
 
96
    cancelTask( i18n("Calendar not loaded.") );
 
97
    return false;
 
98
  }
 
99
  if ( !item.hasPayload<PayloadPtr>() ) {
 
100
    QString msg = (type == CheckForAdded)
 
101
                          ? i18n("Unable to retrieve added item %1.", item.id() )
 
102
                          : i18n("Unable to retrieve modified item %1.", item.id() );
 
103
    cancelTask( msg.arg( item.id() ) );
 
104
    return false;
 
105
  }
 
106
  return true;
 
107
}
 
108
 
 
109
#endif