summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-07 21:22:42 (UTC)
committer alwin <alwin>2005-03-07 21:22:42 (UTC)
commitca82c064ab8834546c55b29c6b2f5c922075b450 (patch) (unidiff)
tree5a7a097400cfb4388c3b742d3d4f517209789740
parentb9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2 (diff)
downloadopie-ca82c064ab8834546c55b29c6b2f5c922075b450.zip
opie-ca82c064ab8834546c55b29c6b2f5c922075b450.tar.gz
opie-ca82c064ab8834546c55b29c6b2f5c922075b450.tar.bz2
hostname should be filtered. Check return value of setting the hostname
and write operations.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index 0a3312c..3222e50 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -1,775 +1,791 @@
1 1
2#include "mainwindowimp.h" 2#include "mainwindowimp.h"
3#include "addconnectionimp.h" 3#include "addconnectionimp.h"
4#include "interfaceinformationimp.h" 4#include "interfaceinformationimp.h"
5#include "interfacesetupimp.h" 5#include "interfacesetupimp.h"
6#include "interfaces.h" 6#include "interfaces.h"
7#include "module.h" 7#include "module.h"
8 8
9/* OPIE */ 9/* OPIE */
10#include <opie2/odebug.h> 10#include <opie2/odebug.h>
11#include <opie2/oprocess.h> 11#include <opie2/oprocess.h>
12#include <qpe/applnk.h> 12#include <qpe/applnk.h>
13#include <qpe/qcopenvelope_qws.h> 13#include <qpe/qcopenvelope_qws.h>
14#include <qpe/qpeapplication.h> 14#include <qpe/qpeapplication.h>
15#include <qpe/config.h> 15#include <qpe/config.h>
16#include <qpe/qlibrary.h> 16#include <qpe/qlibrary.h>
17#include <qpe/resource.h> 17#include <qpe/resource.h>
18 18
19/* QT */ 19/* QT */
20#include <qpushbutton.h> 20#include <qpushbutton.h>
21#include <qlistbox.h> 21#include <qlistbox.h>
22#include <qlineedit.h> 22#include <qlineedit.h>
23#include <qlistview.h> 23#include <qlistview.h>
24#include <qheader.h> 24#include <qheader.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qtabwidget.h> // in order to disable the profiles tab 26#include <qtabwidget.h> // in order to disable the profiles tab
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qregexp.h>
29 30
30 31
31#if QT_VERSION < 0x030000 32#if QT_VERSION < 0x030000
32#include <qlist.h> 33#include <qlist.h>
33#else 34#else
34#include <qptrlist.h> 35#include <qptrlist.h>
35#endif 36#endif
36#include <qdir.h> 37#include <qdir.h>
37#include <qfile.h> 38#include <qfile.h>
38#include <qtextstream.h> 39#include <qtextstream.h>
39#include <qregexp.h> 40#include <qregexp.h>
40 41
41/* STD */ 42/* STD */
42#include <net/if.h> 43#include <net/if.h>
43#include <sys/ioctl.h> 44#include <sys/ioctl.h>
44#include <sys/socket.h> 45#include <sys/socket.h>
45 46
46#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 47#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
47#define _PROCNETDEV "/proc/net/dev" 48#define _PROCNETDEV "/proc/net/dev"
48 49
49// is this always right? 50// is this always right?
50#define _HOSTFILE "/etc/hostname" 51#define _HOSTFILE "/etc/hostname"
51#define _IRDANAME "/proc/sys/net/irda/devname" 52#define _IRDANAME "/proc/sys/net/irda/devname"
52 53
53using namespace Opie::Core; 54using namespace Opie::Core;
54 55
55MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) 56MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME)
56{ 57{
57 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 58 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
58 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 59 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
59 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 60 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
60 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 61 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
61 62
62 //remove tab with no function 63 //remove tab with no function
63 tabWidget->removePage( tab ); 64 tabWidget->removePage( tab );
64 65
65 // Load connections. 66 // Load connections.
66 // /usr/local/kde/lib/libinterfaces.la 67 // /usr/local/kde/lib/libinterfaces.la
67 loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); 68 loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
68 getAllInterfaces(); 69 getAllInterfaces();
69 70
70 Interfaces i; 71 Interfaces i;
71 QStringList list = i.getInterfaceList(); 72 QStringList list = i.getInterfaceList();
72 QMap<QString, Interface*>::Iterator it; 73 QMap<QString, Interface*>::Iterator it;
73 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) 74 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
74 { 75 {
75 /* 76 /*
76 * we skipped it in getAllInterfaces now 77 * we skipped it in getAllInterfaces now
77 * we need to ignore it as well 78 * we need to ignore it as well
78 */ 79 */
79 if (m_handledIfaces.contains( *ni) ) 80 if (m_handledIfaces.contains( *ni) )
80 { 81 {
81 odebug << "Not up iface handled by module" << oendl; 82 odebug << "Not up iface handled by module" << oendl;
82 continue; 83 continue;
83 } 84 }
84 bool found = false; 85 bool found = false;
85 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) 86 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
86 { 87 {
87 if(it.key() == (*ni)) 88 if(it.key() == (*ni))
88 found = true; 89 found = true;
89 } 90 }
90 if(!found) 91 if(!found)
91 { 92 {
92 if(!(*ni).contains("_")) 93 if(!(*ni).contains("_"))
93 { 94 {
94 Interface *i = new Interface(this, *ni, false); 95 Interface *i = new Interface(this, *ni, false);
95 i->setAttached(false); 96 i->setAttached(false);
96 i->setHardwareName(tr("Disconnected")); 97 i->setHardwareName(tr("Disconnected"));
97 interfaceNames.insert(i->getInterfaceName(), i); 98 interfaceNames.insert(i->getInterfaceName(), i);
98 updateInterface(i); 99 updateInterface(i);
99 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); 100 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
100 } 101 }
101 } 102 }
102 } 103 }
103 104
104 //getInterfaceList(); 105 //getInterfaceList();
105 connectionList->header()->hide(); 106 connectionList->header()->hide();
106 107
107 Config cfg("NetworkSetup"); 108 Config cfg("NetworkSetup");
108 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 109 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
109 for ( QStringList::Iterator it = profiles.begin(); 110 for ( QStringList::Iterator it = profiles.begin();
110 it != profiles.end(); ++it) 111 it != profiles.end(); ++it)
111 profilesList->insertItem((*it)); 112 profilesList->insertItem((*it));
112 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 113 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
113 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 114 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
114 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 115 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
115 116
116 QFile file(scheme); 117 QFile file(scheme);
117 if ( file.open(IO_ReadOnly) ) 118 if ( file.open(IO_ReadOnly) )
118 { // file opened successfully 119 { // file opened successfully
119 QTextStream stream( &file ); // use a text stream 120 QTextStream stream( &file ); // use a text stream
120 while ( !stream.eof() ) 121 while ( !stream.eof() )
121 { // until end of file... 122 { // until end of file...
122 QString line = stream.readLine(); // line of text excluding '\n' 123 QString line = stream.readLine(); // line of text excluding '\n'
123 if(line.contains("SCHEME")) 124 if(line.contains("SCHEME"))
124 { 125 {
125 line = line.mid(7, line.length()); 126 line = line.mid(7, line.length());
126 currentProfileLabel->setText(line); 127 currentProfileLabel->setText(line);
127 break; 128 break;
128 } 129 }
129 } 130 }
130 file.close(); 131 file.close();
131 } 132 }
132 makeChannel(); 133 makeChannel();
133 initHostname(); 134 initHostname();
134} 135}
135 136
136/** 137/**
137 * Deconstructor. Save profiles. Delete loaded libraries. 138 * Deconstructor. Save profiles. Delete loaded libraries.
138 */ 139 */
139MainWindowImp::~MainWindowImp() 140MainWindowImp::~MainWindowImp()
140{ 141{
141 // Save profiles. 142 // Save profiles.
142 Config cfg("NetworkSetup"); 143 Config cfg("NetworkSetup");
143 cfg.setGroup("General"); 144 cfg.setGroup("General");
144 cfg.writeEntry("Profiles", profiles.join(" ")); 145 cfg.writeEntry("Profiles", profiles.join(" "));
145 146
146 // Delete all interfaces that don't have owners. 147 // Delete all interfaces that don't have owners.
147 QMap<Interface*, QListViewItem*>::Iterator iIt; 148 QMap<Interface*, QListViewItem*>::Iterator iIt;
148 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 149 for( iIt = items.begin(); iIt != items.end(); ++iIt )
149 { 150 {
150 if(iIt.key()->getModuleOwner() == NULL) 151 if(iIt.key()->getModuleOwner() == NULL)
151 delete iIt.key(); 152 delete iIt.key();
152 } 153 }
153 154
154 // Delete Modules and Libraries 155 // Delete Modules and Libraries
155 QMap<Module*, QLibrary*>::Iterator it; 156 QMap<Module*, QLibrary*>::Iterator it;
156 for( it = libraries.begin(); it != libraries.end(); ++it ) 157 for( it = libraries.begin(); it != libraries.end(); ++it )
157 { 158 {
158 delete it.key(); 159 delete it.key();
159 // I wonder why I can't delete the libraries 160 // I wonder why I can't delete the libraries
160 // What fucking shit this is. 161 // What fucking shit this is.
161 //delete it.data(); 162 //delete it.data();
162 } 163 }
163} 164}
164 165
165/** 166/**
166 * Query the kernel for all of the interfaces. 167 * Query the kernel for all of the interfaces.
167 */ 168 */
168void MainWindowImp::getAllInterfaces() 169void MainWindowImp::getAllInterfaces()
169{ 170{
170 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 171 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
171 if(sockfd == -1) 172 if(sockfd == -1)
172 return; 173 return;
173 174
174 struct ifreq ifr; 175 struct ifreq ifr;
175 QStringList ifaces; 176 QStringList ifaces;
176 QFile procFile(QString(_PROCNETDEV)); 177 QFile procFile(QString(_PROCNETDEV));
177 int result; 178 int result;
178 Interface *i; 179 Interface *i;
179 180
180 if (! procFile.exists()) 181 if (! procFile.exists())
181 { 182 {
182 struct ifreq ifrs[100]; 183 struct ifreq ifrs[100];
183 struct ifconf ifc; 184 struct ifconf ifc;
184 ifc.ifc_len = sizeof(ifrs); 185 ifc.ifc_len = sizeof(ifrs);
185 ifc.ifc_req = ifrs; 186 ifc.ifc_req = ifrs;
186 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 187 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
187 188
188 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 189 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
189 { 190 {
190 struct ifreq *pifr = &ifrs[i]; 191 struct ifreq *pifr = &ifrs[i];
191 192
192 ifaces += pifr->ifr_name; 193 ifaces += pifr->ifr_name;
193 } 194 }
194 } 195 }
195 else 196 else
196 { 197 {
197 procFile.open(IO_ReadOnly); 198 procFile.open(IO_ReadOnly);
198 QString line; 199 QString line;
199 QTextStream procTs(&procFile); 200 QTextStream procTs(&procFile);
200 int loc = -1; 201 int loc = -1;
201 202
202 procTs.readLine(); // eat a line 203 procTs.readLine(); // eat a line
203 procTs.readLine(); // eat a line 204 procTs.readLine(); // eat a line
204 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 205 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
205 { 206 {
206 if((loc = line.find(":")) != -1) 207 if((loc = line.find(":")) != -1)
207 { 208 {
208 ifaces += line.left(loc); 209 ifaces += line.left(loc);
209 } 210 }
210 } 211 }
211 } 212 }
212 213
213 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 214 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
214 { 215 {
215 int flags = 0; 216 int flags = 0;
216 if ( m_handledIfaces.contains( (*it) ) ) 217 if ( m_handledIfaces.contains( (*it) ) )
217 { 218 {
218 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 219 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
219 continue; 220 continue;
220 } 221 }
221 // int family; 222 // int family;
222 i = NULL; 223 i = NULL;
223 224
224 strcpy(ifr.ifr_name, (*it).latin1()); 225 strcpy(ifr.ifr_name, (*it).latin1());
225 226
226 struct ifreq ifcopy; 227 struct ifreq ifcopy;
227 ifcopy = ifr; 228 ifcopy = ifr;
228 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 229 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
229 flags = ifcopy.ifr_flags; 230 flags = ifcopy.ifr_flags;
230 i = new Interface(this, ifr.ifr_name, false); 231 i = new Interface(this, ifr.ifr_name, false);
231 i->setAttached(true); 232 i->setAttached(true);
232 if ((flags & IFF_UP) == IFF_UP) 233 if ((flags & IFF_UP) == IFF_UP)
233 i->setStatus(true); 234 i->setStatus(true);
234 else 235 else
235 i->setStatus(false); 236 i->setStatus(false);
236 237
237 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 238 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
238 i->setHardwareName("Ethernet"); 239 i->setHardwareName("Ethernet");
239 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 240 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
240 i->setHardwareName("Point to Point"); 241 i->setHardwareName("Point to Point");
241 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 242 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
242 i->setHardwareName("Multicast"); 243 i->setHardwareName("Multicast");
243 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 244 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
244 i->setHardwareName("Loopback"); 245 i->setHardwareName("Loopback");
245 else 246 else
246 i->setHardwareName("Unknown"); 247 i->setHardwareName("Unknown");
247 248
248 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 249 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
249 interfaceNames.insert(i->getInterfaceName(), i); 250 interfaceNames.insert(i->getInterfaceName(), i);
250 updateInterface(i); 251 updateInterface(i);
251 connect(i, SIGNAL(updateInterface(Interface*)), 252 connect(i, SIGNAL(updateInterface(Interface*)),
252 this, SLOT(updateInterface(Interface*))); 253 this, SLOT(updateInterface(Interface*)));
253 } 254 }
254 // now lets ask the plugins too ;) 255 // now lets ask the plugins too ;)
255 QMap<Module*, QLibrary*>::Iterator it; 256 QMap<Module*, QLibrary*>::Iterator it;
256 QList<Interface> ilist; 257 QList<Interface> ilist;
257 for( it = libraries.begin(); it != libraries.end(); ++it ) 258 for( it = libraries.begin(); it != libraries.end(); ++it )
258 { 259 {
259 if(it.key()) 260 if(it.key())
260 { 261 {
261 ilist = it.key()->getInterfaces(); 262 ilist = it.key()->getInterfaces();
262 for( i = ilist.first(); i != 0; i = ilist.next() ) 263 for( i = ilist.first(); i != 0; i = ilist.next() )
263 { 264 {
264 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; 265 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
265 interfaceNames.insert(i->getInterfaceName(), i); 266 interfaceNames.insert(i->getInterfaceName(), i);
266 updateInterface(i); 267 updateInterface(i);
267 connect(i, SIGNAL(updateInterface(Interface*)), 268 connect(i, SIGNAL(updateInterface(Interface*)),
268 this, SLOT(updateInterface(Interface*))); 269 this, SLOT(updateInterface(Interface*)));
269 } 270 }
270 } 271 }
271 } 272 }
272} 273}
273 274
274/** 275/**
275 * Load all modules that are found in the path 276 * Load all modules that are found in the path
276 * @param path a directory that is scaned for any plugins that can be loaded 277 * @param path a directory that is scaned for any plugins that can be loaded
277 * and attempts to load them 278 * and attempts to load them
278 */ 279 */
279void MainWindowImp::loadModules(const QString &path) 280void MainWindowImp::loadModules(const QString &path)
280{ 281{
281#ifdef DEBUG 282#ifdef DEBUG
282 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; 283 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
283#endif 284#endif
284 QDir d(path); 285 QDir d(path);
285 if(!d.exists()) 286 if(!d.exists())
286 return; 287 return;
287 288
288 QString lang = ::getenv("LANG"); 289 QString lang = ::getenv("LANG");
289 // Don't want sym links 290 // Don't want sym links
290 d.setFilter( QDir::Files | QDir::NoSymLinks ); 291 d.setFilter( QDir::Files | QDir::NoSymLinks );
291 const QFileInfoList *list = d.entryInfoList(); 292 const QFileInfoList *list = d.entryInfoList();
292 QFileInfoListIterator it( *list ); 293 QFileInfoListIterator it( *list );
293 QFileInfo *fi; 294 QFileInfo *fi;
294 while ( (fi=it.current()) ) 295 while ( (fi=it.current()) )
295 { 296 {
296 if(fi->fileName().contains(".so")) 297 if(fi->fileName().contains(".so"))
297 { 298 {
298 /* if loaded install translation */ 299 /* if loaded install translation */
299 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){ 300 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){
300 QTranslator *trans = new QTranslator(qApp); 301 QTranslator *trans = new QTranslator(qApp);
301 QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm"; 302 QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm";
302 if( trans->load( fn ) ) 303 if( trans->load( fn ) )
303 qApp->installTranslator( trans ); 304 qApp->installTranslator( trans );
304 else 305 else
305 delete trans; 306 delete trans;
306 } 307 }
307 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl; 308 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl;
308 } 309 }
309 ++it; 310 ++it;
310 } 311 }
311} 312}
312 313
313/** 314/**
314 * Attempt to load a function and resolve a function. 315 * Attempt to load a function and resolve a function.
315 * @param pluginFileName - the name of the file in which to attempt to load 316 * @param pluginFileName - the name of the file in which to attempt to load
316 * @param resolveString - function pointer to resolve 317 * @param resolveString - function pointer to resolve
317 * @return pointer to the function with name resolveString or NULL 318 * @return pointer to the function with name resolveString or NULL
318 */ 319 */
319Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) 320Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
320{ 321{
321#ifdef DEBUG 322#ifdef DEBUG
322 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl; 323 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl;
323#endif 324#endif
324 QLibrary *lib = new QLibrary(pluginFileName); 325 QLibrary *lib = new QLibrary(pluginFileName);
325 void *functionPointer = lib->resolve(resolveString); 326 void *functionPointer = lib->resolve(resolveString);
326 if( !functionPointer ) 327 if( !functionPointer )
327 { 328 {
328#ifdef DEBUG 329#ifdef DEBUG
329 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl; 330 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl;
330#endif 331#endif
331 delete lib; 332 delete lib;
332 return 0; 333 return 0;
333 } 334 }
334 // Try to get an object. 335 // Try to get an object.
335 Module *object = ((Module* (*)()) functionPointer)(); 336 Module *object = ((Module* (*)()) functionPointer)();
336 if(object == 0) 337 if(object == 0)
337 { 338 {
338#ifdef DEBUG 339#ifdef DEBUG
339 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; 340 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
340#endif 341#endif
341 delete lib; 342 delete lib;
342 return 0; 343 return 0;
343 } 344 }
344 345
345 m_handledIfaces += object->handledInterfaceNames(); 346 m_handledIfaces += object->handledInterfaceNames();
346 // Store for deletion later 347 // Store for deletion later
347 libraries.insert(object, lib); 348 libraries.insert(object, lib);
348 return object; 349 return object;
349} 350}
350 351
351/** 352/**
352 * The Add button was clicked. Bring up the add dialog and if OK is hit 353 * The Add button was clicked. Bring up the add dialog and if OK is hit
353 * load the plugin and append it to the list 354 * load the plugin and append it to the list
354 */ 355 */
355void MainWindowImp::addClicked() 356void MainWindowImp::addClicked()
356{ 357{
357 QMap<Module*, QLibrary*>::Iterator it; 358 QMap<Module*, QLibrary*>::Iterator it;
358 QMap<QString, QString> list; 359 QMap<QString, QString> list;
359 QMap<QString, Module*> newInterfaceOwners; 360 QMap<QString, Module*> newInterfaceOwners;
360 361
361 for( it = libraries.begin(); it != libraries.end(); ++it ) 362 for( it = libraries.begin(); it != libraries.end(); ++it )
362 { 363 {
363 if(it.key()) 364 if(it.key())
364 { 365 {
365 (it.key())->possibleNewInterfaces(list); 366 (it.key())->possibleNewInterfaces(list);
366 } 367 }
367 } 368 }
368 // See if the list has anything that we can add. 369 // See if the list has anything that we can add.
369 if(list.count() == 0) 370 if(list.count() == 0)
370 { 371 {
371 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 372 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
372 return; 373 return;
373 } 374 }
374 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 375 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
375 addNewConnection.addConnections(list); 376 addNewConnection.addConnections(list);
376 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) 377 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
377 { 378 {
378 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 379 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
379 if(!item) 380 if(!item)
380 return; 381 return;
381 382
382 for( it = libraries.begin(); it != libraries.end(); ++it ) 383 for( it = libraries.begin(); it != libraries.end(); ++it )
383 { 384 {
384 if(it.key()) 385 if(it.key())
385 { 386 {
386 Interface *i = (it.key())->addNewInterface(item->text(0)); 387 Interface *i = (it.key())->addNewInterface(item->text(0));
387 if(i) 388 if(i)
388 { 389 {
389 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl; 390 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl;
390 interfaceNames.insert(i->getInterfaceName(), i); 391 interfaceNames.insert(i->getInterfaceName(), i);
391 updateInterface(i); 392 updateInterface(i);
392 } 393 }
393 } 394 }
394 } 395 }
395 } 396 }
396} 397}
397 398
398/** 399/**
399 * Prompt the user to see if they really want to do this. 400 * Prompt the user to see if they really want to do this.
400 * If they do then remove from the list and unload. 401 * If they do then remove from the list and unload.
401 */ 402 */
402void MainWindowImp::removeClicked() 403void MainWindowImp::removeClicked()
403{ 404{
404 QListViewItem *item = connectionList->currentItem(); 405 QListViewItem *item = connectionList->currentItem();
405 if(!item) 406 if(!item)
406 { 407 {
407 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 408 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
408 return; 409 return;
409 } 410 }
410 411
411 Interface *i = interfaceItems[item]; 412 Interface *i = interfaceItems[item];
412 if(i->getModuleOwner() == NULL) 413 if(i->getModuleOwner() == NULL)
413 { 414 {
414 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 415 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
415 } 416 }
416 else 417 else
417 { 418 {
418 if(!i->getModuleOwner()->remove(i)) 419 if(!i->getModuleOwner()->remove(i))
419 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); 420 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
420 else 421 else
421 { 422 {
422 delete item; 423 delete item;
423 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 424 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
424 } 425 }
425 } 426 }
426} 427}
427 428
428/** 429/**
429 * Pull up the configure about the currently selected interface. 430 * Pull up the configure about the currently selected interface.
430 * Report an error if no interface is selected. 431 * Report an error if no interface is selected.
431 * If the interface has a module owner then request its configure. 432 * If the interface has a module owner then request its configure.
432 */ 433 */
433void MainWindowImp::configureClicked() 434void MainWindowImp::configureClicked()
434{ 435{
435 QListViewItem *item = connectionList->currentItem(); 436 QListViewItem *item = connectionList->currentItem();
436 if(!item) 437 if(!item)
437 { 438 {
438 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); 439 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
439 return; 440 return;
440 } 441 }
441 442
442 QString currentProfileText = currentProfileLabel->text(); 443 QString currentProfileText = currentProfileLabel->text();
443 if(currentProfileText.upper() == "ALL"); 444 if(currentProfileText.upper() == "ALL");
444 currentProfileText = ""; 445 currentProfileText = "";
445 446
446 Interface *i = interfaceItems[item]; 447 Interface *i = interfaceItems[item];
447 448
448 if(i->getModuleOwner()) 449 if(i->getModuleOwner())
449 { 450 {
450 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 451 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
451 if(moduleConfigure != NULL) 452 if(moduleConfigure != NULL)
452 { 453 {
453 i->getModuleOwner()->setProfile(currentProfileText); 454 i->getModuleOwner()->setProfile(currentProfileText);
454 QPEApplication::showWidget( moduleConfigure ); 455 QPEApplication::showWidget( moduleConfigure );
455 return; 456 return;
456 } 457 }
457 } 458 }
458 459
459 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp ); 460 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp );
460 configure->setProfile(currentProfileText); 461 configure->setProfile(currentProfileText);
461 QPEApplication::showDialog( configure ); 462 QPEApplication::showDialog( configure );
462} 463}
463 464
464/** 465/**
465 * Pull up the information about the currently selected interface. 466 * Pull up the information about the currently selected interface.
466 * Report an error if no interface is selected. 467 * Report an error if no interface is selected.
467 * If the interface has a module owner then request its configure. 468 * If the interface has a module owner then request its configure.
468 */ 469 */
469void MainWindowImp::informationClicked() 470void MainWindowImp::informationClicked()
470{ 471{
471 QListViewItem *item = connectionList->currentItem(); 472 QListViewItem *item = connectionList->currentItem();
472 if(!item) 473 if(!item)
473 { 474 {
474 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 475 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
475 return; 476 return;
476 } 477 }
477 478
478 Interface *i = interfaceItems[item]; 479 Interface *i = interfaceItems[item];
479 // if(!i->isAttached()){ 480 // if(!i->isAttached()){
480 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 481 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
481 // return; 482 // return;
482 // } 483 // }
483 484
484 if(i->getModuleOwner()) 485 if(i->getModuleOwner())
485 { 486 {
486 QWidget *moduleInformation = i->getModuleOwner()->information(i); 487 QWidget *moduleInformation = i->getModuleOwner()->information(i);
487 if(moduleInformation != NULL) 488 if(moduleInformation != NULL)
488 { 489 {
489 QPEApplication::showWidget( moduleInformation ); 490 QPEApplication::showWidget( moduleInformation );
490#ifdef DEBUG 491#ifdef DEBUG
491 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; 492 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl;
492#endif 493#endif
493 return; 494 return;
494 } 495 }
495 } 496 }
496 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); 497 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp);
497 QPEApplication::showWidget( information ); 498 QPEApplication::showWidget( information );
498} 499}
499 500
500/** 501/**
501 * Update this interface. If no QListViewItem exists create one. 502 * Update this interface. If no QListViewItem exists create one.
502 * @param Interface* pointer to the interface that needs to be updated. 503 * @param Interface* pointer to the interface that needs to be updated.
503 */ 504 */
504void MainWindowImp::updateInterface(Interface *i) 505void MainWindowImp::updateInterface(Interface *i)
505{ 506{
506 if(!advancedUserMode) 507 if(!advancedUserMode)
507 { 508 {
508 if(i->getInterfaceName() == "lo") 509 if(i->getInterfaceName() == "lo")
509 return; 510 return;
510 } 511 }
511 512
512 QListViewItem *item = NULL; 513 QListViewItem *item = NULL;
513 514
514 // Find the interface, making it if needed. 515 // Find the interface, making it if needed.
515 if(items.find(i) == items.end()) 516 if(items.find(i) == items.end())
516 { 517 {
517 item = new QListViewItem(connectionList, "", "", ""); 518 item = new QListViewItem(connectionList, "", "", "");
518 // See if you can't find a module owner for this interface 519 // See if you can't find a module owner for this interface
519 QMap<Module*, QLibrary*>::Iterator it; 520 QMap<Module*, QLibrary*>::Iterator it;
520 for( it = libraries.begin(); it != libraries.end(); ++it ) 521 for( it = libraries.begin(); it != libraries.end(); ++it )
521 { 522 {
522 if(it.key()->isOwner(i)) 523 if(it.key()->isOwner(i))
523 i->setModuleOwner(it.key()); 524 i->setModuleOwner(it.key());
524 } 525 }
525 items.insert(i, item); 526 items.insert(i, item);
526 interfaceItems.insert(item, i); 527 interfaceItems.insert(item, i);
527 } 528 }
528 else 529 else
529 item = items[i]; 530 item = items[i];
530 531
531 // Update the icons and information 532 // Update the icons and information
532#ifdef QWS 533#ifdef QWS
533 QPixmap pic; 534 QPixmap pic;
534 pic.convertFromImage( Resource::loadImage( i->getStatus() ? "up": "down" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); 535 pic.convertFromImage( Resource::loadImage( i->getStatus() ? "up": "down" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
535 item->setPixmap(0, ( pic )); 536 item->setPixmap(0, ( pic ));
536#else 537#else
537 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 538 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
538#endif 539#endif
539 540
540 QString typeName = "lan"; 541 QString typeName = "lan";
541 if(i->getInterfaceName() == "lo") 542 if(i->getInterfaceName() == "lo")
542 typeName = "lo"; 543 typeName = "lo";
543 if(i->getInterfaceName().contains("irda")) 544 if(i->getInterfaceName().contains("irda"))
544 typeName = "irda"; 545 typeName = "irda";
545 if(i->getInterfaceName().contains("wlan")) 546 if(i->getInterfaceName().contains("wlan"))
546 typeName = "wlan"; 547 typeName = "wlan";
547 if(i->getInterfaceName().contains("usb")) 548 if(i->getInterfaceName().contains("usb"))
548 typeName = "usb"; 549 typeName = "usb";
549 550
550 if(!i->isAttached()) 551 if(!i->isAttached())
551 typeName = "connect_no"; 552 typeName = "connect_no";
552 // Actually try to use the Module 553 // Actually try to use the Module
553 if(i->getModuleOwner() != NULL) 554 if(i->getModuleOwner() != NULL)
554 typeName = i->getModuleOwner()->getPixmapName(i); 555 typeName = i->getModuleOwner()->getPixmapName(i);
555 556
556#ifdef QWS 557#ifdef QWS
557 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 558 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
558#else 559#else
559 item->setPixmap(1, (SmallIcon(typeName))); 560 item->setPixmap(1, (SmallIcon(typeName)));
560#endif 561#endif
561 item->setText(2, i->getHardwareName()); 562 item->setText(2, i->getHardwareName());
562 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 563 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
563 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 564 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
564} 565}
565 566
566void MainWindowImp::newProfileChanged(const QString& newText) 567void MainWindowImp::newProfileChanged(const QString& newText)
567{ 568{
568 if(newText.length() > 0) 569 if(newText.length() > 0)
569 newProfileButton->setEnabled(true); 570 newProfileButton->setEnabled(true);
570 else 571 else
571 newProfileButton->setEnabled(false); 572 newProfileButton->setEnabled(false);
572} 573}
573 574
574/** 575/**
575 * Adds a new profile to the list of profiles. 576 * Adds a new profile to the list of profiles.
576 * Don't add profiles that already exists. 577 * Don't add profiles that already exists.
577 * Appends to the list and QStringList 578 * Appends to the list and QStringList
578 */ 579 */
579void MainWindowImp::addProfile() 580void MainWindowImp::addProfile()
580{ 581{
581 QString newProfileName = newProfile->text(); 582 QString newProfileName = newProfile->text();
582 if(profiles.grep(newProfileName).count() > 0) 583 if(profiles.grep(newProfileName).count() > 0)
583 { 584 {
584 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 585 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
585 return; 586 return;
586 } 587 }
587 profiles.append(newProfileName); 588 profiles.append(newProfileName);
588 profilesList->insertItem(newProfileName); 589 profilesList->insertItem(newProfileName);
589} 590}
590 591
591/** 592/**
592 * Removes the currently selected profile in the combo. 593 * Removes the currently selected profile in the combo.
593 * Doesn't delete if there are less then 2 profiles. 594 * Doesn't delete if there are less then 2 profiles.
594 */ 595 */
595void MainWindowImp::removeProfile() 596void MainWindowImp::removeProfile()
596{ 597{
597 if(profilesList->count() <= 1) 598 if(profilesList->count() <= 1)
598 { 599 {
599 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 600 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
600 return; 601 return;
601 } 602 }
602 QString profileToRemove = profilesList->currentText(); 603 QString profileToRemove = profilesList->currentText();
603 if(profileToRemove == "All") 604 if(profileToRemove == "All")
604 { 605 {
605 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 606 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
606 return; 607 return;
607 } 608 }
608 // Can't remove the curent profile 609 // Can't remove the curent profile
609 if(profileToRemove == currentProfileLabel->text()) 610 if(profileToRemove == currentProfileLabel->text())
610 { 611 {
611 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 612 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
612 return; 613 return;
613 614
614 } 615 }
615 616
616 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) 617 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
617 { 618 {
618 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 619 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
619 profilesList->clear(); 620 profilesList->clear();
620 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 621 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
621 profilesList->insertItem((*it)); 622 profilesList->insertItem((*it));
622 623
623 // Remove any interface settings and mappings. 624 // Remove any interface settings and mappings.
624 Interfaces interfaces; 625 Interfaces interfaces;
625 // Go through them one by one 626 // Go through them one by one
626 QMap<Interface*, QListViewItem*>::Iterator it; 627 QMap<Interface*, QListViewItem*>::Iterator it;
627 for( it = items.begin(); it != items.end(); ++it ) 628 for( it = items.begin(); it != items.end(); ++it )
628 { 629 {
629 QString interfaceName = it.key()->getInterfaceName(); 630 QString interfaceName = it.key()->getInterfaceName();
630 odebug << interfaceName.latin1() << oendl; 631 odebug << interfaceName.latin1() << oendl;
631 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) 632 if(interfaces.setInterface(interfaceName + "_" + profileToRemove))
632 { 633 {
633 interfaces.removeInterface(); 634 interfaces.removeInterface();
634 if(interfaces.setMapping(interfaceName)) 635 if(interfaces.setMapping(interfaceName))
635 { 636 {
636 if(profilesList->count() == 1) 637 if(profilesList->count() == 1)
637 interfaces.removeMapping(); 638 interfaces.removeMapping();
638 else 639 else
639 { 640 {
640 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 641 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
641 } 642 }
642 } 643 }
643 interfaces.write(); 644 interfaces.write();
644 break; 645 break;
645 } 646 }
646 } 647 }
647 } 648 }
648} 649}
649 650
650/** 651/**
651 * A new profile has been selected, change. 652 * A new profile has been selected, change.
652 * @param newProfile the new profile. 653 * @param newProfile the new profile.
653 */ 654 */
654void MainWindowImp::changeProfile() 655void MainWindowImp::changeProfile()
655{ 656{
656 if(profilesList->currentItem() == -1) 657 if(profilesList->currentItem() == -1)
657 { 658 {
658 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 659 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
659 return; 660 return;
660 } 661 }
661 QString newProfile = profilesList->text(profilesList->currentItem()); 662 QString newProfile = profilesList->text(profilesList->currentItem());
662 if(newProfile != currentProfileLabel->text()) 663 if(newProfile != currentProfileLabel->text())
663 { 664 {
664 currentProfileLabel->setText(newProfile); 665 currentProfileLabel->setText(newProfile);
665 QFile::remove(scheme); 666 QFile::remove(scheme);
666 QFile file(scheme); 667 QFile file(scheme);
667 if ( file.open(IO_ReadWrite) ) 668 if ( file.open(IO_ReadWrite) )
668 { 669 {
669 QTextStream stream( &file ); 670 QTextStream stream( &file );
670 stream << QString("SCHEME=%1").arg(newProfile); 671 stream << QString("SCHEME=%1").arg(newProfile);
671 file.close(); 672 file.close();
672 } 673 }
673 // restart all up devices? 674 // restart all up devices?
674 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) 675 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
675 { 676 {
676 // Go through them one by one 677 // Go through them one by one
677 QMap<Interface*, QListViewItem*>::Iterator it; 678 QMap<Interface*, QListViewItem*>::Iterator it;
678 for( it = items.begin(); it != items.end(); ++it ) 679 for( it = items.begin(); it != items.end(); ++it )
679 { 680 {
680 if(it.key()->getStatus() == true) 681 if(it.key()->getStatus() == true)
681 it.key()->restart(); 682 it.key()->restart();
682 } 683 }
683 } 684 }
684 } 685 }
685 // TODO change the profile in the modules 686 // TODO change the profile in the modules
686} 687}
687 688
688 689
689void MainWindowImp::makeChannel() 690void MainWindowImp::makeChannel()
690{ 691{
691 channel = new QCopChannel( "QPE/Application/networksettings", this ); 692 channel = new QCopChannel( "QPE/Application/networksettings", this );
692 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 693 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
693 this, SLOT(receive(const QCString&,const QByteArray&)) ); 694 this, SLOT(receive(const QCString&,const QByteArray&)) );
694} 695}
695 696
696void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 697void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
697{ 698{
698 bool found = false; 699 bool found = false;
699 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; 700 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
700 if (msg == "raise") 701 if (msg == "raise")
701 { 702 {
702 raise(); 703 raise();
703 return; 704 return;
704 } 705 }
705 706
706 QString dest = msg.left(msg.find("(")); 707 QString dest = msg.left(msg.find("("));
707 QCString param = msg.right(msg.length() - msg.find("(") - 1); 708 QCString param = msg.right(msg.length() - msg.find("(") - 1);
708 param = param.left( param.length() - 1 ); 709 param = param.left( param.length() - 1 );
709 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; 710 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
710 711
711 QMap<Module*, QLibrary*>::Iterator it; 712 QMap<Module*, QLibrary*>::Iterator it;
712 for( it = libraries.begin(); it != libraries.end(); ++it ) 713 for( it = libraries.begin(); it != libraries.end(); ++it )
713 { 714 {
714 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; 715 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
715 if(it.key()->type() == dest) 716 if(it.key()->type() == dest)
716 { 717 {
717 it.key()->receive( param, arg ); 718 it.key()->receive( param, arg );
718 found = true; 719 found = true;
719 } 720 }
720 } 721 }
721 722
722 723
723 if (found) QPEApplication::setKeepRunning(); 724 if (found) QPEApplication::setKeepRunning();
724 else odebug << "Huh what do ya want" << oendl; 725 else odebug << "Huh what do ya want" << oendl;
725} 726}
726 727
727void MainWindowImp::setHostname() 728void MainWindowImp::setHostname()
728{ 729{
729 QFile f(_HOSTFILE); 730 static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
731 if (filter.match(m_Nameinput->text())!=-1) {
732 odebug << "Wrong hostname" << oendl;
733 QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
734 return;
735 }
730 736
731 OProcess*h = new OProcess; 737 OProcess h;
732 _procTemp=""; 738 _procTemp="";
733 *h << "hostname" << m_Nameinput->text(); 739 h << "hostname" << m_Nameinput->text();
734 connect(h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 740 connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
735 h->start(OProcess::Block,OProcess::Stderr); 741 h.start(OProcess::Block,OProcess::Stderr);
736 odebug << "Got " << _procTemp << " - " << h->exitStatus() << oendl; 742 odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
743 if (h.exitStatus()!=0) {
744 QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
745 return;
746 }
737 _procTemp=""; 747 _procTemp="";
738 delete h;
739 748
749 QFile f(_HOSTFILE);
740 if (f.open(IO_Truncate|IO_WriteOnly)) 750 if (f.open(IO_Truncate|IO_WriteOnly))
741 { 751 {
742 QTextStream s(&f); 752 QTextStream s(&f);
743 s << m_Nameinput->text(); 753 s << m_Nameinput->text();
754 } else {
755 QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
756 return;
744 } 757 }
758
745 f.close(); 759 f.close();
746 f.setName(_IRDANAME); 760 f.setName(_IRDANAME);
747 if (f.open(IO_WriteOnly)) 761 if (f.open(IO_WriteOnly))
748 { 762 {
749 QTextStream s(&f); 763 QTextStream s(&f);
750 s << m_Nameinput->text(); 764 s << m_Nameinput->text();
765 } else {
766 QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
751 } 767 }
752} 768}
753 769
754void MainWindowImp::initHostname() 770void MainWindowImp::initHostname()
755{ 771{
756 OProcess h; 772 OProcess h;
757 _procTemp=""; 773 _procTemp="";
758 774
759 h << "hostname"; 775 h << "hostname";
760 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 776 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
761 h.start(OProcess::Block,OProcess::AllOutput); 777 h.start(OProcess::Block,OProcess::AllOutput);
762 odebug << "Got " << _procTemp <<oendl; 778 odebug << "Got " << _procTemp <<oendl;
763 m_Nameinput->setText(_procTemp); 779 m_Nameinput->setText(_procTemp.stripWhiteSpace());
764 _procTemp=""; 780 _procTemp="";
765} 781}
766 782
767void MainWindowImp::slotHostname(Opie::Core::OProcess *proc, char *buffer, int buflen) 783void MainWindowImp::slotHostname(Opie::Core::OProcess *proc, char *buffer, int buflen)
768{ 784{
769 if (buflen < 1 || buffer==0) return; 785 if (buflen < 1 || buffer==0) return;
770 char*_t = new char[buflen+1]; 786 char*_t = new char[buflen+1];
771 ::memset(_t,0,buflen+1); 787 ::memset(_t,0,buflen+1);
772 ::memcpy(_t,buffer,buflen); 788 ::memcpy(_t,buffer,buflen);
773 _procTemp+=_t; 789 _procTemp+=_t;
774 delete[]_t; 790 delete[]_t;
775} 791}