Merge lp:~ajalkane/ubuntu-filemanager-app/open-files-using-content-hub into lp:ubuntu-filemanager-app

Proposed by Arto Jalkanen
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 306
Merged at revision: 307
Proposed branch: lp:~ajalkane/ubuntu-filemanager-app/open-files-using-content-hub
Merge into: lp:ubuntu-filemanager-app
Diff against target: 186 lines (+148/-6)
4 files modified
src/app/qml/content-hub/FileOpener.qml (+71/-0)
src/app/qml/content-hub/contenttyperesolver.js (+73/-0)
src/app/qml/filemanager.qml (+4/-0)
src/app/qml/ui/FolderListPage.qml (+0/-6)
To merge this branch: bzr merge lp:~ajalkane/ubuntu-filemanager-app/open-files-using-content-hub
Reviewer Review Type Date Requested Status
Carlos Jose Mazieri Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+239321@code.launchpad.net

Commit message

Using Content-Hub to open clicked files. Contains hard-coded mappings between file-extensions and ContentHub's ContentTypes. In future, when ContentHub supports MIME types, this can be improved.

Description of the change

Using Content-Hub to open clicked files. Contains hard-coded mappings between file-extensions and ContentHub's ContentTypes. In future, when ContentHub supports MIME types, this can be improved.

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
Carlos Jose Mazieri (carlos-mazieri) wrote :

Great, very good job.

Thanks.

review: Approve
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Great, very good job.

Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'src/app/qml/content-hub'
=== added file 'src/app/qml/content-hub/FileOpener.qml'
--- src/app/qml/content-hub/FileOpener.qml 1970-01-01 00:00:00 +0000
+++ src/app/qml/content-hub/FileOpener.qml 2014-10-22 22:05:43 +0000
@@ -0,0 +1,71 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Arto Jalkanen <ajalkane@gmail.com>
17 */
18import QtQuick 2.0
19import Ubuntu.Components 1.1
20
21import Ubuntu.Content 0.1
22
23import "contenttyperesolver.js" as Resolver
24
25Page {
26 id: root
27 title: i18n.tr("Open with")
28
29 property var activeTransfer
30
31 property string fileUrl
32
33 Component.onCompleted: {
34 var contentType = Resolver.resolveContentType(fileUrl)
35 console.log("Resolved contenttype: " + contentType)
36 peerPicker.contentType = contentType
37 }
38
39 Component {
40 id: resultComponent
41 ContentItem {}
42 }
43
44 function __exportItems(url) {
45 if (root.activeTransfer.state === ContentTransfer.InProgress)
46 {
47 root.activeTransfer.items = [ resultComponent.createObject(root, {"url": url}) ];
48 root.activeTransfer.state = ContentTransfer.Charged;
49 }
50 }
51 ContentPeerPicker {
52 id: peerPicker
53 showTitle: false
54
55 // Type of handler: Source, Destination, or Share
56 handler: ContentHandler.Destination
57 contentType: ContentType.Pictures
58
59 onPeerSelected: {
60 root.activeTransfer = peer.request();
61 pageStack.pop();
62 if (root.activeTransfer.state === ContentTransfer.InProgress) {
63 root.__exportItems(root.fileUrl);
64 }
65 }
66
67 onCancelPressed: {
68 pageStack.pop();
69 }
70 }
71}
072
=== added file 'src/app/qml/content-hub/contenttyperesolver.js'
--- src/app/qml/content-hub/contenttyperesolver.js 1970-01-01 00:00:00 +0000
+++ src/app/qml/content-hub/contenttyperesolver.js 2014-10-22 22:05:43 +0000
@@ -0,0 +1,73 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Arto Jalkanen <ajalkane@gmail.com>
17 */
18.import Ubuntu.Content 0.1 as CH
19
20/**
21 * For now a simple static mapping of file extensions to ContentHub types.
22 * This is enough for RTM, but in the future a better strategy would be
23 * for asking for the MIME-type of the file and mapping that to the
24 * ContentType
25 */
26var __mapping = {
27 'png': CH.ContentType.Pictures,
28 'jpg': CH.ContentType.Pictures,
29 'jpeg': CH.ContentType.Pictures,
30 'bmp': CH.ContentType.Pictures,
31 'gif': CH.ContentType.Pictures,
32
33 'mp3': CH.ContentType.Music,
34 'ogg': CH.ContentType.Music,
35 'wav': CH.ContentType.Music,
36
37 'avi': CH.ContentType.Videos,
38 'mpeg': CH.ContentType.Videos,
39 'mp4': CH.ContentType.Videos,
40 'mkv': CH.ContentType.Videos,
41 'mov': CH.ContentType.Videos,
42 'wmv': CH.ContentType.Videos,
43
44 'txt': CH.ContentType.Documents,
45 'doc': CH.ContentType.Documents,
46 'docx': CH.ContentType.Documents,
47 'xls': CH.ContentType.Documents,
48 'xlsx': CH.ContentType.Documents,
49 'pdf': CH.ContentType.Documents,
50}
51
52function resolveContentType(fileUrl) {
53 console.log("resolveContentType for file", fileUrl)
54 var extension = __fileExtension(fileUrl)
55 extension = extension.toLowerCase()
56 console.log("file extension:", extension)
57 var contentType = __mapping[extension]
58
59 if (contentType === null) {
60 console.log("Unrecognized extension", extension)
61 contentTYpe = CH.ContentType.Unknown
62 }
63
64 console.log("returning contentType:", contentType)
65
66 return contentType
67}
68
69function __fileExtension(fileUrl) {
70 var lastDotIndex = fileUrl.lastIndexOf('.')
71 return lastDotIndex > -1 ? fileUrl.substring(lastDotIndex + 1) : ''
72}
73
074
=== modified file 'src/app/qml/filemanager.qml'
--- src/app/qml/filemanager.qml 2014-10-10 22:03:01 +0000
+++ src/app/qml/filemanager.qml 2014-10-22 22:05:43 +0000
@@ -136,6 +136,10 @@
136 }136 }
137 }137 }
138138
139 function openFile(filePath) {
140 pageStack.push(Qt.resolvedUrl("content-hub/FileOpener.qml"), { fileUrl: "file://" + filePath} )
141 }
142
139 Connections {143 Connections {
140 target: ContentHub144 target: ContentHub
141 onExportRequested: {145 onExportRequested: {
142146
=== modified file 'src/app/qml/ui/FolderListPage.qml'
--- src/app/qml/ui/FolderListPage.qml 2014-10-06 12:27:18 +0000
+++ src/app/qml/ui/FolderListPage.qml 2014-10-22 22:05:43 +0000
@@ -728,12 +728,6 @@
728 }728 }
729 }729 }
730730
731 function openFile(filePath) {
732 if (!pageModel.openPath(filePath)) {
733 error(i18n.tr("File operation error"), i18n.tr("Unable to open '%1'").arg(filePath))
734 }
735 }
736
737 function itemClicked(model) {731 function itemClicked(model) {
738 if (model.isDir) {732 if (model.isDir) {
739 if (model.isReadable && model.isExecutable) {733 if (model.isReadable && model.isExecutable) {

Subscribers

People subscribed via source and target branches