2 * Copyright (c) 2006 Szombathelyi György <gyurco@freemail.hu>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <KColorScheme>
22 #include "ku_global.h"
23 #include "ku_usermodel.h"
25 int KU_UserModel::rowCount( const QModelIndex
& parent
) const
29 return KU_Global::users()->count();
32 int KU_UserModel::columnCount( const QModelIndex
& parent
) const
36 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
)
42 QVariant
KU_UserModel::headerData( int section
, Qt::Orientation orientation
, int role
) const
46 if ( role
!= Qt::DisplayRole
) return QVariant();
48 case 0: return(i18n("UID"));
49 case 1: return(i18n("User Login"));
50 case 2: return(i18n("Full Name"));
51 case 3: return(i18n("Home Directory"));
52 case 4: return(i18n("Login Shell"));
53 case 5: return(i18n("Domain SID"));
54 case 6: return(i18n("RID"));
55 case 7: return(i18n("Samba Login Script"));
56 case 8: return(i18n("Samba Profile Path"));
57 case 9: return(i18n("Samba Home Drive"));
58 case 10: return(i18n("Samba Home Path"));
59 default: return QVariant();
63 QVariant
KU_UserModel::data( const QModelIndex
& index
, int role
) const
65 if ( !index
.isValid() ) return QVariant();
66 KU_User user
= KU_Global::users()->at( index
.row() );
69 switch( index
.column() ) {
70 case 0: return user
.getCaps() & KU_User::Cap_POSIX
?
71 QString::number( user
.getUID() ) : QString();
72 case 1: return user
.getName();
73 case 2: return user
.getFullName();
74 case 3: return user
.getHomeDir();
75 case 4: return user
.getShell();
76 case 5: return user
.getSID().getDOM();
77 case 6: return user
.getCaps() & KU_User::Cap_Samba
?
78 QString::number( user
.getSID().getRID() ) : QString();
79 case 7: return user
.getLoginScript();
80 case 8: return user
.getProfilePath();
81 case 9: return user
.getHomeDrive();
82 case 10: return user
.getHomePath();
83 default: return QVariant();
85 case Qt::TextColorRole
:
86 if ( user
.getDisabled() ) return KColorScheme( QPalette::Active
, KColorScheme::View
).foreground( KColorScheme::VisitedText
);
91 void KU_UserModel::commitDel()
93 //Must do the deleting from the bigger indexes to the smaller ones
94 qSort( KU_Global::users()->mDelSucc
);
95 for ( int i
= KU_Global::users()->mDelSucc
.count()-1; i
>= 0; i
-- ) {
96 removeRows(KU_Global::users()->mDelSucc
.at(i
), 1);
98 KU_Global::users()->mDelSucc
.clear();
101 void KU_UserModel::commitAdd()
103 if ( !KU_Global::users()->mAddSucc
.isEmpty() ) {
104 insertRows( rowCount(), KU_Global::users()->mAddSucc
.count() );
105 KU_Global::users()->mAddSucc
.clear();
109 void KU_UserModel::commitMod()
111 for ( KU_Users::ModList::Iterator it
= KU_Global::users()->mModSucc
.begin();
112 it
!= KU_Global::users()->mModSucc
.end(); ++it
) {
114 KU_Global::users()->replace(it
.key(),*it
);
115 for( int i
= 0; i
<columnCount(); i
++ ) {
116 QModelIndex idx
= index( it
.key(), i
);
117 setData( idx
, data(idx
, Qt::DisplayRole
), Qt::DisplayRole
);
120 KU_Global::users()->mModSucc
.clear();
123 bool KU_UserModel::setData( const QModelIndex
& index
, const QVariant
& value
, int role
)
128 emit
dataChanged( index
, index
);
132 bool KU_UserModel::insertRows( int row
, int count
, const QModelIndex
& parent
)
134 beginInsertRows( parent
, row
, row
+count
-1 );
135 for ( KU_Users::AddList::Iterator it
= KU_Global::users()->mAddSucc
.begin();
136 it
!= KU_Global::users()->mAddSucc
.end(); ++it
) {
138 KU_Global::users()->append(*it
);
144 bool KU_UserModel::removeRows( int row
, int count
, const QModelIndex
& parent
)
146 beginRemoveRows( parent
, row
, row
+count
-1 );
147 KU_Global::users()->removeAt( row
);
152 bool KU_UserSortingProxyModel::lessThan( const QModelIndex
& left
, const QModelIndex
& right
) const
154 if ( !left
.isValid() || !right
.isValid() ) return false;
155 if ( left
.column() == 0 ) {
157 uid1
= KU_Global::users()->at( left
.row() ).getUID();
158 uid2
= KU_Global::users()->at( right
.row() ).getUID();
161 return QSortFilterProxyModel::lessThan( left
, right
);
164 bool KU_UserSortingProxyModel::filterAcceptsRow( int source_row
, const QModelIndex
& source_parent
) const
166 Q_UNUSED(source_parent
)
169 uid
= KU_Global::users()->at( source_row
).getUID();
170 if ( uid
>= mFirstUser
)