Skip to content

Commit

Permalink
[nemo-qml-plugin-calendar] Notebook management related changes.
Browse files Browse the repository at this point in the history
 - Add calendar uid property to event. Required by qml to select notebook for saved event.
 - Fix event::realonly to return notebook readonly status where event is stored.
 - Change event:save to require notebook uid. Enables moving event to other notebook.
 - Fix missing colorChanged signal emit.
 - Add readonly role to notebook model.
 - Add localCalendar role to notebook model.
  • Loading branch information
Samuel Nevala committed Dec 10, 2013
1 parent 5225c40 commit fa290d2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-calendar-qt5.spec
Expand Up @@ -9,7 +9,7 @@ Name: nemo-qml-plugin-calendar-qt5
# << macros

Summary: Calendar plugin for Nemo Mobile
Version: 0.0.0
Version: 0.0.22
Release: 1
Group: System/Libraries
License: BSD
Expand Down
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-calendar-qt5.yaml
Expand Up @@ -3,7 +3,7 @@ Summary: Calendar plugin for Nemo Mobile
URL: https://github.com/nemomobile/nemo-qml-plugin-calendar
Group: System/Libraries
Description: "%{summary}."
Version: 0.0.0
Version: 0.0.22
Release: 1
Sources:
- "%{name}-%{version}.tar.bz2"
Expand Down
2 changes: 1 addition & 1 deletion src/calendaragendamodel.h
Expand Up @@ -64,7 +64,7 @@ class NemoCalendarAgendaModel : public QAbstractListModel, public QQmlParserStat
enum {
EventObjectRole = Qt::UserRole,
OccurrenceObjectRole,
SectionBucketRole,
SectionBucketRole
};

explicit NemoCalendarAgendaModel(QObject *parent = 0);
Expand Down
33 changes: 28 additions & 5 deletions src/calendarevent.cpp
Expand Up @@ -409,14 +409,36 @@ void NemoCalendarEvent::setAlarmProgram(const QString &program)
bool NemoCalendarEvent::readonly() const
{
QString eventNotebook = NemoCalendarDb::calendar()->notebook(mEvent);
return eventNotebook != NemoCalendarDb::storage()->defaultNotebook()->uid();
return NemoCalendarDb::storage()->notebook(eventNotebook)->isReadOnly();
}

void NemoCalendarEvent::save()
QString NemoCalendarEvent::calendarUid() const
{
if (mNewEvent) {
mNewEvent = false;
NemoCalendarDb::calendar()->addEvent(mEvent, NemoCalendarDb::storage()->defaultNotebook()->uid());
return NemoCalendarDb::calendar()->notebook(mEvent);
}

void NemoCalendarEvent::save(const QString &calendarUid)
{
QString uid = calendarUid.isEmpty() ? mNewEvent ? NemoCalendarDb::storage()->defaultNotebook()->uid()
: this->calendarUid()
: calendarUid;

mKCal::Notebook::Ptr notebook = NemoCalendarDb::storage()->notebook(uid);

if (notebook == 0) {
return;
}

if (mNewEvent || this->calendarUid() != uid) {

if (mNewEvent) {
mNewEvent = false;
} else if (this->calendarUid() != uid) {
remove();
}

NemoCalendarDb::calendar()->addEvent(mEvent, uid);
emit calendarUidChanged();
}

mEvent->setRevision(mEvent->revision() + 1);
Expand Down Expand Up @@ -489,6 +511,7 @@ void NemoCalendarEvent::setEvent(const KCalCore::Event::Ptr &event)
if (endTime() != et) emit endTimeChanged();
if (allDay() != ad) emit allDayChanged();
if (recur() != re) emit recurChanged();
emit colorChanged();
}

NemoCalendarEventOccurrence::NemoCalendarEventOccurrence(const mKCal::ExtendedCalendar::ExpandedIncidence &o,
Expand Down
5 changes: 4 additions & 1 deletion src/calendarevent.h
Expand Up @@ -58,6 +58,7 @@ class NemoCalendarEvent : public QObject
Q_PROPERTY(QString color READ color NOTIFY colorChanged)
Q_PROPERTY(QString alarmProgram READ alarmProgram WRITE setAlarmProgram NOTIFY alarmProgramChanged)
Q_PROPERTY(bool readonly READ readonly CONSTANT)
Q_PROPERTY(QString calendarUid READ calendarUid NOTIFY calendarUidChanged)

public:
enum Recur {
Expand Down Expand Up @@ -120,8 +121,9 @@ class NemoCalendarEvent : public QObject
void setAlarmProgram(const QString &);

bool readonly() const;
QString calendarUid() const;

Q_INVOKABLE void save();
Q_INVOKABLE void save(const QString &calendarUid = QString());
Q_INVOKABLE void remove();
Q_INVOKABLE QString vCalendar(const QString &prodId = QString()) const;

Expand All @@ -140,6 +142,7 @@ class NemoCalendarEvent : public QObject
void reminderChanged();
void alarmProgramChanged();
void colorChanged();
void calendarUidChanged();

private:
friend class NemoCalendarEventCache;
Expand Down
19 changes: 16 additions & 3 deletions src/calendarnotebookmodel.cpp
Expand Up @@ -42,6 +42,8 @@ NemoCalendarNotebookModel::NemoCalendarNotebookModel()
mRoleNames[DescriptionRole] = "description";
mRoleNames[ColorRole] = "color";
mRoleNames[DefaultRole] = "isDefault";
mRoleNames[ReadOnlyRole] = "readOnly";
mRoleNames[LocalCalendarRole] = "localCalendar";
}

int NemoCalendarNotebookModel::rowCount(const QModelIndex &index) const
Expand Down Expand Up @@ -70,20 +72,31 @@ QVariant NemoCalendarNotebookModel::data(const QModelIndex &index, int role) con
return NemoCalendarEventCache::instance()->notebookColor(notebook->uid());
case DefaultRole:
return notebook->isDefault();
case ReadOnlyRole:
return notebook->isReadOnly();
case LocalCalendarRole:
return (notebook->isMaster() && !notebook->isShared() && notebook->pluginName().isEmpty());
default:
return QVariant();
}
}

bool NemoCalendarNotebookModel::setData(const QModelIndex &index, const QVariant &data, int role)
{
if (!index.isValid() || index.row() >= NemoCalendarDb::storage()->notebooks().count() || role != ColorRole)
if (!index.isValid()
|| index.row() >= NemoCalendarDb::storage()->notebooks().count()
|| (role != ColorRole && role != DefaultRole))
return false;

mKCal::Notebook::Ptr notebook = NemoCalendarDb::storage()->notebooks().at(index.row());
NemoCalendarEventCache::instance()->setNotebookColor(notebook->uid(), data.toString());

emit dataChanged(index, index, QVector<int>() << role);
if (role == ColorRole) {
NemoCalendarEventCache::instance()->setNotebookColor(notebook->uid(), data.toString());
emit dataChanged(index, index, QVector<int>() << role);
} else if (role == DefaultRole) {
NemoCalendarDb::storage()->setDefaultNotebook(notebook);
emit dataChanged(this->index(0, 0), this->index(NemoCalendarDb::storage()->notebooks().count() - 1, 0), QVector<int>() << role);
}

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/calendarnotebookmodel.h
Expand Up @@ -44,7 +44,9 @@ class NemoCalendarNotebookModel : public QAbstractListModel
UidRole,
DescriptionRole,
ColorRole,
DefaultRole
DefaultRole,
ReadOnlyRole,
LocalCalendarRole
};

NemoCalendarNotebookModel();
Expand Down

0 comments on commit fa290d2

Please sign in to comment.