diff --git a/functions.h b/functions.h index 563010e..d8b3413 100644 --- a/functions.h +++ b/functions.h @@ -257,6 +257,18 @@ namespace { checkconfig_str_val = ""; } } + QString readFile(QString file) { + if(QFile::exists(file)) { + QFile fileToRead(file); + fileToRead.open(QIODevice::ReadOnly); + QTextStream in (&fileToRead); + QString content = in.readAll(); + return content; + } + else { + return NULL; + } + } void brightness_writeconfig(int value) { std::ofstream fhandler; fhandler.open(".config/03-brightness/config"); diff --git a/librarywidget.cpp b/librarywidget.cpp index d8b1a65..55b0ec9 100644 --- a/librarywidget.cpp +++ b/librarywidget.cpp @@ -4,17 +4,156 @@ #include #include +#include +#include +#include libraryWidget::libraryWidget(QWidget *parent) : QWidget(parent), ui(new Ui::libraryWidget) { ui->setupUi(this); + ui->recentlyAddedLabel->hide(); + ui->booksStackedWidget->hide(); + + int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Italic.ttf"); + QString family = QFontDatabase::applicationFontFamilies(id).at(0); + QFont crimson_italic(family); + ui->book1Btn->setText(""); ui->book2Btn->setText(""); ui->book3Btn->setText(""); ui->book4Btn->setText(""); + ui->book5Btn->setText(""); + ui->book6Btn->setText(""); + ui->book7Btn->setText(""); + ui->book8Btn->setText(""); + ui->book1Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book2Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book3Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book4Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book5Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book6Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book7Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book8Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book9Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book10Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book11Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book12Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book13Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book14Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book15Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book16Label->setStyleSheet("font-size: 9pt; font-style: italic"); + ui->book1Label->setFont(crimson_italic); + ui->book2Label->setFont(crimson_italic); + ui->book3Label->setFont(crimson_italic); + ui->book4Label->setFont(crimson_italic); + ui->book5Label->setFont(crimson_italic); + ui->book6Label->setFont(crimson_italic); + ui->book7Label->setFont(crimson_italic); + ui->book8Label->setFont(crimson_italic); + ui->book9Label->setFont(crimson_italic); + ui->book10Label->setFont(crimson_italic); + ui->book11Label->setFont(crimson_italic); + ui->book12Label->setFont(crimson_italic); + ui->book13Label->setFont(crimson_italic); + ui->book14Label->setFont(crimson_italic); + ui->book15Label->setFont(crimson_italic); + ui->book16Label->setFont(crimson_italic); + // Getting the screen's size + sW = QGuiApplication::screens()[0]->size().width(); + sH = QGuiApplication::screens()[0]->size().height(); + + // Prevent abusive sync + string_checkconfig_ro("/external_root/opt/storage/gutenberg/last_sync"); + if(!checkconfig_str_val.isEmpty()) { + unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch(); + unsigned long syncEpoch = checkconfig_str_val.toULong(); + unsigned long allowSyncEpoch = syncEpoch + 86400; + if(currentEpoch > allowSyncEpoch) { + syncCatalog(); + } + else { + setupView(); + } + } + else { + syncCatalog(); + } +} + +libraryWidget::~libraryWidget() +{ + delete ui; +} + +void libraryWidget::setupView() { + ui->recentlyAddedLabel->show(); + ui->booksStackedWidget->show(); + + stdIconWidth = sW / 5.5; + stdIconHeight = sH / 5.5; + + ui->book1Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/1/cover.jpg")); + ui->book1Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book2Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/2/cover.jpg")); + ui->book2Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book3Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/3/cover.jpg")); + ui->book3Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book4Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/4/cover.jpg")); + ui->book4Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book5Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/5/cover.jpg")); + ui->book5Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book6Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/6/cover.jpg")); + ui->book6Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book7Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/7/cover.jpg")); + ui->book7Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book8Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/8/cover.jpg")); + ui->book8Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book9Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/9/cover.jpg")); + ui->book9Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book10Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/10/cover.jpg")); + ui->book10Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book11Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/11/cover.jpg")); + ui->book11Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book12Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/12/cover.jpg")); + ui->book12Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book13Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/13/cover.jpg")); + ui->book13Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book14Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/14/cover.jpg")); + ui->book14Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book15Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/15/cover.jpg")); + ui->book15Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->book16Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/16/cover.jpg")); + ui->book16Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + + ui->book1Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/1/title")); + ui->book2Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/2/title")); + ui->book3Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/3/title")); + ui->book4Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/4/title")); + ui->book5Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/5/title")); + ui->book6Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/6/title")); + ui->book7Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/7/title")); + ui->book8Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/8/title")); + ui->book9Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/9/title")); + ui->book10Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/10/title")); + ui->book11Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/11/title")); + ui->book12Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/12/title")); + ui->book13Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/13/title")); + ui->book14Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/14/title")); + ui->book15Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/15/title")); + ui->book16Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/16/title")); +} + +void libraryWidget::showToast(QString messageToDisplay) { + global::toast::message = messageToDisplay; + toastWindow = new toast(this); + toastWindow->setAttribute(Qt::WA_DeleteOnClose); + toastWindow->show(); +} + +void libraryWidget::syncCatalog() { global::toast::modalToast = true; global::toast::indefiniteToast = true; showToast("Sync in progress"); @@ -40,19 +179,3 @@ libraryWidget::libraryWidget(QWidget *parent) : } ); syncCheckTimer->start(); } - -libraryWidget::~libraryWidget() -{ - delete ui; -} - -void libraryWidget::setupView() { - -} - -void libraryWidget::showToast(QString messageToDisplay) { - global::toast::message = messageToDisplay; - toastWindow = new toast(this); - toastWindow->setAttribute(Qt::WA_DeleteOnClose); - toastWindow->show(); -} diff --git a/librarywidget.h b/librarywidget.h index 0a772bf..8936a27 100644 --- a/librarywidget.h +++ b/librarywidget.h @@ -15,12 +15,17 @@ class libraryWidget : public QWidget public: explicit libraryWidget(QWidget *parent = nullptr); ~libraryWidget(); + float sH; + float sW; + float stdIconHeight; + float stdIconWidth; private: Ui::libraryWidget * ui; toast * toastWindow; private slots: + void syncCatalog(); void setupView(); void showToast(QString messageToDisplay); diff --git a/librarywidget.ui b/librarywidget.ui index 456d207..903ba12 100644 --- a/librarywidget.ui +++ b/librarywidget.ui @@ -14,81 +14,419 @@ Form + + 0 + + + 0 + + + 0 + + + 0 + - - - - - - - Book 1 - - - - - - - Book 3 - - - - - - - Book 2 - - - - - - - Book 4 - - - - - - - Book 1 - - - Qt::AlignCenter - - - - - - - Book 2 - - - Qt::AlignCenter - - - - - - - Book 3 - - - Qt::AlignCenter - - - - - - - Book 4 - - - Qt::AlignCenter - - - - + + + 0 + + + + + Qt::Vertical + + + + 20 + 40 + + + - + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Book 7 + + + Qt::AlignCenter + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Book 3 + + + + + + + Book 4 + + + + + + + Book 3 + + + Qt::AlignCenter + + + true + + + + + + + Book 5 + + + + + + + Book 1 + + + Qt::AlignCenter + + + true + + + + + + + Book 6 + + + + + + + Book 5 + + + Qt::AlignCenter + + + true + + + + + + + Book 2 + + + + + + + Book 2 + + + Qt::AlignCenter + + + true + + + + + + + Book 4 + + + Qt::AlignCenter + + + true + + + + + + + Book 7 + + + + + + + Book 8 + + + Qt::AlignCenter + + + true + + + + + + + Book 1 + + + + + + + Book 8 + + + + + + + Book 6 + + + Qt::AlignCenter + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Book 10 + + + + + + + Book 10 + + + Qt::AlignCenter + + + + + + + Book 12 + + + Qt::AlignCenter + + + + + + + Book 14 + + + + + + + Book 16 + + + + + + + Book 9 + + + + + + + Book 9 + + + Qt::AlignCenter + + + + + + + Book 13 + + + + + + + Book 11 + + + + + + + Book 11 + + + Qt::AlignCenter + + + + + + + Book 12 + + + + + + + Book 15 + + + + + + + Book 13 + + + Qt::AlignCenter + + + + + + + Book 14 + + + Qt::AlignCenter + + + + + + + Book 15 + + + Qt::AlignCenter + + + + + + + Book 16 + + + Qt::AlignCenter + + + + + + + + + + + + + + 75 + true + + + + Recently added books on Gutenberg + + + + Qt::Vertical diff --git a/reader.cpp b/reader.cpp index e17f53a..9c6d875 100644 --- a/reader.cpp +++ b/reader.cpp @@ -322,7 +322,7 @@ reader::reader(QWidget *parent) : // Defining what the icons' size will be if(checkconfig("/opt/inkbox_genuine") == true) { string_checkconfig_ro("/opt/inkbox_device"); - if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n" or checkconfig_str_val == "n613\n") { + if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n" or checkconfig_str_val == "n613\n" or checkconfig_str_val == "emu\n") { float stdIconWidth = sW / 16; float stdIconHeight = sW / 16; QPixmap chargingPixmap(":/resources/battery_charging.png");