From 3ca810a7d497af276f78cca9c1d77725cb8ea3ab Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 22 Mar 2022 14:48:24 +0200 Subject: [PATCH] generic: replace QUuid with QByteArray and qRandomUuid() Signed-off-by: Ivailo Monev --- khotkeys/data/defaults.khotkeys | 4 ++-- khotkeys/data/printscreen.khotkeys | 2 +- khotkeys/libkhotkeysprivate/settings.cpp | 11 ++++++----- khotkeys/libkhotkeysprivate/settings_reader_v2.cpp | 4 ++-- khotkeys/libkhotkeysprivate/settings_writer.cpp | 2 +- khotkeys/libkhotkeysprivate/shortcuts_handler.cpp | 5 ++--- khotkeys/libkhotkeysprivate/triggers/shortcut_trigger.cpp | 8 ++++---- khotkeys/libkhotkeysprivate/triggers/triggers.h | 15 ++++++++++++--- klipper/urlgrabber.cpp | 14 +++++++++++--- klipper/urlgrabber.h | 2 +- 10 files changed, 42 insertions(+), 25 deletions(-) diff --git a/khotkeys/data/defaults.khotkeys b/khotkeys/data/defaults.khotkeys index c771aab3..e639358c 100644 --- a/khotkeys/data/defaults.khotkeys +++ b/khotkeys/data/defaults.khotkeys @@ -393,8 +393,8 @@ TriggersCount=1 [Data_1_1Triggers0] Key=Search Type=SHORTCUT -Uuid={d03619b6-9b3c-48cc-9d9c-a2aadb485550} +Uuid=d03619b6-9b3c-48cc-9d9c-a2aadb485550 [Main] -Version=2 +Version=3 ImportId=defaults diff --git a/khotkeys/data/printscreen.khotkeys b/khotkeys/data/printscreen.khotkeys index 3238cea4..607c8051 100644 --- a/khotkeys/data/printscreen.khotkeys +++ b/khotkeys/data/printscreen.khotkeys @@ -432,5 +432,5 @@ Key=Print Type=SHORTCUT [Main] -Version=2 +Version=3 ImportId=printscreen diff --git a/khotkeys/libkhotkeysprivate/settings.cpp b/khotkeys/libkhotkeysprivate/settings.cpp index 8f9fb97f..87b82361 100644 --- a/khotkeys/libkhotkeysprivate/settings.cpp +++ b/khotkeys/libkhotkeysprivate/settings.cpp @@ -234,12 +234,13 @@ bool Settings::isConfigFileValid(KConfigBase const &config, ImportType ask) int version = mainGroup.readEntry( "Version", -1234576 ); switch (version) { - case 2: + case 3: valid = true; break; - case 1: // Version 1 files no longer supported - kDebug() << "Version 1 file encountered."; + case 2: + case 1: // Version 1 and 2 files no longer supported + kDebug() << "Version 1 or 2 file encountered."; break; case -1234576: // No Version entry -> invalid file @@ -461,9 +462,9 @@ bool Settings::read_settings(ActionDataGroup *root, KConfigBase const &config, b QString import_id = mainGroup.readEntry( "ImportId" ); switch (version) { - case 2: + case 3: { - kDebug() << "Version 2 File!"; + kDebug() << "Version 3 File!"; SettingsReaderV2 reader(this, include_disabled, stateStrategy, import_id); reader.read(config, root); } diff --git a/khotkeys/libkhotkeysprivate/settings_reader_v2.cpp b/khotkeys/libkhotkeysprivate/settings_reader_v2.cpp index 69a13ec1..6501410a 100644 --- a/khotkeys/libkhotkeysprivate/settings_reader_v2.cpp +++ b/khotkeys/libkhotkeysprivate/settings_reader_v2.cpp @@ -301,9 +301,9 @@ KHotKeys::Trigger_list *SettingsReaderV2::readTriggerList( { KConfigGroup triggerConfig( triggersGroup.config(), triggersGroup.name() + QString::number( i )); QString type = triggerConfig.readEntry("Type"); - QUuid uuid = triggerConfig.readEntry( "Uuid" ); + QByteArray uuid = triggerConfig.readEntry( "Uuid", QByteArray() ); if( uuid.isNull()) - uuid = QUuid::createUuid(); + uuid = createShortcutID(); if (type == "SHORTCUT" || type == "SINGLE_SHORTCUT") trigger = new KHotKeys::ShortcutTrigger(parent, KShortcut(), uuid); diff --git a/khotkeys/libkhotkeysprivate/settings_writer.cpp b/khotkeys/libkhotkeysprivate/settings_writer.cpp index 086cef69..da5dc0a0 100644 --- a/khotkeys/libkhotkeysprivate/settings_writer.cpp +++ b/khotkeys/libkhotkeysprivate/settings_writer.cpp @@ -38,7 +38,7 @@ namespace KHotKeys { -const int CurrentFileVersion = 2; +const int CurrentFileVersion = 3; SettingsWriter::SettingsWriter( diff --git a/khotkeys/libkhotkeysprivate/shortcuts_handler.cpp b/khotkeys/libkhotkeysprivate/shortcuts_handler.cpp index 3f139cdf..3f62b031 100644 --- a/khotkeys/libkhotkeysprivate/shortcuts_handler.cpp +++ b/khotkeys/libkhotkeysprivate/shortcuts_handler.cpp @@ -20,11 +20,11 @@ #include #include "input.h" +#include "triggers/triggers.h" #include "shortcuts_handler.h" #include "windows_handler.h" #include "khotkeysglobal.h" - #include // #include #include @@ -33,7 +33,6 @@ #include #include -#include #include namespace KHotKeys { @@ -70,7 +69,7 @@ KAction *ShortcutsHandler::addAction( if (_actions->action(id)) { qDebug() << id << " already present. Using new id!"; - realId = QUuid::createUuid().toString(); + realId = QString::fromLatin1(createShortcutID()); } // Create the action diff --git a/khotkeys/libkhotkeysprivate/triggers/shortcut_trigger.cpp b/khotkeys/libkhotkeysprivate/triggers/shortcut_trigger.cpp index 4b4517ad..9da0a9cd 100644 --- a/khotkeys/libkhotkeysprivate/triggers/shortcut_trigger.cpp +++ b/khotkeys/libkhotkeysprivate/triggers/shortcut_trigger.cpp @@ -36,9 +36,9 @@ ShortcutTriggerVisitor::~ShortcutTriggerVisitor() ShortcutTrigger::ShortcutTrigger( ActionData* data_P, const KShortcut& shortcut, - const QUuid &uuid ) + const QByteArray &uuid ) : Trigger( data_P ), - _uuid(uuid.toString()), + _uuid(uuid), _active(false), _shortcut(shortcut) { @@ -93,7 +93,7 @@ void ShortcutTrigger::activate( bool newState ) KAction *act = keyboard_handler->addAction( _uuid, name, _shortcut ); // addAction can change the uuid. That's why we store the uuid from the // action - _uuid = act->objectName(); + _uuid = act->objectName().toLatin1(); connect( act, SIGNAL(triggered(bool)), @@ -128,7 +128,7 @@ void ShortcutTrigger::cfg_write( KConfigGroup& cfg_P ) const ShortcutTrigger* ShortcutTrigger::copy( ActionData* data_P ) const { - return new ShortcutTrigger( data_P ? data_P : data, shortcut(), QUuid::createUuid()); + return new ShortcutTrigger( data_P ? data_P : data, shortcut(), createShortcutID()); } diff --git a/khotkeys/libkhotkeysprivate/triggers/triggers.h b/khotkeys/libkhotkeysprivate/triggers/triggers.h index 3cd38ba9..398b009c 100644 --- a/khotkeys/libkhotkeysprivate/triggers/triggers.h +++ b/khotkeys/libkhotkeysprivate/triggers/triggers.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include @@ -35,6 +35,15 @@ #include +static inline QByteArray createShortcutID() +{ +#if QT_VERSION >= 0x041200 + return qRandomUuid(); +#else + return QByteArray::number(qrand()); +#endif +} + namespace KHotKeys { @@ -153,7 +162,7 @@ class KDE_EXPORT ShortcutTrigger ShortcutTrigger( ActionData* data, const KShortcut& shortcut = KShortcut(), - const QUuid &uuid = QUuid::createUuid() ); + const QByteArray &uuid = createShortcutID() ); virtual ~ShortcutTrigger(); virtual void cfg_write( KConfigGroup& cfg_P ) const; @@ -195,7 +204,7 @@ class KDE_EXPORT ShortcutTrigger private: //! A persistent identifier for this shortcut - QString _uuid; + QByteArray _uuid; //! Are the conditions met? bool _active; diff --git a/klipper/urlgrabber.cpp b/klipper/urlgrabber.cpp index 012a9cfd..70ca067b 100644 --- a/klipper/urlgrabber.cpp +++ b/klipper/urlgrabber.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -44,6 +43,15 @@ #include "history.h" #include "historystringitem.h" +static inline QByteArray createActionID() +{ +#if QT_VERSION >= 0x041200 + return qRandomUuid(); +#else + return QByteArray::number(qrand()); +#endif +} + URLGrabber::URLGrabber(History* history): m_myMenu(0L), m_myPopupKillTimer(new QTimer( this )), @@ -228,7 +236,7 @@ void URLGrabber::actionMenu( const HistoryItem* item, bool automatically_invoked if ( item.isEmpty() ) item = command.command; - QString id = QUuid::createUuid().toString(); + QByteArray id = createActionID(); QAction * action = new QAction(this); action->setData(id); action->setText(item); @@ -270,7 +278,7 @@ void URLGrabber::slotItemSelected(QAction* action) if (m_myMenu) m_myMenu->hide(); // deleted by the timer or the next action - QString id = action->data().toString(); + QByteArray id = action->data().toByteArray(); if (id.isEmpty()) { kDebug() << "Klipper: no command associated"; diff --git a/klipper/urlgrabber.h b/klipper/urlgrabber.h index dc1d1f80..5f7a1b2e 100644 --- a/klipper/urlgrabber.h +++ b/klipper/urlgrabber.h @@ -83,7 +83,7 @@ private: const HistoryItem* m_myClipItem; // holds mappings of menu action IDs to action commands (action+cmd index in it) - QHash > m_myCommandMapper; + QHash > m_myCommandMapper; KMenu* m_myMenu; QTimer* m_myPopupKillTimer; int m_myPopupKillTimeout; -- 2.11.0