From b9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2 Mon Sep 17 00:00:00 2001 From: alwin Date: Mon, 07 Mar 2005 17:43:40 +0000 Subject: let users set hostname via dialog. the same name will set as IRDA name so user can give their personal device a personal name. ;) ToDO: fixup init scripts in OE so hostname will set on startup into IRDA name --- diff --git a/noncore/settings/networksettings/mainwindow/mainwindow.ui b/noncore/settings/networksettings/mainwindow/mainwindow.ui index a730dd5..185b345 100644 --- a/noncore/settings/networksettings/mainwindow/mainwindow.ui +++ b/noncore/settings/networksettings/mainwindow/mainwindow.ui @@ -11,7 +11,7 @@ 0 0 - 240 + 340 289 @@ -41,6 +41,9 @@ layoutMargin + + layoutSpacing + QWidget @@ -432,9 +435,108 @@ + + QWidget + + name + devicenametab + + + title + Device name + + + + margin + 11 + + + spacing + 6 + + + QLabel + + name + m_NameHead + + + text + <b>Name of the device</b> + + + + QLineEdit + + name + m_Nameinput + + + + QPushButton + + name + m_setButton + + + text + Set value + + + + QLabel + + name + m_Infolabel + + + sizePolicy + + 3 + 3 + + + + text + The name here is that one your device identifying with on +console or infrared. + + + + + name + Spacer5 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + + m_setButton + clicked() + MainWindow + setHostname() + + setHostname() + tabWidget connectionList diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp index f83e370..0a3312c 100644 --- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp @@ -8,6 +8,7 @@ /* OPIE */ #include +#include #include #include #include @@ -24,6 +25,7 @@ #include #include // in order to disable the profiles tab #include +#include #if QT_VERSION < 0x030000 @@ -44,6 +46,12 @@ #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" #define _PROCNETDEV "/proc/net/dev" +// is this always right? +#define _HOSTFILE "/etc/hostname" +#define _IRDANAME "/proc/sys/net/irda/devname" + +using namespace Opie::Core; + MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) { connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); @@ -122,6 +130,7 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWi file.close(); } makeChannel(); + initHostname(); } /** @@ -714,3 +723,53 @@ 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); + + OProcess*h = new OProcess; + _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; + _procTemp=""; + delete h; + + if (f.open(IO_Truncate|IO_WriteOnly)) + { + QTextStream s(&f); + s << m_Nameinput->text(); + } + f.close(); + f.setName(_IRDANAME); + if (f.open(IO_WriteOnly)) + { + QTextStream s(&f); + s << m_Nameinput->text(); + } +} + +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 <setText(_procTemp); + _procTemp=""; +} + +void MainWindowImp::slotHostname(Opie::Core::OProcess *proc, char *buffer, int buflen) +{ + if (buflen < 1 || buffer==0) return; + char*_t = new char[buflen+1]; + ::memset(_t,0,buflen+1); + ::memcpy(_t,buffer,buflen); + _procTemp+=_t; + delete[]_t; +} diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.h b/noncore/settings/networksettings/mainwindow/mainwindowimp.h index f211d6e..da1bb8f 100644 --- a/noncore/settings/networksettings/mainwindow/mainwindowimp.h +++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.h @@ -18,6 +18,11 @@ class KLibLoader; #define QLibrary KLibrary #endif +namespace Opie { +namespace Core { + class OProcess; +} +} class MainWindowImp : public MainWindow { Q_OBJECT @@ -46,12 +51,17 @@ private slots: void receive (const QCString &, const QByteArray &); +protected slots: + virtual void setHostname(); + virtual void slotHostname(Opie::Core::OProcess *proc, char *buffer, int buflen); + private: void makeChannel(); void loadModules(const QString &path); + void initHostname(); Module* loadPlugin(const QString &pluginFileName, - const QString &resolveString = "create_plugin"); + const QString &resolveString = "create_plugin"); // For our local list of names QMap interfaceNames; @@ -66,6 +76,7 @@ private: bool advancedUserMode; QString scheme; + QString _procTemp; #ifndef QWS KLibLoader *loader; #endif -- cgit v0.9.0.2