# optiondialog.cpp

    00001 /***************************************************************************
    00002                           optiondialog.cpp  -  description
    00003                              -------------------
    00004     begin                : Fri Oct 26 2001
    00005     copyright            : (C) 2001 by Eggert Ehmke
    00006     email                : eggert.ehmke@berlin.de
    00007
    00008     26 Sep 2002 - Allow for columns to be hidden. Allistar Melville
    00009  ***************************************************************************/
    00010
    00011 /***************************************************************************
    00012  *                                                                         *
    00013  *   This program is free software; you can redistribute it and/or modify  *
    00014  *   it under the terms of the GNU General Public License as published by  *
    00015  *   the Free Software Foundation; either version 2 of the License, or     *
    00016  *   (at your option) any later version.                                   *
    00017  *                                                                         *
    00018  ***************************************************************************/
    00019
    00020 #include <ntqcheckbox.h>
    00021 #include <ntqspinbox.h>
    00022 #include <ntqlabel.h>
    00023 #include <ntqfileinfo.h>
    00024 #include <ntqfiledialog.h>
    00025 #include <ntqpushbutton.h>
    00026
    00027 #include <tdemessagebox.h>
    00028 #include <tdelocale.h>
    00029 #include <knuminput.h>
    00030 #include <kdebug.h>
    00031
    00032 #include "optiondialog.h"
    00033 #include "serverdialog.h"
    00034 #include "configlist.h"
    00035 #include "configelem.h"
    00036 #include "commandlist.h"
    00037
    00038 OptionDialog::OptionDialog(TQWidget *parent, const char *name, ConfigList* config, CommandList* cmd):
    00039        OptionDlg (parent,name,true),
    00040        m_ConfigList (*config),
    00041        m_pConfigList (config),
    00042        m_pCmdList (cmd)
    00043 {
    00044        m_CheckSavePassword->setChecked (m_pConfigList->m_bSavePassword);
    00045        m_CheckConfirmDelete->setChecked (m_pConfigList->confirmDeletion() );
    00046        m_SpinInitTimer->setValue( m_pConfigList->getInitTime() );
    00047        m_SpinIntervalTimer->setValue (m_pConfigList->getRefreshTimeInterval());
    00048     m_SpinPop3Timer->setValue (m_pConfigList->getTimeoutTime() );
    00049     m_CheckBeep->setChecked (m_pConfigList->m_bBeep);
    00050     m_CheckSound->setChecked (m_pConfigList->m_bSound);
    00051        m_ButtonSelectSoundFile->setEnabled (m_pConfigList->m_bSound);
    00052        m_EditSoundFile->setEnabled (m_pConfigList->m_bSound);
    00053        m_ButtonSoundTest->setEnabled (m_pConfigList->m_bSound);
    00054     m_EditSoundFile->setText (m_pConfigList->m_strSoundFile);
    00055     m_CheckStartMinimized->setChecked (m_pConfigList->m_bStartMinimized);
    00056     m_CheckTerminateNoMail->setChecked (m_pConfigList->m_bTerminate);
    00057     m_CheckMinimizeNoMail->setChecked (m_pConfigList->m_bMinimize);
    00058     m_CheckKeepNewMail->setChecked (m_pConfigList->m_bKeepNew);
    00059     m_CheckShowMessagebox->setChecked (m_pConfigList->m_bShowMessage);
    00060     m_CheckShowMainWindow->setChecked (m_pConfigList->m_bShowMainWindow);
    00061     m_CheckExternalProg->setChecked (m_pConfigList->m_bExternalProg);
    00062        m_ButtonExternalProgTest->setEnabled (m_pConfigList->m_bExternalProg);
    00063        m_ComboExternalProg->setEnabled (m_pConfigList->m_bExternalProg);
    00064        TQLabel_5->setEnabled (m_pConfigList->m_bExternalProg);
    00065     m_SpinMaxSize->setValue (m_pConfigList->m_nMaxMailSize);
    00066        m_ConfigList.setCombo (m_ComboAccount);
    00067        m_pCmdList->setCombo (m_ComboExternalProg, m_pConfigList->m_nExternalProg);
    00068        //Modifications made by AM (account columns)
    00069        m_CheckActive->setChecked(m_pConfigList->m_shownAccountColumns[0]);
    00070        m_CheckAccount1->setChecked(m_pConfigList->m_shownAccountColumns[1]);
    00071        m_CheckServer->setChecked(m_pConfigList->m_shownAccountColumns[2]);
    00072        m_CheckUser->setChecked(m_pConfigList->m_shownAccountColumns[3]);
    00073        m_CheckMessages->setChecked(m_pConfigList->m_shownAccountColumns[4]);
    00074        m_CheckSize1->setChecked(m_pConfigList->m_shownAccountColumns[5]);
    00075        //Modifications made by AM (email columns)
    00076        m_CheckNumber->setChecked(m_pConfigList->m_shownMailColumns[0]);
    00077        m_CheckAccount2->setChecked(m_pConfigList->m_shownMailColumns[1]);
    00078        m_CheckFrom->setChecked(m_pConfigList->m_shownMailColumns[2]);
    00079        m_CheckTo->setChecked(m_pConfigList->m_shownMailColumns[3]);
    00080        m_CheckSubject->setChecked(m_pConfigList->m_shownMailColumns[4]);
    00081        m_CheckDate->setChecked(m_pConfigList->m_shownMailColumns[5]);
    00082        m_CheckSize2->setChecked(m_pConfigList->m_shownMailColumns[6]);
    00083        m_CheckContent->setChecked(m_pConfigList->m_shownMailColumns[7]);
    00084        m_CheckState->setChecked(m_pConfigList->m_shownMailColumns[8]);
    00085     // add HTML formatting
    00086     m_checkHTML->setChecked(m_pConfigList->allowHTML() );
    00087     _checkConfirmClose->setChecked(m_pConfigList->m_bConfirmClose);
    00088     // added by morhekil
    00089     // minimize on close
    00090     m_CheckCloseMinimizes->setChecked(m_pConfigList->m_bCloseMinimizes);
    00091     m_CheckMinimizeToTray->setChecked(m_pConfigList->m_bMinimizeToTray);
    00092 }
    00093
    00094 OptionDialog::~OptionDialog(){
    00095 }
    00096
    00097 void OptionDialog::slotButtonAddClicked()
    00098 {
    00099        ConfigElem* pElem = new ConfigElem ( &m_ConfigList );
    00100        ServerDialog dlg (this, "Server Options", pElem, &m_ConfigList);
    00101        if (dlg.exec () == Accepted)
    00102        {
    00103               m_ConfigList.inSort (pElem);
    00104         //connect the signals of the new account
    00105         m_ConfigList.connectAccounts();
    00106
    00107               m_ComboAccount->insertItem (pElem->getAccountName(), m_ConfigList.at ());
    00108               m_ComboAccount->setCurrentItem (m_ConfigList.at ());
    00109        }
    00110        else
    00111               delete pElem;
    00112 }
    00113
    00114 void OptionDialog::slotButtonEditClicked()
    00115 {
    00116        ConfigElem* pElem = m_ConfigList.current ();
    00117        if (pElem)
    00118        {
    00119               ServerDialog dlg (this, "Server Options", pElem, NULL);
    00120               dlg.exec ();
    00121        }
    00122 }
    00123
    00124 void OptionDialog::slotButtonCopyClicked()
    00125 {
    00126        if (m_ConfigList.current())
    00127        {
    00128               ConfigElem* pElem = new ConfigElem (m_ConfigList.current ());
    00129               ServerDialog dlg (this, "Server Options", pElem, &m_ConfigList);
    00130               if (dlg.exec () == Accepted)
    00131               {
    00132                      pElem->clearMailList();
    00133                      m_ConfigList.inSort (pElem);
    00134             m_ConfigList.connectAccounts();
    00135
    00136                      m_ComboAccount->insertItem (pElem->getAccountName(), m_ConfigList.at ());
    00137                      m_ComboAccount->setCurrentItem (m_ConfigList.at ());
    00138               }
    00139               else
    00140                      delete pElem;
    00141        }
    00142 }
    00143
    00144 void OptionDialog::slotButtonDeleteClicked()
    00145 {
    00146        if (m_ConfigList.current())
    00147        {
    00148               if (KMessageBox::warningYesNo (this, i18n("Account %1 will be deleted.\nAre you sure ?").arg(m_ConfigList.current()->getAccountName())) == KMessageBox::Yes)
    00149               {
    00150                      int index = m_ConfigList.at ();
    00151                      m_ConfigList.remove (index);
    00152             m_ConfigList.connectAccounts();
    00153                      m_ComboAccount->removeItem (index);
    00154                      m_ComboAccount->setCurrentItem (m_ConfigList.at ());
    00155               }
    00156        }
    00157 }
    00158
    00159 void OptionDialog::slotButtonOkClicked()
    00160 {
    00161        m_ConfigList.m_bSavePassword = m_CheckSavePassword->isChecked ();
    00162        m_ConfigList.setConfirmDeletion( m_CheckConfirmDelete->isChecked () );
    00163        m_ConfigList.setInitTime( m_SpinInitTimer->value() );
    00164        m_ConfigList.setRefreshTimeInterval( m_SpinIntervalTimer->value () );
    00165     m_ConfigList.setTimeoutTime( m_SpinPop3Timer->value () );
    00166        m_ConfigList.m_nMaxMailSize = m_SpinMaxSize->value ();
    00167        m_ConfigList.m_bBeep = m_CheckBeep->isChecked ();
    00168        m_ConfigList.m_bSound = m_CheckSound->isChecked ();
    00169        m_ConfigList.m_strSoundFile = m_EditSoundFile->text ();
    00170        m_ConfigList.m_bStartMinimized = m_CheckStartMinimized->isChecked ();
    00171        m_ConfigList.m_bTerminate = m_CheckTerminateNoMail->isChecked ();
    00172        m_ConfigList.m_bMinimize = m_CheckMinimizeNoMail->isChecked ();
    00173        m_ConfigList.m_bKeepNew = m_CheckKeepNewMail->isChecked ();
    00174        m_ConfigList.m_bShowMessage = m_CheckShowMessagebox->isChecked ();
    00175        m_ConfigList.m_bShowMainWindow = m_CheckShowMainWindow->isChecked ();
    00176        m_ConfigList.m_nExternalProg = m_ComboExternalProg->currentItem ();
    00177        kdDebug () << "ext prog = " << m_ConfigList.m_nExternalProg << endl;
    00178        kdDebug () << "count = " << m_ConfigList.count() << endl;
    00179        if ((m_ConfigList.m_nExternalProg >= 0) && (m_ConfigList.count() > 0))
    00180               m_ConfigList.m_bExternalProg = m_CheckExternalProg->isChecked ();
    00181        else
    00182               m_ConfigList.m_bExternalProg = false;
    00183        //modifications by AM (hiding columns)
    00184        m_ConfigList.m_shownAccountColumns[0] = m_CheckActive->isChecked();
    00185        m_ConfigList.m_shownAccountColumns[1] = m_CheckAccount1->isChecked();
    00186        m_ConfigList.m_shownAccountColumns[2] = m_CheckServer->isChecked();
    00187        m_ConfigList.m_shownAccountColumns[3] = m_CheckUser->isChecked();
    00188        m_ConfigList.m_shownAccountColumns[4] = m_CheckMessages->isChecked();
    00189        m_ConfigList.m_shownAccountColumns[5] = m_CheckSize1->isChecked();
    00190        m_ConfigList.m_shownMailColumns[0] = m_CheckNumber->isChecked();
    00191        m_ConfigList.m_shownMailColumns[1] = m_CheckAccount2->isChecked();
    00192        m_ConfigList.m_shownMailColumns[2] = m_CheckFrom->isChecked();
    00193        m_ConfigList.m_shownMailColumns[3] = m_CheckTo->isChecked();
    00194        m_ConfigList.m_shownMailColumns[4] = m_CheckSubject->isChecked();
    00195        m_ConfigList.m_shownMailColumns[5] = m_CheckDate->isChecked();
    00196        m_ConfigList.m_shownMailColumns[6] = m_CheckSize2->isChecked();
    00197        m_ConfigList.m_shownMailColumns[7] = m_CheckContent->isChecked();
    00198        m_ConfigList.m_shownMailColumns[8] = m_CheckState->isChecked();
    00199     m_ConfigList.setAllowHTML(  m_checkHTML->isChecked() );
    00200     m_ConfigList.m_bConfirmClose = _checkConfirmClose->isChecked();
    00201
    00202     // added by morhekil
    00203     m_ConfigList.m_bCloseMinimizes = m_CheckCloseMinimizes->isChecked();
    00204     m_ConfigList.m_bMinimizeToTray = m_CheckMinimizeToTray->isChecked();
    00205
    00206     m_ConfigList.saveOptions();
    00207     *m_pConfigList = m_ConfigList;
    00208 }
    00209
    00210 void OptionDialog::slotAccountActivated (int index)
    00211 {
    00212        m_ConfigList.at (index); // will set current item
    00213 }
    00214
    00215 void OptionDialog::slotSavePasswordToggled ()
    00216 {
    00217        if (m_CheckSavePassword->isChecked ())
    00218        {
    00219               if (KMessageBox::warningYesNo (this, i18n("Password will be stored as scrambled text.\n"
    00220                                                    "It might be possible to decipher it.\n"
    00221                                                    "Are you sure ?\n"),
    00222                                          TQString::null,
    00223                                          KStdGuiItem::yes(),
    00224                                          KStdGuiItem::no(),
    00225                                          "savepasswdaskagain") != KMessageBox::Yes)
    00226                      m_CheckSavePassword->setChecked (false);
    00227        }
    00228 }
    00229
    00230 void OptionDialog::slotButtonSelectSoundFile ()
    00231 {
    00232        TQStringList filters;
    00233        filters.append (i18n("Wave files (*.wav)"));
    00234        filters.append (i18n("All files (*)"));
    00235        TQFileInfo info (m_EditSoundFile->text ());
    00236        TQString dir = info.dirPath ();
    00237        TQFileDialog dlg (this, "Sound File", TRUE);
    00238        dlg.setCaption (i18n("Select Sound File"));
    00239        dlg.setDir (dir);
    00240        dlg.setFilters (filters);
    00241        dlg.setMode (TQFileDialog::ExistingFile);
    00242   if (dlg.exec () == TQDialog::Accepted)
    00243               m_EditSoundFile->setText (dlg.selectedFile());
    00244 }
    00245
    00246 void OptionDialog::slotMinimizeNoMailClicked ()
    00247 {
    00248        if (m_CheckMinimizeNoMail->isChecked ())
    00249               m_CheckTerminateNoMail->setChecked (false);
    00250 }
    00251
    00252 void OptionDialog::slotTerminateNoMailClicked ()
    00253 {
    00254        if (m_CheckTerminateNoMail->isChecked ())
    00255               m_CheckMinimizeNoMail->setChecked (false);
    00256 }
    00257
    00258 void OptionDialog::slotSoundTest ()
    00259 {
    00260        m_pConfigList->playSound (m_EditSoundFile->text ());
    00261 }
    00262
    00263 void OptionDialog::slotExternalProgTest ()
    00264 {
    00265        m_pCmdList->exec (m_ComboExternalProg->currentItem (), m_pConfigList->current ());
    00266 }
    00267
    00268