File indexing completed on 2024-04-28 11:41:02

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      * @return the pointer to the KProtocolInfo, or @c nullptr if not found
0043      */
0044     KProtocolInfoPrivate *findProtocol(const QString &protocol);
0045 
0046     /**
0047      * Loads all protocols. Slow, obviously, but fills the cache once and for all.
0048      */
0049     QList<KProtocolInfoPrivate *> allProtocols();
0050 
0051     /**
0052      * Returns list of all known protocols.
0053      * @return a list of all protocols
0054      */
0055     QStringList protocols();
0056 
0057 private:
0058     /**
0059      * Fill the internal cache.
0060      */
0061     bool fillCache();
0062 
0063     typedef QHash<QString, KProtocolInfoPrivate *> ProtocolCache;
0064     ProtocolCache m_cache;
0065     bool m_cacheDirty;
0066     mutable QMutex m_mutex; // protects m_cache and m_allProtocolsLoaded
0067 };
0068 
0069 #endif