Commit 1764fda4 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Fix detection of valid icon in publishing code.

Task-number: QTCREATORBUG-3342
parent c3fe628d
......@@ -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;
}
......
......@@ -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)
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment