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
1=== modified file 'src/app/qml/ui/FolderListPage.qml'
2--- src/app/qml/ui/FolderListPage.qml 2014-12-10 18:34:09 +0000
3+++ src/app/qml/ui/FolderListPage.qml 2014-12-10 18:34:09 +0000
4@@ -14,6 +14,7 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by: Arto Jalkanen <ajalkane@gmail.com>
8+ * Niklas Wenzel <nikwen.developer@gmail.com>
9 */
10 import QtQuick 2.3
11 import Ubuntu.Components 1.1
12@@ -370,6 +371,18 @@
13 visible: viewMethod === i18n.tr("List")
14 }
15
16+ function getArchiveType(fileName) {
17+ var splitName = fileName.split(".")
18+ var fileExtension = splitName[splitName.length - 1]
19+ if (fileExtension === "zip") {
20+ return "zip"
21+ } else if (fileExtension === "tar") {
22+ return "tar"
23+ } else {
24+ return ""
25+ }
26+ }
27+
28 Item {
29 id: contents
30
31@@ -459,34 +472,7 @@
32 text: i18n.tr("Are you sure you want to extract '%1' here?").arg(fileName)
33
34 onAccepted: {
35- console.log("Extract accepted for filePath, fileName", filePath, fileName)
36- PopupUtils.open(extractingDialog, mainView, { "fileName" : fileName })
37- console.log("Extracting...")
38-
39- var parentDirectory = filePath.substring(0, filePath.lastIndexOf("/"))
40- var fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."))
41- var extractDirectory = parentDirectory + "/" + fileNameWithoutExtension
42-
43- // Add numbers if the directory already exist: myfile, myfile-1, myfile-2, etc.
44- while (pageModel.existsDir(extractDirectory)) {
45- var i = 0
46- while ("1234567890".indexOf(extractDirectory.charAt(extractDirectory.length - i - 1)) !== -1) {
47- i++
48- }
49- if (i === 0 || extractDirectory.charAt(extractDirectory.length - i - 1) !== "-") {
50- extractDirectory += "-1"
51- } else {
52- extractDirectory = extractDirectory.substring(0, extractDirectory.lastIndexOf("-") + 1) + (parseInt(extractDirectory.substring(extractDirectory.length - i)) + 1)
53- }
54- }
55-
56- pageModel.mkdir(extractDirectory) // This is needed for the tar command as the given destination has to be an already existing directory
57-
58- if (archiveType === "zip") {
59- archives.extractZip(filePath, extractDirectory)
60- } else if (archiveType === "tar") {
61- archives.extractTar(filePath, extractDirectory)
62- }
63+ extractArchive(filePath, fileName, archiveType)
64 }
65 }
66 }
67@@ -510,15 +496,7 @@
68 property string archiveType: ""
69
70 Component.onCompleted: {
71- var splitName = actionSelectionPopover.model.fileName.split(".")
72- var fileExtension = splitName[splitName.length - 1]
73- if (fileExtension === "zip") {
74- archiveType = "zip"
75- } else if (fileExtension === "tar") {
76- archiveType = "tar"
77- } else {
78- archiveType = ""
79- }
80+ archiveType = getArchiveType(actionSelectionPopover.model.fileName)
81 }
82
83 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)
84@@ -688,6 +666,49 @@
85 }
86 }
87
88+ Component {
89+ id: openArchiveDialog
90+
91+ Dialog {
92+ id: dialog
93+ modal: true
94+ title: i18n.tr("Archive file")
95+ text: i18n.tr("Do you want to extract the archive here?")
96+ property string filePath
97+ property string fileName
98+ property string archiveType
99+
100+ Button {
101+ id: extractButton
102+ text: i18n.tr("Extract archive")
103+ color: UbuntuColors.green
104+ onClicked: {
105+ PopupUtils.close(dialog)
106+ extractArchive(filePath, fileName, archiveType)
107+ }
108+ }
109+
110+ Button {
111+ id: openExternallyButton
112+ text: i18n.tr("Open with another app")
113+ color: UbuntuColors.red
114+ onClicked: {
115+ PopupUtils.close(dialog)
116+ openFile(filePath)
117+ }
118+ }
119+
120+ Button {
121+ id: cancelButton
122+ text: i18n.tr("Cancel")
123+ color: UbuntuColors.lightGrey
124+ onClicked: {
125+ PopupUtils.close(dialog)
126+ }
127+ }
128+ }
129+ }
130+
131 function goTo(location) {
132 // This allows us to enter "~" as a shortcut to the home folder
133 // when entering a location on the Go To dialog
134@@ -847,7 +868,18 @@
135 false,
136 true);
137 } else {
138- openFile(model.filePath)
139+ // Check if file is an archive. If yes, ask the user whether he wants to extract it
140+ var archiveType = getArchiveType(model.fileName)
141+ if (archiveType === "") {
142+ openFile(model.filePath)
143+ } else {
144+ PopupUtils.open(openArchiveDialog, folderListView,
145+ { "filePath" : model.filePath,
146+ "fileName" : model.fileName,
147+ "archiveType" : archiveType
148+ })
149+ }
150+
151 }
152 // PopupUtils.open(Qt.resolvedUrl("FileActionDialog.qml"), root,
153 // {
154@@ -875,6 +907,37 @@
155 return false;
156 }
157
158+ function extractArchive(filePath, fileName, archiveType) {
159+ console.log("Extract accepted for filePath, fileName", filePath, fileName)
160+ PopupUtils.open(extractingDialog, mainView, { "fileName" : fileName })
161+ console.log("Extracting...")
162+
163+ var parentDirectory = filePath.substring(0, filePath.lastIndexOf("/"))
164+ var fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."))
165+ var extractDirectory = parentDirectory + "/" + fileNameWithoutExtension
166+
167+ // Add numbers if the directory already exist: myfile, myfile-1, myfile-2, etc.
168+ while (pageModel.existsDir(extractDirectory)) {
169+ var i = 0
170+ while ("1234567890".indexOf(extractDirectory.charAt(extractDirectory.length - i - 1)) !== -1) {
171+ i++
172+ }
173+ if (i === 0 || extractDirectory.charAt(extractDirectory.length - i - 1) !== "-") {
174+ extractDirectory += "-1"
175+ } else {
176+ extractDirectory = extractDirectory.substring(0, extractDirectory.lastIndexOf("-") + 1) + (parseInt(extractDirectory.substring(extractDirectory.length - i)) + 1)
177+ }
178+ }
179+
180+ pageModel.mkdir(extractDirectory) // This is needed for the tar command as the given destination has to be an already existing directory
181+
182+ if (archiveType === "zip") {
183+ archives.extractZip(filePath, extractDirectory)
184+ } else if (archiveType === "tar") {
185+ archives.extractTar(filePath, extractDirectory)
186+ }
187+ }
188+
189 Component.onCompleted: {
190 forceActiveFocus()
191 }

Subscribers

People subscribed via source and target branches