2 Copyright (C) 2000,2002 Carsten Pfeiffer <pfeiffer@kde.org>
3 Copyright (C) 2005,2006 Olivier Goffart <ogoffart at kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
24 #include <QRadioButton>
26 #include <QVBoxLayout>
28 #include <QHBoxLayout>
29 #include <QDBusInterface>
32 #include <kapplication.h>
33 #include <kaboutdata.h>
34 #include <kcombobox.h>
36 #include <knotifyconfigwidget.h>
37 #include <kpluginfactory.h>
38 #include <kpluginloader.h>
39 #include <kstandarddirs.h>
40 #include <kurlcompletion.h>
41 #include <kurlrequester.h>
45 #include "ui_playersettings.h"
47 static const int COL_FILENAME
= 1;
49 K_PLUGIN_FACTORY( NotifyFactory
, registerPlugin
<KCMKNotify
>(); )
50 K_EXPORT_PLUGIN( NotifyFactory("kcmnotify") )
52 KCMKNotify::KCMKNotify(QWidget
*parent
, const QVariantList
& )
53 : KCModule(NotifyFactory::componentData(), parent
/*, name*/),
54 m_playerSettings( 0L )
56 setButtons( Help
| Default
| Apply
);
58 setQuickHelp( i18n("<h1>System Notifications</h1>"
59 "KDE allows for a great deal of control over how you "
60 "will be notified when certain events occur. There are "
61 "several choices as to how you are notified:"
62 "<ul><li>As the application was originally designed.</li>"
63 "<li>With a beep or other noise.</li>"
64 "<li>Via a popup dialog box with additional information.</li>"
65 "<li>By recording the event in a logfile without "
66 "any additional visual or audible alert.</li>"
69 QVBoxLayout
*layout
= new QVBoxLayout( this );
70 layout
->setMargin( 0 );
71 layout
->setSpacing( KDialog::spacingHint() );
72 QTabWidget
*tab
= new QTabWidget(this);
73 layout
->addWidget(tab
);
75 QWidget
* app_tab
= new QWidget(tab
);
76 QVBoxLayout
*app_layout
= new QVBoxLayout( app_tab
);
78 QLabel
*label
= new QLabel( i18n( "Event source:" ), app_tab
);
79 m_appCombo
= new KComboBox( false, app_tab
);
80 m_appCombo
->setObjectName( "app combo" );
81 QHBoxLayout
*hbox
= new QHBoxLayout();
82 hbox
->setSpacing( KDialog::spacingHint() );
83 app_layout
->addItem( hbox
);
84 hbox
->addWidget( label
);
85 hbox
->addWidget( m_appCombo
, 10 );
87 m_notifyWidget
= new KNotifyConfigWidget( app_tab
);
88 app_layout
->addWidget( m_notifyWidget
);
90 connect( m_notifyWidget
, SIGNAL(changed(bool)), this, SIGNAL(changed(bool)));
92 m_playerSettings
= new PlayerSettingsDialog(tab
);
93 connect(m_playerSettings
, SIGNAL(changed(bool)) , this, SIGNAL(changed(bool)));
95 /* general->layout()->setMargin( KDialog::marginHint() );
96 hardware->layout()->setMargin( KDialog::marginHint() );*/
97 tab
->addTab(app_tab
, i18n("&Applications"));
98 tab
->addTab(m_playerSettings
, i18n("&Player Settings"));
100 connect( m_appCombo
, SIGNAL( activated( int ) ),
101 SLOT( slotAppActivated( int )) );
103 KAboutData
* ab
= new KAboutData(
104 "kcmknotify", 0, ki18n("KNotify"), "4.0",
105 ki18n("System Notification Control Panel Module"),
106 KAboutData::License_GPL
, ki18n("(c) 2002-2006 KDE Team"));
108 ab
->addAuthor( ki18n("Olivier Goffart"), KLocalizedString(), "ogoffart@kde.org" );
109 ab
->addAuthor( ki18n("Carsten Pfeiffer"), KLocalizedString(), "pfeiffer@kde.org" );
110 ab
->addCredit( ki18n("Charles Samuels"), ki18n("Original implementation"),
111 "charles@altair.dhs.org" );
115 KCMKNotify::~KCMKNotify()
117 KConfig
_config("knotifyrc", KConfig::NoGlobals
);
118 KConfigGroup
config(&_config
, "Misc" );
119 config
.writeEntry( "LastConfiguredApp", m_appCombo
->currentText() );
123 void KCMKNotify::slotAppActivated( int index
)
126 if(index
>=0 && index
< m_appNames
.size())
127 text
=m_appNames
[index
];
128 m_notifyWidget
->save();
129 m_notifyWidget
->setApplication( text
);
132 void KCMKNotify::slotPlayerSettings()
137 void KCMKNotify::defaults()
139 // m_notifyWidget->resetDefaults( true ); // ask user
140 m_playerSettings
->defaults();
142 void KCMKNotify::load()
144 //setEnabled( false );
145 // setCursor( KCursor::waitCursor() );
149 // m_notifyWidget->clear();
151 QStringList fullpaths
=
152 KGlobal::dirs()->findAllResources("data", "*/*.notifyrc", KStandardDirs::NoDuplicates
);
154 foreach (const QString
&fullPath
, fullpaths
)
156 int slash
= fullPath
.lastIndexOf( '/' ) - 1;
157 int slash2
= fullPath
.lastIndexOf( '/', slash
);
158 QString appname
= slash2
< 0 ? QString() : fullPath
.mid( slash2
+1 , slash
-slash2
);
159 if ( !appname
.isEmpty() )
161 KConfig
config(fullPath
, KConfig::NoGlobals
, "data" );
162 KConfigGroup
globalConfig( &config
, QString::fromLatin1("Global") );
163 QString icon
= globalConfig
.readEntry(QString::fromLatin1("IconName"), QString::fromLatin1("misc"));
164 QString description
= globalConfig
.readEntry( QString::fromLatin1("Comment"), appname
);
165 m_appCombo
->addItem( SmallIcon( icon
), description
);
166 m_appNames
.append( appname
);
170 KConfig config( "knotifyrc", true, false );
171 config.setGroup( "Misc" );
172 QString appDesc = config.readEntry( "LastConfiguredApp", "KDE System Notifications" );
174 if this code gets enabled again, make sure to apply r494965
176 if ( !appDesc.isEmpty() )
177 m_appCombo->setCurrentItem( appDesc );
179 // sets the applicationEvents for KNotifyWidget
180 slotAppActivated( m_appCombo->currentText() );
182 // unsetCursor(); // unsetting doesn't work. sigh.
184 emit changed( false );
187 m_playerSettings
->load();
189 if ( m_appNames
.count() > 0 )
190 m_notifyWidget
->setApplication( m_appNames
.at( 0 ) );
196 void KCMKNotify::save()
198 if ( m_playerSettings
)
199 m_playerSettings
->save();
201 m_notifyWidget
->save(); // will dcop knotify about its new config
203 emit
changed( true );
206 ///////////////////////////////////////////////////////////////////
207 ///////////////////////////////////////////////////////////////////
209 PlayerSettingsDialog::PlayerSettingsDialog( QWidget
*parent
)
210 : QWidget(parent
), m_change(false)
213 m_ui
= new Ui::PlayerSettingsUI();
214 m_ui
->setupUi( this );
218 connect( m_ui
->cbExternal
, SIGNAL( toggled( bool ) ), this, SLOT( externalToggled( bool ) ) );
219 connect( m_ui
->cbArts
, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
220 connect( m_ui
->cbExternal
, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
221 connect( m_ui
->cbNone
, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
222 connect( m_ui
->volumeSlider
, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
223 connect( m_ui
->reqExternal
, SIGNAL( textChanged( const QString
& ) ), this, SLOT( slotChanged() ) );
224 m_ui
->reqExternal
->setMode(KFile::File
|KFile::ExistingOnly
|KFile::LocalOnly
);
227 void PlayerSettingsDialog::load()
229 KConfig
_config( "knotifyrc", KConfig::NoGlobals
);
230 KConfigGroup
config(&_config
, "Sounds" );
231 bool useExternal
= config
.readEntry( "Use external player", false );
232 m_ui
->cbExternal
->setChecked( useExternal
);
233 m_ui
->reqExternal
->setPath( config
.readPathEntry( "External player", QString() ) );
234 m_ui
->volumeSlider
->setValue( config
.readEntry( "Volume", 100 ) );
236 if ( !m_ui
->cbExternal
->isChecked() )
238 m_ui
->cbNone
->setChecked( config
.readEntry( "No sound", false ) );
240 emit
changed( false );
244 void PlayerSettingsDialog::save()
249 // see kdebase/runtime/knotify/notifybysound.h
250 KConfig
_config("knotifyrc", KConfig::NoGlobals
);
251 KConfigGroup
config(&_config
, "Sounds" );
253 config
.writePathEntry( "External player", m_ui
->reqExternal
->url().path() );
254 config
.writeEntry( "Use external player", m_ui
->cbExternal
->isChecked() );
255 config
.writeEntry( "Volume", m_ui
->volumeSlider
->value() );
256 config
.writeEntry( "No sound", m_ui
->cbNone
->isChecked() );
260 QDBusInterface
itr("org.kde.knotify", "/Notify", "org.kde.KNotify", QDBusConnection::sessionBus(), this);
261 itr
.call("reconfigure");
266 void PlayerSettingsDialog::slotChanged()
272 void PlayerSettingsDialog::defaults()
274 m_ui
->cbArts
->setChecked(true);
279 void PlayerSettingsDialog::externalToggled( bool on
)
282 m_ui
->reqExternal
->setFocus();
284 m_ui
->reqExternal
->clearFocus();
287 PlayerSettingsDialog::~ PlayerSettingsDialog( )
292 #include "knotify.moc"