summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/lancard/lancardedit.cpp
blob: fa7f6dc1169b9ee86a02a477cca6cbd57ad7ab01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <GUIUtils.h>
#include <resources.h>
#include <qlistview.h>
#include <qcheckbox.h>
#include <qheader.h>
#include <qregexp.h>
#include "lancardedit.h"

LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){
    System & S = NSResources->system();
    QRegExp R( "eth[0-9]" );
    QCheckListItem * CLI;

    LanCards_LV->header()->hide();

    // populate with all lancards in system
    for( QDictIterator<InterfaceInfo> It(S.interfaces());
         It.current();
         ++It ) {
      if( R.match( It.current()->Name ) >= 0 &&
          It.current()->CardType == ARPHRD_ETHER
        ) {
        CLI = new QCheckListItem( LanCards_LV, It.current()->Name,
              QCheckListItem::CheckBox );
        CLI->setText( 1, It.current()->MACAddress );
      }
    }
}

QString LanCardEdit::acceptable( void ) {
    return QString();
}


bool LanCardEdit::commit( LanCardData & Data ) {
    bool SM = 0;
    CBM( Data.AnyLanCard, AnyCard_CB, SM );

    if( ! Data.AnyLanCard ) {
      // collect set of lancards that match
      int idx;
      QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
      while( CLI ) {
        idx = Data.HWAddresses.findIndex(CLI->text(1));
        if( CLI->isOn() ) {
          if( idx < 0 ) {
            // should be in list
            Data.HWAddresses.append( CLI->text(1) );
            SM = 1;
          }
        } else {
          // should not be in list
          if( idx >= 0 ) {
            Data.HWAddresses.remove( Data.HWAddresses.at(idx) );
            SM = 1;
          }
        }
        CLI = (QCheckListItem *)CLI->nextSibling();
      }
    }
    return SM || ContainedObsoleteMAC ;
}

void LanCardEdit::showData( LanCardData & Data ) {
    AnyCard_CB->setChecked( Data.AnyLanCard );

    QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();

    ContainedObsoleteMAC = 0;
    // remove obsolete address
    for( QStringList::Iterator it=Data.HWAddresses.begin();
         it != Data.HWAddresses.end(); 
         ) {
      CLI = (QCheckListItem *)LanCards_LV->firstChild();
      while( CLI ) {
        if( CLI->text(1) == (*it) ) 
          // still valid
          break;
        CLI = (QCheckListItem *)CLI->nextSibling();
      }
      if( CLI == 0 ) {
        // address not found -> remove
        ContainedObsoleteMAC = 1;
        Data.HWAddresses.remove( it );
      } else {
        ++ it;
      }
    }

    // set checks
    while( CLI ) {
      CLI->setOn( Data.HWAddresses.findIndex(CLI->text(1)) >= 0 );
      CLI = (QCheckListItem *)CLI->nextSibling();
    }
}