Skip to content

Commit

Permalink
chore: login ui optimization
Browse files Browse the repository at this point in the history
Log: login ui changed
Change-Id: I29b60f367aaa68f66f9fc4f4c4ed6c70546e4c36
  • Loading branch information
deepin-mozart committed Nov 15, 2023
1 parent 8fa8032 commit 37b4171
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(CXX_H
toolchain/toolchain.h
actionmanager/actionmanager.h
actionmanager/command.h
unilog.h
)

set(CXX_CPP
Expand Down
13 changes: 7 additions & 6 deletions src/common/lsp/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "private/client_p.h"
#include "common/util/custompaths.h"
#include "common/util/processutil.h"
#include "common/unilog.h"

#include <QMetaType>
#include <QDebug>
Expand Down Expand Up @@ -291,7 +292,7 @@ void ClientPrivate::callNotification(const QString &method, const QJsonObject &p

void ClientPrivate::writeLspData(const QByteArray &jsonObj)
{
qInfo() << "\nclient->server:\n{\n" << jsonObj << "\n}";
uniDebug() << "\nclient->server:\n{\n" << jsonObj << "\n}";
q->write(jsonObj);
q->waitForBytesWritten();
}
Expand Down Expand Up @@ -1058,18 +1059,18 @@ void ClientPrivate::doReadStdoutLine()
void ClientPrivate::identifyJsonObject(const QJsonObject &jsonObj)
{
if (calledError(jsonObj)) {
qWarning() << "\nclient <- server:\n{\n" << jsonObj << "\n}";
uniCritical() << "\nclient <- server:\n{\n" << jsonObj << "\n}";
return;
}


if (calledResult(jsonObj)) {
qInfo() << "\nclient <- server:\n{\n" << jsonObj << "\n}";
uniWarning() << "\nclient <- server:\n{\n" << jsonObj << "\n}";
return;
}

if (serverCalled(jsonObj)) {
qInfo() << "\nclient <- server:\n{\n" << jsonObj << "\n}";
uniWarning() << "\nclient <- server:\n{\n" << jsonObj << "\n}";
return;
}
}
Expand All @@ -1096,13 +1097,13 @@ ClientPrivate::ClientPrivate(Client * const q)
QObject::connect(q, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, [&](int exitCode, QProcess::ExitStatus status)
{
qCritical() << "\nclient <- server\n{\n" << "lspServerProc finished:\n" << exitCode << status << "\n}";
uniInfo() << "\nclient <- server\n{\n" << "lspServerProc finished:\n" << exitCode << status << "\n}";
});

QObject::connect(q, &QProcess::readyReadStandardError,
this, [=]()
{
qCritical() << "\nclient <- server\n{\n" <<q->readAllStandardError() << "\n}";
uniCritical() << "\nclient <- server\n{\n" <<q->readAllStandardError() << "\n}";
});

QObject::connect(q, &QProcess::readyReadStandardOutput,
Expand Down
25 changes: 25 additions & 0 deletions src/common/unilog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef UNILOG_H
#define UNILOG_H

#include <QDebug>

#ifdef QT_DEBUG
#define UNI_DEBUG
#endif
#ifdef UNI_DEBUG
#define uniDebug(...) qDebug(__VA_ARGS__)
#define uniInfo(...) qInfo(__VA_ARGS__)
#define uniWarning(...) qWarning(__VA_ARGS__)
#define uniCritical(...) qCritical(__VA_ARGS__)
#else
#define NO_DEBUG(LOG) QMessageLogger().noDebug(LOG)
#define uniDebug(...) NO_DEBUG(__VA_ARGS__)
#define uniInfo(...) NO_DEBUG(__VA_ARGS__)
#define uniWarning(...) NO_DEBUG(__VA_ARGS__)
#define uniCritical(...) NO_DEBUG(__VA_ARGS__)
#endif

#endif // UNILOG_H
5 changes: 3 additions & 2 deletions src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void CodeGeeXManager::recevieLoginState(AskApi::LoginState loginState)
} else if (loginState == AskApi::LoginState::kLoginSuccess) {
Q_EMIT loginSuccessed();
// switch to ask page.
queryTimer->stop();
queryTimer->deleteLater();
}
}

Expand All @@ -151,6 +153,7 @@ CodeGeeXManager::CodeGeeXManager(QObject *parent)
{
initConnections();
loadConfig();
queryLoginState();
}

void CodeGeeXManager::initConnections()
Expand All @@ -164,8 +167,6 @@ void CodeGeeXManager::queryLoginState()
{
if (!queryTimer) {
queryTimer = new QTimer(this);
queryTimer->setSingleShot(true);

connect(queryTimer, &QTimer::timeout, this, [ = ] {
if (!sessionId.isEmpty())
askApi.sendQueryRequest(sessionId);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/codegeex/copilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include <QDebug>
#include <QTimer>

static const char *kUrlGenerateOneLine = "https://tianqi.aminer.cn/api/v2/multilingual_code_generate";
//static const char *kUrlGenerateOneLine = "https://tianqi.aminer.cn/api/v2/multilingual_code_generate";
static const char *kUrlGenerateMultiLine = "https://tianqi.aminer.cn/api/v2/multilingual_code_generate_adapt";
static const char *kUrlComment = "https://tianqi.aminer.cn/api/v2/multilingual_code_explain";
static const char *kUrlTranslate = "https://tianqi.aminer.cn/api/v2/multilingual_code_translate";
static const char *kUrlBugfix = "https://tianqi.aminer.cn/api/v2/multilingual_code_bugfix";
//static const char *kUrlBugfix = "https://tianqi.aminer.cn/api/v2/multilingual_code_bugfix";

using namespace CodeGeeX;
using namespace dpfservice;
Expand Down
53 changes: 42 additions & 11 deletions src/plugins/codegeex/widgets/codegeexwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ CodeGeeXWidget::CodeGeeXWidget(QWidget *parent)
{
initUI();
initConnection();
CodeGeeXManager::instance()->queryLoginState();
}

void CodeGeeXWidget::onLoginSuccessed()
{
if (loginBtn) {
auto mainLayout = qobject_cast<QVBoxLayout*>(layout());
mainLayout->removeWidget(loginBtn);
delete loginBtn;
loginBtn = nullptr;
auto mainLayout = qobject_cast<QVBoxLayout*>(layout());
if (mainLayout) {
QLayoutItem* item = nullptr;
while ((item = mainLayout->takeAt(0)) != nullptr) {
delete item->widget();
delete item;
}
}

initAskWidget();
Expand Down Expand Up @@ -63,16 +64,46 @@ void CodeGeeXWidget::onCreateNewBtnClicked()
void CodeGeeXWidget::initUI()
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);

loginBtn = new QPushButton(this);
loginBtn->setText(tr("Login"));
auto initLoginUI = [this](){
auto verticalLayout = new QVBoxLayout(this);
verticalLayout->setAlignment(Qt::AlignCenter);
auto verticalSpacer_top = new QSpacerItem(20, 200, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_top);

auto label_icon = new QLabel();
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
label_icon->setSizePolicy(sizePolicy);
label_icon->setPixmap(QPixmap(":/resoures/images/logo-codegeex.png").scaledToWidth(80));
label_icon->setAlignment(Qt::AlignCenter);

verticalLayout->addWidget(label_icon, Qt::AlignCenter);

auto label_text = new QLabel();
label_text->setSizePolicy(sizePolicy);
label_text->setText(tr("Welcome to CodeGeeX\nA must-have all-round AI tool for developers"));
label_text->setAlignment(Qt::AlignCenter);

verticalLayout->addWidget(label_text, Qt::AlignCenter);

auto loginBtn = new QPushButton();
loginBtn->setSizePolicy(sizePolicy);
loginBtn->setText(tr("Go to login"));
connect(loginBtn, &QPushButton::clicked, this, [ = ]{
qInfo() << "on login clicked";
CodeGeeXManager::instance()->login();
});

verticalLayout->addWidget(loginBtn);

auto verticalSpacer_bottom = new QSpacerItem(20, 500, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_bottom);
};
initLoginUI();
}

void CodeGeeXWidget::initConnection()
{
connect(loginBtn, &QPushButton::clicked, CodeGeeXManager::instance(), &CodeGeeXManager::login);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::loginSuccessed, this, &CodeGeeXWidget::onLoginSuccessed);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::createdNewSession, this, &CodeGeeXWidget::onNewSessionCreated);
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/codegeex/widgets/codegeexwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public Q_SLOTS:

void resetHeaderBtns();

QPushButton *loginBtn { nullptr };
QTabBar *tabBar { nullptr };
QStackedWidget *stackWidget { nullptr };
QPushButton *deleteBtn { nullptr };
Expand Down
1 change: 0 additions & 1 deletion src/plugins/cxx/cxxplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ bool CxxPlugin::start()

dpf::Plugin::ShutdownFlag CxxPlugin::stop()
{
qInfo() << __FUNCTION__;
return Sync;
}

Expand Down

0 comments on commit 37b4171

Please sign in to comment.