QByteArray AbstractMobileApp::generateMainCpp(QString *errorMessage) const { QFile sourceFile(path(MainCppOrigin)); if (!sourceFile.open(QIODevice::ReadOnly)) { *errorMessage = QCoreApplication::translate("Qt4ProjectManager::AbstractMobileApp", "Could not open main.cpp template '%1'.") .arg(sourceFile.fileName()); return QByteArray(); } QTextStream in(&sourceFile); QByteArray mainCppContent; QTextStream out(&mainCppContent, QIODevice::WriteOnly); QString line; while (!(line = in.readLine()).isNull()) { bool adaptLine = true; if (line.contains(QLatin1String("// ORIENTATION"))) { const char *orientationString; switch (orientation()) { case ScreenOrientationLockLandscape: orientationString = "ScreenOrientationLockLandscape"; break; case ScreenOrientationLockPortrait: orientationString = "ScreenOrientationLockPortrait"; break; case ScreenOrientationAuto: orientationString = "ScreenOrientationAuto"; break; } insertParameter(line, mainWindowClassName() + QLatin1String("::") + QLatin1String(orientationString)); } else if (line.contains(QLatin1String("// DELETE_LINE"))) { continue; // omit this line in the output } else { adaptLine = adaptCurrentMainCppTemplateLine(line); } if (adaptLine) { const int commentIndex = line.indexOf(QLatin1String(" //")); if (commentIndex != -1) line.truncate(commentIndex); out << line << endl; } } return mainCppContent; }
QByteArray AbstractMobileApp::generateMainCpp(QString *errorMessage) const { QByteArray mainCppInput; if (!readTemplate(MainCppOrigin, &mainCppInput, errorMessage)) return QByteArray(); QTextStream in(&mainCppInput); QByteArray mainCppContent; QTextStream out(&mainCppContent, QIODevice::WriteOnly | QIODevice::Text); QString line; while (!(line = in.readLine()).isNull()) { bool adaptLine = true; if (line.contains(QLatin1String("// ORIENTATION"))) { const char *orientationString; switch (orientation()) { case ScreenOrientationLockLandscape: orientationString = "ScreenOrientationLockLandscape"; break; case ScreenOrientationLockPortrait: orientationString = "ScreenOrientationLockPortrait"; break; case ScreenOrientationAuto: orientationString = "ScreenOrientationAuto"; break; case ScreenOrientationImplicit: default: continue; // omit line } insertParameter(line, mainWindowClassName() + QLatin1String("::") + QLatin1String(orientationString)); } else if (line.contains(QLatin1String("// DELETE_LINE"))) { continue; // omit this line in the output } else { adaptLine = adaptCurrentMainCppTemplateLine(line); } if (adaptLine) { const int commentIndex = line.indexOf(QLatin1String(" //")); if (commentIndex != -1) line.truncate(commentIndex); out << line << endl; } } return mainCppContent; }