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) {
if(splash == true) {
QString prog ("reboot");
QString prog ("/sbin/reboot");
QStringList args;
if(global::kobox::resetKoboxUserDataBool == true) {
args << "splash" << "reset_kobox";
@ -253,7 +253,7 @@ namespace {
proc->start(prog, args);
}
else {
QString prog ("reboot");
QString prog ("/sbin/reboot");
QStringList args;
if(global::kobox::resetKoboxUserDataBool == true) {
args << "no_splash" << "reset_kobox";
@ -307,5 +307,17 @@ namespace {
void setDefaultWorkDir() {
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

View file

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

View file

@ -83,26 +83,6 @@ OK
</property>
<item>
<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">
<widget class="QLabel" name="label_2">
<property name="font">
@ -116,45 +96,6 @@ OK
</property>
</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="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">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
@ -192,7 +133,68 @@ OK
</item>
</layout>
</item>
<item row="11" column="0">
<item row="7" column="0">
<widget class="Line" name="line_5">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<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="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">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</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>
@ -268,8 +270,21 @@ OK
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="Line" name="line_5">
<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>
@ -278,13 +293,23 @@ OK
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="Line" name="line_4">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</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="orientation">
<enum>Qt::Horizontal</enum>
<property name="text">
<string>Extensions</string>
</property>
</widget>
</item>

View file

@ -381,7 +381,9 @@ MainWindow::MainWindow(QWidget *parent)
// **** 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.
// Problem encontered: it would prompt to connect after a fresh reboot even if no USB cable was plugged in.
//
// usbmsPrompt->start();
//
// **** FEATURE WARNING ****
// 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->setIcon(QIcon(":/resources/plus.png"));
// Style misc.
ui->bookInfoLabel->setStyleSheet("font-style: italic");
// Making text selectable
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
// Font
string_checkconfig(".config/04-book/font");
@ -144,6 +152,17 @@ reader::reader(QWidget *parent) :
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
int brightness_value = get_brightness();
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) {
// Counting number of parsed files
split_total = setup_book(book_file, 0, true);
@ -416,6 +435,23 @@ reader::reader(QWidget *parent) :
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
string_writeconfig("/inkbox/remount", "true");
@ -434,9 +470,9 @@ reader::reader(QWidget *parent) :
string str_book_3 = book_3.toStdString();
string_checkconfig(".config/08-recent_books/4");
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...
if(wakeFromSleep == true) {

View file

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

View file

@ -460,16 +460,6 @@
<property name="bottomMargin">
<number>0</number>
</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">
<spacer name="horizontalSpacer">
<property name="orientation">
@ -483,7 +473,7 @@
</property>
</spacer>
</item>
<item row="0" column="2">
<item row="0" column="4">
<widget class="QLabel" name="timeLabel">
<property name="font">
<font>
@ -496,6 +486,64 @@
</property>
</widget>
</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>
</item>
<item row="1" column="0">