EventViewer.cpp Example File
calendar/src/EventViewer.cpp
#include "EventViewer.hpp"
#include <bb/pim/calendar/CalendarEvent>
#include <bb/pim/calendar/EventRefresh>
#include <bb/pim/calendar/EventSearchParameters>
using namespace bb::pim::calendar;
EventViewer::EventViewer(CalendarService *service, QObject *parent)
: QObject(parent)
, m_calendarService(service)
{
bool ok = connect(m_calendarService, SIGNAL(eventsRefreshed(bb::pim::calendar::EventRefresh)), SLOT(eventsChanged(bb::pim::calendar::EventRefresh)));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
void EventViewer::setEventKey(const EventKey &eventKey)
{
if (m_eventKey.eventId() == eventKey.eventId() &&
m_eventKey.accountId() == eventKey.accountId())
return;
m_eventKey = eventKey;
updateEvent();
}
void EventViewer::eventsChanged(const EventRefresh &refresh)
{
if (refresh.account() == m_eventKey.accountId()) {
if (refresh.updatedEventIds().contains(m_eventKey.eventId()))
updateEvent();
}
}
QString EventViewer::subject() const
{
return m_subject;
}
QString EventViewer::location() const
{
return m_location;
}
QString EventViewer::startTime() const
{
if (!m_startTime.isValid())
return tr("n/a");
else
return m_startTime.toString();
}
QString EventViewer::endTime() const
{
if (!m_endTime.isValid())
return tr("n/a");
else
return m_endTime.toString();
}
void EventViewer::updateEvent()
{
const QString oldSubject = m_subject;
const QString oldLocation = m_location;
const QDateTime oldStartTime = m_startTime;
const QDateTime oldEndTime = m_endTime;
const CalendarEvent event = m_calendarService->event(m_eventKey.accountId(), m_eventKey.eventId());
m_subject = event.subject();
m_location = event.location();
m_startTime = event.startTime();
m_endTime = event.endTime();
if (oldSubject != m_subject)
emit subjectChanged();
if (oldLocation != m_location)
emit locationChanged();
if (oldStartTime != m_startTime)
emit startTimeChanged();
if (oldEndTime != m_endTime)
emit endTimeChanged();
}