Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

lancardedit.cpp

Go to the documentation of this file.
00001 #include <GUIUtils.h>
00002 #include <resources.h>
00003 #include <qarray.h>
00004 #include <qlistview.h>
00005 #include <qcheckbox.h>
00006 #include <qheader.h>
00007 #include <qregexp.h>
00008 
00009 #include "lancardedit.h"
00010 #include "lancard_NN.h"
00011 #include "lancard_NNI.h"
00012 
00013 LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){
00014     LanCards_LV->header()->hide();
00015 
00016 }
00017 
00018 QString LanCardEdit::acceptable( void ) {
00019     return QString();
00020 }
00021 
00022 bool LanCardEdit::commit( LanCardData & Data ) {
00023     bool SM = 0;
00024     CBM( Data.AnyLanCard, AnyCard_CB, SM );
00025 
00026     if( ! Data.AnyLanCard ) {
00027       // take copy for orig list
00028       QStringList NewList( Data.HWAddresses );
00029 
00030       // update HWAddresses to new state
00031       // remove item also from NewList
00032       int idx;
00033       QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
00034       while( CLI ) {
00035         idx = Data.HWAddresses.findIndex(CLI->text(0));
00036         if( CLI->isOn() ) {
00037           if( idx < 0 ) {
00038             // should be in list
00039             Data.HWAddresses.append( CLI->text(0) );
00040             SM = 1;
00041           }
00042         } else {
00043           // should not be in list
00044           if( idx >= 0 ) {
00045             NewList.remove( CLI->text(0) );
00046             Data.HWAddresses.remove( CLI->text(0) );
00047             SM = 1;
00048           }
00049         }
00050         CLI = (QCheckListItem *)CLI->nextSibling();
00051       }
00052 
00053       // if newlist still contains items. it were items
00054       // that were checked but no longer are present in the system
00055       SM |= ( NewList.count() > 0 ) ;
00056     }
00057     return SM;
00058 }
00059 
00060 void LanCardEdit::showData( ALanCard * LC ) {
00061     NNI = LC;
00062     LanCardData & Data = *((LanCardData *)LC->data());
00063 
00064     AnyCard_CB->setChecked( Data.AnyLanCard );
00065 
00066     // load all cards
00067     populateList();
00068 
00069     // set checks
00070     QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
00071     while( CLI ) {
00072       CLI->setOn( Data.HWAddresses.findIndex(CLI->text(0)) >= 0 );
00073       CLI = (QCheckListItem *)CLI->nextSibling();
00074     }
00075 }
00076 
00077 // load all known cards in list
00078 void LanCardEdit::populateList( void ) {
00079     LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass();
00080     QCheckListItem * CLI;
00081     bool Found;
00082 
00083     LanCards_LV->clear();
00084 
00085     for( QStringList::Iterator it = NN->addressesOfNIC().begin();
00086          it != NN->addressesOfNIC().end(); 
00087          ++it ) {
00088       CLI = new QCheckListItem( LanCards_LV, (*it), QCheckListItem::CheckBox );
00089 
00090       // check interfaces and see if this card is present
00091       Found = 0;
00092       for( QDictIterator<InterfaceInfo> NIt(NSResources->system().interfaces());
00093            NIt.current();
00094            ++NIt ) {
00095         if( NIt.current()->MACAddress == (*it) ) {
00096           Found = 1;
00097           break;
00098         }
00099       }
00100 
00101       CLI->setPixmap( 0, NSResources->getPixmap( 
00102         (Found) ? "add" : "remove" ) );
00103     }
00104 }
00105 
00106 // rescan system for new cards
00107 void LanCardEdit::SLOT_ScanCards( void ) {
00108     LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass();
00109 
00110     // add any NIC that is new and matches our interfacename
00111     System & S = NSResources->system();
00112     QRegExp R( "eth[0-9]" );
00113     // populate with all lancards in system
00114     for( QDictIterator<InterfaceInfo> It(S.interfaces());
00115          It.current();
00116          ++It ) {
00117       Log(( "TEST %s %s\n", 
00118           It.current()->Name.latin1(),
00119           It.current()->MACAddress.latin1() ));
00120       if( R.match( It.current()->Name ) >= 0 &&
00121           ( It.current()->CardType == ARPHRD_ETHER
00122 #ifdef ARPHRD_IEEE1394
00123             || It.current()->CardType == ARPHRD_IEEE1394
00124 #endif
00125           )
00126         ) {
00127         // old item ?
00128         QCheckListItem * CLI = 
00129                           (QCheckListItem *)LanCards_LV->firstChild();
00130         while( CLI ) {
00131           if( CLI->text(0) == It.current()->MACAddress ) {
00132             break;
00133           }
00134           CLI = (QCheckListItem *)CLI->nextSibling();
00135         }
00136 
00137         if( ! CLI ) {
00138           // new item
00139           CLI = new QCheckListItem( LanCards_LV, 
00140                 It.current()->MACAddress,
00141                 QCheckListItem::CheckBox );
00142         }
00143 
00144         // mark present
00145         CLI->setPixmap( 0, NSResources->getPixmap( 
00146                     "add" ) );
00147 
00148         if( NN->addressesOfNIC().findIndex( It.current()->MACAddress) < 0 ) {
00149           // new
00150           NN->addressesOfNIC().append( It.current()->MACAddress );
00151         }
00152       }
00153     }
00154 
00155 }
00156 
00157 // remove all cards that are not present -> flagged with 'remove'
00158 // and unchecked
00159 void LanCardEdit::SLOT_RemoveUnknown( void ) {
00160     QArray<QCheckListItem *> AllItems;
00161 
00162     LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass();
00163 
00164     QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
00165     while( CLI ) {
00166       AllItems.resize( AllItems.size()+1 );
00167       AllItems[ AllItems.size()-1 ] = CLI;
00168       CLI = (QCheckListItem *)CLI->nextSibling();
00169     }
00170 
00171     // force update of system
00172     System & S = NSResources->system();
00173     S.probeInterfaces();
00174 
00175     // add any NIC that is new and matches our interfacename
00176     QRegExp R( "eth[0-9]" );
00177 
00178 
00179     for( QDictIterator<InterfaceInfo> It(S.interfaces());
00180          It.current();
00181          ++It ) {
00182       if( R.match( It.current()->Name ) >= 0 &&
00183           ( It.current()->CardType == ARPHRD_ETHER
00184 #ifdef ARPHRD_IEEE1394
00185             || It.current()->CardType == ARPHRD_IEEE1394
00186 #endif
00187           )
00188         ) {
00189 
00190         for ( unsigned i = 0; i< AllItems.size(); i++ ) {
00191           if( AllItems[i] &&
00192               AllItems[i]->text(0) == It.current()->MACAddress ) {
00193             AllItems[i] = 0;
00194             break;
00195           }
00196         }
00197       }
00198     }
00199 
00200     // AllItems now contains all cards NOT present
00201     // remove all items non null and not ON
00202     for ( unsigned i = 0; i< AllItems.size(); i++ ) {
00203       if( AllItems[i] && ! AllItems[i]->isOn() ) {
00204         NN->addressesOfNIC().remove( AllItems[i]->text(0) );
00205         delete AllItems[i];
00206       }
00207     }
00208 }

Generated on Sat Nov 5 16:17:53 2005 for OPIE by  doxygen 1.4.2