remove m_desktopContainments

Summary:
with new corona containment query functions in D11361 the data
copy done in m_desktopContainments is no more necessary: this should
make things a bit more simple and robust

Test Plan: launched plasmashell, tried to add/remove activities and screens, all keeps working

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D11801
wilder-5.14
Marco Martin 8 years ago
parent 2082cfcbfa
commit 5898499c1f
  1. 61
      shell/shellcorona.cpp
  2. 2
      shell/shellcorona.h

@ -853,7 +853,6 @@ void ShellCorona::unload()
m_desktopViewforId.clear(); m_desktopViewforId.clear();
qDeleteAll(m_panelViews); qDeleteAll(m_panelViews);
m_panelViews.clear(); m_panelViews.clear();
m_desktopContainments.clear();
m_waitingPanels.clear(); m_waitingPanels.clear();
m_activityContainmentPlugins.clear(); m_activityContainmentPlugins.clear();
@ -1233,16 +1232,14 @@ void ShellCorona::addOutput(QScreen* screen)
Plasma::Containment *ShellCorona::createContainmentForActivity(const QString& activity, int screenNum) Plasma::Containment *ShellCorona::createContainmentForActivity(const QString& activity, int screenNum)
{ {
if (m_desktopContainments.contains(activity)) { for (Plasma::Containment *cont : containmentsForActivity(activity)) {
for (Plasma::Containment *cont : m_desktopContainments.value(activity)) { //in the case of a corrupt config file
//in the case of a corrupt config file //with multiple containments with same lastScreen
//with multiple containments with same lastScreen //it can happen two insertContainment happen for
//it can happen two insertContainment happen for //the same screen, leading to the old containment
//the same screen, leading to the old containment //to be destroyed
//to be destroyed if (!cont->destroyed() && cont->screen() == screenNum) {
if (!cont->destroyed() && cont->screen() == screenNum && cont->activity() == activity) { return cont;
return cont;
}
} }
} }
@ -1252,11 +1249,10 @@ Plasma::Containment *ShellCorona::createContainmentForActivity(const QString& ac
plugin = defaultContainmentPlugin(); plugin = defaultContainmentPlugin();
} }
Plasma::Containment *containment = containmentForScreen(screenNum, plugin, QVariantList()); Plasma::Containment *containment = containmentForScreen(screenNum, activity, plugin, QVariantList());
Q_ASSERT(containment); Q_ASSERT(containment);
if (containment) { if (containment) {
containment->setActivity(activity);
insertContainment(activity, screenNum, containment); insertContainment(activity, screenNum, containment);
} }
@ -1556,10 +1552,8 @@ void ShellCorona::activityAdded(const QString &id)
void ShellCorona::activityRemoved(const QString &id) void ShellCorona::activityRemoved(const QString &id)
{ {
m_activityContainmentPlugins.remove(id); m_activityContainmentPlugins.remove(id);
if (m_desktopContainments.contains(id)) { for (auto cont : containmentsForActivity(id)) {
for (auto cont : m_desktopContainments.value(id)) { cont->destroy();
cont->destroy();
}
} }
} }
@ -1596,7 +1590,8 @@ void ShellCorona::insertActivity(const QString &id, const QString &plugin)
Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin) Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin)
{ {
Plasma::Containment *oldContainment = containmentForScreen(screen); //search but not create
Plasma::Containment *oldContainment = containmentForScreen(screen, m_activityController->currentActivity(), QString());
//no valid containment in given screen, giving up //no valid containment in given screen, giving up
if (!oldContainment) { if (!oldContainment) {
@ -1675,7 +1670,6 @@ Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const
} }
view->setContainment(newContainment); view->setContainment(newContainment);
newContainment->setActivity(oldContainment->activity()); newContainment->setActivity(oldContainment->activity());
m_desktopContainments.remove(oldContainment->activity());
insertContainment(oldContainment->activity(), screen, newContainment); insertContainment(oldContainment->activity(), screen, newContainment);
//removing the focus from the item that is going to be destroyed //removing the focus from the item that is going to be destroyed
@ -1946,7 +1940,8 @@ void ShellCorona::stopCurrentActivity()
void ShellCorona::insertContainment(const QString &activity, int screenNum, Plasma::Containment *containment) void ShellCorona::insertContainment(const QString &activity, int screenNum, Plasma::Containment *containment)
{ {
Plasma::Containment *cont = nullptr; Plasma::Containment *cont = nullptr;
for (Plasma::Containment *c : m_desktopContainments.value(activity)) { auto candidates = containmentsForActivity(activity);
for (Plasma::Containment *c : candidates) {
//using lastScreen() instead of screen() catches also containments of activities that aren't the current one, so not assigned to a screen right now //using lastScreen() instead of screen() catches also containments of activities that aren't the current one, so not assigned to a screen right now
if (c->lastScreen() == screenNum) { if (c->lastScreen() == screenNum) {
cont = c; cont = c;
@ -1957,34 +1952,12 @@ void ShellCorona::insertContainment(const QString &activity, int screenNum, Plas
} }
} }
Q_ASSERT(!m_desktopContainments.value(activity).values().contains(containment)); Q_ASSERT(candidates.contains(containment));
Q_ASSERT(containment != cont);
if (cont) { if (cont) {
cont->destroy(); cont->destroy();
} }
m_desktopContainments[activity].insert(containment);
//when a containment gets deleted update our map of containments
connect(containment, SIGNAL(destroyed(QObject*)), this, SLOT(desktopContainmentDestroyed(QObject*)));
}
void ShellCorona::desktopContainmentDestroyed(QObject *obj)
{
// when QObject::destroyed arrives, ~Plasma::Containment has run,
// members of Containment are not accessible anymore,
// so keep ugly bookeeping by hand
auto containment = static_cast<Plasma::Containment*>(obj);
//explicitly specify the range by reference, as we need to remove stuff from the sets
for (QSet<Plasma::Containment *> &a : m_desktopContainments) {
QMutableSetIterator<Plasma::Containment *> it(a);
while (it.hasNext()) {
it.next();
if (it.value() == containment) {
it.remove();
return;
}
}
}
} }
void ShellCorona::showOpenGLNotCompatibleWarning() void ShellCorona::showOpenGLNotCompatibleWarning()

@ -200,7 +200,6 @@ private Q_SLOTS:
void primaryOutputChanged(); void primaryOutputChanged();
void panelContainmentDestroyed(QObject* cont); void panelContainmentDestroyed(QObject* cont);
void desktopContainmentDestroyed(QObject*);
void showOpenGLNotCompatibleWarning(); void showOpenGLNotCompatibleWarning();
void interactiveConsoleVisibilityChanged(bool visible); void interactiveConsoleVisibilityChanged(bool visible);
void handleScreenRemoved(QScreen* screen); void handleScreenRemoved(QScreen* screen);
@ -236,7 +235,6 @@ private:
KConfigGroup m_lnfDefaultsConfig; KConfigGroup m_lnfDefaultsConfig;
QList<Plasma::Containment *> m_waitingPanels; QList<Plasma::Containment *> m_waitingPanels;
QHash<QString, QString> m_activityContainmentPlugins; QHash<QString, QString> m_activityContainmentPlugins;
QHash<QString, QSet<Plasma::Containment *> > m_desktopContainments;
QAction *m_addPanelAction; QAction *m_addPanelAction;
QMenu *m_addPanelsMenu; QMenu *m_addPanelsMenu;
KPackage::Package m_lookAndFeelPackage; KPackage::Package m_lookAndFeelPackage;

Loading…
Cancel
Save