support loading for the new architecture

pull/1/head
Michail Vourlakos 8 years ago
parent 2d22b2c243
commit 091295126d

@ -82,6 +82,7 @@ DockCorona::DockCorona(QObject *parent)
setKPackage(package);
//! global settings must be loaded after the package has been set
m_globalSettings->load();
m_universalSettings->load();
m_layoutManager->load();
qmlRegisterTypes();
@ -136,7 +137,7 @@ DockCorona::~DockCorona()
QDir tempLayoutDir(m_layoutDir);
if (tempLayoutDir.exists() && m_layoutDir.startsWith("/tmp")) {
qDebug()<< "old layout directory should be deleted... - " << tempLayoutDir.absolutePath();
qDebug() << "old layout directory should be deleted... - " << tempLayoutDir.absolutePath();
tempLayoutDir.removeRecursively();
}
}
@ -159,10 +160,20 @@ void DockCorona::load()
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &DockCorona::screenCountChanged);
connect(m_screenPool, &ScreenPool::primaryPoolChanged, this, &DockCorona::screenCountChanged);
loadLayout();
foreach (auto containment, containments())
addDock(containment);
QString defaultLayoutPath = m_layoutManager->layoutPath(m_universalSettings->currentLayoutName());
if (!defaultLayoutPath.isEmpty()) {
qDebug() << "loading config file for layout:" << m_universalSettings->currentLayoutName() << " - " << defaultLayoutPath;
loadLayout(defaultLayoutPath);
foreach (auto containment, containments())
addDock(containment);
} else {
qDebug() << "NOT FOUND, config file for layout:" << m_universalSettings->currentLayoutName() << " - " << defaultLayoutPath;
//in such case we cannot load Latte we must first make sure we have created at least a My Layout in the latte directory
}
}
}
@ -203,8 +214,8 @@ bool DockCorona::reloadLayout(QString path)
addDock(containment);
if (oldLayoutDir.exists() && oldLayoutDir.absolutePath().startsWith("/tmp")
&& oldLayoutDir.absolutePath() != path) {
qDebug()<< "old layout directory should be deleted... - "<< oldLayoutDir.absolutePath();
&& oldLayoutDir.absolutePath() != path) {
qDebug() << "old layout directory should be deleted... - " << oldLayoutDir.absolutePath();
oldLayoutDir.removeRecursively();
}
@ -232,7 +243,7 @@ void DockCorona::updateConfigs()
const auto homeLatterc = QDir::homePath() + "/.config/lattedockrc";
const auto homeAppletsrc = QDir::homePath() + "/.config/lattedock-appletsrc";
if (QFile::remove(homeLatterc) && QFile::remove(homeAppletsrc)){
if (QFile::remove(homeLatterc) && QFile::remove(homeAppletsrc)) {
QFile::copy(latterc.fileName() , homeLatterc);
QFile::copy(appletsrc.fileName() , homeAppletsrc);
}
@ -258,7 +269,7 @@ void DockCorona::setupWaylandIntegration()
registry->create(connection);
connect(registry, &Registry::plasmaShellAnnounced, this
, [this, registry](quint32 name, quint32 version) {
, [this, registry](quint32 name, quint32 version) {
m_waylandDockCorona = registry->createPlasmaShell(name, version, this);
});
@ -419,66 +430,66 @@ QRegion DockCorona::availableScreenRegion(int id) const
// need calculate available space for top and bottom location,
// because the left and right are those who dodge others docks
switch (view->location()) {
case Plasma::Types::TopEdge:
if (view->behaveAsPlasmaPanel()) {
available -= view->geometry();
} else {
QRect realGeometry;
int realWidth = view->maxLength() * view->width();
case Plasma::Types::TopEdge:
if (view->behaveAsPlasmaPanel()) {
available -= view->geometry();
} else {
QRect realGeometry;
int realWidth = view->maxLength() * view->width();
switch (view->alignment()) {
case Latte::Dock::Left:
realGeometry = QRect(view->x(), view->y(),
realWidth, realThickness);
break;
switch (view->alignment()) {
case Latte::Dock::Left:
realGeometry = QRect(view->x(), view->y(),
realWidth, realThickness);
break;
case Latte::Dock::Center:
case Latte::Dock::Justify:
realGeometry = QRect(qMax(view->geometry().x(), view->geometry().center().x() - realWidth / 2) , view->y(),
realWidth , realThickness);
break;
case Latte::Dock::Center:
case Latte::Dock::Justify:
realGeometry = QRect(qMax(view->geometry().x(), view->geometry().center().x() - realWidth / 2) , view->y(),
realWidth , realThickness);
break;
case Latte::Dock::Right:
realGeometry = QRect(view->geometry().right() - realWidth + 1, view->y(),
realWidth, realThickness);
break;
}
case Latte::Dock::Right:
realGeometry = QRect(view->geometry().right() - realWidth + 1, view->y(),
realWidth, realThickness);
break;
available -= realGeometry;
}
available -= realGeometry;
}
break;
break;
case Plasma::Types::BottomEdge:
if (view->behaveAsPlasmaPanel()) {
available -= view->geometry();
} else {
QRect realGeometry;
int realWidth = view->maxLength() * view->width();
int realY = view->geometry().bottom() - realThickness + 1;
switch (view->alignment()) {
case Latte::Dock::Left:
realGeometry = QRect(view->x(), realY,
realWidth, realThickness);
break;
case Plasma::Types::BottomEdge:
if (view->behaveAsPlasmaPanel()) {
available -= view->geometry();
} else {
QRect realGeometry;
int realWidth = view->maxLength() * view->width();
int realY = view->geometry().bottom() - realThickness + 1;
switch (view->alignment()) {
case Latte::Dock::Left:
realGeometry = QRect(view->x(), realY,
realWidth, realThickness);
break;
case Latte::Dock::Center:
case Latte::Dock::Justify:
realGeometry = QRect(qMax(view->geometry().x(), view->geometry().center().x() - realWidth / 2),
realY, realWidth, realThickness);
break;
case Latte::Dock::Center:
case Latte::Dock::Justify:
realGeometry = QRect(qMax(view->geometry().x(), view->geometry().center().x() - realWidth / 2),
realY, realWidth, realThickness);
break;
case Latte::Dock::Right:
realGeometry = QRect(view->geometry().right() - realWidth + 1, realY,
realWidth, realThickness);
break;
}
case Latte::Dock::Right:
realGeometry = QRect(view->geometry().right() - realWidth + 1, realY,
realWidth, realThickness);
break;
available -= realGeometry;
}
available -= realGeometry;
}
break;
break;
}
}
}
@ -524,13 +535,13 @@ QRect DockCorona::availableScreenRect(int id) const
// need calculate available space for top and bottom location,
// because the left and right are those who dodge others docks
switch (view->location()) {
case Plasma::Types::TopEdge:
available.setTopLeft({available.x(), dockRect.bottom()});
break;
case Plasma::Types::TopEdge:
available.setTopLeft({available.x(), dockRect.bottom()});
break;
case Plasma::Types::BottomEdge:
available.setBottomLeft({available.x(), dockRect.top()});
break;
case Plasma::Types::BottomEdge:
available.setBottomLeft({available.x(), dockRect.top()});
break;
}
}
}
@ -617,7 +628,7 @@ void DockCorona::syncDockViews()
//! 2. when a dock in explicit, not running and the associated screen currently exists
//! e.g. the screen has just been added
if (((onPrimary && freeEdges(qGuiApp->primaryScreen()).contains(location)) || (!onPrimary && (m_screenPool->connector(id) == scr->name())))
&& (!m_dockViews.contains(cont)) && session == currentSession()) {
&& (!m_dockViews.contains(cont)) && session == currentSession()) {
qDebug() << "screen Count signal: view must be added... for:" << scr->name();
addDock(cont);
}
@ -639,7 +650,7 @@ void DockCorona::syncDockViews()
foreach (auto scr, qGuiApp->screens()) {
if (scr->name() == view->currentScreen()
|| (view->onPrimary() && scr == qGuiApp->primaryScreen() ) ) {
|| (view->onPrimary() && scr == qGuiApp->primaryScreen())) {
found = true;
break;
}
@ -651,7 +662,7 @@ void DockCorona::syncDockViews()
}
if (!found && !view->onPrimary() && (m_dockViews.size() > 1) && m_dockViews.contains(view->containment())
&& !(view->tasksPresent() && noDocksWithTasks() == 1)) { //do not delete last dock containing tasks
&& !(view->tasksPresent() && noDocksWithTasks() == 1)) { //do not delete last dock containing tasks
if (view->tasksPresent()) {
if (preserveContainmentId == -1)
preserveContainmentId = view->containment()->id();
@ -672,7 +683,7 @@ void DockCorona::syncDockViews()
foreach (auto scr, qGuiApp->screens()) {
if (scr->name() == view->currentScreen()
|| (view->onPrimary() && scr == qGuiApp->primaryScreen()) ) {
|| (view->onPrimary() && scr == qGuiApp->primaryScreen())) {
found = true;
break;
}
@ -830,7 +841,7 @@ QList<Plasma::Types::Location> DockCorona::freeEdges(QScreen *screen) const
{
using Plasma::Types;
QList<Types::Location> edges{Types::BottomEdge, Types::LeftEdge,
Types::TopEdge, Types::RightEdge};
Types::TopEdge, Types::RightEdge};
for (auto *view : m_dockViews) {
if (view && view->currentScreen() == screen->name() && view->session() == m_session) {
@ -845,7 +856,7 @@ QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const
{
using Plasma::Types;
QList<Types::Location> edges{Types::BottomEdge, Types::LeftEdge,
Types::TopEdge, Types::RightEdge};
Types::TopEdge, Types::RightEdge};
QScreen *scr = m_screenPool->screenForId(screen);
@ -897,8 +908,8 @@ int DockCorona::screenForContainment(const Plasma::Containment *containment) con
for (auto screen : qGuiApp->screens()) {
// containment->lastScreen() == m_screenPool->id(screen->name()) to check if the lastScreen refers to a screen that exists/it's known
if (containment->lastScreen() == m_screenPool->id(screen->name()) &&
(containment->activity() == m_activityConsumer->currentActivity() ||
containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) {
(containment->activity() == m_activityConsumer->currentActivity() ||
containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) {
return containment->lastScreen();
}
}

@ -79,6 +79,9 @@ bool Importer::updateOldConfiguration()
}
}
m_manager->corona()->universalSettings()->setCurrentLayoutName(i18n("My Layout"));
m_manager->corona()->universalSettings()->setVersion(2);
return true;
}

@ -52,4 +52,16 @@ DockCorona *LayoutManager::corona()
return m_corona;
}
QString LayoutManager::layoutPath(QString layoutName)
{
QString path = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte";
if (!QFile(path).exists()) {
path = "";
}
return path;
}
}

@ -39,9 +39,11 @@ public:
LayoutManager(QObject *parent = nullptr);
~LayoutManager() override;
DockCorona *corona();
void load();
DockCorona *corona();
QString layoutPath(QString layoutName);
private:
DockCorona *m_corona{nullptr};

@ -102,7 +102,6 @@ void LayoutSettings::setGlobalLaunchers(QStringList launchers)
emit globalLaunchersChanged();
}
void LayoutSettings::loadConfig()
{
m_version = m_layoutGroup.readEntry("version", 1);
@ -117,5 +116,4 @@ void LayoutSettings::saveConfig()
m_layoutGroup.writeEntry("globalLaunchers", m_globalLaunchers);
}
}

@ -27,6 +27,7 @@ UniversalSettings::UniversalSettings(KSharedConfig::Ptr config, QObject *parent)
m_config(config),
m_universalGroup(KConfigGroup(config, QStringLiteral("UniversalSettings")))
{
connect(this, &UniversalSettings::currentLayoutNameChanged, this, &UniversalSettings::saveConfig);
connect(this, &UniversalSettings::versionChanged, this, &UniversalSettings::saveConfig);
connect(this, &UniversalSettings::exposeLayoutsMenuChanged, this, &UniversalSettings::saveConfig);
}
@ -74,16 +75,33 @@ void UniversalSettings::setVersion(int ver)
emit versionChanged();
}
QString UniversalSettings::currentLayoutName() const
{
return m_currentLayoutName;
}
void UniversalSettings::setCurrentLayoutName(QString layoutName)
{
if (m_currentLayoutName == layoutName) {
return;
}
m_currentLayoutName = layoutName;
emit currentLayoutNameChanged();
}
void UniversalSettings::loadConfig()
{
m_version = m_universalGroup.readEntry("version", 1);
m_exposeLayoutsMenu = m_universalGroup.readEntry("exposeLayoutsMenu", false);
m_currentLayoutName = m_universalGroup.readEntry("currentLayout", QString());
}
void UniversalSettings::saveConfig()
{
m_universalGroup.writeEntry("version", m_version);
m_universalGroup.writeEntry("exposeLayoutsMenu", m_exposeLayoutsMenu);
m_universalGroup.writeEntry("currentLayout", m_currentLayoutName);
m_universalGroup.sync();
}

@ -26,6 +26,8 @@
#include <KConfigGroup>
#include <KSharedConfig>
#include "layoutsettings.h"
namespace Latte {
//! This class holds all the settings that are universally available
@ -35,6 +37,8 @@ class UniversalSettings : public QObject {
//Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
Q_PROPERTY(bool exposeLayoutsMenu READ exposeLayoutsMenu WRITE setExposeLayoutsMenu NOTIFY exposeLayoutsMenuChanged)
Q_PROPERTY(QString currentLayoutName READ currentLayoutName WRITE setCurrentLayoutName NOTIFY currentLayoutNameChanged)
//Q_PROPERTY(Latte::Dock::SessionType currentSession READ currentSession WRITE setCurrentSession NOTIFY currentSessionChanged)
//Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged)
@ -52,7 +56,11 @@ public:
int version() const;
void setVersion(int ver);
QString currentLayoutName() const;
void setCurrentLayoutName(QString layoutName);
signals:
void currentLayoutNameChanged();
void exposeLayoutsMenuChanged();
void versionChanged();
@ -68,8 +76,11 @@ private:
//when there isnt a version it is an old universal file
int m_version{1};
QString m_currentLayoutName;
KConfigGroup m_universalGroup;
KSharedConfig::Ptr m_config;
};
}

Loading…
Cancel
Save