2
0

ProfilesDialog.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <malte.veerman@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. import QtQuick 2.6
  20. import QtQuick.Controls 2.1
  21. import QtQuick.Layouts 1.2
  22. import org.kde.kirigami 2.3 as Kirigami
  23. import Fancontrol.Qml 1.0 as Fancontrol
  24. Dialog {
  25. title: i18n("Manage profiles")
  26. width: Kirigami.Units.gridUnit * 20
  27. height: Kirigami.Units.gridUnit * 20
  28. standardButtons: Dialog.Close
  29. RowLayout {
  30. anchors.fill: parent
  31. Rectangle {
  32. Layout.fillWidth: true
  33. Layout.fillHeight: true
  34. Kirigami.Theme.colorSet: Kirigami.Theme.View
  35. color: Kirigami.Theme.backgroundColor
  36. border.width: 1
  37. border.color: Kirigami.Theme.textColor
  38. ListView {
  39. id: profilesListView
  40. anchors.fill: parent
  41. anchors.margins: parent.border.width
  42. model: Fancontrol.Base.profileModel
  43. clip: true
  44. currentIndex: Fancontrol.Base.currentProfileIndex
  45. boundsBehavior: Flickable.StopAtBounds
  46. flickableDirection: Flickable.AutoFlickIfNeeded
  47. header: Kirigami.BasicListItem {
  48. label: '<b>' + i18n("Profiles") + '</b>'
  49. reserveSpaceForIcon: false
  50. hoverEnabled: false
  51. separatorVisible: false
  52. leftPadding: Kirigami.Units.smallSpacing
  53. }
  54. delegate: Kirigami.BasicListItem {
  55. label: {
  56. if (Fancontrol.Base.currentProfileIndex === index)
  57. return display + ' ' + i18n("(current profile)")
  58. else
  59. return display
  60. }
  61. reserveSpaceForIcon: false
  62. hoverEnabled: true
  63. highlighted: ListView.isCurrentItem
  64. separatorVisible: false
  65. onPressedChanged: if (pressed) profilesListView.currentIndex = index;
  66. }
  67. }
  68. }
  69. ColumnLayout {
  70. Layout.fillHeight: true
  71. Button {
  72. text: i18n("Apply profile")
  73. enabled: Fancontrol.Base.currentProfileIndex != profilesListView.currentIndex
  74. onClicked: Fancontrol.Base.applyProfile(profilesListView.currentIndex)
  75. }
  76. Button {
  77. text: i18n("Create new profile")
  78. enabled: Fancontrol.Base.currentProfileIndex == -1
  79. onClicked: newProfileNameDialog.open()
  80. }
  81. Button {
  82. text: i18n("Save to profile")
  83. enabled: Fancontrol.Base.currentProfileIndex != profilesListView.currentIndex && profilesListView.currentIndex >= 0
  84. onClicked: Fancontrol.Base.saveProfile(profilesListView.currentItem.label)
  85. }
  86. Button {
  87. text: i18n("Delete profile")
  88. enabled: profilesListView.currentIndex >= 0
  89. onClicked: Fancontrol.Base.deleteProfile(profilesListView.currentIndex)
  90. }
  91. Item {
  92. Layout.fillHeight: true
  93. }
  94. }
  95. }
  96. Dialog {
  97. id: newProfileNameDialog
  98. title: i18n("New profile's name")
  99. standardButtons: Dialog.Ok | Dialog.Cancel
  100. visible: false
  101. x: (parent.width - width) / 2
  102. y: (parent.height - height) / 2
  103. onAccepted: {
  104. Fancontrol.Base.saveProfile(newProfileNameField.text);
  105. newProfileNameField.text = "";
  106. }
  107. onRejected: newProfileNameField.text = ""
  108. TextField {
  109. id: newProfileNameField
  110. }
  111. }
  112. }