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 bool librarySearchDialog;
inline bool libraryResults;
inline bool librarySyncDialog;
}
namespace bookInfoDialog {
inline bool localInfoDialog;

View file

@ -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);

View file

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

View file

@ -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();

View file

@ -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("<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 {
// 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()
{

View file

@ -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