From 0fe15d96f6f178f4eca13f8a3176939974a3335f Mon Sep 17 00:00:00 2001 From: Kugi Eusebio Date: Thu, 3 Dec 2020 02:23:57 +0800 Subject: [PATCH 1/4] moved content picker to a popover --- src/app/ContentExportDialog.qml | 136 ++++++++++++++++++++++++++++++++ src/app/DownloadsPage.qml | 61 +++----------- 2 files changed, 146 insertions(+), 51 deletions(-) create mode 100644 src/app/ContentExportDialog.qml diff --git a/src/app/ContentExportDialog.qml b/src/app/ContentExportDialog.qml new file mode 100644 index 000000000..7605eb2c1 --- /dev/null +++ b/src/app/ContentExportDialog.qml @@ -0,0 +1,136 @@ +/* + * Copyright 2015-2016 Canonical Ltd. + * + * 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 . + */ + + +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 {} + } +} diff --git a/src/app/DownloadsPage.qml b/src/app/DownloadsPage.qml index 20875e22c..f9ef3951b 100644 --- a/src/app/DownloadsPage.qml +++ b/src/app/DownloadsPage.qml @@ -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); - } } ] @@ -169,7 +155,6 @@ BrowserPage { ListView { id: downloadsListView anchors.fill: parent - focus: !exportPeerPicker.focus model: SortFilterModel { model: SortFilterModel { @@ -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() } } } @@ -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 - } - } From b1711fd6bfb33246045be69f5a1d4b1ed4398955 Mon Sep 17 00:00:00 2001 From: kugiigi Date: Thu, 4 Feb 2021 23:08:29 +0800 Subject: [PATCH 2/4] updated copyright texts and enabled click logic in downloads dialog --- src/app/ContentExportDialog.qml | 3 +-- src/app/DownloadsDialog.qml | 19 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/app/ContentExportDialog.qml b/src/app/ContentExportDialog.qml index 7605eb2c1..a3ac50e22 100644 --- a/src/app/ContentExportDialog.qml +++ b/src/app/ContentExportDialog.qml @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 Canonical Ltd. + * Copyright 2021 UBports Foundation * * This file is part of morph-browser. * @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - import QtQuick 2.9 import Ubuntu.Components 1.3 import Ubuntu.Components.Popups 1.3 diff --git a/src/app/DownloadsDialog.qml b/src/app/DownloadsDialog.qml index 9cbec6d44..32231fd49 100644 --- a/src/app/DownloadsDialog.qml +++ b/src/app/DownloadsDialog.qml @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 Canonical Ltd. + * Copyright 2021 UBports Foundation * * This file is part of morph-browser. * @@ -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) From 8539c32a256de318df533fc1ce10bc3f500338d8 Mon Sep 17 00:00:00 2001 From: kugiigi Date: Sat, 27 Mar 2021 22:01:53 +0800 Subject: [PATCH 3/4] Replaced UITK popup with QQC2 --- clickable.json | 1 + src/app/ContentExportDialog.qml | 85 ++++++++++++++++++++------------- src/app/DownloadsDialog.qml | 5 +- src/app/DownloadsPage.qml | 5 +- src/app/webbrowser/Browser.qml | 24 ++++++---- src/app/webcontainer/WebApp.qml | 23 +++++---- 6 files changed, 86 insertions(+), 57 deletions(-) diff --git a/clickable.json b/clickable.json index d6bafd9f6..68a78f74c 100644 --- a/clickable.json +++ b/clickable.json @@ -1,6 +1,7 @@ { "template": "cmake", "kill": "morph-browser", + "qt_version": "5.12", "build_args": "-DCLICK_MODE=ON", "dependencies_target": [ "qtwebengine5-dev" diff --git a/src/app/ContentExportDialog.qml b/src/app/ContentExportDialog.qml index a3ac50e22..3986e55f9 100644 --- a/src/app/ContentExportDialog.qml +++ b/src/app/ContentExportDialog.qml @@ -18,58 +18,80 @@ import QtQuick 2.9 import Ubuntu.Components 1.3 -import Ubuntu.Components.Popups 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 - -Popover { +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(70) - property real preferredWidth: caller ? caller.width * 0.9 : units.gu(40) + property real maximumWidth: units.gu(90) + property real preferredWidth: parent.width 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) + property real preferredHeight: parent.height > maximumHeight ? parent.height * 0.7 : parent.height signal preview(string url) - contentHeight: dialogItem.height - contentWidth: preferredWidth > maximumWidth ? maximumWidth : preferredWidth + 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.width >= units.gu(90) ? (parent.height - height) / 2 : (parent.height - height)}) + open() + } Item { - id: dialogItem - height: (preferredHeight > maximumHeight ? maximumHeight : preferredHeight) - - anchors { - top: parent.top - left: parent.left - right: parent.right - } + anchors.fill: parent PageHeader { id: header + title: i18n.tr("Open with") + subtitle: i18n.tr("File name: %1").arg(contentExportDialog.fileName) + anchors { - top: dialogItem.top + top: parent.top left: parent.left right: parent.right } - + leadingActionBar.actions: [ Action { iconName: "close" text: i18n.tr("Close") - onTriggered: PopupUtils.close(contentExportDialog) + onTriggered: contentExportDialog.close() } ] - + trailingActionBar { actions: [ Action { @@ -77,7 +99,7 @@ Popover { text: i18n.tr("Open link in browser") visible: (contentExportDialog.downloadUrl !== "") && (contentExportDialog.contentType !== ContentType.Unknown) onTriggered: { - PopupUtils.close(contentExportDialog); + contentExportDialog.close() preview((contentExportDialog.mimeType === "application/pdf") ? UrlUtils.getPdfViewerExtensionUrlPrefix() + contentExportDialog.downloadUrl : contentExportDialog.downloadUrl); } }, @@ -86,46 +108,45 @@ Popover { text: i18n.tr("Open file in browser") visible: (contentExportDialog.contentType !== ContentType.Unknown) onTriggered: { - PopupUtils.close(contentExportDialog); + contentExportDialog.close() 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 + 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 } - PopupUtils.close(contentExportDialog) + contentExportDialog.close() } - onCancelPressed: PopupUtils.close(contentExportDialog) - Keys.onEscapePressed: PopupUtils.close(contentExportDialog) + onCancelPressed: contentExportDialog.close() + Keys.onEscapePressed: contentExportDialog.close() } } - } Component { diff --git a/src/app/DownloadsDialog.qml b/src/app/DownloadsDialog.qml index 32231fd49..853d9c810 100644 --- a/src/app/DownloadsDialog.qml +++ b/src/app/DownloadsDialog.qml @@ -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 @@ -118,9 +117,7 @@ Popover { onClicked: { 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) + contentExportLoader.item.openDialog(download.path, MimeTypeMapper.mimeTypeToContentType(download.mimeType), download.mimeType, download.url, title.text) } else { if (download) { if (paused) { diff --git a/src/app/DownloadsPage.qml b/src/app/DownloadsPage.qml index f9ef3951b..e43b94a7d 100644 --- a/src/app/DownloadsPage.qml +++ b/src/app/DownloadsPage.qml @@ -43,7 +43,6 @@ BrowserPage { property bool incognito: false signal done() - signal preview(string url) title: i18n.tr("Downloads") @@ -228,9 +227,7 @@ BrowserPage { onClicked: { 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) + contentExportLoader.item.openDialog(model.path, MimeTypeMapper.mimeTypeToContentType(model.mimetype), model.mimetype, model.url, title) } else { if (download) { if (paused) { diff --git a/src/app/webbrowser/Browser.qml b/src/app/webbrowser/Browser.qml index 7402b4424..49b7ebd1d 100644 --- a/src/app/webbrowser/Browser.qml +++ b/src/app/webbrowser/Browser.qml @@ -1283,10 +1283,6 @@ Common.BrowserView { Connections { target: downloadsViewLoader.item onDone: downloadsViewLoader.active = false - onPreview: { - downloadsViewLoader.active = false - currentWebview.url = url; - } } onStatusChanged: { @@ -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 @@ -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" diff --git a/src/app/webcontainer/WebApp.qml b/src/app/webcontainer/WebApp.qml index 3235af014..78ef2807e 100644 --- a/src/app/webcontainer/WebApp.qml +++ b/src/app/webcontainer/WebApp.qml @@ -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 */ @@ -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; } } From 491a4d75b9a1d5811a621594c31c6ec9af69612e Mon Sep 17 00:00:00 2001 From: Kugi Eusebio Date: Thu, 15 Jul 2021 11:25:01 +0800 Subject: [PATCH 4/4] Change sizing behavior of content export popup --- src/app/ContentExportDialog.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/ContentExportDialog.qml b/src/app/ContentExportDialog.qml index 3986e55f9..9b321d4ae 100644 --- a/src/app/ContentExportDialog.qml +++ b/src/app/ContentExportDialog.qml @@ -38,8 +38,8 @@ QQC2.Dialog { property real maximumWidth: units.gu(90) property real preferredWidth: parent.width - property real maximumHeight: units.gu(80) - property real preferredHeight: parent.height > maximumHeight ? parent.height * 0.7 : parent.height + property real maximumHeight: units.gu(90) + property real preferredHeight: parent.height signal preview(string url) @@ -65,7 +65,7 @@ QQC2.Dialog { mimeType = _mimeType downloadUrl = _downloadURL fileName = _fileName - y = Qt.binding(function(){return parent.width >= units.gu(90) ? (parent.height - height) / 2 : (parent.height - height)}) + y = Qt.binding(function(){ return (parent.height - height) / 2 }) open() }