~renatofilho/address-book-app/fix-1417341-rtm

« back to all changes in this revision

Viewing changes to examples/contenthub.qml

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2013-12-10 22:59:10 UTC
  • mto: This revision was merged to the branch mainline in revision 115.
  • Revision ID: renato.filho@canonical.com-20131210225910-r3rdpp5rm5scs5ys
Added example of use conent hub to import a vcard.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 0.1
 
3
import Ubuntu.Content 0.1
 
4
 
 
5
 
 
6
Rectangle {
 
7
  id: root
 
8
  height: 500
 
9
  width: 500
 
10
  Row {
 
11
      id: buttons
 
12
      anchors {
 
13
        left: parent.left
 
14
        right: parent.right
 
15
        top: parent.top
 
16
      }
 
17
      Button {
 
18
          text: "Import from default"
 
19
           onClicked: {
 
20
               var peer = ContentHub.defaultSourceForType(ContentType.Contacts);
 
21
               activeTransfer = ContentHub.importContent(ContentType.Contact, peer);
 
22
          }
 
23
      }
 
24
      Button {
 
25
          text: "Import from a selectable list"
 
26
           onClicked: {
 
27
               activeTransfer = ContentHub.importContent(ContentType.Contacts);
 
28
               activeTransfer.selectionType = ContentTransfer.Multiple;
 
29
               activeTransfer.start();
 
30
          }
 
31
      }
 
32
  }
 
33
  TextArea {
 
34
    id: textArea
 
35
    anchors {
 
36
        left: parent.left
 
37
        right: parent.right
 
38
        top: buttons.bottom
 
39
        bottom: parent.bottom
 
40
    }
 
41
  }
 
42
  ContentImportHint {
 
43
      id: importHint
 
44
      anchors.fill: parent
 
45
      activeTransfer: root.activeTransfer
 
46
  }
 
47
  property var activeTransfer
 
48
  Connections {
 
49
      target: root.activeTransfer ? root.activeTransfer : null
 
50
      onStateChanged: {
 
51
          if (root.activeTransfer.state === ContentTransfer.Charged) {
 
52
              var fileName = root.activeTransfer.items[0]
 
53
              fh = fopen(fileName, 0)
 
54
              if(fh!=-1) {
 
55
                length = flength(fh)
 
56
                var str = fread(fh, length)
 
57
                fclose(fh)
 
58
                console.debug("VCARD FILE: " + str)
 
59
                textArea.text = str
 
60
              } else {
 
61
                console.debug("Fail to open file:" + fileName)
 
62
                textArea.text = "Fail to open file:" + fileName
 
63
              }
 
64
          }
 
65
      }
 
66
  }
 
67
}