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 all 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
1 change: 1 addition & 0 deletions clickable.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"template": "cmake",
"kill": "morph-browser",
"qt_version": "5.12",
"build_args": "-DCLICK_MODE=ON",
"dependencies_target": [
"qtwebengine5-dev"
Expand Down
156 changes: 156 additions & 0 deletions src/app/ContentExportDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* 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.Content 1.3
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Controls.Suru 2.2

import "UrlUtils.js" as UrlUtils

QQC2.Dialog {
id: contentExportDialog

objectName: "contentExportDialog"

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

property real maximumWidth: units.gu(90)
property real preferredWidth: parent.width

property real maximumHeight: units.gu(90)
property real preferredHeight: parent.height

signal preview(string url)

width: preferredWidth > maximumWidth ? maximumWidth : preferredWidth
height: preferredHeight > maximumHeight ? maximumHeight : preferredHeight
x: (parent.width - width) / 2
parent: QQC2.Overlay.overlay
topPadding: units.gu(0.2)
leftPadding: units.gu(0.2)
rightPadding: units.gu(0.2)
bottomPadding: units.gu(0.2)
closePolicy: QQC2.Popup.CloseOnEscape | QQC2.Popup.CloseOnPressOutside
modal: true

QQC2.Overlay.modal: Rectangle {
color: Suru.overlayColor
Behavior on opacity { NumberAnimation { duration: Suru.animations.FastDuration } }
}

function openDialog(_downloadPath, _contentType, _mimeType, _downloadURL, _fileName){
path = _downloadPath
contentType = _contentType
mimeType = _mimeType
downloadUrl = _downloadURL
fileName = _fileName
y = Qt.binding(function(){ return (parent.height - height) / 2 })
open()
}

Item {
anchors.fill: parent

PageHeader {
id: header

title: i18n.tr("Open with")
subtitle: i18n.tr("File name: %1").arg(contentExportDialog.fileName)

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

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

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

Item {
id: contentPickerItem

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

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
}
contentExportDialog.close()
}
onCancelPressed: contentExportDialog.close()
Keys.onEscapePressed: contentExportDialog.close()
}
}
}

Component {
id: contentItemComponent
ContentItem {}
}
}
24 changes: 10 additions & 14 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 @@ -41,7 +41,6 @@ Popover {
property real preferredHeight: downloadsDialogColumn.height + units.gu(2)

signal showDownloadsPage()
signal preview(string url)

contentHeight: preferredHeight > maximumHeight ? maximumHeight : preferredHeight
contentWidth: preferredWidth > maximumWidth ? maximumWidth : preferredWidth
Expand Down Expand Up @@ -117,20 +116,17 @@ Popover {
icon: MimeDatabase.iconForMimetype(modelData.mimeType)

onClicked: {
/* TODO: Enable once content picker in a popover is merged */
/*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()
if (!incomplete && !error) {
contentExportLoader.item.openDialog(download.path, MimeTypeMapper.mimeTypeToContentType(download.mimeType), download.mimeType, download.url, title.text)
} else {
if (download) {
if (paused) {
download.resume()
} else {
download.pause()
}
}
}
//}
}

onRemove: downloadsListView.removeItem(index)
Expand Down
60 changes: 8 additions & 52 deletions src/app/DownloadsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ BrowserPage {
property bool incognito: false

signal done()
signal preview(string url)

title: i18n.tr("Downloads")

Expand Down Expand Up @@ -125,20 +124,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 +154,6 @@ BrowserPage {
ListView {
id: downloadsListView
anchors.fill: parent
focus: !exportPeerPicker.focus

model: SortFilterModel {
model: SortFilterModel {
Expand Down Expand Up @@ -242,20 +226,14 @@ 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) {
contentExportLoader.item.openDialog(model.path, MimeTypeMapper.mimeTypeToContentType(model.mimetype), model.mimetype, model.url, title)
} else {
if (download) {
if (paused) {
download.resume()
} else {
download.pause()
}
}
}
Expand Down Expand Up @@ -315,26 +293,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
}

}
24 changes: 15 additions & 9 deletions src/app/webbrowser/Browser.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,6 @@ Common.BrowserView {
Connections {
target: downloadsViewLoader.item
onDone: downloadsViewLoader.active = false
onPreview: {
downloadsViewLoader.active = false
currentWebview.url = url;
}
}

onStatusChanged: {
Expand Down Expand Up @@ -1634,11 +1630,6 @@ Common.BrowserView {
target: internal.currentDownloadsDialog

onShowDownloadsPage: showDownloadsPage()

onPreview: {
PopupUtils.close(internal.currentDownloadsDialog);
currentWebview.url = url;
}
}

// Work around https://launchpad.net/bugs/1502675 by delaying the switch to
Expand Down Expand Up @@ -1882,6 +1873,21 @@ Common.BrowserView {
}
}

Loader {
id: contentExportLoader
source: "../ContentExportDialog.qml"
asynchronous: true
}

Connections {
target: contentExportLoader.item

onPreview: {
downloadsViewLoader.active = false
currentWebview.url = url;
}
}

Loader {
id: downloadDialogLoader
source: "ContentDownloadDialog.qml"
Expand Down
23 changes: 15 additions & 8 deletions src/app/webcontainer/WebApp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,6 @@ Common.BrowserView {
Connections {
target: currentDownloadsDialog
onShowDownloadsPage: showDownloadsPage()
onPreview: {
PopupUtils.close(currentDownloadsDialog);
webapp.currentWebview.url = url;
}
}

/* Only used for anchoring the downloads dialog to the top when chromeless */
Expand Down Expand Up @@ -423,10 +419,21 @@ Common.BrowserView {
Connections {
target: downloadsViewLoader.item
onDone: downloadsViewLoader.active = false
onPreview: {
downloadsViewLoader.active = false;
webapp.currentWebview.url = url;
}
}
}

Loader {
id: contentExportLoader
source: "../ContentExportDialog.qml"
asynchronous: true
}

Connections {
target: contentExportLoader.item

onPreview: {
downloadsViewLoader.active = false
webapp.currentWebview.url = url;
}
}

Expand Down