| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import ".." |
| 6 |
import QtQuick |
| 7 |
import QtQuick.Controls |
| 8 |
import QtQuick.Layouts |
| 9 |
import im.nheko |
| 10 |
|
| 11 |
|
| 12 |
ApplicationWindow { |
| 13 |
id: aliasEditorW |
| 14 |
|
| 15 |
property var roomSettings |
| 16 |
property var editingModel: Nheko.editAliases(roomSettings.roomId) |
| 17 |
|
| 18 |
modality: Qt.NonModal |
| 19 |
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint |
| 20 |
minimumWidth: 300 |
| 21 |
minimumHeight: 400 |
| 22 |
height: 600 |
| 23 |
width: 500 |
| 24 |
|
| 25 |
title: qsTr("Aliases to %1").arg(roomSettings.roomName); |
| 26 |
|
| 27 |
// Shortcut { |
| 28 |
// sequence: StandardKey.Cancel |
| 29 |
// onActivated: dbb.rejected() |
| 30 |
// } |
| 31 |
|
| 32 |
ColumnLayout { |
| 33 |
anchors.margins: Nheko.paddingMedium |
| 34 |
anchors.fill: parent |
| 35 |
spacing: 0 |
| 36 |
|
| 37 |
|
| 38 |
MatrixText { |
| 39 |
text: qsTr("List of aliases to this room. Usually you can only add aliases on your server. You can have one canonical alias and many alternate aliases.") |
| 40 |
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1) |
| 41 |
Layout.fillWidth: true |
| 42 |
Layout.fillHeight: false |
| 43 |
color: palette.text |
| 44 |
Layout.bottomMargin: Nheko.paddingMedium |
| 45 |
} |
| 46 |
|
| 47 |
ListView { |
| 48 |
Layout.fillWidth: true |
| 49 |
Layout.fillHeight: true |
| 50 |
|
| 51 |
id: view |
| 52 |
|
| 53 |
clip: true |
| 54 |
|
| 55 |
|
| 56 |
model: editingModel |
| 57 |
spacing: 4 |
| 58 |
cacheBuffer: 50 |
| 59 |
|
| 60 |
delegate: RowLayout { |
| 61 |
anchors.left: parent.left |
| 62 |
anchors.right: parent.right |
| 63 |
|
| 64 |
Text { |
| 65 |
Layout.fillWidth: true |
| 66 |
text: model.name |
| 67 |
color: model.isPublished ? palette.text : Nheko.theme.error |
| 68 |
textFormat: Text.PlainText |
| 69 |
} |
| 70 |
|
| 71 |
ImageButton { |
| 72 |
Layout.alignment: Qt.AlignRight |
| 73 |
Layout.margins: 2 |
| 74 |
image: ":/icons/icons/ui/star.svg" |
| 75 |
hoverEnabled: true |
| 76 |
buttonTextColor: model.isCanonical ? palette.highlight : palette.text |
| 77 |
highlightColor: editingModel.canAdvertize ? palette.highlight : buttonTextColor |
| 78 |
|
| 79 |
ToolTip.visible: hovered |
| 80 |
ToolTip.text: model.isCanonical ? qsTr("Primary alias") : qsTr("Make primary alias") |
| 81 |
|
| 82 |
onClicked: editingModel.makeCanonical(model.index) |
| 83 |
} |
| 84 |
|
| 85 |
ImageButton { |
| 86 |
Layout.alignment: Qt.AlignRight |
| 87 |
Layout.margins: 2 |
| 88 |
image: ":/icons/icons/ui/building-shop.svg" |
| 89 |
hoverEnabled: true |
| 90 |
buttonTextColor: model.isAdvertized ? palette.highlight : palette.text |
| 91 |
highlightColor: editingModel.canAdvertize ? palette.highlight : buttonTextColor |
| 92 |
|
| 93 |
ToolTip.visible: hovered |
| 94 |
ToolTip.text: qsTr("Advertise as an alias in this room") |
| 95 |
|
| 96 |
onClicked: editingModel.toggleAdvertize(model.index) |
| 97 |
} |
| 98 |
|
| 99 |
ImageButton { |
| 100 |
Layout.alignment: Qt.AlignRight |
| 101 |
Layout.margins: 2 |
| 102 |
image: ":/icons/icons/ui/room-directory.svg" |
| 103 |
hoverEnabled: true |
| 104 |
buttonTextColor: model.isPublished ? palette.highlight : palette.text |
| 105 |
|
| 106 |
ToolTip.visible: hovered |
| 107 |
ToolTip.text: qsTr("Publish in room directory") |
| 108 |
|
| 109 |
onClicked: editingModel.togglePublish(model.index) |
| 110 |
} |
| 111 |
|
| 112 |
ImageButton { |
| 113 |
Layout.alignment: Qt.AlignRight |
| 114 |
Layout.margins: 2 |
| 115 |
image: ":/icons/icons/ui/dismiss.svg" |
| 116 |
hoverEnabled: true |
| 117 |
|
| 118 |
ToolTip.visible: hovered |
| 119 |
ToolTip.text: qsTr("Remove this alias") |
| 120 |
|
| 121 |
onClicked: editingModel.deleteAlias(model.index) |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
RowLayout { |
| 127 |
spacing: Nheko.paddingMedium |
| 128 |
Layout.fillWidth: true |
| 129 |
|
| 130 |
MatrixTextField { |
| 131 |
id: newAliasVal |
| 132 |
|
| 133 |
focus: true |
| 134 |
Layout.fillWidth: true |
| 135 |
selectByMouse: true |
| 136 |
font.pixelSize: fontMetrics.font.pixelSize |
| 137 |
color: palette.text |
| 138 |
placeholderText: qsTr("#new-alias:server.tld") |
| 139 |
|
| 140 |
Component.onCompleted: forceActiveFocus() |
| 141 |
Keys.onPressed: { |
| 142 |
if (event.matches(StandardKey.InsertParagraphSeparator)) { |
| 143 |
editingModel.addAlias(newAliasVal.text); |
| 144 |
newAliasVal.clear(); |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
Button { |
| 150 |
text: qsTr("Add") |
| 151 |
Layout.preferredWidth: 100 |
| 152 |
onClicked: { |
| 153 |
editingModel.addAlias(newAliasVal.text); |
| 154 |
newAliasVal.clear(); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
footer: DialogButtonBox { |
| 161 |
id: dbb |
| 162 |
|
| 163 |
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel |
| 164 |
onAccepted: { |
| 165 |
editingModel.commit(); |
| 166 |
aliasEditorW.close(); |
| 167 |
} |
| 168 |
onRejected: aliasEditorW.close(); |
| 169 |
} |
| 170 |
|
| 171 |
} |