Gutenberg: Fix #20

Gutenberg-related services (e.g., 'Online library') will now show an error message if they can't connect to the Internet and refuse to launch.
This commit is contained in:
Nicolas Mailloux 2022-03-23 23:41:14 -04:00
parent c12d8c0017
commit 6cc6737d8d
4 changed files with 69 additions and 66 deletions

View file

@ -693,6 +693,21 @@ namespace {
close(ntxfd);
return !!ptr;
}
int testPing() {
QString pingProg = "ping";
QStringList pingArgs;
pingArgs << "-c" << "1" << "1.1.1.1";
QProcess *pingProcess = new QProcess();
pingProcess->start(pingProg, pingArgs);
pingProcess->waitForFinished();
int exitCode = pingProcess->exitCode();
pingProcess->deleteLater();
if(exitCode == 0) {
global::network::isConnected = true;
}
return exitCode;
}
}
#endif // FUNCTIONS_H

View file

@ -380,6 +380,7 @@ void generalDialog::on_okBtn_clicked()
}
}
else if(ui->searchComboBox->currentText() == "Online library") {
if(testPing() == 0) {
string_writeconfig("/inkbox/searchComboBoxFunction", "Online library");
if(!readFile("/external_root/opt/storage/gutenberg/last_sync").isEmpty()) {
@ -415,7 +416,8 @@ void generalDialog::on_okBtn_clicked()
searchTimer->start();
}
else {
;
emit showToast("Wi-Fi connection error");
}
}
}
else {

View file

@ -902,21 +902,6 @@ void MainWindow::setupSearchDialog() {
}
}
int MainWindow::testPing() {
QString pingProg = "ping";
QStringList pingArgs;
pingArgs << "-c" << "1" << "1.1.1.1";
QProcess *pingProcess = new QProcess();
pingProcess->start(pingProg, pingArgs);
pingProcess->waitForFinished();
int exitCode = pingProcess->exitCode();
pingProcess->deleteLater();
if(exitCode == 0) {
global::network::isConnected = true;
}
return exitCode;
}
void MainWindow::updateWifiIcon(int mode) {
/* Usage:
* mode 0: auto
@ -1101,6 +1086,7 @@ void MainWindow::openEncfsRepackDialog() {
void MainWindow::on_libraryButton_clicked()
{
if(testPing() == 0) {
resetFullWindowException = false;
resetWindow(false);
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
@ -1121,8 +1107,9 @@ void MainWindow::on_libraryButton_clicked()
// Repaint
this->repaint();
}
}
else {
;
showToast("Wi-Fi connection error");
}
}

View file

@ -58,7 +58,6 @@ public:
void openUsbmsDialog();
void resetIcons();
void setBatteryIcon();
int testPing();
bool checkWifiState();
public slots: