App: harmonize API of App::Application

* make getHomePath() static and return a std::string
* make getExecutableName() static and return a std::string
This commit is contained in:
wmayer
2021-11-04 10:50:09 +01:00
parent 095d859b14
commit f36126770c
23 changed files with 45 additions and 45 deletions

View File

@@ -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()

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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());

View File

@@ -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;
}

View File

@@ -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");

View File

@@ -97,15 +97,15 @@ BitmapFactoryInst& BitmapFactoryInst::instance(void)
std::map<std::string,std::string>::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/"));
}

View File

@@ -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);
}

View File

@@ -71,7 +71,7 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent )
for (unsigned int i=0; i<d.count(); i++ )
ui->actionMacros->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; i<d.count(); i++ ) {

View File

@@ -121,7 +121,7 @@ void DlgMacroExecuteImp::fillUpList(void)
item->setText(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)

View File

@@ -666,7 +666,7 @@ void DocumentRecoveryHandler::checkForPreviousCrashes(const std::function<void(Q
tmp.setNameFilters(QStringList() << QString::fromLatin1("*.lock"));
tmp.setFilter(QDir::Files);
QString exeName = QString::fromLatin1(App::GetApplication().getExecutableName());
QString exeName = QString::fromStdString(App::Application::getExecutableName());
QList<QFileInfo> locks = tmp.entryInfoList();
for (QList<QFileInfo>::iterator it = locks.begin(); it != locks.end(); ++it) {
QString bn = it->baseName();

View File

@@ -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<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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());

View File

@@ -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 << " <Source>\n" ;
com << " <Creator>Unknown</Creator>\n" ;
com << " <CreationDate>" << QDateTime::currentDateTime().toString().toLatin1().constData() << "</CreationDate>\n" ;
com << " <CreatingSystem>" << App::GetApplication().getExecutableName() << " " << major << "." << minor << "</CreatingSystem>\n" ;
com << " <CreatingSystem>" << App::Application::getExecutableName() << " " << major << "." << minor << "</CreatingSystem>\n" ;
com << " <PartNumber>Unknown</PartNumber>\n";
com << " <Revision>1.0</Revision>\n";
com << " </Source>\n" ;

View File

@@ -680,7 +680,7 @@ void AboutDialog::on_copyButton_clicked()
QTextStream str(&data);
std::map<std::string, std::string>& config = App::Application::Config();
std::map<std::string,std::string>::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());

View File

@@ -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
//

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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")

View File

@@ -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";