1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
5 import "bytesconv.js" as Conv
6 import "UIConstants.js" as Const
12 property variant secrets
13 property string resource_path: "/~/Ubuntu One";
14 property string content_path: "/content/~/Ubuntu One";
15 property variant properties
19 property alias taskMenu: taskMenu
23 if(mask.state!="defocused" && mask.state!="dialog") {
26 if(root.properties && !prop) {
27 prop = root.properties;
32 secret: Utils.tokenSecret(),
33 consumer_key : Utils.customerKey(),
34 consumer_secret: Utils.customerSecret()
37 root.path = prop.path;
38 root.name = U1.fixFilename(prop.path);
39 U1.getFiles(secrets,prop.resource_path,root);
40 resource_path = prop.resource_path;
41 content_path = prop.content_path;
45 U1.getFileTree(secrets,root);
47 root.properties = prop;
50 function onResp(nodes)
52 createFilesView(nodes);
55 function onErr(status)
59 tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
60 } else if(status==0) {
61 tip.show(qsTr("Unable to connect. Check internet connection."));
63 tip.show(qsTr("Unknown error: ")+status);
70 function onRespRename()
72 pageStack.prevPage().init();
74 tip.show(qsTr("Folder renamed!"));
77 function onErrRename(status)
81 tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
83 tip.show(qsTr("Unknown error: ")+status);
89 pageStack.currentPage.init();
91 tip.show(qsTr("New folder created!"));
94 function onErrNew(status)
99 function createFilesView(nodes)
102 if(files.children.length>0) {
103 l = files.children.length;
105 files.children[i].destroy();
108 var component = Qt.createComponent("components/File.qml");
110 for (i=0; i<l; i++) {
111 var object = component.createObject(files);
112 var ind = nodes[i].path.lastIndexOf("/");
114 object.name = nodes[i].path.substr(ind+1);
116 object.name = nodes[i].path;
118 object.isDirectory = nodes[i].kind == "directory";
119 object.properties = nodes[i];
120 if(object.isDirectory) {
121 object.clicked.connect(function(prop) {
122 pageStack.push("FilesPage.qml");
123 pageStack.currentPage.init(prop);
126 var txt = "" + Conv.bytesToSize(nodes[i].size);
127 object.description = txt;
128 object.isPublic = nodes[i].is_public;
129 object.clicked.connect(function(prop) {
130 pageStack.push("PropertiesPage.qml");
131 pageStack.currentPage.init(prop);
135 ind = object.name.lastIndexOf(".");
137 if(ind>=0) ext = object.name.substr(ind+1);
138 if(ext=="jpg" || ext=="JPG" || ext=="Jpg" ||
139 ext=="jpeg" || ext=="JPEG" || ext=="Jpeg" ||
140 ext=="gif" || ext=="GIF" || ext=="Gif" ||
141 ext=="svg" || ext=="SVG" || ext=="Svg" ||
142 ext=="png" || ext=="PNG" || ext=="Png") {
143 object.isPhoto = true;
145 if(ext=="mp3" || ext=="MP3" || ext=="Mp3" ||
146 ext=="wma" || ext=="WMA" || ext=="Wma" ||
147 ext=="wav" || ext=="WAV" || ext=="Wav" ||
148 ext=="ogg" || ext=="OGG" || ext=="Ogg" ||
149 ext=="acc" || ext=="ACC" || ext=="Acc" ||
150 ext=="m4a" || ext=="M4A" || ext=="M4a" ||
151 ext=="flac" || ext=="FLAC" || ext=="Flac") {
152 object.isMusic = true;
154 if(ext=="avi" || ext=="AVI" || ext=="Avi" ||
155 ext=="mp4" || ext=="MP4" || ext=="Mp4" ||
156 ext=="mpg" || ext=="MPG" || ext=="Mpg" ||
157 ext=="mkv" || ext=="MKV" || ext=="Mkv" ||
158 ext=="flv" || ext=="FLV" || ext=="Flv" ||
159 ext=="m4v" || ext=="M4V" || ext=="M4v" ||
160 ext=="3gp" || ext=="3GP") {
161 object.isVideo = true;
165 if(mask.state!="defocused" && mask.state!="dialog") {
170 empty.visible = true;
172 empty.visible = false;
180 onFileUploaded: init(root.properties);
186 height: parent.height
187 contentHeight: files.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
188 y: Const.TOP_BAR_HEIGHT
189 contentWidth: parent.width
194 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
201 font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
202 color: Const.DEFAULT_FOREGROUND_COLOR
204 anchors.centerIn: parent
213 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
217 fileSelector.close();
218 Utils.setLastFolder(folder);
219 var path = content_path+"/"+file;
220 U1.uploadFile(secrets,root,path,file,folder,Utils);
224 function getParentPath(path) {
226 var ind = path.lastIndexOf("/");
228 ppath = path.substr(0,ind);
230 if(path=="") ppath = "/";
235 var l=0; var r=s.length -1;
236 while(l < s.length && s[l] == ' ')
238 while(r > l && s[r] == ' ')
240 return s.substring(l, r+1);
246 if(pageStack.currentPage==root) {
248 tip.show(qsTr("Folder was deleted!"));
250 pageStack.currentPage.init();
254 if(pageStack.currentPage==root) {
257 tip.show(qsTr("Authorization failed!"));
259 tip.show(qsTr("Error: ")+status);
268 text: qsTr("Delete folder?")
269 onOpened: mask.state = "dialog"
273 U1.deleteFile(secrets,properties.resource_path,root,Utils);
281 textWidth: root.width - 4*Const.DEFAULT_MARGIN
282 label: qsTr("Enter new folder name:")
283 placeholderText: root.name
286 Utils.setOrientation("auto");
290 Utils.setOrientation(root.orientation);
294 var currentPath = root.properties.resource_path;
295 var targetPath = getParentPath(root.properties.path)+"/"+resp;
296 U1.renameFile(secrets,currentPath,targetPath,root);
298 tip.show(qsTr("Invalid folder name!"))
302 Utils.setOrientation(root.orientation);
309 textWidth: root.width - 4*Const.DEFAULT_MARGIN
310 label: qsTr("Enter new folder name:")
314 Utils.setOrientation("auto");
317 Utils.setOrientation(root.orientation);
323 rpath = root.properties.resource_path;
325 rpath = root.resource_path;
326 var newPath = rpath+"/"+resp;
327 U1.newFolder(secrets,newPath,root);
329 tip.show(qsTr("Invalid folder name!"))
333 Utils.setOrientation(root.orientation);
342 menuDynamic: _menuDyn
343 menuHeight: menuDynamic.height+menuFixed.height+7*Const.DEFAULT_MARGIN
348 y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+2*Const.DEFAULT_MARGIN
349 x: Const.DEFAULT_MARGIN
351 width: parent.width-2*Const.DEFAULT_MARGIN
352 spacing: Const.DEFAULT_MARGIN
355 label: qsTr("Upload file");
363 label: qsTr("Rename");
367 tip.show(qsTr("Root folder cannot be renamed."));
375 label: qsTr("Delete");
379 tip.show(qsTr("Root folder cannot be deleted."));
387 label: qsTr("New folder");
395 label: qsTr("Refresh");
398 init(root.properties);