OSDN Git Service

generic: replace QUuid with QString and qRandomUuid()
authorIvailo Monev <xakepa10@gmail.com>
Tue, 22 Mar 2022 13:25:38 +0000 (15:25 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 22 Mar 2022 13:25:38 +0000 (15:25 +0200)
implement new FileSystem::createUUID() method to de-duplicated code while
at it

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
okular/core/page.cpp
partitionmanager/src/fs/filesystem.cpp
partitionmanager/src/fs/filesystem.h
partitionmanager/src/fs/luks.cpp
partitionmanager/src/fs/nilfs2.cpp
partitionmanager/src/fs/reiserfs.cpp

index 5104667..f29182c 100644 (file)
@@ -14,7 +14,6 @@
 #include <QtCore/QSet>
 #include <QtCore/QString>
 #include <QtCore/QVariant>
-#include <QtCore/QUuid>
 #include <QtGui/QPixmap>
 
 #include <QtXml/qdom.h>
@@ -65,6 +64,15 @@ static void deleteObjectRects( QList< ObjectRect * >& rects, const QSet<ObjectRe
             ++it;
 }
 
+static inline QString createAnnotationID()
+{
+#if QT_VERSION >= 0x041200
+    return QString::fromLatin1(qRandomUuid());
+#else
+    return QString::number(qrand());
+#endif
+}
+
 PagePrivate::PagePrivate( Page *page, uint n, double w, double h, Rotation o )
     : m_page( page ), m_number( n ), m_orientation( o ),
       m_width( w ), m_height( h ), m_doc( 0 ), m_boundingBox( 0, 0, 1, 1 ),
@@ -631,10 +639,10 @@ QColor Page::textSelectionColor() const
 
 void Page::addAnnotation( Annotation * annotation )
 {
-    // Generate uniqueName: okular-{UUID}
+    // Generate uniqueName: okular-UUID
     if(annotation->uniqueName().isEmpty())
     {
-        QString uniqueName = "okular-" + QUuid::createUuid().toString();
+        QString uniqueName = "okular-" + createAnnotationID();
         annotation->setUniqueName( uniqueName );
     }
     annotation->d_ptr->m_page = d;
index 69ab9ba..57eb804 100644 (file)
 
 #include <config.h>
 
+#if QT_VERSION < 0x041200
+#  include <QUuid>
+#endif
+
 /** Creates a new FileSystem object
        @param firstsector the first sector used by this FileSystem on the Device
        @param lastsector the last sector used by this FileSystem on the Device
@@ -388,6 +392,18 @@ bool FileSystem::findExternal(const QString& cmdName, const QStringList& args, i
        return cmd.exitCode() == 0 || cmd.exitCode() == expectedCode;
 }
 
+/**
+       @return UUID in the form: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+*/
+QString FileSystem::createUUID()
+{
+#if QT_VERSION >= 0x041200
+       return QString::fromLatin1(qRandomUuid());
+#else
+       return QUuid::createUuid().toString().remove(QRegExp("\\{|\\}"));
+#endif
+}
+
 FileSystem::Type FileSystem::defaultFileSystem()
 {
        return static_cast<FileSystem::Type>(Config::defaultFileSystem());
index 5a8de35..a3885a3 100644 (file)
@@ -173,6 +173,7 @@ class FileSystem
 
        protected:
                static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1);
+               static QString createUUID();
 
        protected:
                FileSystem::Type m_Type;
index 26fd105..dc4f5cf 100644 (file)
@@ -26,7 +26,6 @@
 #include "util/externalcommand.h"
 
 #include <QString>
-#include <QUuid>
 
 #include <KLocale>
 
@@ -135,9 +134,7 @@ namespace FS
 
        bool luks::updateUUID(Report& report, const QString& deviceNode) const
        {
-               QUuid uuid = QUuid::createUuid();
-
-               ExternalCommand cmd(report, "cryptsetup", QStringList() << "luksUUID" << deviceNode << "--uuid" << uuid.toString());
+               ExternalCommand cmd(report, "cryptsetup", QStringList() << "luksUUID" << deviceNode << "--uuid" << createUUID());
                return cmd.run(-1) && cmd.exitCode() == 0;
        }
 
index 40b37aa..88713b9 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <cmath>
 #include <QString>
-#include <QUuid>
 
 #include <KLocale>
 #include <KTempDir>
@@ -177,8 +176,7 @@ namespace FS
 
        bool nilfs2::updateUUID(Report& report, const QString& deviceNode) const
        {
-               QUuid uuid = QUuid::createUuid();
-               ExternalCommand cmd(report, "nilfs-tune", QStringList() << "-U" << uuid.toString() << deviceNode);
+               ExternalCommand cmd(report, "nilfs-tune", QStringList() << "-U" << createUUID() << deviceNode);
                return cmd.run(-1) && cmd.exitCode() == 0;
        }
 }
index 4175342..4684999 100644 (file)
@@ -25,7 +25,6 @@
 #include <QString>
 #include <QStringList>
 #include <QRegExp>
-#include <QUuid>
 
 namespace FS
 {
@@ -165,8 +164,7 @@ namespace FS
 
        bool reiserfs::updateUUID(Report& report, const QString& deviceNode) const
        {
-               const QString uuid = QUuid::createUuid().toString().remove(QRegExp("\\{|\\}"));
-               ExternalCommand cmd(report, "reiserfstune", QStringList() << "-u" << uuid << deviceNode);
+               ExternalCommand cmd(report, "reiserfstune", QStringList() << "-u" << createUUID() << deviceNode);
                return cmd.run(-1) && cmd.exitCode() == 0;
        }
 }