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

0001 /*
0002     SPDX-FileCopyrightText: 2000-2003 Matthias Hoelzer-Kluepfel <mhk@kde.org>
0003     SPDX-FileCopyrightText: 2000-2003 Tobias Koenig <tokoe@kde.org>
0004     SPDX-FileCopyrightText: 2000-2003 Daniel Molkentin <molkentin@kde.org>
0005 
0006     SPDX-License-Identifier: MIT
0007 */
0008 
0009 #ifndef KTIP_H
0010 #define KTIP_H
0011 
0012 #include <QDialog>
0013 #include <QStringList>
0014 #include <memory>
0015 
0016 #include <kconfigwidgets_export.h>
0017 
0018 #if KCONFIGWIDGETS_ENABLE_DEPRECATED_SINCE(5, 83)
0019 
0020 /**
0021  * A database for tips-of-the-day.
0022  *
0023  * This class provides convenient access to a database containing
0024  * tips of the day. The database is stored in a XML file and parsed
0025  * when a KTipDatabase object is created.
0026  *
0027  * Once the file is read in, you can access the tips to display
0028  * them in the tip of the day dialog.
0029  *
0030  * The state of the tipdialog is saved to the applications's config file
0031  * in the group "TipOfDay" with a bool entry "RunOnStart". Check this value
0032  * if you want to allow the user to enable/disable the tipdialog in the
0033  * application's configuration dialog.
0034  *
0035  * \image html ktip.png "KDE Tip-of-the-Day Dialog"
0036  *
0037  * @author Matthias Hoelzer-Kluepfel <mhk@kde.org>
0038  *
0039  * @deprecated Since 5.83, write the information to the handbook instead
0040  */
0041 class KCONFIGWIDGETS_EXPORT KTipDatabase
0042 {
0043 public:
0044     /**
0045      * This constructor reads in the tips from a file with the given name. If
0046      * no name is given, a file called 'application-name/tips' will be loaded.
0047      *
0048      * @param tipFile The absolute path to the tips file.
0049      * @deprecated Since 5.83, write the information to the handbook instead
0050      */
0051     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 83, "write the information to the handbook instead")
0052     explicit KTipDatabase(const QString &tipFile = QString());
0053 
0054     /**
0055      * This constructor takes a list of files that will be merged. This constructor
0056      * essentially behaves like the one above. It returns when tipFiles is empty.
0057      *
0058      * @param tipFiles A list of absolute paths to the tips file
0059      * @deprecated Since 5.83, write the information to the handbook instead
0060      */
0061     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 83, "write the information to the handbook instead")
0062     explicit KTipDatabase(const QStringList &tipFiles);
0063 
0064     ~KTipDatabase();
0065 
0066     /**
0067      * Returns the current tip.
0068      */
0069     QString tip() const;
0070 
0071     /**
0072      * The next tip will become the current one.
0073      */
0074     void nextTip();
0075 
0076     /**
0077      * The previous tip will become the current one.
0078      */
0079     void prevTip();
0080 
0081 private:
0082     std::unique_ptr<class KTipDatabasePrivate> const d;
0083 
0084     Q_DISABLE_COPY(KTipDatabase)
0085 };
0086 
0087 /**
0088  * @class KTipDialog ktipdialog.h KTipDialog
0089  *
0090  * A Tip-of-the-Day dialog.
0091  *
0092  * This dialog class presents a tip-of-the-day.
0093  *
0094  * The tips will be looked up for translation using gettext
0095  * with KLocalizedString::applicationDomain() as domain.
0096  *
0097  * @author Matthias Hoelzer-Kluepfel <mhk@caldera.de>
0098  */
0099 class KCONFIGWIDGETS_EXPORT KTipDialog : public QDialog
0100 {
0101     Q_OBJECT
0102 
0103 public:
0104     /**
0105      * Construct a tip dialog.
0106      *
0107      * @param database TipDatabase that should be used by the TipDialog. The KTipDialog
0108      *                 will take ownership of the database, including deleting it.
0109      * @param parent Parent widget of TipDialog.
0110      * @deprecated Since 5.83, write the information to the handbook instead
0111      */
0112     explicit KTipDialog(KTipDatabase *database, QWidget *parent = nullptr);
0113 
0114     /**
0115      * Destroys the tip dialog.
0116      */
0117     ~KTipDialog() override;
0118 
0119     /**
0120      * Shows a tip.
0121      *
0122      * This static method is all that is needed to add a tip-of-the-day
0123      * dialog to an application. It will pop up the dialog, unless the
0124      * user has asked that the dialog does not pop up on startup.
0125      *
0126      * Note that you probably want an item in the help menu calling
0127      * this method with force=true.
0128      *
0129      * @param parent Parent widget of TipDialog.
0130      * @param tipFile The name of the tip file. It has be relative to the GenericDataLocation
0131      *                resource of QStandardPaths.
0132      * @param force If true, the dialog is show, even when the users
0133      *              disabled it.
0134      */
0135     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 83, "write the information to the handbook instead")
0136     static void showTip(QWidget *parent, const QString &tipFile = QString(), bool force = false);
0137 
0138     /**
0139      * Shows a tip
0140      *
0141      * This method behaves essentially as the one above, but expects a list of tips
0142      *
0143      * @param parent Parent widget of TipDialog.
0144      * @param tipFiles A List of tip files. Each has be relative to the GenericDataLocation
0145      *                resource of QStandardPaths.
0146      * @param force If true, the dialog is show, even when the users
0147      *              disabled it.
0148      * @deprecated Since 5.83, write the information to the handbook instead
0149      */
0150     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 83, "write the information to the handbook instead")
0151     static void showMultiTip(QWidget *parent, const QStringList &tipFiles, bool force = false);
0152 
0153     /**
0154      * Shows a tip.
0155      *
0156      * This methods calls showTip() with the applications main window as parent.
0157      *
0158      * @deprecated Since 5.83, write the information to the handbook instead
0159      */
0160     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 83, "write the information to the handbook instead")
0161     static void showTip(const QString &tipFile = QString(), bool force = false);
0162 
0163     /**
0164      * Toggles the start behavior.
0165      *
0166      * Normally, the user can disable the display of the tip in the dialog.
0167      * This is just a way to change this setting from outside.
0168      * @deprecated Since 5.83, write the information to the handbook instead
0169      */
0170     KCONFIGWIDGETS_DEPRECATED_VERSION(5, 83, "write the information to the handbook instead")
0171     static void setShowOnStart(bool show);
0172 
0173 protected:
0174     bool eventFilter(QObject *, QEvent *) override;
0175 
0176 private:
0177     std::unique_ptr<class KTipDialogPrivate> const d;
0178 
0179     Q_DISABLE_COPY(KTipDialog)
0180 };
0181 
0182 #endif
0183 #endif