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)
61 tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
62 } else if(status==0) {
63 tip.show(qsTr("Unable to connect. Check internet connection."));
65 tip.show(qsTr("Unknown error: ")+status);
68 console.log("index="+pageStack.index);
70 if(pageStack.index>0) {
73 pageStack.initialPage = "LoginPage.qml";
78 function onRespRename()
80 pageStack.prevPage().init();
82 tip.show(qsTr("Folder renamed!"));
85 function onErrRename(status)
89 tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
91 tip.show(qsTr("Unknown error: ")+status);
97 pageStack.currentPage.init();
99 tip.show(qsTr("New folder created!"));
102 function onErrNew(status)
107 function createFilesView(nodes)
110 if(files.children.length>0) {
111 l = files.children.length;
113 files.children[i].destroy();
116 var component = Qt.createComponent("components/File.qml");
118 for (i=0; i<l; i++) {
119 var object = component.createObject(files);
120 var ind = nodes[i].path.lastIndexOf("/");
122 object.name = nodes[i].path.substr(ind+1);
124 object.name = nodes[i].path;
126 object.isDirectory = nodes[i].kind == "directory";
127 object.properties = nodes[i];
128 if(object.isDirectory) {
129 object.clicked.connect(function(prop) {
130 pageStack.push("FilesPage.qml");
131 pageStack.currentPage.init(prop);
134 var txt = "" + Conv.bytesToSize(nodes[i].size);
135 object.description = txt;
136 object.isPublic = nodes[i].is_public;
137 object.clicked.connect(function(prop) {
138 pageStack.push("PropertiesPage.qml");
139 pageStack.currentPage.init(prop);
143 ind = object.name.lastIndexOf(".");
145 if(ind>=0) ext = object.name.substr(ind+1);
146 if(ext=="jpg" || ext=="JPG" || ext=="Jpg" ||
147 ext=="jpeg" || ext=="JPEG" || ext=="Jpeg" ||
148 ext=="gif" || ext=="GIF" || ext=="Gif" ||
149 ext=="svg" || ext=="SVG" || ext=="Svg" ||
150 ext=="png" || ext=="PNG" || ext=="Png") {
151 object.isPhoto = true;
153 if(ext=="mp3" || ext=="MP3" || ext=="Mp3" ||
154 ext=="wma" || ext=="WMA" || ext=="Wma" ||
155 ext=="wav" || ext=="WAV" || ext=="Wav" ||
156 ext=="ogg" || ext=="OGG" || ext=="Ogg" ||
157 ext=="acc" || ext=="ACC" || ext=="Acc" ||
158 ext=="m4a" || ext=="M4A" || ext=="M4a" ||
159 ext=="flac" || ext=="FLAC" || ext=="Flac") {
160 object.isMusic = true;
162 if(ext=="avi" || ext=="AVI" || ext=="Avi" ||
163 ext=="mp4" || ext=="MP4" || ext=="Mp4" ||
164 ext=="mpg" || ext=="MPG" || ext=="Mpg" ||
165 ext=="mkv" || ext=="MKV" || ext=="Mkv" ||
166 ext=="flv" || ext=="FLV" || ext=="Flv" ||
167 ext=="m4v" || ext=="M4V" || ext=="M4v" ||
168 ext=="3gp" || ext=="3GP") {
169 object.isVideo = true;
173 if(mask.state!="defocused" && mask.state!="dialog") {
178 empty.visible = true;
180 empty.visible = false;
188 onFileUploaded: init(root.properties);
194 height: parent.height
195 contentHeight: files.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
196 y: Const.TOP_BAR_HEIGHT
197 contentWidth: parent.width
202 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
209 font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
210 color: Const.DEFAULT_FOREGROUND_COLOR
212 anchors.centerIn: parent
221 folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
225 fileSelector.close();
226 Utils.setLastFolder(folder);
227 var path = content_path+"/"+file;
228 U1.uploadFile(secrets,root,path,file,folder,Utils);
232 function getParentPath(path) {
234 var ind = path.lastIndexOf("/");
236 ppath = path.substr(0,ind);
238 if(path=="") ppath = "/";
243 var l=0; var r=s.length -1;
244 while(l < s.length && s[l] == ' ')
246 while(r > l && s[r] == ' ')
248 return s.substring(l, r+1);
254 if(pageStack.currentPage==root) {
256 tip.show(qsTr("Folder was deleted!"));
258 pageStack.currentPage.init();
262 if(pageStack.currentPage==root) {
265 tip.show(qsTr("Authorization failed!"));
267 tip.show(qsTr("Error: ")+status);
276 text: qsTr("Delete folder?")
277 onOpened: mask.state = "dialog"
281 U1.deleteFile(secrets,properties.resource_path,root,Utils);
289 textWidth: root.width - 4*Const.DEFAULT_MARGIN
290 label: qsTr("Enter new folder name:")
291 placeholderText: root.name
294 Utils.setOrientation("auto");
298 Utils.setOrientation(root.orientation);
302 var currentPath = root.properties.resource_path;
303 var targetPath = getParentPath(root.properties.path)+"/"+resp;
304 U1.renameFile(secrets,currentPath,targetPath,root);
306 tip.show(qsTr("Invalid folder name!"))
310 Utils.setOrientation(root.orientation);
317 textWidth: root.width - 4*Const.DEFAULT_MARGIN
318 label: qsTr("Enter new folder name:")
322 Utils.setOrientation("auto");
325 Utils.setOrientation(root.orientation);
331 rpath = root.properties.resource_path;
333 rpath = root.resource_path;
334 var newPath = rpath+"/"+resp;
335 U1.newFolder(secrets,newPath,root);
337 tip.show(qsTr("Invalid folder name!"))
341 Utils.setOrientation(root.orientation);
350 menuDynamic: _menuDyn
351 menuHeight: menuDynamic.height+menuFixed.height+7*Const.DEFAULT_MARGIN
356 y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+2*Const.DEFAULT_MARGIN
357 x: Const.DEFAULT_MARGIN
359 width: parent.width-2*Const.DEFAULT_MARGIN
360 spacing: Const.DEFAULT_MARGIN
363 label: qsTr("Upload file");
371 label: qsTr("Rename");
375 tip.show(qsTr("Root folder cannot be renamed."));
383 label: qsTr("Delete");
387 tip.show(qsTr("Root folder cannot be deleted."));
395 label: qsTr("New folder");
403 label: qsTr("Refresh");
406 init(root.properties);