File indexing completed on 2024-05-05 05:38:21
0001 /* 0002 SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KConfigGroup> 0010 #include <KConfigWatcher> 0011 #include <KPluginMetaData> 0012 #include <KSharedConfig> 0013 #include <PlasmaActivities/Consumer> 0014 #include <QQuickView> 0015 0016 #include <PlasmaQuick/PlasmaWindow> 0017 #include <PlasmaQuick/SharedQmlEngine> 0018 0019 using namespace Qt::StringLiterals; 0020 0021 class X11WindowScreenRelativePositioner; 0022 class ViewPrivate; 0023 0024 class View : public PlasmaQuick::PlasmaWindow 0025 { 0026 Q_OBJECT 0027 Q_CLASSINFO("D-Bus Interface", "org.kde.krunner.App") 0028 0029 Q_PROPERTY(bool pinned READ pinned WRITE setPinned NOTIFY pinnedChanged) 0030 Q_PROPERTY(bool helpEnabled READ helpEnabled NOTIFY helpEnabledChanged) 0031 Q_PROPERTY(bool retainPriorSearch READ retainPriorSearch NOTIFY retainPriorSearchChanged) 0032 Q_PROPERTY(HistoryBehavior historyBehavior READ historyBehavior NOTIFY historyBehaviorChanged) 0033 Q_PROPERTY(QStringList favoriteIds MEMBER m_favoriteIds NOTIFY favoriteIdsChanged) 0034 0035 public: 0036 explicit View(PlasmaQuick::SharedQmlEngine *engine, QWindow *parent = nullptr); 0037 ~View() override; 0038 0039 enum HistoryBehavior { 0040 Disabled, 0041 ImmediateCompletion, 0042 CompletionSuggestion, 0043 }; 0044 Q_ENUM(HistoryBehavior) 0045 0046 void positionOnScreen(); 0047 0048 bool freeFloating() const; 0049 void setFreeFloating(bool floating); 0050 0051 bool pinned() const; 0052 void setPinned(bool pinned); 0053 0054 bool helpEnabled() 0055 { 0056 const static auto metaData = KPluginMetaData(u"kf6/krunner/helprunner"_s); 0057 const KConfigGroup grp = KSharedConfig::openConfig()->group(u"Plugins"_s); 0058 return metaData.isEnabled(grp); 0059 } 0060 HistoryBehavior historyBehavior() 0061 { 0062 return m_historyBehavior; 0063 } 0064 void setHistoryBehavior(HistoryBehavior behavior) 0065 { 0066 m_historyBehavior = behavior; 0067 Q_EMIT historyBehaviorChanged(); 0068 } 0069 Q_SIGNAL void historyBehaviorChanged(); 0070 0071 Q_SIGNAL void retainPriorSearchChanged(); 0072 bool retainPriorSearch() const 0073 { 0074 return m_retainPriorSearch; 0075 } 0076 void setRetainPriorSearch(bool retain) 0077 { 0078 m_retainPriorSearch = retain; 0079 Q_EMIT retainPriorSearchChanged(); 0080 } 0081 0082 Q_SIGNAL void favoriteIdsChanged(); 0083 void assignFavoriteIds() 0084 { 0085 const KConfigGroup grp = m_config.parent().group(u"Plugins"_s).group(u"Favorites"_s); 0086 m_favoriteIds = grp.readEntry("plugins", QStringList(u"krunner_services"_s)); 0087 Q_EMIT favoriteIdsChanged(); 0088 } 0089 0090 Q_SIGNALS: 0091 void pinnedChanged(); 0092 void helpEnabledChanged(); 0093 void activityChanged(const QString &activity); 0094 0095 protected: 0096 void showEvent(QShowEvent *event) override; 0097 0098 public Q_SLOTS: 0099 void display(); 0100 void toggleDisplay(); 0101 void displaySingleRunner(const QString &runnerName); 0102 void displayWithClipboardContents(); 0103 void query(const QString &term); 0104 void querySingleRunner(const QString &runnerName, const QString &term); 0105 0106 protected Q_SLOTS: 0107 void loadConfig(); 0108 void objectIncubated(); 0109 void slotFocusWindowChanged(); 0110 0111 private: 0112 void writeHistory(); 0113 QPoint m_customPos; 0114 PlasmaQuick::SharedQmlEngine *m_engine; 0115 KConfigGroup m_config; 0116 KConfigGroup m_stateData; 0117 KConfigWatcher::Ptr m_configWatcher; 0118 bool m_floating = false; 0119 bool m_pinned = false; 0120 bool m_retainPriorSearch = false; 0121 bool m_requestedClipboardSelection = false; 0122 QStringList m_history; 0123 QStringList m_favoriteIds; 0124 X11WindowScreenRelativePositioner *m_x11Positioner = nullptr; 0125 HistoryBehavior m_historyBehavior = HistoryBehavior::CompletionSuggestion; 0126 KActivities::Consumer m_consumer; 0127 };