~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/xml-streambookmarks-xbelreader-cpp.html

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
5
<head>
6
 
  <title>Qt 4.5: xbelreader.cpp Example File (xml/streambookmarks/xbelreader.cpp)</title>
 
6
  <title>Qt 4.6: xbelreader.cpp Example File (xml/streambookmarks/xbelreader.cpp)</title>
7
7
  <link href="classic.css" rel="stylesheet" type="text/css" />
8
8
</head>
9
9
<body>
10
10
<table border="0" cellpadding="0" cellspacing="0" width="100%">
11
11
<tr>
12
 
<td align="left" valign="top" width="32"><a href="http://qtsoftware.com/products/qt"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
13
 
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="namespaces.html"><font color="#004faf">All&nbsp;Namespaces</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
14
 
<td align="right" valign="top" width="230"></td></tr></table><h1 class="title">xbelreader.cpp Example File<br /><span class="small-subtitle">xml/streambookmarks/xbelreader.cpp</span>
 
12
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
 
13
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td><td class="searchBar" align="right" valign="center"><form action="http://www.google.com/cse" id="cse-search-box"><div><input type="hidden" name="cx" value="000136343326384750312:dhbxnqlakyu" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></td>
 
14
</tr></table><h1 class="title">xbelreader.cpp Example File<br /><span class="small-subtitle">xml/streambookmarks/xbelreader.cpp</span>
15
15
</h1>
16
16
<pre><span class="comment"> /****************************************************************************
17
17
 **
18
18
 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
19
 ** All rights reserved.
19
20
 ** Contact: Nokia Corporation (qt-info@nokia.com)
20
21
 **
21
22
 ** This file is part of the examples of the Qt Toolkit.
22
23
 **
23
24
 ** $QT_BEGIN_LICENSE:LGPL$
24
 
 ** Commercial Usage
25
 
 ** Licensees holding valid Qt Commercial licenses may use this file in
26
 
 ** accordance with the Qt Commercial License Agreement provided with the
27
 
 ** Software or, alternatively, in accordance with the terms contained in
28
 
 ** a written agreement between you and Nokia.
 
25
 ** No Commercial Usage
 
26
 ** This file contains pre-release code and may not be distributed.
 
27
 ** You may use this file in accordance with the terms and conditions
 
28
 ** contained in the Technology Preview License Agreement accompanying
 
29
 ** this package.
29
30
 **
30
31
 ** GNU Lesser General Public License Usage
31
32
 ** Alternatively, this file may be used under the terms of the GNU Lesser
35
36
 ** ensure the GNU Lesser General Public License version 2.1 requirements
36
37
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
37
38
 **
38
 
 ** In addition, as a special exception, Nokia gives you certain
39
 
 ** additional rights. These rights are described in the Nokia Qt LGPL
40
 
 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
41
 
 ** package.
42
 
 **
43
 
 ** GNU General Public License Usage
44
 
 ** Alternatively, this file may be used under the terms of the GNU
45
 
 ** General Public License version 3.0 as published by the Free Software
46
 
 ** Foundation and appearing in the file LICENSE.GPL included in the
47
 
 ** packaging of this file.  Please review the following information to
48
 
 ** ensure the GNU General Public License version 3.0 requirements will be
49
 
 ** met: http://www.gnu.org/copyleft/gpl.html.
50
 
 **
51
 
 ** If you are unsure which license is appropriate for your use, please
52
 
 ** contact the sales department at http://www.qtsoftware.com/contact.
 
39
 ** In addition, as a special exception, Nokia gives you certain additional
 
40
 ** rights.  These rights are described in the Nokia Qt LGPL Exception
 
41
 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
42
 **
 
43
 ** If you have questions regarding the use of this file, please contact
 
44
 ** Nokia at qt-info@nokia.com.
 
45
 **
 
46
 **
 
47
 **
 
48
 **
 
49
 **
 
50
 **
 
51
 **
 
52
 **
53
53
 ** $QT_END_LICENSE$
54
54
 **
55
55
 ****************************************************************************/</span>
72
72
 
73
73
 bool XbelReader::read(QIODevice *device)
74
74
 {
75
 
     setDevice(device);
76
 
 
77
 
     while (!atEnd()) {
78
 
         readNext();
79
 
 
80
 
         if (isStartElement()) {
81
 
             if (name() == &quot;xbel&quot; &amp;&amp; attributes().value(&quot;version&quot;) == &quot;1.0&quot;)
82
 
                 readXBEL();
83
 
             else
84
 
                 raiseError(QObject::tr(&quot;The file is not an XBEL version 1.0 file.&quot;));
85
 
         }
 
75
     xml.setDevice(device);
 
76
 
 
77
     if (xml.readNextStartElement()) {
 
78
         if (xml.name() == &quot;xbel&quot; &amp;&amp; xml.attributes().value(&quot;version&quot;) == &quot;1.0&quot;)
 
79
             readXBEL();
 
80
         else
 
81
             xml.raiseError(QObject::tr(&quot;The file is not an XBEL version 1.0 file.&quot;));
86
82
     }
87
83
 
88
 
     return !error();
 
84
     return !xml.error();
89
85
 }
90
86
 
91
 
 void XbelReader::readUnknownElement()
 
87
 QString XbelReader::errorString() const
92
88
 {
93
 
     Q_ASSERT(isStartElement());
94
 
 
95
 
     while (!atEnd()) {
96
 
         readNext();
97
 
 
98
 
         if (isEndElement())
99
 
             break;
100
 
 
101
 
         if (isStartElement())
102
 
             readUnknownElement();
103
 
     }
 
89
     return QObject::tr(&quot;%1\nLine %2, column %3&quot;)
 
90
             .arg(xml.errorString())
 
91
             .arg(xml.lineNumber())
 
92
             .arg(xml.columnNumber());
104
93
 }
105
94
 
106
95
 void XbelReader::readXBEL()
107
96
 {
108
 
     Q_ASSERT(isStartElement() &amp;&amp; name() == &quot;xbel&quot;);
109
 
 
110
 
     while (!atEnd()) {
111
 
         readNext();
112
 
 
113
 
         if (isEndElement())
114
 
             break;
115
 
 
116
 
         if (isStartElement()) {
117
 
             if (name() == &quot;folder&quot;)
118
 
                 readFolder(0);
119
 
             else if (name() == &quot;bookmark&quot;)
120
 
                 readBookmark(0);
121
 
             else if (name() == &quot;separator&quot;)
122
 
                 readSeparator(0);
123
 
             else
124
 
                 readUnknownElement();
125
 
         }
 
97
     Q_ASSERT(xml.isStartElement() &amp;&amp; xml.name() == &quot;xbel&quot;);
 
98
 
 
99
     while (xml.readNextStartElement()) {
 
100
         if (xml.name() == &quot;folder&quot;)
 
101
             readFolder(0);
 
102
         else if (xml.name() == &quot;bookmark&quot;)
 
103
             readBookmark(0);
 
104
         else if (xml.name() == &quot;separator&quot;)
 
105
             readSeparator(0);
 
106
         else
 
107
             xml.skipCurrentElement();
126
108
     }
127
109
 }
128
110
 
129
111
 void XbelReader::readTitle(QTreeWidgetItem *item)
130
112
 {
131
 
     Q_ASSERT(isStartElement() &amp;&amp; name() == &quot;title&quot;);
 
113
     Q_ASSERT(xml.isStartElement() &amp;&amp; xml.name() == &quot;title&quot;);
132
114
 
133
 
     QString title = readElementText();
 
115
     QString title = xml.readElementText();
134
116
     item-&gt;setText(0, title);
135
117
 }
136
118
 
137
119
 void XbelReader::readSeparator(QTreeWidgetItem *item)
138
120
 {
 
121
     Q_ASSERT(xml.isStartElement() &amp;&amp; xml.name() == &quot;separator&quot;);
 
122
 
139
123
     QTreeWidgetItem *separator = createChildItem(item);
140
124
     separator-&gt;setFlags(item-&gt;flags() &amp; ~Qt::ItemIsSelectable);
141
125
     separator-&gt;setText(0, QString(30, 0xB7));
142
 
     readElementText();
 
126
     xml.skipCurrentElement();
143
127
 }
144
128
 
145
129
 void XbelReader::readFolder(QTreeWidgetItem *item)
146
130
 {
147
 
     Q_ASSERT(isStartElement() &amp;&amp; name() == &quot;folder&quot;);
 
131
     Q_ASSERT(xml.isStartElement() &amp;&amp; xml.name() == &quot;folder&quot;);
148
132
 
149
133
     QTreeWidgetItem *folder = createChildItem(item);
150
 
     bool folded = (attributes().value(&quot;folded&quot;) != &quot;no&quot;);
 
134
     bool folded = (xml.attributes().value(&quot;folded&quot;) != &quot;no&quot;);
151
135
     treeWidget-&gt;setItemExpanded(folder, !folded);
152
136
 
153
 
     while (!atEnd()) {
154
 
         readNext();
155
 
 
156
 
         if (isEndElement())
157
 
             break;
158
 
 
159
 
         if (isStartElement()) {
160
 
             if (name() == &quot;title&quot;)
161
 
                 readTitle(folder);
162
 
             else if (name() == &quot;folder&quot;)
163
 
                 readFolder(folder);
164
 
             else if (name() == &quot;bookmark&quot;)
165
 
                 readBookmark(folder);
166
 
             else if (name() == &quot;separator&quot;)
167
 
                 readSeparator(folder);
168
 
             else
169
 
                 readUnknownElement();
170
 
         }
 
137
     while (xml.readNextStartElement()) {
 
138
         if (xml.name() == &quot;title&quot;)
 
139
             readTitle(folder);
 
140
         else if (xml.name() == &quot;folder&quot;)
 
141
             readFolder(folder);
 
142
         else if (xml.name() == &quot;bookmark&quot;)
 
143
             readBookmark(folder);
 
144
         else if (xml.name() == &quot;separator&quot;)
 
145
             readSeparator(folder);
 
146
         else
 
147
             xml.skipCurrentElement();
171
148
     }
172
149
 }
173
150
 
174
151
 void XbelReader::readBookmark(QTreeWidgetItem *item)
175
152
 {
176
 
     Q_ASSERT(isStartElement() &amp;&amp; name() == &quot;bookmark&quot;);
 
153
     Q_ASSERT(xml.isStartElement() &amp;&amp; xml.name() == &quot;bookmark&quot;);
177
154
 
178
155
     QTreeWidgetItem *bookmark = createChildItem(item);
179
156
     bookmark-&gt;setFlags(bookmark-&gt;flags() | Qt::ItemIsEditable);
180
157
     bookmark-&gt;setIcon(0, bookmarkIcon);
181
158
     bookmark-&gt;setText(0, QObject::tr(&quot;Unknown title&quot;));
182
 
     bookmark-&gt;setText(1, attributes().value(&quot;href&quot;).toString());
183
 
     while (!atEnd()) {
184
 
         readNext();
185
 
 
186
 
         if (isEndElement())
187
 
             break;
188
 
 
189
 
         if (isStartElement()) {
190
 
             if (name() == &quot;title&quot;)
191
 
                 readTitle(bookmark);
192
 
             else
193
 
                 readUnknownElement();
194
 
         }
 
159
     bookmark-&gt;setText(1, xml.attributes().value(&quot;href&quot;).toString());
 
160
 
 
161
     while (xml.readNextStartElement()) {
 
162
         if (xml.name() == &quot;title&quot;)
 
163
             readTitle(bookmark);
 
164
         else
 
165
             xml.skipCurrentElement();
195
166
     }
196
167
 }
197
168
 
203
174
     } else {
204
175
         childItem = new QTreeWidgetItem(treeWidget);
205
176
     }
206
 
     childItem-&gt;setData(0, Qt::UserRole, name().toString());
 
177
     childItem-&gt;setData(0, Qt::UserRole, xml.name().toString());
207
178
     return childItem;
208
179
 }</pre>
209
180
<p /><address><hr /><div align="center">
210
181
<table width="100%" cellspacing="0" border="0"><tr class="address">
211
 
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
212
 
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
213
 
<td width="30%" align="right"><div align="right">Qt 4.5.2</div></td>
214
 
</tr></table></div></address></body>
 
182
<td width="40%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
 
183
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
184
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
 
185
<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box&t13n_langs=en"></script><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script></tr></table></div></address></body>
215
186
</html>