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 examples of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:BSD$
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21
** of its contributors may be used to endorse or promote products derived
22
** from this software without specific prior written permission.
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39
****************************************************************************/
43
#include "calendardemo.h"
45
#include <qorganizer.h>
47
QTORGANIZER_USE_NAMESPACE
49
Q_DECLARE_METATYPE(QOrganizerItem)
51
DayPage::DayPage(QWidget *parent)
58
QVBoxLayout *mainLayout = new QVBoxLayout();
60
QHBoxLayout *dateLayout = new QHBoxLayout();
61
m_dateLabel = new QLabel(this);
62
m_dateLabel->setAlignment(Qt::AlignCenter);
63
dateLayout->addWidget(m_dateLabel);
64
dateLayout->addStretch();
66
QPushButton* backButton = new QPushButton("View Month",this);
67
connect(backButton,SIGNAL(clicked()),this,SLOT(viewMonthClicked()));
68
dateLayout->addWidget(backButton);
69
mainLayout->addLayout(dateLayout);
71
m_itemList = new QListWidget(this);
72
mainLayout->addWidget(m_itemList);
73
connect(m_itemList, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(itemDoubleClicked(QListWidgetItem *)));
75
QHBoxLayout* hbLayout = new QHBoxLayout();
76
QPushButton* editEventButton = new QPushButton("Edit",this);
77
connect(editEventButton,SIGNAL(clicked()),this,SLOT(editItem()));
78
hbLayout->addWidget(editEventButton);
79
QPushButton* removeEventButton = new QPushButton("Remove",this);
80
connect(removeEventButton,SIGNAL(clicked()),this,SLOT(removeItem()));
81
hbLayout->addWidget(removeEventButton);
82
mainLayout->addLayout(hbLayout);
83
setLayout(mainLayout);
90
void DayPage::refresh()
93
m_dateLabel->setText(m_day.toString());
97
QList<QOrganizerItem> items = m_manager->items(QDateTime(m_day), QDateTime(m_day, QTime(23, 59, 59)));
99
foreach (const QOrganizerItem &item, items)
101
QOrganizerEventTime eventTime = item.detail(QOrganizerItemDetail::TypeEventTime);
102
if (!eventTime.isEmpty()) {
103
QString time = eventTime.startDateTime().time().toString("hh:mm");
104
QListWidgetItem* listItem = new QListWidgetItem();
105
if (item.type() == QOrganizerItemType::TypeEventOccurrence)
106
listItem->setText(QString("Event occurrence:%1-%2").arg(time).arg(item.displayLabel()));
108
listItem->setText(QString("Event:%1-%2").arg(time).arg(item.displayLabel()));
109
QVariant data = QVariant::fromValue<QOrganizerItem>(item);
110
listItem->setData(ORGANIZER_ITEM_ROLE, data);
111
m_itemList->addItem(listItem);
114
QOrganizerTodoTime todoTime = item.detail(QOrganizerItemDetail::TypeTodoTime);
115
if (!todoTime.isEmpty()) {
116
QString time = todoTime.startDateTime().time().toString("hh:mm");
117
QListWidgetItem* listItem = new QListWidgetItem();
118
listItem->setText(QString("Todo:%1-%2").arg(time).arg(item.displayLabel()));
119
QVariant data = QVariant::fromValue<QOrganizerItem>(item);
120
listItem->setData(ORGANIZER_ITEM_ROLE, data);
121
m_itemList->addItem(listItem);
124
QOrganizerJournalTime journalTime = item.detail(QOrganizerItemDetail::TypeJournalTime);
125
if (!journalTime.isEmpty()) {
126
QString time = journalTime.entryDateTime().time().toString("hh:mm");
127
QListWidgetItem* listItem = new QListWidgetItem();
128
listItem->setText(QString("Journal:%1-%2").arg(time).arg(item.displayLabel()));
129
QVariant data = QVariant::fromValue<QOrganizerItem>(item);
130
listItem->setData(ORGANIZER_ITEM_ROLE, data);
131
m_itemList->addItem(listItem);
134
// TODO: other item types
137
if (m_itemList->count() == 0)
138
m_itemList->addItem("(no entries)");
141
void DayPage::changeManager(QOrganizerManager *manager)
146
void DayPage::dayChanged(QDate date)
151
void DayPage::itemDoubleClicked(QListWidgetItem *listItem)
156
QOrganizerItem organizerItem = listItem->data(ORGANIZER_ITEM_ROLE).value<QOrganizerItem>();
157
if (!organizerItem.isEmpty())
158
emit showEditPage(organizerItem);
161
void DayPage::viewMonthClicked()
163
emit showMonthPage();
166
void DayPage::editItem()
168
QListWidgetItem *listItem = m_itemList->currentItem();
172
QOrganizerItem organizerItem = listItem->data(ORGANIZER_ITEM_ROLE).value<QOrganizerItem>();
173
if (!organizerItem.isEmpty())
174
emit showEditPage(organizerItem);
177
void DayPage::removeItem()
179
QListWidgetItem *listItem = m_itemList->currentItem();
183
QOrganizerItem organizerItem = listItem->data(ORGANIZER_ITEM_ROLE).value<QOrganizerItem>();
184
if (organizerItem.isEmpty())
187
if (organizerItem.type() == QOrganizerItemType::TypeEventOccurrence
188
|| organizerItem.type() == QOrganizerItemType::TypeTodoOccurrence) {
189
// Here we could ask if the user wishes to remove only the occurrence (meaning we would
190
// add an exception date to the parent item), or the parent item. The current
191
// implementation is to remove the parent (including all the occurrences).
192
m_manager->removeItem(organizerItem.detail(QOrganizerItemDetail::TypeParent).value<QOrganizerItemId>(QOrganizerItemParent::FieldParentId));
194
m_manager->removeItem(organizerItem.id());
197
if (m_manager->error())
198
QMessageBox::information(this, "Failed!", QString("Failed to remove item!\n(error code %1)").arg(m_manager->error()));
200
delete m_itemList->takeItem(m_itemList->currentRow());
202
if (m_itemList->count() == 0)
203
m_itemList->addItem("(no entries)");
206
void DayPage::showEvent(QShowEvent *event)
208
window()->setWindowTitle(m_day.toString("dddd"));
209
QWidget::showEvent(event);