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 PROFILEMANAGEMENT_H
0021 #define PROFILEMANAGEMENT_H
0022 
0023 #include "profilemanagementinterface.h"
0024 
0025 #include "deviceprofile.h"
0026 #include "profilemanager.h"
0027 
0028 // Qt includes
0029 #include <QString>
0030 #include <QStringList>
0031 
0032 class KConfigGroup;
0033 class QDBusInterface;
0034 
0035 namespace Wacom
0036 {
0037 /**
0038  * The profilemanagement is used as general tablet independent backend to store all parameters per profile
0039  * The KConfig approach is used to store the user data. To apply the profiles the deviceinterface has to
0040  * interpret the profile information into whatever the device backends expect.
0041  * Profiles are saved by tablet name and thus it is possible to have the same profile names for different tablets
0042  */
0043 class ProfileManagement : public ProfileManagementInterface
0044 {
0045 public:
0046     /**
0047      * Returns the instance of this singleton class.
0048      *
0049      * Asks DBus for the currently active device names
0050      */
0051     static ProfileManagement &instance();
0052 
0053     /**
0054      * @brief Returns a singleton of this class without asking DBus for devicename
0055      */
0056     static ProfileManagement &instance(const QString &deviceName, bool hasTouch);
0057 
0058     void setTabletId(const QString &tabletId) override;
0059 
0060     /**
0061      * Creates a new profile for the currently detected device and saves it back to the KConfig file
0062      *
0063      * @param profilename name of the profile that will be created
0064      */
0065     void createNewProfile(const QString &profilename) override;
0066 
0067     /**
0068      * Returns the KConfigGroup with all available profiles for the current tablet device
0069      *
0070      * This is used to fill the combobox with the profile names, create/delete profiles
0071      * and to update the configuration if something changed.
0072      *
0073      * @return the profile group object that holds all profile information.
0074      */
0075     const QStringList availableProfiles() override;
0076 
0077     /**
0078      * Deletes the profile from the current connected device.
0079      *
0080      * Should no profile be left a default profile will be created and selected.
0081      */
0082     void deleteProfile() override;
0083 
0084     /**
0085      * Returns a device profile of the currently active tablet profile.
0086      *
0087      * Always returns a device profile of the currently connected tablet. The
0088      * parameter @c device can be one of stylus/pad/eraser/touch or cursor.
0089      *
0090      * @param device The device profile to get.
0091      *
0092      * @return The device profile of the requested device.
0093      */
0094     DeviceProfile loadDeviceProfile(const DeviceType &device) override;
0095 
0096     /**
0097      * Saves the given profile as a device profile of the currently
0098      * active tablet profile.
0099      *
0100      * @param profile The profile to save.
0101      * @return True on success, false on error.
0102      */
0103     bool saveDeviceProfile(const DeviceProfile &profile) override;
0104 
0105     /**
0106      * Sets the used profile.
0107      *
0108      * If the kcmodule changes the profile the name here should change as well to obtain the
0109      * right config values
0110      *
0111      * @param name Name of the new profile
0112      */
0113     void setProfileName(const QString &name) override;
0114 
0115     /**
0116      * Returns the current used profile name.
0117      *
0118      * @return name of the profile in use
0119      */
0120     QString profileName() const override;
0121 
0122     /**
0123      * Reloads the profiles
0124      *
0125      * If the tablet is removed/connected/changed during runtime, this function updates its internal status
0126      */
0127     void reload() override;
0128 
0129 private:
0130     /**
0131      * Default constructor.
0132      * This is a singleton class, do not use this constructor, use \a instance() instead.
0133      */
0134     ProfileManagement();
0135 
0136     /**
0137      * Overloaded constructor.
0138      * This is a singleton class, do not use this constructor, use \a instance(deviceName, hasTouch) instead.
0139      */
0140     ProfileManagement(const QString &deviceName, bool hasTouch);
0141 
0142     /**
0143      * This is a singleton, no copying allowed
0144      */
0145     ProfileManagement(const ProfileManagement &) = delete;
0146     ProfileManagement &operator=(const ProfileManagement &) = delete;
0147 
0148     QString m_tabletId;
0149     QString m_vendorId;
0150     QString m_sensorId; /** Stores usb id for child device **/
0151     QString m_deviceName; /**< Cached name of the device so. So we don't have to ask via Dbus every time */
0152     bool m_hasTouch = false;
0153     QString m_profileName; /**< Current selected profile. */
0154     ProfileManager m_profileManager; /**< Manages the profile configuration file */
0155 }; // CLASS
0156 } // NAMESPACE
0157 #endif // PROFILEMANAGEMENT_H