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.
24
#include <QHeaderView>
27
#include <QPushButton>
30
#include <QGridLayout>
33
#include <kcolorbutton.h>
35
#include <kmessagebox.h>
36
#include <kstandarddirs.h>
39
#include "bgadvanced.h"
44
/**** BGAdvancedDialog ****/
46
BGAdvancedDialog::BGAdvancedDialog(KBackgroundRenderer *_r,
51
setObjectName("BGAdvancedDialog");
53
setCaption(i18n("Advanced Background Settings"));
54
setButtons(Ok | Cancel);
56
dlg = new BGAdvancedBase(this);
59
dlg->m_listPrograms->header()->setResizeMode(1, QHeaderView::Stretch);
60
dlg->m_listPrograms->setRootIsDecorated(false);
61
dlg->m_listPrograms->setAllColumnsShowFocus(true);
63
connect(dlg->m_listPrograms, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
64
SLOT(slotProgramItemClicked(QTreeWidgetItem *)));
67
const QStringList lst = KBackgroundProgram::list();
68
QStringList::const_iterator it;
69
for (it = lst.constBegin(); it != lst.constEnd(); ++it)
72
// FIXME: support it proper
73
dlg->m_buttonAdd->hide();
74
dlg->m_buttonRemove->hide();
75
dlg->m_buttonModify->hide();
76
dlg->m_groupCache->hide();
78
connect(dlg->m_cbProgram, SIGNAL(toggled(bool)),
79
SLOT(slotEnableProgram(bool)));
81
m_oldBackgroundMode = r->backgroundMode();
82
if (m_oldBackgroundMode == KBackgroundSettings::Program)
83
m_oldBackgroundMode = KBackgroundSettings::Flat;
89
void BGAdvancedDialog::makeReadOnly()
91
dlg->m_cbProgram->setEnabled(false);
92
dlg->m_listPrograms->setEnabled(false);
96
void BGAdvancedDialog::setCacheSize(int s)
98
dlg->m_spinCache->setValue(s);
101
int BGAdvancedDialog::cacheSize()
103
return dlg->m_spinCache->value();
106
QColor BGAdvancedDialog::textColor()
108
return dlg->m_colorText->color();
111
void BGAdvancedDialog::setTextColor(const QColor &color)
113
dlg->m_colorText->setColor(color);
116
QColor BGAdvancedDialog::textBackgroundColor()
118
return dlg->m_cbSolidTextBackground->isChecked() ?
119
dlg->m_colorTextBackground->color() : QColor();
122
void BGAdvancedDialog::setTextBackgroundColor(const QColor &color)
124
dlg->m_colorTextBackground->blockSignals(true);
125
dlg->m_cbSolidTextBackground->blockSignals(true);
126
if (color.isValid()) {
127
dlg->m_cbSolidTextBackground->setChecked(true);
128
dlg->m_colorTextBackground->setColor(color);
129
dlg->m_colorTextBackground->setEnabled(true);
131
dlg->m_cbSolidTextBackground->setChecked(false);
132
dlg->m_colorTextBackground->setColor(Qt::white);
133
dlg->m_colorTextBackground->setEnabled(false);
135
dlg->m_colorTextBackground->blockSignals(false);
136
dlg->m_cbSolidTextBackground->blockSignals(false);
139
bool BGAdvancedDialog::shadowEnabled()
141
return dlg->m_cbShadow->isChecked();
144
void BGAdvancedDialog::setShadowEnabled(bool enabled)
146
dlg->m_cbShadow->setChecked(enabled);
149
void BGAdvancedDialog::setTextLines(int lines)
151
dlg->m_spinTextLines->setValue(lines);
154
int BGAdvancedDialog::textLines() const
156
return dlg->m_spinTextLines->value();
159
void BGAdvancedDialog::setTextWidth(int width)
161
dlg->m_spinTextWidth->setValue(width);
164
int BGAdvancedDialog::textWidth() const
166
return dlg->m_spinTextWidth->value();
170
void BGAdvancedDialog::updateUI()
172
QString prog = r->KBackgroundProgram::name();
174
dlg->m_cbProgram->blockSignals(true);
175
if ((r->backgroundMode() == KBackgroundSettings::Program)
176
&& !prog.isEmpty()) {
177
dlg->m_cbProgram->setChecked(true);
178
dlg->m_listPrograms->setEnabled(true);
179
dlg->m_buttonAdd->setEnabled(true);
180
dlg->m_buttonRemove->setEnabled(true);
181
dlg->m_buttonModify->setEnabled(true);
184
dlg->m_cbProgram->setChecked(false);
185
dlg->m_listPrograms->setEnabled(false);
186
dlg->m_buttonAdd->setEnabled(false);
187
dlg->m_buttonRemove->setEnabled(false);
188
dlg->m_buttonModify->setEnabled(false);
190
dlg->m_cbProgram->blockSignals(false);
194
void BGAdvancedDialog::removeProgram(const QString &name)
196
delete m_programItems.take(name);
200
void BGAdvancedDialog::addProgram(const QString &name)
206
KBackgroundProgram prog(name);
207
if (prog.command().isEmpty() || (prog.isGlobal() && !prog.isAvailable()))
210
QTreeWidgetItem *item = new QTreeWidgetItem(dlg->m_listPrograms);
211
item->setText(0, prog.name());
212
item->setText(1, prog.comment());
213
item->setText(2, i18n("%1 min.", prog.refresh()));
215
m_programItems.insert(name, item);
218
void BGAdvancedDialog::selectProgram(const QString &name)
220
if (QTreeWidgetItem *item = m_programItems[name]) {
221
dlg->m_listPrograms->scrollToItem(item);
222
item->setSelected(true);
223
m_selectedProgram = name;
228
void BGAdvancedDialog::slotAdd()
230
KProgramEditDialog dlg(QString(), this);
232
if (dlg.result() == QDialog::Accepted) {
233
QString program = dlg.program();
235
selectProgram(program);
239
void BGAdvancedDialog::slotRemove()
241
if (m_selectedProgram.isEmpty())
244
KBackgroundProgram prog(m_selectedProgram);
245
if (prog.isGlobal()) {
246
KMessageBox::sorry(this,
247
i18n("Unable to remove the program: the program is global "
248
"and can only be removed by the system administrator."),
249
i18n("Cannot Remove Program"));
252
if (KMessageBox::warningContinueCancel(this,
253
i18n("Are you sure you want to remove the program `%1'?",
255
i18n("Remove Background Program"),
256
KGuiItem(i18n("&Remove"))) != KMessageBox::Continue)
260
removeProgram(m_selectedProgram);
261
m_selectedProgram.clear();
267
void BGAdvancedDialog::slotModify()
269
if (m_selectedProgram.isEmpty())
272
KProgramEditDialog dlg(m_selectedProgram, this);
274
if (dlg.result() == QDialog::Accepted) {
275
QString program = dlg.program();
276
if (program != m_selectedProgram) {
277
KBackgroundProgram prog(m_selectedProgram);
279
removeProgram(m_selectedProgram);
281
addProgram(dlg.program());
282
selectProgram(dlg.program());
287
void BGAdvancedDialog::slotProgramItemClicked(QTreeWidgetItem *item)
290
m_selectedProgram = item->text(0);
291
slotProgramChanged();
295
void BGAdvancedDialog::slotProgramItemDoubleClicked(QTreeWidgetItem *item)
297
slotProgramItemClicked(item);
302
void BGAdvancedDialog::slotProgramChanged()
306
r->setProgram(m_selectedProgram);
307
if (dlg->m_cbProgram->isChecked() && !m_selectedProgram.isEmpty())
308
r->setBackgroundMode(KBackgroundSettings::Program);
310
r->setBackgroundMode(m_oldBackgroundMode);
312
// We have no preview, no need to start the renderer
316
void BGAdvancedDialog::slotEnableProgram(bool b)
318
dlg->m_listPrograms->setEnabled(b);
320
if (QTreeWidgetItem *cur = dlg->m_listPrograms->currentItem()) {
321
dlg->m_listPrograms->blockSignals(true);
322
cur->setSelected(true);
323
dlg->m_listPrograms->scrollToItem(cur);
324
dlg->m_listPrograms->blockSignals(false);
325
slotProgramItemClicked(cur);
328
slotProgramChanged();
332
/**** KProgramEditDialog ****/
334
KProgramEditDialog::KProgramEditDialog(const QString &program, QWidget *parent, char *name)
339
setCaption(i18n("Configure Background Program"));
340
setButtons(Ok | Cancel);
342
QFrame *frame = new QFrame(this);
343
setMainWidget(frame);
345
QGridLayout *grid = new QGridLayout(frame);
346
grid->setSpacing(spacingHint());
348
grid->setColumnMinimumWidth(1, 300);
350
QLabel *lbl = new QLabel(i18n("&Name:"), frame);
351
grid->addWidget(lbl, 0, 0);
352
m_NameEdit = new QLineEdit(frame);
353
lbl->setBuddy(m_NameEdit);
354
grid->addWidget(m_NameEdit, 0, 1);
356
lbl = new QLabel(i18n("Co&mment:"), frame);
357
grid->addWidget(lbl, 1, 0);
358
m_CommentEdit = new QLineEdit(frame);
359
lbl->setBuddy(m_CommentEdit);
360
grid->addWidget(m_CommentEdit, 1, 1);
362
lbl = new QLabel(i18n("Comman&d:"), frame);
363
grid->addWidget(lbl, 2, 0);
364
m_CommandEdit = new QLineEdit(frame);
365
lbl->setBuddy(m_CommandEdit);
366
grid->addWidget(m_CommandEdit, 2, 1);
368
lbl = new QLabel(i18n("&Preview cmd:"), frame);
369
grid->addWidget(lbl, 3, 0);
370
m_PreviewEdit = new QLineEdit(frame);
371
lbl->setBuddy(m_PreviewEdit);
372
grid->addWidget(m_PreviewEdit, 3, 1);
374
lbl = new QLabel(i18n("&Executable:"), frame);
375
grid->addWidget(lbl, 4, 0);
376
m_ExecEdit = new QLineEdit(frame);
377
lbl->setBuddy(m_ExecEdit);
378
grid->addWidget(m_ExecEdit, 4, 1);
380
lbl = new QLabel(i18n("&Refresh time:"), frame);
381
grid->addWidget(lbl, 5, 0);
382
m_RefreshEdit = new QSpinBox(frame);
383
m_RefreshEdit->setRange(5, 60);
384
m_RefreshEdit->setSingleStep(5);
385
m_RefreshEdit->setSuffix(i18n(" min"));
386
m_RefreshEdit->setFixedSize(m_RefreshEdit->sizeHint());
387
lbl->setBuddy(m_RefreshEdit);
388
grid->addWidget(m_RefreshEdit, 5, 1, Qt::AlignLeft);
391
if (m_Program.isEmpty()) {
392
KBackgroundProgram prog(i18n("New Command"));
394
while (!prog.command().isEmpty())
395
prog.load(i18n("New Command <%1>", i++));
396
m_NameEdit->setText(prog.name());
397
m_NameEdit->setSelection(0, 100);
398
m_RefreshEdit->setValue(15);
402
// Fill in the fields
403
m_NameEdit->setText(m_Program);
404
KBackgroundProgram prog(m_Program);
405
m_CommentEdit->setText(prog.comment());
406
m_ExecEdit->setText(prog.executable());
407
m_CommandEdit->setText(prog.command());
408
m_PreviewEdit->setText(prog.previewCommand());
409
m_RefreshEdit->setValue(prog.refresh());
413
QString KProgramEditDialog::program()const
415
return m_NameEdit->text();
418
void KProgramEditDialog::accept()
420
QString s = m_NameEdit->text();
422
KMessageBox::sorry(this, i18n("You did not fill in the `Name' field.\n"
423
"This is a required field."));
427
KBackgroundProgram prog(s);
428
if ((s != m_Program) && !prog.command().isEmpty()) {
429
int ret = KMessageBox::warningContinueCancel(this,
430
i18n("There is already a program with the name `%1'.\n"
431
"Do you want to overwrite it?", s), QString(), KGuiItem(i18n("Overwrite")));
432
if (ret != KMessageBox::Continue)
436
if (m_ExecEdit->text().isEmpty()) {
437
KMessageBox::sorry(this, i18n("You did not fill in the `Executable' field.\n"
438
"This is a required field."));
441
if (m_CommandEdit->text().isEmpty()) {
442
KMessageBox::sorry(this, i18n("You did not fill in the `Command' field.\n"
443
"This is a required field."));
447
prog.setComment(m_CommentEdit->text());
448
prog.setExecutable(m_ExecEdit->text());
449
prog.setCommand(m_CommandEdit->text());
450
prog.setPreviewCommand(m_PreviewEdit->text());
451
prog.setRefresh(m_RefreshEdit->value());
453
prog.writeSettings();
459
#include "bgadvanced.moc"