KDECore
kuser.h
Go to the documentation of this file.00001 /* 00002 * KUser - represent a user/account 00003 * Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de> 00004 * Copyright (C) 2003 Oswald Buddenhagen <ossi@kde.org> 00005 * Copyright (C) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Library General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Library General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public License 00018 * along with this library; see the file COPYING.LIB. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 #ifndef KUSER_H 00023 #define KUSER_H 00024 00025 #include <kdecore_export.h> 00026 #include <ksharedptr.h> 00027 00028 #include <QtCore/QVariant> 00029 00030 class KUserGroup; 00031 class QString; 00032 class QStringList; 00033 template <class T> class QList; 00034 00035 #ifdef Q_OS_WIN 00036 typedef void *K_UID; 00037 typedef void *K_GID; 00038 #else 00039 #include <sys/types.h> 00040 typedef uid_t K_UID; 00041 typedef gid_t K_GID; 00042 struct passwd; 00043 struct group; 00044 #endif 00045 00046 00059 class KDECORE_EXPORT KUser { 00060 00061 public: 00062 00063 enum UIDMode { 00064 UseEffectiveUID, 00065 UseRealUserID 00066 }; 00067 00081 explicit KUser(UIDMode mode = UseEffectiveUID); 00082 00088 explicit KUser(K_UID uid); 00089 00096 explicit KUser(const QString& name); 00097 00104 explicit KUser(const char* name); 00105 00106 #ifndef Q_OS_WIN 00107 00113 explicit KUser(const passwd *p); 00114 #endif 00115 00120 KUser(const KUser & user); 00121 00127 KUser& operator =(const KUser& user); 00128 00133 bool operator ==(const KUser& user) const; 00134 00139 bool operator !=(const KUser &user) const; 00140 00146 bool isValid() const; 00147 00152 K_UID uid() const; 00153 00154 #ifndef Q_OS_WIN 00155 00159 K_GID gid() const; 00160 #endif 00161 00166 bool isSuperUser() const; 00167 00172 QString loginName() const; 00173 00179 KDE_DEPRECATED QString fullName() const; 00180 00186 QString homeDir() const; 00187 00193 QString faceIconPath() const; 00194 00200 QString shell() const; 00201 00206 QList<KUserGroup> groups() const; 00207 00212 QStringList groupNames() const; 00213 00214 enum UserProperty { FullName, RoomNumber, WorkPhone, HomePhone }; 00215 00224 QVariant property(UserProperty which) const; 00225 00229 ~KUser(); 00230 00235 static QList<KUser> allUsers(); 00236 00241 static QStringList allUserNames(); 00242 00243 private: 00244 class Private; 00245 KSharedPtr<Private> d; 00246 }; 00247 00260 class KDECORE_EXPORT KUserGroup { 00261 00262 public: 00263 00269 explicit KUserGroup(const QString& name); 00270 00276 explicit KUserGroup(const char *name); 00277 00278 #ifndef Q_OS_WIN 00279 00289 explicit KUserGroup(KUser::UIDMode mode = KUser::UseEffectiveUID); 00290 00296 explicit KUserGroup(K_GID gid); 00297 00303 explicit KUserGroup(const group *g); 00304 #endif 00305 00310 KUserGroup(const KUserGroup & group); 00311 00317 KUserGroup& operator =(const KUserGroup& group); 00318 00324 bool operator ==(const KUserGroup& group) const; 00325 00331 bool operator !=(const KUserGroup& group) const; 00332 00339 bool isValid() const; 00340 00341 #ifndef Q_OS_WIN 00342 00346 K_GID gid() const; 00347 #endif 00348 00353 QString name() const; 00354 00359 QList<KUser> users() const; 00360 00365 QStringList userNames() const; 00366 00370 ~KUserGroup(); 00371 00375 static QList<KUserGroup> allGroups(); 00376 00380 static QStringList allGroupNames(); 00381 00382 private: 00383 class Private; 00384 KSharedPtr<Private> d; 00385 }; 00386 00387 #endif