3
* Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
19
* Please see the README
25
#include <QtGui/QLayout>
26
#include <QtGui/QLabel>
27
#include <QtGui/QLineEdit>
28
#include <QtCore/QEvent>
29
#include <QtGui/QPixmap>
30
#include <QtCore/QStringList>
31
#include <QtGui/QDragEnterEvent>
33
#include <kpushbutton.h>
35
#include <kpassworddialog.h>
39
#include <kmimetype.h>
40
#include <kstandarddirs.h>
41
#include <kaboutdata.h>
42
#include <kmessagebox.h>
44
#include <kio/netaccess.h>
49
#include "chfnprocess.h"
50
#include <KPluginFactory>
51
#include <KPluginLoader>
53
K_PLUGIN_FACTORY(Factory,
54
registerPlugin<KCMUserAccount>();
56
K_EXPORT_PLUGIN(Factory("useraccount"))
58
KCMUserAccount::KCMUserAccount( QWidget *parent, const QVariantList &)
59
: KCModule( Factory::componentData(), parent)
61
QVBoxLayout *topLayout = new QVBoxLayout(this);
62
topLayout->setSpacing(KDialog::spacingHint());
63
topLayout->setMargin(0);
65
_mw = new MainWidget(this);
66
topLayout->addWidget( _mw );
68
connect( _mw->btnChangeFace, SIGNAL(clicked()), SLOT(slotFaceButtonClicked()));
69
connect( _mw->btnChangePassword, SIGNAL(clicked()), SLOT(slotChangePassword()));
70
_mw->btnChangePassword->setGuiItem( KGuiItem( i18n("Change &Password..."), "preferences-desktop-user-password" ));
72
connect( _mw->leRealname, SIGNAL(textChanged(QString)), SLOT(changed()));
73
connect( _mw->leOrganization, SIGNAL(textChanged(QString)), SLOT(changed()));
74
connect( _mw->leEmail, SIGNAL(textChanged(QString)), SLOT(changed()));
75
connect( _mw->leSMTP, SIGNAL(textChanged(QString)), SLOT(changed()));
78
_kes = new KEMailSettings();
80
_mw->lblUsername->setText( _ku->loginName() );
81
QFont font( _mw->lblUsername->font() );
82
font.setPointSizeF( font.pointSizeF() * 1.41 );
84
_mw->lblUsername->setFont( font );
85
_mw->lblUID->setText( QString().number(_ku->uid()) );
87
KAboutData *about = new KAboutData("kcm_useraccount", 0,
88
ki18n("Password & User Information"), 0, KLocalizedString(),
89
KAboutData::License_GPL,
90
ki18n("(C) 2002, Braden MacDonald, "
91
"(C) 2004 Ravikiran Rajagopal"));
93
about->addAuthor(ki18n("Frans Englich"), ki18n("Maintainer"), "frans.englich@telia.com");
94
about->addAuthor(ki18n("Ravikiran Rajagopal"), KLocalizedString(), "ravi@kde.org");
95
about->addAuthor(ki18n("Michael H\303\244ckel"), KLocalizedString(), "haeckel@kde.org" );
97
about->addAuthor(ki18n("Braden MacDonald"), ki18n("Face editor"), "bradenm_k@shaw.ca");
98
about->addAuthor(ki18n("Geert Jansen"), ki18n("Password changer"), "jansen@kde.org",
99
"http://www.stack.nl/~geertj/");
100
about->addAuthor(ki18n("Daniel Molkentin"));
101
about->addAuthor(ki18n("Alex Zepeda"));
102
about->addAuthor(ki18n("Hans Karlsson"), ki18n("Icons"), "karlsson.h@home.se");
103
about->addAuthor(ki18n("Hermann Thomas"), ki18n("Icons"), "h.thomas@gmx.de");
106
setQuickHelp( i18n("<qt>Here you can change your personal information, which "
107
"will be used, for instance, in mail programs and word processors. You can "
108
"change your login password by clicking <em>Change Password...</em>.</qt>") );
110
addConfig( KCFGPassword::self(), this );
114
void KCMUserAccount::slotChangePassword()
116
QString bin = KGlobal::dirs()->findExe("kdepasswd");
119
kDebug() << "kcm_useraccount: kdepasswd was not found.";
120
KMessageBox::sorry ( this, i18n( "A program error occurred: the internal "
121
"program 'kdepasswd' could not be found. You will "
122
"not be able to change your password."));
124
_mw->btnChangePassword->setEnabled(false);
128
lst << _ku->loginName();
129
QProcess::startDetached(bin,lst);
134
KCMUserAccount::~KCMUserAccount()
140
void KCMUserAccount::load()
142
_mw->lblUsername->setText(_ku->loginName());
144
_kes->setProfile(_kes->defaultProfileName());
146
_mw->leRealname->setText( _kes->getSetting( KEMailSettings::RealName ));
147
_mw->leEmail->setText( _kes->getSetting( KEMailSettings::EmailAddress ));
148
_mw->leOrganization->setText( _kes->getSetting( KEMailSettings::Organization ));
149
_mw->leSMTP->setText( _kes->getSetting( KEMailSettings::OutServer ));
152
_facePixmap = QPixmap( KCFGUserAccount::faceFile() );
153
_mw->btnChangeFace->setIcon( KIcon(_facePixmap) );
154
if (!_facePixmap.isNull()) {
155
_mw->btnChangeFace->setIconSize(_facePixmap.size());
158
KCModule::load(); /* KConfigXT */
162
void KCMUserAccount::save()
164
KCModule::save(); /* KConfigXT */
167
* FIXME: there is apparently no way to set full name
168
* non-interactively as a normal user on FreeBSD.
171
/* Save realname to /etc/passwd */
172
if ( _mw->leRealname->isModified() )
174
KPasswordDialog dlg( _mw );
175
dlg.setPrompt(i18n("Please enter your password in order to save your settings:"));
178
KMessageBox::sorry( this, i18n("You must enter "
179
"your password in order to change your information."));
183
ChfnProcess *proc = new ChfnProcess();
184
int ret = proc->exec(dlg.password().toLocal8Bit() , _mw->leRealname->text().toLocal8Bit() );
187
if ( ret == ChfnProcess::PasswordError )
188
KMessageBox::sorry( this, i18n("You must enter a correct password."));
192
KMessageBox::sorry( this, i18n("An error occurred and your name has "
193
"probably not been changed. The error "
194
"message was:\n%1", QString::fromLocal8Bit(proc->error())));
195
kDebug() << "ChfnProcess->exec() failed. Error code: " << ret
196
<< "\nOutput:" << proc->error() << endl;
208
if( !_facePixmap.isNull() )
210
if( !_facePixmap.save( KCFGUserAccount::faceFile(), "PNG" ))
212
KMessageBox::error( this, i18n("There was an error saving the image: %1" ,
213
KCFGUserAccount::faceFile()) );
218
/* Save KDE's homebrewn settings */
219
_kes->setSetting( KEMailSettings::RealName, _mw->leRealname->text() );
220
_kes->setSetting( KEMailSettings::EmailAddress, _mw->leEmail->text() );
221
_kes->setSetting( KEMailSettings::Organization, _mw->leOrganization->text() );
222
_kes->setSetting( KEMailSettings::OutServer, _mw->leSMTP->text() );
225
void KCMUserAccount::changeFace(const QPixmap &pix)
227
if ( pix.isNull() ) {
228
KMessageBox::sorry( this, i18n("There was an error loading the image.") );
233
_mw->btnChangeFace->setIcon( KIcon(_facePixmap) );
234
_mw->btnChangeFace->setIconSize(_facePixmap.size());
235
emit changed( true );
238
void KCMUserAccount::slotFaceButtonClicked()
240
ChFaceDlg* pDlg = new ChFaceDlg( KGlobal::dirs()->resourceDirs("data").last() +
241
"/kdm/pics/users/", this );
243
if ( pDlg->exec() == QDialog::Accepted && !pDlg->getFaceImage().isNull() )
244
changeFace( pDlg->getFaceImage() );
250
* I merged faceButtonDropEvent into this /Frans
251
* The function was called after checking event type and
252
* the code is now below that if statement
254
bool KCMUserAccount::eventFilter(QObject *, QEvent *e)
256
if (e->type() == QEvent::DragEnter)
258
QDragEnterEvent *ee = (QDragEnterEvent *) e;
259
if (!KUrl::List::fromMimeData( ee->mimeData() ).isEmpty())
266
if (e->type() == QEvent::Drop)
268
KUrl *url = decodeImgDrop( (QDropEvent *) e, this);
272
KIO::NetAccess::download(*url, pixPath, this);
273
changeFace( QPixmap( pixPath ) );
274
KIO::NetAccess::removeTempFile(pixPath);
282
inline KUrl *KCMUserAccount::decodeImgDrop(QDropEvent *e, QWidget *wdg)
284
KUrl::List uris = KUrl::List::fromMimeData(e->mimeData());
287
KUrl *url = new KUrl(uris.first());
289
KMimeType::Ptr mime = KMimeType::findByUrl( *url );
290
if ( mime && KImageIO::isSupported( mime->name(), KImageIO::Reading ) )
293
QStringList qs = KImageIO::pattern().split( '\n');
294
qs.erase(qs.begin());
296
QString msg = i18n( "%1 does not appear to be an image file.\n"
297
"Please use files with these extensions:\n"
298
"%2", url->fileName(), qs.join("\n"));
299
KMessageBox::sorry( wdg, msg);