From d3dde1737a6a8f11dbf83beacde9aeeefd710682 Mon Sep 17 00:00:00 2001 From: Adrien Moulin Date: Sun, 28 Aug 2022 13:56:24 +0200 Subject: [PATCH] network: add a new status bar icon for the network disconnected state --- src/include/86box/machine_status.h | 2 +- src/machine_status.c | 1 + src/qt/qt_machinestatus.cpp | 6 ++++-- src/qt/qt_mediamenu.cpp | 18 ++++++++++++++++-- src/qt/qt_mediamenu.hpp | 2 ++ src/qt/qt_ui.cpp | 1 + src/qt_resources.qrc | 1 + src/win/icons/network_empty.ico | Bin 0 -> 6950 bytes 8 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/win/icons/network_empty.ico diff --git a/src/include/86box/machine_status.h b/src/include/86box/machine_status.h index 6baafeeb0..31cefdfd4 100644 --- a/src/include/86box/machine_status.h +++ b/src/include/86box/machine_status.h @@ -21,7 +21,7 @@ typedef struct { 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[NET_CARD_MAX]; + dev_status_empty_active_t net[NET_CARD_MAX]; dev_status_empty_t cartridge[2]; } machine_status_t; diff --git a/src/machine_status.c b/src/machine_status.c index 3031c9ad3..1429d9295 100644 --- a/src/machine_status.c +++ b/src/machine_status.c @@ -52,5 +52,6 @@ machine_status_init() { for (size_t i = 0; i < NET_CARD_MAX; i++) { machine_status.net[i].active = false; + machine_status.net[i].empty = !network_is_connected(i); } } \ No newline at end of file diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index c04d6ee5c..9e93e882b 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -88,7 +88,7 @@ namespace { PixmapSetEmptyActive zip; PixmapSetEmptyActive mo; PixmapSetActive hd; - PixmapSetActive net; + PixmapSetEmptyActive net; QPixmap sound; }; @@ -232,7 +232,7 @@ struct MachineStatus::States { std::array zip; std::array mo; std::array hdds; - std::array net; + std::array net; std::unique_ptr sound; std::unique_ptr text; }; @@ -369,6 +369,7 @@ void MachineStatus::refreshIcons() { for (size_t i = 0; i < NET_CARD_MAX; i++) { d->net[i].setActive(machine_status.net[i].active); + d->net[i].setEmpty(machine_status.net[i].empty); } for (int i = 0; i < 2; ++i) { @@ -518,6 +519,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { iterateNIC([this, sbar](int i) { d->net[i].label = std::make_unique(); + d->net[i].setEmpty(!network_is_connected(i)); d->net[i].setActive(false); d->net[i].refresh(); d->net[i].label->setToolTip(MediaMenu::ptr->netMenus[i]->title()); diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 90cd80257..0050da900 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -165,7 +165,7 @@ void MediaMenu::refresh(QMenu *parentMenu) { MachineStatus::iterateNIC([this, parentMenu](int i) { auto *menu = parentMenu->addMenu(""); netDisconnPos = menu->children().count(); - auto *action = menu->addAction(tr("&Disconnected"), [i] { network_connect(i, !network_is_connected(i)); config_save(); }); + auto *action = menu->addAction(tr("&Connected"), [this, i] { network_is_connected(i) ? nicDisconnect(i) : nicConnect(i); }); action->setCheckable(true); netMenus[i] = menu; nicUpdateMenu(i); @@ -676,6 +676,20 @@ void MediaMenu::moUpdateMenu(int i) { menu->setTitle(QString::asprintf(tr("MO %i (%ls): %ls").toUtf8().constData(), i + 1, busName.toStdU16String().data(), name.isEmpty() ? tr("(empty)").toStdU16String().data() : name.toStdU16String().data())); } +void MediaMenu::nicConnect(int i) { + network_connect(i, 1); + ui_sb_update_icon_state(SB_NETWORK|i, 0); + nicUpdateMenu(i); + config_save(); +} + +void MediaMenu::nicDisconnect(int i) { + network_connect(i, 0); + ui_sb_update_icon_state(SB_NETWORK|i, 1); + nicUpdateMenu(i); + config_save(); +} + void MediaMenu::nicUpdateMenu(int i) { if (!netMenus.contains(i)) return; @@ -695,7 +709,7 @@ void MediaMenu::nicUpdateMenu(int i) { auto *menu = netMenus[i]; auto childs = menu->children(); auto *connectedAction = dynamic_cast(childs[netDisconnPos]); - connectedAction->setChecked(!network_is_connected(i)); + connectedAction->setChecked(network_is_connected(i)); menu->setTitle(QString::asprintf(tr("NIC %02i (%ls) %ls").toUtf8().constData(), i + 1, netType.toStdU16String().data(), devName.toStdU16String().data())); } diff --git a/src/qt/qt_mediamenu.hpp b/src/qt/qt_mediamenu.hpp index a5c50a472..de892d73c 100644 --- a/src/qt/qt_mediamenu.hpp +++ b/src/qt/qt_mediamenu.hpp @@ -57,6 +57,8 @@ public: void moReload(int i); void moUpdateMenu(int i); + void nicConnect(int i); + void nicDisconnect(int i); void nicUpdateMenu(int i); private: QWidget* parentWidget = nullptr; diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 65a8cec44..febf4cba7 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -215,6 +215,7 @@ ui_sb_update_icon_state(int tag, int state) { case SB_HDD: break; case SB_NETWORK: + machine_status.net[item].empty = state > 0 ? true : false; break; case SB_SOUND: break; diff --git a/src/qt_resources.qrc b/src/qt_resources.qrc index fec56ad71..67f9cadac 100644 --- a/src/qt_resources.qrc +++ b/src/qt_resources.qrc @@ -33,6 +33,7 @@ win/icons/mo_empty_active.ico win/icons/network.ico win/icons/network_active.ico + win/icons/network_empty.ico win/icons/other_peripherals.ico win/icons/other_removable_devices.ico win/icons/ports.ico diff --git a/src/win/icons/network_empty.ico b/src/win/icons/network_empty.ico new file mode 100644 index 0000000000000000000000000000000000000000..4a1a102846ea018ba6d899b5352dd9fbdcfce858 GIT binary patch literal 6950 zcmeHLJ#Q015S{qj1WO4@kuoJEKY@xW1qIUsq z+(bghdow$GXI~r%I^cF?&+dHf>{@wmHzEhplcOVn9La~i$U6}^IkEX@Ao2;i(^H#& z!F+Kja&~6(k0X)UE0NcTK?;Fd^FZuvM_BCm_*l-*&*k#+Qf9N6q-iQwS66a~J5*p}fFns2#BrfZ_;>&<0p;3`NHk z6Rn_TXMQSU080XbTKje(lI0>vBC^UvzCvb@oJUDJ{Q!GOx-E&bfM&&8;`MXQ@wJYt z#MJxy`xaN9JGj=?p1{9-0v!NYfUvO+2(MAuQD7P1o9NmhZkn~L3Mx5A!)*{l_Y0s$ z+$LzU$7RgVmOv=iV`nIrQ@=4&LdgYeWlYA}sWe~p@bC`QTAxPh*Ff{?(7n1^XK)z< z=mS}J5dDV0=s-B8wqgP;nX1a?k&sn|TT1hds&ccIJo^lse-E5D`8~Ul2c6$+>1i*L zwPf?P6w{_$E!T?wxRT2oeEyUN+Pii9dD=mH0{`y`7`TW1``wlR78yY>#O)Y3N~AP& zR;H?}okspu`kQp8< zoL4djZ*fjZ|2bp|Swfakt}x$V{+O4_V`o_UEk3`?W4E`r?f-~yZf$E%pgn=c3D`TL zp*984ukmLbsQQ^*nI7&P-Y3gp<>h1?Pxh@OlghB}cL$3zEvF41wqn~b_)&21G9$ejCDZIQ>v=*26#ghPljYEDIX#e8XsoIL2O1w6shHVQQzD)w z>)RVtv+