File indexing completed on 2024-04-14 03:53:04

0001 // -*- c++ -*-
0002 /*
0003     This file is part of the KDE libraries
0004     SPDX-FileCopyrightText: 2001 Waldo Bastian <bastian@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KIO_WORKER_CONFIG_H
0010 #define KIO_WORKER_CONFIG_H
0011 
0012 #include "metadata.h"
0013 #include <QObject>
0014 
0015 #include <memory>
0016 
0017 namespace KIO
0018 {
0019 class WorkerConfigPrivate;
0020 /**
0021  * This class manages the configuration for KIO workers based on protocol
0022  * and host. The Scheduler makes use of this class to configure the worker
0023  * whenever it has to connect to a new host.
0024  *
0025  * You only need to use this class if you want to override specific
0026  * configuration items of an KIO worker when the worker is used by
0027  * your application.
0028  *
0029  * Normally KIO workers are being configured by "kio_<protocol>rc"
0030  * configuration files. Groups defined in such files are treated as host
0031  * or domain specification. Configuration items defined in a group are
0032  * only applied when the worker is connecting with a host that matches with
0033  * the host and/or domain specified by the group.
0034  */
0035 class WorkerConfig : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     static WorkerConfig *self();
0041     ~WorkerConfig() override;
0042     /**
0043      * Configure workers of type @p protocol by setting @p key to @p value.
0044      * If @p host is specified the configuration only applies when dealing
0045      * with @p host.
0046      *
0047      * Changes made to the worker configuration only apply to workers
0048      * used by the current process.
0049      */
0050     void setConfigData(const QString &protocol, const QString &host, const QString &key, const QString &value);
0051 
0052     /**
0053      * Configure workers of type @p protocol with @p config.
0054      * If @p host is specified the configuration only applies when dealing
0055      * with @p host.
0056      *
0057      * Changes made to the worker configuration only apply to workers
0058      * used by the current process.
0059      */
0060     void setConfigData(const QString &protocol, const QString &host, const MetaData &config);
0061 
0062     /**
0063      * Query worker configuration for workers of type @p protocol when
0064      * dealing with @p host.
0065      */
0066     MetaData configData(const QString &protocol, const QString &host);
0067 
0068     /**
0069      * Query a specific configuration key for workers of type @p protocol when
0070      * dealing with @p host.
0071      */
0072     QString configData(const QString &protocol, const QString &host, const QString &key);
0073 
0074     /**
0075      * Undo any changes made by calls to setConfigData.
0076      */
0077     void reset();
0078 
0079 Q_SIGNALS:
0080     /**
0081      * This signal is raised when a worker of type @p protocol deals
0082      * with @p host for the first time.
0083      *
0084      * Your application can use this signal to make some last minute
0085      * configuration changes with setConfigData based on the
0086      * host.
0087      */
0088     void configNeeded(const QString &protocol, const QString &host);
0089 
0090 protected:
0091     WorkerConfig();
0092 
0093 private:
0094     std::unique_ptr<WorkerConfigPrivate> const d;
0095     friend class WorkerConfigSingleton;
0096 };
0097 }
0098 
0099 #endif