File indexing completed on 2025-01-05 04:58:19

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 #include <KLDAPWidgets/LdapClientSearch>
0009 #include <QList>
0010 #include <QObject>
0011 #include <QStringList>
0012 
0013 #include <Akonadi/Collection>
0014 #include <Akonadi/Item>
0015 #include <KContacts/ContactGroup>
0016 
0017 class KConfig;
0018 class QToolButton;
0019 class QTimer;
0020 namespace Akonadi
0021 {
0022 class ContactGroupSearchJob;
0023 }
0024 
0025 namespace PimCommon
0026 {
0027 class AddresseeLineEdit;
0028 class AddresseeLineEditPrivate : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     AddresseeLineEditPrivate(AddresseeLineEdit *qq, bool enableCompletion);
0033     ~AddresseeLineEditPrivate() override;
0034     void init();
0035     void setCompletedItems(const QStringList &items, bool autoSuggest);
0036     void addCompletionItem(const QString &string, int weight, int source, const QStringList *keyWords = nullptr);
0037     const QStringList adjustedCompletionItems(bool fullSearch);
0038     void updateSearchString();
0039     void startSearches();
0040     void akonadiPerformSearch();
0041     void akonadiHandlePending();
0042     void doCompletion(bool ctrlT);
0043 
0044     [[nodiscard]] bool showOU() const;
0045 
0046     void setIcon(const QIcon &icon, const QString &tooltip);
0047 
0048     [[nodiscard]] bool useCompletion() const;
0049     void setUseCompletion(bool useCompletion);
0050 
0051     [[nodiscard]] bool completionInitialized() const;
0052 
0053     [[nodiscard]] bool smartPaste() const;
0054     void setSmartPaste(bool smartPaste);
0055 
0056     [[nodiscard]] bool searchExtended() const;
0057     void setSearchExtended(bool searchExtended);
0058 
0059     [[nodiscard]] QString searchString() const;
0060     void setSearchString(const QString &searchString);
0061 
0062     [[nodiscard]] bool enableBalooSearch() const;
0063     void setEnableBalooSearch(bool enableBalooSearch);
0064 
0065     [[nodiscard]] bool useSemicolonAsSeparator() const;
0066     void setUseSemicolonAsSeparator(bool useSemicolonAsSeparator);
0067 
0068     [[nodiscard]] bool enableAkonadiSearch() const;
0069     void setEnableAkonadiSearch(bool enableAkonadiSearch);
0070 
0071     void removeCompletionSource(const QString &source);
0072     [[nodiscard]] int addCompletionSource(const QString &source, int weight);
0073     void restartTime(const QString &searchString);
0074     void updateBalooBlackList();
0075     void updateCompletionOrder();
0076 
0077     KLDAPWidgets::LdapClientSearch *ldapSearch();
0078 
0079     void setExpandIntern(bool);
0080     [[nodiscard]] bool expandIntern() const;
0081 
0082     [[nodiscard]] bool autoGroupExpand() const;
0083     void setAutoGroupExpand(bool autoGroupExpand);
0084 
0085     QList<KJob *> mightBeGroupJobs() const;
0086     void setMightBeGroupJobs(const QList<KJob *> &mightBeGroupJobs);
0087 
0088     [[nodiscard]] KContacts::ContactGroup::List groups() const;
0089     void setGroups(const KContacts::ContactGroup::List &groups);
0090 
0091     void mightBeGroupJobsClear();
0092     void groupsClear();
0093     void addGroups(const KContacts::ContactGroup::List &lst);
0094     void mightBeGroupJobsRemoveOne(Akonadi::ContactGroupSearchJob *search);
0095     void mightBeGroupJobsAdd(Akonadi::ContactGroupSearchJob *job);
0096     [[nodiscard]] bool groupsIsEmpty() const;
0097     void setShowRecentAddresses(bool b);
0098     [[nodiscard]] bool showRecentAddresses() const;
0099     void setRecentAddressConfig(KConfig *config);
0100 
0101     KConfig *recentAddressConfig() const;
0102 
0103     [[nodiscard]] bool canDeleteLineEdit() const;
0104     void setCanDeleteLineEdit(bool inprogressToConfigureCompletion);
0105 
0106 public Q_SLOTS:
0107     void slotToggleExpandGroups(bool);
0108     void slotShowOUChanged(bool);
0109 
0110 private Q_SLOTS:
0111     void slotCompletion();
0112     void slotPopupCompletion(const QString &);
0113     void slotReturnPressed(const QString &);
0114     void slotStartLDAPLookup();
0115     void slotLDAPSearchData(const KLDAPWidgets::LdapResult::List &);
0116     void slotEditCompletionOrder();
0117     void slotUserCancelled(const QString &);
0118     void slotAkonadiHandleItems(const Akonadi::Item::List &items);
0119     void slotAkonadiSearchResult(KJob *);
0120     void slotAkonadiCollectionsReceived(const Akonadi::Collection::List &);
0121     void searchInBaloo();
0122     void slotTriggerDelayedQueries();
0123 
0124 private:
0125     AddresseeLineEdit *const q;
0126     QToolButton *mToolButton = nullptr;
0127     QTimer *const mDelayedQueryTimer;
0128     QString mPreviousAddresses;
0129     QString mSearchString;
0130     QList<KJob *> mMightBeGroupJobs;
0131     KContacts::ContactGroup::List mGroups;
0132     KConfig *mRecentAddressConfig = nullptr;
0133     bool mUseCompletion = false;
0134     bool mCompletionInitialized = false;
0135     bool mSmartPaste = false;
0136     bool mLastSearchMode = false;
0137     bool mSearchExtended = false; // has \" been added?
0138     bool mUseSemicolonAsSeparator = false;
0139     bool mEnableBalooSearch = true;
0140     bool mEnableAkonadiSearch = true;
0141     bool mExpandIntern = true;
0142     bool mShowRecentAddresses = true;
0143     bool mCanDeleteLineEdit = true;
0144 };
0145 }