File indexing completed on 2024-05-05 04:34:54

0001 /*
0002  * SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "ShortcutActions.h"
0008 
0009 #include <QGuiApplication>
0010 
0011 #include <KLocalizedString>
0012 
0013 using namespace Qt::StringLiterals;
0014 
0015 ShortcutActions *ShortcutActions::self()
0016 {
0017     static ShortcutActions self;
0018     return &self;
0019 }
0020 
0021 ShortcutActions::ShortcutActions()
0022     : mActions{nullptr, QString()}
0023 {
0024     // everything here is named to match the jumplist actions in our .desktop file
0025     mActions.setComponentName(componentName());
0026     // qdbus org.kde.kglobalaccel /component/org_kde_spectacle_desktop org.kde.kglobalaccel.Component.shortcutNames
0027     // ActiveWindowScreenShot
0028     // WindowUnderCursorScreenShot
0029     // CurrentMonitorScreenShot
0030     // RectangularRegionScreenShot
0031     // FullScreenScreenShot
0032     // OpenWithoutScreenshot
0033     // RecordScreen
0034     // RecordWindow
0035     // RecordRegion
0036     // _launch
0037     {
0038         QAction *action = new QAction(i18n("Launch Spectacle"), &mActions);
0039         action->setObjectName(u"_launch"_s);
0040         action->setProperty("isConfigurationAction", true);
0041         mActions.addAction(action->objectName(), action);
0042     }
0043     {
0044         QAction *action = new QAction(i18n("Capture Entire Desktop"), &mActions);
0045         action->setObjectName(u"FullScreenScreenShot"_s);
0046         action->setProperty("isConfigurationAction", true);
0047         mActions.addAction(action->objectName(), action);
0048     }
0049     {
0050         QAction *action = new QAction(i18n("Capture Current Monitor"), &mActions);
0051         action->setObjectName(u"CurrentMonitorScreenShot"_s);
0052         action->setProperty("isConfigurationAction", true);
0053         mActions.addAction(action->objectName(), action);
0054     }
0055     {
0056         QAction *action = new QAction(i18n("Capture Active Window"), &mActions);
0057         action->setObjectName(u"ActiveWindowScreenShot"_s);
0058         action->setProperty("isConfigurationAction", true);
0059         mActions.addAction(action->objectName(), action);
0060     }
0061     {
0062         QAction *action = new QAction(i18n("Capture Rectangular Region"), &mActions);
0063         action->setObjectName(u"RectangularRegionScreenShot"_s);
0064         action->setProperty("isConfigurationAction", true);
0065         mActions.addAction(action->objectName(), action);
0066     }
0067     {
0068         QAction *action = new QAction(i18n("Capture Window Under Cursor"), &mActions);
0069         action->setObjectName(u"WindowUnderCursorScreenShot"_s);
0070         action->setProperty("isConfigurationAction", true);
0071         mActions.addAction(action->objectName(), action);
0072     }
0073     {
0074         QAction *action = new QAction(i18n("Record Screen"), &mActions);
0075         action->setObjectName(u"RecordScreen"_s);
0076         action->setProperty("isConfigurationAction", true);
0077         mActions.addAction(action->objectName(), action);
0078     }
0079     {
0080         QAction *action = new QAction(i18n("Record Window"), &mActions);
0081         action->setObjectName(u"RecordWindow"_s);
0082         action->setProperty("isConfigurationAction", true);
0083         mActions.addAction(action->objectName(), action);
0084     }
0085     {
0086         QAction *action = new QAction(i18n("Record Rectangular Region"), &mActions);
0087         action->setObjectName(u"RecordRegion"_s);
0088         action->setProperty("isConfigurationAction", true);
0089         mActions.addAction(action->objectName(), action);
0090     }
0091     {
0092         QAction *action = new QAction(i18n("Launch Spectacle without capturing"), &mActions);
0093         action->setObjectName(u"OpenWithoutScreenshot"_s);
0094         action->setProperty("isConfigurationAction", true);
0095         mActions.addAction(action->objectName(), action);
0096     }
0097 }
0098 
0099 KActionCollection *ShortcutActions::shortcutActions()
0100 {
0101     return &mActions;
0102 }
0103 
0104 QString ShortcutActions::componentName() const
0105 {
0106     return QGuiApplication::desktopFileName().append(u".desktop"_s);
0107 }
0108 
0109 QAction *ShortcutActions::openAction() const
0110 {
0111     return mActions.action(0);
0112 }
0113 
0114 QAction *ShortcutActions::fullScreenAction() const
0115 {
0116     return mActions.action(1);
0117 }
0118 
0119 QAction *ShortcutActions::currentScreenAction() const
0120 {
0121     return mActions.action(2);
0122 }
0123 
0124 QAction *ShortcutActions::activeWindowAction() const
0125 {
0126     return mActions.action(3);
0127 }
0128 
0129 QAction *ShortcutActions::regionAction() const
0130 {
0131     return mActions.action(4);
0132 }
0133 
0134 QAction *ShortcutActions::windowUnderCursorAction() const
0135 {
0136     return mActions.action(5);
0137 }
0138 
0139 QAction *ShortcutActions::recordScreenAction() const
0140 {
0141     return mActions.action(6);
0142 }
0143 
0144 QAction *ShortcutActions::recordWindowAction() const
0145 {
0146     return mActions.action(7);
0147 }
0148 
0149 QAction *ShortcutActions::recordRegionAction() const
0150 {
0151     return mActions.action(8);
0152 }
0153 
0154 QAction *ShortcutActions::openWithoutScreenshotAction() const
0155 {
0156     return mActions.action(9);
0157 }