diff --git a/src/functions.h b/src/functions.h index f274ed7..64ecd68 100644 --- a/src/functions.h +++ b/src/functions.h @@ -130,6 +130,7 @@ namespace global { inline QString bookTitle; inline bool librarySearchDialog; inline bool libraryResults; + inline bool librarySyncDialog; } namespace bookInfoDialog { inline bool localInfoDialog; diff --git a/src/homeWidget/mainwindow.cpp b/src/homeWidget/mainwindow.cpp index 08e7fa0..613c282 100644 --- a/src/homeWidget/mainwindow.cpp +++ b/src/homeWidget/mainwindow.cpp @@ -949,25 +949,31 @@ void MainWindow::on_libraryButton_clicked() { log("Launching Online Library", className); if(testPing() == 0 or global::deviceID == "emu\n") { - 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")); + // 'Do you want to sync?' dialog + bool willSync = false; + QString syncEpochQStr = readFile("/external_root/opt/storage/gutenberg/last_sync"); + if(!syncEpochQStr.isEmpty()) { + 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 - 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(); + if(willSync == true) { + global::library::librarySyncDialog = true; + generalDialogWindow = new generalDialog(this); + QObject::connect(generalDialogWindow, &generalDialog::syncOnlineLibrary, this, &MainWindow::launchOnlineLibrary); + QObject::connect(generalDialogWindow, &generalDialog::noSyncOnlineLibrary, this, &MainWindow::on_homeBtn_clicked); + generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); + generalDialogWindow->show(); + } + else { + launchOnlineLibrary(); } } 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() { if(resetFullWindowException == false) { resetWindow(true); diff --git a/src/homeWidget/mainwindow.h b/src/homeWidget/mainwindow.h index 48e994f..3bc787a 100644 --- a/src/homeWidget/mainwindow.h +++ b/src/homeWidget/mainwindow.h @@ -101,6 +101,7 @@ private slots: void resetFullWindow(); void setupLocalLibraryWidget(); void setupHomePageWidget(); + void launchOnlineLibrary(); private: Ui::MainWindow * ui; diff --git a/src/onlineLibrary/librarywidget.cpp b/src/onlineLibrary/librarywidget.cpp index 0d075d1..7c269c1 100644 --- a/src/onlineLibrary/librarywidget.cpp +++ b/src/onlineLibrary/librarywidget.cpp @@ -62,6 +62,14 @@ libraryWidget::libraryWidget(QWidget *parent) : ui->book6Btn->setText(""); ui->book7Btn->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") { ui->book9Btn->setText(""); ui->book10Btn->setText(""); @@ -71,6 +79,14 @@ libraryWidget::libraryWidget(QWidget *parent) : ui->book14Btn->setText(""); ui->book15Btn->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 { ui->book9Btn->hide(); diff --git a/src/widgets/dialogs/generaldialog.cpp b/src/widgets/dialogs/generaldialog.cpp index ec527d5..1f0053b 100644 --- a/src/widgets/dialogs/generaldialog.cpp +++ b/src/widgets/dialogs/generaldialog.cpp @@ -209,6 +209,14 @@ generalDialog::generalDialog(QWidget *parent) : yIncrease = 1.8; 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("Online library requires syncing. Do you want to continue?"); + ui->headerLabel->setText("Sync required"); + QTimer::singleShot(50, this, SLOT(adjust_size())); + } else { // We shouldn't be there ;) log("Launched without settings", className); @@ -280,6 +288,10 @@ void generalDialog::on_cancelBtn_clicked() global::userApps::appCompatibilityText = ""; global::userApps::appCompatibilityDialog = false; } + else if(global::library::librarySyncDialog == true) { + emit noSyncOnlineLibrary(); + global::library::librarySyncDialog = false; + } generalDialog::close(); } } @@ -540,10 +552,15 @@ void generalDialog::on_okBtn_clicked() else if(global::userApps::appCompatibilityDialog == true) { global::userApps::launchApp = true; 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; generalDialog::close(); } + else if(global::library::librarySyncDialog == true) { + emit syncOnlineLibrary(); + global::library::librarySyncDialog = false; + generalDialog::close(); + } } void generalDialog::on_acceptBtn_clicked() { diff --git a/src/widgets/dialogs/generaldialog.h b/src/widgets/dialogs/generaldialog.h index 9f91738..ae592fb 100644 --- a/src/widgets/dialogs/generaldialog.h +++ b/src/widgets/dialogs/generaldialog.h @@ -37,6 +37,7 @@ public: bool resetKoboxDialog = false; bool keyboardDialog = false; bool keypadDialog = false; + bool librarySyncDialog = false; bool dictionaryResults = false; bool vncServerSet = false; bool vncPasswordSet = false; @@ -90,6 +91,8 @@ signals: void openBookFile(QString book, bool relativePath); void cancelDisableStorageEncryption(); void disableStorageEncryption(); + void syncOnlineLibrary(); + void noSyncOnlineLibrary(); }; #endif // GENERALDIALOG_H