1 /***************************************************************************
2 *                                                                         *
3 *   This program is free software; you can redistribute it and/or modify  *
4 *   it under the terms of the GNU General Public License as published by  *
5 *   the Free Software Foundation; either version 3 of the License, or     *
6 *   (at your option) any later version.                                   *
7 *                                                                         *
8 ***************************************************************************/
9 
10 #pragma once
11 
12 #include <QAbstractItemModel>
13 #include <QSortFilterProxyModel>
14 
15 #include "dcpp/stdinc.h"
16 #include "dcpp/FavoriteManager.h"
17 
18 class PublicHubProxyModel: public QSortFilterProxyModel {
19     Q_OBJECT
20 
21 public:
22     virtual void sort(int column, Qt::SortOrder order);
23 };
24 
25 #define COLUMN_PHUB_NAME                0
26 #define COLUMN_PHUB_DESC                1
27 #define COLUMN_PHUB_USERS               2
28 #define COLUMN_PHUB_ADDRESS             3
29 #define COLUMN_PHUB_COUNTRY             4
30 #define COLUMN_PHUB_SHARED              5
31 #define COLUMN_PHUB_MINSHARE            6
32 #define COLUMN_PHUB_MINSLOTS            7
33 #define COLUMN_PHUB_MAXHUBS             8
34 #define COLUMN_PHUB_MAXUSERS            9
35 #define COLUMN_PHUB_REL                 10
36 #define COLUMN_PHUB_RATING              11
37 
38 
39 class PublicHubItem{
40 
41 public:
42 
43     PublicHubItem(const QList<QVariant> &data, PublicHubItem *parent = NULL);
44     ~PublicHubItem();
45 
46     void appendChild(PublicHubItem *child);
47 
48     PublicHubItem *child(int row);
49     int childCount() const;
50     int columnCount() const;
51     QVariant data(int column) const;
52     int row() const;
53     PublicHubItem *parent();
54 
55     QList<PublicHubItem*> childItems;
56 
57     void updateColumn(unsigned, QVariant);
58 
59     dcpp::HubEntry *entry;
60 
61 private:
62     QList<QVariant> itemData;
63     PublicHubItem *parentItem;
64 };
65 
66 class PublicHubModel : public QAbstractItemModel
67 {
68     Q_OBJECT
69 public:
70     PublicHubModel(QObject *parent = 0);
71     virtual ~PublicHubModel();
72 
73     /** */
74     QVariant data(const QModelIndex &, int) const;
75     /** */
76     Qt::ItemFlags flags(const QModelIndex &) const;
77     /** */
78     QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
79     /** */
80     QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const;
81     /** */
82     QModelIndex parent(const QModelIndex &index) const;
83     /** */
84     int rowCount(const QModelIndex &parent = QModelIndex()) const;
85     /** */
86     int columnCount(const QModelIndex &parent = QModelIndex()) const;
87     /** sort list */
88     virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
89 
90     /** */
91     void addResult(const QList<QVariant> &data, dcpp::HubEntry *);
92 
93     /** Clear the model and redraw it*/
94     void clearModel();
95 
96 private:
97 
98     PublicHubItem *rootItem;
99 
100     int sortColumn;
101     Qt::SortOrder sortOrder;
102 };
103