diff --git a/app/indicator/factory.cpp b/app/indicator/factory.cpp index 2901d1b9a..f815a4d3f 100644 --- a/app/indicator/factory.cpp +++ b/app/indicator/factory.cpp @@ -128,34 +128,37 @@ void Factory::reload() 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(metadataFile).exists()) { + KPluginMetaData metadata = KPluginMetaData::fromDesktopFile(metadataFile); - if (QFileInfo(uiFile).exists() && !m_plugins.contains(metadata.pluginId())) { - m_plugins[metadata.pluginId()] = metadata; + if (metadataAreValid(metadata)) { + QString uiFile = standard.absolutePath() + "/" + pluginDir + "/package/" + metadata.value("X-Latte-MainScript"); - if ((metadata.pluginId() != "org.kde.latte.default") - && (metadata.pluginId() != "org.kde.latte.plasma")) { - m_customPluginIds << metadata.pluginId(); - m_customPluginNames << metadata.name(); - } + if (QFileInfo(uiFile).exists() && !m_plugins.contains(metadata.pluginId())) { + m_plugins[metadata.pluginId()] = metadata; - if (standard.absolutePath().startsWith(QDir::homePath())) { - m_customLocalPluginIds << metadata.pluginId(); - } + if ((metadata.pluginId() != "org.kde.latte.default") + && (metadata.pluginId() != "org.kde.latte.plasma")) { + m_customPluginIds << metadata.pluginId(); + m_customPluginNames << metadata.name(); + } - m_pluginUiPaths[metadata.pluginId()] = QFileInfo(uiFile).absolutePath(); + if (standard.absolutePath().startsWith(QDir::homePath())) { + m_customLocalPluginIds << metadata.pluginId(); + } - QString pluginPath = metadata.fileName().remove("metadata.desktop"); - qDebug() << " Indicator Package Loaded ::: " << metadata.name() << " [" << metadata.pluginId() << "]" << " - [" < GenericLayout::unassignFromLayout(Latte::View *latt return containments; } -void GenericLayout::recreateView(Plasma::Containment *containment) +void GenericLayout::recreateView(Plasma::Containment *containment, bool delayed) { - if (!m_corona) { + if (!m_corona || m_viewsToRecreate.contains(containment) || !containment || !m_latteViews.contains(containment)) { return; } - if (!m_viewsToRecreate.contains(containment)) { - m_viewsToRecreate << containment; + int delay = delayed ? 350 : 0; + 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]() { + //! give the time to config window to close itself first and then recreate the dock + //! step:1 remove the latteview + QTimer::singleShot(delay, [this, containment]() { + auto view = m_latteViews[containment]; + view->disconnectSensitiveSignals(); + + //! step:2 add the new latteview + connect(view, &QObject::destroyed, this, [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->disconnectSensitiveSignals(); - view->deleteLater(); - } + 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(); + }); } diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 122db440b..3ebea935c 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -111,7 +111,7 @@ public: //! 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); + void recreateView(Plasma::Containment *containment, bool delayed = true); bool latteViewExists(Plasma::Containment *containment); //! Available edges for specific view in that screen diff --git a/app/view/indicator/indicator.cpp b/app/view/indicator/indicator.cpp index dfc6ff00c..9d71284bd 100644 --- a/app/view/indicator/indicator.cpp +++ b/app/view/indicator/indicator.cpp @@ -54,20 +54,14 @@ Indicator::Indicator(Latte::View *parent) 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)) { + connect(m_view, &Latte::View::customPluginsChanged, [this]() { + if (m_corona && !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->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); diff --git a/app/view/settings/primaryconfigview.cpp b/app/view/settings/primaryconfigview.cpp index 0217caf90..363336aed 100644 --- a/app/view/settings/primaryconfigview.cpp +++ b/app/view/settings/primaryconfigview.cpp @@ -106,9 +106,7 @@ PrimaryConfigView::PrimaryConfigView(Plasma::Containment *containment, Latte::Vi m_thicknessSyncTimer.start(); }); - connections << connect(m_corona, &Latte::Corona::availableScreenRectChanged, this, [this]() { - updateAvailableScreenGeometry(); - }); + connections << connect(m_latteView, &Latte::View::availableScreenRectChangedForViewParts, this, &PrimaryConfigView::updateAvailableScreenGeometry); if (m_corona) { connections << connect(m_corona, &Latte::Corona::raiseViewsTemporaryChanged, this, &PrimaryConfigView::raiseDocksTemporaryChanged); @@ -382,7 +380,7 @@ void PrimaryConfigView::hideEvent(QHideEvent *ev) m_latteView->containment()->setUserConfiguring(false); } - // QQuickWindow::hideEvent(ev); + // QQuickWindow::hideEvent(ev); const auto mode = m_latteView->visibility()->mode(); @@ -406,8 +404,9 @@ void PrimaryConfigView::focusOutEvent(QFocusEvent *ev) const auto *focusWindow = qGuiApp->focusWindow(); - if ((focusWindow && (focusWindow->flags().testFlag(Qt::Popup) - || focusWindow->flags().testFlag(Qt::ToolTip))) + if (!m_latteView + || (focusWindow && (focusWindow->flags().testFlag(Qt::Popup) + || focusWindow->flags().testFlag(Qt::ToolTip))) || m_latteView->alternativesIsShown()) { return; } diff --git a/app/view/view.cpp b/app/view/view.cpp index e8638c65b..e782680e0 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -27,6 +27,7 @@ #include "visibilitymanager.h" #include "settings/primaryconfigview.h" #include "settings/secondaryconfigview.h" +#include "../indicator/factory.h" #include "../lattecorona.h" #include "../layout/genericlayout.h" #include "../layouts/manager.h" @@ -238,6 +239,11 @@ void View::init() connect(m_contextMenu, &ViewPart::ContextMenu::menuChanged, this, &View::contextMenuIsShownChanged); + connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::pluginsUpdated, this, &View::reloadSource); + //! View sends this signal in order to avoid crashes from ViewPart::Indicator when the view is recreated + connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::customPluginsChanged, this, &View::customPluginsChanged); + connect(m_corona, &Latte::Corona::availableScreenRectChanged, this, &View::availableScreenRectChangedForViewParts); + ///!!!!! rootContext()->setContextProperty(QStringLiteral("latteView"), this); @@ -259,6 +265,19 @@ void View::init() qDebug() << "SOURCE:" << source(); } +void View::reloadSource() +{ + if (m_layout && containment()) { + if (settingsWindowIsShown()) { + m_configView->deleteLater(); + } + + engine()->clearComponentCache(); + m_layout->recreateView(containment(), settingsWindowIsShown()); + } +} + + bool View::inDelete() const { return m_inDelete; diff --git a/app/view/view.h b/app/view/view.h index 2e7865292..78aab38e5 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -271,11 +271,16 @@ signals: void absoluteGeometryChanged(const QRect &geometry); + //! pass on signals to children in order to avoid crashes when View is recreated or destroyed + void availableScreenRectChangedForViewParts(); + void customPluginsChanged(); + private slots: void availableScreenRectChangedFrom(View *origin); void configViewCreatedFor(Latte::View *view); void hideWindowsForSlidingOut(); void preferredViewForShortcutsChangedSlot(Latte::View *view); + void reloadSource(); void statusChanged(Plasma::Types::ItemStatus); void restoreConfig();