File indexing completed on 2024-12-22 05:17:15

0001 /*
0002  * This file is part of the KDE wacomtablet project. For copyright
0003  * information and license terms see the AUTHORS and COPYING files
0004  * in the top-level directory of this distribution.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef PROPERTYADAPTOR_H
0021 #define PROPERTYADAPTOR_H
0022 
0023 #include <QList>
0024 #include <QString>
0025 
0026 #include "property.h"
0027 
0028 namespace Wacom
0029 {
0030 
0031 class PropertyAdaptorPrivate;
0032 
0033 /**
0034  * The interface class for property adaptors.
0035  *
0036  * These adaptors are used to map properties between different subsystems.
0037  * They are also used to convert property values between the internal storage
0038  * format of the adapted object and the global data format.
0039  */
0040 class PropertyAdaptor
0041 {
0042 public:
0043     /**
0044      * Default destructor
0045      */
0046     virtual ~PropertyAdaptor();
0047 
0048     /**
0049      * Gets a list of properties which can be set or get.
0050      * The default implementation tries to get a list of properties from the
0051      * adapted object or returns an empty list if no object is set.
0052      *
0053      * @return List of available config properties as string.
0054      */
0055     virtual const QList<Property> getProperties() const;
0056 
0057     /**
0058      * Gets a property value. The default implementation tries to get the value
0059      * from the adapted object and returns it as-is or returns an empty string
0060      * of no object is set.
0061      *
0062      * @param property The property to get.
0063      *
0064      * @return The property value.
0065      */
0066     virtual const QString getProperty(const Property &property) const;
0067 
0068     /**
0069      * Gets a property value as boolean. If the conversion to boolean fails,
0070      * false is returned.
0071      *
0072      * @param property The property to get.
0073      *
0074      * @return The property value as boolean or false if the value can not be converted.
0075      */
0076     virtual bool getPropertyAsBool(const Property &property) const;
0077 
0078     /**
0079      * Sets a property value. The default implementation passes the value to the
0080      * adapted object as-is or does nothing if no object is set.
0081      *
0082      * @param property The property.
0083      * @param value    The new value to set.
0084      *
0085      * @return True if the value was set, else false.
0086      */
0087     virtual bool setProperty(const Wacom::Property &property, const QString &value);
0088 
0089     /**
0090      * Checks if a property is supported by the managed object. The default
0091      * implementation tries to query the managed object or parses the output
0092      * of getProperties() to determine if the given property is supported.
0093      *
0094      * @return True if the property is supported, else false.
0095      */
0096     virtual bool supportsProperty(const Property &property) const;
0097 
0098 protected:
0099     /**
0100      * Protected default constructor.
0101      */
0102     PropertyAdaptor();
0103 
0104     /**
0105      * Constructor.
0106      *
0107      * @param adaptee The object to adapt (possibly NULL).
0108      */
0109     PropertyAdaptor(PropertyAdaptor *adaptee);
0110 
0111     /**
0112      * Gets the adaptee managed by this instance.
0113      */
0114     PropertyAdaptor *getAdaptee();
0115 
0116     /**
0117      * Gets the adaptee managed by this instance.
0118      */
0119     const PropertyAdaptor *getAdaptee() const;
0120 
0121 private:
0122     Q_DECLARE_PRIVATE(PropertyAdaptor)
0123     PropertyAdaptorPrivate *const d_ptr; /**< d-pointer for this class */
0124 
0125 }; // CLASS
0126 } // NAMESPACE
0127 #endif // HEADER PROTECTION