1 /* -*- mode: c++; c-basic-offset:4 -*-
2     view/keytreeview.h
3 
4     This file is part of Kleopatra, the KDE keymanager
5     SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB
6 
7     SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include <QWidget>
13 
14 #include <QString>
15 #include <QStringList>
16 
17 #include <gpgme++/key.h>
18 
19 #include <memory>
20 #include <vector>
21 
22 #include <KConfigGroup>
23 
24 class QTreeView;
25 
26 namespace Kleo
27 {
28 
29 class KeyFilter;
30 class AbstractKeyListModel;
31 class AbstractKeyListSortFilterProxyModel;
32 class KeyListSortFilterProxyModel;
33 
34 class KeyTreeView : public QWidget
35 {
36     Q_OBJECT
37 public:
38     explicit KeyTreeView(QWidget *parent = nullptr);
39     KeyTreeView(const QString &stringFilter, const std::shared_ptr<KeyFilter> &keyFilter,
40                 AbstractKeyListSortFilterProxyModel *additionalProxy, QWidget *parent,
41                 const KConfigGroup &group);
42     ~KeyTreeView() override;
43 
view()44     QTreeView *view() const
45     {
46         return m_view;
47     }
48 
model()49     AbstractKeyListModel *model() const
50     {
51         return m_isHierarchical ? hierarchicalModel() : flatModel();
52     }
53 
flatModel()54     AbstractKeyListModel *flatModel() const
55     {
56         return m_flatModel;
57     }
hierarchicalModel()58     AbstractKeyListModel *hierarchicalModel() const
59     {
60         return m_hierarchicalModel;
61     }
62 
63     void setFlatModel(AbstractKeyListModel *model);
64     void setHierarchicalModel(AbstractKeyListModel *model);
65 
66     void setKeys(const std::vector<GpgME::Key> &keys);
keys()67     const std::vector<GpgME::Key> &keys() const
68     {
69         return m_keys;
70     }
71 
72     void selectKeys(const std::vector<GpgME::Key> &keys);
73     std::vector<GpgME::Key> selectedKeys() const;
74 
75     void addKeysUnselected(const std::vector<GpgME::Key> &keys);
76     void addKeysSelected(const std::vector<GpgME::Key> &keys);
77     void removeKeys(const std::vector<GpgME::Key> &keys);
78 
79 #if 0
80     void setToolTipOptions(int options);
81     int toolTipOptions() const;
82 #endif
83 
stringFilter()84     QString stringFilter() const
85     {
86         return m_stringFilter;
87     }
keyFilter()88     const std::shared_ptr<KeyFilter> &keyFilter() const
89     {
90         return m_keyFilter;
91     }
isHierarchicalView()92     bool isHierarchicalView() const
93     {
94         return m_isHierarchical;
95     }
96 
97     void setColumnSizes(const std::vector<int> &sizes);
98     std::vector<int> columnSizes() const;
99 
100     void setSortColumn(int sortColumn, Qt::SortOrder sortOrder);
101     int sortColumn() const;
102     Qt::SortOrder sortOrder() const;
103 
clone()104     virtual KeyTreeView *clone() const
105     {
106         return new KeyTreeView(*this);
107     }
108 
109     void disconnectSearchBar(const QObject *bar);
110     bool connectSearchBar(const QObject *bar);
111     void resizeColumns();
112 
113     void saveLayout(KConfigGroup &group);
114     void restoreLayout(const KConfigGroup &group);
115 
116 public Q_SLOTS:
117     virtual void setStringFilter(const QString &text);
118     virtual void setKeyFilter(const std::shared_ptr<Kleo::KeyFilter> &filter);
119     virtual void setHierarchicalView(bool on);
120 
121 Q_SIGNALS:
122     void stringFilterChanged(const QString &filter);
123     void keyFilterChanged(const std::shared_ptr<Kleo::KeyFilter> &filter);
124     void hierarchicalChanged(bool on);
125 
126 protected:
127     KeyTreeView(const KeyTreeView &);
128 
129 private:
130     void init();
131     void addKeysImpl(const std::vector<GpgME::Key> &, bool);
132     void restoreExpandState();
133     void setUpTagKeys();
134 
135 private:
136     std::vector<GpgME::Key> m_keys;
137 
138     KeyListSortFilterProxyModel *m_proxy;
139     AbstractKeyListSortFilterProxyModel *m_additionalProxy;
140 
141     QTreeView *m_view;
142 
143     AbstractKeyListModel *m_flatModel;
144     AbstractKeyListModel *m_hierarchicalModel;
145 
146     QString m_stringFilter;
147     std::shared_ptr<KeyFilter> m_keyFilter;
148 
149     QStringList m_expandedKeys;
150 
151     KConfigGroup m_group;
152 
153     bool m_isHierarchical : 1;
154     bool m_onceResized : 1;
155 };
156 
157 }
158 
159