• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
knotifydialog.cpp
1 /*
2  Copyright (C) 2000,2002 Carsten Pfeiffer <pfeiffer@kde.org>
3  Copyright (C) 2002 Neil Stevens <neil@qualityassistant.com>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation;
8 
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 GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library, If not, write to the Free Software Foundation,
16  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include <dcopclient.h>
20 
21 #include <tdeaboutdata.h>
22 #include <tdeapplication.h>
23 #include <kaudioplayer.h>
24 #include <kcombobox.h>
25 #include <tdeconfig.h>
26 #include <kcursor.h>
27 #include <kdebug.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>
39 
40 #include <tqcheckbox.h>
41 #include <tqgroupbox.h>
42 #include <tqheader.h>
43 #include <tqlabel.h>
44 #include <tqlistview.h>
45 #include <tqlayout.h>
46 #include <tqptrlist.h>
47 #include <tqpushbutton.h>
48 #include <tqstring.h>
49 #include <tqtooltip.h>
50 #include <tqtimer.h>
51 #include <tqvbox.h>
52 #include <tqwhatsthis.h>
53 
54 using namespace KNotify;
55 
56 enum
57 {
58  COL_EXECUTE = 0,
59  COL_STDERR = 1,
60  COL_MESSAGE = 2,
61  COL_LOGFILE = 3,
62  COL_SOUND = 4,
63  COL_TASKBAR = 5,
64  COL_EVENT = 6
65 };
66 
67 //
68 // I don't feel like subclassing KComboBox and find ways to insert that into
69 // the .ui file...
70 //
71 namespace KNotify
72 {
73  class SelectionCombo
74  {
75  public:
76  //
77  // Mind the order in fill() and type()
78  //
79  static void fill( KComboBox *combo )
80  {
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") );
88  }
89 
90  static int type( KComboBox *combo )
91  {
92  switch( combo->currentItem() )
93  {
94  case 0:
95  return KNotifyClient::Sound;
96  case 1:
97  return KNotifyClient::Logfile;
98  case 2:
99  return KNotifyClient::Execute;
100  case 3:
101  return KNotifyClient::Messagebox;
102  case 4:
103  return KNotifyClient::PassivePopup;
104  case 5:
105  return KNotifyClient::Stderr;
106  case 6:
107  return KNotifyClient::Taskbar;
108  }
109 
110  return KNotifyClient::None;
111  }
112  };
113 
114  // Needed for displaying tooltips in the listview's QHeader
115  class KNotifyToolTip : public TQToolTip
116  {
117  public:
118  KNotifyToolTip( TQHeader *header )
119  : TQToolTip( header )
120  {
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");
127  }
128  virtual ~KNotifyToolTip() {}
129 
130  protected:
131  virtual void maybeTip ( const TQPoint& p )
132  {
133  TQHeader *header = static_cast<TQHeader*>( parentWidget() );
134  int section = 0;
135 
136  if ( header->orientation() == TQt::Horizontal )
137  section= header->sectionAt( p.x() );
138  else
139  section= header->sectionAt( p.y() );
140 
141  if ( ( section < 0 ) || ( static_cast<uint>( section ) >= (sizeof(m_tips) / sizeof(TQString)) ) )
142  return;
143 
144  tip( header->sectionRect( section ), m_tips[section] );
145  }
146 
147  private:
148  TQString m_tips[6];
149  };
150 
151 }
152 
153 
154 int KNotifyDialog::configure( TQWidget *parent, const char *name,
155  const TDEAboutData *aboutData )
156 {
157  KNotifyDialog dialog( parent, name, true, aboutData );
158  return dialog.exec();
159 }
160 
161 KNotifyDialog::KNotifyDialog( TQWidget *parent, const char *name, bool modal,
162  const TDEAboutData *aboutData )
163  : KDialogBase(parent, name, modal, i18n("Notification Settings"),
164  Ok | Apply | Cancel | Default, Ok, true )
165 {
166  TQVBox *box = makeVBoxMainWidget();
167 
168  m_notifyWidget = new KNotifyWidget( box, "knotify widget" );
169 
170  if ( aboutData )
171  addApplicationEvents( aboutData->appName() );
172 
173  connect( this, TQ_SIGNAL( okClicked() ), m_notifyWidget, TQ_SLOT( save() ));
174  connect( this, TQ_SIGNAL( applyClicked() ), m_notifyWidget, TQ_SLOT( save() ));
175 }
176 
177 KNotifyDialog::~KNotifyDialog()
178 {
179 }
180 
181 void KNotifyDialog::addApplicationEvents( const char *appName )
182 {
183  addApplicationEvents( TQString::fromUtf8( appName ) +
184  TQString::fromLatin1( "/eventsrc" ) );
185 }
186 
187 void KNotifyDialog::addApplicationEvents( const TQString& path )
188 {
189  Application *app = m_notifyWidget->addApplicationEvents( path );
190  if ( app )
191  {
192  m_notifyWidget->addVisibleApp( app );
193  m_notifyWidget->sort();
194  }
195 }
196 
197 void KNotifyDialog::clearApplicationEvents()
198 {
199  m_notifyWidget->clear();
200 }
201 
202 void KNotifyDialog::slotDefault()
203 {
204  m_notifyWidget->resetDefaults( true ); // ask user
205 }
206 
207 
210 
211 
212 class KNotifyWidget::Private
213 {
214 public:
215  TQPixmap pixmaps[6];
216  KNotifyToolTip *toolTip;
217 };
218 
219 // simple access to all knotify-handled applications
220 KNotifyWidget::KNotifyWidget( TQWidget *parent, const char *name,
221  bool handleAllApps )
222  : KNotifyWidgetBase( parent, name ? name : "KNotifyWidget" )
223 {
224  d = new Private;
225 
226  m_allApps.setAutoDelete( true );
227 
228  if ( !handleAllApps )
229  {
230  m_affectAllApps->hide();
231  m_playerButton->hide();
232  }
233 
234  SelectionCombo::fill( m_comboEnable );
235  SelectionCombo::fill( m_comboDisable );
236 
237  m_listview->setFullWidth( true );
238  m_listview->setAllColumnsShowFocus( true );
239 
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");
246 
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;
253 
254  int w = TDEIcon::SizeSmall + 6;
255 
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 );
263 
264  d->toolTip = new KNotifyToolTip( header );
265 
266  m_playButton->setIconSet( SmallIconSet( "media-playback-start" ) );
267  connect( m_playButton, TQ_SIGNAL( clicked() ), TQ_SLOT( playSound() ));
268 
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 )));
273 
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 ) ) );
288 
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& ) ));
295 
296  connect( m_soundPath, TQ_SIGNAL( openFileDialog( KURLRequester * )),
297  TQ_SLOT( openSoundDialog( KURLRequester * )));
298  connect( m_logfilePath, TQ_SIGNAL( openFileDialog( KURLRequester * )),
299  TQ_SLOT( openLogDialog( KURLRequester * )));
300  connect( m_executePath, TQ_SIGNAL( openFileDialog( KURLRequester * )),
301  TQ_SLOT( openExecDialog( KURLRequester * )));
302 
303  connect( m_extension, TQ_SIGNAL( clicked() ),
304  TQ_SLOT( toggleAdvanced()) );
305 
306  connect( m_buttonEnable, TQ_SIGNAL( clicked() ), TQ_SLOT( enableAll() ));
307  connect( m_buttonDisable, TQ_SIGNAL( clicked() ), TQ_SLOT( enableAll() ));
308 
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 );
318 
319  showAdvanced( false );
320 
321  slotEventChanged( 0L ); // disable widgets by default
322 }
323 
324 KNotifyWidget::~KNotifyWidget()
325 {
326  delete d->toolTip;
327  delete d;
328 }
329 
330 void KNotifyWidget::toggleAdvanced()
331 {
332  showAdvanced( m_logToFile->isHidden() );
333 }
334 
335 void KNotifyWidget::showAdvanced( bool show )
336 {
337  if ( show )
338  {
339  m_extension->setText( i18n("Advanced <<") );
340  TQToolTip::add( m_extension, i18n("Hide advanced options") );
341 
342  m_logToFile->show();
343  m_logfilePath->show();
344  m_execute->show();
345  m_executePath->show();
346  m_messageBox->show();
347  m_passivePopup->show();
348  m_stderr->show();
349  m_taskbar->show();
350 
351  m_passivePopup->setEnabled( m_messageBox->isChecked() );
352  m_actionsBoxLayout->setSpacing( KDialog::spacingHint() );
353  }
354  else
355  {
356  m_extension->setText( i18n("Advanced >>") );
357  TQToolTip::add( m_extension, i18n("Show advanced options") );
358 
359  m_logToFile->hide();
360  m_logfilePath->hide();
361  m_execute->hide();
362  m_executePath->hide();
363  m_messageBox->hide();
364  m_passivePopup->hide();
365  m_stderr->hide();
366  m_taskbar->hide();
367 
368  m_actionsBoxLayout->setSpacing( 0 );
369  }
370 }
371 
372 Application * KNotifyWidget::addApplicationEvents( const TQString& path )
373 {
374  kdDebug() << "**** knotify: adding path: " << path << endl;
375  TQString relativePath = path;
376 
377  if ( path.at(0) == '/' && TDEStandardDirs::exists( path ) )
378  relativePath = makeRelative( path );
379 
380  if ( !relativePath.isEmpty() )
381  {
382  Application *app = new Application( relativePath );
383  m_allApps.append( app );
384  return app;
385  }
386 
387  return 0L;
388 }
389 
390 void KNotifyWidget::clear()
391 {
392  clearVisible();
393  m_allApps.clear();
394 }
395 
396 void KNotifyWidget::clearVisible()
397 {
398  m_visibleApps.clear();
399  m_listview->clear();
400  slotEventChanged( 0L ); // disable widgets
401 }
402 
403 void KNotifyWidget::showEvent( TQShowEvent *e )
404 {
405  selectItem( m_listview->firstChild() );
406  KNotifyWidgetBase::showEvent( e );
407 }
408 
409 void KNotifyWidget::slotEventChanged( TQListViewItem *item )
410 {
411  bool on = (item != 0L);
412 
413  m_actionsBox->setEnabled( on );
414  m_controlsBox->setEnabled( on );
415 
416  if ( !on )
417  return;
418 
419  ListViewItem *lit = static_cast<ListViewItem*>( item );
420  updateWidgets( lit );
421 }
422 
423 void KNotifyWidget::updateWidgets( ListViewItem *item )
424 {
425  bool enable;
426  bool checked;
427 
428  blockSignals( true ); // don't emit changed() signals
429 
430  const Event& event = item->event();
431 
432  // sound settings
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 );
441 
442 
443  // logfile settings
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 );
451 
452 
453  // execute program settings
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 );
461 
462 
463  // other settings
464  m_messageBox->setChecked(event.presentation & (KNotifyClient::Messagebox | KNotifyClient::PassivePopup));
465  enable = (event.dontShow & KNotifyClient::Messagebox) == 0;
466  m_messageBox->setEnabled( enable );
467 
468  m_passivePopup->setChecked(event.presentation & KNotifyClient::PassivePopup);
469  enable = (event.dontShow & KNotifyClient::PassivePopup) == 0;
470  m_passivePopup->setEnabled( enable );
471 
472  m_stderr->setChecked( event.presentation & KNotifyClient::Stderr );
473  enable = (event.dontShow & KNotifyClient::Stderr) == 0;
474  m_stderr->setEnabled( enable );
475 
476  m_taskbar->setChecked(event.presentation & KNotifyClient::Taskbar);
477  enable = (event.dontShow & KNotifyClient::Taskbar) == 0;
478  m_taskbar->setEnabled( enable );
479 
480  updatePixmaps( item );
481 
482  blockSignals( false );
483 }
484 
485 void KNotifyWidget::updatePixmaps( ListViewItem *item )
486 {
487  TQPixmap emptyPix;
488  Event &event = item->event();
489 
490  bool doIt = (event.presentation & KNotifyClient::Execute) &&
491  !event.commandline.isEmpty();
492  item->setPixmap( COL_EXECUTE, doIt ? d->pixmaps[COL_EXECUTE] : emptyPix );
493 
494  doIt = (event.presentation & KNotifyClient::Sound) &&
495  !event.soundfile.isEmpty();
496  item->setPixmap( COL_SOUND, doIt ? d->pixmaps[COL_SOUND] : emptyPix );
497 
498  doIt = (event.presentation & KNotifyClient::Logfile) &&
499  !event.logfile.isEmpty();
500  item->setPixmap( COL_LOGFILE, doIt ? d->pixmaps[COL_LOGFILE] : emptyPix );
501 
502  item->setPixmap( COL_MESSAGE,
503  (event.presentation &
504  (KNotifyClient::Messagebox | KNotifyClient::PassivePopup)) ?
505  d->pixmaps[COL_MESSAGE] : emptyPix );
506 
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 );
513 }
514 
515 void KNotifyWidget::addVisibleApp( Application *app )
516 {
517  if ( !app || (m_visibleApps.findRef( app ) != -1) )
518  return;
519 
520  m_visibleApps.append( app );
521  addToView( app->eventList() );
522 
523  TQListViewItem *item = m_listview->selectedItem();
524  if ( !item )
525  item = m_listview->firstChild();
526 
527  selectItem( item );
528 }
529 
530 void KNotifyWidget::addToView( const EventList& events )
531 {
532  ListViewItem *item = 0L;
533 
534  EventListIterator it( events );
535 
536  for ( ; it.current(); ++it )
537  {
538  Event *event = it.current();
539  item = new ListViewItem( m_listview, event );
540 
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] );
556  }
557 }
558 
559 void KNotifyWidget::widgetChanged( TQListViewItem *item,
560  int what, bool on, TQWidget *buddy )
561 {
562  if ( signalsBlocked() )
563  return;
564 
565  if ( buddy )
566  buddy->setEnabled( on );
567 
568  Event &e = static_cast<ListViewItem*>( item )->event();
569  if ( on )
570  {
571  e.presentation |= what;
572  if ( buddy )
573  buddy->setFocus();
574  }
575  else
576  e.presentation &= ~what;
577 
578  emit changed( true );
579 }
580 
581 void KNotifyWidget::soundToggled( bool on )
582 {
583  TQListViewItem *item = m_listview->currentItem();
584  if ( !item )
585  return;
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 );
589 }
590 
591 void KNotifyWidget::loggingToggled( bool on )
592 {
593  TQListViewItem *item = m_listview->currentItem();
594  if ( !item )
595  return;
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 );
599 }
600 
601 void KNotifyWidget::executeToggled( bool on )
602 {
603  TQListViewItem *item = m_listview->currentItem();
604  if ( !item )
605  return;
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 );
609 }
610 
611 void KNotifyWidget::messageBoxChanged()
612 {
613  if ( signalsBlocked() )
614  return;
615 
616  m_passivePopup->setEnabled( m_messageBox->isChecked() );
617 
618  TQListViewItem *item = m_listview->currentItem();
619  if ( !item )
620  return;
621 
622  bool on = m_passivePopup->isEnabled();
623  item->setPixmap( COL_MESSAGE, on ? d->pixmaps[COL_MESSAGE] : TQPixmap() );
624 
625  Event &e = static_cast<ListViewItem*>( item )->event();
626 
627  if ( m_messageBox->isChecked() ) {
628  if ( m_passivePopup->isChecked() ) {
629  e.presentation |= KNotifyClient::PassivePopup;
630  e.presentation &= ~KNotifyClient::Messagebox;
631  }
632  else {
633  e.presentation &= ~KNotifyClient::PassivePopup;
634  e.presentation |= KNotifyClient::Messagebox;
635  }
636  }
637  else {
638  e.presentation &= ~KNotifyClient::Messagebox;
639  e.presentation &= ~KNotifyClient::PassivePopup;
640  }
641 
642  emit changed( true );
643 }
644 
645 void KNotifyWidget::stderrToggled( bool on )
646 {
647  TQListViewItem *item = m_listview->currentItem();
648  if ( !item )
649  return;
650  item->setPixmap( COL_STDERR, on ? d->pixmaps[COL_STDERR] : TQPixmap() );
651  widgetChanged( item, KNotifyClient::Stderr, on );
652 }
653 
654 void KNotifyWidget::taskbarToggled( bool on )
655 {
656  TQListViewItem *item = m_listview->currentItem();
657  if ( !item )
658  return;
659  item->setPixmap( COL_TASKBAR, on ? d->pixmaps[COL_TASKBAR] : TQPixmap() );
660  widgetChanged( item, KNotifyClient::Taskbar, on );
661 }
662 
663 void KNotifyWidget::soundFileChanged( const TQString& text )
664 {
665  if ( signalsBlocked() )
666  return;
667 
668  TQListViewItem *item = m_listview->currentItem();
669  if ( !item )
670  return;
671 
672  m_playButton->setEnabled( !text.isEmpty() );
673 
674  currentEvent()->soundfile = text;
675  bool ok = !text.isEmpty() && m_playSound->isChecked();
676  item->setPixmap( COL_SOUND, ok ? d->pixmaps[COL_SOUND] : TQPixmap() );
677 
678  emit changed( true );
679 }
680 
681 void KNotifyWidget::logfileChanged( const TQString& text )
682 {
683  if ( signalsBlocked() )
684  return;
685 
686  TQListViewItem *item = m_listview->currentItem();
687  if ( !item )
688  return;
689 
690  currentEvent()->logfile = text;
691  bool ok = !text.isEmpty() && m_logToFile->isChecked();
692  item->setPixmap( COL_LOGFILE, ok ? d->pixmaps[COL_LOGFILE] : TQPixmap() );
693 
694  emit changed( true );
695 }
696 
697 void KNotifyWidget::commandlineChanged( const TQString& text )
698 {
699  if ( signalsBlocked() )
700  return;
701 
702  TQListViewItem *item = m_listview->currentItem();
703  if ( !item )
704  return;
705 
706  currentEvent()->commandline = text;
707  bool ok = !text.isEmpty() && m_execute->isChecked();
708  item->setPixmap( COL_EXECUTE, ok ? d->pixmaps[COL_EXECUTE] : TQPixmap() );
709 
710  emit changed( true );
711 }
712 
713 void KNotifyWidget::slotItemClicked( TQListViewItem *item, const TQPoint&,
714  int col )
715 {
716  if ( !item || !item->isSelected() )
717  return;
718 
719  Event *event = currentEvent();
720  if ( !event )
721  return; // very unlikely, but safety first
722 
723  bool doShowAdvanced = false;
724 
725  switch( col )
726  {
727  case COL_EXECUTE:
728  m_execute->toggle();
729  m_executePath->setFocus();
730  doShowAdvanced = true;
731  break;
732  case COL_STDERR:
733  m_stderr->toggle();
734  break;
735  case COL_TASKBAR:
736  m_taskbar->toggle();
737  break;
738  case COL_MESSAGE:
739  m_passivePopup->setChecked( true ); // default to passive popups
740  m_messageBox->toggle();
741  break;
742  case COL_LOGFILE:
743  m_logToFile->toggle();
744  m_logfilePath->setFocus();
745  doShowAdvanced = true;
746  break;
747  case COL_SOUND:
748  m_playSound->toggle();
749  break;
750  default: // do nothing
751  break;
752  }
753 
754  if ( doShowAdvanced && !m_logToFile->isVisible() )
755  {
756  showAdvanced( true );
757  m_listview->ensureItemVisible( m_listview->currentItem() );
758  }
759 }
760 
761 void KNotifyWidget::sort( bool ascending )
762 {
763  m_listview->setSorting( COL_EVENT, ascending );
764  m_listview->sort();
765 }
766 
767 void KNotifyWidget::selectItem( TQListViewItem *item )
768 {
769  if ( item )
770  {
771  m_listview->setCurrentItem( item );
772  item->setSelected( true );
773  slotEventChanged( item );
774  }
775 }
776 
777 void KNotifyWidget::resetDefaults( bool ask )
778 {
779  if ( ask )
780  {
781  if ( KMessageBox::warningContinueCancel(this,
782  i18n("This will cause the notifications "
783  "to be reset to their defaults."),
784  i18n("Are You Sure?"),
785  i18n("&Reset"))
786  != KMessageBox::Continue)
787  return;
788  }
789 
790  reload( true ); // defaults
791  emit changed( true );
792 }
793 
794 void KNotifyWidget::reload( bool revertToDefaults )
795 {
796  m_listview->clear();
797  ApplicationListIterator it( m_visibleApps );
798  for ( ; it.current(); ++it )
799  {
800  it.current()->reloadEvents( revertToDefaults );
801  addToView( it.current()->eventList() );
802  }
803 
804  m_listview->sort();
805  selectItem( m_listview->firstChild() );
806 }
807 
808 void KNotifyWidget::save()
809 {
810  kdDebug() << "save\n";
811 
812  ApplicationListIterator it( m_allApps );
813  while ( it.current() )
814  {
815  (*it)->save();
816  ++it;
817  }
818 
819  if ( kapp )
820  {
821  if ( !kapp->dcopClient()->isAttached() )
822  kapp->dcopClient()->attach();
823  kapp->dcopClient()->send("knotify", "", "reconfigure()", TQString(""));
824  }
825 
826  emit changed( false );
827 }
828 
829 // returns e.g. "twin/eventsrc" from a given path
830 // "/opt/trinity/share/apps/twin/eventsrc"
831 TQString KNotifyWidget::makeRelative( const TQString& fullPath )
832 {
833  int slash = fullPath.findRev( '/' ) - 1;
834  slash = fullPath.findRev( '/', slash );
835 
836  if ( slash < 0 )
837  return TQString::null;
838 
839  return fullPath.mid( slash+1 );
840 }
841 
842 Event * KNotifyWidget::currentEvent()
843 {
844  TQListViewItem *current = m_listview->currentItem();
845  if ( !current )
846  return 0L;
847 
848  return &static_cast<ListViewItem*>( current )->event();
849 }
850 
851 void KNotifyWidget::openSoundDialog( KURLRequester *requester )
852 {
853  // only need to init this once
854  requester->disconnect( TQ_SIGNAL( openFileDialog( KURLRequester * )),
855  this, TQ_SLOT( openSoundDialog( KURLRequester * )));
856 
857  KFileDialog *fileDialog = requester->fileDialog();
858  fileDialog->setCaption( i18n("Select Sound File") );
859  TQStringList filters;
860  filters << "audio/x-wav" << "audio/x-mp3" << "application/ogg"
861  << "audio/x-adpcm";
862  fileDialog->setMimeFilter( filters );
863 
864  // find the first "sound"-resource that contains files
865  const Application *app = currentEvent()->application();
866  TQStringList soundDirs =
867  TDEGlobal::dirs()->findDirs("data", app->appName() + "/sounds");
868  soundDirs += TDEGlobal::dirs()->resourceDirs( "sound" );
869 
870  if ( !soundDirs.isEmpty() ) {
871  KURL soundURL;
872  TQDir dir;
873  dir.setFilter( TQDir::Files | TQDir::Readable );
874  TQStringList::ConstIterator it = soundDirs.begin();
875  while ( it != soundDirs.end() ) {
876  dir = *it;
877  if ( dir.isReadable() && dir.count() > 2 ) {
878  soundURL.setPath( *it );
879  fileDialog->setURL( soundURL );
880  break;
881  }
882  ++it;
883  }
884  }
885 }
886 
887 void KNotifyWidget::openLogDialog( KURLRequester *requester )
888 {
889  // only need to init this once
890  requester->disconnect( TQ_SIGNAL( openFileDialog( KURLRequester * )),
891  this, TQ_SLOT( openLogDialog( KURLRequester * )));
892 
893  KFileDialog *fileDialog = requester->fileDialog();
894  fileDialog->setCaption( i18n("Select Log File") );
895  TQStringList filters;
896  filters << "text/x-log" << "text/plain";
897  fileDialog->setMimeFilter( filters );
898 }
899 
900 void KNotifyWidget::openExecDialog( KURLRequester *requester )
901 {
902  // only need to init this once
903  requester->disconnect( TQ_SIGNAL( openFileDialog( KURLRequester * )),
904  this, TQ_SLOT( openExecDialog( KURLRequester * )));
905 
906 
907  KFileDialog *fileDialog = requester->fileDialog();
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";
912  fileDialog->setMimeFilter( filters );
913 }
914 
915 void KNotifyWidget::playSound()
916 {
917  TQString soundPath = m_soundPath->url();
918  if (!TDEIO::NetAccess::exists( m_soundPath->url(), true, 0 )) {
919  bool foundSound=false;
920 
921  // find the first "sound"-resource that contains files
922  const Application *app = currentEvent()->application();
923  TQStringList soundDirs = TDEGlobal::dirs()->findDirs("data", app->appName() + "/sounds");
924  soundDirs += TDEGlobal::dirs()->resourceDirs( "sound" );
925 
926  if ( !soundDirs.isEmpty() ) {
927  TQDir dir;
928  dir.setFilter( TQDir::Files | TQDir::Readable );
929  TQStringList::ConstIterator it = soundDirs.begin();
930  while ( it != soundDirs.end() ) {
931  dir = *it;
932  if ( dir.isReadable() && dir.count() > 2 &&
933  TDEIO::NetAccess::exists( *it + m_soundPath->url(), true, 0 )) {
934  foundSound=true;
935  soundPath = *it + m_soundPath->url();
936  break;
937  }
938  ++it;
939  }
940  }
941  if ( !foundSound ) {
942  KMessageBox::sorry(this, i18n("The specified file does not exist." ));
943  return;
944  }
945  }
946  KAudioPlayer::play( soundPath );
947 }
948 
949 void KNotifyWidget::enableAll()
950 {
951  bool enable = (sender() == m_buttonEnable);
952  enableAll( SelectionCombo::type(enable ? m_comboEnable : m_comboDisable),
953  enable );
954 }
955 
956 void KNotifyWidget::enableAll( int what, bool enable )
957 {
958  if ( m_listview->childCount() == 0 )
959  return;
960 
961  bool affectAll = m_affectAllApps->isChecked(); // multi-apps mode
962 
963  ApplicationListIterator appIt( affectAll ? m_allApps : m_visibleApps );
964  for ( ; appIt.current(); ++appIt )
965  {
966  const EventList& events = appIt.current()->eventList();
967  EventListIterator it( events );
968  for ( ; it.current(); ++it )
969  {
970  if ( enable )
971  it.current()->presentation |= what;
972  else
973  it.current()->presentation &= ~what;
974  }
975  }
976 
977  // now make the listview reflect the changes
978  TQListViewItemIterator it( m_listview->firstChild() );
979  for ( ; it.current(); ++it )
980  {
981  ListViewItem *item = static_cast<ListViewItem*>( it.current() );
982  updatePixmaps( item );
983  }
984 
985  TQListViewItem *item = m_listview->currentItem();
986  if ( !item )
987  item = m_listview->firstChild();
988  selectItem( item );
989 
990  emit changed( true );
991 }
992 
993 
996 
997 
998 //
999 // path must be "appname/eventsrc", i.e. a relative path
1000 //
1001 Application::Application( const TQString &path )
1002 {
1003  TQString config_file = path;
1004  config_file[config_file.find('/')] = '.';
1005  m_events = 0L;
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") );
1013 
1014  int index = path.find( '/' );
1015  if ( index >= 0 )
1016  m_appname = path.left( index );
1017  else
1018  kdDebug() << "Cannot determine application name from path: " << path << endl;
1019 }
1020 
1021 Application::~Application()
1022 {
1023  delete config;
1024  delete kc;
1025  delete m_events;
1026 }
1027 
1028 
1029 const EventList& Application::eventList()
1030 {
1031  if ( !m_events ) {
1032  m_events = new EventList;
1033  m_events->setAutoDelete( true );
1034  reloadEvents();
1035  }
1036 
1037  return *m_events;
1038 }
1039 
1040 
1041 void Application::save()
1042 {
1043  if ( !m_events )
1044  return;
1045 
1046  EventListIterator it( *m_events );
1047  Event *e;
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 );
1054 
1055  ++it;
1056  }
1057  config->sync();
1058 }
1059 
1060 
1061 void Application::reloadEvents( bool revertToDefaults )
1062 {
1063  if ( m_events )
1064  m_events->clear();
1065  else
1066  {
1067  m_events = new EventList;
1068  m_events->setAutoDelete( true );
1069  }
1070 
1071  Event *e = 0L;
1072 
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");
1077 
1078  TQStringList conflist = kc->groupList();
1079  TQStringList::ConstIterator it = conflist.begin();
1080 
1081  while ( it != conflist.end() ) {
1082  if ( (*it) != global && (*it) != default_group ) { // event group
1083  kc->setGroup( *it );
1084 
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() )
1091  delete e;
1092  else { // load the event
1093  if( !e->name.isEmpty() && e->description.isEmpty() )
1094  e->description = e->name;
1095  // default to passive popups over plain messageboxes
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");
1101 
1102  config->setGroup(*it);
1103 
1104  if ( revertToDefaults )
1105  {
1106  e->presentation = default_rep;
1107  e->logfile = default_logfile;
1108  e->soundfile = default_soundfile;
1109  e->commandline = default_commandline;
1110  }
1111 
1112  else
1113  {
1114  e->presentation = config->readNumEntry("presentation",
1115  default_rep);
1116  e->logfile = config->readPathEntry("logfile",
1117  default_logfile);
1118  e->soundfile = config->readPathEntry("soundfile",
1119  default_soundfile);
1120  e->commandline = config->readPathEntry("commandline",
1121  default_commandline);
1122  }
1123 
1124  m_events->append( e );
1125  }
1126  }
1127 
1128  ++it;
1129  }
1130 
1131  return;
1132 }
1133 
1136 
1137 ListViewItem::ListViewItem( TQListView *view, Event *event )
1138  : TQListViewItem( view ),
1139  m_event( event )
1140 {
1141  setText( COL_EVENT, event->text() );
1142 }
1143 
1144 int ListViewItem::compare ( TQListViewItem * i, int col, bool ascending ) const
1145 {
1146  ListViewItem *item = static_cast<ListViewItem*>( i );
1147  int myPres = m_event->presentation;
1148  int otherPres = item->event().presentation;
1149 
1150  int action = 0;
1151 
1152  switch ( col )
1153  {
1154  case COL_EVENT: // use default sorting
1155  return TQListViewItem::compare( i, col, ascending );
1156 
1157  case COL_EXECUTE:
1158  action = KNotifyClient::Execute;
1159  break;
1160  case COL_LOGFILE:
1161  action = KNotifyClient::Logfile;
1162  break;
1163  case COL_MESSAGE:
1164  action = (KNotifyClient::Messagebox | KNotifyClient::PassivePopup);
1165  break;
1166  case COL_SOUND:
1167  action = KNotifyClient::Sound;
1168  break;
1169  case COL_STDERR:
1170  action = KNotifyClient::Stderr;
1171  break;
1172  case COL_TASKBAR:
1173  action = KNotifyClient::Taskbar;
1174  break;
1175  }
1176 
1177  if ( (myPres & action) == (otherPres & action) )
1178  {
1179  // default sorting by event
1180  return TQListViewItem::compare( i, COL_EVENT, true );
1181  }
1182 
1183  if ( myPres & action )
1184  return -1;
1185  if ( otherPres & action )
1186  return 1;
1187 
1188  return 0;
1189 }
1190 
1191 #include "knotifydialog.moc"
KFileDialog
Provides a user (and developer) friendly way to select files and directories.
Definition: tdefiledialog.h:77
KFileDialog::setMimeFilter
void setMimeFilter(const TQStringList &types, const TQString &defaultType=TQString::null)
Sets the filter up to specify the output type.
Definition: tdefiledialog.cpp:253
KFileDialog::setURL
void setURL(const KURL &url, bool clearforward=true)
Sets the directory to view.
Definition: tdefiledialog.cpp:1159
KNotifyDialog
KNotifyDialog presents an interface for configuring an application's KNotify events.
Definition: knotifydialog.h:53
KNotifyDialog::clearApplicationEvents
virtual void clearApplicationEvents()
Removes all the events added with addApplicationEvents()
Definition: knotifydialog.cpp:197
KNotifyDialog::configure
static int configure(TQWidget *parent=0, const char *name=0, const TDEAboutData *aboutData=TDEGlobal::instance() ->aboutData())
Convenience method to create exec() a modal KNotifyDialog.
Definition: knotifydialog.cpp:154
KNotifyDialog::~KNotifyDialog
virtual ~KNotifyDialog()
Destroys the KNotifyDialog.
Definition: knotifydialog.cpp:177
KNotifyDialog::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...
Definition: knotifydialog.cpp:161
KNotifyDialog::addApplicationEvents
virtual void addApplicationEvents(const char *appName)
With this method, you can add the KNotify events of one eventsrc files to the view.
Definition: knotifydialog.cpp:181
KURLRequester
This class is a widget showing a lineedit and a button, which invokes a filedialog.
Definition: kurlrequester.h:57
KURLRequester::fileDialog
virtual KFileDialog * fileDialog() const
Definition: kurlrequester.cpp:340

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.1
This website is maintained by Timothy Pearson.