00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kshowmail.h"
00021
00022 using namespace TDEIO;
00023
00024 TDEAboutData* KShowMailApp::m_pAbout;
00025
00026 KShowMailApp::KShowMailApp()
00027 {
00028
00029 initActions();
00030
00031
00032 setXMLFile( "kshowmailui.rc" );
00033 createGUI();
00034
00035
00036 setAutoSaveSettings();
00037
00038
00039 initStatusBar();
00040 initDocument();
00041 initView();
00042
00043
00044 m_state = idle;
00045
00046
00047 SetupDialog = NULL;
00048
00049 m_pTimer = new TQTimer (this);
00050 m_pAlertDialog = NULL;
00051 m_pDockWindow = new KShowMailDock (this, m_actionRefresh);
00052 m_bForceClose = false;
00053
00054
00055
00056 m_ConfigList.refreshSetup( m_pView->m_pListAccounts );
00057
00058 readOptions();
00059
00060
00061 m_ConfigList.readStoredMails();
00062
00063
00064
00065 connect (m_pDockWindow, SIGNAL (quitSelected ()), SLOT (slotForceClose ()));
00066 connect (m_pTimer, SIGNAL (timeout ()), SLOT (slotRefresh ()));
00067 connect (m_pView->m_pListAccounts, SIGNAL (currentChanged(TQListViewItem*)), SLOT(slotAccountActivated(TQListViewItem*)));
00068 connect (m_pView, SIGNAL (signalActiveChanged()), SLOT (slotRefreshView()));
00069
00070 connect( &m_ConfigList, SIGNAL( sigDeleteReady() ), this, SLOT( slotDeletionReady() ) );
00071 connect( &m_ConfigList, SIGNAL( sigShowBodiesReady() ), this, SLOT( slotShowMessageReady() ) );
00072 connect( &m_ConfigList, SIGNAL( sigMessageWindowOpened() ), this, SLOT( slotNormalCursor() ) );
00073 connect( &m_ConfigList, SIGNAL( sigAllMessageWindowsClosed() ), this, SLOT( slotWaitingCursor() ) );
00074 connect( &m_ConfigList, SIGNAL( sigRefreshReady() ), this, SLOT( slotRefreshReady() ) );
00075
00076
00077
00078 startTimer (1000);
00079
00080
00081
00082 initFirstRefresh();
00083 }
00084
00085 KShowMailApp::~KShowMailApp()
00086 {
00087 kdDebug() << "cleaning up" << endl;
00088 delete m_pTimer;
00089 delete m_pDockWindow;
00090 kdDebug() << "cleanup finished" << endl;
00091 }
00092
00096 void KShowMailApp::timerEvent (TQTimerEvent *)
00097 {
00098 if (m_nSecondsToGo)
00099 {
00100 TQTime time;
00101 time = time.addSecs (m_nSecondsToGo--);
00102 TQCString msg (i18n("Autorefresh: %1").arg (time.toString()));
00103 statusBar()->changeItem(msg, 3);
00104 }
00105 else
00106 statusBar()->changeItem("", 3);
00107
00108
00109 if ( m_state == refreshing || m_state == deleting )
00110 {
00111 static int color = 0;
00112 color = (color+1)%2;
00113 switch (color)
00114 {
00115 case 0:
00116 m_pDockWindow->clear ();
00117 break;
00118 default:
00119 m_pDockWindow->drawText ("?", TQt::red);
00120 }
00121 }
00122 }
00123
00124
00125
00126 void KShowMailApp::initActions ()
00127 {
00128
00129 m_actionSave = KStdAction::saveOptions( this, SLOT( slotSaveOptions() ), actionCollection() );
00130 KStdAction::quit( this, SLOT( slotFileQuit() ), actionCollection() );
00131
00132
00133 m_actionRefresh = new TDEAction( i18n( "&Refresh messages" ), "reload", Key_F5, this, SLOT( slotRefresh() ), actionCollection(), "refresh" );
00134 new TDEAction( i18n( "Show &header of highlighted messages" ), "letter-closed", Key_F2, this, SLOT( slotShowHeader() ), actionCollection(), "show_header" );
00135 new TDEAction( i18n( "Show &complete highlighted messages" ), "letter-open", Key_F3, this, SLOT( slotShowMessage() ), actionCollection(), "show_complete" );
00136 new TDEAction( i18n( "&Delete highlighted messages" ), "eraser", Key_Delete, this, SLOT( slotDelete() ), actionCollection(), "delete" );
00137 new TDEAction( i18n( "S&top current transfer" ), "stop", 0, this, SLOT( slotStop() ), actionCollection(), "stop" );
00138
00139
00140 KStdAction::preferences( this, SLOT( slotSetup() ), actionCollection() );
00141 new TDEAction( i18n( "Setup &filters" ), "filter", 0, this, SLOT( slotSetupFilters() ), actionCollection(), "filters" );
00142 KStdAction::configureToolbars( this, SLOT( slotEditToolbars() ), actionCollection() );
00143
00144
00145 setStandardToolBarMenuEnabled( true );
00146 createStandardStatusBarAction();
00147
00148
00149 new TDEAction( i18n( "Send &Feedback Mail" ), "email", 0, this, SLOT( slotSendFeedbackMail() ),actionCollection(), "sendFeedback" );
00150
00151
00152 new TDEAction(i18n( "Setup &account" ), "tool", 0, this, SLOT( slotSetupAccount() ), actionCollection(), "setupAccount" );
00153 }
00154
00155 void KShowMailApp::initStatusBar()
00156 {
00158
00159 TQCString user = getenv( "LOGNAME" );
00160 TQCString server = getenv( "HOSTNAME" );
00161 TQCString mesg (TQString ("%1@%2").arg(user).arg(server));
00162
00163 statusBar()->insertItem(i18n("Ready."), 1);
00164 statusBar()->insertItem(mesg, 2, 1);
00165 statusBar()->insertItem("", 3);
00166 statusBar()->insertItem("", 4);
00167 }
00168
00169 void KShowMailApp::initDocument()
00170 {
00171 m_pDoc = new KshowmailDoc(this);
00172 m_pDoc->newDocument();
00173 }
00174
00175 void KShowMailApp::initView()
00176 {
00178
00179
00180
00181 m_pView = new KshowmailView(this);
00182 m_pDoc->addView(m_pView);
00183 setCentralWidget(m_pView);
00184 }
00185
00186 void KShowMailApp::slotSaveOptions()
00187 {
00188 TDEConfig* config = TDEGlobal::config();
00189
00190
00191 m_pView->saveOptions( config );
00192 Filter::saveOptions( config );
00193 m_ConfigList.saveOptions ();
00194
00195
00196 config->sync ();
00197
00198
00199 m_actionSave->setEnabled( false );
00200 }
00201
00202 void KShowMailApp::readOptions()
00203 {
00204 TDEConfig* config = TDEGlobal::config();
00205
00206 Filter::readOptions (config);
00207 m_actionSave->setEnabled (false);
00208 }
00209
00210 bool KShowMailApp::queryClose()
00211 {
00212 bool result;
00213 kdDebug() << "KShowMailApp::queryClose()" << endl;
00214
00215 if (m_bForceClose) {
00216
00217 kdDebug() << "forced exit" << endl;
00218 result = true;
00219 } else if( m_ConfigList.closeToTray() ) {
00220
00221 result = false;
00222 kdDebug() << "ignoring close request and minimizing the window" << endl;
00223 TDEMainWindow* w = memberList->first();
00224 w->hide();
00225 } else {
00226
00227 result = askCloseConfirmation();
00228 }
00229 return result;
00230 }
00231
00232 bool KShowMailApp::queryExit()
00233 {
00234 kdDebug() << "KShowMailApp::queryExit()" << endl;
00235 slotSaveOptions ();
00236
00237 return true;
00238 }
00239
00241
00243
00244 void KShowMailApp::slotFileQuit()
00245 {
00246 kdDebug () << "KShowMailApp::slotFileQuit()" << endl;
00247 if(memberList && askCloseConfirmation())
00248 {
00249 m_bForceClose = true;
00250 TDEMainWindow* w = memberList->first();
00251 w->close();
00252 }
00253 }
00254
00255
00256 void KShowMailApp::slotSetupAccount()
00257 {
00258
00259 if (m_state != idle)
00260 {
00261 kapp->beep();
00262 return;
00263 }
00264
00265
00266 m_state = configure;
00267
00268
00269 stopRefreshTimer();
00270
00271
00272 ConfigElem* pConfig = m_ConfigList.getSelectedAccount();
00273
00274 if( pConfig != NULL )
00275 {
00276
00277
00278 ServerDialog dlg( this, pConfig );
00279
00280 if( dlg.exec() == TQDialog::Accepted )
00281 {
00282
00283 slotConfChanged();
00284 }
00285 }
00286
00287
00288 m_state = idle;
00289 initNextRefresh();
00290 }
00291
00292 void KShowMailApp::slotAccountActivated (TQListViewItem* pItem)
00293 {
00294 TQPtrListIterator<ConfigElem> it(m_ConfigList);
00295
00296 while (ConfigElem* pConfig = it())
00297 {
00298 if (pConfig->getListViewItem() == pItem)
00299 {
00300 setCaption (pConfig->getAccountName());
00301 return;
00302 }
00303 }
00304 }
00305
00306 void KShowMailApp::slotAlertDestroyed()
00307 {
00308 m_pAlertDialog = NULL;
00309 }
00310
00311 void KShowMailApp::slotAlertOk ()
00312 {
00313
00314 showNormal();
00315 raise();
00316 }
00317
00318 void KShowMailApp::slotRefresh()
00319 {
00320
00321 if ( m_state != idle )
00322 {
00323 kapp->beep();
00324 initNextRefresh();
00325 return;
00326 }
00327
00328
00329 stopRefreshTimer();
00330
00331
00332 m_state = refreshing;
00333
00334
00335 slotStatusMsg( i18n( "Refreshing ..." ) );
00336
00337
00338 TQApplication::setOverrideCursor( TQt::waitCursor );
00339
00340
00341 m_ConfigList.refreshMailLists();
00342
00343 return;
00344 }
00345
00346 void KShowMailApp::slotStop ()
00347 {
00348 if (m_state == idle)
00349 {
00350 kapp->beep ();
00351 return;
00352 }
00353 kdDebug() << "KShowMailApp::slotStop" << endl;
00354
00355
00356 m_ConfigList.killPOP3Jobs();
00357
00358 slotRefreshView ();
00359
00360
00361
00362
00363
00364 m_state = idle;
00365
00366
00367
00368 while (TQApplication::overrideCursor())
00369 TQApplication::restoreOverrideCursor ();
00370
00371
00372 slotStatusMsg(i18n("Job was stopped"));
00373 }
00374
00375 void KShowMailApp::slotRefreshView ()
00376 {
00377
00378
00379 m_pView->clearMailListView();
00380
00381
00382 m_ConfigList.fillMailListView( m_pView );
00383
00384
00385 m_ConfigList.refreshAccountList();
00386
00387
00388 int numberMails = m_ConfigList.getNumberMails();
00389 bool hasNewMails = m_ConfigList.getNumberNewMails() > 0;
00390
00391
00392 if( hasNewMails )
00393
00394 m_pDockWindow->drawNumber( numberMails, TQt::red );
00395 else
00396
00397 m_pDockWindow->drawNumber( numberMails, TQt::black );
00398
00399
00400 long totalSize = m_ConfigList.getTotalSize();
00401 slotStatusMsg( i18n( "%1 message(s) with a total of %2 bytes are waiting" ).arg( numberMails ).arg( totalSize ) );
00402 }
00403
00404 void KShowMailApp::slotDelete()
00405 {
00406
00407 if( m_state != idle )
00408 {
00409 kapp->beep();
00410 return;
00411 }
00412
00413
00414 if( !m_ConfigList.hasSelectedMails() )
00415 return;
00416
00417
00418 if( m_ConfigList.confirmDeletion() )
00419 {
00420
00421 TQStringList subjects = m_ConfigList.getSelectedSubjects();
00422
00423
00424 int answer = KMessageBox::questionYesNoList( this, i18n( "Do you want to delete these mails?"), subjects, i18n( "Delete?" ) );
00425
00426 if( answer == KMessageBox::No )
00427 return;
00428 }
00429
00430
00431 m_state = deleting;
00432
00433
00434 slotStatusMsg( i18n( "Deleting Mail(s) ..." ) );
00435
00436
00437 TQApplication::setOverrideCursor( TQt::waitCursor );
00438
00439
00440
00441 m_ConfigList.deleteSelectedMails();
00442 }
00443
00444 void KShowMailApp::slotShowHeader ()
00445 {
00446
00447 if( m_state != idle )
00448 {
00449 kapp->beep ();
00450 return;
00451 }
00452
00453
00454 m_ConfigList.showSelectedHeaders();
00455
00456 }
00457
00458 void KShowMailApp::slotShowMessage ()
00459 {
00460
00461 if( m_state != idle )
00462 {
00463 kapp->beep ();
00464 return;
00465 }
00466
00467
00468 if( !m_ConfigList.hasSelectedMails() )
00469 return;
00470
00471
00472 m_state = showing;
00473
00474
00475 slotStatusMsg( i18n( "Downloading ..." ) );
00476
00477
00478 TQApplication::setOverrideCursor( TQt::waitCursor );
00479
00480
00481 m_ConfigList.showSelectedMails();
00482 }
00483
00484 void KShowMailApp::slotStatusMsg(const TQString& text)
00485 {
00486
00487
00488 TQString sTime = TQTime::currentTime ().toString ();
00489
00490
00491 statusBar()->clear();
00492
00493
00494 statusBar()->changeItem(text, 1);
00495
00496
00497 statusBar()->changeItem(sTime, 4);
00498 }
00499
00500 void KShowMailApp::slotStatusHelpMsg(const TQString &text)
00501 {
00502 statusBar()->message(text, 2000);
00503 }
00504
00505
00506
00507
00508 bool KShowMailApp::event(TQEvent *e)
00509 {
00510
00511 if ((e->type() == TQEvent::Hide) && m_ConfigList.minimizesToTray() ) {
00512 hide ();
00513 }
00514
00515 return(TDEMainWindow::event(e));
00516 }
00517
00518 void KShowMailApp::slotSetupFilters ()
00519 {
00520 if (m_state != idle)
00521 {
00522 kapp->beep ();
00523 return;
00524 }
00525 m_state = configure;
00526 FilterDialog dlg (this, "Filters");
00527 if (dlg.exec () == TQDialog::Accepted)
00528 m_actionSave->setEnabled (true);
00529 m_state = idle;
00530 }
00531
00532 void KShowMailApp::slotForceClose()
00533 {
00534 m_bForceClose = true;
00535 }
00536
00537 bool KShowMailApp::askCloseConfirmation()
00538 {
00539 bool result;
00540
00541 if( m_ConfigList.confirmClose() ) {
00542
00543 result = (KMessageBox::questionYesNo (this, i18n ("KShowmail will be closed.\n"
00544 "Are you sure?")) == KMessageBox::Yes);
00545 } else {
00546
00547 result = true;
00548 }
00549
00550 return result;
00551 }
00552
00553 void KShowMailApp::slotDeletionReady( )
00554 {
00555
00556 m_state = idle;
00557
00558
00559 while( TQApplication::overrideCursor() )
00560 TQApplication::restoreOverrideCursor();
00561
00562
00563 slotStatusMsg( i18n( "Ready." ) );
00564
00565
00566 slotRefresh();
00567 }
00568
00569 void KShowMailApp::slotShowMessageReady( )
00570 {
00571
00572 m_state = idle;
00573
00574
00575 while( TQApplication::overrideCursor() )
00576 TQApplication::restoreOverrideCursor();
00577
00578
00579 slotStatusMsg( i18n( "Ready." ) );
00580
00581
00582 }
00583
00584 void KShowMailApp::slotNormalCursor( )
00585 {
00586
00587 while( TQApplication::overrideCursor() )
00588 TQApplication::restoreOverrideCursor();
00589
00590 }
00591
00592 void KShowMailApp::slotWaitingCursor( )
00593 {
00594
00595 TQApplication::setOverrideCursor( TQt::waitCursor );
00596 }
00597
00598 void KShowMailApp::slotRefreshReady( )
00599 {
00600
00601 m_state = idle;
00602
00603
00604 while( TQApplication::overrideCursor() )
00605 TQApplication::restoreOverrideCursor();
00606
00607
00608 slotRefreshView();
00609
00610
00611 bool hasNewMails = m_ConfigList.getNumberNewMails() > 0;
00612 if ( hasNewMails )
00613 {
00614
00615 if( m_ConfigList.showMainWindowForNewMails() )
00616 {
00617 showNormal();
00618 raise();
00619 }
00620
00621
00622 m_ConfigList.beep();
00623 m_ConfigList.playSound();
00624
00625
00626 m_ConfigList.executeNewMailCommand();
00627
00628
00629 if( m_ConfigList.showAlertMessageForNewMails() )
00630 {
00631
00632 if( m_pAlertDialog != NULL )
00633 {
00634
00635 m_pAlertDialog->show();
00636 m_pAlertDialog->raise();
00637 }
00638 else
00639 {
00640
00641 m_pAlertDialog = new AlertDialog( this );
00642 connect( m_pAlertDialog, SIGNAL( destroyed() ), SLOT( slotAlertDestroyed() ) );
00643 connect( m_pAlertDialog, SIGNAL( signalOk() ), SLOT( slotAlertOk() ) );
00644 }
00645 }
00646
00647 }
00648 else
00649 {
00650
00651
00652
00653
00654 if( m_ConfigList.quitNoNewMails() )
00655 slotFileQuit();
00656 else if( m_ConfigList.minimizeMainWindowNoNewMails() )
00657 {
00658 showMinimized();
00659 hide();
00660 }
00661 }
00662
00663
00664 slotStatusMsg( i18n( "Ready." ) );
00665
00666
00667
00668 initNextRefresh();
00669
00670
00671 m_ConfigList.applyFilters();
00672
00673
00674 if (Filter::_status == Filter::automatic)
00675 {
00676 slotDelete ();
00677 }
00678 }
00679
00680 void KShowMailApp::initFirstRefresh( )
00681 {
00682
00683 if( m_ConfigList.AutoRefreshOn() )
00684 {
00685
00686 if( m_ConfigList.hasInitTime() )
00687 {
00688
00689 m_pTimer->start( m_ConfigList.getInitTime() * 1000, true );
00690 m_nSecondsToGo = m_ConfigList.getInitTime();
00691 }
00692 else
00693 {
00694
00695 m_pTimer->stop();
00696 m_nSecondsToGo = 0;
00697
00698
00699 slotRefresh();
00700 }
00701 }
00702 else
00703 {
00704
00705 m_pTimer->stop();
00706 m_nSecondsToGo = 0;
00707 }
00708 }
00709
00710 void KShowMailApp::stopRefreshTimer( )
00711 {
00712 m_pTimer->stop();
00713 m_nSecondsToGo = 0;
00714 }
00715
00716 void KShowMailApp::initNextRefresh( )
00717 {
00718 if( m_ConfigList.AutoRefreshOn() )
00719 {
00720
00721
00722 m_pTimer->start( m_ConfigList.getRefreshTimeInterval() * 60000, true );
00723 m_nSecondsToGo = m_ConfigList.getRefreshTimeInterval() * 60;
00724 }
00725 else
00726 {
00727
00728
00729 m_pTimer->stop();
00730 m_nSecondsToGo = 0;
00731 }
00732 }
00733
00734 void KShowMailApp::delayNextRefresh( )
00735 {
00736 const unsigned long DELAY_TIME = 60;
00737
00738
00739 if( m_pTimer->isActive() )
00740 {
00741 if( m_nSecondsToGo < DELAY_TIME )
00742 {
00743 m_pTimer->start( DELAY_TIME * 1000, true );
00744 m_nSecondsToGo = DELAY_TIME;
00745 }
00746 }
00747 }
00748
00749 void KShowMailApp::slotEditToolbars()
00750 {
00751
00752 KEditToolbar *dlg = new KEditToolbar(guiFactory());
00753 if( dlg->exec() )
00754 {
00755
00756
00757 createGUI();
00758 }
00759
00760
00761 delete dlg;
00762 }
00763
00764 void KShowMailApp::slotSetup( )
00765 {
00766
00767 if (m_state != idle)
00768 {
00769 kapp->beep();
00770 return;
00771 }
00772
00773
00774 m_state = configure;
00775
00776
00777 stopRefreshTimer();
00778
00779 if ( SetupDialog == NULL )
00780 {
00781
00782 SetupDialog = new KCMultiDialog( KCMultiDialog::IconList, i18n( "Options" ), this, "SetupDialog" );
00783 SetupDialog->addModule( "kshowmailconfigaccounts.desktop" );
00784 SetupDialog->addModule( "kshowmailconfiggeneral.desktop" );
00785 SetupDialog->addModule( "kshowmailconfigdisplay.desktop" );
00786 SetupDialog->addModule( "kshowmailconfigactions.desktop" );
00787
00788
00789 connect( SetupDialog, SIGNAL( configCommitted() ), this, SLOT( slotConfChanged() ) );
00790 }
00791
00792
00793 SetupDialog->exec();
00794
00795
00796 m_state = idle;
00797 initNextRefresh();
00798
00799 }
00800
00801 void KShowMailApp::slotConfChanged( )
00802 {
00803
00804 m_ConfigList.refreshSetup( m_pView->m_pListAccounts );
00805 m_pView->refreshSetup();
00806 }
00807