• Skip to content
  • Skip to link menu
KDE API Documentation - Main.qml Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • examples
  • qml
Main.qml
1 import QtQuick 2.1
2 import org.kde.people 1.0
3 import org.kde.plasma.components 2.0
4 import org.kde.plasma.core 2.0 as Core
5 import org.kde.plasma.extras 2.0
6 import org.kde.kquickcontrolsaddons 2.0
7 
8 Rectangle {
9  width: 300
10  height: 300
11  color: "red"
12 
13  Core.SortFilterModel {
14  id: filteredPeople
15  sortRole: "display"
16  sortCaseSensitivity: Qt.CaseInsensitive
17  sourceModel: PersonsModel {
18  id: people
19  }
20  filterRegExp: searchField.text
21  }
22 
23  CheckBox {
24  id: areWeMerging
25  anchors {
26  top: parent.top
27  left: parent.left
28  }
29  text: "Merging"
30  onCheckedChanged: toMergeItems.clear()
31  }
32 
33  TextField {
34  id: searchField
35  focus: true
36  anchors {
37  left: areWeMerging.right
38  right: mergeLabel.left
39  }
40  }
41 
42  Label {
43  id: mergeLabel
44  anchors {
45  top: parent.top
46  right: view.right
47  }
48  ListModel {
49  id: toMergeItems
50 
51  function uriIndex(uri) {
52  var ret = -1
53  for(var i=0; i<count && ret<0; ++i) {
54  if(get(i).uri==uri)
55  ret=i
56  }
57  return ret
58  }
59 
60  function addUri(uri, name) {
61  if(uriIndex(uri)<0)
62  toMergeItems.append({ "uri": uri, "name": name })
63  }
64 
65  function indexes() {
66  var ret = new Array
67  for(var i=0; i<count; ++i) {
68  ret.push(get(i).uri)
69  }
70  return people.indexesForUris(ret)
71  }
72 
73  function removeUri(uri) {
74  remove(uriIndex(uri))
75  }
76  }
77  }
78 
79  GridView {
80  id: view
81  clip: true
82  anchors {
83  top: searchField.bottom
84  bottom: parent.bottom
85  left: parent.left
86  right: contactItem.left
87  }
88 
89  cellWidth: 100
90  cellHeight: 100
91  model: filteredPeople
92  delegate: ListItem {
93  clip: true
94  height: view.cellHeight
95  width: view.cellWidth-5
96  Core.IconItem {
97  id: avatar
98  source: decoration
99  anchors.fill: parent
100  }
101  Label {
102  width: parent.width
103  height: parent.height
104  text: display
105  wrapMode: Text.WrapAnywhere
106  visible: avatar.status!=Image.Ready
107  }
108  enabled: true
109  onClicked: {
110  contactItem.contactData = model
111  personActions.personUri = model.personUri
112  if(areWeMerging.checked)
113  toMergeItems.addUri(model.personUri, model.display)
114  }
115  }
116  }
117 
118  Flickable {
119  id: contactItem
120  anchors {
121  top: parent.top
122  right: parent.right
123  bottom: parent.bottom
124  }
125  width: parent.width/2
126  property variant contactData
127 
128  Column {
129  width: parent.width
130  spacing: 5
131  Column {
132  visible: toMergeItems.count>0
133  Label { text: "To Merge:" }
134  Repeater {
135  model:toMergeItems
136  delegate: Label { text: name + " - " + uri }
137  }
138  Button {
139  text: "Merge!"
140  onClicked: {
141  people.createPersonFromIndexes(toMergeItems.indexes())
142  toMergeItems.clear()
143  }
144  }
145  }
146 
147  Label {
148  id: contactText
149  width: parent.width
150  text: dataToString(contactItem.contactData)
151 
152  function dataToString(data) {
153  var text = ""
154  if(data==null)
155  return "<null>";
156  else for(var a in data) {
157  text += a + ": ";
158  var curr = data[a]
159  if(curr==null)
160  text += "null"
161  else
162  text += curr
163  text += '\n'
164  }
165  return text
166  }
167  }
168  ToolBar {
169  width: parent.width
170  height: 30
171  Flow {
172  anchors.fill: parent
173  Repeater {
174  model: PersonActions {
175  id: personActions
176  }
177  delegate: Button {
178  text: model.display
179  iconSource: model.decoration
180  onClicked: personActions.triggerAction(model.index)
181  }
182  }
183  }
184  }
185  Rectangle { color: "green"; width: parent.width; height: 5 }
186  Row {
187  Repeater {
188  model: contactItem.contactData ? contactItem.contactData.photo : null
189  delegate: Image {
190  source: modelData
191  }
192  }
193  }
194  Rectangle { color: "blue"; width: parent.width; height: 5}
195  Button {
196  text: "Unmerge"
197  visible: contactItem.contactData!=null && contactItem.contactData.contactsCount>1
198  onClicked: {
199  dialogLoader.sourceComponent = unmergeDialogComponent
200  dialogLoader.item.open()
201  }
202  Loader {
203  id: dialogLoader
204  }
205  }
206  }
207  }
208 
209  Component {
210  id: unmergeDialogComponent
211  CommonDialog {
212  id: unmergeDialog
213  property string name: contactItem.contactData.name
214  property int index: filteredPeople.mapRowToSource(contactItem.contactData.index)
215  property url uri: contactItem.contactData.uri
216 
217  buttonTexts: ["Unmerge", "Cancel"]
218  titleText: i18n("Unmerging %1", unmergeDialog.name)
219  content: Column {
220  width: 500
221  height: 200
222  Repeater {
223  id: unmergesView
224  model: ColumnProxyModel {
225  rootIndex: indexFromModel(people, unmergeDialog.index)
226  }
227  delegate: ListItem {
228  property alias checked: willUnmerge.checked
229  property string contactUri: uri
230  enabled: true
231  onClicked: willUnmerge.checked=!willUnmerge.checked
232  Row {
233  spacing: 5
234  CheckBox { id: willUnmerge }
235  Label { text: display+" - "+contactUri }
236  }
237  }
238  }
239  }
240  onButtonClicked: if(index==0) {
241  for(var i=0; i<unmergesView.count; ++i) {
242  var item = unmergesView.itemAt(i)
243  if(item.checked)
244  people.unmerge(item.contactUri, uri)
245  }
246  }
247  }
248  }
249 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

Skip menu "KPeople"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal