From 64894547b14a9b46ab52323604844dbe83a64d44 Mon Sep 17 00:00:00 2001 From: liuyangming Date: Wed, 15 Nov 2023 15:39:37 +0800 Subject: [PATCH] feat: add create session proccess as title --- assets/translations/en_US.ts | 45 +++++++++---------- assets/translations/zh_CN.ts | 45 +++++++++---------- src/plugins/codegeex/codegeex.qrc | 2 +- src/plugins/codegeex/codegeexmanager.cpp | 29 ++++++++++++ src/plugins/codegeex/codegeexmanager.h | 10 ++++- .../codegeex/widgets/codeeditcomponent.cpp | 7 +++ .../codegeex/widgets/codegeexwidget.cpp | 43 +++++++++++------- src/plugins/codegeex/widgets/codegeexwidget.h | 3 +- src/plugins/codegeex/widgets/intropage.cpp | 2 +- .../codegeex/widgets/messagecomponent.cpp | 4 +- 10 files changed, 121 insertions(+), 69 deletions(-) diff --git a/assets/translations/en_US.ts b/assets/translations/en_US.ts index 4e61ca804..f8a8c33ad 100644 --- a/assets/translations/en_US.ts +++ b/assets/translations/en_US.ts @@ -547,12 +547,12 @@ CodeEditComponent - + Copy - + Insert @@ -591,35 +591,40 @@ CodeGeeXWidget - + Login - + Delete - + History - + New - + Ask CodeGeeX - + Translation + + + Creating a new session... + + CodeLens @@ -936,12 +941,6 @@ The dap port is not ready, please retry. Choose path - - - - Detail - - DetailsButton @@ -1376,38 +1375,38 @@ repos path: %0 MainDialog - + New File or Project - + Choose a template: - + Templates - + Create - + Cancel - - + + Tip - + Can not find kit. @@ -3593,7 +3592,7 @@ Delete anyway? WindowKeeper - + Deepin Union Code diff --git a/assets/translations/zh_CN.ts b/assets/translations/zh_CN.ts index f885a7033..dfc37aafd 100644 --- a/assets/translations/zh_CN.ts +++ b/assets/translations/zh_CN.ts @@ -559,12 +559,12 @@ CodeEditComponent - + Copy 复制 - + Insert 插入 @@ -603,35 +603,40 @@ CodeGeeXWidget - + Login 登录 - + Delete 删除 - + History 历史记录 - + New 新对话 - + Ask CodeGeeX 询问 CodeGeeX - + Translation 翻译代码 + + + Creating a new session... + 创建新的会话中... + CodeLens @@ -960,12 +965,6 @@ dap端口未就绪,请重试。 Choose path 选择路径 - - - - Detail - 细节 - DetailsButton @@ -1401,38 +1400,38 @@ repos path: %0 MainDialog - + New File or Project 新建文件或工程 - + Choose a template: 选择一个模板: - + Templates 模板 - + Create 创建 - + Cancel 取消 - - + + Tip 提示 - + Can not find kit. 找不到配套工具。 @@ -3635,7 +3634,7 @@ Delete anyway? WindowKeeper - + Deepin Union Code diff --git a/src/plugins/codegeex/codegeex.qrc b/src/plugins/codegeex/codegeex.qrc index 2b9363ce4..300a3fb19 100644 --- a/src/plugins/codegeex/codegeex.qrc +++ b/src/plugins/codegeex/codegeex.qrc @@ -1,5 +1,5 @@ - + images/navigation.png images/logo-codegeex.png images/photo.svg diff --git a/src/plugins/codegeex/codegeexmanager.cpp b/src/plugins/codegeex/codegeexmanager.cpp index 4df4a56ff..1efdc5372 100644 --- a/src/plugins/codegeex/codegeexmanager.cpp +++ b/src/plugins/codegeex/codegeexmanager.cpp @@ -16,6 +16,7 @@ static const char *kUrlSSEChat = "https://codegeex.cn/prod/code/chatGlmSse/chat"; static const char *kUrlNewSession = "https://codegeex.cn/prod/code/chatGlmTalk/insert"; +static const char *kUrlDeleteSession = "https://codegeex.cn/prod/code/chatGlmTalk/delete"; using namespace CodeGeeX; @@ -71,6 +72,23 @@ void CodeGeeXManager::loadConfig() } } +void CodeGeeXManager::createNewSession() +{ + QString currentMSecsStr = QString::number(QDateTime::currentMSecsSinceEpoch()); + QString sessionTitle("Session_" + currentMSecsStr); + QString taskId(uuid()); + askApi.postNewSession(kUrlNewSession, sessionId, sessionTitle, taskId); +} + +void CodeGeeXManager::deleteCurrentSession() +{ + if (currentTalkID.isEmpty()) + return; + + askApi.deleteSessions(kUrlDeleteSession, sessionId, { currentTalkID }); + createNewSession(); +} + void CodeGeeXManager::sendMessage(const QString &prompt) { QString askId = "User" + QString::number(QDateTime::currentMSecsSinceEpoch()); @@ -86,6 +104,16 @@ void CodeGeeXManager::sendMessage(const QString &prompt) askApi.postSSEChat(kUrlSSEChat, sessionId, prompt, machineId, history); } +void CodeGeeXManager::onSessionCreated(const QString &talkId, bool isSuccessful) +{ + if (isSuccessful) { + currentTalkID = talkId; + Q_EMIT createdNewSession(); + } else { + qWarning() << "Create session failed!"; + } +} + void CodeGeeXManager::onResponse(const QString &msgID, const QString &data, const QString &event) { if (msgID.isEmpty()) @@ -129,6 +157,7 @@ void CodeGeeXManager::initConnections() { connect(&askApi, &AskApi::response, this, &CodeGeeXManager::onResponse); connect(&askApi, &AskApi::loginState, this, &CodeGeeXManager::recevieLoginState); + connect(&askApi, &AskApi::sessionCreated, this, &CodeGeeXManager::onSessionCreated); } void CodeGeeXManager::queryLoginState() diff --git a/src/plugins/codegeex/codegeexmanager.h b/src/plugins/codegeex/codegeexmanager.h index 7fd652e27..cf2777d97 100644 --- a/src/plugins/codegeex/codegeexmanager.h +++ b/src/plugins/codegeex/codegeexmanager.h @@ -26,6 +26,9 @@ class CodeGeeXManager : public QObject void saveConfig(const QString &sessionId, const QString &userId); void loadConfig(); + void createNewSession(); + void deleteCurrentSession(); + void sendMessage(const QString &prompt); void queryLoginState(); @@ -33,9 +36,11 @@ class CodeGeeXManager : public QObject Q_SIGNALS: void loginSuccessed(); + void createdNewSession(); void requestMessageUpdate(const MessageData &msg); public Q_SLOTS: + void onSessionCreated(const QString &talkId, bool isSuccessful); void onResponse(const QString &msgID, const QString &data, const QString &event); void recevieLoginState(CodeGeeX::AskApi::LoginState loginState); @@ -48,8 +53,9 @@ public Q_SLOTS: QString uuid(); CodeGeeX::AskApi askApi; - QString sessionId; - QString userId; + QString sessionId {}; + QString userId {}; + QString currentTalkID {}; QMap curSessionMsg {}; diff --git a/src/plugins/codegeex/widgets/codeeditcomponent.cpp b/src/plugins/codegeex/widgets/codeeditcomponent.cpp index d31e24dc7..9f0add009 100644 --- a/src/plugins/codegeex/widgets/codeeditcomponent.cpp +++ b/src/plugins/codegeex/widgets/codeeditcomponent.cpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include CodeEditComponent::CodeEditComponent(QWidget *parent) : QWidget (parent) @@ -116,6 +119,10 @@ void CodeEditComponent::onCopyBtnClicked() if (codeEdit->toPlainText().isEmpty()) return; + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setMimeData(new QMimeData); + clipboard->setText(codeEdit->toPlainText()); } void CodeEditComponent::initUI() diff --git a/src/plugins/codegeex/widgets/codegeexwidget.cpp b/src/plugins/codegeex/widgets/codegeexwidget.cpp index 00d42ea66..37f5e7d50 100644 --- a/src/plugins/codegeex/widgets/codegeexwidget.cpp +++ b/src/plugins/codegeex/widgets/codegeexwidget.cpp @@ -12,12 +12,13 @@ #include #include #include +#include CodeGeeXWidget::CodeGeeXWidget(QWidget *parent) : QWidget(parent) { initUI(); - initLoginConnection(); + initConnection(); CodeGeeXManager::instance()->queryLoginState(); } @@ -31,13 +32,20 @@ void CodeGeeXWidget::onLoginSuccessed() } initAskWidget(); + CodeGeeXManager::instance()->createNewSession(); } -void CodeGeeXWidget::onDeleteBtnClicked() +void CodeGeeXWidget::onNewSessionCreated() { + stackWidget->setCurrentIndex(1); + if (askPage) askPage->setIntroPage(); +} +void CodeGeeXWidget::onDeleteBtnClicked() +{ + CodeGeeXManager::instance()->deleteCurrentSession(); CodeGeeXManager::instance()->cleanHistoryMessage(); } @@ -48,10 +56,8 @@ void CodeGeeXWidget::onHistoryBtnClicked() void CodeGeeXWidget::onCreateNewBtnClicked() { - if (askPage) - askPage->setIntroPage(); - CodeGeeXManager::instance()->cleanHistoryMessage(); + CodeGeeXManager::instance()->createNewSession(); } void CodeGeeXWidget::initUI() @@ -62,16 +68,13 @@ void CodeGeeXWidget::initUI() loginBtn = new QPushButton(this); loginBtn->setText(tr("Login")); - - connect(loginBtn, &QPushButton::clicked, this, [ = ]{ - qInfo() << "on login clicked"; - CodeGeeXManager::instance()->login(); - }); } -void CodeGeeXWidget::initLoginConnection() +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); } void CodeGeeXWidget::initAskWidget() @@ -132,11 +135,19 @@ void CodeGeeXWidget::initStackWidget() resetHeaderBtns(); }); - stackWidget->insertWidget(0, askPage); - stackWidget->insertWidget(1, transPage); - stackWidget->setCurrentIndex(0); + QWidget *creatingSessionWidget = new QWidget(this); + QHBoxLayout *layout = new QHBoxLayout; + creatingSessionWidget->setLayout(layout); + + QLabel *creatingLabel = new QLabel(creatingSessionWidget); + creatingLabel->setAlignment(Qt::AlignCenter); + creatingLabel->setText(tr("Creating a new session...")); + layout->addWidget(creatingLabel); - askPage->setIntroPage(); + stackWidget->insertWidget(0, creatingSessionWidget); + stackWidget->insertWidget(1, askPage); + stackWidget->insertWidget(2, transPage); + stackWidget->setCurrentIndex(0); } void CodeGeeXWidget::initAskWidgetConnection() @@ -149,7 +160,7 @@ void CodeGeeXWidget::initAskWidgetConnection() currentState = TrasnlatePage; resetHeaderBtns(); } - stackWidget->setCurrentIndex(index); + stackWidget->setCurrentIndex(index + 1); }); connect(deleteBtn, &QPushButton::clicked, this, &CodeGeeXWidget::onDeleteBtnClicked); connect(historyBtn, &QPushButton::clicked, this, &CodeGeeXWidget::onHistoryBtnClicked); diff --git a/src/plugins/codegeex/widgets/codegeexwidget.h b/src/plugins/codegeex/widgets/codegeexwidget.h index f4aee73f7..b3d1d46d9 100644 --- a/src/plugins/codegeex/widgets/codegeexwidget.h +++ b/src/plugins/codegeex/widgets/codegeexwidget.h @@ -29,13 +29,14 @@ class CodeGeeXWidget : public QWidget public Q_SLOTS: void onLoginSuccessed(); + void onNewSessionCreated(); void onDeleteBtnClicked(); void onHistoryBtnClicked(); void onCreateNewBtnClicked(); private: void initUI(); - void initLoginConnection(); + void initConnection(); void initAskWidget(); void initTabBar(); diff --git a/src/plugins/codegeex/widgets/intropage.cpp b/src/plugins/codegeex/widgets/intropage.cpp index f16ab59ae..d51caa59b 100644 --- a/src/plugins/codegeex/widgets/intropage.cpp +++ b/src/plugins/codegeex/widgets/intropage.cpp @@ -41,7 +41,7 @@ void IntroPage::initLogo() QLabel *logo = new QLabel(this); logo->setAlignment(Qt::AlignHCenter); - logo->setPixmap(QPixmap(":/demo/images/logo-codegeex.png").scaledToWidth(80)); + logo->setPixmap(QPixmap(":/resoures/images/logo-codegeex.png").scaledToWidth(80)); logoLayout->addWidget(logo); QLabel *logoLabel = new QLabel(this); diff --git a/src/plugins/codegeex/widgets/messagecomponent.cpp b/src/plugins/codegeex/widgets/messagecomponent.cpp index 22e7b9d11..9f17c1ee2 100644 --- a/src/plugins/codegeex/widgets/messagecomponent.cpp +++ b/src/plugins/codegeex/widgets/messagecomponent.cpp @@ -101,13 +101,13 @@ void MessageComponent::initSenderInfo() switch (messageData.messageType()) { case MessageData::Ask: { senderName->setText("You"); - QPixmap head(":/demo/images/photo.svg"); + QPixmap head(":/resoures/images/photo.svg"); senderHead->setPixmap(head.scaledToWidth(30)); break; } case MessageData::Anwser: senderName->setText("CodeGeeX"); - QPixmap log(":/demo/images/logo-codegeex.png"); + QPixmap log(":/resoures/images/logo-codegeex.png"); senderHead->setPixmap(log.scaledToWidth(30)); break; }