#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QStringList>
+#include <QtGui/QIcon>
#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
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;
}
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");
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.");
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'
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)
QString MaemoTemplatesManager::shortDescription(const Project *project) const
{
- return controlFileFieldValue(project, ShortDescriptionFieldName);
+ return QString::fromUtf8(controlFileFieldValue(project,
+ ShortDescriptionFieldName, false));
}
bool MaemoTemplatesManager::setShortDescription(const Project *project,
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)