This repository has been archived by the owner on Jan 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Moved content picker into a popover #414
Open
kugiigi
wants to merge
4
commits into
ubports:xenial
Choose a base branch
from
kugiigi:xenial_-_contentpicker
base: xenial
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😀