-rw-r--r-- | noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | 32 |
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,60 +1,61 @@ | |||
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 | ||
53 | using namespace Opie::Core; | 54 | using namespace Opie::Core; |
54 | 55 | ||
55 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) | 56 | MainWindowImp::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())); |
@@ -697,79 +698,94 @@ void 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 | ||
727 | void MainWindowImp::setHostname() | 728 | void 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 | ||
754 | void MainWindowImp::initHostname() | 770 | void 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 | ||
767 | void MainWindowImp::slotHostname(Opie::Core::OProcess *proc, char *buffer, int buflen) | 783 | void 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 | } |