qt: switch to polling for status bar updating

This commit is contained in:
Adrien Moulin
2022-07-13 01:04:01 +02:00
parent 30479fc3b9
commit 24ee676b13
11 changed files with 242 additions and 99 deletions

View File

@@ -96,6 +96,7 @@
#include <86box/thread.h> #include <86box/thread.h>
#include <86box/version.h> #include <86box/version.h>
#include <86box/gdbstub.h> #include <86box/gdbstub.h>
#include <86box/machine_status.h>
// Disable c99-designator to avoid the warnings about int ng // Disable c99-designator to avoid the warnings about int ng
#ifdef __clang__ #ifdef __clang__
@@ -891,6 +892,8 @@ pc_init_modules(void)
video_reset_close(); video_reset_close();
machine_status_init();
return(1); return(1);
} }

View File

@@ -17,7 +17,7 @@
add_executable(86Box 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c add_executable(86Box 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c
dma.c ddma.c discord.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c dma.c ddma.c discord.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c
mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c) mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c machine_status.c)
if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 _LARGEFILE64_SOURCE=1) add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 _LARGEFILE64_SOURCE=1)

View File

@@ -0,0 +1,32 @@
#ifndef EMU_MACHINE_STATUS_H
#define EMU_MACHINE_STATUS_H
typedef struct {
atomic_bool_t empty;
atomic_bool_t active;
} dev_status_empty_active_t;
typedef struct {
atomic_bool_t active;
} dev_status_active_t;
typedef struct {
atomic_bool_t empty;
} dev_status_empty_t;
typedef struct {
dev_status_empty_active_t fdd[FDD_NUM];
dev_status_empty_active_t cdrom[CDROM_NUM];
dev_status_empty_active_t zip[ZIP_NUM];
dev_status_empty_active_t mo[MO_NUM];
dev_status_empty_active_t cassette;
dev_status_active_t hdd[HDD_BUS_USB];
dev_status_active_t net;
dev_status_empty_t cartridge[2];
} machine_status_t;
extern machine_status_t machine_status;
extern void machine_status_init();
#endif /*EMU_MACHINE_STATUS_H*/

View File

@@ -68,10 +68,12 @@ extern int strnicmp(const char* s1, const char* s2, size_t n);
#ifdef __cplusplus #ifdef __cplusplus
#include <atomic> #include <atomic>
#define atomic_flag_t std::atomic_flag #define atomic_flag_t std::atomic_flag
#define atomic_bool_t std::atomic_bool
extern "C" { extern "C" {
#else #else
#include <stdatomic.h> #include <stdatomic.h>
#define atomic_flag_t atomic_flag #define atomic_flag_t atomic_flag
#define atomic_bool_t atomic_bool
#endif #endif
/* Global variables residing in the platform module. */ /* Global variables residing in the platform module. */

View File

@@ -70,8 +70,8 @@ extern void ui_sb_update_panes(void);
extern void ui_sb_update_text(void); extern void ui_sb_update_text(void);
extern void ui_sb_update_tip(int meaning); extern void ui_sb_update_tip(int meaning);
extern void ui_sb_timer_callback(int pane); extern void ui_sb_timer_callback(int pane);
extern void ui_sb_update_icon(int tag, int val); extern void ui_sb_update_icon(int tag, int active);
extern void ui_sb_update_icon_state(int tag, int active); extern void ui_sb_update_icon_state(int tag, int state);
extern void ui_sb_set_text_w(wchar_t *wstr); extern void ui_sb_set_text_w(wchar_t *wstr);
extern void ui_sb_set_text(char *str); extern void ui_sb_set_text(char *str);
extern void ui_sb_bugui(char *str); extern void ui_sb_bugui(char *str);

52
src/machine_status.c Normal file
View File

@@ -0,0 +1,52 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <86box/86box.h>
#include <86box/plat.h>
#include <86box/ui.h>
#include <86box/timer.h>
#include <86box/device.h>
#include <86box/fdd.h>
#include <86box/hdc.h>
#include <86box/scsi.h>
#include <86box/scsi_device.h>
#include <86box/cartridge.h>
#include <86box/cassette.h>
#include <86box/cdrom.h>
#include <86box/zip.h>
#include <86box/mo.h>
#include <86box/hdd.h>
#include <86box/machine_status.h>
machine_status_t machine_status;
void
machine_status_init() {
for (size_t i = 0; i < FDD_NUM; ++i) {
machine_status.fdd[i].empty = (strlen(floppyfns[i]) == 0);
machine_status.fdd[i].active = false;
}
for (size_t i = 0; i < CDROM_NUM; ++i) {
machine_status.cdrom[i].empty = cdrom[i].host_drive != 200 || (strlen(cdrom[i].image_path) == 0);
machine_status.cdrom[i].active = false;
}
for (size_t i = 0; i < ZIP_NUM; i++) {
machine_status.zip[i].empty = (strlen(zip_drives[i].image_path) == 0);
machine_status.zip[i].active = false;
}
for (size_t i = 0; i < MO_NUM; i++) {
machine_status.mo[i].empty = (strlen(mo_drives[i].image_path) == 0);
machine_status.mo[i].active = false;
}
machine_status.cassette.empty = (strlen(cassette_fname) == 0);
for (size_t i = 0; i < HDD_BUS_USB; i++) {
machine_status.hdd[i].active = false;
}
machine_status.net.active = false;
}

View File

@@ -39,6 +39,7 @@ extern uint64_t tsc;
#include <86box/machine.h> #include <86box/machine.h>
#include <86box/network.h> #include <86box/network.h>
#include <86box/ui.h> #include <86box/ui.h>
#include <86box/machine_status.h>
}; };
#include <QIcon> #include <QIcon>
@@ -92,17 +93,21 @@ namespace {
struct StateActive { struct StateActive {
std::unique_ptr<QLabel> label; std::unique_ptr<QLabel> label;
QTimer timer;
PixmapSetActive* pixmaps = nullptr; PixmapSetActive* pixmaps = nullptr;
bool active = false; bool active = false;
void setActive(bool b) { void setActive(bool b) {
active = b; if (!label || b == active)
if (! label) { return;
active = b;
refresh();
}
void refresh() {
if (!label)
return; return;
}
label->setPixmap(active ? pixmaps->active : pixmaps->normal); label->setPixmap(active ? pixmaps->active : pixmaps->normal);
timer.start(75);
} }
}; };
struct StateEmpty { struct StateEmpty {
@@ -111,33 +116,42 @@ namespace {
bool empty = false; bool empty = false;
void setEmpty(bool e) { void setEmpty(bool e) {
empty = e; if (!label || e == empty)
if (! label) { return;
empty = e;
refresh();
}
void refresh() {
if (!label)
return; return;
}
label->setPixmap(empty ? pixmaps->empty : pixmaps->normal); label->setPixmap(empty ? pixmaps->empty : pixmaps->normal);
} }
}; };
struct StateEmptyActive { struct StateEmptyActive {
std::unique_ptr<QLabel> label; std::unique_ptr<QLabel> label;
QTimer timer;
PixmapSetEmptyActive* pixmaps = nullptr; PixmapSetEmptyActive* pixmaps = nullptr;
bool empty = false; bool empty = false;
bool active = false; bool active = false;
void setActive(bool b) { void setActive(bool b) {
if (!label || b == active)
return;
active = b; active = b;
refresh(); refresh();
timer.start(75);
} }
void setEmpty(bool b) { void setEmpty(bool b) {
if (!label || b == empty)
return;
empty = b; empty = b;
refresh(); refresh();
} }
void refresh() { void refresh() {
if (! label) { if (!label)
return; return;
}
if (empty) { if (empty) {
label->setPixmap(active ? pixmaps->empty_active : pixmaps->empty); label->setPixmap(active ? pixmaps->empty_active : pixmaps->empty);
} else { } else {
@@ -190,26 +204,20 @@ struct MachineStatus::States {
cartridge[0].pixmaps = &pixmaps.cartridge; cartridge[0].pixmaps = &pixmaps.cartridge;
cartridge[1].pixmaps = &pixmaps.cartridge; cartridge[1].pixmaps = &pixmaps.cartridge;
cassette.pixmaps = &pixmaps.cassette; cassette.pixmaps = &pixmaps.cassette;
QObject::connect(&cassette.timer, &QTimer::timeout, parent, [&]{ cassette.setActive(false); });
for (auto& f : fdd) { for (auto& f : fdd) {
f.pixmaps = &pixmaps.floppy_disabled; f.pixmaps = &pixmaps.floppy_disabled;
QObject::connect(&f.timer, &QTimer::timeout, parent, [&]{ f.setActive(false); });
} }
for (auto& c : cdrom) { for (auto& c : cdrom) {
c.pixmaps = &pixmaps.cdrom; c.pixmaps = &pixmaps.cdrom;
QObject::connect(&c.timer, &QTimer::timeout, parent, [&]{ c.setActive(false); });
} }
for (auto& z : zip) { for (auto& z : zip) {
z.pixmaps = &pixmaps.zip; z.pixmaps = &pixmaps.zip;
QObject::connect(&z.timer, &QTimer::timeout, parent, [&]{ z.setActive(false); });
} }
for (auto& m : mo) { for (auto& m : mo) {
m.pixmaps = &pixmaps.mo; m.pixmaps = &pixmaps.mo;
QObject::connect(&m.timer, &QTimer::timeout, parent, [&]{ m.setActive(false); });
} }
for (auto& h : hdds) { for (auto& h : hdds) {
h.pixmaps = &pixmaps.hd; h.pixmaps = &pixmaps.hd;
QObject::connect(&h.timer, &QTimer::timeout, parent, [&]{ h.setActive(false); });
} }
net.pixmaps = &pixmaps.net; net.pixmaps = &pixmaps.net;
} }
@@ -227,9 +235,12 @@ struct MachineStatus::States {
}; };
MachineStatus::MachineStatus(QObject *parent) : MachineStatus::MachineStatus(QObject *parent) :
QObject(parent) QObject(parent),
refreshTimer(new QTimer(this))
{ {
d = std::make_unique<MachineStatus::States>(this); d = std::make_unique<MachineStatus::States>(this);
connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons);
refreshTimer->start(75);
} }
MachineStatus::~MachineStatus() = default; MachineStatus::~MachineStatus() = default;
@@ -321,6 +332,38 @@ static int hdd_count(int bus) {
return(c); return(c);
} }
void MachineStatus::refreshIcons() {
for (size_t i = 0; i < FDD_NUM; ++i) {
d->fdd[i].setActive(machine_status.fdd[i].active);
d->fdd[i].setEmpty(machine_status.fdd[i].empty);
}
for (size_t i = 0; i < CDROM_NUM; ++i) {
d->cdrom[i].setActive(machine_status.cdrom[i].active);
d->cdrom[i].setEmpty(machine_status.cdrom[i].empty);
}
for (size_t i = 0; i < ZIP_NUM; i++) {
d->zip[i].setActive(machine_status.zip[i].active);
d->zip[i].setEmpty(machine_status.zip[i].empty);
}
for (size_t i = 0; i < MO_NUM; i++) {
d->mo[i].setActive(machine_status.mo[i].active);
d->mo[i].setEmpty(machine_status.mo[i].empty);
}
d->cassette.setEmpty(machine_status.cassette.empty);
for (size_t i = 0; i < HDD_BUS_USB; i++) {
d->hdds[i].setActive(machine_status.hdd[i].active);
}
d->net.setActive(machine_status.net.active);
for (int i = 0; i < 2; ++i) {
d->cartridge[i].setEmpty(machine_status.cartridge[i].empty);
}
}
void MachineStatus::refresh(QStatusBar* sbar) { void MachineStatus::refresh(QStatusBar* sbar) {
bool has_mfm = machine_has_flags(machine, MACHINE_MFM) > 0; bool has_mfm = machine_has_flags(machine, MACHINE_MFM) > 0;
bool has_xta = machine_has_flags(machine, MACHINE_XTA) > 0; bool has_xta = machine_has_flags(machine, MACHINE_XTA) > 0;
@@ -358,6 +401,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
if (cassette_enable) { if (cassette_enable) {
d->cassette.label = std::make_unique<ClickableLabel>(); d->cassette.label = std::make_unique<ClickableLabel>();
d->cassette.setEmpty(QString(cassette_fname).isEmpty()); d->cassette.setEmpty(QString(cassette_fname).isEmpty());
d->cassette.refresh();
connect((ClickableLabel*)d->cassette.label.get(), &ClickableLabel::clicked, [](QPoint pos) { connect((ClickableLabel*)d->cassette.label.get(), &ClickableLabel::clicked, [](QPoint pos) {
MediaMenu::ptr->cassetteMenu->popup(pos - QPoint(0, MediaMenu::ptr->cassetteMenu->sizeHint().height())); MediaMenu::ptr->cassetteMenu->popup(pos - QPoint(0, MediaMenu::ptr->cassetteMenu->sizeHint().height()));
}); });
@@ -373,6 +417,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
d->cartridge[i].label = std::make_unique<ClickableLabel>(); d->cartridge[i].label = std::make_unique<ClickableLabel>();
d->cartridge[i].setEmpty(QString(cart_fns[i]).isEmpty()); d->cartridge[i].setEmpty(QString(cart_fns[i]).isEmpty());
d->cartridge[i].refresh();
connect((ClickableLabel*)d->cartridge[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { connect((ClickableLabel*)d->cartridge[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
MediaMenu::ptr->cartridgeMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cartridgeMenus[i]->sizeHint().height())); MediaMenu::ptr->cartridgeMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cartridgeMenus[i]->sizeHint().height()));
}); });
@@ -397,6 +442,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
d->fdd[i].label = std::make_unique<ClickableLabel>(); d->fdd[i].label = std::make_unique<ClickableLabel>();
d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty()); d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty());
d->fdd[i].setActive(false); d->fdd[i].setActive(false);
d->fdd[i].refresh();
connect((ClickableLabel*)d->fdd[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { connect((ClickableLabel*)d->fdd[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
MediaMenu::ptr->floppyMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->floppyMenus[i]->sizeHint().height())); MediaMenu::ptr->floppyMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->floppyMenus[i]->sizeHint().height()));
}); });
@@ -412,6 +458,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
d->cdrom[i].label = std::make_unique<ClickableLabel>(); d->cdrom[i].label = std::make_unique<ClickableLabel>();
d->cdrom[i].setEmpty(cdrom[i].host_drive != 200 || QString(cdrom[i].image_path).isEmpty()); d->cdrom[i].setEmpty(cdrom[i].host_drive != 200 || QString(cdrom[i].image_path).isEmpty());
d->cdrom[i].setActive(false); d->cdrom[i].setActive(false);
d->cdrom[i].refresh();
connect((ClickableLabel*)d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { connect((ClickableLabel*)d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
MediaMenu::ptr->cdromMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cdromMenus[i]->sizeHint().height())); MediaMenu::ptr->cdromMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cdromMenus[i]->sizeHint().height()));
}); });
@@ -427,6 +474,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
d->zip[i].label = std::make_unique<ClickableLabel>(); d->zip[i].label = std::make_unique<ClickableLabel>();
d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty()); d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty());
d->zip[i].setActive(false); d->zip[i].setActive(false);
d->zip[i].refresh();
connect((ClickableLabel*)d->zip[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { connect((ClickableLabel*)d->zip[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
MediaMenu::ptr->zipMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->zipMenus[i]->sizeHint().height())); MediaMenu::ptr->zipMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->zipMenus[i]->sizeHint().height()));
}); });
@@ -442,6 +490,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
d->mo[i].label = std::make_unique<ClickableLabel>(); d->mo[i].label = std::make_unique<ClickableLabel>();
d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty()); d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty());
d->mo[i].setActive(false); d->mo[i].setActive(false);
d->mo[i].refresh();
connect((ClickableLabel*)d->mo[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { connect((ClickableLabel*)d->mo[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
MediaMenu::ptr->moMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->moMenus[i]->sizeHint().height())); MediaMenu::ptr->moMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->moMenus[i]->sizeHint().height()));
}); });
@@ -457,24 +506,28 @@ void MachineStatus::refresh(QStatusBar* sbar) {
if ((has_mfm || hdc_name.left(5) == QStringLiteral("st506")) && c_mfm > 0) { if ((has_mfm || hdc_name.left(5) == QStringLiteral("st506")) && c_mfm > 0) {
d->hdds[HDD_BUS_MFM].label = std::make_unique<QLabel>(); d->hdds[HDD_BUS_MFM].label = std::make_unique<QLabel>();
d->hdds[HDD_BUS_MFM].setActive(false); d->hdds[HDD_BUS_MFM].setActive(false);
d->hdds[HDD_BUS_MFM].refresh();
d->hdds[HDD_BUS_MFM].label->setToolTip(tr("Hard disk (%s)").replace("%s", "MFM/RLL")); d->hdds[HDD_BUS_MFM].label->setToolTip(tr("Hard disk (%s)").replace("%s", "MFM/RLL"));
sbar->addWidget(d->hdds[HDD_BUS_MFM].label.get()); sbar->addWidget(d->hdds[HDD_BUS_MFM].label.get());
} }
if ((has_esdi || hdc_name.left(4) == QStringLiteral("esdi")) && c_esdi > 0) { if ((has_esdi || hdc_name.left(4) == QStringLiteral("esdi")) && c_esdi > 0) {
d->hdds[HDD_BUS_ESDI].label = std::make_unique<QLabel>(); d->hdds[HDD_BUS_ESDI].label = std::make_unique<QLabel>();
d->hdds[HDD_BUS_ESDI].setActive(false); d->hdds[HDD_BUS_ESDI].setActive(false);
d->hdds[HDD_BUS_ESDI].refresh();
d->hdds[HDD_BUS_ESDI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "ESDI")); d->hdds[HDD_BUS_ESDI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "ESDI"));
sbar->addWidget(d->hdds[HDD_BUS_ESDI].label.get()); sbar->addWidget(d->hdds[HDD_BUS_ESDI].label.get());
} }
if ((has_xta || hdc_name.left(3) == QStringLiteral("xta")) && c_xta > 0) { if ((has_xta || hdc_name.left(3) == QStringLiteral("xta")) && c_xta > 0) {
d->hdds[HDD_BUS_XTA].label = std::make_unique<QLabel>(); d->hdds[HDD_BUS_XTA].label = std::make_unique<QLabel>();
d->hdds[HDD_BUS_XTA].setActive(false); d->hdds[HDD_BUS_XTA].setActive(false);
d->hdds[HDD_BUS_XTA].refresh();
d->hdds[HDD_BUS_XTA].label->setToolTip(tr("Hard disk (%s)").replace("%s", "XTA")); d->hdds[HDD_BUS_XTA].label->setToolTip(tr("Hard disk (%s)").replace("%s", "XTA"));
sbar->addWidget(d->hdds[HDD_BUS_XTA].label.get()); sbar->addWidget(d->hdds[HDD_BUS_XTA].label.get());
} }
if ((hasIDE() || hdc_name.left(5) == QStringLiteral("xtide") || hdc_name.left(3) == QStringLiteral("ide")) && c_ide > 0) { if ((hasIDE() || hdc_name.left(5) == QStringLiteral("xtide") || hdc_name.left(3) == QStringLiteral("ide")) && c_ide > 0) {
d->hdds[HDD_BUS_IDE].label = std::make_unique<QLabel>(); d->hdds[HDD_BUS_IDE].label = std::make_unique<QLabel>();
d->hdds[HDD_BUS_IDE].setActive(false); d->hdds[HDD_BUS_IDE].setActive(false);
d->hdds[HDD_BUS_IDE].refresh();
d->hdds[HDD_BUS_IDE].label->setToolTip(tr("Hard disk (%s)").replace("%s", "IDE")); d->hdds[HDD_BUS_IDE].label->setToolTip(tr("Hard disk (%s)").replace("%s", "IDE"));
sbar->addWidget(d->hdds[HDD_BUS_IDE].label.get()); sbar->addWidget(d->hdds[HDD_BUS_IDE].label.get());
} }
@@ -482,6 +535,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
(scsi_card_current[2] != 0) || (scsi_card_current[3] != 0)) && c_scsi > 0) { (scsi_card_current[2] != 0) || (scsi_card_current[3] != 0)) && c_scsi > 0) {
d->hdds[HDD_BUS_SCSI].label = std::make_unique<QLabel>(); d->hdds[HDD_BUS_SCSI].label = std::make_unique<QLabel>();
d->hdds[HDD_BUS_SCSI].setActive(false); d->hdds[HDD_BUS_SCSI].setActive(false);
d->hdds[HDD_BUS_SCSI].refresh();
d->hdds[HDD_BUS_SCSI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "SCSI")); d->hdds[HDD_BUS_SCSI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "SCSI"));
sbar->addWidget(d->hdds[HDD_BUS_SCSI].label.get()); sbar->addWidget(d->hdds[HDD_BUS_SCSI].label.get());
} }
@@ -489,6 +543,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
if (do_net) { if (do_net) {
d->net.label = std::make_unique<QLabel>(); d->net.label = std::make_unique<QLabel>();
d->net.setActive(false); d->net.setActive(false);
d->net.refresh();
d->net.label->setToolTip(tr("Network")); d->net.label->setToolTip(tr("Network"));
sbar->addWidget(d->net.label.get()); sbar->addWidget(d->net.label.get());
} }
@@ -505,72 +560,6 @@ void MachineStatus::refresh(QStatusBar* sbar) {
sbar->addWidget(d->text.get()); sbar->addWidget(d->text.get());
} }
void MachineStatus::setActivity(int tag, bool active) {
int category = tag & 0xfffffff0;
int item = tag & 0xf;
switch (category) {
case SB_CASSETTE:
break;
case SB_CARTRIDGE:
break;
case SB_FLOPPY:
d->fdd[item].setActive(active);
break;
case SB_CDROM:
d->cdrom[item].setActive(active);
break;
case SB_ZIP:
d->zip[item].setActive(active);
break;
case SB_MO:
d->mo[item].setActive(active);
break;
case SB_HDD:
d->hdds[item].setActive(active);
break;
case SB_NETWORK:
d->net.setActive(active);
break;
case SB_SOUND:
break;
case SB_TEXT:
break;
}
}
void MachineStatus::setEmpty(int tag, bool empty) {
int category = tag & 0xfffffff0;
int item = tag & 0xf;
switch (category) {
case SB_CASSETTE:
d->cassette.setEmpty(empty);
break;
case SB_CARTRIDGE:
d->cartridge[item].setEmpty(empty);
break;
case SB_FLOPPY:
d->fdd[item].setEmpty(empty);
break;
case SB_CDROM:
d->cdrom[item].setEmpty(empty);
break;
case SB_ZIP:
d->zip[item].setEmpty(empty);
break;
case SB_MO:
d->mo[item].setEmpty(empty);
break;
case SB_HDD:
break;
case SB_NETWORK:
break;
case SB_SOUND:
break;
case SB_TEXT:
break;
}
}
void MachineStatus::message(const QString &msg) { void MachineStatus::message(const QString &msg) {
d->text->setText(msg); d->text->setText(msg);
} }

View File

@@ -70,14 +70,14 @@ public:
QString getMessage(); QString getMessage();
public slots: public slots:
void refresh(QStatusBar* sbar); void refresh(QStatusBar* sbar);
void setActivity(int tag, bool active);
void setEmpty(int tag, bool active);
void message(const QString& msg); void message(const QString& msg);
void updateTip(int tag); void updateTip(int tag);
void refreshIcons();
private: private:
struct States; struct States;
std::unique_ptr<States> d; std::unique_ptr<States> d;
QTimer *refreshTimer;
}; };
#endif // QT_MACHINESTATUS_HPP #endif // QT_MACHINESTATUS_HPP

View File

@@ -266,8 +266,6 @@ MainWindow::MainWindow(QWidget *parent) :
}); });
connect(this, &MainWindow::updateStatusBarPanes, this, &MainWindow::refreshMediaMenu); connect(this, &MainWindow::updateStatusBarPanes, this, &MainWindow::refreshMediaMenu);
connect(this, &MainWindow::updateStatusBarTip, status.get(), &MachineStatus::updateTip); connect(this, &MainWindow::updateStatusBarTip, status.get(), &MachineStatus::updateTip);
connect(this, &MainWindow::updateStatusBarActivity, status.get(), &MachineStatus::setActivity);
connect(this, &MainWindow::updateStatusBarEmpty, status.get(), &MachineStatus::setEmpty);
connect(this, &MainWindow::statusBarMessage, status.get(), &MachineStatus::message, Qt::QueuedConnection); connect(this, &MainWindow::statusBarMessage, status.get(), &MachineStatus::message, Qt::QueuedConnection);
ui->actionKeyboard_requires_capture->setChecked(kbd_req_capture); ui->actionKeyboard_requires_capture->setChecked(kbd_req_capture);

View File

@@ -132,8 +132,6 @@ void ProgSettings::accept()
main_window->refreshMediaMenu(); main_window->refreshMediaMenu();
main_window->status->message(msg); main_window->status->message(msg);
connect(main_window, &MainWindow::updateStatusBarTip, main_window->status.get(), &MachineStatus::updateTip); connect(main_window, &MainWindow::updateStatusBarTip, main_window->status.get(), &MachineStatus::updateTip);
connect(main_window, &MainWindow::updateStatusBarActivity, main_window->status.get(), &MachineStatus::setActivity);
connect(main_window, &MainWindow::updateStatusBarEmpty, main_window->status.get(), &MachineStatus::setEmpty);
connect(main_window, &MainWindow::statusBarMessage, main_window->status.get(), &MachineStatus::message, Qt::QueuedConnection); connect(main_window, &MainWindow::statusBarMessage, main_window->status.get(), &MachineStatus::message, Qt::QueuedConnection);
mouse_sensitivity = mouseSensitivity; mouse_sensitivity = mouseSensitivity;
QDialog::accept(); QDialog::accept();

View File

@@ -25,6 +25,7 @@
#include <QStatusBar> #include <QStatusBar>
#include "qt_mainwindow.hpp" #include "qt_mainwindow.hpp"
#include "qt_machinestatus.hpp"
MainWindow* main_window = nullptr; MainWindow* main_window = nullptr;
@@ -35,6 +36,20 @@ extern "C" {
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/ui.h> #include <86box/ui.h>
#include <86box/mouse.h> #include <86box/mouse.h>
#include <86box/timer.h>
#include <86box/86box.h>
#include <86box/device.h>
#include <86box/fdd.h>
#include <86box/hdc.h>
#include <86box/scsi.h>
#include <86box/scsi_device.h>
#include <86box/cartridge.h>
#include <86box/cassette.h>
#include <86box/cdrom.h>
#include <86box/zip.h>
#include <86box/mo.h>
#include <86box/hdd.h>
#include <86box/machine_status.h>
void void
plat_delay_ms(uint32_t count) plat_delay_ms(uint32_t count)
@@ -161,16 +176,70 @@ void ui_sb_set_ready(int ready) {
void void
ui_sb_update_icon_state(int tag, int state) { ui_sb_update_icon_state(int tag, int state) {
if (main_window == nullptr) { int category = tag & 0xfffffff0;
return; int item = tag & 0xf;
switch (category) {
case SB_CASSETTE:
machine_status.cassette.empty = state > 0 ? true : false;
break;
case SB_CARTRIDGE:
machine_status.cartridge[item].empty = state > 0 ? true : false;
break;
case SB_FLOPPY:
machine_status.fdd[item].empty = state > 0 ? true : false;
break;
case SB_CDROM:
machine_status.cdrom[item].empty = state > 0 ? true : false;
break;
case SB_ZIP:
machine_status.zip[item].empty = state > 0 ? true : false;
break;
case SB_MO:
machine_status.mo[item].empty = state > 0 ? true : false;
break;
case SB_HDD:
break;
case SB_NETWORK:
break;
case SB_SOUND:
break;
case SB_TEXT:
break;
} }
main_window->updateStatusBarEmpty(tag, state > 0 ? true : false);
} }
void void
ui_sb_update_icon(int tag, int active) { ui_sb_update_icon(int tag, int active) {
if (!update_icons) return; int category = tag & 0xfffffff0;
main_window->updateStatusBarActivity(tag, active > 0 ? true : false); int item = tag & 0xf;
switch (category) {
case SB_CASSETTE:
break;
case SB_CARTRIDGE:
break;
case SB_FLOPPY:
machine_status.fdd[item].active = active > 0 ? true : false;
break;
case SB_CDROM:
machine_status.cdrom[item].active = active > 0 ? true : false;
break;
case SB_ZIP:
machine_status.zip[item].active = active > 0 ? true : false;
break;
case SB_MO:
machine_status.mo[item].active = active > 0 ? true : false;
break;
case SB_HDD:
machine_status.hdd[item].active = active > 0 ? true : false;
break;
case SB_NETWORK:
machine_status.net.active = active > 0 ? true : false;
break;
case SB_SOUND:
break;
case SB_TEXT:
break;
}
} }
} }