~ubuntu-branches/ubuntu/quantal/kde-baseapps/quantal

« back to all changes in this revision

Viewing changes to .pc/kubuntu_18_fix_systemsettings_about_me.diff/kdepasswd/kcm/main.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-05-25 17:26:17 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120525172617-xr9bzhlugldbflvq
Tags: 4:4.8.80a-0ubuntu1
* Merge with debian git, remainging changes:
  - keep breaks/replaces
  - keep symbol files
  - keep kubuntu patches
  - dolphin suggests and not recommends ruby
  - add kfind, konsole and kompare to dolphin suggests
* konq-plugins breaks/replaces kde-baseapps-data << 4:4.8.80

* Drop squence numbers from kubuntu patches 

* New upstream beta release
  - refresh kubuntu_fix_systemsettings_about_me.diff
  - add new doc images to {konqueror,dolphin}.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/**
3
 
 *  Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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
17
 
 *
18
 
 *
19
 
 *  Please see the README
20
 
 *
21
 
 */
22
 
 
23
 
#include "main.h"
24
 
 
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>
32
 
 
33
 
#include <kpushbutton.h>
34
 
#include <kguiitem.h>
35
 
#include <kpassworddialog.h>
36
 
#include <kuser.h>
37
 
#include <kdialog.h>
38
 
#include <kimageio.h>
39
 
#include <kmimetype.h>
40
 
#include <kstandarddirs.h>
41
 
#include <kaboutdata.h>
42
 
#include <kmessagebox.h>
43
 
#include <QProcess>
44
 
#include <kio/netaccess.h>
45
 
#include <kurl.h>
46
 
 
47
 
#include "settings.h"
48
 
#include "pass.h"
49
 
#include "chfnprocess.h"
50
 
#include <KPluginFactory>
51
 
#include <KPluginLoader>
52
 
 
53
 
K_PLUGIN_FACTORY(Factory,
54
 
        registerPlugin<KCMUserAccount>();
55
 
        )
56
 
K_EXPORT_PLUGIN(Factory("useraccount"))
57
 
 
58
 
KCMUserAccount::KCMUserAccount( QWidget *parent, const QVariantList &)
59
 
        : KCModule( Factory::componentData(), parent)
60
 
{
61
 
        QVBoxLayout *topLayout = new QVBoxLayout(this);
62
 
        topLayout->setSpacing(KDialog::spacingHint());
63
 
        topLayout->setMargin(0);
64
 
 
65
 
        _mw = new MainWidget(this);
66
 
        topLayout->addWidget( _mw );
67
 
 
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" ));
71
 
 
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()));
76
 
 
77
 
        _ku = new KUser();
78
 
        _kes = new KEMailSettings();
79
 
 
80
 
        _mw->lblUsername->setText( _ku->loginName() );
81
 
        QFont font( _mw->lblUsername->font() );
82
 
        font.setPointSizeF( font.pointSizeF()  * 1.41 );
83
 
        font.setBold( true );
84
 
        _mw->lblUsername->setFont( font );
85
 
        _mw->lblUID->setText( QString().number(_ku->uid()) );
86
 
 
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"));
92
 
 
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" );
96
 
 
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");
104
 
        setAboutData(about);
105
 
 
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>") );
109
 
 
110
 
        addConfig( KCFGPassword::self(), this );
111
 
        load();
112
 
}
113
 
 
114
 
void KCMUserAccount::slotChangePassword()
115
 
{
116
 
        QString bin = KGlobal::dirs()->findExe("kdepasswd");
117
 
        if ( bin.isEmpty() )
118
 
        {
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."));
123
 
 
124
 
                _mw->btnChangePassword->setEnabled(false);
125
 
                return;
126
 
        }
127
 
        QStringList lst;
128
 
        lst << _ku->loginName();
129
 
        QProcess::startDetached(bin,lst);
130
 
 
131
 
}
132
 
 
133
 
 
134
 
KCMUserAccount::~KCMUserAccount()
135
 
{
136
 
        delete _ku;
137
 
        delete _kes;
138
 
}
139
 
 
140
 
void KCMUserAccount::load()
141
 
{
142
 
        _mw->lblUsername->setText(_ku->loginName());
143
 
 
144
 
        _kes->setProfile(_kes->defaultProfileName());
145
 
 
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 ));
150
 
 
151
 
        // load user face
152
 
        _facePixmap = QPixmap( KCFGUserAccount::faceFile() );
153
 
        _mw->btnChangeFace->setIcon( KIcon(_facePixmap) );
154
 
        if (!_facePixmap.isNull()) {
155
 
                _mw->btnChangeFace->setIconSize(_facePixmap.size());
156
 
        }
157
 
 
158
 
        KCModule::load(); /* KConfigXT */
159
 
 
160
 
}
161
 
 
162
 
void KCMUserAccount::save()
163
 
{
164
 
        KCModule::save(); /* KConfigXT */
165
 
 
166
 
/*
167
 
 * FIXME: there is apparently no way to set full name
168
 
 * non-interactively as a normal user on FreeBSD.
169
 
 */
170
 
#ifndef Q_OS_FREEBSD
171
 
        /* Save realname to /etc/passwd */
172
 
        if ( _mw->leRealname->isModified() )
173
 
        {
174
 
                KPasswordDialog dlg( _mw );
175
 
                dlg.setPrompt(i18n("Please enter your password in order to save your settings:"));
176
 
                if ( !dlg.exec() )
177
 
                {
178
 
                        KMessageBox::sorry( this, i18n("You must enter "
179
 
                                "your password in order to change your information."));
180
 
                        return;
181
 
                }
182
 
 
183
 
                ChfnProcess *proc = new ChfnProcess();
184
 
                int ret = proc->exec(dlg.password().toLocal8Bit() , _mw->leRealname->text().toLocal8Bit() );
185
 
                if ( ret )
186
 
                {
187
 
                        if ( ret == ChfnProcess::PasswordError )
188
 
                                KMessageBox::sorry( this, i18n("You must enter a correct password."));
189
 
 
190
 
                        else
191
 
                        {
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;
197
 
                        }
198
 
 
199
 
                        delete proc;
200
 
                        return;
201
 
                }
202
 
 
203
 
                delete proc;
204
 
        }
205
 
#endif
206
 
 
207
 
        /* Save the image */
208
 
        if( !_facePixmap.isNull() )
209
 
        {
210
 
                if( !_facePixmap.save( KCFGUserAccount::faceFile(), "PNG" ))
211
 
                {
212
 
                        KMessageBox::error( this, i18n("There was an error saving the image: %1" ,
213
 
                                KCFGUserAccount::faceFile()) );
214
 
                        return;
215
 
                }
216
 
        }
217
 
 
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() );
223
 
}
224
 
 
225
 
void KCMUserAccount::changeFace(const QPixmap &pix)
226
 
{
227
 
  if ( pix.isNull() ) {
228
 
    KMessageBox::sorry( this, i18n("There was an error loading the image.") );
229
 
    return;
230
 
  }
231
 
 
232
 
  _facePixmap = pix;
233
 
  _mw->btnChangeFace->setIcon( KIcon(_facePixmap) );
234
 
  _mw->btnChangeFace->setIconSize(_facePixmap.size());
235
 
  emit changed( true );
236
 
}
237
 
 
238
 
void KCMUserAccount::slotFaceButtonClicked()
239
 
{
240
 
  ChFaceDlg* pDlg = new ChFaceDlg( KGlobal::dirs()->resourceDirs("data").last() +
241
 
        "/kdm/pics/users/", this );
242
 
 
243
 
  if ( pDlg->exec() == QDialog::Accepted && !pDlg->getFaceImage().isNull() )
244
 
      changeFace( pDlg->getFaceImage() );
245
 
 
246
 
  delete pDlg;
247
 
}
248
 
 
249
 
/**
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
253
 
 */
254
 
bool KCMUserAccount::eventFilter(QObject *, QEvent *e)
255
 
{
256
 
        if (e->type() == QEvent::DragEnter)
257
 
                {
258
 
                QDragEnterEvent *ee = (QDragEnterEvent *) e;
259
 
    if (!KUrl::List::fromMimeData( ee->mimeData() ).isEmpty())
260
 
      ee->accept();
261
 
    else
262
 
      ee->ignore();
263
 
                return true;
264
 
        }
265
 
 
266
 
        if (e->type() == QEvent::Drop)
267
 
        {
268
 
                KUrl *url = decodeImgDrop( (QDropEvent *) e, this);
269
 
                if (url)
270
 
                {
271
 
                        QString pixPath;
272
 
                        KIO::NetAccess::download(*url, pixPath, this);
273
 
                        changeFace( QPixmap( pixPath ) );
274
 
                        KIO::NetAccess::removeTempFile(pixPath);
275
 
                        delete url;
276
 
                }
277
 
                return true;
278
 
        }
279
 
        return false;
280
 
}
281
 
 
282
 
inline KUrl *KCMUserAccount::decodeImgDrop(QDropEvent *e, QWidget *wdg)
283
 
{
284
 
  KUrl::List uris = KUrl::List::fromMimeData(e->mimeData());
285
 
  if (!uris.isEmpty())
286
 
  {
287
 
    KUrl *url = new KUrl(uris.first());
288
 
 
289
 
    KMimeType::Ptr mime = KMimeType::findByUrl( *url );
290
 
    if ( mime && KImageIO::isSupported( mime->name(), KImageIO::Reading ) )
291
 
      return url;
292
 
 
293
 
    QStringList qs = KImageIO::pattern().split( '\n');
294
 
    qs.erase(qs.begin());
295
 
 
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);
300
 
    delete url;
301
 
  }
302
 
  return 0;
303
 
}
304
 
 
305
 
#include "main.moc"
306