Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'omp-jb-15386-dev-accept-invitations' into 'master'
[nemo-qml-plugin-calendar] Changes for accept invitation from email. Contributes to JB#15386

See merge request !19
  • Loading branch information
jpetrell committed Mar 1, 2018
2 parents dcf610f + e56894b commit 95f8cfb
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/calendardata.h
Expand Up @@ -37,6 +37,7 @@ struct Event {
KDateTime recurrenceId;
bool readonly;
QString location;
NemoCalendarEvent::Secrecy secrecy;
QString calendarUid;

bool operator==(const Event& other) const
Expand Down
5 changes: 5 additions & 0 deletions src/calendarevent.cpp
Expand Up @@ -122,6 +122,11 @@ QString NemoCalendarEvent::location() const
return mManager->getEvent(mUniqueId, mRecurrenceId).location;
}

NemoCalendarEvent::Secrecy NemoCalendarEvent::secrecy() const
{
return mManager->getEvent(mUniqueId, mRecurrenceId).secrecy;
}

KDateTime NemoCalendarEvent::recurrenceId() const
{
return mRecurrenceId;
Expand Down
18 changes: 18 additions & 0 deletions src/calendarevent.h
Expand Up @@ -46,6 +46,8 @@ class NemoCalendarEvent : public QObject
Q_ENUMS(Recur)
Q_ENUMS(Reminder)
Q_ENUMS(TimeSpec)
Q_ENUMS(Secrecy)
Q_ENUMS(Response)

Q_PROPERTY(QString displayLabel READ displayLabel NOTIFY displayLabelChanged)
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
Expand All @@ -62,6 +64,7 @@ class NemoCalendarEvent : public QObject
Q_PROPERTY(bool readonly READ readonly CONSTANT)
Q_PROPERTY(QString calendarUid READ calendarUid NOTIFY calendarUidChanged)
Q_PROPERTY(QString location READ location NOTIFY locationChanged)
Q_PROPERTY(Secrecy secrecy READ secrecy NOTIFY secrecyChanged)

public:
enum Recur {
Expand Down Expand Up @@ -91,6 +94,19 @@ class NemoCalendarEvent : public QObject
SpecClockTime
};

enum Secrecy {
SecrecyPublic,
SecrecyPrivate,
SecrecyConfidential
};

enum Response {
ResponseUnspecified,
ResponseAccept,
ResponseTentative,
ResponseDecline
};

NemoCalendarEvent(NemoCalendarManager *manager, const QString &uid, const KDateTime &recurrenceId);
~NemoCalendarEvent();

Expand All @@ -110,6 +126,7 @@ class NemoCalendarEvent : public QObject
QString location() const;
KDateTime recurrenceId() const;
QString recurrenceIdString() const;
Secrecy secrecy() const;

Q_INVOKABLE QString vCalendar(const QString &prodId = QString()) const;

Expand All @@ -131,6 +148,7 @@ private slots:
void locationChanged();
void recurEndDateChanged();
void hasRecurEndDateChanged();
void secrecyChanged();

private:
NemoCalendarManager *mManager;
Expand Down
32 changes: 32 additions & 0 deletions src/calendarimportevent.cpp
Expand Up @@ -98,6 +98,14 @@ NemoCalendarEvent::Reminder CalendarImportEvent::reminder() const
return NemoCalendarUtils::getReminder(mEvent);
}

int CalendarImportEvent::reminderSeconds() const
{
if (!mEvent)
return 0;

return NemoCalendarUtils::getReminderSeconds(mEvent);
}

QString CalendarImportEvent::uniqueId() const
{
if (!mEvent)
Expand Down Expand Up @@ -127,6 +135,30 @@ QList<QObject *> CalendarImportEvent::attendees() const
return NemoCalendarUtils::convertAttendeeList(NemoCalendarUtils::getEventAttendees(mEvent));
}

NemoCalendarEvent::Secrecy CalendarImportEvent::secrecy() const
{
if (!mEvent)
return NemoCalendarEvent::SecrecyPublic;

return NemoCalendarUtils::convertSecrecy(mEvent);
}

QString CalendarImportEvent::organizer() const
{
if (!mEvent || !mEvent->organizer())
return QString();

return mEvent->organizer()->fullName();
}

QString CalendarImportEvent::organizerEmail() const
{
if (!mEvent || !mEvent->organizer())
return QString();

return mEvent->organizer()->email();
}

void CalendarImportEvent::setColor(const QString &color)
{
if (mColor == color)
Expand Down
8 changes: 8 additions & 0 deletions src/calendarimportevent.h
Expand Up @@ -49,11 +49,15 @@ class CalendarImportEvent : public QObject
Q_PROPERTY(QDateTime endTime READ endTime CONSTANT)
Q_PROPERTY(bool allDay READ allDay CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Recur recur READ recur CONSTANT)
Q_PROPERTY(int reminderSeconds READ reminderSeconds CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Reminder reminder READ reminder CONSTANT)
Q_PROPERTY(QString uniqueId READ uniqueId CONSTANT)
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QString location READ location CONSTANT)
Q_PROPERTY(QList<QObject*> attendees READ attendees CONSTANT)
Q_PROPERTY(QString organizer READ organizer CONSTANT)
Q_PROPERTY(QString organizerEmail READ organizerEmail CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Secrecy secrecy READ secrecy CONSTANT)

public:
CalendarImportEvent(KCalCore::Event::Ptr event);
Expand All @@ -64,11 +68,15 @@ class CalendarImportEvent : public QObject
QDateTime endTime() const;
bool allDay() const;
NemoCalendarEvent::Recur recur();
int reminderSeconds() const;
NemoCalendarEvent::Reminder reminder() const;
QString uniqueId() const;
QString color() const;
QString location() const;
QList<QObject*> attendees() const;
NemoCalendarEvent::Secrecy secrecy() const;
QString organizer() const;
QString organizerEmail() const;

void setColor(const QString &color);

Expand Down
45 changes: 35 additions & 10 deletions src/calendarimportmodel.cpp
Expand Up @@ -71,14 +71,23 @@ void NemoCalendarImportModel::setFileName(const QString &fileName)

mFileName = fileName;
emit fileNameChanged();
if (!mFileName.isEmpty()) {
importToMemory(fileName);
} else if (!mEventList.isEmpty()) {
beginResetModel();
mEventList.clear();
endResetModel();
emit countChanged();
}
reload();
}

QString NemoCalendarImportModel::icsUtf8RawString() const
{
return QString::fromUtf8(mIcsRawData);
}

void NemoCalendarImportModel::setIcsUtf8RawString(const QString &icsData)
{
QByteArray data = icsData.toUtf8();
if (mIcsRawData == data)
return;

mIcsRawData = data;
emit icsUtf8RawStringChanged();
reload();
}

QObject *NemoCalendarImportModel::getEvent(int index)
Expand Down Expand Up @@ -184,14 +193,30 @@ static bool incidenceLessThan(const KCalCore::Incidence::Ptr e1,
}
}

bool NemoCalendarImportModel::importToMemory(const QString &fileName)
void NemoCalendarImportModel::reload()
{
if (!mFileName.isEmpty() || !mIcsRawData.isEmpty()) {
importToMemory(mFileName, mIcsRawData);
} else if (!mEventList.isEmpty()) {
beginResetModel();
mEventList.clear();
endResetModel();
emit countChanged();
}
}

bool NemoCalendarImportModel::importToMemory(const QString &fileName, const QByteArray &icsData)
{
if (!mEventList.isEmpty())
mEventList.clear();

beginResetModel();
KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(KDateTime::Spec::LocalZone()));
NemoCalendarUtils::importFromFile(fileName, cal);
if (!fileName.isEmpty()) {
NemoCalendarUtils::importFromFile(fileName, cal);
} else {
NemoCalendarUtils::importFromIcsRawData(icsData, cal);
}
KCalCore::Incidence::List incidenceList = cal->incidences();
for (int i = 0; i < incidenceList.size(); i++) {
KCalCore::Incidence::Ptr incidence = incidenceList.at(i);
Expand Down
9 changes: 8 additions & 1 deletion src/calendarimportmodel.h
Expand Up @@ -43,6 +43,7 @@ class NemoCalendarImportModel : public QAbstractListModel
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
Q_PROPERTY(QString icsUtf8RawString READ icsUtf8RawString WRITE setIcsUtf8RawString NOTIFY icsUtf8RawStringChanged)

public:
enum {
Expand All @@ -63,6 +64,9 @@ class NemoCalendarImportModel : public QAbstractListModel
QString fileName() const;
void setFileName(const QString& fileName);

QString icsUtf8RawString() const;
void setIcsUtf8RawString(const QString &icsData);

virtual int rowCount(const QModelIndex &index) const;
virtual QVariant data(const QModelIndex &index, int role) const;

Expand All @@ -72,6 +76,7 @@ public slots:
signals:
void countChanged();
void fileNameChanged();
void icsUtf8RawStringChanged();

public slots:
bool importToNotebook(const QString &notebookUid = QString());
Expand All @@ -80,9 +85,11 @@ public slots:
virtual QHash<int, QByteArray> roleNames() const;

private:
bool importToMemory(const QString &fileName);
void reload();
bool importToMemory(const QString &fileName, const QByteArray &icsData);

QString mFileName;
QByteArray mIcsRawData;
KCalCore::Event::List mEventList;
};

Expand Down
3 changes: 3 additions & 0 deletions src/calendarmanager.cpp
Expand Up @@ -752,6 +752,9 @@ void NemoCalendarManager::sendEventChangeSignals(const NemoCalendarData::Event &
if (newEvent.location != oldEvent.location)
emit eventObject->locationChanged();

if (newEvent.secrecy != oldEvent.secrecy)
emit eventObject->secrecyChanged();

if (newEvent.recur != oldEvent.recur)
emit eventObject->recurChanged();

Expand Down
35 changes: 33 additions & 2 deletions src/calendarutils.cpp
Expand Up @@ -70,7 +70,21 @@ NemoCalendarEvent::Recur NemoCalendarUtils::convertRecurrence(const KCalCore::Ev
return NemoCalendarEvent::RecurCustom;
}

NemoCalendarEvent::Reminder NemoCalendarUtils::getReminder(const KCalCore::Event::Ptr &event)
NemoCalendarEvent::Secrecy NemoCalendarUtils::convertSecrecy(const KCalCore::Event::Ptr &event)
{
KCalCore::Incidence::Secrecy s = event->secrecy();
switch (s) {
case KCalCore::Incidence::SecrecyPrivate:
return NemoCalendarEvent::SecrecyPrivate;
case KCalCore::Incidence::SecrecyConfidential:
return NemoCalendarEvent::SecrecyConfidential;
case KCalCore::Incidence::SecrecyPublic:
default:
return NemoCalendarEvent::SecrecyPublic;
}
}

int NemoCalendarUtils::getReminderSeconds(const KCalCore::Event::Ptr &event)
{
KCalCore::Alarm::List alarms = event->alarms();

Expand All @@ -90,7 +104,12 @@ NemoCalendarEvent::Reminder NemoCalendarUtils::getReminder(const KCalCore::Event
return NemoCalendarEvent::ReminderNone;

KCalCore::Duration d = alarm->startOffset();
int sec = d.asSeconds();
return d.asSeconds();
}

NemoCalendarEvent::Reminder NemoCalendarUtils::getReminder(const KCalCore::Event::Ptr &event)
{
int sec = getReminderSeconds(event);

switch (sec) {
case 0:
Expand Down Expand Up @@ -229,3 +248,15 @@ bool NemoCalendarUtils::importFromFile(const QString &fileName,

return ok;
}

bool NemoCalendarUtils::importFromIcsRawData(const QByteArray &icsData,
KCalCore::Calendar::Ptr calendar)
{
bool ok = false;
KCalCore::ICalFormat icalFormat;
ok = icalFormat.fromRawString(calendar, icsData);
if (!ok)
qWarning() << "Failed to import from raw data";

return ok;
}
3 changes: 3 additions & 0 deletions src/calendarutils.h
Expand Up @@ -43,12 +43,15 @@
namespace NemoCalendarUtils {

NemoCalendarEvent::Recur convertRecurrence(const KCalCore::Event::Ptr &event);
NemoCalendarEvent::Secrecy convertSecrecy(const KCalCore::Event::Ptr &event);
int getReminderSeconds(const KCalCore::Event::Ptr &event);
NemoCalendarEvent::Reminder getReminder(const KCalCore::Event::Ptr &event);
QList<NemoCalendarData::Attendee> getEventAttendees(const KCalCore::Event::Ptr &event);
QList<QObject*> convertAttendeeList(const QList<NemoCalendarData::Attendee> &list);
NemoCalendarData::EventOccurrence getNextOccurrence(const KCalCore::Event::Ptr &event,
const QDateTime &start = QDateTime::currentDateTime());
bool importFromFile(const QString &fileName, KCalCore::Calendar::Ptr calendar);
bool importFromIcsRawData(const QByteArray &icsData, KCalCore::Calendar::Ptr calendar);

} // namespace NemoCalendarUtils

Expand Down
1 change: 1 addition & 0 deletions src/calendarworker.cpp
Expand Up @@ -613,6 +613,7 @@ NemoCalendarData::Event NemoCalendarWorker::createEventStruct(const KCalCore::Ev
event.displayLabel = e->summary();
event.endTime = e->dtEnd();
event.location = e->location();
event.secrecy = NemoCalendarUtils::convertSecrecy(e);
event.readonly = mStorage->notebook(event.calendarUid)->isReadOnly();
event.recur = NemoCalendarUtils::convertRecurrence(e);
KCalCore::RecurrenceRule *defaultRule = e->recurrence()->defaultRRule();
Expand Down

0 comments on commit 95f8cfb

Please sign in to comment.