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

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 TABLETFINDER_H
0021 #define TABLETFINDER_H
0022 
0023 #include "tabletinformation.h"
0024 
0025 #include <QObject>
0026 
0027 namespace Wacom
0028 {
0029 
0030 class TabletFinderPrivate;
0031 
0032 /**
0033  * Uses the underlying window system and other sources to detect tablets.
0034  * This class needs the help of an event notifier which signals adding
0035  * and removal of tablet devices.
0036  */
0037 class TabletFinder : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     ~TabletFinder() override;
0043 
0044     static TabletFinder &instance();
0045 
0046     /**
0047      * Scan for devices and emit a signal for each tablet found.
0048      */
0049     bool scan();
0050 
0051 public Q_SLOTS:
0052 
0053     /**
0054      * This slot has to be connected to the event notifier.
0055      */
0056     void onX11TabletAdded(int deviceId);
0057 
0058     /**
0059      * This slot has to be connected to the event notifier.
0060      */
0061     void onX11TabletRemoved(int deviceId);
0062 
0063 Q_SIGNALS:
0064 
0065     /**
0066      * Emitted when a tablet is add.
0067      */
0068     void tabletAdded(TabletInformation tabletInformation);
0069 
0070     /**
0071      * Emitted when a tablet is removed.
0072      */
0073     void tabletRemoved(TabletInformation tabletInformation);
0074 
0075 protected:
0076     /**
0077      * Protected default constructor as this class is a singleton.
0078      */
0079     TabletFinder();
0080 
0081     /**
0082      * Looks up tablet information and button mapping from the device database.
0083      *
0084      * @param info The tablet information which will be filled with the information from the database.
0085      *
0086      * @return True on success, false on error.
0087      */
0088     bool lookupInformation(TabletInformation &info);
0089 
0090 private:
0091     /**
0092      * Copy constructor which does nothing as this class is a singleton.
0093      */
0094     explicit TabletFinder(const TabletFinder &finder) = delete;
0095 
0096     /**
0097      * Copy operator which does nothing as this class is a singleton.
0098      */
0099     TabletFinder &operator=(const TabletFinder &finder) = delete;
0100 
0101     Q_DECLARE_PRIVATE(TabletFinder)
0102     TabletFinderPrivate *const d_ptr;
0103 
0104 }; // CLASS
0105 } // NAMESPACE
0106 #endif // HEADER PROTECTION