File indexing completed on 2024-04-14 14:18:47

0001 /*
0002     SPDX-FileCopyrightText: 2003 Jason Keirstead <jason@keirstead.org>
0003     SPDX-FileCopyrightText: 2003-2006 Michel Hermier <michel.hermier@gmail.com>
0004     SPDX-FileCopyrightText: 2007 Nick Shaforostoff <shafff@ukr.net>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 #ifndef KCODECACTION_H
0009 #define KCODECACTION_H
0010 
0011 #include <kconfigwidgets_export.h>
0012 
0013 #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 102)
0014 #include <KEncodingProber>
0015 #endif
0016 
0017 #include <KSelectAction>
0018 #include <memory>
0019 
0020 class QTextCodec;
0021 
0022 /**
0023  *  @class KCodecAction kcodecaction.h KCodecAction
0024  *
0025  *  @short Action for selecting one of several QTextCodec.
0026  *
0027  *  This action shows up a submenu with a list of the available codecs on the system.
0028  */
0029 class KCONFIGWIDGETS_EXPORT KCodecAction : public KSelectAction
0030 {
0031     Q_OBJECT
0032 
0033     Q_PROPERTY(QString codecName READ currentCodecName WRITE setCurrentCodec)
0034 #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 103)
0035     Q_PROPERTY(int codecMib READ currentCodecMib)
0036 #endif
0037 
0038 public:
0039     explicit KCodecAction(QObject *parent, bool showAutoOptions = false);
0040 
0041     KCodecAction(const QString &text, QObject *parent, bool showAutoOptions = false);
0042 
0043     KCodecAction(const QIcon &icon, const QString &text, QObject *parent, bool showAutoOptions = false);
0044 
0045     ~KCodecAction() override;
0046 
0047 public:
0048 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0049     /**
0050      * @deprecated since 5.103, use QTextCodec or QStringConverter.
0051      */
0052     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use QTextCodec or QStringConverter")
0053     int mibForName(const QString &codecName, bool *ok = nullptr) const;
0054 #endif
0055 
0056 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0057     /**
0058      * @deprecated since 5.103, use QTextCodec or QStringConverter.
0059      */
0060     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use QTextCodec or QStringConverter")
0061     QTextCodec *codecForMib(int mib) const;
0062 #endif
0063 
0064 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0065     /**
0066      * @deprecated since 5.103, use currentCodecName
0067      */
0068     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use currentCodecName")
0069     QTextCodec *currentCodec() const;
0070 #endif
0071 
0072 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0073     /**
0074      * @deprecated since 5.103, use setCurrentCodecName
0075      */
0076     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use setCurrentCodecName")
0077     bool setCurrentCodec(QTextCodec *codec);
0078 #endif
0079 
0080     QString currentCodecName() const;
0081     bool setCurrentCodec(const QString &codecName);
0082 
0083 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0084     /**
0085      * @deprecated since 5.103, use currentCodecName
0086      */
0087     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use currentCodecName")
0088     int currentCodecMib() const;
0089 #endif
0090 
0091 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0092     /**
0093      * @deprecated since 5.103, use setCurrentCodecName
0094      */
0095     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use setCurrentCodecName")
0096     bool setCurrentCodec(int mib);
0097 #endif
0098 
0099 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
0100     /**
0101      * Applicable only if showAutoOptions in c'tor was true
0102      *
0103      * @returns KEncodingProber::None if specific encoding is selected, not autodetection, otherwise... you know it!
0104      *
0105      * @deprecated since 5.102, no known users.
0106      */
0107     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 102, "No known users")
0108     KEncodingProber::ProberType currentProberType() const;
0109 #endif
0110 
0111 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
0112     /**
0113      * Applicable only if showAutoOptions in c'tor was true
0114      *
0115      * KEncodingProber::Universal means 'Default' item
0116      *
0117      * @deprecated since 5.102, no known users.
0118      */
0119     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 102, "No known users")
0120     bool setCurrentProberType(KEncodingProber::ProberType);
0121 #endif
0122 
0123 Q_SIGNALS:
0124 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 78)
0125     /**
0126      * Specific (proper) codec was selected
0127      *
0128      * Note that triggered(const QString &) is emitted too (as defined in KSelectAction).
0129      * @deprecated Since 5.78, use codecTriggered(QTextCodec *)
0130      */
0131     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 78, "Use KCodecAction::codecTriggered(QTextCodec *)")
0132     void triggered(QTextCodec *codec); // clazy:exclude=overloaded-signal
0133 #endif
0134 
0135 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 103)
0136     /**
0137      * Specific (proper) codec was selected
0138      *
0139      * Note that textTriggered(const QString &) is emitted too (as defined in KSelectAction).
0140      *
0141      * In your KCodecAction subclass to be backward-compatible to KF < 5.78, emit instead
0142      * just the deprecated signal triggered(QTextCodec *). That will also automatically
0143      * emit codecTriggered(QTextCodec *) because this signal is connected to the deprevcated
0144      * one in the KCodecAction constructor.
0145      * Only if you compile against a variant of KConfigWidgets built without all API
0146      * deprecated up to version 5.78, then emit this signal directly.
0147      * Your code would be like this:
0148      * @code
0149      * #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 78)
0150      *     // will also indirectly emit codecTriggered since 5.78
0151      *     Q_EMIT triggered(codec);
0152      * #else
0153      *     Q_EMIT codecTriggered(codec);
0154      * #endif
0155      * @endcode
0156      *
0157      * @since 5.78
0158      *
0159      * @deprecated since 5.103, use codecNameTriggered()
0160      */
0161     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 103, "Use codecNameTriggered().")
0162     void codecTriggered(QTextCodec *codec);
0163 #endif
0164 
0165 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 78)
0166     /**
0167      * Autodetection has been selected.
0168      * emits KEncodingProber::Universal if Default was selected.
0169      *
0170      * Applicable only if showAutoOptions in c'tor was true
0171      * @deprecated Since 5.78, use encodingProberTriggered(KEncodingProber::ProberType)
0172      */
0173     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 78, "Use KCodecAction::encodingProberTriggered(KEncodingProber::ProberType)")
0174     void triggered(KEncodingProber::ProberType); // clazy:exclude=overloaded-signal
0175 #endif
0176 
0177 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
0178     /**
0179      * Autodetection has been selected.
0180      * emits KEncodingProber::Universal if Default was selected.
0181      *
0182      * Applicable only if showAutoOptions in c'tor was true
0183      *
0184      * In your KCodecAction subclass to be backward-compatible to KF < 5.78, emit instead
0185      * just the deprecated signal triggered(KEncodingProber::ProberType). That will also
0186      * automatically emit encodingProberTriggered(KEncodingProber::ProberType) because this
0187      * signal is connected to the deprecated one in the KCodecAction constructor.
0188      * Only if you compile against a variant of KConfigWidgets built without all API
0189      * deprecated up to version 5.78, then emit this signal directly.
0190      * Your code would be like this:
0191      * @code
0192      * #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 78)
0193      *     // will also indirectly emit encodingProberTriggered since 5.78
0194      *     Q_EMIT triggered(encodingProber);
0195      * #else
0196      *     Q_EMIT encodingProberTriggered(encodingProber);
0197      * #endif
0198      * @endcode
0199      *
0200      * @since 5.78
0201      *
0202      * @deprecated since 5.102, no known users.
0203      */
0204     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 102, "No known users")
0205     void encodingProberTriggered(KEncodingProber::ProberType);
0206 #endif
0207 
0208     /**
0209      * Emitted when a codec was selected
0210      *
0211      * @param name the name of the selected encoding.
0212      *
0213      * Note that textTriggered(const QString &) is emitted too (as defined in KSelectAction).
0214      *
0215      * @since 5.103
0216      */
0217     void codecNameTriggered(const QString &name);
0218 
0219     /**
0220      * Emitted when the 'Default' codec action is triggered.
0221      */
0222     void defaultItemTriggered();
0223 
0224 protected Q_SLOTS:
0225     void actionTriggered(QAction *) override;
0226 
0227 protected:
0228     using KSelectAction::triggered;
0229 
0230 private:
0231     friend class KCodecActionPrivate;
0232     std::unique_ptr<class KCodecActionPrivate> const d;
0233 };
0234 
0235 #endif