The new useraccount KCM. Work in progress.

svn path=/trunk/kdebase/kdepasswd/; revision=292833
This commit is contained in:
Frans Englich 2004-03-01 14:38:03 +00:00
parent 615e83791d
commit 15d6293391
45 changed files with 1265 additions and 0 deletions

20
kdepasswd/kcm/Makefile.am Normal file
View file

@ -0,0 +1,20 @@
SUBDIRS = pics
kde_module_LTLIBRARIES = kcm_useraccount.la
kcm_useraccount_la_SOURCES = main_widget.ui chfnprocess.cpp \
main.cpp chfacedlg.cpp settings.kcfgc pass.kcfgc
kcm_useraccount_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined
kcm_useraccount_la_LIBADD = $(LIB_KDEUI) $(LIB_KIO) -lkonq
AM_CPPFLAGS = $(all_includes)
kde_kcfg_DATA = kcm_useraccount.kcfg kcm_useraccount_pass.kcfg
METASOURCES = AUTO
noinst_HEADERS = main.h chfnprocess.h chfacedlg.h
xdg_apps_DATA = kcm_useraccount.desktop
messages: rc.cpp
$(XGETTEXT) *.cpp $(podir)/useraccount.pot

23
kdepasswd/kcm/README Normal file
View file

@ -0,0 +1,23 @@
Thu Jan 29 00:34:49 CET 2004
Frans Englich <frans.englich@telia.com>
KCM useraccount is a merge of the former kdebase/kcontrol/email
and kdeutils/kdepasswd/userinfo/. They existed in KDE 3.1, at least.
As a bonus, on top of saving the stuff with KEMailSettings it tries
also to save the realname to /etc/passwd. This is done via chfn, wrapped
in ChfnProcess, chfnprocess.h - which is the place to ifdef/modify so
other systems/ychfn/whatever works.
/etc/passwd is not the primary goal, the focus is on KDE's settings. The KCM
tries to hide the implementation differences and play nice with the
user - keep that in mind.
The "face" term is rather scary.. For example I don't think the user immediately
associate to the login image when a phrase such as this is thrown in the face:
"Your administrator has disallowed changing your face". Keep it in mind..
Some information which was available in userinfo is left out - the home
folder and shell info. A typical user is not interested in the info nor
knows what it means. And the advanced users already knows it.

188
kdepasswd/kcm/chfacedlg.cpp Normal file
View file

@ -0,0 +1,188 @@
/**
* Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca>
* Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*
*
* Please see the README
*
*/
/**
* @file UserInfo's Dialog for changing your face.
* @author Braden MacDonald
*/
#include <qstring.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qpushbutton.h>
#include <qdir.h>
#include <qcheckbox.h>
#include <kdialogbase.h>
#include <klocale.h>
#include <kfiledialog.h>
#include <kiconview.h>
#include <kimagefilepreview.h>
#include <kimageio.h>
#include <kmessagebox.h>
#include <konq_operations.h>
#include <kurl.h>
#include "chfacedlg.h"
#include "settings.h" // KConfigXT
/**
* TODO: It would be nice if the widget were in a .ui
*/
ChFaceDlg::ChFaceDlg(const QString& picsdir, QWidget *parent, const char *name, bool modal)
: KDialogBase( parent, name, modal, i18n("Change your Face"), Ok|Cancel, Ok, true )
{
QWidget *page = new QWidget(this);
setMainWidget( page );
QVBoxLayout *top = new QVBoxLayout(page, 0, spacingHint());
QLabel *header = new QLabel( i18n("Select a new face:"), page );
top->addWidget( header );
m_FacesWidget = new KIconView( page );
m_FacesWidget->setSelectionMode( QIconView::Single );
m_FacesWidget->setItemsMovable( false );
m_FacesWidget->setMinimumSize( 400, 200 );
connect( m_FacesWidget, SIGNAL( selectionChanged( QIconViewItem * ) ), SLOT( slotFaceWidgetSelectionChanged( QIconViewItem * ) ) );
connect( m_FacesWidget, SIGNAL( doubleClicked( QIconViewItem *, const QPoint & ) ), SLOT( slotOk() ) );
top->addWidget( m_FacesWidget );
// Buttons to get more pics
QHBoxLayout * morePics = new QHBoxLayout( 0, 0, spacingHint() );
QPushButton *browseBtn = new QPushButton( i18n("Custom &Image..."), page );
connect( browseBtn, SIGNAL( clicked() ), SLOT( slotGetCustomImage() ) );
morePics->addWidget( browseBtn );
#if 0
QPushButton *acquireBtn = new QPushButton( i18n("&Acquire Image..."), page );
acquireBtn->setEnabled( false );
morePics->addWidget( acquireBtn );
#endif
morePics->addStretch();
top->addLayout( morePics );
// Filling the icon view
QDir facesDir( picsdir );
if ( facesDir.exists() )
{
QStringList picslist = facesDir.entryList( QDir::Files );
for ( QStringList::Iterator it = picslist.begin(); it != picslist.end(); ++it )
new QIconViewItem( m_FacesWidget, (*it).section(".",0,0), QPixmap( picsdir + *it ) );
}
facesDir.setPath( KCFGUserAccount::userFaceDir() );
if ( facesDir.exists() )
{
QStringList picslist = facesDir.entryList( QDir::Files );
for ( QStringList::Iterator it = picslist.begin(); it != picslist.end(); ++it )
new QIconViewItem( m_FacesWidget, "/"+(*it) == KCFGUserAccount::customFaceFile() ?
i18n("(Custom)") : (*it).section(".",0,0),
QPixmap( KCFGUserAccount::userFaceDir() + *it ) );
}
m_FacesWidget->setResizeMode( QIconView::Adjust );
//m_FacesWidget->setGridX( FACE_PIX_SIZE - 10 );
m_FacesWidget->arrangeItemsInGrid();
enableButtonOK( false );
//connect( this, SIGNAL( okClicked() ), SLOT( slotSaveCustomImage() ) );
resize( 420, 400 );
}
void ChFaceDlg::addCustomPixmap( QString imPath, bool saveCopy )
{
QImage pix( imPath );
// TODO: save pix to TMPDIR/userinfo-tmp,
// then scale and copy *that* to ~/.faces
if (pix.isNull())
{
KMessageBox::sorry( this, i18n("There was an error loading the image.") );
return;
}
if ( (pix.width() > KCFGUserAccount::faceSize())
|| (pix.height() > KCFGUserAccount::faceSize()) )
pix = pix.scale( KCFGUserAccount::faceSize(), KCFGUserAccount::faceSize(), QImage::ScaleMin );// Should be no bigger than certain size.
if ( saveCopy )
{
// If we should save a copy:
QDir userfaces( KCFGUserAccount::userFaceDir() );
if ( !userfaces.exists( ) )
userfaces.mkdir( userfaces.absPath() );
pix.save( userfaces.absPath() + "/.userinfo-tmp" , "PNG" );
KonqOperations::copy( this, KonqOperations::COPY, KURL::List( KURL( userfaces.absPath() + "/.userinfo-tmp" ) ), KURL( userfaces.absPath() + "/" + QFileInfo(imPath).fileName().section(".",0,0) ) );
#if 0
if ( !pix.save( userfaces.absPath() + "/" + imPath , "PNG" ) )
KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1").arg( userfaces.absPath() ) );
#endif
}
QIconViewItem* newface = new QIconViewItem( m_FacesWidget, QFileInfo(imPath).fileName().section(".",0,0) , pix );
newface->setKey( KCFGUserAccount::customKey() );// Add custom items to end
m_FacesWidget->ensureItemVisible( newface );
m_FacesWidget->setCurrentItem( newface );
}
void ChFaceDlg::slotGetCustomImage( )
{
QCheckBox* checkWidget = new QCheckBox( i18n("&Save copy in custom faces folder for future use"), 0 );
KFileDialog *dlg = new KFileDialog( QDir::homeDirPath(), KImageIO::pattern( KImageIO::Reading ),
this, 0, true, checkWidget);
dlg->setOperationMode( KFileDialog::Opening );
dlg->setCaption( i18n("Choose Image") );
dlg->setMode( KFile::File | KFile::LocalOnly );
KImageFilePreview *ip = new KImageFilePreview( dlg );
dlg->setPreviewWidget( ip );
if (dlg->exec() == QDialog::Accepted)
addCustomPixmap( dlg->selectedFile(), checkWidget->isChecked() );
// Because we give it a parent we have to close it ourselves.
dlg->close(true);
}
#if 0
void ChFaceDlg::slotSaveCustomImage()
{
if ( m_FacesWidget->currentItem()->key() == USER_CUSTOM_KEY)
{
QDir userfaces( QDir::homeDirPath() + USER_FACES_DIR );
if ( !userfaces.exists( ) )
userfaces.mkdir( userfaces.absPath() );
if ( !m_FacesWidget->currentItem()->pixmap()->save( userfaces.absPath() + USER_CUSTOM_FILE , "PNG" ) )
KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1").arg( userfaces.absPath() ) );
}
}
#endif
#include "chfacedlg.moc"

69
kdepasswd/kcm/chfacedlg.h Normal file
View file

@ -0,0 +1,69 @@
/**
* Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca>
* Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*
*
* Please see the README
*
*/
/**
* @file UserInfo-chface: Dialog for choosing a new face for your user.
* @author Braden MacDonald
*/
#ifndef CHFACEDLG_H
#define CHFACEDLG_H
#include <qobject.h>
#include <kiconview.h> // declaration below
enum FacePerm { adminOnly = 1, adminFirst = 2, userFirst = 3, userOnly = 4};
class KDialogBase;
class ChFaceDlg : public KDialogBase
{
Q_OBJECT
public:
ChFaceDlg(const QString& picsdirs, QWidget *parent=0, const char *name=0, bool modal=true);
QPixmap getFaceImage() const
{
if(m_FacesWidget->currentItem())
return *(m_FacesWidget->currentItem()->pixmap());
else
return QPixmap();
}
private slots:
void slotFaceWidgetSelectionChanged( QIconViewItem *item )
{ enableButtonOK( !item->pixmap()->isNull() ); }
void slotGetCustomImage();
//void slotSaveCustomImage();
private:
void addCustomPixmap( QString imPath, bool saveCopy );
KIconView *m_FacesWidget;
};
#endif // CHFACEDLG_H

View file

@ -0,0 +1,100 @@
/***************************************************************************
* Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca> *
* Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> *
* *
* 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. *
* *
***************************************************************************/
/**
* @file Change a user's 'finger' information, specifically their full name.
* derived from kdepasswd.
*/
#include <unistd.h>
#include <stdlib.h>
#include <qcstring.h>
#include <kdesu/process.h>
#include <kdebug.h>
#include <kdebug.h>
#include "chfnprocess.h"
int ChfnProcess::exec(const char *pass, const char *name)
{
// Try to set the default locale to make the parsing of the output
// of `chfn' easier.
putenv((char*)"LC_ALL=C");
QCStringList args;
args += "-f";
args += name;
int ret = PtyProcess::exec("chfn", args);
if (ret < 0)
return ChfnNotFound;
ret = ConverseChfn(pass);
waitForChild();
return ret;
}
/*
* The actual work.
* Return values: -1 = unknown error, 0 = ok, >0 = error code.
*/
int ChfnProcess::ConverseChfn(const char *pass)
{
int status=-1;
QCString line;
while(1)
{
line = readLine();
if ( line.isEmpty() )
continue;// discard line
if ( line.contains( "Password: " )/*isPrompt( line, "password" )*/ )
{
WaitSlave();
write(m_Fd, pass, strlen(pass));
write(m_Fd, "\n", 1);
}
line = readLine(); // Let's see what the outcome was
if ( line.contains( "Changing finger info" ) )
{
// do nothing
}
else if ( line.contains( "information changed" ) )
{
status=0;
break;
}
else if ( line.isEmpty() )
{
status=0;
break;
}
else if ( line.contains( "Password error" ) || line.contains("Incorrect password") )
{
status=PasswordError;
break;
}
else
{
status=MiscError;
m_Error=line;
break;
}
}
return status;
}

View file

@ -0,0 +1,33 @@
/***************************************************************************
* Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca> *
* Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> *
* *
* 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. *
* *
***************************************************************************/
#ifndef CHFNPROC_H
#define CHFNPROC_H
#include <qcstring.h>
#include <kdesu/process.h>
class ChfnProcess : public PtyProcess
{
public:
enum Errors { ChfnNotFound=1, PasswordError=2, MiscError=3 };
int exec(const char *pass, const char *name);
QCString error() { return m_Error; }
private:
int ConverseChfn(const char *pass);
QCString m_Error;
};
#endif

View file

View file

@ -0,0 +1,11 @@
[Desktop Entry]
Encoding=UTF-8
Icon=kdmconfig
Categories=QT;KDE;X-KDE-settings-security;
X-KDE-ParentApp=kcontrol
X-KDE-Library=useraccount
Type=Application
Exec=kcmshell kcm_useraccount
Name=Password & User Information
Keywords=password;email;name;organization;realname;login image;face; echo mode;
Comment=User information such as password, name and email

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
<kcfg>
<kcfgfile name="kdm/kdmrc"/>
<include>kglobal.h</include>
<include>kstandarddirs.h</include>
<group name="X-*-Greeter">
<entry name="faceDir" type="Path">
<default code="true">
KGlobal::dirs()->resourceDirs("data").last() + "kdm/faces" + '/'
</default>
</entry>
<entry name="UserFaceDir" type="Path">
<default>$HOME/.faces/</default>
</entry>
<entry name="FaceSource" type="String">
<default>PreferAdmin</default>
</entry>
<!-- These entries doesn't "exist" or is used in kdmrc
but this is a nifty way of handling default values ;-) -->
<entry name = "FaceSize" type="Int">
<label>The size of login images</label>
<default>64</default>
</entry>
<entry name = "DefaultFile" type="Path">
<label>The default image file</label>
<default>.default.face.icon</default>
</entry>
<entry name="CustomFaceFile" type="Path">
<label>The filename of the user's custom image file</label>
<default>Custom.png</default>
</entry>
<entry name="FaceFile" type="Path">
<label>The user's login image</label>
<default>$HOME/.face.icon</default>
</entry>
<entry name="CustomKey" type="String">
<default>Zz_custom</default>
<label>Sort key for KIconViewItems</label>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
<kcfg>
<kcfgfile name="kdeglobals"/>
<group name="Passwords">
<entry name="EchoMode" type="Enum">
<label>Password echo type</label>
<choices>
<choice name="OneStar"/>
<choice name="ThreeStars"/>
<choice name="NoEcho"/>
</choices>
<default>OneStar</default>
</entry>
<entry name="test" type="String">
<default> adasderasd </default>
</entry>
</group>
</kcfg>

359
kdepasswd/kcm/main.cpp Normal file
View file

@ -0,0 +1,359 @@
/**
* Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*
*
* Please see the README
*
*/
#include <qlayout.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qbuttongroup.h>
#include <qevent.h>
#include <qpixmap.h>
#include <qcstring.h>
#include <qstringlist.h>
#include <qlayout.h>
#include <kpushbutton.h>
#include <kguiitem.h>
#include <kemailsettings.h>
#include <kpassdlg.h>
#include <kuser.h>
#include <kdialog.h>
#include <kimageio.h>
#include <kstandarddirs.h>
#include <kaboutdata.h>
#include <kgenericfactory.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <kio/netaccess.h>
#include <kurl.h>
#include <kurldrag.h>
#include "settings.h"
#include "pass.h"
#include "chfnprocess.h"
#include "chfacedlg.h"
#include "main.h"
typedef KGenericFactory<KCMUserAccount, QWidget> Factory;
K_EXPORT_COMPONENT_FACTORY( kcm_useraccount, Factory("kcm_useraccount") )
KCMUserAccount::KCMUserAccount( QWidget *parent, const char *name,
const QStringList &)
: KCModule( parent, name)
{
QVBoxLayout *topLayout = new QVBoxLayout(this);
_mw = new MainWidget(this);
topLayout->addWidget( _mw );
connect( _mw->btnChangeFace, SIGNAL(clicked()), SLOT(slotFaceButtonClicked()));
connect( _mw->btnChangePassword, SIGNAL(clicked()), SLOT(slotChangePassword()));
_mw->btnChangePassword->setGuiItem( KGuiItem( i18n("Change &Password..."), "password" ));
connect( _mw->leRealname, SIGNAL(textChanged(const QString&)), SLOT(changed()));
connect( _mw->leOrganization, SIGNAL(textChanged(const QString&)), SLOT(changed()));
connect( _mw->leEmail, SIGNAL(textChanged(const QString&)), SLOT(changed()));
connect( _mw->bgpPassword, SIGNAL(clicked(int)), SLOT(changed()));
connect( _mw->leSMTP, SIGNAL(textChanged(const QString&)), SLOT(changed()));
_ku = new KUser();
_kes = new KEMailSettings();
_mw->lblUsername->setText( _ku->loginName() );
_mw->lblUID->setText( QString().number(_ku->uid()) );
setButtons( KCModule::Ok|KCModule::Apply);
load();
}
void KCMUserAccount::slotChangePassword()
{
KProcess *proc = new KProcess;
QString bin = KGlobal::dirs()->findExe("kdepasswd");
if ( !bin )
{
kdDebug() << "kcm_useraccount: kdepasswd was not found." << endl;
KMessageBox::sorry ( this, i18n( "A program error occured, the internal "
"program 'kdepasswd' could not be found. You will "
"not be able to change your password."));
_mw->btnChangePassword->setEnabled(false);
return;
}
*proc << bin << _ku->loginName() ;
proc->start(KProcess::DontCare);
delete proc;
}
KCMUserAccount::~KCMUserAccount()
{
delete _ku;
delete _kes;
}
void KCMUserAccount::load()
{
_mw->lblUsername->setText(_ku->loginName());
_kes->setProfile(_kes->defaultProfileName());
_mw->leRealname->setText( _kes->getSetting( KEMailSettings::RealName ));
_mw->leEmail->setText( _kes->getSetting( KEMailSettings::EmailAddress ));
_mw->leOrganization->setText( _kes->getSetting( KEMailSettings::Organization ));
_mw->leSMTP->setText( _kes->getSetting( KEMailSettings::OutServer ));
_mw->bgpPassword->setButton( KCFGPassword::echoMode() );
QString _userPicsDir = KCFGUserAccount::faceDir() +
KGlobal::dirs()->resourceDirs("data").last() + "kdm/faces" + '/';
QString fs = KCFGUserAccount::faceSource();
FacePerm faceType;
if (fs == QString::fromLatin1("UserOnly"))
faceType = userOnly;
else if (fs == QString::fromLatin1("PreferUser"))
faceType = adminFirst;
else if (fs == QString::fromLatin1("PreferAdmin"))
faceType = adminFirst;
else
faceType = adminOnly; // Admin Only
if ( faceType == adminFirst )
{ // If the administrator's choice takes preference
_facePixmap = QPixmap( _userPicsDir + _ku->loginName() + ".face.icon" );
if ( _facePixmap.isNull() )
faceType = userFirst;
else
_mw->btnChangeFace->setPixmap( _facePixmap );
}
if ( faceType >= userFirst )
{
// If the user's choice takes preference
_facePixmap = QPixmap( KCFGUserAccount::faceFile() );
// The user has no face, should we check for the admin's setting?
if ( _facePixmap.isNull() && faceType == userFirst )
_facePixmap = QPixmap( _userPicsDir + _ku->loginName() + ".face.icon" );
if ( _facePixmap.isNull() )
_facePixmap = QPixmap( _userPicsDir + KCFGUserAccount::defaultFile() );
_mw->btnChangeFace->setPixmap( _facePixmap );
}
else if ( faceType <= adminOnly )
{
// Admin only
_facePixmap = QPixmap( _userPicsDir + _ku->loginName() + ".face.icon" );
if ( _facePixmap.isNull() )
_facePixmap = QPixmap( _userPicsDir + KCFGUserAccount::defaultFile() );
_mw->btnChangeFace->setPixmap( _facePixmap );
}
}
void KCMUserAccount::save()
{
/* Save KDE's homebrewn settings */
_kes->setSetting( KEMailSettings::RealName, _mw->leRealname->text() );
_kes->setSetting( KEMailSettings::EmailAddress, _mw->leEmail->text() );
_kes->setSetting( KEMailSettings::Organization, _mw->leOrganization->text() );
_kes->setSetting( KEMailSettings::OutServer, _mw->leSMTP->text() );
/* Save realname to /etc/passwd */
if ( _mw->leRealname->isModified() )
{
QCString password;
int ret = KPasswordDialog::getPassword( password, i18n("Please enter "
"your password in order to save your settings:"));
if ( !ret )
{
KMessageBox::sorry( this, i18n("You must enter "
"your password in order to change your information."));
return;
}
ChfnProcess *proc = new ChfnProcess();
ret = proc->exec(password, _mw->leRealname->text().ascii() );
if ( ret )
{
if ( ret == ChfnProcess::PasswordError )
KMessageBox::sorry( this, i18n("You must enter a correct password."));
else
{
KMessageBox::sorry( this, i18n("An error occured and your password has "
"probably not been changed. The error "
"message was:\n%1").arg(proc->error()));
kdDebug() << "ChfnProcess->exec() failed. Error code: " << ret
<< "\nOutput:" << proc->error() << endl;
}
}
delete proc;
}
/* Save the image */
if( !_facePixmap.save( KCFGUserAccount::faceFile(), "PNG" ))
KMessageBox::error( this, i18n("There was an error saving the image: %1" ).arg(
KCFGUserAccount::faceFile()) );
/* Password echo */
KCFGPassword::setEchoMode( _mw->bgpPassword->selectedId() );
KCFGPassword::writeConfig(); // Ya know, this one's pretty important.
emit changed(false);
}
const KAboutData* KCMUserAccount::aboutData() const
{
KAboutData* about = new KAboutData(I18N_NOOP("kcm_useraccount"),
I18N_NOOP("Password & User Information"), 0, 0,
KAboutData::License_GPL,
I18N_NOOP("(C) 2002, Braden MacDonald, "
"(C) 2004 Ravikiran Rajagopal"));
about->addAuthor("Ravikiran Rajagopal", I18N_NOOP("Maintainer"), "ravi@kde.org");
about->addAuthor("Michael H\303\244ckel", "haeckel@kde.org" );
about->addAuthor("Braden MacDonald", I18N_NOOP("Face editor"), "bradenm_k@shaw.ca");
about->addAuthor("Geert Jansen", I18N_NOOP("Password changer"), "jansen@kde.org",
"http://www.stack.nl/~geertj/");
about->addAuthor("Daniel Molkentin");
about->addAuthor("Alex Zepeda");
about->addAuthor("Hans Karlsson", I18N_NOOP("Icons"), "karlsson.h@home.se");
about->addAuthor("Hermann Thomas", I18N_NOOP("Icons"), "h.thomas@gmx.de");
return about;
}
void KCMUserAccount::changeFace(const QPixmap &pix)
{
if ( _facePerm < userFirst )
return; // If the user isn't allowed to change their face, don't!
if ( pix.isNull() ) {
KMessageBox::sorry( this, i18n("There was an error loading the image.") );
return;
}
_facePixmap = pix;
_mw->btnChangeFace->setPixmap( _facePixmap );
emit changed( true );
}
void KCMUserAccount::slotFaceButtonClicked()
{
if ( _facePerm < userFirst )
{
KMessageBox::sorry( this, i18n("Your administrator has disallowed changing your face.") );
return;
}
/*
<entry name="kdmFaceDir" type="Path">
<default code="true">
</default>
</entry>
*/
ChFaceDlg* pDlg = new ChFaceDlg( KGlobal::dirs()->resourceDirs("data").last() +
"/kdm/pics/users/" );
if ( pDlg->exec() == QDialog::Accepted )
{
if ( !pDlg->getFaceImage().isNull() )
changeFace( pDlg->getFaceImage() );
}
delete pDlg;
}
/**
* I merged faceButtonDropEvent into this /Frans
* The function was called after checking event type and
* the code is now below that if statement
*/
bool KCMUserAccount::eventFilter(QObject *, QEvent *e)
{
if (e->type() == QEvent::DragEnter)
{
QDragEnterEvent *ee = (QDragEnterEvent *) e;
ee->accept( KURLDrag::canDecode(ee) );
return true;
}
if (e->type() == QEvent::Drop)
{
if ( _facePerm < userFirst )
{
KMessageBox::sorry( this, i18n("Your administrator "
"has disallowed changing your image.") );
return true;
}
KURL *url = decodeImgDrop( (QDropEvent *) e, this);
if (url)
{
QString pixPath;
KIO::NetAccess::download(*url, pixPath, this);
changeFace( QPixmap( pixPath ) );
KIO::NetAccess::removeTempFile(pixPath);
delete url;
}
return true;
}
return false;
}
inline KURL *KCMUserAccount::decodeImgDrop(QDropEvent *e, QWidget *wdg)
{
KURL::List uris;
if (KURLDrag::decode(e, uris) && (uris.count() > 0))
{
KURL *url = new KURL(uris.first());
KImageIO::registerFormats();
if( KImageIO::canRead(KImageIO::type(url->fileName())) )
return url;
QStringList qs = QStringList::split('\n', KImageIO::pattern());
qs.remove(qs.begin());
QString msg = i18n( "%1 does not appear to be an image file.\n"
"Please use files with these extensions:\n"
"%2").arg(url->fileName()).arg(qs.join("\n"));
KMessageBox::sorry( wdg, msg);
delete url;
}
return 0;
}
#include "main.moc"

80
kdepasswd/kcm/main.h Normal file
View file

@ -0,0 +1,80 @@
/**
* Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*/
#ifndef MAIN_H
#define MAIN_H
#include <kcmodule.h>
#include "main_widget.h"
class KAboutData;
class KUser;
class KEmailSettings;
class QEvent;
class QObject;
class KURL;
class Config;
/**
* Please see the README
*/
class KCMUserAccount : public KCModule
{
Q_OBJECT
public:
KCMUserAccount(QWidget* parent, const char* name = "KCMUserAccount",
const QStringList& list=QStringList());
~KCMUserAccount();
/**
* The user data is loaded from chfn(/etc/password) and then
* written back as well as to KDE's own(KEmailSettings).
* The user won't notice this(assuming they change the KDE settings via
* this KCM) and will make KDE play nice with enviroments which uses
* /etc/password.
*/
void load();
void save();
const KAboutData* aboutData() const;
/**
* For the face button
*/
bool eventFilter(QObject *, QEvent *e);
private slots:
void slotChangePassword();
//void configChanged() { emit changed(true); };
void slotFaceButtonClicked();
private:
void changeFace(const QPixmap& pix);
inline KURL* decodeImgDrop(QDropEvent *e, QWidget *wdg);
KEMailSettings *_kes;
KUser *_ku;
MainWidget *_mw;
FacePerm _facePerm;
QPixmap _facePixmap;
};
#endif // MAIN_H

View file

@ -0,0 +1,280 @@
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<class>MainWidget</class>
<author>Frans Englich &lt;frans.englich@telia.com&gt;</author>
<widget class="QWidget">
<property name="name">
<cstring>MainWidget</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>514</height>
</rect>
</property>
<property name="caption">
<string>KCMUserAccount</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="0" column="1" rowspan="1" colspan="3">
<property name="name">
<cstring>lblClickButtonInfo</cstring>
</property>
<property name="text">
<string>&lt;i&gt;Click the button to change your image&lt;/i&gt;</string>
</property>
</widget>
<widget class="KPushButton" row="0" column="0">
<property name="name">
<cstring>btnChangeFace</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>74</width>
<height>74</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>74</width>
<height>74</height>
</size>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="4">
<property name="name">
<cstring>grpUserInformation</cstring>
</property>
<property name="title">
<string>User Information</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="1" column="0">
<property name="name">
<cstring>lblOrganisation</cstring>
</property>
<property name="text">
<string>&amp;Organization:</string>
</property>
<property name="buddy" stdset="0">
<cstring>leOrganization</cstring>
</property>
</widget>
<widget class="QLineEdit" row="0" column="1">
<property name="name">
<cstring>leRealname</cstring>
</property>
</widget>
<widget class="QLabel" row="0" column="0">
<property name="name">
<cstring>lblRealName</cstring>
</property>
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="buddy" stdset="0">
<cstring>leRealname</cstring>
</property>
</widget>
<widget class="QLineEdit" row="1" column="1">
<property name="name">
<cstring>leOrganization</cstring>
</property>
</widget>
<widget class="QLabel" row="2" column="0">
<property name="name">
<cstring>lblEmail</cstring>
</property>
<property name="text">
<string>&amp;Email:</string>
</property>
<property name="buddy" stdset="0">
<cstring>leEmail</cstring>
</property>
</widget>
<widget class="QLineEdit" row="2" column="1">
<property name="name">
<cstring>leEmail</cstring>
</property>
</widget>
<widget class="QLabel" row="3" column="0">
<property name="name">
<cstring>textLabel3</cstring>
</property>
<property name="text">
<string>&amp;SMTP Server:</string>
</property>
<property name="buddy" stdset="0">
<cstring>leSMTP</cstring>
</property>
</widget>
<widget class="QLineEdit" row="3" column="1">
<property name="name">
<cstring>leSMTP</cstring>
</property>
</widget>
<widget class="QLabel" row="4" column="1">
<property name="name">
<cstring>lblUsername</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="4" column="0">
<property name="name">
<cstring>lblUsernameTell</cstring>
</property>
<property name="text">
<string>Username:</string>
</property>
</widget>
<widget class="QLabel" row="5" column="0">
<property name="name">
<cstring>lblUIDTell</cstring>
</property>
<property name="text">
<string>User ID:</string>
</property>
</widget>
<widget class="QLabel" row="5" column="1">
<property name="name">
<cstring>lblUID</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
</grid>
</widget>
<widget class="QButtonGroup" row="2" column="0" rowspan="2" colspan="2">
<property name="name">
<cstring>bgpPassword</cstring>
</property>
<property name="title">
<string>Echo Character As</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="exclusive">
<bool>true</bool>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QRadioButton" row="0" column="0">
<property name="name">
<cstring>rdbOneStar</cstring>
</property>
<property name="text">
<string>One star</string>
</property>
</widget>
<widget class="QRadioButton" row="1" column="0">
<property name="name">
<cstring>rdbThreeStars</cstring>
</property>
<property name="text">
<string>Three stars</string>
</property>
</widget>
<widget class="QRadioButton" row="2" column="0">
<property name="name">
<cstring>rdbNoEcho</cstring>
</property>
<property name="text">
<string>Show password</string>
</property>
</widget>
</grid>
</widget>
<spacer row="2" column="2">
<property name="name">
<cstring>spacer5</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>70</width>
<height>20</height>
</size>
</property>
</spacer>
<spacer row="3" column="3">
<property name="name">
<cstring>spacer6</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>150</height>
</size>
</property>
</spacer>
<widget class="KPushButton" row="2" column="3">
<property name="name">
<cstring>btnChangePassword</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
</grid>
</widget>
<tabstops>
<tabstop>btnChangeFace</tabstop>
<tabstop>leRealname</tabstop>
<tabstop>leOrganization</tabstop>
<tabstop>leEmail</tabstop>
<tabstop>btnChangePassword</tabstop>
</tabstops>
<includes>
<include location="local" impldecl="in implementation">kdialog.h</include>
</includes>
<layoutdefaults spacing="6" margin="11"/>
<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/>
<includehints>
<includehint>kpushbutton.h</includehint>
<includehint>kpushbutton.h</includehint>
</includehints>
</UI>

5
kdepasswd/kcm/pass.kcfgc Normal file
View file

@ -0,0 +1,5 @@
File=kcm_useraccount_pass.kcfg
ClassName=KCFGPassword
Singleton=true
Mutators=true

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
kdepasswd/kcm/pics/Bug.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -0,0 +1,21 @@
Butterfly.png, Konqui.png:
KDE Graphics Team
BeachBall.png BlueMarble1.png Flower.png Night.png Star2.png Star3.png
Star4.png Star.png Stars2.png Stars.png:
Braden MacDonald
Apple.png Cheese.png Ghost.png Pearl.png Skull.png Blowfish.png Cow.png
Guitar.png Penguin.png Smiley.png Bug.png Daemon.png Lion.png Pig.png
Splash.png Burger.png Dog.png Man.png Scream.png Turtle.png Car.png
Elephant.png Monkey.png Shark.png Watch.png Astronaut.png Heart.png
Ring.png Rabbit.png Speakers.png UFO.png :
Hans Karlsson <karlsson.h@home.se>
License: free for commercial and noncommercial usage, distribution and
modification
Arch.png BeachBall2.png Butterfly2.png Cactus.png Car2.png Clock.png
Dice.png Dog2.png Dragon.png Fish.png Flower2.png Flower3.png Frog.png
Kiwi.png Lava.png Pineapple.png Teddybear.png Tiger.png Tukan.png
Wind.png :
Hermann Thomas <h.thomas@gmx.de>

BIN
kdepasswd/kcm/pics/Car.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
kdepasswd/kcm/pics/Cow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
kdepasswd/kcm/pics/Dog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
kdepasswd/kcm/pics/Frog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
kdepasswd/kcm/pics/Lion.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View file

@ -0,0 +1,10 @@
picsdir = $(kde_datadir)/kdm/pics/users
pics_DATA = Apple.png BeachBall.png Blowfish.png Bug.png \
Butterfly.png Car.png Cow.png Daemon.png Dog.png Elephant.png \
Flower.png Frog.png Ghost.png Guitar.png Heart.png Konqui.png \
Lion.png Monkey.png Penguin.png Pig.png Rabbit.png \
Ring.png Scream.png Shark.png Splash.png Star.png Teddybear.png \
Turtle.png
EXTRA_DIST = $(pics_DATA)

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
kdepasswd/kcm/pics/Pig.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
kdepasswd/kcm/pics/Ring.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
kdepasswd/kcm/pics/Star.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View file

@ -0,0 +1,5 @@
File=kcm_useraccount.kcfg
ClassName=KCFGUserAccount
Singleton=true
Mutators=false