1 /* 2 SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 6 */ 7 8 #pragma once 9 10 #include "pimcommonakonadi_private_export.h" 11 #include <KConfig> 12 #include <QDBusAbstractAdaptor> 13 #include <QWidget> 14 15 class QPushButton; 16 class QAbstractItemModel; 17 class QModelIndex; 18 class QTreeWidget; 19 20 namespace KLDAP 21 { 22 class LdapClientSearch; 23 } 24 25 namespace PimCommon 26 { 27 class CompletionOrderEditorAdaptor : public QDBusAbstractAdaptor 28 { 29 Q_OBJECT 30 Q_CLASSINFO("D-Bus Interface", "org.kde.pim.CompletionOrder") 31 public: 32 explicit CompletionOrderEditorAdaptor(QObject *parent); 33 Q_SIGNALS: 34 void completionOrderChanged(); 35 }; 36 37 class CompletionOrderWidget; 38 39 // Base class for items in the list 40 class CompletionItem 41 { 42 public: ~CompletionItem()43 virtual ~CompletionItem() 44 { 45 } 46 47 virtual QString label() const = 0; 48 virtual QIcon icon() const = 0; 49 virtual int completionWeight() const = 0; 50 virtual void setCompletionWeight(int weight) = 0; 51 virtual void save(CompletionOrderWidget *) = 0; 52 virtual bool hasEnableSupport() const = 0; 53 virtual bool isEnabled() const = 0; 54 virtual void setIsEnabled(bool b) = 0; 55 }; 56 57 class PIMCOMMONAKONADI_TESTS_EXPORT CompletionOrderWidget : public QWidget 58 { 59 Q_OBJECT 60 public: 61 explicit CompletionOrderWidget(QWidget *parent = nullptr); 62 ~CompletionOrderWidget() override; 63 void save(); 64 65 KConfig *configFile(); 66 void loadCompletionItems(); 67 void setLdapClientSearch(KLDAP::LdapClientSearch *ldapSearch); 68 69 Q_SIGNALS: 70 void completionOrderChanged(); 71 72 private: 73 void rowsInserted(const QModelIndex &parent, int start, int end); 74 void slotSelectionChanged(); 75 void slotMoveUp(); 76 void slotMoveDown(); 77 void addRecentAddressItem(); 78 void addCompletionItemForCollection(const QModelIndex &); 79 void slotItemChanged(); 80 81 KConfig mConfig; 82 QTreeWidget *mListView = nullptr; 83 QPushButton *mUpButton = nullptr; 84 QPushButton *mDownButton = nullptr; 85 QAbstractItemModel *mCollectionModel = nullptr; 86 KLDAP::LdapClientSearch *mLdapSearch = nullptr; 87 88 int mDefaultValue = 60; 89 bool mDirty = false; 90 }; 91 } 92 93