mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
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:
parent
c12d8c0017
commit
6cc6737d8d
4 changed files with 69 additions and 66 deletions
15
functions.h
15
functions.h
|
@ -693,6 +693,21 @@ namespace {
|
||||||
close(ntxfd);
|
close(ntxfd);
|
||||||
return !!ptr;
|
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
|
#endif // FUNCTIONS_H
|
||||||
|
|
|
@ -380,42 +380,44 @@ void generalDialog::on_okBtn_clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(ui->searchComboBox->currentText() == "Online library") {
|
else if(ui->searchComboBox->currentText() == "Online library") {
|
||||||
string_writeconfig("/inkbox/searchComboBoxFunction", "Online library");
|
if(testPing() == 0) {
|
||||||
|
string_writeconfig("/inkbox/searchComboBoxFunction", "Online library");
|
||||||
|
|
||||||
if(!readFile("/external_root/opt/storage/gutenberg/last_sync").isEmpty()) {
|
if(!readFile("/external_root/opt/storage/gutenberg/last_sync").isEmpty()) {
|
||||||
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
|
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
|
||||||
unsigned long syncEpoch = readFile("/external_root/opt/storage/gutenberg/last_sync").toULong();
|
unsigned long syncEpoch = readFile("/external_root/opt/storage/gutenberg/last_sync").toULong();
|
||||||
unsigned long allowSyncEpoch = syncEpoch + 86400;
|
unsigned long allowSyncEpoch = syncEpoch + 86400;
|
||||||
if(currentEpoch > allowSyncEpoch) {
|
if(currentEpoch > allowSyncEpoch) {
|
||||||
syncGutenbergCatalog();
|
syncGutenbergCatalog();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
noGutenbergSyncToDo = true;
|
noGutenbergSyncToDo = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
syncGutenbergCatalog();
|
|
||||||
}
|
|
||||||
|
|
||||||
QTimer * searchTimer = new QTimer(this);
|
|
||||||
searchTimer->setInterval(100);
|
|
||||||
connect(searchTimer, &QTimer::timeout, [&]() {
|
|
||||||
if(noGutenbergSyncToDo == true or (gutenbergSyncDone == true && gutenbergSyncStatus == true)) {
|
|
||||||
if(searchTimerDone == false) {
|
|
||||||
searchTimerDone = true;
|
|
||||||
string_writeconfig("/inkbox/gutenberg_search_request", global::keyboard::keyboardText.toStdString());
|
|
||||||
string_writeconfig("/opt/ibxd", "gutenberg_search\n");
|
|
||||||
global::toast::modalToast = true;
|
|
||||||
global::toast::indefiniteToast = true;
|
|
||||||
emit showToast("Searching");
|
|
||||||
QTimer::singleShot(100, this, SLOT(waitForGutenbergSearchDone()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
else {
|
||||||
searchTimer->start();
|
syncGutenbergCatalog();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
;
|
QTimer * searchTimer = new QTimer(this);
|
||||||
|
searchTimer->setInterval(100);
|
||||||
|
connect(searchTimer, &QTimer::timeout, [&]() {
|
||||||
|
if(noGutenbergSyncToDo == true or (gutenbergSyncDone == true && gutenbergSyncStatus == true)) {
|
||||||
|
if(searchTimerDone == false) {
|
||||||
|
searchTimerDone = true;
|
||||||
|
string_writeconfig("/inkbox/gutenberg_search_request", global::keyboard::keyboardText.toStdString());
|
||||||
|
string_writeconfig("/opt/ibxd", "gutenberg_search\n");
|
||||||
|
global::toast::modalToast = true;
|
||||||
|
global::toast::indefiniteToast = true;
|
||||||
|
emit showToast("Searching");
|
||||||
|
QTimer::singleShot(100, this, SLOT(waitForGutenbergSearchDone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
searchTimer->start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emit showToast("Wi-Fi connection error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -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) {
|
void MainWindow::updateWifiIcon(int mode) {
|
||||||
/* Usage:
|
/* Usage:
|
||||||
* mode 0: auto
|
* mode 0: auto
|
||||||
|
@ -1101,28 +1086,30 @@ void MainWindow::openEncfsRepackDialog() {
|
||||||
|
|
||||||
void MainWindow::on_libraryButton_clicked()
|
void MainWindow::on_libraryButton_clicked()
|
||||||
{
|
{
|
||||||
resetFullWindowException = false;
|
if(testPing() == 0) {
|
||||||
resetWindow(false);
|
resetFullWindowException = false;
|
||||||
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
|
resetWindow(false);
|
||||||
ui->libraryButton->setStyleSheet("background: black; color: white");
|
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
|
||||||
ui->libraryButton->setIcon(QIcon(":/resources/online-library-inverted.png"));
|
ui->libraryButton->setStyleSheet("background: black; color: white");
|
||||||
|
ui->libraryButton->setIcon(QIcon(":/resources/online-library-inverted.png"));
|
||||||
|
|
||||||
// Create widget
|
// Create widget
|
||||||
libraryWidgetWindow = new libraryWidget();
|
libraryWidgetWindow = new libraryWidget();
|
||||||
connect(libraryWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(resetFullWindow()));
|
connect(libraryWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(resetFullWindow()));
|
||||||
libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
ui->stackedWidget->insertWidget(3, libraryWidgetWindow);
|
ui->stackedWidget->insertWidget(3, libraryWidgetWindow);
|
||||||
global::mainwindow::tabSwitcher::libraryWidgetCreated = true;
|
global::mainwindow::tabSwitcher::libraryWidgetCreated = true;
|
||||||
|
|
||||||
// Switch tab
|
// Switch tab
|
||||||
ui->stackedWidget->setCurrentIndex(3);
|
ui->stackedWidget->setCurrentIndex(3);
|
||||||
global::mainwindow::tabSwitcher::libraryWidgetSelected = true;
|
global::mainwindow::tabSwitcher::libraryWidgetSelected = true;
|
||||||
|
|
||||||
// Repaint
|
// Repaint
|
||||||
this->repaint();
|
this->repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
;
|
showToast("Wi-Fi connection error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ public:
|
||||||
void openUsbmsDialog();
|
void openUsbmsDialog();
|
||||||
void resetIcons();
|
void resetIcons();
|
||||||
void setBatteryIcon();
|
void setBatteryIcon();
|
||||||
int testPing();
|
|
||||||
bool checkWifiState();
|
bool checkWifiState();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
Loading…
Reference in a new issue