summaryrefslogtreecommitdiffstats
path: root/kshowmail/kshowmail.cpp
blob: ff1a3d935db03afa90c8ec5d84be760e68599a5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
/***************************************************************************
                          kshowmail.cpp  -  description
                             -------------------
    begin                : Sat May  6 12:13:57 MEST 2000
    copyright            : (C) 2000-2002 by Eggert Ehmke
    email                : eggert.ehmke@berlin.de

    26 Sep 2002 - Allow for columns to be hidden. Allistar Melville
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kshowmail.h"

using namespace TDEIO;

TDEAboutData* KShowMailApp::m_pAbout;

KShowMailApp::KShowMailApp()
{
  //set up actions
  initActions();

  // create GUI from ui resource file
  setXMLFile( "kshowmailui.rc", true );
  createGUI();

  //the main window settings will be saved automatically
  setAutoSaveSettings();

  //initiate GUI parts
  initStatusBar();
  initDocument();
  initView();

  //the application is idle at beginning
  m_state = idle;

  //the setup dialog will be created in slotSetup() at first use
  SetupDialog = NULL;

  m_pTimer = new TQTimer (this);
  m_pAlertDialog = NULL;
  m_pDockWindow = new KShowMailDock (this, m_actionRefresh);
  m_bForceClose = false;


  //read the setup
  m_ConfigList.refreshSetup( m_pView->m_pListAccounts );

  //load stored mails
  m_ConfigList.readStoredMails();

  //connect signals with slots

  connect (m_pDockWindow, SIGNAL (quitSelected ()), SLOT (slotForceClose ()));
  connect (m_pTimer, SIGNAL (timeout ()), SLOT (slotRefresh ()));
  connect (m_pView->m_pListAccounts, SIGNAL (currentChanged(TQListViewItem*)), SLOT(slotAccountActivated(TQListViewItem*)));
  connect (m_pView, SIGNAL (signalActiveChanged()), SLOT (slotRefreshView()));

  connect( &m_ConfigList, SIGNAL( sigDeleteReady() ), this, SLOT( slotDeletionReady() ) );
  connect( &m_ConfigList, SIGNAL( sigShowBodiesReady() ), this, SLOT( slotShowMessageReady() ) );
  connect( &m_ConfigList, SIGNAL( sigMessageWindowOpened() ), this, SLOT( slotNormalCursor() ) );
  connect( &m_ConfigList, SIGNAL( sigAllMessageWindowsClosed() ), this, SLOT( slotWaitingCursor() ) );
  connect( &m_ConfigList, SIGNAL( sigRefreshReady() ), this, SLOT( slotRefreshReady() ) );

  //show welcome message
  KMessageBox::information( NULL, i18n( "Thank You for using KShowmail.\nPlease use the feedback dialog to tell us your experience with this program." ), i18n("Welcome"), "WelcomeMessage" );

  // this starts the one-second-interval timer
  // this is a TQObject method
  startTimer (1000);

  //we are ready to take off! Lets initiate the first refresh (if desired)
  initFirstRefresh();
}

KShowMailApp::~KShowMailApp()
{
  kdDebug() << "cleaning up" << endl;
  delete m_pTimer;
  delete m_pDockWindow;
  kdDebug() << "cleanup finished" << endl;
}

/**
  * This is reimplemented from TQObject
  */
void KShowMailApp::timerEvent (TQTimerEvent *)
{
  if (m_nSecondsToGo)
  {
    TQTime time;
    time = time.addSecs (m_nSecondsToGo--);
    TQCString msg (i18n("Autorefresh: %1").arg (time.toString()));
    statusBar()->changeItem( msg, STATUSBAR_FIELD_NEXT_REFRESH );
  }
  else
    statusBar()->changeItem( "", STATUSBAR_FIELD_NEXT_REFRESH );

  // if busy, animate the traybar
  if ( m_state == refreshing || m_state == deleting )
  {
    static int color = 0;
    color = (color+1)%2;
    switch (color)
    {
      case 0:
        m_pDockWindow->clear ();
        break;
      default:
        m_pDockWindow->drawText ("?", TQt::red);
    }
  }
}



void KShowMailApp::initActions ()
{
  // file menu
  KStdAction::quit( this, SLOT( slotFileQuit() ), actionCollection() );

  // action menu
  m_actionRefresh = new TDEAction( i18n( "&Refresh messages" ), "reload", Key_F5, this, SLOT( slotRefresh() ), actionCollection(), "refresh" );
  new TDEAction( i18n( "Show &header of highlighted messages" ), "letter-closed", Key_F2, this, SLOT( slotShowHeader() ), actionCollection(), "show_header" );
  new TDEAction( i18n( "Show &complete highlighted messages" ), "letter-open", Key_F3, this, SLOT( slotShowMessage() ), actionCollection(), "show_complete" );
  new TDEAction( i18n( "&Delete highlighted messages" ), "eraser", Key_Delete, this, SLOT( slotDelete() ), actionCollection(), "delete" );
  new TDEAction( i18n( "S&top current transfer" ), "process-stop", 0, this, SLOT( slotStop() ), actionCollection(), "stop" );
  new TDEAction( i18n( "Show Filter Log" ), "text-x-log", Key_F4, this, SLOT( slotShowFilterLog() ), actionCollection(), "show_filterlog" );
  new TDEAction( i18n( "Add sender to whitelist" ), "add_user", 0, this, SLOT( slotAddToWhitelist() ), actionCollection(), "addWhitelist" );
  new TDEAction( i18n( "Add sender to blacklist" ), "delete_user", 0, this, SLOT( slotAddToBlacklist() ), actionCollection(), "addBlacklist" );

  // setup menu
  KStdAction::preferences( this, SLOT( slotSetup() ), actionCollection() );
  KStdAction::configureToolbars( this, SLOT( slotEditToolbars() ), actionCollection() );

  //create menu items for toggle tool and status bar
  setStandardToolBarMenuEnabled( true );
  createStandardStatusBarAction();

  //help menu
  new TDEAction( i18n( "Send &Feedback Mail" ), "email", 0, this, SLOT( slotSendFeedbackMail() ),actionCollection(), "sendFeedback" );

  //for account context menu
  new TDEAction(i18n( "Setup &account" ), "tool", 0, this, SLOT( slotSetupAccount() ), actionCollection(), "setupAccount" );
}


void KShowMailApp::initStatusBar()
{
  statusBar()->insertItem( i18n( "Ready." ), STATUSBAR_FIELD_STATE );
  statusBar()->insertItem( "", STATUSBAR_FIELD_FILTER, 1 );
  statusBar()->setItemAlignment( STATUSBAR_FIELD_FILTER, AlignLeft | AlignVCenter );
  statusBar()->insertItem( "", STATUSBAR_FIELD_NEXT_REFRESH );
  statusBar()->insertItem( "", STATUSBAR_FIELD_LAST_REFRESH );

   TQToolTip::add( statusBar(), i18n( "Shows the number of deleted, moved or ignored mails by the filter.\nThe positions denotes:\nby last refresh / since application start / listed by the log" ) );

  refreshFilterStatusBar();
}

void KShowMailApp::initDocument()
{
  m_pDoc = new KshowmailDoc(this);
  m_pDoc->newDocument();
}

void KShowMailApp::initView()
{
  ////////////////////////////////////////////////////////////////////
  // create the main widget here that is managed by TDEMainWindow's view-region and
  // connect the widget to your document to display document contents.

  m_pView = new KshowmailView(this);
  m_pDoc->addView(m_pView);
  setCentralWidget(m_pView);
}

void KShowMailApp::slotSaveOptions()
{
  TDEConfig* config = TDEGlobal::config();

  //order application parts to save their setup
  m_pView->saveOptions( config );
  m_ConfigList.saveOptions ();
  fLog.save();

  //save config to file
  config->sync ();

}

bool KShowMailApp::queryClose()
{
    bool result;
    kdDebug() << "KShowMailApp::queryClose()" << endl;

    if (m_bForceClose) {
        // We are forced to close app - so just do it
        kdDebug() << "forced exit" << endl;
        result = true;
    } else if( m_ConfigList.closeToTray() ) {
        // Don't close - close button must minimize the window
        result = false;
        kdDebug() << "ignoring close request and minimizing the window" << endl;
        TDEMainWindow* w = memberList->first();
        w->hide();
    } else {
        // Need to ask user first
        result = askCloseConfirmation();
    }
    return result;
}

bool KShowMailApp::queryExit()
{
  kdDebug() << "KShowMailApp::queryExit()" << endl;
  slotSaveOptions ();

  return true;
}

/////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATION
/////////////////////////////////////////////////////////////////////

void KShowMailApp::slotFileQuit()
{
  kdDebug () << "KShowMailApp::slotFileQuit()" << endl;
  if(memberList && askCloseConfirmation())
  {
    m_bForceClose = true;   // Forcing the closing
    TDEMainWindow* w = memberList->first();
    w->close();
  }
}


void KShowMailApp::slotSetupAccount()
{
  //just open the dialog, if the app is idle
  if (m_state != idle)
  {
    kapp->beep();
    return;
  }

  //set application state
  m_state = configure;

  //stop the refresh timer
  stopRefreshTimer();

  //get account to configure
  ConfigElem* pConfig = m_ConfigList.getSelectedAccount();

  if( pConfig != NULL )
  {
    //open dialog
    //the dialog sets the new options directly in the account
    ServerDialog dlg( this, pConfig );

    if( dlg.exec() == TQDialog::Accepted )
    {
      //if OK was clicked, refresh the account list view
      slotConfChanged();
    }
  }

  //we are ready, set application state to idle and initiate next refresh
  m_state = idle;
  initNextRefresh();
}

void KShowMailApp::slotAccountActivated (TQListViewItem* pItem)
{
  TQPtrListIterator<ConfigElem> it(m_ConfigList);
  // this is = not == !!!
  while (ConfigElem* pConfig = it())
  {
    if (pConfig->getListViewItem() == pItem)
    {
      setCaption (pConfig->getAccountName());
      return;
    }
  }
}

void KShowMailApp::slotAlertDestroyed()
{
  m_pAlertDialog = NULL;
}

void KShowMailApp::slotAlertOk ()
{
  //switch main window to normal view
  showNormal();
  raise();
}

void KShowMailApp::slotRefresh()
{
  //return, if the app is not idle
  if ( m_state != idle )
  {
    kapp->beep();
    initNextRefresh();
    return;
  }

  //stop the refresh timer
  stopRefreshTimer();

  //set the state
  m_state = refreshing;

  //show status message
  slotStatusMsg( i18n( "Refreshing ..." ) );

  //set waiting cursor
  TQApplication::setOverrideCursor( TQt::waitCursor );

  //order the account list to refresh its mail lists
  m_ConfigList.refreshMailLists( &fLog );

  return;
}

void KShowMailApp::slotStop ()
{
  if (m_state == idle)
  {
    kapp->beep ();
    return;
  }
  kdDebug() << "KShowMailApp::slotStop" << endl;

  //kill all running pop3 jobs
  m_ConfigList.killPOP3Jobs();

  slotRefreshView ();

  // make sure the view is refreshed before the state gets idle again
  // bug #853651

  //set state to idle
  m_state = idle;

  //set normal cursor
  //might be more than one override cursor ...
  while (TQApplication::overrideCursor())
    TQApplication::restoreOverrideCursor ();

  //print status message
  slotStatusMsg(i18n("Job was stopped"));
}

void KShowMailApp::slotRefreshView ()
{

  //clear mail list view
  m_pView->clearMailListView();

  //fill mail list view
  m_ConfigList.fillMailListView( m_pView );

  //refresh account list
  m_ConfigList.refreshAccountList();

  //get some informations
  int numberMails = m_ConfigList.getNumberMails();
  bool hasNewMails = m_ConfigList.getNumberNewMails() > 0;

  //draw number of mails into dock
  if( hasNewMails )
    //draw red number, because we have new mails
     m_pDockWindow->drawNumber( numberMails, TQt::red );
  else
    //we haven't new mails, draw black
    m_pDockWindow->drawNumber( numberMails, TQt::black );

  //show message in status bar
  long totalSize = m_ConfigList.getTotalSize();
  slotStatusMsg( i18n( "%1 message(s) with a total of %2 bytes are waiting" ).arg( numberMails ).arg( totalSize ) );

  //refresh filter view in the status bar
  refreshFilterStatusBar();
}

void KShowMailApp::slotDelete()
{
  //just delete, if no operation is running
  if( m_state != idle )
  {
    kapp->beep();
    return;
  }

  //return, if no mails are selected
  if( !m_ConfigList.hasSelectedMails() )
    return;

  //confirm deletion if required
  if( m_ConfigList.confirmDeletion() )
  {
    //get subjects off all selected mails
    TQStringList subjects = m_ConfigList.getSelectedSubjects();

    //show question
    int answer = KMessageBox::questionYesNoList( this, i18n( "Do you want to delete these mails?"), subjects, i18n( "Delete?" ) );

    if( answer == KMessageBox::No )
      return;
  }

  //set the state
  m_state = deleting;

  //show status message
  slotStatusMsg( i18n( "Deleting Mail(s) ..." ) );

  //set waiting cursor
  TQApplication::setOverrideCursor( TQt::waitCursor );

  //order the account list to delete the selected mails
  //test!
  m_ConfigList.deleteSelectedMails();
}

void KShowMailApp::slotShowHeader ()
{
  //only show headers, if the app is idle
  if( m_state != idle )
  {
    kapp->beep ();
    return;
  }

  //show the headers
  m_ConfigList.showSelectedHeaders();

}

void KShowMailApp::slotShowMessage ()
{
  //return, if application is not idle
  if( m_state != idle )
  {
    kapp->beep ();
    return;
  }

  //return, if no mails are selected
  if( !m_ConfigList.hasSelectedMails() )
    return;

  //set the state
  m_state = showing;

  //show status message
  slotStatusMsg( i18n( "Downloading ..." ) );

  //set waiting cursor
  TQApplication::setOverrideCursor( TQt::waitCursor );

  //order the account list to show the selected mails
  m_ConfigList.showSelectedMails();
}

void KShowMailApp::slotStatusMsg(const TQString& text)
{
  //get current time
  // added by Gustavo Zamorano to include time
  TQString sTime = TQTime::currentTime ().toString ();

  //clear status bar
  statusBar()->clear();

  //set given text
  statusBar()->changeItem( text, STATUSBAR_FIELD_STATE );

  //set current time
  statusBar()->changeItem( i18n( "Last Refresh: %1" ).arg( sTime ), STATUSBAR_FIELD_LAST_REFRESH );
}

void KShowMailApp::slotStatusHelpMsg(const TQString &text)
{
  statusBar()->message(text, 2000);
}




bool KShowMailApp::event(TQEvent *e)
{
  // to hide the taskbar button; any better solution ??
  if ((e->type() == TQEvent::Hide) && m_ConfigList.minimizesToTray() ) {
    hide ();
  }

  return(TDEMainWindow::event(e));
}

void KShowMailApp::slotForceClose()
{
    m_bForceClose = true;
}

bool KShowMailApp::askCloseConfirmation()
{
    bool result;

    if( m_ConfigList.confirmClose() ) {
        // Need to ask user
        result = (KMessageBox::questionYesNo (this, i18n ("KShowmail will be closed.\n"
                                    "Are you sure?")) == KMessageBox::Yes);
    } else {
        // User doesn't want to be asked - just close it
        result = true;
    }

    return result;
}

void KShowMailApp::slotDeletionReady( )
{
  //set state to idle
  m_state = idle;

  //set normal cursor
  while( TQApplication::overrideCursor() )
    TQApplication::restoreOverrideCursor();

  //show status message
  slotStatusMsg( i18n( "Ready." ) );

  //refresh mail list
  slotRefresh();
}

void KShowMailApp::slotShowMessageReady( )
{
  //set state to idle
  m_state = idle;

  //set normal cursor
  while( TQApplication::overrideCursor() )
    TQApplication::restoreOverrideCursor();

  //show status message
  slotStatusMsg( i18n( "Ready." ) );


}

void KShowMailApp::slotNormalCursor( )
{
  //set normal cursor
  while( TQApplication::overrideCursor() )
    TQApplication::restoreOverrideCursor();

}

void KShowMailApp::slotWaitingCursor( )
{
  //set waiting cursor
  TQApplication::setOverrideCursor( TQt::waitCursor );
}

void KShowMailApp::slotRefreshReady( )
{
  //set state to idle
  m_state = idle;

  //set normal cursor
  while( TQApplication::overrideCursor() )
    TQApplication::restoreOverrideCursor();

  //refresh mail list view
  slotRefreshView();

  //inform the user about new mails
  bool hasNewMails = m_ConfigList.getNumberNewMails() > 0;
  if ( hasNewMails )
  {
    //show main window if desired
    if( m_ConfigList.showMainWindowForNewMails() )
    {
      showNormal();
      raise();
    }

    //get out some sounds
    m_ConfigList.beep();
    m_ConfigList.playSound();

    //execute a command
    m_ConfigList.executeNewMailCommand();

    //show alert message if desired
    if( m_ConfigList.showAlertMessageForNewMails() )
    {
      //have we created one already?
      if( m_pAlertDialog != NULL )
      {
        //yes, we have one
        m_pAlertDialog->show();
        m_pAlertDialog->raise();
      }
      else
      {
        //create a message dialog
        m_pAlertDialog = new AlertDialog( this );
        connect( m_pAlertDialog, SIGNAL( destroyed() ), SLOT( slotAlertDestroyed() ) );
        connect( m_pAlertDialog, SIGNAL( signalOk() ), SLOT( slotAlertOk() ) );
      }
    }

  }
  else
  {
    //no new mails was received
    //perform configured actions

    //terminate app if desired
    if( m_ConfigList.quitNoNewMails() )
      slotFileQuit();
    else if( m_ConfigList.minimizeMainWindowNoNewMails() )
    {
      showMinimized();
      hide();
    }
  }

  //show status message
  slotStatusMsg( i18n( "Ready." ) );


  //prepare next refresh cycle
  initNextRefresh();
}

void KShowMailApp::initFirstRefresh( )
{
  //is auto refresh on? if not, we do nothing
  if( m_ConfigList.AutoRefreshOn() )
  {
    //is an initial time configured? if not, we refresh immediately
    if( m_ConfigList.hasInitTime() )
    {
      //starts refresh timer with the configured initial time to first refresh
      m_pTimer->start( m_ConfigList.getInitTime() * 1000, true );
      m_nSecondsToGo = m_ConfigList.getInitTime();
    }
    else
    {
      //just to set a defined state
      m_pTimer->stop();
      m_nSecondsToGo = 0;

      //start refresh cycle
      slotRefresh();
    }
  }
  else
  {
    //set a defined state
    m_pTimer->stop();
    m_nSecondsToGo = 0;
  }
}

void KShowMailApp::stopRefreshTimer( )
{
  m_pTimer->stop();
  m_nSecondsToGo = 0;
}

void KShowMailApp::initNextRefresh( )
{
  if( m_ConfigList.AutoRefreshOn() )
  {
    //auto refresh is activated
    //restart the refresh timer
    m_pTimer->start( m_ConfigList.getRefreshTimeInterval() * 60000, true );
    m_nSecondsToGo = m_ConfigList.getRefreshTimeInterval() * 60;
  }
  else
  {
    //auto refresh is not activated
    //set a defined state of the refresh timer
    m_pTimer->stop();
    m_nSecondsToGo = 0;
  }
}

void KShowMailApp::delayNextRefresh( )
{
  const unsigned long DELAY_TIME = 60;

  //delay only if the timer is active and the remaining time is less than one minute
  if( m_pTimer->isActive() )
  {
    if( m_nSecondsToGo < DELAY_TIME )
    {
      m_pTimer->start( DELAY_TIME * 1000, true );
      m_nSecondsToGo = DELAY_TIME;
    }
  }
}

void KShowMailApp::slotEditToolbars()
{
  //create the toolbar config dialog
  KEditToolbar *dlg = new KEditToolbar(guiFactory());
  if( dlg->exec() )
  {
    //if dialog closed by OK, create the GUI new
    //the dialog has changed the kshowmailui.rc file
    createGUI();
  }

  //destruct dialog
  delete dlg;
}

void KShowMailApp::slotSetup( )
{
  //just open the dialog, if the app is idle
  if (m_state != idle)
  {
    kapp->beep();
    return;
  }

  //set application state
  m_state = configure;

  //stop the refresh timer
  stopRefreshTimer();

  if ( SetupDialog == NULL )
  {
    //if no preferences dialog was created as yet, create one
    SetupDialog = new KCMultiDialog( KCMultiDialog::IconList, i18n( "Options" ), this, "SetupDialog" );
    SetupDialog->addModule( "kshowmailconfigaccounts.desktop" );
    SetupDialog->addModule( "kshowmailconfiggeneral.desktop" );
    SetupDialog->addModule( "kshowmailconfigdisplay.desktop" );
    SetupDialog->addModule( "kshowmailconfigactions.desktop" );
    SetupDialog->addModule( "kshowmailconfigfilter.desktop" );
    SetupDialog->addModule( "kshowmailconfigspamcheck.desktop" );
    SetupDialog->addModule( "kshowmailconfiglog.desktop" );

    //If the configuration was changed, it will call slotConfChanged
    connect( SetupDialog, SIGNAL( configCommitted() ), this, SLOT( slotConfChanged() ) );
  }

  //execute preferences dialog
  SetupDialog->exec();

  //we are ready, set application state to idle and initiate next refresh
  m_state = idle;
  initNextRefresh();

}

void KShowMailApp::slotConfChanged( )
{
  //read the new setup
  m_ConfigList.refreshSetup( m_pView->m_pListAccounts );
  m_pView->refreshSetup();
  fLog.loadSetup();

}

void KShowMailApp::slotShowFilterLog( )
{
  //open dialog
  FilterLogView view( this, &fLog );
  view.exec();

  refreshFilterStatusBar();
}

void KShowMailApp::refreshFilterStatusBar( )
{
  int numberDeletedLastRefresh = m_ConfigList.numberDeletedMailsLastRefresh();
  int numberDeletedSinceStart = m_ConfigList.numberDeletedMailsStart();
  int numberDeletedLog = fLog.numberDeletedMails();

  int numberMovedLastRefresh = m_ConfigList.numberMovedMailsLastRefresh();
  int numberMovedSinceStart = m_ConfigList.numberMovedMailsStart();
  int numberMovedLog = fLog.numberMovedMails();

  int numberIgnored = m_ConfigList.numberIgnoredMails();

  statusBar()->changeItem( i18n( "Filter: Deleted: %1/%2/%3; Moved: %4/%5/%6; Ignored: %7" ).arg( numberDeletedLastRefresh ).arg( numberDeletedSinceStart ).arg( numberDeletedLog ).arg( numberMovedLastRefresh ).arg( numberMovedSinceStart ).arg( numberMovedLog ).arg( numberIgnored ), STATUSBAR_FIELD_FILTER );
}

void KShowMailApp::slotAddToWhitelist( )
{
  //get new entries
  TQStringList newEntries = m_ConfigList.getSelectedSenders();

  //get previous whitelist from config
  TDEConfig* config = TDEApplication::kApplication()->config();
  config->setGroup( CONFIG_GROUP_FILTER );
  TQStringList whiteList = config->readListEntry( CONFIG_ENTRY_FILTER_WHITELIST );

  //append new entries
  for( TQStringList::Iterator it = newEntries.begin(); it != newEntries.end(); ++it )
  {
    if( whiteList.contains( *it ) == 0 )
    {
      whiteList.append( *it );
    }
  }

  //write extended whitelist back
  config->writeEntry( CONFIG_ENTRY_FILTER_WHITELIST, whiteList );
  config->sync();

  //load new config
  m_ConfigList.refreshFilterSetup();
}

void KShowMailApp::slotAddToBlacklist( )
{
  //get new entries
  TQStringList newEntries = m_ConfigList.getSelectedSenders();

  //get previous blacklist from config
  TDEConfig* config = TDEApplication::kApplication()->config();
  config->setGroup( CONFIG_GROUP_FILTER );
  TQStringList blackList = config->readListEntry( CONFIG_ENTRY_FILTER_BLACKLIST );

  //append new entries
  for( TQStringList::Iterator it = newEntries.begin(); it != newEntries.end(); ++it )
  {
    if( blackList.contains( *it ) == 0 )
    {
      blackList.append( *it );
    }
  }

  //write extended whitelist back
  config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST, blackList );
  config->sync();

  //load new config
  m_ConfigList.refreshFilterSetup();
}