Commit a1da1e8d authored by Carl Schwan's avatar Carl Schwan 🚴 Committed by Claudio Cambra
Browse files

Add folder title in mail list page



Signed-off-by: Carl Schwan's avatarCarl Schwan <carl@carlschwan.eu>
parent ee8cfabb
......@@ -57,6 +57,24 @@ MailManager::MailManager(QObject *parent)
// Setup selection model
m_collectionSelectionModel = new QItemSelectionModel(m_foldersModel);
connect(m_collectionSelectionModel, &QItemSelectionModel::selectionChanged, this, [this](const QItemSelection &selected, const QItemSelection &deselected) {
Q_UNUSED(deselected)
const auto indexes = selected.indexes();
if (indexes.count()) {
QString name;
QModelIndex index = indexes[0];
while (index.isValid()) {
if (name.isEmpty()) {
name = index.data(Qt::DisplayRole).toString();
} else {
name = index.data(Qt::DisplayRole).toString() + QLatin1String(" / ") + name;
}
index = index.parent();
}
m_selectedFolderName = name;
Q_EMIT selectedFolderNameChanged();
}
});
auto selectionModel = new SelectionProxyModel(m_collectionSelectionModel, this);
selectionModel->setSourceModel(treeModel);
selectionModel->setFilterBehavior(KSelectionProxyModel::ChildrenOfExactSelection);
......@@ -102,7 +120,6 @@ MailModel *MailManager::folderModel() const
void MailManager::loadMailCollection(const QModelIndex &modelIndex)
{
if (!modelIndex.isValid()) {
qDebug() << "hello";
return;
}
......@@ -123,3 +140,8 @@ Akonadi::Session *MailManager::session() const
{
return m_session;
}
QString MailManager::selectedFolderName() const
{
return m_selectedFolderName;
}
......@@ -21,6 +21,7 @@ class MailManager : public QObject
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
Q_PROPERTY(Akonadi::CollectionFilterProxyModel *foldersModel READ foldersModel CONSTANT)
Q_PROPERTY(MailModel *folderModel READ folderModel NOTIFY folderModelChanged)
Q_PROPERTY(QString selectedFolderName READ selectedFolderName NOTIFY selectedFolderNameChanged)
public:
MailManager(QObject *parent = nullptr);
......@@ -30,12 +31,14 @@ public:
Akonadi::CollectionFilterProxyModel *foldersModel() const;
MailModel *folderModel() const;
Akonadi::Session *session() const;
QString selectedFolderName() const;
Q_INVOKABLE void loadMailCollection(const QModelIndex &index);
Q_SIGNALS:
void loadingChanged();
void folderModelChanged();
void selectedFolderNameChanged();
private:
bool m_loading;
......@@ -45,5 +48,6 @@ private:
//folders
QItemSelectionModel *m_collectionSelectionModel;
MailModel *m_folderModel;
QString m_selectedFolderName;
};
......@@ -22,14 +22,16 @@ MailModel::MailModel(QObject *parent)
QHash<int, QByteArray> MailModel::roleNames() const
{
return {{TitleRole, QByteArrayLiteral("title")},
{DateRole, QByteArrayLiteral("date")},
{DateTimeRole, QByteArrayLiteral("datetime")},
{SenderRole, QByteArrayLiteral("sender")},
{UnreadRole, QByteArrayLiteral("unread")},
{FavoriteRole, QByteArrayLiteral("favorite")},
{TextColorRole, QByteArrayLiteral("textColor")},
{BackgroundColorRole, QByteArrayLiteral("backgroudColor")}};
return {
{TitleRole, QByteArrayLiteral("title")},
{DateRole, QByteArrayLiteral("date")},
{DateTimeRole, QByteArrayLiteral("datetime")},
{SenderRole, QByteArrayLiteral("sender")},
{UnreadRole, QByteArrayLiteral("unread")},
{FavoriteRole, QByteArrayLiteral("favorite")},
{TextColorRole, QByteArrayLiteral("textColor")},
{BackgroundColorRole, QByteArrayLiteral("backgroudColor")},
};
}
QVariant MailModel::data(const QModelIndex &index, int role) const
......
......@@ -14,8 +14,6 @@ class MailModel : public QIdentityProxyModel
{
Q_OBJECT
// Q_PROPERTY(ViewerHelper *viewerHelper READ viewerHelper WRITE setViewerHelper NOTIFY viewerHelperChanged)
public:
enum AnimalRoles {
TitleRole = Qt::UserRole + 1,
......@@ -29,18 +27,9 @@ public:
FavoriteRole,
};
// ViewerHelper *viewerHelper() const;
// void setViewerHelper(ViewerHelper *viewerHelper);
explicit MailModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
Q_INVOKABLE void loadItem(int row);
///Q_SIGNALS:
/// void viewerHelperChanged();
///
///private:
/// ViewerHelper *m_viewerHelper = nullptr;
};
......@@ -11,6 +11,7 @@ import org.kde.kitemmodels 1.0 as KItemModels
Kirigami.ScrollablePage {
id: folderView
property var mailViewer: null;
title: MailManager.selectedFolderName
ListView {
id: mails
model: MailManager.folderModel
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment