From 75f3b1d4d219a5dbbf04c477cf40e3277962c53a Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 3 Jul 2017 20:40:18 +0300 Subject: [PATCH] update layouts to new architecture --the config window now exposes only the confirmed layouts and can update its layout accordingly --- app/layoutmanager.cpp | 39 +++++++++++++++- app/layoutmanager.h | 13 ++++++ .../configuration/AppearanceConfig.qml | 44 ++++++++++++------- 3 files changed, 78 insertions(+), 18 deletions(-) diff --git a/app/layoutmanager.cpp b/app/layoutmanager.cpp index 5e4ffba0e..a05f5ef89 100644 --- a/app/layoutmanager.cpp +++ b/app/layoutmanager.cpp @@ -47,6 +47,8 @@ LayoutManager::LayoutManager(QObject *parent) m_addWidgetsAction = new QAction(addWidIcon, i18n("Add Widgets..."), this); m_addWidgetsAction->setStatusTip(i18n("Show Plasma Widget Explorer")); connect(m_addWidgetsAction, &QAction::triggered, this, &LayoutManager::showWidgetsExplorer); + + connect(m_corona->universalSettings(), &UniversalSettings::currentLayoutNameChanged, this, &LayoutManager::currentLayoutNameChanged); } } @@ -71,6 +73,8 @@ void LayoutManager::load() } qDebug() << "Latte is loading its layouts..."; + + loadLayouts(); } DockCorona *LayoutManager::corona() @@ -93,6 +97,20 @@ LayoutSettings *LayoutManager::currentLayout() return m_currentLayout; } +QString LayoutManager::currentLayoutName() const +{ + if (m_corona && m_corona->universalSettings()) { + return m_corona->universalSettings()->currentLayoutName(); + } + + return QString(); +} + +QStringList LayoutManager::layouts() const +{ + return m_layouts; +} + QString LayoutManager::layoutPath(QString layoutName) { QString path = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte"; @@ -113,6 +131,25 @@ void LayoutManager::toggleLayout() } } +void LayoutManager::loadLayouts() +{ + m_layouts.clear(); + + QDir layoutDir(QDir::homePath() + "/.config/latte"); + QStringList filter; + filter.append(QString("*.layout.latte")); + QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks); + + foreach (auto layout, files) { + int ext = layout.lastIndexOf(".layout.latte"); + QString layoutName = layout.remove(ext, 13); + + m_layouts.append(layoutName); + } + + emit layoutsChanged(); +} + bool LayoutManager::switchToLayout(QString layoutName) { if (m_currentLayout && m_currentLayout->name() == layoutName) { @@ -146,6 +183,7 @@ bool LayoutManager::switchToLayout(QString layoutName) if (layoutName != i18n("Alternative")) { m_toggleLayoutAction->setChecked(false); + m_lastNonAlternativeLayout = layoutName; } else { m_toggleLayoutAction->setChecked(true); } @@ -153,7 +191,6 @@ bool LayoutManager::switchToLayout(QString layoutName) } } - QString LayoutManager::newLayout(QString layoutName, QString preset) { QDir layoutDir(QDir::homePath() + "/.config/latte"); diff --git a/app/layoutmanager.h b/app/layoutmanager.h index f647bdcb9..caa087c62 100644 --- a/app/layoutmanager.h +++ b/app/layoutmanager.h @@ -40,6 +40,10 @@ namespace Latte { class LayoutManager : public QObject { Q_OBJECT + Q_PROPERTY(QString currentLayoutName READ currentLayoutName NOTIFY currentLayoutNameChanged) + + Q_PROPERTY(QStringList layouts READ layouts NOTIFY layoutsChanged) + Q_PROPERTY(QAction *toggleLayoutAction READ toggleLayoutAction NOTIFY toggleLayoutActionChanged) Q_PROPERTY(QAction *addWidgetsAction READ addWidgetsAction NOTIFY addWidgetsActionChanged) @@ -53,6 +57,10 @@ public: void load(); + QString currentLayoutName() const; + + QStringList layouts() const; + QAction *addWidgetsAction(); QAction *toggleLayoutAction(); @@ -68,6 +76,8 @@ public slots: signals: void addWidgetsActionChanged(); void currentLayoutChanged(); + void currentLayoutNameChanged(); + void layoutsChanged(); void toggleLayoutActionChanged(); private slots: @@ -76,6 +86,7 @@ private slots: private: QString layoutPath(QString layoutName); + void loadLayouts(); //! it is used to activate / deactivate the Alternative Layout void toggleLayout(); @@ -87,6 +98,8 @@ private: QString m_lastNonAlternativeLayout{QString(i18n("My Layout"))}; + QStringList m_layouts; + QAction *m_addWidgetsAction{nullptr}; QAction *m_toggleLayoutAction{nullptr}; }; diff --git a/shell/package/contents/configuration/AppearanceConfig.qml b/shell/package/contents/configuration/AppearanceConfig.qml index 783f2b8af..0689bae13 100644 --- a/shell/package/contents/configuration/AppearanceConfig.qml +++ b/shell/package/contents/configuration/AppearanceConfig.qml @@ -70,29 +70,37 @@ PlasmaComponents.Page { id: layoutCmb Layout.preferredWidth: 0.5 * dialog.maxWidth - property var layouts: [i18nc("current layout","Current")]; - property var layoutObjs + property var layoutTexts: []; + property var layouts; - Component.onCompleted: layoutCmb.loadLayouts(); - - Connections{ - target:globalSettings - onClearLayoutSelection: layoutCmb.currentIndex = 0; - } + Component.onCompleted: loadLayouts(); function loadLayouts(){ - layoutObjs = globalSettings.layouts(); + layouts = layoutManager.layouts; + + var activeLayout = 0; + + for(var i=0; i0 && layoutObjs[currentIndex-1].value === ""){ + /*onCurrentIndexChanged: { + /* if (currentIndex>0 && layoutObjs[currentIndex-1].value === ""){ currentIndex = 0; return; } @@ -100,13 +108,14 @@ PlasmaComponents.Page { if (currentIndex>0) { globalSettings.importLayout(layoutObjs[currentIndex-1].key, layoutObjs[currentIndex-1].value); - } - } + }*/ + //} } PlasmaComponents.Button { Layout.fillWidth: true text: i18n("Import") + enabled: false onClicked: { globalSettings.importConfiguration() } @@ -115,6 +124,7 @@ PlasmaComponents.Page { PlasmaComponents.Button { Layout.fillWidth: true text: i18n("Export") + enabled: false onClicked: { globalSettings.exportConfiguration() }