Proof-reading - fixed one usage of the i18n plural form (it wasn't doing before,...
[kdeadmin.git] / kuser / ku_group.cpp
blobafc82610b6c7d711defdfa24e06087c9345d150c
1 /*
2 * Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
3 * Copyright (c) 2004 Szombathelyi GyĂśrgy <gyurco@freemail.hu>
4 * Former maintainer: Adriaan de Groot <groot@kde.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License version 2 as published by the Free Software Foundation.
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.
19 **/
21 #include <kdebug.h>
22 #include <QSharedData>
24 #include "ku_group.h"
27 KU_Group_Private::KU_Group_Private()
29 Pwd = QString::fromLatin1("*");
30 GID = 0;
31 Type = 2;
32 Caps = 0;
35 KU_Group::KU_Group()
37 d = new KU_Group_Private;
40 KU_Group::KU_Group(KU_Group *group)
42 d = new KU_Group_Private;
43 copy( group );
46 KU_Group::~KU_Group()
50 void KU_Group::copy( const KU_Group *group )
52 if ( group != this ) {
53 *this = *group;
57 bool KU_Group::operator ==(const KU_Group &other) const
59 if ( getGID() == other.getGID() &&
60 getName() == other.getName() )
61 return true;
62 else
63 return false;
66 KU_PROPERTY_IMPL(KU_Group,int, Caps)
68 KU_PROPERTY_IMPL(KU_Group,QString, Name)
69 KU_PROPERTY_IMPL(KU_Group,QString, Pwd)
70 KU_PROPERTY_IMPL(KU_Group,gid_t, GID )
72 //Samba
73 KU_PROPERTY_IMPL(KU_Group,SID, SID)
74 KU_PROPERTY_IMPL(KU_Group,int, Type)
75 KU_PROPERTY_IMPL(KU_Group,QString, DisplayName)
76 KU_PROPERTY_IMPL(KU_Group,QString, Desc)
78 bool KU_Group::lookup_user(const QString &name) const
80 return d->users.contains(name);
83 bool KU_Group::addUser(const QString &name)
85 if (!lookup_user(name)) {
86 d->users.append(name);
87 return true;
88 } else
89 return false;
92 bool KU_Group::removeUser(const QString &name)
94 return ( d->users.removeAll(name) > 0 );
97 uint KU_Group::count() const
99 return d->users.count();
102 QString KU_Group::user(uint i) const
104 return d->users[i];
107 void KU_Group::clear()
109 d->users.clear();
112 KU_Groups::KU_Groups(KU_PrefsBase *cfg)
114 mCfg = cfg;
117 int KU_Groups::lookup(const QString &name) const
119 for ( int i = 0; i<count(); i++ ) {
120 if ( at(i).getName() == name ) return i;
122 return -1;
125 int KU_Groups::lookup(gid_t gid) const
127 for ( int i = 0; i<count(); i++ ) {
128 if ( at(i).getGID() == gid ) return i;
130 return -1;
133 int KU_Groups::lookup_sam( const SID &sid ) const
135 for ( int i = 0; i<count(); i++ ) {
136 if ( at(i).getSID() == sid ) return i;
138 return -1;
141 int KU_Groups::lookup_sam( const QString &sid ) const
143 for ( int i = 0; i<count(); i++ ) {
144 if ( at(i).getSID().getSID() == sid ) return i;
146 return -1;
149 int KU_Groups::lookup_sam( uint rid ) const
151 for ( int i = 0; i<count(); i++ ) {
152 if ( at(i).getSID().getRID() == rid ) return i;
154 return -1;
157 gid_t KU_Groups::first_free() const
159 gid_t t;
161 for (t = mCfg->firstGID(); t<65534; t++)
162 if (lookup(t) == -1)
163 return t;
165 return NO_FREE;
168 uint KU_Groups::first_free_sam() const
170 uint t;
172 for (t = 30000; t<65534; t++)
173 if (lookup_sam(t) == -1)
174 return t;
176 return 0;
179 KU_Groups::~KU_Groups()
183 const QString &KU_Groups::getDOMSID() const
185 return domsid;
188 void KU_Groups::add(const KU_Group &group)
190 kDebug() << "adding group: " << group.getName() << " gid: " << group.getGID();
191 mAdd.append( group );
194 void KU_Groups::del(int index)
196 kDebug() << "deleting group: " << at(index).getName() << " gid: " << at(index).getGID();
197 mDel.append( index );
200 void KU_Groups::mod(int index, const KU_Group &newgroup)
202 kDebug() << "modify group " << newgroup.getName() << " gid: " << newgroup.getGID();
203 mMod.insert( index, newgroup );
206 void KU_Groups::commit()
208 kDebug() << "KU_Groups::commit()";
210 for ( ModList::Iterator it = mModSucc.begin(); it != mModSucc.end(); ++it ) {
211 replace(it.key(),*it);
213 for ( AddList::Iterator it = mAddSucc.begin(); it != mAddSucc.end(); ++it ) {
214 append(*it);
216 for ( DelList::Iterator it = mDelSucc.begin(); it != mDelSucc.end(); ++it ) {
217 removeAt(*it);
219 cancelMods();
222 void KU_Groups::cancelMods()
224 mAdd.clear();
225 mDel.clear();
226 mMod.clear();