Wi-Fi: Fixes to prevent segfault when only one network is detected and connected

This commit is contained in:
Nicolas Mailloux 2023-06-19 23:46:09 -04:00
parent f9a1fe6931
commit 0b4d8138da
3 changed files with 59 additions and 41 deletions

View file

@ -36,7 +36,7 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
} }
if(global::deviceID == "n705\n") { if(global::deviceID == "n705\n") {
bookTitleTruncateThreshold = 30; bookTitleTruncateThreshold = 27;
} }
else if(global::deviceID == "n873\n") { else if(global::deviceID == "n873\n") {
bookTitleTruncateThreshold = 45; bookTitleTruncateThreshold = 45;
@ -57,7 +57,11 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
sW = QGuiApplication::screens()[0]->size().width(); sW = QGuiApplication::screens()[0]->size().width();
sH = QGuiApplication::screens()[0]->size().height(); sH = QGuiApplication::screens()[0]->size().height();
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "kt\n") { if(global::deviceID == "n705\n") {
stdIconWidthDivider = 7.2;
stdIconHeightDivider = 7.2;
}
else if(global::deviceID == "n905\n" or global::deviceID == "kt\n") {
stdIconWidthDivider = 9.5; stdIconWidthDivider = 9.5;
stdIconHeightDivider = 9.5; stdIconHeightDivider = 9.5;
} }

View file

@ -191,8 +191,15 @@ libraryWidget::~libraryWidget()
void libraryWidget::setupView() { void libraryWidget::setupView() {
ui->booksStackedWidget->show(); ui->booksStackedWidget->show();
stdIconWidth = sW / 5.5; if(global::deviceID == "n705\n") {
stdIconHeight = sH / 5.5; stdIconWidth = sW / 7
;
stdIconHeight = sH / 7;
}
else {
stdIconWidth = sW / 5.5;
stdIconHeight = sH / 5.5;
}
ui->book1Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/1/title")); ui->book1Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/1/title"));
ui->book2Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/2/title")); ui->book2Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/2/title"));

View file

@ -248,46 +248,49 @@ void wifiDialog::refreshNetworksList() {
} }
} }
// Sort based on signal strength log(QString::number(pureNetworkList.count()));
QVector<global::wifi::wifiNetworkData> sortedPureNetworkList; if(pureNetworkList.count() >= 1) {
sortedPureNetworkList.append(pureNetworkList.first()); // Sort based on signal strength
pureNetworkList.removeFirst(); QVector<global::wifi::wifiNetworkData> sortedPureNetworkList;
// Possible fix for a segmentation fault sortedPureNetworkList.append(pureNetworkList.first());
if(pureNetworkList.isEmpty() == false) { pureNetworkList.removeFirst();
for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) { // Possible fix for a segmentation fault
bool stopIterating = false; if(pureNetworkList.isEmpty() == false) {
int counter = 0; for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) {
for(global::wifi::wifiNetworkData wifiNetworkToSort: sortedPureNetworkList) { bool stopIterating = false;
if(stopIterating == false) { int counter = 0;
if(wifiNetwork.signal >= wifiNetworkToSort.signal) { for(global::wifi::wifiNetworkData wifiNetworkToSort: sortedPureNetworkList) {
sortedPureNetworkList.insert(counter, wifiNetwork); if(stopIterating == false) {
stopIterating = true; if(wifiNetwork.signal >= wifiNetworkToSort.signal) {
sortedPureNetworkList.insert(counter, wifiNetwork);
stopIterating = true;
}
counter = counter + 1;
} }
counter = counter + 1; }
// This happens if it's the smallest value, so insert it at the end
if(stopIterating == false) {
sortedPureNetworkList.append(wifiNetwork);
} }
} }
// This happens if it's the smallest value, so insert it at the end
if(stopIterating == false) {
sortedPureNetworkList.append(wifiNetwork);
}
} }
} log("There are " + QString::number(sortedPureNetworkList.count()) + " sorted networks", className);
log("There are " + QString::number(sortedPureNetworkList.count()) + " sorted networks", className);
for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) { for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
log("Signal strength with sorting: " + QString::number(wifiNetwork.signal), className); log("Signal strength with sorting: " + QString::number(wifiNetwork.signal), className);
} }
// And now, handle the remainder of the networks // And now, handle the remainder of the networks
for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) { for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
network* connectedNetwork = new network; network* connectedNetwork = new network;
connectedNetwork->mainData = wifiNetwork; connectedNetwork->mainData = wifiNetwork;
connectedNetwork->currentlyConnectedNetwork = currentNetwork; connectedNetwork->currentlyConnectedNetwork = currentNetwork;
connectedNetwork->applyVariables(); connectedNetwork->applyVariables();
connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper); connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper);
connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot); connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot);
connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot); connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot);
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop); ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
}
} }
scannedAtLeastOnce = true; scannedAtLeastOnce = true;
ui->refreshBtn->setEnabled(true); ui->refreshBtn->setEnabled(true);
@ -296,7 +299,6 @@ void wifiDialog::refreshNetworksList() {
secondScanTry = false; secondScanTry = false;
} }
void wifiDialog::on_wifiCheckBox_stateChanged(int arg1) void wifiDialog::on_wifiCheckBox_stateChanged(int arg1)
{ {
if(ignoreCheckBoxCall == false) { if(ignoreCheckBoxCall == false) {
@ -319,7 +321,7 @@ void wifiDialog::on_wifiCheckBox_stateChanged(int arg1)
} }
emit killNetworkWidgets(); emit killNetworkWidgets();
} }
if(wifiButtonEnabled == false){ if(wifiButtonEnabled == false) {
wifiButtonEnabled = true; wifiButtonEnabled = true;
} }
} }
@ -394,7 +396,12 @@ void wifiDialog::watcher() {
} }
if(changing == true) { if(changing == true) {
setStatusText("Disconnecting from a network or cleaning up"); if(global::deviceID == "n705\n") {
setStatusText("Disconnecting or cleaning up");
}
else {
setStatusText("Disconnecting from a network or cleaning up");
}
log("prepare_changing_wifi.sh is active", className); log("prepare_changing_wifi.sh is active", className);
QTimer::singleShot(relaunchMs, this, SLOT(watcher())); QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void(); return void();