Warning, /frameworks/kpeople/examples/qml/Main.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.1
0002 import QtQuick.Controls 1.1
0003 import QtQuick.Layouts 1.1
0004 import org.kde.people 1.0
0005 import org.kde.plasma.components 2.0
0006 import org.kde.plasma.core 2.0 as Core
0007 import org.kde.plasma.extras 2.0
0008 import org.kde.kquickcontrolsaddons 2.0
0009
0010 ApplicationWindow {
0011 width: 640
0012 height: 480
0013 visible: true
0014
0015 Core.SortFilterModel {
0016 id: filteredPeople
0017 sortRole: "display"
0018 sortCaseSensitivity: Qt.CaseInsensitive
0019 sourceModel: PersonsModel {
0020 id: people
0021 }
0022 filterRegExp: searchField.text
0023 }
0024
0025 CheckBox {
0026 id: areWeMerging
0027 anchors {
0028 top: parent.top
0029 left: parent.left
0030 }
0031 text: "Merging"
0032 onCheckedChanged: toMergeItems.clear()
0033 }
0034
0035 TextField {
0036 id: searchField
0037 focus: true
0038 anchors {
0039 left: areWeMerging.right
0040 right: mergeLabel.left
0041 }
0042 }
0043
0044 Label {
0045 id: mergeLabel
0046 anchors {
0047 top: parent.top
0048 right: view.right
0049 }
0050
0051 ListModel {
0052 id: toMergeItems
0053
0054 function uriIndex(uri) {
0055 var ret = -1
0056 for (var i = 0; i < count && ret < 0; ++i) {
0057 if (get(i).uri == uri)
0058 ret = i;
0059 }
0060 return ret
0061 }
0062
0063 function addUri(uri, name) {
0064 if (uriIndex(uri) < 0)
0065 toMergeItems.append({ "uri": uri, "name": name })
0066 }
0067
0068 function indexes() {
0069 var ret = new Array
0070 for(var i=0; i<count; ++i) {
0071 ret.push(get(i).uri)
0072 }
0073 return people.indexesForUris(ret)
0074 }
0075
0076 function removeUri(uri) {
0077 remove(uriIndex(uri))
0078 }
0079 }
0080 }
0081
0082 GridView {
0083 id: view
0084 clip: true
0085 anchors {
0086 top: searchField.bottom
0087 bottom: parent.bottom
0088 left: parent.left
0089 right: contactItem.left
0090 }
0091
0092 cellWidth: 100
0093 cellHeight: 100
0094 model: filteredPeople
0095 delegate: ListItem {
0096 height: view.cellHeight
0097 width: view.cellWidth - 5
0098
0099 clip: true
0100 enabled: true
0101
0102 ColumnLayout {
0103 anchors.fill: parent
0104
0105 Core.IconItem {
0106 id: avatar
0107 Layout.fillWidth: true
0108 Layout.fillHeight: true
0109
0110 source: decoration
0111 }
0112 Label {
0113 width: parent.width
0114 text: display
0115 wrapMode: Text.WrapAnywhere
0116 elide: Text.ElideMiddle
0117 visible: avatar.status!=Image.Ready
0118 }
0119 }
0120
0121 onClicked: {
0122 contactItem.contactData = model
0123 personActions.personUri = model.personUri
0124
0125 if (areWeMerging.checked) {
0126 toMergeItems.addUri(model.personUri, model.display)
0127 }
0128 }
0129 }
0130 }
0131
0132 Flickable {
0133 id: contactItem
0134 anchors {
0135 top: parent.top
0136 right: parent.right
0137 bottom: parent.bottom
0138 }
0139 width: parent.width/2
0140 property variant contactData
0141
0142 ColumnLayout {
0143 width: parent.width
0144 spacing: 5
0145
0146 Column {
0147 Layout.fillWidth: true
0148 visible: toMergeItems.count > 0
0149
0150 Label {
0151 text: "Contacts To Merge:"
0152 }
0153
0154 Repeater {
0155 model: toMergeItems
0156 delegate: Label {
0157 width: parent.width
0158 text: name + " - " + uri
0159 }
0160 }
0161
0162 Button {
0163 text: "Merge!"
0164 onClicked: {
0165 people.createPersonFromIndexes(toMergeItems.indexes())
0166 toMergeItems.clear()
0167 }
0168 }
0169
0170 Rectangle {
0171 width: parent.width
0172 height: 1
0173 color: "#888"
0174 }
0175 }
0176
0177
0178 RowLayout {
0179 Core.IconItem {
0180 id: avatar
0181 height: 64
0182 width: height
0183 source: contactItem.contactData ? contactItem.contactData.decoration : null
0184 }
0185
0186 Label {
0187 text: contactItem.contactData ? contactItem.contactData.display : ""
0188 }
0189 }
0190
0191 Label {
0192 id: contactText
0193 width: parent.width
0194 text: dataToString(contactItem.contactData)
0195
0196 function dataToString(data) {
0197 var text = ""
0198 if (data != null) {
0199 for (var prop in data) {
0200 text += prop + ": ";
0201 var currentData = data[prop]
0202 text += currentData == null ? "null" : currentData
0203 text += '\n'
0204 }
0205 }
0206
0207 return text
0208 }
0209 }
0210
0211 Flow {
0212 Layout.fillWidth: true
0213 Layout.fillHeight: true
0214
0215 Repeater {
0216 width: parent.width
0217 model: PersonActions {
0218 id: personActions
0219 }
0220 delegate: Button {
0221 text: model.display
0222 iconSource: model.iconName
0223 onClicked: personActions.triggerAction(model.index)
0224 }
0225 }
0226 }
0227
0228 Button {
0229 text: "Unmerge"
0230 visible: contactItem.contactData!=null && contactItem.contactData.contactsCount>1
0231 onClicked: {
0232 dialogLoader.sourceComponent = unmergeDialogComponent
0233 dialogLoader.item.open()
0234 }
0235 Loader {
0236 id: dialogLoader
0237 }
0238 }
0239 }
0240 }
0241
0242 Component {
0243 id: unmergeDialogComponent
0244 CommonDialog {
0245 id: unmergeDialog
0246 property string name: contactItem.contactData.name
0247 property int index: filteredPeople.mapRowToSource(contactItem.contactData.index)
0248 property url uri: contactItem.contactData.uri
0249
0250 buttonTexts: ["Unmerge", "Cancel"]
0251 titleText: i18n("Unmerging %1", unmergeDialog.name)
0252 content: Column {
0253 width: 500
0254 height: 200
0255 Repeater {
0256 id: unmergesView
0257 model: ColumnProxyModel {
0258 rootIndex: indexFromModel(people, unmergeDialog.index)
0259 }
0260 delegate: ListItem {
0261 property alias checked: willUnmerge.checked
0262 property string contactUri: uri
0263 enabled: true
0264 onClicked: willUnmerge.checked=!willUnmerge.checked
0265 Row {
0266 spacing: 5
0267 CheckBox { id: willUnmerge }
0268 Label { text: display+" - "+contactUri }
0269 }
0270 }
0271 }
0272 }
0273 onButtonClicked: if(index==0) {
0274 for(var i=0; i<unmergesView.count; ++i) {
0275 var item = unmergesView.itemAt(i)
0276 if(item.checked)
0277 people.unmerge(item.contactUri, uri)
0278 }
0279 }
0280 }
0281 }
0282 }