# # # rename "src/model/Sandbox.cpp" # to "src/model/Workspace.cpp" # # rename "src/model/Sandbox.h" # to "src/model/Workspace.h" # # rename "src/model/SandboxItem.cpp" # to "src/model/WorkspaceItem.cpp" # # rename "src/model/SandboxItem.h" # to "src/model/WorkspaceItem.h" # # rename "src/view/SandboxView.cpp" # to "src/view/WorkspaceView.cpp" # # rename "src/view/SandboxView.h" # to "src/view/WorkspaceView.h" # # patch "build.sh" # from [809f1cc67fe0ecda3454735464ae0b63fe98c696] # to [f0d9d53b77878fec754ad41e92c82390df044eab] # # patch "guitone.pro" # from [89e082af2d348fbe6b7b4ec79c3a3bff03ebc202] # to [ecc11c01d4ab8740e2abb65aff67e3a53a85e499] # # patch "i18n/guitone_de.ts" # from [4d6e118f11b385c34dfee77681fcde4149ec0bbe] # to [71fa0905c9ba2958ee5151fd9496f67c31917996] # # patch "src/model/Workspace.cpp" # from [1215a905f6e6ac7c03a6b682334ea11f0cb9c04e] # to [43e09bc3a0cf24607b0c2d47b433944593a091d6] # # patch "src/model/Workspace.h" # from [1d45782f677961dd0b26756631cca84e2f42f0a3] # to [b2a2b0f4cd224bdaff39b675ca7ec0e4958e534b] # # patch "src/model/WorkspaceItem.cpp" # from [e1ec37af3dacfee226873b073e821eb7f97dda31] # to [556f473be6d28710e2aaf00ed0a5e75df251bd57] # # patch "src/model/WorkspaceItem.h" # from [03027fb5e2ffb9c1681c060813cd7966e3916aac] # to [d6b997b0b651dcd9f9e634a7cd9c093ec07e4332] # # patch "src/view/Guitone.cpp" # from [cd72691e6335053d2a2c3f196e7a19f36fbfa58c] # to [ba0a4ba9d3fe4844028192813ad7d3a8b5b0067e] # # patch "src/view/Guitone.h" # from [8a5da66eca0fa0de1d91c901c483968e06171cdb] # to [5ff58c5b7379df9dc6b0207a2bf2f76ac83bc43c] # # patch "src/view/WorkspaceView.cpp" # from [23ae08df2a13749cb980fd9bcb6526b8a1091b33] # to [131c7316865cddb626c29ec289f650cf24ed55b8] # # patch "src/view/WorkspaceView.h" # from [10fbef1c0180658e46e747d7fbc475bfde876359] # to [79cd48180782e16ea83e15f81e3231b33591ec85] # ============================================================ --- build.sh 809f1cc67fe0ecda3454735464ae0b63fe98c696 +++ build.sh f0d9d53b77878fec754ad41e92c82390df044eab @@ -1,9 +1,13 @@ #!/bin/sh qmake guitone.pro && \ lupdate guitone.pro && \ lrelease guitone.pro && \ make $@ +if [ $? -gt 0 ]; then + exit 1; +fi + i18n_dir=bin/i18n if [ `uname` == "Darwin" ]; then i18n_dir=bin/guitone.app/Contents/MacOS/i18n ============================================================ --- guitone.pro 89e082af2d348fbe6b7b4ec79c3a3bff03ebc202 +++ guitone.pro ecc11c01d4ab8740e2abb65aff67e3a53a85e499 @@ -1,15 +1,16 @@ +CONFIG += qt debug HEADERS += src/view/XPM.h \ src/view/Guitone.h \ - src/view/SandboxView.h \ + src/view/WorkspaceView.h \ src/model/Monotone.h \ - src/model/Sandbox.h \ - src/model/SandboxItem.h + src/model/Workspace.h \ + src/model/WorkspaceItem.h SOURCES += src/view/XPM.cpp \ src/view/Guitone.cpp \ - src/view/SandboxView.cpp \ + src/view/WorkspaceView.cpp \ src/model/Monotone.cpp \ - src/model/Sandbox.cpp \ - src/model/SandboxItem.cpp \ + src/model/Workspace.cpp \ + src/model/WorkspaceItem.cpp \ src/main.cpp TEMPLATE = app DEPENDPATH += src ============================================================ --- i18n/guitone_de.ts 4d6e118f11b385c34dfee77681fcde4149ec0bbe +++ i18n/guitone_de.ts 71fa0905c9ba2958ee5151fd9496f67c31917996 @@ -35,7 +35,7 @@ The chosen directory is no monotone sandbox! - Das gewählte Verzeichnis ist kein monotone-Arbeitsverzeichnis! + Das gewählte Verzeichnis ist kein monotone-Arbeitsverzeichnis! Inventory could not be read @@ -59,95 +59,193 @@ Quit STRG+Q + + The chosen directory is no monotone workspace! + + + SandboxItem + + File + Datei + + + Status + Status + + + Rename Source + Quelle für Umbenennen + + + Rename Target + Ziel für Umbenennen + + + Added + hinzugefügt + + + Dropped + entfernt + + + Missing + fehlend + + + Patched + verändert + + + Unchanged + unverändert + + + Unknown + unbekannt + + + Ignored + ignoriert + + + SandboxView Hide i&gnored items - Verstecke i&gnorierte Elemente + Verstecke i&gnorierte Elemente File - Datei + Datei Folder - Verzeichnis + Verzeichnis Status - Status + Status ROOT - WURZEL + WURZEL Rename Source - Quelle für Umbenennen + Quelle für Umbenennen Rename Target - Ziel für Umbenennen + Ziel für Umbenennen Added - hinzugefügt + hinzugefügt Dropped - entfernt + entfernt Missing - fehlend + fehlend Patched - verändert + verändert Unchanged - unverändert + unverändert Unknown - unbekannt + unbekannt Ignored - ignoriert + ignoriert Add - Hinzufügen + Hinzufügen Drop - Entfernen + Entfernen Select Rename Target - Ziel für Umbenennung selektieren + Ziel für Umbenennung selektieren Select Rename Source - Quelle für Umbenennung selektieren + Quelle für Umbenennung selektieren Revert - Änderungen verwerfen + Änderungen verwerfen Info - Informationen + Informationen No functionality yet, sorry! - Funktioniert leider noch nicht! + Funktioniert leider noch nicht! + WorkspaceItem + + File + Datei + + + Status + Status + + + Rename Source + Quelle für Umbenennen + + + Rename Target + Ziel für Umbenennen + + + Added + hinzugefügt + + + Dropped + entfernt + + + Missing + fehlend + + + Patched + verändert + + + Unchanged + unverändert + + + Unknown + unbekannt + + + Ignored + ignoriert + + + main Unsupported OS ============================================================ --- src/model/Sandbox.cpp 1215a905f6e6ac7c03a6b682334ea11f0cb9c04e +++ src/model/Workspace.cpp 43e09bc3a0cf24607b0c2d47b433944593a091d6 @@ -18,20 +18,26 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "Sandbox.h" +#include "Workspace.h" #include #include -Sandbox::Sandbox() {} +Workspace::Workspace() +{ + // create a dummy item since the view needs at least one item + // in the model, otherwise the app crashes + rootItem = new WorkspaceItem(); +} -Sandbox::~Sandbox() +Workspace::~Workspace() { delete monotone; - delete workspaceDir; + delete workspaceDir; + delete rootItem; } -bool Sandbox::setWorkspaceDir(QString workspace) +bool Workspace::setWorkspaceDir(QString workspace) { workspaceDir = new QDir(workspace); if (!workspaceDir->exists()) @@ -53,7 +59,7 @@ return false; } -bool Sandbox::readInventory() +bool Workspace::readInventory() { monotone = Monotone::singleton(workspaceDir); @@ -65,7 +71,7 @@ return monotone->triggerCommand("inventory"); } -void Sandbox::parseInventory(int returnCode) +void Workspace::parseInventory(int returnCode) { QStringList *output = monotone->getOutput(); @@ -79,12 +85,12 @@ QRegExp regex("^(R|D|[ ])(R|A|[ ])(M|P|U|I|[ ])\\s(\\d+)\\s(\\d+)\\s(.+)$"); regex.setMinimal(TRUE); - std::map renameMap; - std::map::iterator renameIter; + std::map renameMap; + std::map::iterator renameIter; - SandboxItem *item; - std::list* tempItems = new std::list(); - + WorkspaceItem *item; + QList tempItems; + for (QStringList::Iterator it = output->begin(); it != output->end(); ++it) { if (regex.search(*it) == -1) @@ -98,11 +104,11 @@ // the first match if (list[1].compare("R") == 0) { - status |= SandboxItem::RenamedFrom; + status |= WorkspaceItem::RenamedFrom; } else if (list[1].compare("D") == 0) { - status |= SandboxItem::Dropped; + status |= WorkspaceItem::Dropped; } else { @@ -115,11 +121,11 @@ // the second match if (list[2].compare("R") == 0) { - status |= SandboxItem::RenamedTo; + status |= WorkspaceItem::RenamedTo; } else if (list[2].compare("A") == 0) { - status |= SandboxItem::Added; + status |= WorkspaceItem::Added; } else { @@ -132,23 +138,23 @@ // the third match if (list[3].compare("M") == 0) { - status |= SandboxItem::Missing; + status |= WorkspaceItem::Missing; } else if (list[3].compare("P") == 0) { - status |= SandboxItem::Patched; + status |= WorkspaceItem::Patched; } else if (list[3].compare("U") == 0) { - status |= SandboxItem::Unknown; + status |= WorkspaceItem::Unknown; } else if (list[3].compare("I") == 0) { - status |= SandboxItem::Ignored; + status |= WorkspaceItem::Ignored; } else { // if nothing is outputted, the file is unchanged - status |= SandboxItem::Unchanged; + status |= WorkspaceItem::Unchanged; } // now determine if the file has been renamed @@ -163,7 +169,8 @@ isDirectory = true; path = path.left(path.length() - 1); } - item = new SandboxItem(path, status, isDirectory); + // this item is given a parent explicitely later on + item = new WorkspaceItem(NULL, path, status, isDirectory); if (from_id > 0) { @@ -173,7 +180,7 @@ { renameMap[to_id] = item; } - tempItems->push_back(item); + tempItems.push_back(item); } int id = 0; @@ -187,15 +194,18 @@ renameMap[-id]->setRenamedTo(renameMap[id]); } - items = buildTreeRecursive(tempItems, NULL); - emit readyInventoryParsed(items); + rootItem->setChildren(buildTreeRecursive(tempItems, NULL)); + + // send a signal to update the whole view + QModelIndex startIndex = this->createIndex(0,0, rootItem); + emit dataChanged(startIndex, startIndex); } -std::list* Sandbox::buildTreeRecursive(std::list* items, SandboxItem* parentItem) +QList Workspace::buildTreeRecursive(QList items, WorkspaceItem* parentItem) { - std::list *finalItems = new std::list(); + QList finalItems; - SandboxItem *currentItem; + WorkspaceItem *currentItem; QString parentPath = ""; if (parentItem != NULL) @@ -203,9 +213,9 @@ parentPath = parentItem->getPath(); } - while (items->size() > 0) + while (items.size() > 0) { - currentItem = items->front(); + currentItem = items.front(); // // if the item is not directly inside the current path stop immediately @@ -221,13 +231,13 @@ } // remove the item if we can append it now - items->pop_front(); + items.pop_front(); // // it seems to be a valid item // // append item to final list - finalItems->push_back(currentItem); + finalItems.push_back(currentItem); // if the item is directory a directory, make sure we catch decendant items... recursion! if (currentItem->isDirectory()) @@ -238,7 +248,101 @@ return finalItems; } -std::list* Sandbox::getItems() +QModelIndex Workspace::index(int row, int column, const QModelIndex &parent) + const { - return items; + WorkspaceItem *parentItem; + + if (!parent.isValid()) + { + parentItem = rootItem; + } + else + { + parentItem = static_cast(parent.internalPointer()); + } + + WorkspaceItem *childItem = parentItem->child(row); + + if (childItem) + { + return createIndex(row, column, childItem); + } + + return QModelIndex(); } + +int Workspace::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + { + return static_cast(parent.internalPointer())->columnCount(); + } + + return rootItem->columnCount(); +} + +QVariant Workspace::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + WorkspaceItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} + +Qt::ItemFlags Workspace::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + { + return Qt::ItemIsEnabled; + } + + // TODO: add Qt::ItemIsDragEnabled and Qt::ItemIsDropEnabled as soon as this works... + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +// the root item needs to store the header for each field +QVariant Workspace::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + return rootItem->data(section); + } + + return QVariant(); +} + +QModelIndex Workspace::parent(const QModelIndex& index) const +{ + if (!index.isValid()) + { + return QModelIndex(); + } + + WorkspaceItem *childItem = static_cast(index.internalPointer()); + WorkspaceItem *parentItem = childItem->parent(); + + if (parentItem == rootItem) + { + return QModelIndex(); + } + + return createIndex(parentItem->row(), 0, parentItem); +} + +int Workspace::rowCount(const QModelIndex& parent) const +{ + WorkspaceItem *parentItem = rootItem; + + if (parent.isValid()) + { + parentItem = static_cast(parent.internalPointer()); + } + + return parentItem->childCount(); +} + ============================================================ --- src/model/Sandbox.h 1d45782f677961dd0b26756631cca84e2f42f0a3 +++ src/model/Workspace.h b2a2b0f4cd224bdaff39b675ca7ec0e4958e534b @@ -18,44 +18,41 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef SANDBOX_H -#define SANDBOX_H +#ifndef WORKSPACE_H +#define WORKSPACE_H -// -// Forward class declarations -// -class QDir; - -// -// Lib-Includes -// #include -#include +#include +#include -// -// Own-Includes -// -#include "SandboxItem.h" +#include "WorkspaceItem.h" #include "Monotone.h" -class Sandbox : public QObject +class Workspace : public QAbstractItemModel { Q_OBJECT public: - Sandbox(); - ~Sandbox(); + Workspace(); + ~Workspace(); bool setWorkspaceDir(QString workspace); - bool readInventory(); - std::list* getItems(); - signals: - void readyInventoryParsed(std::list*); + bool readInventory(); + + // needed Qt Model methods + QVariant data(const QModelIndex&, int) const; + Qt::ItemFlags flags(const QModelIndex&) const; + QVariant headerData(int, Qt::Orientation, int) const; + QModelIndex index(int, int, const QModelIndex&) const; + QModelIndex parent(const QModelIndex&) const; + int rowCount(const QModelIndex&) const; + int columnCount(const QModelIndex&) const; + private: - std::list* buildTreeRecursive(std::list*, SandboxItem*); + QList buildTreeRecursive(QList, WorkspaceItem*); QDir *workspaceDir; Monotone *monotone; - std::list *items; + WorkspaceItem *rootItem; private slots: void parseInventory(int); }; ============================================================ --- src/model/SandboxItem.cpp e1ec37af3dacfee226873b073e821eb7f97dda31 +++ src/model/WorkspaceItem.cpp 556f473be6d28710e2aaf00ed0a5e75df251bd57 @@ -17,65 +17,76 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "SandboxItem.h" +#include "WorkspaceItem.h" -SandboxItem::SandboxItem() +WorkspaceItem::WorkspaceItem() { - SandboxItem("", 0, FALSE); + parentItem = this; + path = ""; + status = 0; + dirFlag = false; } -SandboxItem::SandboxItem(QString p, int st, bool isDir) +WorkspaceItem::WorkspaceItem(WorkspaceItem* parent, QString p, int st, bool isDir) { + parentItem = parent; + path = p; status = st; dirFlag = isDir; - path = p; - children = new std::list(); } -SandboxItem::~SandboxItem() {} +WorkspaceItem::~WorkspaceItem() +{ + qDeleteAll(children); +} -void SandboxItem::setRenamedFrom(SandboxItem *to_item) +void WorkspaceItem::setRenamedFrom(WorkspaceItem *to_item) { renamed_from = to_item; } -SandboxItem* SandboxItem::getRenamedFrom() +WorkspaceItem* WorkspaceItem::getRenamedFrom() { return renamed_from; } -SandboxItem* SandboxItem::getRenamedTo() +WorkspaceItem* WorkspaceItem::getRenamedTo() { return renamed_to; } -void SandboxItem::setRenamedTo(SandboxItem *from_item) +void WorkspaceItem::setRenamedTo(WorkspaceItem *from_item) { renamed_to = from_item; } -void SandboxItem::setParent(SandboxItem *p) +void WorkspaceItem::setParent(WorkspaceItem *p) { - parent = p; + parentItem = p; } -SandboxItem* SandboxItem::getParent() +WorkspaceItem* WorkspaceItem::parent() { - return parent; + return parentItem; } -void SandboxItem::addChild(SandboxItem* child) +void WorkspaceItem::appendChild(WorkspaceItem* child) { child->setParent(this); - children->push_back(child); + children.append(child); } -void SandboxItem::setChildren(std::list *items) +WorkspaceItem* WorkspaceItem::child(int row) { + return children.value(row); +} + +void WorkspaceItem::setChildren(QList items) +{ // set the current element as parent for each children - std::list::iterator iter; + QList::iterator iter; - for (iter = items->begin(); iter != items->end(); ++iter) + for (iter = items.begin(); iter != items.end(); ++iter) { (*iter)->setParent(this); } @@ -83,38 +94,123 @@ children = items; } -std::list* SandboxItem::getChildren() +int WorkspaceItem::childCount() const { + return children.count(); +} + +int WorkspaceItem::row() const +{ + if (parentItem) + return parentItem->children.indexOf(const_cast(this)); + + return 0; +} + +int WorkspaceItem::columnCount() const +{ + // there are currently three columns per item + // 1: icon, 2: item name, 3: item status + return 3; +} + +QVariant WorkspaceItem::data(int column) const +{ + // return column headers for root item + if (parentItem == this) + { + switch (column) + { + case 1: return QVariant(QString(tr("File"))); + case 2: return QVariant(QString(tr("Status"))); + default: return QVariant(); + } + } + + switch (column) + { + // Qt::DecorationRole for icon display (col 0) + case 1: return QVariant(getFilename()); + case 2: return QVariant(statusString()); + default: return QVariant(); + } +} + +QList WorkspaceItem::getChildren() +{ return children; } -bool SandboxItem::isDirectory() +bool WorkspaceItem::isDirectory() { return dirFlag; } -QString SandboxItem::getPath() +QString WorkspaceItem::getPath() const { return path; } -QString SandboxItem::getFilename() +QString WorkspaceItem::getFilename() const { int pos = path.findRev('/'); - return pos == -1 ? path : path.right(path.length() - pos - 1); + return pos == -1 ? path : path.right(path.length() - pos - 1); } -int SandboxItem::getStatus() +int WorkspaceItem::getStatus() { return status; } -bool SandboxItem::hasStatus(int statusBits) +bool WorkspaceItem::hasStatus(int statusBits) const { return (status & statusBits) == statusBits; } -bool SandboxItem::hasNotStatus(int statusBits) +bool WorkspaceItem::hasNotStatus(int statusBits) const { return (status & statusBits) == 0; } + +QString WorkspaceItem::statusString() const +{ + QStringList list; + + if (this->hasStatus(WorkspaceItem::RenamedFrom)) + { + list.append(tr("Rename Source")); + } + if (this->hasStatus(WorkspaceItem::RenamedTo)) + { + list.append(tr("Rename Target")); + } + if (this->hasStatus(WorkspaceItem::Added)) + { + list.append(tr("Added")); + } + if (this->hasStatus(WorkspaceItem::Dropped)) + { + list.append(tr("Dropped")); + } + if (this->hasStatus(WorkspaceItem::Missing)) + { + list.append(tr("Missing")); + } + if (this->hasStatus(WorkspaceItem::Patched)) + { + list.append(tr("Patched")); + } + if (this->hasStatus(WorkspaceItem::Unchanged)) + { + list.append(tr("Unchanged")); + } + if (this->hasStatus(WorkspaceItem::Unknown)) + { + list.append(tr("Unknown")); + } + if (this->hasStatus(WorkspaceItem::Ignored)) + { + list.append(tr("Ignored")); + } + return list.join(", "); +} ============================================================ --- src/model/SandboxItem.h 03027fb5e2ffb9c1681c060813cd7966e3916aac +++ src/model/WorkspaceItem.h d6b997b0b651dcd9f9e634a7cd9c093ec07e4332 @@ -17,51 +17,66 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef SANDBOX_ITEM_H -#define SANDBOX_ITEM_H +#ifndef WORKSPACE_ITEM_H +#define WORKSPACE_ITEM_H #include -#include +#include +#include +#include -class SandboxItem +class WorkspaceItem : public QObject { -public: - SandboxItem(); - SandboxItem(QString, int, bool); - ~SandboxItem(); - void setRenamedFrom(SandboxItem*); - void setRenamedTo(SandboxItem*); - SandboxItem* getRenamedFrom(); - SandboxItem* getRenamedTo(); - void setParent(SandboxItem*); - SandboxItem* getParent(); - void addChild(SandboxItem*); - void setChildren(std::list*); - std::list* getChildren(); - bool isDirectory(); - QString getPath(); - QString getFilename(); - int getStatus(); - bool hasStatus(int); - bool hasNotStatus(int); + Q_OBJECT + public: + WorkspaceItem(); + WorkspaceItem(WorkspaceItem*, QString, int, bool); + ~WorkspaceItem(); + void setRenamedFrom(WorkspaceItem*); + void setRenamedTo(WorkspaceItem*); + WorkspaceItem* getRenamedFrom(); + WorkspaceItem* getRenamedTo(); + void setParent(WorkspaceItem*); + + void setChildren(QList); + QList getChildren(); + bool isDirectory(); + QString getPath() const; + QString getFilename() const; + int getStatus(); + bool hasStatus(int) const; + bool hasNotStatus(int) const; + QString statusString() const; + + + /* needed for Qt model class */ + WorkspaceItem* child(int); + int childCount() const; + int row() const; + int columnCount() const; + void appendChild(WorkspaceItem*); + WorkspaceItem* parent(); + QVariant data(int) const; + + + static const int RenamedFrom = 1; + static const int RenamedTo = 2; + static const int Added = 4; + static const int Dropped = 8; + static const int Missing = 16; + static const int Patched = 32; + static const int Unchanged = 64; + static const int Unknown = 128; + static const int Ignored = 256; - static const int RenamedFrom = 1; - static const int RenamedTo = 2; - static const int Added = 4; - static const int Dropped = 8; - static const int Missing = 16; - static const int Patched = 32; - static const int Unchanged = 64; - static const int Unknown = 128; - static const int Ignored = 256; -private: - SandboxItem *renamed_from; - SandboxItem *renamed_to; - SandboxItem *parent; - std::list *children; - int status; - bool dirFlag; - QString path; + private: + WorkspaceItem *renamed_from; + WorkspaceItem *renamed_to; + WorkspaceItem *parentItem; + QList children; + int status; + bool dirFlag; + QString path; }; #endif ============================================================ --- src/view/Guitone.cpp cd72691e6335053d2a2c3f196e7a19f36fbfa58c +++ src/view/Guitone.cpp ba0a4ba9d3fe4844028192813ad7d3a8b5b0067e @@ -35,14 +35,14 @@ { setCaption(tr("guitone - a frontend for monotone")); - // create sandbox object - mySandbox = new Sandbox(); + // create Workspace model + myWorkspace = new Workspace(); // // Menubar // menu = menuBar()->addMenu(tr("&File")); - QAction* act = menu->addAction(tr("&Import Sandbox..."), this, SLOT(chooseSandbox())); + QAction* act = menu->addAction(tr("&Import Sandbox..."), this, SLOT(chooseWorkspace())); act->setShortcut(tr("Ctrl+I", "Import")); act = menu->addAction(tr("&Quit"), this, SLOT(close())); @@ -59,9 +59,24 @@ // Main view // QSplitter *mainSplitter = new QSplitter(this); - treeView = new SandboxView(mainSplitter, SandboxView::FolderTree); - listView = new SandboxView(mainSplitter, SandboxView::FileList); + QItemSelectionModel *selection = new QItemSelectionModel(myWorkspace); + treeView = new WorkspaceView(mainSplitter, WorkspaceView::FolderTree); + treeView->setModel(myWorkspace); + treeView->setSelectionModel(selection); + + listView = new WorkspaceView(mainSplitter, WorkspaceView::FileList); + listView->setModel(myWorkspace); + listView->setSelectionModel(selection); + +/* + treeView->setRootIndex(mySandbox->index(0,0)); + listView->setRootIndex(mySandbox->index(0,0)); +*/ + /* + treeView = new WorkspaceView(mainSplitter, WorkspaceView::FolderTree); + listView = new WorkspaceView(mainSplitter, WorkspaceView::FileList); + connect(treeView, SIGNAL(updateDisplay(std::list*)), listView, SLOT(display(std::list*))); @@ -69,7 +84,8 @@ this, SLOT(doFindAndSelectItem(SandboxItem*))); connect(listView, SIGNAL(findAndSelectItem(SandboxItem*)), this, SLOT(doFindAndSelectItem(SandboxItem*))); - + + */ setCentralWidget(mainSplitter); resize( 450, 600 ); @@ -81,7 +97,7 @@ Guitone::~Guitone() {} -void Guitone::chooseSandbox() +void Guitone::chooseWorkspace() { QString fn = QFileDialog::getExistingDirectory( QString::null, @@ -96,23 +112,18 @@ return; } - if (!mySandbox->setWorkspaceDir(fn)) + if (!myWorkspace->setWorkspaceDir(fn)) { QMessageBox::information( this, tr("Invalid workspace"), - tr("The chosen directory is no monotone sandbox!"), + tr("The chosen directory is no monotone workspace!"), QMessageBox::Ok ); return; } - connect( - mySandbox, SIGNAL(readyInventoryParsed(std::list*)), - treeView, SLOT(display(std::list*)) - ); - - if (!mySandbox->readInventory()) + if (!myWorkspace->readInventory()) { QMessageBox::information( this, @@ -126,7 +137,8 @@ statusBar()->message(tr("Loading workspace..."), 2000 ); } -void Guitone::doFindAndSelectItem(SandboxItem* sbItem) +/* +void Guitone::doFindAndSelectItem(WorkspaceItem* sbItem) { // the item is a normal directory... if (sbItem->isDirectory()) @@ -153,3 +165,4 @@ listView->selectItem(sbItem); } } +*/ ============================================================ --- src/view/Guitone.h 8a5da66eca0fa0de1d91c901c483968e06171cdb +++ src/view/Guitone.h 5ff58c5b7379df9dc6b0207a2bf2f76ac83bc43c @@ -38,8 +38,8 @@ // // Own-Includes // -#include "../model/Sandbox.h" -#include "../view/SandboxView.h" +#include "../model/Workspace.h" +#include "../view/WorkspaceView.h" class Guitone: public QMainWindow { @@ -49,16 +49,15 @@ Guitone(); ~Guitone(); private slots: - void chooseSandbox(); - void doFindAndSelectItem( SandboxItem* ); + void chooseWorkspace(); + //void doFindAndSelectItem( WorkspaceItem* ); private: QMenu *menu; QToolBar *toolBar; - QString determineStatus( SandboxItem* ); - Sandbox *mySandbox; - SandboxView *treeView; - SandboxView *listView; + Workspace *myWorkspace; + WorkspaceView *treeView; + WorkspaceView *listView; }; ============================================================ --- src/view/SandboxView.cpp 23ae08df2a13749cb980fd9bcb6526b8a1091b33 +++ src/view/WorkspaceView.cpp 131c7316865cddb626c29ec289f650cf24ed55b8 @@ -1,13 +1,14 @@ -#include "SandboxView.h" +#include "WorkspaceView.h" #include #include -#include +//#include -SandboxView::SandboxView(QWidget* parent, int type) - : Q3ListView(parent) +WorkspaceView::WorkspaceView(QWidget* parent, int type) + : QTreeView(parent) { +/* rootItem = 0; itemPopup = new Q3PopupMenu(this); @@ -16,8 +17,9 @@ hideIgnoredItems_id = viewPopup->insertItem(tr("Hide i&gnored items"), this, SLOT(toggleHideIgnoredItems())); viewType = type; - - if (viewType == SandboxView::FileList) + + + if (viewType == WorkspaceView::FileList) { addColumn(tr("File")); } @@ -29,14 +31,15 @@ // common for both views addColumn(tr("Status")); - + connect(this, SIGNAL(contextMenuRequested(Q3ListViewItem*, const QPoint&,int)), this, SLOT(openContextMenu(Q3ListViewItem*, const QPoint&,int))); +*/ } -SandboxView::~SandboxView() {} - -void SandboxView::display(std::list* items) +WorkspaceView::~WorkspaceView() {} +/* +void WorkspaceView::display(std::list* items) { // clear lookup tables lookupTable.clear(); @@ -45,7 +48,7 @@ // clear view clear(); - if (viewType == SandboxView::FileList) + if (viewType == WorkspaceView::FileList) { displayFileList(items); } @@ -59,9 +62,9 @@ showHideIgnoredItems(!hideIgnoredItems); } -void SandboxView::displayFileList(std::list* items) +void WorkspaceView::displayFileList(std::list* items) { - std::list::iterator iter; + std::list::iterator iter; Q3ListViewItem *viewItem; for (iter= items->begin(); iter != items->end(); iter++) @@ -75,7 +78,7 @@ } } -void SandboxView::displayFolderTree(std::list* items) +void WorkspaceView::displayFolderTree(std::list* items) { connect(this, SIGNAL(selectionChanged(Q3ListViewItem*)), this, SLOT(doUpdateFolderTree(Q3ListViewItem*))); @@ -86,7 +89,7 @@ clear(); // dummy root element - rootItem = new SandboxItem("ROOT", 0 , true); + rootItem = new WorkspaceItem("ROOT", 0 , true); rootItem->setChildren(items); Q3ListViewItem *listViewRoot = new Q3ListViewItem(this, tr("ROOT")); @@ -102,11 +105,11 @@ emit updateDisplay(items); } -void SandboxView::displayFolderTreeRecursive(std::list* items, Q3ListViewItem* parent) +void WorkspaceView::displayFolderTreeRecursive(std::list* items, Q3ListViewItem* parent) { Q3ListViewItem *listItem; - std::list::iterator iter; + std::list::iterator iter; for (iter= items->begin(); iter != items->end(); iter++) { @@ -124,9 +127,9 @@ } -void SandboxView::doUpdateFolderTree(Q3ListViewItem* treeItem) +void WorkspaceView::doUpdateFolderTree(Q3ListViewItem* treeItem) { - std::map::iterator iter; + std::map::iterator iter; for (iter = lookupTable.begin(); iter != lookupTable.end(); iter++) { @@ -143,52 +146,9 @@ treeItem->setPixmap(0, QPixmap(XPM::FolderOpened)); } -QString SandboxView::determineItemStatus(SandboxItem* item) +void WorkspaceView::openContextMenu(Q3ListViewItem *item, const QPoint& pos, int col) { - QStringList list; - - if (item->hasStatus(SandboxItem::RenamedFrom)) - { - list.append(tr("Rename Source")); - } - if (item->hasStatus(SandboxItem::RenamedTo)) - { - list.append(tr("Rename Target")); - } - if (item->hasStatus(SandboxItem::Added)) - { - list.append(tr("Added")); - } - if (item->hasStatus(SandboxItem::Dropped)) - { - list.append(tr("Dropped")); - } - if (item->hasStatus(SandboxItem::Missing)) - { - list.append(tr("Missing")); - } - if (item->hasStatus(SandboxItem::Patched)) - { - list.append(tr("Patched")); - } - if (item->hasStatus(SandboxItem::Unchanged)) - { - list.append(tr("Unchanged")); - } - if (item->hasStatus(SandboxItem::Unknown)) - { - list.append(tr("Unknown")); - } - if (item->hasStatus(SandboxItem::Ignored)) - { - list.append(tr("Ignored")); - } - return list.join(", "); -} - -void SandboxView::openContextMenu(Q3ListViewItem *item, const QPoint& pos, int col) -{ - std::map::iterator iter = lookupTable.find(item); + std::map::iterator iter = lookupTable.find(item); // general, non-item-specific context menu? if (iter == lookupTable.end()) @@ -197,36 +157,36 @@ return; } - SandboxItem *sbItem = iter->second; + WorkspaceItem *sbItem = iter->second; itemPopup->clear(); int entry; - if (sbItem->hasStatus(SandboxItem::Unknown)) + if (sbItem->hasStatus(WorkspaceItem::Unknown)) { entry = itemPopup->insertItem(tr("Add"), this, SLOT(addItem(int))); itemPopup->setItemParameter(entry, (int)sbItem); } - if (sbItem->hasNotStatus(SandboxItem::Ignored) && sbItem->hasNotStatus(SandboxItem::Unknown)) + if (sbItem->hasNotStatus(WorkspaceItem::Ignored) && sbItem->hasNotStatus(WorkspaceItem::Unknown)) { entry = itemPopup->insertItem(tr("Drop"), this, SLOT(dropItem(int))); itemPopup->setItemParameter(entry, (int)sbItem); } - if (sbItem->hasStatus(SandboxItem::RenamedFrom)) + if (sbItem->hasStatus(WorkspaceItem::RenamedFrom)) { entry = itemPopup->insertItem(tr("Select Rename Target"), this, SLOT(selectRenameTarget(int))); itemPopup->setItemParameter(entry, (int)sbItem); } - if (sbItem->hasStatus(SandboxItem::RenamedTo)) + if (sbItem->hasStatus(WorkspaceItem::RenamedTo)) { entry = itemPopup->insertItem(tr("Select Rename Source"), this, SLOT(selectRenameSource(int))); itemPopup->setItemParameter(entry, (int)sbItem); } - if (sbItem->hasNotStatus(SandboxItem::Ignored) && sbItem->hasNotStatus(SandboxItem::Unchanged) && sbItem->hasNotStatus(SandboxItem::Unknown)) + if (sbItem->hasNotStatus(WorkspaceItem::Ignored) && sbItem->hasNotStatus(WorkspaceItem::Unchanged) && sbItem->hasNotStatus(WorkspaceItem::Unknown)) { entry = itemPopup->insertItem(tr("Revert"), this, SLOT(revertItem(int))); itemPopup->setItemParameter(entry, (int)sbItem); @@ -239,7 +199,7 @@ } } -void SandboxView::toggleHideIgnoredItems() +void WorkspaceView::toggleHideIgnoredItems() { bool hideIgnoredItems = viewPopup->isItemChecked(hideIgnoredItems_id); hideIgnoredItems = !hideIgnoredItems; @@ -248,60 +208,60 @@ showHideIgnoredItems(!hideIgnoredItems); } -void SandboxView::showHideIgnoredItems(bool show) +void WorkspaceView::showHideIgnoredItems(bool show) { - std::map::iterator iter; + std::map::iterator iter; for (iter = lookupTable.begin(); iter != lookupTable.end(); iter++) { - if (iter->second->hasStatus(SandboxItem::Ignored)) + if (iter->second->hasStatus(WorkspaceItem::Ignored)) { iter->first->setVisible(show); } } } -void SandboxView::addItem(int item) +void WorkspaceView::addItem(int item) { - SandboxItem *sbItem = (SandboxItem*)item; + WorkspaceItem *sbItem = (WorkspaceItem*)item; QMessageBox::information(this,tr("Info"), tr("No functionality yet, sorry!"),QMessageBox::Ok); qDebug("Adding item %s", sbItem->getFilename().latin1()); } -void SandboxView::dropItem(int item) +void WorkspaceView::dropItem(int item) { - SandboxItem *sbItem = (SandboxItem*)item; + WorkspaceItem *sbItem = (WorkspaceItem*)item; QMessageBox::information(this,tr("Info"), tr("No functionality yet, sorry!"),QMessageBox::Ok); qDebug("Dropping item %s", sbItem->getFilename().latin1()); } -void SandboxView::revertItem(int item) +void WorkspaceView::revertItem(int item) { - SandboxItem *sbItem = (SandboxItem*)item; + WorkspaceItem *sbItem = (WorkspaceItem*)item; QMessageBox::information(this,tr("Info"), tr("No functionality yet, sorry!"),QMessageBox::Ok); qDebug("Reverting item %s", sbItem->getFilename().latin1()); } -void SandboxView::selectRenameSource(int item) +void WorkspaceView::selectRenameSource(int item) { - SandboxItem *sbItem = (SandboxItem*)item; + WorkspaceItem *sbItem = (WorkspaceItem*)item; emit findAndSelectItem(sbItem->getRenamedFrom()); } -void SandboxView::selectRenameTarget(int item) +void WorkspaceView::selectRenameTarget(int item) { - SandboxItem *sbItem = (SandboxItem*)item; + WorkspaceItem *sbItem = (WorkspaceItem*)item; emit findAndSelectItem(sbItem->getRenamedTo()); } -bool SandboxView::selectItem(SandboxItem* sbItem) +bool WorkspaceView::selectItem(WorkspaceItem* sbItem) { - std::map::iterator iter; + std::map::iterator iter; iter = reverseLookupTable.find(sbItem); if (iter == reverseLookupTable.end()) @@ -317,7 +277,7 @@ return true; } -SandboxItem* SandboxView::getRootItem() +WorkspaceItem* WorkspaceView::getRootItem() { if (rootItem == 0) { @@ -326,3 +286,4 @@ } return rootItem; } +*/ ============================================================ --- src/view/SandboxView.h 10fbef1c0180658e46e747d7fbc475bfde876359 +++ src/view/WorkspaceView.h 79cd48180782e16ea83e15f81e3231b33591ec85 @@ -1,47 +1,48 @@ -#ifndef SANDBOX_VIEW_H -#define SANDBOX_VIEW_H +#ifndef WORKSPACE_VIEW_H +#define WORKSPACE_VIEW_H #include "XPM.h" -#include "../model/SandboxItem.h" +#include "../model/WorkspaceItem.h" -#include +#include #include #include -class SandboxView : public Q3ListView +class WorkspaceView : public QTreeView { Q_OBJECT public: - SandboxView(QWidget*, int); - ~SandboxView(); - void setItems(std::list*); - bool selectItem(SandboxItem*); + WorkspaceView(QWidget*, int); + ~WorkspaceView(); + + static const int FolderTree = 1; + static const int FileList = 2; +/* + void setItems(QList*); + bool selectItem(WorkspaceItem*); - static const int FolderTree = 1; - static const int FileList = 2; - public slots: - void display(std::list*); - SandboxItem* getRootItem(); + void display(std::list*); + WorkspaceItem* getRootItem(); private: int viewType; - std::list* sandboxItems; + std::list* sandboxItems; Q3PopupMenu *viewPopup; Q3PopupMenu *itemPopup; - SandboxItem *rootItem; + WorkspaceItem *rootItem; int hideIgnoredItems_id; - QString determineItemStatus(SandboxItem*); void showHideIgnoredItems(bool); - void displayFileList(std::list*); - void displayFolderTree(std::list*); - void displayFolderTreeRecursive(std::list*, Q3ListViewItem*); - std::map lookupTable; - std::map reverseLookupTable; + void displayFileList(std::list*); + void displayFolderTree(std::list*); + void displayFolderTreeRecursive(std::list*, Q3ListViewItem*); + std::map lookupTable; + std::map reverseLookupTable; + private slots: - void doUpdateFolderTree(Q3ListViewItem*); + void doUpdateFolderTree(Q3ListViewItem*); void openContextMenu(Q3ListViewItem*, const QPoint&, int); void toggleHideIgnoredItems(); void addItem(int); @@ -50,8 +51,9 @@ void selectRenameTarget(int); void selectRenameSource(int); signals: - void updateDisplay(std::list*); - void findAndSelectItem(SandboxItem*); + void updateDisplay(std::list*); + void findAndSelectItem(WorkspaceItem*); +*/ }; #endif