fix static positioning of positioned inline replaced elements.
[kdelibs.git] / dnssd / servicemodel.h
blobdebb53c5fee6fb4e8d002efd82f0451ca469582c
1 /* This file is part of the KDE project
3 * Copyright (C) 2008 Jakub Stachowski <qbast@go2.pl>
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.
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.
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.
21 #ifndef DNSSDSERVICEMODEL_H
22 #define DNSSDSERVICEMODEL_H
24 #include <QtCore/QAbstractItemModel>
25 #include <dnssd/dnssd_export.h>
26 #include <dnssd/remoteservice.h>
28 namespace DNSSD
31 struct ServiceModelPrivate;
32 class ServiceBrowser;
35 /**
36 \class ServiceModel servicemodel.h DNSSD/ServiceModel
38 ServiceModel implements Qt Model interface around ServiceBrowser to allow easy integration
39 of service discovery into GUI.
40 Example of combo box showing list of HTTP servers on local network:
41 \code
42 DNSSD::ServiceModel* m=new ServiceModel(new DNSSD::ServiceBrowser("_http._tcp"));
43 QComboBox *c=new QComboBox();
44 c->setModel(m);
45 \endcode
47 After user makes the selection, application typically needs pointer to selected service
48 in order to get host name and port. RemoteService::Ptr can be obtained from QModelIndex
49 using:
50 \code
51 void onSelected(const QModelIndex& selection) {
52 DNSSD::RemoteService::Ptr service=selection.data(DNSSD::ServiceModel::ServicePtrRole).
53 value<DNSSD::RemoteService::Ptr>();
54 \endcode
56 \since 4.1
57 @short Model for list of Zeroconf services
58 @author Jakub Stachowski
61 class KDNSSD_EXPORT ServiceModel : public QAbstractItemModel
63 Q_OBJECT
65 public:
67 enum AdditionalRoles {
68 ServicePtrRole = 0xA06519DE ///< returns pointer to service (RemoteService::Ptr type)
71 /**
72 Default columns for this model. If service browser is not set to resolve automatically, then the model
73 has only one column (service name).
74 */
75 enum ModelColumns {
76 ServiceName = 0,
77 Host = 1,
78 Port = 2
81 /**
82 Creates model for given service browses and starts browsing for services. The model becomes parent of the
83 browser so there is no need to delete it afterwards.
85 explicit ServiceModel(ServiceBrowser* browser, QObject* parent=0);
86 virtual ~ServiceModel();
88 virtual int columnCount(const QModelIndex& parent = QModelIndex() ) const;
89 virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const;
90 virtual QModelIndex parent(const QModelIndex& index ) const;
91 virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex() ) const;
92 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const;
93 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
94 virtual bool hasIndex(int row, int column, const QModelIndex &parent) const;
97 private:
98 ServiceModelPrivate* const d;
99 friend struct ServiceModelPrivate;
105 #endif