View Single Post
Old 09-06-2022, 09:47 AM   #11
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,885
Karma: 6120478
Join Date: Nov 2009
Device: many
It is all platform agnostic code. It works in my macOS.

This is strange.

Code:
HTMLResource *Book::CreateEmptyHTMLFile(const QString &folderpath)
{
    HTMLResource *html_resource = CreateNewHTMLFile(folderpath);
    QString version = html_resource->GetEpubVersion();
    QString data;
    QString template_path;
    if (version.startsWith('2')) {
        template_path = Utility::DefinePrefsDir() + "/" + "user-template2.xhtml";
        data = EMPTY_HTML_FILE;
    } else {
        template_path = Utility::DefinePrefsDir() + "/" + "user-template3.xhtml";
        data = EMPTY_HTML5_FILE;
    }
    if (QFile::exists(template_path)) {
        data = CleanSource::Mend(Utility::ReadUnicodeTextFile(template_path), version);
    }
    html_resource->SetText(data);
    SetModified(true);
    return html_resource;
}
and

Code:
CSSResource *Book::CreateEmptyCSSFile(const QString &folderpath)
{
    TempFolder tempfolder;
    QString fullfilepath = tempfolder.GetPath() + "/" + m_Mainfolder->GetUniqueFilenameVersion(FIRST_CSS_NAME);
    Utility::WriteUnicodeTextFile("", fullfilepath);
    Resource * resource = m_Mainfolder->AddContentFileToFolder(fullfilepath,
                                                               true,
                                                               "text/css",
                                                               QString(),
                                                               folderpath);
    CSSResource *css_resource = qobject_cast<CSSResource *>(resource);
    QString version = css_resource->GetEpubVersion();
    QString data = "";
    QString template_path;
    if (version.startsWith('2')) {
        template_path = Utility::DefinePrefsDir() + "/" + "user-template2.css";
    } else {
        template_path = Utility::DefinePrefsDir() + "/" + "user-template3.css";
    }
    if (QFile::exists(template_path)) {
        data = Utility::ReadUnicodeTextFile(template_path);
    }
    css_resource->SetText(data);
    SetModified(true);
    return css_resource;
}

So long as you used the correct file names it should work.

For epub2:

user-template2.xhtml
user-template2.css

and for epub3:

user-template3.xhtml
user-template3.css

Last edited by KevinH; 09-06-2022 at 11:09 AM.
KevinH is offline   Reply With Quote