Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [recent] Refactor recent display widget and session management #1005

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/util/eventdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ OPI_OBJECT(workspace,
)
OPI_OBJECT(session,
OPI_INTERFACE(readyToSaveSession)
OPI_INTERFACE(sessionStatusChanged)
OPI_INTERFACE(sessionLoaded, "session")
OPI_INTERFACE(sessionCreated, "session")
OPI_INTERFACE(sessionRenamed, "oldName", "newName")
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void CodeGeeXManager::saveConfig(const QString &sessionId, const QString &userId
OptionManager::getInstance()->setValue("CodeGeeX", "Id", map);
}

Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除") void CodeGeeXManager::loadConfig()
Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除")
void CodeGeeXManager::loadConfig()
{
QFile file(configFilePath());
if (!file.exists()) {
Expand Down Expand Up @@ -177,7 +178,7 @@ void CodeGeeXManager::independentAsking(const QString &prompt, const QMultiMap<Q
}
AskApi *api = new AskApi;
api->postSSEChat(kUrlSSEChat, sessionId, prompt, QSysInfo::machineUniqueId(), history, currentTalkID);
QTimer::singleShot(10000, api, [=](){
QTimer::singleShot(10000, api, [=]() {
if (pipe && pipe->isOpen()) {
qWarning() << "timed out, close pipe";
pipe->close();
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/core/modules/sessionmanagermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void SessionManagerModule::initInterfaces()
sessionSrv->isDefaultSession = std::bind(&SessionManager::isDefaultSession, ins, _1);
sessionSrv->isSessionLoading = std::bind(&SessionManager::isSessionLoading, ins);
sessionSrv->isDefaultVirgin = std::bind(&SessionManager::isDefaultVirgin, ins);
sessionSrv->markSessionFileDirty = std::bind(&SessionManager::markSessionFileDirty, ins);
sessionSrv->sessionFile = std::bind(&SessionManager::sessionFile, ins, _1);
}

Expand All @@ -74,4 +75,8 @@ void SessionManagerModule::initOutputEvents()
[](const QString &name) {
session.sessionRemoved(name);
});
connect(ins, &SessionManager::sessionStatusChanged, this,
[] {
session.sessionStatusChanged();
});
}
2 changes: 2 additions & 0 deletions src/plugins/core/session/sessiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <QPushButton>
#include <QVBoxLayout>
#include <QEvent>
#include <QPainterPath>

DWIDGET_USE_NAMESPACE

Expand Down
17 changes: 14 additions & 3 deletions src/plugins/core/session/sessionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <QDir>
#include <QDateTime>
#include <QApplication>

constexpr char kDefaultSession[] { "default" };
constexpr char kSessionGroup[] { "Session" };
Expand Down Expand Up @@ -105,8 +106,9 @@ SessionManager::SessionManager(QObject *parent)
{
d->readSettings();
connect(qApp, &QApplication::aboutToQuit, this, [this] {
if (!isSessionLoading() && !isDefaultVirgin())
saveSession();
d->saveSettings();
saveSession();
});
}

Expand Down Expand Up @@ -279,7 +281,7 @@ bool SessionManager::loadSession(const QString &session)
return true;
}

bool SessionManager::saveSession()
void SessionManager::saveSession()
{
Q_EMIT readyToSaveSession();

Expand All @@ -290,7 +292,7 @@ bool SessionManager::saveSession()
settings.setValue(kSessionGroup, iter.key(), iter.value());
}

return true;
d->sessionDateTimes.insert(d->currentSession, QDateTime::currentDateTime());
}

bool SessionManager::isDefaultSession(const QString &session)
Expand All @@ -313,6 +315,15 @@ bool SessionManager::isAutoLoadLastSession()
return d->isAutoLoad;
}

void SessionManager::markSessionFileDirty()
{
if (!d->virginSession)
return;

d->virginSession = false;
Q_EMIT sessionStatusChanged();
}

QString SessionManager::sessionFile(const QString &session)
{
QString format = "%1/%2.session";
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/core/session/sessionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ class SessionManager : public QObject
QVariant value(const QString &key);

bool loadSession(const QString &session);
bool saveSession();
void saveSession();
bool isDefaultSession(const QString &session);
bool isSessionLoading();
bool isDefaultVirgin();
bool isAutoLoadLastSession();

void markSessionFileDirty();
QString sessionFile(const QString &session);

Q_SIGNALS:
void readyToSaveSession();
void sessionLoaded(const QString &session);
void sessionStatusChanged();

void sessionCreated(const QString &session);
void sessionRenamed(const QString &oldName, const QString &newName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
+ QDir::separator() + QString("translate.support");
}

Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除") QString ProfileSettingWidget::languageFilePath()
Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除")

Check warning on line 53 in src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_DECL_DEPRECATED_X is a macro then please configure it.

Check warning on line 53 in src/plugins/option/optioncore/mainframe/profilesettingwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

There is an unknown macro here somewhere. Configuration is required. If Q_DECL_DEPRECATED_X is a macro then please configure it.
QString ProfileSettingWidget::languageFilePath()
{
return CustomPaths::user(CustomPaths::Flags::Configures)
+ QDir::separator() + QString("chooselanguage.support");
Expand Down Expand Up @@ -83,7 +84,7 @@
{
QString languageName;
QFile file(languageFilePath());
if (file.exists()) {
if (file.exists()) {
QTextStream txtInput(&file);
if (file.open(QIODevice::ReadOnly)) {
languageName = d->languagePaths.key(txtInput.readLine());
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/project/transceiver/projectcorereceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void ProjectCoreReceiver::processActiveProjectEvent(const dpf::Event &event)

void ProjectCoreReceiver::processOpenProjectEvent(const dpf::Event &event)
{
auto sessionSrv = dpfGetService(SessionService);
sessionSrv->markSessionFileDirty();
uiController.doSwitch(dpfservice::MWNA_EDIT);
auto &ctx = dpfInstance.serviceContext();
ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name());
Expand Down
1 change: 0 additions & 1 deletion src/plugins/recent/mainframe/itemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "itemdelegate.h"
#include "itemlistview.h"

#include <DApplication>
#include <DGuiApplicationHelper>
Expand Down
67 changes: 0 additions & 67 deletions src/plugins/recent/mainframe/itemlistview.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions src/plugins/recent/mainframe/itemlistview.h

This file was deleted.

Loading
Loading