2
Copyright (C) 1997-1998 Thomas Tanghus (tanghus@earthling.net)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
22
#include "positioner.h"
24
#include <KApplication>
27
#include <KFileDialog>
28
#include <KIconLoader>
29
#include <KImageFilePreview>
31
#include <KIO/NetAccess>
34
#include <KMessageBox>
36
#include <KConfigGroup>
37
#include <KStandardDirs>
39
#include <QButtonGroup>
40
#include <QDragEnterEvent>
44
#include <QPushButton>
45
#include <QRadioButton>
47
#include <QGridLayout>
48
#include <QHBoxLayout>
49
#include <QVBoxLayout>
51
extern KConfig *config;
53
KDMDialogWidget::KDMDialogWidget( QWidget *parent )
58
QGridLayout *grid = new QGridLayout( this );
59
grid->setMargin( KDialog::marginHint() );
60
grid->setSpacing( KDialog::spacingHint() );
61
grid->setColumnStretch( 1, 1 );
63
QHBoxLayout *hlay = new QHBoxLayout();
64
hlay->setSpacing( KDialog::spacingHint() );
65
grid->addLayout( hlay, 0, 0, 1, 2 );
66
greetstr_lined = new KLineEdit( this );
67
QLabel *label = new QLabel( i18n("&Greeting:"), this );
68
label->setBuddy( greetstr_lined );
69
hlay->addWidget( label );
70
connect( greetstr_lined, SIGNAL(textChanged( const QString& )),
72
hlay->addWidget( greetstr_lined );
73
wtstr = i18n("<p>This is the \"headline\" for KDM's login window. You may want to "
74
"put some nice greeting or information about the operating system here.</p>"
75
"<p>KDM will substitute the following character pairs with the "
76
"respective contents:</p>"
78
"<li>%d -> current display</li>"
79
"<li>%h -> host name, possibly with domain name</li>"
80
"<li>%n -> node name, most probably the host name without domain name</li>"
81
"<li>%s -> the operating system</li>"
82
"<li>%r -> the operating system's version</li>"
83
"<li>%m -> the machine (hardware) type</li>"
84
"<li>%% -> a single %</li>"
86
label->setWhatsThis( wtstr );
87
greetstr_lined->setWhatsThis( wtstr );
90
QGridLayout *hglay = new QGridLayout();
91
hglay->setSpacing( KDialog::spacingHint() );
92
grid->addLayout( hglay, 1, 0 );
94
label = new QLabel( i18n("Logo area:"), this );
95
hglay->addWidget( label, 0, 0 );
96
QVBoxLayout *vlay = new QVBoxLayout();
97
vlay->setSpacing( KDialog::spacingHint() );
98
hglay->addLayout( vlay, 0, 1, 1, 2 );
99
noneRadio = new QRadioButton( i18nc("logo area", "&None"), this );
100
clockRadio = new QRadioButton( i18n("Show cloc&k"), this );
101
logoRadio = new QRadioButton( i18n("Sho&w logo"), this );
102
QButtonGroup *buttonGroup = new QButtonGroup( this );
103
connect( buttonGroup, SIGNAL(buttonClicked( int )),
104
SLOT(slotAreaRadioClicked( int )) );
105
connect( buttonGroup, SIGNAL(buttonClicked( int )), SIGNAL(changed()) );
106
buttonGroup->addButton( noneRadio, KdmNone );
107
buttonGroup->addButton( clockRadio, KdmClock );
108
buttonGroup->addButton( logoRadio, KdmLogo );
109
vlay->addWidget( noneRadio );
110
vlay->addWidget( clockRadio );
111
vlay->addWidget( logoRadio );
112
wtstr = i18n("You can choose to display a custom logo (see below), a clock or no logo at all.");
113
label->setWhatsThis( wtstr );
114
noneRadio->setWhatsThis( wtstr );
115
logoRadio->setWhatsThis( wtstr );
116
clockRadio->setWhatsThis( wtstr );
118
logoLabel = new QLabel( i18n("&Logo:"), this );
119
logobutton = new QPushButton( this );
120
logoLabel->setBuddy( logobutton );
121
logobutton->setAutoDefault( false );
122
logobutton->setAcceptDrops( true );
123
logobutton->installEventFilter( this ); // for drag and drop
124
connect( logobutton, SIGNAL(clicked()), SLOT(slotLogoButtonClicked()) );
125
hglay->addWidget( logoLabel, 1, 0, Qt::AlignVCenter );
126
hglay->addWidget( logobutton, 1, 1, Qt::AlignCenter );
127
hglay->setRowMinimumHeight( 1, 110 );
128
wtstr = i18n("Click here to choose an image that KDM will display. "
129
"You can also drag and drop an image onto this button "
130
"(e.g. from Konqueror).");
131
logoLabel->setWhatsThis( wtstr );
132
logobutton->setWhatsThis( wtstr );
135
vlay = new QVBoxLayout();
136
grid->addLayout( vlay, 1, 1, 2, 1 );
137
vlay->setParent( grid );
139
label = new QLabel( i18n("Dialog &position:"), this );
140
vlay->addWidget( label );
141
positioner = new Positioner( this );
142
label->setBuddy( positioner );
143
connect( positioner, SIGNAL(positionChanged()), SIGNAL(changed()) );
144
vlay->addWidget( positioner );
146
grid->setRowStretch( 3, 1 );
150
void KDMDialogWidget::makeReadOnly()
152
disconnect( logobutton, SIGNAL(clicked()),
153
this, SLOT(slotLogoButtonClicked()) );
154
logobutton->setAcceptDrops( false );
155
greetstr_lined->setReadOnly( true );
156
noneRadio->setEnabled( false );
157
clockRadio->setEnabled( false );
158
logoRadio->setEnabled( false );
159
positioner->makeReadOnly();
162
bool KDMDialogWidget::setLogo(const QString &logo)
164
QString flogo = logo.isEmpty() ?
165
KStandardDirs::locate( "data", QLatin1String("kdm/pics/kdelogo.png") ) :
170
if (p.width() > 100 || p.height() > 100)
171
p = p.scaled( 100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation );
172
logobutton->setPixmap( QPixmap::fromImage( p ) );
173
uint bd = style()->pixelMetric( QStyle::PM_ButtonMargin ) * 2;
174
logobutton->setFixedSize( p.width() + bd, p.height() + bd );
180
void KDMDialogWidget::slotLogoButtonClicked()
182
KFileDialog dialog( KStandardDirs::locate( "data", QLatin1String("kdm/pics/") ),
183
KImageIO::pattern( KImageIO::Reading ),
185
dialog.setOperationMode( KFileDialog::Opening );
186
dialog.setMode( KFile::File | KFile::LocalOnly );
188
KImageFilePreview *imagePreview = new KImageFilePreview( &dialog );
189
dialog.setPreviewWidget( imagePreview );
190
if (dialog.exec() == QDialog::Accepted &&
191
setLogo(dialog.selectedFile() ))
196
void KDMDialogWidget::slotAreaRadioClicked( int id )
198
logobutton->setEnabled( id == KdmLogo );
199
logoLabel->setEnabled( id == KdmLogo );
203
bool KDMDialogWidget::eventFilter( QObject *, QEvent *e )
205
if (e->type() == QEvent::DragEnter) {
206
iconLoaderDragEnterEvent( (QDragEnterEvent *)e );
210
if (e->type() == QEvent::Drop) {
211
iconLoaderDropEvent( (QDropEvent *)e );
218
void KDMDialogWidget::iconLoaderDragEnterEvent( QDragEnterEvent *e )
220
e->setAccepted( K3URLDrag::canDecode( e ) );
224
KUrl *decodeImgDrop( QDropEvent *e, QWidget *wdg );
226
void KDMDialogWidget::iconLoaderDropEvent( QDropEvent *e )
231
KUrl *url = decodeImgDrop( e, this );
234
// we gotta check if it is a non-local file and make a tmp copy at the hd.
235
if (!url->isLocalFile()) {
236
pixurl.setPath( KGlobal::dirs()->
237
resourceDirs("data").last() + "kdm/pics/" + url->fileName() );
238
KIO::NetAccess::file_copy( *url, pixurl, parentWidget() );
245
// By now url should be "file:/..."
246
if (!setLogo( pixurl.path() )) {
247
KIO::NetAccess::del( pixurl, parentWidget() );
248
QString msg = i18n("There was an error loading the image:\n"
250
"It will not be saved.",
252
KMessageBox::sorry( this, msg );
260
void KDMDialogWidget::save()
262
KConfigGroup configGrp = config->group( "X-*-Greeter" );
264
configGrp.writeEntry( "GreetString", greetstr_lined->text() );
266
configGrp.writeEntry( "LogoArea", noneRadio->isChecked() ? "None" :
267
logoRadio->isChecked() ? "Logo" : "Clock" );
269
configGrp.writeEntry( "LogoPixmap", KIconLoader::global()->iconPath( logopath, K3Icon::Desktop, true ) );
271
configGrp.writeEntry( "GreeterPos",
272
QString("%1,%2").arg( positioner->x() ).arg( positioner->y() ) );
276
void KDMDialogWidget::load()
278
KConfigGroup configGrp = config->group( "X-*-Greeter" );
280
// Read the greeting string
281
greetstr_lined->setText( configGrp.readEntry( "GreetString",
282
i18n("Welcome to %s at %n") ) );
284
// Regular logo or clock
285
QString logoArea = configGrp.readEntry( "LogoArea", "Logo" );
286
if (logoArea == "Clock") {
287
clockRadio->setChecked( true );
288
slotAreaRadioClicked( KdmClock );
289
} else if (logoArea == "Logo") {
290
logoRadio->setChecked( true );
291
slotAreaRadioClicked( KdmLogo );
293
noneRadio->setChecked( true );
294
slotAreaRadioClicked( KdmNone );
297
// See if we use alternate logo
298
setLogo( configGrp.readEntry( "LogoPixmap" ) );
300
QStringList sl = configGrp.readEntry( "GreeterPos", QStringList() );
302
positioner->setPosition( 50, 50 );
304
positioner->setPosition( sl.first().toInt(), sl.last().toInt() );
308
void KDMDialogWidget::defaults()
310
greetstr_lined->setText( i18n("Welcome to %s at %n") );
311
logoRadio->setChecked( true );
312
slotAreaRadioClicked( KdmLogo );
314
positioner->setPosition( 50, 50 );
317
QString KDMDialogWidget::quickHelp() const
319
return i18n("<h1>KDM - Dialog</h1> Here you can configure the basic appearance"
320
" of the KDM login manager in dialog mode, i.e. a greeting string, an icon etc.");
323
#include "kdm-dlg.moc"