librecad/0001-fixed-1488-getDirectoryList-failed-on-Linux-when-lib.patch
Jan Engelhardt fbbbf27993 Accepting request 944220 from home:jirislaby:branches:graphics
- replace the revert by an upstream fix
  * add 0001-fixed-1488-getDirectoryList-failed-on-Linux-when-lib.patch
  * remove
    0001-Revert-AppImage-build-on-GitHub-Actions-with-go-appi.patch
    0002-Revert-RS_System-getDirectoryList-add-plugins-folder.patch
    0003-Revert-fix-RS_System-getDirectoryList-use-relative-p.patch

OBS-URL: https://build.opensuse.org/request/show/944220
OBS-URL: https://build.opensuse.org/package/show/graphics/librecad?expand=0&rev=63
2022-01-06 12:03:32 +00:00

273 lines
11 KiB
Diff

From: Armin Stebich <home@mail.lordofbikes.de>
Date: Thu, 6 Jan 2022 11:36:44 +0100
Subject: fixed #1488, getDirectoryList() failed on Linux when librecad is in
$PATH
Git-repo: git://github.com/LibreCAD/LibreCAD.git
Git-commit: 8c3b652a8813588d67ef6bef17ea83ccc3b20f89
Patch-mainline: yes
References: paths fix
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
librecad/src/lib/engine/rs_system.cpp | 27 ++++---
librecad/src/lib/engine/rs_system.h | 15 +---
librecad/src/main/console_dxf2pdf/console_dxf2pdf.cpp | 61 ++++++++----------
librecad/src/main/main.cpp | 21 ++----
4 files changed, 57 insertions(+), 67 deletions(-)
--- a/librecad/src/lib/engine/rs_system.cpp
+++ b/librecad/src/lib/engine/rs_system.cpp
@@ -47,20 +47,20 @@ RS_System* RS_System::uniqueInstance = N
* @param appVersion Application version (e.g. "1.2.3")
* @param appDirName Application directory name used for
* subdirectories in /usr, /etc ~/.
- * @param appDir Absolute application directory (e.g. /opt/qcad)
- * defaults to current directory.
*/
-void RS_System::init(const QString& appName, const QString& appVersion,
- const QString& appDirName, const QString& appDir) {
+void RS_System::init(const QString& appName,
+ const QString& appVersion,
+ const QString& appDirName) {
this->appName = appName;
this->appVersion = appVersion;
this->appDirName = appDirName;
- if (appDir == "") {
- this->appDir = QDir::currentPath();
- }
- else {
- this->appDir = appDir;
- }
+ this->appDir = QCoreApplication::applicationDirPath();
+
+ // when appDir is not HOME or CURRENT dir, search appDir too in getDirectoryList()
+ externalAppDir = (!appDir.isEmpty()
+ && "/" != appDir
+ && getHomeDir() != appDir
+ && getCurrentDir() != appDir);
RS_DEBUG->print("RS_System::init: System %s initialized.", appName.toLatin1().data());
RS_DEBUG->print("RS_System::init: App dir: %s", appDir.toLatin1().data());
@@ -563,14 +563,15 @@ QStringList RS_System::getDirectoryList(
dirList.append( getHomeDir() + "/." + appDirName + "/" + subDirectory);
//local (application) directory has priority over other dirs:
- if (!appDir.isEmpty() && appDir!="/" && appDir!=getHomeDir()) {
- if (appDir != getCurrentDir() && subDirectory != QString( "plugins")) {// 17 Aug, 2011, Dongxu Li, do not look for plugins in the current folder, we should install plugins to system or ~/.LibreCAD/plugins/
+ if (!subDirectory.compare( "plugins")) {
+ // 17 Aug, 2011, Dongxu Li, do not look for plugins in the current folder,
+ // we should install plugins to system or ~/.librecad/plugins/
+ if (externalAppDir) {
dirList.append( appDir + "/" + subDirectory);
}
}
#ifdef Q_OS_UNIX
- RS_DEBUG->print( RS_Debug::D_ERROR, "RS_System::getDirectoryList: %s", appDir.toStdString().c_str());
// for AppImage use relative paths from executable
// from packet manager the executable is in /usr/bin
// in AppImage the executable is APPDIR/usr/bin
--- a/librecad/src/lib/engine/rs_system.h
+++ b/librecad/src/lib/engine/rs_system.h
@@ -63,8 +63,9 @@ public:
return uniqueInstance;
}
- void init(const QString& appName, const QString& appVersion,
- const QString& appDirName, const QString& appDir="");
+ void init(const QString& appName,
+ const QString& appVersion,
+ const QString& appDirName);
void initLanguageList();
void initAllLanguagesList();
@@ -86,13 +87,6 @@ public:
}
/**
- * @return Application directory.
- */
- QString getAppDir() {
- return appDir;
- }
-
- /**
* @return Application Data directory.
*/
QString getAppDataDir();
@@ -200,7 +194,8 @@ protected:
QString appDir;
QStringList languageList; //< List of available translations
- bool initialized;
+ bool initialized {false};
+ bool externalAppDir {false};
QList<QSharedPointer<RS_Locale> > allKnownLocales;
};
--- a/librecad/src/main/console_dxf2pdf/console_dxf2pdf.cpp
+++ b/librecad/src/main/console_dxf2pdf/console_dxf2pdf.cpp
@@ -3,6 +3,7 @@
** This file was created for the LibreCAD project, a 2D CAD program.
**
** Copyright (C) 2018 Alexander Pravdin <aledin@mail.ru>
+** Copyright (C) 2022 A. Stebich (librecad@mail.lordofbikes.de)
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -45,8 +46,6 @@ static void parseMarginsArg(QString, Pdf
int console_dxf2pdf(int argc, char* argv[])
{
- //QT_REQUIRE_VERSION(argc, argv, "5.2.1");
-
RS_DEBUG->setLevel(RS_Debug::D_NOTHING);
QApplication app(argc, argv);
@@ -55,78 +54,78 @@ int console_dxf2pdf(int argc, char* argv
QCoreApplication::setApplicationVersion(XSTR(LC_VERSION));
QFileInfo prgInfo(QFile::decodeName(argv[0]));
- QString prgDir(prgInfo.absolutePath());
RS_SETTINGS->init(app.organizationName(), app.applicationName());
- RS_SYSTEM->init(app.applicationName(), app.applicationVersion(),
- XSTR(QC_APPDIR), prgDir);
+ RS_SYSTEM->init( app.applicationName(), app.applicationVersion(), XSTR(QC_APPDIR));
QCommandLineParser parser;
- QString appDesc;
- QString librecad;
+ QStringList appDesc;
+ QString librecad( prgInfo.filePath());
if (prgInfo.baseName() != "dxf2pdf") {
- librecad = prgInfo.filePath();
- appDesc = "\ndxf2pdf usage: " + prgInfo.filePath()
- + " dxf2pdf [options] <dxf_files>\n";
+ librecad += " dxf2pdf"; // executable is not dxf2pdf, thus argv[1] must be 'dxf2pdf'
+ appDesc << "";
+ appDesc << "dxf2pdf " + QObject::tr( "usage: ") + librecad + QObject::tr( " [options] <dxf_files>");
}
- appDesc += "\nPrint a bunch of DXF files to PDF file(s).";
- appDesc += "\n\n";
- appDesc += "Examples:\n\n";
- appDesc += " " + librecad + " dxf2pdf *.dxf";
- appDesc += " -- print all dxf files to pdf files with the same names.\n";
- appDesc += "\n";
- appDesc += " " + librecad + " dxf2pdf -o some.pdf *.dxf";
- appDesc += " -- print all dxf files to 'some.pdf' file.";
- parser.setApplicationDescription(appDesc);
+ appDesc << "";
+ appDesc << "Print a bunch of DXF files to PDF file(s).";
+ appDesc << "";
+ appDesc << "Examples:";
+ appDesc << "";
+ appDesc << " " + librecad + QObject::tr( " *.dxf");
+ appDesc << " " + QObject::tr( "-- print all dxf files to pdf files with the same names.");
+ appDesc << "";
+ appDesc << " " + librecad + QObject::tr( " -o some.pdf *.dxf");
+ appDesc << " " + QObject::tr( "-- print all dxf files to 'some.pdf' file.");
+ parser.setApplicationDescription( appDesc.join( "\n"));
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption fitOpt(QStringList() << "a" << "fit",
- "Auto fit and center drawing to page.");
+ QObject::tr( "Auto fit and center drawing to page."));
parser.addOption(fitOpt);
QCommandLineOption centerOpt(QStringList() << "c" << "center",
- "Auto center drawing on page.");
+ QObject::tr( "Auto center drawing on page."));
parser.addOption(centerOpt);
QCommandLineOption grayOpt(QStringList() << "k" << "grayscale",
- "Print grayscale.");
+ QObject::tr( "Print grayscale."));
parser.addOption(grayOpt);
QCommandLineOption monoOpt(QStringList() << "m" << "monochrome",
- "Print monochrome (black/white).");
+ QObject::tr( "Print monochrome (black/white)."));
parser.addOption(monoOpt);
QCommandLineOption pageSizeOpt(QStringList() << "p" << "paper",
- "Paper size (Width x Height) in mm.", "WxH");
+ QObject::tr( "Paper size (Width x Height) in mm.", "WxH"));
parser.addOption(pageSizeOpt);
QCommandLineOption resOpt(QStringList() << "r" << "resolution",
- "Output resolution (DPI).", "integer");
+ QObject::tr( "Output resolution (DPI).", "integer"));
parser.addOption(resOpt);
QCommandLineOption scaleOpt(QStringList() << "s" << "scale",
- "Output scale. E.g.: 0.01 (for 1:100 scale).", "double");
+ QObject::tr( "Output scale. E.g.: 0.01 (for 1:100 scale)."), "double");
parser.addOption(scaleOpt);
QCommandLineOption marginsOpt(QStringList() << "f" << "margins",
- "Paper margins in mm (integer or float).", "L,T,R,B");
+ QObject::tr( "Paper margins in mm (integer or float)."), "L,T,R,B");
parser.addOption(marginsOpt);
QCommandLineOption pagesNumOpt(QStringList() << "z" << "pages",
- "Print on multiple pages (Horiz. x Vert.).", "HxV");
+ QObject::tr( "Print on multiple pages (Horiz. x Vert.)."), "HxV");
parser.addOption(pagesNumOpt);
QCommandLineOption outFileOpt(QStringList() << "o" << "outfile",
- "Output PDF file.", "file");
+ QObject::tr( "Output PDF file.", "file"));
parser.addOption(outFileOpt);
QCommandLineOption outDirOpt(QStringList() << "t" << "directory",
- "Target output directory.", "path");
+ QObject::tr( "Target output directory."), "path");
parser.addOption(outDirOpt);
- parser.addPositionalArgument("<dxf_files>", "Input DXF file(s)");
+ parser.addPositionalArgument(QObject::tr( "<dxf_files>"), QObject::tr( "Input DXF file(s)"));
parser.process(app);
--- a/librecad/src/main/main.cpp
+++ b/librecad/src/main/main.cpp
@@ -55,16 +55,13 @@ int main(int argc, char** argv)
{
QT_REQUIRE_VERSION(argc, argv, "5.2.1");
- // Check first two arguments in order to decide if we want to run librecad
- // as console dxf2pdf tool. On Linux we can create a link to librecad
- // executable and name it dxf2pdf. So, we can run either:
- //
- // librecad dxf2pdf [options] ...
- //
- // or just:
- //
- // dxf2pdf [options] ...
- //
+ /* Check first two arguments in order to decide if we want to run librecad
+ * as console dxf2pdf tool. On Linux we can create a link to librecad
+ * executable and name it dxf2pdf. So, we can run either:
+ * librecad dxf2pdf [options] ...
+ * or just:
+ * dxf2pdf [options] ...
+ */
for (int i = 0; i < qMin(argc, 2); i++) {
QString arg(argv[i]);
if (i == 0) {
@@ -206,10 +203,8 @@ int main(int argc, char** argv)
}
RS_DEBUG->print("param 0: %s", argv[0]);
- QFileInfo prgInfo( QFile::decodeName(argv[0]) );
- QString prgDir(prgInfo.absolutePath());
RS_SETTINGS->init(app.organizationName(), app.applicationName());
- RS_SYSTEM->init(app.applicationName(), app.applicationVersion(), XSTR(QC_APPDIR), prgDir);
+ RS_SYSTEM->init(app.applicationName(), app.applicationVersion(), XSTR(QC_APPDIR));
// parse command line arguments that might not need a launched program:
QStringList fileList = handleArgs(argc, argv, argClean);