-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sailfish-browser] Provide an option in site info panel to set user a…
…gent override. Contributes to JB#31240
- Loading branch information
Showing
5 changed files
with
188 additions
and
1 deletion.
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,104 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (c) 2022 Open Mobile Platform LLC. | ||
** | ||
****************************************************************************/ | ||
|
||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import QtQuick 2.1 | ||
import Sailfish.Silica 1.0 | ||
import Sailfish.Browser 1.0 | ||
import "useragenthelper.js" as UserAgentHelper | ||
|
||
Page { | ||
id: page | ||
|
||
property UserAgentModel userAgentModel: UserAgentModel { | ||
currentHost: WebUtils.host(webView.url) | ||
} | ||
property string hostname: userAgentModel.currentHost | ||
property bool isKey: userAgentModel.currentHostUserAgent.isKey | ||
property string userAgent: userAgentModel.currentHostUserAgent.userAgent | ||
property WebPage webPage: null | ||
|
||
SilicaListView { | ||
anchors.fill: parent | ||
model: UserAgentHelper.model | ||
|
||
header: PageHeader { | ||
//% "User agent override" | ||
title: qsTrId("sailfish_browser-he-user_agent_override") | ||
description: page.hostname | ||
} | ||
|
||
delegate: BackgroundItem { | ||
id: delegateItem | ||
|
||
onClicked: { | ||
if ("custom" in modelData) { | ||
pageStack.animatorPush(customUserAgentDialog, | ||
{ | ||
userAgentModel: userAgentModel, | ||
userAgent: page.isKey ? "" : page.userAgent, | ||
hostname: page.hostname | ||
}) | ||
} else { | ||
userAgentModel.setUserAgentOverride(page.hostname, modelData.key, true) | ||
pageStack.pop() | ||
} | ||
} | ||
|
||
Label { | ||
width: parent.width | ||
leftPadding: Theme.horizontalPageMargin | ||
rightPadding: Theme.horizontalPageMargin | ||
text: modelData.name + (!page.isKey && "custom" in modelData ? ": " + userAgent : "") | ||
elide: Text.ElideRight | ||
highlighted: page.isKey ? modelData.key === page.userAgent : "custom" in modelData | ||
} | ||
} | ||
|
||
VerticalScrollDecorator {} | ||
} | ||
|
||
Component { | ||
id: customUserAgentDialog | ||
|
||
Dialog { | ||
id: dialog | ||
|
||
property UserAgentModel userAgentModel | ||
property string userAgent | ||
property string hostname | ||
|
||
canAccept: textField.text !== "" | ||
onAccepted: { | ||
userAgentModel.setUserAgentOverride(hostname, textField.text.trim(), false) | ||
} | ||
|
||
DialogHeader { | ||
id: header | ||
//: Accept button text for adding a home page adress | ||
//% "OK" | ||
acceptText: qsTrId("sailfish_browser-he-ok") | ||
} | ||
|
||
TextField { | ||
id: textField | ||
|
||
anchors.top: header.bottom | ||
focus: true | ||
text: userAgent | ||
//% "User agent to use when loading %1." | ||
description: qsTrId("sailfish_browser-he-user_agent_for_site").arg(hostname) | ||
label: placeholderText | ||
inputMethodHints: Qt.ImhNoPredictiveText | ||
EnterKey.onClicked: dialog.accept() | ||
} | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var model = [].concat( | ||
[{ | ||
key: "", | ||
//: Identifier of the current browser | ||
//% "Gecko-based browser (Default)" | ||
name: qsTrId("sailfish_browser-la-browser_list_current_browser") | ||
}], | ||
UserAgentManager.getBrowserList(), | ||
[{ | ||
custom: true, | ||
//: A user-defined user agent | ||
//% "Custom" | ||
name: qsTrId("sailfish_browser-la-browser_list_custom") | ||
}] | ||
) | ||
|
||
function getUserAgentString(userAgent, isKey) | ||
{ | ||
if (!isKey) { | ||
return userAgent | ||
} | ||
|
||
for (var i = 0; i < model.length; i++) { | ||
if (i in model && model[i].key === userAgent) { | ||
return model[i].name | ||
} | ||
} | ||
|
||
return model[0].name | ||
} |
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