diff --git a/src/eink.qrc b/src/eink.qrc
index 50965c7..5d9ea32 100644
--- a/src/eink.qrc
+++ b/src/eink.qrc
@@ -15,6 +15,8 @@
resources/close.png
resources/chevron-left.png
resources/chevron-right.png
+ resources/chevron-down.png
+ resources/chevron-up.png
resources/christie.png
resources/exit.png
resources/usbms.png
@@ -103,5 +105,7 @@
resources/checkbox-checked-small.png
resources/checkbox-x-small.png
resources/checkbox-x.png
+ resources/folder.png
+ resources/question-mark.png
diff --git a/src/functions.h b/src/functions.h
index 8cb91fb..4c52d51 100644
--- a/src/functions.h
+++ b/src/functions.h
@@ -141,12 +141,16 @@ namespace global {
static inline QString pinnedBooksDatabasePath = databaseDirectoryPath + "PinnedBooks.db";
static inline QString highlightsDatabasePath = databaseDirectoryPath + "Highlights.db";
static inline QString todoDatabasePath = databaseDirectoryPath + "ToDo.db";
+ // Maximum signed integer value for 32-bit systems
+ static inline int folderID = 2147483647;
inline bool headless;
namespace bookOptionsDialog {
inline int bookID;
inline bool deleteOption = true;
inline bool bookDeleted;
inline bool bookPinAction;
+ inline QString folderPath;
+ inline bool isFolder = false;
}
}
namespace localStorage {
diff --git a/src/localLibrary/locallibrarywidget.cpp b/src/localLibrary/locallibrarywidget.cpp
index c1f31f1..5c44413 100644
--- a/src/localLibrary/locallibrarywidget.cpp
+++ b/src/localLibrary/locallibrarywidget.cpp
@@ -16,11 +16,14 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
ui->previousPageBtn->setProperty("type", "borderless");
ui->previousPageBtn->setEnabled(false);
ui->nextPageBtn->setProperty("type", "borderless");
+ ui->goUpBtn->setProperty("type", "borderless");
+ ui->pathBtn->setProperty("type", "borderless");
ui->previousPageBtn->setIcon(QIcon(":/resources/chevron-left.png"));
ui->nextPageBtn->setIcon(QIcon(":/resources/chevron-right.png"));
ui->pageNumberLabel->setFont(QFont("Source Serif Pro"));
ui->pageNumberLabel->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding-left: 10px; padding-right: 10px");
- ui->verticalLayout->setSpacing(4);
+
+ ui->goUpBtn->setEnabled(false);
if(global::deviceID == "n705\n") {
buttonsNumber = 3;
@@ -119,6 +122,17 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
showToast("Generating database");
}
QTimer::singleShot(100, this, SLOT(setupDisplay()));
+
+ if(checkconfig("/mnt/onboard/.adds/inkbox/.config/21-local_library/folders") == false) {
+ folderFeatureEnabled = true;
+ ui->goUpBtn->hide();
+ ui->pathBtn->hide();
+ ui->goUpBtn->deleteLater();
+ ui->pathBtn->deleteLater();
+ }
+ else {
+ folderFeatureEnabled = false;
+ }
}
localLibraryWidget::~localLibraryWidget()
@@ -178,7 +192,12 @@ void localLibraryWidget::setupDatabase() {
databaseJsonArrayList = databaseJsonObject["database"].toArray();
// Determine maximum page number
booksNumber = databaseJsonArrayList.size();
- pagesNumber = std::ceil((double)booksNumber / buttonsNumber);
+ if(folderFeatureEnabled == false) {
+ pagesNumber = std::ceil((double)booksNumber / buttonsNumber);
+ }
+ else {
+ calculateMaximumPagesNumberForFolders();
+ }
if(databaseJsonArrayList.isEmpty()) {
log("Database is empty", className);
noBooksInDatabase = true;
@@ -278,8 +297,19 @@ void localLibraryWidget::setupBooksList(int pageNumber) {
void localLibraryWidget::on_previousPageBtn_clicked()
{
+ log("Previous button clicked", className);
+
+ if(folderFeatureEnabled == true) {
+ log("Decreasing bookIndexVector by buttonsNumber", className);
+ bookIndexVector = (bookIndexVector - goBackInIndex) - buttonsNumber;
+ if(bookIndexVector < 0) {
+ log("Error: Shouldn't be possible to get here", className);
+ bookIndexVector = 0;
+ }
+ }
+
currentPageNumber--;
- setupBooksList(currentPageNumber);
+ setupBooksListToggle(currentPageNumber);
pagesTurned = pagesTurned + 1;
if(pagesTurned >= 3) {
@@ -292,7 +322,7 @@ void localLibraryWidget::on_previousPageBtn_clicked()
void localLibraryWidget::on_nextPageBtn_clicked()
{
currentPageNumber++;
- setupBooksList(currentPageNumber);
+ setupBooksListToggle(currentPageNumber);
pagesTurned = pagesTurned + 1;
if(pagesTurned >= 3) {
@@ -309,9 +339,22 @@ void localLibraryWidget::openBook(int bookID) {
}
void localLibraryWidget::btnOpenBook(int buttonNumber) {
+ log("Book/directory button clicked, buttonNumber is " + QString::number(buttonNumber), className);
int id = idList.at(buttonNumber - 1);
- openBook(id);
- localLibraryWidget::close();
+ if(id == global::localLibrary::folderID) {
+ if(folderFeatureEnabled == true) {
+ log("A folder was selected", className);
+ QString directory = bookBtnArray[buttonNumber]->text();
+ log("Chosen directory is '" + directory + "'", className);
+ ui->goUpBtn->setEnabled(true);
+ changePathAndRefresh(directory);
+ }
+ }
+ else {
+ log("A book was selected", className);
+ openBook(id);
+ localLibraryWidget::close();
+ }
}
void localLibraryWidget::openGoToPageDialog() {
@@ -328,8 +371,11 @@ void localLibraryWidget::goToPage(int page) {
showToast("Request is beyond page range");
}
else {
+ if(folderFeatureEnabled == true) {
+ calculateIndexForPage(page);
+ }
log("Going to page " + QString::number(page), className);
- setupBooksList(page);
+ setupBooksListToggle(page);
emit refreshScreen();
}
}
@@ -343,10 +389,10 @@ void localLibraryWidget::setupDisplay() {
if(noBooksInDatabase == false) {
// Prevent segmentation fault if a book was the last of its page
if(currentPageNumber > pagesNumber) {
- setupBooksList(currentPageNumber - 1);
+ setupBooksListToggle(currentPageNumber - 1);
}
else {
- setupBooksList(currentPageNumber);
+ setupBooksListToggle(currentPageNumber);
}
}
else {
@@ -366,7 +412,26 @@ void localLibraryWidget::showToast(QString messageToDisplay) {
void localLibraryWidget::openBookOptionsDialog(int pseudoBookID) {
// Determine book ID from the book's button number
+ // pseudoBookID represents the button's number
int bookID = ((currentPageNumber * buttonsNumber) - (buttonsNumber - 1)) + (pseudoBookID - 1);
+ log("BookID is " + QString::number(bookID), className);
+ int id = idList.at(pseudoBookID - 1);
+ log("ID from database is " + QString::number(id), className);
+
+ if(id == global::localLibrary::folderID) {
+ if(folderFeatureEnabled == true) {
+ bookID = id;
+ log("Opening options dialog for directory", className);
+ QString directoryPath = bookBtnArray[pseudoBookID]->text();
+ log("Directory path is '" + directoryPath + "'", className);
+ global::localLibrary::bookOptionsDialog::isFolder = true;
+ global::localLibrary::bookOptionsDialog::folderPath = pathForFolders + directoryPath;
+ }
+ }
+ else {
+ global::localLibrary::bookOptionsDialog::isFolder = false;
+ global::localLibrary::bookOptionsDialog::folderPath = "";
+ }
log("Opening book options dialog for book with pseudo-ID " + QString::number(pseudoBookID) + ", ID " + QString::number(bookID), className);
global::localLibrary::bookOptionsDialog::bookID = bookID;
@@ -374,6 +439,7 @@ void localLibraryWidget::openBookOptionsDialog(int pseudoBookID) {
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::showToast, this, &localLibraryWidget::showToast);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion);
+ QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::removedFolder, this, &localLibraryWidget::refreshFolders);
bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
bookOptionsDialogWindow->show();
@@ -397,3 +463,299 @@ void localLibraryWidget::openLocalBookInfoDialog() {
bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookInfoDialogWindow->show();
}
+
+void localLibraryWidget::setupBooksListToggle(int pageNumber) {
+ if(checkconfig("/mnt/onboard/.adds/inkbox/.config/21-local_library/folders") == true) {
+ setupBooksListFolders(pageNumber);
+ }
+ else {
+ setupBooksList(pageNumber);
+ }
+}
+
+void localLibraryWidget::setupBooksListFolders(int pageNumber) {
+ log("Showing local library with folders", className);
+ QStringList dirList = QDir(pathForFolders).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+ log("Full directory list: "+ dirList.join(","), className);
+
+ // This part is calculating which folders to show per page
+ QStringList directoryListFront = dirList;
+ QStringList directoryListBack = dirList;
+ int pageNumberAbove = pageNumber;
+ while(pageNumberAbove != 1) {
+ for (int i = 0; i < buttonsNumber; ++i) {
+ if(directoryListFront.isEmpty() == false) {
+ directoryListFront.removeFirst();
+ }
+ }
+ pageNumberAbove = pageNumberAbove - 1;
+ }
+ log("Front directory list: " + directoryListFront.join(","), className);
+
+ int aboveRemove = pageNumber * buttonsNumber;
+ if(directoryListBack.count() > aboveRemove) {
+ while(directoryListBack.count() > aboveRemove) {
+ if(directoryListBack.isEmpty() == false) {
+ directoryListBack.removeLast();
+ }
+ }
+ }
+ log("Back directory list: " + directoryListBack.join(","), className);
+
+ QStringList directoryListPure;
+ for(QString directory: directoryListFront) {
+ if(directoryListBack.contains(directory) == true) {
+ directoryListPure.append(directory);
+ }
+ }
+ log("Final directory list: " + directoryListPure.join(","), className);
+
+ idList.clear();
+ int in = 1;
+ int directoryCount = 0; // I want to start at 0
+ goBackInIndex = 0;
+ for(int i = (1 * pageNumber * buttonsNumber) - (buttonsNumber - 1); i <= (1 * pageNumber * buttonsNumber); i++) {
+ if(directoryListPure.count() != directoryCount) {
+ // Insert a folder if here
+ log("Showing a folder for index " + QString::number(i), className);
+
+ // Show it, it may be hidden
+ bookIconArray[in]->show();
+ bookBtnArray[in]->show();
+ if(buttonsNumber - in > 0) {
+ lineArray[in]->show();
+ }
+
+ bookBtnArray[in]->setText("" + directoryListPure.at(directoryCount) + "");
+ bookIconArray[in]->setPixmap(pixmapForFolder.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+
+ // ID for indicating that it's a folder in btnOpenBook
+ idList.append(global::localLibrary::folderID);
+ directoryCount = directoryCount + 1;
+ in++;
+ }
+ else {
+ // Show a book otherwise
+ log("bookIndexVector used: " + QString::number(bookIndexVector), className);
+ log("Showing a book for index: " + QString::number(i), className);
+ // Read database info for each book and display the corresponding information on each button
+ bookIconArray[in]->show();
+ bookBtnArray[in]->show();
+ if(buttonsNumber - in > 0) {
+ lineArray[in]->show();
+ }
+
+ // If a book is missing, it's propably because of '>='
+ if(bookIndexVector >= booksListForPathIndex.count()) {
+ continue;
+ }
+
+ QJsonObject jsonObject = databaseJsonArrayList.at(booksListForPathIndex.at(bookIndexVector)).toObject();
+ QString bookTitle = jsonObject["Title"].toString();
+ QString bookAuthor = jsonObject["Author"].toString();
+ QString coverPath = jsonObject["CoverPath"].toString();
+ QString bookID = jsonObject["BookID"].toString();
+
+ if(!coverPath.isEmpty()) {
+ // Display book cover if found
+ QPixmap pixmap(coverPath);
+ bookIconArray[in]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
+ }
+ else {
+ QPixmap pixmap(":/resources/cover_unavailable.png");
+ bookIconArray[in]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ }
+
+ // Display book title
+ idList.append(bookID.toInt());
+ if(bookTitle.length() > bookTitleTruncateThreshold) {
+ bookTitle.truncate(bookTitleTruncateThreshold);
+ bookTitle.append("...");
+ }
+ if(!bookAuthor.isEmpty()) {
+ // Book is likely an ePUB
+ bookBtnArray[in]->setText("" + bookTitle + "" + "
" + bookAuthor);
+ }
+ else {
+ // Book is likely a PDF or a picture
+ bookBtnArray[in]->setText("" + bookTitle + "");
+ }
+ if(!bookID.isEmpty()) {
+ in++;
+ }
+ bookIndexVector = bookIndexVector + 1;
+ }
+ goBackInIndex = goBackInIndex + 1;
+ }
+
+ if(in <= buttonsNumber) {
+ for(int i = in; i <= buttonsNumber; i++) {
+ log("Hiding items in LocalLibrary", className);
+ bookIconArray[i]->hide();
+ bookBtnArray[i]->hide();
+ if(i - 1 < buttonsNumber) {
+ lineArray[(i - 1)]->hide();
+ }
+ }
+ }
+
+ ui->pageNumberLabel->setText(QString::number(pageNumber) + " of " + QString::number(pagesNumber));
+ // NOTICE: Memory leak?
+ // Do it twice, otherwise the layout doesn't show as intended
+ for(int i = 0; i <= 1; i++) {
+ ui->verticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
+ }
+
+ // Set boundaries for 'Previous'/'Next' page turn buttons
+ currentPageNumber = pageNumber;
+ ui->previousPageBtn->setEnabled(true);
+ ui->nextPageBtn->setEnabled(true);
+ if(currentPageNumber - 1 < 1) {
+ ui->previousPageBtn->setEnabled(false);
+ ui->nextPageBtn->setEnabled(true);
+ }
+ if(currentPageNumber + 1 > pagesNumber) {
+ ui->previousPageBtn->setEnabled(true);
+ ui->nextPageBtn->setEnabled(false);
+ }
+ if(currentPageNumber - 1 < 1 and currentPageNumber + 1 > pagesNumber) {
+ ui->previousPageBtn->setEnabled(false);
+ ui->nextPageBtn->setEnabled(false);
+ }
+}
+
+// Sets pagesNumber for folders feature, and everything else
+void localLibraryWidget::calculateMaximumPagesNumberForFolders() {
+ log("Main path is '" + pathForFolders + "'", className);
+
+ // Look for books in this path
+ booksListForPathIndex.clear();
+ int count = 0;
+ for(QJsonValue object: databaseJsonArrayList) {
+ QString bookPath = object.toObject()["BookPath"].toString();
+ QString bookDirPath = QFileInfo(bookPath).absoluteDir().path();
+
+ if(bookDirPath.at(bookDirPath.count() - 1) == "/") {
+ bookDirPath = bookDirPath.remove(bookDirPath.count() - 1, 1);
+ }
+
+ QString temporaryPathForFolders = pathForFolders;
+ if(temporaryPathForFolders.at(temporaryPathForFolders.count() - 1) == "/") {
+ temporaryPathForFolders = temporaryPathForFolders.remove(temporaryPathForFolders.count() - 1, 1);
+ }
+
+ if(bookDirPath == temporaryPathForFolders) {
+ booksListForPathIndex.append(count);
+ }
+ count = count + 1;
+ }
+ QStringList list;
+ foreach (int number, booksListForPathIndex) {
+ list.append(QString::number(number));
+ }
+
+ directoryListCount = QDir(pathForFolders).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name).count();
+ log("Directories count in directory: " + QString::number(directoryListCount), className);
+ completeItemsList = booksListForPathIndex.count() + directoryListCount;
+ log("All items: " + QString::number(completeItemsList), className);
+
+ pagesNumber = std::ceil((double)completeItemsList / buttonsNumber);
+
+ log("Total pages: " + QString::number(pagesNumber), className);
+
+ // This is the last page full of folders
+ firstPageForBooks = (QString::number(float(directoryListCount) / buttonsNumber).split(".").first()).toInt();
+ log("There are so many pages with folders: " + QString::number(firstPageForBooks), className);
+
+ // This indicates how much folders are after firstPageForBooks. It's always less than buttonsNumber
+ lastPageFolderCount = directoryListCount;
+ while(lastPageFolderCount >= buttonsNumber) {
+ lastPageFolderCount = lastPageFolderCount - buttonsNumber;
+ }
+ log("Start after item on the last page: " + QString::number(lastPageFolderCount), className);
+
+ // Sorting the vector if needed should be done here
+}
+
+void localLibraryWidget::calculateIndexForPage(int pageNumber) {
+ if(pageNumber == firstPageForBooks + 1) {
+ log("Variable firstPageForBooks is 0", className);
+ bookIndexVector = 0;
+ return void();
+ }
+
+ if(pageNumber == firstPageForBooks + 2) {
+ log("The page is just after firstPageForBooks", className);
+ bookIndexVector = buttonsNumber - lastPageFolderCount;
+ return void();
+ }
+ else if(pageNumber > firstPageForBooks + 2) {
+ bookIndexVector = buttonsNumber - lastPageFolderCount;
+ int pageUntilGoal = 1;
+ int pageDifference = pageNumber - (firstPageForBooks + 2);
+ log("Variable firstPageForBooks is " + QString::number(firstPageForBooks), className);
+ log("Variable pageDifference is " + QString::number(pageDifference), className);
+ if(pageDifference != 0) {
+ while(pageUntilGoal != pageDifference) {
+ log("Looping for pageUntilGoal");
+ bookIndexVector = bookIndexVector + buttonsNumber;
+ pageUntilGoal++;
+ }
+ }
+ bookIndexVector = bookIndexVector + buttonsNumber;
+ log("Calculated bookIndexVector is " + QString::number(bookIndexVector), className);
+ }
+ else {
+ log("Variable pageNumber isn't higher than firstPageForBooks", className);
+ bookIndexVector = 0;
+ }
+}
+
+void localLibraryWidget::changePathAndRefresh(QString directory) {
+ log("Changing path", className);
+ QString temporaryPathForFolders = pathForFolders + directory + "/";
+ if(QDir(temporaryPathForFolders).isEmpty() == false) {
+ pathForFolders = temporaryPathForFolders;
+ calculateMaximumPagesNumberForFolders();
+ bookIndexVector = 0;
+ goToPage(1);
+ }
+ else {
+ showToast("Directory is empty");
+ }
+}
+
+void localLibraryWidget::on_goUpBtn_clicked()
+{
+ if(pathForFolders != "/mnt/onboard/onboard/") {
+ log("Changing path; going back", className);
+ // This can't be a one-liner
+ QDir temporaryPathForFolders = QDir(pathForFolders);
+ temporaryPathForFolders.cdUp();
+ pathForFolders = temporaryPathForFolders.path();
+ pathForFolders = pathForFolders + "/";
+ if(pathForFolders == "/mnt/onboard/onboard/") {
+ ui->goUpBtn->setDisabled(true);
+ }
+ log("New path is '" + pathForFolders + "'", className);
+
+ calculateMaximumPagesNumberForFolders();
+ bookIndexVector = 0;
+ goToPage(1);
+ }
+}
+
+void localLibraryWidget::on_pathBtn_clicked()
+{
+ log("Showing path dialog", className);
+ QString pathForFoldersSaved = pathForFolders;
+ showToast(pathForFolders.remove(0, 20));
+ pathForFolders = pathForFoldersSaved;
+}
+
+void localLibraryWidget::refreshFolders() {
+ log("Called refresh folders");
+ calculateMaximumPagesNumberForFolders();
+ bookIndexVector = 0;
+ goToPage(1);
+}
diff --git a/src/localLibrary/locallibrarywidget.h b/src/localLibrary/locallibrarywidget.h
index e2dd159..84e450c 100644
--- a/src/localLibrary/locallibrarywidget.h
+++ b/src/localLibrary/locallibrarywidget.h
@@ -41,6 +41,19 @@ public:
int bookTitleTruncateThreshold;
QVector idList;
bool noBooksInDatabase = true;
+ // For folder feature
+ QString pathForFolders = "/mnt/onboard/onboard/";
+ bool folderFeatureEnabled = false;
+ int firstPageForBooks;
+ int lastPageFolderCount;
+ int bookIndexVector = 0;
+ int goBackInIndex = 0;
+ QPixmap pixmapForFolder = QPixmap(":/resources/folder.png");
+ QVector booksListForPathIndex;
+ int fileListCount;
+ int directoryListCount;
+ int completeItemsList;
+
private slots:
void setupDatabase();
@@ -57,6 +70,16 @@ private slots:
void openBookOptionsDialog(int pseudoBookID);
void handlePossibleBookDeletion();
void openLocalBookInfoDialog();
+ // For folder feature
+ void setupBooksListFolders(int pageNumber);
+ void setupBooksListToggle(int pageNumber);
+ void calculateMaximumPagesNumberForFolders();
+ void calculateIndexForPage(int pageNumber);
+ // Dir without "/" at the end and begining
+ void changePathAndRefresh(QString directory);
+ void refreshFolders();
+ void on_goUpBtn_clicked();
+ void on_pathBtn_clicked();
private:
Ui::localLibraryWidget * ui;
diff --git a/src/localLibrary/locallibrarywidget.ui b/src/localLibrary/locallibrarywidget.ui
index b12493a..fcad662 100644
--- a/src/localLibrary/locallibrarywidget.ui
+++ b/src/localLibrary/locallibrarywidget.ui
@@ -43,14 +43,31 @@
-
-
-
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ :/resources/question-mark.png:/resources/question-mark.png
+
+
+
+ -
- -
+
-
@@ -58,22 +75,13 @@
-
-
-
- Qt::Horizontal
+
+
+
-
- QSizePolicy::Maximum
-
-
-
- 40
- 20
-
-
-
+
- -
+
-
Qt::Horizontal
@@ -89,7 +97,23 @@
- -
+
-
+
+
+ Qt::Horizontal
+
+
+ QSizePolicy::Maximum
+
+
+
+ 40
+ 20
+
+
+
+
+ -
Qt::Horizontal
@@ -106,10 +130,20 @@
-
-
+
+
+
+ 0
+ 0
+
+
+
+
+ :/resources/chevron-up.png:/resources/chevron-up.png
+
-
@@ -125,6 +159,19 @@
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
-
@@ -212,6 +259,8 @@ Add some via USB or explore the Online Library.
-
+
+
+
diff --git a/src/resources/chevron-down.png b/src/resources/chevron-down.png
new file mode 100644
index 0000000..d32a6bd
Binary files /dev/null and b/src/resources/chevron-down.png differ
diff --git a/src/resources/chevron-up.png b/src/resources/chevron-up.png
new file mode 100644
index 0000000..3f86033
Binary files /dev/null and b/src/resources/chevron-up.png differ
diff --git a/src/resources/folder.png b/src/resources/folder.png
new file mode 100644
index 0000000..4a60b8f
Binary files /dev/null and b/src/resources/folder.png differ
diff --git a/src/resources/question-mark.png b/src/resources/question-mark.png
new file mode 100644
index 0000000..13d55de
Binary files /dev/null and b/src/resources/question-mark.png differ
diff --git a/src/settings/settings.cpp b/src/settings/settings.cpp
index 9d92ac4..b4734e8 100644
--- a/src/settings/settings.cpp
+++ b/src/settings/settings.cpp
@@ -338,6 +338,11 @@ settings::settings(QWidget *parent) :
ui->tzComboBox->setCurrentText(readFile(".config/19-timezone/config-name"));
}
+ // Local library folders support
+ if(checkconfig(".config/21-local_library/folders") == true) {
+ ui->localLibraryShowFoldersCheckBox->click();
+ }
+
if(checkconfig("/opt/inkbox_genuine") == true) {
// Enforcing security policy if the user has not rooted the device
if(checkconfig("/external_root/opt/root/rooted") == true) {
@@ -1089,3 +1094,19 @@ void settings::on_pageSizeWidthIncBtn_clicked()
pageSizeWidthSaved = pageSizeWidthSaved + 5;
ui->pageSizeWidthLabel->setText(QString::number(pageSizeWidthSaved));
}
+
+void settings::on_localLibraryShowFoldersCheckBox_toggled(bool checked)
+{
+ QString settingString = "local library folders support";
+ if(checked == true) {
+ logEnabled(settingString, className);
+ checked_box = true;
+ writeconfig(".config/21-local_library/folders", "Folders");
+ }
+ else {
+ logDisabled(settingString, className);
+ checked_box = false;
+ writeconfig(".config/21-local_library/folders", "Folders");
+ }
+}
+
diff --git a/src/settings/settings.h b/src/settings/settings.h
index dac885e..0fa66e4 100644
--- a/src/settings/settings.h
+++ b/src/settings/settings.h
@@ -76,6 +76,8 @@ private slots:
void on_pageSizeWidthDecBtn_clicked();
void on_pageSizeWidthIncBtn_clicked();
+ void on_localLibraryShowFoldersCheckBox_toggled(bool checked);
+
signals:
void showToast(QString messageToDisplay);
void closeIndefiniteToast();
diff --git a/src/settings/settings.ui b/src/settings/settings.ui
index 7eb1cf4..64d1939 100644
--- a/src/settings/settings.ui
+++ b/src/settings/settings.ui
@@ -68,8 +68,8 @@
0
0
- 457
- 667
+ 463
+ 632
@@ -118,139 +118,6 @@
0
-
-
-
-
- QFrame::Plain
-
-
- Qt::Horizontal
-
-
-
- -
-
-
- Disable "Welcome to InkBox" message
-
-
-
- -
-
-
-
- Chivo
- true
-
-
-
- USB networking
-
-
-
- -
-
-
-
- Chivo
- 50
- true
- false
-
-
-
- Storage
-
-
-
- -
-
-
- Show scroll bar if needed
-
-
-
- -
-
-
-
- Chivo
- 50
- true
- false
-
-
-
- Reading
-
-
-
- -
-
-
- QFrame::Plain
-
-
- Qt::Horizontal
-
-
-
- -
-
-
- Global reading settings
-
-
-
- -
-
-
- QFrame::Plain
-
-
- Qt::Horizontal
-
-
-
- -
-
-
- Clock: Show seconds
-
-
-
- -
-
-
- QFrame::Plain
-
-
- Qt::Horizontal
-
-
-
- -
-
-
-
- Chivo
- 50
- true
- false
-
-
-
- Home
-
-
-
- -
-
-
- Disable authors quotes
-
-
-
-
@@ -363,6 +230,230 @@
+ -
+
+
+
+ Chivo
+ 50
+ true
+ false
+
+
+
+ Reading
+
+
+
+ -
+
+
+ Clock: Show seconds
+
+
+
+ -
+
+
+ QFrame::Plain
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+
+ Chivo
+ true
+
+
+
+ Local library
+
+
+
+ -
+
+
+ Show scroll bar if needed
+
+
+
+ -
+
+
+ Global reading settings
+
+
+
+ -
+
+
+ 0
+
+
-
+
+
+
+ 75
+ true
+
+
+
+ Go
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Enter USB Mass Storage session
+
+
+
+
+
+ -
+
+
+ Always show status bar
+
+
+
+ -
+
+
+ 0
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Request DHCP lease
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Request
+
+
+
+
+
+ -
+
+
+ 0
+
+
-
+
+
+ Export highlights
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Export
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+ -
+
+
+ Disable authors quotes
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::MinimumExpanding
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+
+ Chivo
+ 50
+ true
+ false
+
+
+
+ Home
+
+
+
-
@@ -419,45 +510,15 @@
- -
-
-
- 0
+
-
+
+
+ QFrame::Plain
-
-
-
-
- Export highlights
-
-
-
- -
-
-
-
- 75
- true
-
-
-
- Export
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
+
+ Qt::Horizontal
+
+
-
@@ -531,107 +592,76 @@
-
-
-
- 0
+
+
+
+ Chivo
+ 50
+ true
+ false
+
-
-
-
-
-
- 75
- true
-
-
-
- Go
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Enter USB Mass Storage session
-
-
-
-
-
- -
-
- Always show status bar
+ Storage
+
+
+
+ -
+
+
+ Disable "Welcome to InkBox" message
-
-
-
- 0
+
+
+
+ Chivo
+ true
+
-
-
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Request DHCP lease
-
-
-
- -
-
-
-
- 75
- true
-
-
-
- Request
-
-
-
-
+
+ USB networking
+
+
+
+ -
+
+
+ Show folders
+
+
+
+ -
+
+
+ QFrame::Plain
+
+
+ Qt::Horizontal
+
+
-
-
+
+
+ QFrame::Plain
+
- Qt::Vertical
+ Qt::Horizontal
-
- QSizePolicy::MinimumExpanding
+
+
+ -
+
+
+ QFrame::Plain
-
-
- 0
- 0
-
+
+ Qt::Horizontal
-
+
diff --git a/src/widgets/dialogs/library/bookinfodialog.cpp b/src/widgets/dialogs/library/bookinfodialog.cpp
index 9e177a1..a96d27d 100644
--- a/src/widgets/dialogs/library/bookinfodialog.cpp
+++ b/src/widgets/dialogs/library/bookinfodialog.cpp
@@ -83,26 +83,31 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) :
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("Title: " + title + "
");
+ if(global::localLibrary::bookOptionsDialog::bookID != global::localLibrary::folderID) {
+ 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("Title: " + title + "
");
+ }
+ if(!author.isEmpty()) {
+ bookInfo.append("Author: " + author + "
");
+ }
+ if(!publicationDate.isEmpty()) {
+ bookInfo.append("Publication date: " + publicationDate + "
");
+ }
+ if(!path.isEmpty()) {
+ bookInfo.append("Path: " + path + "
");
+ }
+ global::text::textBrowserContents = bookInfo;
}
- if(!author.isEmpty()) {
- bookInfo.append("Author: " + author + "
");
+ else {
+ QString bookInfo = "Path: " + global::localLibrary::bookOptionsDialog::folderPath;
+ global::text::textBrowserContents = bookInfo;
}
- if(!publicationDate.isEmpty()) {
- bookInfo.append("Publication date: " + publicationDate + "
");
- }
- if(!path.isEmpty()) {
- bookInfo.append("Path: " + path + "
");
- }
-
- global::text::textBrowserContents = bookInfo;
textwidget * textwidgetWindow = new textwidget(this);
ui->stackedWidget->insertWidget(1, textwidgetWindow);
ui->stackedWidget->setCurrentIndex(1);
diff --git a/src/widgets/dialogs/library/bookoptionsdialog.cpp b/src/widgets/dialogs/library/bookoptionsdialog.cpp
index 657ecd0..9e061b3 100644
--- a/src/widgets/dialogs/library/bookoptionsdialog.cpp
+++ b/src/widgets/dialogs/library/bookoptionsdialog.cpp
@@ -22,23 +22,40 @@ bookOptionsDialog::bookOptionsDialog(QWidget *parent) :
ui->wipeLocalReadingSettingsBtn->setProperty("type", "borderless");
ui->infoBtn->setProperty("type", "borderless");
- global::localLibrary::bookOptionsDialog::bookPinAction = false;
-
- bookPath = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID)["BookPath"].toString();
- if(isBookPinned(global::localLibrary::bookOptionsDialog::bookID)) {
- bookPinned = true;
- ui->pinBtn->setText("Unpin");
+ if(global::localLibrary::bookOptionsDialog::isFolder == true) {
+ global::localLibrary::bookOptionsDialog::isFolder = false;
+ isFolder = true;
+ log("Detected a folder", className);
+ ui->pinBtn->hide();
+ ui->pinBtn->deleteLater();
+ ui->line->hide();
+ ui->line->deleteLater();
+ ui->wipeLocalReadingSettingsBtn->hide();
+ ui->wipeLocalReadingSettingsBtn->deleteLater();
+ ui->line_2->hide();
+ ui->line_2->deleteLater();
}
else {
- bookPinned = false;
+ isFolder = false;
+ global::localLibrary::bookOptionsDialog::bookPinAction = false;
+
+ bookPath = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID)["BookPath"].toString();
+ if(isBookPinned(global::localLibrary::bookOptionsDialog::bookID)) {
+ bookPinned = true;
+ ui->pinBtn->setText("Unpin");
+ }
+ else {
+ bookPinned = false;
+ }
+
+ bookChecksum = fileChecksum(bookPath, QCryptographicHash::Sha256);
+ QDir localReadingSettingsPath("/mnt/onboard/onboard/." + bookChecksum);
+ if(!localReadingSettingsPath.exists()) {
+ ui->wipeLocalReadingSettingsBtn->setEnabled(false);
+ ui->wipeLocalReadingSettingsBtn->setStyleSheet(ui->wipeLocalReadingSettingsBtn->styleSheet() + "color: gray");
+ }
}
- bookChecksum = fileChecksum(bookPath, QCryptographicHash::Sha256);
- QDir localReadingSettingsPath("/mnt/onboard/onboard/." + bookChecksum);
- if(!localReadingSettingsPath.exists()) {
- ui->wipeLocalReadingSettingsBtn->setEnabled(false);
- ui->wipeLocalReadingSettingsBtn->setStyleSheet(ui->wipeLocalReadingSettingsBtn->styleSheet() + "color: gray");
- }
this->adjustSize();
}
@@ -59,6 +76,15 @@ void bookOptionsDialog::on_pinBtn_clicked()
void bookOptionsDialog::on_deleteBtn_clicked()
{
+ if(isFolder == true) {
+ deleteFolder();
+ }
+ else {
+ deleteBook();
+ }
+}
+
+void bookOptionsDialog::deleteBook() {
log("Deleting book '" + bookPath + "'", className);
global::toast::delay = 3000;
if(QFile::remove(bookPath)) {
@@ -71,6 +97,20 @@ void bookOptionsDialog::on_deleteBtn_clicked()
}
}
+void bookOptionsDialog::deleteFolder() {
+ log("Removing empty directory '" + global::localLibrary::bookOptionsDialog::folderPath + "'", className);
+ if(QDir(global::localLibrary::bookOptionsDialog::folderPath).isEmpty() == true) {
+ global::toast::delay = 3000;
+ QDir(global::localLibrary::bookOptionsDialog::folderPath).removeRecursively();
+ emit showToast("Directory removed successfully");
+ emit removedFolder();
+ }
+ else {
+ emit showToast("Directory is not empty");
+ }
+}
+
+
void bookOptionsDialog::on_infoBtn_clicked()
{
emit openLocalBookInfoDialog();
diff --git a/src/widgets/dialogs/library/bookoptionsdialog.h b/src/widgets/dialogs/library/bookoptionsdialog.h
index 018a7ca..725085f 100644
--- a/src/widgets/dialogs/library/bookoptionsdialog.h
+++ b/src/widgets/dialogs/library/bookoptionsdialog.h
@@ -19,6 +19,7 @@ public:
QString bookPath;
QString bookChecksum;
bool bookPinned;
+ bool isFolder;
private slots:
void on_pinBtn_clicked();
@@ -27,11 +28,14 @@ private slots:
void on_wipeLocalReadingSettingsBtn_clicked();
void pinBook(int bookID);
void unpinBook(int bookID);
+ void deleteBook();
+ void deleteFolder();
bool isBookPinned(int bookID);
signals:
void openLocalBookInfoDialog();
void showToast(QString messageToDisplay);
+ void removedFolder();
private:
Ui::bookOptionsDialog *ui;