# # # patch "src/model/Workspace.cpp" # from [2e2e0360fa9790fc042e538c317c5376d53f2d68] # to [11e182493b340a11ebe3729fe5f1bb1a93d7e210] # # patch "src/model/Workspace.h" # from [5d709d9768dae3e35eb91a043f161b53ca27a8a0] # to [5bd5433c0ba3e9b54d352e8685a636f9a40eaef8] # ============================================================ --- src/model/Workspace.cpp 2e2e0360fa9790fc042e538c317c5376d53f2d68 +++ src/model/Workspace.cpp 11e182493b340a11ebe3729fe5f1bb1a93d7e210 @@ -50,28 +50,22 @@ bool Workspace::setWorkspaceDir(QString workspace) { - // FIXME: if an invalid directory is selected, the current active - // view gets its model deleted and thus is cleared! - if(modelPresent) + QDir tempDir(workspace); + if (!tempDir.exists()) { - deleteModel(); - } - - workspaceDir->setPath(workspace); - if (!workspaceDir->exists()) - { qWarning("Cannot find directory %s", qPrintable(workspace)); return false; } do { - if (workspaceDir->cd("_MTN")) + if (tempDir.cd("_MTN")) { + workspaceDir->setPath(workspace); return true; } } - while (!workspaceDir->isRoot() && workspaceDir->cdUp()); + while (!tempDir.isRoot() && tempDir.cdUp()); qWarning("Cannot find _MTN directory in or above %s", qPrintable(workspace)); return false; @@ -81,8 +75,7 @@ { if(modelPresent) { - qWarning("Workspace::readInventory: A model is already present!"); - return false; + deleteModel(); } // enable the wait cursor @@ -138,24 +131,28 @@ int to_id(0); QString path(""); bool isDirectory(false); + bool isOk(false); for (QStringList::Iterator it = output->begin(); it != output->end(); ++it) { - parseOutputLine(*it, status, from_id, to_id, path, isDirectory); + parseOutputLine(*it, status, from_id, to_id, path, isDirectory, isOk); - // this item is given a parent explicitely later on - item = new WorkspaceItem(NULL, path, status, isDirectory); - - if (from_id > 0) + if (isOk) { - renameMap[-from_id] = item; - } - if (to_id > 0) - { - renameMap[to_id] = item; - } + // this item is given a parent explicitely later on + item = new WorkspaceItem(NULL, path, status, isDirectory); - tempItems.push_back(item); + if (from_id > 0) + { + renameMap[-from_id] = item; + } + if (to_id > 0) + { + renameMap[to_id] = item; + } + + tempItems.push_back(item); + } } int id = 0; @@ -169,12 +166,6 @@ renameMap[-id]->setRenamedTo(renameMap[id]); } - // clear the map to avoid memory leaks by having pointers to objects - // in more than one container - // TODO: we should still look out for some tool which allows us to - // monitor the app during execution for possible memory leaks. - //renameMap.clear(); - rootItem->setChildren(buildTreeRecursive(tempItems, NULL)); // reset the model to repaint the view completly @@ -353,15 +344,17 @@ int &from_id, int &to_id, QString &path, - bool &isDirectory) + bool &isDirectory, + bool &ok) { - // FIXME: we need to break here and ensure that no item - // is created if we really can't parse the inputString if (regex->indexIn(inputString) == -1) { qWarning("Couldn't parse inventory line %s", qPrintable(inputString)); -// continue; + ok = false; + return; } + ok = true; + QStringList list = regex->capturedTexts(); status = 0; ============================================================ --- src/model/Workspace.h 5d709d9768dae3e35eb91a043f161b53ca27a8a0 +++ src/model/Workspace.h 5bd5433c0ba3e9b54d352e8685a636f9a40eaef8 @@ -48,16 +48,18 @@ int columnCount(const QModelIndex&) const; private: - void parseOutputLine(const QString &, int &, int &, int &, QString &, bool &); + void parseOutputLine(const QString &, int &, int &, int &, QString &, bool &, bool &); QList buildTreeRecursive(QList &, WorkspaceItem*); void deleteModel(void); + QDir *workspaceDir; Monotone *monotone; WorkspaceItem *rootItem; IconProvider *iconProvider; QRegExp *regex; bool modelPresent; - private slots: + + private slots: void createModel(int); };