[umbrello] /: Use standard KDE4/KF5 docbook support to create application welcome page.

Ralf Habacker null at kde.org
Mon Jan 9 20:46:38 UTC 2017


Git commit 67be64955649836cef148a7208c863ff98ae180b by Ralf Habacker.
Committed on 09/01/2017 at 20:46.
Pushed by habacker into branch 'master'.

Use standard KDE4/KF5 docbook support to create application welcome page.

Application welcome page is now installed in apphelp subdir of umbrello
doc installation path.

M  +1    -79   doc/CMakeLists.txt
A  +14   -0    doc/apphelp/CMakeLists.txt
R  +0    -0    doc/apphelp/index.docbook [from: doc/welcome.docbook - 100% similarity]
M  +32   -13   umbrello/umlappprivate.cpp
M  +2    -0    umbrello/umlappprivate.h

https://commits.kde.org/umbrello/67be64955649836cef148a7208c863ff98ae180b

diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
index d20d0e705..b4d6a8578 100644
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -1,77 +1,9 @@
 if (NOT BUILD_KF5)
     set(KDOCTOOLS_CUSTOMIZATION_DIR "${KDE4_DATA_INSTALL_DIR}/ksgmltools2/customization")
-    if(DEFINED KDE4_MEINPROC_EXECUTABLE)
-        set(KDOCTOOLS_MEINPROC_EXECUTABLE ${KDE4_MEINPROC_EXECUTABLE})
-    else()
-        set(KDOCTOOLS_MEINPROC_EXECUTABLE meinproc4)
-    endif()
 else()
     set(KDOCTOOLS_CUSTOMIZATION_DIR "${KDOCTOOLS_DATA_INSTALL_DIR}/kdoctools/customization")
 endif()
 
-function(_kdoctools_create_target_name out in)
-    string(REGEX REPLACE "^${CMAKE_BINARY_DIR}/?" "" in "${in}")
-    string(REGEX REPLACE "[^0-9a-zA-Z]+" "-" tmp "${in}")
-    set(${out} ${tmp} PARENT_SCOPE)
-endfunction()
-
-function (kdoctools_create_article docbook)
-    # Parse arguments
-    set(options)
-    set(oneValueArgs INSTALL_DESTINATION SUBDIR)
-    set(multiValueArgs)
-    cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
-    if(NOT DEFINED ARGS_SUBDIR)
-        message(FATAL_ERROR "SUBDIR needs to be defined when calling kdoctools_create_article")
-    endif()
-
-    # Init vars
-    get_filename_component(docbook ${docbook} ABSOLUTE)
-    file(RELATIVE_PATH src_doc ${CMAKE_CURRENT_SOURCE_DIR} ${docbook})
-    get_filename_component(src_dir ${src_doc} DIRECTORY)
-    get_filename_component(_name ${docbook} NAME_WE)
-    set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/${src_dir})
-    set(build_html ${build_dir}/${_name}.html)
-
-    # current directory is the docbook directory, but if this is empty, the
-    # globs which finds the docbooks and the images will be empty too as
-    # they will expand into "/*.docbook" and "/*.png"
-    if (src_dir STREQUAL "")
-        set(src_dir ".")
-    endif ()
-
-    # Create some place to store our files
-    file(MAKE_DIRECTORY ${build_dir})
-
-    #Bootstrap
-    if (_kdoctoolsBootStrapping)
-        set(_bootstrapOption "--srcdir=${KDocTools_BINARY_DIR}/src")
-    elseif (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
-        set(_bootstrapOption "--srcdir=${KDOCTOOLS_DATA_INSTALL_DIR}/kdoctools")
-    else ()
-        set(_bootstrapOption)
-    endif ()
-    set(_ssheet "${KDOCTOOLS_CUSTOMIZATION_DIR}/kde-chunk.xsl")
-
-    add_custom_command(OUTPUT ${build_html}
-        COMMAND ${KDOCTOOLS_MEINPROC_EXECUTABLE} --check ${_bootstrapOption} -o ${build_html} ${src_doc}
-        DEPENDS ${src_doc} ${_ssheet}
-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-    )
-
-    _kdoctools_create_target_name(_targ_html ${build_html})
-    add_custom_target(${_targ_html} ALL DEPENDS ${build_html})
-
-    set(installDest "${ARGS_INSTALL_DESTINATION}")
-    if(installDest)
-        set(subdir "${ARGS_SUBDIR}")
-#        file(GLOB images ${src_dir}/*.png)
-#        install(FILES ${build_doc} ${src_docs} ${images} DESTINATION ${installDest}/${subdir})
-        install(FILES ${build_html} DESTINATION ${installDest}/${subdir})
-    endif()
-endfunction()
-
 ########### install files ###############
 if(BUILD_KF5)
     file(READ "index.docbook" index_file)
@@ -79,18 +11,8 @@ if(BUILD_KF5)
     string(REPLACE "kdex.dtd" "kdedbx45.dtd" index_file "${index_file}")
     file(WRITE "index-kf5.docbook" "${index_file}")
     kdoctools_create_handbook(index-kf5.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR umbrello)
-
-    file(READ "welcome.docbook" index_file)
-    string(REPLACE "4.2" "4.5" index_file "${index_file}")
-    string(REPLACE "kdex.dtd" "kdedbx45.dtd" index_file "${index_file}")
-    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/welcome.docbook "${index_file}")
-    if(WITH_WELCOME_PAGE)
-        kdoctools_create_article(${CMAKE_CURRENT_BINARY_DIR}/welcome.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR umbrello)
-    endif()
 else()
     kde4_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR umbrello)
-    if(WITH_WELCOME_PAGE)
-        kdoctools_create_article(welcome.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR umbrello)
-    endif()
 endif()
 
+add_subdirectory(apphelp)
diff --git a/doc/apphelp/CMakeLists.txt b/doc/apphelp/CMakeLists.txt
new file mode 100644
index 000000000..c389ca919
--- /dev/null
+++ b/doc/apphelp/CMakeLists.txt
@@ -0,0 +1,14 @@
+########### install files ###############
+if(BUILD_KF5)
+    file(READ "index.docbook" index_file)
+    string(REPLACE "4.2" "4.5" index_file "${index_file}")
+    string(REPLACE "kdex.dtd" "kdedbx45.dtd" index_file "${index_file}")
+    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/index.docbook "${index_file}")
+    if(WITH_WELCOME_PAGE)
+        kdoctools_create_handbook(${CMAKE_CURRENT_BINARY_DIR}/index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR umbrello/apphelp)
+    endif()
+else()
+    if(WITH_WELCOME_PAGE)
+        kde4_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR umbrello/apphelp)
+    endif()
+endif()
diff --git a/doc/welcome.docbook b/doc/apphelp/index.docbook
similarity index 100%
rename from doc/welcome.docbook
rename to doc/apphelp/index.docbook
diff --git a/umbrello/umlappprivate.cpp b/umbrello/umlappprivate.cpp
index cf8a9b5b9..64f051e4c 100644
--- a/umbrello/umlappprivate.cpp
+++ b/umbrello/umlappprivate.cpp
@@ -12,6 +12,8 @@
 
 #include "debug_utils.h"
 
+#include <KFilterDev>
+
 /**
  * Find welcome.html file for displaying in the welcome window.
  *
@@ -21,7 +23,7 @@ QString UMLAppPrivate::findWelcomeFile()
 {
     QStringList dirList;
     // from build dir
-    dirList.append(QCoreApplication::applicationDirPath() + QLatin1String("/../doc"));
+    dirList.append(QCoreApplication::applicationDirPath() + QLatin1String("/../doc/apphelp"));
 
     // determine path from installation
 #if QT_VERSION > 0x050000
@@ -34,30 +36,30 @@ QString UMLAppPrivate::findWelcomeFile()
 
     // from custom install
     foreach(const QString &lang, langList) {
-        dirList.append(QCoreApplication::applicationDirPath() + QString(QLatin1String("/../share/doc/HTML/%1/umbrello")).arg(lang));
+        dirList.append(QCoreApplication::applicationDirPath() + QString(QLatin1String("/../share/doc/HTML/%1/umbrello/apphelp")).arg(lang));
     }
-    dirList.append(QCoreApplication::applicationDirPath() + QLatin1String("/../share/doc/HTML/en/umbrello"));
+    dirList.append(QCoreApplication::applicationDirPath() + QLatin1String("/../share/doc/HTML/en/umbrello/apphelp"));
 
     QStringList locations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
     // from real installation
     foreach(const QString &location, locations) {
         foreach(const QString &lang, langList) {
-            dirList.append(QString(QLatin1String("%1/doc/HTML/%2/umbrello")).arg(location).arg(lang));
+            dirList.append(QString(QLatin1String("%1/doc/HTML/%2/umbrello/apphelp")).arg(location).arg(lang));
         }
-        dirList.append(QString(QLatin1String("%1/doc/HTML/en/umbrello")).arg(location));
+        dirList.append(QString(QLatin1String("%1/doc/HTML/en/umbrello/apphelp")).arg(location));
     }
 #else
     KLocale *local = KGlobal::locale();
     QString lang = local->language();
     // from custom install
-    dirList.append(QCoreApplication::applicationDirPath() + QString(QLatin1String("/../share/doc/HTML/%1/umbrello")).arg(lang));
-    dirList.append(QCoreApplication::applicationDirPath() + QLatin1String("/../share/doc/HTML/en/umbrello"));
+    dirList.append(QCoreApplication::applicationDirPath() + QString(QLatin1String("/../share/doc/HTML/%1/umbrello/apphelp")).arg(lang));
+    dirList.append(QCoreApplication::applicationDirPath() + QLatin1String("/../share/doc/HTML/en/umbrello/apphelp"));
 
     // /usr/share/doc/kde
-    dirList.append(KStandardDirs::installPath("html") + lang + QLatin1String("/umbrello"));
+    dirList.append(KStandardDirs::installPath("html") + lang + QLatin1String("/umbrello/apphelp"));
 #endif
     foreach(const QString &dir, dirList) {
-        QString filePath = dir + QLatin1String("/welcome.html");
+        QString filePath = dir + QLatin1String("/index.cache.bz2");
         QFileInfo fi(filePath);
         if (fi.exists()) {
             uDebug() << "searching for" << filePath << "found";
@@ -78,11 +80,28 @@ QString UMLAppPrivate::findWelcomeFile()
  */
 QString UMLAppPrivate::readWelcomeFile(const QString &file)
 {
-    QFile f(file);
-    if (!f.open(QIODevice::ReadOnly))
+    QString html;
+    if (file.endsWith(QLatin1String(".cache.bz2"))) {
+        QIODevice *d =  KFilterDev::deviceForFile(file);
+        if (!d->open(QIODevice::ReadOnly)) {
+            uError() << "could not open archive " << file;
+            return QString();
+        }
+        QByteArray data = d->readAll();
+        html = QString::fromUtf8(data);
+        d->close();
+    } else {
+        QFile f(file);
+        if (!f.open(QIODevice::ReadOnly))
+            return QString();
+        QTextStream in(&f);
+        html = in.readAll();
+    }
+
+    if (html.isEmpty()) {
+        uError() << "Empty welcome page loaded" << file;
         return QString();
-    QTextStream in(&f);
-    QString html = in.readAll();
+    }
 
     html.replace(QLatin1String("<FILENAME filename=\"index.html\">"),QLatin1String(""));
     html.replace(QLatin1String("</FILENAME>"),QLatin1String(""));
diff --git a/umbrello/umlappprivate.h b/umbrello/umlappprivate.h
index ed265b64f..9a9c8b61f 100644
--- a/umbrello/umlappprivate.h
+++ b/umbrello/umlappprivate.h
@@ -167,6 +167,8 @@ public slots:
         if (file.isEmpty())
             return;
         QString html = readWelcomeFile(file);
+        if (html.isEmpty())
+            return;
         // qDebug() << html;
         welcomeWindow = new QDockWidget(i18n("Welcome"), parent);
         welcomeWindow->setObjectName(QLatin1String("WelcomeDock"));


More information about the kde-doc-english mailing list