• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

DNSSD

  • dnssd
servicemodel.cpp
Go to the documentation of this file.
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#include "servicemodel.h"
22#include "servicebrowser.h"
23#include <klocale.h>
24
25namespace DNSSD
26{
27
28struct ServiceModelPrivate
29{
30 ServiceBrowser* m_browser;
31};
32
33
34ServiceModel::ServiceModel(ServiceBrowser* browser, QObject* parent)
35 : QAbstractItemModel(parent), d(new ServiceModelPrivate)
36{
37 d->m_browser=browser;
38 browser->setParent(this);
39 connect(browser, SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)), this,
40 SIGNAL(layoutChanged()));
41 connect(browser, SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)), this,
42 SIGNAL(layoutChanged()));
43 browser->startBrowse();
44}
45
46ServiceModel::~ServiceModel()
47{
48 delete d;
49}
50
51int ServiceModel::columnCount(const QModelIndex&) const
52{
53 return d->m_browser->isAutoResolving() ? 3 : 1;
54}
55int ServiceModel::rowCount(const QModelIndex& parent ) const
56{
57 return (parent.isValid()) ? 0 : d->m_browser->services().size();
58}
59
60QModelIndex ServiceModel::parent(const QModelIndex&) const
61{
62 return QModelIndex();
63}
64
65QModelIndex ServiceModel::index(int row, int column, const QModelIndex& parent ) const
66{
67 return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
68}
69
70bool ServiceModel::hasIndex(int row, int column, const QModelIndex &parent) const
71{
72 if (parent.isValid()) return false;
73 if (column<0 || column>=columnCount()) return false;
74 if (row<0 || row>=rowCount(parent)) return false;
75 return true;
76}
77
78QVariant ServiceModel::data(const QModelIndex& index, int role ) const
79{
80 if (!index.isValid()) return QVariant();
81 if (!hasIndex(index.row(), index.column(), index.parent())) return QVariant();
82 const QList<RemoteService::Ptr> srv=d->m_browser->services();
83 switch (role) {
84 case Qt::DisplayRole:
85 switch (index.column()) {
86 case ServiceName: return srv[index.row()]->serviceName();
87 case Host: return srv[index.row()]->hostName();
88 case Port: return srv[index.row()]->port();
89 }
90 case int(ServicePtrRole): QVariant ret;
91 ret.setValue(srv[index.row()]);
92 return ret;
93 }
94 return QVariant();
95}
96
97QVariant ServiceModel::headerData(int section, Qt::Orientation orientation, int role) const
98{
99 if (orientation!=Qt::Horizontal || role!=Qt::DisplayRole) return QVariant();
100 switch (section) {
101 case ServiceName: return i18n("Name");
102 case Host: return i18n("Host");
103 case Port: return i18n("Port");
104 }
105 return QVariant();
106}
107
108}
DNSSD::ServiceBrowser
Browses for network services advertised over DNS-SD.
Definition: servicebrowser.h:65
DNSSD::ServiceBrowser::startBrowse
virtual void startBrowse()
Starts browsing for services.
Definition: dummy-servicebrowser.cpp:46
DNSSD::ServiceModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: servicemodel.cpp:78
DNSSD::ServiceModel::ServicePtrRole
@ ServicePtrRole
gets a RemoteService::Ptr for the service
Definition: servicemodel.h:74
DNSSD::ServiceModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: servicemodel.cpp:51
DNSSD::ServiceModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: servicemodel.cpp:55
DNSSD::ServiceModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: servicemodel.cpp:65
DNSSD::ServiceModel::ServiceModel
ServiceModel(ServiceBrowser *browser, QObject *parent=0)
Creates a model for the given service browser and starts browsing for services.
Definition: servicemodel.cpp:34
DNSSD::ServiceModel::~ServiceModel
virtual ~ServiceModel()
Definition: servicemodel.cpp:46
DNSSD::ServiceModel::Host
@ Host
Definition: servicemodel.h:85
DNSSD::ServiceModel::ServiceName
@ ServiceName
Definition: servicemodel.h:84
DNSSD::ServiceModel::Port
@ Port
Definition: servicemodel.h:86
DNSSD::ServiceModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: servicemodel.cpp:97
DNSSD::ServiceModel::parent
virtual QModelIndex parent(const QModelIndex &index) const
Definition: servicemodel.cpp:60
DNSSD::ServiceModel::hasIndex
virtual bool hasIndex(int row, int column, const QModelIndex &parent) const
Definition: servicemodel.cpp:70
KSharedPtr
QAbstractItemModel
QList
QObject
klocale.h
i18n
QString i18n(const char *text)
DNSSD
Definition: domainbrowser.h:29
servicebrowser.h
servicemodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

DNSSD

Skip menu "DNSSD"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal