author | alwin <alwin> | 2005-03-07 17:43:40 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-07 17:43:40 (UTC) |
commit | b9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2 (patch) (side-by-side diff) | |
tree | 4f93456e3f1d4bb9334bccf0e97c04c51d7b2133 /noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | |
parent | 5ab00b78b199b1a03d3f27faa8b1dcffd9a86ff7 (diff) | |
download | opie-b9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2.zip opie-b9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2.tar.gz opie-b9b5ec22a5969c57a2e2b940faf42ae6f9fd74d2.tar.bz2 |
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
Diffstat (limited to 'noncore/settings/networksettings/mainwindow/mainwindowimp.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
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 @@ -3,32 +3,34 @@ #include "addconnectionimp.h" #include "interfaceinformationimp.h" #include "interfacesetupimp.h" #include "interfaces.h" #include "module.h" /* OPIE */ #include <opie2/odebug.h> +#include <opie2/oprocess.h> #include <qpe/applnk.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/qlibrary.h> #include <qpe/resource.h> /* QT */ #include <qpushbutton.h> #include <qlistbox.h> #include <qlineedit.h> #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> #if QT_VERSION < 0x030000 #include <qlist.h> #else #include <qptrlist.h> #endif #include <qdir.h> @@ -39,16 +41,22 @@ /* STD */ #include <net/if.h> #include <sys/ioctl.h> #include <sys/socket.h> #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())); connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); //remove tab with no function @@ -117,16 +125,17 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWi line = line.mid(7, line.length()); currentProfileLabel->setText(line); break; } } file.close(); } makeChannel(); + initHostname(); } /** * Deconstructor. Save profiles. Delete loaded libraries. */ MainWindowImp::~MainWindowImp() { // Save profiles. @@ -709,8 +718,58 @@ void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) found = true; } } 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 <<oendl; + m_Nameinput->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; +} |