2021-12-27 12:04:39 -08:00
|
|
|
#include "bookinfodialog.h"
|
|
|
|
#include "ui_bookinfodialog.h"
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
|
|
|
bookInfoDialog::bookInfoDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::bookInfoDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-12-27 20:59:28 -08:00
|
|
|
|
|
|
|
// Stylesheet
|
|
|
|
QFile stylesheetFile(":/resources/eink.qss");
|
|
|
|
stylesheetFile.open(QFile::ReadOnly);
|
|
|
|
this->setStyleSheet(stylesheetFile.readAll());
|
|
|
|
stylesheetFile.close();
|
|
|
|
|
2021-12-27 12:04:39 -08:00
|
|
|
ui->closeBtn->setProperty("type", "borderless");
|
|
|
|
ui->closeBtn->setText("");
|
|
|
|
ui->closeBtn->setIcon(QIcon(":/resources/close.png"));
|
|
|
|
ui->bookCoverLabel->setText("");
|
|
|
|
ui->getBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px");
|
|
|
|
|
|
|
|
// Getting the screen's size
|
|
|
|
sW = QGuiApplication::screens()[0]->size().width();
|
|
|
|
sH = QGuiApplication::screens()[0]->size().height();
|
|
|
|
|
|
|
|
// Setting icons up
|
|
|
|
stdIconWidth = sW / 4;
|
|
|
|
stdIconHeight = sH / 4;
|
|
|
|
|
|
|
|
if(global::library::isLatestBook == true) {
|
|
|
|
QString bookNumberQstr = QString::number(global::library::latestBookNumber);
|
2021-12-29 20:09:51 -08:00
|
|
|
|
2021-12-27 12:04:39 -08:00
|
|
|
QString coverPath = "/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/";
|
|
|
|
coverPath = coverPath.append(bookNumberQstr);
|
|
|
|
coverPath = coverPath.append("/cover.jpg");
|
|
|
|
|
2021-12-29 20:09:51 -08:00
|
|
|
QString idPath = "/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/";
|
|
|
|
idPath = idPath.append(bookNumberQstr);
|
|
|
|
idPath = idPath.append("/id");
|
|
|
|
global::library::bookId = readFile(idPath).toULong();
|
|
|
|
|
2021-12-27 12:04:39 -08:00
|
|
|
QPixmap coverPixmap(coverPath);
|
|
|
|
QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->bookCoverLabel->setPixmap(scaledCoverPixmap);
|
|
|
|
global::library::isLatestBook = false;
|
|
|
|
|
|
|
|
ui->bookTitleLabel->setText(global::library::bookTitle);
|
|
|
|
global::library::bookTitle = "";
|
|
|
|
}
|
|
|
|
else {
|
2021-12-28 16:08:14 -08:00
|
|
|
ui->bookTitleLabel->setText(global::library::bookTitle);
|
|
|
|
global::library::bookTitle = "";
|
2021-12-27 12:04:39 -08:00
|
|
|
|
2021-12-29 20:09:51 -08:00
|
|
|
QDir gutenbergDir;
|
|
|
|
gutenbergDir.mkpath("/inkbox/gutenberg");
|
2021-12-28 16:08:14 -08:00
|
|
|
string_writeconfig("/inkbox/gutenberg/bookid", QString::number(global::library::bookId).toStdString());
|
|
|
|
string_writeconfig("/opt/ibxd", "gutenberg_get_cover\n");
|
|
|
|
while(true) {
|
|
|
|
if(QFile::exists("/inkbox/gutenberg/getCoverDone")) {
|
|
|
|
if(checkconfig("/inkbox/gutenberg/getCoverDone") == true) {
|
|
|
|
QPixmap coverPixmap("/inkbox/gutenberg/book_cover.jpg");
|
|
|
|
QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->bookCoverLabel->setPixmap(scaledCoverPixmap);
|
|
|
|
QFile::remove("/inkbox/gutenberg/getCoverDone");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QPixmap coverPixmap(":/resources/cover_unavailable.png");
|
|
|
|
QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->bookCoverLabel->setPixmap(scaledCoverPixmap);
|
|
|
|
QFile::remove("/inkbox/gutenberg/getCoverDone");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-27 12:04:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Centering dialog
|
|
|
|
this->adjustSize();
|
|
|
|
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
|
|
|
|
int x = (screenGeometry.width() - this->width()) / 2;
|
|
|
|
int y = (screenGeometry.height() - this->height()) / 2;
|
|
|
|
this->move(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bookInfoDialog::~bookInfoDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bookInfoDialog::on_closeBtn_clicked()
|
|
|
|
{
|
|
|
|
bookInfoDialog::close();
|
|
|
|
}
|
|
|
|
|
2021-12-29 20:09:51 -08:00
|
|
|
|
|
|
|
void bookInfoDialog::on_getBtn_clicked()
|
|
|
|
{
|
|
|
|
QDir gutenbergDir;
|
|
|
|
gutenbergDir.mkpath("/inkbox/gutenberg");
|
|
|
|
string_writeconfig("/inkbox/gutenberg/bookid", QString::number(global::library::bookId).toStdString());
|
|
|
|
string_writeconfig("/opt/ibxd", "gutenberg_get_book\n");
|
|
|
|
|
|
|
|
global::toast::modalToast = true;
|
|
|
|
global::toast::indefiniteToast = true;
|
|
|
|
emit showToast("Downloading");
|
|
|
|
|
|
|
|
QTimer::singleShot(500, this, SLOT(waitForBookFetch()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void bookInfoDialog::waitForBookFetch() {
|
|
|
|
while(true) {
|
|
|
|
if(QFile::exists("/inkbox/gutenberg/getBookDone")) {
|
|
|
|
if(checkconfig("/inkbox/gutenberg/getBookDone") == true) {
|
|
|
|
emit closeIndefiniteToast();
|
|
|
|
emit showToast("Download successful");
|
2021-12-29 20:12:38 -08:00
|
|
|
QFile::remove("/inkbox/gutenberg/getBookDone");
|
2021-12-29 20:09:51 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit closeIndefiniteToast();
|
|
|
|
emit showToast("Download failed");
|
2021-12-29 20:12:38 -08:00
|
|
|
QFile::remove("/inkbox/gutenberg/getBookDone");
|
2021-12-29 20:09:51 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|