Merge lp:~nikwen/ubuntu-filemanager-app/select-archive-fix into lp:ubuntu-filemanager-app

Proposed by Niklas Wenzel
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 323
Merged at revision: 353
Proposed branch: lp:~nikwen/ubuntu-filemanager-app/select-archive-fix
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~nikwen/ubuntu-filemanager-app/tars
Diff against target: 191 lines (+101/-38)
1 file modified
src/app/qml/ui/FolderListPage.qml (+101/-38)
To merge this branch: bzr merge lp:~nikwen/ubuntu-filemanager-app/select-archive-fix
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+244342@code.launchpad.net

Commit message

Added a dialog which is shown when the user clicks on an archive file. It allows him to select whether he wants to extract the archive or open it with another app.

Description of the change

Added a dialog which is shown when the user clicks on an archive file. It allows him to select whether he wants to extract the archive or open it with another app.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Looks good to me. Thank you!

review: Approve
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thanks for merging. :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/qml/ui/FolderListPage.qml'
--- src/app/qml/ui/FolderListPage.qml 2014-12-10 18:34:09 +0000
+++ src/app/qml/ui/FolderListPage.qml 2014-12-10 18:34:09 +0000
@@ -14,6 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15 *
16 * Authored by: Arto Jalkanen <ajalkane@gmail.com>16 * Authored by: Arto Jalkanen <ajalkane@gmail.com>
17 * Niklas Wenzel <nikwen.developer@gmail.com>
17 */18 */
18import QtQuick 2.319import QtQuick 2.3
19import Ubuntu.Components 1.120import Ubuntu.Components 1.1
@@ -370,6 +371,18 @@
370 visible: viewMethod === i18n.tr("List")371 visible: viewMethod === i18n.tr("List")
371 }372 }
372373
374 function getArchiveType(fileName) {
375 var splitName = fileName.split(".")
376 var fileExtension = splitName[splitName.length - 1]
377 if (fileExtension === "zip") {
378 return "zip"
379 } else if (fileExtension === "tar") {
380 return "tar"
381 } else {
382 return ""
383 }
384 }
385
373 Item {386 Item {
374 id: contents387 id: contents
375388
@@ -459,34 +472,7 @@
459 text: i18n.tr("Are you sure you want to extract '%1' here?").arg(fileName)472 text: i18n.tr("Are you sure you want to extract '%1' here?").arg(fileName)
460473
461 onAccepted: {474 onAccepted: {
462 console.log("Extract accepted for filePath, fileName", filePath, fileName)475 extractArchive(filePath, fileName, archiveType)
463 PopupUtils.open(extractingDialog, mainView, { "fileName" : fileName })
464 console.log("Extracting...")
465
466 var parentDirectory = filePath.substring(0, filePath.lastIndexOf("/"))
467 var fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."))
468 var extractDirectory = parentDirectory + "/" + fileNameWithoutExtension
469
470 // Add numbers if the directory already exist: myfile, myfile-1, myfile-2, etc.
471 while (pageModel.existsDir(extractDirectory)) {
472 var i = 0
473 while ("1234567890".indexOf(extractDirectory.charAt(extractDirectory.length - i - 1)) !== -1) {
474 i++
475 }
476 if (i === 0 || extractDirectory.charAt(extractDirectory.length - i - 1) !== "-") {
477 extractDirectory += "-1"
478 } else {
479 extractDirectory = extractDirectory.substring(0, extractDirectory.lastIndexOf("-") + 1) + (parseInt(extractDirectory.substring(extractDirectory.length - i)) + 1)
480 }
481 }
482
483 pageModel.mkdir(extractDirectory) // This is needed for the tar command as the given destination has to be an already existing directory
484
485 if (archiveType === "zip") {
486 archives.extractZip(filePath, extractDirectory)
487 } else if (archiveType === "tar") {
488 archives.extractTar(filePath, extractDirectory)
489 }
490 }476 }
491 }477 }
492 }478 }
@@ -510,15 +496,7 @@
510 property string archiveType: ""496 property string archiveType: ""
511497
512 Component.onCompleted: {498 Component.onCompleted: {
513 var splitName = actionSelectionPopover.model.fileName.split(".")499 archiveType = getArchiveType(actionSelectionPopover.model.fileName)
514 var fileExtension = splitName[splitName.length - 1]
515 if (fileExtension === "zip") {
516 archiveType = "zip"
517 } else if (fileExtension === "tar") {
518 archiveType = "tar"
519 } else {
520 archiveType = ""
521 }
522 }500 }
523501
524 delegate: Empty { // NOTE: This is a workaround for LP: #1395118 and should be removed as soon as the patch for upstream gets released (https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1395118)502 delegate: Empty { // NOTE: This is a workaround for LP: #1395118 and should be removed as soon as the patch for upstream gets released (https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1395118)
@@ -688,6 +666,49 @@
688 }666 }
689 }667 }
690668
669 Component {
670 id: openArchiveDialog
671
672 Dialog {
673 id: dialog
674 modal: true
675 title: i18n.tr("Archive file")
676 text: i18n.tr("Do you want to extract the archive here?")
677 property string filePath
678 property string fileName
679 property string archiveType
680
681 Button {
682 id: extractButton
683 text: i18n.tr("Extract archive")
684 color: UbuntuColors.green
685 onClicked: {
686 PopupUtils.close(dialog)
687 extractArchive(filePath, fileName, archiveType)
688 }
689 }
690
691 Button {
692 id: openExternallyButton
693 text: i18n.tr("Open with another app")
694 color: UbuntuColors.red
695 onClicked: {
696 PopupUtils.close(dialog)
697 openFile(filePath)
698 }
699 }
700
701 Button {
702 id: cancelButton
703 text: i18n.tr("Cancel")
704 color: UbuntuColors.lightGrey
705 onClicked: {
706 PopupUtils.close(dialog)
707 }
708 }
709 }
710 }
711
691 function goTo(location) {712 function goTo(location) {
692 // This allows us to enter "~" as a shortcut to the home folder713 // This allows us to enter "~" as a shortcut to the home folder
693 // when entering a location on the Go To dialog714 // when entering a location on the Go To dialog
@@ -847,7 +868,18 @@
847 false,868 false,
848 true);869 true);
849 } else {870 } else {
850 openFile(model.filePath)871 // Check if file is an archive. If yes, ask the user whether he wants to extract it
872 var archiveType = getArchiveType(model.fileName)
873 if (archiveType === "") {
874 openFile(model.filePath)
875 } else {
876 PopupUtils.open(openArchiveDialog, folderListView,
877 { "filePath" : model.filePath,
878 "fileName" : model.fileName,
879 "archiveType" : archiveType
880 })
881 }
882
851 }883 }
852 // PopupUtils.open(Qt.resolvedUrl("FileActionDialog.qml"), root,884 // PopupUtils.open(Qt.resolvedUrl("FileActionDialog.qml"), root,
853 // {885 // {
@@ -875,6 +907,37 @@
875 return false;907 return false;
876 }908 }
877909
910 function extractArchive(filePath, fileName, archiveType) {
911 console.log("Extract accepted for filePath, fileName", filePath, fileName)
912 PopupUtils.open(extractingDialog, mainView, { "fileName" : fileName })
913 console.log("Extracting...")
914
915 var parentDirectory = filePath.substring(0, filePath.lastIndexOf("/"))
916 var fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."))
917 var extractDirectory = parentDirectory + "/" + fileNameWithoutExtension
918
919 // Add numbers if the directory already exist: myfile, myfile-1, myfile-2, etc.
920 while (pageModel.existsDir(extractDirectory)) {
921 var i = 0
922 while ("1234567890".indexOf(extractDirectory.charAt(extractDirectory.length - i - 1)) !== -1) {
923 i++
924 }
925 if (i === 0 || extractDirectory.charAt(extractDirectory.length - i - 1) !== "-") {
926 extractDirectory += "-1"
927 } else {
928 extractDirectory = extractDirectory.substring(0, extractDirectory.lastIndexOf("-") + 1) + (parseInt(extractDirectory.substring(extractDirectory.length - i)) + 1)
929 }
930 }
931
932 pageModel.mkdir(extractDirectory) // This is needed for the tar command as the given destination has to be an already existing directory
933
934 if (archiveType === "zip") {
935 archives.extractZip(filePath, extractDirectory)
936 } else if (archiveType === "tar") {
937 archives.extractTar(filePath, extractDirectory)
938 }
939 }
940
878 Component.onCompleted: {941 Component.onCompleted: {
879 forceActiveFocus()942 forceActiveFocus()
880 }943 }

Subscribers

People subscribed via source and target branches