Mercurial > projects > qtd
comparison demos/browser/xbel.d @ 80:85c59c4e5f19
remove QLatin1String and other fixes
author | mandel |
---|---|
date | Sun, 24 May 2009 15:25:41 +0000 |
parents | 0654fc9bac95 |
children | 5c8c9c5d9ee1 |
comparison
equal
deleted
inserted
replaced
79:957f549cfc65 | 80:85c59c4e5f19 |
---|---|
75 qDeleteAll(m_children); | 75 qDeleteAll(m_children); |
76 m_parent = 0; | 76 m_parent = 0; |
77 m_type = BookmarkNode.Root; | 77 m_type = BookmarkNode.Root; |
78 } | 78 } |
79 | 79 |
80 bool operator==(BookmarkNode other) | 80 int opEquals(BookmarkNode other) |
81 { | 81 { |
82 if (url != other.url || title != other.title || desc != other.desc || expanded != other.expanded | 82 if (url != other.url || title != other.title || desc != other.desc || expanded != other.expanded |
83 || m_type != other.m_type || m_children.length != other.m_children.length) | 83 || m_type != other.m_type || m_children.length != other.m_children.length) |
84 return false; | 84 return cast(int) false; |
85 | 85 |
86 for (int i = 0; i < m_children.length; ++i) | 86 for (int i = 0; i < m_children.length; ++i) |
87 if (!((*(m_children[i])) == (*(other.m_children[i])))) | 87 if (!((*(m_children[i])) == (*(other.m_children[i])))) |
88 return false; | 88 return cast(int) false; |
89 return true; | 89 return cast(int) true; |
90 } | 90 } |
91 | 91 |
92 Type type() | 92 Type type() |
93 { | 93 { |
94 return m_type; | 94 return m_type; |
161 BookmarkNode root = new BookmarkNode(BookmarkNode.Root); | 161 BookmarkNode root = new BookmarkNode(BookmarkNode.Root); |
162 setDevice(device); | 162 setDevice(device); |
163 while (!atEnd()) { | 163 while (!atEnd()) { |
164 readNext(); | 164 readNext(); |
165 if (isStartElement()) { | 165 if (isStartElement()) { |
166 string version_ = attributes().value(QLatin1String("version")).toString(); | 166 string version_ = attributes().value("version").toString(); |
167 if (name() == QLatin1String("xbel") && (version_.isEmpty() || version_ == QLatin1String("1.0"))) { | 167 if (name() == "xbel" && (version_.isEmpty() || version_ == "1.0")) { |
168 readXBEL(root); | 168 readXBEL(root); |
169 } else { | 169 } else { |
170 raiseError(QObject.tr("The file is not an XBEL version 1.0 file.")); | 170 raiseError(QObject.tr("The file is not an XBEL version 1.0 file.")); |
171 } | 171 } |
172 } | 172 } |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void readXBEL(BookmarkNode parent) | 194 void readXBEL(BookmarkNode parent) |
195 { | 195 { |
196 assert(isStartElement() && name() == QLatin1String("xbel")); | 196 assert(isStartElement() && name() == "xbel"); |
197 | 197 |
198 while (!atEnd()) { | 198 while (!atEnd()) { |
199 readNext(); | 199 readNext(); |
200 if (isEndElement()) | 200 if (isEndElement()) |
201 break; | 201 break; |
202 | 202 |
203 if (isStartElement()) { | 203 if (isStartElement()) { |
204 if (name() == QLatin1String("folder")) | 204 if (name() == "folder") |
205 readFolder(parent); | 205 readFolder(parent); |
206 else if (name() == QLatin1String("bookmark")) | 206 else if (name() == ("bookmark") |
207 readBookmarkNode(parent); | 207 readBookmarkNode(parent); |
208 else if (name() == QLatin1String("separator")) | 208 else if (name() == ("separator") |
209 readSeparator(parent); | 209 readSeparator(parent); |
210 else | 210 else |
211 skipUnknownElement(); | 211 skipUnknownElement(); |
212 } | 212 } |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 void readTitle(BookmarkNode parent) | 216 void readTitle(BookmarkNode parent) |
217 { | 217 { |
218 assert(isStartElement() && name() == QLatin1String("title")); | 218 assert(isStartElement() && name() == "title"); |
219 parent.title = readElementText(); | 219 parent.title = readElementText(); |
220 } | 220 } |
221 | 221 |
222 void readDescription(BookmarkNode parent) | 222 void readDescription(BookmarkNode parent) |
223 { | 223 { |
224 assert(isStartElement() && name() == QLatin1String("desc")); | 224 assert(isStartElement() && name() == "desc"); |
225 parent.desc = readElementText(); | 225 parent.desc = readElementText(); |
226 } | 226 } |
227 | 227 |
228 void readSeparator(BookmarkNode parent) | 228 void readSeparator(BookmarkNode parent) |
229 { | 229 { |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 void readFolder(BookmarkNode parent) | 236 void readFolder(BookmarkNode parent) |
237 { | 237 { |
238 assert(isStartElement() && name() == QLatin1String("folder")); | 238 assert(isStartElement() && name() == "folder"); |
239 | 239 |
240 BookmarkNode folder = new BookmarkNode(BookmarkNode.Folder, parent); | 240 BookmarkNode folder = new BookmarkNode(BookmarkNode.Folder, parent); |
241 folder.expanded = (attributes().value(QLatin1String("folded")) == QLatin1String("no")); | 241 folder.expanded = (attributes().value("folded") == "no"); |
242 | 242 |
243 while (!atEnd()) { | 243 while (!atEnd()) { |
244 readNext(); | 244 readNext(); |
245 | 245 |
246 if (isEndElement()) | 246 if (isEndElement()) |
247 break; | 247 break; |
248 | 248 |
249 if (isStartElement()) { | 249 if (isStartElement()) { |
250 if (name() == QLatin1String("title")) | 250 if (name() == "title") |
251 readTitle(folder); | 251 readTitle(folder); |
252 else if (name() == QLatin1String("desc")) | 252 else if (name() == "desc") |
253 readDescription(folder); | 253 readDescription(folder); |
254 else if (name() == QLatin1String("folder")) | 254 else if (name() == "folder") |
255 readFolder(folder); | 255 readFolder(folder); |
256 else if (name() == QLatin1String("bookmark")) | 256 else if (name() == "bookmark") |
257 readBookmarkNode(folder); | 257 readBookmarkNode(folder); |
258 else if (name() == QLatin1String("separator")) | 258 else if (name() == "separator") |
259 readSeparator(folder); | 259 readSeparator(folder); |
260 else | 260 else |
261 skipUnknownElement(); | 261 skipUnknownElement(); |
262 } | 262 } |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 void readBookmarkNode(BookmarkNode parent) | 266 void readBookmarkNode(BookmarkNode parent) |
267 { | 267 { |
268 assert(isStartElement() && name() == QLatin1String("bookmark")); | 268 assert(isStartElement() && name() == "bookmark"); |
269 BookmarkNode bookmark = new BookmarkNode(BookmarkNode.Bookmark, parent); | 269 BookmarkNode bookmark = new BookmarkNode(BookmarkNode.Bookmark, parent); |
270 bookmark.url = attributes().value(QLatin1String("href")).toString(); | 270 bookmark.url = attributes().value("href").toString(); |
271 while (!atEnd()) { | 271 while (!atEnd()) { |
272 readNext(); | 272 readNext(); |
273 if (isEndElement()) | 273 if (isEndElement()) |
274 break; | 274 break; |
275 | 275 |
276 if (isStartElement()) { | 276 if (isStartElement()) { |
277 if (name() == QLatin1String("title")) | 277 if (name() == "title") |
278 readTitle(bookmark); | 278 readTitle(bookmark); |
279 else if (name() == QLatin1String("desc")) | 279 else if (name() == "desc") |
280 readDescription(bookmark); | 280 readDescription(bookmark); |
281 else | 281 else |
282 skipUnknownElement(); | 282 skipUnknownElement(); |
283 } | 283 } |
284 } | 284 } |
309 bool write(QIODevice device, BookmarkNode root) | 309 bool write(QIODevice device, BookmarkNode root) |
310 { | 310 { |
311 setDevice(device); | 311 setDevice(device); |
312 | 312 |
313 writeStartDocument(); | 313 writeStartDocument(); |
314 writeDTD(QLatin1String("<!DOCTYPE xbel>")); | 314 writeDTD("<!DOCTYPE xbel>"); |
315 writeStartElement(QLatin1String("xbel")); | 315 writeStartElement("xbel"); |
316 writeAttribute(QLatin1String("version"), QLatin1String("1.0")); | 316 writeAttribute("version", "1.0"); |
317 if (root.type() == BookmarkNode.Root) { | 317 if (root.type() == BookmarkNode.Root) { |
318 for (int i = 0; i < root.children().length; ++i) | 318 for (int i = 0; i < root.children().length; ++i) |
319 writeItem(root.children()[i]); | 319 writeItem(root.children()[i]); |
320 } else { | 320 } else { |
321 writeItem(root); | 321 writeItem(root); |
329 | 329 |
330 void writeItem(BookmarkNode parent) | 330 void writeItem(BookmarkNode parent) |
331 { | 331 { |
332 switch (parent.type()) { | 332 switch (parent.type()) { |
333 case BookmarkNode.Folder: | 333 case BookmarkNode.Folder: |
334 writeStartElement(QLatin1String("folder")); | 334 writeStartElement("folder"); |
335 writeAttribute(QLatin1String("folded"), parent.expanded ? QLatin1String("no") : QLatin1String("yes")); | 335 writeAttribute("folded", parent.expanded ? "no" : "yes"); |
336 writeTextElement(QLatin1String("title"), parent.title); | 336 writeTextElement("title", parent.title); |
337 for (int i = 0; i < parent.children().count(); ++i) | 337 for (int i = 0; i < parent.children().count(); ++i) |
338 writeItem(parent.children()[i]); | 338 writeItem(parent.children()[i]); |
339 writeEndElement(); | 339 writeEndElement(); |
340 break; | 340 break; |
341 case BookmarkNode.Bookmark: | 341 case BookmarkNode.Bookmark: |
342 writeStartElement(QLatin1String("bookmark")); | 342 writeStartElement("bookmark"); |
343 if (!parent.url.isEmpty()) | 343 if (!parent.url.isEmpty()) |
344 writeAttribute(QLatin1String("href"), parent.url); | 344 writeAttribute("href", parent.url); |
345 writeTextElement(QLatin1String("title"), parent.title); | 345 writeTextElement("title", parent.title); |
346 if (!parent.desc.isEmpty()) | 346 if (!parent.desc.isEmpty()) |
347 writeAttribute(QLatin1String("desc"), parent.desc); | 347 writeAttribute("desc", parent.desc); |
348 writeEndElement(); | 348 writeEndElement(); |
349 break; | 349 break; |
350 case BookmarkNode.Separator: | 350 case BookmarkNode.Separator: |
351 writeEmptyElement(QLatin1String("separator")); | 351 writeEmptyElement("separator"); |
352 break; | 352 break; |
353 default: | 353 default: |
354 break; | 354 break; |
355 } | 355 } |
356 } | 356 } |