Skip to content

Commit

Permalink
#3026 ui: implement AI enable checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed May 15, 2024
1 parent c14d71d commit b943032
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11892,6 +11892,9 @@ void MainWindow::on_actionMove_down_in_tag_list_triggered() {
void MainWindow::buildAiToolbarAndActions() {
_aiToolbar->clear();
_aiToolbar->addAction(ui->actionEnable_AI);
ui->actionEnable_AI->blockSignals(true);
ui->actionEnable_AI->setChecked(OpenAiService::getEnabled());
ui->actionEnable_AI->blockSignals(false);

_aiBackendComboBox = new QComboBox(this);
connect(_aiBackendComboBox,
Expand Down Expand Up @@ -11923,3 +11926,8 @@ void MainWindow::buildAiToolbarAndActions() {
aiModelWidgetAction->setText(tr("AI model selector"));
_aiToolbar->addAction(aiModelWidgetAction);
}

void MainWindow::on_actionEnable_AI_toggled(bool arg1) {
OpenAiService::setEnabled(arg1);
qDebug() << __func__ << " - 'checked': " << arg1;
}
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ class MainWindow : public QMainWindow {

void on_actionMove_down_in_tag_list_triggered();

void on_actionEnable_AI_toggled(bool arg1);

public:
/** Settings access **/
static bool isInDistractionFreeMode();
Expand Down
12 changes: 12 additions & 0 deletions src/services/openaiservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ QString OpenAiService::getCurrentModelSettingsKey() {
return QStringLiteral("ai/") + getBackendId() + QStringLiteral("/") + QStringLiteral("currentModel");
}

bool OpenAiService::setEnabled(bool enabled) {
QSettings settings;
settings.setValue(QStringLiteral("ai/enabled"), enabled);

return true;
}

bool OpenAiService::getEnabled() {
QSettings settings;
return settings.value(QStringLiteral("ai/enabled")).toBool();
}

OpenAiCompleter::OpenAiCompleter(QString apiKey, QString modelId, QString apiBaseUrl,
QObject* parent)
: QObject(parent),
Expand Down
2 changes: 2 additions & 0 deletions src/services/openaiservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class OpenAiService : public QObject {
QString getBackendId();
bool setModelId(const QString& id);
QString getModelId();
static bool setEnabled(bool enabled);
static bool getEnabled();

private:
QMap<QString, QStringList> backendModels;
Expand Down

0 comments on commit b943032

Please sign in to comment.