HI everybody,

I have created a patch that implements wishlist #164687 
(https://bugs.kde.org/show_bug.cgi?id=164687), namely provide the UI to 
configure the buttons which are shown in the Lock/Logout plasmoid (Lock, 
Logout or both).

I wasn't sure whether I should commit it (plasma is quite a "sensitive" area 
that I wouldn't like to mess), so I send it to you, the Plasma devs to review 
it. It's quite small btw.

I have followed the coding styles and all these things, but there were some 
things that I wasn't sure for. For example, under Windows the logout button is 
not shown so the configuration UI should not apply there. Thus I have put all 
config-related code in the appropriate #ifndef Q_OS_WIN. Still, I don't really 
like this (I am afraid I abused it and spread it all over the code), so feel 
free to make suggestions.

Cheers,
Konstantinos Smanis
Index: lockout.cpp
===================================================================
--- lockout.cpp	(revision 922924)
+++ lockout.cpp	(working copy)
@@ -31,6 +31,8 @@
 // KDE
 #include <KIcon>
 #ifndef Q_OS_WIN
+#include <KConfigDialog>
+#include <KSharedConfig>
 #include <kworkspace/kworkspace.h>
 #include <screensaver_interface.h>
 #endif
@@ -47,6 +49,9 @@
 LockOut::LockOut(QObject *parent, const QVariantList &args)
     : Plasma::Applet(parent, args)
 {
+#ifndef Q_OS_WIN
+    setHasConfigurationInterface(true);
+#endif
     resize(MINBUTTONSIZE, MINBUTTONSIZE * 2 + MARGINSIZE);
 }
 
@@ -56,14 +61,19 @@
     m_layout->setContentsMargins(0,0,0,0);
     m_layout->setSpacing(0);
 
-    Plasma::IconWidget *icon_lock = new Plasma::IconWidget(KIcon("system-lock-screen"), "", this);
-    m_layout->addItem(icon_lock);
+#ifndef Q_OS_WIN
+    KConfigGroup cg = config();
+    m_showLockButton = cg.readEntry("showLockButton", true);
+    m_showLogoutButton = cg.readEntry("showLogoutButton", true);
+#endif
+
+    icon_lock = new Plasma::IconWidget(KIcon("system-lock-screen"), "", this);
     connect(icon_lock, SIGNAL(clicked()), this, SLOT(clickLock()));
-#ifndef Q_OS_WIN
-    Plasma::IconWidget *icon_logout = new Plasma::IconWidget(KIcon("system-shutdown"), "", this);
-    m_layout->addItem(icon_logout);
+
+    icon_logout = new Plasma::IconWidget(KIcon("system-shutdown"), "", this);
     connect(icon_logout, SIGNAL(clicked()), this, SLOT(clickLogout()));
-#endif
+
+    showButtons();
 }
 
 LockOut::~LockOut()
@@ -155,5 +165,63 @@
 #endif
 }
 
+#ifndef Q_OS_WIN
+void LockOut::configAccepted()
+{
+    m_showLockButton = (ui.radioButton_lock->isChecked() || ui.radioButton_both->isChecked());
+    m_showLogoutButton = (ui.radioButton_logout->isChecked() || ui.radioButton_both->isChecked());
 
+    KConfigGroup cg = config();
+    cg.writeEntry("showLockButton", m_showLockButton);
+    cg.writeEntry("showLogoutButton", m_showLogoutButton);
+
+    showButtons();
+
+    emit configNeedsSaving();
+}
+
+void LockOut::createConfigurationInterface(KConfigDialog *parent)
+{
+    QWidget *widget = new QWidget(parent);
+    ui.setupUi(widget);
+    parent->addPage(widget, i18n("General"), Applet::icon());
+    connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
+    connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
+
+    if (m_showLockButton && m_showLogoutButton) {
+        ui.radioButton_both->setChecked(Qt::Checked);
+    } else if (m_showLockButton) {
+        ui.radioButton_lock->setChecked(Qt::Checked);
+    } else {
+        ui.radioButton_logout->setChecked(Qt::Checked);
+    }
+}
+#endif
+
+void LockOut::showButtons()
+{
+#ifdef Q_OS_WIN
+    m_layout->addItem(icon_lock);
+#else
+    //make sure we don't add a button twice in the layout
+    //definitely not the best workaround...
+    m_layout->removeItem(icon_lock);
+    m_layout->removeItem(icon_logout);
+
+    if (m_showLockButton) {
+	icon_lock->setVisible(true);
+        m_layout->addItem(icon_lock);
+    } else {
+	icon_lock->setVisible(false);
+    }
+
+    if (m_showLogoutButton) {
+	icon_logout->setVisible(true);
+        m_layout->addItem(icon_logout);
+    } else {
+	icon_logout->setVisible(false);
+    }
+#endif // !Q_OS_WIN
+}
+
 #include "lockout.moc"
Index: lockoutConfig.ui
===================================================================
--- lockoutConfig.ui	(revision 0)
+++ lockoutConfig.ui	(revision 0)
@@ -0,0 +1,57 @@
+<ui version="4.0" >
+ <class>lockoutConfig</class>
+ <widget class="QWidget" name="lockoutConfig" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>157</width>
+    <height>126</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Configure Lock/Logout</string>
+  </property>
+  <property name="accessibleName" >
+   <string>Configure Lock/Logout</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <widget class="QRadioButton" name="radioButton_lock" >
+     <property name="text" >
+      <string>Show lock button</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" >
+    <widget class="QRadioButton" name="radioButton_logout" >
+     <property name="text" >
+      <string>Show logout button</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" >
+    <widget class="QRadioButton" name="radioButton_both" >
+     <property name="text" >
+      <string>Show both buttons</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0" >
+    <spacer name="verticalSpacer" >
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
Index: lockout.h
===================================================================
--- lockout.h	(revision 922924)
+++ lockout.h	(working copy)
@@ -22,6 +22,15 @@
 
 #include <Plasma/Applet>
 
+namespace Plasma
+{
+    class IconWidget;
+}
+
+#ifndef Q_OS_WIN
+#include "ui_lockoutConfig.h"
+#endif
+
 class QGraphicsLinearLayout;
 
 class LockOut : public Plasma::Applet
@@ -37,10 +46,23 @@
     public slots:
         void clickLogout();
         void clickLock();
+#ifndef Q_OS_WIN
+    protected Q_SLOTS:
+        void configAccepted();
 
+    protected:
+        void createConfigurationInterface(KConfigDialog *parent);
+
     private:
+        Ui::lockoutConfig ui;
+        bool m_showLockButton;
+        bool m_showLogoutButton;
+#endif
+        Plasma::IconWidget *icon_lock;
+        Plasma::IconWidget *icon_logout;
         QGraphicsLinearLayout *m_layout;
         void checkLayout();
+        void showButtons();
 };
 
 K_EXPORT_PLASMA_APPLET(lockout, LockOut)
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 922924)
+++ CMakeLists.txt	(working copy)
@@ -9,6 +9,9 @@
 set(ksmserver_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/ksmserver/org.kde.KSMServerInterface.xml)
 QT4_ADD_DBUS_INTERFACE(lockout_SRCS ${ksmserver_xml} ksmserver_interface)
 
+if(NOT WIN32)
+kde4_add_ui_files(lockout_SRCS lockoutConfig.ui)
+endif(NOT WIN32)
 kde4_add_plugin(plasma_applet_lockout ${lockout_SRCS})
 target_link_libraries(plasma_applet_lockout ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS})
 if(NOT WIN32)
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to