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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmobilityglobal.h"
#include "qtorganizer.h"
#include <QDebug>
#include <QCoreApplication>
#include <QObject>
#include <QTimer>
QTM_USE_NAMESPACE
static void snippets();
static void dumpItems(QOrganizerItemManager* manager);
static void dumpItem(const QOrganizerItem& item);
int main(int, char**)
{
snippets();
return 0;
}
void snippets()
{
//! [Instantiating the default manager for the platform]
QOrganizerItemManager defaultManager;
//! [Instantiating the default manager for the platform]
//! [Instantiating a specific manager]
QOrganizerItemManager specificManager("KCal");
//! [Instantiating a specific manager]
// XXX TODO: use rrule instead of rdates.
QDateTime startDateTime = QDateTime::currentDateTime();
QDate firstOccDate = startDateTime.date().addDays(7);
QDate secondOccDate = startDateTime.date().addDays(14);
QDate thirdOccDate = startDateTime.date().addDays(21);
QDateTime endDateTime = startDateTime.addDays(28);
QSet<QDate> rDates;
rDates << firstOccDate << secondOccDate << thirdOccDate;
//! [Creating a recurrent event]
QOrganizerEvent recEvent;
recEvent.setRecurrenceDates(rDates);
recEvent.setPriority(QOrganizerItemPriority::HighPriority);
recEvent.setLocation("Meeting Room 8");
recEvent.setDescription("A meeting every wednesday to discuss the vitally important topic of marshmallows");
recEvent.setDisplayLabel("Marshmallow Conference");
if (!defaultManager.saveItem(&recEvent))
qDebug() << "Failed to save the recurrent event; error:" << defaultManager.error();
//! [Creating a recurrent event]
//! [Retrieving occurrences of a particular recurrent event within a time period]
QList<QOrganizerItem> instances = defaultManager.itemOccurrences(recEvent, startDateTime, endDateTime);
//! [Retrieving occurrences of a particular recurrent event within a time period]
qDebug() << "dumping retrieved instances:";
foreach(const QOrganizerItem& currInst, instances)
{
dumpItem(currInst);
qDebug() << "....................";
}
//! [Retrieving the next 5 occurrences of a particular recurrent event]
instances = defaultManager.itemOccurrences(recEvent, QDateTime::currentDateTime(), QDateTime(), 5);
//! [Retrieving the next 5 occurrences of a particular recurrent event]
//! [Retrieving the next 10 occurrences of any item (Agenda View)]
// XXX TODO: make this more convenient.
// QOIM::itemOccurrences(count) ?
//! [Retrieving the next 10 occurrences of any item (Agenda View)]
//! [Creating a non-recurrent entry]
// a default constructed journal will have it's date/time set to the current date/time.
QOrganizerJournal journal;
journal.setDescription("The conference went well. We all agree that marshmallows are awesome, "\
"but we were unable to reach any agreement as to how we could possibly "\
"increase our intake of marshmallows. Several action points were assigned "\
"to various members of the group; I have been tasked with finding a good "\
"recipe that combines both marshmallows and chocolate, by next Wednesday.");
defaultManager.saveItem(&journal);
//! [Creating a non-recurrent entry]
//! [Editing a non-recurrent entry]
journal.addComment("Serves: 8. Ingredients: 500g Milk Chocolate, 500g Marshmallows. Step 1: Put the marshmallows into 8 separate bowls. Step 2: Melt the chocolate. Step 3: Pour the chocolate over the marshmallows in the bowls. Step 4: Put the bowls into the refrigerator for 20 minutes; serve chilled.");
if (!defaultManager.saveItem(&journal)) qDebug() << "Unable to save updated journal! Error:" << defaultManager.error();
//! [Editing a non-recurrent entry]
//! [Retrieving any entry (not occurrence) which matches a search criteria]
QList<QOrganizerItem> entries = defaultManager.items(QOrganizerItemLocation::match("Meeting Room 8"));
//! [Retrieving any entry (not occurrence) which matches a search criteria]
//! [Creating an exception to a particular recurrent event]
// the following line should be made simpler via QOIM::itemOccurrences(item, startDateTime, endDateTime, count)...
/* FIXME: correct the example
QOrganizerEventOccurrence nextMarshmallowMeeting = QOrganizerEventOccurrence(defaultManager.itemOccurrences().value(0)); // should use dfil.
nextMarshmallowMeeting.setStartDateTime(QDateTime::fromString("13.05.2010 18:00:00", "dd.MM.yy hh:mm:ss"));
nextMarshmallowMeeting.setEndDateTime(QDateTime::fromString("13.05.2010 20:00:00", "dd.MM.yy hh:mm:ss"));
nextMarshmallowMeeting.addComment("The next meeting will go for an hour longer (starting one "\
"hour earlier than usual), since we have scheduled one hour"\
"to taste the results of the recipe that I will be presenting "\
"at the meeting.");
defaultManager.saveItem(&nextMarshmallowMeeting);
*/
//! [Creating an exception to a particular recurrent event]
dumpItems(&defaultManager);
}
void dumpItems(QOrganizerItemManager* manager)
{
QList<QOrganizerItem> items = manager->items();
qDebug() << "dumping" << items.count() << "items:";
qDebug() << "=============================";
for (int i = 0; i < items.size(); ++i) {
QOrganizerItem curr = items.at(i);
dumpItem(curr);
if (i < (items.size() - 1)) {
qDebug() << "--------------";
}
}
qDebug() << "=============================";
}
void dumpItem(const QOrganizerItem& item)
{
qDebug() << "item:" << item.displayLabel() << ", id:" << item.id();
QList<QOrganizerItemDetail> dets = item.details();
foreach (const QOrganizerItemDetail det, dets) {
qDebug() << " new" << det.definitionName() << "detail:";
QVariantMap values = det.variantValues();
QStringList keys = values.keys();
foreach (const QString& key, keys) {
qDebug() << " " << key << "=" << values.value(key);
}
}
}
|