SearchModel.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
00023 #ifndef SEARCHMODEL_H
00024 #define SEARCHMODEL_H
00025
00026 #include "Gnutella/Packets/QueryHits.h"
00027
00028 using Gnutella::Packets::QueryHits;
00029
00030 namespace UIs {
00031 namespace Searching {
00033
00034 struct SearchResult {
00036 SearchResult(const QString &fn, const QString &ext, const quint32 &sz, quint32 sp, QString ht, QString clt)
00037 : fileName(fn), extension(ext), speed(QString()), size (0),
00038 rating("Good"), status("Available"), host(ht),
00039 client(clt), duration("0:53:24"),
00040 bitrate("8 bps"), hosts(), showEmphasized (false)
00041 {
00042 float fz = sz;
00043 int i = 0;
00044
00045 while (fz > 1024) {
00046 fz /= 1024;
00047 i++;
00048 }
00049
00050 switch (i) {
00051 case 0:
00052 size = QString().sprintf ("%.2f B", fz);
00053 break;
00054 case 1:
00055 size = QString().sprintf ("%.2f KB", fz);
00056 break;
00057 case 2:
00058 size = QString().sprintf ("%.2f MB", fz);
00059 break;
00060 default:
00061 size = QString().sprintf ("%.2f GB", fz);
00062 break;
00063 }
00064
00065 if (sp) {
00066 speed = QString().sprintf ("%d kbps", sp);
00067 }
00068 };
00069
00070 QString fileName;
00071 QString extension;
00072 QString speed;
00073 QString size;
00074 QString rating;
00075 QString status;
00076 QString host;
00077 QString client;
00078 QString duration;
00079 QString bitrate;
00080
00081 QList<SearchResult> hosts;
00082 bool showEmphasized;
00083 };
00084
00085 class SearchModel : public QAbstractTableModel
00086 {
00087 Q_OBJECT
00088 REFERENCE_OBJECT (SearchModel)
00089
00090 public:
00091 SearchModel(QObject *parent);
00092
00093 int rowCount(const QModelIndex &parent = QModelIndex()) const;
00094 int columnCount(const QModelIndex &parent = QModelIndex()) const;
00095 QVariant data(const QModelIndex &index, int role) const;
00096 QVariant headerData(int section, Qt::Orientation orientation,
00097 int role = Qt::DisplayRole) const;
00098 bool hasChildren (const QModelIndex &index) const;
00099 QModelIndex index(int row, int column, const QModelIndex &parent) const;
00100
00101 void tabActivated();
00102 void tabDisactivated();
00103
00104 private:
00105 int findIndex (SearchResult *result);
00106
00107 private:
00108 class IconProvider
00109 {
00110 public:
00111 IconProvider();
00112 ~IconProvider() {}
00113
00114 QIcon icon (QString fileExtension) const;
00115
00116 private:
00117 enum FileTypes {video, audio, compressed, photo, text, unknown};
00118
00119 QList<QIcon> iconList;
00120 QList<QString> videoFileExtensions;
00121 QList<QString> audioFileExtensions;
00122 QList<QString> compressedFileExtensions;
00123 QList<QString> photoFileExtensions;
00124 QList<QString> textFileExtensions;
00125 };
00126
00127 private:
00128
00129 enum SearchModelField {fileName, extension, size, hosts, speed, client};
00130
00131 QList<SearchResult> resultList;
00132 IconProvider iconProvider;
00133 int cCount;
00134 bool tabActive;
00135
00136 public:
00137 void addItem(SearchResult *result);
00138 void addHits(const QueryHits &quieryHits);
00139
00140 signals:
00141 void itemAdded();
00142
00143 };
00144
00145 }
00146 }
00148
00149 #endif // SEARCHMODEL_H