collectionswitchermodel.h 1.37 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
This file is part of KMail, the KDE mail client.
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>

SPDX-License-Identifier: GPL-2.0-only
*/
#pragma once
#include <Akonadi/Collection>
#include <QAbstractListModel>
#include <QVector>

class CollectionSwitcherModel : public QAbstractListModel
{
    Q_OBJECT
public:
Laurent Montel's avatar
Laurent Montel committed
16
17
18
19
20
    enum CollectionInfoRole {
        CollectionFullPath = Qt::UserRole + 1,
        CollectionAkonadId,
    };

Laurent Montel's avatar
Laurent Montel committed
21
    struct CollectionInfo {
22
23
24
25
26
27
28
        CollectionInfo(){};
        CollectionInfo(const Akonadi::Collection &col, const QString &path)
            : mNewCollection(col)
            , mFullPath(path)
        {
        }

Laurent Montel's avatar
Laurent Montel committed
29
        const Akonadi::Collection mNewCollection;
Laurent Montel's avatar
Laurent Montel committed
30
        const QString mFullPath;
Laurent Montel's avatar
Laurent Montel committed
31
32
33
34
35
36
37
38
    };

    explicit CollectionSwitcherModel(QObject *parent = nullptr);
    ~CollectionSwitcherModel() override;

    Q_REQUIRED_RESULT int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override;

39
40
41
42
    void addHistory(const Akonadi::Collection &currentCol, const QString &fullPath = {});

    Q_REQUIRED_RESULT const Akonadi::Collection collection(int index);

Laurent Montel's avatar
Laurent Montel committed
43
44
45
46
47
48
private:
    QVector<CollectionInfo> mCollectionsInfo;
};

Q_DECLARE_METATYPE(CollectionSwitcherModel::CollectionInfo)
Q_DECLARE_TYPEINFO(CollectionSwitcherModel::CollectionInfo, Q_MOVABLE_TYPE);