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

DNSSD

  • sources
  • kde-4.14
  • kdelibs
  • 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 
25 namespace DNSSD
26 {
27 
28 struct ServiceModelPrivate
29 {
30  ServiceBrowser* m_browser;
31 };
32 
33 
34 ServiceModel::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 
46 ServiceModel::~ServiceModel()
47 {
48  delete d;
49 }
50 
51 int ServiceModel::columnCount(const QModelIndex&) const
52 {
53  return d->m_browser->isAutoResolving() ? 3 : 1;
54 }
55 int ServiceModel::rowCount(const QModelIndex& parent ) const
56 {
57  return (parent.isValid()) ? 0 : d->m_browser->services().size();
58 }
59 
60 QModelIndex ServiceModel::parent(const QModelIndex&) const
61 {
62  return QModelIndex();
63 }
64 
65 QModelIndex ServiceModel::index(int row, int column, const QModelIndex& parent ) const
66 {
67  return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
68 }
69 
70 bool 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 
78 QVariant 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 ServicePtrRole: QVariant ret;
91  ret.setValue(srv[index.row()]);
92  return ret;
93  }
94  return QVariant();
95 }
96 
97 QVariant 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 }
i18n
QString i18n(const char *text)
QModelIndex
DNSSD::ServiceModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: servicemodel.cpp:55
KSharedPtr
DNSSD::ServiceModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: servicemodel.cpp:78
QAbstractItemModel::layoutChanged
void layoutChanged()
DNSSD::ServiceModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: servicemodel.cpp:97
servicebrowser.h
DNSSD::ServiceModel::hasIndex
virtual bool hasIndex(int row, int column, const QModelIndex &parent) const
Definition: servicemodel.cpp:70
klocale.h
DNSSD::ServiceBrowser::startBrowse
virtual void startBrowse()
Starts browsing for services.
Definition: dummy-servicebrowser.cpp:46
DNSSD::ServiceBrowser
Browses for network services advertised over DNS-SD.
Definition: servicebrowser.h:64
QModelIndex::isValid
bool isValid() const
DNSSD::ServiceModel::Port
Definition: servicemodel.h:86
DNSSD::ServiceModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: servicemodel.cpp:65
DNSSD::ServiceModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: servicemodel.cpp:51
QObject
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
QModelIndex::row
int row() const
QList
QModelIndex::parent
QModelIndex parent() const
QAbstractItemModel::createIndex
QModelIndex createIndex(int row, int column, void *ptr) const
DNSSD::ServiceModel::ServicePtrRole
gets a RemoteService::Ptr for the service
Definition: servicemodel.h:74
QObject::setParent
void setParent(QObject *parent)
QVariant::setValue
void setValue(const T &value)
DNSSD::ServiceModel::~ServiceModel
virtual ~ServiceModel()
Definition: servicemodel.cpp:46
QModelIndex::column
int column() const
QAbstractItemModel
DNSSD::ServiceModel::Host
Definition: servicemodel.h:85
DNSSD::ServiceModel::ServiceName
Definition: servicemodel.h:84
servicemodel.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:22 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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