diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-12-28 01:25:33 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-12-28 01:25:33 -0500 |
| commit | 51db1f99f0c4cddc0af224d46d6e5679d18d2a53 (patch) | |
| tree | ddb11e4aef19b1d428c9f71bdc734e59b2e2d25d /src | |
| parent | 106ed49baecc60dbdf4844ed684df750e5caf3aa (diff) | |
custom browser command
changed some places that used QDesktopServices to use shell::Open() from uibase instead
Diffstat (limited to 'src')
| -rw-r--r-- | src/downloadmanager.cpp | 2 | ||||
| -rw-r--r-- | src/lootdialog.cpp | 2 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 12 | ||||
| -rw-r--r-- | src/modinfodialognexus.cpp | 12 | ||||
| -rw-r--r-- | src/nxmaccessmanager.cpp | 2 | ||||
| -rw-r--r-- | src/settings.cpp | 39 | ||||
| -rw-r--r-- | src/settings.h | 23 | ||||
| -rw-r--r-- | src/settingsdialog.ui | 90 | ||||
| -rw-r--r-- | src/settingsdialognexus.cpp | 37 | ||||
| -rw-r--r-- | src/settingsdialognexus.h | 7 |
10 files changed, 182 insertions, 44 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index c912464d..676b43de 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1109,7 +1109,7 @@ void DownloadManager::visitOnNexus(int index) QString gameName = info->m_FileInfo->gameName; if (modID > 0) { - QDesktopServices::openUrl(QUrl(m_NexusInterface->getModURL(modID, gameName))); + shell::Open(QUrl(m_NexusInterface->getModURL(modID, gameName))); } else { emit showMessage(tr("Nexus ID for this Mod is unknown")); diff --git a/src/lootdialog.cpp b/src/lootdialog.cpp index 58699d6e..3673c5c6 100644 --- a/src/lootdialog.cpp +++ b/src/lootdialog.cpp @@ -56,7 +56,7 @@ bool MarkdownPage::acceptNavigationRequest(const QUrl &url, NavigationType, bool static const QStringList allowed = {"qrc", "data"}; if (!allowed.contains(url.scheme())) { - QDesktopServices::openUrl(url); + shell::Open(url); return false; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5ddc489c..1e7741ac 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1678,7 +1678,7 @@ void MainWindow::registerModPage(IPluginModPage *modPage) m_IntegratedBrowser->openUrl(modPage->pageURL()); } else { - QDesktopServices::openUrl(QUrl(modPage->pageURL())); + shell::Open(QUrl(modPage->pageURL())); } }, Qt::QueuedConnection); @@ -2408,17 +2408,17 @@ void MainWindow::helpTriggered() void MainWindow::wikiTriggered() { - QDesktopServices::openUrl(QUrl("https://modorganizer2.github.io/")); + shell::Open(QUrl("https://modorganizer2.github.io/")); } void MainWindow::discordTriggered() { - QDesktopServices::openUrl(QUrl("https://discord.gg/cYwdcxj")); + shell::Open(QUrl("https://discord.gg/cYwdcxj")); } void MainWindow::issueTriggered() { - QDesktopServices::openUrl(QUrl("https://github.com/Modorganizer2/modorganizer/issues")); + shell::Open(QUrl("https://github.com/Modorganizer2/modorganizer/issues")); } void MainWindow::tutorialTriggered() @@ -5177,13 +5177,13 @@ void MainWindow::on_actionNexus_triggered() QString gameName = game->gameShortName(); if (game->gameNexusName().isEmpty() && game->primarySources().count()) gameName = game->primarySources()[0]; - QDesktopServices::openUrl(QUrl(NexusInterface::instance().getGameURL(gameName))); + shell::Open(QUrl(NexusInterface::instance().getGameURL(gameName))); } void MainWindow::linkClicked(const QString &url) { - QDesktopServices::openUrl(QUrl(url)); + shell::Open(QUrl(url)); } diff --git a/src/modinfodialognexus.cpp b/src/modinfodialognexus.cpp index 1ee3cefc..f81cfa89 100644 --- a/src/modinfodialognexus.cpp +++ b/src/modinfodialognexus.cpp @@ -217,11 +217,11 @@ void NexusTab::onModChanged() padding-top: 20px; padding-bottom: 20px; } - + img { max-width: 100%; } - + figure.quote { position: relative; padding: 24px; @@ -257,7 +257,7 @@ void NexusTab::onModChanged() display: inline-block; cursor: pointer; } - + details summary::-webkit-details-marker { display:none; } @@ -268,7 +268,7 @@ void NexusTab::onModChanged() a { - /*should avoid overflow with long links forcing wordwrap regardless of spaces*/ + /*should avoid overflow with long links forcing wordwrap regardless of spaces*/ overflow-wrap: break-word; word-wrap: break-word; @@ -325,7 +325,7 @@ void NexusTab::onSourceGameChanged() for (auto game : plugin().plugins<MOBase::IPluginGame>()) { if (game->gameName() == ui->sourceGame->currentText()) { - mod().setGameName(game->gameShortName()); + mod().setGameName(game->gameShortName()); mod().setLastNexusQuery(QDateTime::fromSecsSinceEpoch(0)); refreshData(mod().nexusId()); return; @@ -411,7 +411,7 @@ void NexusTab::onCustomURLChanged() void NexusTab::onVisitCustomURL() { - const auto url = mod().parseCustomURL(); + const QUrl url = mod().parseCustomURL(); if (url.isValid()) { shell::Open(url); } diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp index 79c067a2..30108c21 100644 --- a/src/nxmaccessmanager.cpp +++ b/src/nxmaccessmanager.cpp @@ -303,7 +303,7 @@ void NexusSSOLogin::onMessage(const QString& s) // first answer // open browser - const auto url = NexusSSOPage.arg(m_guid); + const QUrl url = NexusSSOPage.arg(m_guid); shell::Open(url); m_timeout.stop(); diff --git a/src/settings.cpp b/src/settings.cpp index ebb4fabe..6445bfbe 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -66,7 +66,8 @@ Settings::Settings(const QString& path, bool globalInstance) : m_Settings(path, QSettings::IniFormat), m_Game(m_Settings), m_Geometry(m_Settings), m_Widgets(m_Settings, globalInstance), m_Colors(m_Settings), - m_Plugins(m_Settings), m_Paths(m_Settings), m_Network(m_Settings), + m_Plugins(m_Settings), m_Paths(m_Settings), + m_Network(m_Settings, globalInstance), m_Nexus(*this, m_Settings), m_Steam(*this, m_Settings), m_Interface(m_Settings), m_Diagnostics(m_Settings) { @@ -1670,9 +1671,21 @@ void PathSettings::setOverwrite(const QString& path) } -NetworkSettings::NetworkSettings(QSettings& settings) +NetworkSettings::NetworkSettings(QSettings& settings, bool globalInstance) : m_Settings(settings) { + if (globalInstance) { + updateCustomBrowser(); + } +} + +void NetworkSettings::updateCustomBrowser() +{ + if (useCustomBrowser()) { + MOBase::shell::SetUrlHandler(customBrowserCommand()); + } else { + MOBase::shell::SetUrlHandler(""); + } } bool NetworkSettings::offlineMode() const @@ -1804,6 +1817,28 @@ void NetworkSettings::updateFromOldMap() updateServers(servers); } +bool NetworkSettings::useCustomBrowser() const +{ + return get<bool>(m_Settings, "Settings", "use_custom_browser", false); +} + +void NetworkSettings::setUseCustomBrowser(bool b) +{ + set(m_Settings, "Settings", "use_custom_browser", b); + updateCustomBrowser(); +} + +QString NetworkSettings::customBrowserCommand() const +{ + return get<QString>(m_Settings, "Settings", "custom_browser", ""); +} + +void NetworkSettings::setCustomBrowserCommand(const QString& s) +{ + set(m_Settings, "Settings", "custom_browser", s); + updateCustomBrowser(); +} + ServerList NetworkSettings::serversFromOldMap() const { // for 2.2.1 and before diff --git a/src/settings.h b/src/settings.h index 82c3a615..4d1258bf 100644 --- a/src/settings.h +++ b/src/settings.h @@ -447,7 +447,10 @@ private: class NetworkSettings { public: - NetworkSettings(QSettings& settings); + // globalInstance is forwarded from the Settings constructor; NetworkSettings + // will set the global URL custom command + // + NetworkSettings(QSettings& settings, bool globalInstance); // whether the user has disabled online features // @@ -477,6 +480,16 @@ public: // void updateFromOldMap(); + // whether to use a custom command to open links + // + bool useCustomBrowser() const; + void setUseCustomBrowser(bool b); + + // custom command to open links + // + QString customBrowserCommand() const; + void setCustomBrowserCommand(const QString& s); + void dump() const; private: @@ -485,6 +498,10 @@ private: // for pre 2.2.1 ini files // ServerList serversFromOldMap() const; + + // sets the custom command in uibase, called when the settings change + // + void updateCustomBrowser(); }; @@ -693,8 +710,8 @@ public: // any Settings object created with globalInstance==false won't set the // singleton // - // only WidgetSettings need to know whether it created from a globalInstance, - // see its constructor + // some sub-objects like WidgetSettings and NetworkSettings need to know + // whether they were created from a globalInstance, see their constructor // // @param path path to an ini file // @param globalInsance whether this is the global instance; creates the diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 8670752b..43af5e9f 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -836,7 +836,7 @@ </widget> </item> <item> - <layout class="QGridLayout" name="gridLayout_8"> + <layout class="QGridLayout" name="gridLayout_8" columnstretch="1,1"> <item row="1" column="0"> <widget class="QCheckBox" name="proxyBox"> <property name="statusTip"> @@ -850,16 +850,13 @@ </property> </widget> </item> - <item row="0" column="0"> - <widget class="QCheckBox" name="offlineBox"> - <property name="statusTip"> - <string>Disable automatic internet features</string> - </property> - <property name="whatsThis"> - <string>Disable automatic internet features. This does not affect features that are explicitly invoked by the user (like checking mods for updates, endorsing, opening the web browser)</string> - </property> + <item row="1" column="1"> + <widget class="QCheckBox" name="trackedBox"> <property name="text"> - <string>Offline Mode</string> + <string>Tracked Integration</string> + </property> + <property name="checked"> + <bool>true</bool> </property> </widget> </item> @@ -873,6 +870,19 @@ </property> </widget> </item> + <item row="0" column="0"> + <widget class="QCheckBox" name="offlineBox"> + <property name="statusTip"> + <string>Disable automatic internet features</string> + </property> + <property name="whatsThis"> + <string>Disable automatic internet features. This does not affect features that are explicitly invoked by the user (like checking mods for updates, endorsing, opening the web browser)</string> + </property> + <property name="text"> + <string>Offline Mode</string> + </property> + </widget> + </item> <item row="2" column="0"> <widget class="QCheckBox" name="hideAPICounterBox"> <property name="toolTip"> @@ -886,14 +896,58 @@ </property> </widget> </item> - <item row="1" column="1"> - <widget class="QCheckBox" name="trackedBox"> - <property name="text"> - <string>Tracked Integration</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> + <item row="2" column="1"> + <widget class="QWidget" name="widget_7" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QCheckBox" name="useCustomBrowser"> + <property name="toolTip"> + <string>Use "%1" as a placeholder for the URL.</string> + </property> + <property name="statusTip"> + <string>Use "%1" as a placeholder for the URL.</string> + </property> + <property name="whatsThis"> + <string>Use "%1" as a placeholder for the URL.</string> + </property> + <property name="text"> + <string>Custom browser</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="browserCommand"> + <property name="toolTip"> + <string>Use "%1" as a placeholder for the URL.</string> + </property> + <property name="statusTip"> + <string>Use "%1" as a placeholder for the URL.</string> + </property> + <property name="whatsThis"> + <string>Use "%1" as a placeholder for the URL.</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="browseCustomBrowser"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> </widget> </item> </layout> diff --git a/src/settingsdialognexus.cpp b/src/settingsdialognexus.cpp index 461ff8d6..48827a0e 100644 --- a/src/settingsdialognexus.cpp +++ b/src/settingsdialognexus.cpp @@ -300,6 +300,8 @@ NexusSettingsTab::NexusSettingsTab(Settings& s, SettingsDialog& d) ui->endorsementBox->setChecked(settings().nexus().endorsementIntegration()); ui->trackedBox->setChecked(settings().nexus().trackedIntegration()); ui->hideAPICounterBox->setChecked(settings().interface().hideAPICounter()); + ui->useCustomBrowser->setChecked(settings().network().useCustomBrowser()); + ui->browserCommand->setText(settings().network().customBrowserCommand()); // display server preferences for (const auto& server : s.network().servers()) { @@ -345,10 +347,13 @@ NexusSettingsTab::NexusSettingsTab(Settings& s, SettingsDialog& d) [&]{ dialog().setExitNeeded(Exit::Restart); }); - QObject::connect(ui->clearCacheButton, &QPushButton::clicked, [&]{ on_clearCacheButton_clicked(); }); - QObject::connect(ui->associateButton, &QPushButton::clicked, [&]{ on_associateButton_clicked(); }); + QObject::connect(ui->clearCacheButton, &QPushButton::clicked, [&]{ clearCache(); }); + QObject::connect(ui->associateButton, &QPushButton::clicked, [&]{ associate(); }); + QObject::connect(ui->useCustomBrowser, &QCheckBox::clicked, [&]{ updateCustomBrowser(); }); + QObject::connect(ui->browseCustomBrowser, &QPushButton::clicked, [&]{ browseCustomBrowser(); }); updateNexusData(); + updateCustomBrowser(); } void NexusSettingsTab::update() @@ -358,6 +363,8 @@ void NexusSettingsTab::update() settings().nexus().setEndorsementIntegration(ui->endorsementBox->isChecked()); settings().nexus().setTrackedIntegration(ui->trackedBox->isChecked()); settings().interface().setHideAPICounter(ui->hideAPICounterBox->isChecked()); + settings().network().setUseCustomBrowser(ui->useCustomBrowser->isChecked()); + settings().network().setCustomBrowserCommand(ui->browserCommand->text()); auto servers = settings().network().servers(); @@ -407,13 +414,13 @@ void NexusSettingsTab::update() settings().network().updateServers(servers); } -void NexusSettingsTab::on_clearCacheButton_clicked() +void NexusSettingsTab::clearCache() { QDir(Settings::instance().paths().cache()).removeRecursively(); NexusInterface::instance().clearCache(); } -void NexusSettingsTab::on_associateButton_clicked() +void NexusSettingsTab::associate() { Settings::instance().nexus().registerAsNXMHandler(true); } @@ -442,3 +449,25 @@ void NexusSettingsTab::updateNexusData() ui->nexusHourlyRequests->setText(QObject::tr("N/A")); } } + +void NexusSettingsTab::updateCustomBrowser() +{ + ui->browserCommand->setEnabled(ui->useCustomBrowser->isChecked()); +} + +void NexusSettingsTab::browseCustomBrowser () +{ + const QString Filters = + QObject::tr("Executables (*.exe)") + ";;" + + QObject::tr("All Files (*.*)"); + + QString file = QFileDialog::getOpenFileName( + parentWidget(), QObject::tr("Select the browser executable"), + ui->browserCommand->text(), Filters); + + if (file.isNull() || file == "") { + return; + } + + ui->browserCommand->setText(file + " \"%1\""); +} diff --git a/src/settingsdialognexus.h b/src/settingsdialognexus.h index c915accf..a9bd46c7 100644 --- a/src/settingsdialognexus.h +++ b/src/settingsdialognexus.h @@ -65,9 +65,12 @@ public: private: std::unique_ptr<NexusConnectionUI> m_connectionUI; - void on_clearCacheButton_clicked(); - void on_associateButton_clicked(); + void clearCache(); + void associate(); + void updateNexusData(); + void updateCustomBrowser(); + void browseCustomBrowser(); }; #endif // SETTINGSDIALOGNEXUS_H |
