Verified Commit b4f7e1fc authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Replace the kaidan context property by a singleton

parent 1801830b
Pipeline #14313 passed with stages
in 23 minutes and 21 seconds
......@@ -377,8 +377,10 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qmlRegisterSingletonType<QmlUtils>(APPLICATION_ID, 1, 0, "Utils", [](QQmlEngine *, QJSEngine *) {
return static_cast<QObject*>(QmlUtils::instance());
});
qmlRegisterSingletonType<Kaidan>(APPLICATION_ID, 1, 0, "Kaidan", [](QQmlEngine *, QJSEngine *) {
return static_cast<QObject*>(Kaidan::instance());
});
engine.rootContext()->setContextProperty("kaidan", &kaidan);
engine.load(QUrl("qrc:/qml/main.qml"));
if (engine.rootObjects().isEmpty())
return -1;
......
......@@ -69,43 +69,43 @@ ChatPageBase {
Kirigami.Action {
visible: true
icon.name: {
kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
Kaidan.notificationsMuted(Kaidan.messageModel.chatPartner)
? "player-volume"
: "audio-volume-muted-symbolic"
}
text: {
kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
Kaidan.notificationsMuted(Kaidan.messageModel.chatPartner)
? qsTr("Unmute notifications")
: qsTr("Mute notifications")
}
onTriggered: {
kaidan.setNotificationsMuted(
kaidan.messageModel.chatPartner,
!kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
Kaidan.setNotificationsMuted(
Kaidan.messageModel.chatPartner,
!Kaidan.notificationsMuted(Kaidan.messageModel.chatPartner)
)
}
function handleNotificationsMuted(jid) {
text = kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
text = Kaidan.notificationsMuted(Kaidan.messageModel.chatPartner)
? qsTr("Unmute notifications")
: qsTr("Mute notifications")
icon.name = kaidan.notificationsMuted(kaidan.messageModel.chatPartner)
icon.name = Kaidan.notificationsMuted(Kaidan.messageModel.chatPartner)
? "player-volume"
: "audio-volume-muted-symbolic"
}
Component.onCompleted: {
kaidan.notificationsMutedChanged.connect(handleNotificationsMuted)
Kaidan.notificationsMutedChanged.connect(handleNotificationsMuted)
}
Component.onDestruction: {
kaidan.notificationsMutedChanged.disconnect(handleNotificationsMuted)
Kaidan.notificationsMutedChanged.disconnect(handleNotificationsMuted)
}
},
Kirigami.Action {
visible: true
icon.name: "user-identity"
text: qsTr("View profile")
onTriggered: pageStack.push(userProfilePage, {jid: kaidan.messageModel.chatPartner, name: chatName})
onTriggered: pageStack.push(userProfilePage, {jid: Kaidan.messageModel.chatPartner, name: chatName})
},
Kirigami.Action {
readonly property int type: Enums.MessageType.MessageImage
......@@ -118,7 +118,7 @@ ChatPageBase {
}
onTriggered: {
sendMediaSheet.sendNewMessageType(kaidan.messageModel.chatPartner, type)
sendMediaSheet.sendNewMessageType(Kaidan.messageModel.chatPartner, type)
}
},
Kirigami.Action {
......@@ -131,7 +131,7 @@ ChatPageBase {
}
onTriggered: {
sendMediaSheet.sendNewMessageType(kaidan.messageModel.chatPartner, type)
sendMediaSheet.sendNewMessageType(Kaidan.messageModel.chatPartner, type)
}
},
Kirigami.Action {
......@@ -145,7 +145,7 @@ ChatPageBase {
}
onTriggered: {
sendMediaSheet.sendNewMessageType(kaidan.messageModel.chatPartner, type)
sendMediaSheet.sendNewMessageType(Kaidan.messageModel.chatPartner, type)
}
},
Kirigami.Action {
......@@ -158,7 +158,7 @@ ChatPageBase {
}
onTriggered: {
sendMediaSheet.sendNewMessageType(kaidan.messageModel.chatPartner, type)
sendMediaSheet.sendNewMessageType(Kaidan.messageModel.chatPartner, type)
}
},
Kirigami.Action {
......@@ -205,16 +205,16 @@ ChatPageBase {
if (searchBar.active && searchField.text.length > 0) {
if (searchUpwards) {
if (startIndex === 0) {
newIndex = kaidan.messageModel.searchForMessageFromNewToOld(searchField.text)
newIndex = Kaidan.messageModel.searchForMessageFromNewToOld(searchField.text)
} else {
newIndex = kaidan.messageModel.searchForMessageFromNewToOld(searchField.text, startIndex)
newIndex = Kaidan.messageModel.searchForMessageFromNewToOld(searchField.text, startIndex)
if (newIndex === -1)
newIndex = kaidan.messageModel.searchForMessageFromNewToOld(searchField.text, 0)
newIndex = Kaidan.messageModel.searchForMessageFromNewToOld(searchField.text, 0)
}
} else {
newIndex = kaidan.messageModel.searchForMessageFromOldToNew(searchField.text, startIndex)
newIndex = Kaidan.messageModel.searchForMessageFromOldToNew(searchField.text, startIndex)
if (newIndex === -1)
newIndex = kaidan.messageModel.searchForMessageFromOldToNew(searchField.text)
newIndex = Kaidan.messageModel.searchForMessageFromOldToNew(searchField.text)
}
}
messageListView.currentIndex = newIndex
......@@ -318,7 +318,7 @@ ChatPageBase {
FileChooser {
id: fileChooser
title: qsTr("Select a file")
onAccepted: sendMediaSheet.sendFile(kaidan.messageModel.chatPartner, fileUrl)
onAccepted: sendMediaSheet.sendFile(Kaidan.messageModel.chatPartner, fileUrl)
}
function openFileDialog(filterName, filter, title) {
......@@ -419,7 +419,7 @@ ChatPageBase {
currentIndex: -1
// Connect to the database,
model: kaidan.messageModel
model: Kaidan.messageModel
delegate: ChatMessage {
msgId: model.id
......@@ -481,7 +481,7 @@ ChatPageBase {
Controls.ToolButton {
id: attachButton
visible: kaidan.uploadServiceFound
visible: Kaidan.uploadServiceFound
Layout.preferredWidth: Kirigami.Units.gridUnit * 3
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
padding: 0
......@@ -632,15 +632,15 @@ ChatPageBase {
// send the message
if (messageField.state == "compose") {
kaidan.sendMessage(
kaidan.messageModel.chatPartner,
Kaidan.sendMessage(
Kaidan.messageModel.chatPartner,
messageField.text,
isWritingSpoiler,
spoilerHintField.text
)
} else if (messageField.state == "edit") {
kaidan.correctMessage(
kaidan.messageModel.chatPartner,
Kaidan.correctMessage(
Kaidan.messageModel.chatPartner,
messageToCorrect,
messageField.text
)
......
......@@ -40,7 +40,7 @@ import "settings"
Kirigami.GlobalDrawer {
id: globalDrawer
title: Utils.applicationDisplayName()
titleIcon: Utils.getResourcePath("images/kaidan.svg")
titleIcon: Utils.getResourcePath("images/Kaidan.svg")
bannerImageSource: Utils.getResourcePath("images/banner.png")
SettingsSheet {
......@@ -52,17 +52,17 @@ Kirigami.GlobalDrawer {
RowLayout {
spacing: -4
property bool disconnected: kaidan.connectionState === Enums.StateDisconnected
property bool connected: kaidan.connectionState === Enums.StateConnected
property bool disconnected: Kaidan.connectionState === Enums.StateDisconnected
property bool connected: Kaidan.connectionState === Enums.StateConnected
Controls.Switch {
checked: !parent.disconnected
onClicked: parent.disconnected ? kaidan.mainConnect() : kaidan.mainDisconnect()
onClicked: parent.disconnected ? Kaidan.mainConnect() : Kaidan.mainDisconnect()
}
Text {
text: {
var jidAndStatus = kaidan.jid + " ("
var jidAndStatus = Kaidan.jid + " ("
if (parent.disconnected)
jidAndStatus += qsTr("Offline");
......@@ -86,7 +86,7 @@ Kirigami.GlobalDrawer {
text: qsTr("Invite friends")
icon.name: "mail-invitation"
onTriggered: {
Utils.copyToClipboard(Utils.invitationUrl(kaidan.jid))
Utils.copyToClipboard(Utils.invitationUrl(Kaidan.jid))
passiveNotification(qsTr("Invitation link copied to clipboard"))
}
},
......@@ -96,7 +96,7 @@ Kirigami.GlobalDrawer {
onTriggered: {
popLayersAboveLowest()
// disconnect (open log in page)
kaidan.mainDisconnect(true)
Kaidan.mainDisconnect(true)
}
},
Kirigami.Action {
......
......@@ -92,7 +92,7 @@ Kirigami.Page {
id: connectButton
label.text: qsTr("Connect")
state: kaidan.connectionState !== Enums.StateDisconnected ? "connecting" : ""
state: Kaidan.connectionState !== Enums.StateDisconnected ? "connecting" : ""
states: [
State {
name: "connecting"
......@@ -116,9 +116,9 @@ Kirigami.Page {
} else if (!passwordField.valid) {
passwordField.forceFocus()
} else {
kaidan.jid = jidField.text
kaidan.password = passwordField.text
kaidan.mainConnect()
Kaidan.jid = jidField.text
Kaidan.password = passwordField.text
Kaidan.mainConnect()
}
}
}
......@@ -135,7 +135,7 @@ Kirigami.Page {
}
Connections {
target: kaidan
target: Kaidan
onConnectionErrorChanged: showPassiveNotificationForConnectionError()
}
......
......@@ -80,7 +80,7 @@ Kirigami.Page {
onScanningSucceeded: {
pageStack.layers.pop()
// login by the data from the decoded QR code
kaidan.loginByUri(result)
Kaidan.loginByUri(result)
}
onUnsupportedFormatReceived: {
pageStack.layers.pop()
......
......@@ -37,8 +37,8 @@ import "elements"
Kirigami.ScrollablePage {
title: {
kaidan.connectionState === Enums.StateConnecting ? qsTr("Connecting…") :
kaidan.connectionState === Enums.StateDisconnected ? qsTr("Offline") :
Kaidan.connectionState === Enums.StateConnecting ? qsTr("Connecting…") :
Kaidan.connectionState === Enums.StateDisconnected ? qsTr("Offline") :
qsTr("Contacts")
}
leftPadding: 0
......@@ -93,7 +93,7 @@ Kirigami.ScrollablePage {
verticalLayoutDirection: ListView.TopToBottom
model: RosterFilterProxyModel {
id: filterModel
sourceModel: kaidan.rosterModel
sourceModel: Kaidan.rosterModel
}
delegate: RosterListItem {
id: rosterItem
......@@ -101,13 +101,13 @@ Kirigami.ScrollablePage {
name: model.name ? model.name : model.jid
jid: model.jid
lastMessage: model.lastMessage
presenceType: kaidan.presenceCache.getPresenceType(model.jid)
statusMsg: kaidan.presenceCache.getStatusText(model.jid)
presenceType: Kaidan.presenceCache.getPresenceType(model.jid)
statusMsg: Kaidan.presenceCache.getStatusText(model.jid)
unreadMessages: model.unreadMessages
avatarImagePath: kaidan.avatarStorage.getAvatarUrl(model.jid)
avatarImagePath: Kaidan.avatarStorage.getAvatarUrl(model.jid)
backgroundColor: {
if (!Kirigami.Settings.isMobile &&
kaidan.messageModel.chatPartner === model.jid) {
Kaidan.messageModel.chatPartner === model.jid) {
Kirigami.Theme.highlightColor
} else {
Kirigami.Theme.backgroundColor
......@@ -120,7 +120,7 @@ Kirigami.ScrollablePage {
// will then remove this item and readd an updated version of it, so
// model.* won't work anymore after this.
var chatName = model.name ? model.name : model.jid
kaidan.messageModel.chatPartner = model.jid
Kaidan.messageModel.chatPartner = model.jid
pageStack.push(chatPage, {
"chatName": chatName
})
......@@ -128,8 +128,8 @@ Kirigami.ScrollablePage {
function newPresenceArrived(jid) {
if (jid === model.jid) {
rosterItem.presenceType = kaidan.presenceCache.getPresenceType(model.jid)
rosterItem.statusMsg = kaidan.presenceCache.getStatusText(model.jid)
rosterItem.presenceType = Kaidan.presenceCache.getPresenceType(model.jid)
rosterItem.statusMsg = Kaidan.presenceCache.getStatusText(model.jid)
}
}
......@@ -140,12 +140,12 @@ Kirigami.ScrollablePage {
}
Component.onCompleted: {
kaidan.presenceCache.presenceChanged.connect(newPresenceArrived)
kaidan.xmppUriReceived.connect(xmppUriReceived)
Kaidan.presenceCache.presenceChanged.connect(newPresenceArrived)
Kaidan.xmppUriReceived.connect(xmppUriReceived)
}
Component.onDestruction: {
kaidan.presenceCache.presenceChanged.disconnect(newPresenceArrived)
kaidan.xmppUriReceived.disconnect(xmppUriReceived)
Kaidan.presenceCache.presenceChanged.disconnect(newPresenceArrived)
Kaidan.xmppUriReceived.disconnect(xmppUriReceived)
}
}
}
......
......@@ -47,8 +47,8 @@ Kirigami.Page {
property string jid
property string name
property int presenceType: kaidan.presenceCache.getPresenceType(jid)
property string statusMessage: kaidan.presenceCache.getStatusText(jid)
property int presenceType: Kaidan.presenceCache.getPresenceType(jid)
property string statusMessage: Kaidan.presenceCache.getStatusText(jid)
Timer {
id: pageTimer
......@@ -124,7 +124,7 @@ Kirigami.Page {
Layout.preferredHeight: Kirigami.Units.gridUnit * 10
Layout.preferredWidth: Kirigami.Units.gridUnit * 10
name: root.name
avatarUrl: kaidan.avatarStorage.getAvatarUrl(jid)
avatarUrl: Kaidan.avatarStorage.getAvatarUrl(jid)
}
ColumnLayout {
......@@ -201,15 +201,15 @@ Kirigami.Page {
function newPresenceArrived(jid) {
if (jid === root.jid) {
presenceType = kaidan.presenceCache.getPresenceType(root.jid);
statusMessage = kaidan.presenceCache.getStatusText(root.jid);
presenceType = Kaidan.presenceCache.getPresenceType(root.jid);
statusMessage = Kaidan.presenceCache.getStatusText(root.jid);
}
}
Component.onCompleted: {
kaidan.presenceCache.presenceChanged.connect(newPresenceArrived);
Kaidan.presenceCache.presenceChanged.connect(newPresenceArrived);
}
Component.onDestruction: {
kaidan.presenceCache.presenceChanged.disconnect(newPresenceArrived);
Kaidan.presenceCache.presenceChanged.disconnect(newPresenceArrived);
}
}
......@@ -50,11 +50,11 @@ RowLayout {
property string mediaGetUrl
property string mediaLocation
property bool edited
property bool isLoading: kaidan.transferCache.hasUpload(msgId)
property bool isLoading: Kaidan.transferCache.hasUpload(msgId)
property string name
property TransferJob upload: {
if (mediaType !== Enums.MessageType.MessageText && isLoading) {
return kaidan.transferCache.jobByMessageId(model.id)
return Kaidan.transferCache.jobByMessageId(model.id)
}
return null
......@@ -62,7 +62,7 @@ RowLayout {
property bool isSpoiler
property string spoilerHint
property bool isShowingSpoiler: false
property string avatarUrl: kaidan.avatarStorage.getAvatarUrl(sender)
property string avatarUrl: Kaidan.avatarStorage.getAvatarUrl(sender)
signal messageEditRequested(string id, string body)
signal quoteRequested(string body)
......@@ -135,7 +135,7 @@ RowLayout {
Controls.MenuItem {
text: qsTr("Edit Message")
enabled: kaidan.messageModel.canCorrectMessage(msgId)
enabled: Kaidan.messageModel.canCorrectMessage(msgId)
onTriggered: root.messageEditRequested(msgId, messageBody)
}
......@@ -224,7 +224,7 @@ RowLayout {
text: qsTr("Download")
onClicked: {
print("Downloading " + mediaGetUrl + "...")
kaidan.downloadMedia(msgId, mediaGetUrl)
Kaidan.downloadMedia(msgId, mediaGetUrl)
}
}
......@@ -325,13 +325,13 @@ RowLayout {
}
function updateIsLoading() {
isLoading = kaidan.transferCache.hasUpload(msgId)
isLoading = Kaidan.transferCache.hasUpload(msgId)
}
Component.onCompleted: {
kaidan.transferCache.jobsChanged.connect(updateIsLoading)
Kaidan.transferCache.jobsChanged.connect(updateIsLoading)
}
Component.onDestruction: {
kaidan.transferCache.jobsChanged.disconnect(updateIsLoading)
Kaidan.transferCache.jobsChanged.disconnect(updateIsLoading)
}
}
......@@ -109,7 +109,7 @@ Kirigami.OverlaySheet {
jidField.text.slice(-1) !== "@" // last character is no '@'
}
onClicked: {
kaidan.addContact(jidField.text.toLowerCase(),
Kaidan.addContact(jidField.text.toLowerCase(),
nickField.text, msgField.text)
clearInput()
close()
......
......@@ -103,7 +103,7 @@ Kirigami.SwipeListItem {
source: "audio-volume-muted-symbolic"
width: 16
height: 16
visible: kaidan.notificationsMuted(jid)
visible: Kaidan.notificationsMuted(jid)
}
Item {
Layout.fillWidth: true
......@@ -133,7 +133,7 @@ Kirigami.SwipeListItem {
id: counter
visible: unreadMessages > 0
counter: unreadMessages
muted: kaidan.notificationsMuted(jid)
muted: Kaidan.notificationsMuted(jid)
Layout.preferredHeight: Kirigami.Units.gridUnit * 1.25
Layout.preferredWidth: Kirigami.Units.gridUnit * 1.25
......@@ -141,14 +141,14 @@ Kirigami.SwipeListItem {
}
function handleNotificationsMuted(mutedContact) {
counter.muted = kaidan.notificationsMuted(jid)
muteIcon.visible = kaidan.notificationsMuted(jid)
counter.muted = Kaidan.notificationsMuted(jid)
muteIcon.visible = Kaidan.notificationsMuted(jid)
}
Component.onCompleted: {
kaidan.notificationsMutedChanged.connect(handleNotificationsMuted)
Kaidan.notificationsMutedChanged.connect(handleNotificationsMuted)
}
Component.onDestruction: {
kaidan.notificationsMutedChanged.disconnect(handleNotificationsMuted)
Kaidan.notificationsMutedChanged.disconnect(handleNotificationsMuted)
}
}
......@@ -70,7 +70,7 @@ Kirigami.OverlaySheet {
Button {
text: qsTr("Delete")
onClicked: {
kaidan.removeContact(jid)
Kaidan.removeContact(jid)
close()
}
Layout.fillWidth: true
......
......@@ -67,7 +67,7 @@ Kirigami.OverlaySheet {
id: addButton
text: qsTr("Rename")
onClicked: {
kaidan.renameContact(jid, nickField.text);
Kaidan.renameContact(jid, nickField.text);
close();
}
Layout.fillWidth: true
......
......@@ -143,10 +143,10 @@ Kirigami.OverlaySheet {
case Enums.MessageType.MessageVideo:
case Enums.MessageType.MessageFile:
case Enums.MessageType.MessageDocument:
kaidan.sendFile(root.targetJid, root.source, descField.text)
Kaidan.sendFile(root.targetJid, root.source, descField.text)
break
case Enums.MessageType.MessageGeoLocation:
kaidan.sendMessage(root.targetJid, root.source, false, '')
Kaidan.sendMessage(root.targetJid, root.source, false, '')
break
}
......
......@@ -60,7 +60,7 @@ Kirigami.OverlaySheet {
Layout.fillWidth: true
text: qsTr("Decline")
onClicked: {
kaidan.subscriptionRequestAnswered(from, false)
Kaidan.subscriptionRequestAnswered(from, false)
close()
}
}
......@@ -69,7 +69,7 @@ Kirigami.OverlaySheet {
Layout.fillWidth: true
text: qsTr("Accept")
onClicked: {
kaidan.subscriptionRequestAnswered(from, true)
Kaidan.subscriptionRequestAnswered(from, true)
close()
}
}
......
......@@ -70,7 +70,7 @@ Kirigami.ApplicationWindow {
// when the window was closed, disconnect from jabber server
onClosing: {
kaidan.mainDisconnect()
Kaidan.mainDisconnect()
}
// load all pages
......@@ -90,7 +90,7 @@ Kirigami.ApplicationWindow {
}
function showPassiveNotificationForConnectionError() {
passiveNotification(Utils.connectionErrorMessage(kaidan.connectionError))
passiveNotification(Utils.connectionErrorMessage(Kaidan.connectionError))
}
function openLoginPage() {
......@@ -131,7 +131,7 @@ Kirigami.ApplicationWindow {
}
function handleSubRequest(from, message) {
kaidan.vCardRequested(from)
Kaidan.vCardRequested(from)
subReqAcceptSheet.from = from
subReqAcceptSheet.message = message
......@@ -140,21 +140,21 @@ Kirigami.ApplicationWindow {
}
Component.onCompleted: {
kaidan.passiveNotificationRequested.connect(passiveNotification)
kaidan.newCredentialsNeeded.connect(openLoginPage)
kaidan.logInWorked.connect(openChatView)
kaidan.subscriptionRequestReceived.connect(handleSubRequest)
Kaidan.passiveNotificationRequested.connect(passiveNotification)
Kaidan.newCredentialsNeeded.connect(openLoginPage)
Kaidan.logInWorked.connect(openChatView)
Kaidan.subscriptionRequestReceived.connect(handleSubRequest)
openChatView()
// Announce that the user interface is ready and the application can start connecting.
kaidan.start()
Kaidan.start()
}
Component.onDestruction: {
kaidan.passiveNotificationRequested.disconnect(passiveNotification)
kaidan.newCredentialsNeeded.disconnect(openLoginPage)
kaidan.logInWorked.disconnect(openChatView)
kaidan.subscriptionRequestReceived.disconnect(handleSubRequest)
Kaidan.passiveNotificationRequested.disconnect(passiveNotification)
Kaidan.newCredentialsNeeded.disconnect(openLoginPage)
Kaidan.logInWorked.disconnect(openChatView)
Kaidan.subscriptionRequestReceived.disconnect(handleSubRequest)
}
}
......@@ -100,7 +100,7 @@ Kirigami.Page {
}
Kirigami.InlineMessage {
visible: kaidan.connectionState !== Enums.StateConnected
visible: Kaidan.connectionState !== Enums.StateConnected
type: Kirigami.MessageType.Error
text: qsTr("You need to be connected to change your password.")
anchors.left: parent.left
......@@ -130,15 +130,15 @@ Kirigami.Page {
Layout.fillWidth: true
enabled: {
password1.text === password2.text && password1.text !== ""
&& kaidan.connectionState === Enums.StateConnected
&& Kaidan.connectionState === Enums.StateConnected
}
onClicked: {
if (oldPassword.text !== kaidan.password) {
if (oldPassword.text !== Kaidan.password) {
currentPasswordInvalidMessage.visible = true
return
}
kaidan.changePassword(password1.text)
Kaidan.changePassword(password1.text)
content.visible = false
busyIndicator.visible = true
}
......@@ -152,11 +152,11 @@ Kirigami.Page {
}
Component.onCompleted: {
kaidan.passwordChangeSucceeded.connect(handleChangeResult)
kaidan.passwordChangeFailed.connect(handleChangeResult)
Kaidan.passwordChangeSucceeded.connect(handleChangeResult)
Kaidan.passwordChangeFailed.connect(handleChangeResult)
}
Component.onDestruction: {
kaidan.passwordChangeSucceeded.disconnect(handleChangeResult)
kaidan.passwordChangeFailed.disconnect(handleChangeResult)
Kaidan.passwordChangeSucceeded.disconnect(handleChangeResult)
Kaidan.passwordChangeFailed.disconnect(handleChangeResult)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment