Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JASP configuration file feature + remote option #5062

Draft
wants to merge 38 commits into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6c46eaf
Implements a data mode
JorisGoosen May 21, 2021
003123c
SKF JASP postmerge and fix
JorisGoosen Sep 21, 2021
aa63d26
latest version of jaspProcessControl and other submodules
JorisGoosen Dec 1, 2021
82f7f86
post qt6 merge fixes
JorisGoosen Mar 10, 2022
825d474
post rebase fixes 10-11-22
JorisGoosen Nov 10, 2022
8a49630
post rebase fix 7-12-22
JorisGoosen Dec 7, 2022
3d71dac
(event)=>{}
JorisGoosen Dec 7, 2022
7edb7cd
Rebasing mistake
boutinb Jan 27, 2023
6349af9
Make sure editing is quick and analyses are hidden in dataMode (#5040)
JorisGoosen Mar 1, 2023
191709f
dirty fix for the resize dialog (#5042)
RensDofferhoff Mar 1, 2023
55fea62
odule shenanigans
JorisGoosen Mar 16, 2023
aba724b
start
RensDofferhoff Apr 3, 2023
5f2fb73
progress
RensDofferhoff Apr 4, 2023
bef03ee
progress
RensDofferhoff Apr 5, 2023
a6a1bf2
progress
RensDofferhoff Apr 5, 2023
a44a893
progress
RensDofferhoff Apr 6, 2023
84807bc
progress
RensDofferhoff Apr 7, 2023
f286ea0
before overhaul
RensDofferhoff Apr 10, 2023
b0c3a38
functional
RensDofferhoff Apr 12, 2023
72b965f
giant oops
RensDofferhoff Apr 12, 2023
6945cab
v1
RensDofferhoff Apr 12, 2023
c94ee85
enabled sounds better
RensDofferhoff Apr 13, 2023
53c39e4
oops
RensDofferhoff Apr 15, 2023
b20d6ae
oops
RensDofferhoff Apr 15, 2023
d71aaa2
oops
RensDofferhoff Apr 16, 2023
c826d3d
constant access improvements
RensDofferhoff Apr 18, 2023
2d54356
add option locking
RensDofferhoff Apr 18, 2023
d56c6d3
oops
RensDofferhoff May 11, 2023
0dd5bbf
progress
RensDofferhoff May 12, 2023
3ed5704
factory
RensDofferhoff May 12, 2023
bb506d6
more extendable this way
RensDofferhoff May 15, 2023
8d58dd8
a small comment never hurts
RensDofferhoff May 15, 2023
f431a57
add toml
RensDofferhoff May 16, 2023
8a8df43
forgot the parser lib
RensDofferhoff May 16, 2023
a58c026
Documentation for analysis writers
RensDofferhoff May 17, 2023
8a232b9
Update jasp-qml-guide.md
RensDofferhoff May 22, 2023
c976461
dont change the submodule commits
RensDofferhoff May 22, 2023
311866d
added local conf browser
RensDofferhoff May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added local conf browser
  • Loading branch information
RensDofferhoff committed May 23, 2023
commit 311866d216fc92092478179d92fa2c3ac8ee963e
40 changes: 39 additions & 1 deletion Desktop/components/JASP/Widgets/FileMenu/PrefsAdvanced.qml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ ScrollView
KeyNavigation.tab: useRemoteConf
activeFocusOnTab: true
}



CheckBox
Expand Down Expand Up @@ -255,7 +256,44 @@ ScrollView
right: parent.right
}

KeyNavigation.tab: logToFile
KeyNavigation.tab: localconf
}
}

Item
{
id: localconf
//enabled: !preferencesModel.remoteConfiguration
width: parent.width
height: browseLocalconfButton.height

RectangularButton
{
id: browseLocalconfButton
text: qsTr("Select configuration file")
onClicked: preferencesModel.browseConfigurationFile()
anchors.left: parent.left
toolTip: qsTr("Select configuration file.")

KeyNavigation.tab: browseLocalconfFolderText.textInput
activeFocusOnTab: true
}

PrefsTextInput
{
id: browseLocalconfFolderText

text: preferencesModel.localConfigurationPATH
onEditingFinished: preferencesModel.localConfigurationPATH = text
nextEl: logToFile

height: browseLocalconfButton.height
anchors
{
left: browseLocalconfButton.right
right: parent.right
top: parent.top
}
}
}
}
Expand Down
44 changes: 33 additions & 11 deletions Desktop/gui/jaspConfiguration/jaspconfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "jaspconfiguration.h"
#include "jaspconfigurationparser.h"
#include "utilities/settings.h"
#include "gui/preferencesmodel.h"
#include "log.h"
#include <QNetworkReply>
#include <QStandardPaths>
Expand All @@ -24,7 +25,6 @@ JASPConfiguration* JASPConfiguration::getInstance(QObject *parent)
JASPConfiguration::JASPConfiguration(QObject *parent)
: QObject{parent}
{

}

bool JASPConfiguration::constantExists(const QString &constant, const QString &module, const QString &analysis)
Expand Down Expand Up @@ -87,10 +87,10 @@ void JASPConfiguration::processConfiguration()
if(!JASPConfigurationParser::getParser(JASPConfigurationParser::Format::TOML)->parse(this, payload))
throw std::runtime_error("Parsing failed");

auto localConfFile = getLocalConfFile(true);
localConfFile->write(payload);
localConfFile->close();
Log::log() << "Updated local copy of remote configuration" << std::endl;
auto conf = getDefaultConfFile(true);
conf->write(payload);
conf->close();
Log::log() << "Stored local copy of remote configuration" << std::endl;
emit this->configurationProcessed("REMOTE");
}
catch (std::runtime_error& e)
Expand Down Expand Up @@ -142,16 +142,38 @@ void JASPConfiguration::remoteChanged()
}

std::shared_ptr<QFile> JASPConfiguration::getLocalConfFile(bool truncate) {
QString confPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);

//the right default path can only be determined here, so after jasp init
if(PreferencesModel::prefs()->localConfigurationPATH() == "")
{
defaultConfigurationFolder = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
defaultConfigurationPath = defaultConfigurationFolder + "/" + defaultConfigurationFilename;
PreferencesModel::prefs()->setLocalConfigurationPATH(defaultConfigurationPath);
}

if(Settings::value(Settings::REMOTE_CONFIGURATION).toBool()) //if we use a remote but we are offline
return getDefaultConfFile(truncate);
else //user specified local file
return getConfFile(Settings::value(Settings::LOCAL_CONFIGURATION_PATH).toString(), truncate);
}

std::shared_ptr<QFile> JASPConfiguration::getDefaultConfFile(bool truncate)
{
QDir confDir;
if(!confDir.mkpath(confPath))
throw std::runtime_error("Could not Access app configuration path");
defaultConfigurationFolder = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
defaultConfigurationPath = defaultConfigurationFolder + "/" + defaultConfigurationFilename;
if(!confDir.mkpath(defaultConfigurationFolder))
throw std::runtime_error("Could not access app configuration path");

QString configurationFilePath = confPath + "/" + configurationFilename;
std::shared_ptr<QFile> localConfFile = std::make_shared<QFile>(configurationFilePath);
return getConfFile(defaultConfigurationPath, truncate);
}

std::shared_ptr<QFile> JASPConfiguration::getConfFile(QString path, bool truncate)
{
std::shared_ptr<QFile> localConfFile = std::make_shared<QFile>(path);
QIODeviceBase::OpenMode flags = QIODeviceBase::ReadWrite | QIODeviceBase::Text | (truncate ? QIODeviceBase::Truncate : QIODeviceBase::NotOpen);
if (!localConfFile->open(flags))
throw std::runtime_error("Could not open local configuration file " + configurationFilePath.toStdString() + ": " + localConfFile->errorString().toStdString());
throw std::runtime_error("Could not open local configuration file " + path.toStdString() + ": " + localConfFile->errorString().toStdString());
return localConfFile;
}

Expand Down
11 changes: 8 additions & 3 deletions Desktop/gui/jaspConfiguration/jaspconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class JASPConfiguration : public QObject
JASPConfiguration(JASPConfiguration& other) = delete;
void operator=(const JASPConfiguration&) = delete;

QString getDefaultConfigurationPath() { return defaultConfigurationPath; };

public slots:
void remoteChanged();

Expand All @@ -77,8 +79,9 @@ private slots:
bool processLocal();
void clear();


std::shared_ptr<QFile> getLocalConfFile(bool truncate = false);
std::shared_ptr<QFile> getDefaultConfFile(bool truncate = false);
std::shared_ptr<QFile> getConfFile(QString path, bool truncate = false);

QNetworkAccessManager _networkManager;

Expand All @@ -89,10 +92,12 @@ private slots:
QString _startupCommands;
QStringList _modulesToLoad;

const QString configurationFilename = "conf.toml";

explicit JASPConfiguration(QObject *parent = nullptr);
static JASPConfiguration* _instance;

const QString defaultConfigurationFilename = "conf.toml";
QString defaultConfigurationFolder;
QString defaultConfigurationPath;
};

#endif // JASPCONFIGURATION_H
25 changes: 25 additions & 0 deletions Desktop/gui/preferencesmodel.cpp.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "gui/jaspConfiguration/jaspconfiguration.h"
#include "preferencesmodel.h"
#include "utils.h"
#include "utilities/qutils.h"
Expand Down Expand Up @@ -83,6 +84,28 @@ void PreferencesModel::browseDeveloperFolder()

}

void PreferencesModel::browseConfigurationFile()
{
QString defaultfolder = JASPConfiguration::getInstance()->getDefaultConfigurationPath();
if (defaultfolder.isEmpty())
{
#ifdef _WIN32
defaultfolder = "c:\\";
#else
defaultfolder = "~";
#endif
}

QString folder = MessageForwarder::browseOpenFile(tr("Select a file..."), defaultfolder, "");

if (!folder.isEmpty())
{
setLocalConfigurationPATH(folder);
JASPConfiguration::getInstance()->processConfiguration();
}

}

#define GET_PREF_FUNC(TYPE, NAME, SETTING, TO_FUNC) TYPE PreferencesModel::NAME() const { return Settings::value(SETTING).TO_FUNC; }
#define GET_PREF_FUNC_BOOL(NAME, SETTING) GET_PREF_FUNC(bool, NAME, SETTING, toBool())
#define GET_PREF_FUNC_INT(NAME, SETTING) GET_PREF_FUNC(int, NAME, SETTING, toInt())
Expand Down Expand Up @@ -127,6 +150,7 @@ GET_PREF_FUNC_BOOL( reportingMode, Settings::REPORT_SHOW )
GET_PREF_FUNC_BOOL( showRSyntax, Settings::SHOW_RSYNTAX )
GET_PREF_FUNC_BOOL( showAllROptions, Settings::SHOW_ALL_R_OPTIONS )
GET_PREF_FUNC_BOOL( showRSyntaxInResults, Settings::SHOW_RSYNTAX_IN_RESULTS )
GET_PREF_FUNC_STR( localConfigurationPATH, Settings::LOCAL_CONFIGURATION_PATH )
GET_PREF_FUNC_BOOL( remoteConfiguration, Settings::REMOTE_CONFIGURATION )
GET_PREF_FUNC_STR( remoteConfigurationURL, Settings::REMOTE_CONFIGURATION_URL )

Expand Down Expand Up @@ -309,6 +333,7 @@ SET_PREF_FUNCTION( bool, setReportingMode, reportingMode, reportingMode
SET_PREF_FUNCTION_EMIT_NO_ARG( bool, setShowRSyntax, showRSyntax, showRSyntaxChanged, Settings::SHOW_RSYNTAX )
SET_PREF_FUNCTION_EMIT_NO_ARG( bool, setShowAllROptions, showAllROptions, showAllROptionsChanged, Settings::SHOW_ALL_R_OPTIONS )
SET_PREF_FUNCTION( bool, setShowRSyntaxInResults, showRSyntaxInResults, showRSyntaxInResultsChanged, Settings::SHOW_RSYNTAX_IN_RESULTS )
SET_PREF_FUNCTION( QString, setLocalConfigurationPATH, localConfigurationPATH, localConfigurationPATHChanged, Settings::LOCAL_CONFIGURATION_PATH )
SET_PREF_FUNCTION( bool, setRemoteConfiguration, remoteConfiguration, remoteConfigurationChanged, Settings::REMOTE_CONFIGURATION )
SET_PREF_FUNCTION( QString, setRemoteConfigurationURL, remoteConfigurationURL, remoteConfigurationURLChanged, Settings::REMOTE_CONFIGURATION_URL )

Expand Down
7 changes: 6 additions & 1 deletion Desktop/gui/preferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class PreferencesModel : public PreferencesModelBase
Q_PROPERTY(bool showRSyntax READ showRSyntax WRITE setShowRSyntax NOTIFY showRSyntaxChanged )
Q_PROPERTY(bool showAllROptions READ showAllROptions WRITE setShowAllROptions NOTIFY showAllROptionsChanged )
Q_PROPERTY(bool showRSyntaxInResults READ showRSyntaxInResults WRITE setShowRSyntaxInResults NOTIFY showRSyntaxInResultsChanged )
Q_PROPERTY(bool remoteConfiguration READ remoteConfiguration WRITE setRemoteConfiguration NOTIFY remoteConfigurationChanged )
Q_PROPERTY(QString localConfigurationPATH READ localConfigurationPATH WRITE setLocalConfigurationPATH NOTIFY localConfigurationPATHChanged )
Q_PROPERTY(bool remoteConfiguration READ remoteConfiguration WRITE setRemoteConfiguration NOTIFY remoteConfigurationChanged )
Q_PROPERTY(QString remoteConfigurationURL READ remoteConfigurationURL WRITE setRemoteConfigurationURL NOTIFY remoteConfigurationURLChanged )


Expand Down Expand Up @@ -137,6 +138,7 @@ class PreferencesModel : public PreferencesModelBase
void zoomReset();
int maxEnginesAdmin() const;
bool developerMode() const;
QString localConfigurationPATH() const;
QString remoteConfigurationURL() const;
bool remoteConfiguration() const;

Expand All @@ -158,6 +160,7 @@ public slots:
void setDataAutoSynchronization( bool dataAutoSynchronization);
void browseSpreadsheetEditor();
void browseDeveloperFolder();
void browseConfigurationFile();
void updateUtilsMissingValues();
void removeMissingValue( QString value);
void addMissingValue( QString value);
Expand Down Expand Up @@ -197,6 +200,7 @@ public slots:
void setShowAllROptions( bool showAllROptions) override;
void setShowRSyntaxInResults( bool showRSyntax);
void currentThemeNameHandler();
void setLocalConfigurationPATH( QString path);
void setRemoteConfiguration( bool enabled);
void setRemoteConfigurationURL( QString URL);

Expand Down Expand Up @@ -248,6 +252,7 @@ public slots:
void guiQtTextRenderChanged( bool guiQtTextRender);
void reportingModeChanged( bool reportingMode);
void showRSyntaxInResultsChanged( bool showRSyntax);
void localConfigurationPATHChanged( QString path);
void remoteConfigurationChanged( bool enabled);
void remoteConfigurationURLChanged( QString remoteConfigurationURL);

Expand Down
6 changes: 4 additions & 2 deletions Desktop/utilities/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "settings.h"
#include "gui/jaspConfiguration/jaspconfiguration.h"
#include "utilities/qutils.h"
#include "enginedefinitions.h"


QSettings* Settings::_settings = nullptr;

const char * Settings::defaultMissingValues = "NaN|nan|.|NA";
Expand Down Expand Up @@ -89,10 +91,10 @@ const Settings::Setting Settings::Values[] = {
{"showReports", false },
{"showRSyntax", false },
{"showAllROptions", false },
{"guiQtTextRender", true },
{"showRSyntaxInResults", false },
{"remoteConfiguration", false },
{"remoteConfigurationURL", "" }
{"remoteConfigurationURL", "" },
{"localConfigurationPath", "" }
};

QVariant Settings::value(Settings::Type key)
Expand Down
3 changes: 2 additions & 1 deletion Desktop/utilities/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class Settings {
SHOW_ALL_R_OPTIONS,
SHOW_RSYNTAX_IN_RESULTS,
REMOTE_CONFIGURATION,
REMOTE_CONFIGURATION_URL
REMOTE_CONFIGURATION_URL,
LOCAL_CONFIGURATION_PATH
};

static QVariant value(Settings::Type key);
Expand Down