From f36126770ca08c7b0d5d32587b8bb7e7b4394d96 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 4 Nov 2021 10:50:09 +0100 Subject: [PATCH] App: harmonize API of App::Application * make getHomePath() static and return a std::string * make getExecutableName() static and return a std::string --- src/App/Application.cpp | 8 ++++---- src/App/Application.h | 4 ++-- src/App/ApplicationPy.cpp | 2 +- src/App/Document.cpp | 2 +- src/Gui/Application.cpp | 8 ++++---- src/Gui/ApplicationPy.cpp | 6 +++--- src/Gui/Assistant.cpp | 8 ++++---- src/Gui/BitmapFactory.cpp | 6 +++--- src/Gui/Command.cpp | 2 +- src/Gui/DlgActionsImp.cpp | 2 +- src/Gui/DlgMacroExecuteImp.cpp | 6 +++--- src/Gui/DocumentRecovery.cpp | 2 +- src/Gui/DownloadItem.cpp | 2 +- src/Gui/GuiApplication.cpp | 2 +- src/Gui/MainWindow.cpp | 4 ++-- src/Gui/NetworkRetriever.cpp | 6 +++--- src/Gui/SoFCOffscreenRenderer.cpp | 4 ++-- src/Gui/Splashscreen.cpp | 2 +- src/Gui/WidgetFactory.cpp | 2 +- src/Mod/Import/App/AppImportPy.cpp | 2 +- src/Mod/Import/Gui/AppImportGuiPy.cpp | 2 +- src/Mod/Path/Gui/AppPathGuiPy.cpp | 6 +++--- src/Mod/Raytracing/App/AppRaytracingPy.cpp | 2 +- 23 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index d51a6740fc..faac993af3 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1040,14 +1040,14 @@ Application::TransactionSignaller::~TransactionSignaller() { } } -const char* Application::getHomePath(void) const +std::string Application::getHomePath() { - return _mConfig["AppHomePath"].c_str(); + return mConfig["AppHomePath"]; } -const char* Application::getExecutableName(void) const +std::string Application::getExecutableName() { - return _mConfig["ExeName"].c_str(); + return mConfig["ExeName"]; } std::string Application::getTempPath() diff --git a/src/App/Application.h b/src/App/Application.h index 0d38fcfdab..fbd20abc7c 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -395,8 +395,8 @@ public: /** @name Application directories */ //@{ - const char* getHomePath(void) const; - const char* getExecutableName(void) const; + static std::string getHomePath(); + static std::string getExecutableName(); /*! Returns the temporary directory. By default, this is set to the system's temporary directory but can be customized by the user. diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 0eaa6ac788..de213ff32e 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -691,7 +691,7 @@ PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args) if (!PyArg_ParseTuple(args, "")) // convert args: Python->C return NULL; // NULL triggers exception - Py::String homedir(GetApplication().getHomePath(),"utf-8"); + Py::String homedir(Application::getHomePath(),"utf-8"); return Py::new_reference_to(homedir); } diff --git a/src/App/Document.cpp b/src/App/Document.cpp index f6ec4f46ac..0c6fceb43f 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1685,7 +1685,7 @@ std::string Document::getTransientDirectoryName(const std::string& uuid, const s std::stringstream s; QCryptographicHash hash(QCryptographicHash::Sha1); hash.addData(filename.c_str(), filename.size()); - s << App::Application::getTempPath() << GetApplication().getExecutableName() + s << App::Application::getTempPath() << App::Application::getExecutableName() << "_Doc_" << uuid << "_" << hash.result().toHex().left(6).constData() << "_" << QCoreApplication::applicationPid(); diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index e0ce35be61..0dc5ed879a 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1955,13 +1955,13 @@ void Application::runApplication(void) mainApp.setApplicationName(QString::fromUtf8(it->second.c_str())); } else { - mainApp.setApplicationName(QString::fromUtf8(App::GetApplication().getExecutableName())); + mainApp.setApplicationName(QString::fromStdString(App::Application::getExecutableName())); } #ifndef Q_OS_MACX mainApp.setWindowIcon(Gui::BitmapFactory().pixmap(App::Application::Config()["AppIcon"].c_str())); #endif QString plugin; - plugin = QString::fromUtf8(App::GetApplication().getHomePath()); + plugin = QString::fromStdString(App::Application::getHomePath()); plugin += QLatin1String("/plugins"); QCoreApplication::addLibraryPath(plugin); @@ -2127,7 +2127,7 @@ void Application::runApplication(void) // init the Inventor subsystem initOpenInventor(); - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); it = cfg.find("WindowTitle"); if (it != cfg.end()) { @@ -2267,7 +2267,7 @@ void Application::runApplication(void) try { std::stringstream s; - s << App::Application::getTempPath() << App::GetApplication().getExecutableName() + s << App::Application::getTempPath() << App::Application::getExecutableName() << "_" << QCoreApplication::applicationPid() << ".lock"; // open a lock file with the PID Base::FileInfo fi(s.str()); diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index cf23554b0d..82a883cb1f 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -1029,7 +1029,7 @@ PyObject* Application::sAddResPath(PyObject * /*self*/, PyObject *args) PyMem_Free(filePath); if (QDir::isRelativePath(path)) { // Home path ends with '/' - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); path = home + path; } @@ -1048,7 +1048,7 @@ PyObject* Application::sAddLangPath(PyObject * /*self*/, PyObject *args) PyMem_Free(filePath); if (QDir::isRelativePath(path)) { // Home path ends with '/' - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); path = home + path; } @@ -1066,7 +1066,7 @@ PyObject* Application::sAddIconPath(PyObject * /*self*/, PyObject *args) PyMem_Free(filePath); if (QDir::isRelativePath(path)) { // Home path ends with '/' - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); path = home + path; } diff --git a/src/Gui/Assistant.cpp b/src/Gui/Assistant.cpp index f903c7a28f..e905fe8dfd 100644 --- a/src/Gui/Assistant.cpp +++ b/src/Gui/Assistant.cpp @@ -85,8 +85,8 @@ bool Assistant::startAssistant() if (proc->state() != QProcess::Running) { #ifdef Q_OS_WIN QString app; - app = QDir::toNativeSeparators(QString::fromUtf8 - (App::GetApplication().getHomePath()) + QLatin1String("bin/")); + app = QDir::toNativeSeparators(QString::fromStdString + (App::Application::getHomePath()) + QLatin1String("bin/")); #elif defined(Q_OS_MAC) QString app = QCoreApplication::applicationDirPath() + QDir::separator(); #else @@ -95,8 +95,8 @@ bool Assistant::startAssistant() app += QLatin1String("assistant"); // get the name of the executable and the doc path - QString exe = QString::fromUtf8(App::GetApplication().getExecutableName()); - QString doc = QString::fromUtf8(App::Application::getHelpDir().c_str()); + QString exe = QString::fromStdString(App::Application::getExecutableName()); + QString doc = QString::fromStdString(App::Application::getHelpDir()); QString qhc = doc + exe.toLower() + QLatin1String(".qhc"); diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index bfa5317cf1..2e9ffd7156 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -97,15 +97,15 @@ BitmapFactoryInst& BitmapFactoryInst::instance(void) std::map::const_iterator it; it = App::GetApplication().Config().find("ProgramIcons"); if (it != App::GetApplication().Config().end()) { - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); QString path = QString::fromUtf8(it->second.c_str()); if (QDir(path).isRelative()) { path = QFileInfo(QDir(home), path).absoluteFilePath(); } _pcSingleton->addPath(path); } - _pcSingleton->addPath(QString::fromLatin1("%1/icons").arg(QString::fromUtf8(App::GetApplication().getHomePath()))); - _pcSingleton->addPath(QString::fromLatin1("%1/icons").arg(QString::fromUtf8(App::GetApplication().Config()["UserAppData"].c_str()))); + _pcSingleton->addPath(QString::fromLatin1("%1/icons").arg(QString::fromStdString(App::Application::getHomePath()))); + _pcSingleton->addPath(QString::fromLatin1("%1/icons").arg(QString::fromStdString(App::Application::getUserAppDataDir()))); _pcSingleton->addPath(QLatin1String(":/icons/")); _pcSingleton->addPath(QLatin1String(":/Icons/")); } diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index cd95d3ae31..3f44c28d87 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -1117,7 +1117,7 @@ void MacroCommand::activated(int iMsg) d = QDir(QString::fromUtf8(cMacroPath.c_str())); } else { - QString dirstr = QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro"); + QString dirstr = QString::fromStdString(App::Application::getHomePath()) + QString::fromLatin1("Macro"); d = QDir(dirstr); } diff --git a/src/Gui/DlgActionsImp.cpp b/src/Gui/DlgActionsImp.cpp index 35aa3b9f0b..f2c85ebb99 100644 --- a/src/Gui/DlgActionsImp.cpp +++ b/src/Gui/DlgActionsImp.cpp @@ -71,7 +71,7 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent ) for (unsigned int i=0; iactionMacros->insertItem(0,d[i],QVariant(false)); - QString systemMacroDirStr = QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro"); + QString systemMacroDirStr = QString::fromStdString(App::Application::getHomePath()) + QString::fromLatin1("Macro"); d = QDir(systemMacroDirStr, QLatin1String("*.FCMacro *.py")); if (d.exists()) { for (unsigned int i=0; isetText(0, dir[i]); } - QString dirstr = QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro"); + QString dirstr = QString::fromStdString(App::Application::getHomePath()) + QString::fromLatin1("Macro"); dir = QDir(dirstr, QLatin1String("*.FCMacro *.py")); ui->systemMacroListBox->clear(); @@ -268,7 +268,7 @@ void DlgMacroExecuteImp::accept() dir =QDir(this->macroPath); } else { - QString dirstr = QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro"); + QString dirstr = QString::fromStdString(App::Application::getHomePath()) + QString::fromLatin1("Macro"); dir = QDir(dirstr); } @@ -319,7 +319,7 @@ void DlgMacroExecuteImp::on_editButton_clicked() else { //index == 1 system-wide item = ui->systemMacroListBox->currentItem(); - dir.setPath(QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro")); + dir.setPath(QString::fromStdString(App::Application::getHomePath()) + QString::fromLatin1("Macro")); } if (!item) diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 4f2d60006e..924c4e32fb 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -666,7 +666,7 @@ void DocumentRecoveryHandler::checkForPreviousCrashes(const std::function locks = tmp.entryInfoList(); for (QList::iterator it = locks.begin(); it != locks.end(); ++it) { QString bn = it->baseName(); diff --git a/src/Gui/DownloadItem.cpp b/src/Gui/DownloadItem.cpp index 43e59a26ba..6e87fbc5e8 100644 --- a/src/Gui/DownloadItem.cpp +++ b/src/Gui/DownloadItem.cpp @@ -273,7 +273,7 @@ void DownloadItem::init() QString DownloadItem::getDownloadDirectory() const { - QString exe = QString::fromLatin1(App::GetApplication().getExecutableName()); + QString exe = QString::fromStdString(App::Application::getExecutableName()); QString path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); QString dirPath = QDir(path).filePath(exe); Base::Reference hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp") diff --git a/src/Gui/GuiApplication.cpp b/src/Gui/GuiApplication.cpp index b254658000..1a9e7e335f 100644 --- a/src/Gui/GuiApplication.cpp +++ b/src/Gui/GuiApplication.cpp @@ -177,7 +177,7 @@ public: , running(false) { timer->setSingleShot(true); - std::string exeName = App::GetApplication().getExecutableName(); + std::string exeName = App::Application::getExecutableName(); serverName = QString::fromStdString(exeName); } diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 35a335e9c3..b0dfe66630 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1490,7 +1490,7 @@ QPixmap MainWindow::aboutImage() const if (!about_path.empty() && about_image.isNull()) { QString path = QString::fromUtf8(about_path.c_str()); if (QDir(path).isRelative()) { - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); path = QFileInfo(QDir(home), path).absoluteFilePath(); } about_image.load(path); @@ -1517,7 +1517,7 @@ QPixmap MainWindow::splashImage() const if (splash_image.isNull()) { QString path = QString::fromUtf8(splash_path.c_str()); if (QDir(path).isRelative()) { - QString home = QString::fromUtf8(App::GetApplication().getHomePath()); + QString home = QString::fromStdString(App::Application::getHomePath()); path = QFileInfo(QDir(home), path).absoluteFilePath(); } diff --git a/src/Gui/NetworkRetriever.cpp b/src/Gui/NetworkRetriever.cpp index 8ba993e207..38e8528f62 100644 --- a/src/Gui/NetworkRetriever.cpp +++ b/src/Gui/NetworkRetriever.cpp @@ -418,7 +418,7 @@ Action * StdCmdDownloadOnlineHelp::createAction(void) { Action *pcAction; - QString exe = QString::fromLatin1(App::GetApplication().getExecutableName()); + QString exe = QString::fromStdString(App::Application::getExecutableName()); pcAction = new Action(this,getMainWindow()); pcAction->setText(QCoreApplication::translate( this->className(), getMenuText())); @@ -437,7 +437,7 @@ Action * StdCmdDownloadOnlineHelp::createAction(void) void StdCmdDownloadOnlineHelp::languageChange() { if (_pcAction) { - QString exe = QString::fromLatin1(App::GetApplication().getExecutableName()); + QString exe = QString::fromStdString(App::Application::getExecutableName()); _pcAction->setText(QCoreApplication::translate( this->className(), getMenuText())); _pcAction->setToolTip(QCoreApplication::translate( @@ -483,7 +483,7 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg) bool canStart = false; // set output directory - QString path = QString::fromUtf8(App::GetApplication().getHomePath()); + QString path = QString::fromStdString(App::Application::getHomePath()); path += QString::fromLatin1("/doc/"); ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OnlineHelp"); path = QString::fromUtf8(hURLGrp->GetASCII( "DownloadLocation", path.toLatin1() ).c_str()); diff --git a/src/Gui/SoFCOffscreenRenderer.cpp b/src/Gui/SoFCOffscreenRenderer.cpp index a54220fac7..01c393fd46 100644 --- a/src/Gui/SoFCOffscreenRenderer.cpp +++ b/src/Gui/SoFCOffscreenRenderer.cpp @@ -166,7 +166,7 @@ void SoFCOffscreenRenderer::writeToImageFile(const char* filename, const char* c img.setText(QLatin1String("Description"), QString::fromUtf8(comment)); img.setText(QLatin1String("Creation Time"), QDateTime::currentDateTime().toString()); img.setText(QLatin1String("Software"), - QString::fromUtf8(App::GetApplication().getExecutableName())); + QString::fromStdString(App::Application::getExecutableName())); } QFile f(QString::fromUtf8(filename)); @@ -296,7 +296,7 @@ std::string SoFCOffscreenRenderer::createMIBA(const SbMatrix& mat) const com << " \n" ; com << " Unknown\n" ; com << " " << QDateTime::currentDateTime().toString().toLatin1().constData() << "\n" ; - com << " " << App::GetApplication().getExecutableName() << " " << major << "." << minor << "\n" ; + com << " " << App::Application::getExecutableName() << " " << major << "." << minor << "\n" ; com << " Unknown\n"; com << " 1.0\n"; com << " \n" ; diff --git a/src/Gui/Splashscreen.cpp b/src/Gui/Splashscreen.cpp index 4b8e5b53fd..c899f92ae9 100644 --- a/src/Gui/Splashscreen.cpp +++ b/src/Gui/Splashscreen.cpp @@ -680,7 +680,7 @@ void AboutDialog::on_copyButton_clicked() QTextStream str(&data); std::map& config = App::Application::Config(); std::map::iterator it; - QString exe = QString::fromLatin1(App::GetApplication().getExecutableName()); + QString exe = QString::fromStdString(App::Application::getExecutableName()); QString major = QString::fromLatin1(config["BuildVersionMajor"].c_str()); QString minor = QString::fromLatin1(config["BuildVersionMinor"].c_str()); diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp index b68456e7a4..241c35f655 100644 --- a/src/Gui/WidgetFactory.cpp +++ b/src/Gui/WidgetFactory.cpp @@ -431,7 +431,7 @@ void PyResource::load(const char* name) // checks whether it's a relative path if (fi.isRelative()) { QString cwd = QDir::currentPath (); - QString home= QDir(QString::fromUtf8(App::GetApplication().getHomePath())).path(); + QString home= QDir(QString::fromStdString(App::Application::getHomePath())).path(); // search in cwd and home path for the file // diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index f76e59bf15..88e7f2be6e 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -368,7 +368,7 @@ private: //makeHeader.SetName(new TCollection_HAsciiString((Standard_CString)Utf8Name.c_str())); makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str())); makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str())); - makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::GetApplication().getExecutableName())); + makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::Application::getExecutableName().c_str())); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str()); if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) { diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 774c40e2f9..8f855a3a32 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -668,7 +668,7 @@ private: //makeHeader.SetName(new TCollection_HAsciiString((Standard_CString)Utf8Name.c_str())); makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str())); makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str())); - makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::GetApplication().getExecutableName())); + makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::Application::getExecutableName().c_str())); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str()); if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) { diff --git a/src/Mod/Path/Gui/AppPathGuiPy.cpp b/src/Mod/Path/Gui/AppPathGuiPy.cpp index a442244b41..062da3a069 100644 --- a/src/Mod/Path/Gui/AppPathGuiPy.cpp +++ b/src/Mod/Path/Gui/AppPathGuiPy.cpp @@ -82,7 +82,7 @@ private: wc.restoreCursor(); try { - std::string path = App::GetApplication().getHomePath(); + std::string path = App::Application::getHomePath(); path += "Mod/Path/PathScripts/post/"; QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py")); std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro") @@ -149,7 +149,7 @@ private: wc.restoreCursor(); try { - std::string path = App::GetApplication().getHomePath(); + std::string path = App::Application::getHomePath(); path += "Mod/Path/PathScripts/post/"; QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py")); std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro") @@ -225,7 +225,7 @@ private: if (objlist.size() == 0) throw Py::RuntimeError("No object to export"); - std::string path = App::GetApplication().getHomePath(); + std::string path = App::Application::getHomePath(); path += "Mod/Path/PathScripts/post/"; QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_post.py")); std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro") diff --git a/src/Mod/Raytracing/App/AppRaytracingPy.cpp b/src/Mod/Raytracing/App/AppRaytracingPy.cpp index 5b124e91fc..dc6a528415 100644 --- a/src/Mod/Raytracing/App/AppRaytracingPy.cpp +++ b/src/Mod/Raytracing/App/AppRaytracingPy.cpp @@ -222,7 +222,7 @@ private: if (! PyArg_ParseTuple(args.ptr(), "ss",&FileName,&DestDir)) throw Py::Exception(); - std::string resName = App::GetApplication().getHomePath(); + std::string resName = App::Application::getHomePath(); resName += "Mod"; resName += PATHSEP ; resName += "Raytracing";