MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / widgetName

Method widgetName

src/domain/UBGraphicsWidgetItem.cpp:498–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498QString UBGraphicsWidgetItem::widgetName(const QUrl& widgetPath)
499{
500 QString name;
501 QString version;
502 QFile w3CConfigFile(widgetPath.toLocalFile() + "/config.xml");
503 QFile appleConfigFile(widgetPath.toLocalFile() + "/Info.plist");
504
505 if (w3CConfigFile.exists() && w3CConfigFile.open(QFile::ReadOnly)) {
506 QDomDocument doc;
507 doc.setContent(w3CConfigFile.readAll());
508 QDomElement root = doc.firstChildElement("widget");
509 if (!root.isNull()) {
510 QDomElement nameElement = root.firstChildElement("name");
511 if (!nameElement.isNull())
512 name = nameElement.text();
513 version = root.attribute("version", "");
514 }
515 w3CConfigFile.close();
516 }
517 else if (appleConfigFile.exists() && appleConfigFile.open(QFile::ReadOnly)) {
518 QDomDocument doc;
519 doc.setContent(appleConfigFile.readAll());
520 QDomElement root = doc.firstChildElement("plist");
521 if (!root.isNull()) {
522 QDomElement dictElement = root.firstChildElement("dict");
523 if (!dictElement.isNull()) {
524 QDomNodeList childNodes = dictElement.childNodes();
525
526 /* looking for something like
527 * ..
528 * <key>CFBundleDisplayName</key>
529 * <string>brain scans</string>
530 * ..
531 */
532
533 for(int i = 0; i < childNodes.count() - 1; i++) {
534 if (childNodes.at(i).isElement()) {
535 QDomElement elKey = childNodes.at(i).toElement();
536 if (elKey.text() == "CFBundleDisplayName") {
537 if (childNodes.at(i + 1).isElement()) {
538 QDomElement elValue = childNodes.at(i + 1).toElement();
539 name = elValue.text();
540 }
541 }
542 else if (elKey.text() == "CFBundleShortVersionString") {
543 if (childNodes.at(i + 1).isElement()) {
544 QDomElement elValue = childNodes.at(i + 1).toElement();
545 version = elValue.text();
546 }
547 }
548 }
549 }
550 }
551 }
552 appleConfigFile.close();
553 }
554 QString result;
555

Callers

nothing calls this directly

Calls 2

closeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected