From 58f9f288fc5b3a7edf42e4dc997fe93418977249 Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Mon, 7 Dec 2015 00:17:51 +0100 Subject: add folderlistmodel --- framework/mail/CMakeLists.txt | 1 + framework/mail/folderlistmodel.cpp | 42 ++++++++++++++++++++++++++++++++++++++ framework/mail/folderlistmodel.h | 27 ++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 framework/mail/folderlistmodel.cpp create mode 100644 framework/mail/folderlistmodel.h (limited to 'framework') diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt index c57ac1fe..f1c14470 100644 --- a/framework/mail/CMakeLists.txt +++ b/framework/mail/CMakeLists.txt @@ -3,6 +3,7 @@ set(mailplugin_SRCS maillistcontroller.cpp maillistmodel.cpp singlemailcontroller.cpp + folderlistmodel.cpp ) add_library(mailplugin SHARED ${mailplugin_SRCS}) diff --git a/framework/mail/folderlistmodel.cpp b/framework/mail/folderlistmodel.cpp new file mode 100644 index 00000000..d7889da4 --- /dev/null +++ b/framework/mail/folderlistmodel.cpp @@ -0,0 +1,42 @@ +#include "folderlistmodel.h" +#include + +FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() +{ + Akonadi2::Query query; + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = true; + QList requestedProperties; + requestedProperties << "name" << "icon"; + query.requestedProperties = requestedProperties.toSet(); + //TODO + //mModel = Akonadi2::Store::loadModel(query); + //setSourceModel(mModel.data()); +} + +FolderListModel::~FolderListModel() +{ + +} + +QHash< int, QByteArray > FolderListModel::roleNames() const +{ + QHash roles; + + roles[Name] = "name"; + roles[Icon] = "icon"; + + return roles; +} + +QVariant FolderListModel::data(const QModelIndex &idx, int role) const +{ + switch (role) { + case Name: + return mapToSource(idx).data(Qt::DisplayRole).toString(); + case Icon: + return mapToSource(idx).data(Qt::DisplayRole).toString(); + } + return QIdentityProxyModel::data(idx, role); +} diff --git a/framework/mail/folderlistmodel.h b/framework/mail/folderlistmodel.h new file mode 100644 index 00000000..9a782327 --- /dev/null +++ b/framework/mail/folderlistmodel.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include + +class FolderListModel : public QIdentityProxyModel +{ + Q_OBJECT + +public: + FolderListModel(QObject *parent = Q_NULLPTR); + ~FolderListModel(); + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + enum Roles { + Name = Qt::UserRole + 1, + Icon + }; + + QHash roleNames() const; + +private: + QSharedPointer mModel; +}; -- cgit v1.2.3