OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / helpitem.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "helpitem.h"
34
35 #include <coreplugin/helpmanager.h>
36 #include <utils/htmldocextractor.h>
37
38 #include <QtCore/QUrl>
39 #include <QtCore/QByteArray>
40 #include <QtCore/QMap>
41
42 using namespace TextEditor;
43
44 HelpItem::HelpItem()
45 {}
46
47 HelpItem::HelpItem(const QString &helpId, Category category) :
48     m_helpId(helpId), m_docMark(helpId), m_category(category)
49 {}
50
51 HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category category) :
52     m_helpId(helpId), m_docMark(docMark), m_category(category)
53 {}
54
55 HelpItem::~HelpItem()
56 {}
57
58 void HelpItem::setHelpId(const QString &id)
59 { m_helpId = id; }
60
61 const QString &HelpItem::helpId() const
62 { return m_helpId; }
63
64 void HelpItem::setDocMark(const QString &mark)
65 { m_docMark = mark; }
66
67 const QString &HelpItem::docMark() const
68 { return m_docMark; }
69
70 void HelpItem::setCategory(Category cat)
71 { m_category = cat; }
72
73 HelpItem::Category HelpItem::category() const
74 { return m_category; }
75
76 bool HelpItem::isValid() const
77 {
78     if (!Core::HelpManager::instance()->linksForIdentifier(m_helpId).isEmpty())
79         return true;
80     return false;
81 }
82
83 QString HelpItem::extractContent(bool extended) const
84 {
85     Utils::HtmlDocExtractor htmlExtractor;
86     if (extended)
87         htmlExtractor.setMode(Utils::HtmlDocExtractor::Extended);
88     else
89         htmlExtractor.setMode(Utils::HtmlDocExtractor::FirstParagraph);
90
91     QString contents;
92     QMap<QString, QUrl> helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
93     foreach (const QUrl &url, helpLinks) {
94         const QByteArray &html = Core::HelpManager::instance()->fileData(url);
95         switch (m_category) {
96         case Brief:
97             contents = htmlExtractor.getClassOrNamespaceBrief(html, m_docMark);
98             break;
99         case ClassOrNamespace:
100             contents = htmlExtractor.getClassOrNamespaceDescription(html, m_docMark);
101             break;
102         case Function:
103             contents = htmlExtractor.getFunctionDescription(html, m_docMark);
104             break;
105         case Enum:
106             contents = htmlExtractor.getEnumDescription(html, m_docMark);
107             break;
108         case Typedef:
109             contents = htmlExtractor.getTypedefDescription(html, m_docMark);
110             break;
111         case Macro:
112             contents = htmlExtractor.getMacroDescription(html, m_docMark);
113             break;
114         case QmlComponent:
115             contents = htmlExtractor.getQmlComponentDescription(html, m_docMark);
116             break;
117         case QmlProperty:
118             contents = htmlExtractor.getQmlPropertyDescription(html, m_docMark);
119             break;
120
121         default:
122             break;
123         }
124
125         if (!contents.isEmpty())
126             break;
127     }
128     return contents;
129 }