~qqworini/aesydict/online-improve

« back to all changes in this revision

Viewing changes to app/dict/ContentHubPicker.qml

  • Committer: Joey Chan
  • Date: 2015-04-10 14:38:56 UTC
  • Revision ID: qqworini@gmail.com-20150410143856-f6y58wmgno21agim
search functions now initially works

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    property var activeTransfer
18
18
    property list<ContentPeer> peers
19
19
 
 
20
    // some variables to indicate the files are missing or not
 
21
    property bool isIFO: false
 
22
    property bool isIDX: false
 
23
    property bool isDICT: false
 
24
 
20
25
    signal filesPicked(string filePath)
21
26
 
22
27
    Component.onCompleted: {
23
28
//        PopupUtils.open(contentPickerDialog)
24
29
//        loaderContentHub.load()
25
 
        timerContentPickerDialog.start()
 
30
//        timerContentPickerDialog.start()
26
31
//        mainStack.push(contentPickerDialog)
27
32
    }
28
33
 
78
83
            console.log("StateChanged: " + contentHubPicker.activeTransfer.state);
79
84
            if (contentHubPicker.activeTransfer.state === ContentTransfer.Charged) {
80
85
                contentHubPicker.importItems = contentHubPicker.activeTransfer.items;
81
 
                console.log("importItems[0].: " + String(contentHubPicker.importItems[0].url).split("/").pop() );
 
86
//                console.log("importItems[0].: " + String(contentHubPicker.importItems[0].url).split("/").pop() );
82
87
//                console.log("importItems[1].: " + JSON.stringify(importItems[1]) );
83
88
//                console.log("importItems[2].: " + JSON.stringify(importItems[2]) );
84
89
//                contentHubPicker.imgPath =
85
90
//                        String(contentHubPicker.importItems[0].url).replace("file://", "")
86
91
//                loaderPreview.load()
 
92
                isIFO = false
 
93
                isIDX = false
 
94
                isDICT = false
 
95
                modelImportItems.clear()
87
96
                for (var i=0; i<importItems.length; i++) {
88
97
                    modelImportItems.append({ "url": String(importItems[i].url) })
 
98
                    print("url: ", String(importItems[i].url))
 
99
                    var suffix = String(importItems[i].url).split(".").pop().toString()
 
100
                    if (suffix === "ifo" || suffix === "IFO") { isIFO = true }
 
101
                    if (suffix === "idx" || suffix === "IDX") { isIDX = true }
 
102
                    if (suffix === "dict" || suffix === "DICT") { isDICT = true }
89
103
                }
90
104
            }
91
105
            else if (contentHubPicker.activeTransfer.state === ContentTransfer.Aborted) {
92
 
                timerPop.start()
 
106
//                timerPop.start()
93
107
            }
94
108
        }
95
109
    }
96
110
 
97
 
    Column {
98
 
        anchors { left: parent.left; right: parent.right }
99
 
 
100
 
        Repeater {
101
 
            model: modelImportItems
102
 
 
103
 
            ListItem.Standard {
104
 
                text: String(url).split("/").pop().toString()
 
111
    ///////////////////////////////////////////////////////////
 
112
    //  UI for end users
 
113
 
 
114
    Flickable {
 
115
        id: scrollArea
 
116
        boundsBehavior: (contentHeight > height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
117
        anchors.fill: parent; anchors.topMargin: units.gu(1)
 
118
        contentWidth: width
 
119
        contentHeight: columnInnerArea.height + units.gu(3)
 
120
        clip: true
 
121
 
 
122
        Column {
 
123
            id: columnInnerArea
 
124
            anchors { left: parent.left; right: parent.right }
 
125
 
 
126
            Column {
 
127
                anchors { left: parent.left; right: parent.right }
 
128
                spacing: units.gu(1)
 
129
 
 
130
                Label {
 
131
                    anchors { left: parent.left; right: parent.right; margins: units.gu(1) }
 
132
                    wrapMode: Text.WrapAtWordBoundaryOrAnywhere
 
133
                    horizontalAlignment: Text.AlignHCenter
 
134
                    text: {
 
135
                        if (modelImportItems.count == 0) {
 
136
                            return i18n.tr("No file detected, please press the button below to import files. "
 
137
                                           + "Or if you don't know what to import, please read the instruction")
 
138
                        }
 
139
                        else {
 
140
                            if (isIFO && isIDX && isDICT) {
 
141
                                return i18n.tr("Dictionary files detected, please press the button below to proceed. ")
 
142
                            }
 
143
                            else {
 
144
                                return i18n.tr("Some files are missing, please make sure there are "
 
145
                                               + "one .ifo file, one .idx file and one .dict file. ")
 
146
                            }
 
147
                        }
 
148
                    }
 
149
                }
 
150
 
 
151
                Row {
 
152
                    //                anchors { left: parent.left; right: parent.right; margins: units.gu(1) }
 
153
                    anchors.horizontalCenter: parent.horizontalCenter
 
154
                    width: childrenRect.width
 
155
                    height: childrenRect.height
 
156
                    spacing: units.gu(5)
 
157
                    visible: !isIFO || !isIDX || !isDICT
 
158
 
 
159
                    Button {
 
160
                        text: i18n.tr("Instruction")
 
161
                    }
 
162
 
 
163
                    Button {
 
164
                        color: UbuntuColors.orange
 
165
                        text: i18n.tr("Start Import")
 
166
                        onClicked: { mainStack.push(contentPickerDialog) }
 
167
                    }
 
168
                }
 
169
 
 
170
                Button {
 
171
                    anchors.horizontalCenter: parent.horizontalCenter
 
172
                    color: UbuntuColors.orange
 
173
                    visible: isIFO && isIDX && isDICT
 
174
                    text: i18n.tr("Complete Import")
 
175
 
 
176
                    onClicked: {
 
177
                        var dictlist = new Array
 
178
                        for (var i=0; i<importItems.length; i++) {
 
179
                            dictlist.push(String(importItems[i].url).replace("file://", ""))
 
180
                        }
 
181
                        var result = dictCenter.importDict(dictlist)
 
182
                        if (result.error) {
 
183
                            print(result.error)
 
184
                        }
 
185
                        else { mainStack.pop() }
 
186
                    }
 
187
                }
 
188
            }
 
189
 
 
190
            Repeater {
 
191
                model: modelImportItems
 
192
 
 
193
                ListItem.Standard {
 
194
                    text: String(url).split("/").pop().toString()
 
195
                }
105
196
            }
106
197
        }
 
198
 
107
199
    }
108
200
 
109
201
    ListModel {