update indicators runtime

--fixes to signals in ViewParts in order to avoid
crashes. Currently the recreateView approach is used
in order to reload indicators runtime dynamically.
The "View::setSource" approach does not reload the
indicators properly
pull/6/head
Michail Vourlakos 6 years ago
parent 85e49d41bf
commit ba6460e919

@ -128,34 +128,37 @@ void Factory::reload()
for (const auto &pluginDir : pluginDirs) { for (const auto &pluginDir : pluginDirs) {
if (pluginDir != "." && pluginDir != "..") { if (pluginDir != "." && pluginDir != "..") {
QString metadataFile = standard.absolutePath() + "/" + pluginDir + "/metadata.desktop"; QString metadataFile = standard.absolutePath() + "/" + pluginDir + "/metadata.desktop";
KPluginMetaData metadata = KPluginMetaData::fromDesktopFile(metadataFile);
if (metadataAreValid(metadata)) { if(QFileInfo(metadataFile).exists()) {
QString uiFile = standard.absolutePath() + "/" + pluginDir + "/package/" + metadata.value("X-Latte-MainScript"); KPluginMetaData metadata = KPluginMetaData::fromDesktopFile(metadataFile);
if (QFileInfo(uiFile).exists() && !m_plugins.contains(metadata.pluginId())) { if (metadataAreValid(metadata)) {
m_plugins[metadata.pluginId()] = metadata; QString uiFile = standard.absolutePath() + "/" + pluginDir + "/package/" + metadata.value("X-Latte-MainScript");
if ((metadata.pluginId() != "org.kde.latte.default") if (QFileInfo(uiFile).exists() && !m_plugins.contains(metadata.pluginId())) {
&& (metadata.pluginId() != "org.kde.latte.plasma")) { m_plugins[metadata.pluginId()] = metadata;
m_customPluginIds << metadata.pluginId();
m_customPluginNames << metadata.name();
}
if (standard.absolutePath().startsWith(QDir::homePath())) { if ((metadata.pluginId() != "org.kde.latte.default")
m_customLocalPluginIds << metadata.pluginId(); && (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"); m_pluginUiPaths[metadata.pluginId()] = QFileInfo(uiFile).absolutePath();
qDebug() << " Indicator Package Loaded ::: " << metadata.name() << " [" << metadata.pluginId() << "]" << " - [" <<pluginPath<<"]";
/*qDebug() << " Indicator value ::: " << metadata.pluginId(); QString pluginPath = metadata.fileName().remove("metadata.desktop");
qDebug() << " Indicator Package Loaded ::: " << metadata.name() << " [" << metadata.pluginId() << "]" << " - [" <<pluginPath<<"]";
/*qDebug() << " Indicator value ::: " << metadata.pluginId();
qDebug() << " Indicator value ::: " << metadata.fileName(); qDebug() << " Indicator value ::: " << metadata.fileName();
qDebug() << " Indicator value ::: " << metadata.value("X-Latte-MainScript"); qDebug() << " Indicator value ::: " << metadata.value("X-Latte-MainScript");
qDebug() << " Indicator value ::: " << metadata.value("X-Latte-ConfigUi"); qDebug() << " Indicator value ::: " << metadata.value("X-Latte-ConfigUi");
qDebug() << " Indicator value ::: " << metadata.value("X-Latte-ConfigXml");*/ qDebug() << " Indicator value ::: " << metadata.value("X-Latte-ConfigXml");*/
}
} }
} }
} }

@ -919,39 +919,35 @@ QList<Plasma::Containment *> GenericLayout::unassignFromLayout(Latte::View *latt
return containments; 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; return;
} }
if (!m_viewsToRecreate.contains(containment)) { int delay = delayed ? 350 : 0;
m_viewsToRecreate << containment; m_viewsToRecreate << containment;
//! give the time to config window to close itself first and then recreate the dock //! give the time to config window to close itself first and then recreate the dock
//! step:1 remove the latteview //! step:1 remove the latteview
QTimer::singleShot(350, [this, containment]() { QTimer::singleShot(delay, [this, containment]() {
auto view = m_latteViews.take(containment); auto view = m_latteViews[containment];
view->disconnectSensitiveSignals();
if (view) { //! step:2 add the new latteview
qDebug() << "recreate - step 1: removing dock for containment:" << containment->id(); connect(view, &QObject::destroyed, this, [this, containment]() {
auto view = m_latteViews.take(containment);
//! step:2 add the new latteview QTimer::singleShot(250, this, [this, containment]() {
connect(view, &QObject::destroyed, this, [this, containment]() { if (!m_latteViews.contains(containment)) {
QTimer::singleShot(250, this, [this, containment]() { qDebug() << "recreate - step 2: adding dock for containment:" << containment->id();
if (!m_latteViews.contains(containment)) { addView(containment);
qDebug() << "recreate - step 2: adding dock for containment:" << containment->id(); m_viewsToRecreate.removeAll(containment);
addView(containment); }
m_viewsToRecreate.removeAll(containment); });
}
});
});
view->disconnectSensitiveSignals();
view->deleteLater();
}
}); });
}
view->deleteLater();
});
} }

@ -111,7 +111,7 @@ public:
//! this function needs the layout to have first set the corona through initToCorona() function //! 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); virtual void addView(Plasma::Containment *containment, bool forceOnPrimary = false, int explicitScreen = -1, Layout::ViewsMap *occupied = nullptr);
void copyView(Plasma::Containment *containment); void copyView(Plasma::Containment *containment);
void recreateView(Plasma::Containment *containment); void recreateView(Plasma::Containment *containment, bool delayed = true);
bool latteViewExists(Plasma::Containment *containment); bool latteViewExists(Plasma::Containment *containment);
//! Available edges for specific view in that screen //! Available edges for specific view in that screen

@ -54,20 +54,14 @@ Indicator::Indicator(Latte::View *parent)
connect(m_view, &Latte::View::latteTasksArePresentChanged, this, &Indicator::latteTasksArePresentChanged); connect(m_view, &Latte::View::latteTasksArePresentChanged, this, &Indicator::latteTasksArePresentChanged);
connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::customPluginsChanged, [this]() { connect(m_view, &Latte::View::customPluginsChanged, [this]() {
if (!m_corona->indicatorFactory()->pluginExists(m_type)) { if (m_corona && !m_corona->indicatorFactory()->pluginExists(m_type)) {
setType("org.kde.latte.default"); setType("org.kde.latte.default");
} }
emit customPluginsChanged(); 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]() { connect(this, &Indicator::pluginChanged, [this]() {
if ((m_type != "org.kde.latte.default") && m_type != "org.kde.latte.plasma") { if ((m_type != "org.kde.latte.default") && m_type != "org.kde.latte.plasma") {
setCustomType(m_type); setCustomType(m_type);

@ -106,9 +106,7 @@ PrimaryConfigView::PrimaryConfigView(Plasma::Containment *containment, Latte::Vi
m_thicknessSyncTimer.start(); m_thicknessSyncTimer.start();
}); });
connections << connect(m_corona, &Latte::Corona::availableScreenRectChanged, this, [this]() { connections << connect(m_latteView, &Latte::View::availableScreenRectChangedForViewParts, this, &PrimaryConfigView::updateAvailableScreenGeometry);
updateAvailableScreenGeometry();
});
if (m_corona) { if (m_corona) {
connections << connect(m_corona, &Latte::Corona::raiseViewsTemporaryChanged, this, &PrimaryConfigView::raiseDocksTemporaryChanged); connections << connect(m_corona, &Latte::Corona::raiseViewsTemporaryChanged, this, &PrimaryConfigView::raiseDocksTemporaryChanged);
@ -382,7 +380,7 @@ void PrimaryConfigView::hideEvent(QHideEvent *ev)
m_latteView->containment()->setUserConfiguring(false); m_latteView->containment()->setUserConfiguring(false);
} }
// QQuickWindow::hideEvent(ev); // QQuickWindow::hideEvent(ev);
const auto mode = m_latteView->visibility()->mode(); const auto mode = m_latteView->visibility()->mode();
@ -406,8 +404,9 @@ void PrimaryConfigView::focusOutEvent(QFocusEvent *ev)
const auto *focusWindow = qGuiApp->focusWindow(); const auto *focusWindow = qGuiApp->focusWindow();
if ((focusWindow && (focusWindow->flags().testFlag(Qt::Popup) if (!m_latteView
|| focusWindow->flags().testFlag(Qt::ToolTip))) || (focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip)))
|| m_latteView->alternativesIsShown()) { || m_latteView->alternativesIsShown()) {
return; return;
} }

@ -27,6 +27,7 @@
#include "visibilitymanager.h" #include "visibilitymanager.h"
#include "settings/primaryconfigview.h" #include "settings/primaryconfigview.h"
#include "settings/secondaryconfigview.h" #include "settings/secondaryconfigview.h"
#include "../indicator/factory.h"
#include "../lattecorona.h" #include "../lattecorona.h"
#include "../layout/genericlayout.h" #include "../layout/genericlayout.h"
#include "../layouts/manager.h" #include "../layouts/manager.h"
@ -238,6 +239,11 @@ void View::init()
connect(m_contextMenu, &ViewPart::ContextMenu::menuChanged, this, &View::contextMenuIsShownChanged); 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); rootContext()->setContextProperty(QStringLiteral("latteView"), this);
@ -259,6 +265,19 @@ void View::init()
qDebug() << "SOURCE:" << source(); 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 bool View::inDelete() const
{ {
return m_inDelete; return m_inDelete;

@ -271,11 +271,16 @@ signals:
void absoluteGeometryChanged(const QRect &geometry); 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: private slots:
void availableScreenRectChangedFrom(View *origin); void availableScreenRectChangedFrom(View *origin);
void configViewCreatedFor(Latte::View *view); void configViewCreatedFor(Latte::View *view);
void hideWindowsForSlidingOut(); void hideWindowsForSlidingOut();
void preferredViewForShortcutsChangedSlot(Latte::View *view); void preferredViewForShortcutsChangedSlot(Latte::View *view);
void reloadSource();
void statusChanged(Plasma::Types::ItemStatus); void statusChanged(Plasma::Types::ItemStatus);
void restoreConfig(); void restoreConfig();

Loading…
Cancel
Save