diff --git a/app/indicator/factory.cpp b/app/indicator/factory.cpp index e86fed64..2901d1b9 100644 --- a/app/indicator/factory.cpp +++ b/app/indicator/factory.cpp @@ -1,321 +1,321 @@ /* * Copyright 2019 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock 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. * * Latte-Dock 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, see . */ #include "factory.h" // local #include "../layouts/importer.h" // Qt #include #include #include #include #include #include // KDE #include #include #include #include #include #include #include #include #include namespace Latte { namespace Indicator { Factory::Factory(QObject *parent) : QObject(parent) { m_parentWidget = new QWidget(); m_watchedPaths = Latte::Layouts::Importer::standardPaths(); for(int i=0; iaddDir(dir); } connect(KDirWatch::self(), &KDirWatch::dirty, this, [ & ](const QString & path) { if (m_watchedPaths.contains(path)) { reload(); emit pluginsUpdated(); } }); qDebug() << m_plugins["org.kde.latte.default"].name(); } Factory::~Factory() { m_parentWidget->deleteLater(); } bool Factory::pluginExists(QString id) const { return m_plugins.contains(id); } int Factory::customPluginsCount() { return m_customPluginIds.count(); } QStringList Factory::customPluginIds() { return m_customPluginIds; } QStringList Factory::customPluginNames() { return m_customPluginNames; } QStringList Factory::customLocalPluginIds() { return m_customLocalPluginIds; } KPluginMetaData Factory::metadata(QString pluginId) { if (m_plugins.contains(pluginId)) { return m_plugins[pluginId]; } return KPluginMetaData(); } void Factory::reload() { m_plugins.clear(); m_pluginUiPaths.clear(); m_customPluginIds.clear(); m_customPluginNames.clear(); m_customLocalPluginIds.clear(); for(const auto &path : m_watchedPaths) { QDir standard(path); if (standard.exists()) { QStringList pluginDirs = standard.entryList(QStringList(),QDir::AllDirs | QDir::NoSymLinks); for (const auto &pluginDir : pluginDirs) { if (pluginDir != "." && pluginDir != "..") { QString metadataFile = standard.absolutePath() + "/" + pluginDir + "/metadata.desktop"; KPluginMetaData metadata = KPluginMetaData::fromDesktopFile(metadataFile); if (metadataAreValid(metadata)) { QString uiFile = standard.absolutePath() + "/" + pluginDir + "/package/" + metadata.value("X-Latte-MainScript"); if (QFileInfo(uiFile).exists() && !m_plugins.contains(metadata.pluginId())) { m_plugins[metadata.pluginId()] = metadata; if ((metadata.pluginId() != "org.kde.latte.default") && (metadata.pluginId() != "org.kde.latte.plasma")) { m_customPluginIds << metadata.pluginId(); m_customPluginNames << metadata.name(); } if (standard.absolutePath().startsWith(QDir::homePath())) { m_customLocalPluginIds << metadata.pluginId(); } m_pluginUiPaths[metadata.pluginId()] = QFileInfo(uiFile).absolutePath(); - QString pluginPath = metadata.fileName().remove("metadata.desktop"); + QString pluginPath = metadata.fileName().remove("metadata.desktop"); qDebug() << " Indicator Package Loaded ::: " << metadata.name() << " [" << metadata.pluginId() << "]" << " - [" <setText(i18n("Failed to import indicator")); notification->sendEvent(); }; auto showNotificationSucceed = [](QString name, bool updated) { auto notification = new KNotification("import-done", KNotification::CloseOnTimeout); notification->setText(updated ? i18nc("indicator_name, imported updated","%0 indicator updated successfully").arg(name) : i18nc("indicator_name, imported success","%0 indicator installed successfully").arg(name)); notification->sendEvent(); }; KArchive *archive; KZip *zipArchive = new KZip(compressedFile); zipArchive->open(QIODevice::ReadOnly); //! if the file isnt a zip archive if (!zipArchive->isOpen()) { delete zipArchive; KTar *tarArchive = new KTar(compressedFile, QStringLiteral("application/x-tar")); tarArchive->open(QIODevice::ReadOnly); if (!tarArchive->isOpen()) { delete tarArchive; showNotificationError(); return Latte::Types::Failed; } else { archive = tarArchive; } } else { archive = zipArchive; } QTemporaryDir archiveTempDir; archive->directory()->copyTo(archiveTempDir.path()); //metadata file QString packagePath = archiveTempDir.path(); QString metadataFile = archiveTempDir.path() + "/metadata.desktop"; if (!QFileInfo(metadataFile).exists()){ QDirIterator iter(archiveTempDir.path(), QDir::Dirs | QDir::NoDotAndDotDot); while(iter.hasNext() ) { QString currentPath = iter.next(); QString tempMetadata = currentPath + "/metadata.desktop"; if (QFileInfo(tempMetadata).exists()) { metadataFile = tempMetadata; packagePath = currentPath; } } } KPluginMetaData metadata = KPluginMetaData::fromDesktopFile(metadataFile); if (metadataAreValid(metadata)) { QStringList standardPaths = Latte::Layouts::Importer::standardPaths(); QString installPath = standardPaths[0] + "/latte/indicators/" + metadata.pluginId(); bool updated{QDir(installPath).exists()}; if (QDir(installPath).exists()) { QDir(installPath).removeRecursively(); } QProcess process; process.start(QString("mv " +packagePath + " " + installPath)); process.waitForFinished(); QString output(process.readAllStandardOutput()); showNotificationSucceed(metadata.name(), updated); return Latte::Types::Installed; } showNotificationError(); return Latte::Types::Failed; } void Factory::removeIndicator(QString id) { if (m_plugins.contains(id)) { QString pluginName = m_plugins[id].name(); auto msg = new QMessageBox(m_parentWidget); msg->setIcon(QMessageBox::Warning); msg->setWindowTitle(i18n("Remove Indicator")); msg->setText( i18n("Do you want to remove %0 indicator from your system?").arg(pluginName)); msg->setStandardButtons(QMessageBox::Yes | QMessageBox::No); msg->setDefaultButton(QMessageBox::No); connect(msg, &QMessageBox::finished, this, [ &, msg, id, pluginName](int result) { auto showRemovedSucceed = [](QString name) { auto notification = new KNotification("remove-done", KNotification::CloseOnTimeout); notification->setText(i18nc("indicator_name, removed success","%0 indicator removed successfully").arg(name)); notification->sendEvent(); }; if (result == QMessageBox::Yes) { qDebug() << "Trying to remove indicator :: " << id; QProcess process; process.start(QString("kpackagetool5 -r " +id + " -t Latte/Indicator")); process.waitForFinished(); showRemovedSucceed(pluginName); } }); msg->open(); } } void Factory::downloadIndicator() { KNS3::DownloadDialog dialog(QStringLiteral("latte-indicators.knsrc"), m_parentWidget); dialog.exec(); } } } diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index e78dac12..45d64cc5 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1,1235 +1,1241 @@ /* * Copyright 2019 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock 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. * * Latte-Dock 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, see . */ #include "genericlayout.h" // local #include "abstractlayout.h" #include "storage.h" #include "../lattecorona.h" #include "../screenpool.h" #include "../layouts/importer.h" #include "../layouts/manager.h" #include "../layouts/synchronizer.h" #include "../shortcuts/shortcutstracker.h" #include "../view/view.h" #include "../view/positioner.h" // Qt #include #include // Plasma #include #include #include // KDE #include namespace Latte { namespace Layout { GenericLayout::GenericLayout(QObject *parent, QString layoutFile, QString assignedName) : AbstractLayout (parent, layoutFile, assignedName), m_storage(new Storage(this)) { } GenericLayout::~GenericLayout() { } Type GenericLayout::type() const { return Type::Generic; } void GenericLayout::unloadContainments() { if (!m_corona) { return; } //!disconnect signals in order to avoid crashes when the layout is unloading disconnect(this, &GenericLayout::viewsCountChanged, m_corona, &Plasma::Corona::availableScreenRectChanged); disconnect(this, &GenericLayout::viewsCountChanged, m_corona, &Plasma::Corona::availableScreenRegionChanged); disconnect(m_corona->activityConsumer(), &KActivities::Consumer::currentActivityChanged, this, &GenericLayout::updateLastUsedActivity); qDebug() << "Layout - " + name() + " unload: containments ... size ::: " << m_containments.size() << " ,latteViews in memory ::: " << m_latteViews.size() << " ,hidden latteViews in memory ::: " << m_waitingLatteViews.size(); for (const auto view : m_latteViews) { view->disconnectSensitiveSignals(); } for (const auto view : m_waitingLatteViews) { view->disconnectSensitiveSignals(); } m_unloadedContainmentsIds.clear(); QList systrays; //!identify systrays and unload them first for (const auto containment : m_containments) { if (Plasma::Applet *parentApplet = qobject_cast(containment->parent())) { systrays.append(containment); } } while (!systrays.isEmpty()) { Plasma::Containment *systray = systrays.at(0); m_unloadedContainmentsIds << QString::number(systray->id()); systrays.removeFirst(); m_containments.removeAll(systray); delete systray; } while (!m_containments.isEmpty()) { Plasma::Containment *containment = m_containments.at(0); m_unloadedContainmentsIds << QString::number(containment->id()); m_containments.removeFirst(); delete containment; } } void GenericLayout::unloadLatteViews() { if (!m_corona) { return; } qDebug() << "Layout - " + name() + " unload: latteViews ... size: " << m_latteViews.size(); qDeleteAll(m_latteViews); qDeleteAll(m_waitingLatteViews); m_latteViews.clear(); m_waitingLatteViews.clear(); } bool GenericLayout::blockAutomaticLatteViewCreation() const { return m_blockAutomaticLatteViewCreation; } void GenericLayout::setBlockAutomaticLatteViewCreation(bool block) { if (m_blockAutomaticLatteViewCreation == block) { return; } m_blockAutomaticLatteViewCreation = block; } bool GenericLayout::isActive() const { if (!m_corona) { return false; } GenericLayout *generic = m_corona->layoutsManager()->synchronizer()->layout(m_layoutName); if (generic) { return true; } else { return false; } } bool GenericLayout::isCurrent() const { if (!m_corona) { return false; } return name() == m_corona->layoutsManager()->currentLayoutName(); } int GenericLayout::viewsCount(int screen) const { if (!m_corona) { return 0; } QScreen *scr = m_corona->screenPool()->screenForId(screen); int views{0}; for (const auto view : m_latteViews) { if (view && view->screen() == scr && !view->containment()->destroyed()) { ++views; } } return views; } int GenericLayout::viewsCount(QScreen *screen) const { if (!m_corona) { return 0; } int views{0}; for (const auto view : m_latteViews) { if (view && view->screen() == screen && !view->containment()->destroyed()) { ++views; } } return views; } int GenericLayout::viewsCount() const { if (!m_corona) { return 0; } int views{0}; for (const auto view : m_latteViews) { if (view && view->containment() && !view->containment()->destroyed()) { ++views; } } return views; } QList GenericLayout::qmlFreeEdges(int screen) const { if (!m_corona) { const QList emptyEdges; return emptyEdges; } const auto edges = freeEdges(screen); QList edgesInt; for (const Plasma::Types::Location &edge : edges) { edgesInt.append(static_cast(edge)); } return edgesInt; } QList GenericLayout::freeEdges(QScreen *scr) const { using Plasma::Types; QList edges{Types::BottomEdge, Types::LeftEdge, Types::TopEdge, Types::RightEdge}; if (!m_corona) { return edges; } for (const auto view : m_latteViews) { if (view && view->positioner()->currentScreenName() == scr->name()) { edges.removeOne(view->location()); } } return edges; } QList GenericLayout::freeEdges(int screen) const { using Plasma::Types; QList edges{Types::BottomEdge, Types::LeftEdge, Types::TopEdge, Types::RightEdge}; if (!m_corona) { return edges; } QScreen *scr = m_corona->screenPool()->screenForId(screen); for (const auto view : m_latteViews) { if (view && scr && view->positioner()->currentScreenName() == scr->name()) { edges.removeOne(view->location()); } } return edges; } int GenericLayout::viewsWithTasks() const { if (!m_corona) { return 0; } int result = 0; for (const auto view : m_latteViews) { if (view->tasksPresent()) { result++; } } return result; } QStringList GenericLayout::unloadedContainmentsIds() { return m_unloadedContainmentsIds; } Latte::Corona *GenericLayout::corona() { return m_corona; } Types::ViewType GenericLayout::latteViewType(int containmentId) const { for (const auto view : m_latteViews) { if (view->containment() && view->containment()->id() == containmentId) { return view->type(); } } return Types::DockView; } Latte::View *GenericLayout::highestPriorityView() { QList views = sortedLatteViews(); return (views.count() > 0 ? views[0] : nullptr); } Latte::View *GenericLayout::lastConfigViewFor() { if (!latteViews().contains(m_lastConfigViewFor)) { m_lastConfigViewFor = nullptr; return nullptr; } return m_lastConfigViewFor; } void GenericLayout::setLastConfigViewFor(Latte::View *view) { if (m_lastConfigViewFor == view) { return; } m_lastConfigViewFor = view; emit lastConfigViewForChanged(view); } Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) { if (m_containments.contains(containment) && m_latteViews.contains(containment)) { return m_latteViews[containment]; } return nullptr; } QList GenericLayout::latteViews() { return m_latteViews.values(); } QList GenericLayout::sortedLatteViews(QList views) { QList sortedViews = views.isEmpty() ? latteViews() : views; qDebug() << " -------- "; for (int i = 0; i < sortedViews.count(); ++i) { qDebug() << i << ". " << sortedViews[i]->screen()->name() << " - " << sortedViews[i]->location(); } //! sort the views based on screens and edges priorities //! views on primary screen have higher priority and //! for views in the same screen the priority goes to //! Bottom,Left,Top,Right for (int i = 0; i < sortedViews.size(); ++i) { for (int j = 0; j < sortedViews.size() - i - 1; ++j) { if (viewAtLowerScreenPriority(sortedViews[j], sortedViews[j + 1]) || (sortedViews[j]->screen() == sortedViews[j + 1]->screen() && viewAtLowerEdgePriority(sortedViews[j], sortedViews[j + 1]))) { Latte::View *temp = sortedViews[j + 1]; sortedViews[j + 1] = sortedViews[j]; sortedViews[j] = temp; } } } Latte::View *highestPriorityView{nullptr}; for (int i = 0; i < sortedViews.size(); ++i) { if (sortedViews[i]->isPreferredForShortcuts()) { highestPriorityView = sortedViews[i]; sortedViews.removeAt(i); break; } } if (highestPriorityView) { sortedViews.prepend(highestPriorityView); } qDebug() << " -------- sorted -----"; for (int i = 0; i < sortedViews.count(); ++i) { qDebug() << i << ". " << sortedViews[i]->isPreferredForShortcuts() << " - " << sortedViews[i]->screen()->name() << " - " << sortedViews[i]->location(); } return sortedViews; } bool GenericLayout::viewAtLowerScreenPriority(Latte::View *test, Latte::View *base) { if (!base || ! test) { return true; } if (base->screen() == test->screen()) { return false; } else if (base->screen() != qGuiApp->primaryScreen() && test->screen() == qGuiApp->primaryScreen()) { return false; } else if (base->screen() == qGuiApp->primaryScreen() && test->screen() != qGuiApp->primaryScreen()) { return true; } else { int basePriority = -1; int testPriority = -1; for (int i = 0; i < qGuiApp->screens().count(); ++i) { if (base->screen() == qGuiApp->screens()[i]) { basePriority = i; } if (test->screen() == qGuiApp->screens()[i]) { testPriority = i; } } if (testPriority <= basePriority) { return true; } else { return false; } } qDebug() << "viewAtLowerScreenPriority : shouldn't had reached here..."; return false; } bool GenericLayout::viewAtLowerEdgePriority(Latte::View *test, Latte::View *base) { if (!base || ! test) { return true; } QList edges{Plasma::Types::RightEdge, Plasma::Types::TopEdge, Plasma::Types::LeftEdge, Plasma::Types::BottomEdge}; int testPriority = -1; int basePriority = -1; for (int i = 0; i < edges.count(); ++i) { if (edges[i] == base->location()) { basePriority = i; } if (edges[i] == test->location()) { testPriority = i; } } if (testPriority < basePriority) return true; else return false; } const QList *GenericLayout::containments() { return &m_containments; } QList GenericLayout::viewsWithPlasmaShortcuts() { QList views; if (!m_corona) { return views; } QList appletsWithShortcuts = m_corona->globalShortcuts()->shortcutsTracker()->appletsWithPlasmaShortcuts(); for (const auto &appletId : appletsWithShortcuts) { for (const auto view : m_latteViews) { bool found{false}; for (const auto applet : view->containment()->applets()) { if (appletId == applet->id()) { if (!views.contains(view)) { views.append(view); found = true; break; } } } if (found) { break; } } } return views; } //! Containments Actions void GenericLayout::addContainment(Plasma::Containment *containment) { if (!containment || m_containments.contains(containment)) { return; } bool containmentInLayout{false}; if (m_corona->layoutsManager()->memoryUsage() == Types::SingleLayout) { m_containments.append(containment); containmentInLayout = true; } else if (m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts) { QString layoutId = containment->config().readEntry("layoutId", QString()); if (!layoutId.isEmpty() && (layoutId == m_layoutName)) { m_containments.append(containment); containmentInLayout = true; } } if (containmentInLayout) { if (!blockAutomaticLatteViewCreation()) { addView(containment); } else { qDebug() << "delaying LatteView creation for containment :: " << containment->id(); } connect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); } } void GenericLayout::appletCreated(Plasma::Applet *applet) { //! In Multiple Layout the orphaned systrays must be assigned to layouts //! when the user adds them KConfigGroup appletSettings = applet->containment()->config().group("Applets").group(QString::number(applet->id())).group("Configuration"); int systrayId = appletSettings.readEntry("SystrayContainmentId", -1); if (systrayId != -1) { uint sId = (uint)systrayId; for (const auto containment : m_corona->containments()) { if (containment->id() == sId) { containment->config().writeEntry("layoutId", m_layoutName); } addContainment(containment); } } } void GenericLayout::containmentDestroyed(QObject *cont) { if (!m_corona) { return; } Plasma::Containment *containment = static_cast(cont); if (containment) { int containmentIndex = m_containments.indexOf(containment); if (containmentIndex >= 0) { m_containments.removeAt(containmentIndex); } qDebug() << "Layout " << name() << " :: containment destroyed!!!!"; auto view = m_latteViews.take(containment); if (!view) { view = m_waitingLatteViews.take(containment); } if (view) { view->disconnectSensitiveSignals(); view->deleteLater(); emit viewEdgeChanged(); emit viewsCountChanged(); } } } void GenericLayout::destroyedChanged(bool destroyed) { if (!m_corona) { return; } qDebug() << "dock containment destroyed changed!!!!"; Plasma::Containment *sender = qobject_cast(QObject::sender()); if (!sender) { return; } if (destroyed) { m_waitingLatteViews[sender] = m_latteViews.take(static_cast(sender)); } else { m_latteViews[sender] = m_waitingLatteViews.take(static_cast(sender)); } emit viewEdgeChanged(); emit viewsCountChanged(); } void GenericLayout::renameLayout(QString newName) { if (!m_corona || m_corona->layoutsManager()->memoryUsage() != Types::MultipleLayouts) { return; } if (m_layoutFile != Layouts::Importer::layoutFilePath(newName)) { setFile(Layouts::Importer::layoutFilePath(newName)); } setName(newName); for (const auto containment : m_containments) { qDebug() << "Cont ID :: " << containment->id(); containment->config().writeEntry("layoutId", m_layoutName); } } void GenericLayout::addNewView() { if (!m_corona) { return; } m_corona->addViewForLayout(name()); emit viewEdgeChanged(); } void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimary, int explicitScreen, Layout::ViewsMap *occupied) { qDebug() << "Layout :::: " << m_layoutName << " ::: addView was called... m_containments :: " << m_containments.size(); if (!containment || !m_corona || !containment->kPackage().isValid()) { qWarning() << "the requested containment plugin can not be located or loaded"; return; } qDebug() << "step 1..."; if (!m_storage->isLatteContainment(containment)) return; qDebug() << "step 2..."; for (auto *dock : m_latteViews) { if (dock->containment() == containment) return; } qDebug() << "step 3..."; QScreen *nextScreen{qGuiApp->primaryScreen()}; bool onPrimary = containment->config().readEntry("onPrimary", true); int id = containment->screen(); if (id == -1 && explicitScreen == -1) { id = containment->lastScreen(); } if (onPrimary) { id = m_corona->screenPool()->primaryScreenId(); } else if (explicitScreen > -1) { id = explicitScreen; } Plasma::Types::Location edge = containment->location(); QString connector = m_corona->screenPool()->hasId(id) ? m_corona->screenPool()->connector(id) : ""; qDebug() << "Adding view - containment id:" << containment->id() << " ,screen :" << id << " - " << connector << " ,onprimary:" << onPrimary << " - " << " edge:" << edge << " ,screenName:" << qGuiApp->primaryScreen()->name() << " ,forceOnPrimary:" << forceOnPrimary; if (occupied && m_corona->screenPool()->hasId(id) && (*occupied).contains(connector) && (*occupied)[connector].contains(edge)) { qDebug() << "Rejected : adding view because the edge is already occupied by a higher priority view ! : " << (*occupied)[connector][edge]; return; } if (id >= 0 && !onPrimary && !forceOnPrimary) { qDebug() << "Add view - connector : " << connector; bool found{false}; if (m_corona->screenPool()->hasId(id)) { for (const auto scr : qGuiApp->screens()) { if (scr && scr->name() == connector) { found = true; nextScreen = scr; break; } } } if (!found) { qDebug() << "Rejected : adding explicit view, screen not available ! : " << connector; return; } //! explicit dock can not be added at explicit screen when that screen is the same with //! primary screen and that edge is already occupied by a primary dock if (nextScreen == qGuiApp->primaryScreen() && primaryDockOccupyEdge(containment->location())) { qDebug() << "Rejected : adding explicit view, primary dock occupies edge at screen ! : " << connector; return; } } if (id >= 0 && onPrimary) { qDebug() << "add dock - connector : " << connector; for (const auto view : m_latteViews) { auto testContainment = view->containment(); int testScreenId = testContainment->screen(); if (testScreenId == -1) { testScreenId = testContainment->lastScreen(); } bool testOnPrimary = testContainment->config().readEntry("onPrimary", true); Plasma::Types::Location testLocation = static_cast((int)testContainment->config().readEntry("location", (int)Plasma::Types::BottomEdge)); if (!testOnPrimary && m_corona->screenPool()->primaryScreenId() == testScreenId && testLocation == containment->location()) { qDebug() << "Rejected explicit latteView and removing it in order add an onPrimary with higher priority at screen: " << connector; auto viewToDelete = m_latteViews.take(testContainment); viewToDelete->disconnectSensitiveSignals(); viewToDelete->deleteLater(); } } } qDebug() << "Adding view passed ALL checks" << " ,onPrimary:" << onPrimary << " ,screen:" << nextScreen->name() << " !!!"; //! it is used to set the correct flag during the creation //! of the window... This of course is also used during //! recreations of the window between different visibility modes auto mode = static_cast(containment->config().readEntry("visibility", static_cast(Types::DodgeActive))); bool byPassWM{false}; if (mode == Types::AlwaysVisible || mode == Types::WindowsGoBelow) { byPassWM = false; } else { byPassWM = containment->config().readEntry("byPassWM", false); } auto latteView = new Latte::View(m_corona, nextScreen, byPassWM); latteView->init(); latteView->setContainment(containment); //! force this special dock case to become primary //! even though it isnt if (forceOnPrimary) { qDebug() << "Enforcing onPrimary:true as requested for LatteView..."; latteView->setOnPrimary(true); } latteView->setLayout(this); //! Qt 5.9 creates a crash for this in wayland, that is why the check is used //! but on the other hand we need this for copy to work correctly and show //! the copied dock under X11 //if (!KWindowSystem::isPlatformWayland()) { latteView->show(); //} m_latteViews[containment] = latteView; emit viewsCountChanged(); } bool GenericLayout::initToCorona(Latte::Corona *corona) { if (m_corona) { return false; } m_corona = corona; for (const auto containment : m_corona->containments()) { if (m_corona->layoutsManager()->memoryUsage() == Types::SingleLayout) { addContainment(containment); } else if (m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts) { QString layoutId = containment->config().readEntry("layoutId", QString()); if (!layoutId.isEmpty() && (layoutId == m_layoutName)) { addContainment(containment); } } } qDebug() << "Layout ::::: " << name() << " added containments ::: " << m_containments.size(); updateLastUsedActivity(); //! signals connect(m_corona->activityConsumer(), &KActivities::Consumer::currentActivityChanged, this, &GenericLayout::updateLastUsedActivity); connect(m_corona, &Plasma::Corona::containmentAdded, this, &GenericLayout::addContainment); //!connect signals after adding the containment connect(this, &GenericLayout::viewsCountChanged, m_corona, &Plasma::Corona::availableScreenRectChanged); connect(this, &GenericLayout::viewsCountChanged, m_corona, &Plasma::Corona::availableScreenRegionChanged); emit viewsCountChanged(); return true; } void GenericLayout::updateLastUsedActivity() { if (!m_corona) { return; } if (!m_lastUsedActivity.isEmpty() && !m_corona->layoutsManager()->synchronizer()->activities().contains(m_lastUsedActivity)) { clearLastUsedActivity(); } QString currentId = m_corona->activitiesConsumer()->currentActivity(); QStringList appliedActivitiesIds = appliedActivities(); if (m_lastUsedActivity != currentId && (appliedActivitiesIds.contains(currentId) || m_corona->layoutsManager()->memoryUsage() == Types::SingleLayout)) { m_lastUsedActivity = currentId; emit lastUsedActivityChanged(); } } void GenericLayout::assignToLayout(Latte::View *latteView, QList containments) { if (!m_corona) { return; } if (latteView) { m_latteViews[latteView->containment()] = latteView; m_containments << containments; for (const auto containment : containments) { containment->config().writeEntry("layoutId", name()); if (latteView->containment() != containment) { //! assign signals only to systrays //! the View::setLayout() is responsible for the View::Containment signals connect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); connect(containment, &Plasma::Applet::destroyedChanged, this, &GenericLayout::destroyedChanged); connect(containment, &Plasma::Containment::appletCreated, this, &GenericLayout::appletCreated); } } latteView->setLayout(this); emit viewsCountChanged(); } //! sync the original layout file for integrity if (m_corona && m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts) { m_storage->syncToLayoutFile(false); } } QList GenericLayout::unassignFromLayout(Latte::View *latteView) { QList containments; if (!m_corona) { return containments; } containments << latteView->containment(); for (const auto containment : m_containments) { Plasma::Applet *parentApplet = qobject_cast(containment->parent()); //! add systrays from that latteView if (parentApplet && parentApplet->containment() && parentApplet->containment() == latteView->containment()) { containments << containment; //! unassign signals only to systrays //! the View::setLayout() is responsible for the View::Containment signals disconnect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); disconnect(containment, &Plasma::Applet::destroyedChanged, this, &GenericLayout::destroyedChanged); disconnect(containment, &Plasma::Containment::appletCreated, this, &GenericLayout::appletCreated); } } for (const auto containment : containments) { m_containments.removeAll(containment); } if (containments.size() > 0) { m_latteViews.remove(latteView->containment()); } //! sync the original layout file for integrity if (m_corona && m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts) { m_storage->syncToLayoutFile(false); } return containments; } void GenericLayout::recreateView(Plasma::Containment *containment) { if (!m_corona) { return; } - //! give the time to config window to close itself first and then recreate the dock - //! step:1 remove the latteview - QTimer::singleShot(350, [this, containment]() { - auto view = m_latteViews.take(containment); - - if (view) { - qDebug() << "recreate - step 1: removing dock for containment:" << containment->id(); - - //! step:2 add the new latteview - connect(view, &QObject::destroyed, this, [this, containment]() { - QTimer::singleShot(250, this, [this, containment]() { - if (!m_latteViews.contains(containment)) { - qDebug() << "recreate - step 2: adding dock for containment:" << containment->id(); - addView(containment); - } + if (!m_viewsToRecreate.contains(containment)) { + m_viewsToRecreate << containment; + + //! give the time to config window to close itself first and then recreate the dock + //! step:1 remove the latteview + QTimer::singleShot(350, [this, containment]() { + auto view = m_latteViews.take(containment); + + if (view) { + qDebug() << "recreate - step 1: removing dock for containment:" << containment->id(); + + //! step:2 add the new latteview + connect(view, &QObject::destroyed, this, [this, containment]() { + QTimer::singleShot(250, this, [this, containment]() { + if (!m_latteViews.contains(containment)) { + qDebug() << "recreate - step 2: adding dock for containment:" << containment->id(); + addView(containment); + m_viewsToRecreate.removeAll(containment); + } + }); }); - }); - view->deleteLater(); - } - }); + view->disconnectSensitiveSignals(); + view->deleteLater(); + } + }); + } } bool GenericLayout::latteViewExists(Plasma::Containment *containment) { if (!m_corona) { return false; } return m_latteViews.keys().contains(containment); } QList GenericLayout::availableEdgesForView(QScreen *scr, Latte::View *forView) const { using Plasma::Types; QList edges{Types::BottomEdge, Types::LeftEdge, Types::TopEdge, Types::RightEdge}; if (!m_corona) { return edges; } for (const auto view : m_latteViews) { //! make sure that availabe edges takes into account only views that should be excluded, //! this is why the forView should not be excluded if (view && view != forView && view->positioner()->currentScreenName() == scr->name()) { edges.removeOne(view->location()); } } return edges; } bool GenericLayout::explicitDockOccupyEdge(int screen, Plasma::Types::Location location) const { if (!m_corona) { return false; } for (const auto containment : m_containments) { if (m_storage->isLatteContainment(containment)) { bool onPrimary = containment->config().readEntry("onPrimary", true); int id = containment->lastScreen(); Plasma::Types::Location contLocation = containment->location(); if (!onPrimary && id == screen && contLocation == location) { return true; } } } return false; } bool GenericLayout::primaryDockOccupyEdge(Plasma::Types::Location location) const { if (!m_corona) { return false; } for (const auto containment : m_containments) { if (m_storage->isLatteContainment(containment)) { bool onPrimary = containment->config().readEntry("onPrimary", true); Plasma::Types::Location contLocation = containment->location(); if (onPrimary && contLocation == location) { return true; } } } return false; } bool GenericLayout::mapContainsId(const Layout::ViewsMap *map, uint viewId) const { for(const auto &scr : map->keys()) { for(const auto &edge : (*map)[scr].keys()) { if ((*map)[scr][edge] == viewId) { return true; } } } return false; } //! screen name, location, containmentId Layout::ViewsMap GenericLayout::validViewsMap(Layout::ViewsMap *occupiedMap) { Layout::ViewsMap map; if (!m_corona) { return map; } if (occupiedMap != nullptr) { map = (*occupiedMap); } QString prmScreenName = qGuiApp->primaryScreen()->name(); //! first step: primary docks must be placed in primary screen free edges for (const auto containment : m_containments) { if (m_storage->isLatteContainment(containment)) { int screenId = 0; //! valid screen id if (latteViewExists(containment)) { screenId = m_latteViews[containment]->positioner()->currentScreenId(); } else { screenId = containment->screen(); if (screenId == -1) { screenId = containment->lastScreen(); } } bool onPrimary{true}; //! valid onPrimary flag if (latteViewExists(containment)) { onPrimary = m_latteViews[containment]->onPrimary(); } else { onPrimary = containment->config().readEntry("onPrimary", true); } //! valid location Plasma::Types::Location location = containment->location(); if (onPrimary && !map[prmScreenName].contains(location)) { map[prmScreenName][location] = containment->id(); } } } //! second step: explicit docks must be placed in their screens if the screen edge is free for (const auto containment : m_containments) { if (m_storage->isLatteContainment(containment)) { int screenId = 0; //! valid screen id if (latteViewExists(containment)) { screenId = m_latteViews[containment]->positioner()->currentScreenId(); } else { screenId = containment->screen(); if (screenId == -1) { screenId = containment->lastScreen(); } } bool onPrimary{true}; //! valid onPrimary flag if (latteViewExists(containment)) { onPrimary = m_latteViews[containment]->onPrimary(); } else { onPrimary = containment->config().readEntry("onPrimary", true); } //! valid location Plasma::Types::Location location = containment->location(); if (!onPrimary) { QString expScreenName = m_corona->screenPool()->connector(screenId); if (m_corona->screenPool()->screenExists(screenId) && !map[expScreenName].contains(location)) { map[expScreenName][location] = containment->id(); } } } } return map; } //! the central functions that updates loading/unloading latteviews //! concerning screen changed (for multi-screen setups mainly) void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap) { if (!m_corona) { return; } qDebug() << "START of SyncLatteViewsToScreens ...."; qDebug() << "LAYOUT ::: " << name(); qDebug() << "screen count changed -+-+ " << qGuiApp->screens().size(); Layout::ViewsMap viewsMap = validViewsMap(occupiedMap); if (occupiedMap != nullptr) { qDebug() << "Occupied map used :: " << *occupiedMap; } QString prmScreenName = qGuiApp->primaryScreen()->name(); qDebug() << "PRIMARY SCREEN :: " << prmScreenName; qDebug() << "LATTEVIEWS MAP :: " << viewsMap; //! add views for (const auto containment : m_containments) { int screenId = containment->screen(); if (screenId == -1) { screenId = containment->lastScreen(); } if (!latteViewExists(containment) && mapContainsId(&viewsMap, containment->id())) { qDebug() << "syncLatteViewsToScreens: view must be added... for containment:" << containment->id() << " at screen:" << m_corona->screenPool()->connector(screenId); addView(containment); } } //! remove views QList viewsToDelete; for (auto view : m_latteViews) { auto containment = view->containment(); if (containment && !mapContainsId(&viewsMap, containment->id())) { viewsToDelete << containment; } } while(!viewsToDelete.isEmpty()) { auto containment = viewsToDelete.takeFirst(); auto view = m_latteViews.take(containment); qDebug() << "syncLatteViewsToScreens: view must be deleted... for containment:" << containment->id() << " at screen:" << view->positioner()->currentScreenName(); view->disconnectSensitiveSignals(); view->deleteLater(); } //! reconsider views for (const auto view : m_latteViews) { if (view->containment() && mapContainsId(&viewsMap, view->containment()->id())) { //! if the dock will not be deleted its a very good point to reconsider //! if the screen in which is running is the correct one qDebug() << "syncLatteViewsToScreens: view must consider its screen... for containment:" << view->containment()->id() << " at screen:" << view->positioner()->currentScreenName(); view->reconsiderScreen(); } } qDebug() << "end of, syncLatteViewsToScreens ...."; } //! STORAGE bool GenericLayout::isWritable() const { return m_storage->isWritable(); } void GenericLayout::lock() { m_storage->lock(); } void GenericLayout::unlock() { m_storage->unlock(); } void GenericLayout::syncToLayoutFile(bool removeLayoutId) { m_storage->syncToLayoutFile(removeLayoutId); } void GenericLayout::copyView(Plasma::Containment *containment) { m_storage->copyView(containment); emit viewEdgeChanged(); } void GenericLayout::importToCorona() { m_storage->importToCorona(); } bool GenericLayout::layoutIsBroken() const { return m_storage->layoutIsBroken(); } } } diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 5d04e060..122db440 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -1,195 +1,198 @@ /* * Copyright 2019 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock 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. * * Latte-Dock 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, see . */ #ifndef GENERICLAYOUT_H #define GENERICLAYOUT_H // local #include "abstractlayout.h" #include "../../liblatte2/types.h" // Qt #include #include #include #include // Plasma #include namespace Plasma { class Applet; class Containment; class Types; } namespace Latte { class Corona; class View; } namespace Latte { namespace Layout { class Storage; } } namespace Latte { namespace Layout { //! This is views map in the following structure: //! SCREEN_NAME -> EDGE -> VIEWID typedef QHash> ViewsMap; class GenericLayout : public AbstractLayout { Q_OBJECT Q_PROPERTY(int viewsCount READ viewsCount NOTIFY viewsCountChanged) public: GenericLayout(QObject *parent, QString layoutFile, QString assignedName = QString()); ~GenericLayout() override; virtual const QStringList appliedActivities() = 0; // to move at an interface void importToCorona(); bool initToCorona(Latte::Corona *corona); bool isActive() const; //! is loaded and running virtual bool isCurrent() const; bool isWritable() const; bool layoutIsBroken() const; virtual int viewsCount(int screen) const; virtual int viewsCount(QScreen *screen) const; virtual int viewsCount() const; Type type() const override; Latte::Corona *corona(); QStringList unloadedContainmentsIds(); virtual Types::ViewType latteViewType(int containmentId) const; const QList *containments(); Latte::View *highestPriorityView(); Latte::View *viewForContainment(Plasma::Containment *containment); virtual QList sortedLatteViews(QList views = QList()); virtual QList viewsWithPlasmaShortcuts(); virtual QList latteViews(); ViewsMap validViewsMap(ViewsMap *occupiedMap = nullptr); virtual void syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap = nullptr); void syncToLayoutFile(bool removeLayoutId = false); void lock(); //! make it only read-only void renameLayout(QString newName); virtual void unloadContainments(); void unloadLatteViews(); void unlock(); //! make it writable which it should be the default virtual void setLastConfigViewFor(Latte::View *view); virtual Latte::View *lastConfigViewFor(); //! this function needs the layout to have first set the corona through initToCorona() function virtual void addView(Plasma::Containment *containment, bool forceOnPrimary = false, int explicitScreen = -1, Layout::ViewsMap *occupied = nullptr); void copyView(Plasma::Containment *containment); void recreateView(Plasma::Containment *containment); bool latteViewExists(Plasma::Containment *containment); //! Available edges for specific view in that screen virtual QList availableEdgesForView(QScreen *scr, Latte::View *forView) const; //! All free edges in that screen virtual QList freeEdges(QScreen *scr) const; virtual QList freeEdges(int screen) const; //! Bind this latteView and its relevant containments(including systrays) //! to this layout. It is used for moving a Latte::View from layout to layout) void assignToLayout(Latte::View *latteView, QList containments); //! Unassign that latteView from this layout (this is used for moving a latteView //! from layout to layout) and returns all the containments relevant to //! that latteView QList unassignFromLayout(Latte::View *latteView); public slots: Q_INVOKABLE void addNewView(); Q_INVOKABLE int viewsWithTasks() const; virtual Q_INVOKABLE QList qmlFreeEdges(int screen) const; //change to types signals: void activitiesChanged(); // to move at an interface void viewsCountChanged(); void viewEdgeChanged(); //! used from ConfigView(s) in order to be informed which is one should be shown void lastConfigViewForChanged(Latte::View *view); //! used from LatteView(s) in order to exist only one each time that has the highest priority //! to use the global shortcuts activations void preferredViewForShortcutsChanged(Latte::View *view); protected: void updateLastUsedActivity(); protected: Latte::Corona *m_corona{nullptr}; QList m_containments; QHash m_latteViews; QHash m_waitingLatteViews; private slots: void addContainment(Plasma::Containment *containment); void appletCreated(Plasma::Applet *applet); void destroyedChanged(bool destroyed); void containmentDestroyed(QObject *cont); private: //! It can be used in order for LatteViews to not be created automatically when //! their corresponding containments are created e.g. copyView functionality bool blockAutomaticLatteViewCreation() const; void setBlockAutomaticLatteViewCreation(bool block); bool explicitDockOccupyEdge(int screen, Plasma::Types::Location location) const; bool primaryDockOccupyEdge(Plasma::Types::Location location) const; bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base); bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base); bool mapContainsId(const ViewsMap *map, uint viewId) const; private: bool m_blockAutomaticLatteViewCreation{false}; QPointer m_lastConfigViewFor; QStringList m_unloadedContainmentsIds; QPointer m_storage; + //! try to avoid crashes from recreating the same views all the time + QList m_viewsToRecreate; + friend class Storage; friend class Latte::View; }; } } #endif diff --git a/app/view/indicator/indicator.cpp b/app/view/indicator/indicator.cpp index ba279d6f..dfc6ff00 100644 --- a/app/view/indicator/indicator.cpp +++ b/app/view/indicator/indicator.cpp @@ -1,461 +1,460 @@ /* * Copyright 2019 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock 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. * * Latte-Dock 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, see . */ #include "indicator.h" // local #include "indicatorinfo.h" #include "../view.h" #include "../../lattecorona.h" #include "../../indicator/factory.h" #include "../../../liblatte2/types.h" // Qt #include // KDE #include #include #include #include namespace Latte { namespace ViewPart { Indicator::Indicator(Latte::View *parent) : QObject(parent), m_view(parent), m_info(new IndicatorPart::Info(this)), m_resources(new IndicatorPart::Resources(this)) { m_corona = qobject_cast(m_view->corona()); loadConfig(); connect(this, &Indicator::enabledChanged, this, &Indicator::saveConfig); connect(this, &Indicator::enabledForAppletsChanged, this, &Indicator::saveConfig); connect(this, &Indicator::paddingChanged, this, &Indicator::saveConfig); connect(this, &Indicator::pluginChanged, this, &Indicator::saveConfig); connect(m_view, &Latte::View::latteTasksArePresentChanged, this, &Indicator::latteTasksArePresentChanged); connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::customPluginsChanged, [this]() { if (!m_corona->indicatorFactory()->pluginExists(m_type)) { setType("org.kde.latte.default"); } emit customPluginsChanged(); }); connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::pluginsUpdated, [this]() { - if (m_view && m_view->layout()) { - m_view->layout()->recreateView(m_view->containment()); + if (m_view && m_view->layout() && m_view->containment()) { + // m_view->layout()->recreateView(m_view->containment()); } - }); connect(this, &Indicator::pluginChanged, [this]() { if ((m_type != "org.kde.latte.default") && m_type != "org.kde.latte.plasma") { setCustomType(m_type); } }); load(m_type); loadPlasmaComponent(); } Indicator::~Indicator() { if (m_component) { m_component->deleteLater(); } if (m_configLoader) { m_configLoader->deleteLater(); } if (m_configuration) { m_configuration->deleteLater(); } if (m_info) { m_info->deleteLater(); } } bool Indicator::enabled() const { return m_enabled; } void Indicator::setEnabled(bool enabled) { if (m_enabled == enabled) { return; } m_enabled = enabled; emit enabledChanged(); } bool Indicator::enabledForApplets() const { return m_enabledForApplets; } void Indicator::setEnabledForApplets(bool enabled) { if (m_enabledForApplets == enabled) { return; } m_enabledForApplets = enabled; emit enabledForAppletsChanged(); } bool Indicator::latteTasksArePresent() { return m_view->latteTasksArePresent(); } bool Indicator::providesConfigUi() const { return m_providesConfigUi; } void Indicator::setProvidesConfigUi(bool provides) { if (m_providesConfigUi == provides) { return; } m_providesConfigUi = provides; emit providesConfigUiChanged(); } float Indicator::padding() const { return m_padding; } void Indicator::setPadding(float padding) { if (m_padding == padding) { return; } m_padding = padding; emit paddingChanged(); } bool Indicator::pluginIsReady() { return m_pluginIsReady; } void Indicator::setPluginIsReady(bool ready) { if (m_pluginIsReady == ready) { return; } m_pluginIsReady = ready; emit pluginIsReadyChanged(); } QString Indicator::type() const { return m_type; } void Indicator::setType(QString type) { if (m_type == type) { return; } load(type); } QString Indicator::customType() const { return m_customType; } void Indicator::setCustomType(QString type) { if (m_customType == type) { return; } m_customType = type; emit customPluginChanged(); } int Indicator::customPluginsCount() const { return m_corona->indicatorFactory()->customPluginsCount(); } QString Indicator::uiPath() const { return m_corona->indicatorFactory()->uiPath(m_type); } QStringList Indicator::customPluginIds() const { return m_corona->indicatorFactory()->customPluginIds(); } QStringList Indicator::customPluginNames() const { return m_corona->indicatorFactory()->customPluginNames(); } QStringList Indicator::customLocalPluginIds() const { return m_corona->indicatorFactory()->customLocalPluginIds(); } IndicatorPart::Info *Indicator::info() const { return m_info; } IndicatorPart::Resources *Indicator::resources() const { return m_resources; } QQmlComponent *Indicator::component() const { return m_component; } QQmlComponent *Indicator::plasmaComponent() const { return m_plasmaComponent; } QObject *Indicator::configuration() const { return m_configuration; } void Indicator::load(QString type) { KPluginMetaData metadata = m_corona->indicatorFactory()->metadata(type); if (metadata.isValid()) { bool state{m_enabled}; //! remove all previous indicators setPluginIsReady(false); m_metadata = metadata; m_type = type; QString path = m_metadata.fileName(); m_pluginPath = path.remove("metadata.desktop"); updateScheme(); updateComponent(); emit pluginChanged(); //! create all indicators with the new type setPluginIsReady(true); } else if (type!="org.kde.latte.default") { qDebug() << " Indicator metadata are not valid : " << type; setType("org.kde.latte.default"); } } void Indicator::updateComponent() { auto prevComponent = m_component; QString uiPath = m_metadata.value("X-Latte-MainScript"); if (!uiPath.isEmpty()) { uiPath = m_pluginPath + "package/" + uiPath; m_component = new QQmlComponent(m_view->engine(), uiPath); } if (prevComponent) { prevComponent->deleteLater(); } } void Indicator::loadPlasmaComponent() { auto prevComponent = m_plasmaComponent; KPluginMetaData metadata = m_corona->indicatorFactory()->metadata("org.kde.latte.plasma"); QString uiPath = metadata.value("X-Latte-MainScript"); if (!uiPath.isEmpty()) { QString path = metadata.fileName(); path = path.remove("metadata.desktop"); uiPath = path + "package/" + uiPath; m_plasmaComponent = new QQmlComponent(m_view->engine(), uiPath); } if (prevComponent) { prevComponent->deleteLater(); } emit plasmaComponentChanged(); } void Indicator::configUiFor(QString type, QQuickItem *parent) { if (m_lastCreatedConfigUi) { delete m_lastCreatedConfigUi; m_lastCreatedConfigUi = nullptr; } auto prevConfigUi = m_lastCreatedConfigUi; KPluginMetaData metadata; if (m_metadata.pluginId() == type) { metadata = m_metadata; } else { metadata = m_corona->indicatorFactory()->metadata(type); } if (metadata.isValid()) { QString uiPath = metadata.value("X-Latte-ConfigUi"); if (!uiPath.isEmpty()) { m_lastCreatedConfigUi = new KDeclarative::QmlObjectSharedEngine(parent); m_lastCreatedConfigUi->setTranslationDomain(QLatin1String("latte_indicator_") + m_metadata.pluginId()); m_lastCreatedConfigUi->setInitializationDelayed(true); uiPath = m_pluginPath + "package/" + uiPath; m_lastCreatedConfigUi->setSource(QUrl::fromLocalFile(uiPath)); m_lastCreatedConfigUi->rootContext()->setContextProperty(QStringLiteral("dialog"), parent); m_lastCreatedConfigUi->rootContext()->setContextProperty(QStringLiteral("indicator"), this); m_lastCreatedConfigUi->completeInitialization(); QQuickItem *qmlItem = qobject_cast(m_lastCreatedConfigUi->rootObject()); qmlItem->setParentItem(parent); setProvidesConfigUi(true); } else { setProvidesConfigUi(false); } } } void Indicator::unloadIndicators() { setPluginIsReady(false); } void Indicator::updateScheme() { auto prevConfigLoader = m_configLoader; auto prevConfiguration = m_configuration; QString xmlPath = m_metadata.value("X-Latte-ConfigXml"); if (!xmlPath.isEmpty()) { QFile file(m_pluginPath + "package/" + xmlPath); m_configLoader = new KConfigLoader(m_view->containment()->config().group("Indicator").group(m_metadata.pluginId()), &file); m_configuration = new KDeclarative::ConfigPropertyMap(m_configLoader, this); } else { m_configLoader = nullptr; m_configuration = nullptr; } if (prevConfigLoader) { prevConfigLoader->deleteLater(); } if (prevConfiguration) { prevConfiguration->deleteLater(); } } void Indicator::addIndicator() { QFileDialog *fileDialog = new QFileDialog(nullptr , i18nc("add indicator", "Add Indicator") , QDir::homePath() , QStringLiteral("indicator.latte")); fileDialog->setFileMode(QFileDialog::AnyFile); fileDialog->setAcceptMode(QFileDialog::AcceptOpen); fileDialog->setDefaultSuffix("indicator.latte"); QStringList filters; filters << QString(i18nc("add indicator file", "Latte Indicator") + "(*.indicator.latte)"); fileDialog->setNameFilters(filters); connect(fileDialog, &QFileDialog::finished, fileDialog, &QFileDialog::deleteLater); connect(fileDialog, &QFileDialog::fileSelected, this, [&](const QString & file) { qDebug() << "Trying to import indicator file ::: " << file; m_corona->indicatorFactory()->importIndicatorFile(file); }); fileDialog->open(); } void Indicator::downloadIndicator() { //! call asynchronously in order to not crash when view settings window //! loses focus and it closes QTimer::singleShot(0, [this]() { m_corona->indicatorFactory()->downloadIndicator(); }); } void Indicator::removeIndicator(QString pluginId) { //! call asynchronously in order to not crash when view settings window //! loses focus and it closes QTimer::singleShot(0, [this, pluginId]() { m_corona->indicatorFactory()->removeIndicator(pluginId); }); } void Indicator::loadConfig() { auto config = m_view->containment()->config().group("Indicator"); m_customType = config.readEntry("customType", QString()); m_enabled = config.readEntry("enabled", true); m_enabledForApplets = config.readEntry("enabledForApplets", true); m_padding = config.readEntry("padding", (float)0.08); m_type = config.readEntry("type", "org.kde.latte.default"); } void Indicator::saveConfig() { auto config = m_view->containment()->config().group("Indicator"); config.writeEntry("customType", m_customType); config.writeEntry("enabled", m_enabled); config.writeEntry("enabledForApplets", m_enabledForApplets); config.writeEntry("padding", m_padding); config.writeEntry("type", m_type); config.sync(); } } }