fix static positioning of positioned inline replaced elements.
[kdelibs.git] / dnssd / servicemodel.cpp
blob38f0e5dfaa272331be1e0966ab91ae9a5e76d22d
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 #include "servicemodel.h"
22 #include "servicebrowser.h"
23 #include <klocale.h>
25 namespace DNSSD
28 struct ServiceModelPrivate
30 ServiceBrowser* m_browser;
34 ServiceModel::ServiceModel(ServiceBrowser* browser, QObject* parent)
35 : QAbstractItemModel(parent), d(new ServiceModelPrivate)
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();
46 ServiceModel::~ServiceModel()
48 delete d;
51 int ServiceModel::columnCount(const QModelIndex&) const
53 return d->m_browser->isAutoResolving() ? 3 : 1;
55 int ServiceModel::rowCount(const QModelIndex& parent ) const
57 return (parent.isValid()) ? 0 : d->m_browser->services().size();
60 QModelIndex ServiceModel::parent(const QModelIndex&) const
62 return QModelIndex();
65 QModelIndex ServiceModel::index(int row, int column, const QModelIndex& parent ) const
67 return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
70 bool ServiceModel::hasIndex(int row, int column, const QModelIndex &parent) const
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;
78 QVariant ServiceModel::data(const QModelIndex& index, int role ) const
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();
90 case ServicePtrRole: QVariant ret;
91 ret.setValue(srv[index.row()]);
92 return ret;
94 return QVariant();
97 QVariant ServiceModel::headerData(int section, Qt::Orientation orientation, int role) const
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");
105 return QVariant();