mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-11 13:18:13 +03:00
fix #84,closing Latte cleans config file
--when Latte is closing removes all entries for containments that are obsolete
This commit is contained in:
parent
17b48b6eea
commit
5b1d152dc9
@ -44,7 +44,7 @@ DockCorona::DockCorona(QObject *parent)
|
|||||||
m_activityConsumer(new KActivities::Consumer(this))
|
m_activityConsumer(new KActivities::Consumer(this))
|
||||||
{
|
{
|
||||||
KPackage::Package package(new DockPackage(this));
|
KPackage::Package package(new DockPackage(this));
|
||||||
|
|
||||||
if (!package.isValid()) {
|
if (!package.isValid()) {
|
||||||
qWarning() << staticMetaObject.className()
|
qWarning() << staticMetaObject.className()
|
||||||
<< "the package" << package.metadata().rawData() << "is invalid!";
|
<< "the package" << package.metadata().rawData() << "is invalid!";
|
||||||
@ -53,30 +53,32 @@ DockCorona::DockCorona(QObject *parent)
|
|||||||
qDebug() << staticMetaObject.className()
|
qDebug() << staticMetaObject.className()
|
||||||
<< "the package" << package.metadata().rawData() << "is valid!";
|
<< "the package" << package.metadata().rawData() << "is valid!";
|
||||||
}
|
}
|
||||||
|
|
||||||
setKPackage(package);
|
setKPackage(package);
|
||||||
qmlRegisterTypes();
|
qmlRegisterTypes();
|
||||||
|
|
||||||
connect(this, &Corona::containmentAdded, this, &DockCorona::addDock);
|
connect(this, &Corona::containmentAdded, this, &DockCorona::addDock);
|
||||||
|
|
||||||
connect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &DockCorona::load);
|
connect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &DockCorona::load);
|
||||||
}
|
}
|
||||||
|
|
||||||
DockCorona::~DockCorona()
|
DockCorona::~DockCorona()
|
||||||
{
|
{
|
||||||
|
cleanConfig();
|
||||||
|
|
||||||
while (!containments().isEmpty()) {
|
while (!containments().isEmpty()) {
|
||||||
//deleting a containment will remove it from the list due to QObject::destroyed connect in Corona
|
//deleting a containment will remove it from the list due to QObject::destroyed connect in Corona
|
||||||
delete containments().first();
|
delete containments().first();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDeleteAll(m_dockViews);
|
qDeleteAll(m_dockViews);
|
||||||
qDeleteAll(m_waitingDockViews);
|
qDeleteAll(m_waitingDockViews);
|
||||||
m_dockViews.clear();
|
m_dockViews.clear();
|
||||||
m_waitingDockViews.clear();
|
m_waitingDockViews.clear();
|
||||||
|
|
||||||
disconnect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &DockCorona::load);
|
disconnect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &DockCorona::load);
|
||||||
delete m_activityConsumer;
|
delete m_activityConsumer;
|
||||||
|
|
||||||
qDebug() << "deleted" << this;
|
qDebug() << "deleted" << this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +87,37 @@ void DockCorona::load()
|
|||||||
loadLayout();
|
loadLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DockCorona::cleanConfig()
|
||||||
|
{
|
||||||
|
auto containmentsEntries = config()->group("Containments");
|
||||||
|
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
foreach (auto id, containmentsEntries.groupList()) {
|
||||||
|
if (!containmentExists(id.toInt())) {
|
||||||
|
containmentsEntries.group(id).deleteGroup();
|
||||||
|
changed = true;
|
||||||
|
qDebug() << "obsolete containment configuration deleted:" << id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
config()->sync();
|
||||||
|
qDebug() << "configuration file cleaned...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DockCorona::containmentExists(int id) const
|
||||||
|
{
|
||||||
|
foreach (auto containment, containments()) {
|
||||||
|
if (id == containment->id()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int DockCorona::numScreens() const
|
int DockCorona::numScreens() const
|
||||||
{
|
{
|
||||||
return qGuiApp->screens().count();
|
return qGuiApp->screens().count();
|
||||||
@ -93,51 +126,51 @@ int DockCorona::numScreens() const
|
|||||||
QRect DockCorona::screenGeometry(int id) const
|
QRect DockCorona::screenGeometry(int id) const
|
||||||
{
|
{
|
||||||
const auto screens = qGuiApp->screens();
|
const auto screens = qGuiApp->screens();
|
||||||
|
|
||||||
if (id >= 0 && id < screens.count()) {
|
if (id >= 0 && id < screens.count()) {
|
||||||
return screens[id]->geometry();
|
return screens[id]->geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
return qGuiApp->primaryScreen()->geometry();
|
return qGuiApp->primaryScreen()->geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegion DockCorona::availableScreenRegion(int id) const
|
QRegion DockCorona::availableScreenRegion(int id) const
|
||||||
{
|
{
|
||||||
const auto screens = qGuiApp->screens();
|
const auto screens = qGuiApp->screens();
|
||||||
|
|
||||||
if (id >= 0 && id < screens.count()) {
|
if (id >= 0 && id < screens.count()) {
|
||||||
return screens[id]->geometry();
|
return screens[id]->geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
return qGuiApp->primaryScreen()->availableGeometry();
|
return qGuiApp->primaryScreen()->availableGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect DockCorona::availableScreenRect(int id) const
|
QRect DockCorona::availableScreenRect(int id) const
|
||||||
{
|
{
|
||||||
const auto screens = qGuiApp->screens();
|
const auto screens = qGuiApp->screens();
|
||||||
|
|
||||||
if (id >= 0 && id < screens.count()) {
|
if (id >= 0 && id < screens.count()) {
|
||||||
return screens[id]->availableGeometry();
|
return screens[id]->availableGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
return qGuiApp->primaryScreen()->availableGeometry();
|
return qGuiApp->primaryScreen()->availableGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DockCorona::primaryScreenId() const
|
int DockCorona::primaryScreenId() const
|
||||||
{
|
{
|
||||||
const auto screens = qGuiApp->screens();
|
const auto screens = qGuiApp->screens();
|
||||||
|
|
||||||
int id = -1;
|
int id = -1;
|
||||||
|
|
||||||
for (int i = 0; i < screens.size(); ++i) {
|
for (int i = 0; i < screens.size(); ++i) {
|
||||||
auto *scr = screens.at(i);
|
auto *scr = screens.at(i);
|
||||||
|
|
||||||
if (scr == qGuiApp->primaryScreen()) {
|
if (scr == qGuiApp->primaryScreen()) {
|
||||||
id = i;
|
id = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,14 +207,14 @@ QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const
|
|||||||
|
|
||||||
//when screen=-1 is passed then the primaryScreenid is used
|
//when screen=-1 is passed then the primaryScreenid is used
|
||||||
int fixedScreen = (screen == -1) ? primaryScreenId() : screen;
|
int fixedScreen = (screen == -1) ? primaryScreenId() : screen;
|
||||||
|
|
||||||
for (const auto &view : m_dockViews) {
|
for (const auto &view : m_dockViews) {
|
||||||
if (view && view->containment()
|
if (view && view->containment()
|
||||||
&& view->containment()->screen() == fixedScreen) {
|
&& view->containment()->screen() == fixedScreen) {
|
||||||
edges.removeOne(view->location());
|
edges.removeOne(view->location());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return edges;
|
return edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +225,7 @@ int DockCorona::screenForContainment(const Plasma::Containment *containment) con
|
|||||||
if (view->screen())
|
if (view->screen())
|
||||||
return qGuiApp->screens().indexOf(view->screen());
|
return qGuiApp->screens().indexOf(view->screen());
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,33 +235,33 @@ void DockCorona::addDock(Plasma::Containment *containment)
|
|||||||
qWarning() << "the requested containment plugin can not be located or loaded";
|
qWarning() << "the requested containment plugin can not be located or loaded";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the system tray is a containment that behaves as an applet
|
// the system tray is a containment that behaves as an applet
|
||||||
// so a dockview shouldnt be created for it
|
// so a dockview shouldnt be created for it
|
||||||
KPluginMetaData metadata = containment->kPackage().metadata();
|
KPluginMetaData metadata = containment->kPackage().metadata();
|
||||||
|
|
||||||
if (metadata.pluginId() == "org.kde.plasma.private.systemtray") {
|
if (metadata.pluginId() == "org.kde.plasma.private.systemtray") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DockView *dock, m_dockViews) {
|
foreach (DockView *dock, m_dockViews) {
|
||||||
if (dock->containment() == containment) {
|
if (dock->containment() == containment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Adding dock for container...";
|
qDebug() << "Adding dock for container...";
|
||||||
|
|
||||||
auto dockView = new DockView(this);
|
auto dockView = new DockView(this);
|
||||||
dockView->init();
|
dockView->init();
|
||||||
dockView->setContainment(containment);
|
dockView->setContainment(containment);
|
||||||
connect(containment, &QObject::destroyed, this, &DockCorona::dockContainmentDestroyed);
|
connect(containment, &QObject::destroyed, this, &DockCorona::dockContainmentDestroyed);
|
||||||
connect(containment, &Plasma::Applet::destroyedChanged, this, &DockCorona::destroyedChanged);
|
connect(containment, &Plasma::Applet::destroyedChanged, this, &DockCorona::destroyedChanged);
|
||||||
|
|
||||||
dockView->show();
|
dockView->show();
|
||||||
|
|
||||||
m_dockViews[containment] = dockView;
|
m_dockViews[containment] = dockView;
|
||||||
|
|
||||||
emit containmentsNoChanged();
|
emit containmentsNoChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,38 +295,38 @@ void DockCorona::loadDefaultLayout()
|
|||||||
qDebug() << "loading default layout";
|
qDebug() << "loading default layout";
|
||||||
//! Settting mutable for create a containment
|
//! Settting mutable for create a containment
|
||||||
setImmutability(Plasma::Types::Mutable);
|
setImmutability(Plasma::Types::Mutable);
|
||||||
|
|
||||||
QVariantList args;
|
QVariantList args;
|
||||||
auto defaultContainment = createContainmentDelayed("org.kde.latte.containment", args);
|
auto defaultContainment = createContainmentDelayed("org.kde.latte.containment", args);
|
||||||
|
|
||||||
defaultContainment->setContainmentType(Plasma::Types::PanelContainment);
|
defaultContainment->setContainmentType(Plasma::Types::PanelContainment);
|
||||||
defaultContainment->init();
|
defaultContainment->init();
|
||||||
|
|
||||||
if (!defaultContainment || !defaultContainment->kPackage().isValid()) {
|
if (!defaultContainment || !defaultContainment->kPackage().isValid()) {
|
||||||
qWarning() << "the requested containment plugin can not be located or loaded";
|
qWarning() << "the requested containment plugin can not be located or loaded";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto config = defaultContainment->config();
|
auto config = defaultContainment->config();
|
||||||
defaultContainment->restore(config);
|
defaultContainment->restore(config);
|
||||||
|
|
||||||
QList<Plasma::Types::Location> edges = freeEdges(defaultContainment->screen());
|
QList<Plasma::Types::Location> edges = freeEdges(defaultContainment->screen());
|
||||||
|
|
||||||
if (edges.count() > 0) {
|
if (edges.count() > 0) {
|
||||||
defaultContainment->setLocation(edges.at(0));
|
defaultContainment->setLocation(edges.at(0));
|
||||||
} else {
|
} else {
|
||||||
defaultContainment->setLocation(Plasma::Types::BottomEdge);
|
defaultContainment->setLocation(Plasma::Types::BottomEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultContainment->updateConstraints(Plasma::Types::StartupCompletedConstraint);
|
defaultContainment->updateConstraints(Plasma::Types::StartupCompletedConstraint);
|
||||||
defaultContainment->save(config);
|
defaultContainment->save(config);
|
||||||
requestConfigSync();
|
requestConfigSync();
|
||||||
defaultContainment->flushPendingConstraintsEvents();
|
defaultContainment->flushPendingConstraintsEvents();
|
||||||
emit containmentAdded(defaultContainment);
|
emit containmentAdded(defaultContainment);
|
||||||
emit containmentCreated(defaultContainment);
|
emit containmentCreated(defaultContainment);
|
||||||
|
|
||||||
addDock(defaultContainment);
|
addDock(defaultContainment);
|
||||||
|
|
||||||
defaultContainment->createApplet(QStringLiteral("org.kde.latte.plasmoid"));
|
defaultContainment->createApplet(QStringLiteral("org.kde.latte.plasmoid"));
|
||||||
defaultContainment->createApplet(QStringLiteral("org.kde.plasma.analogclock"));
|
defaultContainment->createApplet(QStringLiteral("org.kde.plasma.analogclock"));
|
||||||
}
|
}
|
||||||
@ -303,7 +336,7 @@ inline void DockCorona::qmlRegisterTypes() const
|
|||||||
constexpr auto uri = "org.kde.latte.shell";
|
constexpr auto uri = "org.kde.latte.shell";
|
||||||
constexpr auto vMajor = 0;
|
constexpr auto vMajor = 0;
|
||||||
constexpr auto vMinor = 2;
|
constexpr auto vMinor = 2;
|
||||||
|
|
||||||
// qmlRegisterUncreatableType<Candil::Dock>(uri, vMajor, vMinor, "Dock", "class Dock uncreatable");
|
// qmlRegisterUncreatableType<Candil::Dock>(uri, vMajor, vMinor, "Dock", "class Dock uncreatable");
|
||||||
// qmlRegisterUncreatableType<Candil::VisibilityManager>(uri, vMajor, vMinor, "VisibilityManager", "class VisibilityManager uncreatable");
|
// qmlRegisterUncreatableType<Candil::VisibilityManager>(uri, vMajor, vMinor, "VisibilityManager", "class VisibilityManager uncreatable");
|
||||||
// qmlRegisterUncreatableType<NowDockView>(uri, vMajor, vMinor, "DockView", "class DockView uncreatable");
|
// qmlRegisterUncreatableType<NowDockView>(uri, vMajor, vMinor, "DockView", "class DockView uncreatable");
|
||||||
|
@ -39,44 +39,46 @@ namespace Latte {
|
|||||||
|
|
||||||
class DockCorona : public Plasma::Corona {
|
class DockCorona : public Plasma::Corona {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DockCorona(QObject *parent = nullptr);
|
DockCorona(QObject *parent = nullptr);
|
||||||
virtual ~DockCorona();
|
virtual ~DockCorona();
|
||||||
|
|
||||||
int numScreens() const override;
|
int numScreens() const override;
|
||||||
QRect screenGeometry(int id) const override;
|
QRect screenGeometry(int id) const override;
|
||||||
QRegion availableScreenRegion(int id) const override;
|
QRegion availableScreenRegion(int id) const override;
|
||||||
QRect availableScreenRect(int id) const override;
|
QRect availableScreenRect(int id) const override;
|
||||||
|
|
||||||
QList<Plasma::Types::Location> freeEdges(int screen) const;
|
QList<Plasma::Types::Location> freeEdges(int screen) const;
|
||||||
|
|
||||||
int docksCount(int screen) const;
|
int docksCount(int screen) const;
|
||||||
int screenForContainment(const Plasma::Containment *containment) const override;
|
int screenForContainment(const Plasma::Containment *containment) const override;
|
||||||
|
|
||||||
void addDock(Plasma::Containment *containment);
|
void addDock(Plasma::Containment *containment);
|
||||||
|
|
||||||
void closeApplication();
|
void closeApplication();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadDefaultLayout() override;
|
void loadDefaultLayout() override;
|
||||||
void dockContainmentDestroyed(QObject *cont);
|
void dockContainmentDestroyed(QObject *cont);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void configurationShown(PlasmaQuick::ConfigView *configView);
|
void configurationShown(PlasmaQuick::ConfigView *configView);
|
||||||
void containmentsNoChanged();
|
void containmentsNoChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void destroyedChanged(bool destroyed);
|
void destroyedChanged(bool destroyed);
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void cleanConfig();
|
||||||
|
bool containmentExists(int id) const;
|
||||||
void qmlRegisterTypes() const;
|
void qmlRegisterTypes() const;
|
||||||
int primaryScreenId() const;
|
int primaryScreenId() const;
|
||||||
|
|
||||||
QHash<const Plasma::Containment *, DockView *> m_dockViews;
|
QHash<const Plasma::Containment *, DockView *> m_dockViews;
|
||||||
QHash<const Plasma::Containment *, DockView *> m_waitingDockViews;
|
QHash<const Plasma::Containment *, DockView *> m_waitingDockViews;
|
||||||
|
|
||||||
KActivities::Consumer *m_activityConsumer;
|
KActivities::Consumer *m_activityConsumer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user