Commit d2b461e1 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳 Committed by Nicolas Fella

containments: Optimization

parent c43777d1
......@@ -16,7 +16,7 @@ target_link_libraries(plasma_containment_phone_homescreen
KF5::I18n
KF5::Service
KF5::KIOWidgets
)
)
install(TARGETS plasma_containment_phone_homescreen DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/applets)
......
......@@ -34,6 +34,7 @@
#include <KIOWidgets/KRun>
#include <QDebug>
constexpr int MAX_FAVOURITES = 5;
ApplicationListModel::ApplicationListModel(HomeScreen *parent)
: QAbstractListModel(parent),
......@@ -45,8 +46,7 @@ ApplicationListModel::ApplicationListModel(HomeScreen *parent)
loadSettings();
}
ApplicationListModel::~ApplicationListModel()
= default;
ApplicationListModel::~ApplicationListModel() = default;
void ApplicationListModel::loadSettings()
{
......@@ -58,7 +58,7 @@ void ApplicationListModel::loadSettings()
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)) {
......@@ -84,7 +84,7 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
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;
}
......@@ -100,7 +100,7 @@ bool appNameLessThan(const ApplicationData &a1, const ApplicationData &a2)
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
......@@ -127,7 +127,7 @@ void ApplicationListModel::loadApplications()
subGroupList.pop_front();
if (groupEntry->isType(KST_KServiceGroup)) {
KServiceGroup::Ptr serviceGroup(static_cast<KServiceGroup* >(groupEntry.data()));
KServiceGroup::Ptr serviceGroup(dynamic_cast<KServiceGroup* >(groupEntry.data()));
if (!serviceGroup->noDisplay()) {
KServiceGroup::List entryGroupList = serviceGroup->entries(true);
......@@ -136,16 +136,16 @@ void ApplicationListModel::loadApplications()
KSycocaEntry::Ptr entry = (*it);
if (entry->isType(KST_KServiceGroup)) {
KServiceGroup::Ptr serviceGroup(static_cast<KServiceGroup* >(entry.data()));
KServiceGroup::Ptr serviceGroup(dynamic_cast<KServiceGroup* >(entry.data()));
subGroupList << serviceGroup;
} else if (entry->property("Exec").isValid()) {
KService::Ptr service(static_cast<KService* >(entry.data()));
} else if (entry->property(QStringLiteral("Exec")).isValid()) {
KService::Ptr service(dynamic_cast<KService* >(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();
......@@ -154,12 +154,12 @@ void ApplicationListModel::loadApplications()
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());
......@@ -218,7 +218,7 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
Qt::ItemFlags ApplicationListModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return nullptr;
return {};
return Qt::ItemIsDragEnabled|QAbstractListModel::flags(index);
}
......@@ -236,18 +236,19 @@ void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int so
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"<<row<<data.name;
if (location == ApplicationData::Favorites) {
qWarning() << "favoriting" << row << data.name;
// Deny favorites when full
if (row >= m_maxFavoriteCount || m_favorites.count() >= m_maxFavoriteCount) {
return;
......@@ -259,21 +260,21 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
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;
......@@ -347,8 +348,8 @@ void ApplicationListModel::setMaxFavoriteCount(int count)
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;
......
......@@ -33,11 +33,16 @@ 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;
};
......@@ -50,9 +55,9 @@ class ApplicationListModel : public QAbstractListModel {
public:
enum LauncherLocation {
Grid = 0,
Favorites,
Desktop
Grid = ApplicationData::Grid,
Favorites = ApplicationData::Favorites,
Desktop = ApplicationData::Desktop
};
Q_ENUM(LauncherLocation)
......@@ -87,9 +92,9 @@ public:
QHash<int, QByteArray> 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);
......
......@@ -21,13 +21,14 @@
#include <QColor>
#include <QImage>
#include <QDebug>
#include <signal.h>
#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;
......
......@@ -25,7 +25,8 @@
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);
};
......@@ -29,19 +29,14 @@ HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args)
{
qmlRegisterUncreatableType<ApplicationListModel>("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel"));
qmlRegisterSingletonType<ColourAverage>("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<ColourAverage>("org.kde.phone.homescreen", 1, 0, "ColourAverage", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new ColourAverage();
});
setHasConfigurationInterface(true);
}
HomeScreen::~HomeScreen()
= default;
HomeScreen::~HomeScreen() = default;
void HomeScreen::configChanged()
{
......
......@@ -31,18 +31,19 @@
#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"<<command;
qWarning() << "Executing" << command;
QProcess::startDetached(command);
}
......@@ -82,14 +83,14 @@ void PhonePanel::toggleTorch()
void PhonePanel::takeScreenshot()
{
// wait ~200 ms to wait for rest of animations
QTimer::singleShot(200, [=]() {
QTimer::singleShot(SCREENSHOT_DELAY, [=]() {
auto *interface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
// screenshot fullscreen currently doesn't work on all devices -> we need to use screenshot area
// this won't work with multiple screens
QSize screenSize = QGuiApplication::primaryScreen()->size();
QDBusPendingReply<QString> 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<QString> reply = *watcher;
......
......@@ -34,6 +34,7 @@
#include <KWayland/Client/surface.h>
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)
......@@ -43,14 +44,12 @@ TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment