# # # add_file "src/model/IconProvider.cpp" # content [5ddb47c181717faa5abde519814eabc988c2509a] # # add_file "src/model/IconProvider.h" # content [885144fb251922aa222e90a0cbd3de49583ead14] # # patch "guitone.pro" # from [34c066c0fa40573afab0aa3fb5bcacc2225371f2] # to [e2372618dba45d2cbe93cce1187b6566f5e5f56c] # # patch "src/model/Workspace.cpp" # from [5f18048e6aa58cd66a1e4d1328aa70223c89d706] # to [a6496038ed7c10ae2d8427e3e5ad8533bdd24621] # # patch "src/model/Workspace.h" # from [dab043e1554f0c31547a9a410f2bfa672e88137f] # to [1443da62cced3ce55c2baabe5aa7d9d3c15d36ad] # # patch "src/model/WorkspaceItem.cpp" # from [8bd5cfab5b1aa74cb911729f215062fadea19f95] # to [aa03e0d283226c4a0c5ce01c5c474084b31aae4c] # # patch "src/stable.h" # from [1f38d45f42008383c3bba0c1a804b795d330e09f] # to [3a167b78f2f1c2aa7cb024962a1d9e7b0b0438e3] # # patch "src/view/Guitone.cpp" # from [71d73b9c49cc351b2d6544a1f91e19abc379732f] # to [b7382268b4b19157b7f3490d031f72bc601c2e1b] # ============================================================ --- src/model/IconProvider.cpp 5ddb47c181717faa5abde519814eabc988c2509a +++ src/model/IconProvider.cpp 5ddb47c181717faa5abde519814eabc988c2509a @@ -0,0 +1,60 @@ +/*************************************************************************** + * 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 "stable.h" +#include "IconProvider.h" +#include "WorkspaceItem.h" + +IconProvider::IconProvider(void) +{ + iconDirUnchanged = new QIcon(); + iconDirChanged = new QIcon(); + QStyle *style = QApplication::style(); + iconDirUnchanged->addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon)); + iconDirUnchanged->addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); + iconDirChanged->addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon)); + iconDirChanged->addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); +} + +IconProvider::~IconProvider(void) +{ + delete iconDirUnchanged; + delete iconDirChanged; +} + +QIcon IconProvider::getIcon(WorkspaceItem* item) +{ + if(item->isDirectory()) + { + if(item->hasStatus(WorkspaceItem::Unchanged)) + { + return *iconDirUnchanged; + } + else if(item->hasStatus(WorkspaceItem::Unchanged)) + { + return *iconDirChanged; + } + } + + + // TODO: Provide more icons for the differnt states + + return QIcon(":/monkey_on_16x16.png"); +} ============================================================ --- src/model/IconProvider.h 885144fb251922aa222e90a0cbd3de49583ead14 +++ src/model/IconProvider.h 885144fb251922aa222e90a0cbd3de49583ead14 @@ -0,0 +1,40 @@ +/*************************************************************************** + * 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 ICONPROVIDER_H +#define ICONPROVIDER_H + +class WorkspaceItem; +class QIcon; + +class IconProvider +{ +public: + IconProvider(void); + ~IconProvider(void); + QIcon getIcon(WorkspaceItem* item); + +private: + QIcon *iconDirUnchanged; + QIcon *iconDirChanged; +}; + +#endif + ============================================================ --- guitone.pro 34c066c0fa40573afab0aa3fb5bcacc2225371f2 +++ guitone.pro e2372618dba45d2cbe93cce1187b6566f5e5f56c @@ -5,21 +5,23 @@ src/view/WorkspaceView.h \ src/model/Monotone.h \ src/model/Workspace.h \ - src/model/WorkspaceItem.h + src/model/WorkspaceItem.h \ + src/model/IconProvider.h SOURCES += src/view/XPM.cpp \ src/view/Guitone.cpp \ src/view/WorkspaceView.cpp \ src/model/Monotone.cpp \ src/model/Workspace.cpp \ src/model/WorkspaceItem.cpp \ + src/model/IconProvider.cpp \ src/main.cpp -TEMPLATE = app -DEPENDPATH += src -INCLUDEPATH += . src -OBJECTS_DIR = tmp -MOC_DIR = tmp -DESTDIR = bin -QT += qt3support +TEMPLATE = app +DEPENDPATH += src +INCLUDEPATH += . src +OBJECTS_DIR = tmp +MOC_DIR = tmp +DESTDIR = bin +QT += qt3support TRANSLATIONS = i18n/guitone_de.ts RESOURCES = res/guitone.qrc PRECOMPILED_HEADER = src/stable.h ============================================================ --- src/model/Workspace.cpp 5f18048e6aa58cd66a1e4d1328aa70223c89d706 +++ src/model/Workspace.cpp a6496038ed7c10ae2d8427e3e5ad8533bdd24621 @@ -20,11 +20,16 @@ #include "Workspace.h" -Workspace::Workspace() +#include "Monotone.h" +#include "WorkspaceItem.h" +#include "IconProvider.h" + +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(); + iconProvider = new IconProvider(); } Workspace::~Workspace() @@ -32,6 +37,7 @@ delete monotone; delete workspaceDir; delete rootItem; + delete iconProvider; } bool Workspace::setWorkspaceDir(QString workspace) @@ -183,22 +189,22 @@ // 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; + } // Display the item properties - qDebug("Item: Name %s, PATH %s, Status %s, IsDir %d", - item->getFilename().trimmed().latin1(), - item->getPath().trimmed().latin1(), - item->statusString().trimmed().latin1(), - item->isDirectory() - ); + //qDebug("Item: Name %s, PATH %s, Status %s, IsDir %d", + // item->getFilename().trimmed().latin1(), + // item->getPath().trimmed().latin1(), + // item->statusString().trimmed().latin1(), + // item->isDirectory() + // ); tempItems->push_back(item); } @@ -215,7 +221,7 @@ } rootItem->setChildren(*(buildTreeRecursive(tempItems, NULL))); - + delete tempItems; // reset the model to repaint the view completly @@ -319,8 +325,15 @@ } WorkspaceItem *item = static_cast(index.internalPointer()); - - return item->data(index.column(), role); + + if((role == Qt::DecorationRole)) + { + return iconProvider->getIcon(item); + } + else + { + return item->data(index.column(), role); + } } Qt::ItemFlags Workspace::flags(const QModelIndex &index) const ============================================================ --- src/model/Workspace.h dab043e1554f0c31547a9a410f2bfa672e88137f +++ src/model/Workspace.h 1443da62cced3ce55c2baabe5aa7d9d3c15d36ad @@ -23,16 +23,16 @@ #include -#include "WorkspaceItem.h" -#include "Monotone.h" +class WorkspaceItem; +class Monotone; +class IconProvider; - class Workspace : public QAbstractItemModel { Q_OBJECT public: - Workspace(); + Workspace(QObject *parent); ~Workspace(); bool setWorkspaceDir(QString workspace); bool readInventory(); @@ -51,6 +51,7 @@ QDir *workspaceDir; Monotone *monotone; WorkspaceItem *rootItem; + IconProvider *iconProvider; private slots: void parseInventory(int); }; ============================================================ --- src/model/WorkspaceItem.cpp 8bd5cfab5b1aa74cb911729f215062fadea19f95 +++ src/model/WorkspaceItem.cpp aa03e0d283226c4a0c5ce01c5c474084b31aae4c @@ -92,6 +92,10 @@ (*iter)->setParent(this); } + while (!children.isEmpty()) + { + delete children.takeFirst(); + } children = items; } @@ -141,14 +145,7 @@ } else if (role == Qt::DecorationRole) { - if(column == 0) - { - return QIcon(":/monkey_on_16x16.png"); - } - else - { - return QVariant(); - } + return QVariant(); } else { ============================================================ --- src/stable.h 1f38d45f42008383c3bba0c1a804b795d330e09f +++ src/stable.h 3a167b78f2f1c2aa7cb024962a1d9e7b0b0438e3 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include ============================================================ --- src/view/Guitone.cpp 71d73b9c49cc351b2d6544a1f91e19abc379732f +++ src/view/Guitone.cpp b7382268b4b19157b7f3490d031f72bc601c2e1b @@ -26,7 +26,7 @@ setCaption(tr("guitone - a frontend for monotone")); // create Workspace model - myWorkspace = new Workspace(); + myWorkspace = new Workspace(this); // // Menubar