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
1=== added directory 'src/app/qml/content-hub'
2=== added file 'src/app/qml/content-hub/FileOpener.qml'
3--- src/app/qml/content-hub/FileOpener.qml 1970-01-01 00:00:00 +0000
4+++ src/app/qml/content-hub/FileOpener.qml 2014-10-22 22:05:43 +0000
5@@ -0,0 +1,71 @@
6+/*
7+ * Copyright (C) 2014 Canonical Ltd
8+ *
9+ * This program is free software: you can redistribute it and/or modify
10+ * it under the terms of the GNU General Public License version 3 as
11+ * published by the Free Software Foundation.
12+ *
13+ * This program is distributed in the hope that it will be useful,
14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+ * GNU General Public License for more details.
17+ *
18+ * You should have received a copy of the GNU General Public License
19+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20+ *
21+ * Authored by: Arto Jalkanen <ajalkane@gmail.com>
22+ */
23+import QtQuick 2.0
24+import Ubuntu.Components 1.1
25+
26+import Ubuntu.Content 0.1
27+
28+import "contenttyperesolver.js" as Resolver
29+
30+Page {
31+ id: root
32+ title: i18n.tr("Open with")
33+
34+ property var activeTransfer
35+
36+ property string fileUrl
37+
38+ Component.onCompleted: {
39+ var contentType = Resolver.resolveContentType(fileUrl)
40+ console.log("Resolved contenttype: " + contentType)
41+ peerPicker.contentType = contentType
42+ }
43+
44+ Component {
45+ id: resultComponent
46+ ContentItem {}
47+ }
48+
49+ function __exportItems(url) {
50+ if (root.activeTransfer.state === ContentTransfer.InProgress)
51+ {
52+ root.activeTransfer.items = [ resultComponent.createObject(root, {"url": url}) ];
53+ root.activeTransfer.state = ContentTransfer.Charged;
54+ }
55+ }
56+ ContentPeerPicker {
57+ id: peerPicker
58+ showTitle: false
59+
60+ // Type of handler: Source, Destination, or Share
61+ handler: ContentHandler.Destination
62+ contentType: ContentType.Pictures
63+
64+ onPeerSelected: {
65+ root.activeTransfer = peer.request();
66+ pageStack.pop();
67+ if (root.activeTransfer.state === ContentTransfer.InProgress) {
68+ root.__exportItems(root.fileUrl);
69+ }
70+ }
71+
72+ onCancelPressed: {
73+ pageStack.pop();
74+ }
75+ }
76+}
77
78=== added file 'src/app/qml/content-hub/contenttyperesolver.js'
79--- src/app/qml/content-hub/contenttyperesolver.js 1970-01-01 00:00:00 +0000
80+++ src/app/qml/content-hub/contenttyperesolver.js 2014-10-22 22:05:43 +0000
81@@ -0,0 +1,73 @@
82+/*
83+ * Copyright (C) 2014 Canonical Ltd
84+ *
85+ * This program is free software: you can redistribute it and/or modify
86+ * it under the terms of the GNU General Public License version 3 as
87+ * published by the Free Software Foundation.
88+ *
89+ * This program is distributed in the hope that it will be useful,
90+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
91+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92+ * GNU General Public License for more details.
93+ *
94+ * You should have received a copy of the GNU General Public License
95+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
96+ *
97+ * Authored by: Arto Jalkanen <ajalkane@gmail.com>
98+ */
99+.import Ubuntu.Content 0.1 as CH
100+
101+/**
102+ * For now a simple static mapping of file extensions to ContentHub types.
103+ * This is enough for RTM, but in the future a better strategy would be
104+ * for asking for the MIME-type of the file and mapping that to the
105+ * ContentType
106+ */
107+var __mapping = {
108+ 'png': CH.ContentType.Pictures,
109+ 'jpg': CH.ContentType.Pictures,
110+ 'jpeg': CH.ContentType.Pictures,
111+ 'bmp': CH.ContentType.Pictures,
112+ 'gif': CH.ContentType.Pictures,
113+
114+ 'mp3': CH.ContentType.Music,
115+ 'ogg': CH.ContentType.Music,
116+ 'wav': CH.ContentType.Music,
117+
118+ 'avi': CH.ContentType.Videos,
119+ 'mpeg': CH.ContentType.Videos,
120+ 'mp4': CH.ContentType.Videos,
121+ 'mkv': CH.ContentType.Videos,
122+ 'mov': CH.ContentType.Videos,
123+ 'wmv': CH.ContentType.Videos,
124+
125+ 'txt': CH.ContentType.Documents,
126+ 'doc': CH.ContentType.Documents,
127+ 'docx': CH.ContentType.Documents,
128+ 'xls': CH.ContentType.Documents,
129+ 'xlsx': CH.ContentType.Documents,
130+ 'pdf': CH.ContentType.Documents,
131+}
132+
133+function resolveContentType(fileUrl) {
134+ console.log("resolveContentType for file", fileUrl)
135+ var extension = __fileExtension(fileUrl)
136+ extension = extension.toLowerCase()
137+ console.log("file extension:", extension)
138+ var contentType = __mapping[extension]
139+
140+ if (contentType === null) {
141+ console.log("Unrecognized extension", extension)
142+ contentTYpe = CH.ContentType.Unknown
143+ }
144+
145+ console.log("returning contentType:", contentType)
146+
147+ return contentType
148+}
149+
150+function __fileExtension(fileUrl) {
151+ var lastDotIndex = fileUrl.lastIndexOf('.')
152+ return lastDotIndex > -1 ? fileUrl.substring(lastDotIndex + 1) : ''
153+}
154+
155
156=== modified file 'src/app/qml/filemanager.qml'
157--- src/app/qml/filemanager.qml 2014-10-10 22:03:01 +0000
158+++ src/app/qml/filemanager.qml 2014-10-22 22:05:43 +0000
159@@ -136,6 +136,10 @@
160 }
161 }
162
163+ function openFile(filePath) {
164+ pageStack.push(Qt.resolvedUrl("content-hub/FileOpener.qml"), { fileUrl: "file://" + filePath} )
165+ }
166+
167 Connections {
168 target: ContentHub
169 onExportRequested: {
170
171=== modified file 'src/app/qml/ui/FolderListPage.qml'
172--- src/app/qml/ui/FolderListPage.qml 2014-10-06 12:27:18 +0000
173+++ src/app/qml/ui/FolderListPage.qml 2014-10-22 22:05:43 +0000
174@@ -728,12 +728,6 @@
175 }
176 }
177
178- function openFile(filePath) {
179- if (!pageModel.openPath(filePath)) {
180- error(i18n.tr("File operation error"), i18n.tr("Unable to open '%1'").arg(filePath))
181- }
182- }
183-
184 function itemClicked(model) {
185 if (model.isDir) {
186 if (model.isReadable && model.isExecutable) {

Subscribers

People subscribed via source and target branches