mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
Impove UX general setting by added helpers dialogs for user (#42)
- Added dialogs for selecting url, model and custom model when provider doesn't provide model list or setup of qode assist is not finishing
This commit is contained in:
parent
5e813ba402
commit
f209cb75a2
@ -95,15 +95,24 @@ void ConfigurationManager::selectModel()
|
|||||||
|
|
||||||
auto &targetSettings = isCodeCompletion ? m_generalSettings.ccModel : m_generalSettings.caModel;
|
auto &targetSettings = isCodeCompletion ? m_generalSettings.ccModel : m_generalSettings.caModel;
|
||||||
|
|
||||||
const auto modelList
|
if (auto provider = m_providersManager.getProviderByName(providerName)) {
|
||||||
= m_providersManager.getProviderByName(providerName)->getInstalledModels(providerUrl);
|
if (!provider->supportsModelListing()) {
|
||||||
|
m_generalSettings.showModelsNotSupportedDialog(targetSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto modelList = provider->getInstalledModels(providerUrl);
|
||||||
|
|
||||||
|
if (modelList.isEmpty()) {
|
||||||
|
m_generalSettings.showModelsNotFoundDialog(targetSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTimer::singleShot(0, &m_generalSettings, [this, modelList, &targetSettings]() {
|
QTimer::singleShot(0, &m_generalSettings, [this, modelList, &targetSettings]() {
|
||||||
m_generalSettings.showSelectionDialog(modelList,
|
m_generalSettings.showSelectionDialog(
|
||||||
targetSettings,
|
modelList, targetSettings, Tr::tr("Select LLM Model"), Tr::tr("Models:"));
|
||||||
Tr::tr("Select LLM Model"),
|
|
||||||
Tr::tr("Models:"));
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurationManager::selectTemplate()
|
void ConfigurationManager::selectTemplate()
|
||||||
@ -130,6 +139,10 @@ void ConfigurationManager::selectTemplate()
|
|||||||
|
|
||||||
void ConfigurationManager::selectUrl()
|
void ConfigurationManager::selectUrl()
|
||||||
{
|
{
|
||||||
|
auto *settingsButton = qobject_cast<ButtonAspect *>(sender());
|
||||||
|
if (!settingsButton)
|
||||||
|
return;
|
||||||
|
|
||||||
QStringList urls;
|
QStringList urls;
|
||||||
for (const auto &name : m_providersManager.providersNames()) {
|
for (const auto &name : m_providersManager.providersNames()) {
|
||||||
const auto url = m_providersManager.getProviderByName(name)->url();
|
const auto url = m_providersManager.getProviderByName(name)->url();
|
||||||
@ -137,19 +150,12 @@ void ConfigurationManager::selectUrl()
|
|||||||
urls.append(url);
|
urls.append(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *settingsButton = qobject_cast<ButtonAspect *>(sender());
|
|
||||||
if (!settingsButton)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto &targetSettings = (settingsButton == &m_generalSettings.ccSetUrl)
|
auto &targetSettings = (settingsButton == &m_generalSettings.ccSetUrl)
|
||||||
? m_generalSettings.ccUrl
|
? m_generalSettings.ccUrl
|
||||||
: m_generalSettings.caUrl;
|
: m_generalSettings.caUrl;
|
||||||
|
|
||||||
QTimer::singleShot(0, &m_generalSettings, [this, urls, &targetSettings]() {
|
QTimer::singleShot(0, &m_generalSettings, [this, urls, &targetSettings]() {
|
||||||
m_generalSettings.showSelectionDialog(urls,
|
m_generalSettings.showUrlSelectionDialog(targetSettings, urls);
|
||||||
targetSettings,
|
|
||||||
Tr::tr("Select URL"),
|
|
||||||
Tr::tr("URLs:"));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
virtual QString url() const = 0;
|
virtual QString url() const = 0;
|
||||||
virtual QString completionEndpoint() const = 0;
|
virtual QString completionEndpoint() const = 0;
|
||||||
virtual QString chatEndpoint() const = 0;
|
virtual QString chatEndpoint() const = 0;
|
||||||
|
virtual bool supportsModelListing() const = 0;
|
||||||
|
|
||||||
virtual void prepareRequest(QJsonObject &request, RequestType type) = 0;
|
virtual void prepareRequest(QJsonObject &request, RequestType type) = 0;
|
||||||
virtual bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) = 0;
|
virtual bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) = 0;
|
||||||
|
@ -53,6 +53,11 @@ QString LMStudioProvider::chatEndpoint() const
|
|||||||
return "/v1/chat/completions";
|
return "/v1/chat/completions";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LMStudioProvider::supportsModelListing() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void LMStudioProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
void LMStudioProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
||||||
{
|
{
|
||||||
auto prepareMessages = [](QJsonObject &req) -> QJsonArray {
|
auto prepareMessages = [](QJsonObject &req) -> QJsonArray {
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
QString url() const override;
|
QString url() const override;
|
||||||
QString completionEndpoint() const override;
|
QString completionEndpoint() const override;
|
||||||
QString chatEndpoint() const override;
|
QString chatEndpoint() const override;
|
||||||
|
bool supportsModelListing() const override;
|
||||||
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
||||||
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
||||||
QList<QString> getInstalledModels(const QString &url) override;
|
QList<QString> getInstalledModels(const QString &url) override;
|
||||||
|
@ -53,6 +53,11 @@ QString OllamaProvider::chatEndpoint() const
|
|||||||
return "/api/chat";
|
return "/api/chat";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OllamaProvider::supportsModelListing() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void OllamaProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
void OllamaProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
||||||
{
|
{
|
||||||
auto applySettings = [&request](const auto &settings) {
|
auto applySettings = [&request](const auto &settings) {
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
QString url() const override;
|
QString url() const override;
|
||||||
QString completionEndpoint() const override;
|
QString completionEndpoint() const override;
|
||||||
QString chatEndpoint() const override;
|
QString chatEndpoint() const override;
|
||||||
|
bool supportsModelListing() const override;
|
||||||
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
||||||
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
||||||
QList<QString> getInstalledModels(const QString &url) override;
|
QList<QString> getInstalledModels(const QString &url) override;
|
||||||
|
@ -50,6 +50,11 @@ QString OpenAICompatProvider::chatEndpoint() const
|
|||||||
return "/v1/chat/completions";
|
return "/v1/chat/completions";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OpenAICompatProvider::supportsModelListing() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void OpenAICompatProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
void OpenAICompatProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
||||||
{
|
{
|
||||||
auto prepareMessages = [](QJsonObject &req) -> QJsonArray {
|
auto prepareMessages = [](QJsonObject &req) -> QJsonArray {
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
QString url() const override;
|
QString url() const override;
|
||||||
QString completionEndpoint() const override;
|
QString completionEndpoint() const override;
|
||||||
QString chatEndpoint() const override;
|
QString chatEndpoint() const override;
|
||||||
|
bool supportsModelListing() const override;
|
||||||
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
||||||
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
||||||
QList<QString> getInstalledModels(const QString &url) override;
|
QList<QString> getInstalledModels(const QString &url) override;
|
||||||
|
@ -7,6 +7,7 @@ add_library(QodeAssistSettings STATIC
|
|||||||
SettingsTr.hpp
|
SettingsTr.hpp
|
||||||
CodeCompletionSettings.hpp CodeCompletionSettings.cpp
|
CodeCompletionSettings.hpp CodeCompletionSettings.cpp
|
||||||
ChatAssistantSettings.hpp ChatAssistantSettings.cpp
|
ChatAssistantSettings.hpp ChatAssistantSettings.cpp
|
||||||
|
SettingsDialog.hpp SettingsDialog.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(QodeAssistSettings
|
target_link_libraries(QodeAssistSettings
|
||||||
|
@ -19,15 +19,22 @@
|
|||||||
|
|
||||||
#include "GeneralSettings.hpp"
|
#include "GeneralSettings.hpp"
|
||||||
|
|
||||||
#include <QInputDialog>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QtWidgets/qboxlayout.h>
|
||||||
|
#include <QtWidgets/qcompleter.h>
|
||||||
|
#include <QtWidgets/qgroupbox.h>
|
||||||
|
#include <QtWidgets/qradiobutton.h>
|
||||||
|
#include <QtWidgets/qstackedwidget.h>
|
||||||
|
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
#include "SettingsConstants.hpp"
|
#include "SettingsConstants.hpp"
|
||||||
|
#include "SettingsDialog.hpp"
|
||||||
#include "SettingsTr.hpp"
|
#include "SettingsTr.hpp"
|
||||||
#include "SettingsUtils.hpp"
|
#include "SettingsUtils.hpp"
|
||||||
|
|
||||||
@ -109,16 +116,16 @@ GeneralSettings::GeneralSettings()
|
|||||||
|
|
||||||
auto ccGrid = Grid{};
|
auto ccGrid = Grid{};
|
||||||
ccGrid.addRow({ccProvider, ccSelectProvider});
|
ccGrid.addRow({ccProvider, ccSelectProvider});
|
||||||
|
ccGrid.addRow({ccUrl, ccSetUrl});
|
||||||
ccGrid.addRow({ccModel, ccSelectModel});
|
ccGrid.addRow({ccModel, ccSelectModel});
|
||||||
ccGrid.addRow({ccTemplate, ccSelectTemplate});
|
ccGrid.addRow({ccTemplate, ccSelectTemplate});
|
||||||
ccGrid.addRow({ccUrl, ccSetUrl});
|
|
||||||
ccGrid.addRow({ccStatus, ccTest});
|
ccGrid.addRow({ccStatus, ccTest});
|
||||||
|
|
||||||
auto caGrid = Grid{};
|
auto caGrid = Grid{};
|
||||||
caGrid.addRow({caProvider, caSelectProvider});
|
caGrid.addRow({caProvider, caSelectProvider});
|
||||||
|
caGrid.addRow({caUrl, caSetUrl});
|
||||||
caGrid.addRow({caModel, caSelectModel});
|
caGrid.addRow({caModel, caSelectModel});
|
||||||
caGrid.addRow({caTemplate, caSelectTemplate});
|
caGrid.addRow({caTemplate, caSelectTemplate});
|
||||||
caGrid.addRow({caUrl, caSetUrl});
|
|
||||||
caGrid.addRow({caStatus, caTest});
|
caGrid.addRow({caStatus, caTest});
|
||||||
|
|
||||||
auto ccGroup = Group{title(TrConstants::CODE_COMPLETION), ccGrid};
|
auto ccGroup = Group{title(TrConstants::CODE_COMPLETION), ccGrid};
|
||||||
@ -161,6 +168,129 @@ void GeneralSettings::showSelectionDialog(const QStringList &data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeneralSettings::showModelsNotFoundDialog(Utils::StringAspect &aspect)
|
||||||
|
{
|
||||||
|
SettingsDialog dialog(TrConstants::CONNECTION_ERROR);
|
||||||
|
dialog.addLabel(TrConstants::NO_MODELS_FOUND);
|
||||||
|
dialog.addLabel(TrConstants::CHECK_CONNECTION);
|
||||||
|
dialog.addSpacing();
|
||||||
|
|
||||||
|
ButtonAspect *providerButton = nullptr;
|
||||||
|
ButtonAspect *urlButton = nullptr;
|
||||||
|
|
||||||
|
if (&aspect == &ccModel) {
|
||||||
|
providerButton = &ccSelectProvider;
|
||||||
|
urlButton = &ccSetUrl;
|
||||||
|
} else if (&aspect == &caModel) {
|
||||||
|
providerButton = &caSelectProvider;
|
||||||
|
urlButton = &caSetUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (providerButton && urlButton) {
|
||||||
|
auto selectProviderBtn = new QPushButton(TrConstants::SELECT_PROVIDER);
|
||||||
|
auto selectUrlBtn = new QPushButton(TrConstants::SELECT_URL);
|
||||||
|
auto enterManuallyBtn = new QPushButton(TrConstants::ENTER_MODEL_MANUALLY);
|
||||||
|
|
||||||
|
connect(selectProviderBtn, &QPushButton::clicked, &dialog, [this, providerButton, &dialog]() {
|
||||||
|
dialog.close();
|
||||||
|
emit providerButton->clicked();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(selectUrlBtn, &QPushButton::clicked, &dialog, [this, urlButton, &dialog]() {
|
||||||
|
dialog.close();
|
||||||
|
emit urlButton->clicked();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(enterManuallyBtn, &QPushButton::clicked, &dialog, [this, &aspect, &dialog]() {
|
||||||
|
dialog.close();
|
||||||
|
showModelsNotSupportedDialog(aspect);
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.buttonLayout()->addWidget(selectProviderBtn);
|
||||||
|
dialog.buttonLayout()->addWidget(selectUrlBtn);
|
||||||
|
dialog.buttonLayout()->addWidget(enterManuallyBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto closeBtn = new QPushButton(TrConstants::CLOSE);
|
||||||
|
connect(closeBtn, &QPushButton::clicked, &dialog, &QDialog::close);
|
||||||
|
dialog.buttonLayout()->addWidget(closeBtn);
|
||||||
|
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeneralSettings::showModelsNotSupportedDialog(Utils::StringAspect &aspect)
|
||||||
|
{
|
||||||
|
SettingsDialog dialog(TrConstants::MODEL_SELECTION);
|
||||||
|
dialog.addLabel(TrConstants::MODEL_LISTING_NOT_SUPPORTED_INFO);
|
||||||
|
dialog.addSpacing();
|
||||||
|
|
||||||
|
QString key = QString("CompleterHistory/")
|
||||||
|
.append(
|
||||||
|
(&aspect == &ccModel) ? Constants::CC_MODEL_HISTORY
|
||||||
|
: Constants::CA_MODEL_HISTORY);
|
||||||
|
QStringList historyList = qtcSettings()->value(Utils::Key(key.toLocal8Bit())).toStringList();
|
||||||
|
|
||||||
|
auto modelList = dialog.addComboBox(historyList, aspect.value());
|
||||||
|
dialog.addSpacing();
|
||||||
|
|
||||||
|
auto okButton = new QPushButton(TrConstants::OK);
|
||||||
|
connect(okButton, &QPushButton::clicked, &dialog, [this, &aspect, modelList, &dialog]() {
|
||||||
|
QString value = modelList->currentText().trimmed();
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
aspect.setValue(value);
|
||||||
|
writeSettings();
|
||||||
|
dialog.accept();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
auto cancelButton = new QPushButton(TrConstants::CANCEL);
|
||||||
|
connect(cancelButton, &QPushButton::clicked, &dialog, &QDialog::reject);
|
||||||
|
|
||||||
|
dialog.buttonLayout()->addWidget(cancelButton);
|
||||||
|
dialog.buttonLayout()->addWidget(okButton);
|
||||||
|
|
||||||
|
modelList->setFocus();
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeneralSettings::showUrlSelectionDialog(
|
||||||
|
Utils::StringAspect &aspect, const QStringList &predefinedUrls)
|
||||||
|
{
|
||||||
|
SettingsDialog dialog(TrConstants::URL_SELECTION);
|
||||||
|
dialog.addLabel(TrConstants::URL_SELECTION_INFO);
|
||||||
|
dialog.addSpacing();
|
||||||
|
|
||||||
|
QStringList allUrls = predefinedUrls;
|
||||||
|
QString key
|
||||||
|
= QString("CompleterHistory/")
|
||||||
|
.append((&aspect == &ccUrl) ? Constants::CC_URL_HISTORY : Constants::CA_URL_HISTORY);
|
||||||
|
QStringList historyList = qtcSettings()->value(Utils::Key(key.toLocal8Bit())).toStringList();
|
||||||
|
allUrls.append(historyList);
|
||||||
|
allUrls.removeDuplicates();
|
||||||
|
|
||||||
|
auto urlList = dialog.addComboBox(allUrls, aspect.value());
|
||||||
|
dialog.addSpacing();
|
||||||
|
|
||||||
|
auto okButton = new QPushButton(TrConstants::OK);
|
||||||
|
connect(okButton, &QPushButton::clicked, &dialog, [this, &aspect, urlList, &dialog]() {
|
||||||
|
QString value = urlList->currentText().trimmed();
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
aspect.setValue(value);
|
||||||
|
writeSettings();
|
||||||
|
dialog.accept();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
auto cancelButton = new QPushButton(TrConstants::CANCEL);
|
||||||
|
connect(cancelButton, &QPushButton::clicked, &dialog, &QDialog::reject);
|
||||||
|
|
||||||
|
dialog.buttonLayout()->addWidget(cancelButton);
|
||||||
|
dialog.buttonLayout()->addWidget(okButton);
|
||||||
|
|
||||||
|
urlList->setFocus();
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void GeneralSettings::setupConnections()
|
void GeneralSettings::setupConnections()
|
||||||
{
|
{
|
||||||
connect(&enableLogging, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
connect(&enableLogging, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||||
|
@ -74,6 +74,12 @@ public:
|
|||||||
const QString &title = {},
|
const QString &title = {},
|
||||||
const QString &text = {});
|
const QString &text = {});
|
||||||
|
|
||||||
|
void showModelsNotFoundDialog(Utils::StringAspect &aspect);
|
||||||
|
|
||||||
|
void showModelsNotSupportedDialog(Utils::StringAspect &aspect);
|
||||||
|
|
||||||
|
void showUrlSelectionDialog(Utils::StringAspect &aspect, const QStringList &predefinedUrls);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupConnections();
|
void setupConnections();
|
||||||
void resetPageToDefaults();
|
void resetPageToDefaults();
|
||||||
|
89
settings/SettingsDialog.cpp
Normal file
89
settings/SettingsDialog.cpp
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SettingsDialog.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::Settings {
|
||||||
|
|
||||||
|
SettingsDialog::SettingsDialog(const QString &title, QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, m_mainLayout(new QVBoxLayout(this))
|
||||||
|
, m_buttonLayout(nullptr)
|
||||||
|
{
|
||||||
|
setWindowTitle(title);
|
||||||
|
m_mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *SettingsDialog::addLabel(const QString &text)
|
||||||
|
{
|
||||||
|
auto label = new QLabel(text, this);
|
||||||
|
label->setWordWrap(true);
|
||||||
|
label->setMinimumWidth(300);
|
||||||
|
m_mainLayout->addWidget(label);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineEdit *SettingsDialog::addInputField(const QString &labelText, const QString &value)
|
||||||
|
{
|
||||||
|
auto inputLayout = new QGridLayout;
|
||||||
|
auto inputLabel = new QLabel(labelText, this);
|
||||||
|
auto inputField = new QLineEdit(value, this);
|
||||||
|
inputField->setMinimumWidth(200);
|
||||||
|
|
||||||
|
inputLayout->addWidget(inputLabel, 0, 0);
|
||||||
|
inputLayout->addWidget(inputField, 0, 1);
|
||||||
|
inputLayout->setColumnStretch(1, 1);
|
||||||
|
m_mainLayout->addLayout(inputLayout);
|
||||||
|
|
||||||
|
return inputField;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::addSpacing(int space)
|
||||||
|
{
|
||||||
|
m_mainLayout->addSpacing(space);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHBoxLayout *SettingsDialog::buttonLayout()
|
||||||
|
{
|
||||||
|
if (!m_buttonLayout) {
|
||||||
|
m_buttonLayout = new QHBoxLayout;
|
||||||
|
m_buttonLayout->addStretch();
|
||||||
|
m_mainLayout->addLayout(m_buttonLayout);
|
||||||
|
}
|
||||||
|
return m_buttonLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
QComboBox *SettingsDialog::addComboBox(
|
||||||
|
const QStringList &items, const QString ¤tText, bool editable)
|
||||||
|
{
|
||||||
|
auto comboBox = new QComboBox(this);
|
||||||
|
comboBox->addItems(items);
|
||||||
|
comboBox->setCurrentText(currentText);
|
||||||
|
comboBox->setMinimumWidth(300);
|
||||||
|
comboBox->setEditable(editable);
|
||||||
|
m_mainLayout->addWidget(comboBox);
|
||||||
|
return comboBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVBoxLayout *SettingsDialog::mainLayout() const
|
||||||
|
{
|
||||||
|
return m_mainLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Settings
|
50
settings/SettingsDialog.hpp
Normal file
50
settings/SettingsDialog.hpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
namespace QodeAssist::Settings {
|
||||||
|
|
||||||
|
class SettingsDialog : public QDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SettingsDialog(const QString &title, QWidget *parent = Core::ICore::dialogParent());
|
||||||
|
|
||||||
|
QLabel *addLabel(const QString &text);
|
||||||
|
QLineEdit *addInputField(const QString &labelText, const QString &value);
|
||||||
|
void addSpacing(int space = 12);
|
||||||
|
QHBoxLayout *buttonLayout();
|
||||||
|
QVBoxLayout *mainLayout() const;
|
||||||
|
|
||||||
|
QComboBox *addComboBox(
|
||||||
|
const QStringList &items, const QString ¤tText = QString(), bool editable = true);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVBoxLayout *m_mainLayout;
|
||||||
|
QHBoxLayout *m_buttonLayout;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Settings
|
@ -42,6 +42,44 @@ inline const char *RESET_SETTINGS = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Reset
|
|||||||
inline const char *CONFIRMATION
|
inline const char *CONFIRMATION
|
||||||
= QT_TRANSLATE_NOOP("QtC::QodeAssist",
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist",
|
||||||
"Are you sure you want to reset all settings to default values?");
|
"Are you sure you want to reset all settings to default values?");
|
||||||
|
|
||||||
|
inline const char CONNECTION_ERROR[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Connection Error");
|
||||||
|
inline const char NO_MODELS_FOUND[]
|
||||||
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Unable to retrieve the list of models from the server.");
|
||||||
|
inline const char CHECK_CONNECTION[] = QT_TRANSLATE_NOOP(
|
||||||
|
"QtC::QodeAssist",
|
||||||
|
"Please verify the following:\n"
|
||||||
|
"- Server is running and accessible\n"
|
||||||
|
"- URL is correct\n"
|
||||||
|
"- Provider is properly configured\n\n"
|
||||||
|
"You can try selecting a different provider or changing the URL:");
|
||||||
|
inline const char SELECT_PROVIDER[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Select Provider");
|
||||||
|
inline const char SELECT_URL[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Select URL");
|
||||||
|
inline const char CLOSE[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Close");
|
||||||
|
inline const char MODEL_SELECTION[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Model Selection");
|
||||||
|
inline const char MODEL_LISTING_NOT_SUPPORTED_INFO[] = QT_TRANSLATE_NOOP(
|
||||||
|
"QtC::QodeAssist",
|
||||||
|
"Select from previously used models or enter a new model name.\n\n"
|
||||||
|
"If entering a new model name:\n"
|
||||||
|
"• For providers with automatic listing - ensure the model is installed\n"
|
||||||
|
"• For providers without listing support - check provider's documentation\n"
|
||||||
|
"• Make sure the model name matches exactly");
|
||||||
|
inline const char MODEL_NAME[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Model name:");
|
||||||
|
inline const char OK[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "OK");
|
||||||
|
inline const char CANCEL[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Cancel");
|
||||||
|
inline const char ENTER_MODEL_MANUALLY[]
|
||||||
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Enter Model Manually");
|
||||||
|
inline const char URL_SELECTION[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "URL Selection");
|
||||||
|
inline const char URL_SELECTION_INFO[] = QT_TRANSLATE_NOOP(
|
||||||
|
"QtC::QodeAssist",
|
||||||
|
"Select from the list of default and previously used URLs, or enter a custom one.\n"
|
||||||
|
"Please ensure the selected URL is accessible and the service is running.");
|
||||||
|
inline const char PREDEFINED_URL[]
|
||||||
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Use default provider URL or from history");
|
||||||
|
inline const char CUSTOM_URL[] = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Enter custom URL");
|
||||||
|
inline const char ENTER_MODEL_MANUALLY_BUTTON[]
|
||||||
|
= QT_TRANSLATE_NOOP("QtC::QodeAssist", "Enter Model Name Manually");
|
||||||
|
|
||||||
} // namespace TrConstants
|
} // namespace TrConstants
|
||||||
|
|
||||||
struct Tr
|
struct Tr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user