summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/mainwindow/mainwindowimp.cpp') (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
@@ -17,24 +17,25 @@
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
@@ -717,59 +718,74 @@ void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
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}