New GUI
[ubi] / qml / ubi / FileDialog.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "components"
3 import "UIConstants.js" as Const
4 import Qt 4.7
5 import Qt.labs.folderlistmodel 1.0
6
7 DialogBox {
8     id: root
9
10     property string currentFilePath: fileSelector.currentFilePath
11     property bool load: fileSelector.load
12     property alias folder: folderModel.folder
13     property bool folderOnly: true
14
15     signal folderSelected(string folder)
16     signal fileSelected(string folder, string file)
17
18     function fixPath(path) {
19         path = path.toString();
20         var ind = path.lastIndexOf("/");
21         if(ind>=0) {
22             path = path.substr(ind+1);
23         }
24         if(path=="") path = "/";
25
26         return path;
27     }
28
29     MouseArea {
30         anchors.fill: parent
31     }
32
33     Rectangle {
34         id: fileSelector
35
36         anchors.left: root.left; anchors.right: root.right
37         anchors.top: root.top
38
39         height: parent.height
40
41         property string currentFilePath: folderModel.folder
42         property bool load: true
43         property string folder: folderModel.folder
44
45         color: Const.DEFAULT_DIALOG_BACKGROUND_COLOR
46
47         function setFolder(folder) {
48             folderAnimation.folderToChange = folder;
49             folderAnimation.start();
50         }
51
52         Rectangle {
53             id: pathController
54             width: parent.width
55             height: currentFolderButton.height+2*Const.DEFAULT_MARGIN
56             anchors.top: parent.top
57             z: 1
58             color: Const.LIGHT_AUBERGINE_COLOR
59
60             ButtonResizable {
61                 id: currentFolderButton
62                 anchors.margins: Const.DEFAULT_MARGIN
63                 anchors.left: parent.left
64                 anchors.verticalCenter: parent.verticalCenter
65                 text: fixPath(folderModel.folder)
66                 width: pathController.width-folderUpButton.width-cancelButton.width-4*Const.DEFAULT_MARGIN
67                 height: folderUpButton.height
68                 onClicked: root.folderSelected(folderModel.folder)
69                 disabled: !root.folderOnly
70             }
71             Button {
72                 id: folderUpButton
73                 anchors.margins: Const.DEFAULT_MARGIN
74                 anchors.right: cancelButton.left
75                 anchors.verticalCenter: parent.verticalCenter
76                 label: "up"
77                 iconSource: "images/up.png"
78                 onButtonClicked: fileSelector.setFolder(folderModel.parentFolder);
79
80             }
81             Button {
82                 id: cancelButton
83                 anchors.margins: Const.DEFAULT_MARGIN
84                 anchors.right: parent.right
85                 anchors.verticalCenter: parent.verticalCenter
86                 label: "cancel"
87                 iconSource: "images/close.png"
88                 onButtonClicked: {
89                     root.close();
90                     mask.state = "idle";
91                 }
92             }
93
94         }
95
96         Shadow {
97             y: pathController.height
98             z: 1
99         }
100
101         Rectangle {
102             id: folderModelContainer
103             width: parent.width
104             anchors.top: pathController.bottom;
105             anchors.bottom: parent.bottom
106             color: Const.TRANSPARENT
107
108             FolderListModel {
109                 id: folderModel
110                 //folder: "/"
111                 nameFilters: root.folderOnly ? [""] : ["*"]
112             }
113
114             Component {
115                 id: folderModelDelegate
116
117                 FileSmall {
118                     id: file
119                     width: root.width
120                     visible: root.folderOnly? folderModel.isFolder(index) : true
121                     text: fileName
122                     isDirectory: folderModel.isFolder(index)
123                     onClicked: {
124                         if(isDirectory)
125                             fileSelector.setFolder(filePath);
126                         else
127                             root.fileSelected(folderModel.folder,text)
128                     }
129
130                     Component.onCompleted: {
131                         var ind = text.lastIndexOf(".");
132                         var ext = "";
133                         if(ind>=0) ext = text.substr(ind+1);
134                         if(ext=="jpg" || ext=="JPG" || ext=="Jpg" ||
135                            ext=="jpeg" || ext=="JPEG" || ext=="Jpeg" ||
136                            ext=="gif" || ext=="GIF" || ext=="Gif" ||
137                            ext=="svg" || ext=="SVG" || ext=="Svg" ||
138                            ext=="png" || ext=="PNG" || ext=="Png") {
139                             isPhoto = true;
140                         }
141                         if(ext=="mp3" || ext=="MP3" || ext=="Mp3" ||
142                            ext=="wma" || ext=="WMA" || ext=="Wma" ||
143                            ext=="wav" || ext=="WAV" || ext=="Wav" ||
144                            ext=="ogg" || ext=="OGG" || ext=="Ogg" ||
145                            ext=="acc" || ext=="ACC" || ext=="Acc" ||
146                            ext=="flac" || ext=="FLAC" || ext=="Flac") {
147                             isMusic = true;
148                         }
149                         if(ext=="avi" || ext=="AVI" || ext=="Avi" ||
150                            ext=="mp4" || ext=="MP4" || ext=="Mp4" ||
151                            ext=="mpg" || ext=="MPG" || ext=="Mpg" ||
152                            ext=="mkv" || ext=="MKV" || ext=="Mkv" ||
153                            ext=="flv" || ext=="FLV" || ext=="Flv" ||
154                            ext=="3gp" || ext=="3GP") {
155                             isVideo = true;
156                         }
157                     }
158                 }
159             }
160
161             ListView {
162                 id: folderModelView
163
164                 anchors {
165                     fill: parent;
166                 }
167
168                 model: folderModel
169                 delegate: folderModelDelegate
170
171                 SequentialAnimation {
172                     id: folderAnimation
173
174                     property string folderToChange
175
176                     PropertyAnimation { target: folderModelView; property: "opacity"; to: 0; duration: 100 }
177                     PropertyAction { target: folderModel; property: "folder"; value: folderAnimation.folderToChange }
178                     PropertyAnimation { target: folderModelView; property: "opacity"; to: 1.0; duration: 100 }
179                 }
180             }
181
182         }
183     }
184 }
185