summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp
index b102a10..fb279ee 100644
--- a/noncore/settings/networksettings/ppp/pppmodule.cpp
+++ b/noncore/settings/networksettings/ppp/pppmodule.cpp
@@ -1,285 +1,286 @@
1 1
2#include "modem.h" 2#include "modem.h"
3#include "pppconfig.h" 3#include "pppconfig.h"
4#include "pppmodule.h" 4#include "pppmodule.h"
5#include "pppdata.h" 5#include "pppdata.h"
6#include "interfaceinformationppp.h" 6#include "interfaceinformationppp.h"
7#include "interfaceppp.h" 7#include "interfaceppp.h"
8 8
9/* OPIE */ 9/* OPIE */
10#include <opie2/odebug.h> 10#include <opie2/odebug.h>
11#include <qpe/config.h> 11#include <qpe/config.h>
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13using namespace Opie::Core; 13using namespace Opie::Core;
14 14
15/* QT */ 15/* QT */
16#include <qt.h>
16 17
17/* STD */ 18/* STD */
18#include <errno.h> 19#include <errno.h>
19#include <signal.h> 20#include <signal.h>
20 21
21// don't polute global namespace 22// don't polute global namespace
22namespace 23namespace
23{ 24{
24 /* 25 /*
25 * If network settings is qutting and we've ppp 26 * If network settings is qutting and we've ppp
26 * devices open we need to save the pid_t the PPData 27 * devices open we need to save the pid_t the PPData
27 * and the interface number 28 * and the interface number
28 */ 29 */
29 struct Connection 30 struct Connection
30 { 31 {
31 pid_t pid; 32 pid_t pid;
32 QString device; 33 QString device;
33 QString name; 34 QString name;
34 }; 35 };
35 class InterfaceKeeper 36 class InterfaceKeeper
36 { 37 {
37 public: 38 public:
38 InterfaceKeeper(); 39 InterfaceKeeper();
39 ~InterfaceKeeper(); 40 ~InterfaceKeeper();
40 41
41 void addInterface( pid_t, const QString& pppDev, const QString& name ); 42 void addInterface( pid_t, const QString& pppDev, const QString& name );
42 QMap<QString, Connection> interfaces()const; // will check if still available 43 QMap<QString, Connection> interfaces()const; // will check if still available
43 private: 44 private:
44 bool isAvailable( pid_t )const; 45 bool isAvailable( pid_t )const;
45 QMap<QString, Connection> m_interfaces; 46 QMap<QString, Connection> m_interfaces;
46 }; 47 };
47} 48}
48 49
49 50
50/** 51/**
51 * Constructor, find all of the possible interfaces 52 * Constructor, find all of the possible interfaces
52 * We also need to restore the state.. it could be that 53 * We also need to restore the state.. it could be that
53 * an interface was up while closing the application 54 * an interface was up while closing the application
54 * we need to be able to shut it down... 55 * we need to be able to shut it down...
55 */ 56 */
56PPPModule::PPPModule() : Module() 57PPPModule::PPPModule() : Module()
57{ 58{
58 InterfaceKeeper inFace; 59 InterfaceKeeper inFace;
59 QMap<QString,Connection> running = inFace.interfaces(); 60 QMap<QString,Connection> running = inFace.interfaces();
60 QStringList handledInterfaceNames; 61 QStringList handledInterfaceNames;
61 62
62 QMap<QString,QString> ifaces = PPPData::getConfiguredInterfaces(); 63 QMap<QString,QString> ifaces = PPPData::getConfiguredInterfaces();
63 QMap<QString,QString>::Iterator it; 64 QMap<QString,QString>::Iterator it;
64 InterfacePPP *iface; 65 InterfacePPP *iface;
65 odebug << "getting interfaces" << oendl; 66 odebug << "getting interfaces" << oendl;
66 for( it = ifaces.begin(); it != ifaces.end(); ++it ) 67 for( it = ifaces.begin(); it != ifaces.end(); ++it )
67 { 68 {
68 odebug << "ifaces " << it.key().latin1() << " " << it.data().latin1() << "" << oendl; 69 odebug << "ifaces " << it.key().latin1() << " " << it.data().latin1() << "" << oendl;
69 iface = new InterfacePPP( 0, it.key() ); 70 iface = new InterfacePPP( 0, it.key() );
70 iface->setHardwareName( it.data() ); 71 iface->setHardwareName( it.data() );
71 list.append( (Interface*)iface ); 72 list.append( (Interface*)iface );
72 73
73 // check if (*it) is one of the running ifaces 74 // check if (*it) is one of the running ifaces
74 if ( running.contains( it.data() ) ) 75 if ( running.contains( it.data() ) )
75 { 76 {
76 odebug << "iface is running " << it.key().latin1() << "" << oendl; 77 odebug << "iface is running " << it.key().latin1() << "" << oendl;
77 handledInterfaceNames << running[it.data()].device; 78 handledInterfaceNames << running[it.data()].device;
78 iface->setStatus( true ); 79 iface->setStatus( true );
79 iface->setPPPDpid( running[it.data()].pid ); 80 iface->setPPPDpid( running[it.data()].pid );
80 iface->modem()->setPPPDevice( running[it.data()].device ); 81 iface->modem()->setPPPDevice( running[it.data()].device );
81 iface->refresh(); 82 iface->refresh();
82 } 83 }
83 } 84 }
84 85
85 setHandledInterfaceNames( handledInterfaceNames ); 86 setHandledInterfaceNames( handledInterfaceNames );
86} 87}
87 88
88/** 89/**
89 * Delete any interfaces that we own. 90 * Delete any interfaces that we own.
90 */ 91 */
91PPPModule::~PPPModule() 92PPPModule::~PPPModule()
92{ 93{
93 odebug << "PPPModule::~PPPModule() " << oendl; 94 odebug << "PPPModule::~PPPModule() " << oendl;
94 QMap<QString,QString> ifaces; 95 QMap<QString,QString> ifaces;
95 InterfaceKeeper keeper; 96 InterfaceKeeper keeper;
96 Interface *i; 97 Interface *i;
97 for ( i=list.first(); i != 0; i=list.next() ) 98 for ( i=list.first(); i != 0; i=list.next() )
98 { 99 {
99 /* if online save the state */ 100 /* if online save the state */
100 if ( i->getStatus() ) 101 if ( i->getStatus() )
101 { 102 {
102 odebug << "Iface " << i->getHardwareName().latin1() << " is still up" << oendl; 103 odebug << "Iface " << i->getHardwareName().latin1() << " is still up" << oendl;
103 InterfacePPP* ppp = static_cast<InterfacePPP*>(i); 104 InterfacePPP* ppp = static_cast<InterfacePPP*>(i);
104 keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() ); 105 keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() );
105 } 106 }
106 ifaces.insert( i->getInterfaceName(), i->getHardwareName() ); 107 ifaces.insert( i->getInterfaceName(), i->getHardwareName() );
107 delete i; 108 delete i;
108 } 109 }
109 PPPData::setConfiguredInterfaces( ifaces ); 110 PPPData::setConfiguredInterfaces( ifaces );
110} 111}
111 112
112/** 113/**
113 * Change the current profile 114 * Change the current profile
114 */ 115 */
115void PPPModule::setProfile(const QString &newProfile) 116void PPPModule::setProfile(const QString &newProfile)
116{ 117{
117 profile = newProfile; 118 profile = newProfile;
118} 119}
119 120
120/** 121/**
121 * get the icon name for this device. 122 * get the icon name for this device.
122 * @param Interface* can be used in determining the icon. 123 * @param Interface* can be used in determining the icon.
123 * @return QString the icon name (minus .png, .gif etc) 124 * @return QString the icon name (minus .png, .gif etc)
124 */ 125 */
125QString PPPModule::getPixmapName(Interface* ) 126QString PPPModule::getPixmapName(Interface* )
126{ 127{
127 return "ppp"; 128 return "ppp";
128} 129}
129 130
130/** 131/**
131 * Check to see if the interface i is owned by this module. 132 * Check to see if the interface i is owned by this module.
132 * @param Interface* interface to check against 133 * @param Interface* interface to check against
133 * @return bool true if i is owned by this module, false otherwise. 134 * @return bool true if i is owned by this module, false otherwise.
134 */ 135 */
135bool PPPModule::isOwner(Interface *i) 136bool PPPModule::isOwner(Interface *i)
136{ 137{
137 return list.find( i ) != -1; 138 return list.find( i ) != -1;
138} 139}
139 140
140/** 141/**
141 * Create, and return the WLANConfigure Module 142 * Create, and return the WLANConfigure Module
142 * @return QWidget* pointer to this modules configure. 143 * @return QWidget* pointer to this modules configure.
143 */ 144 */
144QWidget *PPPModule::configure(Interface *i) 145QWidget *PPPModule::configure(Interface *i)
145{ 146{
146 odebug << "return ModemWidget" << oendl; 147 odebug << "return ModemWidget" << oendl;
147 PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i, 148 PPPConfigWidget *pppconfig = new PPPConfigWidget( (InterfacePPP*)i,
148 0, "PPPConfig", false, 149 0, "PPPConfig", false,
149 (Qt::WDestructiveClose | Qt::WStyle_ContextHelp)); 150 ::Qt::WDestructiveClose | ::Qt::WStyle_ContextHelp);
150 return pppconfig; 151 return pppconfig;
151} 152}
152 153
153/** 154/**
154 * Create, and return the Information Module 155 * Create, and return the Information Module
155 * @return QWidget* pointer to this modules info. 156 * @return QWidget* pointer to this modules info.
156 */ 157 */
157QWidget *PPPModule::information(Interface *i) 158QWidget *PPPModule::information(Interface *i)
158{ 159{
159 // We don't have any advanced pppd information widget yet :-D 160 // We don't have any advanced pppd information widget yet :-D
160 // TODO ^ 161 // TODO ^
161 162
162 return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i ); 163 return new InterfaceInformationPPP( 0, "InterfaceInformationPPP", i );
163} 164}
164 165
165/** 166/**
166 * Get all active (up or down) interfaces 167 * Get all active (up or down) interfaces
167 * @return QList<Interface> A list of interfaces that exsist that havn't 168 * @return QList<Interface> A list of interfaces that exsist that havn't
168 * been called by isOwner() 169 * been called by isOwner()
169 */ 170 */
170QList<Interface> PPPModule::getInterfaces() 171QList<Interface> PPPModule::getInterfaces()
171{ 172{
172 // List all of the files in the peer directory 173 // List all of the files in the peer directory
173 odebug << "PPPModule::getInterfaces" << oendl; 174 odebug << "PPPModule::getInterfaces" << oendl;
174 return list; 175 return list;
175} 176}
176 177
177/** 178/**
178 * Attempt to add a new interface as defined by name 179 * Attempt to add a new interface as defined by name
179 * @param name the name of the type of interface that should be created given 180 * @param name the name of the type of interface that should be created given
180 * by possibleNewInterfaces(); 181 * by possibleNewInterfaces();
181 * @return Interface* NULL if it was unable to be created. 182 * @return Interface* NULL if it was unable to be created.
182 */ 183 */
183Interface *PPPModule::addNewInterface(const QString &newInterface) 184Interface *PPPModule::addNewInterface(const QString &newInterface)
184{ 185{
185 186
186 InterfacePPP *ifaceppp; 187 InterfacePPP *ifaceppp;
187 Interface *iface; 188 Interface *iface;
188 ifaceppp = new InterfacePPP(); 189 ifaceppp = new InterfacePPP();
189 PPPConfigWidget imp(ifaceppp, 0, "PPPConfigImp", true); 190 PPPConfigWidget imp(ifaceppp, 0, "PPPConfigImp", true);
190 191
191 if( QPEApplication::execDialog( &imp ) == QDialog::Accepted ) 192 if( QPEApplication::execDialog( &imp ) == QDialog::Accepted )
192 { 193 {
193 iface = (InterfacePPP*) ifaceppp; 194 iface = (InterfacePPP*) ifaceppp;
194 iface->setModuleOwner( this ); 195 iface->setModuleOwner( this );
195 list.append( iface ); 196 list.append( iface );
196 return iface; 197 return iface;
197 } 198 }
198 else 199 else
199 { 200 {
200 delete ifaceppp; 201 delete ifaceppp;
201 iface = NULL; 202 iface = NULL;
202 } 203 }
203 return iface; 204 return iface;
204} 205}
205 206
206/** 207/**
207 * Attempts to remove the interface, doesn't delete i 208 * Attempts to remove the interface, doesn't delete i
208 * @return bool true if successful, false otherwise. 209 * @return bool true if successful, false otherwise.
209 */ 210 */
210bool PPPModule::remove(Interface *i) 211bool PPPModule::remove(Interface *i)
211{ 212{
212 return list.remove(i); 213 return list.remove(i);
213} 214}
214 215
215void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) 216void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces)
216{ 217{
217 newIfaces.insert(QObject::tr("PPP") , 218 newIfaces.insert(::QObject::tr("PPP") ,
218 QObject::tr("generic ppp device")); 219 ::QObject::tr("generic ppp device"));
219} 220}
220 221
221 222
222 223
223namespace 224namespace
224{ 225{
225 InterfaceKeeper::InterfaceKeeper( ) 226 InterfaceKeeper::InterfaceKeeper( )
226 {} 227 {}
227 InterfaceKeeper::~InterfaceKeeper() 228 InterfaceKeeper::~InterfaceKeeper()
228 { 229 {
229 Config cfg("ppp_plugin_keeper"); 230 Config cfg("ppp_plugin_keeper");
230 QStringList lst = cfg.groupList(); 231 QStringList lst = cfg.groupList();
231 for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) 232 for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )
232 { 233 {
233 Connection con; 234 Connection con;
234 cfg.setGroup( (*it) ); 235 cfg.setGroup( (*it) );
235 cfg.clearGroup(); 236 cfg.clearGroup();
236 } 237 }
237 238
238 for (QMap<QString, Connection>::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it ) 239 for (QMap<QString, Connection>::Iterator it = m_interfaces.begin(); it != m_interfaces.end(); ++it )
239 { 240 {
240 Connection con = it.data(); 241 Connection con = it.data();
241 cfg.setGroup( con.name ); 242 cfg.setGroup( con.name );
242 cfg.writeEntry( "pid", con.pid ); 243 cfg.writeEntry( "pid", con.pid );
243 cfg.writeEntry( "device", con.device ); 244 cfg.writeEntry( "device", con.device );
244 } 245 }
245 } 246 }
246 void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name ) 247 void InterfaceKeeper::addInterface(pid_t pid, const QString& dev, const QString& name )
247 { 248 {
248 Connection con; 249 Connection con;
249 con.pid = pid; 250 con.pid = pid;
250 con.device = dev; 251 con.device = dev;
251 con.name = name; 252 con.name = name;
252 m_interfaces.insert( name, con ); 253 m_interfaces.insert( name, con );
253 } 254 }
254 QMap<QString, Connection> InterfaceKeeper::interfaces()const 255 QMap<QString, Connection> InterfaceKeeper::interfaces()const
255 { 256 {
256 Config cfg("ppp_plugin_keeper"); 257 Config cfg("ppp_plugin_keeper");
257 QMap<QString, Connection> ifaces; 258 QMap<QString, Connection> ifaces;
258 QStringList lst = cfg.groupList(); 259 QStringList lst = cfg.groupList();
259 for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) 260 for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )
260 { 261 {
261 Connection con; 262 Connection con;
262 cfg.setGroup( (*it) ); 263 cfg.setGroup( (*it) );
263 con.name = (*it); 264 con.name = (*it);
264 con.pid = cfg.readNumEntry("pid"); 265 con.pid = cfg.readNumEntry("pid");
265 con.device = cfg.readEntry("device"); 266 con.device = cfg.readEntry("device");
266 odebug << " " << con.name.latin1() << " " << con.device.latin1() << " " << con.pid << "" << oendl; 267 odebug << " " << con.name.latin1() << " " << con.device.latin1() << " " << con.pid << "" << oendl;
267 268
268 if ( con.pid != -1 && isAvailable( con.pid ) ) 269 if ( con.pid != -1 && isAvailable( con.pid ) )
269 ifaces.insert( con.name, con ); 270 ifaces.insert( con.name, con );
270 } 271 }
271 return ifaces; 272 return ifaces;
272 } 273 }
273 bool InterfaceKeeper::isAvailable( pid_t p)const 274 bool InterfaceKeeper::isAvailable( pid_t p)const
274 { 275 {
275 if (::kill(p, 0 ) == 0 || errno != ESRCH ) 276 if (::kill(p, 0 ) == 0 || errno != ESRCH )
276 { 277 {
277 odebug << "isAvailable " << p << "" << oendl; 278 odebug << "isAvailable " << p << "" << oendl;
278 return true; 279 return true;
279 } 280 }
280 281
281 odebug << "notAvailable " << p << "" << oendl; 282 odebug << "notAvailable " << p << "" << oendl;
282 return false; 283 return false;
283 } 284 }
284 285
285} 286}