1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-25 14:03:58 +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,6 +128,8 @@ void Factory::reload()
for (const auto &pluginDir : pluginDirs) {
if (pluginDir != "." && pluginDir != "..") {
QString metadataFile = standard.absolutePath() + "/" + pluginDir + "/metadata.desktop";
if(QFileInfo(metadataFile).exists()) {
KPluginMetaData metadata = KPluginMetaData::fromDesktopFile(metadataFile);
if (metadataAreValid(metadata)) {
@ -162,6 +164,7 @@ void Factory::reload()
}
}
}
}
emit customPluginsChanged();
}

View File

@ -919,25 +919,24 @@ 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)) {
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]() {
auto view = m_latteViews.take(containment);
if (view) {
qDebug() << "recreate - step 1: removing dock for containment:" << containment->id();
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);
QTimer::singleShot(250, this, [this, containment]() {
if (!m_latteViews.contains(containment)) {
qDebug() << "recreate - step 2: adding dock for containment:" << containment->id();
@ -947,12 +946,9 @@ void GenericLayout::recreateView(Plasma::Containment *containment)
});
});
view->disconnectSensitiveSignals();
view->deleteLater();
}
});
}
}
bool GenericLayout::latteViewExists(Plasma::Containment *containment)

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);
@ -406,7 +404,8 @@ void PrimaryConfigView::focusOutEvent(QFocusEvent *ev)
const auto *focusWindow = qGuiApp->focusWindow();
if ((focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
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();