2 * Copyright 2014 Sandro Knauß <knauss@kolabsys.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License or (at your option) version 3 or any later version
8 * accepted by the membership of KDE e.V. (or its successor approved
9 * by the membership of KDE e.V.), which shall act as a proxy
10 * defined in Section 14 of version 3 of the license.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "resourceitem.h"
23 #include <kldap/ldapserver.h>
25 using namespace IncidenceEditorNG
;
27 ResourceItem::ResourceItem(const KLDAP::LdapDN
&dn
, const QStringList
&attrs
, const KLDAP::LdapClient
&ldapClient
, const ResourceItem::Ptr
&parent
)
30 , mLdapClient(0, this)
34 KLDAP::LdapServer server
= ldapClient
.server();
36 server
.setScope(KLDAP::LdapUrl::Base
);
38 mLdapClient
.setServer(server
);
40 connect(&mLdapClient
, &KLDAP::LdapClient::result
, this, &ResourceItem::slotLDAPResult
);
42 mAttrs
<< QStringLiteral("uniqueMember");
43 mLdapClient
.setAttributes(attrs
);
45 foreach (const QString
&header
, mAttrs
) {
51 ResourceItem::~ResourceItem()
55 ResourceItem::Ptr
ResourceItem::child(int number
)
57 return childItems
.value(number
);
60 int ResourceItem::childCount() const
62 return childItems
.count();
65 int ResourceItem::childNumber() const
69 foreach (const ResourceItem::Ptr
&child
, parentItem
->childItems
) {
80 int ResourceItem::columnCount() const
82 return itemData
.count();
85 QVariant
ResourceItem::data(int column
) const
87 return itemData
.value(column
);
90 QVariant
ResourceItem::data(const QString
&column
) const
92 if (!mLdapObject
.attributes()[column
].isEmpty()) {
93 return QString::fromUtf8(mLdapObject
.attributes()[column
][0]);
98 bool ResourceItem::insertChild(int position
, const ResourceItem::Ptr
&item
)
100 if (position
< 0 || position
> childItems
.size()) {
104 childItems
.insert(position
, item
);
109 ResourceItem::Ptr
ResourceItem::parent()
114 bool ResourceItem::removeChildren(int position
, int count
)
116 if (position
< 0 || position
+ count
> childItems
.size()) {
120 for (int row
= 0; row
< count
; ++row
) {
121 childItems
.removeAt(position
);
127 const QStringList
&ResourceItem::attributes() const
132 const KLDAP::LdapObject
&ResourceItem::ldapObject() const
137 void ResourceItem::startSearch()
139 mLdapClient
.startQuery(QStringLiteral("objectclass=*"));
142 void ResourceItem::setLdapObject(const KLDAP::LdapObject
&obj
)
144 slotLDAPResult(mLdapClient
, obj
);
147 const KLDAP::LdapClient
&ResourceItem::ldapClient() const
152 void ResourceItem::slotLDAPResult(const KLDAP::LdapClient
&/*client*/,
153 const KLDAP::LdapObject
&obj
)
156 foreach (const QString
&header
, mAttrs
) {
157 if (!obj
.attributes()[header
].isEmpty()) {
158 itemData
<< QString::fromUtf8(obj
.attributes()[header
][0]);
163 emit
searchFinished();