File indexing completed on 2024-04-28 04:05:04

0001 /*
0002     SPDX-FileCopyrightText: 2012 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KGAMETHEME_H
0008 #define KGAMETHEME_H
0009 
0010 // own
0011 #include "kdegames_export.h"
0012 // Qt
0013 #include <QMetaType>
0014 #include <QObject>
0015 // Std
0016 #include <memory>
0017 
0018 /**
0019  * @class KGameTheme kgametheme.h <KGameTheme>
0020  *
0021  * A theme describes the visual appearance of a game. Themes in kdegames usually
0022  * reference a SVGZ file which is loaded into a KGameRenderer to provide pixmaps
0023  * for use on the game canvas.
0024  *
0025  * Themes are usually managed (and discovered) by a KGameThemeProvider.
0026  *
0027  * @section fileformat Default file format for theme descriptions
0028  *
0029  * Although KGameTheme and KGameThemeProvider do not need special theme description
0030  * files for most basic usage, there is a format for theme description files
0031  * based on the XDG Desktop File Specification. The following example shows the
0032  * recognized keys:
0033  *
0034  * @code
0035  * [KGameTheme]
0036  * VersionFormat=1
0037  * Name=Example
0038  * Description=This theme serves as an example.
0039  * License=CC-BY-SA-4.0
0040  * Copyright=1984 John Doe
0041  * Version=1.0
0042  * Website=https://theme.example
0043  * BugReportUrl=https://theme.example/newbugform
0044  * FileName=example.svgz
0045  * Author=John Doe
0046  * AuthorEmail=john.doe@example.com
0047  * Preview=example.png
0048  * @endcode
0049  *
0050  * All keys are considered optional, except perhaps for the "FileName" key: If
0051  * that is not given, the theme cannot be used with KGameRenderer. The paths in
0052  * "FileName" and "Preview" are resolved relative to the directory that contains
0053  * the theme description file.
0054  *
0055  * If the [KGameTheme] group contains any further keys, their values can be
0056  * retrieved through the KGameTheme::customData() method.
0057  */
0058 
0059 class KDEGAMES_EXPORT KGameTheme : public QObject
0060 {
0061     Q_OBJECT
0062     Q_PROPERTY(QByteArray identifier READ identifier NOTIFY readOnlyProperty)
0063     // it is not intended to allow these properties to change after the initial
0064     // setup (note how KGameThemeProvider returns only const KGameTheme*), hence
0065     // a dummy NOTIFY signal is enough
0066     Q_PROPERTY(QString name READ name WRITE setName NOTIFY readOnlyProperty)
0067     Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY readOnlyProperty)
0068     Q_PROPERTY(QString license READ license WRITE setLicense NOTIFY readOnlyProperty)
0069     Q_PROPERTY(QString copyrightText READ copyrightText WRITE setCopyrightText NOTIFY readOnlyProperty)
0070     Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY readOnlyProperty)
0071     Q_PROPERTY(QString website READ website WRITE setWebsite NOTIFY readOnlyProperty)
0072     Q_PROPERTY(QString bugReportUrl READ bugReportUrl WRITE setBugReportUrl NOTIFY readOnlyProperty)
0073     Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY readOnlyProperty)
0074     Q_PROPERTY(QString authorEmail READ authorEmail WRITE setAuthorEmail NOTIFY readOnlyProperty)
0075     Q_PROPERTY(QString graphicsPath READ graphicsPath WRITE setGraphicsPath NOTIFY readOnlyProperty)
0076     Q_PROPERTY(QString previewPath READ previewPath WRITE setPreviewPath NOTIFY readOnlyProperty)
0077     Q_DISABLE_COPY(KGameTheme)
0078 
0079 public:
0080     /// Constructor. The @a identifier must be application-unique.
0081     explicit KGameTheme(const QByteArray &identifier, QObject *parent = nullptr);
0082     /// Destructor.
0083     ~KGameTheme() override;
0084 
0085     /// Initializes a KGameTheme instance by reading a description file.
0086     /// @return whether @a path is a valid theme description file (if not,
0087     ///         the theme instance is not changed by this method call)
0088     /// @note A non-static member function has been chosen over the more
0089     ///       common pattern of using a static member function like
0090     ///       "KGameTheme::fromDesktopFile" to accommodate applications which
0091     ///       want to subclass KGameTheme.
0092     virtual bool readFromDesktopFile(const QString &path);
0093 
0094     /// @return the internal identifier for this theme (used e.g. for
0095     ///         finding a pixmap cache or storing a theme selection)
0096     QByteArray identifier() const;
0097 
0098     /// @return the name of this theme
0099     QString name() const;
0100     /// @see name()
0101     void setName(const QString &name);
0102     /// @return an additional description beyond the name()
0103     QString description() const;
0104     /// @see description()
0105     void setDescription(const QString &description);
0106     /// @return the short license identifier, as SPDX expression
0107     QString license() const;
0108     /// @see license()
0109     void setLicense(const QString &license);
0110     /// @return a short copyright statement
0111     QString copyrightText() const;
0112     /// @see copyrightText()
0113     void setCopyrightText(const QString &copyrightText);
0114     /// @return the version of the theme.
0115     QString version() const;
0116     /// @see version()
0117     void setVersion(const QString &version);
0118     /// @return the website of the theme.
0119     QString website() const;
0120     /// @see website()
0121     void setWebsite(const QString &website);
0122     /// @return the website where people can report a bug found in this theme.
0123     QString bugReportUrl() const;
0124     /// @see bugReportUrl()
0125     void setBugReportUrl(const QString &bugReportUrl);
0126     /// @return the name of the theme author
0127     QString author() const;
0128     /// @see author()
0129     void setAuthor(const QString &author);
0130     /// @return the email address of the theme author
0131     QString authorEmail() const;
0132     /// @see authorEmail()
0133     void setAuthorEmail(const QString &authorEmail);
0134 
0135     /// @return the path of the SVG file which holds the theme contents
0136     QString graphicsPath() const;
0137     /// @see graphicsPath()
0138     void setGraphicsPath(const QString &path);
0139     /// @return the path to an image file containing a preview, or an empty
0140     ///         string if no preview file is known
0141     QString previewPath() const;
0142     /// @see previewPath()
0143     void setPreviewPath(const QString &path);
0144 
0145     /// @return custom data
0146     ///
0147     /// This API is provided for theme description files which contain
0148     /// additional application-specific metadata.
0149     QMap<QString, QString> customData() const;
0150     /// This is an overloaded member function that returns a single value from the customData() map
0151     QString customData(const QString &key, const QString &defaultValue = QString()) const;
0152     /// @see customData()
0153     void setCustomData(const QMap<QString, QString> &customData);
0154 Q_SIGNALS:
0155     /// This signal is never emitted. It is provided because QML likes to
0156     /// complain about properties without NOTIFY signals, even readonly ones.
0157     void readOnlyProperty();
0158 
0159 private:
0160     std::unique_ptr<class KGameThemePrivate> const d_ptr;
0161     Q_DECLARE_PRIVATE(KGameTheme)
0162 };
0163 
0164 Q_DECLARE_METATYPE(const KGameTheme *)
0165 
0166 #endif // KGAMETHEME_H