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 object.width = root.width;
159 //object.height = 50;
160 if(object.isDirectory) {
161 object.clicked.connect(function(prop) {
162 pageStack.push("FilesPage.qml");
163 pageStack.currentPage.init(prop);
166 object.clicked.connect(function(prop) {
167 pageStack.push("PropertiesPage.qml");
168 pageStack.currentPage.init(prop);
172 if(mask.state!="defocused") {
176 if(files.children.length==0) {
177 empty.visible = true;
183 onFileUploaded: init(root.properties);
189 height: parent.height
190 contentHeight: files.height+Const.SYSTEM_BAR_HEIGHT+2*Const.TEXT_MARGIN
191 //y: Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
192 y: Const.SYSTEM_BAR_HEIGHT+Const.DEFAULT_MARGIN
193 contentWidth: parent.width
197 //spacing: Const.DEFAULT_MARGIN
198 //x: Const.TEXT_MARGIN
200 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
207 font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
208 color: Const.DEFAULT_FOREGROUND_COLOR
209 text: qsTr("Folder is empty.")
210 anchors.centerIn: parent
218 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
222 //console.log("selected: "+file+" "+U1.fixFolder(folder));
223 fileSelector.close();
224 Utils.setLastFolder(folder);
225 var path = content_path+"/"+file;
227 U1.uploadFile(secrets,root,path,file,folder,Utils);
232 function getParentPath(path) {
235 var ind = path.lastIndexOf("/");
237 ppath = path.substr(0,ind);
239 if(path=="") ppath = "/";
241 //console.log(ppath);
246 var l=0; var r=s.length -1;
247 while(l < s.length && s[l] == ' ')
249 while(r > l && s[r] == ' ')
251 return s.substring(l, r+1);
257 if(pageStack.currentPage==root) {
259 tip.show(qsTr("Folder was deleted!"));
261 pageStack.currentPage.init();
265 if(pageStack.currentPage==root) {
268 tip.show(qsTr("Authorization failed!"));
270 tip.show(qsTr("Error: ")+status);
279 text: qsTr("Delete folder?")
280 onOpened: mask.state = "dialog"
285 U1.deleteFile(secrets,properties.resource_path,root,Utils);
288 onCanceled: mask.state = "idle"
294 textWidth: root.width - 4*Const.DEFAULT_MARGIN
295 label: qsTr("Enter new folder name:")
296 placeholderText: root.name
299 Utils.setOrientation("auto");
300 mask.state = "dialog";
304 Utils.setOrientation(root.orientation);
308 var currentPath = root.properties.resource_path;
309 var targetPath = getParentPath(root.properties.path)+"/"+resp;
310 //console.log("targetPath: "+targetPath);
311 U1.renameFile(secrets,currentPath,targetPath,root);
313 tip.show(qsTr("Invalid folder name!"))
317 Utils.setOrientation(root.orientation);
325 textWidth: root.width - 4*Const.DEFAULT_MARGIN
326 label: qsTr("Enter new folder name:")
330 Utils.setOrientation("auto");
331 mask.state = "dialog";
335 Utils.setOrientation(root.orientation);
341 rpath = root.properties.resource_path;
343 rpath = root.resource_path;
344 var newPath = rpath+"/"+resp;
345 //console.log("newPath: "+newPath);
346 U1.newFolder(secrets,newPath,root);
348 tip.show(qsTr("Invalid folder name!"))
352 Utils.setOrientation(root.orientation);