Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kcontrol / launch / kcmlaunch.cpp
blob6ea4c83e0f0fe6a00d2a325a6f1896179136fd8c
1 /*
2 * Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
18 #include <QCheckBox>
19 #include <QComboBox>
20 #include <QLabel>
21 #include <QGroupBox>
23 //Added by qt3to4:
24 #include <QVBoxLayout>
25 #include <QGridLayout>
27 #include <kapplication.h>
28 #include <klocale.h>
29 #include <kconfig.h>
30 #include <kdialog.h>
31 #include <knuminput.h>
33 #include "kcmlaunch.h"
34 #include "krunner_interface.h"
35 #include <KPluginFactory>
36 #include <KPluginLoader>
38 K_PLUGIN_FACTORY(LaunchFactory,
39 registerPlugin<LaunchConfig>();
41 K_EXPORT_PLUGIN(LaunchFactory("kcmlaunch"))
44 LaunchConfig::LaunchConfig(QWidget * parent, const QVariantList &)
45 : KCModule(LaunchFactory::componentData(), parent)
47 QVBoxLayout* Form1Layout = new QVBoxLayout( this );
48 Form1Layout->setMargin( 0 );
49 Form1Layout->setSpacing( KDialog::spacingHint() );
51 setQuickHelp( i18n ( "<h1>Launch Feedback</h1>"
52 " You can configure the application-launch feedback here." ) );
54 QGroupBox* GroupBox1 = new QGroupBox(i18n( "Bus&y Cursor" ));
55 GroupBox1->setWhatsThis( i18n(
56 "<h1>Busy Cursor</h1>\n"
57 "KDE offers a busy cursor for application startup notification.\n"
58 "To enable the busy cursor, select one kind of visual feedback\n"
59 "from the combobox.\n"
60 "It may occur, that some applications are not aware of this startup\n"
61 "notification. In this case, the cursor stops blinking after the time\n"
62 "given in the section 'Startup indication timeout'"));
64 QVBoxLayout *lay = new QVBoxLayout;
65 lay->setSpacing( 0 );
66 lay->setMargin( 0 );
67 GroupBox1->setLayout(lay);
68 Form1Layout->addWidget(GroupBox1);
70 QGridLayout* GroupBox1Layout = new QGridLayout();
71 GroupBox1->layout()->addItem( GroupBox1Layout );
72 GroupBox1Layout->setSpacing( 6 );
73 GroupBox1Layout->setMargin( 11 );
74 GroupBox1Layout->setColumnStretch( 1, 1 );
76 cb_busyCursor = new QComboBox( GroupBox1);
77 cb_busyCursor->setObjectName( "cb_busyCursor" );
78 cb_busyCursor->insertItem( 0, i18n( "No Busy Cursor" ) );
79 cb_busyCursor->insertItem( 1, i18n( "Passive Busy Cursor" ) );
80 cb_busyCursor->insertItem( 2, i18n( "Blinking Cursor" ) );
81 cb_busyCursor->insertItem( 3, i18n( "Bouncing Cursor" ) );
82 GroupBox1Layout->addWidget( cb_busyCursor, 0, 0 );
83 connect( cb_busyCursor, SIGNAL( activated(int) ),
84 SLOT ( slotBusyCursor(int)));
85 connect( cb_busyCursor, SIGNAL( activated(int) ), SLOT( checkChanged() ) );
87 lbl_cursorTimeout = new QLabel( GroupBox1 );
88 lbl_cursorTimeout->setObjectName( "TextLabel1" );
89 lbl_cursorTimeout->setText( i18n( "&Startup indication timeout:" ) );
90 GroupBox1Layout->addWidget( lbl_cursorTimeout, 2, 0 );
91 sb_cursorTimeout = new KIntNumInput( GroupBox1);
92 sb_cursorTimeout->setRange( 0, 99 );
93 sb_cursorTimeout->setSuffix( i18n(" sec") );
94 GroupBox1Layout->addWidget( sb_cursorTimeout, 2, 1 );
95 lbl_cursorTimeout->setBuddy( sb_cursorTimeout );
96 connect( sb_cursorTimeout, SIGNAL( valueChanged(int) ),
97 SLOT( checkChanged() ) );
99 QGroupBox* GroupBox2 = new QGroupBox( i18n( "Taskbar &Notification" ) );
100 GroupBox2->setWhatsThis( i18n("<H1>Taskbar Notification</H1>\n"
101 "You can enable a second method of startup notification which is\n"
102 "used by the taskbar where a button with a rotating hourglass appears,\n"
103 "symbolizing that your started application is loading.\n"
104 "It may occur, that some applications are not aware of this startup\n"
105 "notification. In this case, the button disappears after the time\n"
106 "given in the section 'Startup indication timeout'"));
108 lay = new QVBoxLayout;
109 lay->setSpacing( 0 );
110 lay->setMargin( 0 );
111 GroupBox2->setLayout(lay);
112 Form1Layout->addWidget( GroupBox2 );
113 QGridLayout* GroupBox2Layout = new QGridLayout();
114 GroupBox2->layout()->addItem( GroupBox2Layout );
115 GroupBox2Layout->setSpacing( 6 );
116 GroupBox2Layout->setMargin( 11 );
117 GroupBox2Layout->setColumnStretch( 1, 1 );
119 cb_taskbarButton = new QCheckBox( GroupBox2 );
120 cb_taskbarButton->setObjectName( "cb_taskbarButton" );
121 cb_taskbarButton->setText( i18n( "Enable &taskbar notification" ) );
122 GroupBox2Layout->addWidget( cb_taskbarButton, 0, 0, 1, 2 );
123 connect( cb_taskbarButton, SIGNAL( toggled(bool) ),
124 SLOT( slotTaskbarButton(bool)));
125 connect( cb_taskbarButton, SIGNAL( toggled(bool) ), SLOT( checkChanged()));
127 lbl_taskbarTimeout = new QLabel( GroupBox2 );
128 lbl_taskbarTimeout->setObjectName( "TextLabel2" );
129 lbl_taskbarTimeout->setText( i18n( "Start&up indication timeout:" ) );
130 GroupBox2Layout->addWidget( lbl_taskbarTimeout, 1, 0 );
131 sb_taskbarTimeout = new KIntNumInput( GroupBox2);
132 sb_taskbarTimeout->setRange( 0, 99 );
133 sb_taskbarTimeout->setSuffix( i18n(" sec") );
134 GroupBox2Layout->addWidget( sb_taskbarTimeout, 1, 1 );
135 lbl_taskbarTimeout->setBuddy( sb_taskbarTimeout );
136 connect( sb_taskbarTimeout, SIGNAL( valueChanged(int) ),
137 SLOT( checkChanged() ) );
139 Form1Layout->addStretch();
141 load();
144 LaunchConfig::~LaunchConfig()
148 void
149 LaunchConfig::slotBusyCursor(int i)
151 lbl_cursorTimeout->setEnabled( i != 0 );
152 sb_cursorTimeout->setEnabled( i != 0 );
155 void
156 LaunchConfig::slotTaskbarButton(bool b)
158 lbl_taskbarTimeout->setEnabled( b );
159 sb_taskbarTimeout->setEnabled( b );
162 void
163 LaunchConfig::load()
165 KConfig conf("klaunchrc", KConfig::NoGlobals);
166 KConfigGroup c = conf.group("FeedbackStyle");
168 bool busyCursor =
169 c.readEntry("BusyCursor", (Default & BusyCursor));
171 bool taskbarButton =
172 c.readEntry("TaskbarButton", (Default & TaskbarButton));
174 cb_taskbarButton->setChecked(taskbarButton);
176 c= conf.group( "BusyCursorSettings" );
177 sb_cursorTimeout->setValue( c.readEntry( "Timeout", 30 ));
178 bool busyBlinking =c.readEntry("Blinking", false);
179 bool busyBouncing =c.readEntry("Bouncing", true);
180 if ( !busyCursor )
181 cb_busyCursor->setCurrentIndex(0);
182 else if ( busyBlinking )
183 cb_busyCursor->setCurrentIndex(2);
184 else if ( busyBouncing )
185 cb_busyCursor->setCurrentIndex(3);
186 else
187 cb_busyCursor->setCurrentIndex(1);
189 c= conf.group( "TaskbarButtonSettings" );
190 sb_taskbarTimeout->setValue( c.readEntry( "Timeout", 30 ));
192 slotBusyCursor( cb_busyCursor->currentIndex() );
193 slotTaskbarButton( taskbarButton );
195 emit changed( false );
198 void
199 LaunchConfig::save()
201 KConfig conf("klaunchrc", KConfig::NoGlobals);
202 KConfigGroup c = conf.group("FeedbackStyle");
204 c.writeEntry("BusyCursor", cb_busyCursor->currentIndex() != 0);
205 c.writeEntry("TaskbarButton", cb_taskbarButton->isChecked());
207 c = conf.group("BusyCursorSettings");
208 c.writeEntry( "Timeout", sb_cursorTimeout->value());
209 c.writeEntry("Blinking", cb_busyCursor->currentIndex() == 2);
210 c.writeEntry("Bouncing", cb_busyCursor->currentIndex() == 3);
212 c = conf.group("TaskbarButtonSettings");
213 c.writeEntry( "Timeout", sb_taskbarTimeout->value());
215 c.sync();
217 emit changed( false );
219 org::kde::krunner::App desktop("org.kde.krunner", "/App", QDBusConnection::sessionBus());
220 desktop.initializeStartupNotification();
221 //TODO: do we need to replace this with a call to plasma to kick over the taskbar? needs
222 //investigating
223 //QDBusInterface kicker("org.kde.kicker", "/Panel", "org.kde.kicker.Panel");
224 //kicker.call("restart");
227 void
228 LaunchConfig::defaults()
230 cb_busyCursor->setCurrentIndex(2);
231 cb_taskbarButton->setChecked(Default & TaskbarButton);
233 sb_cursorTimeout->setValue( 30 );
234 sb_taskbarTimeout->setValue( 30 );
236 slotBusyCursor( 2 );
237 slotTaskbarButton( Default & TaskbarButton );
239 checkChanged();
242 void
243 LaunchConfig::checkChanged()
245 KConfig conf("klaunchrc", KConfig::NoGlobals);
246 KConfigGroup c = conf.group("FeedbackStyle");
248 bool savedBusyCursor =
249 c.readEntry("BusyCursor", (Default & BusyCursor));
251 bool savedTaskbarButton =
252 c.readEntry("TaskbarButton", (Default & TaskbarButton));
254 c = conf.group("BusyCursorSettings");
255 unsigned int savedCursorTimeout = c.readEntry( "Timeout", 30 );
256 bool savedBusyBlinking =c.readEntry("Blinking", false);
257 bool savedBusyBouncing =c.readEntry("Bouncing", true);
259 c = conf.group("TaskbarButtonSettings");
260 unsigned int savedTaskbarTimeout = c.readEntry( "Timeout", 30 );
262 bool newBusyCursor =cb_busyCursor->currentIndex()!=0;
264 bool newTaskbarButton =cb_taskbarButton->isChecked();
266 bool newBusyBlinking= cb_busyCursor->currentIndex()==2;
267 bool newBusyBouncing= cb_busyCursor->currentIndex()==3;
269 unsigned int newCursorTimeout = sb_cursorTimeout->value();
271 unsigned int newTaskbarTimeout = sb_taskbarTimeout->value();
273 emit changed(
274 savedBusyCursor != newBusyCursor
276 savedTaskbarButton != newTaskbarButton
278 savedCursorTimeout != newCursorTimeout
280 savedTaskbarTimeout != newTaskbarTimeout
282 savedBusyBlinking != newBusyBlinking
284 savedBusyBouncing != newBusyBouncing
288 #include "kcmlaunch.moc"