19 #include <QPushButton> 23 #include <QXmlInputSource> 25 #include <QGridLayout> 35 m_caption(tr(
"Tip of the Day"))
40 settings.beginGroup(
"TipOfTheDay");
42 if (!settings.value(
"showonstartup",
true).toBool())
return;
48 QGridLayout *grid =
new QGridLayout;
51 QGroupBox *groupBox =
new QGroupBox;
53 grid->addWidget(groupBox, 0, 0);
55 QGridLayout *subgrid =
new QGridLayout;
56 groupBox->setLayout(subgrid);
59 subgrid->addWidget(
m_label, 0, 0);
62 QHBoxLayout *hbox =
new QHBoxLayout;
63 grid->addLayout(hbox, 1, 0);
65 QCheckBox *show =
new QCheckBox(tr(
"Show tip on startup"));
66 hbox->addWidget(show);
71 QPushButton *prev =
new QPushButton(tr(
"<< Previous"));
72 hbox->addWidget(prev);
73 connect(prev, SIGNAL(clicked()),
this, SLOT(
previous()));
75 QPushButton *
next =
new QPushButton(tr(
"Next >>"));
76 hbox->addWidget(next);
77 connect(next, SIGNAL(clicked()),
this, SLOT(
next()));
79 QPushButton *close =
new QPushButton(tr(
"Close"));
80 hbox->addWidget(close);
81 connect(close, SIGNAL(clicked()),
this, SLOT(accept()));
83 close->setDefault(
true);
117 SVDEBUG <<
"TipDialog::readTips" << endl;
119 QString language = QLocale::system().name();
120 QString filename = QString(
":i18n/tips_%1.xml").arg(language);
122 if (!QFileInfo(filename).exists()) {
124 QString base = language.section(
'_', 0, 0);
125 filename = QString(
":i18n/tips_%1.xml").arg(base);
127 if (!QFileInfo(filename).exists()) {
129 filename = QString(
":i18n/tips.xml");
131 if (!QFileInfo(filename).exists())
return;
135 QFile file(filename);
137 SVDEBUG <<
"TipDialog::readTips from " << filename << endl;
139 QXmlInputSource source(&file);
142 parser.
parse(source);
156 if (++tn >=
int(
m_tips.size())) tn = 0;
159 settings.beginGroup(
"TipOfTheDay");
160 settings.setValue(
"nexttip", tn);
178 QXmlSimpleReader reader;
179 reader.setContentHandler(
this);
180 reader.setErrorHandler(
this);
181 reader.parse(source);
186 const QString &qName,
187 const QXmlAttributes &attributes)
189 QString name = qName.toLower();
191 SVDEBUG <<
"TipFileParser::startElement(" << name <<
")" << endl;
193 if (name ==
"tips") {
194 QString caption = attributes.value(
"caption");
195 SVDEBUG <<
"TipFileParser::caption = " << caption << endl;
197 }
else if (name ==
"tip") {
199 cerr <<
"WARNING: TipFileParser: nested <tip> elements" << endl;
202 }
else if (name ==
"text") {
205 cerr <<
"TipFileParser: adding new tip" << endl;
208 cerr <<
"WARNING: TipFileParser: <text> outside <tip> element" << endl;
210 }
else if (name ==
"html") {
213 cerr <<
"TipFileParser: adding new tip" << endl;
216 cerr <<
"WARNING: TipFileParser: <html> outside <tip> element" << endl;
220 for (
int i = 0; i < attributes.count(); ++i) {
222 " " + attributes.qName(i) +
"=\"" + attributes.value(i) +
"\"";
227 SVDEBUG <<
"TipFileParser::startElement done" << endl;
233 const QString &qName)
235 QString name = qName.toLower();
237 if (name ==
"text") {
239 cerr <<
"WARNING: TipFileParser: </text> without <text>" << endl;
242 }
else if (name ==
"html") {
244 cerr <<
"WARNING: TipFileParser: </html> without <html>" << endl;
247 }
else if (name ==
"tip") {
249 cerr <<
"WARNING: TipFileParser: <text> without </text>" << endl;
251 cerr <<
"WARNING: TipFileParser: <html> without </html>" << endl;
253 cerr <<
"WARNING: TipFileParser: </tip> without <tip>" << endl;
266 SVDEBUG <<
"TipFileParser::characters(" << text <<
")" << endl;
278 QString errorString =
279 QString(
"ERROR: TipFileParser: %1 at line %2, column %3")
280 .arg(exception.message())
281 .arg(exception.lineNumber())
282 .arg(exception.columnNumber());
283 cerr << errorString << endl;
284 return QXmlDefaultHandler::error(exception);
290 QString errorString =
291 QString(
"FATAL ERROR: TipFileParser: %1 at line %2, column %3")
292 .arg(exception.message())
293 .arg(exception.lineNumber())
294 .arg(exception.columnNumber());
295 cerr << errorString << endl;
296 return QXmlDefaultHandler::fatalError(exception);
bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName) override
TipFileParser(TipDialog *dialog)
bool error(const QXmlParseException &exception) override
std::vector< QString > m_tips
void parse(QXmlInputSource &source)
TipDialog(QWidget *parent=0)
bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts) override
bool fatalError(const QXmlParseException &exception) override
bool characters(const QString &) override