3
This file is part of the KDE project, module kcmbackground.
5
Copyright (C) 1999 Geert Jansen <g.t.jansen@stud.tue.nl>
6
Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
version 2 as published by the Free Software Foundation.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public License
18
along with this library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
Boston, MA 02110-1301, USA.
23
#include <qbuttongroup.h>
24
#include <qcheckbox.h>
28
#include <qlineedit.h>
29
#include <qcombobox.h>
30
#include <qpushbutton.h>
33
#include <qwhatsthis.h>
36
#include <kcolorbutton.h>
38
#include <kmessagebox.h>
40
#include <kstandarddirs.h>
44
#include "bgadvanced.h"
45
#include "bgadvanced_ui.h"
49
/**** BGAdvancedDialog ****/
51
static QCString desktopConfigname()
55
desktop = DefaultScreen(qt_xdisplay());
60
name.sprintf("kdesktop-screen-%drc", desktop);
66
BGAdvancedDialog::BGAdvancedDialog(KBackgroundRenderer *_r,
69
: KDialogBase(parent, "BGAdvancedDialog",
70
true, i18n("Advanced Background Settings"),
71
Ok | Cancel, Ok, true),
74
dlg = new BGAdvancedBase(this);
77
dlg->m_listPrograms->header()->setStretchEnabled ( true, 1 );
78
dlg->m_listPrograms->setAllColumnsShowFocus(true);
80
connect(dlg->m_listPrograms, SIGNAL(clicked(QListViewItem *)),
81
SLOT(slotProgramItemClicked(QListViewItem *)));
84
QStringList lst = KBackgroundProgram::list();
85
QStringList::Iterator it;
86
for (it=lst.begin(); it != lst.end(); ++it)
91
KConfig cfg(desktopConfigname(), false, false);
92
cfg.setGroup( "General" );
93
if (!cfg.readBoolEntry( "Enabled", true ))
95
dlg->m_groupIconText->hide();
98
dlg->m_spinCache->setSteps(512, 1024);
99
dlg->m_spinCache->setRange(0, 40960);
100
dlg->m_spinCache->setSpecialValueText(i18n("Unlimited"));
101
dlg->m_spinCache->setSuffix(i18n(" KB"));
103
connect(dlg->m_buttonAdd, SIGNAL(clicked()),
105
connect(dlg->m_buttonRemove, SIGNAL(clicked()),
107
connect(dlg->m_buttonModify, SIGNAL(clicked()),
110
connect(dlg->m_listPrograms, SIGNAL(doubleClicked(QListViewItem *)),
111
SLOT(slotProgramItemDoubleClicked(QListViewItem *)));
115
dlg->m_buttonAdd->hide();
116
dlg->m_buttonRemove->hide();
117
dlg->m_buttonModify->hide();
118
dlg->m_groupIconText->hide();
119
dlg->m_groupCache->hide();
122
connect( dlg->m_cbProgram, SIGNAL(toggled(bool)),
123
SLOT(slotEnableProgram(bool)));
125
m_backgroundMode = m_oldBackgroundMode = r->backgroundMode();
126
if (m_oldBackgroundMode == KBackgroundSettings::Program)
127
m_oldBackgroundMode = KBackgroundSettings::Flat;
133
void BGAdvancedDialog::makeReadOnly()
135
dlg->m_cbProgram->setEnabled(false);
136
dlg->m_listPrograms->setEnabled(false);
139
void BGAdvancedDialog::setCacheSize(int s)
141
dlg->m_spinCache->setValue(s);
144
int BGAdvancedDialog::cacheSize()
146
return dlg->m_spinCache->value();
149
QColor BGAdvancedDialog::textColor()
151
return dlg->m_colorText->color();
154
void BGAdvancedDialog::setTextColor(const QColor &color)
156
dlg->m_colorText->setColor(color);
159
QColor BGAdvancedDialog::textBackgroundColor()
161
return dlg->m_cbSolidTextBackground->isChecked() ?
162
dlg->m_colorTextBackground->color() : QColor();
165
void BGAdvancedDialog::setTextBackgroundColor(const QColor &color)
167
dlg->m_colorTextBackground->blockSignals(true);
168
dlg->m_cbSolidTextBackground->blockSignals(true);
171
dlg->m_cbSolidTextBackground->setChecked(true);
172
dlg->m_colorTextBackground->setColor(color);
173
dlg->m_colorTextBackground->setEnabled(true);
177
dlg->m_cbSolidTextBackground->setChecked(false);
178
dlg->m_colorTextBackground->setColor(Qt::white);
179
dlg->m_colorTextBackground->setEnabled(false);
181
dlg->m_colorTextBackground->blockSignals(false);
182
dlg->m_cbSolidTextBackground->blockSignals(false);
185
bool BGAdvancedDialog::shadowEnabled()
187
return dlg->m_cbShadow->isChecked();
190
void BGAdvancedDialog::setShadowEnabled(bool enabled)
192
dlg->m_cbShadow->setChecked(enabled);
195
void BGAdvancedDialog::setTextLines(int lines)
197
dlg->m_spinTextLines->setValue(lines);
200
int BGAdvancedDialog::textLines() const
202
return dlg->m_spinTextLines->value();
205
void BGAdvancedDialog::setTextWidth(int width)
207
dlg->m_spinTextWidth->setValue(width);
210
int BGAdvancedDialog::textWidth() const
212
return dlg->m_spinTextWidth->value();
215
void BGAdvancedDialog::updateUI()
217
QString prog = r->KBackgroundProgram::name();
219
dlg->m_cbProgram->blockSignals(true);
220
if ((r->backgroundMode() == KBackgroundSettings::Program)
223
dlg->m_cbProgram->setChecked(true);
224
dlg->m_listPrograms->setEnabled(true);
225
dlg->m_buttonAdd->setEnabled(true);
226
dlg->m_buttonRemove->setEnabled(true);
227
dlg->m_buttonModify->setEnabled(true);
232
dlg->m_cbProgram->setChecked(false);
233
dlg->m_listPrograms->setEnabled(false);
234
dlg->m_buttonAdd->setEnabled(false);
235
dlg->m_buttonRemove->setEnabled(false);
236
dlg->m_buttonModify->setEnabled(false);
238
dlg->m_cbProgram->blockSignals(false);
241
void BGAdvancedDialog::removeProgram(const QString &name)
243
if (m_programItems.find(name))
245
delete m_programItems[name];
246
m_programItems.remove(name);
250
void BGAdvancedDialog::addProgram(const QString &name)
254
KBackgroundProgram prog(name);
255
if (prog.command().isEmpty() || (prog.isGlobal() && !prog.isAvailable()))
258
QListViewItem *item = new QListViewItem(dlg->m_listPrograms);
259
item->setText(0, prog.name());
260
item->setText(1, prog.comment());
261
item->setText(2, i18n("%1 min.").arg(prog.refresh()));
263
m_programItems.insert(name, item);
266
void BGAdvancedDialog::selectProgram(const QString &name)
268
if (m_programItems.find(name))
270
QListViewItem *item = m_programItems[name];
271
dlg->m_listPrograms->ensureItemVisible(item);
272
dlg->m_listPrograms->setSelected(item, true);
273
m_selectedProgram = name;
277
void BGAdvancedDialog::slotAdd()
279
KProgramEditDialog dlg;
281
if (dlg.result() == QDialog::Accepted)
283
QString program = dlg.program();
285
selectProgram(program);
289
void BGAdvancedDialog::slotRemove()
291
if (m_selectedProgram.isEmpty())
294
KBackgroundProgram prog(m_selectedProgram);
297
KMessageBox::sorry(this,
298
i18n("Unable to remove the program: the program is global "
299
"and can only be removed by the system administrator."),
300
i18n("Cannot Remove Program"));
303
if (KMessageBox::warningContinueCancel(this,
304
i18n("Are you sure you want to remove the program `%1'?")
306
i18n("Remove Background Program"),
307
i18n("&Remove")) != KMessageBox::Continue)
311
removeProgram(m_selectedProgram);
312
m_selectedProgram = QString::null;
318
void BGAdvancedDialog::slotModify()
320
if (m_selectedProgram.isEmpty())
323
KProgramEditDialog dlg(m_selectedProgram);
325
if (dlg.result() == QDialog::Accepted)
327
QString program = dlg.program();
328
if (program != m_selectedProgram)
330
KBackgroundProgram prog(m_selectedProgram);
332
removeProgram(m_selectedProgram);
334
addProgram(dlg.program());
335
selectProgram(dlg.program());
339
void BGAdvancedDialog::slotProgramItemClicked(QListViewItem *item)
342
m_selectedProgram = item->text(0);
343
slotProgramChanged();
346
void BGAdvancedDialog::slotProgramItemDoubleClicked(QListViewItem *item)
348
slotProgramItemClicked(item);
352
void BGAdvancedDialog::slotProgramChanged()
354
if (dlg->m_cbProgram->isChecked() && !m_selectedProgram.isEmpty())
355
m_backgroundMode = KBackgroundSettings::Program;
357
m_backgroundMode = m_oldBackgroundMode;
360
void BGAdvancedDialog::slotEnableProgram(bool b)
362
dlg->m_listPrograms->setEnabled(b);
365
dlg->m_listPrograms->blockSignals(true);
366
QListViewItem *cur = dlg->m_listPrograms->currentItem();
367
dlg->m_listPrograms->setSelected(cur, true);
368
dlg->m_listPrograms->ensureItemVisible(cur);
369
dlg->m_listPrograms->blockSignals(false);
370
slotProgramItemClicked(cur);
374
slotProgramChanged();
378
QString BGAdvancedDialog::backgroundProgram() const
380
return m_selectedProgram;
383
int BGAdvancedDialog::backgroundMode() const
385
return m_backgroundMode;
388
/**** KProgramEditDialog ****/
390
KProgramEditDialog::KProgramEditDialog(const QString &program, QWidget *parent, char *name)
391
: KDialogBase(parent, name, true, i18n("Configure Background Program"),
392
Ok | Cancel, Ok, true)
394
QFrame *frame = makeMainWidget();
396
QGridLayout *grid = new QGridLayout(frame, 6, 2, 0, spacingHint());
397
grid->addColSpacing(1, 300);
399
QLabel *lbl = new QLabel(i18n("&Name:"), frame);
400
grid->addWidget(lbl, 0, 0);
401
m_NameEdit = new QLineEdit(frame);
402
lbl->setBuddy(m_NameEdit);
403
grid->addWidget(m_NameEdit, 0, 1);
405
lbl = new QLabel(i18n("Co&mment:"), frame);
406
grid->addWidget(lbl, 1, 0);
407
m_CommentEdit = new QLineEdit(frame);
408
lbl->setBuddy(m_CommentEdit);
409
grid->addWidget(m_CommentEdit, 1, 1);
411
lbl = new QLabel(i18n("Comman&d:"), frame);
412
grid->addWidget(lbl, 2, 0);
413
m_CommandEdit = new QLineEdit(frame);
414
lbl->setBuddy(m_CommandEdit);
415
grid->addWidget(m_CommandEdit, 2, 1);
417
lbl = new QLabel(i18n("&Preview cmd:"), frame);
418
grid->addWidget(lbl, 3, 0);
419
m_PreviewEdit = new QLineEdit(frame);
420
lbl->setBuddy(m_PreviewEdit);
421
grid->addWidget(m_PreviewEdit, 3, 1);
423
lbl = new QLabel(i18n("&Executable:"), frame);
424
grid->addWidget(lbl, 4, 0);
425
m_ExecEdit = new QLineEdit(frame);
426
lbl->setBuddy(m_ExecEdit);
427
grid->addWidget(m_ExecEdit, 4, 1);
429
lbl = new QLabel(i18n("&Refresh time:"), frame);
430
grid->addWidget(lbl, 5, 0);
431
m_RefreshEdit = new QSpinBox(frame);
432
m_RefreshEdit->setRange(5, 60);
433
m_RefreshEdit->setSteps(5, 10);
434
m_RefreshEdit->setSuffix(i18n(" min"));
435
m_RefreshEdit->setFixedSize(m_RefreshEdit->sizeHint());
436
lbl->setBuddy(m_RefreshEdit);
437
grid->addWidget(m_RefreshEdit, 5, 1, AlignLeft);
440
if (m_Program.isEmpty()) {
441
KBackgroundProgram prog(i18n("New Command"));
443
while (!prog.command().isEmpty())
444
prog.load(i18n("New Command <%1>").arg(i++));
445
m_NameEdit->setText(prog.name());
446
m_NameEdit->setSelection(0, 100);
447
m_RefreshEdit->setValue(15);
451
// Fill in the fields
452
m_NameEdit->setText(m_Program);
453
KBackgroundProgram prog(m_Program);
454
m_CommentEdit->setText(prog.comment());
455
m_ExecEdit->setText(prog.executable());
456
m_CommandEdit->setText(prog.command());
457
m_PreviewEdit->setText(prog.previewCommand());
458
m_RefreshEdit->setValue(prog.refresh());
462
QString KProgramEditDialog::program()const
464
return m_NameEdit->text();
467
void KProgramEditDialog::slotOk()
469
QString s = m_NameEdit->text();
471
KMessageBox::sorry(this, i18n("You did not fill in the `Name' field.\n"
472
"This is a required field."));
476
KBackgroundProgram prog(s);
477
if ((s != m_Program) && !prog.command().isEmpty()) {
478
int ret = KMessageBox::warningContinueCancel(this,
479
i18n("There is already a program with the name `%1'.\n"
480
"Do you want to overwrite it?").arg(s),QString::null,i18n("Overwrite"));
481
if (ret != KMessageBox::Continue)
485
if (m_ExecEdit->text().isEmpty()) {
486
KMessageBox::sorry(this, i18n("You did not fill in the `Executable' field.\n"
487
"This is a required field."));
490
if (m_CommandEdit->text().isEmpty()) {
491
KMessageBox::sorry(this, i18n("You did not fill in the `Command' field.\n"
492
"This is a required field."));
496
prog.setComment(m_CommentEdit->text());
497
prog.setExecutable(m_ExecEdit->text());
498
prog.setCommand(m_CommandEdit->text());
499
prog.setPreviewCommand(m_PreviewEdit->text());
500
prog.setRefresh(m_RefreshEdit->value());
502
prog.writeSettings();
507
#include "bgadvanced.moc"