1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-25 19:21:41 +03:00

move functionality to new architecture

--add functionality for layoutManager
--add widgets action and alternative layout action to
layoutManager
--remove more functionality that belongs to globalSettings
This commit is contained in:
Michail Vourlakos 2017-07-03 19:04:37 +03:00
parent 14e61b3a59
commit f2de335d35
12 changed files with 161 additions and 91 deletions

View File

@ -103,6 +103,8 @@ void DockConfigView::init()
if (dockCorona) {
rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings());
rootContext()->setContextProperty(QStringLiteral("universalSettings"), dockCorona->universalSettings());
rootContext()->setContextProperty(QStringLiteral("layoutManager"), dockCorona->layoutManager());
}
KDeclarative::KDeclarative kdeclarative;

View File

@ -160,20 +160,10 @@ void DockCorona::load()
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &DockCorona::screenCountChanged);
connect(m_screenPool, &ScreenPool::primaryPoolChanged, this, &DockCorona::screenCountChanged);
m_layoutManager->switchToLayout(m_universalSettings->currentLayoutName());
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
}
foreach (auto containment, containments())
addDock(containment);
}
}
@ -226,20 +216,13 @@ bool DockCorona::reloadLayout(QString path)
return false;
}
void DockCorona::loadLatteLayout(QString layoutName)
void DockCorona::loadLatteLayout(QString layoutPath)
{
QString layoutPath = m_layoutManager->layoutPath(layoutName);
if (layoutPath.isEmpty() && layoutName == i18n("Alternative")) {
layoutPath = m_layoutManager->requestLayout(i18n("Alternative"), i18n("Default"));
}
if (!layoutPath.isEmpty()) {
qDebug() << "corona is unloading the interface...";
unload();
qDebug() << "loading config file for layout:" << layoutName << " - " << layoutPath;
qDebug() << "loading layout:" << layoutPath;
loadLayout(layoutPath);
universalSettings()->setCurrentLayoutName(layoutName);
foreach (auto containment, containments())
addDock(containment);

View File

@ -73,7 +73,7 @@ public:
QList<Plasma::Types::Location> freeEdges(int screen) const;
QList<Plasma::Types::Location> freeEdges(QScreen *screen) const;
void loadLatteLayout(QString layoutName);
void loadLatteLayout(QString layoutPath);
bool reloadLayout(QString path);
int docksCount() const;

View File

@ -213,6 +213,8 @@ void DockView::init()
if (dockCorona) {
rootContext()->setContextProperty(QStringLiteral("globalSettings"), dockCorona->globalSettings());
rootContext()->setContextProperty(QStringLiteral("universalSettings"), dockCorona->universalSettings());
rootContext()->setContextProperty(QStringLiteral("layoutManager"), dockCorona->layoutManager());
}
setSource(corona()->kPackage().filePath("lattedockui"));
@ -1771,7 +1773,7 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona) {
desktopMenu->addAction(dockCorona->globalSettings()->addWidgetsAction());
desktopMenu->addAction(dockCorona->layoutManager()->addWidgetsAction());
}
desktopMenu->addAction(this->containment()->actions()->action(QStringLiteral("configure")));
@ -1781,11 +1783,11 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
desktopMenu->addSeparator();
if (dockCorona && dockCorona->globalSettings()->exposeAltSession()) {
desktopMenu->addAction(dockCorona->globalSettings()->altSessionAction());
if (dockCorona && dockCorona->universalSettings()->exposeLayoutsMenu()) {
desktopMenu->addAction(dockCorona->layoutManager()->toggleLayoutAction());
}
desktopMenu->addAction(dockCorona->globalSettings()->addWidgetsAction());
desktopMenu->addAction(dockCorona->layoutManager()->addWidgetsAction());
desktopMenu->addActions(actions);
}

View File

@ -112,13 +112,15 @@ void GlobalSettings::enableAltSession(bool enabled)
//! crash when switching sessions through the Tasks plasmoid Context menu
//! Latte was unstable and was crashing very often during changing
//! sessions
QTimer::singleShot(200, [this, enabled]() {
/*QTimer::singleShot(200, [this, enabled]() {
if (enabled) {
m_corona->loadLatteLayout(QString(i18n("Alternative")));
} else {
m_corona->loadLatteLayout(QString(i18n("My Layout")));
}
});
});*/
//m_corona->layoutManager()->toggleLayout();
}
bool GlobalSettings::exposeAltSession() const

View File

@ -22,6 +22,7 @@
#include <QDir>
#include <QFile>
#include <QtDBus/QtDBus>
#include <KLocalizedString>
@ -32,11 +33,27 @@ LayoutManager::LayoutManager(QObject *parent)
m_importer(new Importer(this))
{
m_corona = qobject_cast<DockCorona *>(parent);
if (m_corona) {
//! create the alternative session action
const QIcon toggleIcon = QIcon::fromTheme("user-identity");
m_toggleLayoutAction = new QAction(toggleIcon, i18n("Alternative Layout"), this);
m_toggleLayoutAction->setStatusTip(i18n("Enable/Disable Alternative Layout"));
m_toggleLayoutAction->setCheckable(true);
connect(m_toggleLayoutAction, &QAction::triggered, this, &LayoutManager::toggleLayout);
//! create the add widgets action
const QIcon addWidIcon = QIcon::fromTheme("add");
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);
}
}
LayoutManager::~LayoutManager()
{
m_importer->deleteLater();
m_toggleLayoutAction->deleteLater();
}
void LayoutManager::load()
@ -57,6 +74,16 @@ DockCorona *LayoutManager::corona()
return m_corona;
}
QAction *LayoutManager::toggleLayoutAction()
{
return m_toggleLayoutAction;
}
QAction *LayoutManager::addWidgetsAction()
{
return m_addWidgetsAction;
}
QString LayoutManager::layoutPath(QString layoutName)
{
QString path = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte";
@ -68,20 +95,77 @@ QString LayoutManager::layoutPath(QString layoutName)
return path;
}
QString LayoutManager::requestLayout(QString layoutName, QString preset)
void LayoutManager::toggleLayout()
{
QString newFile = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte";
QString resFile;
qDebug() << "adding layout : " << layoutName << " based on preset:" << preset;
if (m_corona->universalSettings()->currentLayoutName() == i18n("Alternative")) {
switchToLayout(m_lastNonAlternativeLayout);
} else {
switchToLayout(i18n("Alternative"));
}
}
if (preset == i18n("Default") && !QFile(newFile).exists()) {
qDebug() << "adding layout : succeed";
QFile(m_corona->kPackage().filePath("preset1")).copy(newFile);
resFile = newFile;
bool LayoutManager::switchToLayout(QString layoutName)
{
QString lPath = layoutPath(layoutName);
if (lPath.isEmpty() && layoutName == i18n("Alternative")) {
lPath = newLayout(i18n("Alternative"), i18n("Default"));
}
return resFile;
if (!lPath.isEmpty()) {
//! this code must be called asynchronously because it is called
//! also from qml (Tasks plasmoid). This change fixes a very important
//! crash when switching sessions through the Tasks plasmoid Context menu
//! Latte was unstable and was crashing very often during changing
//! sessions
QTimer::singleShot(200, [this, layoutName, lPath]() {
qDebug() << layoutName << " - " << lPath;
m_corona->loadLatteLayout(lPath);
m_corona->universalSettings()->setCurrentLayoutName(layoutName);
if (layoutName != i18n("Alternative")) {
m_toggleLayoutAction->setChecked(false);
} else {
m_toggleLayoutAction->setChecked(true);
}
});
}
}
QString LayoutManager::newLayout(QString layoutName, QString preset)
{
QDir layoutDir(QDir::homePath() + "/.config/latte");
QStringList filter;
filter.append(QString(layoutName + "*.layout.latte"));
QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
//! if the newLayout already exists provide a newName that doesnt
if (files.count() >= 1) {
int newCounter = files.count() + 1;
layoutName = layoutName + "-" + QString::number(newCounter);
}
QString newLayoutPath = layoutDir.absolutePath() + "/" + layoutName + ".layout.latte";
qDebug() << "adding layout : " << layoutName << " based on preset:" << preset;
if (preset == i18n("Default") && !QFile(newLayoutPath).exists()) {
qDebug() << "adding layout : succeed";
QFile(m_corona->kPackage().filePath("preset1")).copy(newLayoutPath);
}
return layoutName;
}
void LayoutManager::showWidgetsExplorer()
{
QDBusInterface iface("org.kde.plasmashell", "/PlasmaShell", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
iface.call("toggleWidgetExplorer");
}
}
}

View File

@ -24,8 +24,11 @@
#include "dockcorona.h"
#include "importer.h"
#include <QAction>
#include <QObject>
#include <KLocalizedString>
class Importer;
namespace Latte {
@ -35,6 +38,9 @@ namespace Latte {
class LayoutManager : public QObject {
Q_OBJECT
Q_PROPERTY(QAction *toggleLayoutAction READ toggleLayoutAction NOTIFY toggleLayoutActionChanged)
Q_PROPERTY(QAction *addWidgetsAction READ addWidgetsAction NOTIFY addWidgetsActionChanged)
public:
LayoutManager(QObject *parent = nullptr);
~LayoutManager() override;
@ -43,14 +49,36 @@ public:
void load();
QString layoutPath(QString layoutName);
QAction *addWidgetsAction();
QAction *toggleLayoutAction();
public slots:
//! switch to specified layout
Q_INVOKABLE bool switchToLayout(QString layoutName);
//! creates a new layout with layoutName based on the preset
QString requestLayout(QString layoutName, QString preset);
Q_INVOKABLE QString newLayout(QString layoutName, QString preset = QString(i18n("Default")));
signals:
void addWidgetsActionChanged();
void toggleLayoutActionChanged();
private slots:
void showWidgetsExplorer();
private:
QString layoutPath(QString layoutName);
//! it is used to activate / deactivate the Alternative Layout
void toggleLayout();
private:
DockCorona *m_corona{nullptr};
Importer *m_importer{nullptr};
QString m_lastNonAlternativeLayout{QString(i18n("My Layout"))};
QAction *m_addWidgetsAction{nullptr};
QAction *m_toggleLayoutAction{nullptr};
};
}

View File

@ -73,7 +73,8 @@ DragDrop.DropArea {
property bool disablePanelShadowMaximized: plasmoid.configuration.disablePanelShadowForMaximized
property bool drawShadowsExternal: panelShadowsActive && behaveAsPlasmaPanel
property bool editMode: plasmoid.userConfiguring
property bool exposeAltSession: globalSettings ? globalSettings.exposeAltSession : false
// property bool exposeAltSession: globalSettings ? globalSettings.exposeAltSession : false
// property bool exposeLayoutsMenu: universalSettings ? universalSettings.exposeLayoutsMenu : false
property bool forceTransparentPanel: root.backgroundOnlyOnMaximized && !windowsModel.hasMaximizedWindow
&& Latte.WindowSystem.compositingActive
@ -216,9 +217,12 @@ DragDrop.DropArea {
property Item parabolicManager: _parabolicManager
property QtObject dock
property QtObject globalSettings
property QtObject universalSettings
property QtObject universalLayoutManager
property QtObject addWidgetsAction: globalSettings ? globalSettings.addWidgetsAction : null
property QtObject altSessionAction: globalSettings ? globalSettings.altSessionAction : null
//property QtObject addWidgetsAction: globalSettings ? globalSettings.addWidgetsAction : null
//property QtObject altSessionAction: globalSettings ? globalSettings.altSessionAction : null
//property QtObject toggleLayoutAction: universalLayoutManager ? universalLayoutManager.toggleLayoutAction : null
// TO BE DELETED, if not needed: property int counter:0;

View File

@ -791,18 +791,18 @@ PlasmaComponents.ContextMenu {
PlasmaComponents.MenuItem {
id: altSession
visible: root.exposeAltSession
visible: latteDock && latteDock.universalSettings.exposeLayoutsMenu
icon: "user-identity"
text: i18n("Alternative Session")
text: i18n("Alternative Layout")
checkable: true
Component.onCompleted: {
checked = root.altSessionAction.checked;
checked = latteDock ? latteDock.universalLayoutManager.toggleLayoutAction.checked : false;
}
onClicked: {
//fix a crash that when going to Alternative Session through Context Menu,
//fix a crash that when going to Alternative Layout through Context Menu,
//animations are played during the destruction and because of that Latte.IconItem is crashing
menu.changingLayout = true;
root.disableRestoreZoom = false;
@ -815,12 +815,12 @@ PlasmaComponents.ContextMenu {
PlasmaComponents.MenuItem {
id: addWidgets
visible: latteDock && latteDock.addWidgetsAction
visible: latteDock && latteDock.universalLayoutManager.addWidgetsAction
icon: "add"
text: i18n("Add Widgets...")
onClicked: latteDock.addWidgetsAction.trigger();
onClicked: latteDock.universalLayoutManager.addWidgetsAction.trigger();
}
PlasmaComponents.MenuItem {

View File

@ -132,7 +132,6 @@ Item {
property bool disableLeftSpacer: false
property bool disableRightSpacer: false
property bool dockIsHidden: latteDock ? latteDock.dockIsHidden : false
property bool exposeAltSession: latteDock ? latteDock.exposeAltSession : false
property bool highlightWindows: latteDock ? latteDock.highlightWindows: plasmoid.configuration.highlightWindows
property bool indicateAudioStreams: latteDock ? latteDock.indicateAudioStreams : plasmoid.configuration.indicateAudioStreams
property bool mouseWheelActions: latteDock ? latteDock.mouseWheelActions : true
@ -499,8 +498,8 @@ Item {
root.contextMenu.destroy();
root.contextMenu = null;
}
if (root.altSessionAction)
root.altSessionAction.trigger();
latteDock.universalLayoutManager.toggleLayoutAction.trigger();
}
}

View File

@ -159,10 +159,10 @@ PlasmaComponents.Page {
PlasmaComponents.CheckBox {
Layout.leftMargin: units.smallSpacing * 2
text: i18n("Show Alternative Session in the context menu")
checked: globalSettings.exposeAltSession
checked: universalSettings.exposeLayoutsMenu
onClicked: {
globalSettings.exposeAltSession = checked
universalSettings.exposeLayoutsMenu = checked;
}
}
@ -256,42 +256,6 @@ PlasmaComponents.Page {
}
//! END: Active Indicator
//! BEGIN: Session
ColumnLayout {
spacing: units.smallSpacing
Layout.rightMargin: units.smallSpacing * 2
Header {
text: i18n("Session")
}
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: units.smallSpacing * 2
spacing: units.smallSpacing
PlasmaComponents.Button {
Layout.fillWidth: true
text: i18n("Alternative Session")
checked: globalSettings.currentSession === Latte.Dock.AlternativeSession
checkable: true
tooltip: i18n("Sometimes the current layout of your panels is not sufficient \nfor example when you are travelling. Latte provides you with a full \nalternative sessionn to work on.")
onClicked: {
if (globalSettings.currentSession === Latte.Dock.DefaultSession) {
globalSettings.currentSession = Latte.Dock.AlternativeSession
} else {
globalSettings.currentSession = Latte.Dock.DefaultSession
}
dockConfig.hideConfigWindow()
}
}
}
}
//! END: Session
//! BEGIN: Extra Actions
ColumnLayout {
Layout.fillWidth: true

View File

@ -94,6 +94,8 @@ PlasmaCore.FrameSvgItem {
dockLayout = containment.children[i];
dockLayout.dock = dock;
dockLayout.globalSettings = globalSettings;
dockLayout.universalSettings = universalSettings;
dockLayout.universalLayoutManager = layoutManager;
}
}
}