File indexing completed on 2024-12-15 04:54:40

0001 /******************************************************************************
0002  *
0003  *  SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  *******************************************************************************/
0008 
0009 #pragma once
0010 
0011 #include <QString>
0012 
0013 class QDataStream;
0014 
0015 namespace MessageList
0016 {
0017 namespace Core
0018 {
0019 /**
0020  * A set of options that can be applied to the MessageList in one shot.
0021  * In the sources and in the user interface you can find this set of options
0022  * referred also as "View Mode" or "Preset".
0023  *
0024  * The option set has a name and an unique id that identifies it. The name
0025  * is shown to the user in the combo box above the message list view.
0026  * The set has also a description that is shown as tooltip and should explain
0027  * the purpose, the best usage cases, eventually the advantages and disadvantages.
0028  *
0029  * The option set can be "packed" to a string and "unpacked" from a string. This
0030  * is basically for storing it in a configuration file.
0031  */
0032 class OptionSet
0033 {
0034 public:
0035     explicit OptionSet();
0036     explicit OptionSet(const OptionSet &src);
0037     explicit OptionSet(const QString &name, const QString &description, bool readOnly = false);
0038     virtual ~OptionSet();
0039 
0040 protected:
0041     QString mId;
0042     QString mName;
0043     QString mDescription;
0044     bool mReadOnly = false;
0045 
0046 public:
0047     /**
0048      * Returns the unique id of this OptionSet.
0049      * The id can't be set. It's either automatically generated or loaded from configuration.
0050      */
0051     const QString &id() const
0052     {
0053         return mId;
0054     }
0055 
0056     /**
0057      * Returns the name of this OptionSet
0058      */
0059     const QString &name() const
0060     {
0061         return mName;
0062     }
0063 
0064     /**
0065      * Sets the name of this OptionSet. You must take care
0066      * of specifying an _unique_ name in order for the Manager to
0067      * store the sets properly.
0068      */
0069     void setName(const QString &name)
0070     {
0071         mName = name;
0072     }
0073 
0074     /**
0075      * Returns a description of this option set. Ideally it should contain
0076      * its purpose and what to expect from it. But in the end we'll show
0077      * whatever the user will put in here.
0078      */
0079     const QString &description() const
0080     {
0081         return mDescription;
0082     }
0083 
0084     /**
0085      * Sets the description for this option set.
0086      */
0087     void setDescription(const QString &description)
0088     {
0089         mDescription = description;
0090     }
0091 
0092     /**
0093      * Packs this configuration object into a string suitable for storing
0094      * in a config file.
0095      */
0096     QString saveToString() const;
0097 
0098     /**
0099      * Attempts to unpack this configuration object from a string (that is
0100      * likely to come out from a config file). Returns true if the string
0101      * was in a valid format and the load operation succeeded, false otherwise.
0102      */
0103     bool loadFromString(const QString &data);
0104 
0105     /**
0106      * (Re)generates a (hopefully) unique identifier for this option set.
0107      * Please note that this function is reserved to this class and to
0108      * Configure*Dialog instances which need it for cloning option sets.
0109      * You shouldn't need to call it.
0110      */
0111     void generateUniqueId();
0112 
0113     bool readOnly() const
0114     {
0115         return mReadOnly;
0116     }
0117 
0118     void setReadOnly(bool b)
0119     {
0120         mReadOnly = b;
0121     }
0122 
0123 protected:
0124     /**
0125      * Saves the inner contents of this option set to the specified data stream.
0126      * The implementation of this method MUST be provided by derived classes.
0127      */
0128     virtual void save(QDataStream &s) const = 0;
0129 
0130     /**
0131      * Loads the inner contents of this option set from the specified data stream.
0132      * The implementation of this method MUST be provided by derived classes
0133      * and must return true in case of success and false in case of load failure.
0134      */
0135     virtual bool load(QDataStream &s) = 0;
0136 };
0137 } // namespace Core
0138 } // namespace MessageList