summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/pppmodule.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/pppmodule.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.cpp147
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,8 +1,3 @@
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"
8#include "pppconfig.h" 3#include "pppconfig.h"
@@ -11,19 +6,32 @@
11#include "interfaceinformationppp.h" 6#include "interfaceinformationppp.h"
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
15namespace { 20namespace
21{
16 /* 22 /*
17 * If network settings is qutting and we've ppp 23 * If network settings is qutting and we've ppp
18 * devices open we need to save the pid_t the PPData 24 * devices open we need to save the pid_t the PPData
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();
29 ~InterfaceKeeper(); 37 ~InterfaceKeeper();
@@ -53,14 +61,16 @@ PPPModule::PPPModule() : Module()
53 QMap<QString,QString>::Iterator it; 61 QMap<QString,QString>::Iterator it;
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() );
59 iface->setHardwareName( it.data() ); 68 iface->setHardwareName( it.data() );
60 list.append( (Interface*)iface ); 69 list.append( (Interface*)iface );
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;
66 iface->setStatus( true ); 76 iface->setStatus( true );
@@ -76,14 +86,17 @@ PPPModule::PPPModule() : Module()
76/** 86/**
77 * Delete any interfaces that we own. 87 * Delete any interfaces that we own.
78 */ 88 */
79PPPModule::~PPPModule(){ 89PPPModule::~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);
89 keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() ); 102 keeper.addInterface( ppp->pppPID(), ppp->pppDev(), ppp->getHardwareName() );
@@ -97,8 +110,9 @@ PPPModule::~PPPModule(){
97/** 110/**
98 * Change the current profile 111 * Change the current profile
99 */ 112 */
100void PPPModule::setProfile(const QString &newProfile){ 113void PPPModule::setProfile(const QString &newProfile)
101 profile = newProfile; 114{
115 profile = newProfile;
102} 116}
103 117
104/** 118/**
@@ -106,8 +120,9 @@ void PPPModule::setProfile(const QString &newProfile){
106 * @param Interface* can be used in determining the icon. 120 * @param Interface* can be used in determining the icon.
107 * @return QString the icon name (minus .png, .gif etc) 121 * @return QString the icon name (minus .png, .gif etc)
108 */ 122 */
109QString PPPModule::getPixmapName(Interface* ){ 123QString PPPModule::getPixmapName(Interface* )
110 return "ppp"; 124{
125 return "ppp";
111} 126}
112 127
113/** 128/**
@@ -115,7 +130,8 @@ QString PPPModule::getPixmapName(Interface* ){
115 * @param Interface* interface to check against 130 * @param Interface* interface to check against
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 */
118bool PPPModule::isOwner(Interface *i){ 133bool PPPModule::isOwner(Interface *i)
134{
119 return list.find( i ) != -1; 135 return list.find( i ) != -1;
120} 136}
121 137
@@ -123,11 +139,12 @@ bool PPPModule::isOwner(Interface *i){
123 * Create, and return the WLANConfigure Module 139 * Create, and return the WLANConfigure Module
124 * @return QWidget* pointer to this modules configure. 140 * @return QWidget* pointer to this modules configure.
125 */ 141 */
126QWidget *PPPModule::configure(Interface *i){ 142QWidget *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}
133 150
@@ -135,11 +152,12 @@ QWidget *PPPModule::configure(Interface *i){
135 * Create, and return the Information Module 152 * Create, and return the Information Module
136 * @return QWidget* pointer to this modules info. 153 * @return QWidget* pointer to this modules info.
137 */ 154 */
138QWidget *PPPModule::information(Interface *i){ 155QWidget *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
145/** 163/**
@@ -147,10 +165,11 @@ QWidget *PPPModule::information(Interface *i){
147 * @return QList<Interface> A list of interfaces that exsist that havn't 165 * @return QList<Interface> A list of interfaces that exsist that havn't
148 * been called by isOwner() 166 * been called by isOwner()
149 */ 167 */
150QList<Interface> PPPModule::getInterfaces(){ 168QList<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
156/** 175/**
@@ -159,30 +178,35 @@ QList<Interface> PPPModule::getInterfaces(){
159 * by possibleNewInterfaces(); 178 * by possibleNewInterfaces();
160 * @return Interface* NULL if it was unable to be created. 179 * @return Interface* NULL if it was unable to be created.
161 */ 180 */
162Interface *PPPModule::addNewInterface(const QString &newInterface){ 181Interface *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
181/** 204/**
182 * Attempts to remove the interface, doesn't delete i 205 * Attempts to remove the interface, doesn't delete i
183 * @return bool true if successful, false otherwise. 206 * @return bool true if successful, false otherwise.
184 */ 207 */
185bool PPPModule::remove(Interface *i){ 208bool PPPModule::remove(Interface *i)
209{
186 return list.remove(i); 210 return list.remove(i);
187} 211}
188 212
@@ -194,37 +218,44 @@ void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces)
194 218
195 219
196 220
197namespace { 221namespace
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) );
206 cfg.clearGroup(); 233 cfg.clearGroup();
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 );
212 cfg.writeEntry( "pid", con.pid ); 240 cfg.writeEntry( "pid", con.pid );
213 cfg.writeEntry( "device", con.device ); 241 cfg.writeEntry( "device", con.device );
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;
219 con.device = dev; 248 con.device = dev;
220 con.name = name; 249 con.name = name;
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) );
230 con.name = (*it); 261 con.name = (*it);
@@ -237,8 +268,10 @@ namespace {
237 } 268 }
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;
244 } 277 }