Auth bug fix
[ubi] / qml / ubi / FilesPage.qml
index 3eb523c..5a55fa8 100644 (file)
@@ -2,6 +2,7 @@ import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
 import "components"
 import Qt 4.7
 import "u1.js" as U1
+import "bytesconv.js" as Conv
 import "UIConstants.js" as Const
 
 Page {
@@ -15,44 +16,11 @@ Page {
     property string path
     property string name
 
-    menu: [
-        [qsTr("Upload file"),false],
-        [qsTr("Rename"),false],
-        [qsTr("Delete"),false],
-        [qsTr("New folder"),false],
-        [qsTr("Refresh"),false]
-    ]
-
-    function menuFun(id) {
-        if(id==qsTr("Upload file")) {
-            mask.state = "dialog";
-            fileSelector.open();
-        }
-        if(id==qsTr("Refresh")) {
-            init(root.properties);
-        }
-        if(id==qsTr("Rename")) {
-            if(root.path=="/") {
-                tip.show(qsTr("Root folder can't be renamed!"));
-            } else {
-                dialogRename.open();
-            }
-        }
-        if(id==qsTr("Delete")) {
-            if(root.path=="/") {
-                tip.show(qsTr("Root folder can't be deleted!"));
-            } else {
-                dialogDelete.open();
-            }
-        }
-        if(id==qsTr("New folder")) {
-            dialogNew.open();
-        }
-    }
+    property alias taskMenu: taskMenu
 
     function init(prop)
     {
-        if(mask.state!="defocused") {
+        if(mask.state!="defocused" && mask.state!="dialog") {
             mask.state = "busy";
         }
         if(root.properties && !prop) {
@@ -86,22 +54,29 @@ Page {
 
     function onErr(status)
     {
-        //console.log("onErr");
         mask.state = "idle";
+        initPage.hide();
+
         if(status==401) {
-            tip.show(qsTr("Authorization failed!"));
+            tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
         } else if(status==0) {
-            tip.show(qsTr("Unable to connect!"));
+            tip.show(qsTr("Unable to connect. Check internet connection."));
         } else {
-            tip.show(qsTr("Error: ")+status);
+            tip.show(qsTr("Unknown error: ")+status);
+        }
+
+        console.log("index="+pageStack.index);
+
+        if(pageStack.index>0) {
+            pageStack.pop();
+        } else {
+            pageStack.initialPage = "LoginPage.qml";
         }
-        pageStack.pop();
     }
 
 
     function onRespRename()
     {
-        //console.log("onRespRename");
         pageStack.prevPage().init();
         mask.state = "idle";
         tip.show(qsTr("Folder renamed!"));
@@ -109,18 +84,16 @@ Page {
 
     function onErrRename(status)
     {
-        //console.log("onErrRenamed");
         mask.state = "idle";
         if(status==401) {
-            tip.show(qsTr("Authorization failed!"));
+            tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
         } else {
-            tip.show(qsTr("Error: ")+status);
+            tip.show(qsTr("Unknown error: ")+status);
         }
     }
 
     function onRespNew()
     {
-        //console.log("onRespNew");
         pageStack.currentPage.init();
         mask.state = "idle";
         tip.show(qsTr("New folder created!"));
@@ -142,12 +115,9 @@ Page {
         }
         var component = Qt.createComponent("components/File.qml");
         l = nodes.length;
-        //console.log("l="+l);
         for (i=0; i<l; i++) {
             var object = component.createObject(files);
             var ind = nodes[i].path.lastIndexOf("/");
-            object.textMax = root.width/17;
-            //console.log("ind="+ind);
             if(ind>=0) {
                 object.name = nodes[i].path.substr(ind+1);
             }  else {
@@ -155,27 +125,62 @@ Page {
             }
             object.isDirectory = nodes[i].kind == "directory";
             object.properties = nodes[i];
-            object.width = root.width;
-            //object.height = 50;
             if(object.isDirectory) {
                 object.clicked.connect(function(prop) {
                             pageStack.push("FilesPage.qml");
                             pageStack.currentPage.init(prop);
                         });
             } else {
+                var txt = "" + Conv.bytesToSize(nodes[i].size);
+                object.description = txt;
+                object.isPublic = nodes[i].is_public;
                 object.clicked.connect(function(prop) {
                             pageStack.push("PropertiesPage.qml");
                             pageStack.currentPage.init(prop);
                         });
+
+                // extension
+                ind = object.name.lastIndexOf(".");
+                var ext = "";
+                if(ind>=0) ext = object.name.substr(ind+1);
+                if(ext=="jpg" || ext=="JPG" || ext=="Jpg" ||
+                   ext=="jpeg" || ext=="JPEG" || ext=="Jpeg" ||
+                   ext=="gif" || ext=="GIF" || ext=="Gif" ||
+                   ext=="svg" || ext=="SVG" || ext=="Svg" ||
+                   ext=="png" || ext=="PNG" || ext=="Png") {
+                    object.isPhoto = true;
+                }
+                if(ext=="mp3" || ext=="MP3" || ext=="Mp3" ||
+                   ext=="wma" || ext=="WMA" || ext=="Wma" ||
+                   ext=="wav" || ext=="WAV" || ext=="Wav" ||
+                   ext=="ogg" || ext=="OGG" || ext=="Ogg" ||
+                   ext=="acc" || ext=="ACC" || ext=="Acc" ||
+                   ext=="m4a" || ext=="M4A" || ext=="M4a" ||
+                   ext=="flac" || ext=="FLAC" || ext=="Flac") {
+                    object.isMusic = true;
+                }
+                if(ext=="avi" || ext=="AVI" || ext=="Avi" ||
+                   ext=="mp4" || ext=="MP4" || ext=="Mp4" ||
+                   ext=="mpg" || ext=="MPG" || ext=="Mpg" ||
+                   ext=="mkv" || ext=="MKV" || ext=="Mkv" ||
+                   ext=="flv" || ext=="FLV" || ext=="Flv" ||
+                   ext=="m4v" || ext=="M4V" || ext=="M4v" ||
+                   ext=="3gp" || ext=="3GP") {
+                    object.isVideo = true;
+                }
             }
         }
-        if(mask.state!="defocused") {
+        if(mask.state!="defocused" && mask.state!="dialog") {
             mask.state = "idle";
         }
 
-        if(files.children.length==0) {
+        if(l==0) {
             empty.visible = true;
+        } else {
+            empty.visible = false;
         }
+
+        initPage.hide()
     }
 
     Connections {
@@ -187,15 +192,12 @@ Page {
         id: flickable
         width: parent.width
         height: parent.height
-        contentHeight: files.height+Const.SYSTEM_BAR_HEIGHT+2*Const.TEXT_MARGIN
-        //y: Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
-        y: Const.SYSTEM_BAR_HEIGHT+Const.DEFAULT_MARGIN
+        contentHeight: files.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
+        y: Const.TOP_BAR_HEIGHT
         contentWidth: parent.width
 
         Column {
             id: files
-            //spacing: Const.DEFAULT_MARGIN
-            //x: Const.TEXT_MARGIN
             add: Transition {
                 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
             }
@@ -206,39 +208,34 @@ Page {
         id: empty
         font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
         color: Const.DEFAULT_FOREGROUND_COLOR
-        text: qsTr("Folder is empty.")
+        text: qsTr("Empty")
         anchors.centerIn: parent
         font.italic: true
         visible: false
     }
 
-    FileSelector {
+    FileDialog {
         id: fileSelector
         z: 200
+        hidden: true
         folder: Utils.lastFolder()=="" ? Const.DEFAULT_FOLDER : Utils.lastFolder()
         folderOnly: false
         onFileSelected: {
             mask.state = "idle";
-            //console.log("selected: "+file+" "+U1.fixFolder(folder));
             fileSelector.close();
             Utils.setLastFolder(folder);
             var path = content_path+"/"+file;
-            //console.log(path);
             U1.uploadFile(secrets,root,path,file,folder,Utils);
         }
-
     }
 
     function getParentPath(path) {
-        //console.log(path);
         var ppath;
         var ind = path.lastIndexOf("/");
         if(ind>=0) {
             ppath = path.substr(0,ind);
         }
         if(path=="") ppath = "/";
-
-        //console.log(ppath);
         return ppath;
     }
 
@@ -279,13 +276,11 @@ Page {
         text: qsTr("Delete folder?")
         onOpened: mask.state = "dialog"
         onClosed: {
-            mask.state = "idle";
             if(ok) {
                 mask.state = "busy";
                 U1.deleteFile(secrets,properties.resource_path,root,Utils);
             }
         }
-        onCanceled: mask.state = "idle"
     }
 
     DialogInput {
@@ -297,7 +292,6 @@ Page {
         onOpened: {
             reset();
             Utils.setOrientation("auto");
-            mask.state = "dialog";
         }
         onClosed: {
             mask.state = "idle";
@@ -307,7 +301,6 @@ Page {
                 mask.state = "busy";
                 var currentPath = root.properties.resource_path;
                 var targetPath = getParentPath(root.properties.path)+"/"+resp;
-                //console.log("targetPath: "+targetPath);
                 U1.renameFile(secrets,currentPath,targetPath,root);
             } else {
                 tip.show(qsTr("Invalid folder name!"))
@@ -315,7 +308,6 @@ Page {
         }
         onCanceled: {
             Utils.setOrientation(root.orientation);
-            mask.state = "idle";
         }
     }
 
@@ -328,10 +320,8 @@ Page {
         onOpened: {
             reset();
             Utils.setOrientation("auto");
-            mask.state = "dialog";
         }
         onClosed: {
-            mask.state = "idle";
             Utils.setOrientation(root.orientation);
             var r = trim(resp);
             if(r!="") {
@@ -342,7 +332,6 @@ Page {
                 else
                     rpath = root.resource_path;
                 var newPath = rpath+"/"+resp;
-                //console.log("newPath: "+newPath);
                 U1.newFolder(secrets,newPath,root);
             } else {
                 tip.show(qsTr("Invalid folder name!"))
@@ -350,7 +339,73 @@ Page {
         }
         onCanceled: {
             Utils.setOrientation(root.orientation);
-            mask.state = "idle";
+        }
+    }
+
+    TaskMenu {
+        z: 200
+        id: taskMenu
+
+        contexMenu: true
+        menuDynamic: _menuDyn
+        menuHeight: menuDynamic.height+menuFixed.height+7*Const.DEFAULT_MARGIN
+
+        Flow {
+            id: _menuDyn
+
+            y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+2*Const.DEFAULT_MARGIN
+            x: Const.DEFAULT_MARGIN
+
+            width: parent.width-2*Const.DEFAULT_MARGIN
+            spacing: Const.DEFAULT_MARGIN
+
+            Button {
+                label: qsTr("Upload file");
+                onButtonClicked: {
+                    taskMenu.close();
+                    fileSelector.open();
+                }
+            }
+
+            Button {
+                label: qsTr("Rename");
+                onButtonClicked: {
+                    taskMenu.close();
+                    if(root.path=="/") {
+                        tip.show(qsTr("Root folder cannot be renamed."));
+                    } else {
+                        dialogRename.open();
+                    }
+                }
+            }
+
+            Button {
+                label: qsTr("Delete");
+                onButtonClicked: {
+                    taskMenu.close();
+                    if(root.path=="/") {
+                        tip.show(qsTr("Root folder cannot be deleted."));
+                    } else {
+                        dialogDelete.open();
+                    }
+                }
+            }
+
+            Button {
+                label: qsTr("New folder");
+                onButtonClicked: {
+                    taskMenu.close();
+                    dialogNew.open();
+                }
+            }
+
+            Button {
+                label: qsTr("Refresh");
+                onButtonClicked: {
+                    taskMenu.close();
+                    init(root.properties);
+                }
+            }
         }
     }
 }