forked from qt-creator/qt-creator
Maemo: Serialize package contents.
Reviewed-by: kh1
This commit is contained in:
@@ -31,13 +31,22 @@
|
||||
|
||||
#include "maemopackagecreationstep.h"
|
||||
|
||||
namespace {
|
||||
const char * const MODIFIED_KEY =
|
||||
"Qt4ProjectManager.BuildStep.MaemoPackage.Modified";
|
||||
const char * const LOCAL_FILES_KEY
|
||||
= "Qt4ProjectManager.BuildStep.MaemoPackage.LocalFiles";
|
||||
const char * const REMOTE_FILES_KEY
|
||||
= "Qt4ProjectManager.BuildStep.MaemoPackage.RemoteFiles";
|
||||
}
|
||||
|
||||
namespace Qt4ProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep)
|
||||
: QAbstractTableModel(packageStep),
|
||||
m_packageStep(packageStep),
|
||||
m_modified(true) // TODO: Has to come from settings
|
||||
m_modified(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,5 +108,32 @@ QVariant MaemoPackageContents::headerData(int section,
|
||||
return section == 0 ? tr("Local File Path") : tr("Remote File Path");
|
||||
}
|
||||
|
||||
QVariantMap MaemoPackageContents::toMap() const
|
||||
{
|
||||
QVariantMap map;
|
||||
map.insert(MODIFIED_KEY, m_modified);
|
||||
QStringList localFiles;
|
||||
QStringList remoteFiles;
|
||||
foreach (const Deployable &p, m_deployables) {
|
||||
localFiles << p.localFilePath;
|
||||
remoteFiles << p.remoteFilePath;
|
||||
}
|
||||
map.insert(LOCAL_FILES_KEY, localFiles);
|
||||
map.insert(REMOTE_FILES_KEY, remoteFiles);
|
||||
return map;
|
||||
}
|
||||
|
||||
void MaemoPackageContents::fromMap(const QVariantMap &map)
|
||||
{
|
||||
m_modified = map.value(MODIFIED_KEY).toBool();
|
||||
const QStringList localFiles = map.value(LOCAL_FILES_KEY).toStringList();
|
||||
const QStringList remoteFiles = map.value(REMOTE_FILES_KEY).toStringList();
|
||||
if (localFiles.count() != remoteFiles.count())
|
||||
qWarning("%s: serialized data inconsistent", Q_FUNC_INFO);
|
||||
const int count = qMin(localFiles.count(), remoteFiles.count());
|
||||
for (int i = 0; i < count; ++i)
|
||||
m_deployables << Deployable(localFiles.at(i), remoteFiles.at(i));
|
||||
}
|
||||
|
||||
} // namespace Qt4ProjectManager
|
||||
} // namespace Internal
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QtCore/QAbstractTableModel>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QVariantMap>
|
||||
|
||||
namespace Qt4ProjectManager {
|
||||
namespace Internal {
|
||||
@@ -62,14 +63,15 @@ public:
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
QVariantMap toMap() const;
|
||||
void fromMap(const QVariantMap &map);
|
||||
|
||||
Deployable deployableAt(int row) const;
|
||||
bool addDeployable(const Deployable &deployable);
|
||||
void removeDeployableAt(int row);
|
||||
bool isModified() const { return m_modified; }
|
||||
void setUnModified() { m_modified = false; }
|
||||
|
||||
// TODO: to/from map
|
||||
|
||||
private:
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index,
|
||||
|
||||
@@ -94,7 +94,13 @@ BuildStep *MaemoPackageCreationFactory::restore(BuildConfiguration *parent,
|
||||
StepType type, const QVariantMap &map)
|
||||
{
|
||||
Q_ASSERT(canRestore(parent, type, map));
|
||||
return new MaemoPackageCreationStep(parent);
|
||||
MaemoPackageCreationStep * const step
|
||||
= new MaemoPackageCreationStep(parent);
|
||||
if (!step->fromMap(map)) {
|
||||
delete step;
|
||||
return 0;
|
||||
}
|
||||
return step;
|
||||
}
|
||||
|
||||
bool MaemoPackageCreationFactory::canClone(BuildConfiguration *parent,
|
||||
|
||||
@@ -87,6 +87,18 @@ bool MaemoPackageCreationStep::init()
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariantMap MaemoPackageCreationStep::toMap() const
|
||||
{
|
||||
QVariantMap map(ProjectExplorer::BuildStep::toMap());
|
||||
return map.unite(m_packageContents->toMap());
|
||||
}
|
||||
|
||||
bool MaemoPackageCreationStep::fromMap(const QVariantMap &map)
|
||||
{
|
||||
m_packageContents->fromMap(map);
|
||||
return ProjectExplorer::BuildStep::fromMap(map);
|
||||
}
|
||||
|
||||
void MaemoPackageCreationStep::run(QFutureInterface<bool> &fi)
|
||||
{
|
||||
fi.reportResult(createPackage());
|
||||
|
||||
@@ -76,6 +76,8 @@ private:
|
||||
virtual void run(QFutureInterface<bool> &fi);
|
||||
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
|
||||
virtual bool immutable() const { return true; }
|
||||
virtual QVariantMap toMap() const;
|
||||
virtual bool fromMap(const QVariantMap &map);
|
||||
|
||||
bool createPackage();
|
||||
bool runCommand(QProcess &proc, const QString &command);
|
||||
|
||||
Reference in New Issue
Block a user