unify behavior when failed to open URL
This commit is contained in:
parent
5d6484a657
commit
0228ff8c68
6 changed files with 27 additions and 50 deletions
|
@ -844,11 +844,7 @@ void FormMain::hideEvent(QHideEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::showDocs() {
|
void FormMain::showDocs() {
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(APP_URL_DOCUMENTATION)) {
|
qApp->web()->openUrlInExternalBrowser(APP_URL_DOCUMENTATION);
|
||||||
qApp->showGuiMessage(tr("Cannot open external browser"),
|
|
||||||
tr("Cannot open external browser. Navigate to application website manually."),
|
|
||||||
QSystemTrayIcon::Warning, this, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::showAddAccountDialog() {
|
void FormMain::showAddAccountDialog() {
|
||||||
|
@ -860,17 +856,9 @@ void FormMain::showAddAccountDialog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::reportABug() {
|
void FormMain::reportABug() {
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(QSL(APP_URL_ISSUES_NEW))) {
|
qApp->web()->openUrlInExternalBrowser(QSL(APP_URL_ISSUES_NEW));
|
||||||
qApp->showGuiMessage(tr("Cannot open external browser"),
|
|
||||||
tr("Cannot open external browser. Navigate to application website manually."),
|
|
||||||
QSystemTrayIcon::Warning, this, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::donate() {
|
void FormMain::donate() {
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(QSL(APP_DONATE_URL))) {
|
qApp->web()->openUrlInExternalBrowser(QSL(APP_DONATE_URL));
|
||||||
qApp->showGuiMessage(tr("Cannot open external browser"),
|
|
||||||
tr("Cannot open external browser. Navigate to application website manually."),
|
|
||||||
QSystemTrayIcon::Warning, this, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,11 +237,6 @@ void FormUpdate::startUpdate() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Self-update and package are not available.
|
// Self-update and package are not available.
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(url_file)) {
|
qApp->web()->openUrlInExternalBrowser(url_file);
|
||||||
qApp->showGuiMessage(tr("Cannot update application"),
|
|
||||||
tr("Cannot navigate to installation file. Download new installation file manually on project website."),
|
|
||||||
QSystemTrayIcon::MessageIcon::Warning,
|
|
||||||
this, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,12 +380,7 @@ void MessagesView::openSelectedSourceMessagesExternally() {
|
||||||
.m_url
|
.m_url
|
||||||
.replace(QRegularExpression("[\\t\\n]"), QString());
|
.replace(QRegularExpression("[\\t\\n]"), QString());
|
||||||
|
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(link)) {
|
qApp->web()->openUrlInExternalBrowser(link);
|
||||||
qApp->showGuiMessage(tr("Problem with starting external web browser"),
|
|
||||||
tr("External web browser could not be started."),
|
|
||||||
QSystemTrayIcon::Critical);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, mark opened messages as read.
|
// Finally, mark opened messages as read.
|
||||||
|
|
|
@ -185,13 +185,7 @@ void WebBrowser::openCurrentSiteInSystemBrowser() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(url.toString())) {
|
qApp->web()->openUrlInExternalBrowser(url.toString());
|
||||||
qApp->showGuiMessage(tr("Failed to open URL in web browser"),
|
|
||||||
tr("URL '%1' could not be opened in system's web browser.").arg(url.toString()),
|
|
||||||
QSystemTrayIcon::MessageIcon::Critical,
|
|
||||||
qApp->mainFormWidget(),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::onTitleChanged(const QString& new_title) {
|
void WebBrowser::onTitleChanged(const QString& new_title) {
|
||||||
|
|
|
@ -332,13 +332,5 @@ void OAuth2Service::retrieveAuthCode() {
|
||||||
m_id);
|
m_id);
|
||||||
|
|
||||||
// We run login URL in external browser, response is caught by light HTTP server.
|
// We run login URL in external browser, response is caught by light HTTP server.
|
||||||
if (!qApp->web()->openUrlInExternalBrowser(auth_url)) {
|
qApp->web()->openUrlInExternalBrowser(auth_url);
|
||||||
MessageBox::show(qApp->mainFormWidget(),
|
|
||||||
QMessageBox::Icon::Question,
|
|
||||||
tr("Navigate to website"),
|
|
||||||
tr("To login, you need to navigate to the below website."),
|
|
||||||
{},
|
|
||||||
auth_url,
|
|
||||||
QMessageBox::StandardButton::Ok);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
|
|
||||||
|
#include "gui/messagebox.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
|
||||||
|
@ -64,9 +65,9 @@ bool WebFactory::sendMessageViaEmail(const Message& message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebFactory::openUrlInExternalBrowser(const QString& url) const {
|
bool WebFactory::openUrlInExternalBrowser(const QString& url) const {
|
||||||
qDebugNN << LOGSEC_NETWORK
|
qDebugNN << LOGSEC_NETWORK << "We are trying to open URL" << QUOTE_W_SPACE_DOT(url);
|
||||||
<< "We are trying to open URL:"
|
|
||||||
<< QUOTE_W_SPACE_DOT(url);
|
bool result = false;
|
||||||
|
|
||||||
if (qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserEnabled)).toBool()) {
|
if (qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserEnabled)).toBool()) {
|
||||||
const QString browser = qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserExecutable)).toString();
|
const QString browser = qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserExecutable)).toString();
|
||||||
|
@ -75,17 +76,29 @@ bool WebFactory::openUrlInExternalBrowser(const QString& url) const {
|
||||||
|
|
||||||
qDebugNN << LOGSEC_NETWORK << "Arguments for external browser:" << QUOTE_W_SPACE_DOT(nice_args);
|
qDebugNN << LOGSEC_NETWORK << "Arguments for external browser:" << QUOTE_W_SPACE_DOT(nice_args);
|
||||||
|
|
||||||
const bool result = IOFactory::startProcessDetached(browser, {}, nice_args);
|
result = IOFactory::startProcessDetached(browser, {}, nice_args);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
qDebugNN << LOGSEC_NETWORK << "External web browser call failed.";
|
qDebugNN << LOGSEC_NETWORK << "External web browser call failed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QDesktopServices::openUrl(url);
|
result = QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
// We display GUI information that browser was not probably opened.
|
||||||
|
MessageBox::show(qApp->mainFormWidget(),
|
||||||
|
QMessageBox::Icon::Critical,
|
||||||
|
tr("Navigate to website manually"),
|
||||||
|
tr("%1 was unable to launch your web browser with the given URL, you need to open the "
|
||||||
|
"below website URL in your web browser manually.").arg(APP_NAME),
|
||||||
|
{},
|
||||||
|
url,
|
||||||
|
QMessageBox::StandardButton::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WebFactory::stripTags(QString text) {
|
QString WebFactory::stripTags(QString text) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue