diff options
| author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2025-09-30 16:55:23 -0500 |
|---|---|---|
| committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2025-10-05 17:07:05 -0500 |
| commit | 15de3774dcbcdc2913a5e334a47bc169e877902e (patch) | |
| tree | 1875da20c3b8d73c6995aff40f36c8de3fd4837d /src/userconfigdlg.cpp | |
| parent | 270b1b4accb42c6345b5544f0cae32ac3c1aa67b (diff) | |
| download | kcmldapmanager-15de3774dcbcdc2913a5e334a47bc169e877902e.tar.gz kcmldapmanager-15de3774dcbcdc2913a5e334a47bc169e877902e.zip | |
Add ability to set user profile avatars
Signed-off-by: Timothy Pearson <kb9vqf@pearsoncomputing.net>
Diffstat (limited to 'src/userconfigdlg.cpp')
| -rw-r--r-- | src/userconfigdlg.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/userconfigdlg.cpp b/src/userconfigdlg.cpp index 32fad5f..b731f13 100644 --- a/src/userconfigdlg.cpp +++ b/src/userconfigdlg.cpp @@ -41,10 +41,12 @@ #include <kdatetimewidget.h> #include <kpassdlg.h> #include <kiconloader.h> +#include <kmdcodec.h> #include <ksslcertificate.h> #include "ldapmgr.h" #include "userconfigdlg.h" +#include "chfacedlg.h" UserConfigDialog::UserConfigDialog(LDAPUserInfo user, LDAPConfig* parent, const char* name) : KDialogBase(parent, name, true, i18n("LDAP User Properties"), Ok|Cancel, Ok, true), m_user(user), m_ldapconfig(parent) @@ -77,6 +79,8 @@ UserConfigDialog::UserConfigDialog(LDAPUserInfo user, LDAPConfig* parent, const connect(m_base->passwordExpireDisabled, TQ_SIGNAL(clicked()), this, TQ_SLOT(processLockouts())); connect(m_base->requirePasswordAging, TQ_SIGNAL(clicked()), this, TQ_SLOT(processLockouts())); connect(m_base->requirePasswordMinAge, TQ_SIGNAL(clicked()), this, TQ_SLOT(processLockouts())); + connect(m_base->changeAvatar, TQ_SIGNAL(clicked()), this, TQ_SLOT(changeAvatar())); + connect(m_base->clearAvatar, TQ_SIGNAL(clicked()), this, TQ_SLOT(clearAvatar())); connect(m_base->primaryGroup, TQ_SIGNAL(activated(const TQString&)), this, TQ_SLOT(processLockouts())); connect(m_base->certGenPrivateKey, TQ_SIGNAL(clicked()), this, TQ_SLOT(processLockouts())); connect(m_base->certPrivateKeyFileName, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(processLockouts())); @@ -145,6 +149,14 @@ UserConfigDialog::UserConfigDialog(LDAPUserInfo user, LDAPConfig* parent, const m_base->telephoneNumber->setText(m_user.telephoneNumber); m_base->faxNumber->setText(m_user.faxNumber); m_base->email->setText(m_user.email); + if (!m_user.profileAvatar.isNull()) { + TQPixmap pixmapAvatar; + pixmapAvatar.loadFromData(m_user.profileAvatar); + if (!pixmapAvatar.isNull()) { + m_profileAvatar = pixmapAvatar; + m_base->changeAvatar->setPixmap(m_profileAvatar); + } + } // Certificate generation information TQDateTime suggestedExpiration = TQDateTime::currentDateTime().addDays(KERBEROS_PKI_KRB_EXPIRY_DAYS); @@ -322,6 +334,52 @@ void UserConfigDialog::processLockouts() { m_prevPrimaryGroup = m_base->primaryGroup->currentText(); } +void UserConfigDialog::setNewAvatar(const TQPixmap &pix) { + if (pix.isNull()) { + KMessageBox::sorry(this, i18n("There was an error loading the image.")); + return; + } + + TQByteArray rawImage; + TQBuffer imageBuffer(rawImage); + imageBuffer.open(IO_WriteOnly); + // NOTE: + // While the LDAP attribute technically specifies JPEG, in practice compatibility has improved to include PNG + // with later versions of Microsoft software (e.g., the thumbnailPhoto aliased attribute) + // JPEG does not store alpha channel information, which causes ugly graphical artifacts + // Use PNG, even though it is in technical violation of the LDAP standards, for an improved user experience + if (!pix.save(&imageBuffer, "PNG")) { + KMessageBox::sorry(this, i18n("There was an error preparing the image.")); + } + imageBuffer.close(); + m_user.profileAvatar = rawImage; + + m_profileAvatar = pix; + m_base->changeAvatar->setPixmap(m_profileAvatar); +} + +void UserConfigDialog::changeAvatar() { + ChFaceDlg* avatarPickerDialog = new ChFaceDlg( TDEGlobal::dirs()->resourceDirs("data").last() + "/tdm/pics/users/" ); + + if (avatarPickerDialog->exec() == TQDialog::Accepted && !avatarPickerDialog->getFaceImage().isNull()) { + setNewAvatar(avatarPickerDialog->getFaceImage()); + } + + delete avatarPickerDialog; + + processLockouts(); +} + +void UserConfigDialog::clearAvatar() { + TQPixmap nullPixmap; + + m_user.profileAvatar = TQByteArray(); + m_profileAvatar = nullPixmap; + m_base->changeAvatar->setPixmap(m_profileAvatar); + + processLockouts(); +} + void UserConfigDialog::createPKICertificate() { int ret; TQString errorstring; |
