RosterPage.qml 2.86 KB
Newer Older
1
/*
2
 *  Kaidan - A user-friendly XMPP client for every device!
3
 *
4
 *  Copyright (C) 2016-2017 LNJ <git@lnj.li>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *  Copyright (C) 2016 Marzanna
 *
 *  Kaidan is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Kaidan is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
 */

Linus Jahn's avatar
Linus Jahn committed
21
import QtQuick 2.0
22
import QtQuick.Layouts 1.3
Jonah Brüchert's avatar
Jonah Brüchert committed
23
import org.kde.kirigami 2.0 as Kirigami
Linus Jahn's avatar
Linus Jahn committed
24
import io.github.kaidanim 1.0
Marzanna's avatar
Marzanna committed
25

Linus Jahn's avatar
Linus Jahn committed
26
Kirigami.ScrollablePage {
27
	title: qsTr("Contacts")
Linus Jahn's avatar
Linus Jahn committed
28

29 30 31
	RosterAddContactSheet {
		id: addContactSheet
	}
32 33 34 35
	RosterRemoveContactSheet {
		id: removeContactSheet
		jid: ""
	}
36

Marzanna's avatar
Marzanna committed
37
	ListView {
Linus Jahn's avatar
Linus Jahn committed
38 39
		verticalLayoutDirection: ListView.TopToBottom

40
		model: kaidan.rosterController.rosterModel
41

Jonah Brüchert's avatar
Jonah Brüchert committed
42
		delegate: Kirigami.SwipeListItem {
43
			id: listItem
Jonah Brüchert's avatar
Jonah Brüchert committed
44 45
			height: Kirigami.Units.gridUnit * 2.5

46 47 48 49 50 51 52 53 54 55 56 57 58 59
			RowLayout {
				Kirigami.Label {
					Layout.fillWidth: true
					// use the Name or JID
					text: model.name ? model.name : model.jid
				}

				Rectangle {
					id: counterCircle
					visible: model.unreadMessages > 0
					Layout.preferredHeight: Kirigami.Units.gridUnit * 1.25
					Layout.preferredWidth: Kirigami.Units.gridUnit * 1.25
					radius: counterCircle.height * 0.5
					color: "#4CAF50"
60

61 62 63 64 65 66 67 68 69 70 71 72 73
					Text {
						id: msgCounter
						text: model.unreadMessages
						color: "white"
						anchors.centerIn: parent
					}
				}

				// placeholder
				Item {
					width: Kirigami.Units.gridUnit * 2
				}
			}
74

75 76
			onClicked: {
				// first push the chat page
77
				pageStack.push(chatPage, {
78 79 80
					"chatName": (model.name ? model.name : model.jid),
					"recipientJid": model.jid
				});
81 82 83 84 85

				// then set the message filter for this jid
				// this will update the unread message count,
				// which will update the roster and will reset the
				// model variable
Linus Jahn's avatar
Linus Jahn committed
86
				kaidan.chatPartner = model.jid;
87 88
			}

Jonah Brüchert's avatar
Jonah Brüchert committed
89
			actions: [
90 91 92
				Kirigami.Action {
					iconName: "bookmark-remove"
					onTriggered: {
93 94
						removeContactSheet.jid = model.jid;
						removeContactSheet.open();
Jonah Brüchert's avatar
Jonah Brüchert committed
95 96 97
					}
				}
			]
Marzanna's avatar
Marzanna committed
98 99
		}
	}
100 101 102 103 104 105 106 107 108 109 110

	Component.onCompleted: {
		function openAddContactSheet() { addContactSheet.open(); }
		function disconnectOpenAddContactSheet() {
			addContactDialogRequested.disconnect(openAddContactSheet);
		}
		// open sheet when requested from drawer over signal
		addContactDialogRequested.connect(openAddContactSheet);
		// disconnect the open function, when the roster page is closed
		connectionStateDisconnected.connect(disconnectOpenAddContactSheet);
	}
Marzanna's avatar
Marzanna committed
111
}