kdecore: do not block while parsing files in KDeviceDatabase

parsing ~30k lines and filling maps for the entries takes some time and
could block the events of kinfocenter for example which is noticable
because the parsing of files is delayed until a KDeviceDatabase query is
made

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-06 16:07:14 +03:00
parent f0c713f831
commit 6ae96c3c1d

View file

@ -21,6 +21,9 @@
#include "kdebug.h"
#include <QFile>
#include <QCoreApplication>
#define KDEVICEDATABASE_TIMEOUT 100
struct KDeviceEntry
{
@ -75,12 +78,19 @@ static void extractIDs(QFile *idsfile,
{
// qDebug() << Q_FUNC_INFO << idsfile->fileName();
int counter = 0;
char idbuffer[5];
char strbuffer[1024];
bool classessection = false;
QByteArray lastvendorid;
QByteArray lastdeviceid;
while (!idsfile->atEnd()) {
counter++;
if (counter >= KDEVICEDATABASE_TIMEOUT) {
QCoreApplication::processEvents(QEventLoop::AllEvents, KDEVICEDATABASE_TIMEOUT);
counter = 0;
}
const QByteArray dbline = idsfile->readLine();
const QByteArray trimmeddbline = dbline.trimmed();
// qDebug() << Q_FUNC_INFO << dbline;