NoteViewer.cpp Example File
notebook/src/NoteViewer.cpp
#include "NoteViewer.hpp"
#include <bb/pim/notebook/NotebookEntry>
using namespace bb::pim::notebook;
NoteViewer::NoteViewer(NotebookService *service, QObject *parent)
: QObject(parent)
, m_notebookService(service)
, m_status(NotebookEntryStatus::NotCompleted)
{
bool ok = connect(m_notebookService, SIGNAL(notebookEntriesUpdated(QList<bb::pim::notebook::NotebookEntryId>)), SLOT(noteChanged(QList<bb::pim::notebook::NotebookEntryId>)));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
QString NoteViewer::statusToString(NotebookEntryStatus::Type status)
{
switch (status) {
case NotebookEntryStatus::NotActionable:
return tr("Not actionable");
case NotebookEntryStatus::NotCompleted:
return tr("Not completed");
case NotebookEntryStatus::Completed:
return tr("Completed");
}
return QString();
}
void NoteViewer::updateNote()
{
const QString oldTitle = m_title;
const QString oldDescription = m_description;
const QDateTime oldDueDateTime = m_dueDateTime;
const NotebookEntryStatus::Type oldStatus = m_status;
const NotebookEntry note = m_notebookService->notebookEntry(m_noteId);
m_title = note.title();
m_description = note.description().plainText();
m_dueDateTime = note.dueDateTime();
m_status = note.status();
if (oldTitle != m_title)
emit titleChanged();
if (oldDescription != m_description)
emit descriptionChanged();
if (oldDueDateTime != m_dueDateTime)
emit dueDateTimeChanged();
if (oldStatus != m_status)
emit statusChanged();
}
void NoteViewer::noteChanged(const QList<NotebookEntryId> &entries)
{
if (entries.contains(m_noteId))
updateNote();
}
void NoteViewer::setNoteId(const NotebookEntryId ¬eId)
{
m_noteId = noteId;
updateNote();
}
QString NoteViewer::title() const
{
return m_title;
}
QString NoteViewer::description() const
{
return m_description;
}
QString NoteViewer::dueDateTime() const
{
if (!m_dueDateTime.isValid())
return tr("n/a");
else
return m_dueDateTime.date().toString();
}
QString NoteViewer::status() const
{
return statusToString(m_status);
}