-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ku_usermodel.cpp
173 lines (153 loc) · 5.33 KB
/
ku_usermodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright (c) 2006 Szombathelyi György <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
**/
#include <KColorScheme>
#include <klocale.h>
#include "ku_global.h"
#include "ku_usermodel.h"
int KU_UserModel::rowCount( const QModelIndex & parent ) const
{
Q_UNUSED(parent)
return KU_Global::users()->count();
}
int KU_UserModel::columnCount( const QModelIndex & parent ) const
{
Q_UNUSED(parent)
if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba )
return 11;
else
return 5;
}
QVariant KU_UserModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
Q_UNUSED(orientation)
if ( role != Qt::DisplayRole ) return QVariant();
switch ( section ) {
case 0: return(i18n("UID"));
case 1: return(i18n("User Login"));
case 2: return(i18n("Full Name"));
case 3: return(i18n("Home Directory"));
case 4: return(i18n("Login Shell"));
case 5: return(i18n("Domain SID"));
case 6: return(i18n("RID"));
case 7: return(i18n("Samba Login Script"));
case 8: return(i18n("Samba Profile Path"));
case 9: return(i18n("Samba Home Drive"));
case 10: return(i18n("Samba Home Path"));
default: return QVariant();
}
}
QVariant KU_UserModel::data( const QModelIndex & index, int role ) const
{
if ( !index.isValid() ) return QVariant();
KU_User user = KU_Global::users()->at( index.row() );
switch( role ) {
case Qt::DisplayRole:
switch( index.column() ) {
case 0: return user.getCaps() & KU_User::Cap_POSIX ?
QString::number( user.getUID() ) : QString();
case 1: return user.getName();
case 2: return user.getFullName();
case 3: return user.getHomeDir();
case 4: return user.getShell();
case 5: return user.getSID().getDOM();
case 6: return user.getCaps() & KU_User::Cap_Samba ?
QString::number( user.getSID().getRID() ) : QString();
case 7: return user.getLoginScript();
case 8: return user.getProfilePath();
case 9: return user.getHomeDrive();
case 10: return user.getHomePath();
default: return QVariant();
}
case Qt::TextColorRole:
if ( user.getDisabled() ) return KColorScheme( QPalette::Active, KColorScheme::View ).foreground( KColorScheme::VisitedText );
}
return QVariant();
}
void KU_UserModel::commitDel()
{
//Must do the deleting from the bigger indexes to the smaller ones
qSort( KU_Global::users()->mDelSucc );
for ( int i = KU_Global::users()->mDelSucc.count()-1; i >= 0; i-- ) {
removeRows(KU_Global::users()->mDelSucc.at(i), 1);
}
KU_Global::users()->mDelSucc.clear();
}
void KU_UserModel::commitAdd()
{
if ( !KU_Global::users()->mAddSucc.isEmpty() ) {
insertRows( rowCount(), KU_Global::users()->mAddSucc.count() );
KU_Global::users()->mAddSucc.clear();
}
}
void KU_UserModel::commitMod()
{
for ( KU_Users::ModList::Iterator it = KU_Global::users()->mModSucc.begin();
it != KU_Global::users()->mModSucc.end(); ++it ) {
KU_Global::users()->replace(it.key(),*it);
for( int i = 0; i<columnCount(); i++ ) {
QModelIndex idx = index( it.key(), i );
setData( idx, data(idx, Qt::DisplayRole), Qt::DisplayRole );
}
}
KU_Global::users()->mModSucc.clear();
}
bool KU_UserModel::setData( const QModelIndex & index, const QVariant & value, int role )
{
Q_UNUSED(value)
Q_UNUSED(role)
emit dataChanged( index, index );
return true;
}
bool KU_UserModel::insertRows( int row, int count, const QModelIndex & parent )
{
beginInsertRows( parent, row, row+count-1 );
for ( KU_Users::AddList::Iterator it = KU_Global::users()->mAddSucc.begin();
it != KU_Global::users()->mAddSucc.end(); ++it ) {
KU_Global::users()->append(*it);
}
endInsertRows();
return true;
}
bool KU_UserModel::removeRows( int row, int count, const QModelIndex & parent )
{
beginRemoveRows( parent, row, row+count-1 );
KU_Global::users()->removeAt( row );
endRemoveRows();
return true;
}
bool KU_UserSortingProxyModel::lessThan( const QModelIndex & left, const QModelIndex & right ) const
{
if ( !left.isValid() || !right.isValid() ) return false;
if ( left.column() == 0 ) {
uid_t uid1, uid2;
uid1 = KU_Global::users()->at( left.row() ).getUID();
uid2 = KU_Global::users()->at( right.row() ).getUID();
return uid1<uid2;
} else
return QSortFilterProxyModel::lessThan( left, right );
}
bool KU_UserSortingProxyModel::filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const
{
Q_UNUSED(source_parent)
uid_t uid;
uid = KU_Global::users()->at( source_row ).getUID();
if ( uid >= mFirstUser )
return true;
return false;
}