Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/xkb_rules.cpp
Show First 20 Lines • Show All 403 Lines • ▼ Show 20 Line(s) | 403 | if( variantInfo->languages.contains(lang) ) | |||
---|---|---|---|---|---|
404 | return true; | 404 | return true; | ||
405 | 405 | | |||
406 | // if variant has no languages try to "inherit" them from layout | 406 | // if variant has no languages try to "inherit" them from layout | ||
407 | if( variantInfo->languages.empty() && languages.contains(lang) ) | 407 | if( variantInfo->languages.empty() && languages.contains(lang) ) | ||
408 | return true; | 408 | return true; | ||
409 | 409 | | |||
410 | return false; | 410 | return false; | ||
411 | } | 411 | } | ||
412 | | ||||
413 | #ifdef NEW_GEOMETRY | | |||
414 | | ||||
415 | Rules::GeometryId Rules::getGeometryId(const QString& model) { | | |||
416 | QString xkbDir = Rules::findXkbDir(); | | |||
417 | QString rulesName = Rules::getRulesName(); | | |||
418 | QString ruleFileName = QStringLiteral("%1/rules/%2").arg(xkbDir, rulesName); | | |||
419 | QFile ruleFile(ruleFileName); | | |||
420 | | ||||
421 | GeometryId defaultGeoId(QStringLiteral("pc"), QStringLiteral("pc104")); | | |||
422 | | ||||
423 | if ( ! ruleFile.open(QIODevice::ReadOnly | QIODevice::Text) ){ | | |||
424 | qCCritical(KCM_KEYBOARD) << "Unable to open file" << ruleFileName; | | |||
425 | return defaultGeoId; | | |||
426 | } | | |||
427 | | ||||
428 | QString modelGeoId = model; | | |||
429 | bool inTable = false; | | |||
430 | QTextStream in(&ruleFile); | | |||
431 | | ||||
432 | while (!in.atEnd()) { | | |||
433 | QString line = in.readLine().trimmed(); | | |||
434 | | ||||
435 | if( line.isEmpty() || QRegExp(QStringLiteral("^\\s*//")).indexIn(line) != -1 ) | | |||
436 | continue; | | |||
437 | | ||||
438 | QRegExp modelGroupRegex(QStringLiteral("!\\s*(\\$[a-zA-Z0-9_]+)\\s*=(.*)")); | | |||
439 | | ||||
440 | if( modelGroupRegex.indexIn(line) != -1 ) { | | |||
441 | QStringList parts = modelGroupRegex.capturedTexts(); | | |||
442 | QString groupName = parts[1]; | | |||
443 | QStringList models = parts[2].split(QRegExp(QStringLiteral("\\s+")), QString::SkipEmptyParts); | | |||
444 | | ||||
445 | // qCDebug(KCM_KEYBOARD) << "modelGroup definition" << groupName << ":" << models; | | |||
446 | if( models.contains(model) ) { | | |||
447 | modelGeoId = groupName; | | |||
448 | } | | |||
449 | continue; | | |||
450 | } | | |||
451 | | ||||
452 | | ||||
453 | if( inTable ) { | | |||
454 | QRegExp modelTableEntry (QStringLiteral("\\s*(\\$?[a-zA-Z0-9_]+|\\*)\\s*=\\s*([a-zA-Z0-9_]+)\\(([a-zA-Z0-9_%]+)\\)")); | | |||
455 | if( modelTableEntry.indexIn(line) == -1 ) { | | |||
456 | if( QRegExp(QStringLiteral("^!\\s*")).indexIn(line) != -1 ) | | |||
457 | break; | | |||
458 | | ||||
459 | qCWarning(KCM_KEYBOARD) << "could not parse geometry line" << line; | | |||
460 | continue; | | |||
461 | } | | |||
462 | | ||||
463 | QStringList parts = modelTableEntry.capturedTexts(); | | |||
464 | QString modelName = parts[1]; | | |||
465 | QString fileName = parts[2]; | | |||
466 | QString geoName = parts[3]; | | |||
467 | if( geoName == QLatin1String("%m") ) { | | |||
468 | geoName = model; | | |||
469 | } | | |||
470 | if( modelName == QLatin1String("*") ) { | | |||
471 | defaultGeoId = GeometryId(fileName, geoName); | | |||
472 | } | | |||
473 | | ||||
474 | // qCDebug(KCM_KEYBOARD) << "geo entry" << modelName << fileName << geoName; | | |||
475 | | ||||
476 | if( modelName == model ) { | | |||
477 | return GeometryId(fileName, geoName); | | |||
478 | } | | |||
479 | | ||||
480 | continue; | | |||
481 | } | | |||
482 | | ||||
483 | QRegExp modelTableHeader (QStringLiteral("!\\s+model\\s*=\\s*geometry")); | | |||
484 | if( modelTableHeader.indexIn(line) != -1 ) { | | |||
485 | inTable = true; | | |||
486 | continue; | | |||
487 | } | | |||
488 | | ||||
489 | } | | |||
490 | | ||||
491 | return defaultGeoId; | | |||
492 | } | | |||
493 | | ||||
494 | #endif | |