diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp index 2b2e9384e2815b970e9a2dd7c04fbf34b08c28b7..e1e9f6588558d6560805bd5be0f4350d78b2434d 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopublisherfremantlefree.cpp @@ -46,6 +46,7 @@ #include <QtCore/QDir> #include <QtCore/QFileInfo> #include <QtCore/QStringList> +#include <QtGui/QIcon> #define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state) @@ -559,16 +560,15 @@ QStringList MaemoPublisherFremantleFree::findProblems() const QStringList problems; const MaemoTemplatesManager * const templatesManager = MaemoTemplatesManager::instance(); - const QString &description = templatesManager - ->controlFileFieldValue(m_project, QLatin1String("Description")); + const QString &description = templatesManager->shortDescription(m_project); if (description.trimmed().isEmpty()) { problems << tr("The package description is empty."); } else if (description.contains(QLatin1String("insert up to"))) { problems << tr("The package description is '%1', which is probably " "not what you want.").arg(description); } - if (templatesManager->controlFileFieldValue(m_project, - QLatin1String("XB-Maemo-Icon-26")).trimmed().isEmpty()) + QString dummy; + if (templatesManager->packageManagerIcon(m_project, &dummy).isNull()) problems << tr("You have not set an icon for the package manager."); return problems; } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.cpp index b9abc708caef8d67f35ae4cc36e3c66867e568e8..bc144074bf9c745dfb51a0f7653fd2a5abb902db 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.cpp @@ -61,7 +61,7 @@ namespace Qt4ProjectManager { namespace Internal { namespace { -const QByteArray IconFieldName("XB-Maemo-Icon-26:"); +const QByteArray IconFieldName("XB-Maemo-Icon-26"); const QByteArray NameFieldName("XB-Maemo-Display-Name"); const QByteArray ShortDescriptionFieldName("Description"); const QLatin1String PackagingDirName("qtc_packaging"); @@ -484,36 +484,10 @@ bool MaemoTemplatesManager::setVersion(const Project *project, QIcon MaemoTemplatesManager::packageManagerIcon(const Project *project, QString *error) const { - QSharedPointer<QFile> controlFile - = openFile(controlFilePath(project), QIODevice::ReadOnly, error); - if (!controlFile) - return QIcon(); - - bool iconFieldFound = false; - QByteArray currentLine; - while (!iconFieldFound && !controlFile->atEnd()) { - currentLine = controlFile->readLine(); - iconFieldFound = currentLine.startsWith(IconFieldName); - } - if (!iconFieldFound) + const QByteArray &base64Icon + = controlFileFieldValue(project, IconFieldName, true); + if (base64Icon.isEmpty()) return QIcon(); - - int pos = IconFieldName.length(); - currentLine = currentLine.trimmed(); - QByteArray base64Icon; - do { - while (pos < currentLine.length()) - base64Icon += currentLine.at(pos++); - do - currentLine = controlFile->readLine(); - while (currentLine.startsWith('#')); - if (currentLine.isEmpty() || !isspace(currentLine.at(0))) - break; - currentLine = currentLine.trimmed(); - if (currentLine.isEmpty()) - break; - pos = 0; - } while (true); QPixmap pixmap; if (!pixmap.loadFromData(QByteArray::fromBase64(base64Icon))) { *error = tr("Invalid icon data in Debian control file."); @@ -546,16 +520,17 @@ bool MaemoTemplatesManager::setPackageManagerIcon(const Project *project, buffer.close(); iconAsBase64 = iconAsBase64.toBase64(); QByteArray contents = controlFile->readAll(); - const int iconFieldPos = contents.startsWith(IconFieldName) - ? 0 : contents.indexOf('\n' + IconFieldName); + const QByteArray iconFieldNameWithColon = IconFieldName + ':'; + const int iconFieldPos = contents.startsWith(iconFieldNameWithColon) + ? 0 : contents.indexOf('\n' + iconFieldNameWithColon); if (iconFieldPos == -1) { if (!contents.endsWith('\n')) contents += '\n'; - contents.append(IconFieldName).append(' ').append(iconAsBase64) + contents.append(iconFieldNameWithColon).append(' ').append(iconAsBase64) .append('\n'); } else { - const int oldIconStartPos - = (iconFieldPos != 0) + iconFieldPos + IconFieldName.length(); + const int oldIconStartPos = (iconFieldPos != 0) + iconFieldPos + + iconFieldNameWithColon.length(); int nextEolPos = contents.indexOf('\n', oldIconStartPos); while (nextEolPos != -1 && nextEolPos != contents.length() - 1 && contents.at(nextEolPos + 1) != '\n' @@ -580,7 +555,7 @@ bool MaemoTemplatesManager::setPackageManagerIcon(const Project *project, QString MaemoTemplatesManager::name(const Project *project) const { - return controlFileFieldValue(project, NameFieldName); + return QString::fromUtf8(controlFileFieldValue(project, NameFieldName, false)); } bool MaemoTemplatesManager::setName(const Project *project, const QString &name) @@ -590,7 +565,8 @@ bool MaemoTemplatesManager::setName(const Project *project, const QString &name) QString MaemoTemplatesManager::shortDescription(const Project *project) const { - return controlFileFieldValue(project, ShortDescriptionFieldName); + return QString::fromUtf8(controlFileFieldValue(project, + ShortDescriptionFieldName, false)); } bool MaemoTemplatesManager::setShortDescription(const Project *project, @@ -636,22 +612,42 @@ QString MaemoTemplatesManager::controlFilePath(const Project *project) const return debianDirPath(project) + QLatin1String("/control"); } -QString MaemoTemplatesManager::controlFileFieldValue(const Project *project, - const QString &key) const +QByteArray MaemoTemplatesManager::controlFileFieldValue(const Project *project, + const QString &key, bool multiLine) const { + QByteArray value; QFile controlFile(controlFilePath(project)); if (!controlFile.open(QIODevice::ReadOnly)) - return QString(); + return value; const QByteArray &contents = controlFile.readAll(); const int keyPos = contents.indexOf(key.toUtf8() + ':'); if (keyPos == -1) - return QString(); - const int valueStartPos = keyPos + key.length() + 1; + return value; + int valueStartPos = keyPos + key.length() + 1; int valueEndPos = contents.indexOf('\n', keyPos); if (valueEndPos == -1) valueEndPos = contents.count(); - return QString::fromUtf8(contents.mid(valueStartPos, - valueEndPos - valueStartPos)).trimmed(); + value = contents.mid(valueStartPos, valueEndPos - valueStartPos).trimmed(); + if (multiLine) { + Q_FOREVER { + valueStartPos = valueEndPos + 1; + if (valueStartPos >= contents.count()) + break; + const char firstChar = contents.at(valueStartPos); + if (firstChar == '#' || isspace(firstChar)) { + valueEndPos = contents.indexOf('\n', valueStartPos); + if (valueEndPos == -1) + valueEndPos = contents.count(); + if (firstChar != '#') { + value += contents.mid(valueStartPos, + valueEndPos - valueStartPos).trimmed(); + } + } else { + break; + } + } + } + return value; } void MaemoTemplatesManager::raiseError(const QString &reason) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.h b/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.h index 6fe3ae0cbf0970d0b68786ec5dcfc4f9aba69163..70880d1df88e886f1788bd8c0bcd8cc40b3b71ca 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemotemplatesmanager.h @@ -79,9 +79,6 @@ public: bool setShortDescription(const ProjectExplorer::Project *project, const QString &description); - QString controlFileFieldValue(const ProjectExplorer::Project *project, - const QString &key) const; - signals: void debianDirContentsChanged(const ProjectExplorer::Project *project); void changeLogChanged(const ProjectExplorer::Project *project); @@ -115,6 +112,8 @@ private: QIODevice::OpenMode mode, QString *error) const; bool setFieldValue(const ProjectExplorer::Project *project, const QByteArray &fieldName, const QByteArray &fieldValue); + QByteArray controlFileFieldValue(const ProjectExplorer::Project *project, + const QString &key, bool multiLine) const; static MaemoTemplatesManager *m_instance;