File indexing completed on 2025-01-05 04:58:21
0001 /* 0002 * 0003 * SPDX-FileCopyrightText: 2001-2003 Carsten Pfeiffer <pfeiffer@kde.org> 0004 * SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 #pragma once 0009 0010 #include "pimcommonakonadi_export.h" 0011 #include <KContacts/Addressee> 0012 #include <QStringList> 0013 class KConfig; 0014 0015 namespace PimCommon 0016 { 0017 /** 0018 * Handles a list of "recent email-addresses". Simply set a max-count and 0019 * call @ref add() to add entries. 0020 * 0021 * @author Carsten Pfeiffer <pfeiffer@kde.org> 0022 */ 0023 0024 class PIMCOMMONAKONADI_EXPORT RecentAddresses 0025 { 0026 public: 0027 ~RecentAddresses(); 0028 /** 0029 * @returns the only possible instance of this class. 0030 */ 0031 static RecentAddresses *self(KConfig *config = nullptr); 0032 0033 /* 0034 * @return true if self() was called, i.e. a RecentAddresses instance exists 0035 */ 0036 static bool exists(); 0037 0038 /** 0039 * @returns the list of recent addresses. 0040 * Note: an entry doesn't have to be one email address, it can be multiple, 0041 * like "Foo <foo@bar.org>, Bar Baz <bar@baz.org>". 0042 */ 0043 [[nodiscard]] QStringList addresses() const; 0044 0045 /** 0046 * Adds an entry to the list. 0047 * Note: an entry doesn't have to be one email address, it can be multiple, 0048 * like "Foo <foo@bar.org>, Bar Baz <bar@baz.org>". 0049 */ 0050 void add(const QString &entry); 0051 0052 /** 0053 * Sets the maximum number, the list can hold. The list adjusts to this 0054 * size if necessary. Default maximum is 40. 0055 */ 0056 void setMaxCount(int count); 0057 0058 /** 0059 * @returns the current maximum number of entries. 0060 */ 0061 [[nodiscard]] int maxCount() const; 0062 0063 /** 0064 * Loads the list of recently used addresses from the configfile. 0065 * Automatically done on startup. 0066 */ 0067 void load(KConfig *); 0068 0069 /** 0070 * Saves the list of recently used addresses to the configfile. 0071 * Make sure to call KSharedConfig::openConfig()->sync() afterwards, to really save. 0072 */ 0073 void save(KConfig *); 0074 0075 /** 0076 * Removes all entries from the history. 0077 */ 0078 void clear(); 0079 0080 private: 0081 PIMCOMMONAKONADI_NO_EXPORT explicit RecentAddresses(KConfig *config = nullptr); 0082 PIMCOMMONAKONADI_NO_EXPORT void adjustSize(); 0083 0084 KContacts::Addressee::List m_addresseeList; 0085 0086 int m_maxCount; 0087 }; 0088 }