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 | * @return the instance of KProtocolInfoFactory (singleton). |
31 | */ |
32 | static KProtocolInfoFactory *self(); |
33 | |
34 | KProtocolInfoFactory(); |
35 | ~KProtocolInfoFactory(); |
36 | |
37 | /** |
38 | * Returns protocol info for @p protocol. |
39 | * |
40 | * Does not take proxy settings into account. |
41 | * @param protocol the protocol to search for |
42 | * @param updateCacheIfNotfound Flag for revalidating the cache. This will cause all plugins to be reloaded |
43 | * @return the pointer to the KProtocolInfo, or @c nullptr if not found |
44 | */ |
45 | KProtocolInfoPrivate *findProtocol(const QString &protocol, bool updateCacheIfNotfound = true); |
46 | |
47 | /** |
48 | * Loads all protocols. Slow, obviously, but fills the cache once and for all. |
49 | */ |
50 | QList<KProtocolInfoPrivate *> allProtocols(); |
51 | |
52 | /** |
53 | * Returns list of all known protocols. |
54 | * @return a list of all protocols |
55 | */ |
56 | QStringList protocols(); |
57 | |
58 | private: |
59 | /** |
60 | * Fill the internal cache. |
61 | */ |
62 | bool fillCache(); |
63 | |
64 | typedef QHash<QString, KProtocolInfoPrivate *> ProtocolCache; |
65 | ProtocolCache m_cache; |
66 | bool m_cacheDirty; |
67 | mutable QMutex m_mutex; // protects m_cache and m_allProtocolsLoaded |
68 | }; |
69 | |
70 | #endif |
71 | |