# # # patch "src/model/GetAttributes.cpp" # from [c52394f265f3b54ffd7f9bdead8abf5a08f67cad] # to [d8a85b2fc3848f2eb913c49ddaf3423c63273284] # # patch "src/model/GetAttributes.h" # from [691ce26cea013eebf8c329a2cf31a3f95da68ad6] # to [12f8e60c5fcb81caacd778b3b99c6da131af706f] # ============================================================ --- src/model/GetAttributes.cpp c52394f265f3b54ffd7f9bdead8abf5a08f67cad +++ src/model/GetAttributes.cpp d8a85b2fc3848f2eb913c49ddaf3423c63273284 @@ -17,9 +17,9 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - + #include "GetAttributes.h" -#include "Monotone.h" +#include "MonotoneUtil.h" #include "BasicIOParser.h" #include @@ -73,15 +73,15 @@ void GetAttributes::processTaskResult(co for (int i=0, size = list.size(); i < size; ++i) { Stanza stanza = list.at(i); - + Attribute attr; - + bool isItem = 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") @@ -94,12 +94,12 @@ void GetAttributes::processTaskResult(co } break; } - + // we're now only interested in stanzas starting with a "attr" entry if (j == 0 && entry.sym != "attr") break; - + isItem = true; - + if (entry.sym == "attr") { I(entry.vals.size() == 2); @@ -107,32 +107,32 @@ void GetAttributes::processTaskResult(co attr.value = entry.vals.at(1); continue; } - + if (entry.sym == "state") { I(entry.vals.size() == 1); QString state = entry.vals.at(0); - + if (state == "added") attr.state = Attribute::Added; else if (state == "dropped") attr.state = Attribute::Dropped; else if (state == "changed") attr.state = Attribute::Changed; else if (state == "unchanged") attr.state = Attribute::Unchanged; - else + else W(QString("Unknown attribute state '%1'.").arg(state)); - + continue; } W(QString("Unknown symbol %1.").arg(entry.sym)); } - + // check if we really processed an item entry if (!isItem) continue; attributes->append(attr); - } - + } + // reset the view reset(); - + // signal that we've finished (whoever listens to that) emit attributesRead(); } @@ -140,23 +140,23 @@ int GetAttributes::columnCount(const QMo int GetAttributes::columnCount(const QModelIndex & parent) const { Q_UNUSED(parent); - return 3; + return 3; } QVariant GetAttributes::data(const QModelIndex & index, int role) const { - if (!index.isValid()) - { - return QVariant(); - } - + if (!index.isValid()) + { + return QVariant(); + } + int row = index.row(), col = index.column(); if (row >= attributes->size()) return QVariant(); - + Attribute attr = attributes->at(row); - + if (role == Qt::DisplayRole) - { + { switch (col) { case 1: return QVariant(attr.key.length() == 0 ? tr("empty") : attr.key); @@ -164,7 +164,7 @@ QVariant GetAttributes::data(const QMode default: return QVariant(); } } - + if (role == Qt::ToolTipRole) { switch (attr.state) @@ -176,7 +176,7 @@ QVariant GetAttributes::data(const QMode default: return QVariant(); } } - + if (role == Qt::DecorationRole && col == 0) { switch (attr.state) @@ -188,21 +188,21 @@ QVariant GetAttributes::data(const QMode default: return QVariant(); } } - + if (role == Qt::FontRole) { QFont font; font.setItalic(true); - + if (col == 1 && attr.key.length() == 0) return QVariant(font); - + if (col == 2 && attr.value.length() == 0) return QVariant(font); - + return QVariant(); } - + if (role == Qt::UserRole) { switch (col) @@ -212,22 +212,22 @@ QVariant GetAttributes::data(const QMode default: return QVariant(); } } - + return QVariant(); } Qt::ItemFlags GetAttributes::flags(const QModelIndex & index) const { Q_UNUSED(index); - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QVariant GetAttributes::headerData(int section, Qt::Orientation orientation, int role) const { I(orientation == Qt::Horizontal); - - if (role == Qt::DisplayRole) - { + + if (role == Qt::DisplayRole) + { switch (section) { case 1: return QVariant(tr("Key")); @@ -235,19 +235,19 @@ QVariant GetAttributes::headerData(int s default: return QVariant(); } } - + if (role == Qt::DecorationRole && section == 0) { return QVariant(QIcon(":/icons/arrow_down.png")); } - + return QVariant(); } int GetAttributes::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); - return attributes->size(); + return attributes->size(); } QModelIndex GetAttributes::index(int row, int column, const QModelIndex & parent) const @@ -261,3 +261,17 @@ QModelIndex GetAttributes::parent(const return QModelIndex(); } +bool GetAttributes::setAttribute(const QString & key, const QString & value) +{ + MonotoneTask in(QStringList() << "set_attribute" << path << key << value); + MonotoneTask out = MonotoneUtil::runSynchronousTask(getDbPath(), in); + return out.getReturnCode() == 0; +} + +bool GetAttributes::dropAttribute(const QString & key) +{ + MonotoneTask in(QStringList() << "drop_attribute" << path << key); + MonotoneTask out = MonotoneUtil::runSynchronousTask(getDbPath(), in); + return out.getReturnCode() == 0; +} + ============================================================ --- src/model/GetAttributes.h 691ce26cea013eebf8c329a2cf31a3f95da68ad6 +++ src/model/GetAttributes.h 12f8e60c5fcb81caacd778b3b99c6da131af706f @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - + #ifndef GETATTRIBUTES_H #define GETATTRIBUTES_H @@ -38,9 +38,7 @@ public: public: GetAttributes(QObject *, const QString &); virtual ~GetAttributes(); - - inline QString currentPath() const { return path; } - + // needed Qt Model methods QVariant data(const QModelIndex &, int) const; Qt::ItemFlags flags(const QModelIndex &) const; @@ -50,10 +48,13 @@ public: int rowCount(const QModelIndex &) const; int columnCount(const QModelIndex &) const; + bool setAttribute(const QString &, const QString &); + bool dropAttribute(const QString &); + public slots: void readAttributes(const QString &); void revert(); - + signals: void attributesRead();