# # # patch "src/model/Monotone.cpp" # from [2e0022fd6cbfd817c79732f36fe587be707acef9] # to [83753eba69edcd9a471999590ca9685b6cb0f06f] # # patch "src/model/Workspace.cpp" # from [c89d0710c7f5953b4a23d762f19325ab8df72639] # to [86ba2597c1bc1ca022362d3e5c4a93245342be52] # # patch "src/model/Workspace.h" # from [632684069f8acbaa38ae4581b7c3cb47cdf5486e] # to [5d709d9768dae3e35eb91a043f161b53ca27a8a0] # # patch "src/model/WorkspaceItem.cpp" # from [42f9501c46b9cfd11402868855b5faa3e5c279a5] # to [75c3f62ceaa818055cdb85311e0806274a72d81a] # # patch "src/model/WorkspaceItem.h" # from [ed64ce2be44956bcd5dddc51eb0abed655928bf6] # to [efede517ccae18daa2b01eabfc266a089b815861] # # patch "src/stable.h" # from [63bb88d06044fe26b69cda1f52f54866812c5582] # to [8b50802d613c8ac53f4cbe531907166cf5d6d3c1] # # patch "src/view/Guitone.cpp" # from [11d16b92e4d558dc60057c5bd7b307399b46ac85] # to [9479fbb59d8eb850a4c86735004ef2d25189fb66] # ============================================================ --- src/model/Monotone.cpp 2e0022fd6cbfd817c79732f36fe587be707acef9 +++ src/model/Monotone.cpp 83753eba69edcd9a471999590ca9685b6cb0f06f @@ -41,6 +41,7 @@ qDebug("Calling waitForFinished"); // block until the process has really been finished process->waitForFinished(); + delete process; qDebug("Process finished"); } @@ -81,6 +82,7 @@ { isCleanExit = true; delete process; + delete output; process = 0; } ============================================================ --- src/model/Workspace.cpp c89d0710c7f5953b4a23d762f19325ab8df72639 +++ src/model/Workspace.cpp 86ba2597c1bc1ca022362d3e5c4a93245342be52 @@ -24,13 +24,18 @@ #include "WorkspaceItem.h" #include "IconProvider.h" -Workspace::Workspace(QObject *parent) : QAbstractItemModel(parent) +Workspace::Workspace(QObject *parent) : QAbstractItemModel(parent), +monotone(NULL), modelPresent(false) { // create a dummy item since the view needs at least one item // in the model, otherwise the app crashes - rootItem = new WorkspaceItem(); + rootItem = new WorkspaceItem(); + iconProvider = new IconProvider(); - monotone = 0; + regex = new QRegExp("^(R|D|[ ])(R|A|[ ])(M|P|U|I|[ ])\\s(\\d+)\\s(\\d+)\\s(.+)$"); + workspaceDir = new QDir(); + + regex->setMinimal(true); } Workspace::~Workspace() @@ -39,11 +44,18 @@ delete workspaceDir; delete rootItem; delete iconProvider; + delete regex; + delete workspaceDir; } bool Workspace::setWorkspaceDir(QString workspace) { - workspaceDir = new QDir(workspace); + if(modelPresent) + { + deleteModel(); + } + + workspaceDir->setPath(workspace); if (!workspaceDir->exists()) { qWarning("Cannot find directory %s", qPrintable(workspace)); @@ -65,6 +77,12 @@ bool Workspace::readInventory() { + if(modelPresent) + { + qWarning("Workspace::readInventory: A model is already present!"); + return false; + } + // enable the wait cursor qApp->setOverrideCursor(Qt::WaitCursor); @@ -73,7 +91,7 @@ connect( monotone, SIGNAL(commandFinished(int)), - this, SLOT(parseInventory(int)) + this, SLOT(createModel(int)) ); // setup a new process instance with a new working directory @@ -82,8 +100,13 @@ return monotone->triggerCommand("inventory"); } -void Workspace::parseInventory(int returnCode) +void Workspace::createModel(int returnCode) { + if(modelPresent) + { + qWarning("Workspace::createModel: A model is already created!"); + return; + } QStringList *output = monotone->getOutput(); // TODO: Better error reporting! @@ -103,106 +126,34 @@ return; } - QRegExp regex("^(R|D|[ ])(R|A|[ ])(M|P|U|I|[ ])\\s(\\d+)\\s(\\d+)\\s(.+)$"); - regex.setMinimal(true); - QMap renameMap; QMap::iterator renameIter; WorkspaceItem *item; QList tempItems; + int status(0); + int from_id(0); + int to_id(0); + QString path(""); + bool isDirectory(false); for (QStringList::Iterator it = output->begin(); it != output->end(); ++it) { - if (regex.indexIn(*it) == -1) + parseOutputLine(*it, status, from_id, to_id, path, isDirectory); + + // this item is given a parent explicitely later on + item = new WorkspaceItem(NULL, path, status, isDirectory); + + if (from_id > 0) { - qWarning("Couldn't parse inventory line %s", qPrintable(*it)); - continue; + renameMap[-from_id] = item; } - QStringList list = regex.capturedTexts(); - int status = 0; - - // the first match - if (list[1].compare("R") == 0) + if (to_id > 0) { - status |= WorkspaceItem::RenamedFrom; - } else - if (list[1].compare("D") == 0) - { - status |= WorkspaceItem::Dropped; - } - else - { - if (list[1].compare(" ") != 0) - { - qWarning("Unknown status first tripel %s", qPrintable(list[1])); - } - } + renameMap[to_id] = item; + } - // the second match - if (list[2].compare("R") == 0) - { - status |= WorkspaceItem::RenamedTo; - } else - if (list[2].compare("A") == 0) - { - status |= WorkspaceItem::Added; - } - else - { - if (list[2].compare(" ") != 0) - { - qWarning("Unknown status second tripel %s", qPrintable(list[2])); - } - } - - // the third match - if (list[3].compare("M") == 0) - { - status |= WorkspaceItem::Missing; - } else - if (list[3].compare("P") == 0) - { - status |= WorkspaceItem::Patched; - } else - if (list[3].compare("U") == 0) - { - status |= WorkspaceItem::Unknown; - } else - if (list[3].compare("I") == 0) - { - status |= WorkspaceItem::Ignored; - } else - { - // if nothing is outputted, the file is unchanged - status |= WorkspaceItem::Unchanged; - } - - // now determine if the file has been renamed - int from_id = list[4].toInt(); - int to_id = list[5].toInt(); - - // remove trailing slash - QString path = list[6].trimmed(); - bool isDirectory = false; - if (path.endsWith('/')) - { - isDirectory = true; - path = path.left(path.length() - 1); - } - // this item is given a parent explicitely later on - item = new WorkspaceItem(NULL, path, status, isDirectory); - - if (from_id > 0) - { - renameMap[-from_id] = item; - } - if (to_id > 0) - { - renameMap[to_id] = item; - } - - tempItems.push_back(item); + tempItems.push_back(item); } int id = 0; @@ -231,6 +182,8 @@ // restore the normal cursor qApp->restoreOverrideCursor(); + modelPresent = true; + return; } @@ -392,3 +345,99 @@ return parentItem->childCount(); } + +void Workspace::parseOutputLine(const QString &inputString, + int &status, + int &from_id, + int &to_id, + QString &path, + bool &isDirectory) +{ + if (regex->indexIn(inputString) == -1) + { + qWarning("Couldn't parse inventory line %s", qPrintable(inputString)); +// continue; + } + QStringList list = regex->capturedTexts(); + status = 0; + + // the first match + if (list[1].compare("R") == 0) + { + status |= WorkspaceItem::RenamedFrom; + } else + if (list[1].compare("D") == 0) + { + status |= WorkspaceItem::Dropped; + } + else + { + if (list[1].compare(" ") != 0) + { + qWarning("Unknown status first tripel %s", qPrintable(list[1])); + } + } + + // the second match + if (list[2].compare("R") == 0) + { + status |= WorkspaceItem::RenamedTo; + } else + if (list[2].compare("A") == 0) + { + status |= WorkspaceItem::Added; + } + else + { + if (list[2].compare(" ") != 0) + { + qWarning("Unknown status second tripel %s", qPrintable(list[2])); + } + } + + // the third match + if (list[3].compare("M") == 0) + { + status |= WorkspaceItem::Missing; + } else + if (list[3].compare("P") == 0) + { + status |= WorkspaceItem::Patched; + } else + if (list[3].compare("U") == 0) + { + status |= WorkspaceItem::Unknown; + } else + if (list[3].compare("I") == 0) + { + status |= WorkspaceItem::Ignored; + } else + { + // if nothing is outputted, the file is unchanged + status |= WorkspaceItem::Unchanged; + } + + // now determine if the file has been renamed + from_id = list[4].toInt(); + to_id = list[5].toInt(); + + // remove trailing slash + path = list[6].trimmed(); + isDirectory = false; + if (path.endsWith('/')) + { + isDirectory = true; + path = path.left(path.length() - 1); + } +} + +void Workspace::deleteModel(void) +{ + disconnect( + monotone, SIGNAL(commandFinished(int)), + this, SLOT(createModel(int)) + ); + rootItem->deleteAllChildren(); + modelPresent = false; + this->reset(); +} ============================================================ --- src/model/Workspace.h 632684069f8acbaa38ae4581b7c3cb47cdf5486e +++ src/model/Workspace.h 5d709d9768dae3e35eb91a043f161b53ca27a8a0 @@ -26,6 +26,7 @@ class WorkspaceItem; class Monotone; class IconProvider; +class QRegExp; class Workspace : public QAbstractItemModel { @@ -47,13 +48,17 @@ int columnCount(const QModelIndex&) const; private: + void parseOutputLine(const QString &, int &, int &, int &, QString &, bool &); QList buildTreeRecursive(QList &, WorkspaceItem*); - QDir *workspaceDir; - Monotone *monotone; - WorkspaceItem *rootItem; - IconProvider *iconProvider; + void deleteModel(void); + QDir *workspaceDir; + Monotone *monotone; + WorkspaceItem *rootItem; + IconProvider *iconProvider; + QRegExp *regex; + bool modelPresent; private slots: - void parseInventory(int); + void createModel(int); }; #endif ============================================================ --- src/model/WorkspaceItem.cpp 42f9501c46b9cfd11402868855b5faa3e5c279a5 +++ src/model/WorkspaceItem.cpp 75c3f62ceaa818055cdb85311e0806274a72d81a @@ -53,6 +53,17 @@ qDeleteAll(children); } +void WorkspaceItem::deleteAllChildren(void) +{ + parentItem = this; + path = ""; + status = 0; + dirFlag = false; + childDirFlag = false; + qDeleteAll(children); + children.clear(); +} + void WorkspaceItem::setRenamedFrom(WorkspaceItem *to_item) { renamed_from = to_item; @@ -110,10 +121,11 @@ } } - while (!children.isEmpty()) - { - delete children.takeFirst(); - } + //while (!children.isEmpty()) + //{ + // delete children.takeFirst(); + //} + children.clear(); children = items; } ============================================================ --- src/model/WorkspaceItem.h ed64ce2be44956bcd5dddc51eb0abed655928bf6 +++ src/model/WorkspaceItem.h efede517ccae18daa2b01eabfc266a089b815861 @@ -33,6 +33,7 @@ WorkspaceItem(void); WorkspaceItem(WorkspaceItem*, QString, int, bool); ~WorkspaceItem(void); + void deleteAllChildren(void); void setRenamedFrom(WorkspaceItem*); void setRenamedTo(WorkspaceItem*); WorkspaceItem* getRenamedFrom(void); ============================================================ --- src/stable.h 63bb88d06044fe26b69cda1f52f54866812c5582 +++ src/stable.h 8b50802d613c8ac53f4cbe531907166cf5d6d3c1 @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include ============================================================ --- src/view/Guitone.cpp 11d16b92e4d558dc60057c5bd7b307399b46ac85 +++ src/view/Guitone.cpp 9479fbb59d8eb850a4c86735004ef2d25189fb66 @@ -151,7 +151,7 @@ if (fn.isEmpty()) { - statusBar()->showMessage(tr("Loading aborted"), 2000 ); + statusBar()->showMessage(tr("Loading aborted"), 2000); return; }