generic: replace QUuid with QString and qRandomUuid()

implement new FileSystem::createUUID() method to de-duplicated code while
at it

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-03-22 15:25:38 +02:00
parent 90b1789d62
commit fc3ff6c252
6 changed files with 31 additions and 13 deletions

View file

@ -14,7 +14,6 @@
#include <QtCore/QSet> #include <QtCore/QSet>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtCore/QUuid>
#include <QtGui/QPixmap> #include <QtGui/QPixmap>
#include <QtXml/qdom.h> #include <QtXml/qdom.h>
@ -65,6 +64,15 @@ static void deleteObjectRects( QList< ObjectRect * >& rects, const QSet<ObjectRe
++it; ++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 ) PagePrivate::PagePrivate( Page *page, uint n, double w, double h, Rotation o )
: m_page( page ), m_number( n ), m_orientation( 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 ), 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 ) void Page::addAnnotation( Annotation * annotation )
{ {
// Generate uniqueName: okular-{UUID} // Generate uniqueName: okular-UUID
if(annotation->uniqueName().isEmpty()) if(annotation->uniqueName().isEmpty())
{ {
QString uniqueName = "okular-" + QUuid::createUuid().toString(); QString uniqueName = "okular-" + createAnnotationID();
annotation->setUniqueName( uniqueName ); annotation->setUniqueName( uniqueName );
} }
annotation->d_ptr->m_page = d; annotation->d_ptr->m_page = d;

View file

@ -28,6 +28,10 @@
#include <config.h> #include <config.h>
#if QT_VERSION < 0x041200
# include <QUuid>
#endif
/** Creates a new FileSystem object /** Creates a new FileSystem object
@param firstsector the first sector used by this FileSystem on the Device @param firstsector the first sector used by this FileSystem on the Device
@param lastsector the last 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 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() FileSystem::Type FileSystem::defaultFileSystem()
{ {
return static_cast<FileSystem::Type>(Config::defaultFileSystem()); return static_cast<FileSystem::Type>(Config::defaultFileSystem());

View file

@ -173,6 +173,7 @@ class FileSystem
protected: protected:
static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1); static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1);
static QString createUUID();
protected: protected:
FileSystem::Type m_Type; FileSystem::Type m_Type;

View file

@ -26,7 +26,6 @@
#include "util/externalcommand.h" #include "util/externalcommand.h"
#include <QString> #include <QString>
#include <QUuid>
#include <KLocale> #include <KLocale>
@ -135,9 +134,7 @@ namespace FS
bool luks::updateUUID(Report& report, const QString& deviceNode) const bool luks::updateUUID(Report& report, const QString& deviceNode) const
{ {
QUuid uuid = QUuid::createUuid(); ExternalCommand cmd(report, "cryptsetup", QStringList() << "luksUUID" << deviceNode << "--uuid" << createUUID());
ExternalCommand cmd(report, "cryptsetup", QStringList() << "luksUUID" << deviceNode << "--uuid" << uuid.toString());
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }

View file

@ -25,7 +25,6 @@
#include <cmath> #include <cmath>
#include <QString> #include <QString>
#include <QUuid>
#include <KLocale> #include <KLocale>
#include <KTempDir> #include <KTempDir>
@ -177,8 +176,7 @@ namespace FS
bool nilfs2::updateUUID(Report& report, const QString& deviceNode) const bool nilfs2::updateUUID(Report& report, const QString& deviceNode) const
{ {
QUuid uuid = QUuid::createUuid(); ExternalCommand cmd(report, "nilfs-tune", QStringList() << "-U" << createUUID() << deviceNode);
ExternalCommand cmd(report, "nilfs-tune", QStringList() << "-U" << uuid.toString() << deviceNode);
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }
} }

View file

@ -25,7 +25,6 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QRegExp> #include <QRegExp>
#include <QUuid>
namespace FS namespace FS
{ {
@ -165,8 +164,7 @@ namespace FS
bool reiserfs::updateUUID(Report& report, const QString& deviceNode) const bool reiserfs::updateUUID(Report& report, const QString& deviceNode) const
{ {
const QString uuid = QUuid::createUuid().toString().remove(QRegExp("\\{|\\}")); ExternalCommand cmd(report, "reiserfstune", QStringList() << "-u" << createUUID() << deviceNode);
ExternalCommand cmd(report, "reiserfstune", QStringList() << "-u" << uuid << deviceNode);
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }
} }