summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/wlan/wlan_NNI.cpp
blob: 61969f24eca4feec0724d4d1dbe1d38cf36c60ec (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <unistd.h>
#include "wlanedit.h"
#include "wlan_NNI.h"
#include "wlan_NN.h"

AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) {
    GUI = 0;
    RT = 0;
    Data.ESSID = "";
    Data.NodeName = tr("<UseHostName>");
    Data.Mode = 0;
    Data.SpecificAP = 0;
    Data.APMac = "";
    Data.Encrypted = 0;
    Data.AcceptNonEncrypted = 0;
    Data.Key[0] = "";
    Data.Key[1] = "";
    Data.Key[2] = "";
    Data.Key[3] = "";
}

void AWLan::setSpecificAttribute( QString & A, QString & V ) {
    if( A == "essid" ) {
      Data.ESSID = V;
    } else if( A == "nodename" ) {
      Data.NodeName = V;
    } else if( A == "mode" ) {
      Data.Mode = V.toShort();
    } else if( A == "specificap" ) {
      Data.SpecificAP = (V=="yes");
    } else if( A == "apmac" ) {
      Data.APMac = V;
    } else if( A == "encrypted" ) {
      Data.Encrypted = (V=="yes");
    } else if( A == "acceptnonencrypted" ) {
      Data.AcceptNonEncrypted = (V=="yes");
    } else if( A == "key0" ) {
      Data.Key[0] = V;
    } else if( A == "key1" ) {
      Data.Key[1] = V;
    } else if( A == "key2" ) {
      Data.Key[2] = V;
    } else if( A == "key3" ) {
      Data.Key[3] = V;
    }
}

void AWLan::saveSpecificAttribute( QTextStream & S ) {
    S << "essid=" << quote( Data.ESSID ) << endl;
    S << "nodename=" << quote( Data.NodeName ) << endl;
    S << "mode=" << Data.Mode << endl;
    S << "specificap=" 
      << ((Data.SpecificAP) ? "yes" : "no") 
      << endl;
    S << "apmac=" << Data.APMac << endl;
    S << "encrypted=" 
      << ((Data.Encrypted) ? "yes" : "no") 
      << endl;
    S << "acceptnonencrypted=" 
      << ((Data.AcceptNonEncrypted) ? "yes" : "no") 
      << endl;
    for( int i = 0 ;i < 4 ; i ++ ) {
      S << "key" << i << "=" << Data.Key[i] << endl;
    }
}

QWidget * AWLan::edit( QWidget * parent ) {
    GUI = new WLanEdit( parent, this );
    GUI->showData( Data );
    return GUI;
}

QString AWLan::acceptable( void ) {
    return ( GUI ) ? GUI->acceptable( ) : QString();
}

void AWLan::commit( void ) {
    if( GUI && GUI->commit( Data ) )
      setModified( 1 );
}

bool AWLan::generateDataForCommonFile( 
                                SystemFile & S, 
                                long ) {

      S << "  wireless_essid \""
        << Data.ESSID
        << "\""
        << endl;

      if( ! Data.NodeName.isEmpty() ) {
        if( Data.NodeName == tr("<UseHostName>") ) {
          char Buf[100];
          if( gethostname(Buf, sizeof(Buf) ) == 0 ) {
            Buf[99] = '\0'; // just to make sure
            S << "  wireless_nick "  
              << Buf
              << endl;
          }
        } else {
          S << "  wireless_nick \""  
            << Data.NodeName
            << "\""
            << endl;
        }
      }

      char * M;
      switch ( Data.Mode ) {
        case 0 : 
          M = "Auto";
          break;
        case 1 : 
          M = "Managed";
          break;
        case 2 : 
          M = "Ad-Hoc";
          break;
      }

      S << "  wireless_mode "
        << M
        << endl;
      if( Data.Encrypted ) {
        for( int i = 0; i < 4; i ++ ) {
          if( ! Data.Key[i].isEmpty() ) {
            S << "  wireless_key"
              << i
              << " "
              << Data.Key[i]
              << endl;
          }
        }
        S << "  wireless_keymode "
          << ((Data.AcceptNonEncrypted) ? "open" : "restricted")
          << endl;
      }
      return 0;
}