source: trunk/tools/assistant/compat/profile.cpp@ 235

Last change on this file since 235 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt Assistant of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "profile.h"
43#include <QTextCodec>
44#include <QFileInfo>
45#include <QRegExp>
46#include <QDir>
47#include <QList>
48#include <QLibraryInfo>
49
50QT_BEGIN_NAMESPACE
51
52#define QT_TITLE QLatin1String("Qt Reference Documentation")
53#define DESIGNER_TITLE QLatin1String("Qt Designer Manual")
54#define ASSISTANT_TITLE QLatin1String("Qt Assistant Manual")
55#define LINGUIST_TITLE QLatin1String("Qt Linguist Manual")
56#define QMAKE_TITLE QLatin1String("qmake Manual")
57
58Profile *Profile::createDefaultProfile(const QString &docPath)
59{
60 QString path = QLibraryInfo::location(QLibraryInfo::DocumentationPath);
61 if (!docPath.isEmpty())
62 path = docPath;
63 path = QDir::cleanPath(path) + QLatin1String("/html/");
64
65 Profile *profile = new Profile;
66 profile->valid = true;
67 profile->type = DefaultProfile;
68 profile->props[QLatin1String("name")] = QLatin1String("default");
69 profile->props[QLatin1String("applicationicon")] = QLatin1String("assistant.png");
70 profile->props[QLatin1String("aboutmenutext")] = QLatin1String("About Qt");
71 profile->props[QLatin1String("abouturl")] = QLatin1String("about_qt");
72 profile->props[QLatin1String("basepath")] = path;
73 profile->props[QLatin1String("startpage")] = path + QLatin1String("index.html");
74
75 profile->addDCFTitle( path + QLatin1String("qt.dcf"), QT_TITLE );
76 profile->addDCFTitle( path + QLatin1String("designer.dcf"), DESIGNER_TITLE );
77 profile->addDCFTitle( path + QLatin1String("assistant.dcf"), ASSISTANT_TITLE );
78 profile->addDCFTitle( path + QLatin1String("linguist.dcf"), LINGUIST_TITLE );
79 profile->addDCFTitle( path + QLatin1String("qmake.dcf"), QMAKE_TITLE );
80
81 profile->addDCFIcon( QT_TITLE, QLatin1String("qt.png") );
82 profile->addDCFIcon( DESIGNER_TITLE, QLatin1String("designer.png") );
83 profile->addDCFIcon( ASSISTANT_TITLE, QLatin1String("assistant.png") );
84 profile->addDCFIcon( LINGUIST_TITLE, QLatin1String("linguist.png") );
85
86 profile->addDCFIndexPage( QT_TITLE, path + QLatin1String("index.html") );
87 profile->addDCFIndexPage( DESIGNER_TITLE, path + QLatin1String("designer-manual.html") );
88 profile->addDCFIndexPage( ASSISTANT_TITLE, path + QLatin1String("assistant-manual.html") );
89 profile->addDCFIndexPage( LINGUIST_TITLE, path + QLatin1String("linguist-manual.html") );
90 profile->addDCFIndexPage( QMAKE_TITLE, path + QLatin1String("qmake-manual.html") );
91
92 profile->addDCFImageDir( QT_TITLE, QLatin1String("../../gif/") );
93 profile->addDCFImageDir( DESIGNER_TITLE, QLatin1String("../../gif/") );
94 profile->addDCFImageDir( ASSISTANT_TITLE, QLatin1String("../../gif/") );
95 profile->addDCFImageDir( LINGUIST_TITLE, QLatin1String("../../gif/") );
96 profile->addDCFImageDir( QMAKE_TITLE, QLatin1String("../../gif/") );
97
98 return profile;
99}
100
101Profile::Profile()
102 : valid( true ), dparser( 0 )
103{
104 type = DefaultProfile;
105}
106
107bool Profile::isValid() const
108{
109 return valid;
110}
111
112void Profile::addDCFTitle(const QString &dcf, const QString &title)
113{
114 QString absdcf = QFileInfo(dcf).absoluteFilePath();
115 dcfTitles[title] = absdcf;
116 if (!docs.contains(absdcf))
117 docs << absdcf;
118}
119
120void Profile::addDCF(const QString &docfile)
121{
122 if( !docs.contains( docfile ) == 0 )
123 docs << docfile;
124}
125
126void Profile::addDCFIcon(const QString docfile, const QString &icon)
127{
128 icons[docfile] = icon;
129}
130
131void Profile::addDCFIndexPage(const QString title, const QString &indexPage)
132{
133 indexPages[title] = indexPage;
134}
135
136void Profile::addDCFImageDir(const QString docfile, const QString &imgDir)
137{
138 imageDirs[docfile] = imgDir;
139}
140
141void Profile::addProperty(const QString &name, const QString &value)
142{
143 props[name] = value;
144}
145
146bool Profile::hasDocFile(const QString &name)
147{
148 return docs.contains( name );
149}
150
151void Profile::removeDocFileEntry(const QString &docfile)
152{
153 docs.removeAll(docfile);
154 QStringList titles;
155
156 for( QMap<QString,QString>::Iterator it = dcfTitles.begin();
157 it != dcfTitles.end(); ++it ) {
158 if( (*it) == docfile ) {
159 indexPages.remove( *it );
160 icons.remove( *it );
161 imageDirs.remove( *it );
162 titles << it.key();
163 }
164 }
165
166 for( QStringList::ConstIterator title = titles.constBegin();
167 title != titles.constEnd(); ++title )
168 dcfTitles.remove( *title );
169
170#ifdef ASSISTANT_DEBUG
171 qDebug() << "docs:\n - " << docs.join("\n - ");
172 qDebug() << "titles:\n - " << titles.join("\n - ");
173 qDebug() << "keys:\n - " << ((QStringList*)&(dcfTitles.keys()))->join("\n - ");
174 qDebug() << "values:\n - " << ((QStringList*)&(dcfTitles.values()))->join("\n - ");
175#endif
176}
177
178QString Profile::storableFilePath(const QString &fileName)
179{
180 QString path = QLibraryInfo::location(QLibraryInfo::DocumentationPath).replace(QLatin1String("\\"), QLatin1String("/"));
181 QString fName = fileName;
182 if (fName.startsWith(path))
183 fName.replace(0, path.length(), QLatin1String("$DOCPATH$"));
184 return fName;
185}
186
187QString Profile::loadableFilePath(const QString &fileName)
188{
189 QString path = QLibraryInfo::location(QLibraryInfo::DocumentationPath).replace(QLatin1String("\\"), QLatin1String("/"));
190 QString fName = fileName;
191 if (fName.startsWith(QLatin1String("$DOCPATH$")))
192 fName.replace(0, 9, path);
193 return fName;
194}
195
196QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.