-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathfahrplan_calendar_manager.h
101 lines (81 loc) · 3.14 KB
/
fahrplan_calendar_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/****************************************************************************
**
** This file is a part of Fahrplan.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef FAHRPLAN_CALENDAR_MANAGER_H
#define FAHRPLAN_CALENDAR_MANAGER_H
#include <QAbstractListModel>
#if !defined(BUILD_FOR_BLACKBERRY) && !defined(BUILD_FOR_SAILFISHOS) && !defined(BUILD_FOR_DESKTOP) && !defined(BUILD_FOR_UBUNTU)
# include <QOrganizerCollectionId>
QTM_USE_NAMESPACE
#endif
struct CalendarInfo
{
QString name;
#ifdef BUILD_FOR_BLACKBERRY
int accountId;
int folderId;
CalendarInfo(const QString &name, int accountId = -1, int folderId = -1)
: name(name), accountId(accountId), folderId(folderId) {}
#elif defined(BUILD_FOR_SAILFISHOS) && defined(BUILD_FOR_OPENREPOS)
QString notebookUID;
CalendarInfo(const QString &name, const QString ¬ebookUID = QString())
: name(name), notebookUID(notebookUID) {}
#else
QString collectionId;
CalendarInfo(const QString &name, const QString &collectionId = QString())
: name(name), collectionId(collectionId) {}
#endif
};
class QSettings;
#ifndef QT_NO_CONCURRENT
template <typename T>
class QFutureWatcher;
#endif
class FahrplanCalendarManager: public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged)
Q_PROPERTY(QString selectedCalendarName READ selectedCalendarName NOTIFY selectedCalendarNameChanged)
public:
explicit FahrplanCalendarManager(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QHash<int, QByteArray> roleNames() const;
int count() const;
int selectedIndex() const;
void setSelectedIndex(int index);
QString selectedCalendarName() const;
Q_INVOKABLE void reload();
signals:
void countChanged();
void selectedIndexChanged();
void selectedCalendarNameChanged();
private:
QSettings *settings;
#ifndef QT_NO_CONCURRENT
QFutureWatcher<void> *m_watcher;
#endif
QList<CalendarInfo> m_calendars;
int m_selectedIndex;
void getCalendarsList();
QString normalizeCalendarName(QString name);
private slots:
void getCalendarsListFinished();
};
#endif // FAHRPLAN_CALENDAR_MANAGER_H