Browse Source

Implement stringable interface for `Version` type

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
7c1a986e61
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 4
      src/base/search/searchpluginmanager.cpp
  2. 2
      src/base/utils/foreignapps.cpp
  3. 5
      src/base/utils/version.h
  4. 4
      src/gui/mainwindow.cpp
  5. 4
      src/gui/search/pluginselectdialog.cpp
  6. 2
      src/webui/api/appcontroller.cpp
  7. 2
      src/webui/api/searchcontroller.cpp

4
src/base/search/searchpluginmanager.cpp

@ -232,7 +232,7 @@ void SearchPluginManager::installPlugin_impl(const QString &name, const Path &pa
const PluginInfo *plugin = pluginInfo(name); const PluginInfo *plugin = pluginInfo(name);
if (plugin && !(plugin->version < newVersion)) if (plugin && !(plugin->version < newVersion))
{ {
LogMsg(tr("Plugin already at version %1, which is greater than %2").arg(plugin->version, newVersion), Log::INFO); LogMsg(tr("Plugin already at version %1, which is greater than %2").arg(plugin->version.toString(), newVersion.toString()), Log::INFO);
emit pluginUpdateFailed(name, tr("A more recent version of this plugin is already installed.")); emit pluginUpdateFailed(name, tr("A more recent version of this plugin is already installed."));
return; return;
} }
@ -536,7 +536,7 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info)
++numCorrectData; ++numCorrectData;
if (isUpdateNeeded(pluginName, version)) if (isUpdateNeeded(pluginName, version))
{ {
LogMsg(tr("Plugin \"%1\" is outdated, updating to version %2").arg(pluginName, version), Log::INFO); LogMsg(tr("Plugin \"%1\" is outdated, updating to version %2").arg(pluginName, version.toString()), Log::INFO);
updateInfo[pluginName] = version; updateInfo[pluginName] = version;
} }
} }

2
src/base/utils/foreignapps.cpp

@ -83,7 +83,7 @@ namespace
} }
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Python detected, executable name: '%1', version: %2") LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Python detected, executable name: '%1', version: %2")
.arg(info.executableName, info.version), Log::INFO); .arg(info.executableName, info.version.toString()), Log::INFO);
return true; return true;
} }

5
src/base/utils/version.h

@ -35,11 +35,12 @@
#include "base/exceptions.h" #include "base/exceptions.h"
#include "base/global.h" #include "base/global.h"
#include "base/interfaces/istringable.h"
namespace Utils namespace Utils
{ {
template <typename T, std::size_t N, std::size_t Mandatory = N> template <typename T, std::size_t N, std::size_t Mandatory = N>
class Version class Version final : public IStringable
{ {
static_assert(N > 0, "The number of version components may not be smaller than 1"); static_assert(N > 0, "The number of version components may not be smaller than 1");
static_assert(N >= Mandatory, static_assert(N >= Mandatory,
@ -108,7 +109,7 @@ namespace Utils
return m_components.at(i); return m_components.at(i);
} }
operator QString() const QString toString() const override
{ {
// find the last one non-zero component // find the last one non-zero component
std::size_t lastSignificantIndex = N - 1; std::size_t lastSignificantIndex = N - 1;

4
src/gui/mainwindow.cpp

@ -1892,14 +1892,14 @@ void MainWindow::on_actionSearchWidget_triggered()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
const QMessageBox::StandardButton buttonPressed = QMessageBox::question(this, tr("Old Python Runtime") const QMessageBox::StandardButton buttonPressed = QMessageBox::question(this, tr("Old Python Runtime")
, tr("Your Python version (%1) is outdated. Minimum requirement: %2.\nDo you want to install a newer version now?") , tr("Your Python version (%1) is outdated. Minimum requirement: %2.\nDo you want to install a newer version now?")
.arg(pyInfo.version, QLatin1String("3.5.0")) .arg(pyInfo.version.toString(), u"3.5.0")
, (QMessageBox::Yes | QMessageBox::No), QMessageBox::Yes); , (QMessageBox::Yes | QMessageBox::No), QMessageBox::Yes);
if (buttonPressed == QMessageBox::Yes) if (buttonPressed == QMessageBox::Yes)
installPython(); installPython();
#else #else
QMessageBox::information(this, tr("Old Python Runtime") QMessageBox::information(this, tr("Old Python Runtime")
, tr("Your Python version (%1) is outdated. Please upgrade to latest version for search engines to work.\nMinimum requirement: %2.") , tr("Your Python version (%1) is outdated. Please upgrade to latest version for search engines to work.\nMinimum requirement: %2.")
.arg(pyInfo.version, QLatin1String("3.5.0"))); .arg(pyInfo.version.toString(), u"3.5.0"));
#endif #endif
return; return;
} }

4
src/gui/search/pluginselectdialog.cpp

@ -315,7 +315,7 @@ void PluginSelectDialog::addNewPlugin(const QString &pluginName)
DownloadRequest(plugin->url + u"/favicon.ico").saveToFile(true) DownloadRequest(plugin->url + u"/favicon.ico").saveToFile(true)
, this, &PluginSelectDialog::iconDownloadFinished); , this, &PluginSelectDialog::iconDownloadFinished);
} }
item->setText(PLUGIN_VERSION, plugin->version); item->setText(PLUGIN_VERSION, plugin->version.toString());
} }
void PluginSelectDialog::startAsyncOp() void PluginSelectDialog::startAsyncOp()
@ -483,7 +483,7 @@ void PluginSelectDialog::pluginUpdated(const QString &name)
finishAsyncOp(); finishAsyncOp();
PluginVersion version = m_pluginManager->pluginInfo(name)->version; PluginVersion version = m_pluginManager->pluginInfo(name)->version;
QTreeWidgetItem *item = findItemWithID(name); QTreeWidgetItem *item = findItemWithID(name);
item->setText(PLUGIN_VERSION, version); item->setText(PLUGIN_VERSION, version.toString());
m_updatedPlugins.append(name); m_updatedPlugins.append(name);
finishPluginUpdate(); finishPluginUpdate();
} }

2
src/webui/api/appcontroller.cpp

@ -63,7 +63,7 @@
void AppController::webapiVersionAction() void AppController::webapiVersionAction()
{ {
setResult(static_cast<QString>(API_VERSION)); setResult(API_VERSION.toString());
} }
void AppController::versionAction() void AppController::versionAction()

2
src/webui/api/searchcontroller.cpp

@ -388,7 +388,7 @@ QJsonArray SearchController::getPluginsInfo(const QStringList &plugins) const
pluginsArray << QJsonObject pluginsArray << QJsonObject
{ {
{u"name"_qs, pluginInfo->name}, {u"name"_qs, pluginInfo->name},
{u"version"_qs, QString(pluginInfo->version)}, {u"version"_qs, pluginInfo->version.toString()},
{u"fullName"_qs, pluginInfo->fullName}, {u"fullName"_qs, pluginInfo->fullName},
{u"url"_qs, pluginInfo->url}, {u"url"_qs, pluginInfo->url},
{u"supportedCategories"_qs, getPluginCategories(pluginInfo->supportedCategories)}, {u"supportedCategories"_qs, getPluginCategories(pluginInfo->supportedCategories)},

Loading…
Cancel
Save