File indexing completed on 2024-04-21 16:17:13

0001 /*
0002 *  Copyright 2019  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock 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 *  Latte-Dock 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 SHORTCUTSTRACKER_H
0021 #define SHORTCUTSTRACKER_H
0022 
0023 // Qt
0024 #include <QObject>
0025 
0026 // KDE
0027 #include <KSharedConfig>
0028 
0029 namespace Latte {
0030 namespace ShortcutsPart {
0031 
0032 class ShortcutsTracker: public QObject {
0033     Q_OBJECT
0034     Q_PROPERTY(bool basedOnPositionEnabled READ basedOnPositionEnabled NOTIFY badgesForActivateChanged)
0035     Q_PROPERTY(QStringList badgesForActivate READ badgesForActivate NOTIFY badgesForActivateChanged)
0036 
0037 public:
0038     ShortcutsTracker(QObject *parent);
0039     ~ShortcutsTracker() override;
0040 
0041     void clearAllAppletShortcuts();
0042 
0043     bool basedOnPositionEnabled() const;
0044 
0045     QStringList badgesForActivate() const;
0046 
0047     QList<int> appletsWithPlasmaShortcuts();
0048 
0049 public slots:
0050     Q_INVOKABLE QString appletShortcutBadge(int appletId);
0051 
0052 signals:
0053     void badgesForActivateChanged();
0054 
0055 private slots:
0056     void shortcutsFileChanged(const QString &file);
0057 
0058 private:
0059     void initGlobalShortcutsWatcher();
0060     //! access user set global shortcuts for activate entries
0061     void parseGlobalShortcuts();
0062 
0063     QString shortcutToBadge(QStringList shortcutRecords);
0064 
0065 private:
0066     bool m_basedOnPositionEnabled{false};
0067 
0068     QStringList m_badgesForActivate;
0069 
0070     //! shortcuts assigned to applets through plasma infrastructure
0071     //! <applet id, shortcut>
0072     QHash<int, QString> m_appletShortcuts;
0073 
0074     KSharedConfig::Ptr m_shortcutsConfigPtr;
0075 };
0076 
0077 }
0078 }
0079 
0080 #endif