network: add a new status bar icon for the network disconnected state

This commit is contained in:
Adrien Moulin
2022-08-28 13:56:24 +02:00
parent ea21790fc9
commit d3dde1737a
8 changed files with 26 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ typedef struct {
dev_status_empty_active_t mo[MO_NUM]; dev_status_empty_active_t mo[MO_NUM];
dev_status_empty_active_t cassette; dev_status_empty_active_t cassette;
dev_status_active_t hdd[HDD_BUS_USB]; 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]; dev_status_empty_t cartridge[2];
} machine_status_t; } machine_status_t;

View File

@@ -52,5 +52,6 @@ machine_status_init() {
for (size_t i = 0; i < NET_CARD_MAX; i++) { for (size_t i = 0; i < NET_CARD_MAX; i++) {
machine_status.net[i].active = false; machine_status.net[i].active = false;
machine_status.net[i].empty = !network_is_connected(i);
} }
} }

View File

@@ -88,7 +88,7 @@ namespace {
PixmapSetEmptyActive zip; PixmapSetEmptyActive zip;
PixmapSetEmptyActive mo; PixmapSetEmptyActive mo;
PixmapSetActive hd; PixmapSetActive hd;
PixmapSetActive net; PixmapSetEmptyActive net;
QPixmap sound; QPixmap sound;
}; };
@@ -232,7 +232,7 @@ struct MachineStatus::States {
std::array<StateEmptyActive, ZIP_NUM> zip; std::array<StateEmptyActive, ZIP_NUM> zip;
std::array<StateEmptyActive, MO_NUM> mo; std::array<StateEmptyActive, MO_NUM> mo;
std::array<StateActive, HDD_BUS_USB> hdds; std::array<StateActive, HDD_BUS_USB> hdds;
std::array<StateActive, NET_CARD_MAX> net; std::array<StateEmptyActive, NET_CARD_MAX> net;
std::unique_ptr<ClickableLabel> sound; std::unique_ptr<ClickableLabel> sound;
std::unique_ptr<QLabel> text; std::unique_ptr<QLabel> text;
}; };
@@ -369,6 +369,7 @@ void MachineStatus::refreshIcons() {
for (size_t i = 0; i < NET_CARD_MAX; i++) { for (size_t i = 0; i < NET_CARD_MAX; i++) {
d->net[i].setActive(machine_status.net[i].active); 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) { for (int i = 0; i < 2; ++i) {
@@ -518,6 +519,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
iterateNIC([this, sbar](int i) { iterateNIC([this, sbar](int i) {
d->net[i].label = std::make_unique<ClickableLabel>(); d->net[i].label = std::make_unique<ClickableLabel>();
d->net[i].setEmpty(!network_is_connected(i));
d->net[i].setActive(false); d->net[i].setActive(false);
d->net[i].refresh(); d->net[i].refresh();
d->net[i].label->setToolTip(MediaMenu::ptr->netMenus[i]->title()); d->net[i].label->setToolTip(MediaMenu::ptr->netMenus[i]->title());

View File

@@ -165,7 +165,7 @@ void MediaMenu::refresh(QMenu *parentMenu) {
MachineStatus::iterateNIC([this, parentMenu](int i) { MachineStatus::iterateNIC([this, parentMenu](int i) {
auto *menu = parentMenu->addMenu(""); auto *menu = parentMenu->addMenu("");
netDisconnPos = menu->children().count(); 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); action->setCheckable(true);
netMenus[i] = menu; netMenus[i] = menu;
nicUpdateMenu(i); 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())); 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) { void MediaMenu::nicUpdateMenu(int i) {
if (!netMenus.contains(i)) if (!netMenus.contains(i))
return; return;
@@ -695,7 +709,7 @@ void MediaMenu::nicUpdateMenu(int i) {
auto *menu = netMenus[i]; auto *menu = netMenus[i];
auto childs = menu->children(); auto childs = menu->children();
auto *connectedAction = dynamic_cast<QAction*>(childs[netDisconnPos]); auto *connectedAction = dynamic_cast<QAction*>(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())); menu->setTitle(QString::asprintf(tr("NIC %02i (%ls) %ls").toUtf8().constData(), i + 1, netType.toStdU16String().data(), devName.toStdU16String().data()));
} }

View File

@@ -57,6 +57,8 @@ public:
void moReload(int i); void moReload(int i);
void moUpdateMenu(int i); void moUpdateMenu(int i);
void nicConnect(int i);
void nicDisconnect(int i);
void nicUpdateMenu(int i); void nicUpdateMenu(int i);
private: private:
QWidget* parentWidget = nullptr; QWidget* parentWidget = nullptr;

View File

@@ -215,6 +215,7 @@ ui_sb_update_icon_state(int tag, int state) {
case SB_HDD: case SB_HDD:
break; break;
case SB_NETWORK: case SB_NETWORK:
machine_status.net[item].empty = state > 0 ? true : false;
break; break;
case SB_SOUND: case SB_SOUND:
break; break;

View File

@@ -33,6 +33,7 @@
<file>win/icons/mo_empty_active.ico</file> <file>win/icons/mo_empty_active.ico</file>
<file>win/icons/network.ico</file> <file>win/icons/network.ico</file>
<file>win/icons/network_active.ico</file> <file>win/icons/network_active.ico</file>
<file>win/icons/network_empty.ico</file>
<file>win/icons/other_peripherals.ico</file> <file>win/icons/other_peripherals.ico</file>
<file>win/icons/other_removable_devices.ico</file> <file>win/icons/other_removable_devices.ico</file>
<file>win/icons/ports.ico</file> <file>win/icons/ports.ico</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB