Online library progressing

This commit is contained in:
Nicolas Mailloux 2021-12-26 19:08:21 -05:00
parent fa1e05af99
commit cbd7f2c7de
5 changed files with 568 additions and 90 deletions

View file

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

View file

@ -4,17 +4,156 @@
#include <QProcess>
#include <QDebug>
#include <QDateTime>
#include <QScreen>
#include <QFontDatabase>
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();
}

View file

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

View file

@ -14,81 +14,419 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QPushButton" name="book1Btn">
<property name="text">
<string>Book 1</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="book3Btn">
<property name="text">
<string>Book 3</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="book2Btn">
<property name="text">
<string>Book 2</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="book4Btn">
<property name="text">
<string>Book 4</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="book1Label">
<property name="text">
<string>Book 1</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="book2Label">
<property name="text">
<string>Book 2</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="book3Label">
<property name="text">
<string>Book 3</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="book4Label">
<property name="text">
<string>Book 4</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" name="gridLayout_3">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<item row="4" column="0">
<widget class="QStackedWidget" name="booksStackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="3">
<widget class="QLabel" name="book7Label">
<property name="text">
<string>Book 7</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="book3Btn">
<property name="text">
<string>Book 3</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="book4Btn">
<property name="text">
<string>Book 4</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="book3Label">
<property name="text">
<string>Book 3</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="book5Btn">
<property name="text">
<string>Book 5</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="book1Label">
<property name="text">
<string>Book 1</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="book6Btn">
<property name="text">
<string>Book 6</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="book5Label">
<property name="text">
<string>Book 5</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="book2Btn">
<property name="text">
<string>Book 2</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="book2Label">
<property name="text">
<string>Book 2</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QLabel" name="book4Label">
<property name="text">
<string>Book 4</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="book7Btn">
<property name="text">
<string>Book 7</string>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QLabel" name="book8Label">
<property name="text">
<string>Book 8</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="book1Btn">
<property name="text">
<string>Book 1</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="book8Btn">
<property name="text">
<string>Book 8</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="book6Label">
<property name="text">
<string>Book 6</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="5">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="book10Btn">
<property name="text">
<string>Book 10</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="book10Label">
<property name="text">
<string>Book 10</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="book12Label">
<property name="text">
<string>Book 12</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="book14Btn">
<property name="text">
<string>Book 14</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="book16Btn">
<property name="text">
<string>Book 16</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="book9Btn">
<property name="text">
<string>Book 9</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="book9Label">
<property name="text">
<string>Book 9</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="book13Btn">
<property name="text">
<string>Book 13</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="book11Btn">
<property name="text">
<string>Book 11</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="book11Label">
<property name="text">
<string>Book 11</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="book12Btn">
<property name="text">
<string>Book 12</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="book15Btn">
<property name="text">
<string>Book 15</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="book13Label">
<property name="text">
<string>Book 13</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="book14Label">
<property name="text">
<string>Book 14</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="book15Label">
<property name="text">
<string>Book 15</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="book16Label">
<property name="text">
<string>Book 16</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="recentlyAddedLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Recently added books on Gutenberg</string>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>

View file

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