add currentLayout into the layoutManager

pull/1/head
Michail Vourlakos 8 years ago
parent f2de335d35
commit 673c398d32

@ -54,6 +54,10 @@ LayoutManager::~LayoutManager()
{
m_importer->deleteLater();
m_toggleLayoutAction->deleteLater();
if (m_currentLayout) {
m_currentLayout->deleteLater();
}
}
void LayoutManager::load()
@ -84,6 +88,11 @@ QAction *LayoutManager::addWidgetsAction()
return m_addWidgetsAction;
}
LayoutSettings *LayoutManager::currentLayout()
{
return m_currentLayout;
}
QString LayoutManager::layoutPath(QString layoutName)
{
QString path = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte";
@ -106,6 +115,10 @@ void LayoutManager::toggleLayout()
bool LayoutManager::switchToLayout(QString layoutName)
{
if (m_currentLayout && m_currentLayout->name() == layoutName) {
return false;
}
QString lPath = layoutPath(layoutName);
if (lPath.isEmpty() && layoutName == i18n("Alternative")) {
@ -123,6 +136,14 @@ bool LayoutManager::switchToLayout(QString layoutName)
m_corona->loadLatteLayout(lPath);
m_corona->universalSettings()->setCurrentLayoutName(layoutName);
if (m_currentLayout) {
m_currentLayout->deleteLater();
}
m_currentLayout = new LayoutSettings(this, lPath, layoutName);
emit currentLayoutChanged();
if (layoutName != i18n("Alternative")) {
m_toggleLayoutAction->setChecked(false);
} else {

@ -23,6 +23,7 @@
#include "dockcorona.h"
#include "importer.h"
#include "layoutsettings.h"
#include <QAction>
#include <QObject>
@ -30,6 +31,7 @@
#include <KLocalizedString>
class Importer;
class LayoutSettings;
namespace Latte {
@ -41,6 +43,8 @@ class LayoutManager : public QObject {
Q_PROPERTY(QAction *toggleLayoutAction READ toggleLayoutAction NOTIFY toggleLayoutActionChanged)
Q_PROPERTY(QAction *addWidgetsAction READ addWidgetsAction NOTIFY addWidgetsActionChanged)
Q_PROPERTY(LayoutSettings *currentLayout READ currentLayout NOTIFY currentLayoutChanged)
public:
LayoutManager(QObject *parent = nullptr);
~LayoutManager() override;
@ -52,6 +56,8 @@ public:
QAction *addWidgetsAction();
QAction *toggleLayoutAction();
LayoutSettings *currentLayout();
public slots:
//! switch to specified layout
Q_INVOKABLE bool switchToLayout(QString layoutName);
@ -61,6 +67,7 @@ public slots:
signals:
void addWidgetsActionChanged();
void currentLayoutChanged();
void toggleLayoutActionChanged();
private slots:
@ -68,6 +75,7 @@ private slots:
private:
QString layoutPath(QString layoutName);
//! it is used to activate / deactivate the Alternative Layout
void toggleLayout();
@ -75,6 +83,8 @@ private:
DockCorona *m_corona{nullptr};
Importer *m_importer{nullptr};
LayoutSettings *m_currentLayout{nullptr};
QString m_lastNonAlternativeLayout{QString(i18n("My Layout"))};
QAction *m_addWidgetsAction{nullptr};

@ -25,21 +25,30 @@
namespace Latte {
LayoutSettings::LayoutSettings(QObject *parent, KSharedConfig::Ptr config)
/*LayoutSettings::LayoutSettings(QObject *parent, KSharedConfig::Ptr config)
: QObject(parent)
{
m_layoutGroup = KConfigGroup(config, "LayoutSettings");
init();
}
}*/
LayoutSettings::LayoutSettings(QObject *parent, QString layoutFile)
LayoutSettings::LayoutSettings(QObject *parent, QString layoutFile, QString layoutName)
: QObject(parent)
{
if (QFile(layoutFile).exists()) {
if (layoutName.isEmpty()) {
int lastSlash = layoutFile.lastIndexOf("/");
layoutName = layoutFile.remove(0, lastSlash + 1);
int ext = layoutName.lastIndexOf(".latterc");
layoutName = layoutName.remove(ext, 8);
}
KSharedConfigPtr lConfig = KSharedConfig::openConfig(layoutFile);
m_layoutGroup = KConfigGroup(lConfig, "LayoutSettings");
m_layoutFile = layoutFile;
setFile(layoutFile);
setName(layoutName);
init();
}
}
@ -73,6 +82,38 @@ void LayoutSettings::setVersion(int ver)
emit versionChanged();
}
QString LayoutSettings::name() const
{
return m_layoutName;
}
void LayoutSettings::setName(QString name)
{
if (m_layoutName == name) {
return;
}
m_layoutName = name;
emit nameChanged();
}
QString LayoutSettings::file() const
{
return m_layoutFile;
}
void LayoutSettings::setFile(QString file)
{
if (m_layoutFile == file) {
return;
}
m_layoutFile = file;
emit fileChanged();
}
bool LayoutSettings::syncLaunchers() const
{
return m_syncLaunchers;

@ -38,13 +38,17 @@ namespace Latte {
class LayoutSettings : public QObject {
Q_OBJECT
Q_PROPERTY(bool syncLaunchers READ syncLaunchers WRITE setSyncLaunchers NOTIFY syncLaunchersChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QStringList globalLaunchers READ globalLaunchers WRITE setGlobalLaunchers NOTIFY globalLaunchersChanged)
public:
LayoutSettings(QObject *parent, QString layoutFile);
LayoutSettings(QObject *parent, KSharedConfig::Ptr config);
LayoutSettings(QObject *parent, QString layoutFile, QString layoutName = QString());
//LayoutSettings(QObject *parent, KSharedConfig::Ptr config);
~LayoutSettings() override;
QString name() const;
QString file() const;
QStringList globalLaunchers() const;
void setGlobalLaunchers(QStringList launchers);
@ -55,7 +59,9 @@ public:
void setSyncLaunchers(bool sync);
signals:
void fileChanged();
void globalLaunchersChanged();
void nameChanged();
void versionChanged();
void syncLaunchersChanged();
@ -65,6 +71,8 @@ private slots:
private:
void init();
void setName(QString name);
void setFile(QString file);
private:
bool m_syncLaunchers{false};
@ -72,6 +80,7 @@ private:
int m_version{1};
QString m_layoutFile;
QString m_layoutName;
QStringList m_globalLaunchers;
DockCorona *m_corona{nullptr};

Loading…
Cancel
Save