Skip to content

Commit

Permalink
App: remove LibraryInfoArray global object
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Jan 29, 2025
1 parent e6171c2 commit 7bbee9a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 71 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ list(
${PROJECT_SOURCE_DIR}/src/app/app_module_properties.cpp
${PROJECT_SOURCE_DIR}/src/app/app_module.cpp
${PROJECT_SOURCE_DIR}/src/app/app_ui_state.cpp
${PROJECT_SOURCE_DIR}/src/app/library_info.cpp
${PROJECT_SOURCE_DIR}/src/app/recent_files.cpp
)

Expand Down
21 changes: 21 additions & 0 deletions src/app/app_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ QString AppModule::languageCode() const
return QString::fromUtf8(langDefault.data(), CppUtils::safeStaticCast<int>(langDefault.size()));
}

void AppModule::addLibraryInfo(const LibraryInfo& lib)
{
if (!lib.name.empty() && !lib.version.empty())
m_vecLibraryInfo.push_back(lib);
}

void AppModule::addLibraryInfo(
std::string_view libName, std::string_view version, std::string_view versionDetails
)
{
const LibraryInfo libInfo{
std::string{libName}, std::string{version}, std::string{versionDetails}
};
this->addLibraryInfo(libInfo);
}

Span<const LibraryInfo> AppModule::libraryInfoArray() const
{
return m_vecLibraryInfo;
}

bool AppModule::excludeSettingPredicate(const Property& prop)
{
return !prop.isUserVisible();
Expand Down
7 changes: 7 additions & 0 deletions src/app/app_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "app_module_properties.h"
#include "library_info.h"
#include "qstring_utils.h"

#include "../base/application.h"
Expand Down Expand Up @@ -78,6 +79,11 @@ class AppModule :
// Short-name of the current language in use(eg. en=english)
QString languageCode() const;

// Information about 3rd-party libraries used by the application
void addLibraryInfo(const LibraryInfo& lib);
void addLibraryInfo(std::string_view libName, std::string_view version, std::string_view versionDetails = "");
Span<const LibraryInfo> libraryInfoArray() const;

// Logging
void clearMessageLog();
Span<const Message> messageLog() const { return m_messageLog; }
Expand Down Expand Up @@ -135,6 +141,7 @@ class AppModule :
QLocale m_qtLocale;
std::vector<std::unique_ptr<DocumentTreeNodePropertiesProvider>> m_vecDocTreeNodePropsProvider;
std::function<Thumbnail(GuiDocument*, QSize)> m_fnRecentFileThumbnailRecorder;
std::vector<LibraryInfo> m_vecLibraryInfo;
};

} // namespace Mayo
2 changes: 1 addition & 1 deletion src/app/command_system_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ QString CommandSystemInformation::data()
ostr << '\n' << "OpenCascade: " << OCC_VERSION_STRING_EXT << " (build)" << '\n';

// Other registered libraries
for (const auto& libInfo : LibraryInfoArray::get()) {
for (const LibraryInfo& libInfo : AppModule::get()->libraryInfoArray()) {
ostr << '\n' << libInfo.name << ": " << libInfo.version << " " << libInfo.versionDetails << '\n';
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/commands_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "commands_help.h"

#include "app_module.h"
#include "dialog_about.h"
#include "library_info.h"
#include "qtwidgets_utils.h"
Expand Down Expand Up @@ -42,7 +43,7 @@ CommandAbout::CommandAbout(IAppContext* context)
void CommandAbout::execute()
{
auto dlg = new DialogAbout(this->widgetMain());
for (const auto& libInfo : LibraryInfoArray::get())
for (const LibraryInfo& libInfo : AppModule::get()->libraryInfoArray())
dlg->addLibraryInfo(libInfo.name, libInfo.version);

QtWidgetsUtils::asyncDialogExec(dlg);
Expand Down
40 changes: 0 additions & 40 deletions src/app/library_info.cpp

This file was deleted.

15 changes: 4 additions & 11 deletions src/app/library_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@

#pragma once

#include "../base/span.h"

#include <string>
#include <string_view>

namespace Mayo {

// Provides information about a 3rd-party library used by the application
struct LibraryInfo {
// Precise name of the library
std::string name;
// Version string, can be codenamed and/or semantic
std::string version;
// Addition details about the version, such as compilation flags
std::string versionDetails;
};

struct LibraryInfoArray {
static void add(
std::string_view libName, std::string_view version, std::string_view versionDetails = ""
);

static Span<const LibraryInfo> get();
};

} // namespace Mayo
15 changes: 7 additions & 8 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ static int runApp(QCoreApplication* qtApp)
auto appModule = AppModule::get();
appModule->settings()->setStorage(std::make_unique<QSettingsStorage>());
appModule->setRecentFileThumbnailRecorder(&createGuiDocumentThumbnail);
appModule->addLibraryInfo(
IO::AssimpLib::strName(), IO::AssimpLib::strVersion(), IO::AssimpLib::strVersionDetails()
);
appModule->addLibraryInfo(
IO::GmioLib::strName(), IO::GmioLib::strVersion(), IO::GmioLib::strVersionDetails()
);

{
// Load translation files
auto fnLoadQmFile = [=](const QString& qmFilePath) {
Expand Down Expand Up @@ -401,14 +408,6 @@ static int runApp(QCoreApplication* qtApp)
appModule->properties()->IO_bindParameters(ioSystem);
appModule->properties()->retranslate();

// Register library infos
LibraryInfoArray::add(
IO::AssimpLib::strName(), IO::AssimpLib::strVersion(), IO::AssimpLib::strVersionDetails()
);
LibraryInfoArray::add(
IO::GmioLib::strName(), IO::GmioLib::strVersion(), IO::GmioLib::strVersionDetails()
);

// Process CLI
if (args.showSystemInformation) {
CommandSystemInformation cmdSysInfo(nullptr);
Expand Down
16 changes: 7 additions & 9 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void showSystemInformation(std::ostream& ostr)
ostr << '\n' << "OpenCascade: " << OCC_VERSION_STRING_EXT << " (build)" << '\n';

// Other registered libraries
for (const LibraryInfo& libInfo : LibraryInfoArray::get()) {
for (const LibraryInfo& libInfo : AppModule::get()->libraryInfoArray()) {
ostr << '\n' << libInfo.name << ": " << libInfo.version
<< " " << libInfo.versionDetails
<< '\n';
Expand Down Expand Up @@ -406,6 +406,12 @@ static int runApp(QCoreApplication* qtApp)

// Initialize Base application
auto app = appModule->application();
appModule->addLibraryInfo(
IO::AssimpLib::strName(), IO::AssimpLib::strVersion(), IO::AssimpLib::strVersionDetails()
);
appModule->addLibraryInfo(
IO::GmioLib::strName(), IO::GmioLib::strVersion(), IO::GmioLib::strVersionDetails()
);
TextId::addTranslatorFunction(&qtAppTranslate); // Set Qt i18n backend
#ifdef MAYO_OS_WINDOWS
initOpenCascadeEnvironment("opencascade.conf");
Expand Down Expand Up @@ -448,14 +454,6 @@ static int runApp(QCoreApplication* qtApp)
return 0;
}

// Register library infos
LibraryInfoArray::add(
IO::AssimpLib::strName(), IO::AssimpLib::strVersion(), IO::AssimpLib::strVersionDetails()
);
LibraryInfoArray::add(
IO::GmioLib::strName(), IO::GmioLib::strVersion(), IO::GmioLib::strVersionDetails()
);

// Process CLI
if (args.showSystemInformation) {
showSystemInformation(std::cout);
Expand Down

0 comments on commit 7bbee9a

Please sign in to comment.