Commit 0d02c49c authored by Christian Kandeler's avatar Christian Kandeler

Maemo: Add GUI element to set project description.

parent 519b544f
......@@ -103,6 +103,9 @@ void MaemoPackageCreationWidget::initGui()
SIGNAL(controlChanged(const ProjectExplorer::Project*)), this,
SLOT(handleControlFileUpdate(const ProjectExplorer::Project*)));
connect(m_ui->nameLineEdit, SIGNAL(editingFinished()), SLOT(setName()));
m_ui->shortDescriptionLineEdit->setMaxLength(60);
connect(m_ui->shortDescriptionLineEdit, SIGNAL(editingFinished()),
SLOT(setShortDescription()));
}
void MaemoPackageCreationWidget::updateDebianFileList(const ProjectExplorer::Project *project)
......@@ -164,8 +167,8 @@ void MaemoPackageCreationWidget::updateName(const Project *project)
void MaemoPackageCreationWidget::updateShortDescription(const Project *project)
{
// TODO: Implment
Q_UNUSED(project);
m_ui->shortDescriptionLineEdit
->setText(MaemoTemplatesManager::instance()->shortDescription(project));
}
void MaemoPackageCreationWidget::setPackageManagerIcon()
......@@ -197,7 +200,11 @@ void MaemoPackageCreationWidget::setName()
void MaemoPackageCreationWidget::setShortDescription()
{
if (!MaemoTemplatesManager::instance()->setShortDescription(thisProject(),
m_ui->shortDescriptionLineEdit->text())) {
QMessageBox::critical(this, tr("File Error"),
tr("Could not set project description."));
}
}
void MaemoPackageCreationWidget::handleToolchainChanged()
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<height>189</height>
<width>584</width>
<height>230</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -27,22 +27,22 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
......@@ -61,7 +61,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
......@@ -156,14 +156,14 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>&lt;b&gt;Name for Package Manager:&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLineEdit" name="nameLineEdit"/>
......@@ -183,7 +183,34 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="shortDescriptionLabel">
<property name="text">
<string>&lt;b&gt;Short description for Package Manager:&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLineEdit" name="shortDescriptionLineEdit"/>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="packageManagerIconLabel">
<property name="minimumSize">
<size>
......@@ -196,7 +223,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QToolButton" name="packageManagerIconButton">
......@@ -235,14 +262,14 @@
</item>
</layout>
</item>
<item row="3" column="0">
<item row="6" column="0">
<widget class="QLabel" name="editDebianFileLabel">
<property name="text">
<string>&lt;b&gt;Adapt Debian file:&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="debianFilesComboBox"/>
......
......@@ -62,7 +62,8 @@ namespace Internal {
namespace {
const QByteArray IconFieldName("XB-Maemo-Icon-26:");
const QByteArray DescriptionFieldName("XB-Maemo-Display-Name");
const QByteArray NameFieldName("XB-Maemo-Display-Name");
const QByteArray ShortDescriptionFieldName("Description");
const QLatin1String PackagingDirName("qtc_packaging");
const QLatin1String DebianDirNameFremantle("debian_fremantle");
} // anonymous namespace
......@@ -261,7 +262,7 @@ bool MaemoTemplatesManager::adaptControlFile(const Project *project)
adaptControlFileField(controlContents, "Section", "user/hidden");
adaptControlFileField(controlContents, "Priority", "optional");
adaptControlFileField(controlContents, DescriptionFieldName,
adaptControlFileField(controlContents, NameFieldName,
project->displayName().toUtf8());
const int buildDependsOffset = controlContents.indexOf("Build-Depends:");
if (buildDependsOffset == -1) {
......@@ -288,21 +289,29 @@ bool MaemoTemplatesManager::adaptControlFile(const Project *project)
return true;
}
void MaemoTemplatesManager::adaptControlFileField(QByteArray &document,
bool MaemoTemplatesManager::adaptControlFileField(QByteArray &document,
const QByteArray &fieldName, const QByteArray &newFieldValue)
{
QByteArray adaptedLine = fieldName + ": " + newFieldValue;
const int lineOffset = document.indexOf(fieldName + ":");
if (lineOffset == -1) {
document.append(adaptedLine).append('\n');
} else {
int newlineOffset = document.indexOf('\n', lineOffset);
if (newlineOffset == -1) {
newlineOffset = document.length();
adaptedLine += '\n';
}
document.replace(lineOffset, newlineOffset - lineOffset, adaptedLine);
return true;
}
int newlineOffset = document.indexOf('\n', lineOffset);
bool updated = false;
if (newlineOffset == -1) {
newlineOffset = document.length();
adaptedLine += '\n';
updated = true;
}
const int replaceCount = newlineOffset - lineOffset;
if (!updated && document.mid(lineOffset, replaceCount) != adaptedLine)
updated = true;
if (updated)
document.replace(lineOffset, replaceCount, adaptedLine);
return updated;
}
bool MaemoTemplatesManager::updateDesktopFiles(const Qt4Target *target)
......@@ -571,19 +580,37 @@ bool MaemoTemplatesManager::setPackageManagerIcon(const Project *project,
QString MaemoTemplatesManager::name(const Project *project) const
{
return controlFileFieldValue(project, DescriptionFieldName);
return controlFileFieldValue(project, NameFieldName);
}
bool MaemoTemplatesManager::setName(const Project *project, const QString &name)
{
return setFieldValue(project, NameFieldName, name.toUtf8());
}
bool MaemoTemplatesManager::setName(const Project *project,
QString MaemoTemplatesManager::shortDescription(const Project *project) const
{
return controlFileFieldValue(project, ShortDescriptionFieldName);
}
bool MaemoTemplatesManager::setShortDescription(const Project *project,
const QString &description)
{
return setFieldValue(project, ShortDescriptionFieldName,
description.toUtf8());
}
bool MaemoTemplatesManager::setFieldValue(const Project *project,
const QByteArray &fieldName, const QByteArray &fieldValue)
{
QFile controlFile(controlFilePath(project));
if (!controlFile.open(QIODevice::ReadWrite))
return false;
QByteArray contents = controlFile.readAll();
adaptControlFileField(contents, DescriptionFieldName, description.toUtf8());
controlFile.resize(0);
controlFile.write(contents);
if (adaptControlFileField(contents, fieldName, fieldValue)) {
controlFile.resize(0);
controlFile.write(contents);
}
return true;
}
......
......@@ -73,6 +73,10 @@ public:
QString name(const ProjectExplorer::Project *project) const;
bool setName(const ProjectExplorer::Project *project,
const QString &name);
QString shortDescription(const ProjectExplorer::Project *project) const;
bool setShortDescription(const ProjectExplorer::Project *project,
const QString &description);
QString controlFileFieldValue(const ProjectExplorer::Project *project,
......@@ -105,10 +109,12 @@ private:
int &lineEndPos, int &valuePos);
bool adaptRulesFile(const ProjectExplorer::Project *project);
bool adaptControlFile(const ProjectExplorer::Project *project);
void adaptControlFileField(QByteArray &document, const QByteArray &fieldName,
bool adaptControlFileField(QByteArray &document, const QByteArray &fieldName,
const QByteArray &newFieldValue);
QSharedPointer<QFile> openFile(const QString &filePath,
QIODevice::OpenMode mode, QString *error) const;
bool setFieldValue(const ProjectExplorer::Project *project,
const QByteArray &fieldName, const QByteArray &fieldValue);
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