~verzegnassi-stefano/edit/brand-name-not-translatable

« back to all changes in this revision

Viewing changes to app/edIt.qml

  • Committer: pawstr
  • Date: 2015-01-23 19:41:38 UTC
  • Revision ID: pawstr@gmail.com-20150123194138-bd8zysyrzcqa0uq6
All files added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 1.1
 
3
import EdIt 1.0
 
4
import Ubuntu.Content 0.1
 
5
import Ubuntu.Components.Popups 1.0
 
6
import "components"
 
7
import "ui"
 
8
 
 
9
/*!
 
10
    \brief MainView with Tabs element.
 
11
           First Tab has a single Label and
 
12
           second Tab has a single ToolbarAction.
 
13
*/
 
14
 
 
15
MainView {
 
16
    // objectName for functional testing purposes (autopilot-qt5)
 
17
    objectName: "mainView"
 
18
 
 
19
    // Note! applicationName needs to match the "name" field of the click manifest
 
20
    applicationName: "com.ubuntu.developer.pawstr.edit"
 
21
 
 
22
    /*
 
23
     This property enables the application to change orientation
 
24
     when the device is rotated. The default is false.
 
25
    */
 
26
    //automaticOrientation: true
 
27
 
 
28
    // Removes the old toolbar and enables new features of the new header.
 
29
    useDeprecatedToolbar: false
 
30
 
 
31
    anchorToKeyboard: true
 
32
 
 
33
    width: units.gu(100)
 
34
    height: units.gu(75)
 
35
 
 
36
    property string infoText: ""
 
37
 
 
38
    Component {
 
39
        id: popover
 
40
        Popover {
 
41
            id: po
 
42
            Text {
 
43
                anchors.centerIn: parent
 
44
                text: infoText
 
45
            }
 
46
            MouseArea {
 
47
                anchors.fill: parent
 
48
                onClicked: PopupUtils.close(po)
 
49
            }
 
50
            Timer {
 
51
                interval: 2000
 
52
                repeat: false
 
53
                running: true
 
54
                onTriggered: PopupUtils.close(po)
 
55
            }
 
56
        }
 
57
    }
 
58
 
 
59
    FileIO {id: fileIO}
 
60
 
 
61
    function moveFile(item,dir) {
 
62
        var initialUrl = item.url;
 
63
        item.move(dir);
 
64
        if(fileIO.isWritable(dir)) {
 
65
            if(item.url === initialUrl) {
 
66
                var name = fileIO.getFileName(initialUrl);
 
67
                var suffix = fileIO.getSuffix(initialUrl);
 
68
                var i = 0;
 
69
                do {
 
70
                    i++;
 
71
                    item.move(dir, name + "(" + i + ")" + "." + suffix);
 
72
                } while(item.url === initialUrl);
 
73
                showInfo("Couldn't overwrite.\nSaved as " + name + "(" + i + ")" + "." + suffix)
 
74
                root.title = fileIO.getFullName(root.importItems[0].url)
 
75
            } else
 
76
                showInfo("Saved");
 
77
        } else
 
78
            showInfo("Location isn't writable")
 
79
    }
 
80
 
 
81
    function saveFile(item,dir) {
 
82
        if(item.url == "") {
 
83
            PopupUtils.open(saveAsDialog)
 
84
        } else {
 
85
            var newFileName = "file://" + dir + fileIO.getFullName(item.url);
 
86
            if(newFileName != item.url || !fileIO.write(newFileName, textArea.text)) {
 
87
                moveFile(item,dir);
 
88
                fileIO.write(item.url, textArea.text);
 
89
            } else
 
90
                showInfo("Saved");
 
91
            root.saved = true;
 
92
        }
 
93
    }
 
94
 
 
95
    function showInfo(info) {
 
96
        infoText = "\n" + info + "\n";
 
97
        PopupUtils.open(popover);
 
98
    }
 
99
 
 
100
    PageStack {
 
101
        id: pageStack
 
102
        Component.onCompleted: pageStack.push(root)
 
103
 
 
104
        Connections {
 
105
            target: ContentHub
 
106
            onExportRequested: {
 
107
                root.activeTransfer = transfer;
 
108
                console.log ("onExportRequested: " + root.activeTransfer.state);
 
109
            }
 
110
        }
 
111
 
 
112
        Page {
 
113
            id: root
 
114
            title: i18n.tr("edIt")
 
115
 
 
116
            ContentItem {
 
117
                id: nullItem
 
118
                url: ""
 
119
            }
 
120
 
 
121
            property list<ContentItem> importItems: [ContentItem{url: ""}]
 
122
            property var fileList;
 
123
            property var activeTransfer;
 
124
            property bool saved: true
 
125
 
 
126
            NewFileDialog {id: newFileDialog}
 
127
            UnsavedDialog {id: unsavedDialog}
 
128
            SaveAsDialog  {id: saveAsDialog }
 
129
 
 
130
            tools: Toolbar{id: toolbar}
 
131
 
 
132
            Component {
 
133
                id: resultComponent
 
134
                ContentItem {}
 
135
            }
 
136
 
 
137
            TextArea {
 
138
                id: textArea
 
139
                anchors {
 
140
                    margins: units.gu(1)
 
141
                    fill: parent
 
142
                }
 
143
                textFormat: TextEdit.AutoText
 
144
                inputMethodHints: Qt.ImhMultiLine | Qt.ImhNoPredictiveText
 
145
                selectByMouse: true
 
146
                onTextChanged: root.saved = false;
 
147
            }
 
148
 
 
149
            ContentTransferHint {
 
150
                id: importHint
 
151
                anchors.fill: parent
 
152
                activeTransfer: root.activeTransfer
 
153
            }
 
154
            Connections {
 
155
                target: root.activeTransfer
 
156
                onStateChanged: {
 
157
                    if (root.activeTransfer.state === ContentTransfer.Charged &&
 
158
                        root.activeTransfer.direction === ContentTransfer.Import) {
 
159
                        root.importItems = root.activeTransfer.items;
 
160
 
 
161
                        textArea.text = fileIO.read(root.importItems[0].url);
 
162
                        root.title = fileIO.getFullName(root.importItems[0].url);
 
163
                    }
 
164
                }
 
165
            }
 
166
        }
 
167
 
 
168
        Settings {id: settings}
 
169
        LocalFilePicker {id: localFilePicker}
 
170
 
 
171
        Page {
 
172
            id: picker
 
173
            visible: false
 
174
            ContentPeerPicker {
 
175
                id: peerPicker
 
176
                visible: parent.visible
 
177
 
 
178
                // Type of handler: Source, Destination, or Share
 
179
                handler: ContentHandler.Source
 
180
                // well know content type
 
181
                contentType: ContentType.Documents
 
182
 
 
183
                onPeerSelected: {
 
184
                    peer.selectionType = ContentTransfer.Single;
 
185
                    root.activeTransfer = peer.request();
 
186
                    pageStack.pop();
 
187
                }
 
188
                onCancelPressed: pageStack.pop()
 
189
            }
 
190
        }
 
191
        // TODO someday
 
192
//        Page {
 
193
//            id: exportPicker
 
194
//            visible: false
 
195
//            property var curTransfer
 
196
//            property var url
 
197
//            property var handler: ContentHandler.Destination
 
198
//            property alias contentType: exportPeerPicker.contentType
 
199
 
 
200
//            function __exportItems(url) {
 
201
//                if (exportPicker.curTransfer.state === ContentTransfer.InProgress)
 
202
//                {
 
203
//                    exportPicker.curTransfer.items = [ resultComponent.createObject(root, {"url": url}) ];
 
204
//                    exportPicker.curTransfer.state = ContentTransfer.Charged;
 
205
//                }
 
206
//            }
 
207
 
 
208
//            ContentPeerPicker {
 
209
//                id: exportPeerPicker
 
210
 
 
211
//                visible: parent.visible
 
212
//                contentType: ContentType.Documents
 
213
//                handler: exportPicker.handler
 
214
 
 
215
//                onPeerSelected: {
 
216
//                    exportPicker.curTransfer = peer.request();
 
217
//                        pageStack.pop();
 
218
//                        if (exportPicker.curTransfer.state === ContentTransfer.InProgress)
 
219
//                            exportPicker.__exportItems(exportPicker.url);
 
220
//                }
 
221
//                onCancelPressed: pageStack.pop()
 
222
//            }
 
223
//            Connections {
 
224
//                target: exportPicker.curTransfer
 
225
//                onStateChanged: {
 
226
//                    console.log("curTransfer StateChanged: " + exportPicker.curTransfer.state);
 
227
//                    if (exportPicker.curTransfer.state === ContentTransfer.InProgress)
 
228
//                    {
 
229
//                        exportPicker.__exportItems(exportPicker.url);
 
230
//                    }
 
231
//                }
 
232
//            }
 
233
//        }
 
234
    }
 
235
}