1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2008 Jakub Stachowski <qbast@go2.pl>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef DNSSDDOMAINMODEL_H
22#define DNSSDDOMAINMODEL_H
23
24#include <QtCore/QAbstractItemModel>
25#include <dnssd/dnssd_export.h>
26
27namespace DNSSD
28{
29
30struct DomainModelPrivate;
31class DomainBrowser;
32
33
34/**
35 * @class DomainModel domainmodel.h DNSSD/DomainModel
36 * @short Model for list of Zeroconf domains
37 *
38 * This class provides a Qt Model for DomainBrowser to allow easy
39 * integration of domain discovery into a GUI. For example, to
40 * provide a combo box listing available domains, you can do:
41 * @code
42 * DNSSD::DomainModel *domainModel = new DomainModel(
43 * new DNSSD::DomainBrowser(DNSSD::DomainBrowser::Browsing)
44 * );
45 * QComboBox *domainCombo = new QComboBox();
46 * domainCombo->setModel(domainModel);
47 * @endcode
48 *
49 * @since 4.1
50 * @author Jakub Stachowski
51 */
52
53class KDNSSD_EXPORT DomainModel : public QAbstractItemModel
54{
55 Q_OBJECT
56
57public:
58 /**
59 * Creates a model for given domain browser and starts
60 * browsing for domains.
61 *
62 * The model takes ownership of the browser,
63 * so there is no need to delete it afterwards.
64 *
65 * You should @b not call DomainBrowser::startBrowse() on @p browser
66 * before passing it to DomainModel.
67 *
68 * @param browser the domain browser that will provide the domains
69 * to be listed by the model
70 * @param parent the parent object (see QObject documentation)
71 */
72 explicit DomainModel(DomainBrowser* browser, QObject* parent = 0);
73
74 virtual ~DomainModel();
75
76 /** @reimp */
77 virtual int columnCount(const QModelIndex& parent = QModelIndex() ) const;
78 /** @reimp */
79 virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const;
80 /** @reimp */
81 virtual QModelIndex parent(const QModelIndex& index ) const;
82 /** @reimp */
83 virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex() ) const;
84 /** @reimp */
85 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const;
86 /** @reimp */
87 virtual bool hasIndex(int row, int column, const QModelIndex &parent) const;
88
89private:
90 DomainModelPrivate* const d;
91 friend struct DomainModelPrivate;
92
93};
94
95}
96
97#endif
98