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
Next Next commit
progress
  • Loading branch information
RensDofferhoff committed May 22, 2023
commit 5f2fb7352432cd4c0a2078bf5d8487ae3d7e382d
3 changes: 3 additions & 0 deletions Desktop/gui/preferencesmodel.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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( remoteSettingsURL, Settings::REMOTE_SETTINGS_URL )

int PreferencesModel::maxEngines() const
{
Expand Down Expand Up @@ -307,6 +308,8 @@ 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, setRemoteSettingsURL, remoteSettingsURL, remoteSettingsURLChanged, Settings::REMOTE_SETTINGS_URL )


void PreferencesModel::setGithubPatCustom(QString newPat)
{
Expand Down
99 changes: 79 additions & 20 deletions Desktop/gui/remotesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,113 @@
#include <QTextStream>
#include <QRegularExpression>
#include <QString>
#include <QDir>


RemoteSettings::RemoteSettings(QObject *parent)
: QObject{parent}
{
//connect(&_networkManager, &QNetworkAccessManager::finished, this, &RemoteSettings::downloadFinished);
versionRE.setPattern("Version:\\s*(?<versionNum>\\d+)");
// versionRE.setPattern("Version:\\s*(?<versionNum>\\d+)");
}

void RemoteSettings::processRemoteSettings()
{
//read & parse local
QString confPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QFile local(confPath + configurationFilename);
if (!local.open(QIODevice::ReadWrite | QIODevice::Text))
QDir confDir;
confDir.mkpath(confPath);

QString settingsPath = confPath + "/" + configurationFilename;
QFile localSettingsFile(settingsPath);
if (!localSettingsFile.open(QIODevice::ReadWrite | QIODevice::Text))
{
Log::log() << "Could not open local configuration file!";
Log::log() << "!!!Could not open local configuration file " << settingsPath.toStdString() << ": " << localSettingsFile.errorString().toStdString() << std::endl;
return;
}
QTextStream in(&local);
QTextStream in(&localSettingsFile);
parse(in.readAll());
localSettingsFile.close();


//read,parse & save remote settings
auto conn = std::make_shared<QMetaObject::Connection>();
*conn = connect(&_networkManager, &QNetworkAccessManager::finished, this, [&, this, settingsPath, conn](QNetworkReply* reply) {
QObject::disconnect(*conn);
reply->deleteLater();

if(reply->error())
{
Log::log() << "!!!Error fetching remote settings file " << reply->request().url().toString().toStdString() << " : " << reply->errorString().toStdString() << std::endl;
emit this->remoteSettingsProcessed("FAIL");
return;
}
QString payload = reply->readAll();
parse(payload);

QFile localSettingsFile(settingsPath);
if (!localSettingsFile.open(QIODevice::ReadWrite | QIODevice::Text))
{
Log::log() << "!!!Could not open local configuration file " << settingsPath.toStdString() << ": " << localSettingsFile.errorString().toStdString() << std::endl;
emit this->remoteSettingsProcessed("FAIL");
return;
}
localSettingsFile.write(payload.toUtf8());
localSettingsFile.close();

//read & parse remote
Log::log() << "!!!Updated local copy of remote settings" << std::endl;
emit this->remoteSettingsProcessed("OK");
});

//make the request
QNetworkRequest request(Settings::value(Settings::REMOTE_SETTINGS_URL).toString());
QNetworkReply* reply = _networkManager.get(request);
connect(reply, &QNetworkReply::sslErrors, this, &RemoteSettings::sslErrors);
}

void RemoteSettings::parse(const QString &settings)
void RemoteSettings::remoteChanged(QString remoteURL)
{
_version = getVersion(settings);
processRemoteSettings();
}

void RemoteSettings::parse(const QString &settings)
{
_patches.clear();
QStringList lines = settings.split("\n");
for(auto& line : lines)
{
auto match = versionRE.match(line);
if(!match.hasMatch())
_patches.append(line);
_patches.insert(line);
}
}

int32_t RemoteSettings::getVersion(const QString& settings)
void RemoteSettings::sslErrors(const QList<QSslError> &errors)
{
auto match = versionRE.match(settings);
if(match.hasCaptured("versionNum"))
{
bool ok;
int32_t version = match.captured("versionNum").toULong(&ok);
return ok ? version : -1;
}
return -1;
for (const QSslError &error : errors)
Log::log() << "!!!Error fetching remote settings:" << error.errorString().toStdString() << std::endl;
}

//void RemoteSettings::parse(const QString &settings)
//{
// _version = getVersion(settings);

// _patches.clear();
// QStringList lines = settings.split("\n");
// for(auto& line : lines)
// {
// auto match = versionRE.match(line);
// if(!match.hasMatch())
// _patches.append(line);
// }
//}

//int32_t RemoteSettings::getVersion(const QString& settings)
//{
// auto match = versionRE.match(settings);
// if(match.hasCaptured("versionNum"))
// {
// bool ok;
// int32_t version = match.captured("versionNum").toULong(&ok);
// return ok ? version : -1;
// }
// return -1;
//}
13 changes: 5 additions & 8 deletions Desktop/gui/remotesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ private slots:
private:
void processTasks();
void parse(const QString& settings);
int32_t getVersion(const QString& settings);
QNetworkReply* download(const QString& path);
bool saveToDisk(const QString& path, QNetworkReply* data);

// int32_t getVersion(const QString& settings);

QNetworkAccessManager _networkManager;
int32_t _version = -1;
QList<QString> _patches;
// int32_t _version = -1;
QSet<QString> _patches;

const QString configurationFilename = "jasp.conf";
static QRegularExpression versionRE;
const QString configurationFilename = "remote_settings.conf";
// static QRegularExpression versionRE;

};

Expand Down
4 changes: 4 additions & 0 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ MainWindow::MainWindow(QApplication * application) : QObject(application), _appl
_resultMenuModel = new ResultMenuModel(this);
_plotEditorModel = new PlotEditorModel();
_columnTypesModel = new ColumnTypesModel(this);
_remoteSettings = new RemoteSettings(this);

#ifdef WIN32
_windowsWorkaroundCPs = new CodePagesWindows(this);
Expand All @@ -159,6 +160,8 @@ MainWindow::MainWindow(QApplication * application) : QObject(application), _appl

makeConnections();

_remoteSettings->processRemoteSettings();

qmlRegisterUncreatableType<JASPControl> ("JASP", 1, 0 ,"JASP", "Impossible to create JASP Object" ); //This is here to keep JASP.enum short I guess?
qmlRegisterUncreatableType<MessageForwarder> ("JASP", 1, 0, "MessageForwarder", "You can't touch this" );

Expand Down Expand Up @@ -372,6 +375,7 @@ void MainWindow::makeConnections()
connect(_preferences, &PreferencesModel::missingValuesChanged, _package, &DataSetPackage::emptyValuesChangedHandler );
connect(_preferences, &PreferencesModel::dataLabelNAChanged, _package, &DataSetPackage::refresh, Qt::QueuedConnection);
connect(_preferences, &PreferencesModel::dataAutoSynchronizationChanged, _package, &DataSetPackage::synchingExternallyChanged );
connect(_preferences, &PreferencesModel::remoteSettingsURLChanged, _remoteSettings, &RemoteSettings::remoteChanged );
connect(_preferences, &PreferencesModel::plotBackgroundChanged, this, &MainWindow::setImageBackgroundHandler );
connect(_preferences, &PreferencesModel::plotPPIChanged, this, &MainWindow::plotPPIChangedHandler );
connect(_preferences, &PreferencesModel::dataAutoSynchronizationChanged, _fileMenu, &FileMenu::dataAutoSynchronizationChanged );
Expand Down
2 changes: 2 additions & 0 deletions Desktop/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "gui/aboutmodel.h"
#include "gui/columntypesmodel.h"
#include "gui/preferencesmodel.h"
#include "gui/remotesettings.h"
#include "modules/dynamicmodule.h"
#include "modules/ribbonbutton.h"
#include "modules/ribbonmodelfiltered.h"
Expand Down Expand Up @@ -281,6 +282,7 @@ private slots:
Upgrader * _upgrader = nullptr;
Reporter * _reporter = nullptr;
CodePagesWindows * _windowsWorkaroundCPs = nullptr;
RemoteSettings * _remoteSettings = nullptr;

QSettings _settings;

Expand Down