forked from qt-creator/qt-creator
Maemo: Fix detection of valid icon in publishing code.
Task-number: QTCREATORBUG-3342
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtGui/QIcon>
|
||||||
|
|
||||||
#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
|
#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
|
||||||
|
|
||||||
@@ -559,16 +560,15 @@ QStringList MaemoPublisherFremantleFree::findProblems() const
|
|||||||
QStringList problems;
|
QStringList problems;
|
||||||
const MaemoTemplatesManager * const templatesManager
|
const MaemoTemplatesManager * const templatesManager
|
||||||
= MaemoTemplatesManager::instance();
|
= MaemoTemplatesManager::instance();
|
||||||
const QString &description = templatesManager
|
const QString &description = templatesManager->shortDescription(m_project);
|
||||||
->controlFileFieldValue(m_project, QLatin1String("Description"));
|
|
||||||
if (description.trimmed().isEmpty()) {
|
if (description.trimmed().isEmpty()) {
|
||||||
problems << tr("The package description is empty.");
|
problems << tr("The package description is empty.");
|
||||||
} else if (description.contains(QLatin1String("insert up to"))) {
|
} else if (description.contains(QLatin1String("insert up to"))) {
|
||||||
problems << tr("The package description is '%1', which is probably "
|
problems << tr("The package description is '%1', which is probably "
|
||||||
"not what you want.").arg(description);
|
"not what you want.").arg(description);
|
||||||
}
|
}
|
||||||
if (templatesManager->controlFileFieldValue(m_project,
|
QString dummy;
|
||||||
QLatin1String("XB-Maemo-Icon-26")).trimmed().isEmpty())
|
if (templatesManager->packageManagerIcon(m_project, &dummy).isNull())
|
||||||
problems << tr("You have not set an icon for the package manager.");
|
problems << tr("You have not set an icon for the package manager.");
|
||||||
return problems;
|
return problems;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace Qt4ProjectManager {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const QByteArray IconFieldName("XB-Maemo-Icon-26:");
|
const QByteArray IconFieldName("XB-Maemo-Icon-26");
|
||||||
const QByteArray NameFieldName("XB-Maemo-Display-Name");
|
const QByteArray NameFieldName("XB-Maemo-Display-Name");
|
||||||
const QByteArray ShortDescriptionFieldName("Description");
|
const QByteArray ShortDescriptionFieldName("Description");
|
||||||
const QLatin1String PackagingDirName("qtc_packaging");
|
const QLatin1String PackagingDirName("qtc_packaging");
|
||||||
@@ -484,36 +484,10 @@ bool MaemoTemplatesManager::setVersion(const Project *project,
|
|||||||
QIcon MaemoTemplatesManager::packageManagerIcon(const Project *project,
|
QIcon MaemoTemplatesManager::packageManagerIcon(const Project *project,
|
||||||
QString *error) const
|
QString *error) const
|
||||||
{
|
{
|
||||||
QSharedPointer<QFile> controlFile
|
const QByteArray &base64Icon
|
||||||
= openFile(controlFilePath(project), QIODevice::ReadOnly, error);
|
= controlFileFieldValue(project, IconFieldName, true);
|
||||||
if (!controlFile)
|
if (base64Icon.isEmpty())
|
||||||
return QIcon();
|
return QIcon();
|
||||||
|
|
||||||
bool iconFieldFound = false;
|
|
||||||
QByteArray currentLine;
|
|
||||||
while (!iconFieldFound && !controlFile->atEnd()) {
|
|
||||||
currentLine = controlFile->readLine();
|
|
||||||
iconFieldFound = currentLine.startsWith(IconFieldName);
|
|
||||||
}
|
|
||||||
if (!iconFieldFound)
|
|
||||||
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;
|
QPixmap pixmap;
|
||||||
if (!pixmap.loadFromData(QByteArray::fromBase64(base64Icon))) {
|
if (!pixmap.loadFromData(QByteArray::fromBase64(base64Icon))) {
|
||||||
*error = tr("Invalid icon data in Debian control file.");
|
*error = tr("Invalid icon data in Debian control file.");
|
||||||
@@ -546,16 +520,17 @@ bool MaemoTemplatesManager::setPackageManagerIcon(const Project *project,
|
|||||||
buffer.close();
|
buffer.close();
|
||||||
iconAsBase64 = iconAsBase64.toBase64();
|
iconAsBase64 = iconAsBase64.toBase64();
|
||||||
QByteArray contents = controlFile->readAll();
|
QByteArray contents = controlFile->readAll();
|
||||||
const int iconFieldPos = contents.startsWith(IconFieldName)
|
const QByteArray iconFieldNameWithColon = IconFieldName + ':';
|
||||||
? 0 : contents.indexOf('\n' + IconFieldName);
|
const int iconFieldPos = contents.startsWith(iconFieldNameWithColon)
|
||||||
|
? 0 : contents.indexOf('\n' + iconFieldNameWithColon);
|
||||||
if (iconFieldPos == -1) {
|
if (iconFieldPos == -1) {
|
||||||
if (!contents.endsWith('\n'))
|
if (!contents.endsWith('\n'))
|
||||||
contents += '\n';
|
contents += '\n';
|
||||||
contents.append(IconFieldName).append(' ').append(iconAsBase64)
|
contents.append(iconFieldNameWithColon).append(' ').append(iconAsBase64)
|
||||||
.append('\n');
|
.append('\n');
|
||||||
} else {
|
} else {
|
||||||
const int oldIconStartPos
|
const int oldIconStartPos = (iconFieldPos != 0) + iconFieldPos
|
||||||
= (iconFieldPos != 0) + iconFieldPos + IconFieldName.length();
|
+ iconFieldNameWithColon.length();
|
||||||
int nextEolPos = contents.indexOf('\n', oldIconStartPos);
|
int nextEolPos = contents.indexOf('\n', oldIconStartPos);
|
||||||
while (nextEolPos != -1 && nextEolPos != contents.length() - 1
|
while (nextEolPos != -1 && nextEolPos != contents.length() - 1
|
||||||
&& contents.at(nextEolPos + 1) != '\n'
|
&& contents.at(nextEolPos + 1) != '\n'
|
||||||
@@ -580,7 +555,7 @@ bool MaemoTemplatesManager::setPackageManagerIcon(const Project *project,
|
|||||||
|
|
||||||
QString MaemoTemplatesManager::name(const Project *project) const
|
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)
|
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
|
QString MaemoTemplatesManager::shortDescription(const Project *project) const
|
||||||
{
|
{
|
||||||
return controlFileFieldValue(project, ShortDescriptionFieldName);
|
return QString::fromUtf8(controlFileFieldValue(project,
|
||||||
|
ShortDescriptionFieldName, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaemoTemplatesManager::setShortDescription(const Project *project,
|
bool MaemoTemplatesManager::setShortDescription(const Project *project,
|
||||||
@@ -636,22 +612,42 @@ QString MaemoTemplatesManager::controlFilePath(const Project *project) const
|
|||||||
return debianDirPath(project) + QLatin1String("/control");
|
return debianDirPath(project) + QLatin1String("/control");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MaemoTemplatesManager::controlFileFieldValue(const Project *project,
|
QByteArray MaemoTemplatesManager::controlFileFieldValue(const Project *project,
|
||||||
const QString &key) const
|
const QString &key, bool multiLine) const
|
||||||
{
|
{
|
||||||
|
QByteArray value;
|
||||||
QFile controlFile(controlFilePath(project));
|
QFile controlFile(controlFilePath(project));
|
||||||
if (!controlFile.open(QIODevice::ReadOnly))
|
if (!controlFile.open(QIODevice::ReadOnly))
|
||||||
return QString();
|
return value;
|
||||||
const QByteArray &contents = controlFile.readAll();
|
const QByteArray &contents = controlFile.readAll();
|
||||||
const int keyPos = contents.indexOf(key.toUtf8() + ':');
|
const int keyPos = contents.indexOf(key.toUtf8() + ':');
|
||||||
if (keyPos == -1)
|
if (keyPos == -1)
|
||||||
return QString();
|
return value;
|
||||||
const int valueStartPos = keyPos + key.length() + 1;
|
int valueStartPos = keyPos + key.length() + 1;
|
||||||
int valueEndPos = contents.indexOf('\n', keyPos);
|
int valueEndPos = contents.indexOf('\n', keyPos);
|
||||||
if (valueEndPos == -1)
|
if (valueEndPos == -1)
|
||||||
valueEndPos = contents.count();
|
valueEndPos = contents.count();
|
||||||
return QString::fromUtf8(contents.mid(valueStartPos,
|
value = contents.mid(valueStartPos, valueEndPos - valueStartPos).trimmed();
|
||||||
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)
|
void MaemoTemplatesManager::raiseError(const QString &reason)
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ public:
|
|||||||
bool setShortDescription(const ProjectExplorer::Project *project,
|
bool setShortDescription(const ProjectExplorer::Project *project,
|
||||||
const QString &description);
|
const QString &description);
|
||||||
|
|
||||||
QString controlFileFieldValue(const ProjectExplorer::Project *project,
|
|
||||||
const QString &key) const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void debianDirContentsChanged(const ProjectExplorer::Project *project);
|
void debianDirContentsChanged(const ProjectExplorer::Project *project);
|
||||||
void changeLogChanged(const ProjectExplorer::Project *project);
|
void changeLogChanged(const ProjectExplorer::Project *project);
|
||||||
@@ -115,6 +112,8 @@ private:
|
|||||||
QIODevice::OpenMode mode, QString *error) const;
|
QIODevice::OpenMode mode, QString *error) const;
|
||||||
bool setFieldValue(const ProjectExplorer::Project *project,
|
bool setFieldValue(const ProjectExplorer::Project *project,
|
||||||
const QByteArray &fieldName, const QByteArray &fieldValue);
|
const QByteArray &fieldName, const QByteArray &fieldValue);
|
||||||
|
QByteArray controlFileFieldValue(const ProjectExplorer::Project *project,
|
||||||
|
const QString &key, bool multiLine) const;
|
||||||
|
|
||||||
static MaemoTemplatesManager *m_instance;
|
static MaemoTemplatesManager *m_instance;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user