diff --git a/containments/homescreen/CMakeLists.txt b/containments/homescreen/CMakeLists.txt index d9eedc6..4cb6f5c 100644 --- a/containments/homescreen/CMakeLists.txt +++ b/containments/homescreen/CMakeLists.txt @@ -1,25 +1,25 @@ set(homescreen_SRCS homescreen.cpp applicationlistmodel.cpp colouraverage.cpp ) add_library(plasma_containment_phone_homescreen MODULE ${homescreen_SRCS}) kcoreaddons_desktop_to_json(plasma_containment_phone_homescreen package/metadata.desktop) target_link_libraries(plasma_containment_phone_homescreen Qt5::Gui KF5::Plasma Qt5::Qml Qt5::Quick KF5::I18n KF5::Service KF5::KIOWidgets - ) +) install(TARGETS plasma_containment_phone_homescreen DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/applets) plasma_install_package(package org.kde.phone.homescreen) diff --git a/containments/homescreen/applicationlistmodel.cpp b/containments/homescreen/applicationlistmodel.cpp index ab8638b..05c56a0 100644 --- a/containments/homescreen/applicationlistmodel.cpp +++ b/containments/homescreen/applicationlistmodel.cpp @@ -1,365 +1,366 @@ /* * Copyright (C) 2014 Antonis Tsiapaliokas * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Self #include "applicationlistmodel.h" // Qt #include #include #include // KDE #include #include #include #include #include #include #include +constexpr int MAX_FAVOURITES = 5; ApplicationListModel::ApplicationListModel(HomeScreen *parent) : QAbstractListModel(parent), m_homeScreen(parent) { connect(KSycoca::self(), qOverload(&KSycoca::databaseChanged), this, &ApplicationListModel::sycocaDbChanged); loadSettings(); } -ApplicationListModel::~ApplicationListModel() -= default; +ApplicationListModel::~ApplicationListModel() = default; void ApplicationListModel::loadSettings() { m_favorites = m_homeScreen->config().readEntry("Favorites", QStringList()); #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) const auto di = m_homeScreen->config().readEntry("DesktopItems", QStringList()); m_desktopItems = QSet(di.begin(), di.end()); #else m_desktopItems = m_homeScreen->config().readEntry("DesktopItems", QStringList()).toSet(); #endif m_appOrder = m_homeScreen->config().readEntry("AppOrder", QStringList()); - m_maxFavoriteCount = m_homeScreen->config().readEntry("MaxFavoriteCount", 5); + m_maxFavoriteCount = m_homeScreen->config().readEntry("MaxFavoriteCount", MAX_FAVOURITES); int i = 0; for (const QString &app : qAsConst(m_appOrder)) { m_appPositions[app] = i; ++i; } loadApplications(); } QHash ApplicationListModel::roleNames() const { return { {ApplicationNameRole, QByteArrayLiteral("applicationName")}, {ApplicationIconRole, QByteArrayLiteral("applicationIcon")}, {ApplicationStorageIdRole, QByteArrayLiteral("applicationStorageId")}, {ApplicationEntryPathRole, QByteArrayLiteral("applicationEntryPath")}, {ApplicationOriginalRowRole, QByteArrayLiteral("applicationOriginalRow")}, {ApplicationStartupNotifyRole, QByteArrayLiteral("applicationStartupNotify")}, {ApplicationLocationRole, QByteArrayLiteral("applicationLocation")} }; } void ApplicationListModel::sycocaDbChanged(const QStringList &changes) { - if (!changes.contains("apps") && !changes.contains("xdgdata-apps")) { + if (!changes.contains(QStringLiteral("apps")) && !changes.contains(QStringLiteral("xdgdata-apps"))) { return; } m_applicationList.clear(); loadApplications(); } bool appNameLessThan(const ApplicationData &a1, const ApplicationData &a2) { return a1.name.toLower() < a2.name.toLower(); } void ApplicationListModel::loadApplications() { - auto cfg = KSharedConfig::openConfig("applications-blacklistrc"); + auto cfg = KSharedConfig::openConfig(QStringLiteral("applications-blacklistrc")); auto blgroup = KConfigGroup(cfg, QStringLiteral("Applications")); // This is only temporary to get a clue what those apps' desktop files are called // I'll remove it once I've done a blacklist QStringList bl; QStringList blacklist = blgroup.readEntry("blacklist", QStringList()); beginResetModel(); m_applicationList.clear(); KServiceGroup::Ptr group = KServiceGroup::root(); if (!group || !group->isValid()) return; KServiceGroup::List subGroupList = group->entries(true); QMap orderedList; QList unorderedList; // Iterate over all entries in the group while (!subGroupList.isEmpty()) { KSycocaEntry::Ptr groupEntry = subGroupList.first(); subGroupList.pop_front(); if (groupEntry->isType(KST_KServiceGroup)) { - KServiceGroup::Ptr serviceGroup(static_cast(groupEntry.data())); + KServiceGroup::Ptr serviceGroup(dynamic_cast(groupEntry.data())); if (!serviceGroup->noDisplay()) { KServiceGroup::List entryGroupList = serviceGroup->entries(true); for(KServiceGroup::List::ConstIterator it = entryGroupList.constBegin(); it != entryGroupList.constEnd(); it++) { KSycocaEntry::Ptr entry = (*it); if (entry->isType(KST_KServiceGroup)) { - KServiceGroup::Ptr serviceGroup(static_cast(entry.data())); + KServiceGroup::Ptr serviceGroup(dynamic_cast(entry.data())); subGroupList << serviceGroup; - } else if (entry->property("Exec").isValid()) { - KService::Ptr service(static_cast(entry.data())); + } else if (entry->property(QStringLiteral("Exec")).isValid()) { + KService::Ptr service(dynamic_cast(entry.data())); if (service->isApplication() && !blacklist.contains(service->desktopEntryName()) && service->showOnCurrentPlatform() && - !service->property("Terminal", QVariant::Bool).toBool()) { + !service->property(QStringLiteral("Terminal"), QVariant::Bool).toBool()) { bl << service->desktopEntryName(); ApplicationData data; data.name = service->name(); data.icon = service->icon(); data.storageId = service->storageId(); data.entryPath = service->exec(); - data.startupNotify = service->property("StartupNotify").toBool(); + data.startupNotify = service->property(QStringLiteral("StartupNotify")).toBool(); if (m_favorites.contains(data.storageId)) { - data.location = Favorites; + data.location = ApplicationData::Favorites; } else if (m_desktopItems.contains(data.storageId)) { - data.location = Desktop; + data.location = ApplicationData::Desktop; } auto it = m_appPositions.constFind(service->storageId()); if (it != m_appPositions.constEnd()) { orderedList[*it] = data; } else { unorderedList << data; } } } } } } } blgroup.writeEntry("allapps", bl); blgroup.writeEntry("blacklist", blacklist); cfg->sync(); std::sort(unorderedList.begin(), unorderedList.end(), appNameLessThan); m_applicationList << orderedList.values(); m_applicationList << unorderedList; endResetModel(); emit countChanged(); } QVariant ApplicationListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } switch (role) { case Qt::DisplayRole: case ApplicationNameRole: return m_applicationList.at(index.row()).name; case ApplicationIconRole: return m_applicationList.at(index.row()).icon; case ApplicationStorageIdRole: return m_applicationList.at(index.row()).storageId; case ApplicationEntryPathRole: return m_applicationList.at(index.row()).entryPath; case ApplicationOriginalRowRole: return index.row(); case ApplicationStartupNotifyRole: return m_applicationList.at(index.row()).startupNotify; case ApplicationLocationRole: return m_applicationList.at(index.row()).location; default: return QVariant(); } } Qt::ItemFlags ApplicationListModel::flags(const QModelIndex &index) const { if (!index.isValid()) - return nullptr; + return {}; return Qt::ItemIsDragEnabled|QAbstractListModel::flags(index); } int ApplicationListModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return m_applicationList.count(); } void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int sourceRow, const QModelIndex& /* destinationParent */, int destinationChild) { moveItem(sourceRow, destinationChild); } -void ApplicationListModel::setLocation(int row, LauncherLocation location) +void ApplicationListModel::setLocation(int row, ApplicationData::LauncherLocation location) { if (row < 0 || row >= m_applicationList.length()) { return; } - ApplicationData &data = m_applicationList[row]; + ApplicationData data = m_applicationList.at(row); if (data.location == location) { return; } - if (location == Favorites) {qWarning()<<"favoriting"<= m_maxFavoriteCount || m_favorites.count() >= m_maxFavoriteCount) { return; } m_favorites.insert(row, data.storageId); m_homeScreen->config().writeEntry("Favorites", m_favorites); emit favoriteCountChanged(); // Out of favorites - } else if (data.location == Favorites) { + } else if (data.location == ApplicationData::Favorites) { m_favorites.removeAll(data.storageId); m_homeScreen->config().writeEntry("Favorites", m_favorites); emit favoriteCountChanged(); } // In Desktop - if (location == Desktop) { + if (location == ApplicationData::Desktop) { m_desktopItems.insert(data.storageId); m_homeScreen->config().writeEntry("DesktopItems", m_desktopItems.values()); // Out of Desktop - } else if (data.location == Desktop) { + } else if (data.location == ApplicationData::Desktop) { m_desktopItems.remove(data.storageId); - m_homeScreen->config().writeEntry("DesktopItems", m_desktopItems.values()); + m_homeScreen->config().writeEntry(QStringLiteral("DesktopItems"), m_desktopItems.values()); } data.location = location; emit m_homeScreen->configNeedsSaving(); emit dataChanged(index(row, 0), index(row, 0)); } void ApplicationListModel::moveItem(int row, int destination) { if (row < 0 || destination < 0 || row >= m_applicationList.length() || destination >= m_applicationList.length() || row == destination) { return; } if (destination > row) { ++destination; } beginMoveRows(QModelIndex(), row, row, QModelIndex(), destination); if (destination > row) { ApplicationData data = m_applicationList.at(row); m_applicationList.insert(destination, data); m_applicationList.takeAt(row); } else { ApplicationData data = m_applicationList.takeAt(row); m_applicationList.insert(destination, data); } m_appOrder.clear(); m_appPositions.clear(); int i = 0; for (const ApplicationData &app : qAsConst(m_applicationList)) { m_appOrder << app.storageId; m_appPositions[app.storageId] = i; ++i; } m_homeScreen->config().writeEntry("AppOrder", m_appOrder); endMoveRows(); } void ApplicationListModel::runApplication(const QString &storageId) { if (storageId.isEmpty()) { return; } KService::Ptr service = KService::serviceByStorageId(storageId); KRun::runService(*service, QList(), nullptr); } int ApplicationListModel::maxFavoriteCount() const { return m_maxFavoriteCount; } void ApplicationListModel::setMaxFavoriteCount(int count) { if (m_maxFavoriteCount == count) { return; } if (m_maxFavoriteCount > count) { while (m_favorites.size() > count && m_favorites.count() > 0) { m_favorites.pop_back(); } emit favoriteCountChanged(); int i = 0; for (auto &app : m_applicationList) { - if (i >= count && app.location == Favorites) { - app.location = Grid; + if (i >= count && app.location == ApplicationData::Favorites) { + app.location = ApplicationData::Grid; emit dataChanged(index(i, 0), index(i, 0)); } ++i; } } m_maxFavoriteCount = count; m_homeScreen->config().writeEntry("MaxFavoriteCount", m_maxFavoriteCount); emit maxFavoriteCountChanged(); } #include "moc_applicationlistmodel.cpp" diff --git a/containments/homescreen/applicationlistmodel.h b/containments/homescreen/applicationlistmodel.h index c8e913a..b9eb1e8 100644 --- a/containments/homescreen/applicationlistmodel.h +++ b/containments/homescreen/applicationlistmodel.h @@ -1,117 +1,122 @@ /* * Copyright (C) 2014 Antonis Tsiapaliokas * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef APPLICATIONLISTMODEL_H #define APPLICATIONLISTMODEL_H // Qt #include #include #include #include #include "homescreen.h" class QString; class ApplicationListModel; struct ApplicationData { + enum LauncherLocation { + Grid = 0, + Favorites, + Desktop + }; QString name; QString icon; QString storageId; QString entryPath; - int location = 0; //FIXME + LauncherLocation location = Grid; bool startupNotify = true; }; class ApplicationListModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged) Q_PROPERTY(int maxFavoriteCount READ maxFavoriteCount WRITE setMaxFavoriteCount NOTIFY maxFavoriteCountChanged) public: enum LauncherLocation { - Grid = 0, - Favorites, - Desktop + Grid = ApplicationData::Grid, + Favorites = ApplicationData::Favorites, + Desktop = ApplicationData::Desktop }; Q_ENUM(LauncherLocation) enum Roles { ApplicationNameRole = Qt::UserRole + 1, ApplicationIconRole, ApplicationStorageIdRole, ApplicationEntryPathRole, ApplicationOriginalRowRole, ApplicationStartupNotifyRole, ApplicationLocationRole }; ApplicationListModel(HomeScreen *parent = nullptr); ~ApplicationListModel() override; void loadSettings(); int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild); int count() const { return m_applicationList.count(); } int favoriteCount() const { return m_favorites.count();} int maxFavoriteCount() const; void setMaxFavoriteCount(int count); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &index) const override; QHash roleNames() const Q_DECL_OVERRIDE; - Q_INVOKABLE void setLocation(int row, ApplicationListModel::LauncherLocation location); + Q_INVOKABLE void setLocation(int row, ApplicationData::LauncherLocation location); - Q_INVOKABLE void moveItem(int row, int order); + Q_INVOKABLE void moveItem(int row, int destination); Q_INVOKABLE void runApplication(const QString &storageId); Q_INVOKABLE void loadApplications(); public Q_SLOTS: void sycocaDbChanged(const QStringList &change); Q_SIGNALS: void countChanged(); void favoriteCountChanged(); void maxFavoriteCountChanged(); private: QList m_applicationList; HomeScreen *m_homeScreen = nullptr; int m_maxFavoriteCount = 0; QStringList m_appOrder; QStringList m_favorites; QSet m_desktopItems; QHash m_appPositions; }; #endif // APPLICATIONLISTMODEL_H diff --git a/containments/homescreen/colouraverage.cpp b/containments/homescreen/colouraverage.cpp index 81b43ad..1e269ed 100644 --- a/containments/homescreen/colouraverage.cpp +++ b/containments/homescreen/colouraverage.cpp @@ -1,57 +1,58 @@ /*************************************************************************** * Copyright (C) 2019 Carson Black * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include #include #include #include -#include #include "colouraverage.h" -ColourAverage::ColourAverage(QObject* parent) : QObject(parent) {} +ColourAverage::ColourAverage(QObject *parent) : QObject(parent) +{ +} -QColor ColourAverage::averageColour(QImage img) { +QColor ColourAverage::averageColour(const QImage &img) { int r = 0; int g = 0; int b = 0; int c = 0; for (int i = 0; i < img.width(); i++) { for (int ii = 0; ii < img.height(); ii++) { QRgb pix = img.pixel(i, ii); if (pix == 0) continue; c++; r += qRed(pix); g += qGreen(pix); b += qBlue(pix); } } r = r / c; g = g / c; b = b / c; QColor color = QColor::fromRgb(r,g,b); color.setHsv(color.hue(), color.saturation() / 4, color.value()); return color; } diff --git a/containments/homescreen/colouraverage.h b/containments/homescreen/colouraverage.h index 609f138..0d15f53 100644 --- a/containments/homescreen/colouraverage.h +++ b/containments/homescreen/colouraverage.h @@ -1,31 +1,32 @@ /*************************************************************************** * Copyright (C) 2019 Carson Black * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #pragma once #include #include #include class ColourAverage : public QObject { Q_OBJECT + public: - explicit ColourAverage(QObject* parent = nullptr); - Q_INVOKABLE QColor averageColour(QImage img); + explicit ColourAverage(QObject *parent = nullptr); + Q_INVOKABLE QColor averageColour(const QImage &img); }; diff --git a/containments/homescreen/homescreen.cpp b/containments/homescreen/homescreen.cpp index c006de8..318b0e8 100644 --- a/containments/homescreen/homescreen.cpp +++ b/containments/homescreen/homescreen.cpp @@ -1,82 +1,77 @@ /*************************************************************************** * Copyright (C) 2015 Marco Martin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "homescreen.h" #include "applicationlistmodel.h" #include "colouraverage.h" #include #include #include HomeScreen::HomeScreen(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) { qmlRegisterUncreatableType("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel")); - qmlRegisterSingletonType("org.kde.phone.homescreen", 1, 0, "ColourAverage", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - - ColourAverage *obj = new ColourAverage(); - return obj; + qmlRegisterSingletonType("org.kde.phone.homescreen", 1, 0, "ColourAverage", [](QQmlEngine *, QJSEngine *) -> QObject * { + return new ColourAverage(); }); setHasConfigurationInterface(true); } -HomeScreen::~HomeScreen() -= default; +HomeScreen::~HomeScreen() = default; void HomeScreen::configChanged() { Plasma::Containment::configChanged(); if (m_applicationListModel) { m_applicationListModel->loadSettings(); } } ApplicationListModel *HomeScreen::applicationListModel() { if (!m_applicationListModel) { m_applicationListModel = new ApplicationListModel(this); } return m_applicationListModel; } void HomeScreen::stackBefore(QQuickItem *item1, QQuickItem *item2) { if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) { return; } item1->stackBefore(item2); } void HomeScreen::stackAfter(QQuickItem *item1, QQuickItem *item2) { if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) { return; } item1->stackAfter(item2); } K_EXPORT_PLASMA_APPLET_WITH_JSON(homescreen, HomeScreen, "metadata.json") #include "homescreen.moc" diff --git a/containments/panel/phonepanel.cpp b/containments/panel/phonepanel.cpp index e61cf95..651a77f 100644 --- a/containments/panel/phonepanel.cpp +++ b/containments/panel/phonepanel.cpp @@ -1,137 +1,138 @@ /*************************************************************************** * Copyright (C) 2015 Marco Martin * * Copyright (C) 2018 Bhushan Shah * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "phonepanel.h" #include #include #include #include #include #include #include #include #include "screenshotinterface.h" +constexpr int SCREENSHOT_DELAY = 200; + PhonePanel::PhonePanel(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) { //setHasConfigurationInterface(true); } -PhonePanel::~PhonePanel() -= default; +PhonePanel::~PhonePanel() = default; void PhonePanel::executeCommand(const QString &command) { - qWarning()<<"Executing"< we need to use screenshot area // this won't work with multiple screens QSize screenSize = QGuiApplication::primaryScreen()->size(); QDBusPendingReply reply = interface->screenshotArea(0, 0, screenSize.width(), screenSize.height()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + auto *watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (reply.isError()) { qWarning() << "Creating the screenshot failed:" << reply.error().name() << reply.error().message(); } else { QString filePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); if (filePath.isEmpty()) { qWarning() << "Couldn't find a writable location for the screenshot! The screenshot is in /tmp."; return; } QDir picturesDir(filePath); if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) { qWarning() << "Couldn't create folder at" << picturesDir.path() + QStringLiteral("/Screenshots") << "to take screenshot."; return; } filePath += QStringLiteral("/Screenshots/Screenshot_%1.png") .arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss"))); const QString currentPath = reply.argumentAt<0>(); QtConcurrent::run(QThreadPool::globalInstance(), [=]() { QFile screenshotFile(currentPath); if (!screenshotFile.rename(filePath)) { qWarning() << "Couldn't move screenshot into Pictures folder:" << screenshotFile.errorString(); } qDebug() << "Successfully saved screenshot at" << filePath; }); } watcher->deleteLater(); interface->deleteLater(); }); }); } K_EXPORT_PLASMA_APPLET_WITH_JSON(quicksettings, PhonePanel, "metadata.json") #include "phonepanel.moc" diff --git a/containments/taskpanel/taskpanel.cpp b/containments/taskpanel/taskpanel.cpp index 174a998..78bed31 100644 --- a/containments/taskpanel/taskpanel.cpp +++ b/containments/taskpanel/taskpanel.cpp @@ -1,203 +1,202 @@ /*************************************************************************** * Copyright (C) 2015 Marco Martin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "taskpanel.h" #include #include #include #include #include #include #include #include #include #include #include static const QString s_kwinService = QStringLiteral("org.kde.KWin"); +constexpr int ACTIVE_WINDOW_UPDATE_INVERVAL = 250; TaskPanel::TaskPanel(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) , m_showingDesktop(false) , m_windowManagement(nullptr) { setHasConfigurationInterface(true); m_activeTimer = new QTimer(this); m_activeTimer->setSingleShot(true); - m_activeTimer->setInterval(250); + m_activeTimer->setInterval(ACTIVE_WINDOW_UPDATE_INVERVAL); connect(m_activeTimer, &QTimer::timeout, this, &TaskPanel::updateActiveWindow); initWayland(); } -TaskPanel::~TaskPanel() -{ -} +TaskPanel::~TaskPanel() = default; void TaskPanel::requestShowingDesktop(bool showingDesktop) { if (!m_windowManagement) { return; } m_windowManagement->setShowingDesktop(showingDesktop); } void TaskPanel::initWayland() { if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) { return; } using namespace KWayland::Client; ConnectionThread *connection = ConnectionThread::fromApplication(this); if (!connection) { return; } auto *registry = new Registry(this); registry->create(connection); connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry] (quint32 name, quint32 version) { m_windowManagement = registry->createPlasmaWindowManagement(name, version, this); qRegisterMetaType >("QVector"); connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, [this] (bool showing) { if (showing == m_showingDesktop) { return; } m_showingDesktop = showing; emit showingDesktopChanged(m_showingDesktop); } ); //FIXME //connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow, Qt::QueuedConnection); connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged, m_activeTimer, qOverload<>(&QTimer::start)); updateActiveWindow(); } ); connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry] (quint32 name, quint32 version) { m_shellInterface = registry->createPlasmaShell(name, version, this); if (!m_panel) { return; } Surface *s = Surface::fromWindow(m_panel); if (!s) { return; } m_shellSurface = m_shellInterface->createSurface(s, this); m_shellSurface->setSkipTaskbar(true); } ); registry->setup(); connection->roundtrip(); } QWindow *TaskPanel::panel() { return m_panel; } void TaskPanel::setPanel(QWindow *panel) { if (panel == m_panel) { return; } if (m_panel) { disconnect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility); } m_panel = panel; connect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility, Qt::QueuedConnection); emit panelChanged(); updatePanelVisibility(); } void TaskPanel::updatePanelVisibility() { using namespace KWayland::Client; if (!m_panel->isVisible()) { return; } Surface *s = Surface::fromWindow(m_panel); if (!s) { return; } m_shellSurface = m_shellInterface->createSurface(s, this); if (m_shellSurface) { m_shellSurface->setSkipTaskbar(true); } } void TaskPanel::updateActiveWindow() { if (!m_windowManagement || m_activeWindow == m_windowManagement->activeWindow()) { return; } if (m_activeWindow) { disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow); } m_activeWindow = m_windowManagement->activeWindow(); if (m_activeWindow) { connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow); } // TODO: connect to closeableChanged, not needed right now as KWin doesn't provide this changeable emit hasCloseableActiveWindowChanged(); } bool TaskPanel::hasCloseableActiveWindow() const { return m_activeWindow && m_activeWindow->isCloseable() /*&& !m_activeWindow->isMinimized()*/; } void TaskPanel::forgetActiveWindow() { if (m_activeWindow) { disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow); } m_activeWindow.clear(); emit hasCloseableActiveWindowChanged(); } void TaskPanel::closeActiveWindow() { if (m_activeWindow) { m_activeWindow->requestClose(); } } K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json") #include "taskpanel.moc"