generic: replace QUuid with QByteArray and qRandomUuid()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-03-22 14:48:24 +02:00
parent ff13ae7a6a
commit 3ca810a7d4
10 changed files with 42 additions and 25 deletions

View file

@ -393,8 +393,8 @@ TriggersCount=1
[Data_1_1Triggers0] [Data_1_1Triggers0]
Key=Search Key=Search
Type=SHORTCUT Type=SHORTCUT
Uuid={d03619b6-9b3c-48cc-9d9c-a2aadb485550} Uuid=d03619b6-9b3c-48cc-9d9c-a2aadb485550
[Main] [Main]
Version=2 Version=3
ImportId=defaults ImportId=defaults

View file

@ -432,5 +432,5 @@ Key=Print
Type=SHORTCUT Type=SHORTCUT
[Main] [Main]
Version=2 Version=3
ImportId=printscreen ImportId=printscreen

View file

@ -234,12 +234,13 @@ bool Settings::isConfigFileValid(KConfigBase const &config, ImportType ask)
int version = mainGroup.readEntry( "Version", -1234576 ); int version = mainGroup.readEntry( "Version", -1234576 );
switch (version) switch (version)
{ {
case 2: case 3:
valid = true; valid = true;
break; break;
case 1: // Version 1 files no longer supported case 2:
kDebug() << "Version 1 file encountered."; case 1: // Version 1 and 2 files no longer supported
kDebug() << "Version 1 or 2 file encountered.";
break; break;
case -1234576: // No Version entry -> invalid file 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" ); QString import_id = mainGroup.readEntry( "ImportId" );
switch (version) switch (version)
{ {
case 2: case 3:
{ {
kDebug() << "Version 2 File!"; kDebug() << "Version 3 File!";
SettingsReaderV2 reader(this, include_disabled, stateStrategy, import_id); SettingsReaderV2 reader(this, include_disabled, stateStrategy, import_id);
reader.read(config, root); reader.read(config, root);
} }

View file

@ -301,9 +301,9 @@ KHotKeys::Trigger_list *SettingsReaderV2::readTriggerList(
{ {
KConfigGroup triggerConfig( triggersGroup.config(), triggersGroup.name() + QString::number( i )); KConfigGroup triggerConfig( triggersGroup.config(), triggersGroup.name() + QString::number( i ));
QString type = triggerConfig.readEntry("Type"); QString type = triggerConfig.readEntry("Type");
QUuid uuid = triggerConfig.readEntry( "Uuid" ); QByteArray uuid = triggerConfig.readEntry( "Uuid", QByteArray() );
if( uuid.isNull()) if( uuid.isNull())
uuid = QUuid::createUuid(); uuid = createShortcutID();
if (type == "SHORTCUT" || type == "SINGLE_SHORTCUT") if (type == "SHORTCUT" || type == "SINGLE_SHORTCUT")
trigger = new KHotKeys::ShortcutTrigger(parent, KShortcut(), uuid); trigger = new KHotKeys::ShortcutTrigger(parent, KShortcut(), uuid);

View file

@ -38,7 +38,7 @@
namespace KHotKeys { namespace KHotKeys {
const int CurrentFileVersion = 2; const int CurrentFileVersion = 3;
SettingsWriter::SettingsWriter( SettingsWriter::SettingsWriter(

View file

@ -20,11 +20,11 @@
#include <config-X11.h> #include <config-X11.h>
#include "input.h" #include "input.h"
#include "triggers/triggers.h"
#include "shortcuts_handler.h" #include "shortcuts_handler.h"
#include "windows_handler.h" #include "windows_handler.h"
#include "khotkeysglobal.h" #include "khotkeysglobal.h"
#include <X11/X.h> #include <X11/X.h>
// #include <X11/Xutil.h> // #include <X11/Xutil.h>
#include <QtGui/qx11info_x11.h> #include <QtGui/qx11info_x11.h>
@ -33,7 +33,6 @@
#include <KAction> #include <KAction>
#include <KDebug> #include <KDebug>
#include <QtCore/QUuid>
#include <kkeyserver.h> #include <kkeyserver.h>
namespace KHotKeys { namespace KHotKeys {
@ -70,7 +69,7 @@ KAction *ShortcutsHandler::addAction(
if (_actions->action(id)) if (_actions->action(id))
{ {
qDebug() << id << " already present. Using new id!"; qDebug() << id << " already present. Using new id!";
realId = QUuid::createUuid().toString(); realId = QString::fromLatin1(createShortcutID());
} }
// Create the action // Create the action

View file

@ -36,9 +36,9 @@ ShortcutTriggerVisitor::~ShortcutTriggerVisitor()
ShortcutTrigger::ShortcutTrigger( ShortcutTrigger::ShortcutTrigger(
ActionData* data_P, ActionData* data_P,
const KShortcut& shortcut, const KShortcut& shortcut,
const QUuid &uuid ) const QByteArray &uuid )
: Trigger( data_P ), : Trigger( data_P ),
_uuid(uuid.toString()), _uuid(uuid),
_active(false), _active(false),
_shortcut(shortcut) _shortcut(shortcut)
{ {
@ -93,7 +93,7 @@ void ShortcutTrigger::activate( bool newState )
KAction *act = keyboard_handler->addAction( _uuid, name, _shortcut ); KAction *act = keyboard_handler->addAction( _uuid, name, _shortcut );
// addAction can change the uuid. That's why we store the uuid from the // addAction can change the uuid. That's why we store the uuid from the
// action // action
_uuid = act->objectName(); _uuid = act->objectName().toLatin1();
connect( connect(
act, SIGNAL(triggered(bool)), act, SIGNAL(triggered(bool)),
@ -128,7 +128,7 @@ void ShortcutTrigger::cfg_write( KConfigGroup& cfg_P ) const
ShortcutTrigger* ShortcutTrigger::copy( ActionData* data_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());
} }

View file

@ -22,7 +22,7 @@
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QUuid> #include <QtCore/QByteArray>
#include <KShortcut> #include <KShortcut>
@ -35,6 +35,15 @@
#include <QKeySequence> #include <QKeySequence>
static inline QByteArray createShortcutID()
{
#if QT_VERSION >= 0x041200
return qRandomUuid();
#else
return QByteArray::number(qrand());
#endif
}
namespace KHotKeys namespace KHotKeys
{ {
@ -153,7 +162,7 @@ class KDE_EXPORT ShortcutTrigger
ShortcutTrigger( ShortcutTrigger(
ActionData* data, ActionData* data,
const KShortcut& shortcut = KShortcut(), const KShortcut& shortcut = KShortcut(),
const QUuid &uuid = QUuid::createUuid() ); const QByteArray &uuid = createShortcutID() );
virtual ~ShortcutTrigger(); virtual ~ShortcutTrigger();
virtual void cfg_write( KConfigGroup& cfg_P ) const; virtual void cfg_write( KConfigGroup& cfg_P ) const;
@ -195,7 +204,7 @@ class KDE_EXPORT ShortcutTrigger
private: private:
//! A persistent identifier for this shortcut //! A persistent identifier for this shortcut
QString _uuid; QByteArray _uuid;
//! Are the conditions met? //! Are the conditions met?
bool _active; bool _active;

View file

@ -22,7 +22,6 @@
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QUuid>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtGui/qx11info_x11.h> #include <QtGui/qx11info_x11.h>
@ -44,6 +43,15 @@
#include "history.h" #include "history.h"
#include "historystringitem.h" #include "historystringitem.h"
static inline QByteArray createActionID()
{
#if QT_VERSION >= 0x041200
return qRandomUuid();
#else
return QByteArray::number(qrand());
#endif
}
URLGrabber::URLGrabber(History* history): URLGrabber::URLGrabber(History* history):
m_myMenu(0L), m_myMenu(0L),
m_myPopupKillTimer(new QTimer( this )), m_myPopupKillTimer(new QTimer( this )),
@ -228,7 +236,7 @@ void URLGrabber::actionMenu( const HistoryItem* item, bool automatically_invoked
if ( item.isEmpty() ) if ( item.isEmpty() )
item = command.command; item = command.command;
QString id = QUuid::createUuid().toString(); QByteArray id = createActionID();
QAction * action = new QAction(this); QAction * action = new QAction(this);
action->setData(id); action->setData(id);
action->setText(item); action->setText(item);
@ -270,7 +278,7 @@ void URLGrabber::slotItemSelected(QAction* action)
if (m_myMenu) if (m_myMenu)
m_myMenu->hide(); // deleted by the timer or the next action m_myMenu->hide(); // deleted by the timer or the next action
QString id = action->data().toString(); QByteArray id = action->data().toByteArray();
if (id.isEmpty()) { if (id.isEmpty()) {
kDebug() << "Klipper: no command associated"; kDebug() << "Klipper: no command associated";

View file

@ -83,7 +83,7 @@ private:
const HistoryItem* m_myClipItem; const HistoryItem* m_myClipItem;
// holds mappings of menu action IDs to action commands (action+cmd index in it) // holds mappings of menu action IDs to action commands (action+cmd index in it)
QHash<QString, QPair<ClipAction*, int> > m_myCommandMapper; QHash<QByteArray, QPair<ClipAction*, int> > m_myCommandMapper;
KMenu* m_myMenu; KMenu* m_myMenu;
QTimer* m_myPopupKillTimer; QTimer* m_myPopupKillTimer;
int m_myPopupKillTimeout; int m_myPopupKillTimeout;