filterdialog.cpp

00001 /***************************************************************************
00002                           filterdialog.cpp  -  description
00003                              -------------------
00004     begin                : Die Sep 23 2003
00005     copyright            : (C) 2003 by Eggert Ehmke
00006     email                : eggert.ehmke@berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <qradiobutton.h>
00019 #include <qcombobox.h>
00020 #include <klocale.h>
00021 #include <kmessagebox.h>
00022 #include <kdebug.h>
00023  
00024 #include "filterdialog.h"
00025 #include "filterentrydialog.h"
00026 
00027 FilterDialog::FilterDialog(QWidget *parent, const char *name ) :
00028   FilterDlg(parent,name)
00029 {
00030   switch (Filter::_status)
00031   {
00032     case Filter::off:
00033       _radioOff->setChecked(true);
00034       break;
00035     case Filter::on:
00036       _radioOn->setChecked(true);
00037       break;
00038     case Filter::automatic:
00039       _radioAuto->setChecked(true);
00040       break;
00041   }
00042   _filters = Filter::_filter;
00043   _filters.setCombo(_comboFilter, 0);
00044 }
00045 
00046 FilterDialog::~FilterDialog()
00047 {
00048 }
00049 
00050 void FilterDialog::slotFilterActivated (int index)
00051 {
00052   _filters.at (index);
00053 }
00054 
00055 void FilterDialog::slotAdd ()
00056 {
00057        FilterElem* entry = new FilterElem ();
00058        FilterEntryDialog dlg (this, "New filter", entry);
00059        if (dlg.exec () == QDialog::Accepted)
00060        {
00061               _filters.inSort (entry);
00062               int pos = _filters.at ();
00063     _filters.setCombo(_comboFilter, pos);
00064   }
00065        else
00066               delete entry;
00067 }
00068 
00069 void FilterDialog::slotEdit ()
00070 {
00071        if (_filters.current ())
00072        {
00073               FilterEntryDialog dlg (this, "Edit command", _filters.current ());
00074               if (dlg.exec () == QDialog::Accepted)
00075               {
00076                      // the command name may have changed. Update the combo box.
00077       _filters.sort();
00078       int pos = _filters.at ();
00079       _filters.setCombo(_comboFilter, pos);
00080               }
00081        }
00082 }
00083 
00084 void FilterDialog::slotCopy ()
00085 {
00086        if (_filters.current ())
00087        {
00088               FilterElem* entry = new FilterElem (*_filters.current ());
00089               FilterEntryDialog dlg (this, "Copy command", entry);
00090               if (dlg.exec () == QDialog::Accepted)
00091               {
00092                      _filters.inSort (entry);
00093                      int pos = _filters.at ();
00094       _filters.setCombo(_comboFilter, pos);
00095               }
00096               else
00097                      delete entry;
00098        }
00099 }
00100 
00101 void FilterDialog::slotDelete ()
00102 {
00103        if (_filters.current())
00104        {
00105               if (KMessageBox::warningYesNo (this, i18n("Filter %1 will be deleted.\n"
00106                                               "Are you sure ?").arg(_filters.current()->toString())) == KMessageBox::Yes)
00107               {
00108                      int pos = _filters.at ();
00109                      _filters.remove (pos);
00110       _filters.setCombo(_comboFilter, pos);
00111               }
00112        }
00113 }
00114 
00115 void FilterDialog::slotOk ()
00116 {
00117   if (_radioOff->isChecked())
00118     Filter::_status = Filter::off;
00119   else if (_radioOn->isChecked())
00120     Filter::_status = Filter::on;
00121   else if (_radioAuto->isChecked())
00122     Filter::_status = Filter::automatic;
00123   else
00124     Filter::_status = Filter::off;
00125   
00126   Filter::_filter = _filters;
00127   accept ();
00128 }
00129 
00130 void FilterDialog::slotAutomaticActivated ()
00131 {
00132   if (_radioAuto->isChecked())
00133   {
00134     if (KMessageBox::warningContinueCancel (this, i18n("Automatic filters can cause loss of important mails.\n"
00135                                                        "Please test your filters.\n"
00136                                                        "Are you sure ?"),
00137                                                        QString::null,
00138                                                        KStdGuiItem::cont(),
00139                                                        "autofilteraskagain") == KMessageBox::Cancel)
00140       _radioOn->setChecked (true);
00141   }
00142 }
00143 

Generated on Thu Jul 5 19:36:06 2007 for kshowmail by  doxygen 1.5.0