New feature: show book name and author in Reader framework

This commit is contained in:
Nicolas Mailloux 2021-06-20 13:31:24 -04:00
parent c36e7e2ac2
commit e68900babb
7 changed files with 280 additions and 154 deletions

View file

@ -244,7 +244,7 @@ namespace {
} }
void reboot(bool splash) { void reboot(bool splash) {
if(splash == true) { if(splash == true) {
QString prog ("reboot"); QString prog ("/sbin/reboot");
QStringList args; QStringList args;
if(global::kobox::resetKoboxUserDataBool == true) { if(global::kobox::resetKoboxUserDataBool == true) {
args << "splash" << "reset_kobox"; args << "splash" << "reset_kobox";
@ -253,7 +253,7 @@ namespace {
proc->start(prog, args); proc->start(prog, args);
} }
else { else {
QString prog ("reboot"); QString prog ("/sbin/reboot");
QStringList args; QStringList args;
if(global::kobox::resetKoboxUserDataBool == true) { if(global::kobox::resetKoboxUserDataBool == true) {
args << "no_splash" << "reset_kobox"; args << "no_splash" << "reset_kobox";
@ -307,5 +307,17 @@ namespace {
void setDefaultWorkDir() { void setDefaultWorkDir() {
QDir::setCurrent("/mnt/onboard/.adds/inkbox"); QDir::setCurrent("/mnt/onboard/.adds/inkbox");
} }
QString findEpubMetadata(QString book_file, QString metadata) {
setDefaultWorkDir();
QString prog ("sh");
QStringList args;
args << "find_epub_metadata.sh" << book_file << metadata;
QProcess *proc = new QProcess();
proc->start(prog, args);
proc->waitForFinished();
QString returnedMetadata = proc->readAllStandardOutput();
return returnedMetadata;
}
} }
#endif // FUNCTIONS_H #endif // FUNCTIONS_H

View file

@ -26,9 +26,11 @@ koboxSettings::koboxSettings(QWidget *parent) :
ui->koboxStatusLabel->setText("KoBox is <b>enabled</b>"); ui->koboxStatusLabel->setText("KoBox is <b>enabled</b>");
not_user_change = true; not_user_change = true;
ui->checkBox->click(); ui->checkBox->click();
ui->runtimeSettingsWidget->setVisible(true);
} }
else { else {
ui->koboxStatusLabel->setText("KoBox is <b>disabled</b>"); ui->koboxStatusLabel->setText("KoBox is <b>disabled</b>");
ui->runtimeSettingsWidget->setVisible(false);
} }
// DPI setting // DPI setting

View file

@ -83,26 +83,6 @@ OK
</property> </property>
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<widget class="QLabel" name="koboxStatusLabel">
<property name="text">
<string>KoBox is &lt;status&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Line" name="line_3">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="font"> <property name="font">
@ -116,45 +96,6 @@ OK
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Extensions</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
<item row="12" column="0">
<spacer name="verticalSpacer">
<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 row="5" column="0"> <item row="5" column="0">
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1"> <item row="0" column="1">
@ -192,82 +133,6 @@ OK
</item> </item>
</layout> </layout>
</item> </item>
<item row="11" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Applications scale (DPI)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_3">
<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="0" column="2">
<widget class="QSpinBox" name="spinBox">
<property name="minimum">
<number>25</number>
</property>
<property name="maximum">
<number>250</number>
</property>
<property name="singleStep">
<number>25</number>
</property>
<property name="value">
<number>125</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Reset KoBox</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_5">
<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="2">
<widget class="QPushButton" name="resetKoboxBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0"> <item row="7" column="0">
<widget class="Line" name="line_5"> <widget class="Line" name="line_5">
<property name="frameShadow"> <property name="frameShadow">
@ -278,8 +143,31 @@ OK
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0"> <item row="3" column="0">
<widget class="Line" name="line_4"> <widget class="QLabel" name="koboxStatusLabel">
<property name="text">
<string>KoBox is &lt;status&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="13" column="0">
<spacer name="verticalSpacer">
<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 row="2" column="0">
<widget class="Line" name="line_3">
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
@ -288,6 +176,143 @@ OK
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0">
<widget class="QStackedWidget" name="runtimeSettingsWidget">
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_3">
<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_5">
<item row="2" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Applications scale (DPI)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_3">
<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="0" column="2">
<widget class="QSpinBox" name="spinBox">
<property name="minimum">
<number>25</number>
</property>
<property name="maximum">
<number>250</number>
</property>
<property name="singleStep">
<number>25</number>
</property>
<property name="value">
<number>125</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Reset KoBox</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_5">
<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="2">
<widget class="QPushButton" name="resetKoboxBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Line" name="line_4">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_4"/>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Extensions</string>
</property>
</widget>
</item>
<item row="8" column="0"> <item row="8" column="0">
<layout class="QGridLayout" name="usbmsGridLayout"> <layout class="QGridLayout" name="usbmsGridLayout">
<property name="bottomMargin"> <property name="bottomMargin">

View file

@ -381,7 +381,9 @@ MainWindow::MainWindow(QWidget *parent)
// **** FEATURE WARNING **** // **** FEATURE WARNING ****
// Due to the fsl-usb2-udc/gadget/suspended file which really only changes after a real plug/unplug of the USB cable, further development on this feature is no longer possible and is abandoned unless a fix is found. // Due to the fsl-usb2-udc/gadget/suspended file which really only changes after a real plug/unplug of the USB cable, further development on this feature is no longer possible and is abandoned unless a fix is found.
// Problem encontered: it would prompt to connect after a fresh reboot even if no USB cable was plugged in. // Problem encontered: it would prompt to connect after a fresh reboot even if no USB cable was plugged in.
//
// usbmsPrompt->start(); // usbmsPrompt->start();
//
// **** FEATURE WARNING **** // **** FEATURE WARNING ****
// We set the brightness level saved in the config file // We set the brightness level saved in the config file

View file

@ -71,9 +71,17 @@ reader::reader(QWidget *parent) :
ui->brightnessIncBtn->setText(""); ui->brightnessIncBtn->setText("");
ui->brightnessIncBtn->setIcon(QIcon(":/resources/plus.png")); ui->brightnessIncBtn->setIcon(QIcon(":/resources/plus.png"));
// Style misc.
ui->bookInfoLabel->setStyleSheet("font-style: italic");
// Making text selectable // Making text selectable
ui->text->setTextInteractionFlags(Qt::TextSelectableByMouse); ui->text->setTextInteractionFlags(Qt::TextSelectableByMouse);
// Font misc.
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Italic.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont crimson(family);
// Custom settings // Custom settings
// Font // Font
string_checkconfig(".config/04-book/font"); string_checkconfig(".config/04-book/font");
@ -144,6 +152,17 @@ reader::reader(QWidget *parent) :
ui->statusBarWidget->setVisible(false); ui->statusBarWidget->setVisible(false);
} }
// Topbar widget / book info
if(checkconfig(".config/13-topbarinfo/config") == true) {
ui->topbarStackedWidget->setVisible(true);
showTopbarWidget = true;
ui->bookInfoLabel->setFont(crimson);
}
else {
ui->topbarStackedWidget->setVisible(false);
showTopbarWidget = false;
}
// Getting brightness level // Getting brightness level
int brightness_value = get_brightness(); int brightness_value = get_brightness();
ui->brightnessStatus->setValue(brightness_value); ui->brightnessStatus->setValue(brightness_value);
@ -348,7 +367,7 @@ reader::reader(QWidget *parent) :
} }
} }
// Checking if we're waking from sleep; if so, do nothing there because the book should have already been parsed // Checking if we're waking from sleep; if so, do nothing there because the book should already have been parsed
if(wakeFromSleep != true) { if(wakeFromSleep != true) {
// Counting number of parsed files // Counting number of parsed files
split_total = setup_book(book_file, 0, true); split_total = setup_book(book_file, 0, true);
@ -416,6 +435,23 @@ reader::reader(QWidget *parent) :
ui->text->setText(epubPageContent); ui->text->setText(epubPageContent);
} }
// Topbar info widget
if(is_epub == true) {
QString bookCreator = findEpubMetadata(book_file, "creator");
QString bookTitle = findEpubMetadata(book_file, "title");
bookCreator = bookCreator.trimmed();
bookTitle = bookTitle.trimmed();
QString infoLabelContent = bookCreator;
infoLabelContent.append("");
infoLabelContent.append(bookTitle);
ui->bookInfoLabel->setText(infoLabelContent);
}
else {
QString bookReadRelativePath = book_file.split("/").last();
ui->bookInfoLabel->setText(bookReadRelativePath);
}
// Clean up // Clean up
string_writeconfig("/inkbox/remount", "true"); string_writeconfig("/inkbox/remount", "true");
@ -434,9 +470,9 @@ reader::reader(QWidget *parent) :
string str_book_3 = book_3.toStdString(); string str_book_3 = book_3.toStdString();
string_checkconfig(".config/08-recent_books/4"); string_checkconfig(".config/08-recent_books/4");
book_4 = checkconfig_str_val; book_4 = checkconfig_str_val;
string str_book_4 = book_4.toStdString(); std::string str_book_4 = book_4.toStdString();
string book_file_str; std::string book_file_str;
// Don't mess up "Recently read books" with random "book.txt" buttons... // Don't mess up "Recently read books" with random "book.txt" buttons...
if(wakeFromSleep == true) { if(wakeFromSleep == true) {

View file

@ -48,11 +48,11 @@ public:
bool nextdefinition_lock = false; bool nextdefinition_lock = false;
bool is_epub = false; bool is_epub = false;
bool parser_ran = false; bool parser_ran = false;
bool booktostr_ran = false;
bool filematch_ran = false; bool filematch_ran = false;
bool neverRefresh = false; bool neverRefresh = false;
bool wakeFromSleep = false; bool wakeFromSleep = false;
bool remount = true; bool remount = true;
bool showTopbarWidget;
QString book_1; QString book_1;
QString book_2; QString book_2;
QString book_3; QString book_3;
@ -72,6 +72,7 @@ public:
QPixmap scaledEmptyPixmap; QPixmap scaledEmptyPixmap;
QList<QString> content; QList<QString> content;
QString epubPageContent; QString epubPageContent;
int setup_book(QString book, int i, bool run_parser); int setup_book(QString book, int i, bool run_parser);
void checkwords(); void checkwords();
bool epub_file_match(QString file); bool epub_file_match(QString file);

View file

@ -460,16 +460,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0">
<widget class="QLabel" name="inkboxLabel">
<property name="text">
<string>InkBox</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -483,7 +473,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="2"> <item row="0" column="4">
<widget class="QLabel" name="timeLabel"> <widget class="QLabel" name="timeLabel">
<property name="font"> <property name="font">
<font> <font>
@ -496,6 +486,64 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2">
<widget class="QStackedWidget" name="topbarStackedWidget">
<widget class="QWidget" name="page_7">
<layout class="QVBoxLayout" name="verticalLayout_7">
<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_13">
<item row="0" column="0">
<widget class="QLabel" name="bookInfoLabel">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_14"/>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="inkboxLabel">
<property name="text">
<string>InkBox</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_9">
<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> </layout>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">