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>
26 #include <KFileDialog>
27 #include <KIconLoader>
28 #include <KImageFilePreview>
30 #include <KIO/NetAccess>
33 #include <KMessageBox>
35 #include <KConfigGroup>
36 #include <KStandardDirs>
38 #include <QButtonGroup>
39 #include <QDragEnterEvent>
43 #include <QPushButton>
44 #include <QRadioButton>
46 #include <QGridLayout>
47 #include <QHBoxLayout>
48 #include <QVBoxLayout>
50 extern KConfig
*config
;
52 KDMDialogWidget::KDMDialogWidget( QWidget
*parent
)
57 QGridLayout
*grid
= new QGridLayout( this );
58 grid
->setMargin( KDialog::marginHint() );
59 grid
->setSpacing( KDialog::spacingHint() );
60 grid
->setColumnStretch( 1, 1 );
62 QHBoxLayout
*hlay
= new QHBoxLayout();
63 hlay
->setSpacing( KDialog::spacingHint() );
64 grid
->addLayout( hlay
, 0, 0, 1, 2 );
65 greetstr_lined
= new KLineEdit( this );
66 QLabel
*label
= new QLabel( i18n("&Greeting:"), this );
67 label
->setBuddy( greetstr_lined
);
68 hlay
->addWidget( label
);
69 connect( greetstr_lined
, SIGNAL(textChanged( const QString
& )),
71 hlay
->addWidget( greetstr_lined
);
73 "<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 );
129 "Click here to choose an image that KDM will display. "
130 "You can also drag and drop an image onto this button "
131 "(e.g. from Konqueror).");
132 logoLabel
->setWhatsThis( wtstr
);
133 logobutton
->setWhatsThis( wtstr
);
136 vlay
= new QVBoxLayout();
137 grid
->addLayout( vlay
, 1, 1, 2, 1 );
138 vlay
->setParent( grid
);
140 label
= new QLabel( i18n("Dialog &position:"), this );
141 vlay
->addWidget( label
);
142 positioner
= new Positioner( this );
143 label
->setBuddy( positioner
);
144 connect( positioner
, SIGNAL(positionChanged()), SIGNAL(changed()) );
145 vlay
->addWidget( positioner
);
147 grid
->setRowStretch( 3, 1 );
151 void KDMDialogWidget::makeReadOnly()
153 disconnect( logobutton
, SIGNAL(clicked()),
154 this, SLOT(slotLogoButtonClicked()) );
155 logobutton
->setAcceptDrops( false );
156 greetstr_lined
->setReadOnly( true );
157 noneRadio
->setEnabled( false );
158 clockRadio
->setEnabled( false );
159 logoRadio
->setEnabled( false );
160 positioner
->makeReadOnly();
163 bool KDMDialogWidget::setLogo( const QString
&logo
)
165 QString flogo
= logo
.isEmpty() ?
166 KStandardDirs::locate( "data", QLatin1String("kdm/pics/kdelogo.png") ) :
171 if (p
.width() > 100 || p
.height() > 100)
172 p
= p
.scaled( 100, 100, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
173 logobutton
->setIcon( QPixmap::fromImage( p
) );
174 uint bd
= style()->pixelMetric( QStyle::PM_ButtonMargin
) * 2;
175 logobutton
->setFixedSize( p
.width() + bd
, p
.height() + bd
);
181 void KDMDialogWidget::slotLogoButtonClicked()
183 KFileDialog
dialog( KStandardDirs::locate( "data", QLatin1String("kdm/pics/") ),
184 KImageIO::pattern( KImageIO::Reading
),
186 dialog
.setOperationMode( KFileDialog::Opening
);
187 dialog
.setMode( KFile::File
| KFile::LocalOnly
);
189 KImageFilePreview
*imagePreview
= new KImageFilePreview( &dialog
);
190 dialog
.setPreviewWidget( imagePreview
);
191 if (dialog
.exec() == QDialog::Accepted
&&
192 setLogo( dialog
.selectedFile() ))
197 void KDMDialogWidget::slotAreaRadioClicked( int id
)
199 logobutton
->setEnabled( id
== KdmLogo
);
200 logoLabel
->setEnabled( id
== KdmLogo
);
204 bool KDMDialogWidget::eventFilter( QObject
*, QEvent
*e
)
206 if (e
->type() == QEvent::DragEnter
) {
207 iconLoaderDragEnterEvent( (QDragEnterEvent
*)e
);
211 if (e
->type() == QEvent::Drop
) {
212 iconLoaderDropEvent( (QDropEvent
*)e
);
219 void KDMDialogWidget::iconLoaderDragEnterEvent( QDragEnterEvent
*e
)
221 e
->setAccepted( KUrl::List::canDecode( e
->mimeData() ) );
225 KUrl
*decodeImgDrop( QDropEvent
*e
, QWidget
*wdg
);
227 void KDMDialogWidget::iconLoaderDropEvent( QDropEvent
*e
)
232 KUrl
*url
= decodeImgDrop( e
, this );
235 // we gotta check if it is a non-local file and make a tmp copy at the hd.
236 if (!url
->isLocalFile()) {
237 pixurl
.setPath( KStandardDirs::installPath( "data" ) +
238 "kdm/pics/" + url
->fileName() );
239 KIO::NetAccess::file_copy( *url
, pixurl
, parentWidget() );
246 // By now url should be "file:/..."
247 if (!setLogo( pixurl
.path() )) {
248 KIO::NetAccess::del( pixurl
, parentWidget() );
249 QString msg
= i18n("There was an error loading the image:\n"
251 "It will not be saved.",
253 KMessageBox::sorry( this, msg
);
261 void KDMDialogWidget::save()
263 KConfigGroup configGrp
= config
->group( "X-*-Greeter" );
265 configGrp
.writeEntry( "GreetString", greetstr_lined
->text() );
267 configGrp
.writeEntry( "LogoArea", noneRadio
->isChecked() ? "None" :
268 logoRadio
->isChecked() ? "Logo" : "Clock" );
270 configGrp
.writeEntry( "LogoPixmap",
271 KIconLoader::global()->iconPath( logopath
, KIconLoader::Desktop
, true ) );
273 configGrp
.writeEntry( "GreeterPos",
274 QString("%1,%2").arg( positioner
->x() ).arg( positioner
->y() ) );
278 void KDMDialogWidget::load()
280 KConfigGroup configGrp
= config
->group( "X-*-Greeter" );
282 // Read the greeting string
283 greetstr_lined
->setText( configGrp
.readEntry( "GreetString",
284 i18n("Welcome to %s at %n") ) );
286 // Regular logo or clock
287 QString logoArea
= configGrp
.readEntry( "LogoArea", "Logo" );
288 if (logoArea
== "Clock") {
289 clockRadio
->setChecked( true );
290 slotAreaRadioClicked( KdmClock
);
291 } else if (logoArea
== "Logo") {
292 logoRadio
->setChecked( true );
293 slotAreaRadioClicked( KdmLogo
);
295 noneRadio
->setChecked( true );
296 slotAreaRadioClicked( KdmNone
);
299 // See if we use alternate logo
300 setLogo( configGrp
.readEntry( "LogoPixmap" ) );
302 QStringList sl
= configGrp
.readEntry( "GreeterPos", QStringList() );
304 positioner
->setPosition( 50, 50 );
306 positioner
->setPosition( sl
.first().toInt(), sl
.last().toInt() );
310 void KDMDialogWidget::defaults()
312 greetstr_lined
->setText( i18n("Welcome to %s at %n") );
313 logoRadio
->setChecked( true );
314 slotAreaRadioClicked( KdmLogo
);
316 positioner
->setPosition( 50, 50 );
319 QString
KDMDialogWidget::quickHelp() const
322 "<h1>KDM - Dialog</h1> Here you can configure the basic appearance of "
323 "the KDM login manager in dialog mode, i.e. a greeting string, an icon etc.");
326 #include "kdm-dlg.moc"