Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Moved content picker into a popover #414

Open
wants to merge 4 commits into
base: xenial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions src/app/ContentExportDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright 2021 UBports Foundation
*
* This file is part of morph-browser.
*
* morph-browser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* morph-browser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.9
import Ubuntu.Components 1.3
import Ubuntu.Components.Popups 1.3
import Ubuntu.Content 1.3

import "UrlUtils.js" as UrlUtils


Popover {
id: contentExportDialog

property alias path: exportPeerPicker.path
property alias contentType: exportPeerPicker.contentType
property string mimeType
property string downloadUrl

property real maximumWidth: units.gu(70)
property real preferredWidth: caller ? caller.width * 0.9 : units.gu(40)

property real maximumHeight: units.gu(80)
property real preferredHeight: caller ? caller.height > maximumHeight ? caller.height * 0.8 : caller.height - units.gu(5) : units.gu(40)

signal preview(string url)

contentHeight: dialogItem.height
contentWidth: preferredWidth > maximumWidth ? maximumWidth : preferredWidth

Item {
id: dialogItem
height: (preferredHeight > maximumHeight ? maximumHeight : preferredHeight)

anchors {
top: parent.top
left: parent.left
right: parent.right
}

PageHeader {
id: header
title: i18n.tr("Open with")
anchors {
top: dialogItem.top
left: parent.left
right: parent.right
}

leadingActionBar.actions: [
Action {
iconName: "close"
text: i18n.tr("Close")
onTriggered: PopupUtils.close(contentExportDialog)
}
]

trailingActionBar {
actions: [
Action {
iconName: "external-link"
text: i18n.tr("Open link in browser")
visible: (contentExportDialog.downloadUrl !== "") && (contentExportDialog.contentType !== ContentType.Unknown)
onTriggered: {
PopupUtils.close(contentExportDialog);
preview((contentExportDialog.mimeType === "application/pdf") ? UrlUtils.getPdfViewerExtensionUrlPrefix() + contentExportDialog.downloadUrl : contentExportDialog.downloadUrl);
}
},
Action {
iconName: "document-open"
text: i18n.tr("Open file in browser")
visible: (contentExportDialog.contentType !== ContentType.Unknown)
onTriggered: {
PopupUtils.close(contentExportDialog);
preview((contentExportDialog.mimeType === "application/pdf") ? UrlUtils.getPdfViewerExtensionUrlPrefix() + "file://%1".arg(contentExportDialog.path) : contentExportDialog.path);
}
}
]
}
}

Item {
id: contentPickerItem

height: (preferredHeight > maximumHeight ? maximumHeight : preferredHeight) - header.height

anchors {
top: header.bottom
left: parent.left
right: parent.right
}

ContentPeerPicker {
id: exportPeerPicker

property string path
focus: visible
handler: ContentHandler.Destination
showTitle: false

onPeerSelected: {
var transfer = peer.request()
if (transfer.state === ContentTransfer.InProgress) {
transfer.items = [contentItemComponent.createObject(contentExportDialog, {"url": path})]
transfer.state = ContentTransfer.Charged
}
PopupUtils.close(contentExportDialog)
}
onCancelPressed: PopupUtils.close(contentExportDialog)
Keys.onEscapePressed: PopupUtils.close(contentExportDialog)
}
}

}

Component {
id: contentItemComponent
ContentItem {}
}
}
19 changes: 9 additions & 10 deletions src/app/DownloadsDialog.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 Canonical Ltd.
* Copyright 2021 UBports Foundation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops... In this case, both copyright statements would be kept. The code was under copyright by Canonical, and now we've added some stake with our changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that file was created in #415
i actually noticed that there are a few others that we missed in that PR 😅
I'm planning to correct them in a separate PR but I just corrected this one here since I modified it anyway.

But this is definitely a lesson learned for me moving forward - don't just copy paste copyright texts 😀

*
* This file is part of morph-browser.
*
Expand Down Expand Up @@ -117,20 +117,19 @@ Popover {
icon: MimeDatabase.iconForMimetype(modelData.mimeType)

onClicked: {
/* TODO: Enable once content picker in a popover is merged */
/*if (!incomplete && !error) {
if (!incomplete && !error) {
var properties = {"path": download.path, "contentType": MimeTypeMapper.mimeTypeToContentType(download.mimeType), "mimeType": download.mimeType, "downloadUrl": download.url}
var exportDialog = PopupUtils.open(Qt.resolvedUrl("ContentExportDialog.qml"), downloadsDialog.parent, properties)
exportDialog.preview.connect(downloadsDialog.preview)
} else {*/
if (download) {
if (paused) {
download.resume()
} else {
download.pause()
} else {
if (download) {
if (paused) {
download.resume()
} else {
download.pause()
}
}
}
//}
}

onRemove: downloadsListView.removeItem(index)
Expand Down
61 changes: 10 additions & 51 deletions src/app/DownloadsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ BrowserPage {
selectMode = true
multiSelect = true
}
},
Action {
iconName: "external-link"
visible: exportPeerPicker.visible && (exportPeerPicker.downloadUrl !== "") && (exportPeerPicker.contentType !== ContentType.Unknown)
onTriggered: {
preview((exportPeerPicker.mimeType === "application/pdf") ? UrlUtils.getPdfViewerExtensionUrlPrefix() + exportPeerPicker.downloadUrl : exportPeerPicker.downloadUrl);
}
},
Action {
iconName: "document-open"
visible: exportPeerPicker.visible && (exportPeerPicker.contentType !== ContentType.Unknown)
onTriggered: {
preview((exportPeerPicker.mimeType === "application/pdf") ? UrlUtils.getPdfViewerExtensionUrlPrefix() + "file://%1".arg(exportPeerPicker.path) : exportPeerPicker.path);
}
}
]

Expand Down Expand Up @@ -169,7 +155,6 @@ BrowserPage {
ListView {
id: downloadsListView
anchors.fill: parent
focus: !exportPeerPicker.focus

model: SortFilterModel {
model: SortFilterModel {
Expand Down Expand Up @@ -242,20 +227,16 @@ BrowserPage {
}

onClicked: {
if (!selectMode) {
if (model.complete) {
exportPeerPicker.contentType = MimeTypeMapper.mimeTypeToContentType(model.mimetype);
exportPeerPicker.visible = true;
exportPeerPicker.path = model.path;
exportPeerPicker.mimeType = model.mimetype;
exportPeerPicker.downloadUrl = model.url;
} else {
if (download) {
if (paused) {
download.resume()
} else {
download.pause()
}
if (model.complete && !selectMode) {
var properties = {"path": model.path, "contentType": MimeTypeMapper.mimeTypeToContentType(model.mimetype), "mimeType": model.mimetype, "downloadUrl": model.url}
var exportDialog = PopupUtils.open(Qt.resolvedUrl("ContentExportDialog.qml"), downloadsItem, properties)
exportDialog.preview.connect(downloadsItem.preview)
} else {
if (download) {
if (paused) {
download.resume()
} else {
download.pause()
}
}
}
Expand Down Expand Up @@ -315,26 +296,4 @@ BrowserPage {
id: contentItemComponent
ContentItem {}
}

ContentPeerPicker {
id: exportPeerPicker
visible: false
focus: visible
anchors.fill: parent
handler: ContentHandler.Destination
property string path
property string mimeType
property string downloadUrl
onPeerSelected: {
var transfer = peer.request()
if (transfer.state === ContentTransfer.InProgress) {
transfer.items = [contentItemComponent.createObject(downloadsItem, {"url": path})]
transfer.state = ContentTransfer.Charged
}
visible = false
}
onCancelPressed: visible = false
Keys.onEscapePressed: visible = false
}

}