NodeModel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef NODEMODEL_H
00027 #define NODEMODEL_H
00028
00029 #include "Gnutella/Namespace.h"
00030 #include "Gnutella/NodeInfo.h"
00031 #include "Protocols/Transports/Connection.h"
00032
00033 using Gnutella::LocalPeer;
00034 using Gnutella::NodeInfo;
00035 using Protocols::Transports::NodeAddress;
00036 using Protocols::Transports::Connection;
00037
00039
00048 class NodeModel : public QAbstractTableModel
00049 {
00050 Q_OBJECT
00051
00052 public:
00053
00055 enum Status
00056 {
00057 Connecting,
00058 Handshaking,
00059 Connected,
00060 Disconnecting,
00061 Disconnected
00062 };
00063
00065
00072 enum Type
00073 {
00074 Undetermined,
00075 Peer,
00076 Ultrapeer,
00077 Leaf
00078 };
00079
00080 NodeModel();
00081 ~NodeModel();
00082
00083
00084 int rowCount (const QModelIndex &parent = QModelIndex()) const;
00085 int columnCount (const QModelIndex &parent = QModelIndex()) const;
00086 QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const;
00087 QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00088
00089 public slots:
00090
00091 void nodeConnecting (Connection *, NodeAddress);
00092 void setHandshaking (Connection *);
00093 void setConnected (Connection *, NodeInfo);
00094 void setDisconnected (QObject *);
00095
00096 private:
00097 bool setNodeStatus (ConnectionId id, Status status);
00098 bool setNodeType (ConnectionId id, Type type);
00099 bool setNodeServent (ConnectionId id, const QString &servent);
00100 bool setNodePort (ConnectionId id, quint16 port);
00101 bool nodeDisconnected (ConnectionId id);
00102
00103 private slots:
00104 void refreshModel();
00105
00106 private:
00107
00109 enum Constants
00110 {
00111 ModelRefreshInterval = 1000,
00112 AddressIndex = 0,
00113 PortIndex ,
00114 DurationIndex ,
00115 TypeIndex ,
00116 ServentIndex ,
00117 ColumnCount
00118 };
00119
00121
00124 struct NodeData
00125 {
00126 ConnectionId id;
00127 QString address;
00128 quint16 port;
00129 QDateTime startDateTime;
00130 QString servent;
00131 Status status;
00132 Type type;
00133
00134 NodeData() : id (0), address(), port (0), startDateTime(),
00135 servent(), status (Disconnected), type (Undetermined)
00136 {}
00137 };
00138
00139 typedef QList <NodeData *> NodeInfos;
00140
00141 int nodeIndex (ConnectionId id);
00142
00143 NodeInfos nodeInfos;
00144 QTimer updateTimer;
00145 QSignalMapper mapper;
00146 };
00147
00148 #endif // NODEMODEL_H