From Paul WOISARD, 2 Years ago, written in Plain Text.
Embed
  1. /*
  2.  *   Copyright 2016 David Edmundson <davidedmundson@kde.org>
  3.  *
  4.  *   This program is free software; you can redistribute it and/or modify
  5.  *   it under the terms of the GNU Library General Public License as
  6.  *   published by the Free Software Foundation; either version 2 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 Library General Public
  15.  *   License 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.  
  22. import QtQuick.Layouts 1.1
  23. import QtQuick.Controls 1.1
  24.  
  25. import org.kde.plasma.core 2.0 as PlasmaCore
  26. import org.kde.plasma.components 2.0 as PlasmaComponents
  27. import org.kde.plasma.extras 2.0 as PlasmaExtras
  28.  
  29. import "components"
  30.  
  31. PlasmaCore.ColorScope {
  32.     id: root
  33.     colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
  34.  
  35.     width: 1600
  36.     height: 900
  37.  
  38.     property string notificationMessage
  39.  
  40.     LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
  41.     LayoutMirroring.childrenInherit: true
  42.  
  43.     PlasmaCore.DataSource {
  44.         id: keystateSource
  45.         engine: "keystate"
  46.         connectedSources: "Caps Lock"
  47.     }
  48.  
  49.     Repeater {
  50.         model: screenModel
  51.  
  52.         Background {
  53.             x: geometry.x; y: geometry.y; width: geometry.width; height:geometry.height
  54.             source: config.background
  55.             fillMode: Image.PreserveAspectCrop
  56.         }
  57.     }
  58.  
  59.     Clock {
  60.         visible: y > 0
  61.         anchors.bottom: parent.verticalCenter
  62.         anchors.bottomMargin: units.gridUnit * 13
  63.         anchors.horizontalCenter: parent.horizontalCenter
  64.     }
  65.  
  66.  
  67.     StackView {
  68.         id: mainStack
  69.         anchors {
  70.             top: parent.top
  71.             bottom: footer.top
  72.             left: parent.left
  73.             right: parent.right
  74.             topMargin: footer.height // effectively centre align within the view
  75.         }
  76.         focus: true //StackView is an implicit focus scope, so we need to give this focus so the item inside will have it
  77.  
  78.         Timer {
  79.             //SDDM has a bug in 0.13 where even though we set the focus on the right item within the window, the window doesn't have focus
  80.             //it is fixed in 6d5b36b28907b16280ff78995fef764bb0c573db which will be 0.14
  81.             //we need to call "window->activate()" *After* it's been shown. We can't control that in QML so we use a shoddy timer
  82.             //it's been this way for all Plasma 5.x without a huge problem
  83.             running: true
  84.             repeat: false
  85.             interval: 200
  86.             onTriggered: mainStack.forceActiveFocus()
  87.         }
  88.  
  89.         initialItem: Login {
  90.             id: userListComponent
  91.             userListModel: userModel
  92.             userListCurrentIndex: userModel.lastIndex >= 0 ? userModel.lastIndex : 0
  93.             showUserList: {
  94.                  if ( !userListModel.hasOwnProperty("count")
  95.                    || !userListModel.hasOwnProperty("disableAvatarsThreshold"))
  96.                      return true
  97.  
  98.                  if ( userListModel.count == 0 ) return false
  99.  
  100.                  return userListModel.count <= userListModel.disableAvatarsThreshold
  101.             }
  102.  
  103.             notificationMessage: {
  104.                 var text = ""
  105.                 if (keystateSource.data["Caps Lock"]["Locked"]) {
  106.                     text += i18nd("plasma_lookandfeel_org.kde.lookandfeel","Verr. Maj. est activé")
  107.                     if (root.notificationMessage) {
  108.                         text += " • "
  109.                     }
  110.                 }
  111.                 text += root.notificationMessage
  112.                 return text
  113.             }
  114.  
  115.             actionItems: [
  116.                 ActionButton {
  117.                     iconSource: "system-suspend"
  118.                     text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Suspendre")
  119.                     onClicked: sddm.suspend()
  120.                     enabled: sddm.canSuspend
  121.                 },
  122.                 ActionButton {
  123.                     iconSource: "system-reboot"
  124.                     text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Redémarrer")
  125.                     onClicked: sddm.reboot()
  126.                     enabled: sddm.canReboot
  127.                 },
  128.                 ActionButton {
  129.                     iconSource: "system-shutdown"
  130.                     text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Éteindre")
  131.                     onClicked: sddm.powerOff()
  132.                     enabled: sddm.canPowerOff
  133.                 },
  134.                 ActionButton {
  135.                     iconSource: "system-search"
  136.                     text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Changer d'utilisateur")
  137.                     onClicked: mainStack.push(userPromptComponent)
  138.                     enabled: true
  139.                     visible: !userListComponent.showUsernamePrompt
  140.                 }
  141.             ]
  142.  
  143.             onLoginRequest: {
  144.                 root.notificationMessage = ""
  145.                 sddm.login(username, password, sessionButton.currentIndex)
  146.             }
  147.         }
  148.  
  149.         Behavior on opacity {
  150.             OpacityAnimator {
  151.                 duration: units.longDuration
  152.             }
  153.         }
  154.  
  155.     }
  156.  
  157.     Component {
  158.         id: userPromptComponent
  159.         Login {
  160.             showUsernamePrompt: true
  161.             notificationMessage: root.notificationMessage
  162.  
  163.             userListModel: QtObject {
  164.                 property string name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Autre utilisateur")
  165.                 property string iconSource: ""
  166.             }
  167.  
  168.             onLoginRequest: {
  169.                 root.notificationMessage = ""
  170.                 sddm.login(username, password, sessionButton.currentIndex)
  171.             }
  172.  
  173.             actionItems: [
  174.                 ActionButton {
  175.                     iconSource: "go-previous"
  176.                     text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Retour")
  177.                     onClicked: mainStack.pop()
  178.                 }
  179.             ]
  180.         }
  181.     }
  182.  
  183.     //Footer
  184.     RowLayout {
  185.         id: footer
  186.         anchors {
  187.             bottom: parent.bottom
  188.             left: parent.left
  189.             right: parent.right
  190.             margins: units.smallSpacing
  191.         }
  192.  
  193.         Behavior on opacity {
  194.             OpacityAnimator {
  195.                 duration: units.longDuration
  196.             }
  197.         }
  198.  
  199.         KeyboardButton {
  200.         }
  201.  
  202.         SessionButton {
  203.             id: sessionButton
  204.         }
  205.  
  206.         Item {
  207.             Layout.fillWidth: true
  208.         }
  209.  
  210.         Battery { }
  211.     }
  212.  
  213.     Connections {
  214.         target: sddm
  215.         onLoginFailed: {
  216.             notificationMessage = i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Echec de la connection")
  217.         }
  218.         onLoginSucceeded: {
  219.             //note SDDM will kill the greeter at some random point after this
  220.             //there is no certainty any transition will finish, it depends on the time it
  221.             //takes to complete the init
  222.             mainStack.opacity = 0
  223.             footer.opacity = 0
  224.         }
  225.     }
  226.  
  227.     onNotificationMessageChanged: {
  228.         if (notificationMessage) {
  229.             notificationResetTimer.start();
  230.         }
  231.     }
  232.  
  233.     Timer {
  234.         id: notificationResetTimer
  235.         interval: 3000
  236.         onTriggered: notificationMessage = ""
  237.     }
  238.  
  239. }
  240.