use QRandomGenerator to generate random numbers
Signed-off-by: 侯红勋 <houhongxun@kylinos.cn>
This commit is contained in:
parent
4c5fc4034b
commit
2c5e73798b
139
0001-use-QRandomGenerator-to-generate-random-numbers.patch
Normal file
139
0001-use-QRandomGenerator-to-generate-random-numbers.patch
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
From bc6119282e36cd9392db81f85d227bb7367a57bd Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?=E4=BE=AF=E7=BA=A2=E5=8B=8B?= <houhongxun@kylinos.cn>
|
||||||
|
Date: Fri, 26 Apr 2024 10:44:42 +0800
|
||||||
|
Subject: [PATCH] use QRandomGenerator to generate random numbers
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
|
Signed-off-by: 侯红勋 <houhongxun@kylinos.cn>
|
||||||
|
---
|
||||||
|
screensaver/mbackground.cpp | 5 +++--
|
||||||
|
screensaver/screensaver.cpp | 12 ++++++------
|
||||||
|
screensaver/screensaver.h | 2 ++
|
||||||
|
src/configuration.cpp | 7 ++++---
|
||||||
|
4 files changed, 15 insertions(+), 11 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/screensaver/mbackground.cpp b/screensaver/mbackground.cpp
|
||||||
|
index a1e6553..00efebe 100644
|
||||||
|
--- a/screensaver/mbackground.cpp
|
||||||
|
+++ b/screensaver/mbackground.cpp
|
||||||
|
@@ -23,6 +23,7 @@
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <QStringList>
|
||||||
|
+#include <QRandomGenerator>
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include "mbackground.h"
|
||||||
|
@@ -82,8 +83,8 @@ QString MBackground::getRand()
|
||||||
|
{
|
||||||
|
if(list.count() <= 0)
|
||||||
|
return "";
|
||||||
|
- qsrand(time(NULL));
|
||||||
|
- currentIndex = qrand() % list.count();
|
||||||
|
+ QRandomGenerator rand1(time(NULL));
|
||||||
|
+ currentIndex = rand1.generate() % list.count();
|
||||||
|
|
||||||
|
return list.at(currentIndex);
|
||||||
|
}
|
||||||
|
diff --git a/screensaver/screensaver.cpp b/screensaver/screensaver.cpp
|
||||||
|
index c6ec6d4..f38b841 100644
|
||||||
|
--- a/screensaver/screensaver.cpp
|
||||||
|
+++ b/screensaver/screensaver.cpp
|
||||||
|
@@ -92,13 +92,13 @@ Screensaver::Screensaver(QWidget *parent):
|
||||||
|
process(nullptr),
|
||||||
|
screenLabel(nullptr),
|
||||||
|
respondClick(false),
|
||||||
|
- m_weatherManager(new WeatherManager(this))
|
||||||
|
+ m_weatherManager(new WeatherManager(this)),
|
||||||
|
+ m_rand(QTime(0,0,0).secsTo(QTime::currentTime()))
|
||||||
|
{
|
||||||
|
installEventFilter(this);
|
||||||
|
// setWindowFlags(Qt::X11BypassWindowManagerHint);
|
||||||
|
setUpdateCenterWidget();
|
||||||
|
setMouseTracking(true);
|
||||||
|
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
||||||
|
|
||||||
|
isCustom = configuration->getIsCustom();
|
||||||
|
if(isCustom){
|
||||||
|
@@ -548,9 +548,9 @@ void Screensaver::setRandomPos()
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
if(x2 > x1)
|
||||||
|
- x = qrand()%(x2 - x1) + x1;
|
||||||
|
+ x = m_rand.generate()%(x2 - x1) + x1;
|
||||||
|
if(y2 > y1)
|
||||||
|
- y = qrand()%(y2 - y1) + y1;
|
||||||
|
+ y = m_rand.generate()%(y2 - y1) + y1;
|
||||||
|
|
||||||
|
myTextWidget->move(x,y);
|
||||||
|
|
||||||
|
@@ -650,7 +650,7 @@ void Screensaver::startSwitchImages()
|
||||||
|
switchTimer = new QTimer(this);
|
||||||
|
connect(switchTimer, &QTimer::timeout, this, [&]{
|
||||||
|
if(isAutoSwitch){
|
||||||
|
- int index = qrand() % imagePaths.count();
|
||||||
|
+ int index = m_rand.generate() % imagePaths.count();
|
||||||
|
background = QPixmap(imagePaths.at(index));
|
||||||
|
}else{
|
||||||
|
if(currentIndex>=imagePaths.count() - 1 || currentIndex<0){
|
||||||
|
@@ -700,7 +700,7 @@ void Screensaver::updateCenterWidget(int index)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(index<=1){
|
||||||
|
- index = qrand() % qlist.count() + 1;
|
||||||
|
+ index = m_rand.generate() % qlist.count() + 1;
|
||||||
|
}
|
||||||
|
qsettings->beginGroup(QString::number(index));
|
||||||
|
if(qsettings->contains("OL")){
|
||||||
|
diff --git a/screensaver/screensaver.h b/screensaver/screensaver.h
|
||||||
|
index 07cc994..ce5036c 100644
|
||||||
|
--- a/screensaver/screensaver.h
|
||||||
|
+++ b/screensaver/screensaver.h
|
||||||
|
@@ -30,6 +30,7 @@
|
||||||
|
#include <QSplitterHandle>
|
||||||
|
#include <QSplitter>
|
||||||
|
#include <QTime>
|
||||||
|
+#include <QRandomGenerator>
|
||||||
|
|
||||||
|
#include "sleeptime.h"
|
||||||
|
#include "chinesedate.h"
|
||||||
|
@@ -143,6 +144,7 @@ private:
|
||||||
|
QLabel *m_labelNoticeIcon;
|
||||||
|
QLabel *m_labelNoticeMessage;
|
||||||
|
int currentIndex = 0;
|
||||||
|
+ QRandomGenerator m_rand;
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
diff --git a/src/configuration.cpp b/src/configuration.cpp
|
||||||
|
index ac964a0..dcc6e6a 100644
|
||||||
|
--- a/src/configuration.cpp
|
||||||
|
+++ b/src/configuration.cpp
|
||||||
|
@@ -25,6 +25,7 @@
|
||||||
|
#include <QGSettings>
|
||||||
|
#include <QMimeType>
|
||||||
|
#include <ctime>
|
||||||
|
+#include <QRandomGenerator>
|
||||||
|
|
||||||
|
#include "commonfunc.h"
|
||||||
|
#define GSETTINGS_SCHEMA_SCREENSAVER "org.ukui.screensaver"
|
||||||
|
@@ -143,11 +144,11 @@ ScreenSaver *Configuration::getScreensaver()
|
||||||
|
saver->path = "/usr/lib/ukui-screensaver/ukui-screensaver-default";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
- qsrand((unsigned)time(0));
|
||||||
|
- int index = qrand() % themes.count();
|
||||||
|
+ QRandomGenerator rand1(time(0));
|
||||||
|
+ int index = rand1.generate() % themes.count();
|
||||||
|
while(QString::compare(themes[index], "kyccss-personal-slideshow")==0)
|
||||||
|
{
|
||||||
|
- index = qrand() % themes.count();
|
||||||
|
+ index = rand1.generate() % themes.count();
|
||||||
|
}
|
||||||
|
saver->path = getXScreensaverPath(themes[index]);
|
||||||
|
break;
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
Name: ukui-screensaver
|
Name: ukui-screensaver
|
||||||
Version: 3.1.1
|
Version: 3.1.1
|
||||||
Release: 6
|
Release: 7
|
||||||
Summary: Screensaver for UKUI desktop environment
|
Summary: Screensaver for UKUI desktop environment
|
||||||
License: GPL-3+ and GPL-2+
|
License: GPL-3+ and GPL-2+
|
||||||
URL: http://www.ukui.org
|
URL: http://www.ukui.org
|
||||||
@ -11,6 +11,7 @@ Patch02: 0002-fix-build-compile-error.patch
|
|||||||
Patch03: disable-Suspend-and-Sleep-of-ukui-screensaver.patch
|
Patch03: disable-Suspend-and-Sleep-of-ukui-screensaver.patch
|
||||||
Patch04: add-switchuser-no-limits-in-ukui-screensaver.patch
|
Patch04: add-switchuser-no-limits-in-ukui-screensaver.patch
|
||||||
%endif
|
%endif
|
||||||
|
Patch05: 0001-use-QRandomGenerator-to-generate-random-numbers.patch
|
||||||
BuildRequires: cmake
|
BuildRequires: cmake
|
||||||
BuildRequires: qt5-qtbase-devel
|
BuildRequires: qt5-qtbase-devel
|
||||||
BuildRequires: qt5-qtx11extras-devel
|
BuildRequires: qt5-qtx11extras-devel
|
||||||
@ -40,14 +41,15 @@ provided by biometric-auth service.
|
|||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q
|
%setup -q
|
||||||
%patch01 -p1
|
%patch 1 -p1
|
||||||
if [ -e "/usr/include/glib-2.0/gio/gunixfdlist.h" ]; then
|
if [ -e "/usr/include/glib-2.0/gio/gunixfdlist.h" ]; then
|
||||||
%patch02 -p1
|
%patch 2 -p1
|
||||||
fi
|
fi
|
||||||
%if 0%{?kylin}
|
%if 0%{?kylin}
|
||||||
%patch03 -p1
|
%patch 3 -p1
|
||||||
%patch04 -p1
|
%patch 4 -p1
|
||||||
%endif
|
%endif
|
||||||
|
%patch 5 -p1
|
||||||
|
|
||||||
%build
|
%build
|
||||||
cmake .
|
cmake .
|
||||||
@ -82,6 +84,9 @@ glib-compile-schemas /usr/share/glib-2.0/schemas/ &> /dev/null ||:
|
|||||||
%{_prefix}/lib/ukui-screensaver/screensaver-focus-helper
|
%{_prefix}/lib/ukui-screensaver/screensaver-focus-helper
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Apr 26 2024 houhongxun <houhongxun@kylinos.cn> - 3.1.1-7
|
||||||
|
- use QRandomGenerator to generate random numbers
|
||||||
|
|
||||||
* Mon Sep 04 2023 peijiankang <peijiankang@kylinos.cn> - 3.1.1-6
|
* Mon Sep 04 2023 peijiankang <peijiankang@kylinos.cn> - 3.1.1-6
|
||||||
- Type:bugfix
|
- Type:bugfix
|
||||||
- ID:NA
|
- ID:NA
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user