comparison widgets/TipDialog.cpp @ 586:1ae54a29e59e

Merge from debug-output branch
author Chris Cannam
date Tue, 14 Jun 2011 14:48:29 +0100
parents f4960f8ce798
children 4806715f7a19
comparison
equal deleted inserted replaced
583:4c484636d5ec 586:1ae54a29e59e
112 } 112 }
113 113
114 void 114 void
115 TipDialog::readTips() 115 TipDialog::readTips()
116 { 116 {
117 std::cerr << "TipDialog::readTips" << std::endl; 117 DEBUG << "TipDialog::readTips" << endl;
118 118
119 QString language = QLocale::system().name(); 119 QString language = QLocale::system().name();
120 QString filename = QString(":i18n/tips_%1.xml").arg(language); 120 QString filename = QString(":i18n/tips_%1.xml").arg(language);
121 121
122 if (!QFileInfo(filename).exists()) { 122 if (!QFileInfo(filename).exists()) {
132 } 132 }
133 } 133 }
134 134
135 QFile file(filename); 135 QFile file(filename);
136 136
137 std::cerr << "TipDialog::readTips from " << filename.toStdString() << std::endl; 137 DEBUG << "TipDialog::readTips from " << filename << endl;
138 138
139 QXmlInputSource source(&file); 139 QXmlInputSource source(&file);
140 140
141 TipFileParser parser(this); 141 TipFileParser parser(this);
142 parser.parse(source); 142 parser.parse(source);
144 144
145 void 145 void
146 TipDialog::showTip() 146 TipDialog::showTip()
147 { 147 {
148 if (m_tipNumber < int(m_tips.size())) { 148 if (m_tipNumber < int(m_tips.size())) {
149 std::cerr << "Tip " << m_tipNumber << " is: " << m_tips[m_tipNumber].toStdString() << std::endl; 149 std::cerr << "Tip " << m_tipNumber << " is: " << m_tips[m_tipNumber] << std::endl;
150 m_label->setText(m_tips[m_tipNumber]); 150 m_label->setText(m_tips[m_tipNumber]);
151 } else { 151 } else {
152 accept(); 152 accept();
153 } 153 }
154 154
186 const QString &qName, 186 const QString &qName,
187 const QXmlAttributes &attributes) 187 const QXmlAttributes &attributes)
188 { 188 {
189 QString name = qName.toLower(); 189 QString name = qName.toLower();
190 190
191 std::cerr << "TipFileParser::startElement(" << name.toStdString() << ")" << std::endl; 191 DEBUG << "TipFileParser::startElement(" << name << ")" << endl;
192 192
193 if (name == "tips") { 193 if (name == "tips") {
194 QString caption = attributes.value("caption"); 194 QString caption = attributes.value("caption");
195 std::cerr << "TipFileParser::caption = " << caption.toStdString() << std::endl; 195 DEBUG << "TipFileParser::caption = " << caption << endl;
196 if (caption != "") m_dialog->m_caption = caption; 196 if (caption != "") m_dialog->m_caption = caption;
197 } else if (name == "tip") { 197 } else if (name == "tip") {
198 if (m_inTip) { 198 if (m_inTip) {
199 std::cerr << "WARNING: TipFileParser: nested <tip> elements" << std::endl; 199 std::cerr << "WARNING: TipFileParser: nested <tip> elements" << std::endl;
200 } 200 }
222 " " + attributes.qName(i) + "=\"" + attributes.value(i) + "\""; 222 " " + attributes.qName(i) + "=\"" + attributes.value(i) + "\"";
223 } 223 }
224 m_dialog->m_tips[m_dialog->m_tips.size()-1] += ">"; 224 m_dialog->m_tips[m_dialog->m_tips.size()-1] += ">";
225 } 225 }
226 226
227 std::cerr << "TipFileParser::startElement done" << std::endl; 227 DEBUG << "TipFileParser::startElement done" << endl;
228 return true; 228 return true;
229 } 229 }
230 230
231 bool 231 bool
232 TipDialog::TipFileParser::endElement(const QString &, const QString &, 232 TipDialog::TipFileParser::endElement(const QString &, const QString &,
261 } 261 }
262 262
263 bool 263 bool
264 TipDialog::TipFileParser::characters(const QString &text) 264 TipDialog::TipFileParser::characters(const QString &text)
265 { 265 {
266 std::cerr << "TipFileParser::characters(" << text.toStdString() << ")" << std::endl; 266 DEBUG << "TipFileParser::characters(" << text << ")" << endl;
267 267
268 if (m_inText || m_inHtml) { 268 if (m_inText || m_inHtml) {
269 m_dialog->m_tips[m_dialog->m_tips.size()-1] += text; 269 m_dialog->m_tips[m_dialog->m_tips.size()-1] += text;
270 } 270 }
271 271
278 QString errorString = 278 QString errorString =
279 QString("ERROR: TipFileParser: %1 at line %2, column %3") 279 QString("ERROR: TipFileParser: %1 at line %2, column %3")
280 .arg(exception.message()) 280 .arg(exception.message())
281 .arg(exception.lineNumber()) 281 .arg(exception.lineNumber())
282 .arg(exception.columnNumber()); 282 .arg(exception.columnNumber());
283 std::cerr << errorString.toStdString() << std::endl; 283 std::cerr << errorString << std::endl;
284 return QXmlDefaultHandler::error(exception); 284 return QXmlDefaultHandler::error(exception);
285 } 285 }
286 286
287 bool 287 bool
288 TipDialog::TipFileParser::fatalError(const QXmlParseException &exception) 288 TipDialog::TipFileParser::fatalError(const QXmlParseException &exception)
290 QString errorString = 290 QString errorString =
291 QString("FATAL ERROR: TipFileParser: %1 at line %2, column %3") 291 QString("FATAL ERROR: TipFileParser: %1 at line %2, column %3")
292 .arg(exception.message()) 292 .arg(exception.message())
293 .arg(exception.lineNumber()) 293 .arg(exception.lineNumber())
294 .arg(exception.columnNumber()); 294 .arg(exception.columnNumber());
295 std::cerr << errorString.toStdString() << std::endl; 295 std::cerr << errorString << std::endl;
296 return QXmlDefaultHandler::fatalError(exception); 296 return QXmlDefaultHandler::fatalError(exception);
297 } 297 }