Skip to content

Commit

Permalink
preserve media overlay active class selectors from being considered u…
Browse files Browse the repository at this point in the history
…nused
  • Loading branch information
kevinhendricks committed Nov 30, 2023
1 parent 7ed53a3 commit 8be6790
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ pre-2.x.x
- assign menu accelerators P - &Plugins, and K - Chec&kpoints (thank you BeckyEbook)
- add ability to change keyboard focus using keyboard shortcuts or menus
to BookBrowser, Preview, CodeView, ClipsWindow, and TableOfContents Windows
- preserve Media Overlay Active Classes when deleting unused classes

Bug Fixes
- patch Qt6.5.3 to avoid transient child window resize bug on Windows
- fix QuickParser bug when parseing attribute names not properly ignoreing all legal whitespace
- make OPF parsing robust to alternative whitespace usage as well


Sigil-2.0.2
Expand Down
7 changes: 6 additions & 1 deletion src/MainUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,12 +2980,17 @@ bool MainWindow::DeleteUnusedStyles(bool in_automate)
return false;
}

// get list of any media overlay active class selectors from the opf
QStringList activeclassselectors = m_Book->GetOPF()->GetMediaOverlayActiveClassSelectors();

// This one handles all selector types
QList<BookReports::StyleData *> css_selector_usage = BookReports::GetAllCSSSelectorsUsed(m_Book, true);
QList<BookReports::StyleData *> css_selectors_to_delete;
foreach(BookReports::StyleData *selector, css_selector_usage) {
if (selector->html_filename.isEmpty()) {
css_selectors_to_delete.append(selector);
if (!activeclassselectors.contains(selector->css_selector_text)) {
css_selectors_to_delete.append(selector);
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/ResourceObjects/OPFResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#define QT_ENUM_KEEPEMPTYPARTS QString::KeepEmptyParts
#endif

static const QString MEDIA_PLAYBACK_ACTIVE_CLASS = "media:playback-active-class";
static const QString MEDIA_ACTIVE_CLASS = "media:active-class";
static const QString SIGIL_VERSION_META_NAME = "Sigil version";
static const QString OPF_XML_NAMESPACE = "http://www.idpf.org/2007/opf";
static const QString FALLBACK_MIMETYPE = "text/plain";
Expand Down Expand Up @@ -561,6 +563,30 @@ QStringList OPFResource::GetSpineOrderBookPaths() const
return book_paths_in_reading_order;
}


QStringList OPFResource::GetMediaOverlayActiveClassSelectors() const
{
QReadLocker locker(&GetLock());
QStringList activeclassselectors;
QString source = CleanSource::ProcessXML(GetText(),"application/oebps-package+xml");
OPFParser p;
p.parse(source);
for (int i=0; i < p.m_metadata.count(); ++i) {
if (p.m_metadata.at(i).m_name == "meta") {
MetaEntry me = p.m_metadata.at(i);
QString propval = me.m_atts.value("property", "");
if (propval == MEDIA_ACTIVE_CLASS) {
activeclassselectors << "." + me.m_content;
}
if (propval == MEDIA_PLAYBACK_ACTIVE_CLASS) {
activeclassselectors << "." + me.m_content;
}
}
}
return activeclassselectors;
}


QString OPFResource::GetPrimaryBookTitle() const
{
QString title = "";
Expand Down
7 changes: 6 additions & 1 deletion src/ResourceObjects/OPFResource.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/************************************************************************
**
** Copyright (C) 2015-2020 Kevin B. Hendricks, Stratford ON
** Copyright (C) 2015-2023 Kevin B. Hendricks, Stratford ON
** Copyright (C) 2013 John Schember <[email protected]>
** Copyright (C) 2009-2011 Strahinja Markovic <[email protected]>
**
Expand Down Expand Up @@ -130,6 +130,11 @@ class OPFResource : public XMLResource
*/
QList<MetaEntry> GetDCMetadata() const;

/**
* Returns list of any Media Overlay Active Class Selctors if defined in OPF metadata
*/
QStringList GetMediaOverlayActiveClassSelectors() const;

/**
* Returns the values for a specific dc: metadata name.
*
Expand Down

0 comments on commit 8be6790

Please sign in to comment.