← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~renatofilho/ubuntu-filemanager-app/import-contact into lp:ubuntu-filemanager-app

 

Renato Araujo Oliveira Filho has proposed merging lp:~renatofilho/ubuntu-filemanager-app/import-contact into lp:ubuntu-filemanager-app.

Requested reviews:
  Ubuntu File Manager Developers (ubuntu-filemanager-dev)

For more details, see:
https://code.launchpad.net/~renatofilho/ubuntu-filemanager-app/import-contact/+merge/300087
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~renatofilho/ubuntu-filemanager-app/import-contact into lp:ubuntu-filemanager-app.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2016-03-10 22:37:45 +0000
+++ CMakeLists.txt	2016-07-14 15:05:34 +0000
@@ -18,7 +18,7 @@
 set(ICON_FILE filemanager64.png)
 set(AUTOPILOT_DIR ${APP_NAME})
 set(EXEC "${APP_NAME}")
-set(CONTENT_HUB_EXPORTER hub-exporter.json)
+set(CONTENT_HUB_JSON content-hub.json)
 set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")
 
 # global FILE definitions for stat system call, it works for any sub module
@@ -71,7 +71,7 @@
 
     add_custom_target(com_ubuntu_calendar_CLICKFiles ALL SOURCES ${CLICK_FILES})
 
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json filemanager.apparmor ${CONTENT_HUB_EXPORTER} DESTINATION ${CMAKE_INSTALL_PREFIX})
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json filemanager.apparmor ${CONTENT_HUB_JSON} DESTINATION ${CMAKE_INSTALL_PREFIX})
 
         set(UPSTREAM_LIBS_DIR ${CMAKE_BINARY_DIR}/upstream-libs)
 

=== renamed file 'hub-exporter.json' => 'content-hub.json'
--- hub-exporter.json	2014-10-30 21:20:11 +0000
+++ content-hub.json	2016-07-14 15:05:34 +0000
@@ -1,4 +1,10 @@
 {
+    "destination": [
+        "contacts"
+    ],
+    "share": [
+        "contacts"
+    ],
     "source": [
         "pictures",
         "documents",

=== modified file 'manifest.json.in'
--- manifest.json.in	2016-04-07 17:27:53 +0000
+++ manifest.json.in	2016-07-14 15:05:34 +0000
@@ -7,7 +7,7 @@
         "filemanager": {
             "apparmor": "filemanager.apparmor",
             "desktop": "com.ubuntu.filemanager.desktop",
-            "content-hub": "hub-exporter.json"
+            "content-hub": "content-hub.json"
         }
     },
     "icon": "filemanager64.png",

=== modified file 'src/app/qml/filemanager.qml'
--- src/app/qml/filemanager.qml	2016-03-16 16:15:41 +0000
+++ src/app/qml/filemanager.qml	2016-07-14 15:05:34 +0000
@@ -58,6 +58,7 @@
         id: fileSelector
         property var activeTransfer: null
         property var fileSelectorComponent: null
+        property bool importMode: false
     }
 
     Component {
@@ -101,8 +102,9 @@
         tabs.selectedTabIndex = 0
     }
 
-    function openFileSelector() {
-        pageStack.push(fileSelectorComponent, { fileSelectorMode: true} )
+    function openFileSelector(selectFolderMode) {
+        fileSelector.fileSelectorComponent = pageStack.push(fileSelectorComponent, { fileSelectorMode: !selectFolderMode,
+                                                                                     folderSelectorMode: selectFolderMode })
     }
 
     function cancelFileSelector() {
@@ -114,29 +116,60 @@
 
     function acceptFileSelector(fileUrls) {
         console.log("accept file selector " + fileUrls)
-        var results = fileUrls.map(function(fileUrl) {
+        if (fileSelector.importMode) {
+            importFiles(fileSelector.activeTransfer, fileUrls[0])
+        }
+        else
+        {
+            exportFiles(fileSelector.activeTransfer, fileUrls)
+        }
+    }
+
+    function openLocalFile(filePath) {
+        pageStack.push(Qt.resolvedUrl("content-hub/FileOpener.qml"), { fileUrl: "file://" + filePath} )
+    }
+
+    function startImport(activeTransfer) {
+        if (activeTransfer.state === ContentTransfer.Charged) {
+            fileSelector.activeTransfer = activeTransfer
+            fileSelector.importMode = true
+            openFileSelector(true)
+        }
+    }
+
+    function importFiles(activeTransfer, destDir) {
+        for(var i=0; i < activeTransfer.items.length; i++) {
+            var item = activeTransfer.items[i]
+            var uniqueName = fileSelector.fileSelectorComponent.newFileUniqueName(destDir,
+                                                                                  fileSelector.fileSelectorComponent.basename(String(item.url)))
+            console.log("Move file to:" + destDir + " with name: " + uniqueName)
+            activeTransfer.items[i].move(destDir, uniqueName)
+        }
+        finishImport(destDir)
+    }
+
+    function exportFiles(activeTransfer, filesUrls) {
+        var results = filesUrls.map(function(fileUrl) {
             return fileSelectorResultComponent.createObject(mainView, {"url": fileUrl})
         })
 
-        if (fileSelector.activeTransfer !== null) {
-            fileSelector.activeTransfer.items = results
-            fileSelector.activeTransfer.state = ContentTransfer.Charged
+        if (activeTransfer !== null) {
+            activeTransfer.items = results
+            activeTransfer.state = ContentTransfer.Charged
             console.log("set activeTransfer")
         } else {
             console.log("activeTransfer null, not setting, testing code")
         }
     }
 
-    function openLocalFile(filePath) {
-        pageStack.push(Qt.resolvedUrl("content-hub/FileOpener.qml"), { fileUrl: "file://" + filePath} )
-    }
-
     Connections {
         target: ContentHub
         onExportRequested: {
             fileSelector.activeTransfer = transfer
-            openFileSelector()
+            openFileSelector(false)
         }
+        onImportRequested: startImport(transfer)
+        onShareRequested: startImport(transfer)
     }
 
     Component {
@@ -275,6 +308,16 @@
                         })
     }
 
+    function finishImport(folder) {
+        pageStack.pop()
+        fileSelector.fileSelectorComponent = null
+        PopupUtils.open(Qt.resolvedUrl("./ui/NotifyDialog.qml"), mainView,
+                        {
+                            title: i18n.tr("Files imported"),
+                            text: i18n.tr("Files imported into: " + folder)
+                        })
+    }
+
     Keys.onPressed: {
         print("Key pressed!")
         event.accepted = tabs.currentPage.keyPressed(event.key, event.modifiers)

=== modified file 'src/app/qml/ui/FolderListPage.qml'
--- src/app/qml/ui/FolderListPage.qml	2016-06-05 06:58:11 +0000
+++ src/app/qml/ui/FolderListPage.qml	2016-07-14 15:05:34 +0000
@@ -160,6 +160,8 @@
 
     // Set to true if called as file selector for ContentHub
     property bool fileSelectorMode: false
+    property bool folderSelectorMode: false
+    readonly property bool selectionMode: fileSelectorMode || folderSelectorMode
 
     property FolderListSelection selectionManager: pageModel.selectionObject()
 
@@ -343,26 +345,30 @@
         width: parent.width - sidebar.width
 
         spacing: units.gu(2)
-        visible: fileSelectorMode || pageModel.onlyAllowedPaths
+        visible: selectionMode || pageModel.onlyAllowedPaths
 
         Button {
             text: i18n.tr("Select")
-            enabled: selectionManager.counter > 0
-            visible: fileSelectorMode
+            enabled: (selectionManager.counter > 0) || folderSelectorMode
+            visible: selectionMode
             onClicked: {
-                var selectedAbsPaths = selectionManager.selectedAbsFilePaths();
-                // For now support only selection in filesystem
-                var selectedAbsUrls = selectedAbsPaths.map(function(item) {
-                    return "file://" + item;
-                });
+                var selectedAbsUrls = []
+                if (folderSelectorMode) {
+                    selectedAbsUrls = [ folder ]
+                } else {
+                    var selectedAbsPaths = selectionManager.selectedAbsFilePaths();
+                    // For now support only selection in filesystem
+                    selectedAbsUrls = selectedAbsPaths.map(function(item) {
+                        return "file://" + item;
+                    });
+                }
                 console.log("FileSelector OK clicked, selected items: " + selectedAbsUrls)
-
                 acceptFileSelector(selectedAbsUrls)
             }
         }
         Button {
             text: i18n.tr("Cancel")
-            visible: fileSelectorMode
+            visible: selectionMode
             onClicked: {
                 console.log("FileSelector cancelled")
                 cancelFileSelector()
@@ -948,6 +954,7 @@
                 console.log("Changing to dir", model.filePath)
                 //prefer pageModel.cdIntoIndex() because it is not necessary to parse the path
                 //goTo(model.filePath)
+                folder = model.filePath
                 pageModel.cdIntoIndex(model.index)
             } else {
                 PopupUtils.open(Qt.resolvedUrl("NotifyDialog.qml"), delegate,
@@ -962,7 +969,7 @@
             console.log("Non dir clicked")
             if (fileSelectorMode) {
                 selectionManager.select(model.index,false,true)
-            } else {
+            } else if (!folderSelectorMode){
                 openFile(model)
             }
         }
@@ -1022,6 +1029,19 @@
         }
     }
 
+    function newFileUniqueName(filePath, fileName) {
+        var fileBaseName = fileName.substring(0, fileName.lastIndexOf("."))
+        var fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1)
+        var fullName = filePath + "/" + fileName
+        var index = 1
+
+        while (pageModel.existsFile(fullName)) {
+            fullName = filePath + "/" + fileBaseName + "-" + index + "." + fileExtension;
+        }
+
+        return fullName.substring(fullName.lastIndexOf("/") + 1);
+    }
+
     Component.onCompleted: {
         forceActiveFocus()
     }

=== modified file 'ubuntu-filemanager-app.json'
--- ubuntu-filemanager-app.json	2014-08-01 02:41:53 +0000
+++ ubuntu-filemanager-app.json	2016-07-14 15:05:34 +0000
@@ -4,5 +4,5 @@
         "content_exchange_source",
         "content_exchange"
     ],
-    "policy_version": 1
-}
\ No newline at end of file
+    "policy_version": 1.3
+}


Follow ups