Warning, /plasma-mobile/spacebar/src/contents/ui/settings/SettingsPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Michael Lang <criticaltemp@protonmail.com>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 import QtQuick
0006 import QtQuick.Layouts
0007 import QtQuick.Controls as Controls
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 import org.kde.spacebar
0012 import org.kde.kirigamiaddons.formcard as FormCard
0013 
0014 Kirigami.ScrollablePage {
0015     id: page
0016     title: i18n("Settings")
0017 
0018     leftPadding: 0
0019     rightPadding: 0
0020     topPadding: Kirigami.Units.gridUnit
0021     bottomPadding: Kirigami.Units.gridUnit
0022 
0023     property ChatListModel chatListModel;
0024 
0025     Component.onDestruction: if (chatListModel) chatListModel.saveSettings()
0026 
0027     width: applicationWindow().width
0028     Kirigami.ColumnView.fillWidth: true
0029     
0030     ColumnLayout {
0031         spacing: 0
0032 
0033         FormCard.FormCard {
0034             Layout.fillWidth: true
0035 
0036             ColumnLayout {
0037                 spacing: 0
0038 
0039                 FormCard.FormHeader {
0040                     title: i18n("General")
0041                 }
0042 
0043                 FormCard.FormButtonDelegate {
0044                     id: aboutButton
0045                     text: i18n("About")
0046                     onClicked: applicationWindow().pageStack.push("qrc:/AboutPage.qml")
0047                 }
0048 
0049                 FormCard.FormDelegateSeparator { above: aboutButton; below: mmsButton }
0050 
0051                 FormCard.FormButtonDelegate {
0052                     id: mmsButton
0053                     text: i18n("Multimedia Messages (MMS)")
0054                     onClicked: applicationWindow().pageStack.push("qrc:/settings/MMSSettingsPage.qml")
0055                 }
0056 
0057                 FormCard.FormDelegateSeparator { above: mmsButton }
0058 
0059                 FormCard.FormTextDelegate {
0060                     id: restoreButton
0061                     text: i18n("Restore defaults")
0062 
0063                     trailing: Controls.Button {
0064                         text: i18n("Reset")
0065                         onClicked: {
0066                             const server = SettingsManager.mmsc
0067                             const proxy = SettingsManager.mmsProxy
0068                             chatListModel.restoreDefaults()
0069                             SettingsManager.mmsc = server
0070                             SettingsManager.mmsProxy = proxy
0071                         }
0072                     }
0073                 }
0074             }
0075         }
0076 
0077         FormCard.FormCard {
0078             Layout.fillWidth: true
0079             Layout.topMargin: Kirigami.Units.largeSpacing
0080 
0081             ColumnLayout {
0082                 spacing: 0
0083 
0084                 FormCard.FormHeader {
0085                     title: i18n("Appearance")
0086                 }
0087 
0088                 FormCard.FormSwitchDelegate {
0089                     id: customMessageColors
0090                     checked: SettingsManager.customMessageColors
0091                     text: i18n("Use custom colors for messages")
0092                     onToggled: SettingsManager.customMessageColors = checked
0093                 }
0094 
0095                 FormCard.FormDelegateSeparator { above: customMessageColors }
0096 
0097                 FormCard.FormTextDelegate {
0098                     id: incomingMessageColor
0099                     text: i18n("Incoming message color")
0100                     visible: SettingsManager.customMessageColors
0101                     trailing: Controls.Button {
0102                         width: Kirigami.Units.gridUnit * 1.5
0103                         height: Kirigami.Units.gridUnit * 1.5
0104                         onClicked: {
0105                             colorDialog.selected = SettingsManager.incomingMessageColor
0106                             colorDialog.field = "incomingMessageColor"
0107                             colorDialog.open()
0108                         }
0109 
0110                         Rectangle {
0111                             anchors.fill: parent
0112                             anchors.margins: 1
0113                             color: SettingsManager.incomingMessageColor
0114                         }
0115                     }
0116                 }
0117 
0118                 FormCard.FormDelegateSeparator { visible: incomingMessageColor.visible }
0119 
0120                 FormCard.FormTextDelegate {
0121                     id: outgoingMessageColor
0122                     text: i18n("Outgoing message color")
0123                     visible: SettingsManager.customMessageColors
0124                     trailing: Controls.Button {
0125                         width: Kirigami.Units.gridUnit * 1.5
0126                         height: Kirigami.Units.gridUnit * 1.5
0127                         onClicked: {
0128                             colorDialog.selected = SettingsManager.outgoingMessageColor
0129                             colorDialog.field = "outgoingMessageColor"
0130                             colorDialog.open()
0131                         }
0132 
0133                         Rectangle {
0134                             anchors.fill: parent
0135                             anchors.margins: 1
0136                             color: SettingsManager.outgoingMessageColor
0137                         }
0138                     }
0139                 }
0140 
0141                 FormCard.FormDelegateSeparator { visible: outgoingMessageColor.visible }
0142 
0143                 FormCard.FormTextDelegate {
0144                     id: messageFontSize
0145                     text: i18n("Message font size")
0146                     trailing: Controls.SpinBox {
0147                         value: SettingsManager.messageFontSize
0148                         from: -3
0149                         to: 3
0150                         stepSize: 1
0151                         onValueModified: SettingsManager.messageFontSize = value
0152                     }
0153                 }
0154             }
0155         }
0156 
0157         FormCard.FormCard {
0158             Layout.fillWidth: true
0159             Layout.topMargin: Kirigami.Units.largeSpacing
0160 
0161             ColumnLayout {
0162                 spacing: 0
0163 
0164                 FormCard.FormHeader {
0165                     title: i18n("Notifications")
0166                 }
0167 
0168                 FormCard.FormCheckDelegate {
0169                     id: showSenderInfo
0170                     checked: SettingsManager.showSenderInfo
0171                     text: i18n("Show sender name / number")
0172                     onToggled: SettingsManager.showSenderInfo = checked
0173                 }
0174 
0175                 FormCard.FormCheckDelegate {
0176                     id: showMessageContent
0177                     checked: SettingsManager.showMessageContent
0178                     text: i18n("Show a preview of the message content")
0179                     onToggled: SettingsManager.showMessageContent = checked
0180                 }
0181 
0182                 FormCard.FormCheckDelegate {
0183                     id: showAttachments
0184                     checked: SettingsManager.showAttachments
0185                     text: i18n("Show attachment previews")
0186                     onToggled: SettingsManager.showAttachments = checked
0187                 }
0188 
0189                 FormCard.FormCheckDelegate {
0190                     id: ignoreTapbacks
0191                     checked: SettingsManager.ignoreTapbacks
0192                     text: i18n("Ignore tapbacks")
0193                     onToggled: SettingsManager.ignoreTapbacks = checked
0194                 }
0195             }
0196         }
0197     }
0198 
0199     Kirigami.Dialog {
0200         id: colorDialog
0201         topPadding: 0
0202         bottomPadding: 0
0203         leftPadding: 0
0204         rightPadding: 0
0205 
0206         property string field
0207         property color selected
0208 
0209         title: i18n("Choose a color")
0210         standardButtons: Kirigami.Dialog.Cancel | Kirigami.Dialog.Apply
0211 
0212         onApplied: {
0213             SettingsManager[colorDialog.field] = colorDialog.selected;
0214             colorDialog.close();
0215         }
0216 
0217         Grid {
0218             spacing: Kirigami.Units.smallSpacing
0219             padding: Kirigami.Units.largeSpacing * 2
0220             flow: Grid.TopToBottom
0221             columns: 9
0222 
0223             property real cellSize: Math.min(page.width / columns - Kirigami.Units.largeSpacing, Kirigami.Units.gridUnit * 2.5)
0224 
0225             Repeater {
0226                 model: [
0227                     "#99c1f1", "#62a0ea", "#3584e4", "#1c71d8", "#1a5fb4",
0228                     "#8ff0a4", "#57e389", "#33d17a", "#2ec27e", "#26a269",
0229                     "#fff4a2", "#f9f06b", "#f8e45c", "#f6d32d", "#f5c211",
0230                     "#ffbe6f", "#ffa348", "#ff7800", "#e66100", "#c64600",
0231                     "#f66151", "#ed333b", "#e01b24", "#c01c28", "#a51d2d",
0232                     "#dc8add", "#c061cb", "#9141ac", "#813d9c", "#613583",
0233                     "#cdab8f", "#b5835a", "#986a44", "#865e3c", "#63452c",
0234                     "#ffffff", "#f6f5f4", "#deddda", "#c0bfbc", "#9a9996",
0235                     "#77767b", "#5e5c64", "#3d3846", "#241f31", "#000000"
0236                 ]
0237 
0238                 delegate: Controls.Button {
0239                     width: parent.cellSize
0240                     height: parent.cellSize
0241                     background: Rectangle {
0242                         color: modelData
0243                         border.width: 1
0244                         border.color: Kirigami.Theme.disabledTextColor
0245                     }
0246                     onClicked: colorDialog.selected = modelData
0247 
0248                     Kirigami.Icon {
0249                         visible: modelData == colorDialog.selected
0250                         anchors.fill: parent
0251                         source: "object-select-symbolic"
0252                         color: modelData == "#000000" ? "white" : "black"
0253                     }
0254                 }
0255             }
0256         }
0257     }
0258 }