1 /*
2 
3   SPDX-FileCopyrightText: 2009-2021 Laurent Montel <montel@kde.org>
4 
5   SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 #include "foldertreewidget.h"
11 #include "mailcommon/mailutil.h"
12 #include "mailcommon_export.h"
13 
14 #include <Akonadi/Collection>
15 #include <Akonadi/EntityTreeView>
16 
17 class QMouseEvent;
18 
19 namespace Akonadi
20 {
21 class CollectionStatisticsDelegate;
22 }
23 
24 namespace MailCommon
25 {
26 /**
27  * This is an enhanced EntityTreeView specially suited for the folders in KMail's
28  * main folder widget.
29  */
30 class MAILCOMMON_EXPORT FolderTreeView : public Akonadi::EntityTreeView
31 {
32     Q_OBJECT
33 
34 public:
35     explicit FolderTreeView(QWidget *parent = nullptr, bool showUnreadCount = true);
36 
37     explicit FolderTreeView(KXMLGUIClient *xmlGuiClient, QWidget *parent = nullptr, bool showUnreadCount = true);
38 
39     ~FolderTreeView() override;
40 
41     void selectNextUnreadFolder(bool confirm = false);
42     void selectPrevUnreadFolder(bool confirm = false);
43 
44     void showStatisticAnimation(bool anim);
45 
46     void disableContextMenuAndExtraColumn();
47 
48     void setTooltipsPolicy(FolderTreeWidget::ToolTipDisplayPolicy);
49 
50     void restoreHeaderState(const QByteArray &data);
51 
52     Q_REQUIRED_RESULT Akonadi::Collection currentFolder() const;
53 
54     void disableSaveConfig();
55     void readConfig();
56 
57     void updatePalette();
58 
59     void keyboardSearch(const QString &) override;
60 
61 protected:
62     enum Move { Next = 0, Previous = 1 };
63 
64     void init(bool showUnreadCount);
65     void selectModelIndex(const QModelIndex &);
66     void setCurrentModelIndex(const QModelIndex &);
67     QModelIndex selectNextFolder(const QModelIndex &current);
68     bool isUnreadFolder(const QModelIndex &current, QModelIndex &nextIndex, FolderTreeView::Move move, bool confirm);
69     void writeConfig();
70 
71     void setSortingPolicy(FolderTreeWidget::SortingPolicy policy, bool writeInConfig = false);
72 
73     void mousePressEvent(QMouseEvent *e) override;
74 
75 public Q_SLOTS:
76     void slotFocusNextFolder();
77     void slotFocusPrevFolder();
78     void slotSelectFocusFolder();
79     void slotFocusFirstFolder();
80     void slotFocusLastFolder();
81 
82 protected Q_SLOTS:
83     void slotHeaderContextMenuRequested(const QPoint &);
84     void slotHeaderContextMenuChangeIconSize(bool);
85     void slotHeaderContextMenuChangeHeader(bool);
86     void slotHeaderContextMenuChangeToolTipDisplayPolicy(bool);
87     void slotHeaderContextMenuChangeSortingPolicy(bool);
88 
89 Q_SIGNALS:
90     void changeTooltipsPolicy(FolderTreeWidget::ToolTipDisplayPolicy);
91     void manualSortingChanged(bool actif);
92     void newTabRequested(bool);
93 
94 private:
95     enum SearchDirection { ForwardSearch, BackwardSearch };
96 
97     QModelIndex indexAbove(const QModelIndex &current) const;
98     QModelIndex indexBelow(const QModelIndex &current) const;
99     QModelIndex lastChild(const QModelIndex &current) const;
100     QModelIndex nextUnreadCollection(const QModelIndex &current, SearchDirection direction) const;
101 
102     bool ignoreUnreadFolder(const Akonadi::Collection &, bool) const;
103     bool allowedToEnterFolder(const Akonadi::Collection &, bool) const;
104     bool trySelectNextUnreadFolder(const QModelIndex &, SearchDirection, bool);
105 
106     FolderTreeWidget::ToolTipDisplayPolicy mToolTipDisplayPolicy;
107     FolderTreeWidget::SortingPolicy mSortingPolicy;
108     Akonadi::CollectionStatisticsDelegate *mCollectionStatisticsDelegate = nullptr;
109     bool mbDisableContextMenuAndExtraColumn = false;
110     bool mbDisableSaveConfig = false;
111 };
112 }
113 
114