File indexing completed on 2024-04-21 03:55:08

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 Torben Weis <weis@kde.org>
0004     SPDX-FileCopyrightText: 2000, 2003 Waldo Bastian <bastian@kde.org>
0005     SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-only
0008 */
0009 #ifndef kprotocolinfofactory_h
0010 #define kprotocolinfofactory_h
0011 
0012 #include <QHash>
0013 #include <QMutex>
0014 #include <QString>
0015 #include <QStringList>
0016 
0017 class KProtocolInfoPrivate;
0018 
0019 /**
0020  * @internal
0021  *
0022  * KProtocolInfoFactory is a factory for getting
0023  * KProtocolInfo. The factory is a singleton
0024  * (only one instance can exist).
0025  */
0026 class KProtocolInfoFactory
0027 {
0028 public:
0029     /**
0030      * @return the instance of KProtocolInfoFactory (singleton).
0031      */
0032     static KProtocolInfoFactory *self();
0033 
0034     KProtocolInfoFactory();
0035     ~KProtocolInfoFactory();
0036 
0037     /**
0038      * Returns protocol info for @p protocol.
0039      *
0040      * Does not take proxy settings into account.
0041      * @param protocol the protocol to search for
0042      * @param updateCacheIfNotfound Flag for revalidating the cache. This will cause all plugins to be reloaded
0043      * @return the pointer to the KProtocolInfo, or @c nullptr if not found
0044      */
0045     KProtocolInfoPrivate *findProtocol(const QString &protocol, bool updateCacheIfNotfound = true);
0046 
0047     /**
0048      * Loads all protocols. Slow, obviously, but fills the cache once and for all.
0049      */
0050     QList<KProtocolInfoPrivate *> allProtocols();
0051 
0052     /**
0053      * Returns list of all known protocols.
0054      * @return a list of all protocols
0055      */
0056     QStringList protocols();
0057 
0058 private:
0059     /**
0060      * Fill the internal cache.
0061      */
0062     bool fillCache();
0063 
0064     typedef QHash<QString, KProtocolInfoPrivate *> ProtocolCache;
0065     ProtocolCache m_cache;
0066     bool m_cacheDirty;
0067     mutable QMutex m_mutex; // protects m_cache and m_allProtocolsLoaded
0068 };
0069 
0070 #endif