summaryrefslogtreecommitdiffstats
path: root/htmlhelpdatainterface.cpp
blob: 5a2fe585bf8a0f286643d9e3d230c0b94189315b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/****************************************************************************
 **
 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
 ** This file is part of the doxygen2qthelp project on Trolltech Labs.
 **
 ** This file may be used under the terms of the GNU General Public
 ** License version 2.0 or 3.0 as published by the Free Software Foundation
 ** and appearing in the file LICENSE.GPL included in the packaging of
 ** this file.  Please review the following information to ensure GNU
 ** General Public Licensing requirements will be met:
 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
 ** http://www.gnu.org/copyleft/gpl.html.
 **
 ** If you are unsure which license is appropriate for your use, please
 ** contact the sales department at qt-sales@nokia.com.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/

#include "htmlhelpdatainterface_p.h"
#include "htmlhelpparser_p.h"

#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QVariant>
#include <QtCore/QSettings>

QT_BEGIN_NAMESPACE

HtmlHelpDataInterface::HtmlHelpDataInterface(const QString &projectFileName,
        const QString &namespaceName, const QString &virtualFolder)
        : m_nameSpace(namespaceName), m_virtualFolder(virtualFolder)
{
    initFromDoxygenHtmlHelpProject(projectFileName);
}

void HtmlHelpDataInterface::initFromDoxygenHtmlHelpProject(
        const QString &projectFileName)
{
    // Parse hhc/hhk/hhp
    QSettings iniReader(projectFileName, QSettings::IniFormat);
    m_projectTitle = iniReader.value("OPTIONS/Title").toString();
    m_filterIdent = m_projectTitle;
    m_entryPageHref = iniReader.value("OPTIONS/Default topic",
            "index.html").toString();
    parseToc(getTocFileName(projectFileName));
    parseIndex(getIndexFileName(projectFileName));

    // File list
    m_rootPath = getRootPath(projectFileName);
    scanRootPath();

    // Custom filters
    QHelpDataCustomFilter everything;
    everything.filterAttributes << m_filterIdent;
    everything.name = m_projectTitle;
    m_custumFilters << everything;

    // Sections
    QHelpDataFilterSection section;
    section.addFilterAttribute(m_filterIdent);
    section.setIndices(m_index);
    section.setContents(m_toc);
    section.setFiles(m_files);
    m_filterSections.append(section);
}

const QStringList HtmlHelpDataInterface::applyPrefix(const QStringList &list,
        const QString &prefix) const
{
    if (prefix.isNull()) {
        return list;
    }

    QStringList processed;
    foreach (const QString &entry, list) {
        processed << prefix + "/" + entry;
    }
    return processed;
}

QStringList HtmlHelpDataInterface::findSubDirs(const QString &dir) const
{
    return QDir(dir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
}

QStringList HtmlHelpDataInterface::findDoxygenFiles(const QString &dir) const
{
    const QStringList filter = QStringList()
            << "*.css"
            << "*.gif"
            << "*.htm"
            << "*.html"
            << "*.jpeg"
            << "*.jpg"
            << "*.png"
            ;
    return QDir(dir).entryList(filter);
}

QStringList HtmlHelpDataInterface::findDoxygenFilesRecursively(const QString &dir,
        const QString &prefix) const
{
    QStringList files;
    foreach (const QString &subDir, findSubDirs(dir)) {
        files += findDoxygenFilesRecursively(dir + "/" + subDir,
                prefix.isNull() ? subDir : prefix + "/" + subDir);
    }
    return files + applyPrefix(findDoxygenFiles(dir), prefix);
}

void HtmlHelpDataInterface::scanRootPath()
{
    m_files = findDoxygenFilesRecursively(m_rootPath);
}

void HtmlHelpDataInterface::parseToc(const QString &fileName)
{
    HtmlHelpParser parser;
    parser.parseFile(fileName);
    m_toc = parser.stealToc(m_projectTitle, m_entryPageHref);
}

void HtmlHelpDataInterface::parseIndex(const QString &fileName)
{
    HtmlHelpParser parser;
    parser.parseFile(fileName);
    m_index = parser.stealIndex();
}

QString HtmlHelpDataInterface::replaceFileExtension(const QString &fileName,
        const QString &extension)
{
    QFileInfo fileInfo(fileName);
    const int suffixLen = fileInfo.suffix().count();
    return fileName.left(fileName.count() - suffixLen) + extension;
}

QString HtmlHelpDataInterface::getTocFileName(const QString &projectFileName)
{
    return replaceFileExtension(projectFileName, QLatin1String("hhc"));
}

QString HtmlHelpDataInterface::getIndexFileName(const QString &projectFileName)
{
    return replaceFileExtension(projectFileName, QLatin1String("hhk"));
}

QString HtmlHelpDataInterface::getRootPath(const QString &projectFileName)
{
    QFileInfo fileInfo(projectFileName);
    return fileInfo.dir().absolutePath();
}

QString HtmlHelpDataInterface::namespaceName() const
{
    return m_nameSpace;
}

QString HtmlHelpDataInterface::virtualFolder() const
{
    return m_virtualFolder;
}

QList<QHelpDataCustomFilter> HtmlHelpDataInterface::customFilters() const
{
    return m_custumFilters;
}

QList<QHelpDataFilterSection> HtmlHelpDataInterface::filterSections() const
{
    return m_filterSections;
}

QMap<QString, QVariant> HtmlHelpDataInterface::metaData() const
{
    return QMap<QString, QVariant>();
}

QString HtmlHelpDataInterface::rootPath() const
{
    return m_rootPath;
}

QT_END_NAMESPACE