1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the Qt Mobility Components.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include "qmobilityglobal.h"
43
#include "qtorganizer.h"
46
#include <QCoreApplication>
52
static void snippets();
53
static void dumpItems(QOrganizerManager* manager);
54
static void dumpItem(const QOrganizerItem& item);
64
//! [Instantiating the default manager for the platform]
65
QOrganizerManager defaultManager;
66
//! [Instantiating the default manager for the platform]
68
//! [Instantiating a specific manager]
69
QOrganizerManager specificManager("KCal");
70
//! [Instantiating a specific manager]
72
// XXX TODO: use rrule instead of rdates.
73
QDateTime startDateTime = QDateTime::currentDateTime();
74
QDate firstOccDate = startDateTime.date().addDays(7);
75
QDate secondOccDate = startDateTime.date().addDays(14);
76
QDate thirdOccDate = startDateTime.date().addDays(21);
77
QDateTime endDateTime = startDateTime.addDays(28);
79
rDates << firstOccDate << secondOccDate << thirdOccDate;
81
//! [Creating a recurrent event]
82
QOrganizerEvent marshmallowMeeting;
83
marshmallowMeeting.setRecurrenceDates(rDates);
84
marshmallowMeeting.setPriority(QOrganizerItemPriority::HighPriority);
85
marshmallowMeeting.setLocation("Meeting Room 8");
86
marshmallowMeeting.setDescription("A meeting every wednesday to discuss the vitally important topic of marshmallows");
87
marshmallowMeeting.setDisplayLabel("Marshmallow Conference");
88
if (!defaultManager.saveItem(&marshmallowMeeting))
89
qDebug() << "Failed to save the recurrent event; error:" << defaultManager.error();
90
//! [Creating a recurrent event]
92
//! [Retrieving occurrences of a particular recurrent event within a time period]
93
QList<QOrganizerItem> instances = defaultManager.itemOccurrences(marshmallowMeeting, startDateTime, endDateTime);
94
//! [Retrieving occurrences of a particular recurrent event within a time period]
95
qDebug() << "dumping retrieved instances:";
96
foreach (const QOrganizerItem& currInst, instances)
99
qDebug() << "....................";
103
//! [Retrieving the next 5 occurrences of a particular recurrent event]
104
instances = defaultManager.itemOccurrences(marshmallowMeeting, QDateTime::currentDateTime(), QDateTime(), 5);
105
//! [Retrieving the next 5 occurrences of a particular recurrent event]
107
//! [Retrieving the next 10 occurrences of any item (Agenda View)]
108
instances = defaultManager.items(QDateTime::currentDateTime(), QDateTime());
109
instances = instances.mid(0, 10);
110
//! [Retrieving the next 10 occurrences of any item (Agenda View)]
112
//! [Creating a non-recurrent entry]
113
// a default constructed journal will have it's date/time set to the current date/time.
114
QOrganizerJournal journal;
115
journal.setDescription("The conference went well. We all agree that marshmallows are awesome, "\
116
"but we were unable to reach any agreement as to how we could possibly "\
117
"increase our intake of marshmallows. Several action points were assigned "\
118
"to various members of the group; I have been tasked with finding a good "\
119
"recipe that combines both marshmallows and chocolate, by next Wednesday.");
120
defaultManager.saveItem(&journal);
121
//! [Creating a non-recurrent entry]
123
//! [Editing a non-recurrent entry]
124
journal.addComment("Serves: 8. Ingredients: 500g Milk Chocolate, 500g Marshmallows."\
125
" Step 1: Put the marshmallows into 8 separate bowls."\
126
" Step 2: Melt the chocolate."\
127
" Step 3: Pour the chocolate over the marshmallows in the bowls."\
128
" Step 4: Put the bowls into the refrigerator for 20 minutes; serve chilled.");
129
if (!defaultManager.saveItem(&journal))
130
qDebug() << "Unable to save updated journal! Error:" << defaultManager.error();
131
//! [Editing a non-recurrent entry]
133
//! [Removing an entry]
134
defaultManager.removeItem(journal.id());
135
//! [Removing an entry]
137
//! [Retrieving entries for a time period]
138
QList<QOrganizerItem> entries =
139
defaultManager.items(QDateTime(QDate(2010, 1, 1), QTime(0, 0, 0)),
140
QDateTime(QDate(2010, 1, 31), QTime(23, 59, 59)));
141
//! [Retrieving entries for a time period]
143
//! [Retrieving entries with a filter]
144
entries = defaultManager.items(QOrganizerItemLocation::match("Meeting Room 8"));
145
//! [Retrieving entries with a filter]
147
//! [Downcasting items]
148
QList<QOrganizerItem> items = defaultManager.items();
149
foreach (QOrganizerItem item, entries) {
150
if (item.type() == QOrganizerItemType::TypeEvent) {
151
QOrganizerEvent event(item);
152
qDebug() << "Event:" << event.startDateTime() << ", " << event.displayLabel();
153
} else if (item.type() == QOrganizerItemType::TypeEventOccurrence) {
154
QOrganizerEventOccurrence event(item);
155
qDebug() << "Event:" << event.startDateTime() << ", " << event.displayLabel();
156
} else if (item.type() == QOrganizerItemType::TypeTodo) {
158
} else if (item.type() == QOrganizerItemType::TypeTodoOccurrence) {
159
// process recurring todos
160
} else if (item.type() == QOrganizerItemType::TypeJournal) {
162
} else if (item.type() == QOrganizerItemType::TypeNote) {
166
//! [Downcasting items]
168
//! [Creating an exception to a particular recurrent event]
169
QOrganizerEventOccurrence nextMarshmallowMeeting = defaultManager.itemOccurrences(marshmallowMeeting).value(0);
170
nextMarshmallowMeeting.setStartDateTime(QDateTime::fromString("13.05.2010 18:00:00", "dd.MM.yy hh:mm:ss"));
171
nextMarshmallowMeeting.setEndDateTime(QDateTime::fromString("13.05.2010 20:00:00", "dd.MM.yy hh:mm:ss"));
172
nextMarshmallowMeeting.addComment("The next meeting will go for an hour longer (starting one "\
173
"hour earlier than usual), since we have scheduled one hour"\
174
"to taste the results of the recipe that I will be presenting "\
176
defaultManager.saveItem(&nextMarshmallowMeeting);
177
//! [Creating an exception to a particular recurrent event]
179
//! [Getting a list of collections]
180
QList<QOrganizerCollection> collections = defaultManager.collections();
181
//! [Getting a list of collections]
183
QOrganizerCollection collection = collections.first();
185
//! [Saving an item to a collection]
186
marshmallowMeeting.setCollectionId(collection.id());
187
defaultManager.saveItem(&marshmallowMeeting);
188
//! [Saving an item to a collection]
190
//! [Retrieving items in a collection]
191
QOrganizerItemCollectionFilter collectionFilter;
192
collectionFilter.setCollectionId(collection.id());
193
items = defaultManager.items(collectionFilter);
194
//! [Retrieving items in a collection]
196
dumpItems(&defaultManager);
199
void dumpItems(QOrganizerManager* manager)
201
QList<QOrganizerItem> items = manager->items();
202
qDebug() << "dumping" << items.count() << "items:";
203
qDebug() << "=============================";
204
for (int i = 0; i < items.size(); ++i) {
205
QOrganizerItem curr = items.at(i);
207
if (i < (items.size() - 1)) {
208
qDebug() << "--------------";
211
qDebug() << "=============================";
214
void dumpItem(const QOrganizerItem& item)
216
qDebug() << "item:" << item.displayLabel() << ", id:" << item.id();
217
QList<QOrganizerItemDetail> dets = item.details();
218
foreach (const QOrganizerItemDetail det, dets) {
219
qDebug() << " new" << det.definitionName() << "detail:";
220
QVariantMap values = det.variantValues();
221
QStringList keys = values.keys();
222
foreach (const QString& key, keys) {
223
qDebug() << " " << key << "=" << values.value(key);