commandlist.cpp

00001 /***************************************************************************
00002                           commandlist.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 <kdebug.h>
00019 #include "commandentry.h"
00020 #include "commandlist.h"
00021 
00022 CommandList::CommandList()
00023 {
00024        setAutoDelete (true);
00025 }
00026 
00027 CommandList::~CommandList()
00028 {
00029 }
00030 
00031 void CommandList::setCombo (TQComboBox* combo, int nIndex)
00032 {
00033        combo->clear ();
00034        for (CommandEntry* pElem = first(); pElem; pElem = next())
00035        {
00036               combo->insertItem (pElem->m_name);
00037        }
00038        if (nIndex >= 0)
00039        {
00040               at (nIndex);
00041               combo->setCurrentItem (nIndex);
00042        }
00043 }
00044 
00045 CommandList& CommandList::operator = (CommandList& list)
00046 {
00047        clear ();
00048        int nIndex = list.at ();
00049        for (CommandEntry* item = list.first (); item; item = list.next ())
00050        {
00051               append (new CommandEntry (item));         
00052        }
00053        at (nIndex);
00054        return *this;
00055 }
00056 
00057 bool CommandList::exec (unsigned int id, ConfigElem* pelem, const char* header, const char* body)
00058 {
00059        bool result = false;
00060        CommandEntry* test = new CommandEntry (NULL, NULL, id, true);
00061        int pos = find (test);
00062        if (pos >= 0)
00063        {
00064               result = at (pos)->exec (pelem, header, body);
00065        }
00066        else
00067               kdError () << "No ID " << id << " found in commandlist." << endl;
00068        delete test;
00069        return result;
00070 }
00071 
00072 bool CommandList::exec (unsigned int pos, ConfigElem* pelem)
00073 {
00074        // command may have bee deleted
00075        if (pos < count ())
00076               return at (pos)->exec (pelem);
00077        else
00078               return false;
00079 }
00080 
00081 int CommandList::compareItems (TQPtrCollection::Item item1, TQPtrCollection::Item item2 )
00082 {
00083        CommandEntry* entry1 = (CommandEntry*) item1;
00084        CommandEntry* entry2 = (CommandEntry*) item2;
00085        if (entry1->m_id > entry2->m_id)
00086               return 1;
00087        else if (entry1->m_id == entry2->m_id)
00088               return 0;
00089        else return -1;
00090 }
00091 
00092 TQPtrCollection::Item CommandList::newItem (TQPtrCollection::Item d)
00093 {
00094        return new CommandEntry ((CommandEntry*)d);
00095 }
00096 
00097 void CommandList::readOptions (TDEConfig* config)
00098 {
00099        config->setGroup ("usercommands");
00100        bool goon = true;
00101        int i = 0;
00102        while (goon)
00103        {
00104               TQString cmd (config->readEntry (TQString ("cmd%1").arg(i)));
00105               if (!cmd.isEmpty ())
00106               {
00107                      TQString path = config->readEntry (TQString("path%1").arg(i));
00108                      int id = config->readNumEntry (TQString("id%1").arg(i));
00109       bool modal = config->readBoolEntry (TQString("modal%1").arg(i), true);
00110       append (new CommandEntry (cmd, path, id, modal));
00111                      i++;
00112               }
00113               else
00114                      goon = false;
00115        }
00116        if (i > 0)
00117               at (0);
00118 }
00119 
00120 void CommandList::saveOptions (TDEConfig* config)
00121 {
00122        kdDebug () << "CommandList::saveOptions" << endl;
00123        config->setGroup ("usercommands");
00124        for (unsigned int i = 0; i < count (); i++)
00125        {
00126               config->writeEntry (TQString("cmd%1").arg(i), at(i)->m_name);
00127               config->writeEntry (TQString("path%1").arg(i), at(i)->m_path);
00128               config->writeEntry (TQString("id%1").arg(i), at(i)->m_id);
00129               config->writeEntry (TQString("modal%1").arg(i), at(i)->m_waitForCommand);
00130        }
00131 }

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