Online library: Ask user if he wants to sync before doing so

This commit is contained in:
Nicolas Mailloux 2023-05-21 17:19:18 +00:00
parent b684f25fa9
commit b411c40849
6 changed files with 86 additions and 19 deletions

View file

@ -130,6 +130,7 @@ namespace global {
inline QString bookTitle; inline QString bookTitle;
inline bool librarySearchDialog; inline bool librarySearchDialog;
inline bool libraryResults; inline bool libraryResults;
inline bool librarySyncDialog;
} }
namespace bookInfoDialog { namespace bookInfoDialog {
inline bool localInfoDialog; inline bool localInfoDialog;

View file

@ -949,25 +949,31 @@ void MainWindow::on_libraryButton_clicked()
{ {
log("Launching Online Library", className); log("Launching Online Library", className);
if(testPing() == 0 or global::deviceID == "emu\n") { if(testPing() == 0 or global::deviceID == "emu\n") {
resetFullWindowException = true; // 'Do you want to sync?' dialog
resetWindow(false); bool willSync = false;
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) { QString syncEpochQStr = readFile("/external_root/opt/storage/gutenberg/last_sync");
ui->libraryButton->setStyleSheet("background: black; color: white"); if(!syncEpochQStr.isEmpty()) {
ui->libraryButton->setIcon(QIcon(":/resources/online-library-inverted.png")); unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
unsigned long syncEpoch = syncEpochQStr.toULong();
unsigned long allowSyncEpoch = syncEpoch + 86400;
if(currentEpoch > allowSyncEpoch) {
willSync = true;
}
}
else if(syncEpochQStr.isEmpty()) {
willSync = true;
}
// Create widget if(willSync == true) {
libraryWidgetWindow = new libraryWidget(); global::library::librarySyncDialog = true;
connect(libraryWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(resetFullWindow())); generalDialogWindow = new generalDialog(this);
libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose); QObject::connect(generalDialogWindow, &generalDialog::syncOnlineLibrary, this, &MainWindow::launchOnlineLibrary);
ui->stackedWidget->insertWidget(3, libraryWidgetWindow); QObject::connect(generalDialogWindow, &generalDialog::noSyncOnlineLibrary, this, &MainWindow::on_homeBtn_clicked);
global::mainwindow::tabSwitcher::libraryWidgetCreated = true; generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
generalDialogWindow->show();
// Switch tab }
ui->stackedWidget->setCurrentIndex(3); else {
global::mainwindow::tabSwitcher::libraryWidgetSelected = true; launchOnlineLibrary();
// Repaint
this->repaint();
} }
} }
else { else {
@ -975,6 +981,29 @@ void MainWindow::on_libraryButton_clicked()
} }
} }
void MainWindow::launchOnlineLibrary() {
resetFullWindowException = true;
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;
// Switch tab
ui->stackedWidget->setCurrentIndex(3);
global::mainwindow::tabSwitcher::libraryWidgetSelected = true;
// Repaint
this->repaint();
}
}
void MainWindow::resetFullWindow() { void MainWindow::resetFullWindow() {
if(resetFullWindowException == false) { if(resetFullWindowException == false) {
resetWindow(true); resetWindow(true);

View file

@ -101,6 +101,7 @@ private slots:
void resetFullWindow(); void resetFullWindow();
void setupLocalLibraryWidget(); void setupLocalLibraryWidget();
void setupHomePageWidget(); void setupHomePageWidget();
void launchOnlineLibrary();
private: private:
Ui::MainWindow * ui; Ui::MainWindow * ui;

View file

@ -62,6 +62,14 @@ libraryWidget::libraryWidget(QWidget *parent) :
ui->book6Btn->setText(""); ui->book6Btn->setText("");
ui->book7Btn->setText(""); ui->book7Btn->setText("");
ui->book8Btn->setText(""); ui->book8Btn->setText("");
ui->book1Btn->setProperty("type", "borderless");
ui->book2Btn->setProperty("type", "borderless");
ui->book3Btn->setProperty("type", "borderless");
ui->book4Btn->setProperty("type", "borderless");
ui->book5Btn->setProperty("type", "borderless");
ui->book6Btn->setProperty("type", "borderless");
ui->book7Btn->setProperty("type", "borderless");
ui->book8Btn->setProperty("type", "borderless");
if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") {
ui->book9Btn->setText(""); ui->book9Btn->setText("");
ui->book10Btn->setText(""); ui->book10Btn->setText("");
@ -71,6 +79,14 @@ libraryWidget::libraryWidget(QWidget *parent) :
ui->book14Btn->setText(""); ui->book14Btn->setText("");
ui->book15Btn->setText(""); ui->book15Btn->setText("");
ui->book16Btn->setText(""); ui->book16Btn->setText("");
ui->book9Btn->setProperty("type", "borderless");
ui->book10Btn->setProperty("type", "borderless");
ui->book11Btn->setProperty("type", "borderless");
ui->book12Btn->setProperty("type", "borderless");
ui->book13Btn->setProperty("type", "borderless");
ui->book14Btn->setProperty("type", "borderless");
ui->book15Btn->setProperty("type", "borderless");
ui->book16Btn->setProperty("type", "borderless");
} }
else { else {
ui->book9Btn->hide(); ui->book9Btn->hide();

View file

@ -209,6 +209,14 @@ generalDialog::generalDialog(QWidget *parent) :
yIncrease = 1.8; yIncrease = 1.8;
QTimer::singleShot(50, this, SLOT(increaseSize())); QTimer::singleShot(50, this, SLOT(increaseSize()));
} }
else if(global::library::librarySyncDialog == true) {
librarySyncDialog = true;
ui->okBtn->setText("Continue");
ui->cancelBtn->setText("Not now");
ui->bodyLabel->setText("<font face='u001'>Online library requires syncing. Do you want to continue</font><font face='Inter'>?</font>");
ui->headerLabel->setText("Sync required");
QTimer::singleShot(50, this, SLOT(adjust_size()));
}
else { else {
// We shouldn't be there ;) // We shouldn't be there ;)
log("Launched without settings", className); log("Launched without settings", className);
@ -280,6 +288,10 @@ void generalDialog::on_cancelBtn_clicked()
global::userApps::appCompatibilityText = ""; global::userApps::appCompatibilityText = "";
global::userApps::appCompatibilityDialog = false; global::userApps::appCompatibilityDialog = false;
} }
else if(global::library::librarySyncDialog == true) {
emit noSyncOnlineLibrary();
global::library::librarySyncDialog = false;
}
generalDialog::close(); generalDialog::close();
} }
} }
@ -540,10 +552,15 @@ void generalDialog::on_okBtn_clicked()
else if(global::userApps::appCompatibilityDialog == true) { else if(global::userApps::appCompatibilityDialog == true) {
global::userApps::launchApp = true; global::userApps::launchApp = true;
global::userApps::appCompatibilityText = ""; global::userApps::appCompatibilityText = "";
global::userApps::appCompatibilityLastContinueStatus = true; // Not really necceserry, only if something fails horibly global::userApps::appCompatibilityLastContinueStatus = true; // Not really necessary, only needed if something fails horribly
global::userApps::appCompatibilityDialog = false; global::userApps::appCompatibilityDialog = false;
generalDialog::close(); generalDialog::close();
} }
else if(global::library::librarySyncDialog == true) {
emit syncOnlineLibrary();
global::library::librarySyncDialog = false;
generalDialog::close();
}
} }
void generalDialog::on_acceptBtn_clicked() void generalDialog::on_acceptBtn_clicked()
{ {

View file

@ -37,6 +37,7 @@ public:
bool resetKoboxDialog = false; bool resetKoboxDialog = false;
bool keyboardDialog = false; bool keyboardDialog = false;
bool keypadDialog = false; bool keypadDialog = false;
bool librarySyncDialog = false;
bool dictionaryResults = false; bool dictionaryResults = false;
bool vncServerSet = false; bool vncServerSet = false;
bool vncPasswordSet = false; bool vncPasswordSet = false;
@ -90,6 +91,8 @@ signals:
void openBookFile(QString book, bool relativePath); void openBookFile(QString book, bool relativePath);
void cancelDisableStorageEncryption(); void cancelDisableStorageEncryption();
void disableStorageEncryption(); void disableStorageEncryption();
void syncOnlineLibrary();
void noSyncOnlineLibrary();
}; };
#endif // GENERALDIALOG_H #endif // GENERALDIALOG_H