[education/rkward] rkward: Move RKGlobals::startup_options to settings, move R_BINARY env var to RKSessionVars
Thomas Friedrichsmeier
null at kde.org
Thu Apr 14 22:14:06 BST 2022
Git commit 33681ecb24376f4c12fed562d954a4c24a139ab3 by Thomas Friedrichsmeier.
Committed on 13/04/2022 at 21:08.
Pushed by tfry into branch 'master'.
Move RKGlobals::startup_options to settings, move R_BINARY env var to RKSessionVars
M +4 -5 rkward/dialogs/rkloadlibsdialog.cpp
M +7 -7 rkward/main.cpp
M +6 -6 rkward/rbackend/rkfrontendtransmitter.cpp
M +1 -0 rkward/rbackend/rksessionvars.cpp
M +3 -0 rkward/rbackend/rksessionvars.h
M +0 -2 rkward/rkglobals.cpp
M +0 -2 rkward/rkglobals.h
M +3 -3 rkward/rkward.cpp
M +2 -0 rkward/settings/rksettingsmodulegeneral.cpp
M +6 -0 rkward/settings/rksettingsmodulegeneral.h
https://invent.kde.org/education/rkward/commit/33681ecb24376f4c12fed562d954a4c24a139ab3
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index 9f835696..e6c207fe 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -26,8 +26,8 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include <kmessagebox.h>
#include <kuser.h>
-#include "../rkglobals.h"
#include "../rbackend/rkrinterface.h"
+#include "../rbackend/rksessionvars.h"
#include "../settings/rksettingsmodulegeneral.h"
#include "../settings/rksettings.h"
#include "../core/robjectlist.h"
@@ -319,19 +319,18 @@ void RKLoadLibsDialog::runInstallationCommand (const QString& command, bool as_r
RK_ASSERT (false);
}
- QString R_binary (getenv ("R_BINARY"));
QString call;
QStringList params;
#ifdef Q_OS_WIN
RK_ASSERT (!as_root);
- call = R_binary;
+ call = RKSessionVars::RBinary();
#else
if (as_root) {
call = QStandardPaths::findExecutable ("kdesu");
if (call.isEmpty ()) call = QStandardPaths::findExecutable ("kdesudo");
- params << "-t" << "--" << R_binary;
+ params << "-t" << "--" << RKSessionVars::RBinary();
} else {
- call = R_binary;
+ call = RKSessionVars::RBinary();
}
#endif
params << "--no-save" << "--no-restore" << "--file=" + file.fileName ();
diff --git a/rkward/main.cpp b/rkward/main.cpp
index f87f22a5..3a5d3d35 100644
--- a/rkward/main.cpp
+++ b/rkward/main.cpp
@@ -76,8 +76,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include <stdlib.h>
#include "rkward.h"
-#include "rkglobals.h"
#include "settings/rksettingsmoduledebug.h"
+#include "settings/rksettingsmodulegeneral.h"
+#include "rbackend/rksessionvars.h"
#include "windows/rkdebugmessagewindow.h"
#include "misc/rkdbusapi.h"
#include "misc/rkcommonfunctions.h"
@@ -313,11 +314,11 @@ int main (int argc, char *argv[]) {
for (int i = 0; i < url_args.size (); ++i) {
url_args[i] = QUrl::fromUserInput (url_args[i], QDir::currentPath (), QUrl::AssumeLocalFile).toString ();
}
- RKGlobals::startup_options["initial_urls"] = url_args;
- RKGlobals::startup_options["warn_external"] = !parser.isSet ("nowarn-external");
+ RKSettingsModuleGeneral::setStartupOption("initial_urls", url_args);
+ RKSettingsModuleGeneral::setStartupOption("warn_external", !parser.isSet("nowarn-external"));
}
- RKGlobals::startup_options["evaluate"] = parser.value ("evaluate");
- RKGlobals::startup_options["backend-debugger"] = parser.value ("backend-debugger");
+ RKSettingsModuleGeneral::setStartupOption("evaluate", parser.value("evaluate"));
+ RKSettingsModuleGeneral::setStartupOption("backend-debugger", parser.value("backend-debugger"));
// MacOS may need some path adjustments, first
#ifdef Q_OS_MACOS
@@ -383,8 +384,7 @@ int main (int argc, char *argv[]) {
RK_DEBUG (APP, DL_DEBUG, "Using R as configured at compile time");
}
}
- // TODO: Store somewhere else
- qputenv ("R_BINARY", r_exe.toLocal8Bit ());
+ RKSessionVars::r_binary = r_exe;
qsrand (QTime::currentTime ().msec ()); // Workaround for some versions of kcoreaddons (5.21.0 through at least 5.34.0). See https://phabricator.kde.org/D5966
if (app.isSessionRestored ()) {
diff --git a/rkward/rbackend/rkfrontendtransmitter.cpp b/rkward/rbackend/rkfrontendtransmitter.cpp
index f6b30212..40701dc7 100644
--- a/rkward/rbackend/rkfrontendtransmitter.cpp
+++ b/rkward/rbackend/rkfrontendtransmitter.cpp
@@ -9,9 +9,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include "rkrbackendprotocol_frontend.h"
#include "rkwarddevice/rkgraphicsdevice_frontendtransmitter.h"
+#include "rksessionvars.h"
#include "../misc/rkcommonfunctions.h"
#include "../settings/rksettingsmodulegeneral.h"
-#include "../rkglobals.h"
#include <KLocalizedString>
#include <krandom.h>
@@ -107,7 +107,7 @@ void RKFrontendTransmitter::run () {
exec(); // To actually show the transmission error
return;
}
- QString debugger = RKGlobals::startup_options["backend-debugger"].toString ();
+ QString debugger = RKSettingsModuleGeneral::startupOption("backend-debugger").toString();
args.prepend (RKCommonFunctions::windowsShellScriptSafeCommand (backend_executable));
if (!debugger.isEmpty ()) {
args = debugger.split (' ') + args;
@@ -116,7 +116,7 @@ void RKFrontendTransmitter::run () {
// Resolving libR.dylib and friends is a pain on MacOS, and running through R CMD does not always seem to be enough.
// (Apparently DYLIB_FALLBACK_LIBRARY_PATH is ignored on newer versions of MacOS). Safest best seems to be to start in the lib directory, itself.
QProcess dummy;
- dummy.start (qgetenv ("R_BINARY"), QStringList() << "--slave" << "--no-save" << "--no-init-file" << "-e" << "cat(R.home('lib'))");
+ dummy.start(RKSessionVars::RBinary(), QStringList() << "--slave" << "--no-save" << "--no-init-file" << "-e" << "cat(R.home('lib'))");
dummy.waitForFinished ();
QString r_home = QString::fromLocal8Bit (dummy.readAllStandardOutput ());
RK_DEBUG(RBACKEND, DL_INFO, "Setting working directory to %s", qPrintable (r_home));
@@ -124,10 +124,10 @@ void RKFrontendTransmitter::run () {
#endif
args.prepend ("CMD");
if (DL_DEBUG >= RK_Debug::RK_Debug_Level) {
- qDebug ("%s", qPrintable (qgetenv ("R_BINARY")));
- qDebug ("%s", qPrintable (args.join ("\n")));
+ qDebug("%s", qPrintable(RKSessionVars::RBinary()));
+ qDebug("%s", qPrintable(args.join("\n")));
}
- backend->start (qgetenv ("R_BINARY"), args, QIODevice::ReadOnly);
+ backend->start(RKSessionVars::RBinary(), args, QIODevice::ReadOnly);
if (!backend->waitForStarted()) {
handleTransmissionError(i18n("The backend executable could not be started. Error message was: %1", backend->errorString()));
diff --git a/rkward/rbackend/rksessionvars.cpp b/rkward/rbackend/rksessionvars.cpp
index 467ca0cc..f9fe68f5 100644
--- a/rkward/rbackend/rksessionvars.cpp
+++ b/rkward/rbackend/rksessionvars.cpp
@@ -28,6 +28,7 @@ quint32 RKSessionVars::rkward_version = 0;
QString RKSessionVars::rkward_version_suffix;
quint32 RKSessionVars::r_version = 0;
QString RKSessionVars::r_version_string;
+QString RKSessionVars::r_binary;
RKSessionVars::RKSessionVars (RInterface *parent) : QObject (parent) {
RK_TRACE (RBACKEND);
diff --git a/rkward/rbackend/rksessionvars.h b/rkward/rbackend/rksessionvars.h
index 3cbcd804..ad7c1052 100644
--- a/rkward/rbackend/rksessionvars.h
+++ b/rkward/rbackend/rksessionvars.h
@@ -33,6 +33,7 @@ Anything else (everything after the fourth dot, or after the first character tha
is returned as suffix (via the suffix pointer; if that is 0, an error is reported, instead). */
static quint32 parseVersionString (const QString &version, QString *suffix);
static QStringList frontendSessionInfo ();
+ static QString RBinary() { return r_binary; }
signals:
void installedPackagesChanged ();
protected:
@@ -47,6 +48,8 @@ private:
static QString rkward_version_suffix;
static quint32 r_version;
static QString r_version_string;
+friend int main(int, char**);
+ static QString r_binary;
};
#endif
diff --git a/rkward/rkglobals.cpp b/rkward/rkglobals.cpp
index 4d5241cd..46f8e920 100644
--- a/rkward/rkglobals.cpp
+++ b/rkward/rkglobals.cpp
@@ -8,8 +8,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include <qstring.h>
-QVariantMap RKGlobals::startup_options;
-
#include <QApplication>
#include <QStyle>
diff --git a/rkward/rkglobals.h b/rkward/rkglobals.h
index 70ab24c8..7a2fe2b8 100644
--- a/rkward/rkglobals.h
+++ b/rkward/rkglobals.h
@@ -30,8 +30,6 @@ public:
static int marginHint ();
/// returns KDialog::spacingHint (), without the need to include kdialog.h in all the sources
static int spacingHint ();
-
- static QVariantMap startup_options;
};
#endif
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 551e7bd7..5b3b5887 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -216,9 +216,9 @@ void RKWardMainWindow::closeEvent (QCloseEvent *e) {
void RKWardMainWindow::doPostInit () {
RK_TRACE (APP);
- QStringList open_urls = RKGlobals::startup_options.take ("initial_urls").toStringList ();
- bool warn_external = RKGlobals::startup_options.take ("warn_external").toBool ();
- QString evaluate_code = RKGlobals::startup_options.take ("evaluate").toString ();
+ QStringList open_urls = RKSettingsModuleGeneral::takeStartupOption("initial_urls").toStringList();
+ bool warn_external = RKSettingsModuleGeneral::takeStartupOption("warn_external").toBool();
+ QString evaluate_code = RKSettingsModuleGeneral::takeStartupOption("evaluate").toString();
initPlugins ();
gui_rebuild_locked = false;
diff --git a/rkward/settings/rksettingsmodulegeneral.cpp b/rkward/settings/rksettingsmodulegeneral.cpp
index 2c7875f1..e9a96c81 100644
--- a/rkward/settings/rksettingsmodulegeneral.cpp
+++ b/rkward/settings/rksettingsmodulegeneral.cpp
@@ -52,6 +52,8 @@ bool RKSettingsModuleGeneral::installation_moved = false;
QString RKSettingsModuleGeneral::previous_rkward_data_dir;
QUrl RKSettingsModuleGeneral::generic_filedialog_start_url;
+QVariantMap RKSettingsModuleGeneral::startup_options;
+
RKSettingsModuleGeneral::RKSettingsModuleGeneral (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
RK_TRACE (SETTINGS);
diff --git a/rkward/settings/rksettingsmodulegeneral.h b/rkward/settings/rksettingsmodulegeneral.h
index a68d8c01..fa21f67f 100644
--- a/rkward/settings/rksettingsmodulegeneral.h
+++ b/rkward/settings/rksettingsmodulegeneral.h
@@ -98,6 +98,10 @@ public:
static bool rkwardVersionChanged () { return rkward_version_changed; };
/** Returns true, if rkward seems to have started from a different path than on the previous run. */
static bool installationMoved () { return installation_moved; };
+
+ static void setStartupOption(const QString &key, const QVariant &value) { startup_options[key] = value; };
+ static QVariant startupOption(const QString &key) { return startup_options.value(key); };
+ static QVariant takeStartupOption(const QString &key) { return startup_options.take(key); };
private:
GetFileNameWidget *files_choser;
QButtonGroup *workplace_save_chooser;
@@ -120,6 +124,8 @@ private:
static bool config_exists;
static bool installation_moved;
static QUrl generic_filedialog_start_url;
+
+ static QVariantMap startup_options;
};
#endif
More information about the rkward-tracker
mailing list