summaryrefslogtreecommitdiffstats
path: root/kuser/kuservw.cpp
blob: 8f769e550c1720a1cce8df6fdaa32b40d08dd86d (plain)
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
/*
 *  Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
 *  Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
 *  Former maintainer: Adriaan de Groot <groot@kde.org>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  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 "kglobal_.h"
#include "misc.h"

#include "kuservw.h"


KUserViewItem::KUserViewItem(KListView *tqparent, KU::KUser *aku)
 : KListViewItem(tqparent), mUser(aku)
{
}

int KUserViewItem::compare( TQListViewItem *i, int col, bool ascending ) const
{
  if ( col == 0 ) {
    uid_t uid1, uid2;

    uid1 = mUser->getUID();
    uid2 = ((KUserViewItem*) i)->mUser->getUID();

    if ( uid1 == uid2 ) return 0;
    return ( uid1 < uid2) ? -1: 1;
  } else {
    return TQListViewItem::compare( i, col, ascending );
  }
}

void KUserViewItem::paintCell( TQPainter *p, const TQColorGroup &cg,
                               int column, int width, int tqalignment )
{
    TQColorGroup _cg( cg );
    TQColor c = _cg.text();

    if ( mUser->getDisabled() )
        _cg.setColor( TQColorGroup::Text, KGlobalSettings::visitedLinkColor() );

    KListViewItem::paintCell( p, _cg, column, width, tqalignment );

    _cg.setColor( TQColorGroup::Text, c );
}

TQString KUserViewItem::text(int num) const
{
  switch(num)
  {
     case 0: return mUser->getCaps() & KU::KUser::Cap_POSIX ? 
      TQString::number( mUser->getUID() ) : TQString();
     case 1: return mUser->getName();
     case 2: return mUser->getFullName();
     case 3: return mUser->getHomeDir();
     case 4: return mUser->getShell();
     case 5: return mUser->getSID().getDOM();
     case 6: return mUser->getCaps() & KU::KUser::Cap_Samba ? 
      TQString::number( mUser->getSID().getRID() ) : TQString();
     case 7: return mUser->getLoginScript();
     case 8: return mUser->getProfilePath();
     case 9: return mUser->getHomeDrive();
     case 10: return mUser->getHomePath();
  }

  return TQString();
}

KUserView::KUserView(TQWidget *tqparent, const char *name)
  : KListView( tqparent, name )
{
  setSelectionMode( TQListView::Extended );
}

KUserView::~KUserView()
{
}

void KUserView::insertItem(KU::KUser *aku) {
  KUserViewItem *userItem = new KUserViewItem(this, aku);
  KListView::insertItem(userItem);
}

void KUserView::removeItem(KU::KUser *aku) {
  KUserViewItem *userItem = (KUserViewItem *)firstChild();

  while(userItem)
  {
     if (userItem->user() == aku)
     {
        delete userItem;
        return;
     }
     userItem = (KUserViewItem*) userItem->nextSibling();
  }
}

void KUserView::init()
{
  while ( columns() > 5 ) {
    removeColumn( 5 );
  }

  setAllColumnsShowFocus(true);
  if ( columns() < 5 ) {
    addColumn(i18n("UID"));
    setColumnAlignment(0, AlignRight);
    addColumn(i18n("User Login"));
    addColumn(i18n("Full Name"));
    addColumn(i18n("Home Directory"));
    addColumn(i18n("Login Shell"));
  }

  if ( kug->getUsers().getCaps() & KU::KUsers::Cap_Samba ) {
    addColumn(i18n("Domain SID"));
    addColumn(i18n("RID"));
    addColumn(i18n("Samba Login Script"));
    addColumn(i18n("Samba Profile Path"));
    addColumn(i18n("Samba Home Drive"));
    addColumn(i18n("Samba Home Path"));
  }
}

KU::KUser *KUserView::getCurrentUser() {
  KUserViewItem *userItem = (KUserViewItem *)currentItem();
  if (!userItem) return 0;

  return userItem->user();
}

#include "kuservw.moc"