# # # add_file "src/Properties.cpp" # content [0c0831ffb9b173f3241286a72d34e4aa1cab46e5] # # add_file "src/Properties.h" # content [cee36b1fe0f3991a17365a3e2545b4098d95c723] # # patch "guitone.pro" # from [b87a7840beaebee66e362affcc92d3521bdc6e63] # to [d44f240539c53e325f8b1421fed21764fbedd679] # # patch "src/main.cpp" # from [980a3179878d33e38f2c16a98426dfdea4bd6840] # to [82ac06413ea9424d2835940c1a8fc12cf0f6466d] # # patch "src/model/ProxyModel.cpp" # from [dbada65ccb1b618becbe252ea4d5f72d7298514d] # to [f3b31a260e8ed6d4eabea51f4d2a63490f7f22de] # # patch "src/model/ProxyModel.h" # from [f8cc3edc262e6b6b3f0444723c6dd4698aa1d6a1] # to [148d1e218bb9c5229ae658db2c559b87b875adc0] # # patch "src/model/Workspace.cpp" # from [71359dde2f05e2f6ed7d2a9198b565f8993e4f83] # to [c89d0710c7f5953b4a23d762f19325ab8df72639] # # patch "src/model/WorkspaceItem.cpp" # from [ffac4afb4b7e9163bebb4bc51d0a10c5accc878b] # to [42f9501c46b9cfd11402868855b5faa3e5c279a5] # # patch "src/model/WorkspaceItem.h" # from [7cb74cc1ba628fc44af9bf601d99ac238bd67ed6] # to [ed64ce2be44956bcd5dddc51eb0abed655928bf6] # # patch "src/stable.h" # from [2e0f2e1a3953c8322726b86377b7902fe9263313] # to [63bb88d06044fe26b69cda1f52f54866812c5582] # # patch "src/view/Guitone.cpp" # from [cec9aa01303fe91e5619f5cdf5e3570c3985f212] # to [13e22d9863110d3c3016c1bf669041871e6976fe] # # patch "src/view/Guitone.h" # from [b045f88f34fec2d40cd70df6b5ae8d3fdd692a1d] # to [c255b20f0b057f5b04c71dc6373fdd08c7e427e3] # # patch "src/view/WorkspaceView.cpp" # from [da3f96d45b48d1decd6dcc98d3e68e7504a875f6] # to [1d9d8dd6173a212bc4f584458ca031e3d8dc4bc9] # # patch "src/view/WorkspaceView.h" # from [425b7e0bb87fe2d50b6fdc51bcf40f7921a85f18] # to [aa73630a6dd978497fbc7abaa2e4c1d667963b9c] # ============================================================ --- src/Properties.cpp 0c0831ffb9b173f3241286a72d34e4aa1cab46e5 +++ src/Properties.cpp 0c0831ffb9b173f3241286a72d34e4aa1cab46e5 @@ -0,0 +1,65 @@ +/*************************************************************************** +* Copyright (C) 2006 by Ingo Maindorfer * +* address@hidden * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include "Properties.h" + +Properties::Properties() +{ + settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "GUITONE", "GUITONE"); +} + + +Properties::~Properties() +{ + delete settings; +} + +QSize Properties::getStartupSize(void) const +{ + return settings->value("StartupSize", QSize(300, 200)).toSize(); +} + +void Properties::setStartupSize(QSize size) +{ + settings->setValue("StartupSize", size); + settings->sync(); +} + +QSize Properties::getFileListSize(void) const +{ + return settings->value("FileListSize", QSize(100, 100)).toSize(); +} + +void Properties::setFileListSize(QSize size) +{ + settings->setValue("FileListSize", size); + settings->sync(); +} + +QSize Properties::getTreeViewSize(void) const +{ + return settings->value("TreeViewSize", QSize(100, 100)).toSize(); +} + +void Properties::setTreeViewSize(QSize size) +{ + settings->setValue("TreeViewSize", size); + settings->sync(); +} ============================================================ --- src/Properties.h cee36b1fe0f3991a17365a3e2545b4098d95c723 +++ src/Properties.h cee36b1fe0f3991a17365a3e2545b4098d95c723 @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ingo Maindorfer * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef PROPERTIES_H +#define PROPERTIES_H + +// +// Forward class declarations +// +class QSettings; +class QSize; + +class Properties +{ + +public: + Properties(void); + ~Properties(void); + QSize getStartupSize(void) const; + void setStartupSize(QSize size); + QSize getFileListSize(void) const; + void setFileListSize(QSize size); + QSize getTreeViewSize(void) const; + void setTreeViewSize(QSize size); + + +private: + QSettings *settings; +}; + + +#endif ============================================================ --- guitone.pro b87a7840beaebee66e362affcc92d3521bdc6e63 +++ guitone.pro d44f240539c53e325f8b1421fed21764fbedd679 @@ -5,7 +5,8 @@ src/model/Workspace.h \ src/model/WorkspaceItem.h \ src/model/IconProvider.h \ - src/model/ProxyModel.h + src/model/ProxyModel.h \ + src/Properties.h SOURCES += src/view/Guitone.cpp \ src/view/WorkspaceView.cpp \ src/model/Monotone.cpp \ @@ -13,6 +14,7 @@ src/model/WorkspaceItem.cpp \ src/model/IconProvider.cpp \ src/model/ProxyModel.cpp \ + src/Properties.cpp \ src/main.cpp TEMPLATE = app DEPENDPATH += src ============================================================ --- src/main.cpp 980a3179878d33e38f2c16a98426dfdea4bd6840 +++ src/main.cpp 82ac06413ea9424d2835940c1a8fc12cf0f6466d @@ -55,7 +55,6 @@ // create and show the main window Guitone *mainWnd = new Guitone(); mainWnd->show(); - app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); return app.exec(); } ============================================================ --- src/model/ProxyModel.cpp dbada65ccb1b618becbe252ea4d5f72d7298514d +++ src/model/ProxyModel.cpp f3b31a260e8ed6d4eabea51f4d2a63490f7f22de @@ -23,7 +23,8 @@ #include "WorkspaceItem.h" ProxyModel::ProxyModel(QObject *parent, bool folderTree_) -: QSortFilterProxyModel(parent), folderTree(folderTree_) +: QSortFilterProxyModel(parent), folderTree(folderTree_), +sortColumn(0), sortOrder(Qt::AscendingOrder) { } @@ -40,7 +41,7 @@ { if(item->isDirectory()) { - return true; + return true; } return false; } @@ -53,21 +54,42 @@ WorkspaceItem *itemLeft = static_cast(left.internalPointer()); WorkspaceItem *itemRight = static_cast(right.internalPointer()); - if (itemLeft->isDirectory() && itemRight->isDirectory()) + // We shall sort by the name of the item + if (sortColumn == 0) { - return itemLeft->getFilename() < itemRight->getFilename(); - } + if (itemLeft->isDirectory() && itemRight->isDirectory()) + { + return itemLeft->getFilename() < itemRight->getFilename(); + } - if (!itemLeft->isDirectory() && !itemRight->isDirectory()) + if (!itemLeft->isDirectory() && !itemRight->isDirectory()) + { + return itemLeft->getFilename() < itemRight->getFilename(); + } + + if (itemLeft->isDirectory() && !itemRight->isDirectory()) + { + return true; + } + + // last case: !itemLeft->isDirectory() && itemRight->isDirectory() + return false; + } + // we shall sort only by status + else if (sortColumn == 1) { - return itemLeft->getFilename() < itemRight->getFilename(); + return itemLeft->getStatus() < itemRight->getStatus(); } - - if (itemLeft->isDirectory() && !itemRight->isDirectory()) + // anything else + else { - return true; + return false; } +} - // last case: !itemLeft->isDirectory() && itemRight->isDirectory() - return false; +void ProxyModel::sort(int column, Qt::SortOrder order) +{ + sortOrder = order; + sortColumn = column; + QSortFilterProxyModel::sort(column, order); } ============================================================ --- src/model/ProxyModel.h f8cc3edc262e6b6b3f0444723c6dd4698aa1d6a1 +++ src/model/ProxyModel.h 148d1e218bb9c5229ae658db2c559b87b875adc0 @@ -31,9 +31,12 @@ ~ProxyModel(void); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); private: bool folderTree; + int sortColumn; + Qt::SortOrder sortOrder; }; #endif ============================================================ --- src/model/Workspace.cpp 71359dde2f05e2f6ed7d2a9198b565f8993e4f83 +++ src/model/Workspace.cpp c89d0710c7f5953b4a23d762f19325ab8df72639 @@ -1,22 +1,22 @@ /*************************************************************************** - * Copyright (C) 2006 by Thomas Keller * - * address@hidden * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ +* Copyright (C) 2006 by Thomas Keller * +* address@hidden * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ #include "Workspace.h" @@ -26,65 +26,65 @@ Workspace::Workspace(QObject *parent) : QAbstractItemModel(parent) { - // create a dummy item since the view needs at least one item - // in the model, otherwise the app crashes - rootItem = new WorkspaceItem(); + // create a dummy item since the view needs at least one item + // in the model, otherwise the app crashes + rootItem = new WorkspaceItem(); iconProvider = new IconProvider(); - monotone = 0; + monotone = 0; } Workspace::~Workspace() { - delete monotone; - delete workspaceDir; - delete rootItem; + delete monotone; + delete workspaceDir; + delete rootItem; delete iconProvider; } bool Workspace::setWorkspaceDir(QString workspace) { - workspaceDir = new QDir(workspace); - if (!workspaceDir->exists()) - { - qWarning("Cannot find directory %s", qPrintable(workspace)); - return false; - } + workspaceDir = new QDir(workspace); + if (!workspaceDir->exists()) + { + qWarning("Cannot find directory %s", qPrintable(workspace)); + return false; + } - do - { - if (workspaceDir->cd("_MTN")) - { - return true; - } - } - while (!workspaceDir->isRoot() && workspaceDir->cdUp()); + do + { + if (workspaceDir->cd("_MTN")) + { + return true; + } + } + while (!workspaceDir->isRoot() && workspaceDir->cdUp()); - qWarning("Cannot find _MTN directory in or above %s", qPrintable(workspace)); - return false; + qWarning("Cannot find _MTN directory in or above %s", qPrintable(workspace)); + return false; } bool Workspace::readInventory() { - // enable the wait cursor - qApp->setOverrideCursor(Qt::WaitCursor); + // enable the wait cursor + qApp->setOverrideCursor(Qt::WaitCursor); - // grab the Monotone wrapper instance - monotone = Monotone::singleton(); + // grab the Monotone wrapper instance + monotone = Monotone::singleton(); - connect( - monotone, SIGNAL(commandFinished(int)), - this, SLOT(parseInventory(int)) - ); + connect( + monotone, SIGNAL(commandFinished(int)), + this, SLOT(parseInventory(int)) + ); - // setup a new process instance with a new working directory + // setup a new process instance with a new working directory monotone->setup(workspaceDir); - return monotone->triggerCommand("inventory"); + return monotone->triggerCommand("inventory"); } void Workspace::parseInventory(int returnCode) { - QStringList *output = monotone->getOutput(); + QStringList *output = monotone->getOutput(); // TODO: Better error reporting! if ((returnCode > 0) && (!output->isEmpty())) @@ -103,19 +103,19 @@ return; } - QRegExp regex("^(R|D|[ ])(R|A|[ ])(M|P|U|I|[ ])\\s(\\d+)\\s(\\d+)\\s(.+)$"); - regex.setMinimal(true); + QRegExp regex("^(R|D|[ ])(R|A|[ ])(M|P|U|I|[ ])\\s(\\d+)\\s(\\d+)\\s(.+)$"); + regex.setMinimal(true); - QMap renameMap; - QMap::iterator renameIter; + QMap renameMap; + QMap::iterator renameIter; - WorkspaceItem *item; - QList tempItems; + WorkspaceItem *item; + QList tempItems; - for (QStringList::Iterator it = output->begin(); it != output->end(); ++it) - { - if (regex.indexIn(*it) == -1) - { + for (QStringList::Iterator it = output->begin(); it != output->end(); ++it) + { + if (regex.indexIn(*it) == -1) + { qWarning("Couldn't parse inventory line %s", qPrintable(*it)); continue; } @@ -127,109 +127,109 @@ { status |= WorkspaceItem::RenamedFrom; } else - if (list[1].compare("D") == 0) - { - status |= WorkspaceItem::Dropped; - } - else - { - if (list[1].compare(" ") != 0) + if (list[1].compare("D") == 0) { - qWarning("Unknown status first tripel %s", qPrintable(list[1])); + 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) + // the second match + if (list[2].compare("R") == 0) { - qWarning("Unknown status second tripel %s", qPrintable(list[2])); - } - } + 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; - } + // 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(); + // 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); + // 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; - } + 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; + int id = 0; - while (true) - { - renameIter = renameMap.find(++id); - if (renameIter == renameMap.end()) break; + while (true) + { + renameIter = renameMap.find(++id); + if (renameIter == renameMap.end()) break; - renameMap[id]->setRenamedFrom(renameMap[-id]); - renameMap[-id]->setRenamedTo(renameMap[id]); - } + renameMap[id]->setRenamedFrom(renameMap[-id]); + 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(); + // 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 - // (all QModelIndexes are discarded through that, e.g. selections!) - this->reset(); + // reset the model to repaint the view completly + // (all QModelIndexes are discarded through that, e.g. selections!) + this->reset(); - // restore the normal cursor - qApp->restoreOverrideCursor(); + // restore the normal cursor + qApp->restoreOverrideCursor(); return; } @@ -238,94 +238,94 @@ { QList finalItems; - WorkspaceItem *currentItem; - QString parentPath = ""; + WorkspaceItem *currentItem; + QString parentPath = ""; - if (parentItem != NULL) - { - parentPath = parentItem->getPath(); - } + if (parentItem != NULL) + { + parentPath = parentItem->getPath(); + } - while (items.size() > 0) - { + while (items.size() > 0) + { currentItem = items.front(); - // - // if the item is not directly inside the current path stop immediately - // - QString tmpPath = parentPath; - tmpPath.append("/"); - tmpPath.append(currentItem->getFilename()); + // + // if the item is not directly inside the current path stop immediately + // + QString tmpPath = parentPath; + tmpPath.append("/"); + tmpPath.append(currentItem->getFilename()); - // path may not be empty for this condition - if (!parentPath.isEmpty() && currentItem->getPath().compare(tmpPath) != 0) - { - break; - } + // path may not be empty for this condition + if (!parentPath.isEmpty() && currentItem->getPath().compare(tmpPath) != 0) + { + break; + } - // remove the item if we can append it now + // remove the item if we can append it now items.pop_front(); - // - // it seems to be a valid item - // + // + // it seems to be a valid item + // - // if the item is directory a directory, make sure we catch decendant items... recursion! - if (currentItem->isDirectory()) - { - //currentItem->setChildren(*(buildTreeRecursive(items, currentItem))); + // if the item is directory a directory, make sure we catch decendant items... recursion! + if (currentItem->isDirectory()) + { + //currentItem->setChildren(*(buildTreeRecursive(items, currentItem))); currentItem->setChildren(buildTreeRecursive(items, currentItem)); - } + } - // append item to final list + // append item to final list finalItems.push_back(currentItem); - } - return finalItems; + } + return finalItems; } QModelIndex Workspace::index(int row, int column, const QModelIndex &parent) - const +const { - WorkspaceItem *parentItem; + WorkspaceItem *parentItem; - if (!parent.isValid()) - { - parentItem = rootItem; - } - else - { - parentItem = static_cast(parent.internalPointer()); - } + if (!parent.isValid()) + { + parentItem = rootItem; + } + else + { + parentItem = static_cast(parent.internalPointer()); + } - WorkspaceItem *childItem = parentItem->child(row); + WorkspaceItem *childItem = parentItem->child(row); - if (childItem) - { - return createIndex(row, column, childItem); - } + if (childItem) + { + return createIndex(row, column, childItem); + } - return QModelIndex(); + return QModelIndex(); } int Workspace::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) - { - return static_cast(parent.internalPointer())->columnCount(); - } + if (parent.isValid()) + { + return static_cast(parent.internalPointer())->columnCount(); + } - return rootItem->columnCount(); + return rootItem->columnCount(); } QVariant Workspace::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - { - return QVariant(); - } + if (!index.isValid()) + { + return QVariant(); + } - WorkspaceItem *item = static_cast(index.internalPointer()); + WorkspaceItem *item = static_cast(index.internalPointer()); if((role == Qt::DecorationRole) && (index.column() == 0)) { @@ -339,53 +339,56 @@ Qt::ItemFlags Workspace::flags(const QModelIndex &index) const { - if (!index.isValid()) - { - return Qt::ItemIsEnabled; - } + if (index.isValid()) + { + return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled; + } + else + { + return Qt::ItemIsDropEnabled; + } - // TODO: add Qt::ItemIsDragEnabled and Qt::ItemIsDropEnabled as soon as this works... - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + // 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, role); - } + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + return rootItem->data(section, role); + } - return QVariant(); + return QVariant(); } QModelIndex Workspace::parent(const QModelIndex& index) const { - if (!index.isValid()) - { - return QModelIndex(); - } + if (!index.isValid()) + { + return QModelIndex(); + } - WorkspaceItem *childItem = static_cast(index.internalPointer()); - WorkspaceItem *parentItem = childItem->parent(); + WorkspaceItem *childItem = static_cast(index.internalPointer()); + WorkspaceItem *parentItem = childItem->parent(); - if (parentItem == rootItem) - { - return QModelIndex(); - } + if (parentItem == rootItem) + { + return QModelIndex(); + } - return createIndex(parentItem->row(), 0, parentItem); + return createIndex(parentItem->row(), 0, parentItem); } int Workspace::rowCount(const QModelIndex& parent) const { - WorkspaceItem *parentItem = rootItem; + WorkspaceItem *parentItem = rootItem; - if (parent.isValid()) - { - parentItem = static_cast(parent.internalPointer()); - } + if (parent.isValid()) + { + parentItem = static_cast(parent.internalPointer()); + } - return parentItem->childCount(); + return parentItem->childCount(); } - ============================================================ --- src/model/WorkspaceItem.cpp ffac4afb4b7e9163bebb4bc51d0a10c5accc878b +++ src/model/WorkspaceItem.cpp 42f9501c46b9cfd11402868855b5faa3e5c279a5 @@ -36,6 +36,7 @@ path = ""; status = 0; dirFlag = false; + childDirFlag = false; } WorkspaceItem::WorkspaceItem(WorkspaceItem* parent, QString p, int st, bool isDir) @@ -44,6 +45,7 @@ path = p; status = st; dirFlag = isDir; + childDirFlag = false; } WorkspaceItem::~WorkspaceItem() @@ -97,9 +99,15 @@ // set the current element as parent for each children QList::iterator iter; + WorkspaceItem *item; for (iter = items.begin(); iter != items.end(); ++iter) { - (*iter)->setParent(this); + item = (*iter); + item->setParent(this); + if(item->dirFlag) + { + childDirFlag = true; + } } while (!children.isEmpty()) @@ -109,11 +117,6 @@ children = items; } -int WorkspaceItem::childCount() const -{ - return children.count(); -} - int WorkspaceItem::row() const { if (parentItem) @@ -163,32 +166,12 @@ } } -QList WorkspaceItem::getChildren() -{ - return children; -} - -bool WorkspaceItem::isDirectory() -{ - return dirFlag; -} - -QString WorkspaceItem::getPath() const -{ - return path; -} - QString WorkspaceItem::getFilename() const { int pos = path.lastIndexOf('/'); return pos == -1 ? path : path.right(path.length() - pos - 1); } -int WorkspaceItem::getStatus() -{ - return status; -} - bool WorkspaceItem::hasStatus(int statusBits) const { return (status & statusBits) == statusBits; ============================================================ --- src/model/WorkspaceItem.h 7cb74cc1ba628fc44af9bf601d99ac238bd67ed6 +++ src/model/WorkspaceItem.h ed64ce2be44956bcd5dddc51eb0abed655928bf6 @@ -30,33 +30,34 @@ { Q_OBJECT public: - WorkspaceItem(); + WorkspaceItem(void); WorkspaceItem(WorkspaceItem*, QString, int, bool); - ~WorkspaceItem(); + ~WorkspaceItem(void); void setRenamedFrom(WorkspaceItem*); void setRenamedTo(WorkspaceItem*); - WorkspaceItem* getRenamedFrom(); - WorkspaceItem* getRenamedTo(); + WorkspaceItem* getRenamedFrom(void); + WorkspaceItem* getRenamedTo(void); void setParent(WorkspaceItem*); void setChildren(QList); - QList getChildren(); - bool isDirectory(); - QString getPath() const; - QString getFilename() const; - int getStatus(); + inline QList getChildren(void) const { return children; }; + inline QString getPath(void) const { return path; }; + QString getFilename(void) const; + bool hasStatus(int) const; bool hasNotStatus(int) const; - QString statusString() const; + QString statusString(void) const; + inline bool isDirectory(void) const { return dirFlag; }; + inline bool hasChildDirs(void) const { return childDirFlag; }; + inline int getStatus(void){ return status; }; - /* needed for Qt model class */ WorkspaceItem* child(int); - int childCount() const; - int row() const; - int columnCount() const; + inline int childCount(void) const { return children.count(); } + int row(void) const; + int columnCount(void) const; void appendChild(WorkspaceItem*); - WorkspaceItem* parent(); + WorkspaceItem* parent(void); QVariant data(int, int) const; @@ -77,6 +78,7 @@ QList children; int status; bool dirFlag; + bool childDirFlag; QString path; }; ============================================================ --- src/stable.h 2e0f2e1a3953c8322726b86377b7902fe9263313 +++ src/stable.h 63bb88d06044fe26b69cda1f52f54866812c5582 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include #include ============================================================ --- src/view/Guitone.cpp cec9aa01303fe91e5619f5cdf5e3570c3985f212 +++ src/view/Guitone.cpp 13e22d9863110d3c3016c1bf669041871e6976fe @@ -23,6 +23,7 @@ #include "../model/Workspace.h" #include "../model/ProxyModel.h" #include "../view/WorkspaceView.h" +#include "Properties.h" Guitone::Guitone() : QMainWindow() @@ -87,7 +88,8 @@ setCentralWidget(mainSplitter); - resize(450, 600); + Properties properties; + resize(properties.getStartupSize()); statusBar()->showMessage(tr("Ready"), 2000); } @@ -113,10 +115,10 @@ // treeView->setExpanded(treeView->selectionModel()->currentIndex(), false); listView->setRootIndex(proxyIndex); index = proxyModelFolderTree->mapFromSource( index ); - //if(item->childCount() > 0) - //{ - // treeView->expand(index); - //} + if(item->hasChildDirs()) + { + treeView->expand(index); + } treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); } } @@ -166,3 +168,12 @@ statusBar()->showMessage(tr("Loading workspace..."), 2000 ); } + +void Guitone::closeEvent(QCloseEvent *event) +{ + // Do some cleanup before colseing down the application + Properties properties; + + properties.setStartupSize(size()); + event->accept(); +} ============================================================ --- src/view/Guitone.h b045f88f34fec2d40cd70df6b5ae8d3fdd692a1d +++ src/view/Guitone.h c255b20f0b057f5b04c71dc6373fdd08c7e427e3 @@ -44,10 +44,12 @@ void chooseWorkspace(); void criticalMtnError(const QString &); //void doFindAndSelectItem( WorkspaceItem* ); - void slotMapFolderTreeToFileList( const QModelIndex & proxyIndex ); - void slotMapFileListToFolderTree( const QModelIndex & proxyIndex ); + void slotMapFolderTreeToFileList( const QModelIndex &proxyIndex ); + void slotMapFileListToFolderTree( const QModelIndex &proxyIndex ); private: + void closeEvent(QCloseEvent *event); + QMenu *menu; QToolBar *toolBar; Workspace *myWorkspace; ============================================================ --- src/view/WorkspaceView.cpp da3f96d45b48d1decd6dcc98d3e68e7504a875f6 +++ src/view/WorkspaceView.cpp 1d9d8dd6173a212bc4f584458ca031e3d8dc4bc9 @@ -19,26 +19,40 @@ ***************************************************************************/ #include "WorkspaceView.h" +#include "../Properties.h" WorkspaceView::WorkspaceView(QWidget* parent, Type type_) : QTreeView(parent), type(type_) { + Properties properties; + if(type == FileList) { setRootIsDecorated(false); setItemsExpandable(false); + resize(properties.getFileListSize()); } else { setRootIsDecorated(true); + resize(properties.getTreeViewSize()); } setSelectionMode(QAbstractItemView::ExtendedSelection); + //setSelectionMode(QAbstractItemView::SingleSelection); + setDragEnabled(true); + setDropIndicatorShown(true); + //setAcceptDrops(true); header()->setClickable(true); header()->setSortIndicatorShown(true); createAndConnectContextActions(); + + connect( + qApp, SIGNAL(lastWindowClosed(void)), + this, SLOT(slotSaveState(void)) + ); } WorkspaceView::~WorkspaceView() {} @@ -224,3 +238,22 @@ { qDebug("WorkspaceView::slotUnignore!!!"); } + +void WorkspaceView::slotSaveState(void) +{ + Properties properties; + if(type == FileList) + { + properties.setFileListSize(size()); + } + else + { + properties.setTreeViewSize(size()); + } +} + +void WorkspaceView::reset(void) +{ + sortByColumn(0); + resizeColumnToContents(0); +} ============================================================ --- src/view/WorkspaceView.h 425b7e0bb87fe2d50b6fdc51bcf40f7921a85f18 +++ src/view/WorkspaceView.h aa73630a6dd978497fbc7abaa2e4c1d667963b9c @@ -42,8 +42,12 @@ void contextMenuEvent(QContextMenuEvent * ev); +public slots: + void reset(void); + private: void createAndConnectContextActions(void); + void closeEvent(void); QAction *actAdd; QAction *actRemove; @@ -63,6 +67,7 @@ void slotUnignore(void); void slotRevert(void); void slotRename(void); + void slotSaveState(void); }; #endif