ukui-screensaver/0001-fix-the-problem-that-the-app-version-not-set.patch
侯红勋 98aa26b101 Fix the problem that application version is not set
Signed-off-by: 侯红勋 <houhongxun@kylinos.cn>
2024-05-28 14:59:24 +08:00

106 lines
3.0 KiB
Diff

From cca34e2f88f6a2c2af752a39f665ce9fdc776464 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BE=AF=E7=BA=A2=E5=8B=8B?= <houhongxun@kylinos.cn>
Date: Tue, 28 May 2024 14:47:33 +0800
Subject: [PATCH] fix the problem that the app version not set
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 侯红勋 <houhongxun@kylinos.cn>
---
src/ukui-screensaver-command.cpp | 22 ++++++++++++++++++++++
src/ukui-screensaver-dialog.cpp | 21 +++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/src/ukui-screensaver-command.cpp b/src/ukui-screensaver-command.cpp
index 1ce2d54..97f1eb7 100644
--- a/src/ukui-screensaver-command.cpp
+++ b/src/ukui-screensaver-command.cpp
@@ -22,15 +22,37 @@
#include <QTranslator>
#include <QCommandLineParser>
#include <QDebug>
+#include <QProcess>
+#include <QRegularExpression>
#include "types.h"
#include <ukui-log4qt.h>
#define WORKING_DIRECTORY "/usr/share/ukui-screensaver"
+static QString getVersion()
+{
+ QProcess v_p;
+ v_p.start("rpm", QStringList() << "-q" << "ukui-screensaver");
+
+ if (!v_p.waitForFinished())
+ return "none";
+
+ QByteArray ba = v_p.readAllStandardOutput();
+
+ QRegularExpression qe("-([^-]+)-[^-]+\n$");
+
+ QRegularExpressionMatch qem = qe.match(ba);
+ if (qem.hasMatch()) {
+ return qem.captured(1);
+ }
+ return "none";
+}
+
int main(int argc, char **argv)
{
initUkuiLog4qt("ukui-screensaver-command");
QCoreApplication a(argc, argv);
+ a.setApplicationVersion(getVersion());
QString locale = QLocale::system().name();
QTranslator translator;
diff --git a/src/ukui-screensaver-dialog.cpp b/src/ukui-screensaver-dialog.cpp
index e05cd00..3ea7bad 100644
--- a/src/ukui-screensaver-dialog.cpp
+++ b/src/ukui-screensaver-dialog.cpp
@@ -28,6 +28,7 @@
#include <QDebug>
#include <QDesktopWidget>
#include <QDBusInterface>
+#include <QRegularExpression>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
@@ -125,6 +126,25 @@ void handler(int signum)
window->closeScreensaver();
}
+static QString getVersion()
+{
+ QProcess v_p;
+ v_p.start("rpm", QStringList() << "-q" << "ukui-screensaver");
+
+ if (!v_p.waitForFinished())
+ return "none";
+
+ QByteArray ba = v_p.readAllStandardOutput();
+
+ QRegularExpression qe("-([^-]+)-[^-]+\n$");
+
+ QRegularExpressionMatch qem = qe.match(ba);
+ if (qem.hasMatch()) {
+ return qem.captured(1);
+ }
+ return "none";
+}
+
#define WORKING_DIRECTORY "/usr/share/ukui-screensaver"
int main(int argc, char *argv[])
{
@@ -169,6 +189,7 @@ int main(int argc, char *argv[])
//signal(SIGTERM,handler);
QApplication a(argc, argv);
QApplication::setSetuidAllowed(true);
+ a.setApplicationVersion(getVersion());
QDesktopWidget *desktop = QApplication::desktop();
if(desktop->geometry().width()<=0 || desktop->geometry().height()<=0)
--
2.33.0