1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
5 import "UIConstants.js" as Const
11 property variant secrets
12 property string resource_path: "/~/Ubuntu One";
13 property string content_path: "/content/~/Ubuntu One";
14 property variant properties
19 [qsTr("Upload file"),false],
20 [qsTr("Rename"),false],
21 [qsTr("Delete"),false],
22 [qsTr("New folder"),false],
23 [qsTr("Refresh"),false]
26 function menuFun(id) {
27 if(id==qsTr("Upload file")) {
28 mask.state = "dialog";
31 if(id==qsTr("Refresh")) {
32 init(root.properties);
34 if(id==qsTr("Rename")) {
36 tip.show(qsTr("Root folder can't be renamed!"));
41 if(id==qsTr("Delete")) {
43 tip.show(qsTr("Root folder can't be deleted!"));
48 if(id==qsTr("New folder")) {
55 if(mask.state!="defocused") {
58 if(root.properties && !prop) {
59 prop = root.properties;
64 secret: Utils.tokenSecret(),
65 consumer_key : Utils.customerKey(),
66 consumer_secret: Utils.customerSecret()
69 root.path = prop.path;
70 root.name = U1.fixFilename(prop.path);
71 U1.getFiles(secrets,prop.resource_path,root);
72 resource_path = prop.resource_path;
73 content_path = prop.content_path;
77 U1.getFileTree(secrets,root);
79 root.properties = prop;
82 function onResp(nodes)
84 createFilesView(nodes);
87 function onErr(status)
89 //console.log("onErr");
92 tip.show(qsTr("Authorization failed!"));
93 } else if(status==0) {
94 tip.show(qsTr("Unable to connect!"));
96 tip.show(qsTr("Error: ")+status);
102 function onRespRename()
104 //console.log("onRespRename");
105 pageStack.prevPage().init();
107 tip.show(qsTr("Folder renamed!"));
110 function onErrRename(status)
112 //console.log("onErrRenamed");
115 tip.show(qsTr("Authorization failed!"));
117 tip.show(qsTr("Error: ")+status);
123 //console.log("onRespNew");
124 pageStack.currentPage.init();
126 tip.show(qsTr("New folder created!"));
129 function onErrNew(status)
134 function createFilesView(nodes)
137 if(files.children.length>0) {
138 l = files.children.length;
140 files.children[i].destroy();
143 var component = Qt.createComponent("components/File.qml");
145 //console.log("l="+l);
146 for (i=0; i<l; i++) {
147 var object = component.createObject(files);
148 var ind = nodes[i].path.lastIndexOf("/");
149 object.textMax = root.width/17;
150 //console.log("ind="+ind);
152 object.name = nodes[i].path.substr(ind+1);
154 object.name = nodes[i].path;
156 object.isDirectory = nodes[i].kind == "directory";
157 object.properties = nodes[i];
158 if(object.isDirectory) {
159 object.clicked.connect(function(prop) {
160 pageStack.push("FilesPage.qml");
161 pageStack.currentPage.init(prop);
164 object.clicked.connect(function(prop) {
165 pageStack.push("PropertiesPage.qml");
166 pageStack.currentPage.init(prop);
170 if(mask.state!="defocused") {
177 onFileUploaded: init(root.properties);
183 height: parent.height
184 contentHeight: files.height+Const.SYSTEM_BAR_HEIGHT+2*Const.TEXT_MARGIN
185 y: Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
186 contentWidth: parent.width
190 spacing: Const.DEFAULT_MARGIN
193 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
197 font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
198 color: Const.DEFAULT_FOREGROUND_COLOR
201 visible: files.children.length==1
209 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
213 //console.log("selected: "+file+" "+U1.fixFolder(folder));
214 fileSelector.close();
215 Utils.setLastFolder(folder);
216 var path = content_path+"/"+file;
218 U1.uploadFile(secrets,root,path,file,folder,Utils);
223 function getParentPath(path) {
226 var ind = path.lastIndexOf("/");
228 ppath = path.substr(0,ind);
230 if(path=="") ppath = "/";
232 //console.log(ppath);
237 var l=0; var r=s.length -1;
238 while(l < s.length && s[l] == ' ')
240 while(r > l && s[r] == ' ')
242 return s.substring(l, r+1);
248 if(pageStack.currentPage==root) {
250 tip.show(qsTr("Folder was deleted!"));
252 pageStack.currentPage.init();
256 if(pageStack.currentPage==root) {
259 tip.show(qsTr("Authorization failed!"));
261 tip.show(qsTr("Error: ")+status);
270 text: qsTr("Delete folder?")
271 onOpened: mask.state = "dialog"
276 U1.deleteFile(secrets,properties.resource_path,root,Utils);
279 onCanceled: mask.state = "idle"
285 textWidth: root.width - 4*Const.DEFAULT_MARGIN
286 label: qsTr("Enter new folder name:")
287 placeholderText: root.name
290 Utils.setOrientation("auto");
291 mask.state = "dialog";
295 Utils.setOrientation(root.orientation);
299 var currentPath = root.properties.resource_path;
300 var targetPath = getParentPath(root.properties.path)+"/"+resp;
301 //console.log("targetPath: "+targetPath);
302 U1.renameFile(secrets,currentPath,targetPath,root);
304 tip.show(qsTr("Invalid folder name!"))
308 Utils.setOrientation(root.orientation);
316 textWidth: root.width - 4*Const.DEFAULT_MARGIN
317 label: qsTr("Enter new folder name:")
321 Utils.setOrientation("auto");
322 mask.state = "dialog";
326 Utils.setOrientation(root.orientation);
332 rpath = root.properties.resource_path;
334 rpath = root.resource_path;
335 var newPath = rpath+"/"+resp;
336 //console.log("newPath: "+newPath);
337 U1.newFolder(secrets,newPath,root);
339 tip.show(qsTr("Invalid folder name!"))
343 Utils.setOrientation(root.orientation);