1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-10 21:18:19 +03:00

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
This commit is contained in:
Michail Vourlakos 2019-06-20 17:42:49 +03:00
parent 85e49d41bf
commit ba6460e919
7 changed files with 74 additions and 58 deletions

View File

@ -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() << "]" << " - [" <<pluginPath<<"]";
m_pluginUiPaths[metadata.pluginId()] = QFileInfo(uiFile).absolutePath();
/*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.value("X-Latte-MainScript");
qDebug() << " Indicator value ::: " << metadata.value("X-Latte-ConfigUi");
qDebug() << " Indicator value ::: " << metadata.value("X-Latte-ConfigXml");*/
}
}
}
}

View File

@ -919,39 +919,35 @@ QList<Plasma::Containment *> 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();
});
}

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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();