# # # patch "src/model/GetRevision.cpp" # from [1ca82e3b9ba7a2956fc60cff0e976c0ec1e681e2] # to [77ca78c81dd8faca37a87aada5170b436758b8c6] # # patch "src/model/GetRevision.h" # from [9c2675f10e96cf957979a04a2df71ae989d1d6c6] # to [b56605574c48d9c4d51b2b5e3a84340b8813f793] # ============================================================ --- src/model/GetRevision.cpp 1ca82e3b9ba7a2956fc60cff0e976c0ec1e681e2 +++ src/model/GetRevision.cpp 77ca78c81dd8faca37a87aada5170b436758b8c6 @@ -17,59 +17,61 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - + #include "GetRevision.h" #include "InventoryItem.h" -#include "Monotone.h" #include "vocab.h" #include #include #include -GetRevision::GetRevision(QObject *parent) - : QAbstractItemModel(parent) -{ - mtnDelegate = new MonotoneDelegate(this); -} +GetRevision::GetRevision(QObject * parent, const QString & db) + : QAbstractItemModel(parent), AutomateCommand(db) +{} -GetRevision::~GetRevision() -{ - delete mtnDelegate; -} +GetRevision::~GetRevision() {} -bool GetRevision::readRevision(const QString & rev) +void GetRevision::readRevision(const QString & rev) { revision.clear(); - + QStringList cmd; cmd << "get_revision"; if (rev.size() > 0) { cmd << rev; } - - return mtnDelegate->triggerCommand(cmd); + + MonotoneTask task(cmd); + AutomateCommand::enqueueTask(task); } -void GetRevision::parseOutput() +void GetRevision::processTaskResult(const MonotoneTask & task) { - BasicIOParser parser(AutomateCommand::data); + if (task.getReturnCode() != 0) + { + C(QString("Command returned with a non-zero return code (%1)") + .arg(task.getOutputUtf8())); + return; + } + + BasicIOParser parser(task.getOutputUtf8()); I(parser.parse()); - + StanzaList list = parser.getStanzas(); QString currentRevision; - + for (int i=0, size = list.size(); i < size; ++i) { Stanza stanza = list.at(i); Change change; bool found_change = false; - + for (int j=0, size2 = stanza.size(); j < size2; j++) { StanzaEntry entry = stanza.at(j); - + if (i == 0 && j == 0) { if (entry.sym != "format_version") @@ -82,14 +84,14 @@ void GetRevision::parseOutput() } break; } - + if (j == 0 && entry.sym == "new_manifest") { I(!entry.hash.isNull()); revision.new_manifest = entry.hash; break; } - + if (entry.sym == "old_revision") { I(!entry.hash.isNull()); @@ -98,9 +100,9 @@ void GetRevision::parseOutput() revision.changesAgainstParent.insert(currentRevision, changelist); break; } - + found_change = true; - + if (entry.sym == "delete") { I(entry.vals.size() == 1); @@ -108,7 +110,7 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + if (entry.sym == "rename") { I(entry.vals.size() == 1); @@ -116,7 +118,7 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + if (entry.sym == "add_dir") { I(entry.vals.size() == 1); @@ -124,7 +126,7 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + if (entry.sym == "add_file") { I(entry.vals.size() == 1); @@ -132,7 +134,7 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + if (entry.sym == "patch") { I(entry.vals.size() == 1); @@ -140,7 +142,7 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + if (entry.sym == "clear") { I(entry.vals.size() == 1); @@ -148,7 +150,7 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + if (entry.sym == "set") { I(entry.vals.size() == 1); @@ -156,46 +158,47 @@ void GetRevision::parseOutput() change.stanza = stanza; break; } - + found_change = false; - + W(QString("Unknown symbol %1.").arg(entry.sym)); } - + // check if we really processed an item entry if (!found_change) continue; I(revision.changesAgainstParent.contains(currentRevision)); revision.changesAgainstParent[currentRevision].append(change); } - + // set the first as the default parent against which changes are displayed changesAgainstParent = revision.changesAgainstParent.keys().at(0); - + // reset the view reset(); - + // signal that we've finished (whoever listens to that) emit revisionRead(); } -int GetRevision::columnCount(const QModelIndex &parent) const +int GetRevision::columnCount(const QModelIndex & parent) const { - return 2; + Q_UNUSED(parent); + return 2; } QVariant GetRevision::data(const QModelIndex & index, int role) const { if (!index.isValid()) - return QVariant(); - + return QVariant(); + if (!revision.changesAgainstParent.contains(changesAgainstParent)) return QVariant(); - - Change change = + + Change change = revision.changesAgainstParent[changesAgainstParent].at(index.row()); - + if (role == Qt::DisplayRole) - { + { switch (index.column()) { case 0: return QVariant(change.getTypeString()); @@ -227,14 +230,16 @@ QVariant GetRevision::data(const QModelI return QVariant(); } -Qt::ItemFlags GetRevision::flags(const QModelIndex &index) const -{ - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +Qt::ItemFlags GetRevision::flags(const QModelIndex & index) const +{ + Q_UNUSED(index); + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QVariant GetRevision::headerData(int section, Qt::Orientation orientation, int role) const { - if (role == Qt::DisplayRole) + Q_UNUSED(orientation); + if (role == Qt::DisplayRole) { switch (section) { @@ -248,25 +253,28 @@ int GetRevision::rowCount(const QModelIn int GetRevision::rowCount(const QModelIndex & parent) const { + Q_UNUSED(parent); if (!revision.changesAgainstParent.contains(changesAgainstParent)) return 0; - + return revision.changesAgainstParent[changesAgainstParent].size(); } QModelIndex GetRevision::index(int row, int column, const QModelIndex & parent) const { + Q_UNUSED(parent); if (!revision.changesAgainstParent.contains(changesAgainstParent)) return QModelIndex(); - - if (row >= revision.changesAgainstParent[changesAgainstParent].size()) + + if (row >= revision.changesAgainstParent[changesAgainstParent].size()) return QModelIndex(); - + return createIndex(row, column); } -QModelIndex GetRevision::parent(const QModelIndex& index) const +QModelIndex GetRevision::parent(const QModelIndex & index) const { + Q_UNUSED(index); return QModelIndex(); } @@ -278,9 +286,9 @@ void GetRevision::showChangesAgainstPare void GetRevision::showChangesAgainstParent(const QString & parent) { QStringList parents = getParentRevisions(); - + if (!parents.contains(parent)) return; - + changesAgainstParent = parent; reset(); } ============================================================ --- src/model/GetRevision.h 9c2675f10e96cf957979a04a2df71ae989d1d6c6 +++ src/model/GetRevision.h b56605574c48d9c4d51b2b5e3a84340b8813f793 @@ -17,12 +17,11 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - + #ifndef GET_REVISION_H #define GET_REVISION_H #include "AutomateCommand.h" -#include "MonotoneDelegate.h" #include "BasicIOParser.h" #include @@ -32,7 +31,7 @@ struct Change { struct Change { ChangeType type; Stanza stanza; - + inline QString getTypeString() { switch (type) @@ -47,7 +46,7 @@ struct Change { } return QString(); } - + inline Qt::GlobalColor getTypeColor() { switch (type) @@ -62,7 +61,7 @@ struct Change { } return Qt::transparent; } - + inline QString getDisplayData() { switch (type) @@ -94,7 +93,7 @@ struct Revision { QString new_manifest; QMap > changesAgainstParent; - + inline void clear() { new_manifest.clear(); @@ -106,10 +105,10 @@ public: { Q_OBJECT public: - GetRevision(QObject *); + GetRevision(QObject *, const QString &); virtual ~GetRevision(); QStringList getParentRevisions() const; - + // needed Qt Model methods QVariant data(const QModelIndex &, int) const; Qt::ItemFlags flags(const QModelIndex &) const; @@ -117,21 +116,21 @@ public: QModelIndex index(int, int, const QModelIndex &) const; QModelIndex parent(const QModelIndex &) const; int rowCount(const QModelIndex &) const; - int columnCount(const QModelIndex &) const; + int columnCount(const QModelIndex &) const; public slots: - bool readRevision(const QString &); + void readRevision(const QString &); void showChangesAgainstParent(const QString &); - + signals: void revisionRead(); private: - void parseOutput(); + void processTaskResult(const MonotoneTask &); - MonotoneDelegate * mtnDelegate; Revision revision; QString changesAgainstParent; }; #endif +