summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -23,12 +23,13 @@
#include <qlistview.h>
#include <qheader.h>
#include <qlabel.h>
#include <qtabwidget.h> // in order to disable the profiles tab
#include <qmessagebox.h>
#include <qtextstream.h>
+#include <qregexp.h>
#if QT_VERSION < 0x030000
#include <qlist.h>
#else
#include <qptrlist.h>
@@ -723,47 +724,62 @@ void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
if (found) QPEApplication::setKeepRunning();
else odebug << "Huh what do ya want" << oendl;
}
void MainWindowImp::setHostname()
{
- QFile f(_HOSTFILE);
+ static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
+ if (filter.match(m_Nameinput->text())!=-1) {
+ odebug << "Wrong hostname" << oendl;
+ QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
+ return;
+ }
- OProcess*h = new OProcess;
+ OProcess h;
_procTemp="";
- *h << "hostname" << m_Nameinput->text();
- connect(h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
- h->start(OProcess::Block,OProcess::Stderr);
- odebug << "Got " << _procTemp << " - " << h->exitStatus() << oendl;
+ h << "hostname" << m_Nameinput->text();
+ connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
+ h.start(OProcess::Block,OProcess::Stderr);
+ odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
+ if (h.exitStatus()!=0) {
+ QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
+ return;
+ }
_procTemp="";
- delete h;
+ QFile f(_HOSTFILE);
if (f.open(IO_Truncate|IO_WriteOnly))
{
QTextStream s(&f);
s << m_Nameinput->text();
+ } else {
+ QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
+ return;
}
+
f.close();
f.setName(_IRDANAME);
if (f.open(IO_WriteOnly))
{
QTextStream s(&f);
s << m_Nameinput->text();
+ } else {
+ QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
}
}
void MainWindowImp::initHostname()
{
OProcess h;
_procTemp="";
h << "hostname";
connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
h.start(OProcess::Block,OProcess::AllOutput);
odebug << "Got " << _procTemp <<oendl;
- m_Nameinput->setText(_procTemp);
+ m_Nameinput->setText(_procTemp.stripWhiteSpace());
_procTemp="";
}
void MainWindowImp::slotHostname(Opie::Core::OProcess *proc, char *buffer, int buflen)
{
if (buflen < 1 || buffer==0) return;