Skip to content
Merged
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
61 changes: 34 additions & 27 deletions src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "commondefine.h"
#include "utils.h"

#include <QDBusPendingReply>

Check warning on line 10 in src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusPendingReply> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonParseError>

Check warning on line 11 in src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonParseError> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonObject>

Check warning on line 12 in src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DDBusSender>

Check warning on line 13 in src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDBusSender> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>

DGUI_USE_NAMESPACE
Expand Down Expand Up @@ -253,38 +254,44 @@
{
QString runDir = utils::GetUserRuntimeDir();

QFile file("/proc/self/sessionid");
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "open /proc/self/sessionid fail";
return false;
}

QString currentSessionId = file.readAll();
currentSessionId = currentSessionId.simplified();
QDBusPendingReply<QString> currentSessionPath = DDBusSender()
.service("org.deepin.dde.SessionManager1")
.path("/org/deepin/dde/Session1")
.interface("org.deepin.dde.Session1")
.method("GetSessionPath")
.call();

bool needChangeBg = false;
runDir = runDir + "/dde-daemon-wallpaper-slideshow-login" + "/" + monitorSpace;
QFile fileTemp(runDir);

if (!file.exists()) {
needChangeBg = true;
} else if (!fileTemp.open(QIODevice::ReadOnly)) {
qWarning() << "open " << runDir << " fail";
return false;
QFileInfo fileInfo(runDir);
QDir().mkpath(fileInfo.absolutePath());

if (!fileInfo.exists()) {
// 文件不存在,创建并写入当前会话路径
QFile fileTemp(runDir);
if (fileTemp.open(QIODevice::WriteOnly | QIODevice::Text)) {
fileTemp.write(currentSessionPath.value().toLatin1());
fileTemp.close();
autoChangeBg(monitorSpace, QDateTime::currentDateTimeUtc());
} else {
qWarning() << "failed to create file: " << runDir;
return false;
}
} else {
if (currentSessionId != fileTemp.readAll().simplified()) {
needChangeBg = true;
// 文件存在,读取并比较
QFile fileTemp(runDir);
if (fileTemp.open(QIODevice::ReadWrite | QIODevice::Text)) {
const QString &recordSessionPath = fileTemp.readAll().simplified();
if (recordSessionPath != currentSessionPath) {
autoChangeBg(monitorSpace, QDateTime::currentDateTimeUtc());
fileTemp.resize(0);
fileTemp.write(currentSessionPath.value().toLatin1());
}
fileTemp.close();
} else {
qWarning() << "failed to open file: " << runDir;
return false;
}
}

if (needChangeBg) {
autoChangeBg(monitorSpace, QDateTime::currentDateTimeUtc());
fileTemp.write(currentSessionId.toLatin1());
}

file.close();
fileTemp.close();

return true;
}

Expand Down
Loading