Changeset View
Changeset View
Standalone View
Standalone View
src/kuitmarkup.cpp
Show All 19 Lines | |||||
20 | #include <QHash> | 20 | #include <QHash> | ||
21 | #include <QSet> | 21 | #include <QSet> | ||
22 | #include <QRegExp> | 22 | #include <QRegExp> | ||
23 | #include <QStack> | 23 | #include <QStack> | ||
24 | #include <QXmlStreamReader> | 24 | #include <QXmlStreamReader> | ||
25 | #include <QStringList> | 25 | #include <QStringList> | ||
26 | #include <QPair> | 26 | #include <QPair> | ||
27 | #include <QDir> | 27 | #include <QDir> | ||
28 | #include <QDebug> | | |||
29 | 28 | | |||
30 | #include <kuitmarkup.h> | 29 | #include <kuitmarkup.h> | ||
31 | #include <kuitmarkup_p.h> | 30 | #include <kuitmarkup_p.h> | ||
32 | #include <klocalizedstring.h> | 31 | #include <klocalizedstring.h> | ||
33 | 32 | | |||
33 | #include "ki18n_logging_kuit.h" | ||||
34 | | ||||
34 | #define QL1S(x) QLatin1String(x) | 35 | #define QL1S(x) QLatin1String(x) | ||
35 | #define QSL(x) QStringLiteral(x) | 36 | #define QSL(x) QStringLiteral(x) | ||
36 | #define QL1C(x) QLatin1Char(x) | 37 | #define QL1C(x) QLatin1Char(x) | ||
37 | 38 | | |||
38 | QString Kuit::escape(const QString &text) | 39 | QString Kuit::escape(const QString &text) | ||
39 | { | 40 | { | ||
40 | int tlen = text.length(); | 41 | int tlen = text.length(); | ||
41 | QString ntext; | 42 | QString ntext; | ||
▲ Show 20 Lines • Show All 449 Lines • ▼ Show 20 Line(s) | 489 | if (!aggText.isEmpty()) { | |||
491 | for (const QString &attribName : attributeOrder) { | 492 | for (const QString &attribName : attributeOrder) { | ||
492 | aggText = aggText.subs(attributes.value(attribName)); | 493 | aggText = aggText.subs(attributes.value(attribName)); | ||
493 | } | 494 | } | ||
494 | formattedText = aggText.ignoreMarkup().toString(languages); | 495 | formattedText = aggText.ignoreMarkup().toString(languages); | ||
495 | } else { | 496 | } else { | ||
496 | formattedText = modText; | 497 | formattedText = modText; | ||
497 | } | 498 | } | ||
498 | } else if (patterns.contains(attribKey)) { | 499 | } else if (patterns.contains(attribKey)) { | ||
499 | qWarning() << QStringLiteral( | 500 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
500 | "Undefined visual format for tag <%1> and attribute combination %2: %3.") | 501 | "Undefined visual format for tag <%1> and attribute combination %2: %3.") | ||
501 | .arg(name, attribKey, s->namesByFormat.value(format)); | 502 | .arg(name, attribKey, s->namesByFormat.value(format)); | ||
502 | } else { | 503 | } else { | ||
503 | qWarning() << QStringLiteral( | 504 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
504 | "Undefined attribute combination for tag <%1>: %2.") | 505 | "Undefined attribute combination for tag <%1>: %2.") | ||
505 | .arg(name, attribKey); | 506 | .arg(name, attribKey); | ||
506 | } | 507 | } | ||
507 | return formattedText; | 508 | return formattedText; | ||
508 | } | 509 | } | ||
509 | 510 | | |||
510 | KuitSetup &Kuit::setupForDomain(const QByteArray& domain) | 511 | KuitSetup &Kuit::setupForDomain(const QByteArray& domain) | ||
511 | { | 512 | { | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 588 | { | |||
589 | 590 | | |||
590 | QString roleName, cueName, formatName; | 591 | QString roleName, cueName, formatName; | ||
591 | parseUiMarker(marker, roleName, cueName, formatName); | 592 | parseUiMarker(marker, roleName, cueName, formatName); | ||
592 | 593 | | |||
593 | Kuit::Role role; | 594 | Kuit::Role role; | ||
594 | if (s->rolesByName.contains(roleName)) { | 595 | if (s->rolesByName.contains(roleName)) { | ||
595 | role = s->rolesByName.value(roleName); | 596 | role = s->rolesByName.value(roleName); | ||
596 | } else if (!roleName.isEmpty()) { | 597 | } else if (!roleName.isEmpty()) { | ||
597 | qWarning() << QStringLiteral( | 598 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
598 | "Unknown role '@%1' in UI marker {%2}, visual format not set.") | 599 | "Unknown role '@%1' in UI marker {%2}, visual format not set.") | ||
599 | .arg(roleName, marker); | 600 | .arg(roleName, marker); | ||
600 | return; | 601 | return; | ||
601 | } else { | 602 | } else { | ||
602 | qWarning() << QStringLiteral( | 603 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
603 | "Empty role in UI marker {%1}, visual format not set.") | 604 | "Empty role in UI marker {%1}, visual format not set.") | ||
604 | .arg(marker); | 605 | .arg(marker); | ||
605 | return; | 606 | return; | ||
606 | } | 607 | } | ||
607 | 608 | | |||
608 | Kuit::Cue cue; | 609 | Kuit::Cue cue; | ||
609 | if (s->cuesByName.contains(cueName)) { | 610 | if (s->cuesByName.contains(cueName)) { | ||
610 | cue = s->cuesByName.value(cueName); | 611 | cue = s->cuesByName.value(cueName); | ||
611 | if (!s->knownRoleCues.value(role).contains(cue)) { | 612 | if (!s->knownRoleCues.value(role).contains(cue)) { | ||
612 | qWarning() << QStringLiteral( | 613 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
613 | "Subcue ':%1' does not belong to role '@%2' in UI marker {%3}, visual format not set.") | 614 | "Subcue ':%1' does not belong to role '@%2' in UI marker {%3}, visual format not set.") | ||
614 | .arg(cueName, roleName, marker); | 615 | .arg(cueName, roleName, marker); | ||
615 | return; | 616 | return; | ||
616 | } | 617 | } | ||
617 | } else if (!cueName.isEmpty()) { | 618 | } else if (!cueName.isEmpty()) { | ||
618 | qWarning() << QStringLiteral( | 619 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
619 | "Unknown subcue ':%1' in UI marker {%2}, visual format not set.") | 620 | "Unknown subcue ':%1' in UI marker {%2}, visual format not set.") | ||
620 | .arg(cueName, marker); | 621 | .arg(cueName, marker); | ||
621 | return; | 622 | return; | ||
622 | } else { | 623 | } else { | ||
623 | cue = Kuit::UndefinedCue; | 624 | cue = Kuit::UndefinedCue; | ||
624 | } | 625 | } | ||
625 | 626 | | |||
626 | formatsByRoleCue[role][cue] = format; | 627 | formatsByRoleCue[role][cue] = format; | ||
▲ Show 20 Lines • Show All 622 Lines • ▼ Show 20 Line(s) | 1248 | { | |||
1249 | 1250 | | |||
1250 | QString roleName, cueName, formatName; | 1251 | QString roleName, cueName, formatName; | ||
1251 | parseUiMarker(context, roleName, cueName, formatName); | 1252 | parseUiMarker(context, roleName, cueName, formatName); | ||
1252 | 1253 | | |||
1253 | // Set role from name. | 1254 | // Set role from name. | ||
1254 | Kuit::Role role = s->rolesByName.value(roleName, Kuit::UndefinedRole); | 1255 | Kuit::Role role = s->rolesByName.value(roleName, Kuit::UndefinedRole); | ||
1255 | if (role == Kuit::UndefinedRole) { // unknown role | 1256 | if (role == Kuit::UndefinedRole) { // unknown role | ||
1256 | if (!roleName.isEmpty()) { | 1257 | if (!roleName.isEmpty()) { | ||
1257 | qWarning() << QStringLiteral( | 1258 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1258 | "Unknown role '@%1' in UI marker in context {%2}.") | 1259 | "Unknown role '@%1' in UI marker in context {%2}.") | ||
1259 | .arg(roleName, shorten(context)); | 1260 | .arg(roleName, shorten(context)); | ||
1260 | } | 1261 | } | ||
1261 | } | 1262 | } | ||
1262 | 1263 | | |||
1263 | // Set subcue from name. | 1264 | // Set subcue from name. | ||
1264 | Kuit::Cue cue; | 1265 | Kuit::Cue cue; | ||
1265 | if (role != Kuit::UndefinedRole) { | 1266 | if (role != Kuit::UndefinedRole) { | ||
1266 | cue = s->cuesByName.value(cueName, Kuit::UndefinedCue); | 1267 | cue = s->cuesByName.value(cueName, Kuit::UndefinedCue); | ||
1267 | if (cue != Kuit::UndefinedCue) { // known subcue | 1268 | if (cue != Kuit::UndefinedCue) { // known subcue | ||
1268 | if (!s->knownRoleCues.value(role).contains(cue)) { | 1269 | if (!s->knownRoleCues.value(role).contains(cue)) { | ||
1269 | cue = Kuit::UndefinedCue; | 1270 | cue = Kuit::UndefinedCue; | ||
1270 | qWarning() << QStringLiteral( | 1271 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1271 | "Subcue ':%1' does not belong to role '@%2' in UI marker in context {%3}.") | 1272 | "Subcue ':%1' does not belong to role '@%2' in UI marker in context {%3}.") | ||
1272 | .arg(cueName, roleName, shorten(context)); | 1273 | .arg(cueName, roleName, shorten(context)); | ||
1273 | } | 1274 | } | ||
1274 | } else { // unknown or not given subcue | 1275 | } else { // unknown or not given subcue | ||
1275 | if (!cueName.isEmpty()) { | 1276 | if (!cueName.isEmpty()) { | ||
1276 | qWarning() << QStringLiteral( | 1277 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1277 | "Unknown subcue ':%1' in UI marker in context {%2}.") | 1278 | "Unknown subcue ':%1' in UI marker in context {%2}.") | ||
1278 | .arg(cueName, shorten(context)); | 1279 | .arg(cueName, shorten(context)); | ||
1279 | } | 1280 | } | ||
1280 | } | 1281 | } | ||
1281 | } else { | 1282 | } else { | ||
1282 | // Bad role, silently ignore the cue. | 1283 | // Bad role, silently ignore the cue. | ||
1283 | cue = Kuit::UndefinedCue; | 1284 | cue = Kuit::UndefinedCue; | ||
1284 | } | 1285 | } | ||
1285 | 1286 | | |||
1286 | // Set format from name, or by derivation from contex/subcue. | 1287 | // Set format from name, or by derivation from contex/subcue. | ||
1287 | Kuit::VisualFormat format = s->formatsByName.value(formatName, Kuit::UndefinedFormat); | 1288 | Kuit::VisualFormat format = s->formatsByName.value(formatName, Kuit::UndefinedFormat); | ||
1288 | if (format == Kuit::UndefinedFormat) { // unknown or not given format | 1289 | if (format == Kuit::UndefinedFormat) { // unknown or not given format | ||
1289 | // Check first if there is a format defined for role/subcue | 1290 | // Check first if there is a format defined for role/subcue | ||
1290 | // combination, then for role only, otherwise default to undefined. | 1291 | // combination, then for role only, otherwise default to undefined. | ||
1291 | if (setup.d->formatsByRoleCue.contains(role)) { | 1292 | if (setup.d->formatsByRoleCue.contains(role)) { | ||
1292 | if (setup.d->formatsByRoleCue.value(role).contains(cue)) { | 1293 | if (setup.d->formatsByRoleCue.value(role).contains(cue)) { | ||
1293 | format = setup.d->formatsByRoleCue.value(role).value(cue); | 1294 | format = setup.d->formatsByRoleCue.value(role).value(cue); | ||
1294 | } else { | 1295 | } else { | ||
1295 | format = setup.d->formatsByRoleCue.value(role).value(Kuit::UndefinedCue); | 1296 | format = setup.d->formatsByRoleCue.value(role).value(Kuit::UndefinedCue); | ||
1296 | } | 1297 | } | ||
1297 | } | 1298 | } | ||
1298 | if (!formatName.isEmpty()) { | 1299 | if (!formatName.isEmpty()) { | ||
1299 | qWarning() << QStringLiteral( | 1300 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1300 | "Unknown format '/%1' in UI marker for message {%2}.") | 1301 | "Unknown format '/%1' in UI marker for message {%2}.") | ||
1301 | .arg(formatName, shorten(context)); | 1302 | .arg(formatName, shorten(context)); | ||
1302 | } | 1303 | } | ||
1303 | } | 1304 | } | ||
1304 | if (format == Kuit::UndefinedFormat) { | 1305 | if (format == Kuit::UndefinedFormat) { | ||
1305 | format = Kuit::PlainText; | 1306 | format = Kuit::PlainText; | ||
1306 | } | 1307 | } | ||
1307 | 1308 | | |||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 1415 | } else { | |||
1415 | nctext += c; | 1416 | nctext += c; | ||
1416 | } | 1417 | } | ||
1417 | } | 1418 | } | ||
1418 | openEls.top().formattedText += nctext; | 1419 | openEls.top().formattedText += nctext; | ||
1419 | } | 1420 | } | ||
1420 | } | 1421 | } | ||
1421 | 1422 | | |||
1422 | if (xml.hasError()) { | 1423 | if (xml.hasError()) { | ||
1423 | qWarning() << QStringLiteral( | 1424 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1424 | "Markup error in message {%1}: %2. Last tag parsed: %3. Complete message follows:\n%4") | 1425 | "Markup error in message {%1}: %2. Last tag parsed: %3. Complete message follows:\n%4") | ||
1425 | .arg(shorten(text), xml.errorString(), lastElementName.toString(), | 1426 | .arg(shorten(text), xml.errorString(), lastElementName.toString(), | ||
1426 | text); | 1427 | text); | ||
1427 | return QString(); | 1428 | return QString(); | ||
1428 | } | 1429 | } | ||
1429 | 1430 | | |||
1430 | // Cannot reach here. | 1431 | // Cannot reach here. | ||
1431 | return text; | 1432 | return text; | ||
Show All 27 Lines | 1456 | if (setup.d->knownTags.contains(oel.name)) { // known KUIT element | |||
1459 | // If this element can be contained within enclosing element, | 1460 | // If this element can be contained within enclosing element, | ||
1460 | // mark it proper, otherwise mark it for removal. | 1461 | // mark it proper, otherwise mark it for removal. | ||
1461 | if (tag.name.isEmpty() | 1462 | if (tag.name.isEmpty() | ||
1462 | || tag.type == Kuit::PhraseTag | 1463 | || tag.type == Kuit::PhraseTag | ||
1463 | || etag.type == Kuit::StructTag) { | 1464 | || etag.type == Kuit::StructTag) { | ||
1464 | oel.handling = OpenEl::Proper; | 1465 | oel.handling = OpenEl::Proper; | ||
1465 | } else { | 1466 | } else { | ||
1466 | oel.handling = OpenEl::Dropout; | 1467 | oel.handling = OpenEl::Dropout; | ||
1467 | qWarning() << QStringLiteral( | 1468 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1468 | "Structuring tag ('%1') cannot be subtag of phrase tag ('%2') in message {%3}.") | 1469 | "Structuring tag ('%1') cannot be subtag of phrase tag ('%2') in message {%3}.") | ||
1469 | .arg(tag.name, etag.name, shorten(text)); | 1470 | .arg(tag.name, etag.name, shorten(text)); | ||
1470 | } | 1471 | } | ||
1471 | 1472 | | |||
1472 | // Resolve attributes and compute attribute set key. | 1473 | // Resolve attributes and compute attribute set key. | ||
1473 | QSet<QString> attset; | 1474 | QSet<QString> attset; | ||
1474 | for (int i = 0; i < attribNames.size(); ++i) { | 1475 | for (int i = 0; i < attribNames.size(); ++i) { | ||
1475 | QString att = attribNames[i]; | 1476 | QString att = attribNames[i]; | ||
1476 | if (tag.knownAttribs.contains(att)) { | 1477 | if (tag.knownAttribs.contains(att)) { | ||
1477 | attset << att; | 1478 | attset << att; | ||
1478 | oel.attributes[att] = attribValues[i]; | 1479 | oel.attributes[att] = attribValues[i]; | ||
1479 | } else { | 1480 | } else { | ||
1480 | qWarning() << QStringLiteral( | 1481 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1481 | "Attribute '%1' not defined for tag '%2' in message {%3}.") | 1482 | "Attribute '%1' not defined for tag '%2' in message {%3}.") | ||
1482 | .arg(att, tag.name, shorten(text)); | 1483 | .arg(att, tag.name, shorten(text)); | ||
1483 | } | 1484 | } | ||
1484 | } | 1485 | } | ||
1485 | 1486 | | |||
1486 | // Continue tag path. | 1487 | // Continue tag path. | ||
1487 | oel.tagPath = enclosingOel.tagPath; | 1488 | oel.tagPath = enclosingOel.tagPath; | ||
1488 | oel.tagPath.prepend(enclosingOel.name); | 1489 | oel.tagPath.prepend(enclosingOel.name); | ||
1489 | 1490 | | |||
1490 | } else { // unknown element, leave it in verbatim | 1491 | } else { // unknown element, leave it in verbatim | ||
1491 | oel.handling = OpenEl::Ignored; | 1492 | oel.handling = OpenEl::Ignored; | ||
1492 | qWarning() << QStringLiteral( | 1493 | qCWarning(KI18N_KUIT) << QStringLiteral( | ||
1493 | "Tag '%1' is not defined in message {%2}.") | 1494 | "Tag '%1' is not defined in message {%2}.") | ||
1494 | .arg(oel.name, shorten(text)); | 1495 | .arg(oel.name, shorten(text)); | ||
1495 | } | 1496 | } | ||
1496 | 1497 | | |||
1497 | return oel; | 1498 | return oel; | ||
1498 | } | 1499 | } | ||
1499 | 1500 | | |||
1500 | QString KuitFormatterPrivate::formatSubText(const QString &ptext, | 1501 | QString KuitFormatterPrivate::formatSubText(const QString &ptext, | ||
▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines |