TransferModel.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #ifndef TRANSFERMODEL_H
00024 #define TRANSFERMODEL_H
00025 
00026 namespace UIs {
00028 
00029 class NodesModel;
00030 class NodeDelegate;
00031 
00032 class Transfer
00033 {
00034 public:
00035     QString         fileName;
00036     int             size;
00037     QString         progress;
00038     QString         speed;
00039     QString         status;
00040     int             completed;
00041     QString         client;
00042     mutable QList<Transfer> childList;
00043     mutable Transfer *parent;
00044 
00045     Transfer (const QString &fn, const int &s, const QString &cl)
00046      :  fileName (fn), size (s), progress ("0"), speed ("0 Kbps"),
00047         status ("Requesting"), completed (0), client (cl), childList(),
00048         parent (0)
00049     {}
00050 
00051     Transfer (const Transfer &other)
00052      :  fileName (other.fileName), size (other.size), progress (other.progress),
00053         speed (other.speed), status (other.status), completed (other.completed),
00054         client (other.client), childList (other.childList),
00055         parent (other.parent)
00056     {}
00057 
00058     Transfer & operator= (const Transfer &other)
00059     {
00060         if (this != &other) {
00061             fileName = other.fileName;
00062             size  = other.size;
00063             progress  = other.progress;
00064             speed  = other.speed;
00065             status = other.status;
00066             completed = other.completed;
00067             client = other.client;
00068             childList = other.childList;
00069             parent = other.parent;
00070         }
00071         return *this;
00072     }
00073 };
00074 
00075 class TransferModel : public QAbstractTableModel
00076 {
00077     Q_OBJECT
00078     REFERENCE_OBJECT (TransferModel)
00079 
00080 public:
00081     TransferModel(QObject *parent);
00082 
00083     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00084     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00085     QVariant data(const QModelIndex &index, int role) const;
00086     QVariant headerData(int section, Qt::Orientation orientation,
00087                         int role = Qt::DisplayRole) const;
00088     bool hasChildren (const QModelIndex &index) const;
00089     QModelIndex index(int row, int column, const QModelIndex &parent) const;
00090     QModelIndex parent ( const QModelIndex & index ) const;
00091     //QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex *index, QEvent *e);
00092 private:
00093     QList<Transfer> transferList;
00094     int cCount;
00095 
00096 public:
00097     void addItem(Transfer *transfer, QTreeView *treeView);
00098 
00099 };
00100 
00101 } // namespace UIs
00103 
00104 #endif // TRANSFERMODEL_H