Skip to content

Commit

Permalink
adopt some suggestions from BeckyEbook
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Oct 26, 2024
1 parent 3ed7c2f commit 70bd634
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
11 changes: 2 additions & 9 deletions src/Dialogs/SemanticTargetID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

static QString SETTINGS_GROUP = "semantic_target_id";

SemanticTargetID::SemanticTargetID(HTMLResource *html_resource, QWidget *parent)
SemanticTargetID::SemanticTargetID(HTMLResource *html_resource, const QStringList& idlst, QWidget *parent)
:
QDialog(parent),
m_SelectedText(""),
Expand All @@ -36,16 +36,9 @@ SemanticTargetID::SemanticTargetID(HTMLResource *html_resource, QWidget *parent)
ui.setupUi(this);
connectSignalsSlots();
ReadSettings();
SetList();
}

void SemanticTargetID::SetList()
{
QString BookPath = m_HTMLResource->GetRelativePath();
QString xhtmlsrc = m_HTMLResource->GetText();
QStringList ids = XhtmlDoc::GetAllDescendantIDs(xhtmlsrc);
ui.id->addItem(BookPath);
foreach(QString id, ids) {
foreach(QString id, idlst) {
ui.id->addItem(id);
}
ui.id->setEditText(BookPath);
Expand Down
5 changes: 2 additions & 3 deletions src/Dialogs/SemanticTargetID.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define SEMANTICTARGETID_H

#include <QDialog>
#include <QStringList>

#include "ResourceObjects/Resource.h"
#include "ResourceObjects/HTMLResource.h"
Expand All @@ -34,9 +35,7 @@ class SemanticTargetID: public QDialog
Q_OBJECT

public:
SemanticTargetID(HTMLResource *html_resource, QWidget *parent = 0);

void SetList();
SemanticTargetID(HTMLResource *html_resource, const QStringList& idlst, QWidget *parent = 0);

QString GetID();

Expand Down
25 changes: 17 additions & 8 deletions src/MainUI/BookBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,13 @@ void BookBrowser::GetInfo()
if (!html_resource) return;

QString bookpath = resource->GetRelativePath();
QString folder_path = resource->GetFolder();
if (folder_path == ".") folder_path = tr("root folder");
QString primary_lang = html_resource->GetLanguageAttribute();
// fallback to the primary language specified in the OPF metadata
if (primary_lang.isEmpty()) {
primary_lang = m_Book->GetOPF()->GetPrimaryBookLanguage();
}
QString fullfilepath = resource->GetFullPath();
QString version = resource->GetEpubVersion();
double ffsize = QFile(fullfilepath).size() / 1024.0;
Expand All @@ -1717,7 +1723,7 @@ void BookBrowser::GetInfo()
mdlst << "- " + resource->Filename() + "\n";

mdlst << tr("Folder");
mdlst << "- " + resource->GetFolder() + "\n";
mdlst << "- " + folder_path + "\n";

mdlst << tr("Media Type");
mdlst << "- " + resource->GetMediaType() + "\n";
Expand All @@ -1726,9 +1732,8 @@ void BookBrowser::GetInfo()
mdlst << "- " + version + " \n";

mdlst << tr("Primary Language");
QString pl = html_resource->GetLanguageAttribute();
if (!pl.isEmpty()) {
mdlst << "= " + pl + "\n";
if (!primary_lang.isEmpty()) {
mdlst << "= " + primary_lang + "\n";
} else {
mdlst << QString(" \n");
}
Expand Down Expand Up @@ -1822,11 +1827,15 @@ void BookBrowser::AddSemanticCode()
HTMLResource *html_resource = qobject_cast<HTMLResource *>(resource);

QString tgt_id = "";
SemanticTargetID getTarget(html_resource, this);
if (getTarget.exec() == QDialog::Accepted) {
tgt_id = getTarget.GetID();
QString xhtmlsrc = html_resource->GetText();
QStringList idlst = XhtmlDoc::GetAllDescendantIDs(xhtmlsrc);
// run the dialog only if there are ids defined in the xhtml source
if (!idlst.isEmpty()) {
SemanticTargetID getTarget(html_resource, idlst, this);
if (getTarget.exec() == QDialog::Accepted) {
tgt_id = getTarget.GetID();
}
}

QString version = m_Book->GetConstOPF()->GetEpubVersion();
HTMLResource * nav_resource = NULL;
if (version.startsWith('3')) {
Expand Down

0 comments on commit 70bd634

Please sign in to comment.