19 #include <dcopclient.h>
21 #include <tdeaboutdata.h>
22 #include <tdeapplication.h>
23 #include <kaudioplayer.h>
24 #include <kcombobox.h>
25 #include <tdeconfig.h>
28 #include <tdefiledialog.h>
29 #include <kiconloader.h>
30 #include <kicontheme.h>
31 #include <klineedit.h>
32 #include <tdelocale.h>
33 #include <tdemessagebox.h>
34 #include <knotifyclient.h>
35 #include <knotifydialog.h>
36 #include <kstandarddirs.h>
37 #include <kurlrequester.h>
38 #include <tdeio/netaccess.h>
40 #include <tqcheckbox.h>
41 #include <tqgroupbox.h>
44 #include <tqlistview.h>
46 #include <tqptrlist.h>
47 #include <tqpushbutton.h>
49 #include <tqtooltip.h>
52 #include <tqwhatsthis.h>
54 using namespace KNotify;
79 static void fill( KComboBox *combo )
81 combo->insertItem( i18n(
"Sounds") );
82 combo->insertItem( i18n(
"Logging") );
83 combo->insertItem( i18n(
"Program Execution") );
84 combo->insertItem( i18n(
"Message Windows") );
85 combo->insertItem( i18n(
"Passive Windows") );
86 combo->insertItem( i18n(
"Standard Error Output") );
87 combo->insertItem( i18n(
"Taskbar") );
90 static int type( KComboBox *combo )
92 switch( combo->currentItem() )
95 return KNotifyClient::Sound;
97 return KNotifyClient::Logfile;
99 return KNotifyClient::Execute;
101 return KNotifyClient::Messagebox;
103 return KNotifyClient::PassivePopup;
105 return KNotifyClient::Stderr;
107 return KNotifyClient::Taskbar;
110 return KNotifyClient::None;
115 class KNotifyToolTip :
public TQToolTip
118 KNotifyToolTip( TQHeader *header )
119 : TQToolTip( header )
121 m_tips[COL_EXECUTE] = i18n(
"Execute a program");
122 m_tips[COL_STDERR] = i18n(
"Print to Standard error output");
123 m_tips[COL_MESSAGE] = i18n(
"Display a messagebox");
124 m_tips[COL_LOGFILE] = i18n(
"Log to a file");
125 m_tips[COL_SOUND] = i18n(
"Play a sound");
126 m_tips[COL_TASKBAR] = i18n(
"Flash the taskbar entry");
128 virtual ~KNotifyToolTip() {}
131 virtual void maybeTip (
const TQPoint& p )
133 TQHeader *header =
static_cast<TQHeader*
>( parentWidget() );
136 if ( header->orientation() == TQt::Horizontal )
137 section= header->sectionAt( p.x() );
139 section= header->sectionAt( p.y() );
141 if ( ( section < 0 ) || (
static_cast<uint
>( section ) >= (
sizeof(m_tips) /
sizeof(TQString)) ) )
144 tip( header->sectionRect( section ), m_tips[section] );
155 const TDEAboutData *aboutData )
158 return dialog.exec();
162 const TDEAboutData *aboutData )
163 : KDialogBase(parent, name, modal, i18n(
"Notification Settings"),
164 Ok | Apply | Cancel | Default, Ok, true )
166 TQVBox *box = makeVBoxMainWidget();
168 m_notifyWidget =
new KNotifyWidget( box,
"knotify widget" );
173 connect(
this, TQ_SIGNAL( okClicked() ), m_notifyWidget, TQ_SLOT( save() ));
174 connect(
this, TQ_SIGNAL( applyClicked() ), m_notifyWidget, TQ_SLOT( save() ));
184 TQString::fromLatin1(
"/eventsrc" ) );
189 Application *app = m_notifyWidget->addApplicationEvents( path );
192 m_notifyWidget->addVisibleApp( app );
193 m_notifyWidget->sort();
199 m_notifyWidget->clear();
202 void KNotifyDialog::slotDefault()
204 m_notifyWidget->resetDefaults(
true );
212 class KNotifyWidget::Private
216 KNotifyToolTip *toolTip;
220 KNotifyWidget::KNotifyWidget( TQWidget *parent,
const char *name,
222 : KNotifyWidgetBase( parent, name ? name :
"KNotifyWidget" )
226 m_allApps.setAutoDelete(
true );
228 if ( !handleAllApps )
230 m_affectAllApps->hide();
231 m_playerButton->hide();
234 SelectionCombo::fill( m_comboEnable );
235 SelectionCombo::fill( m_comboDisable );
237 m_listview->setFullWidth(
true );
238 m_listview->setAllColumnsShowFocus(
true );
240 TQPixmap pexec = SmallIcon(
"application-x-executable");
241 TQPixmap pstderr = SmallIcon(
"terminal");
242 TQPixmap pmessage = SmallIcon(
"application-vnd.tde.info");
243 TQPixmap plogfile = SmallIcon(
"text-x-log");
244 TQPixmap psound = SmallIcon(
"audio-x-generic");
245 TQPixmap ptaskbar = SmallIcon(
"kicker");
247 d->pixmaps[COL_EXECUTE] = pexec;
248 d->pixmaps[COL_STDERR] = pstderr;
249 d->pixmaps[COL_MESSAGE] = pmessage;
250 d->pixmaps[COL_LOGFILE] = plogfile;
251 d->pixmaps[COL_SOUND] = psound;
252 d->pixmaps[COL_TASKBAR] = ptaskbar;
254 int w = TDEIcon::SizeSmall + 6;
256 TQHeader *header = m_listview->header();
257 header->setLabel( COL_EXECUTE, pexec, TQString::null, w );
258 header->setLabel( COL_STDERR, pstderr, TQString::null, w );
259 header->setLabel( COL_MESSAGE, pmessage, TQString::null, w );
260 header->setLabel( COL_LOGFILE, plogfile, TQString::null, w );
261 header->setLabel( COL_SOUND, psound, TQString::null, w );
262 header->setLabel( COL_TASKBAR, ptaskbar, TQString::null, w );
264 d->toolTip =
new KNotifyToolTip( header );
266 m_playButton->setIconSet( SmallIconSet(
"media-playback-start" ) );
267 connect( m_playButton, TQ_SIGNAL( clicked() ), TQ_SLOT( playSound() ));
269 connect( m_listview, TQ_SIGNAL( currentChanged( TQListViewItem * ) ),
270 TQ_SLOT( slotEventChanged( TQListViewItem * ) ));
271 connect( m_listview, TQ_SIGNAL(clicked( TQListViewItem *,
const TQPoint&,
int)),
272 TQ_SLOT( slotItemClicked( TQListViewItem *,
const TQPoint&,
int )));
274 connect( m_playSound, TQ_SIGNAL( toggled(
bool )),
275 TQ_SLOT( soundToggled(
bool )) );
276 connect( m_logToFile, TQ_SIGNAL( toggled(
bool )),
277 TQ_SLOT( loggingToggled(
bool )) );
278 connect( m_execute, TQ_SIGNAL( toggled(
bool )),
279 TQ_SLOT( executeToggled(
bool )) );
280 connect( m_messageBox, TQ_SIGNAL( toggled(
bool )),
281 TQ_SLOT( messageBoxChanged() ) );
282 connect( m_passivePopup, TQ_SIGNAL( toggled(
bool )),
283 TQ_SLOT( messageBoxChanged() ) );
284 connect( m_stderr, TQ_SIGNAL( toggled(
bool )),
285 TQ_SLOT( stderrToggled(
bool ) ) );
286 connect( m_taskbar, TQ_SIGNAL( toggled(
bool )),
287 TQ_SLOT( taskbarToggled(
bool ) ) );
289 connect( m_soundPath, TQ_SIGNAL( textChanged(
const TQString& )),
290 TQ_SLOT( soundFileChanged(
const TQString& )));
291 connect( m_logfilePath, TQ_SIGNAL( textChanged(
const TQString& )),
292 TQ_SLOT( logfileChanged(
const TQString& ) ));
293 connect( m_executePath, TQ_SIGNAL( textChanged(
const TQString& )),
294 TQ_SLOT( commandlineChanged(
const TQString& ) ));
296 connect( m_soundPath, TQ_SIGNAL( openFileDialog(
KURLRequester * )),
298 connect( m_logfilePath, TQ_SIGNAL( openFileDialog(
KURLRequester * )),
300 connect( m_executePath, TQ_SIGNAL( openFileDialog(
KURLRequester * )),
303 connect( m_extension, TQ_SIGNAL( clicked() ),
304 TQ_SLOT( toggleAdvanced()) );
306 connect( m_buttonEnable, TQ_SIGNAL( clicked() ), TQ_SLOT( enableAll() ));
307 connect( m_buttonDisable, TQ_SIGNAL( clicked() ), TQ_SLOT( enableAll() ));
309 TQString whatsThis = i18n(
"<qt>You may use the following macros<br>"
310 "in the commandline:<br>"
311 "<b>%e</b>: for the event name,<br>"
312 "<b>%a</b>: for the name of the application that sent the event,<br>"
313 "<b>%s</b>: for the notification message,<br>"
314 "<b>%w</b>: for the numeric window ID where the event originated,<br>"
315 "<b>%i</b>: for the numeric event ID.");
316 TQWhatsThis::add( m_execute, whatsThis );
317 TQWhatsThis::add( m_executePath, whatsThis );
319 showAdvanced(
false );
321 slotEventChanged( 0L );
324 KNotifyWidget::~KNotifyWidget()
330 void KNotifyWidget::toggleAdvanced()
332 showAdvanced( m_logToFile->isHidden() );
335 void KNotifyWidget::showAdvanced(
bool show )
339 m_extension->setText( i18n(
"Advanced <<") );
340 TQToolTip::add( m_extension, i18n(
"Hide advanced options") );
343 m_logfilePath->show();
345 m_executePath->show();
346 m_messageBox->show();
347 m_passivePopup->show();
351 m_passivePopup->setEnabled( m_messageBox->isChecked() );
352 m_actionsBoxLayout->setSpacing( KDialog::spacingHint() );
356 m_extension->setText( i18n(
"Advanced >>") );
357 TQToolTip::add( m_extension, i18n(
"Show advanced options") );
360 m_logfilePath->hide();
362 m_executePath->hide();
363 m_messageBox->hide();
364 m_passivePopup->hide();
368 m_actionsBoxLayout->setSpacing( 0 );
372 Application * KNotifyWidget::addApplicationEvents(
const TQString& path )
374 kdDebug() <<
"**** knotify: adding path: " << path << endl;
375 TQString relativePath = path;
377 if ( path.at(0) ==
'/' && TDEStandardDirs::exists( path ) )
378 relativePath = makeRelative( path );
380 if ( !relativePath.isEmpty() )
382 Application *app =
new Application( relativePath );
383 m_allApps.append( app );
390 void KNotifyWidget::clear()
396 void KNotifyWidget::clearVisible()
398 m_visibleApps.clear();
400 slotEventChanged( 0L );
403 void KNotifyWidget::showEvent( TQShowEvent *e )
405 selectItem( m_listview->firstChild() );
406 KNotifyWidgetBase::showEvent( e );
409 void KNotifyWidget::slotEventChanged( TQListViewItem *item )
411 bool on = (item != 0L);
413 m_actionsBox->setEnabled( on );
414 m_controlsBox->setEnabled( on );
419 ListViewItem *lit =
static_cast<ListViewItem*
>( item );
420 updateWidgets( lit );
423 void KNotifyWidget::updateWidgets( ListViewItem *item )
428 blockSignals(
true );
430 const Event&
event = item->event();
433 m_playButton->setEnabled( !event.soundfile.isEmpty() );
434 m_soundPath->setURL( event.soundfile );
435 enable = (
event.dontShow & KNotifyClient::Sound) == 0;
436 checked = enable && !
event.soundfile.isEmpty() &&
437 (
event.presentation & KNotifyClient::Sound);
438 m_playSound->setEnabled( enable );
439 m_playSound->setChecked( checked );
440 m_soundPath->setEnabled( checked );
444 m_logfilePath->setURL( event.logfile );
445 enable = (
event.dontShow & KNotifyClient::Logfile) == 0;
446 checked = enable && !
event.logfile.isEmpty() &&
447 (
event.presentation & KNotifyClient::Logfile);
448 m_logToFile->setEnabled( enable );
449 m_logToFile->setChecked( checked );
450 m_logfilePath->setEnabled( checked );
454 m_executePath->setURL( event.commandline );
455 enable = (
event.dontShow & KNotifyClient::Execute) == 0;
456 checked = enable && !
event.commandline.isEmpty() &&
457 (
event.presentation & KNotifyClient::Execute);
458 m_execute->setEnabled( enable );
459 m_execute->setChecked( checked );
460 m_executePath->setEnabled( checked );
464 m_messageBox->setChecked(event.presentation & (KNotifyClient::Messagebox | KNotifyClient::PassivePopup));
465 enable = (
event.dontShow & KNotifyClient::Messagebox) == 0;
466 m_messageBox->setEnabled( enable );
468 m_passivePopup->setChecked(event.presentation & KNotifyClient::PassivePopup);
469 enable = (
event.dontShow & KNotifyClient::PassivePopup) == 0;
470 m_passivePopup->setEnabled( enable );
472 m_stderr->setChecked( event.presentation & KNotifyClient::Stderr );
473 enable = (
event.dontShow & KNotifyClient::Stderr) == 0;
474 m_stderr->setEnabled( enable );
476 m_taskbar->setChecked(event.presentation & KNotifyClient::Taskbar);
477 enable = (
event.dontShow & KNotifyClient::Taskbar) == 0;
478 m_taskbar->setEnabled( enable );
480 updatePixmaps( item );
482 blockSignals(
false );
485 void KNotifyWidget::updatePixmaps( ListViewItem *item )
488 Event &
event = item->event();
490 bool doIt = (
event.presentation & KNotifyClient::Execute) &&
491 !event.commandline.isEmpty();
492 item->setPixmap( COL_EXECUTE, doIt ? d->pixmaps[COL_EXECUTE] : emptyPix );
494 doIt = (
event.presentation & KNotifyClient::Sound) &&
495 !event.soundfile.isEmpty();
496 item->setPixmap( COL_SOUND, doIt ? d->pixmaps[COL_SOUND] : emptyPix );
498 doIt = (
event.presentation & KNotifyClient::Logfile) &&
499 !event.logfile.isEmpty();
500 item->setPixmap( COL_LOGFILE, doIt ? d->pixmaps[COL_LOGFILE] : emptyPix );
502 item->setPixmap( COL_MESSAGE,
503 (event.presentation &
504 (KNotifyClient::Messagebox | KNotifyClient::PassivePopup)) ?
505 d->pixmaps[COL_MESSAGE] : emptyPix );
507 item->setPixmap( COL_STDERR,
508 (event.presentation & KNotifyClient::Stderr) ?
509 d->pixmaps[COL_STDERR] : emptyPix );
510 item->setPixmap( COL_TASKBAR,
511 (event.presentation & KNotifyClient::Taskbar) ?
512 d->pixmaps[COL_TASKBAR] : emptyPix );
515 void KNotifyWidget::addVisibleApp( Application *app )
517 if ( !app || (m_visibleApps.findRef( app ) != -1) )
520 m_visibleApps.append( app );
521 addToView( app->eventList() );
523 TQListViewItem *item = m_listview->selectedItem();
525 item = m_listview->firstChild();
530 void KNotifyWidget::addToView(
const EventList& events )
532 ListViewItem *item = 0L;
534 EventListIterator it( events );
536 for ( ; it.current(); ++it )
538 Event *
event = it.current();
539 item =
new ListViewItem( m_listview, event );
541 if ( (event->presentation & KNotifyClient::Execute) &&
542 !event->commandline.isEmpty() )
543 item->setPixmap( COL_EXECUTE, d->pixmaps[COL_EXECUTE] );
544 if ( (event->presentation & KNotifyClient::Sound) &&
545 !event->soundfile.isEmpty() )
546 item->setPixmap( COL_SOUND, d->pixmaps[COL_SOUND] );
547 if ( (event->presentation & KNotifyClient::Logfile) &&
548 !event->logfile.isEmpty() )
549 item->setPixmap( COL_LOGFILE, d->pixmaps[COL_LOGFILE] );
550 if ( event->presentation & (KNotifyClient::Messagebox|KNotifyClient::PassivePopup) )
551 item->setPixmap( COL_MESSAGE, d->pixmaps[COL_MESSAGE] );
552 if ( event->presentation & KNotifyClient::Stderr )
553 item->setPixmap( COL_STDERR, d->pixmaps[COL_STDERR] );
554 if ( event->presentation & KNotifyClient::Taskbar )
555 item->setPixmap( COL_TASKBAR, d->pixmaps[COL_TASKBAR] );
559 void KNotifyWidget::widgetChanged( TQListViewItem *item,
560 int what,
bool on, TQWidget *buddy )
562 if ( signalsBlocked() )
566 buddy->setEnabled( on );
568 Event &e =
static_cast<ListViewItem*
>( item )->event();
571 e.presentation |= what;
576 e.presentation &= ~what;
578 emit changed(
true );
581 void KNotifyWidget::soundToggled(
bool on )
583 TQListViewItem *item = m_listview->currentItem();
586 bool doIcon = on && !m_soundPath->url().isEmpty();
587 item->setPixmap( COL_SOUND, doIcon ? d->pixmaps[COL_SOUND] : TQPixmap() );
588 widgetChanged( item, KNotifyClient::Sound, on, m_soundPath );
591 void KNotifyWidget::loggingToggled(
bool on )
593 TQListViewItem *item = m_listview->currentItem();
596 bool doIcon = on && !m_logfilePath->url().isEmpty();
597 item->setPixmap(COL_LOGFILE, doIcon ? d->pixmaps[COL_LOGFILE] : TQPixmap());
598 widgetChanged( item, KNotifyClient::Logfile, on, m_logfilePath );
601 void KNotifyWidget::executeToggled(
bool on )
603 TQListViewItem *item = m_listview->currentItem();
606 bool doIcon = on && !m_executePath->url().isEmpty();
607 item->setPixmap(COL_EXECUTE, doIcon ? d->pixmaps[COL_EXECUTE] : TQPixmap());
608 widgetChanged( item, KNotifyClient::Execute, on, m_executePath );
611 void KNotifyWidget::messageBoxChanged()
613 if ( signalsBlocked() )
616 m_passivePopup->setEnabled( m_messageBox->isChecked() );
618 TQListViewItem *item = m_listview->currentItem();
622 bool on = m_passivePopup->isEnabled();
623 item->setPixmap( COL_MESSAGE, on ? d->pixmaps[COL_MESSAGE] : TQPixmap() );
625 Event &e =
static_cast<ListViewItem*
>( item )->event();
627 if ( m_messageBox->isChecked() ) {
628 if ( m_passivePopup->isChecked() ) {
629 e.presentation |= KNotifyClient::PassivePopup;
630 e.presentation &= ~KNotifyClient::Messagebox;
633 e.presentation &= ~KNotifyClient::PassivePopup;
634 e.presentation |= KNotifyClient::Messagebox;
638 e.presentation &= ~KNotifyClient::Messagebox;
639 e.presentation &= ~KNotifyClient::PassivePopup;
642 emit changed(
true );
645 void KNotifyWidget::stderrToggled(
bool on )
647 TQListViewItem *item = m_listview->currentItem();
650 item->setPixmap( COL_STDERR, on ? d->pixmaps[COL_STDERR] : TQPixmap() );
651 widgetChanged( item, KNotifyClient::Stderr, on );
654 void KNotifyWidget::taskbarToggled(
bool on )
656 TQListViewItem *item = m_listview->currentItem();
659 item->setPixmap( COL_TASKBAR, on ? d->pixmaps[COL_TASKBAR] : TQPixmap() );
660 widgetChanged( item, KNotifyClient::Taskbar, on );
663 void KNotifyWidget::soundFileChanged(
const TQString& text )
665 if ( signalsBlocked() )
668 TQListViewItem *item = m_listview->currentItem();
672 m_playButton->setEnabled( !text.isEmpty() );
674 currentEvent()->soundfile = text;
675 bool ok = !text.isEmpty() && m_playSound->isChecked();
676 item->setPixmap( COL_SOUND, ok ? d->pixmaps[COL_SOUND] : TQPixmap() );
678 emit changed(
true );
681 void KNotifyWidget::logfileChanged(
const TQString& text )
683 if ( signalsBlocked() )
686 TQListViewItem *item = m_listview->currentItem();
690 currentEvent()->logfile = text;
691 bool ok = !text.isEmpty() && m_logToFile->isChecked();
692 item->setPixmap( COL_LOGFILE, ok ? d->pixmaps[COL_LOGFILE] : TQPixmap() );
694 emit changed(
true );
697 void KNotifyWidget::commandlineChanged(
const TQString& text )
699 if ( signalsBlocked() )
702 TQListViewItem *item = m_listview->currentItem();
706 currentEvent()->commandline = text;
707 bool ok = !text.isEmpty() && m_execute->isChecked();
708 item->setPixmap( COL_EXECUTE, ok ? d->pixmaps[COL_EXECUTE] : TQPixmap() );
710 emit changed(
true );
713 void KNotifyWidget::slotItemClicked( TQListViewItem *item,
const TQPoint&,
716 if ( !item || !item->isSelected() )
719 Event *
event = currentEvent();
723 bool doShowAdvanced =
false;
729 m_executePath->setFocus();
730 doShowAdvanced =
true;
739 m_passivePopup->setChecked(
true );
740 m_messageBox->toggle();
743 m_logToFile->toggle();
744 m_logfilePath->setFocus();
745 doShowAdvanced =
true;
748 m_playSound->toggle();
754 if ( doShowAdvanced && !m_logToFile->isVisible() )
756 showAdvanced(
true );
757 m_listview->ensureItemVisible( m_listview->currentItem() );
761 void KNotifyWidget::sort(
bool ascending )
763 m_listview->setSorting( COL_EVENT, ascending );
767 void KNotifyWidget::selectItem( TQListViewItem *item )
771 m_listview->setCurrentItem( item );
772 item->setSelected(
true );
773 slotEventChanged( item );
777 void KNotifyWidget::resetDefaults(
bool ask )
781 if ( KMessageBox::warningContinueCancel(
this,
782 i18n(
"This will cause the notifications "
783 "to be reset to their defaults."),
784 i18n(
"Are You Sure?"),
786 != KMessageBox::Continue)
791 emit changed(
true );
794 void KNotifyWidget::reload(
bool revertToDefaults )
797 ApplicationListIterator it( m_visibleApps );
798 for ( ; it.current(); ++it )
800 it.current()->reloadEvents( revertToDefaults );
801 addToView( it.current()->eventList() );
805 selectItem( m_listview->firstChild() );
808 void KNotifyWidget::save()
810 kdDebug() <<
"save\n";
812 ApplicationListIterator it( m_allApps );
813 while ( it.current() )
821 if ( !kapp->dcopClient()->isAttached() )
822 kapp->dcopClient()->attach();
823 kapp->dcopClient()->send(
"knotify",
"",
"reconfigure()", TQString(
""));
826 emit changed(
false );
831 TQString KNotifyWidget::makeRelative(
const TQString& fullPath )
833 int slash = fullPath.findRev(
'/' ) - 1;
834 slash = fullPath.findRev(
'/', slash );
837 return TQString::null;
839 return fullPath.mid( slash+1 );
842 Event * KNotifyWidget::currentEvent()
844 TQListViewItem *current = m_listview->currentItem();
848 return &
static_cast<ListViewItem*
>( current )->event();
851 void KNotifyWidget::openSoundDialog(
KURLRequester *requester )
854 requester->disconnect( TQ_SIGNAL( openFileDialog(
KURLRequester * )),
858 fileDialog->setCaption( i18n(
"Select Sound File") );
859 TQStringList filters;
860 filters <<
"audio/x-wav" <<
"audio/x-mp3" <<
"application/ogg"
865 const Application *app = currentEvent()->application();
866 TQStringList soundDirs =
867 TDEGlobal::dirs()->findDirs(
"data", app->appName() +
"/sounds");
868 soundDirs += TDEGlobal::dirs()->resourceDirs(
"sound" );
870 if ( !soundDirs.isEmpty() ) {
873 dir.setFilter( TQDir::Files | TQDir::Readable );
874 TQStringList::ConstIterator it = soundDirs.begin();
875 while ( it != soundDirs.end() ) {
877 if ( dir.isReadable() && dir.count() > 2 ) {
878 soundURL.setPath( *it );
879 fileDialog->
setURL( soundURL );
887 void KNotifyWidget::openLogDialog(
KURLRequester *requester )
890 requester->disconnect( TQ_SIGNAL( openFileDialog(
KURLRequester * )),
894 fileDialog->setCaption( i18n(
"Select Log File") );
895 TQStringList filters;
896 filters <<
"text/x-log" <<
"text/plain";
900 void KNotifyWidget::openExecDialog(
KURLRequester *requester )
903 requester->disconnect( TQ_SIGNAL( openFileDialog(
KURLRequester * )),
908 fileDialog->setCaption( i18n(
"Select File to Execute") );
909 TQStringList filters;
910 filters <<
"application/x-executable" <<
"application/x-shellscript"
911 <<
"application/x-perl" <<
"application/x-python";
915 void KNotifyWidget::playSound()
917 TQString soundPath = m_soundPath->url();
918 if (!TDEIO::NetAccess::exists( m_soundPath->url(),
true, 0 )) {
919 bool foundSound=
false;
922 const Application *app = currentEvent()->application();
923 TQStringList soundDirs = TDEGlobal::dirs()->findDirs(
"data", app->appName() +
"/sounds");
924 soundDirs += TDEGlobal::dirs()->resourceDirs(
"sound" );
926 if ( !soundDirs.isEmpty() ) {
928 dir.setFilter( TQDir::Files | TQDir::Readable );
929 TQStringList::ConstIterator it = soundDirs.begin();
930 while ( it != soundDirs.end() ) {
932 if ( dir.isReadable() && dir.count() > 2 &&
933 TDEIO::NetAccess::exists( *it + m_soundPath->url(),
true, 0 )) {
935 soundPath = *it + m_soundPath->url();
942 KMessageBox::sorry(
this, i18n(
"The specified file does not exist." ));
946 KAudioPlayer::play( soundPath );
949 void KNotifyWidget::enableAll()
951 bool enable = (sender() == m_buttonEnable);
952 enableAll( SelectionCombo::type(enable ? m_comboEnable : m_comboDisable),
956 void KNotifyWidget::enableAll(
int what,
bool enable )
958 if ( m_listview->childCount() == 0 )
961 bool affectAll = m_affectAllApps->isChecked();
963 ApplicationListIterator appIt( affectAll ? m_allApps : m_visibleApps );
964 for ( ; appIt.current(); ++appIt )
966 const EventList& events = appIt.current()->eventList();
967 EventListIterator it( events );
968 for ( ; it.current(); ++it )
971 it.current()->presentation |= what;
973 it.current()->presentation &= ~what;
978 TQListViewItemIterator it( m_listview->firstChild() );
979 for ( ; it.current(); ++it )
981 ListViewItem *item =
static_cast<ListViewItem*
>( it.current() );
982 updatePixmaps( item );
985 TQListViewItem *item = m_listview->currentItem();
987 item = m_listview->firstChild();
990 emit changed(
true );
1001 Application::Application(
const TQString &path )
1003 TQString config_file = path;
1004 config_file[config_file.find(
'/')] =
'.';
1006 config =
new TDEConfig(config_file,
false,
false);
1007 kc =
new TDEConfig(path,
true,
false,
"data");
1008 kc->setGroup( TQString::fromLatin1(
"!Global!") );
1009 m_icon = kc->readEntry(TQString::fromLatin1(
"IconName"),
1010 TQString::fromLatin1(
"misc"));
1011 m_description = kc->readEntry( TQString::fromLatin1(
"Comment"),
1012 i18n(
"No description available") );
1014 int index = path.find(
'/' );
1016 m_appname = path.left( index );
1018 kdDebug() <<
"Cannot determine application name from path: " << path << endl;
1021 Application::~Application()
1029 const EventList& Application::eventList()
1032 m_events =
new EventList;
1033 m_events->setAutoDelete(
true );
1041 void Application::save()
1046 EventListIterator it( *m_events );
1048 while ( (e = it.current()) ) {
1049 config->setGroup( e->configGroup );
1050 config->writeEntry(
"presentation", e->presentation );
1051 config->writePathEntry(
"soundfile", e->soundfile );
1052 config->writePathEntry(
"logfile", e->logfile );
1053 config->writePathEntry(
"commandline", e->commandline );
1061 void Application::reloadEvents(
bool revertToDefaults )
1067 m_events =
new EventList;
1068 m_events->setAutoDelete(
true );
1073 TQString global = TQString::fromLatin1(
"!Global!");
1074 TQString default_group = TQString::fromLatin1(
"<default>");
1075 TQString name = TQString::fromLatin1(
"Name");
1076 TQString comment = TQString::fromLatin1(
"Comment");
1078 TQStringList conflist = kc->groupList();
1079 TQStringList::ConstIterator it = conflist.begin();
1081 while ( it != conflist.end() ) {
1082 if ( (*it) != global && (*it) != default_group ) {
1083 kc->setGroup( *it );
1085 e =
new Event(
this );
1086 e->name = kc->readEntry( name );
1087 e->description = kc->readEntry( comment );
1088 e->dontShow = kc->readNumEntry(
"nopresentation", 0 );
1089 e->configGroup = *it;
1090 if ( e->name.isEmpty() && e->description.isEmpty() )
1093 if( !e->name.isEmpty() && e->description.isEmpty() )
1094 e->description = e->name;
1096 int default_rep = kc->readNumEntry(
"default_presentation",
1097 0 | KNotifyClient::PassivePopup);
1098 TQString default_logfile = kc->readPathEntry(
"default_logfile");
1099 TQString default_soundfile = kc->readPathEntry(
"default_sound");
1100 TQString default_commandline = kc->readPathEntry(
"default_commandline");
1102 config->setGroup(*it);
1104 if ( revertToDefaults )
1106 e->presentation = default_rep;
1107 e->logfile = default_logfile;
1108 e->soundfile = default_soundfile;
1109 e->commandline = default_commandline;
1114 e->presentation = config->readNumEntry(
"presentation",
1116 e->logfile = config->readPathEntry(
"logfile",
1118 e->soundfile = config->readPathEntry(
"soundfile",
1120 e->commandline = config->readPathEntry(
"commandline",
1121 default_commandline);
1124 m_events->append( e );
1137 ListViewItem::ListViewItem( TQListView *view, Event *event )
1138 : TQListViewItem( view ),
1141 setText( COL_EVENT, event->text() );
1144 int ListViewItem::compare ( TQListViewItem * i,
int col,
bool ascending )
const
1146 ListViewItem *item =
static_cast<ListViewItem*
>( i );
1147 int myPres = m_event->presentation;
1148 int otherPres = item->event().presentation;
1155 return TQListViewItem::compare( i, col, ascending );
1158 action = KNotifyClient::Execute;
1161 action = KNotifyClient::Logfile;
1164 action = (KNotifyClient::Messagebox | KNotifyClient::PassivePopup);
1167 action = KNotifyClient::Sound;
1170 action = KNotifyClient::Stderr;
1173 action = KNotifyClient::Taskbar;
1177 if ( (myPres & action) == (otherPres & action) )
1180 return TQListViewItem::compare( i, COL_EVENT,
true );
1183 if ( myPres & action )
1185 if ( otherPres & action )
1191 #include "knotifydialog.moc"
Provides a user (and developer) friendly way to select files and directories.
void setMimeFilter(const TQStringList &types, const TQString &defaultType=TQString::null)
Sets the filter up to specify the output type.
void setURL(const KURL &url, bool clearforward=true)
Sets the directory to view.
KNotifyDialog presents an interface for configuring an application's KNotify events.
virtual void clearApplicationEvents()
Removes all the events added with addApplicationEvents()
static int configure(TQWidget *parent=0, const char *name=0, const TDEAboutData *aboutData=TDEGlobal::instance() ->aboutData())
Convenience method to create exec() a modal KNotifyDialog.
virtual ~KNotifyDialog()
Destroys the KNotifyDialog.
KNotifyDialog(TQWidget *parent=0, const char *name=0, bool modal=true, const TDEAboutData *aboutData=TDEGlobal::instance() ->aboutData())
If you want a non-modal dialog, you need to instantiate KNotifyDialog yourself instead of using the c...
virtual void addApplicationEvents(const char *appName)
With this method, you can add the KNotify events of one eventsrc files to the view.
This class is a widget showing a lineedit and a button, which invokes a filedialog.
virtual KFileDialog * fileDialog() const