mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
kdecore: store KUser properties as a vector of QString
clever use of QVector<T> is clever Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
6ba957038d
commit
c22d136874
2 changed files with 25 additions and 19 deletions
|
@ -25,14 +25,13 @@
|
||||||
#include <kdecore_export.h>
|
#include <kdecore_export.h>
|
||||||
#include <ksharedptr.h>
|
#include <ksharedptr.h>
|
||||||
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
|
|
||||||
class KUserGroup;
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
class KUserGroup;
|
||||||
typedef uid_t K_UID;
|
typedef uid_t K_UID;
|
||||||
typedef gid_t K_GID;
|
typedef gid_t K_GID;
|
||||||
struct passwd;
|
struct passwd;
|
||||||
|
@ -195,17 +194,20 @@ public:
|
||||||
*/
|
*/
|
||||||
QStringList groupNames() const;
|
QStringList groupNames() const;
|
||||||
|
|
||||||
enum UserProperty { FullName, RoomNumber, WorkPhone, HomePhone };
|
enum UserProperty {
|
||||||
|
FullName = 0,
|
||||||
|
RoomNumber = 1,
|
||||||
|
WorkPhone = 2,
|
||||||
|
HomePhone = 3
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an extended property.
|
* Returns an extended property.
|
||||||
*
|
*
|
||||||
* Under Windows, @p RoomNumber, @p WorkPhone and @p HomePhone are unsupported.
|
* @return a QString with the value of the property or an empty QString,
|
||||||
*
|
|
||||||
* @return a QVariant with the value of the property or an invalid QVariant,
|
|
||||||
* if the property is not set
|
* if the property is not set
|
||||||
*/
|
*/
|
||||||
QVariant property(UserProperty which) const;
|
QString property(UserProperty which) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
|
|
||||||
#include <kuser.h>
|
#include <kuser.h>
|
||||||
|
|
||||||
#include <QtCore/qstringlist.h>
|
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QVector>
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
QString loginName;
|
QString loginName;
|
||||||
QString homeDir, shell;
|
QString homeDir, shell;
|
||||||
QMap<UserProperty, QVariant> properties;
|
QVector<QString> properties;
|
||||||
|
|
||||||
Private() : uid(uid_t(-1)), gid(gid_t(-1)) {}
|
Private() : uid(uid_t(-1)), gid(gid_t(-1)) {}
|
||||||
Private(const char *name) : uid(uid_t(-1)), gid(gid_t(-1))
|
Private(const char *name) : uid(uid_t(-1)), gid(gid_t(-1))
|
||||||
|
@ -61,10 +61,11 @@ public:
|
||||||
uid = p->pw_uid;
|
uid = p->pw_uid;
|
||||||
gid = p->pw_gid;
|
gid = p->pw_gid;
|
||||||
loginName = QString::fromLocal8Bit(p->pw_name);
|
loginName = QString::fromLocal8Bit(p->pw_name);
|
||||||
properties[KUser::FullName] = QVariant(gecosList[0]);
|
properties.resize(4);
|
||||||
properties[KUser::RoomNumber] = QVariant(gecosList[1]);
|
properties[static_cast<int>(KUser::FullName)] = gecosList[0];
|
||||||
properties[KUser::WorkPhone] = QVariant(gecosList[2]);
|
properties[static_cast<int>(KUser::RoomNumber)] = gecosList[1];
|
||||||
properties[KUser::HomePhone] = QVariant(gecosList[3]);
|
properties[static_cast<int>(KUser::WorkPhone)] = gecosList[2];
|
||||||
|
properties[static_cast<int>(KUser::HomePhone)] = gecosList[3];
|
||||||
homeDir = QString::fromLocal8Bit(p->pw_dir);
|
homeDir = QString::fromLocal8Bit(p->pw_dir);
|
||||||
shell = QString::fromLocal8Bit(p->pw_shell);
|
shell = QString::fromLocal8Bit(p->pw_shell);
|
||||||
}
|
}
|
||||||
|
@ -203,9 +204,9 @@ QStringList KUser::groupNames() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant KUser::property(UserProperty which) const
|
QString KUser::property(UserProperty which) const
|
||||||
{
|
{
|
||||||
return d->properties.value(which);
|
return d->properties[static_cast<int>(which)];
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<KUser> KUser::allUsers()
|
QList<KUser> KUser::allUsers()
|
||||||
|
@ -314,15 +315,18 @@ bool KUserGroup::operator !=(const KUserGroup& user) const
|
||||||
return (gid() != user.gid()) || (gid() == gid_t(-1));
|
return (gid() != user.gid()) || (gid() == gid_t(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KUserGroup::isValid() const {
|
bool KUserGroup::isValid() const
|
||||||
|
{
|
||||||
return gid() != gid_t(-1);
|
return gid() != gid_t(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
K_GID KUserGroup::gid() const {
|
K_GID KUserGroup::gid() const
|
||||||
|
{
|
||||||
return d->gid;
|
return d->gid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString KUserGroup::name() const {
|
QString KUserGroup::name() const
|
||||||
|
{
|
||||||
return d->name;
|
return d->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue