mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07: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);
|
||||
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
|
||||
|
|
|
@ -380,42 +380,44 @@ void generalDialog::on_okBtn_clicked()
|
|||
}
|
||||
}
|
||||
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()) {
|
||||
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
|
||||
unsigned long syncEpoch = readFile("/external_root/opt/storage/gutenberg/last_sync").toULong();
|
||||
unsigned long allowSyncEpoch = syncEpoch + 86400;
|
||||
if(currentEpoch > allowSyncEpoch) {
|
||||
syncGutenbergCatalog();
|
||||
}
|
||||
else {
|
||||
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()));
|
||||
if(!readFile("/external_root/opt/storage/gutenberg/last_sync").isEmpty()) {
|
||||
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
|
||||
unsigned long syncEpoch = readFile("/external_root/opt/storage/gutenberg/last_sync").toULong();
|
||||
unsigned long allowSyncEpoch = syncEpoch + 86400;
|
||||
if(currentEpoch > allowSyncEpoch) {
|
||||
syncGutenbergCatalog();
|
||||
}
|
||||
else {
|
||||
noGutenbergSyncToDo = true;
|
||||
}
|
||||
}
|
||||
} );
|
||||
searchTimer->start();
|
||||
}
|
||||
else {
|
||||
;
|
||||
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()));
|
||||
}
|
||||
}
|
||||
} );
|
||||
searchTimer->start();
|
||||
}
|
||||
else {
|
||||
emit showToast("Wi-Fi connection error");
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
/* Usage:
|
||||
* mode 0: auto
|
||||
|
@ -1101,28 +1086,30 @@ void MainWindow::openEncfsRepackDialog() {
|
|||
|
||||
void MainWindow::on_libraryButton_clicked()
|
||||
{
|
||||
resetFullWindowException = false;
|
||||
resetWindow(false);
|
||||
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
|
||||
ui->libraryButton->setStyleSheet("background: black; color: white");
|
||||
ui->libraryButton->setIcon(QIcon(":/resources/online-library-inverted.png"));
|
||||
if(testPing() == 0) {
|
||||
resetFullWindowException = false;
|
||||
resetWindow(false);
|
||||
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
|
||||
ui->libraryButton->setStyleSheet("background: black; color: white");
|
||||
ui->libraryButton->setIcon(QIcon(":/resources/online-library-inverted.png"));
|
||||
|
||||
// Create widget
|
||||
libraryWidgetWindow = new libraryWidget();
|
||||
connect(libraryWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(resetFullWindow()));
|
||||
libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->stackedWidget->insertWidget(3, libraryWidgetWindow);
|
||||
global::mainwindow::tabSwitcher::libraryWidgetCreated = true;
|
||||
// Create widget
|
||||
libraryWidgetWindow = new libraryWidget();
|
||||
connect(libraryWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(resetFullWindow()));
|
||||
libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->stackedWidget->insertWidget(3, libraryWidgetWindow);
|
||||
global::mainwindow::tabSwitcher::libraryWidgetCreated = true;
|
||||
|
||||
// Switch tab
|
||||
ui->stackedWidget->setCurrentIndex(3);
|
||||
global::mainwindow::tabSwitcher::libraryWidgetSelected = true;
|
||||
// Switch tab
|
||||
ui->stackedWidget->setCurrentIndex(3);
|
||||
global::mainwindow::tabSwitcher::libraryWidgetSelected = true;
|
||||
|
||||
// Repaint
|
||||
this->repaint();
|
||||
// Repaint
|
||||
this->repaint();
|
||||
}
|
||||
}
|
||||
else {
|
||||
;
|
||||
showToast("Wi-Fi connection error");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
void openUsbmsDialog();
|
||||
void resetIcons();
|
||||
void setBatteryIcon();
|
||||
int testPing();
|
||||
bool checkWifiState();
|
||||
|
||||
public slots:
|
||||
|
|
Loading…
Reference in a new issue