A bit more clang-format

This commit is contained in:
Jasmine Iwanek
2022-11-19 08:49:04 -05:00
parent b04dd8cc8b
commit 3fe4f75108
223 changed files with 8047 additions and 7456 deletions

View File

@@ -1,20 +1,19 @@
/*
* 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.
*
* This file is part of the 86Box distribution.
*
* Media history management module
*
*
*
* Authors: cold-brewed
*
* Copyright 2022 The 86Box development team
*/
* 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.
*
* This file is part of the 86Box distribution.
*
* Media history management module
*
*
*
* Authors: cold-brewed
*
* Copyright 2022 The 86Box development team
*/
#include <QApplication>
#include <QFileInfo>
@@ -23,8 +22,7 @@
#include <utility>
#include "qt_mediahistorymanager.hpp"
extern "C"
{
extern "C" {
#include <86box/timer.h>
#include <86box/cdrom.h>
#include <86box/fdd.h>
@@ -32,23 +30,23 @@ extern "C"
namespace ui {
MediaHistoryManager::MediaHistoryManager() {
MediaHistoryManager::MediaHistoryManager()
{
initializeImageHistory();
deserializeAllImageHistory();
initialDeduplication();
}
MediaHistoryManager::~MediaHistoryManager()
= default;
= default;
master_list_t &
MediaHistoryManager::blankImageHistory(master_list_t &initialized_master_list) const
{
for ( const auto device_type : ui::AllSupportedMediaHistoryTypes ) {
for (const auto device_type : ui::AllSupportedMediaHistoryTypes) {
device_media_history_t device_media_history;
// Loop for all possible media devices
for (int device_index = 0 ; device_index < maxDevicesSupported(device_type); device_index++) {
for (int device_index = 0; device_index < maxDevicesSupported(device_type); device_index++) {
device_index_list_t indexing_list;
device_media_history[device_index] = indexing_list;
// Loop for each history slot
@@ -61,12 +59,11 @@ MediaHistoryManager::blankImageHistory(master_list_t &initialized_master_list) c
return initialized_master_list;
}
const device_index_list_t&
const device_index_list_t &
MediaHistoryManager::getHistoryListForDeviceIndex(int index, ui::MediaType type)
{
if (master_list.contains(type)) {
if ((index >= 0 ) && (index < master_list[type].size())) {
if ((index >= 0) && (index < master_list[type].size())) {
return master_list[type][index];
} else {
qWarning("Media device index %i for device type %s was requested but index %i is out of range (valid range: >= 0 && < %i)",
@@ -77,7 +74,8 @@ MediaHistoryManager::getHistoryListForDeviceIndex(int index, ui::MediaType type)
return empty_device_index_list;
}
void MediaHistoryManager::setHistoryListForDeviceIndex(int index, ui::MediaType type, device_index_list_t history_list)
void
MediaHistoryManager::setHistoryListForDeviceIndex(int index, ui::MediaType type, device_index_list_t history_list)
{
master_list[type][index] = std::move(history_list);
}
@@ -85,7 +83,7 @@ void MediaHistoryManager::setHistoryListForDeviceIndex(int index, ui::MediaType
QString
MediaHistoryManager::getImageForSlot(int index, int slot, ui::MediaType type)
{
QString image_name;
QString image_name;
device_index_list_t device_history = getHistoryListForDeviceIndex(index, type);
if ((slot >= 0) && (slot < device_history.size())) {
image_name = device_history[slot];
@@ -99,44 +97,47 @@ MediaHistoryManager::getImageForSlot(int index, int slot, ui::MediaType type)
// These are hardcoded since we can't include the various
// header files where they are defined (e.g., fdd.h, mo.h).
// However, all in ui::MediaType support 4 except cassette.
int MediaHistoryManager::maxDevicesSupported(ui::MediaType type)
int
MediaHistoryManager::maxDevicesSupported(ui::MediaType type)
{
return type == ui::MediaType::Cassette ? 1 : 4;
}
void MediaHistoryManager::deserializeImageHistoryType(ui::MediaType type)
void
MediaHistoryManager::deserializeImageHistoryType(ui::MediaType type)
{
for (int device = 0; device < maxDevicesSupported(type); device++) {
char **device_history_ptr = getEmuHistoryVarForType(type, device);
if(device_history_ptr == nullptr) {
if (device_history_ptr == nullptr) {
// Device not supported, return and do not deserialize.
// This will leave the image listing at the default initialization state
// from the ui side (this class)
continue;
}
for ( int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
master_list[type][device][slot] = device_history_ptr[slot];
}
}
}
void MediaHistoryManager::deserializeAllImageHistory()
void
MediaHistoryManager::deserializeAllImageHistory()
{
for ( const auto device_type : ui::AllSupportedMediaHistoryTypes ) {
for (const auto device_type : ui::AllSupportedMediaHistoryTypes) {
deserializeImageHistoryType(device_type);
}
}
void MediaHistoryManager::serializeImageHistoryType(ui::MediaType type)
void
MediaHistoryManager::serializeImageHistoryType(ui::MediaType type)
{
for (int device = 0; device < maxDevicesSupported(type); device++) {
char **device_history_ptr = getEmuHistoryVarForType(type, device);
if(device_history_ptr == nullptr) {
if (device_history_ptr == nullptr) {
// Device not supported, return and do not serialize.
// This will leave the image listing at the current state,
// and it will not be saved on the emu side
continue;
}
for ( int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
if (device_history_ptr[slot] != nullptr) {
strncpy(device_history_ptr[slot], master_list[type][device][slot].toUtf8().constData(), MAX_IMAGE_PATH_LEN);
}
@@ -144,19 +145,21 @@ void MediaHistoryManager::serializeImageHistoryType(ui::MediaType type)
}
}
void MediaHistoryManager::serializeAllImageHistory()
void
MediaHistoryManager::serializeAllImageHistory()
{
for ( const auto device_type : ui::AllSupportedMediaHistoryTypes ) {
for (const auto device_type : ui::AllSupportedMediaHistoryTypes) {
serializeImageHistoryType(device_type);
}
}
void MediaHistoryManager::initialDeduplication()
void
MediaHistoryManager::initialDeduplication()
{
QString current_image;
// Perform initial dedup if an image is loaded
for ( const auto device_type : ui::AllSupportedMediaHistoryTypes ) {
for (const auto device_type : ui::AllSupportedMediaHistoryTypes) {
for (int device_index = 0; device_index < maxDevicesSupported(device_type); device_index++) {
device_index_list_t device_history = getHistoryListForDeviceIndex(device_index, device_type);
switch (device_type) {
@@ -170,10 +173,10 @@ void MediaHistoryManager::initialDeduplication()
continue;
break;
}
deduplicateList(device_history, QVector<QString> (1, current_image));
deduplicateList(device_history, QVector<QString>(1, current_image));
// Fill in missing, if any
int missing = MAX_PREV_IMAGES - device_history.size();
if(missing) {
if (missing) {
for (int i = 0; i < missing; i++) {
device_history.push_back(QString());
}
@@ -183,7 +186,8 @@ void MediaHistoryManager::initialDeduplication()
}
}
char ** MediaHistoryManager::getEmuHistoryVarForType(ui::MediaType type, int index)
char **
MediaHistoryManager::getEmuHistoryVarForType(ui::MediaType type, int index)
{
switch (type) {
case ui::MediaType::Optical:
@@ -192,24 +196,23 @@ char ** MediaHistoryManager::getEmuHistoryVarForType(ui::MediaType type, int ind
return &fdd_image_history[index][0];
default:
return nullptr;
}
}
device_index_list_t &
MediaHistoryManager::deduplicateList(device_index_list_t &device_history, const QVector<QString>& filenames)
MediaHistoryManager::deduplicateList(device_index_list_t &device_history, const QVector<QString> &filenames)
{
QVector<QString> items_to_delete;
for (auto &list_item_path : device_history) {
if(list_item_path.isEmpty()) {
continue ;
if (list_item_path.isEmpty()) {
continue;
}
for (const auto& path_to_check : filenames) {
if(path_to_check.isEmpty()) {
continue ;
for (const auto &path_to_check : filenames) {
if (path_to_check.isEmpty()) {
continue;
}
QString adjusted_path = pathAdjustSingle(path_to_check);
int match = QString::localeAwareCompare(list_item_path, adjusted_path);
int match = QString::localeAwareCompare(list_item_path, adjusted_path);
if (match == 0) {
items_to_delete.append(list_item_path);
}
@@ -217,22 +220,22 @@ MediaHistoryManager::deduplicateList(device_index_list_t &device_history, const
}
// Remove by name rather than index because the index would change
// after each removal
for (const auto& path: items_to_delete) {
for (const auto &path : items_to_delete) {
device_history.removeAll(path);
}
return device_history;
}
void MediaHistoryManager::addImageToHistory(int index, ui::MediaType type, const QString& image_name, const QString& new_image_name)
void
MediaHistoryManager::addImageToHistory(int index, ui::MediaType type, const QString &image_name, const QString &new_image_name)
{
device_index_list_t device_history = getHistoryListForDeviceIndex(index, type);
QVector<QString> files_to_check;
QVector<QString> files_to_check;
files_to_check.append(image_name);
files_to_check.append(new_image_name);
device_history = deduplicateList(device_history, files_to_check);
if (!image_name.isEmpty()) {
device_history.push_front(image_name);
}
@@ -244,7 +247,7 @@ void MediaHistoryManager::addImageToHistory(int index, ui::MediaType type, const
// Fill in missing, if any
int missing = MAX_PREV_IMAGES - device_history.size();
if(missing) {
if (missing) {
for (int i = 0; i < missing; i++) {
device_history.push_back(QString());
}
@@ -257,7 +260,8 @@ void MediaHistoryManager::addImageToHistory(int index, ui::MediaType type, const
serializeImageHistoryType(type);
}
QString MediaHistoryManager::mediaTypeToString(ui::MediaType type)
QString
MediaHistoryManager::mediaTypeToString(ui::MediaType type)
{
QMetaEnum qme = QMetaEnum::fromType<ui::MediaType>();
return qme.valueToKey(static_cast<int>(type));
@@ -266,7 +270,7 @@ QString MediaHistoryManager::mediaTypeToString(ui::MediaType type)
QString
MediaHistoryManager::pathAdjustSingle(QString checked_path)
{
QString current_usr_path = getUsrPath();
QString current_usr_path = getUsrPath();
QFileInfo file_info(checked_path);
if (file_info.filePath().isEmpty() || current_usr_path.isEmpty() || file_info.isRelative()) {
return checked_path;
@@ -285,7 +289,8 @@ MediaHistoryManager::pathAdjustFull(device_index_list_t &device_history)
}
return device_history;
}
QString MediaHistoryManager::getUsrPath()
QString
MediaHistoryManager::getUsrPath()
{
QString current_usr_path(usr_path);
// Ensure `usr_path` has a trailing slash
@@ -301,7 +306,7 @@ MediaHistoryManager::removeMissingImages(device_index_list_t &device_history)
}
// For this check, explicitly prepend `usr_path` to relative paths to account for $CWD platform variances
QFileInfo absolute_path = file_info.isRelative() ? QFileInfo(getUsrPath().append(file_info.filePath())) : file_info;
if(!absolute_path.exists()) {
if (!absolute_path.exists()) {
qWarning("Image file %s does not exist - removing from history", qPrintable(file_info.filePath()));
checked_path = "";
}
@@ -309,7 +314,8 @@ MediaHistoryManager::removeMissingImages(device_index_list_t &device_history)
return device_history;
}
void MediaHistoryManager::initializeImageHistory()
void
MediaHistoryManager::initializeImageHistory()
{
auto initial_master_list = getMasterList();
setMasterList(blankImageHistory(initial_master_list));