mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-29 00:57:22 -08:00
Implement auto-sync if user searchs in Online Library
This commit is contained in:
parent
2ba3b42599
commit
a24b84acf4
4 changed files with 108 additions and 35 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
generalDialog::generalDialog(QWidget *parent) :
|
generalDialog::generalDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
|
@ -39,6 +40,11 @@ generalDialog::generalDialog(QWidget *parent) :
|
||||||
ui->bodyLabel->setStyleSheet("font-size: 9pt");
|
ui->bodyLabel->setStyleSheet("font-size: 9pt");
|
||||||
ui->searchComboBox->setStyleSheet("font-size: 9pt");
|
ui->searchComboBox->setStyleSheet("font-size: 9pt");
|
||||||
|
|
||||||
|
// Disabling "Online library" search if device doesn't have Wi-Fi
|
||||||
|
if(global::device::isWifiAble == false && readFile("/opt/inkbox_device") != "emu\n") {
|
||||||
|
ui->searchComboBox->removeItem(2);
|
||||||
|
}
|
||||||
|
|
||||||
if(QFile::exists("/inkbox/searchComboBoxFunction") == true) {
|
if(QFile::exists("/inkbox/searchComboBoxFunction") == true) {
|
||||||
string_checkconfig_ro("/inkbox/searchComboBoxFunction");
|
string_checkconfig_ro("/inkbox/searchComboBoxFunction");
|
||||||
if(checkconfig_str_val == "Dictionary") {
|
if(checkconfig_str_val == "Dictionary") {
|
||||||
|
@ -356,6 +362,28 @@ 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");
|
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) {
|
||||||
|
syncCatalog();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
noGutenbergSyncToDo = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
syncCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
|
QTimer * syncTimer = new QTimer(this);
|
||||||
|
syncTimer->setInterval(100);
|
||||||
|
connect(syncTimer, &QTimer::timeout, [&]() {
|
||||||
|
if(noGutenbergSyncToDo == true or (gutenbergSyncDone == true && gutenbergSyncStatus == true)) {
|
||||||
|
if(syncTimerDone == false) {
|
||||||
|
syncTimerDone = true;
|
||||||
string_writeconfig("/inkbox/gutenberg_search_request", global::keyboard::keyboardText.toStdString());
|
string_writeconfig("/inkbox/gutenberg_search_request", global::keyboard::keyboardText.toStdString());
|
||||||
string_writeconfig("/opt/ibxd", "gutenberg_search\n");
|
string_writeconfig("/opt/ibxd", "gutenberg_search\n");
|
||||||
while(true) {
|
while(true) {
|
||||||
|
@ -394,6 +422,10 @@ void generalDialog::on_okBtn_clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
syncTimer->start();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -610,3 +642,38 @@ void generalDialog::quit_restart() {
|
||||||
process.startDetached("inkbox", QStringList());
|
process.startDetached("inkbox", QStringList());
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void generalDialog::syncCatalog() {
|
||||||
|
global::toast::modalToast = true;
|
||||||
|
global::toast::indefiniteToast = true;
|
||||||
|
showToast("Sync in progress");
|
||||||
|
|
||||||
|
string_writeconfig("/opt/ibxd", "gutenberg_sync\n");
|
||||||
|
QTimer * syncCheckTimer = new QTimer(this);
|
||||||
|
syncCheckTimer->setInterval(100);
|
||||||
|
connect(syncCheckTimer, &QTimer::timeout, [&]() {
|
||||||
|
if(QFile::exists("/inkbox/gutenbergSyncDone") == true) {
|
||||||
|
if(checkconfig("/inkbox/gutenbergSyncDone") == true) {
|
||||||
|
qDebug() << "Gutenberg sync successfully completed";
|
||||||
|
gutenbergSyncDone = true;
|
||||||
|
gutenbergSyncStatus = true;
|
||||||
|
emit closeIndefiniteToast();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "Gutenberg sync encountered an error";
|
||||||
|
gutenbergSyncDone = true;
|
||||||
|
gutenbergSyncStatus = false;
|
||||||
|
emit closeIndefiniteToast();
|
||||||
|
showToast("Error");
|
||||||
|
global::keyboard::searchDialog = false;
|
||||||
|
global::forbidOpenSearchDialog = true;
|
||||||
|
global::keyboard::keyboardDialog = false;
|
||||||
|
global::keyboard::keyboardText = "";
|
||||||
|
global::library::librarySearchDialog = false;
|
||||||
|
QTimer::singleShot(5000, this, SLOT(close()));
|
||||||
|
}
|
||||||
|
QFile::remove("/inkbox/gutenbergSyncDone");
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
syncCheckTimer->start();
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ public:
|
||||||
bool dictionaryResults = false;
|
bool dictionaryResults = false;
|
||||||
bool vncServerSet = false;
|
bool vncServerSet = false;
|
||||||
bool vncPasswordSet = false;
|
bool vncPasswordSet = false;
|
||||||
|
bool gutenbergSyncDone = false;
|
||||||
|
bool gutenbergSyncStatus = false;
|
||||||
|
bool noGutenbergSyncToDo = false;
|
||||||
|
bool syncTimerDone = false;
|
||||||
QString vncServerAddress;
|
QString vncServerAddress;
|
||||||
QString vncServerPassword;
|
QString vncServerPassword;
|
||||||
QString vncServerPort;
|
QString vncServerPort;
|
||||||
|
@ -58,6 +62,7 @@ private slots:
|
||||||
void showToastNative(QString messageToDisplay);
|
void showToastNative(QString messageToDisplay);
|
||||||
void closeIndefiniteToastNative();
|
void closeIndefiniteToastNative();
|
||||||
void quit_restart();
|
void quit_restart();
|
||||||
|
void syncCatalog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::generalDialog *ui;
|
Ui::generalDialog *ui;
|
||||||
|
|
|
@ -182,6 +182,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
// Deleting/Hiding "Library" button if device is not WiFi-able
|
// Deleting/Hiding "Library" button if device is not WiFi-able
|
||||||
if(global::device::isWifiAble == false && readFile("/opt/inkbox_device") != "emu\n") {
|
if(global::device::isWifiAble == false && readFile("/opt/inkbox_device") != "emu\n") {
|
||||||
|
ui->libraryButton->hide();
|
||||||
|
ui->line_10->hide();
|
||||||
ui->libraryButton->deleteLater();
|
ui->libraryButton->deleteLater();
|
||||||
ui->line_10->deleteLater();
|
ui->line_10->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ void searchResultsWidget::setListViewContents(QStringList searchResults) {
|
||||||
void searchResultsWidget::on_openBtn_clicked()
|
void searchResultsWidget::on_openBtn_clicked()
|
||||||
{
|
{
|
||||||
if(libraryResults == true) {
|
if(libraryResults == true) {
|
||||||
qDebug() << "Got there";
|
|
||||||
index = ui->listView->currentIndex();
|
index = ui->listView->currentIndex();
|
||||||
itemText = index.data(Qt::DisplayRole).toString();
|
itemText = index.data(Qt::DisplayRole).toString();
|
||||||
if(!itemText.isEmpty()) {
|
if(!itemText.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue