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"
25
#include <KFileDialog>
26
#include <KIconLoader>
27
#include <KImageFilePreview>
31
#include <KMessageBox>
33
#include <KConfigGroup>
34
#include <KStandardDirs>
35
#include <KIO/NetAccess>
37
#include <QButtonGroup>
38
#include <QDragEnterEvent>
41
#include <QPushButton>
42
#include <QRadioButton>
44
#include <QGridLayout>
45
#include <QHBoxLayout>
46
#include <QVBoxLayout>
48
extern KConfig *config;
50
KDMDialogWidget::KDMDialogWidget(QWidget *parent)
55
QGridLayout *grid = new QGridLayout(this);
56
grid->setMargin(KDialog::marginHint());
57
grid->setSpacing(KDialog::spacingHint());
58
grid->setColumnStretch(1, 1);
60
QHBoxLayout *hlay = new QHBoxLayout();
61
hlay->setSpacing(KDialog::spacingHint());
62
grid->addLayout(hlay, 0, 0, 1, 2);
63
greetstr_lined = new KLineEdit(this);
64
QLabel *label = new QLabel(i18n("&Greeting:"), this);
65
label->setBuddy(greetstr_lined);
66
hlay->addWidget(label);
67
connect(greetstr_lined, SIGNAL(textChanged(const QString &)),
69
hlay->addWidget(greetstr_lined);
71
"<p>This is the \"headline\" for KDM's login window. You may want to "
72
"put some nice greeting or information about the operating system here.</p>"
73
"<p>KDM will substitute the following character pairs with the "
74
"respective contents:</p>"
76
"<li>%d -> current display</li>"
77
"<li>%h -> host name, possibly with domain name</li>"
78
"<li>%n -> node name, most probably the host name without domain name</li>"
79
"<li>%s -> the operating system</li>"
80
"<li>%r -> the operating system's version</li>"
81
"<li>%m -> the machine (hardware) type</li>"
82
"<li>%% -> a single %</li>"
84
label->setWhatsThis(wtstr);
85
greetstr_lined->setWhatsThis(wtstr);
88
QGridLayout *hglay = new QGridLayout();
89
hglay->setSpacing(KDialog::spacingHint());
90
grid->addLayout(hglay, 1, 0);
92
label = new QLabel(i18n("Logo area:"), this);
93
hglay->addWidget(label, 0, 0);
94
QVBoxLayout *vlay = new QVBoxLayout();
95
vlay->setSpacing(KDialog::spacingHint());
96
hglay->addLayout(vlay, 0, 1, 1, 2);
97
noneRadio = new QRadioButton(i18nc("logo area", "&None"), this);
98
clockRadio = new QRadioButton(i18n("Show cloc&k"), this);
99
logoRadio = new QRadioButton(i18n("Sho&w logo"), this);
100
QButtonGroup *buttonGroup = new QButtonGroup(this);
101
connect(buttonGroup, SIGNAL(buttonClicked(int)),
102
SLOT(slotAreaRadioClicked(int)));
103
connect(buttonGroup, SIGNAL(buttonClicked(int)), SIGNAL(changed()));
104
buttonGroup->addButton(noneRadio, KdmNone);
105
buttonGroup->addButton(clockRadio, KdmClock);
106
buttonGroup->addButton(logoRadio, KdmLogo);
107
vlay->addWidget(noneRadio);
108
vlay->addWidget(clockRadio);
109
vlay->addWidget(logoRadio);
110
wtstr = i18n("You can choose to display a custom logo (see below), a clock or no logo at all.");
111
label->setWhatsThis(wtstr);
112
noneRadio->setWhatsThis(wtstr);
113
logoRadio->setWhatsThis(wtstr);
114
clockRadio->setWhatsThis(wtstr);
116
logoLabel = new QLabel(i18n("&Logo:"), this);
117
logobutton = new QPushButton(this);
118
logoLabel->setBuddy(logobutton);
119
logobutton->setAutoDefault(false);
120
logobutton->setAcceptDrops(true);
121
logobutton->installEventFilter(this); // for drag and drop
122
connect(logobutton, SIGNAL(clicked()), SLOT(slotLogoButtonClicked()));
123
hglay->addWidget(logoLabel, 1, 0, Qt::AlignVCenter);
124
hglay->addWidget(logobutton, 1, 1, Qt::AlignCenter);
125
hglay->setRowMinimumHeight(1, 110);
127
"Click here to choose an image that KDM will display. "
128
"You can also drag and drop an image onto this button "
129
"(e.g. from Konqueror).");
130
logoLabel->setWhatsThis(wtstr);
131
logobutton->setWhatsThis(wtstr);
134
vlay = new QVBoxLayout();
135
grid->addLayout(vlay, 1, 1, 2, 1);
136
vlay->setParent(grid);
138
label = new QLabel(i18n("Dialog &position:"), this);
139
vlay->addWidget(label);
140
positioner = new Positioner(this);
141
label->setBuddy(positioner);
142
connect(positioner, SIGNAL(positionChanged()), SIGNAL(changed()));
143
vlay->addWidget(positioner);
145
grid->setRowStretch(3, 1);
149
bool KDMDialogWidget::setLogo(const QString &logo)
151
QString flogo = logo.isEmpty() ?
152
KStandardDirs::locate("data", QLatin1String("kdm/pics/kdelogo.png")) :
157
if (p.width() > 100 || p.height() > 100)
158
p = p.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation);
159
logobutton->setIcon(QPixmap::fromImage(p));
160
uint bd = style()->pixelMetric(QStyle::PM_ButtonMargin) * 2;
161
logobutton->setFixedSize(p.width() + bd, p.height() + bd);
166
void KDMDialogWidget::slotLogoButtonClicked()
168
KFileDialog dialog(KStandardDirs::locate("data", QLatin1String("kdm/pics/")),
169
KImageIO::pattern(KImageIO::Reading),
171
dialog.setOperationMode(KFileDialog::Opening);
172
dialog.setMode(KFile::File | KFile::LocalOnly);
174
KImageFilePreview *imagePreview = new KImageFilePreview(&dialog);
175
dialog.setPreviewWidget(imagePreview);
176
if (dialog.exec() == QDialog::Accepted &&
177
setLogo(dialog.selectedFile()))
182
void KDMDialogWidget::slotAreaRadioClicked(int id)
184
logobutton->setEnabled(id == KdmLogo);
185
logoLabel->setEnabled(id == KdmLogo);
189
bool KDMDialogWidget::eventFilter(QObject *, QEvent *e)
191
if (e->type() == QEvent::DragEnter) {
192
iconLoaderDragEnterEvent((QDragEnterEvent *)e);
196
if (e->type() == QEvent::Drop) {
197
iconLoaderDropEvent((QDropEvent *)e);
204
void KDMDialogWidget::iconLoaderDragEnterEvent(QDragEnterEvent *e)
206
e->setAccepted(KUrl::List::canDecode(e->mimeData()));
210
KUrl *decodeImgDrop(QDropEvent *e, QWidget *wdg);
212
void KDMDialogWidget::iconLoaderDropEvent(QDropEvent *e)
214
// Installation of a logo from a non-local file is not
215
// such a prominent feature to introduce a new KAuth action
216
// for it. So let us just ignore these drops.
218
KUrl *url = decodeImgDrop(e, this);
219
if (url && url->isLocalFile()) {
220
if (!setLogo(url->toLocalFile())) {
221
QString msg = i18n("There was an error loading the image:\n"
223
"It will not be saved.",
225
KMessageBox::sorry(this, msg);
234
void KDMDialogWidget::save()
236
KConfigGroup configGrp = config->group("X-*-Greeter");
238
configGrp.writeEntry("GreetString", greetstr_lined->text());
240
configGrp.writeEntry("LogoArea", noneRadio->isChecked() ? "None" :
241
logoRadio->isChecked() ? "Logo" : "Clock");
243
configGrp.writeEntry("LogoPixmap",
244
KIconLoader::global()->iconPath(logopath, KIconLoader::Desktop, true));
246
configGrp.writeEntry("GreeterPos",
247
QString("%1,%2").arg(positioner->x()).arg(positioner->y()));
251
void KDMDialogWidget::load()
253
KConfigGroup configGrp = config->group("X-*-Greeter");
255
// Read the greeting string
256
greetstr_lined->setText(configGrp.readEntry("GreetString",
257
i18n("Welcome to %s at %n")));
259
// Regular logo or clock
260
QString logoArea = configGrp.readEntry("LogoArea", "Logo");
261
if (logoArea == "Clock") {
262
clockRadio->setChecked(true);
263
slotAreaRadioClicked(KdmClock);
264
} else if (logoArea == "Logo") {
265
logoRadio->setChecked(true);
266
slotAreaRadioClicked(KdmLogo);
268
noneRadio->setChecked(true);
269
slotAreaRadioClicked(KdmNone);
272
// See if we use alternate logo
273
setLogo(configGrp.readEntry("LogoPixmap"));
275
QStringList sl = configGrp.readEntry("GreeterPos", QStringList());
277
positioner->setPosition(50, 50);
279
positioner->setPosition(sl.first().toInt(), sl.last().toInt());
283
void KDMDialogWidget::defaults()
285
greetstr_lined->setText(i18n("Welcome to %s at %n"));
286
logoRadio->setChecked(true);
287
slotAreaRadioClicked(KdmLogo);
289
positioner->setPosition(50, 50);
292
QString KDMDialogWidget::quickHelp() const
295
"<h1>KDM - Dialog</h1> Here you can configure the basic appearance of "
296
"the KDM login manager in dialog mode, i.e. a greeting string, an icon etc.");
299
#include "kdm-dlg.moc"