| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 1999 Torben Weis <weis@kde.org> |
| 4 | SPDX-FileCopyrightText: 2000, 2003 Waldo Bastian <bastian@kde.org> |
| 5 | SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org> |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.0-only |
| 8 | */ |
| 9 | #ifndef kprotocolinfofactory_h |
| 10 | #define kprotocolinfofactory_h |
| 11 | |
| 12 | #include <QHash> |
| 13 | #include <QMutex> |
| 14 | #include <QString> |
| 15 | #include <QStringList> |
| 16 | |
| 17 | class KProtocolInfoPrivate; |
| 18 | |
| 19 | /*! |
| 20 | * \internal |
| 21 | * |
| 22 | * KProtocolInfoFactory is a factory for getting |
| 23 | * KProtocolInfo. The factory is a singleton |
| 24 | * (only one instance can exist). |
| 25 | */ |
| 26 | class KProtocolInfoFactory |
| 27 | { |
| 28 | public: |
| 29 | /*! |
| 30 | * Returns the instance of KProtocolInfoFactory (singleton). |
| 31 | */ |
| 32 | static KProtocolInfoFactory *self(); |
| 33 | |
| 34 | KProtocolInfoFactory(); |
| 35 | ~KProtocolInfoFactory(); |
| 36 | |
| 37 | /*! |
| 38 | * Returns protocol info for \a protocol. |
| 39 | * |
| 40 | * Does not take proxy settings into account. |
| 41 | * |
| 42 | * \a protocol the protocol to search for |
| 43 | * |
| 44 | * \a updateCacheIfNotfound Flag for revalidating the cache. This will cause all plugins to be reloaded |
| 45 | * |
| 46 | * Returns the pointer to the KProtocolInfo, or \c nullptr if not found |
| 47 | */ |
| 48 | KProtocolInfoPrivate *findProtocol(const QString &protocol, bool updateCacheIfNotfound = true); |
| 49 | |
| 50 | /*! |
| 51 | * Loads all protocols. Slow, obviously, but fills the cache once and for all. |
| 52 | */ |
| 53 | QList<KProtocolInfoPrivate *> allProtocols(); |
| 54 | |
| 55 | /*! |
| 56 | * Returns list of all known protocols. |
| 57 | */ |
| 58 | QStringList protocols(); |
| 59 | |
| 60 | private: |
| 61 | /*! |
| 62 | * Fill the internal cache. |
| 63 | */ |
| 64 | bool fillCache(); |
| 65 | |
| 66 | typedef QHash<QString, KProtocolInfoPrivate *> ProtocolCache; |
| 67 | ProtocolCache m_cache; |
| 68 | bool m_cacheDirty; |
| 69 | mutable QMutex m_mutex; // protects m_cache and m_allProtocolsLoaded |
| 70 | }; |
| 71 | |
| 72 | #endif |
| 73 | |