Diffstat (limited to 'noncore/settings/networksettings/ppp/pppmodule.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/pppmodule.cpp | 147 |
1 files changed, 90 insertions, 57 deletions
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp index f7dacf6..a7caffe 100644 --- a/noncore/settings/networksettings/ppp/pppmodule.cpp +++ b/noncore/settings/networksettings/ppp/pppmodule.cpp | |||
@@ -1,7 +1,2 @@ | |||
1 | #include <errno.h> | ||
2 | #include <signal.h> | ||
3 | |||
4 | |||
5 | #include <qpe/config.h> | ||
6 | 1 | ||
7 | #include "modem.h" | 2 | #include "modem.h" |
@@ -12,6 +7,17 @@ | |||
12 | #include "interfaceppp.h" | 7 | #include "interfaceppp.h" |
13 | 8 | ||
9 | /* OPIE */ | ||
10 | #include <qpe/config.h> | ||
11 | #include <qpe/qpeapplication.h> | ||
12 | |||
13 | /* QT */ | ||
14 | |||
15 | /* STD */ | ||
16 | #include <errno.h> | ||
17 | #include <signal.h> | ||
18 | |||
14 | // don't polute global namespace | 19 | // don't polute global namespace |
15 | namespace { | 20 | namespace |
21 | { | ||
16 | /* | 22 | /* |
17 | * If network settings is qutting and we've ppp | 23 | * If network settings is qutting and we've ppp |
@@ -19,10 +25,12 @@ namespace { | |||
19 | * and the interface number | 25 | * and the interface number |
20 | */ | 26 | */ |
21 | struct Connection { | 27 | struct Connection |
28 | { | ||
22 | pid_t pid; | 29 | pid_t pid; |
23 | QString device; | 30 | QString device; |
24 | QString name; | 31 | QString name; |
25 | }; | 32 | }; |
26 | class InterfaceKeeper { | 33 | class InterfaceKeeper |
34 | { | ||
27 | public: | 35 | public: |
28 | InterfaceKeeper(); | 36 | InterfaceKeeper(); |
@@ -54,5 +62,6 @@ PPPModule::PPPModule() : Module() | |||
54 | InterfacePPP *iface; | 62 | InterfacePPP *iface; |
55 | qDebug("getting interfaces"); | 63 | qDebug("getting interfaces"); |
56 | for( it = ifaces.begin(); it != ifaces.end(); ++it ){ | 64 | for( it = ifaces.begin(); it != ifaces.end(); ++it ) |
65 | { | ||
57 | qDebug("ifaces %s %s", it.key().latin1(), it.data().latin1() ); | 66 | qDebug("ifaces %s %s", it.key().latin1(), it.data().latin1() ); |
58 | iface = new InterfacePPP( 0, it.key() ); | 67 | iface = new InterfacePPP( 0, it.key() ); |
@@ -61,5 +70,6 @@ PPPModule::PPPModule() : Module() | |||
61 | 70 | ||
62 | // check if (*it) is one of the running ifaces | 71 | // check if (*it) is one of the running ifaces |
63 | if ( running.contains( it.data() ) ) { | 72 | if ( running.contains( it.data() ) ) |
73 | { | ||
64 | qDebug("iface is running %s", it.key().latin1() ); | 74 | qDebug("iface is running %s", it.key().latin1() ); |
65 | handledInterfaceNames << running[it.data()].device; | 75 | handledInterfaceNames << running[it.data()].device; |
@@ -77,12 +87,15 @@ PPPModule::PPPModule() : Module() | |||
77 | * Delete any interfaces that we own. | 87 | * Delete any interfaces that we own. |
78 | */ | 88 | */ |
79 | PPPModule::~PPPModule(){ | 89 | PPPModule::~PPPModule() |
90 | { | ||
80 | qDebug("PPPModule::~PPPModule() " ); | 91 | qDebug("PPPModule::~PPPModule() " ); |
81 | QMap<QString,QString> ifaces; | 92 | QMap<QString,QString> ifaces; |
82 | InterfaceKeeper keeper; | 93 | InterfaceKeeper keeper; |
83 | Interface *i; | 94 | Interface *i; |
84 | for ( i=list.first(); i != 0; i=list.next() ){ | 95 | for ( i=list.first(); i != 0; i=list.next() ) |
96 | { | ||
85 | /* if online save the state */ | 97 | /* if online save the state */ |
86 | if ( i->getStatus() ) { | 98 | if ( i->getStatus() ) |
99 | { | ||
87 | qDebug("Iface %s is still up", i->getHardwareName().latin1() ); | 100 | qDebug("Iface %s is still up", i->getHardwareName().latin1() ); |
88 | InterfacePPP* ppp = static_cast<InterfacePPP*>(i); | 101 | InterfacePPP* ppp = static_cast<InterfacePPP*>(i); |
@@ -98,6 +111,7 @@ PPPModule::~PPPModule(){ | |||
98 | * Change the current profile | 111 | * Change the current profile |
99 | */ | 112 | */ |
100 | void PPPModule::setProfile(const QString &newProfile){ | 113 | void PPPModule::setProfile(const QString &newProfile) |
101 | profile = newProfile; | 114 | { |
115 | profile = newProfile; | ||
102 | } | 116 | } |
103 | 117 | ||
@@ -107,6 +121,7 @@ void PPPModule::setProfile(const QString &newProfile){ | |||
107 | * @return QString the icon name (minus .png, .gif etc) | 121 | * @return QString the icon name (minus .png, .gif etc) |
108 | */ | 122 | */ |
109 | QString PPPModule::getPixmapName(Interface* ){ | 123 | QString PPPModule::getPixmapName(Interface* ) |
110 | return "ppp"; | 124 | { |
125 | return "ppp"; | ||
111 | } | 126 | } |
112 | 127 | ||
@@ -116,5 +131,6 @@ QString PPPModule::getPixmapName(Interface* ){ | |||
116 | * @return bool true if i is owned by this module, false otherwise. | 131 | * @return bool true if i is owned by this module, false otherwise. |
117 | */ | 132 | */ |
118 | bool PPPModule::isOwner(Interface *i){ | 133 | bool PPPModule::isOwner(Interface *i) |
134 | { | ||
119 | return list.find( i ) != -1; | 135 | return list.find( i ) != -1; |
120 | } | 136 | } |
@@ -124,9 +140,10 @@ bool PPPModule::isOwner(Interface *i){ | |||
124 | * @return QWidget* pointer to this modules configure. | 140 | * @return QWidget* pointer to this modules configure. |
125 | */ | 141 | */ |
126 | QWidget *PPPModule::configure(Interface *i){ | 142 | QWidget *PPPModule::configure(Interface *i) |
143 | { | ||
127 | qDebug("return ModemWidget"); | 144 | qDebug("return ModemWidget"); |
128 | PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, | 145 | PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, |
129 | 0, "PPPConfig", false, | 146 | 0, "PPPConfig", false, |
130 | (Qt::WDestructiveClose | Qt::WStyle_ContextHelp)); | 147 | (Qt::WDestructiveClose | Qt::WStyle_ContextHelp)); |
131 | return pppconfig; | 148 | return pppconfig; |
132 | } | 149 | } |
@@ -136,9 +153,10 @@ QWidget *PPPModule::configure(Interface *i){ | |||
136 | * @return QWidget* pointer to this modules info. | 153 | * @return QWidget* pointer to this modules info. |
137 | */ | 154 | */ |
138 | QWidget *PPPModule::information(Interface *i){ | 155 | QWidget *PPPModule::information(Interface *i) |
139 | // We don't have any advanced pppd information widget yet :-D | 156 | { |
140 | // TODO ^ | 157 | // We don't have any advanced pppd information widget yet :-D |
158 | // TODO ^ | ||
141 | 159 | ||
142 | return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i ); | 160 | return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i ); |
143 | } | 161 | } |
144 | 162 | ||
@@ -148,8 +166,9 @@ QWidget *PPPModule::information(Interface *i){ | |||
148 | * been called by isOwner() | 166 | * been called by isOwner() |
149 | */ | 167 | */ |
150 | QList<Interface> PPPModule::getInterfaces(){ | 168 | QList<Interface> PPPModule::getInterfaces() |
151 | // List all of the files in the peer directory | 169 | { |
170 | // List all of the files in the peer directory | ||
152 | qDebug("PPPModule::getInterfaces"); | 171 | qDebug("PPPModule::getInterfaces"); |
153 | return list; | 172 | return list; |
154 | } | 173 | } |
155 | 174 | ||
@@ -160,21 +179,25 @@ QList<Interface> PPPModule::getInterfaces(){ | |||
160 | * @return Interface* NULL if it was unable to be created. | 179 | * @return Interface* NULL if it was unable to be created. |
161 | */ | 180 | */ |
162 | Interface *PPPModule::addNewInterface(const QString &newInterface){ | 181 | Interface *PPPModule::addNewInterface(const QString &newInterface) |
163 | 182 | { | |
164 | InterfacePPP *ifaceppp; | 183 | |
165 | Interface *iface; | 184 | InterfacePPP *ifaceppp; |
166 | ifaceppp = new InterfacePPP(); | 185 | Interface *iface; |
167 | PPPConfigWidget imp(ifaceppp, 0, "PPPConfigImp", true); | 186 | ifaceppp = new InterfacePPP(); |
168 | imp.showMaximized(); | 187 | PPPConfigWidget imp(ifaceppp, 0, "PPPConfigImp", true); |
169 | if(imp.exec() == QDialog::Accepted ){ | 188 | |
170 | iface = (InterfacePPP*) ifaceppp; | 189 | if( QPEApplication::execDialog( &imp ) == QDialog::Accepted ) |
171 | iface->setModuleOwner( this ); | 190 | { |
172 | list.append( iface ); | 191 | iface = (InterfacePPP*) ifaceppp; |
173 | return iface; | 192 | iface->setModuleOwner( this ); |
174 | }else { | 193 | list.append( iface ); |
175 | delete ifaceppp; | 194 | return iface; |
176 | iface = NULL; | 195 | } |
177 | } | 196 | else |
178 | return iface; | 197 | { |
198 | delete ifaceppp; | ||
199 | iface = NULL; | ||
200 | } | ||
201 | return iface; | ||
179 | } | 202 | } |
180 | 203 | ||
@@ -183,5 +206,6 @@ Interface *PPPModule::addNewInterface(const QString &newInterface){ | |||
183 | * @return bool true if successful, false otherwise. | 206 | * @return bool true if successful, false otherwise. |
184 | */ | 207 | */ |
185 | bool PPPModule::remove(Interface *i){ | 208 | bool PPPModule::remove(Interface *i) |
209 | { | ||
186 | return list.remove(i); | 210 | return list.remove(i); |
187 | } | 211 | } |
@@ -195,11 +219,14 @@ void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) | |||
195 | 219 | ||
196 | 220 | ||
197 | namespace { | 221 | namespace |
198 | InterfaceKeeper::InterfaceKeeper( ) { | 222 | { |
199 | } | 223 | InterfaceKeeper::InterfaceKeeper( ) |
200 | InterfaceKeeper::~InterfaceKeeper() { | 224 | {} |
225 | InterfaceKeeper::~InterfaceKeeper() | ||
226 | { | ||
201 | Config cfg("ppp_plugin_keeper"); | 227 | Config cfg("ppp_plugin_keeper"); |
202 | QStringList lst = cfg.groupList(); | 228 | QStringList lst = cfg.groupList(); |
203 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 229 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) |
230 | { | ||
204 | Connection con; | 231 | Connection con; |
205 | cfg.setGroup( (*it) ); | 232 | cfg.setGroup( (*it) ); |
@@ -207,5 +234,6 @@ namespace { | |||
207 | } | 234 | } |
208 | 235 | ||
209 | for (QMap<QString, Connection>::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it ) { | 236 | for (QMap<QString, Connection>::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it ) |
237 | { | ||
210 | Connection con = it.data(); | 238 | Connection con = it.data(); |
211 | cfg.setGroup( con.name ); | 239 | cfg.setGroup( con.name ); |
@@ -214,5 +242,6 @@ namespace { | |||
214 | } | 242 | } |
215 | } | 243 | } |
216 | void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name ) { | 244 | void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name ) |
245 | { | ||
217 | Connection con; | 246 | Connection con; |
218 | con.pid = pid; | 247 | con.pid = pid; |
@@ -221,9 +250,11 @@ namespace { | |||
221 | m_interfaces.insert( name, con ); | 250 | m_interfaces.insert( name, con ); |
222 | } | 251 | } |
223 | QMap<QString, Connection> InterfaceKeeper::interfaces()const { | 252 | QMap<QString, Connection> InterfaceKeeper::interfaces()const |
253 | { | ||
224 | Config cfg("ppp_plugin_keeper"); | 254 | Config cfg("ppp_plugin_keeper"); |
225 | QMap<QString, Connection> ifaces; | 255 | QMap<QString, Connection> ifaces; |
226 | QStringList lst = cfg.groupList(); | 256 | QStringList lst = cfg.groupList(); |
227 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 257 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) |
258 | { | ||
228 | Connection con; | 259 | Connection con; |
229 | cfg.setGroup( (*it) ); | 260 | cfg.setGroup( (*it) ); |
@@ -238,6 +269,8 @@ namespace { | |||
238 | return ifaces; | 269 | return ifaces; |
239 | } | 270 | } |
240 | bool InterfaceKeeper::isAvailable( pid_t p)const { | 271 | bool InterfaceKeeper::isAvailable( pid_t p)const |
241 | if (::kill(p, 0 ) == 0 || errno != ESRCH ) { | 272 | { |
273 | if (::kill(p, 0 ) == 0 || errno != ESRCH ) | ||
274 | { | ||
242 | qDebug("isAvailable %d", p); | 275 | qDebug("isAvailable %d", p); |
243 | return true; | 276 | return true; |