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

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 XSETWACOMADAPTOR_H
0021 #define XSETWACOMADAPTOR_H
0022 
0023 #include <QMap>
0024 #include <QString>
0025 
0026 #include "propertyadaptor.h"
0027 
0028 namespace Wacom
0029 {
0030 
0031 // Forward Declarations
0032 class XsetwacomProperty;
0033 class XsetwacomAdaptorPrivate;
0034 
0035 /**
0036  * A property adaptor which uses xsetwacom to set properties on a tablet.
0037  */
0038 class XsetwacomAdaptor : public PropertyAdaptor
0039 {
0040 public:
0041     //! Default constructor.
0042     explicit XsetwacomAdaptor(const QString &deviceName);
0043 
0044     XsetwacomAdaptor(const QString &deviceName, const QMap<QString, QString> &buttonMap);
0045 
0046     //! Destructor
0047     ~XsetwacomAdaptor() override;
0048 
0049     /**
0050      * @sa PropertyAdaptor::getProperties()
0051      */
0052     const QList<Property> getProperties() const override;
0053 
0054     /**
0055      * @sa PropertyAdaptor::getProperty(const Property&)
0056      */
0057     const QString getProperty(const Property &property) const override;
0058 
0059     /**
0060      * @sa PropertyAdaptor::setProperty(const Property&, const QString&)
0061      */
0062     bool setProperty(const Wacom::Property &property, const QString &value) override;
0063 
0064     /**
0065      * @sa PropertyAdaptor::supportsProperty(const Property&)
0066      */
0067     bool supportsProperty(const Property &property) const override;
0068 
0069 private:
0070     /**
0071      * Does any necessary conversion of the xsetwacom parameter.
0072      *
0073      * @param param The parameter to convert.
0074      *
0075      * @return The converted parameter.
0076      */
0077     const QString convertParameter(const XsetwacomProperty &param) const;
0078 
0079     /**
0080      * Makes sure a button shortcut is in the correct format. The result of the
0081      * conversion will be stored in the \a value parameter. If the property is
0082      * not a button shortcut, the value is left untouched.
0083      *
0084      * @param value The shortcut to validate.
0085      */
0086     void convertButtonShortcut(const XsetwacomProperty &property, QString &value) const;
0087 
0088     /**
0089      * Converts a value from xsetwacom format to internal format.
0090      *
0091      * @param property The property this value belongs to.
0092      * @param value    The value of the property. This will also contain the result of the conversion.
0093      */
0094     void convertFromXsetwacomValue(const XsetwacomProperty &property, QString &value) const;
0095 
0096     /**
0097      * Converts a value from internal format to xsetwacom format.
0098      *
0099      * @param property The property the value belongs to.
0100      * @param value    The value of the property. This will also contain the result of the conversion.
0101      */
0102     void convertToXsetwacomValue(const XsetwacomProperty &property, QString &value) const;
0103 
0104     /**
0105      * Gets a parameter using the xsetwacom command line tool. All parameters to this
0106      * method as well as the device name have to be in a format which is understood
0107      * by xsetwacom.
0108      *
0109      * @param device The device to get the parameter from.
0110      * @param param  The parameter to get.
0111      */
0112     const QString getParameter(const QString &device, const QString &param) const;
0113 
0114     /**
0115      * Sets the usable tablet area.
0116      */
0117     bool setArea(const QString &value);
0118 
0119     /**
0120      * Sets the tablet rotation.
0121      */
0122     bool setRotation(const QString &value);
0123 
0124     /**
0125      * Sets a parameter using the xsetwacom command line tool. All parameters, values and
0126      * device names passed to this method have to be in a format which is understood by
0127      * xsetwacom.
0128      *
0129      * @param device The device to set the parameter for.
0130      * @param param  The parameter to set.
0131      * @param value  The new value of the parameter.
0132      */
0133     bool setParameter(const QString &device, const QString &param, const QString &value) const;
0134 
0135     Q_DECLARE_PRIVATE(XsetwacomAdaptor)
0136     XsetwacomAdaptorPrivate *const d_ptr; /**< d-pointer for this class */
0137 
0138 }; // CLASS
0139 } // NAMESPACE
0140 #endif // HEADER PROTECTION