From 87082460655945c6742f7e0e13b2ecc159174829 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Mon, 27 Jun 2022 02:40:34 -0400 Subject: [PATCH] Local library: Allow opening books which have spaces in filenames This commit also fixes a segmentation fault that would be caused when deleting libraryWidget (Gutenberg) that first appeared in 4a104522f54f4a8ade41f64a16bb7a24cfe0f337. TODO: Handle what happens when there are no books in the library TODO: Re-generate database upon exiting USBMS session or books download (libraryWidget) TODO: Adjust various icon width/height variables depending on the device --- locallibrarywidget.cpp | 56 ++++++++++++++++++++++++++++++++---------- locallibrarywidget.h | 2 ++ mainwindow.cpp | 2 +- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/locallibrarywidget.cpp b/locallibrarywidget.cpp index 2d8e85c..4cf1479 100644 --- a/locallibrarywidget.cpp +++ b/locallibrarywidget.cpp @@ -20,24 +20,24 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) : ui->pageNumberLabel->setFont(QFont("Source Serif Pro")); ui->verticalLayout->setSpacing(4); - if(global::deviceID == "n705\n" or global::deviceID == "n905\n") { - buttonsNumber = 4; + if(global::deviceID == "n705\n") { + buttonsNumber = 3; } - else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") { - buttonsNumber = 5; - } - else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") { + else if(global::deviceID == "n873\n") { buttonsNumber = 5; } else { buttonsNumber = 4; } - if(global::deviceID == "n873\n") { - bookTitleTruncateThreshold = 50; + if(global::deviceID == "n705\n") { + bookTitleTruncateThreshold = 30; + } + else if(global::deviceID == "n873\n") { + bookTitleTruncateThreshold = 45; } else { - bookTitleTruncateThreshold = 40; + bookTitleTruncateThreshold = 35; } bookIconArray.resize(buttonsNumber); @@ -49,8 +49,36 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) : sW = QGuiApplication::screens()[0]->size().width(); sH = QGuiApplication::screens()[0]->size().height(); - stdIconWidth = sW / 9.5; - stdIconHeight = sH / 9.5; + if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "kt\n") { + stdIconWidthDivider = 9.5; + stdIconHeightDivider = 9.5; + stdIconWidth = sW / stdIconWidthDivider; + stdIconHeight = sH / stdIconHeightDivider; + } + else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") { + stdIconWidthDivider = 8.5; + stdIconHeightDivider = 8.5; + stdIconWidth = sW / stdIconWidthDivider; + stdIconWidth = sH / stdIconHeightDivider; + } + else if(global::deviceID == "n437\n") { + stdIconWidthDivider = 7.5; + stdIconHeightDivider = 7.5; + stdIconWidth = sW / stdIconWidthDivider; + stdIconHeight = sH / stdIconHeightDivider; + } + else if(global::deviceID == "n873\n") { + stdIconWidthDivider = 7.5; + stdIconHeightDivider = 7.5; + stdIconWidth = sW / stdIconWidthDivider; + stdIconHeight = sH / stdIconHeightDivider; + } + else { + stdIconWidthDivider = 9.5; + stdIconHeightDivider = 9.5; + stdIconWidth = sW / stdIconWidthDivider; + stdIconHeight = sH / stdIconHeightDivider; + } for(int i = 1; i <= buttonsNumber; i++) { // Horizontal layout that will contain the book button and its icon @@ -91,6 +119,7 @@ localLibraryWidget::~localLibraryWidget() } void localLibraryWidget::setupDatabase() { + QString localLibraryDatabasePathRaw = "/inkbox/LocalLibrary.db.raw"; QString localLibraryDatabasePath = "/mnt/onboard/onboard/.inkbox/LocalLibrary.db"; setDefaultWorkDir(); if(!QFile::exists(localLibraryDatabasePath)) { @@ -111,11 +140,12 @@ void localLibraryWidget::setupDatabase() { QString prog("busybox-initrd"); QStringList args; - args << "sh" << "explore_local_library.sh" << booksList; + args << "env" << "icon_width_divider=" + QString::number(stdIconWidthDivider) << "icon_height_divider=" + QString::number(stdIconHeightDivider) << "./explore_local_library.sh" << booksList; QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); - QJsonDocument jsonDocument = QJsonDocument::fromJson(proc->readAllStandardOutput()); + QJsonDocument jsonDocument = QJsonDocument::fromJson(readFile(localLibraryDatabasePathRaw).toUtf8()); + QFile::remove(localLibraryDatabasePathRaw); proc->deleteLater(); // Write database in compressed form, encoded in Base64 format diff --git a/locallibrarywidget.h b/locallibrarywidget.h index 746966c..5f9d47c 100644 --- a/locallibrarywidget.h +++ b/locallibrarywidget.h @@ -23,6 +23,8 @@ public: int buttonsNumber; int sW; int sH; + float stdIconWidthDivider; + float stdIconHeightDivider; int stdIconWidth; int stdIconHeight; QJsonDocument databaseJsonDocument; diff --git a/mainwindow.cpp b/mainwindow.cpp index 965dc06..9d0f664 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -934,7 +934,7 @@ void MainWindow::on_libraryButton_clicked() ui->libraryButton->setIcon(QIcon(":/resources/online-library-inverted.png")); // Create widget - libraryWidget * libraryWidgetWindow = new libraryWidget(); + libraryWidgetWindow = new libraryWidget(); connect(libraryWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(resetFullWindow())); libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose); ui->stackedWidget->insertWidget(3, libraryWidgetWindow);