Skip to content

Commit 18821d7

Browse files
committed
#3561 ai: hide toolbar without configured backend
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 55c66ec commit 18821d7

5 files changed

Lines changed: 62 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## 26.4.12
44

5+
- Turned the **AI toolbar** off by default when no AI backend is configured, so
6+
fresh installs without AI setup start with a less cluttered interface; if an
7+
AI backend is configured later while the toolbar is hidden, the application
8+
now asks whether it should be turned on (for
9+
[#3561](https://github.com/pbek/QOwnNotes/issues/3561))
510
- Fixed the **Search engine** setting being reset to **Google** when the
611
**Settings** dialog was applied without opening the **General** page first
712
(for [#3562](https://github.com/pbek/QOwnNotes/issues/3562))

src/mainwindow.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
352352
// used in toolbars
353353
restoreToolbars();
354354

355+
QTimer::singleShot(isMaximized() || isFullScreen() ? 600 : 0, this,
356+
[this]() { checkAiToolbarConfiguration(false); });
357+
355358
// update the workspace menu and combobox entries again after
356359
// restoreToolbars() to fill the workspace combo box again
357360
_workspaceManager->updateWorkspaceLists();
@@ -3912,6 +3915,7 @@ void MainWindow::openSettingsDialog(int page, bool openScriptRepository) {
39123915
// read all relevant settings, that can be set in the settings dialog,
39133916
// even if the dialog was canceled
39143917
readSettingsFromSettingsDialog();
3918+
checkAiToolbarConfiguration();
39153919

39163920
// update the panels sort and order
39173921
updatePanelsSortOrder();
@@ -3941,6 +3945,33 @@ void MainWindow::openSettingsDialog(int page, bool openScriptRepository) {
39413945
forceRegenerateNotePreview();
39423946
}
39433947

3948+
void MainWindow::checkAiToolbarConfiguration(bool askToShowToolbar) {
3949+
QToolBar *aiToolbar = _aiToolbarManager->aiToolbar();
3950+
const bool hasConfiguredAiBackend = OpenAiService::instance()->hasConfiguredBackend();
3951+
const bool aiToolbarWasHidden = aiToolbar->isHidden();
3952+
3953+
if (!hasConfiguredAiBackend) {
3954+
aiToolbar->hide();
3955+
3956+
if (!aiToolbarWasHidden) {
3957+
storeCurrentWorkspace();
3958+
}
3959+
3960+
return;
3961+
}
3962+
3963+
if (askToShowToolbar && aiToolbarWasHidden &&
3964+
Utils::Gui::question(this, tr("AI toolbar disabled"),
3965+
tr("An AI backend is configured, but the AI toolbar is currently "
3966+
"disabled. Do you want to turn it on?"),
3967+
QStringLiteral("enable-ai-toolbar-question"),
3968+
QMessageBox::Yes | QMessageBox::No,
3969+
QMessageBox::Yes) == QMessageBox::Yes) {
3970+
aiToolbar->show();
3971+
storeCurrentWorkspace();
3972+
}
3973+
}
3974+
39443975
void MainWindow::forceRegenerateNotePreview() {
39453976
_notePreviewHash.clear();
39463977
currentNote.resetNoteTextHtmlConversionHash();

src/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ class MainWindow : public QMainWindow {
10531053
void makeCurrentNoteFirstInNoteList();
10541054

10551055
void readSettingsFromSettingsDialog(const bool isAppLaunch = false);
1056+
void checkAiToolbarConfiguration(bool askToShowToolbar = true);
10561057

10571058
void setCurrentNoteFromHistoryItem(const NoteHistoryItem &item);
10581059

src/services/openaiservice.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,30 @@ QStringList OpenAiService::getModelsForCurrentBackend() {
214214

215215
QMap<QString, QString> OpenAiService::getBackendNames() { return _backendNames; }
216216

217+
bool OpenAiService::hasConfiguredBackend() const {
218+
SettingsService settings;
219+
220+
for (auto it = _backendNames.constBegin(); it != _backendNames.constEnd(); ++it) {
221+
const QString& backendId = it.key();
222+
QString apiKey = _backendApiKeys.value(backendId);
223+
224+
if (backendId == QStringLiteral("groq") || backendId == QStringLiteral("openai")) {
225+
apiKey = CryptoService::instance()->decryptToString(
226+
settings.value(getApiKeySettingsKeyForBackend(backendId)).toString());
227+
}
228+
229+
if (!apiKey.trimmed().isEmpty()) {
230+
return true;
231+
}
232+
233+
if (backendId != QStringLiteral("groq") && backendId != QStringLiteral("openai")) {
234+
return true;
235+
}
236+
}
237+
238+
return false;
239+
}
240+
217241
QString OpenAiService::getApiBaseUrlForCurrentBackend() {
218242
return getApiBaseUrlForBackend(getBackendId());
219243
}

src/services/openaiservice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class OpenAiService : public QObject {
7171
void setApiKeyForCurrentBackend(const QString& apiKey);
7272
QMap<QString, QString> getBackendNames();
7373
QString getApiBaseUrlForBackend(const QString& backendId);
74+
bool hasConfiguredBackend() const;
7475

7576
// Callback for autocomplete results (avoids circular dependency)
7677
using AutocompleteCallback = std::function<void(const QString&)>;

0 commit comments

Comments
 (0)