forked from linuxdeepin/deepin-unioncode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log: Change-Id: I00709b1879be24a2400a68a5910f0eeafc4d6d05
- Loading branch information
1 parent
e9128f3
commit 8693515
Showing
14 changed files
with
339 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "codegeexoptionwidget.h" | ||
#include "detailwidget.h" | ||
|
||
#include "services/option/optionutils.h" | ||
#include "services/option/optiondatastruct.h" | ||
#include "services/option/optionmanager.h" | ||
|
||
#include <QHBoxLayout> | ||
#include <QTabWidget> | ||
|
||
|
||
static const char *kCATEGORY_CODEGEEX = "CodeGeeX"; | ||
|
||
class CodeGeeXOptionWidgetPrivate | ||
{ | ||
QTabWidget* tabWidget = nullptr; | ||
friend class CodeGeeXOptionWidget; | ||
}; | ||
|
||
CodeGeeXOptionWidget::CodeGeeXOptionWidget(QWidget *parent) | ||
: PageWidget(parent) | ||
, d(new CodeGeeXOptionWidgetPrivate()) | ||
{ | ||
QHBoxLayout *layout = new QHBoxLayout(); | ||
d->tabWidget = new QTabWidget(); | ||
layout->addWidget(d->tabWidget); | ||
|
||
d->tabWidget->addTab(new DetailWidget(), tr("CodeGeeX")); | ||
QObject::connect(d->tabWidget, &QTabWidget::currentChanged, [this]() { | ||
readConfig(); | ||
}); | ||
|
||
setLayout(layout); | ||
} | ||
|
||
CodeGeeXOptionWidget::~CodeGeeXOptionWidget() | ||
{ | ||
if (d) | ||
delete d; | ||
} | ||
|
||
void CodeGeeXOptionWidget::saveConfig() | ||
{ | ||
for (int index = 0; index < d->tabWidget->count(); index++) { | ||
PageWidget *pageWidget = qobject_cast<PageWidget*>(d->tabWidget->widget(index)); | ||
if (pageWidget) { | ||
QString itemNode = d->tabWidget->tabText(d->tabWidget->currentIndex()); | ||
QMap<QString, QVariant> map; | ||
pageWidget->getUserConfig(map); | ||
OptionUtils::writeJsonSection(OptionUtils::getJsonFilePath(), kCATEGORY_CODEGEEX, itemNode, map); | ||
|
||
OptionManager::getInstance()->updateData(); | ||
} | ||
} | ||
} | ||
|
||
void CodeGeeXOptionWidget::readConfig() | ||
{ | ||
for (int index = 0; index < d->tabWidget->count(); index++) { | ||
PageWidget *pageWidget = qobject_cast<PageWidget*>(d->tabWidget->widget(index)); | ||
if (pageWidget) { | ||
QString itemNode = d->tabWidget->tabText(d->tabWidget->currentIndex()); | ||
QMap<QString, QVariant> map; | ||
OptionUtils::readJsonSection(OptionUtils::getJsonFilePath(), | ||
kCATEGORY_CODEGEEX, itemNode, map); | ||
pageWidget->setUserConfig(map); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef CODEGEEXOPTIONWIDGET_H | ||
#define CODEGEEXOPTIONWIDGET_H | ||
|
||
#include "common/common.h" | ||
|
||
class CodeGeeXOptionWidgetPrivate; | ||
class CodeGeeXOptionWidget : public PageWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CodeGeeXOptionWidget(QWidget *parent = nullptr); | ||
~CodeGeeXOptionWidget() override; | ||
|
||
void saveConfig() override; | ||
void readConfig() override; | ||
|
||
signals: | ||
|
||
public slots: | ||
private: | ||
CodeGeeXOptionWidgetPrivate *const d; | ||
}; | ||
|
||
#endif // CODEGEEXOPTIONWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "detailwidget.h" | ||
#include "common/util/custompaths.h" | ||
|
||
#include <QJsonObject> | ||
#include <QJsonDocument> | ||
#include <QByteArray> | ||
#include <QJsonArray> | ||
#include <QFile> | ||
#include <QDir> | ||
#include <QRadioButton> | ||
#include <QLineEdit> | ||
#include <QVBoxLayout> | ||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
#include <QHeaderView> | ||
#include <QDebug> | ||
|
||
static const char *kApiKey = "apiKey"; | ||
|
||
// this is a temporary key | ||
static const char *kDefaultApiKey = "f30ea902c3824ee88e221a32363c0823"; | ||
|
||
class DetailWidgetPrivate | ||
{ | ||
friend class DetailWidget; | ||
|
||
QLineEdit *apiKeyWidget = nullptr; | ||
}; | ||
|
||
DetailWidget::DetailWidget(QWidget *parent) | ||
: PageWidget(parent) | ||
, d(new DetailWidgetPrivate()) | ||
{ | ||
setupUi(); | ||
updateUi(); | ||
} | ||
|
||
DetailWidget::~DetailWidget() | ||
{ | ||
if (d) { | ||
delete d; | ||
} | ||
} | ||
|
||
void DetailWidget::setupUi() | ||
{ | ||
QVBoxLayout *vLayout = new QVBoxLayout(); | ||
setLayout(vLayout); | ||
|
||
QHBoxLayout *hLayout = new QHBoxLayout(); | ||
QLabel *label = new QLabel(QLabel::tr("CodeGeeX Api Key:")); | ||
d->apiKeyWidget = new QLineEdit(); | ||
hLayout->addWidget(label); | ||
hLayout->addWidget(d->apiKeyWidget); | ||
|
||
vLayout->addLayout(hLayout); | ||
vLayout->addStretch(); | ||
} | ||
|
||
void DetailWidget::updateUi() | ||
{ | ||
} | ||
|
||
bool DetailWidget::getControlValue(QMap<QString, QVariant> &map) | ||
{ | ||
CodeGeeXConfig config; | ||
config.apiKey = d->apiKeyWidget->text(); | ||
dataToMap(config, map); | ||
|
||
return true; | ||
} | ||
|
||
void DetailWidget::setControlValue(const QMap<QString, QVariant> &map) | ||
{ | ||
CodeGeeXConfig config; | ||
mapToData(map, config); | ||
|
||
if (config.apiKey.isEmpty()) { | ||
config.apiKey = kDefaultApiKey; | ||
} | ||
d->apiKeyWidget->setText(config.apiKey); | ||
} | ||
|
||
bool DetailWidget::dataToMap(const CodeGeeXConfig &config, QMap<QString, QVariant> &map) | ||
{ | ||
QMap<QString, QVariant> apiKey; | ||
apiKey.insert(kApiKey, config.apiKey); | ||
|
||
map.insert(tr("Detail"), apiKey); | ||
|
||
return true; | ||
} | ||
|
||
bool DetailWidget::mapToData(const QMap<QString, QVariant> &map, CodeGeeXConfig &config) | ||
{ | ||
QMap<QString, QVariant> detail = map.value(tr("Detail")).toMap(); | ||
config.apiKey = detail.value(kApiKey).toString(); | ||
|
||
return true; | ||
} | ||
|
||
void DetailWidget::setUserConfig(const QMap<QString, QVariant> &map) | ||
{ | ||
setControlValue(map); | ||
} | ||
|
||
void DetailWidget::getUserConfig(QMap<QString, QVariant> &map) | ||
{ | ||
getControlValue(map); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef DETAILWIDGET_H | ||
#define DETAILWIDGET_H | ||
|
||
#include "services/option/toolchaindata.h" | ||
#include "common/widget/pagewidget.h" | ||
|
||
struct CodeGeeXConfig{ | ||
QString apiKey; | ||
}; | ||
|
||
class DetailWidgetPrivate; | ||
class DetailWidget : public PageWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit DetailWidget(QWidget *parent = nullptr); | ||
~DetailWidget() override; | ||
|
||
void setUserConfig(const QMap<QString, QVariant> &map) override; | ||
void getUserConfig(QMap<QString, QVariant> &map) override; | ||
|
||
signals: | ||
|
||
public slots: | ||
|
||
private: | ||
void setupUi(); | ||
void updateUi(); | ||
|
||
bool dataToMap(const CodeGeeXConfig &config, QMap<QString, QVariant> &map); | ||
bool mapToData(const QMap<QString, QVariant> &map, CodeGeeXConfig &config); | ||
|
||
bool getControlValue(QMap<QString, QVariant> &map); | ||
void setControlValue(const QMap<QString, QVariant> &map); | ||
|
||
DetailWidgetPrivate *const d; | ||
}; | ||
|
||
#endif // DETAILWIDGET_H |
Oops, something went wrong.