Implement local book info dialog

This commit is contained in:
Nicolas Mailloux 2022-07-12 12:34:36 -04:00
parent 80bdeb32ed
commit 03c2732aff
9 changed files with 120 additions and 58 deletions

View file

@ -30,57 +30,95 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) :
stdIconWidth = sW / 4; stdIconWidth = sW / 4;
stdIconHeight = sH / 4; stdIconHeight = sH / 4;
if(global::library::isLatestBook == true) { if(global::bookInfoDialog::localInfoDialog == false) {
QString bookNumberQstr = QString::number(global::library::latestBookNumber); if(global::library::isLatestBook == true) {
QString bookNumberQstr = QString::number(global::library::latestBookNumber);
QString coverPath = "/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/"; QString coverPath = "/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/";
coverPath = coverPath.append(bookNumberQstr); coverPath = coverPath.append(bookNumberQstr);
coverPath = coverPath.append("/cover.jpg"); coverPath = coverPath.append("/cover.jpg");
QString idPath = "/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/"; QString idPath = "/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/";
idPath = idPath.append(bookNumberQstr); idPath = idPath.append(bookNumberQstr);
idPath = idPath.append("/id"); idPath = idPath.append("/id");
global::library::bookId = readFile(idPath).toULong(); global::library::bookId = readFile(idPath).toULong();
QPixmap coverPixmap(coverPath); QPixmap coverPixmap(coverPath);
QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio); QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->bookCoverLabel->setPixmap(scaledCoverPixmap); ui->bookCoverLabel->setPixmap(scaledCoverPixmap);
global::library::isLatestBook = false; global::library::isLatestBook = false;
ui->bookTitleLabel->setText(global::library::bookTitle); ui->bookTitleLabel->setText(global::library::bookTitle);
} }
else { else {
ui->bookTitleLabel->setText(global::library::bookTitle); ui->bookTitleLabel->setText(global::library::bookTitle);
QDir gutenbergDir; QDir gutenbergDir;
gutenbergDir.mkpath("/inkbox/gutenberg"); gutenbergDir.mkpath("/inkbox/gutenberg");
string_writeconfig("/inkbox/gutenberg/bookid", QString::number(global::library::bookId).toStdString()); string_writeconfig("/inkbox/gutenberg/bookid", QString::number(global::library::bookId).toStdString());
string_writeconfig("/opt/ibxd", "gutenberg_get_cover\n"); string_writeconfig("/opt/ibxd", "gutenberg_get_cover\n");
while(true) { while(true) {
if(QFile::exists("/inkbox/gutenberg/getCoverDone")) { if(QFile::exists("/inkbox/gutenberg/getCoverDone")) {
if(checkconfig("/inkbox/gutenberg/getCoverDone") == true) { if(checkconfig("/inkbox/gutenberg/getCoverDone") == true) {
QPixmap coverPixmap("/inkbox/gutenberg/book_cover.jpg"); QPixmap coverPixmap("/inkbox/gutenberg/book_cover.jpg");
QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio); QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->bookCoverLabel->setPixmap(scaledCoverPixmap); ui->bookCoverLabel->setPixmap(scaledCoverPixmap);
QFile::remove("/inkbox/gutenberg/getCoverDone"); QFile::remove("/inkbox/gutenberg/getCoverDone");
break; break;
} }
else { else {
QPixmap coverPixmap(":/resources/cover_unavailable.png"); QPixmap coverPixmap(":/resources/cover_unavailable.png");
QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio); QPixmap scaledCoverPixmap = coverPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->bookCoverLabel->setPixmap(scaledCoverPixmap); ui->bookCoverLabel->setPixmap(scaledCoverPixmap);
QFile::remove("/inkbox/gutenberg/getCoverDone"); QFile::remove("/inkbox/gutenberg/getCoverDone");
break; break;
}
} }
} }
} }
log("Setting up book info dialog, ID: " + QString::number(global::library::bookId) + ", title: " + global::library::bookTitle, className);
}
else {
QJsonObject bookJsonObject = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID);
QString bookInfo;
QString title = bookJsonObject["Title"].toString();
QString author = bookJsonObject["Author"].toString();
QString publicationDate = bookJsonObject["PublicationDate"].toString();
QString path = bookJsonObject["BookPath"].toString();
if(!title.isEmpty()) {
bookInfo.append("<b>Title:</b> " + title + "<br>");
}
if(!author.isEmpty()) {
bookInfo.append("<b>Author:</b> " + author + "<br>");
}
if(!publicationDate.isEmpty()) {
bookInfo.append("<b>Publication date:</b> " + publicationDate + "<br>");
}
if(!path.isEmpty()) {
bookInfo.append("<b>Path:</b> " + path + "<br>");
}
log(bookInfo, className);
global::text::textBrowserContents = bookInfo;
textwidget * textwidgetWindow = new textwidget(this);
ui->stackedWidget->insertWidget(1, textwidgetWindow);
ui->stackedWidget->setCurrentIndex(1);
} }
log("Setting up book info dialog, ID: " + QString::number(global::library::bookId) + ", title: " + global::library::bookTitle, className); QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
{
int wx = screenGeometry.width();
int x = wx - 25;
int y = this->height() * determineYIncrease();
this->setFixedWidth(x);
this->setFixedHeight(y);
this->adjustSize();
}
// Centering dialog // Centering dialog
this->adjustSize();
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
int x = (screenGeometry.width() - this->width()) / 2; int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2; int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y); this->move(x, y);
@ -94,6 +132,7 @@ bookInfoDialog::~bookInfoDialog()
void bookInfoDialog::on_closeBtn_clicked() void bookInfoDialog::on_closeBtn_clicked()
{ {
global::library::bookTitle = ""; global::library::bookTitle = "";
global::bookInfoDialog::localInfoDialog = false;
bookInfoDialog::close(); bookInfoDialog::close();
} }

View file

@ -3,6 +3,8 @@
#include <QDialog> #include <QDialog>
#include "textwidget.h"
namespace Ui { namespace Ui {
class bookInfoDialog; class bookInfoDialog;
} }
@ -30,7 +32,8 @@ signals:
void closeIndefiniteToast(); void closeIndefiniteToast();
private: private:
Ui::bookInfoDialog *ui; Ui::bookInfoDialog * ui;
textwidget * textwidgetWindow;
}; };
#endif // BOOKINFODIALOG_H #endif // BOOKINFODIALOG_H

View file

@ -183,7 +183,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_2"/> <widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3"/>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>

View file

@ -35,9 +35,7 @@ void bookOptionsDialog::on_deleteBtn_clicked()
ui->deleteBtn->setStyleSheet("padding: 10px; color: lightGrey"); ui->deleteBtn->setStyleSheet("padding: 10px; color: lightGrey");
} }
void bookOptionsDialog::on_infoBtn_clicked() void bookOptionsDialog::on_infoBtn_clicked()
{ {
// TODO emit openLocalBookInfoDialog();
} }

View file

@ -23,6 +23,9 @@ private slots:
void on_deleteBtn_clicked(); void on_deleteBtn_clicked();
void on_infoBtn_clicked(); void on_infoBtn_clicked();
signals:
void openLocalBookInfoDialog();
private: private:
Ui::bookOptionsDialog *ui; Ui::bookOptionsDialog *ui;
}; };

View file

@ -126,6 +126,9 @@ namespace global {
inline bool librarySearchDialog; inline bool librarySearchDialog;
inline bool libraryResults; inline bool libraryResults;
} }
namespace bookInfoDialog {
inline bool localInfoDialog;
}
namespace localLibrary { namespace localLibrary {
static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw"; static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw";
static inline QString databaseDirectoryPath = "/mnt/onboard/onboard/.database/"; static inline QString databaseDirectoryPath = "/mnt/onboard/onboard/.database/";
@ -184,7 +187,7 @@ namespace {
int defaultPdfPageHeight; int defaultPdfPageHeight;
bool checked_box = false; bool checked_box = false;
QFile logFile("/external_root/var/log/inkbox-gui.log"); QFile logFile("/external_root/var/log/inkbox-gui.log");
void log(QString message, QString className, bool applicationStart = false) { void log(QString message, QString className = "undefined", bool applicationStart = false) {
if(global::logger::status == true) { if(global::logger::status == true) {
QString initialTime; QString initialTime;
if(applicationStart == true) { if(applicationStart == true) {
@ -1001,6 +1004,20 @@ namespace {
QJsonArray jsonArrayList = jsonObject["database"].toArray(); QJsonArray jsonArrayList = jsonObject["database"].toArray();
return jsonArrayList.at(bookID - 1).toObject(); return jsonArrayList.at(bookID - 1).toObject();
} }
float determineYIncrease() {
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
return 2;
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
return 2.6;
}
else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") {
return 3;
}
else {
return 2;
}
}
} }
#endif // FUNCTIONS_H #endif // FUNCTIONS_H

View file

@ -359,9 +359,10 @@ void localLibraryWidget::showToast(QString messageToDisplay) {
} }
void localLibraryWidget::openBookOptionsDialog(int bookID) { void localLibraryWidget::openBookOptionsDialog(int bookID) {
log("Opening book options dialog for book with ID " + QString::number(bookID), className); log("Opening book options dialog for book with pseudo-ID " + QString::number(bookID), className);
global::localLibrary::bookOptionsDialog::bookID = bookID; global::localLibrary::bookOptionsDialog::bookID = bookID;
bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this); bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion); QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion);
bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose); bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
@ -377,3 +378,10 @@ void localLibraryWidget::handlePossibleBookDeletion() {
QTimer::singleShot(100, this, SLOT(setupDisplay())); QTimer::singleShot(100, this, SLOT(setupDisplay()));
} }
} }
void localLibraryWidget::openLocalBookInfoDialog() {
global::bookInfoDialog::localInfoDialog = true;
bookInfoDialog * bookInfoDialogWindow = new bookInfoDialog(this);
bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookInfoDialogWindow->show();
}

View file

@ -10,6 +10,7 @@
#include "generaldialog.h" #include "generaldialog.h"
#include "toast.h" #include "toast.h"
#include "bookoptionsdialog.h" #include "bookoptionsdialog.h"
#include "bookinfodialog.h"
namespace Ui { namespace Ui {
class localLibraryWidget; class localLibraryWidget;
@ -55,12 +56,14 @@ private slots:
void showToast(QString messageToDisplay); void showToast(QString messageToDisplay);
void openBookOptionsDialog(int bookID); void openBookOptionsDialog(int bookID);
void handlePossibleBookDeletion(); void handlePossibleBookDeletion();
void openLocalBookInfoDialog();
private: private:
Ui::localLibraryWidget * ui; Ui::localLibraryWidget * ui;
generalDialog * generalDialogWindow; generalDialog * generalDialogWindow;
bookOptionsDialog * bookOptionsDialogWindow; bookOptionsDialog * bookOptionsDialogWindow;
toast * toastWindow; toast * toastWindow;
bookInfoDialog * bookInfoDialogWindow;
QVector<QHBoxLayout*> horizontalLayoutArray; QVector<QHBoxLayout*> horizontalLayoutArray;
QVector<QLabel*> bookIconArray; QVector<QLabel*> bookIconArray;
QVector<QClickableLabel*> bookBtnArray; QVector<QClickableLabel*> bookBtnArray;

View file

@ -822,18 +822,7 @@ void settings::on_showSystemInfoBtn_clicked()
// Show a system info dialog // Show a system info dialog
log("Showing system info dialog", className); log("Showing system info dialog", className);
generalDialogWindow = new generalDialog(); generalDialogWindow = new generalDialog();
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") { generalDialogWindow->yIncrease = determineYIncrease();
generalDialogWindow->yIncrease = 2;
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
generalDialogWindow->yIncrease = 2.6;
}
else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") {
generalDialogWindow->yIncrease = 3;
}
else {
generalDialogWindow->yIncrease = 2;
}
generalDialogWindow->increaseSize(); generalDialogWindow->increaseSize();
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
} }