| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import "./dialogs" |
| 6 |
import "./pages" |
| 7 |
import "./ui" |
| 8 |
import QtQuick |
| 9 |
import QtQuick.Controls |
| 10 |
import QtQuick.Window |
| 11 |
import QtQuick.Dialogs |
| 12 |
import im.nheko |
| 13 |
|
| 14 |
Pane { |
| 15 |
id: timelineRoot |
| 16 |
|
| 17 |
function destroyOnClose(obj) { |
| 18 |
if (obj.closing != undefined) |
| 19 |
obj.closing.connect(() => obj.destroy(1000)); |
| 20 |
else if (obj.aboutToHide != undefined) |
| 21 |
obj.aboutToHide.connect(() => obj.destroy(1000)); |
| 22 |
} |
| 23 |
function destroyOnClosed(obj) { |
| 24 |
obj.aboutToHide.connect(() => obj.destroy(1000)); |
| 25 |
} |
| 26 |
|
| 27 |
//Timer { |
| 28 |
// onTriggered: gc() |
| 29 |
// interval: 1000 |
| 30 |
// running: true |
| 31 |
// repeat: true |
| 32 |
//} |
| 33 |
function showAliasEditor(settings) { |
| 34 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/AliasEditor.qml"); |
| 35 |
if (component.status == Component.Ready) { |
| 36 |
var dialog = component.createObject(timelineRoot, { |
| 37 |
"roomSettings": settings |
| 38 |
}); |
| 39 |
dialog.show(); |
| 40 |
destroyOnClose(dialog); |
| 41 |
} else { |
| 42 |
console.error("Failed to create component: " + component.errorString()); |
| 43 |
} |
| 44 |
} |
| 45 |
function showAllowedRoomsEditor(settings) { |
| 46 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/AllowedRoomsSettingsDialog.qml"); |
| 47 |
if (component.status == Component.Ready) { |
| 48 |
var dialog = component.createObject(timelineRoot, { |
| 49 |
"roomSettings": settings |
| 50 |
}); |
| 51 |
dialog.show(); |
| 52 |
destroyOnClose(dialog); |
| 53 |
} else { |
| 54 |
console.error("Failed to create component: " + component.errorString()); |
| 55 |
} |
| 56 |
} |
| 57 |
function showPLEditor(settings) { |
| 58 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/PowerLevelEditor.qml"); |
| 59 |
if (component.status == Component.Ready) { |
| 60 |
var dialog = component.createObject(timelineRoot, { |
| 61 |
"roomSettings": settings |
| 62 |
}); |
| 63 |
dialog.show(); |
| 64 |
destroyOnClose(dialog); |
| 65 |
} else { |
| 66 |
console.error("Failed to create component: " + component.errorString()); |
| 67 |
} |
| 68 |
} |
| 69 |
function showSpacePLApplyPrompt(settings, editingModel) { |
| 70 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/PowerLevelSpacesApplyDialog.qml"); |
| 71 |
if (component.status == Component.Ready) { |
| 72 |
var dialog = component.createObject(timelineRoot, { |
| 73 |
"roomSettings": settings, |
| 74 |
"editingModel": editingModel |
| 75 |
}); |
| 76 |
dialog.show(); |
| 77 |
destroyOnClose(dialog); |
| 78 |
} else { |
| 79 |
console.error("Failed to create component: " + component.errorString()); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
background: null |
| 84 |
padding: 0 |
| 85 |
|
| 86 |
FontMetrics { |
| 87 |
id: fontMetrics |
| 88 |
|
| 89 |
} |
| 90 |
UserDirectoryModel { |
| 91 |
id: userDirectory |
| 92 |
|
| 93 |
} |
| 94 |
RoomDirectoryModel { |
| 95 |
id: publicRooms |
| 96 |
|
| 97 |
} |
| 98 |
Component { |
| 99 |
id: readReceiptsDialog |
| 100 |
|
| 101 |
ReadReceipts { |
| 102 |
} |
| 103 |
} |
| 104 |
Shortcut { |
| 105 |
sequence: StandardKey.Quit |
| 106 |
|
| 107 |
onActivated: Qt.quit() |
| 108 |
} |
| 109 |
Shortcut { |
| 110 |
sequence: "Ctrl+K" |
| 111 |
|
| 112 |
onActivated: { |
| 113 |
var component = Qt.createComponent("qrc:/resources/qml/QuickSwitcher.qml"); |
| 114 |
if (component.status == Component.Ready) { |
| 115 |
var quickSwitch = component.createObject(timelineRoot); |
| 116 |
quickSwitch.open(); |
| 117 |
destroyOnClosed(quickSwitch); |
| 118 |
} else { |
| 119 |
console.error("Failed to create component: " + component.errorString()); |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
Shortcut { |
| 124 |
// Add alternative shortcut, because sometimes Alt+A is stolen by the TextEdit |
| 125 |
sequences: ["Alt+A", "Ctrl+Shift+A"] |
| 126 |
|
| 127 |
onActivated: Rooms.nextRoomWithActivity() |
| 128 |
} |
| 129 |
Shortcut { |
| 130 |
sequences: ["Ctrl+Down", "Ctrl+PgDown"] |
| 131 |
|
| 132 |
onActivated: Rooms.nextRoom() |
| 133 |
} |
| 134 |
Shortcut { |
| 135 |
sequences: ["Ctrl+Up", "Ctrl+PgUp"] |
| 136 |
|
| 137 |
onActivated: Rooms.previousRoom() |
| 138 |
} |
| 139 |
Connections { |
| 140 |
function onOpenJoinRoomDialog() { |
| 141 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/JoinRoomDialog.qml"); |
| 142 |
if (component.status == Component.Ready) { |
| 143 |
var dialog = component.createObject(timelineRoot); |
| 144 |
dialog.show(); |
| 145 |
destroyOnClose(dialog); |
| 146 |
} else { |
| 147 |
console.error("Failed to create component: " + component.errorString()); |
| 148 |
} |
| 149 |
} |
| 150 |
function onOpenLogoutDialog() { |
| 151 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/LogoutDialog.qml"); |
| 152 |
if (component.status == Component.Ready) { |
| 153 |
var dialog = component.createObject(timelineRoot); |
| 154 |
dialog.open(); |
| 155 |
destroyOnClose(dialog); |
| 156 |
} else { |
| 157 |
console.error("Failed to create component: " + component.errorString()); |
| 158 |
} |
| 159 |
} |
| 160 |
function onShowRoomJoinPrompt(summary) { |
| 161 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ConfirmJoinRoomDialog.qml"); |
| 162 |
if (component.status == Component.Ready) { |
| 163 |
var dialog = component.createObject(timelineRoot, { |
| 164 |
"summary": summary |
| 165 |
}); |
| 166 |
dialog.show(); |
| 167 |
destroyOnClose(dialog); |
| 168 |
} else { |
| 169 |
console.error("Failed to create component: " + component.errorString()); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
target: Nheko |
| 174 |
} |
| 175 |
Connections { |
| 176 |
function onNewDeviceVerificationRequest(flow) { |
| 177 |
var component = Qt.createComponent("qrc:/resources/qml/device-verification/DeviceVerification.qml"); |
| 178 |
if (component.status == Component.Ready) { |
| 179 |
var dialog = component.createObject(timelineRoot, { |
| 180 |
"flow": flow |
| 181 |
}); |
| 182 |
dialog.show(); |
| 183 |
destroyOnClose(dialog); |
| 184 |
} else { |
| 185 |
console.error("Failed to create component: " + component.errorString()); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
target: VerificationManager |
| 190 |
} |
| 191 |
Connections { |
| 192 |
function onOpenInviteUsersDialog(invitees) { |
| 193 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/InviteDialog.qml"); |
| 194 |
if (component.status == Component.Ready) { |
| 195 |
var dialog = component.createObject(timelineRoot, { |
| 196 |
"invitees": invitees |
| 197 |
}); |
| 198 |
dialog.show(); |
| 199 |
destroyOnClose(dialog); |
| 200 |
} else { |
| 201 |
console.error("Failed to create component: " + component.errorString()); |
| 202 |
} |
| 203 |
} |
| 204 |
function onOpenLeaveRoomDialog(roomid, reason) { |
| 205 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/LeaveRoomDialog.qml"); |
| 206 |
if (component.status == Component.Ready) { |
| 207 |
var dialog = component.createObject(timelineRoot, { |
| 208 |
"roomId": roomid, |
| 209 |
"reason": reason |
| 210 |
}); |
| 211 |
dialog.open(); |
| 212 |
destroyOnClose(dialog); |
| 213 |
} else { |
| 214 |
console.error("Failed to create component: " + component.errorString()); |
| 215 |
} |
| 216 |
} |
| 217 |
function onOpenProfile(profile) { |
| 218 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/UserProfile.qml"); |
| 219 |
if (component.status == Component.Ready) { |
| 220 |
var userProfile = component.createObject(timelineRoot, { |
| 221 |
"profile": profile |
| 222 |
}); |
| 223 |
userProfile.show(); |
| 224 |
destroyOnClose(userProfile); |
| 225 |
} else { |
| 226 |
console.error("Failed to create component: " + component.errorString()); |
| 227 |
} |
| 228 |
} |
| 229 |
function onOpenRoomMembersDialog(members, room) { |
| 230 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/RoomMembers.qml"); |
| 231 |
if (component.status == Component.Ready) { |
| 232 |
var membersDialog = component.createObject(timelineRoot, { |
| 233 |
"members": members, |
| 234 |
"room": room |
| 235 |
}); |
| 236 |
membersDialog.show(); |
| 237 |
destroyOnClose(membersDialog); |
| 238 |
} else { |
| 239 |
console.error("Failed to create component: " + component.errorString()); |
| 240 |
} |
| 241 |
} |
| 242 |
function onOpenRoomSettingsDialog(settings) { |
| 243 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/RoomSettingsDialog.qml"); |
| 244 |
if (component.status == Component.Ready) { |
| 245 |
var roomSettings = component.createObject(timelineRoot, { |
| 246 |
"roomSettings": settings |
| 247 |
}); |
| 248 |
roomSettings.show(); |
| 249 |
destroyOnClose(roomSettings); |
| 250 |
} else { |
| 251 |
console.error("Failed to create component: " + component.errorString()); |
| 252 |
} |
| 253 |
} |
| 254 |
function onShowImageOverlay(room, eventId, url, originalWidth, proportionalHeight) { |
| 255 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ImageOverlay.qml"); |
| 256 |
if (component.status == Component.Ready) { |
| 257 |
var dialog = component.createObject(timelineRoot, { |
| 258 |
"room": room, |
| 259 |
"eventId": eventId, |
| 260 |
"url": url, |
| 261 |
"originalWidth": originalWidth ?? 0, |
| 262 |
"proportionalHeight": proportionalHeight ?? 0 |
| 263 |
}); |
| 264 |
dialog.showFullScreen(); |
| 265 |
destroyOnClose(dialog); |
| 266 |
} else { |
| 267 |
console.error("Failed to create component: " + component.errorString()); |
| 268 |
} |
| 269 |
} |
| 270 |
function onShowImagePackSettings(room, packlist) { |
| 271 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ImagePackSettingsDialog.qml"); |
| 272 |
if (component.status == Component.Ready) { |
| 273 |
var packSet = component.createObject(timelineRoot, { |
| 274 |
"room": room, |
| 275 |
"packlist": packlist |
| 276 |
}); |
| 277 |
packSet.show(); |
| 278 |
destroyOnClose(packSet); |
| 279 |
} else { |
| 280 |
console.error("Failed to create component: " + component.errorString()); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
target: TimelineManager |
| 285 |
} |
| 286 |
Connections { |
| 287 |
function onNewInviteState() { |
| 288 |
if (CallManager.haveCallInvite && Settings.mobileMode) { |
| 289 |
var component = Qt.createComponent("qrc:/resources/qml/voip/CallInvite.qml"); |
| 290 |
if (component.status == Component.Ready) { |
| 291 |
var dialog = component.createObject(timelineRoot); |
| 292 |
dialog.open(); |
| 293 |
destroyOnClose(dialog); |
| 294 |
} else { |
| 295 |
console.error("Failed to create component: " + component.errorString()); |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
target: CallManager |
| 301 |
} |
| 302 |
SelfVerificationCheck { |
| 303 |
} |
| 304 |
InputDialog { |
| 305 |
id: uiaPassPrompt |
| 306 |
|
| 307 |
echoMode: TextInput.Password |
| 308 |
prompt: qsTr("Please enter your login password to continue:") |
| 309 |
title: UIA.title |
| 310 |
|
| 311 |
onAccepted: t => { |
| 312 |
return UIA.continuePassword(t); |
| 313 |
} |
| 314 |
} |
| 315 |
InputDialog { |
| 316 |
id: uiaEmailPrompt |
| 317 |
|
| 318 |
prompt: qsTr("Please enter a valid email address to continue:") |
| 319 |
title: UIA.title |
| 320 |
|
| 321 |
onAccepted: t => { |
| 322 |
return UIA.continueEmail(t); |
| 323 |
} |
| 324 |
} |
| 325 |
PhoneNumberInputDialog { |
| 326 |
id: uiaPhoneNumberPrompt |
| 327 |
|
| 328 |
prompt: qsTr("Please enter a valid phone number to continue:") |
| 329 |
title: UIA.title |
| 330 |
|
| 331 |
onAccepted: (p, t) => { |
| 332 |
return UIA.continuePhoneNumber(p, t); |
| 333 |
} |
| 334 |
} |
| 335 |
InputDialog { |
| 336 |
id: uiaTokenPrompt |
| 337 |
|
| 338 |
prompt: qsTr("Please enter the token which has been sent to you:") |
| 339 |
title: UIA.title |
| 340 |
|
| 341 |
onAccepted: t => { |
| 342 |
return UIA.submit3pidToken(t); |
| 343 |
} |
| 344 |
} |
| 345 |
MessageDialog { |
| 346 |
id: uiaConfirmationLinkDialog |
| 347 |
|
| 348 |
buttons: MessageDialog.Ok |
| 349 |
text: qsTr("Wait for the confirmation link to arrive, then continue.") |
| 350 |
|
| 351 |
onAccepted: UIA.continue3pidReceived() |
| 352 |
} |
| 353 |
Connections { |
| 354 |
function onConfirm3pidToken() { |
| 355 |
uiaConfirmationLinkDialog.open(); |
| 356 |
} |
| 357 |
function onEmail() { |
| 358 |
uiaEmailPrompt.show(); |
| 359 |
} |
| 360 |
function onFallbackAuth(fallback) { |
| 361 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/FallbackAuthDialog.qml"); |
| 362 |
if (component.status == Component.Ready) { |
| 363 |
var dialog = component.createObject(timelineRoot, { |
| 364 |
"fallback": fallback |
| 365 |
}); |
| 366 |
dialog.show(); |
| 367 |
destroyOnClose(dialog); |
| 368 |
} else { |
| 369 |
console.error("Failed to create component: " + component.errorString()); |
| 370 |
} |
| 371 |
} |
| 372 |
function onPassword() { |
| 373 |
console.log("UIA: password needed"); |
| 374 |
uiaPassPrompt.show(); |
| 375 |
} |
| 376 |
function onPhoneNumber() { |
| 377 |
uiaPhoneNumberPrompt.show(); |
| 378 |
} |
| 379 |
function onPrompt3pidToken() { |
| 380 |
uiaTokenPrompt.show(); |
| 381 |
} |
| 382 |
function onReCaptcha(recaptcha) { |
| 383 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ReCaptchaDialog.qml"); |
| 384 |
if (component.status == Component.Ready) { |
| 385 |
var dialog = component.createObject(timelineRoot, { |
| 386 |
"recaptcha": recaptcha |
| 387 |
}); |
| 388 |
dialog.show(); |
| 389 |
destroyOnClose(dialog); |
| 390 |
} else { |
| 391 |
console.error("Failed to create component: " + component.errorString()); |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
target: UIA |
| 396 |
} |
| 397 |
StackView { |
| 398 |
id: mainWindow |
| 399 |
|
| 400 |
property Transition popEnterOrg |
| 401 |
property Transition popExitOrg |
| 402 |
|
| 403 |
// for some reason direct bindings to a hidden StackView don't work, so manually store and restore here. |
| 404 |
property Transition pushEnterOrg |
| 405 |
property Transition pushExitOrg |
| 406 |
property Transition replaceEnterOrg |
| 407 |
property Transition replaceExitOrg |
| 408 |
|
| 409 |
function updateTrans() { |
| 410 |
pushEnter = Settings.reducedMotion ? reducedMotionTransitionEnter : pushEnterOrg; |
| 411 |
pushExit = Settings.reducedMotion ? reducedMotionTransitionExit : pushExitOrg; |
| 412 |
popEnter = Settings.reducedMotion ? reducedMotionTransitionEnter : popEnterOrg; |
| 413 |
popExit = Settings.reducedMotion ? reducedMotionTransitionExit : popExitOrg; |
| 414 |
replaceEnter = Settings.reducedMotion ? reducedMotionTransitionEnter : replaceEnterOrg; |
| 415 |
replaceExit = Settings.reducedMotion ? reducedMotionTransitionExit : replaceExitOrg; |
| 416 |
} |
| 417 |
|
| 418 |
anchors.fill: parent |
| 419 |
initialItem: welcomePage |
| 420 |
|
| 421 |
Component.onCompleted: { |
| 422 |
pushEnterOrg = pushEnter; |
| 423 |
popEnterOrg = popEnter; |
| 424 |
replaceEnterOrg = replaceEnter; |
| 425 |
pushExitOrg = pushExit; |
| 426 |
popExitOrg = popExit; |
| 427 |
replaceExitOrg = replaceExit; |
| 428 |
updateTrans(); |
| 429 |
} |
| 430 |
|
| 431 |
Transition { |
| 432 |
id: reducedMotionTransitionExit |
| 433 |
|
| 434 |
PropertyAnimation { |
| 435 |
duration: 200 |
| 436 |
from: 1 |
| 437 |
property: "opacity" |
| 438 |
to: 0 |
| 439 |
} |
| 440 |
} |
| 441 |
Transition { |
| 442 |
id: reducedMotionTransitionEnter |
| 443 |
|
| 444 |
SequentialAnimation { |
| 445 |
PropertyAction { |
| 446 |
property: "opacity" |
| 447 |
value: 0 |
| 448 |
} |
| 449 |
PauseAnimation { |
| 450 |
duration: 200 |
| 451 |
} |
| 452 |
PropertyAnimation { |
| 453 |
duration: 200 |
| 454 |
from: 0 |
| 455 |
property: "opacity" |
| 456 |
to: 1 |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
Connections { |
| 461 |
function onReducedMotionChanged() { |
| 462 |
mainWindow.updateTrans(); |
| 463 |
} |
| 464 |
|
| 465 |
target: Settings |
| 466 |
} |
| 467 |
} |
| 468 |
Component { |
| 469 |
id: welcomePage |
| 470 |
|
| 471 |
WelcomePage { |
| 472 |
} |
| 473 |
} |
| 474 |
Component { |
| 475 |
id: chatPage |
| 476 |
|
| 477 |
ChatPage { |
| 478 |
} |
| 479 |
} |
| 480 |
Component { |
| 481 |
id: loginPage |
| 482 |
|
| 483 |
LoginPage { |
| 484 |
} |
| 485 |
} |
| 486 |
Component { |
| 487 |
id: registerPage |
| 488 |
|
| 489 |
RegisterPage { |
| 490 |
} |
| 491 |
} |
| 492 |
Component { |
| 493 |
id: userSettingsPage |
| 494 |
|
| 495 |
UserSettingsPage { |
| 496 |
} |
| 497 |
} |
| 498 |
Snackbar { |
| 499 |
id: snackbar |
| 500 |
|
| 501 |
} |
| 502 |
Connections { |
| 503 |
function onShowNotification(msg) { |
| 504 |
snackbar.showNotification(msg); |
| 505 |
console.log("New snack: " + msg); |
| 506 |
} |
| 507 |
function onSwitchToChatPage() { |
| 508 |
mainWindow.replace(null, chatPage); |
| 509 |
} |
| 510 |
function onSwitchToLoginPage(error) { |
| 511 |
mainWindow.replace(welcomePage, {}, loginPage, { |
| 512 |
"error": error |
| 513 |
}, StackView.PopTransition); |
| 514 |
} |
| 515 |
|
| 516 |
target: MainWindow |
| 517 |
} |
| 518 |
} |