KUser Class

Represents a user on your system. More...

Header: #include <KUser>
CMake: find_package(KF6 REQUIRED COMPONENTS CoreAddons)
target_link_libraries(mytarget PRIVATE KF6::CoreAddons)

Public Types

enum UIDMode { UseEffectiveUID, UseRealUserID }

Public Functions

KUser(KUser::UIDMode mode = UseEffectiveUID)
KUser(KUserId uid)
KUser(K_UID uid)
KUser(const QString &name)
KUser(const char *name)
KUser(const passwd *p)
KUser(const KUser &user)
QString faceIconPath() const
KGroupId groupId() const
QStringList groupNames(uint maxCount = KCOREADDONS_UINT_MAX) const
QList<KUserGroup> groups(uint maxCount = KCOREADDONS_UINT_MAX) const
QString homeDir() const
bool isSuperUser() const
bool isValid() const
QString loginName() const
QVariant property(KUser::UserProperty which) const
QString shell() const
KUserId userId() const
bool operator!=(const KUser &user) const
KUser &operator=(const KUser &user)
bool operator==(const KUser &user) const

Static Public Members

QStringList allUserNames(uint maxCount = KCOREADDONS_UINT_MAX)
QList<KUser> allUsers(uint maxCount = KCOREADDONS_UINT_MAX)

Detailed Description

This class represents a user on your system. You can either get information about the current user, or fetch information about a user on the system. Instances of this class will be explicitly shared, so copying objects is very cheap and you can safely pass objects by value.

Member Type Documentation

enum KUser::UIDMode

ConstantValueDescription
KUser::UseEffectiveUID0Use the effective user id
KUser::UseRealUserID1Use the real user id

Member Function Documentation

[explicit] KUser::KUser(KUser::UIDMode mode = UseEffectiveUID)

Creates an object that contains information about the current user. (as returned by getuid(2) or geteuid(2), taking $LOGNAME/$USER into account).

mode if #UseEffectiveUID is passed the effective user is returned. If #UseRealUserID is passed the real user will be returned. The real UID will be different than the effective UID in setuid programs; in such a case use the effective UID for checking permissions, and the real UID for displaying information about the user.

[explicit] KUser::KUser(KUserId uid)

Creates an object for the user with the given user id. If the KUserId object is invalid this one will be, too.

uid the user id

[explicit] KUser::KUser(K_UID uid)

Creates an object for the user with the given user id. If the user does not exist isValid() will return false.

uid the user id

[explicit] KUser::KUser(const QString &name)

Creates an object that contains information about the user with the given name. If the user does not exist isValid() will return false.

name the name of the user

[explicit] KUser::KUser(const char *name)

Creates an object that contains information about the user with the given name. If the user does not exist isValid() will return false.

name the name of the user

[explicit] KUser::KUser(const passwd *p)

Creates an object from a passwd structure. If the pointer is null isValid() will return false.

p the passwd structure to create the user from

KUser::KUser(const KUser &user)

Creates an object from another KUser object

user the user to create the new object from

[static] QStringList KUser::allUserNames(uint maxCount = KCOREADDONS_UINT_MAX)

maxCount the maximum number of users to return

Returns all user names of the system.

[static] QList<KUser> KUser::allUsers(uint maxCount = KCOREADDONS_UINT_MAX)

maxCount the maximum number of users to return

Returns all users of the system.

QString KUser::faceIconPath() const

The path to the user's face file. Returns the path to the user's face file or QString() if no face has been set

KGroupId KUser::groupId() const

Returns the native user id of the user.

QStringList KUser::groupNames(uint maxCount = KCOREADDONS_UINT_MAX) const

maxCount the maximum number of groups to return

Returns all group names of the user

QList<KUserGroup> KUser::groups(uint maxCount = KCOREADDONS_UINT_MAX) const

maxCount the maximum number of groups to return

Returns all groups of the user

QString KUser::homeDir() const

The path to the user's home directory. Returns the home directory of the user or QString() if the user is invalid

bool KUser::isSuperUser() const

Checks whether the user is the super user (root). Returns true if the user is root

bool KUser::isValid() const

Returns true if the user is valid. A KUser object can be invalid if you created it with an non-existing uid or name. Returns true if the user is valid

QString KUser::loginName() const

The login name of the user. Returns the login name of the user or QString() if user is invalid

QVariant KUser::property(KUser::UserProperty which) const

Returns an extended property given by which.

Under Windows, RoomNumber, WorkPhone and HomePhone are unsupported.

Returns a QVariant with the value of the property or an invalid QVariant, if the property is not set

QString KUser::shell() const

The path to the user's login shell. Returns the login shell of the user or QString() if the user is invalid

KUserId KUser::userId() const

Returns the native user id of the user.

bool KUser::operator!=(const KUser &user) const

Two KUser objects are not equal if userId() are not identical. Invalid users always compare unequal.

KUser &KUser::operator=(const KUser &user)

Copies a user

user the user to copy

Returns this object

bool KUser::operator==(const KUser &user) const

Two KUser objects are equal if the userId() are identical. Invalid users never compare equal.