Warning, file /sdk/cervisia/updateview_items.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Copyright (C) 1999-2002 Bernd Gehrmann <bernd@mail.berlios.de>
0003  * Copyright (c) 2003-2008 André Wöbbeking <Woebbeking@kde.org>
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 #ifndef UPDATEVIEW_ITEMS_H
0021 #define UPDATEVIEW_ITEMS_H
0022 
0023 #include <QTreeWidgetItem>
0024 #include <qdatetime.h>
0025 #include <qmap.h>
0026 
0027 #include "entry.h"
0028 #include "updateview.h"
0029 
0030 class UpdateDirItem;
0031 class UpdateFileItem;
0032 class Visitor;
0033 
0034 UpdateDirItem *findOrCreateDirItem(const QString &, UpdateDirItem *);
0035 
0036 class UpdateItem : public QTreeWidgetItem
0037 {
0038 public:
0039     UpdateItem(UpdateView *parent, const Cervisia::Entry &entry, int type)
0040         : QTreeWidgetItem(parent, type)
0041         , m_entry(entry)
0042         , itemDepth(0)
0043     {
0044     }
0045 
0046     UpdateItem(UpdateItem *parent, const Cervisia::Entry &entry, int type)
0047         : QTreeWidgetItem(parent, type)
0048         , m_entry(entry)
0049         , itemDepth(parent->depth() + 1)
0050     {
0051     }
0052 
0053     const Cervisia::Entry &entry() const
0054     {
0055         return m_entry;
0056     }
0057 
0058     // Returns the path (relative to the repository).
0059     // QString() for the root item and its (direct) children.
0060     // If it's not QString() it ends with '/'.
0061     QString dirPath() const;
0062 
0063     // Returns the file name, including the path (relative to the repository)
0064     QString filePath() const;
0065 
0066     virtual void accept(Visitor &) = 0;
0067 
0068     virtual void setOpen(bool)
0069     {
0070     }
0071 
0072     int depth() const
0073     {
0074         return itemDepth;
0075     }
0076 
0077 protected:
0078     UpdateView *updateView() const
0079     {
0080         return static_cast<UpdateView *>(treeWidget());
0081     }
0082 
0083     Cervisia::Entry m_entry;
0084 
0085     int itemDepth;
0086 };
0087 
0088 class UpdateDirItem : public UpdateItem
0089 {
0090 public:
0091     enum { Name };
0092 
0093     UpdateDirItem(UpdateView *parent, const Cervisia::Entry &entry);
0094     UpdateDirItem(UpdateDirItem *parent, const Cervisia::Entry &entry);
0095 
0096     void syncWithDirectory();
0097     void syncWithEntries();
0098     void updateChildItem(const QString &name, Cervisia::EntryStatus status, bool isdir);
0099     void updateEntriesItem(const Cervisia::Entry &entry, bool isBinary);
0100 
0101     bool wasScanned() const
0102     {
0103         return m_opened;
0104     }
0105 
0106     bool operator<(const QTreeWidgetItem &other) const override;
0107 
0108     QVariant data(int column, int role) const override;
0109 
0110     void setOpen(bool o) override;
0111 
0112     void maybeScanDir(bool recursive);
0113 
0114     void accept(Visitor &) override;
0115 
0116     enum { RTTI = 10000 };
0117 
0118 private:
0119     void scanDirectory();
0120 
0121     UpdateDirItem *createDirItem(const Cervisia::Entry &entry);
0122     UpdateFileItem *createFileItem(const Cervisia::Entry &entry);
0123 
0124     UpdateItem *insertItem(UpdateItem *item);
0125 
0126     UpdateItem *findItem(const QString &name) const;
0127 
0128     using TMapItemsByName = QMap<QString, UpdateItem *>;
0129 
0130     TMapItemsByName m_itemsByName;
0131 
0132     bool m_opened;
0133 
0134     friend UpdateDirItem *findOrCreateDirItem(const QString &, UpdateDirItem *);
0135 };
0136 
0137 class UpdateFileItem : public UpdateItem
0138 {
0139 public:
0140     enum { Name, Status, Revision, TagOrDate, Timestamp };
0141 
0142     UpdateFileItem(UpdateDirItem *parent, const Cervisia::Entry &entry);
0143 
0144     bool undefinedState() const
0145     {
0146         return m_undefined;
0147     }
0148 
0149     bool operator<(const QTreeWidgetItem &other) const override;
0150 
0151     QVariant data(int column, int role) const override;
0152 
0153     void setStatus(Cervisia::EntryStatus status);
0154     void setRevTag(const QString &rev, const QString &tag);
0155     void setDate(const QDateTime &date);
0156     void setUndefinedState(bool b)
0157     {
0158         m_undefined = b;
0159     }
0160 
0161     void markUpdated(bool laststage, bool success);
0162 
0163     void accept(Visitor &) override;
0164 
0165     bool applyFilter(UpdateView::Filter filter);
0166 
0167     enum { RTTI = 10001 };
0168 
0169 private:
0170     int statusClass() const;
0171 
0172     bool m_undefined;
0173 };
0174 
0175 inline bool isDirItem(const QTreeWidgetItem *item)
0176 {
0177     return item && item->type() == UpdateDirItem::RTTI;
0178 }
0179 
0180 inline bool isFileItem(const QTreeWidgetItem *item)
0181 {
0182     return item && item->type() == UpdateFileItem::RTTI;
0183 }
0184 
0185 #endif // UPDATEVIEW_ITEMS_H