summaryrefslogtreecommitdiffstats
path: root/kshutdownlockout
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2013-07-28 02:30:20 +0200
committerSlávek Banko <slavek.banko@axis.cz>2013-07-28 02:30:20 +0200
commit48a589b8c526b34e79e8cdddc4cb7f5fc7b76815 (patch)
tree0f30d90998669b60a0aa840f824cc3d4ea7ddc66 /kshutdownlockout
downloadkshutdown-48a589b8c526b34e79e8cdddc4cb7f5fc7b76815.tar.gz
kshutdown-48a589b8c526b34e79e8cdddc4cb7f5fc7b76815.zip
Initial import of kshutdown 1.0.4
Diffstat (limited to 'kshutdownlockout')
-rw-r--r--kshutdownlockout/Makefile.am15
-rw-r--r--kshutdownlockout/kshutdownlockout.desktop71
-rw-r--r--kshutdownlockout/lockout.cpp236
-rw-r--r--kshutdownlockout/lockout.h59
4 files changed, 381 insertions, 0 deletions
diff --git a/kshutdownlockout/Makefile.am b/kshutdownlockout/Makefile.am
new file mode 100644
index 0000000..7fd6b25
--- /dev/null
+++ b/kshutdownlockout/Makefile.am
@@ -0,0 +1,15 @@
+INCLUDES = $(all_includes)
+METASOURCES = AUTO
+
+kde_module_LTLIBRARIES = kshutdownlockout_panelapplet.la
+
+kshutdownlockout_panelapplet_la_SOURCES = lockout.cpp
+kshutdownlockout_panelapplet_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+kshutdownlockout_panelapplet_la_LIBADD = $(LIB_KSYCOCA)
+
+noinst_HEADERS = lockout.h
+
+lnkdir = $(kde_datadir)/kicker/applets
+lnk_DATA = kshutdownlockout.desktop
+
+EXTRA_DIST = $(lnk_DATA)
diff --git a/kshutdownlockout/kshutdownlockout.desktop b/kshutdownlockout/kshutdownlockout.desktop
new file mode 100644
index 0000000..7cdc247
--- /dev/null
+++ b/kshutdownlockout/kshutdownlockout.desktop
@@ -0,0 +1,71 @@
+[Desktop Entry]
+Type=Plugin
+# Encoding: UTF-8
+Name=KShutDown
+Comment=Lock/Logout buttons for the panel
+Comment[af]=Sluit/Teken af knoppies vir die paneel
+Comment[ar]=أزرار اقفال/خروج للوحة المهام
+Comment[az]=Panel appletlərini bağla/ayır
+Comment[bg]=Системен аплет за заключване на екрана и изход от системата
+Comment[bn]=প্যানেল-এর জন্য লক এবং লগ-আউট বাটন
+Comment[bs]=Dugmad za zaključavanje i odjavu za panel
+Comment[ca]=Botons al plafó per a bloquejar/sortir
+Comment[cs]=Umožňuje snadné odhlášení/uzamčení z panelu
+Comment[cy]=Botymau cloi/allgofnodi i'r panel
+Comment[da]=Lås/Logaf-knapper til panelet
+Comment[de]=Bildschirmsperr- und Abmeldeknöpfe für die Kontrollleiste
+Comment[el]=Κουμπιά Κλειδώματος/Αποσύνδεσης για τον πίνακα
+Comment[eo]=Butonoj por ekranŝloso kaj adiaŭo en Panelo
+Comment[es]=Botones de bloqueo y salida del panel
+Comment[et]=Lukustamise ja väljalogimise nupud paneelil
+Comment[eu]=Lock/Logout botoiak panelerako
+Comment[fa]=دکمه‌ی خروج/قفل صفحه‌ی‌ کنترل‌
+Comment[fi]=Lukitse/Kirjaudu ulos napit paneeliin
+Comment[fr]=Des boutons sur le tableau de bord pour verrouiller le bureau ou se déconnecter
+Comment[gl]=Botóns de Bloqueo/Saída no panel
+Comment[he]=כפתורי נעילה\יציאה ללוח
+Comment[hi]=फलक के लिए ताला/लॉगआउट बटन
+Comment[hr]=Tipke za zaključavanje/odjavu na ploči
+Comment[hu]=A panelba illeszkedő nyomógomok az asztal zárolásához és a kijelentkezéshez
+Comment[is]=Stimpla út/Læsa skjáborði hnappar fyrir spjaldið
+Comment[it]=Pulsanti sul pannello per il blocco dello schermo o il termine della sessione
+Comment[ja]=パネルからロック/ログアウトができます
+Comment[lo]=ປຸ່ມລອກ/ລອກອິນສຳລັບຖາດພາເນລ
+Comment[lt]=Užrakinimo/išsiregistravimo mygtukai pultui
+Comment[lv]=Slēgt/Atteikties pogas panelim
+Comment[mk]=Копчиња Заклучи/Одјави се за панелот
+Comment[mn]=Удирдах цонхон дээрх дэлгэц түгжих- ба гарах товч
+Comment[mt]=Applet għall-pannell biex ittemm is-sessjoni jew issakkar l-iskrin
+Comment[nb]=Lås/Loggut-knapp for panelet
+Comment[nds]=Paneelknööp för't Schirm afsluten / Afmellen
+Comment[nl]=Paneelknoppen om af te melden of het scherm te vergrendelen
+Comment[nn]=Panelknappar for skjermlås/utlogging
+Comment[nso]=Ditobetswa tsa Notlelo/Etswa tsa panel
+Comment[pa]=ਪੈਨਲ ਲਈ ਤਾਲਾ/ਬਾਹਰੀ ਦਰ ਐਪਲਿਟ
+Comment[pl]=Przyciski blokowania i wylogowania dla panelu
+Comment[pt]=Os botões para trancar o ecrã e sair do KDE para o painel
+Comment[pt_BR]=Botões de Travar/Sair para o Painel
+Comment[ro]=Butoane de ieşire şi de blocare ecran, pentru panou
+Comment[ru]=Кнопки выхода/запирания экрана на панели
+Comment[se]=Lohkadan-/olggosčálihanboalut panela várás
+Comment[sk]=Tlačidlá panelu pre odhlásenie alebo uzamknutie obrazovky
+Comment[sl]=Gumba za zaklenitev in odjavo na pultu
+Comment[sr]=Дугмад за закључавање/одјављивање за панел
+Comment[sr@Latn]=Dugmad za zaključavanje/odjavljivanje za panel
+Comment[sv]=Lås/Logga ut-knappar för panelen
+Comment[ta]=பூட்டு/பலகத்திற்கான வெளிச்செல் பட்டன்கள்
+Comment[tg]=Кнопкаҳои баромад/қуфли экран дар панел
+Comment[th]=ปุ่มล็อค/ล็อกอินสำหรับถาดพาเนล
+Comment[tr]=Panel için Kilitle/Çık düğmeleri
+Comment[uk]=Кнопки "Замкнути" та "Завершити" для панелі
+Comment[uz]=Панел учун қулфлаш/чиқиш тугмалари
+Comment[ven]=Khiela/bathene dzau litsha dza phanele
+Comment[vi]=Nút Lock/Logout cho khung
+Comment[xh]=Tshixa/Amaqhosa ophumo ngaphandle lwe window eneenkcukacha
+Comment[xx]=xxLock/Logout buttons for the panelxx
+Comment[zh_CN]=面板的锁定/注销按钮
+Comment[zh_TW]=在面板上顯示「螢幕鎖定/登出」按鈕
+Comment[zu]=Izinkinobho Zokukhiya/Ukuphumela ngaphandle zewindi lemininingwane
+# DUPLICATE: Comment[el]=Κουμπιά κλειδώματος/αποσύνδεσης για τον πίνακα
+Icon=kshutdown
+X-KDE-Library=kshutdownlockout_panelapplet
diff --git a/kshutdownlockout/lockout.cpp b/kshutdownlockout/lockout.cpp
new file mode 100644
index 0000000..6fd7085
--- /dev/null
+++ b/kshutdownlockout/lockout.cpp
@@ -0,0 +1,236 @@
+/*****************************************************************
+
+Copyright (c) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
+ 2001 Matthias Elter <elter@kde.org>
+ 2001 Martijn Klingens <mklingens@yahoo.com>
+
+ KShutDown Branch:
+ 2005 Stephen Ellwood
+ 2005 Konrad Twardowski <kdtonline@poczta.onet.pl>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+
+// TODO: 2.0: update handbook
+
+#include <sys/types.h>
+
+#include "lockout.h"
+
+#include <qlayout.h>
+#include <qtoolbutton.h>
+#include <qtooltip.h>
+
+#include <dcopclient.h>
+#include <kaction.h>
+#include <kapplication.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kpopupmenu.h>
+#include <kprocess.h>
+#include <krun.h>
+
+// plugin
+
+#if !KDE_IS_VERSION(3,3,2)
+#undef KDE_EXPORT
+#define KDE_EXPORT
+#endif
+
+extern "C"
+{
+ KDE_EXPORT KPanelApplet *init(QWidget *parent, const QString& configFile)
+ {
+ // share i18n with KShutDown
+ KGlobal::locale()->insertCatalogue("kshutdown");
+
+ return new Lockout(configFile, parent);
+ }
+}
+
+// public
+
+Lockout::Lockout(const QString& configFile, QWidget *parent)
+ : KPanelApplet(
+ configFile,
+ KPanelApplet::Normal,
+ 0, // no standard actions
+ parent,
+ "kshutdownlockout"
+ )
+{
+ setBackgroundOrigin(AncestorOrigin);
+ setFrameStyle(Panel | Sunken);
+
+ initActions();
+
+ KPopupMenu *pm_actions = new KPopupMenu(this);
+ pm_actions->insertTitle(SmallIcon("messagebox_warning"), i18n("No Delay"));
+ _shutDownAction->plug(pm_actions);
+ _rebootAction->plug(pm_actions);
+ _lockScreenAction->plug(pm_actions);
+ _logoutAction->plug(pm_actions);
+ pm_actions->insertSeparator();
+ _configureKShutDownAction->plug(pm_actions);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ QToolButton *button = new QToolButton(this);
+ button->setAutoRaise(true);
+ button->setBackgroundMode(X11ParentRelative);
+ button->setPixmap(SmallIcon("exit"));
+ button->setPopupDelay(100);
+ button->setMinimumSize(button->pixmap()->size());
+ button->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
+ connect(button, SIGNAL(clicked()), this, SLOT(slotShowKShutDown()));
+
+ button->setPopup(pm_actions);
+ layout->addWidget(button);
+
+/* // read configuration
+ KConfig *config = this->config();
+ config->setGroup("kshutdownlockout");
+ _transparent = config->readBoolEntry("Transparent", true);
+*/
+ if (!kapp->dcopClient()->isAttached())
+ kapp->dcopClient()->attach();
+ connect(kapp, SIGNAL(iconChanged(int)), SLOT(slotIconChanged()));
+
+ QToolTip::add(
+ this,
+ "<qt>" \
+ "<b>KShutDown</b><br><br>" +
+ i18n("Click for KShutDown main window<br>Click and hold for menu") +
+ "</qt>"
+ );
+}
+
+Lockout::~Lockout()
+{
+ KGlobal::locale()->removeCatalogue("kshutdown");
+}
+
+int Lockout::heightForWidth(int/* width*/) const
+{
+ return sizeHint().height();
+}
+
+int Lockout::widthForHeight(int/* height*/) const
+{
+ return sizeHint().width();
+}
+
+// private
+
+void Lockout::callKShutDown(const QCString &function) {
+ DCOPClient *client = kapp->dcopClient();
+ if (!client->isApplicationRegistered("kshutdown")) {
+ // run KShutDown
+ KProcess *p = new KProcess();
+ if (!p) {
+ KMessageBox::error(0, i18n("Could not run KShutDown!"));
+
+ return;
+ }
+ *p << "kshutdown";
+ *p << "--init";
+ if (!p->start(KProcess::Block))
+ KMessageBox::error(0, i18n("Could not run KShutDown!"));
+ delete p;
+ }
+ client->send("kshutdown", "KShutdownIface", function, "");
+}
+
+void Lockout::initActions() {
+ KActionCollection *ac_shutDown = new KActionCollection(this, this);
+
+ _lockScreenAction = new KAction(
+ i18n("Lock Screen"), "lock", KShortcut(),
+ this, SLOT(slotLockScreen()),
+ ac_shutDown, "kshutdown_lockscreen"
+ );
+
+ _logoutAction = new KAction(
+ i18n("End Current Session"), "undo", KShortcut(),
+ this, SLOT(slotLogout()),
+ ac_shutDown, "kshutdown_logout"
+ );
+
+ _rebootAction = new KAction(
+ i18n("Restart Computer"), "reload", KShortcut(),
+ this, SLOT(slotReboot()),
+ ac_shutDown, "kshutdown_reboot"
+ );
+
+ _shutDownAction = new KAction(
+ i18n("Turn Off Computer"), "exit", KShortcut(),
+ this, SLOT(slotShutDown()),
+ ac_shutDown, "kshutdown_shutdown"
+ );
+
+ // standard actions
+
+ _configureKShutDownAction = new KAction(
+ i18n("&Configure KShutDown..."), "configure", KShortcut(),
+ this, SLOT(slotConfigureKShutDown()),
+ ac_shutDown, "options_configure"
+ );
+}
+
+void Lockout::runCommand(const QString &command) {
+ pid_t pid = KRun::run(command, KURL::List());
+ if (!pid)
+ KMessageBox::error(0, i18n("Could not run KShutDown!"));
+}
+
+// private slots
+
+void Lockout::slotCancel() {
+ callKShutDown("cancel()");
+}
+
+void Lockout::slotConfigureKShutDown() {
+ callKShutDown("configure()");
+}
+
+void Lockout::slotIconChanged() {
+// FIXME: 2.0: update action icons
+ setIcon(SmallIcon("exit"));
+}
+
+void Lockout::slotLockScreen() {
+ callKShutDown("lockScreen()");
+}
+
+void Lockout::slotLogout() {
+ runCommand("kshutdown --init --confirm --logout");
+}
+
+void Lockout::slotReboot() {
+ runCommand("kshutdown --init --confirm --reboot");
+}
+
+void Lockout::slotShowKShutDown() {
+ callKShutDown("makeVisible()");
+}
+
+void Lockout::slotShutDown() {
+ runCommand("kshutdown --init --confirm --shutdown");
+}
diff --git a/kshutdownlockout/lockout.h b/kshutdownlockout/lockout.h
new file mode 100644
index 0000000..faecd58
--- /dev/null
+++ b/kshutdownlockout/lockout.h
@@ -0,0 +1,59 @@
+#ifndef __LOCKOUT_H__
+#define __LOCKOUT_H__
+
+#include <kpanelapplet.h>
+
+class KAction;
+
+/**
+ * @short A KShutDown panel applet.
+ * Based on the Lockout applet.
+ */
+class Lockout: public KPanelApplet
+{
+ Q_OBJECT
+public:
+ /**
+ * Constructs a new applet.
+ * @param configFile A configuration file (provided by the Kicker)
+ * @param parent A parent widget
+ */
+ Lockout(const QString& configFile, QWidget *parent = 0);
+
+ /**
+ * Destructor.
+ */
+ ~Lockout();
+
+ /**
+ * Returns a suggested height for a given @p width.
+ */
+ int heightForWidth(int width) const;
+
+ /**
+ * Returns a suggested width for a given @p height.
+ */
+ int widthForHeight(int height) const;
+private:
+ bool _transparent;
+ KAction
+ *_configureKShutDownAction,
+ *_lockScreenAction,
+ *_logoutAction,
+ *_rebootAction,
+ *_shutDownAction;
+ void callKShutDown(const QCString &function);
+ void initActions();
+ void runCommand(const QString &command);
+private slots:
+ void slotCancel();
+ void slotConfigureKShutDown();
+ void slotIconChanged();
+ void slotLockScreen();
+ void slotLogout();
+ void slotReboot();
+ void slotShowKShutDown();
+ void slotShutDown();
+};
+
+#endif // __LOCKOUT_H__