~mutse-young/ubuntu-docviewer-app/trunk

« back to all changes in this revision

Viewing changes to ubuntu-docviewer-app.qml

  • Committer: Granger Anthony
  • Date: 2013-04-22 17:40:25 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: grangeranthony@gmail.com-20130422174025-2tlqqq0x4sqsqloi
Fix bad QML file path, fix QML filename, fix bad exec path in .desktop, fix error when the QML file is not found

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.Components.ListItems 0.1 as ListItem
 
4
 
 
5
MainView {
 
6
    // objectName for functional testing purposes (autopilot-qt5)
 
7
    objectName: "docviewer"
 
8
 
 
9
    applicationName: "ubuntu-docviewer-app"
 
10
    
 
11
    width: units.gu(50)
 
12
    height: units.gu(75)
 
13
 
 
14
    Component.onCompleted: {
 
15
 
 
16
    }
 
17
 
 
18
    Component.onDestruction: {
 
19
 
 
20
    }
 
21
    
 
22
    Tabs {
 
23
        id: tabs
 
24
        anchors.fill: parent
 
25
 
 
26
        Tab {
 
27
            objectName: "tabViewer"
 
28
            id: tabViewer;
 
29
            
 
30
            title: getNameOfFile(file);
 
31
            
 
32
            page: Page {
 
33
 
 
34
                tools: ToolbarActions {
 
35
                    back {
 
36
                        visible: true
 
37
                    }
 
38
                }
 
39
 
 
40
                Column {
 
41
                    id: columnMain;
 
42
                    width: parent.width;
 
43
                    height: childrenRect.height;
 
44
 
 
45
                    TextArea {
 
46
 
 
47
                        id: textAreaMain;
 
48
 
 
49
                        width: parent.width;
 
50
                        height: units.gu(66);
 
51
 
 
52
                        activeFocusOnPress: false;
 
53
                        highlighted: true;
 
54
 
 
55
                        signal loadCompleted()
 
56
 
 
57
                        Component.onCompleted: {
 
58
                            var xhr = new XMLHttpRequest;
 
59
 
 
60
                            xhr.open("GET", file);
 
61
                            xhr.onreadystatechange = function() {
 
62
                                if (xhr.readyState === XMLHttpRequest.DONE) {
 
63
                                    textAreaMain.text = xhr.responseText;
 
64
                                    textAreaMain.loadCompleted();
 
65
                                }
 
66
                            }
 
67
 
 
68
                            xhr.send();
 
69
                        }
 
70
                    }
 
71
                }
 
72
            }
 
73
        }
 
74
 
 
75
        Tab {
 
76
            objectName: "TabDetails"
 
77
            id: tabDetails;
 
78
 
 
79
            title: i18n.tr("Details")
 
80
            page: Page {
 
81
                Column {
 
82
                    width: units.gu(50)
 
83
                    ListItem.SingleValue {
 
84
                        text: i18n.tr("Location")
 
85
                        value: file
 
86
                    }
 
87
                    ListItem.SingleValue {
 
88
                        text: i18n.tr("Size")
 
89
                        value: printSize(textAreaMain.text.length);
 
90
                    }
 
91
 
 
92
                    ListItem.SingleValue {
 
93
                        text: i18n.tr("Created")
 
94
                        value: "01/01/2001";
 
95
                    }
 
96
 
 
97
                    ListItem.SingleValue {
 
98
                        text: i18n.tr("Modified")
 
99
                        value: "01/01/2001";
 
100
                    }
 
101
                }
 
102
            }
 
103
        }
 
104
    }
 
105
 
 
106
    function printSize(size)
 
107
    {
 
108
        if (size >= 1073741824)
 
109
        {
 
110
            return parseInt(size/1073741824) + "," + size%1073741824 + " Gio";
 
111
        }
 
112
 
 
113
        if (size >= 1048576)
 
114
        {
 
115
            return parseInt(size/1048576) + "," + size%1048576 + " Mio";
 
116
        }
 
117
 
 
118
        if (size >= 1024)
 
119
        {
 
120
            return parseInt(size/1024) + "," + size%1024 + " Kio";
 
121
        }
 
122
 
 
123
        return size + " o";
 
124
    }
 
125
 
 
126
    function getNameOfFile(path)
 
127
    {
 
128
        var name = String(path);
 
129
 
 
130
        return name.substring(name.lastIndexOf('/')+1);
 
131
 
 
132
    }
 
133
}