From Paul WOISARD, 2 Years ago, written in Plain Text.
Embed
  1. /***************************************************************************
  2.  *   Copyright (C) 2014 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>  *
  3.  *                                                                         *
  4.  *   This program is free software; you can redistribute it and/or modify  *
  5.  *   it under the terms of the GNU General Public License as published by  *
  6.  *   the Free Software Foundation; either version 2 of the License, or     *
  7.  *   (at your option) any later version.                                   *
  8.  *                                                                         *
  9.  *   This program is distributed in the hope that it will be useful,       *
  10.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  11.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  12.  *   GNU General Public License for more details.                          *
  13.  *                                                                         *
  14.  *   You should have received a copy of the GNU General Public License     *
  15.  *   along with this program; if not, write to the                         *
  16.  *   Free Software Foundation, Inc.,                                       *
  17.  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  18.  ***************************************************************************/
  19.  
  20. import QtQuick 2.2
  21. import QtQuick.Layouts 1.2
  22. import QtQuick.Controls 1.1 as Controls
  23.  
  24. import org.kde.plasma.core 2.0 as PlasmaCore
  25. import org.kde.plasma.components 2.0 as PlasmaComponents
  26. import org.kde.kcoreaddons 1.0 as KCoreAddons
  27.  
  28. import "../components"
  29.  
  30. PlasmaCore.ColorScope {
  31.     id: root
  32.     colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
  33.     height: screenGeometry.height
  34.     width: screenGeometry.width
  35.  
  36.     signal logoutRequested()
  37.     signal haltRequested()
  38.     signal suspendRequested(int spdMethod)
  39.     signal rebootRequested()
  40.     signal rebootRequested2(int opt)
  41.     signal cancelRequested()
  42.     signal lockScreenRequested()
  43.  
  44.     function sleepRequested() {
  45.         root.suspendRequested(2);
  46.     }
  47.  
  48.     property real timeout: 30
  49.     property real remainingTime: root.timeout
  50.     property var currentAction: {
  51.         switch (sdtype) {
  52.             case ShutdownType.ShutdownTypeReboot:
  53.                 return root.rebootRequested;
  54.             case ShutdownType.ShutdownTypeHalt:
  55.                 return root.haltRequested;
  56.             default:
  57.                 return root.logoutRequested;
  58.         }
  59.     }
  60.  
  61.     KCoreAddons.KUser {
  62.         id: kuser
  63.     }
  64.  
  65.     Controls.Action {
  66.         onTriggered: root.cancelRequested()
  67.         shortcut: "Escape"
  68.     }
  69.  
  70.     onRemainingTimeChanged: {
  71.         if (remainingTime <= 0) {
  72.             root.currentAction();
  73.         }
  74.     }
  75.  
  76.     Timer {
  77.         running: true
  78.         repeat: true
  79.         interval: 1000
  80.         onTriggered: remainingTime--
  81.     }
  82.  
  83.     Rectangle {
  84.         anchors.fill: parent
  85.         color: PlasmaCore.ColorScope.backgroundColor
  86.         opacity: 0.5
  87.     }
  88.     MouseArea {
  89.         anchors.fill: parent
  90.         onClicked: root.cancelRequested()
  91.     }
  92.     UserDelegate {
  93.         width: units.iconSizes.enormous
  94.         height: width
  95.         anchors {
  96.             horizontalCenter: parent.horizontalCenter
  97.             bottom: parent.verticalCenter
  98.         }
  99.         avatarPath: kuser.faceIconUrl
  100.         iconSource: "user-identity"
  101.         isCurrent: true
  102.         name: kuser.fullName
  103.     }
  104.     ColumnLayout {
  105.         anchors {
  106.             top: parent.verticalCenter
  107.             topMargin: units.gridUnit * 2
  108.             horizontalCenter: parent.horizontalCenter
  109.         }
  110.         spacing: units.largeSpacing
  111.  
  112.         height: Math.max(implicitHeight, units.gridUnit * 10)
  113.         width: Math.max(implicitWidth, units.gridUnit * 16)
  114.  
  115.         RowLayout {
  116.             spacing: units.largeSpacing * 2
  117.             Layout.alignment: Qt.AlignHCenter
  118.             LogoutButton {
  119.                 id: suspendButton
  120.                 iconSource: "system-suspend"
  121.                 text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Suspendre")
  122.                 action: root.sleepRequested
  123.                 KeyNavigation.left: logoutButton
  124.                 KeyNavigation.right: rebootButton
  125.             }
  126.             LogoutButton {
  127.                 id: rebootButton
  128.                 iconSource: "system-reboot"
  129.                 text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Redémarrer")
  130.                 action: root.rebootRequested
  131.                 KeyNavigation.left: suspendButton
  132.                 KeyNavigation.right: shutdownButton
  133.                 focus: sdtype == ShutdownType.ShutdownTypeReboot
  134.             }
  135.             LogoutButton {
  136.                 id: shutdownButton
  137.                 iconSource: "system-shutdown"
  138.                 text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Éteindre")
  139.                 action: root.haltRequested
  140.                 KeyNavigation.left: rebootButton
  141.                 KeyNavigation.right: logoutButton
  142.                 focus: sdtype == ShutdownType.ShutdownTypeHalt
  143.             }
  144.             LogoutButton {
  145.                 id: logoutButton
  146.                 iconSource: "system-log-out"
  147.                 text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Déconnecter")
  148.                 action: root.logoutRequested
  149.                 KeyNavigation.left: shutdownButton
  150.                 KeyNavigation.right: suspendButton
  151.                 focus: sdtype == ShutdownType.ShutdownTypeNone
  152.             }
  153.         }
  154.  
  155.         PlasmaComponents.Label {
  156.             Layout.alignment: Qt.AlignHCenter
  157.             text: {
  158.                 switch (sdtype) {
  159.                     case ShutdownType.ShutdownTypeReboot:
  160.                         return i18ndp("plasma_lookandfeel_org.kde.lookandfeel", "Redémarrage dans 1 seconde", "Redémarrage dans %1 secondes", root.remainingTime);
  161.                     case ShutdownType.ShutdownTypeHalt:
  162.                         return i18ndp("plasma_lookandfeel_org.kde.lookandfeel", "Extinction dans 1 seconde", "Extinction dans %1 secondes", root.remainingTime);
  163.                     default:
  164.                         return i18ndp("plasma_lookandfeel_org.kde.lookandfeel", "Déconnexion dans 1 seconde", "Déconnexion dans %1 secondes", root.remainingTime);
  165.                 }
  166.             }
  167.         }
  168.  
  169.         PlasmaComponents.Button {
  170.             Layout.alignment: Qt.AlignHCenter
  171.             text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Cancel")
  172.             onClicked: root.cancelRequested()
  173.         }
  174.     }
  175. }
  176.