commanddialog.cpp

00001 /***************************************************************************
00002                           commanddialog.cpp  -  description
00003                              -------------------
00004     begin                : Wed Oct 31 2001
00005     copyright            : (C) 2001 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 <tdelocale.h>
00019 #include <tdemessagebox.h>
00020 #include "kshowmail.h"
00021 #include "commanddialog.h"
00022 #include "commandentrydialog.h"
00023 
00024 CommandDialog::CommandDialog(TQWidget *parent, const char *name, CommandList* list, ConfigElem* pConfig, ConfigList* pConfigList):
00025        CommandDlg(parent,name,true),
00026 //     m_locallist (*list), we don't have a proper copy contructor
00027        m_plist (list),
00028        m_pConfigList (pConfigList),
00029        m_pConfig (pConfig)
00030 {
00031        m_locallist = *list;
00032        int index = list->at ();
00033        for (unsigned int i = 0; i < list->count(); i ++)
00034        {
00035               m_ComboCommand->insertItem (m_locallist.at (i)->m_name);
00036        }
00037        m_locallist.at (index);
00038        m_ComboCommand->setCurrentItem (index);
00039 }
00040 
00041 CommandDialog::~CommandDialog()
00042 {
00043 }
00044 
00045 void CommandDialog::slotAdd ()
00046 {
00047        CommandEntry* entry = new CommandEntry ();
00048        CommandEntryDialog dlg (this, "New command", entry, m_pConfig);
00049        if (dlg.exec () == TQDialog::Accepted)
00050        {
00051               m_locallist.append (entry);
00052               int pos = m_locallist.at ();
00053     m_locallist.setCombo (m_ComboCommand, pos);
00054   }
00055        else
00056               delete entry;
00057 }
00058 
00059 void CommandDialog::slotEdit ()
00060 {
00061        if (m_locallist.current ())
00062        {
00063               CommandEntryDialog dlg (this, "Edit command", m_locallist.current (), m_pConfig);
00064               if (dlg.exec () == TQDialog::Accepted)
00065               {
00066                      // the command name may have changed. Update the combo box.
00067                      int pos = m_locallist.at ();
00068       m_locallist.setCombo (m_ComboCommand, pos);
00069               }
00070        }
00071 }
00072 
00073 void CommandDialog::slotCopy ()
00074 {
00075        if (m_locallist.current ())
00076        {
00077               CommandEntry* entry = new CommandEntry (m_locallist.current ());
00078               CommandEntryDialog dlg (this, "Copy command", entry, m_pConfig);
00079               if (dlg.exec () == TQDialog::Accepted)
00080               {
00081                      m_locallist.append (entry);
00082                      int pos = m_locallist.at ();
00083       m_locallist.setCombo (m_ComboCommand, pos);
00084               }
00085               else
00086                      delete entry;
00087        }
00088 }
00089 
00090 void CommandDialog::slotDelete ()
00091 {
00092        if (m_locallist.current())
00093        {
00094               if (KMessageBox::warningYesNo (this, i18n("Command %1 will be deleted.\nAre you sure ?").arg(m_locallist.current()->m_name)) == KMessageBox::Yes)
00095               {
00096                      int pos = m_locallist.at ();
00097                      m_locallist.remove (pos);
00098       m_locallist.setCombo (m_ComboCommand, pos);
00099               }
00100        }
00101 }
00102 
00103 void CommandDialog::slotOk ()
00104 {
00105        *m_plist = m_locallist;
00106        int index = m_locallist.at ();
00107        for (unsigned int i = 0; i < m_plist->count (); i++)
00108        {
00109               if (m_plist->at (i)->m_name == "complain")
00110                      m_plist->at (i)->m_id = ID_OPTION_COMPLAIN;
00111               else
00112                      m_plist->at (i)->m_id = ID_OPTION_COMPLAIN + 1 + i;
00113        }
00114        if (m_pConfigList->m_bExternalProg && (m_pConfigList->m_nExternalProg >= m_plist->count ()))
00115        {
00116               m_pConfigList->m_bExternalProg = false;
00117               m_pConfigList->m_nExternalProg = -1;
00118        }
00119        m_plist->at (index);
00120        accept ();
00121 }
00122 
00123 void CommandDialog::slotCommandActivated (int index)
00124 {
00125        m_locallist.at (index); // will set current item
00126 }
00127 
00128 

Generated on Wed May 16 21:15:18 2007 for kshowmail by  doxygen 1.5.0