mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-05 18:54:14 +02:00
Merge pull request #1314 from ispyisail/feature/live-remember
Remember live mode's start warning and "Always" across restarts
This commit is contained in:
+22
-3
@@ -7217,6 +7217,16 @@ This setting is in Configure QElectroTech > General > Projects.</translati
|
||||
<source>&Désactiver</source>
|
||||
<translation>&Turn off</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/scripting/liveserver.cpp" line="126"/>
|
||||
<source>Ne plus demander au démarrage</source>
|
||||
<translation>Don't ask again at start</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/scripting/liveserver.cpp" line="127"/>
|
||||
<source>Le mode direct s'ouvrira à chaque démarrage. Pour être de nouveau averti, désactivez-le puis réactivez-le dans Configurer QElectroTech > Général > Projets.</source>
|
||||
<translation>Live mode will open at every start. To be warned again, turn it off and back on in Configure QElectroTech > General > Projects.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/scripting/liveserver.cpp" line="379"/>
|
||||
<location filename="../sources/scripting/liveserver.cpp" line="903"/>
|
||||
@@ -7273,9 +7283,13 @@ This setting is in Configure QElectroTech > General > Projects.</translati
|
||||
<translation>&Decline</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/scripting/liveserver.cpp" line="912"/>
|
||||
<location filename="../sources/scripting/liveserver.cpp" line="530"/>
|
||||
<source>&Toujours</source>
|
||||
<translation>&Always</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>&Toujours pour cette session</source>
|
||||
<translation>&Always this session</translation>
|
||||
<translation type="vanished">&Always this session</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
@@ -11320,6 +11334,11 @@ A script runs with your permissions: it can read and modify the open project and
|
||||
|
||||
Enable scripts? This setting can be changed in Configure QElectroTech > General > Projects.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/qetdiagrameditor.cpp" line="4089"/>
|
||||
<source>Retenu après un redémarrage</source>
|
||||
<translation>Remembered after a restart</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/qetdiagrameditor.cpp" line="3873"/>
|
||||
<source>Scripts JavaScript (*.js);;Tous les fichiers (*)</source>
|
||||
@@ -11412,7 +11431,7 @@ To make a script of it, ask your AI assistant: the button below copies the reque
|
||||
<message>
|
||||
<location filename="../sources/qetdiagrameditor.cpp" line="4091"/>
|
||||
<source>Pour cette session seulement : chaque démarrage redemande</source>
|
||||
<translation>For this session only: every start asks again</translation>
|
||||
<translation type="vanished">For this session only: every start asks again</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources/qetdiagrameditor.cpp" line="4146"/>
|
||||
|
||||
@@ -369,7 +369,8 @@ between pages need no tool of their own: in `qet_live_run_script`,
|
||||
contacts, across folios.
|
||||
|
||||
A script the assistant writes on the spot is shown to you first, with
|
||||
*Run*, *Decline* or *Always this session*; the Assistant
|
||||
*Run*, *Decline* or *Always* (remembered after a restart; untick "Ask
|
||||
before running" in the Assistant panel to be asked again); the Assistant
|
||||
panel lists everything it did.
|
||||
|
||||
QElectroTech only listens when three things are true:
|
||||
@@ -380,7 +381,8 @@ QElectroTech only listens when three things are true:
|
||||
mode)" is ticked (off by default; in French, Configurer QElectroTech >
|
||||
Général > Projets);
|
||||
3. at this start, you answered *Continue* to the warning QElectroTech shows
|
||||
every time it starts with that setting on.
|
||||
when it starts with that setting on -- or, once, ticked "Don't ask again
|
||||
at start" in it, which lasts until the setting is switched off.
|
||||
|
||||
While it listens, the status bar says so and shows the assistant's last
|
||||
action, with a *Stop* button that closes the channel for the rest of
|
||||
|
||||
@@ -4088,7 +4088,7 @@ void QETDiagramEditor::setUpLiveIndicator()
|
||||
auto *dock_layout = new QVBoxLayout(content);
|
||||
auto *ask = new QCheckBox(tr("Demander avant d'exécuter un script écrit par l'assistant"), content);
|
||||
ask->setChecked(LiveServer::instance().askFirst());
|
||||
ask->setToolTip(tr("Pour cette session seulement : chaque démarrage redemande"));
|
||||
ask->setToolTip(tr("Retenu après un redémarrage"));
|
||||
auto *log = new QListWidget(content);
|
||||
log->setWordWrap(true);
|
||||
dock_layout->addWidget(ask);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <QPixmap>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QDialog>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
@@ -81,7 +82,8 @@ LiveServer &LiveServer::instance()
|
||||
return server;
|
||||
}
|
||||
|
||||
LiveServer::LiveServer()
|
||||
LiveServer::LiveServer() :
|
||||
m_ask_first(QetSettings::liveAskFirst())
|
||||
{
|
||||
connect(qApp, &QCoreApplication::aboutToQuit, this, &LiveServer::stop);
|
||||
}
|
||||
@@ -112,6 +114,10 @@ void LiveServer::askAndStart(QWidget *parent)
|
||||
return;
|
||||
}
|
||||
m_asked = true;
|
||||
if (QetSettings::liveSkipStartWarning()) {
|
||||
start();
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox box(QMessageBox::Warning, tr("Mode direct"),
|
||||
tr("Le mode direct est activé : un assistant IA connecté "
|
||||
@@ -125,11 +131,17 @@ void LiveServer::askAndStart(QWidget *parent)
|
||||
box.addButton(tr("&Pas pour cette session"), QMessageBox::RejectRole);
|
||||
QPushButton *off = box.addButton(tr("&Désactiver"), QMessageBox::DestructiveRole);
|
||||
box.setDefaultButton(go);
|
||||
auto *remember = new QCheckBox(tr("Ne plus demander au démarrage"), &box);
|
||||
remember->setToolTip(tr("Le mode direct s'ouvrira à chaque démarrage. Pour être "
|
||||
"de nouveau averti, désactivez-le puis réactivez-le dans "
|
||||
"Configurer QElectroTech > Général > Projets."));
|
||||
box.setCheckBox(remember);
|
||||
box.exec();
|
||||
|
||||
if (box.clickedButton() == off) {
|
||||
QetSettings::setLiveAssistantEnabled(false);
|
||||
} else if (box.clickedButton() == go) {
|
||||
if (remember->isChecked()) QetSettings::setLiveSkipStartWarning(true);
|
||||
start();
|
||||
}
|
||||
}
|
||||
@@ -249,7 +261,7 @@ void LiveServer::handle(const QJsonObject &request)
|
||||
const QString name = request.value(QStringLiteral("name")).toString();
|
||||
const QString source = request.value(QStringLiteral("source")).toString();
|
||||
//A script the assistant just wrote: the user sees it first,
|
||||
//unless they said "always" this session. A stored script
|
||||
//unless they chose "always" (remembered). A stored script
|
||||
//is one the user already has, so it runs as a click would.
|
||||
if (m_ask_first && !confirm(name, source))
|
||||
answer = failure(QStringLiteral("refused by the user"));
|
||||
@@ -405,6 +417,7 @@ void LiveServer::setAskFirst(bool ask)
|
||||
{
|
||||
if (ask == m_ask_first) return;
|
||||
m_ask_first = ask;
|
||||
QetSettings::setLiveAskFirst(ask);
|
||||
emit askFirstChanged(ask);
|
||||
}
|
||||
|
||||
@@ -909,7 +922,7 @@ bool LiveServer::confirm(const QString &name, const QString &source)
|
||||
auto *buttons = new QDialogButtonBox(&dialog);
|
||||
QPushButton *run = buttons->addButton(tr("&Exécuter"), QDialogButtonBox::AcceptRole);
|
||||
buttons->addButton(tr("&Refuser"), QDialogButtonBox::RejectRole);
|
||||
QPushButton *always = buttons->addButton(tr("&Toujours pour cette session"),
|
||||
QPushButton *always = buttons->addButton(tr("&Toujours"),
|
||||
QDialogButtonBox::AcceptRole);
|
||||
layout->addWidget(buttons);
|
||||
QPushButton *clicked = nullptr;
|
||||
|
||||
@@ -35,7 +35,8 @@ class QWidget;
|
||||
|
||||
Three things must all be true before anything can connect: scripting is
|
||||
allowed, the "mode direct" setting is on (off by default), and the user
|
||||
accepted the warning shown at this start. With the setting off this
|
||||
accepted the warning shown at this start (or once ticked "don't ask
|
||||
again", which lasts until the setting is switched off). With the setting off this
|
||||
class opens nothing and QElectroTech behaves as if it did not exist.
|
||||
|
||||
The channel is a QLocalServer only the user's own account can open,
|
||||
@@ -106,7 +107,7 @@ class LiveServer : public QObject
|
||||
State m_state = Off;
|
||||
bool m_asked = false;
|
||||
bool m_busy = false;
|
||||
bool m_ask_first = true; ///< per session, never saved: every start asks again
|
||||
bool m_ask_first = true; ///< saved: QetSettings::liveAskFirst()
|
||||
};
|
||||
|
||||
#endif // LIVESERVER_H
|
||||
|
||||
@@ -171,6 +171,44 @@ namespace QetSettings
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("scripting/live_assistant", enabled);
|
||||
//Turned off and on again: the start warning comes back, so
|
||||
//"don't ask again" never outlives the choice it was made for
|
||||
if (!enabled) settings.remove("scripting/live_skip_warning");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief liveSkipStartWarning
|
||||
* @return true when the user ticked "don't ask again" in live mode's
|
||||
* start warning: live mode then opens at every start without asking,
|
||||
* until it is switched off in the settings. False unless they did.
|
||||
*/
|
||||
bool liveSkipStartWarning()
|
||||
{
|
||||
QSettings settings;
|
||||
return settings.value("scripting/live_skip_warning", false).toBool();
|
||||
}
|
||||
|
||||
void setLiveSkipStartWarning(bool skip)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("scripting/live_skip_warning", skip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief liveAskFirst
|
||||
* @return whether live mode shows each script the assistant wrote and
|
||||
* asks before running it. On unless the user chose "always".
|
||||
*/
|
||||
bool liveAskFirst()
|
||||
{
|
||||
QSettings settings;
|
||||
return settings.value("scripting/live_ask_first", true).toBool();
|
||||
}
|
||||
|
||||
void setLiveAskFirst(bool ask)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("scripting/live_ask_first", ask);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,10 @@ namespace QetSettings
|
||||
bool scriptingForcedByEnvironment();
|
||||
bool liveAssistantEnabled();
|
||||
void setLiveAssistantEnabled(bool enabled);
|
||||
bool liveSkipStartWarning();
|
||||
void setLiveSkipStartWarning(bool skip);
|
||||
bool liveAskFirst();
|
||||
void setLiveAskFirst(bool ask);
|
||||
|
||||
/**
|
||||
@brief Free-text drawing conventions for this installation (grid,
|
||||
|
||||
Reference in New Issue
Block a user