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)
57 //console.log("onErr");
60 tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
61 } else if(status==0) {
62 tip.show(qsTr("Unable to connect. Check internet connection."));
64 tip.show(qsTr("Unknown error: ")+status);
71 function onRespRename()
73 //console.log("onRespRename");
74 pageStack.prevPage().init();
76 tip.show(qsTr("Folder renamed!"));
79 function onErrRename(status)
81 //console.log("onErrRenamed");
84 tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
86 tip.show(qsTr("Unknown error: ")+status);
92 //console.log("onRespNew");
93 pageStack.currentPage.init();
95 tip.show(qsTr("New folder created!"));
98 function onErrNew(status)
103 function createFilesView(nodes)
106 if(files.children.length>0) {
107 l = files.children.length;
109 files.children[i].destroy();
112 var component = Qt.createComponent("components/File.qml");
114 //console.log("l="+l);
115 for (i=0; i<l; i++) {
116 var object = component.createObject(files);
117 var ind = nodes[i].path.lastIndexOf("/");
118 //object.textMax = root.width/17;
119 //console.log("ind="+ind);
121 object.name = nodes[i].path.substr(ind+1);
123 object.name = nodes[i].path;
125 object.isDirectory = nodes[i].kind == "directory";
126 object.properties = nodes[i];
127 //object.width = root.width;
128 //object.height = 50;
129 if(object.isDirectory) {
130 /*if(!nodes[i].has_children) {
131 object.description = "Empty";
133 object.clicked.connect(function(prop) {
134 pageStack.push("FilesPage.qml");
135 pageStack.currentPage.init(prop);
138 var txt = "" + Conv.bytesToSize(nodes[i].size);
139 object.description = txt;
140 object.isPublic = nodes[i].is_public;
141 object.clicked.connect(function(prop) {
142 pageStack.push("PropertiesPage.qml");
143 pageStack.currentPage.init(prop);
147 ind = object.name.lastIndexOf(".");
149 if(ind>=0) ext = object.name.substr(ind+1);
150 if(ext=="jpg" || ext=="JPG" || ext=="Jpg" ||
151 ext=="jpeg" || ext=="JPEG" || ext=="Jpeg" ||
152 ext=="gif" || ext=="GIF" || ext=="Gif" ||
153 ext=="svg" || ext=="SVG" || ext=="Svg" ||
154 ext=="png" || ext=="PNG" || ext=="Png") {
155 object.isPhoto = true;
157 if(ext=="mp3" || ext=="MP3" || ext=="Mp3" ||
158 ext=="wma" || ext=="WMA" || ext=="Wma" ||
159 ext=="wav" || ext=="WAV" || ext=="Wav" ||
160 ext=="ogg" || ext=="OGG" || ext=="Ogg" ||
161 ext=="acc" || ext=="ACC" || ext=="Acc" ||
162 ext=="m4a" || ext=="M4A" || ext=="M4a" ||
163 ext=="flac" || ext=="FLAC" || ext=="Flac") {
164 object.isMusic = true;
166 if(ext=="avi" || ext=="AVI" || ext=="Avi" ||
167 ext=="mp4" || ext=="MP4" || ext=="Mp4" ||
168 ext=="mpg" || ext=="MPG" || ext=="Mpg" ||
169 ext=="mkv" || ext=="MKV" || ext=="Mkv" ||
170 ext=="flv" || ext=="FLV" || ext=="Flv" ||
171 ext=="m4v" || ext=="M4V" || ext=="M4v" ||
172 ext=="3gp" || ext=="3GP") {
173 object.isVideo = true;
177 if(mask.state!="defocused" && mask.state!="dialog") {
181 /*if(files.children.length==0) {
182 empty.visible = true;
184 empty.visible = false;
188 empty.visible = true;
190 empty.visible = false;
198 onFileUploaded: init(root.properties);
204 height: parent.height
205 contentHeight: files.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
206 y: Const.TOP_BAR_HEIGHT
207 contentWidth: parent.width
212 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
219 font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
220 color: Const.DEFAULT_FOREGROUND_COLOR
222 anchors.centerIn: parent
230 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
234 //console.log("selected: "+file+" "+U1.fixFolder(folder));
235 fileSelector.close();
236 Utils.setLastFolder(folder);
237 var path = content_path+"/"+file;
239 U1.uploadFile(secrets,root,path,file,folder,Utils);
248 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
252 fileSelector.close();
253 Utils.setLastFolder(folder);
254 var path = content_path+"/"+file;
255 U1.uploadFile(secrets,root,path,file,folder,Utils);
259 function getParentPath(path) {
262 var ind = path.lastIndexOf("/");
264 ppath = path.substr(0,ind);
266 if(path=="") ppath = "/";
268 //console.log(ppath);
273 var l=0; var r=s.length -1;
274 while(l < s.length && s[l] == ' ')
276 while(r > l && s[r] == ' ')
278 return s.substring(l, r+1);
284 if(pageStack.currentPage==root) {
286 tip.show(qsTr("Folder was deleted!"));
288 pageStack.currentPage.init();
292 if(pageStack.currentPage==root) {
295 tip.show(qsTr("Authorization failed!"));
297 tip.show(qsTr("Error: ")+status);
306 text: qsTr("Delete folder?")
307 onOpened: mask.state = "dialog"
311 U1.deleteFile(secrets,properties.resource_path,root,Utils);
319 textWidth: root.width - 4*Const.DEFAULT_MARGIN
320 label: qsTr("Enter new folder name:")
321 placeholderText: root.name
324 Utils.setOrientation("auto");
328 Utils.setOrientation(root.orientation);
332 var currentPath = root.properties.resource_path;
333 var targetPath = getParentPath(root.properties.path)+"/"+resp;
334 //console.log("targetPath: "+targetPath);
335 U1.renameFile(secrets,currentPath,targetPath,root);
337 tip.show(qsTr("Invalid folder name!"))
341 Utils.setOrientation(root.orientation);
348 textWidth: root.width - 4*Const.DEFAULT_MARGIN
349 label: qsTr("Enter new folder name:")
353 Utils.setOrientation("auto");
356 Utils.setOrientation(root.orientation);
362 rpath = root.properties.resource_path;
364 rpath = root.resource_path;
365 var newPath = rpath+"/"+resp;
366 //console.log("newPath: "+newPath);
367 U1.newFolder(secrets,newPath,root);
369 tip.show(qsTr("Invalid folder name!"))
373 Utils.setOrientation(root.orientation);
377 /*[qsTr("Upload file"),false],
378 [qsTr("Rename"),false],
379 [qsTr("Delete"),false],
380 [qsTr("New folder"),false],
381 [qsTr("Refresh"),false]
382 function menuFun(id) {
383 if(id==qsTr("Upload file")) {
384 mask.state = "dialog";
387 if(id==qsTr("Refresh")) {
388 init(root.properties);
390 if(id==qsTr("Rename")) {
392 tip.show(qsTr("Root folder can't be renamed!"));
397 if(id==qsTr("Delete")) {
399 tip.show(qsTr("Root folder can't be deleted!"));
404 if(id==qsTr("New folder")) {
415 menuDynamic: _menuDyn
416 menuHeight: menuDynamic.height+menuFixed.height+7*Const.DEFAULT_MARGIN
421 y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+2*Const.DEFAULT_MARGIN
422 x: Const.DEFAULT_MARGIN
424 width: parent.width-2*Const.DEFAULT_MARGIN
425 spacing: Const.DEFAULT_MARGIN
428 label: qsTr("Upload file");
436 label: qsTr("Rename");
440 tip.show(qsTr("Root folder cannot be renamed."));
448 label: qsTr("Delete");
452 tip.show(qsTr("Root folder cannot be deleted."));
460 label: qsTr("New folder");
468 label: qsTr("Refresh");
471 init(root.properties);