Diffstat (limited to 'noncore/settings/networksettings/mainwindow') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp index 650e634..e81f603 100644 --- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | |||
@@ -151,97 +151,98 @@ MainWindowImp::~MainWindowImp() | |||
151 | { | 151 | { |
152 | if(iIt.key()->getModuleOwner() == NULL) | 152 | if(iIt.key()->getModuleOwner() == NULL) |
153 | delete iIt.key(); | 153 | delete iIt.key(); |
154 | } | 154 | } |
155 | 155 | ||
156 | // Delete Modules and Libraries | 156 | // Delete Modules and Libraries |
157 | QMap<Module*, QLibrary*>::Iterator it; | 157 | QMap<Module*, QLibrary*>::Iterator it; |
158 | for( it = libraries.begin(); it != libraries.end(); ++it ) | 158 | for( it = libraries.begin(); it != libraries.end(); ++it ) |
159 | { | 159 | { |
160 | delete it.key(); | 160 | delete it.key(); |
161 | // I wonder why I can't delete the libraries | 161 | // I wonder why I can't delete the libraries |
162 | // What fucking shit this is. | 162 | // What fucking shit this is. |
163 | //delete it.data(); | 163 | //delete it.data(); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Query the kernel for all of the interfaces. | 168 | * Query the kernel for all of the interfaces. |
169 | */ | 169 | */ |
170 | void MainWindowImp::getAllInterfaces() | 170 | void MainWindowImp::getAllInterfaces() |
171 | { | 171 | { |
172 | int sockfd = socket(PF_INET, SOCK_DGRAM, 0); | 172 | int sockfd = socket(PF_INET, SOCK_DGRAM, 0); |
173 | if(sockfd == -1) | 173 | if(sockfd == -1) |
174 | return; | 174 | return; |
175 | 175 | ||
176 | struct ifreq ifr; | 176 | struct ifreq ifr; |
177 | QStringList ifaces; | 177 | QStringList ifaces; |
178 | QFile procFile(QString(_PROCNETDEV)); | 178 | QFile procFile(QString(_PROCNETDEV)); |
179 | int result; | 179 | int result; |
180 | Interface *i; | 180 | Interface *i; |
181 | 181 | ||
182 | if (! procFile.exists()) | 182 | if (! procFile.exists()) |
183 | { | 183 | { |
184 | struct ifreq ifrs[100]; | 184 | struct ifreq ifrs[100]; |
185 | struct ifconf ifc; | 185 | struct ifconf ifc; |
186 | ifc.ifc_len = sizeof(ifrs); | 186 | ifc.ifc_len = sizeof(ifrs); |
187 | ifc.ifc_req = ifrs; | 187 | ifc.ifc_req = ifrs; |
188 | result = ioctl(sockfd, SIOCGIFCONF, &ifc); | 188 | result = ioctl(sockfd, SIOCGIFCONF, &ifc); |
189 | 189 | ||
190 | for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) | 190 | for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) |
191 | { | 191 | { |
192 | struct ifreq *pifr = &ifrs[i]; | 192 | struct ifreq *pifr = &ifrs[i]; |
193 | if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name; | 193 | if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name; |
194 | else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl; | 194 | else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl; |
195 | } | 195 | } |
196 | } | 196 | } |
197 | else | 197 | else |
198 | { | 198 | { |
199 | procFile.open(IO_ReadOnly); | 199 | if (!procFile.open(IO_ReadOnly)) |
200 | owarn << "Failed to open proc file " << procFile.name() << oendl; | ||
200 | QString line; | 201 | QString line; |
201 | QTextStream procTs(&procFile); | 202 | QTextStream procTs(&procFile); |
202 | int loc = -1; | 203 | int loc = -1; |
203 | 204 | ||
204 | procTs.readLine(); // eat a line | 205 | procTs.readLine(); // eat a line |
205 | procTs.readLine(); // eat a line | 206 | procTs.readLine(); // eat a line |
206 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) | 207 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) |
207 | { | 208 | { |
208 | if((loc = line.find(":")) != -1) | 209 | if((loc = line.find(":")) != -1) |
209 | { | 210 | { |
210 | // ignore wifi* (hostap control interfaces) | 211 | // ignore wifi* (hostap control interfaces) |
211 | if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc); | 212 | if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc); |
212 | else odebug << "ignoring hostap control interface " << line.left(loc) << oendl; | 213 | else odebug << "ignoring hostap control interface " << line.left(loc) << oendl; |
213 | } | 214 | } |
214 | } | 215 | } |
215 | } | 216 | } |
216 | 217 | ||
217 | for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) | 218 | for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) |
218 | { | 219 | { |
219 | int flags = 0; | 220 | int flags = 0; |
220 | if ( m_handledIfaces.contains( (*it) ) ) | 221 | if ( m_handledIfaces.contains( (*it) ) ) |
221 | { | 222 | { |
222 | odebug << " " << (*it).latin1() << " is handled by a module" << oendl; | 223 | odebug << " " << (*it).latin1() << " is handled by a module" << oendl; |
223 | continue; | 224 | continue; |
224 | } | 225 | } |
225 | // int family; | 226 | // int family; |
226 | i = NULL; | 227 | i = NULL; |
227 | 228 | ||
228 | strcpy(ifr.ifr_name, (*it).latin1()); | 229 | strcpy(ifr.ifr_name, (*it).latin1()); |
229 | 230 | ||
230 | struct ifreq ifcopy; | 231 | struct ifreq ifcopy; |
231 | ifcopy = ifr; | 232 | ifcopy = ifr; |
232 | result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); | 233 | result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); |
233 | flags = ifcopy.ifr_flags; | 234 | flags = ifcopy.ifr_flags; |
234 | i = new Interface(this, ifr.ifr_name, false); | 235 | i = new Interface(this, ifr.ifr_name, false); |
235 | i->setAttached(true); | 236 | i->setAttached(true); |
236 | if ((flags & IFF_UP) == IFF_UP) | 237 | if ((flags & IFF_UP) == IFF_UP) |
237 | i->setStatus(true); | 238 | i->setStatus(true); |
238 | else | 239 | else |
239 | i->setStatus(false); | 240 | i->setStatus(false); |
240 | 241 | ||
241 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) | 242 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) |
242 | i->setHardwareName("Ethernet"); | 243 | i->setHardwareName("Ethernet"); |
243 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) | 244 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) |
244 | i->setHardwareName("Point to Point"); | 245 | i->setHardwareName("Point to Point"); |
245 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) | 246 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) |
246 | i->setHardwareName("Multicast"); | 247 | i->setHardwareName("Multicast"); |
247 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) | 248 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) |
@@ -687,99 +688,101 @@ void MainWindowImp::makeChannel() | |||
687 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 688 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
688 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 689 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
689 | } | 690 | } |
690 | 691 | ||
691 | void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) | 692 | void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) |
692 | { | 693 | { |
693 | bool found = false; | 694 | bool found = false; |
694 | odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; | 695 | odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; |
695 | if (msg == "raise") | 696 | if (msg == "raise") |
696 | { | 697 | { |
697 | raise(); | 698 | raise(); |
698 | return; | 699 | return; |
699 | } | 700 | } |
700 | 701 | ||
701 | QString dest = msg.left(msg.find("(")); | 702 | QString dest = msg.left(msg.find("(")); |
702 | QCString param = msg.right(msg.length() - msg.find("(") - 1); | 703 | QCString param = msg.right(msg.length() - msg.find("(") - 1); |
703 | param = param.left( param.length() - 1 ); | 704 | param = param.left( param.length() - 1 ); |
704 | odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; | 705 | odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; |
705 | 706 | ||
706 | QMap<Module*, QLibrary*>::Iterator it; | 707 | QMap<Module*, QLibrary*>::Iterator it; |
707 | for( it = libraries.begin(); it != libraries.end(); ++it ) | 708 | for( it = libraries.begin(); it != libraries.end(); ++it ) |
708 | { | 709 | { |
709 | odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; | 710 | odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; |
710 | if(it.key()->type() == dest) | 711 | if(it.key()->type() == dest) |
711 | { | 712 | { |
712 | it.key()->receive( param, arg ); | 713 | it.key()->receive( param, arg ); |
713 | found = true; | 714 | found = true; |
714 | } | 715 | } |
715 | } | 716 | } |
716 | 717 | ||
717 | 718 | ||
718 | if (found) QPEApplication::setKeepRunning(); | 719 | if (found) QPEApplication::setKeepRunning(); |
719 | else odebug << "Huh what do ya want" << oendl; | 720 | else odebug << "Huh what do ya want" << oendl; |
720 | } | 721 | } |
721 | 722 | ||
722 | void MainWindowImp::setHostname() | 723 | void MainWindowImp::setHostname() |
723 | { | 724 | { |
724 | static QRegExp filter("[^A-Za-z0-9_\\-\\.]"); | 725 | static QRegExp filter("[^A-Za-z0-9_\\-\\.]"); |
725 | if (filter.match(m_Nameinput->text())!=-1) { | 726 | if (filter.match(m_Nameinput->text())!=-1) { |
726 | odebug << "Wrong hostname" << oendl; | 727 | odebug << "Wrong hostname" << oendl; |
727 | QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot.")); | 728 | QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot.")); |
728 | return; | 729 | return; |
729 | } | 730 | } |
730 | 731 | ||
731 | OProcess h; | 732 | OProcess h; |
732 | _procTemp=""; | 733 | _procTemp=""; |
733 | h << "hostname" << m_Nameinput->text(); | 734 | h << "hostname" << m_Nameinput->text(); |
734 | connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); | 735 | connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); |
735 | h.start(OProcess::Block,OProcess::Stderr); | 736 | if (!h.start(OProcess::Block,OProcess::Stderr)) |
737 | owarn << "Failed execution of 'hostname'. Are the paths correct?" << oendl; | ||
736 | odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl; | 738 | odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl; |
737 | if (h.exitStatus()!=0) { | 739 | if (h.exitStatus()!=0) { |
738 | QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace())); | 740 | QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace())); |
739 | return; | 741 | return; |
740 | } | 742 | } |
741 | _procTemp=""; | 743 | _procTemp=""; |
742 | 744 | ||
743 | QFile f(_HOSTFILE); | 745 | QFile f(_HOSTFILE); |
744 | if (f.open(IO_Truncate|IO_WriteOnly)) | 746 | if (f.open(IO_Truncate|IO_WriteOnly)) |
745 | { | 747 | { |
746 | QTextStream s(&f); | 748 | QTextStream s(&f); |
747 | s << m_Nameinput->text(); | 749 | s << m_Nameinput->text(); |
748 | } else { | 750 | } else { |
749 | QMessageBox::critical(0, tr("Sorry"), tr("Could not save name.")); | 751 | QMessageBox::critical(0, tr("Sorry"), tr("Could not save name.")); |
750 | return; | 752 | return; |
751 | } | 753 | } |
752 | 754 | ||
753 | f.close(); | 755 | f.close(); |
754 | f.setName(_IRDANAME); | 756 | f.setName(_IRDANAME); |
755 | if (f.open(IO_WriteOnly)) | 757 | if (f.open(IO_WriteOnly)) |
756 | { | 758 | { |
757 | QTextStream s(&f); | 759 | QTextStream s(&f); |
758 | s << m_Nameinput->text(); | 760 | s << m_Nameinput->text(); |
759 | } else { | 761 | } else { |
760 | QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name.")); | 762 | QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name.")); |
761 | } | 763 | } |
762 | } | 764 | } |
763 | 765 | ||
764 | void MainWindowImp::initHostname() | 766 | void MainWindowImp::initHostname() |
765 | { | 767 | { |
766 | OProcess h; | 768 | OProcess h; |
767 | _procTemp=""; | 769 | _procTemp=""; |
768 | 770 | ||
769 | h << "hostname"; | 771 | h << "hostname"; |
770 | connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); | 772 | connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); |
771 | h.start(OProcess::Block,OProcess::AllOutput); | 773 | if (!h.start(OProcess::Block,OProcess::AllOutput)) |
774 | owarn << "Could not execute 'hostname'. Are the paths correct?" oendl; | ||
772 | odebug << "Got " << _procTemp <<oendl; | 775 | odebug << "Got " << _procTemp <<oendl; |
773 | m_Nameinput->setText(_procTemp.stripWhiteSpace()); | 776 | m_Nameinput->setText(_procTemp.stripWhiteSpace()); |
774 | _procTemp=""; | 777 | _procTemp=""; |
775 | } | 778 | } |
776 | 779 | ||
777 | void MainWindowImp::slotHostname(Opie::Core::OProcess */*proc*/, char *buffer, int buflen) | 780 | void MainWindowImp::slotHostname(Opie::Core::OProcess * /*proc*/, char *buffer, int buflen) |
778 | { | 781 | { |
779 | if (buflen < 1 || buffer==0) return; | 782 | if (buflen < 1 || buffer==0) return; |
780 | char*_t = new char[buflen+1]; | 783 | char*_t = new char[buflen+1]; |
781 | ::memset(_t,0,buflen+1); | 784 | ::memset(_t,0,buflen+1); |
782 | ::memcpy(_t,buffer,buflen); | 785 | ::memcpy(_t,buffer,buflen); |
783 | _procTemp+=_t; | 786 | _procTemp+=_t; |
784 | delete[]_t; | 787 | delete[]_t; |
785 | } | 788 | } |