File indexing completed on 2024-05-26 05:25:11

0001 /*
0002 
0003   SPDX-FileCopyrightText: 2009-2024 Laurent Montel <montel@kde.org>
0004 
0005   SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "mailcommon_export.h"
0011 #include <Akonadi/EntityOrderProxyModel>
0012 
0013 namespace MailCommon
0014 {
0015 class HierarchicalFolderMatcher;
0016 
0017 /**
0018  * @brief The EntityCollectionOrderProxyModel class implements ordering of mail collections.
0019  * It supports two modes: manual sorting and automatic sorting.
0020  *
0021  * The manual sorting (which has to be activated explicitly by the user) allows the user to
0022  * reorder the collections (both toplevel resources and folders within the resource) by drag-n-drop,
0023  * and is implemented by the base class EntityOrderProxyModel.
0024  *
0025  * The automatic sorting is implemented by this class itself, and consists of assigning ranks
0026  * to various special folders (outbox, drafts, sent etc.) and then having the other folders sorted
0027  * by name (or another column), i.e. the default behaviour from QSortFilterProxyModel.
0028  * In that mode, the order of the toplevel folders can be controlled with setTopLevelOrder().
0029  */
0030 class MAILCOMMON_EXPORT EntityCollectionOrderProxyModel : public Akonadi::EntityOrderProxyModel
0031 {
0032     Q_OBJECT
0033 public:
0034     explicit EntityCollectionOrderProxyModel(QObject *parent = nullptr);
0035 
0036     ~EntityCollectionOrderProxyModel() override;
0037 
0038     [[nodiscard]] bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
0039 
0040     void setManualSortingActive(bool active);
0041     [[nodiscard]] bool isManualSortingActive() const;
0042 
0043     void clearRanks();
0044     void setTopLevelOrder(const QStringList &list);
0045 
0046     void setFolderMatcher(const HierarchicalFolderMatcher &matcher);
0047 
0048 public Q_SLOTS:
0049     void slotSpecialCollectionsChanged();
0050 
0051 protected:
0052     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0053 
0054 private:
0055     class EntityCollectionOrderProxyModelPrivate;
0056     std::unique_ptr<EntityCollectionOrderProxyModelPrivate> const d;
0057 };
0058 }