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
20 [qsTr("Upload file"),false],
21 [qsTr("Rename"),false],
22 [qsTr("Delete"),false],
23 [qsTr("New folder"),false],
24 [qsTr("Refresh"),false]
27 function menuFun(id) {
28 if(id==qsTr("Upload file")) {
29 mask.state = "dialog";
32 if(id==qsTr("Refresh")) {
33 init(root.properties);
35 if(id==qsTr("Rename")) {
37 tip.show(qsTr("Root folder can't be renamed!"));
42 if(id==qsTr("Delete")) {
44 tip.show(qsTr("Root folder can't be deleted!"));
49 if(id==qsTr("New folder")) {
56 if(mask.state!="defocused") {
59 if(root.properties && !prop) {
60 prop = root.properties;
65 secret: Utils.tokenSecret(),
66 consumer_key : Utils.customerKey(),
67 consumer_secret: Utils.customerSecret()
70 root.path = prop.path;
71 root.name = U1.fixFilename(prop.path);
72 U1.getFiles(secrets,prop.resource_path,root);
73 resource_path = prop.resource_path;
74 content_path = prop.content_path;
78 U1.getFileTree(secrets,root);
80 root.properties = prop;
83 function onResp(nodes)
85 createFilesView(nodes);
88 function onErr(status)
90 //console.log("onErr");
93 tip.show(qsTr("Authorization failed!"));
94 } else if(status==0) {
95 tip.show(qsTr("Unable to connect!"));
97 tip.show(qsTr("Error: ")+status);
103 function onRespRename()
105 //console.log("onRespRename");
106 pageStack.prevPage().init();
108 tip.show(qsTr("Folder renamed!"));
111 function onErrRename(status)
113 //console.log("onErrRenamed");
116 tip.show(qsTr("Authorization failed!"));
118 tip.show(qsTr("Error: ")+status);
124 //console.log("onRespNew");
125 pageStack.currentPage.init();
127 tip.show(qsTr("New folder created!"));
130 function onErrNew(status)
135 function createFilesView(nodes)
138 if(files.children.length>0) {
139 l = files.children.length;
141 files.children[i].destroy();
144 var component = Qt.createComponent("components/File.qml");
146 //console.log("l="+l);
147 for (i=0; i<l; i++) {
148 var object = component.createObject(files);
149 var ind = nodes[i].path.lastIndexOf("/");
150 //object.textMax = root.width/17;
151 //console.log("ind="+ind);
153 object.name = nodes[i].path.substr(ind+1);
155 object.name = nodes[i].path;
157 object.isDirectory = nodes[i].kind == "directory";
158 object.properties = nodes[i];
159 object.width = root.width;
160 //object.height = 50;
161 if(object.isDirectory) {
162 /*if(!nodes[i].has_children) {
163 object.description = "Empty";
165 object.clicked.connect(function(prop) {
166 pageStack.push("FilesPage.qml");
167 pageStack.currentPage.init(prop);
170 var txt = "" + Conv.bytesToSize(nodes[i].size);
171 object.description = txt;
172 object.isPublic = nodes[i].is_public;
173 object.clicked.connect(function(prop) {
174 pageStack.push("PropertiesPage.qml");
175 pageStack.currentPage.init(prop);
178 ind = object.name.lastIndexOf(".");
180 if(ind>=0) ext = object.name.substr(ind+1);
181 if(ext=="jpg" || ext=="JPG" || ext=="Jpg" ||
182 ext=="jpeg" || ext=="JPEG" || ext=="Jpeg" ||
183 ext=="gif" || ext=="GIF" || ext=="Gif" ||
184 ext=="png" || ext=="PNG" || ext=="Png") {
185 object.isPhoto = true;
189 if(mask.state!="defocused") {
193 if(files.children.length==0) {
194 empty.visible = true;
196 empty.visible = false;
202 onFileUploaded: init(root.properties);
208 height: parent.height
209 contentHeight: files.height+Const.SYSTEM_BAR_HEIGHT+2*Const.TEXT_MARGIN
210 //y: Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
211 y: Const.SYSTEM_BAR_HEIGHT+Const.DEFAULT_MARGIN
212 contentWidth: parent.width
216 //spacing: Const.DEFAULT_MARGIN
217 //x: Const.TEXT_MARGIN
219 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
226 font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
227 color: Const.DEFAULT_FOREGROUND_COLOR
229 anchors.centerIn: parent
237 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
241 //console.log("selected: "+file+" "+U1.fixFolder(folder));
242 fileSelector.close();
243 Utils.setLastFolder(folder);
244 var path = content_path+"/"+file;
246 U1.uploadFile(secrets,root,path,file,folder,Utils);
251 function getParentPath(path) {
254 var ind = path.lastIndexOf("/");
256 ppath = path.substr(0,ind);
258 if(path=="") ppath = "/";
260 //console.log(ppath);
265 var l=0; var r=s.length -1;
266 while(l < s.length && s[l] == ' ')
268 while(r > l && s[r] == ' ')
270 return s.substring(l, r+1);
276 if(pageStack.currentPage==root) {
278 tip.show(qsTr("Folder was deleted!"));
280 pageStack.currentPage.init();
284 if(pageStack.currentPage==root) {
287 tip.show(qsTr("Authorization failed!"));
289 tip.show(qsTr("Error: ")+status);
298 text: qsTr("Delete folder?")
299 onOpened: mask.state = "dialog"
304 U1.deleteFile(secrets,properties.resource_path,root,Utils);
307 onCanceled: mask.state = "idle"
313 textWidth: root.width - 4*Const.DEFAULT_MARGIN
314 label: qsTr("Enter new folder name:")
315 placeholderText: root.name
318 Utils.setOrientation("auto");
319 mask.state = "dialog";
323 Utils.setOrientation(root.orientation);
327 var currentPath = root.properties.resource_path;
328 var targetPath = getParentPath(root.properties.path)+"/"+resp;
329 //console.log("targetPath: "+targetPath);
330 U1.renameFile(secrets,currentPath,targetPath,root);
332 tip.show(qsTr("Invalid folder name!"))
336 Utils.setOrientation(root.orientation);
344 textWidth: root.width - 4*Const.DEFAULT_MARGIN
345 label: qsTr("Enter new folder name:")
349 Utils.setOrientation("auto");
350 mask.state = "dialog";
354 Utils.setOrientation(root.orientation);
360 rpath = root.properties.resource_path;
362 rpath = root.resource_path;
363 var newPath = rpath+"/"+resp;
364 //console.log("newPath: "+newPath);
365 U1.newFolder(secrets,newPath,root);
367 tip.show(qsTr("Invalid folder name!"))
371 Utils.setOrientation(root.orientation);