1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-03-30 14:50:12 +03:00

fix #272,expose alternative session in menu

This commit is contained in:
Michail Vourlakos 2017-03-18 01:53:44 +02:00
parent 8e17e58f24
commit d0321f3baa
10 changed files with 191 additions and 37 deletions

View File

@ -285,26 +285,9 @@ void DockConfigView::setAutostart(bool state)
}
}
Dock::SessionType DockConfigView::currentSession() const
void DockConfigView::hideConfigWindow()
{
auto *dockCorona = qobject_cast<DockCorona *>(m_dockView->corona());
if (dockCorona) {
return dockCorona->currentSession();
}
return Dock::DefaultSession;
}
void DockConfigView::setCurrentSession(Dock::SessionType session)
{
auto *dockCorona = qobject_cast<DockCorona *>(m_dockView->corona());
if (dockCorona && dockCorona->currentSession() != session) {
dockCorona->switchToSession(session);
hide();
}
hide();
}
}

View File

@ -44,7 +44,6 @@ class DockView;
class DockConfigView : public PlasmaQuick::ConfigView {
Q_OBJECT
Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
Q_PROPERTY(Latte::Dock::SessionType currentSession READ currentSession WRITE setCurrentSession NOTIFY currentSessionChanged)
public:
DockConfigView(Plasma::Containment *containment, DockView *dockView, QWindow *parent = nullptr);
@ -56,17 +55,14 @@ public:
bool autostart() const;
void setAutostart(bool state);
Latte::Dock::SessionType currentSession() const;
void setCurrentSession(Latte::Dock::SessionType session);
public slots:
Q_INVOKABLE void addPanelSpacer();
Q_INVOKABLE void hideConfigWindow();
Q_INVOKABLE void setSticker(bool blockFocusLost);
Q_INVOKABLE void syncGeometry();
signals:
void autostartChanged();
void currentSessionChanged();
void raiseDocksTemporaryChanged();
void showSignal();

View File

@ -55,6 +55,7 @@ DockCorona::DockCorona(QObject *parent)
m_screenPool(new ScreenPool(KSharedConfig::openConfig(), this)),
m_activityConsumer(new KActivities::Consumer(this))
{
restoreConfig();
KPackage::Package package(new DockPackage(this));
m_screenPool->load();
@ -97,6 +98,7 @@ DockCorona::~DockCorona()
delete containments().first();
}
m_altSessionAction->deleteLater();
qDeleteAll(m_dockViews);
qDeleteAll(m_waitingDockViews);
m_dockViews.clear();
@ -121,6 +123,13 @@ void DockCorona::load()
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &DockCorona::screenCountChanged);
connect(m_screenPool, &ScreenPool::primaryPoolChanged, this, &DockCorona::screenCountChanged);
//! create the alternative session action
const QIcon altIcon = QIcon::fromTheme("user-identity");
m_altSessionAction = new QAction(altIcon, i18n("Alternative Session"), this);
m_altSessionAction->setStatusTip(tr("Enable/Disable Alternative Session"));
m_altSessionAction->setCheckable(true);
connect(m_altSessionAction, &QAction::triggered, this, &DockCorona::enableAltSession);
loadLayout();
}
}
@ -616,6 +625,34 @@ bool DockCorona::autostart() const
return autostartFile.exists();
}
QAction *DockCorona::altSessionAction()
{
return m_altSessionAction;
}
void DockCorona::enableAltSession(bool flag)
{
if (flag) {
switchToSession(Dock::AlternativeSession);
} else {
switchToSession(Dock::DefaultSession);
}
}
bool DockCorona::exposeAltSession() const
{
return m_exposeAltSession;
}
void DockCorona::setExposeAltSession(bool state)
{
if (m_exposeAltSession == state) {
return;
}
m_exposeAltSession = state;
saveConfig();
emit exposeAltSessionChanged();
}
Dock::SessionType DockCorona::currentSession()
{
@ -629,6 +666,11 @@ void DockCorona::setCurrentSession(Dock::SessionType session)
}
m_session = session;
if (m_session == Dock::DefaultSession)
m_altSessionAction->setChecked(false);
else
m_altSessionAction->setChecked(true);
}
void DockCorona::switchToSession(Dock::SessionType session)
{
@ -1083,6 +1125,21 @@ void DockCorona::activateLauncherMenu()
}
}
//!BEGIN configuration functions
void DockCorona::saveConfig()
{
auto conf = config()->group("General");
conf.writeEntry("exposeAltSession", m_exposeAltSession);
conf.sync();
}
void DockCorona::restoreConfig()
{
auto conf = config()->group("General");;
setExposeAltSession(conf.readEntry("exposeAltSession", false));
}
//!END configuration functions
inline void DockCorona::qmlRegisterTypes() const
{
qmlRegisterType<QScreen>();

View File

@ -70,6 +70,11 @@ public:
bool autostart() const;
void setAutostart(bool state);
bool exposeAltSession() const;
void setExposeAltSession(bool state);
QAction *altSessionAction();
Dock::SessionType currentSession();
void setCurrentSession(Dock::SessionType session);
void switchToSession(Dock::SessionType session);
@ -89,6 +94,7 @@ signals:
void configurationShown(PlasmaQuick::ConfigView *configView);
void docksCountChanged();
void dockLocationChanged();
void exposeAltSessionChanged();
void raiseDocksTemporaryChanged();
private slots:
@ -98,6 +104,7 @@ private slots:
void load();
void addOutput(QScreen *screen);
void enableAltSession(bool flag);
void primaryOutputChanged();
void screenRemoved(QScreen *screen);
void screenCountChanged();
@ -105,7 +112,7 @@ private slots:
private:
void cleanConfig();
void loadConfig();
void restoreConfig();
void saveConfig();
void qmlRegisterTypes() const;
bool appletExists(uint containmentId, uint appletId) const;
@ -127,8 +134,12 @@ private:
//! with tasks" will be loaded otherwise. Currently the older one dock wins
int m_firstContainmentWithTasks{ -1};
bool m_exposeAltSession{false};
Dock::SessionType m_session{Dock::DefaultSession};
QAction *m_altSessionAction{nullptr};
QHash<const Plasma::Containment *, DockView *> m_dockViews;
QHash<const Plasma::Containment *, DockView *> m_waitingDockViews;
QList<KDeclarative::QmlObject *> m_alternativesObjects;

View File

@ -112,6 +112,8 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis
m_screenSyncTimer.start();
}
});
connect(dockCorona, SIGNAL(exposeAltSessionChanged()), this, SIGNAL(exposeAltSessionChanged()));
connect(dockCorona, SIGNAL(exposeAltSessionChanged()), this, SIGNAL(altSessionActionChanged()));
}
m_screenSyncTimer.setSingleShot(true);
@ -122,6 +124,7 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis
DockView::~DockView()
{
m_screenSyncTimer.stop();
qDebug() << "dock view deleting...";
rootContext()->setContextProperty(QStringLiteral("dock"), nullptr);
@ -694,6 +697,16 @@ int DockView::docksWithTasks()
return dockCorona->noDocksWithTasks();
}
QAction *DockView::altSessionAction() const
{
auto dockCorona = qobject_cast<DockCorona *>(corona());
if (!dockCorona)
return 0;
return dockCorona->altSessionAction();
}
void DockView::updateFormFactor()
{
if (!this->containment())
@ -786,6 +799,46 @@ void DockView::setSession(Dock::SessionType type)
emit sessionChanged();
}
Dock::SessionType DockView::runningSession() const
{
auto *dockCorona = qobject_cast<DockCorona *>(corona());
if (dockCorona) {
return dockCorona->currentSession();
}
return Dock::DefaultSession;
}
void DockView::setRunningSession(Dock::SessionType session)
{
auto *dockCorona = qobject_cast<DockCorona *>(corona());
if (dockCorona && dockCorona->currentSession() != session) {
dockCorona->switchToSession(session);
}
}
bool DockView::exposeAltSession() const
{
auto *dockCorona = qobject_cast<DockCorona *>(corona());
if (dockCorona) {
return dockCorona->exposeAltSession();
}
return false;
}
void DockView::setExposeAltSession(bool state)
{
auto *dockCorona = qobject_cast<DockCorona *>(corona());
if (dockCorona && dockCorona->exposeAltSession() != state) {
dockCorona->setExposeAltSession(state);
}
}
float DockView::maxLength() const
{
return m_maxLength;
@ -1299,15 +1352,16 @@ void DockView::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEve
if (enabled) {
//if there is only one, don't create a submenu
if (enabled < 2) {
foreach (QAction *action, containmentMenu->actions()) {
if (action->isVisible() && !action->isSeparator()) {
desktopMenu->addAction(action);
}
// if (enabled < 2) {
foreach (QAction *action, containmentMenu->actions()) {
if (action->isVisible()) {
desktopMenu->addAction(action);
}
} else {
desktopMenu->addMenu(containmentMenu);
}
// } else {
// desktopMenu->addMenu(containmentMenu);
// }
}
}
@ -1368,6 +1422,13 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
desktopMenu->addAction(this->containment()->actions()->action(QStringLiteral("configure")));
}
} else {
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona && exposeAltSession()) {
desktopMenu->addSeparator();
desktopMenu->addAction(dockCorona->altSessionAction());
}
desktopMenu->addActions(actions);
}

View File

@ -47,6 +47,7 @@ class DockView : public PlasmaQuick::ContainmentView {
Q_OBJECT
Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged)
Q_PROPERTY(bool drawEffects READ drawEffects WRITE setDrawEffects NOTIFY drawEffectsChanged)
Q_PROPERTY(bool exposeAltSession READ exposeAltSession WRITE setExposeAltSession NOTIFY exposeAltSessionChanged)
Q_PROPERTY(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged)
Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
@ -65,16 +66,18 @@ class DockView : public PlasmaQuick::ContainmentView {
Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged)
Q_PROPERTY(VisibilityManager *visibility READ visibility NOTIFY visibilityChanged)
Q_PROPERTY(QQmlListProperty<QScreen> screens READ screens)
Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged)
Q_PROPERTY(QRect effectsArea READ effectsArea WRITE setEffectsArea NOTIFY effectsAreaChanged)
Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged)
Q_PROPERTY(QRect maskArea READ maskArea WRITE setMaskArea NOTIFY maskAreaChanged)
Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
Q_PROPERTY(Latte::Dock::SessionType session READ session WRITE setSession NOTIFY sessionChanged)
Q_PROPERTY(Latte::Dock::SessionType runningSession READ runningSession WRITE setRunningSession NOTIFY runningSessionChanged)
public:
DockView(Plasma::Corona *corona, QScreen *targetScreen = nullptr, bool alwaysVisible = false);
@ -100,6 +103,9 @@ public:
bool drawEffects() const;
void setDrawEffects(bool draw);
bool exposeAltSession() const;
void setExposeAltSession(bool state);
float maxLength() const;
void setMaxLength(float length);
@ -124,6 +130,11 @@ public:
QRect absGeometry() const;
QRect screenGeometry() const;
QAction *altSessionAction() const;
Latte::Dock::SessionType runningSession() const;
void setRunningSession(Latte::Dock::SessionType session);
Plasma::FrameSvg::EnabledBorders enabledBorders() const;
QString currentScreen() const;
@ -170,6 +181,7 @@ signals:
void eventTriggered(QEvent *ev);
void alignmentChanged();
void altSessionActionChanged();
void currentScreenChanged();
void dockLocationChanged();
void docksCountChanged();
@ -177,6 +189,7 @@ signals:
void drawEffectsChanged();
void effectsAreaChanged();
void enabledBordersChanged();
void exposeAltSessionChanged();
void widthChanged();
void heightChanged();
void localGeometryChanged();
@ -186,6 +199,7 @@ signals:
void onPrimaryChanged();
void visibilityChanged();
void maskAreaChanged();
void runningSessionChanged();
void screenGeometryChanged();
void sessionChanged();
void shadowChanged();

View File

@ -55,6 +55,7 @@ DragDrop.DropArea {
&& (plasmoid.configuration.panelPosition === Latte.Dock.Justify) && !root.solidPanel
property bool editMode: plasmoid.userConfiguring
property bool exposeAltSession: dock ? dock.exposeAltSession : false
property bool immutable: plasmoid.immutable
property bool inStartup: true
property bool isHorizontal: plasmoid.formFactor === PlasmaCore.Types.Horizontal
@ -161,6 +162,8 @@ DragDrop.DropArea {
property Item latteApplet
property QtObject dock
property QtObject altSessionAction: dock ? dock.altSessionAction : 0
// TO BE DELETED, if not needed: property int counter:0;
///BEGIN properties provided to Latte Plasmoid

View File

@ -638,6 +638,21 @@ PlasmaComponents.ContextMenu {
separator: true
}
PlasmaComponents.MenuItem {
id: altSession
visible: root.exposeAltSession
icon: "user-identity"
text: "Alternative Session"
checkable: true
Component.onCompleted: {
checked = root.altSessionAction.checked;
}
onClicked: root.altSessionAction.trigger();
}
PlasmaComponents.MenuItem {
id: containmentMenuItem

View File

@ -97,6 +97,7 @@ 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 reverseLinesPosition: latteDock ? latteDock.reverseLinesPosition : plasmoid.configuration.reverseLinesPosition
property bool dotsOnActive: latteDock ? latteDock.dotsOnActive : plasmoid.configuration.dotsOnActive
@ -144,6 +145,8 @@ Item {
property alias tasksCount: tasksModel.count
property alias hoveredIndex: icList.hoveredIndex
property QtObject altSessionAction : latteDock ? latteDock.altSessionAction : 0
property Item latteDock: null
//END Now Dock Panel properties

View File

@ -89,6 +89,16 @@ PlasmaComponents.Page {
}
}
PlasmaComponents.CheckBox {
Layout.leftMargin: units.smallSpacing * 2
text: i18n("Expose Alternative Session in the context menu")
checked: dock.exposeAltSession
onClicked: {
dock.exposeAltSession = checked;
}
}
PlasmaComponents.CheckBox {
Layout.leftMargin: units.smallSpacing * 2
text: i18n("Raise dock on desktop change")
@ -123,15 +133,16 @@ PlasmaComponents.Page {
Layout.rightMargin: units.smallSpacing * 2
Layout.fillWidth: true
text: i18n("Alternative Session")
checked: dockConfig.currentSession === Latte.Dock.AlternativeSession
checked: dock.runningSession === Latte.Dock.AlternativeSession
checkable: true
onClicked: {
if (dockConfig.currentSession === Latte.Dock.DefaultSession){
dockConfig.currentSession = Latte.Dock.AlternativeSession;
if (dock.runningSession === Latte.Dock.DefaultSession){
dock.runningSession = Latte.Dock.AlternativeSession;
} else {
dockConfig.currentSession = Latte.Dock.DefaultSession;
dock.runningSession = Latte.Dock.DefaultSession;
}
dockConfig.hideConfigWindow();
}
}