2022-02-07 15:00:02 +06:00
|
|
|
/*
|
2023-01-06 15:36:05 -05:00
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Utility functions.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Authors: Teemu Korhonen
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Copyright 2022 Teemu Korhonen
|
2022-02-07 15:00:02 +06:00
|
|
|
*/
|
2022-01-23 22:48:36 +02:00
|
|
|
#include <QStringBuilder>
|
|
|
|
|
#include <QStringList>
|
2022-02-10 15:30:39 +06:00
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 0)
|
2022-11-19 08:49:04 -05:00
|
|
|
# include <QDesktopWidget>
|
2022-02-10 15:30:39 +06:00
|
|
|
#endif
|
2024-03-29 08:23:55 -04:00
|
|
|
#include <QUuid>
|
2022-01-23 22:48:36 +02:00
|
|
|
#include "qt_util.hpp"
|
|
|
|
|
|
2024-03-29 08:23:55 -04:00
|
|
|
extern "C" {
|
|
|
|
|
#include <86box/86box.h>
|
|
|
|
|
#include <86box/config.h>
|
|
|
|
|
#include <86box/device.h>
|
|
|
|
|
#include <86box/ini.h>
|
|
|
|
|
#include <86box/random.h>
|
|
|
|
|
#include <86box/thread.h>
|
|
|
|
|
#include <86box/timer.h>
|
|
|
|
|
#include <86box/network.h>
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
namespace util {
|
|
|
|
|
QScreen *
|
|
|
|
|
screenOfWidget(QWidget *widget)
|
2022-01-23 22:48:36 +02:00
|
|
|
{
|
2022-02-10 15:30:39 +06:00
|
|
|
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 0)
|
2022-11-19 08:49:04 -05:00
|
|
|
return QApplication::screens()[QApplication::desktop()->screenNumber(widget) == -1 ? 0 : QApplication::desktop()->screenNumber(widget)];
|
2022-02-10 15:30:39 +06:00
|
|
|
#else
|
2022-11-19 08:49:04 -05:00
|
|
|
return widget->screen();
|
2022-02-10 15:30:39 +06:00
|
|
|
#endif
|
2022-11-19 08:49:04 -05:00
|
|
|
}
|
2022-01-23 22:48:36 +02:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
QString
|
|
|
|
|
DlgFilter(std::initializer_list<QString> extensions, bool last)
|
|
|
|
|
{
|
|
|
|
|
QStringList temp;
|
2022-01-23 22:48:36 +02:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
for (auto ext : extensions) {
|
2022-01-23 22:48:36 +02:00
|
|
|
#ifdef Q_OS_UNIX
|
2022-11-19 08:49:04 -05:00
|
|
|
if (ext == "*") {
|
|
|
|
|
temp.append("*");
|
|
|
|
|
continue;
|
2022-01-23 22:48:36 +02:00
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
temp.append("*." % ext.toUpper());
|
|
|
|
|
#endif
|
|
|
|
|
temp.append("*." % ext);
|
|
|
|
|
}
|
2022-01-23 22:48:36 +02:00
|
|
|
|
|
|
|
|
#ifdef Q_OS_UNIX
|
2022-11-19 08:49:04 -05:00
|
|
|
temp.removeDuplicates();
|
2022-01-23 22:48:36 +02:00
|
|
|
#endif
|
2022-11-19 08:49:04 -05:00
|
|
|
return " (" % temp.join(' ') % ")" % (!last ? ";;" : "");
|
|
|
|
|
}
|
2022-01-23 22:48:36 +02:00
|
|
|
|
2024-03-29 08:23:55 -04:00
|
|
|
QString currentUuid()
|
|
|
|
|
{
|
|
|
|
|
return QUuid::createUuidV5(QUuid{}, QString(usr_path)).toString(QUuid::WithoutBraces);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool compareUuid()
|
|
|
|
|
{
|
|
|
|
|
// A uuid not set in the config file will have a zero length.
|
|
|
|
|
// Any uuid that is lower than the minimum length will be considered invalid
|
|
|
|
|
// and a new one will be generated
|
|
|
|
|
if (const auto currentUuidLength = QString(uuid).length(); currentUuidLength < UUID_MIN_LENGTH) {
|
|
|
|
|
storeCurrentUuid();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// The uuid appears to be a valid, at least by length.
|
|
|
|
|
// Compare with a simple string match
|
|
|
|
|
return uuid == currentUuid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
storeCurrentUuid()
|
|
|
|
|
{
|
|
|
|
|
strncpy(uuid, currentUuid().toUtf8().constData(), sizeof(uuid) - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
generateNewMacAdresses()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < NET_CARD_MAX; ++i) {
|
|
|
|
|
auto net_card = net_cards_conf[i];
|
|
|
|
|
if (net_card.device_num != 0) {
|
|
|
|
|
const auto network_device = network_card_getdevice(net_card.device_num);
|
|
|
|
|
device_context_t device_context;
|
|
|
|
|
|
|
|
|
|
device_set_context(&device_context, network_device, i+1);
|
|
|
|
|
auto generatedMac = QString::asprintf("%02X:%02X:%02X", random_generate(), random_generate(), random_generate()).toLower();
|
|
|
|
|
config_set_string(device_context.name, "mac", generatedMac.toUtf8().constData());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-07 15:00:02 +06:00
|
|
|
}
|