File indexing completed on 2025-01-26 05:06:22
0001 /* 0002 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com> 0003 0004 Work sponsored by the LiMux project of the city of Munich. 0005 SPDX-FileContributor: Andras Mantia <andras.mantia@kdab.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <QList> 0012 #include <QObject> 0013 #include <QPointer> 0014 #include <QVariantHash> 0015 0016 #include <Plasma/Corona> 0017 0018 #include "folderplugin_private_export.h" 0019 0020 class QTimer; 0021 0022 class FOLDERPLUGIN_TESTS_EXPORT ScreenMapper : public QObject 0023 { 0024 Q_OBJECT 0025 0026 public: 0027 enum MappingSignalBehavior { 0028 DelayedSignal = 0, 0029 ImmediateSignal, 0030 }; 0031 0032 static ScreenMapper *instance(); 0033 ~ScreenMapper() override = default; 0034 0035 /** 0036 * Convert m_screenItemMap to QStringList 0037 * 0038 * The format of screenMapping is 0039 * - URL of the item 0040 * - Screen ID 0041 * - Activity ID 0042 * 0043 * @return QStringList the formatted config strings in a list 0044 */ 0045 QStringList screenMapping() const; 0046 void setScreenMapping(const QStringList &mapping); 0047 0048 int screenForItem(const QUrl &url, const QString &activity) const; 0049 void addMapping(const QUrl &url, int screen, const QString &activity, MappingSignalBehavior behavior = ImmediateSignal); 0050 void removeFromMap(const QUrl &url, const QString &activity); 0051 void setCorona(Plasma::Corona *corona); 0052 0053 void addScreen(int screenId, const QString &activity, const QUrl &screenUrl); 0054 void removeScreen(int screenId, const QString &activity, const QUrl &screenUrl); 0055 int firstAvailableScreen(const QUrl &screenUrl, const QString &activity) const; 0056 void removeItemFromDisabledScreen(const QUrl &url); 0057 0058 bool sharedDesktops() const 0059 { 0060 return m_sharedDesktops; 0061 } 0062 void setSharedDesktop(bool sharedDesktops); 0063 0064 #ifdef BUILD_TESTING 0065 void cleanup(); 0066 #endif 0067 0068 static QUrl stringToUrl(const QString &path); 0069 0070 Q_SIGNALS: 0071 void screenMappingChanged() const; 0072 void screensChanged() const; 0073 0074 private: 0075 /** 0076 * The format of DisabledScreensMap is: 0077 * - Screen ID (controlled by readingScreenId) 0078 * - Activity ID (controlled by readingActivityId) 0079 * - The number of items 0080 * - List of items 0081 * 0082 * @return QStringList the formatted config strings in a list 0083 */ 0084 QStringList disabledScreensMap() const; 0085 void saveDisabledScreensMap() const; 0086 void readDisabledScreensMap(const QStringList &serializedMap); 0087 0088 ScreenMapper(QObject *parent = nullptr); 0089 0090 QHash<std::pair<QUrl, QString /* activity ID */>, int> m_screenItemMap; 0091 // Use QSet when appropriate to improve lookup times substantially. 0092 QHash<std::pair<int /* screen */, QString /* activity ID */>, QSet<QUrl>> m_itemsOnDisabledScreensMap; 0093 QHash<QUrl, QList<std::pair<int /* screen */, QString /* activity ID */>>> m_screensPerPath; // screens per registered path 0094 QList<std::pair<int /* screen */, QString /* activity ID */>> m_availableScreens; 0095 QPointer<Plasma::Corona> m_corona; 0096 QTimer *const m_screenMappingChangedTimer; 0097 bool m_sharedDesktops = false; // all screens share the same desktops, disabling the screen mapping 0098 0099 friend class ScreenMapperTest; 0100 };