Skip to content

Commit

Permalink
[nemo-qml-plugin-calendar] Expose notebook account information. Fixes…
Browse files Browse the repository at this point in the history
… MER#887

Some notebooks are associated with particular accounts (ie, synced).
This commit exposes this account information (id and icon) in the
notebook data so that it can be displayed in the UI if required.

Fixes MER#887
  • Loading branch information
Chris Adams committed Apr 13, 2015
1 parent fa78c2e commit 511b8b2
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lightweight/calendardataservice/calendardataservice.pro
Expand Up @@ -6,7 +6,7 @@ QT += qml dbus
QT -= gui

CONFIG += link_pkgconfig
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical accounts-qt5

HEADERS += \
calendardataservice.h \
Expand Down
1 change: 1 addition & 0 deletions rpm/nemo-qml-plugin-calendar-qt5.spec
Expand Up @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(Qt5Concurrent)
BuildRequires: pkgconfig(libmkcal-qt5)
BuildRequires: pkgconfig(libkcalcoren-qt5)
BuildRequires: pkgconfig(libical)
BuildRequires: pkgconfig(accounts-qt5)

%description
%{summary}.
Expand Down
10 changes: 7 additions & 3 deletions src/calendardata.h
Expand Up @@ -2,6 +2,7 @@
#define NEMOCALENDARDATA_H

#include <QString>
#include <QUrl>

// KCalCore
#include <attendee.h>
Expand Down Expand Up @@ -54,18 +55,21 @@ struct Notebook {
QString uid;
QString description;
QString color;
int accountId;
QUrl accountIcon;
bool isDefault;
bool readOnly;
bool localCalendar;
bool excluded;

Notebook() : isDefault(false), readOnly(false), localCalendar(false), excluded(false) { }
Notebook() : accountId(0), isDefault(false), readOnly(false), localCalendar(false), excluded(false) { }

bool operator==(const Notebook other) const
{
return uid == other.uid && name == other.name && description == other.description &&
color == other.color && isDefault == other.isDefault && readOnly == other.readOnly &&
localCalendar == other.localCalendar && excluded == other.excluded;
color == other.color && accountId == other.accountId && accountIcon == other.accountIcon &&
isDefault == other.isDefault && readOnly == other.readOnly && localCalendar == other.localCalendar &&
excluded == other.excluded;
}

bool operator!=(const Notebook other) const
Expand Down
6 changes: 6 additions & 0 deletions src/calendarnotebookmodel.cpp
Expand Up @@ -73,6 +73,10 @@ QVariant NemoCalendarNotebookModel::data(const QModelIndex &index, int role) con
return notebook.readOnly;
case LocalCalendarRole:
return notebook.localCalendar;
case AccountIdRole:
return notebook.accountId;
case AccountIconRole:
return notebook.accountIcon;
default:
return QVariant();
}
Expand Down Expand Up @@ -120,6 +124,8 @@ QHash<int, QByteArray> NemoCalendarNotebookModel::roleNames() const
roleNames[DefaultRole] = "isDefault";
roleNames[ReadOnlyRole] = "readOnly";
roleNames[LocalCalendarRole] = "localCalendar";
roleNames[AccountIdRole] = "accountId";
roleNames[AccountIconRole] = "accountIcon";

return roleNames;
}
4 changes: 3 additions & 1 deletion src/calendarnotebookmodel.h
Expand Up @@ -46,7 +46,9 @@ class NemoCalendarNotebookModel : public QAbstractListModel
ColorRole,
DefaultRole,
ReadOnlyRole,
LocalCalendarRole
LocalCalendarRole,
AccountIdRole,
AccountIconRole
};

NemoCalendarNotebookModel();
Expand Down
16 changes: 16 additions & 0 deletions src/calendarnotebookquery.cpp
Expand Up @@ -47,6 +47,16 @@ QString NemoCalendarNotebookQuery::color() const
return m_notebook.color;
}

int NemoCalendarNotebookQuery::accountId() const
{
return m_notebook.accountId;
}

QUrl NemoCalendarNotebookQuery::accountIcon() const
{
return m_notebook.accountIcon;
}

bool NemoCalendarNotebookQuery::isDefault() const
{
return m_notebook.isDefault;
Expand Down Expand Up @@ -82,6 +92,8 @@ void NemoCalendarNotebookQuery::updateData()
bool nameUpdated = (notebook.name != m_notebook.name);
bool descriptionUpdated = (notebook.description != m_notebook.description);
bool colorUpdated = (notebook.color != m_notebook.color);
bool accountIdUpdated = (notebook.accountId != m_notebook.accountId);
bool accountIconUpdated = (notebook.accountIcon != m_notebook.accountIcon);
bool isDefaultUpdated = (notebook.isDefault != m_notebook.isDefault);
bool localCalendarUpdated = (notebook.localCalendar != m_notebook.localCalendar);
bool isReadOnlyUpdated = (notebook.readOnly != m_notebook.readOnly);
Expand All @@ -94,6 +106,10 @@ void NemoCalendarNotebookQuery::updateData()
emit descriptionChanged();
if (colorUpdated)
emit colorChanged();
if (accountIdUpdated)
emit accountIdChanged();
if (accountIconUpdated)
emit accountIconChanged();
if (isDefaultUpdated)
emit isDefaultChanged();
if (localCalendarUpdated)
Expand Down
6 changes: 6 additions & 0 deletions src/calendarnotebookquery.h
Expand Up @@ -12,6 +12,8 @@ class NemoCalendarNotebookQuery : public QObject
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
Q_PROPERTY(QString color READ color NOTIFY colorChanged)
Q_PROPERTY(int accountId READ accountId NOTIFY accountIdChanged)
Q_PROPERTY(QUrl accountIcon READ accountIcon NOTIFY accountIconChanged)
Q_PROPERTY(bool isDefault READ isDefault NOTIFY isDefaultChanged)
Q_PROPERTY(bool localCalendar READ localCalendar NOTIFY localCalendarChanged)
Q_PROPERTY(bool isReadOnly READ isReadOnly NOTIFY isReadOnlyChanged)
Expand All @@ -27,6 +29,8 @@ class NemoCalendarNotebookQuery : public QObject
QString name() const;
QString description() const;
QString color() const;
int accountId() const;
QUrl accountIcon() const;
bool isDefault() const;
bool localCalendar() const;
bool isReadOnly() const;
Expand All @@ -37,6 +41,8 @@ class NemoCalendarNotebookQuery : public QObject
void nameChanged();
void descriptionChanged();
void colorChanged();
void accountIdChanged();
void accountIconChanged();
void isDefaultChanged();
void localCalendarChanged();
void isReadOnlyChanged();
Expand Down
28 changes: 27 additions & 1 deletion src/calendarworker.cpp
Expand Up @@ -48,8 +48,13 @@
#include <libical/vobject.h>
#include <libical/vcaltmp.h>

// libaccounts-qt
#include <Accounts/Manager>
#include <Accounts/Provider>
#include <Accounts/Account>

NemoCalendarWorker::NemoCalendarWorker() :
QObject(0)
QObject(0), mAccountManager(0)
{
}

Expand Down Expand Up @@ -692,6 +697,27 @@ void NemoCalendarWorker::loadNotebooks()
if (notebook.color.isEmpty())
notebook.color = defaultNotebookColors.at((nextDefaultNotebookColor++) % defaultNotebookColors.count());

QString accountStr = notebooks.at(ii)->account();
if (!accountStr.isEmpty()) {
if (!mAccountManager) {
mAccountManager = new Accounts::Manager(this);
}
bool ok = false;
int accountId = accountStr.toInt(&ok);
if (ok && accountId > 0) {
Accounts::Account *account = Accounts::Account::fromId(mAccountManager, accountId, this);
if (account) {
notebook.accountId = accountId;
notebook.accountIcon = mAccountManager->provider(account->providerName()).iconName();
if (notebook.description.isEmpty()) {
// fill the description field with some account information
notebook.description = account->displayName();
}
}
delete account;
}
}

if (mNotebooks.contains(notebook.uid) && mNotebooks.value(notebook.uid) != notebook)
changed = true;

Expand Down
5 changes: 5 additions & 0 deletions src/calendarworker.h
Expand Up @@ -41,6 +41,9 @@
// mkcal
#include <extendedstorage.h>

// libaccounts-qt
namespace Accounts { class Manager; }

class NemoCalendarWorker : public QObject, public mKCal::ExtendedStorageObserver
{
Q_OBJECT
Expand Down Expand Up @@ -114,6 +117,8 @@ public slots:
const QMultiHash<QString, KDateTime> &allDay,
const QList<NemoCalendarData::EventOccurrence> &occurrences);

Accounts::Manager *mAccountManager;

mKCal::ExtendedCalendar::Ptr mCalendar;
mKCal::ExtendedStorage::Ptr mStorage;

Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -8,7 +8,7 @@ QT += qml concurrent
QT -= gui

target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical accounts-qt5

INSTALLS += target

Expand Down

0 comments on commit 511b8b2

Please sign in to comment.