Skip to content

Commit

Permalink
allow more than one semantic per file
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Oct 16, 2024
1 parent e1e7280 commit 81dfbcd
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 111 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ set( DIALOG_FILES
Dialogs/SelectIndexTitle.h
Dialogs/SelectFiles.cpp
Dialogs/SelectFiles.h
Dialogs/SemanticTargetID.cpp
Dialogs/SemanticTargetID.h
Dialogs/AddAutomateTool.cpp
Dialogs/AddAutomateTool.h
Dialogs/AddAutomatePlugin.cpp
Expand Down Expand Up @@ -528,6 +530,7 @@ set( UI_FILES
Form_Files/SelectId.ui
Form_Files/SelectIndexTitle.ui
Form_Files/SelectFiles.ui
Form_Files/SemanticTargetID.ui
Form_Files/MetaEditor.ui
Form_Files/AddAutomateTool.ui
Form_Files/AddAutomatePlugin.ui
Expand Down
2 changes: 1 addition & 1 deletion src/Dialogs/SelectHyperlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void SelectHyperlink::SetList()
{
m_SelectHyperlinkModel->clear();
QStringList header;
header.append(tr("Targets in the Book"));
header.append(tr("Targets"));
m_SelectHyperlinkModel->setHorizontalHeaderLabels(header);
ui.list->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.list->setModel(m_SelectHyperlinkModel);
Expand Down
90 changes: 90 additions & 0 deletions src/Dialogs/SemanticTargetID.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/************************************************************************
**
** Copyright (C) 2024 Kevin B. Hendricks, Stratford Ontario Canada
**
** This file is part of Sigil.
**
** Sigil is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Sigil is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Sigil. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/

#include <QLineEdit>

#include "Dialogs/SemanticTargetID.h"
#include "ResourceObjects/HTMLResource.h"
#include "Misc/SettingsStore.h"

static QString SETTINGS_GROUP = "semantic_target_id";

SemanticTargetID::SemanticTargetID(HTMLResource *html_resource, QWidget *parent)
:
QDialog(parent),
m_SelectedText(""),
m_HTMLResource(html_resource)
{
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) {
ui.id->addItem(id);
}
ui.id->setEditText(BookPath);
}


QString SemanticTargetID::GetID()
{
return m_SelectedText;
}

void SemanticTargetID::SetSelectedText()
{
QString tgt = ui.id->currentText();
if (tgt == m_HTMLResource->GetRelativePath()) tgt = "";
m_SelectedText = tgt;
}

void SemanticTargetID::ReadSettings()
{
SettingsStore settings;
settings.beginGroup(SETTINGS_GROUP);
QByteArray geometry = settings.value("geometry").toByteArray();
if (!geometry.isNull()) {
restoreGeometry(geometry);
}
settings.endGroup();
}

void SemanticTargetID::WriteSettings()
{
SetSelectedText();
SettingsStore settings;
settings.beginGroup(SETTINGS_GROUP);
settings.setValue("geometry", saveGeometry());
settings.endGroup();
}

void SemanticTargetID::connectSignalsSlots()
{
connect(this, SIGNAL(accepted()), this, SLOT(WriteSettings()));
}
59 changes: 59 additions & 0 deletions src/Dialogs/SemanticTargetID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/************************************************************************
**
** Copyright (C) 2024 Kevin B. Hendricks, Stratford Ontario Canada
**
** This file is part of Sigil.
**
** Sigil is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Sigil is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Sigil. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/

#pragma once
#ifndef SEMANTICTARGETID_H
#define SEMANTICTARGETID_H

#include <QDialog>

#include "ResourceObjects/Resource.h"
#include "ResourceObjects/HTMLResource.h"
#include "ui_SemanticTargetID.h"

class SemanticTargetID: public QDialog
{
Q_OBJECT

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

void SetList();

QString GetID();

private slots:
void WriteSettings();

private:
void SetSelectedText();

void ReadSettings();
void connectSignalsSlots();

QString m_SelectedText;

HTMLResource *m_HTMLResource;

Ui::SemanticTargetID ui;
};

#endif // SEMANTICTARGETID_H
107 changes: 107 additions & 0 deletions src/Form_Files/SemanticTargetID.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SemanticTargetID</class>
<widget class="QDialog" name="SemanticTargetID">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>504</width>
<height>106</height>
</rect>
</property>
<property name="windowTitle">
<string>Target for Semantic</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="toolTip">
<string>Select an ID or use the default file level target for this Semantic setting.</string>
</property>
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="id">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<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>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SemanticTargetID</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SemanticTargetID</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
15 changes: 11 additions & 4 deletions src/MainUI/BookBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "BookManipulation/FolderKeeper.h"
#include "Dialogs/DeleteFiles.h"
#include "Dialogs/RenameTemplate.h"
#include "Dialogs/SemanticTargetID.h"
#include "Dialogs/AddSemantics.h"
#include "Dialogs/SelectFolder.h"
#include "Dialogs/RERenamer.h"
Expand Down Expand Up @@ -1686,6 +1687,12 @@ 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 version = m_Book->GetConstOPF()->GetEpubVersion();
HTMLResource * nav_resource = NULL;
if (version.startsWith('3')) {
Expand All @@ -1697,9 +1704,9 @@ void BookBrowser::AddSemanticCode()

if (version.startsWith('3')) {
NavProcessor navproc(nav_resource);
current_code = navproc.GetLandmarkCodeForResource(resource);
current_code = navproc.GetLandmarkCodeForResource(resource, tgt_id);
} else {
current_code = m_Book->GetOPF()->GetGuideSemanticCodeForResource(resource);
current_code = m_Book->GetOPF()->GetGuideSemanticCodeForResource(resource, tgt_id);
}

if (version.startsWith('3')) {
Expand All @@ -1711,7 +1718,7 @@ void BookBrowser::AddSemanticCode()
// do allow a user to change only the toc semantics on the nav resource
if ((html_resource != nav_resource) || (new_code == "toc")) {
NavProcessor navproc(nav_resource);
navproc.AddLandmarkCode(html_resource, new_code);
navproc.AddLandmarkCode(html_resource, new_code, true, tgt_id);
m_OPFModel->Refresh();
emit BookContentModified();
}
Expand All @@ -1722,7 +1729,7 @@ void BookBrowser::AddSemanticCode()
if (addmeaning.exec() == QDialog::Accepted) {
codes = addmeaning.GetSelectedEntries();
if (!codes.isEmpty()) {
m_Book->GetOPF()->AddGuideSemanticCode(html_resource, codes.at(0));
m_Book->GetOPF()->AddGuideSemanticCode(html_resource, codes.at(0), true, tgt_id);
m_OPFModel->Refresh();
emit BookContentModified();
}
Expand Down
Loading

2 comments on commit 81dfbcd

@dougmassay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to build and test a bit in the next few days. If not I'll do it this weekend.

@kevinhendricks
Copy link
Contributor Author

@kevinhendricks kevinhendricks commented on 81dfbcd Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It is hard to find epubs with more than one semantic set in the same file in the wild. Normally landmarks/guides items standalone as separate files since they typically start on a new page. Technically it is possible but I have never actualky seen one before.

I will try to concoct a test case from the bug report and post it for testing.

We will also need to better handle this case in the "Reports". I have ignored Reports for the time being.

Also we need to add a GetInfo command for xhtml files in BookBrowser to show all manifest properties, and all semantics for the selected file. Maybe include all images, all footnotes, all ids, etc.

Please sign in to comment.