author | zecke <zecke> | 2002-10-31 16:14:20 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-31 16:14:20 (UTC) |
commit | d2a79869efe8b18849e45b8e1beedb5108eba6ac (patch) (side-by-side diff) | |
tree | 98b5d50f696d2d411cd287f4fe1bc7e1c0f7b7a2 | |
parent | c3a6f53669140cf9e3c953772c610cd91d69ab78 (diff) | |
download | opie-d2a79869efe8b18849e45b8e1beedb5108eba6ac.zip opie-d2a79869efe8b18849e45b8e1beedb5108eba6ac.tar.gz opie-d2a79869efe8b18849e45b8e1beedb5108eba6ac.tar.bz2 |
Auto connect on Locale Console again!
MyPty test if cmd is available(exists) and then
either use /bin/bash or /bin/sh
ConsoleConfigWidget added a comment about the expected behaviour
-rw-r--r-- | noncore/apps/opie-console/MyPty.cpp | 17 | ||||
-rw-r--r-- | noncore/apps/opie-console/consoleconfigwidget.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/opie-console/profileeditordialog.cpp | 2 |
3 files changed, 22 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp index b0f0275..c3c58be 100644 --- a/noncore/apps/opie-console/MyPty.cpp +++ b/noncore/apps/opie-console/MyPty.cpp @@ -166,190 +166,205 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int) static struct termios ttmode; if ( setsid() < 0 ) perror( "failed to set process group" ); #if defined (TIOCSCTTY) // grabbed from APUE by Stevens ioctl(STDIN_FILENO, TIOCSCTTY, 0); #endif tcgetattr( STDIN_FILENO, &ttmode ); ttmode.c_cc[VINTR] = 3; ttmode.c_cc[VERASE] = 8; tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); setenv("TERM",m_term,1); setenv("COLORTERM","0",1); EnvironmentMap::Iterator it; for (it = m_env.begin(); it != m_env.end(); it++) { setenv(it.key().latin1(), it.data().latin1(), 1); } if (getuid() == 0) { char msg[] = "WARNING: You are running this shell as root!\n"; write(ttyfd, msg, sizeof(msg)); } execl(cmd, cmd, 0); donePty(); exit(-1); } // parent - continue as a widget delete m_sn_r; m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); delete m_sn_e; m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error())); return 0; } int MyPty::openPty() { // This is code from the Qt DumbTerminal example int ptyfd = -1; #ifdef HAVE_OPENPTY int ttyfd; if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) ptyfd = -1; else close(ttyfd); // we open the ttynam ourselves. #else for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) { for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) { sprintf(m_ptynam,"/dev/pty%c%c",*c0,*c1); sprintf(m_ttynam,"/dev/tty%c%c",*c0,*c1); if ((ptyfd = ::open(m_ptynam,O_RDWR)) >= 0) { if (geteuid() != 0 && !access(m_ttynam,R_OK|W_OK) == 0) { ::close(ptyfd); ptyfd = -1; } } } } #endif if ( ptyfd < 0 ) { // qApp->exit(1); return -1; } return ptyfd; } /*! Create an instance. */ MyPty::MyPty(const Profile& prof) : m_cpid(0) { int term = prof.readNumEntry("Terminal", Profile::VT100 ); switch( term ) { default: case Profile::VT100: case Profile::VT102: m_term = "vt100"; break; case Profile::Linux: m_term = "linux"; break; case Profile::XTerm: m_term = "xterm"; break; } m_sn_e = 0l; m_sn_r = 0l; m_fd = openPty(); ProcCtl* ctl = ProcCtl::self(); Q_UNUSED(ctl); reload(prof); } /*! Destructor. Note that the related client program is not killed (yet) when a instance is deleted. */ MyPty::~MyPty() { donePty(); } QString MyPty::identifier()const { return QString::fromLatin1("term"); } QString MyPty::name()const{ return identifier(); } bool MyPty::open() { if (m_fd < 0) m_fd = openPty(); start(); return true; } void MyPty::close() { donePty(); m_fd = openPty(); } void MyPty::reload( const Profile& prof) { m_env.clear(); - m_cmd = prof.readEntry("Command", "/bin/bash"); + m_cmd = prof.readEntry("Command", "/bin/sh"); + + /* + * Lets check if m_cmd actually + * exists.... + * we try to use bin/bash and if + * this fails we + * will fallback to /bin/sh + * which should be there 100% + */ + if ( !QFile::exists(QFile::encodeName(m_cmd) ) ) + if (QFile::exists("/bin/bash") ) + m_cmd = "/bin/bash"; + else + m_cmd = "/bin/sh"; + int envcount = prof.readNumEntry("EnvVars", 0); for (int i=0; i<envcount; i++) { QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); if (!(name.isEmpty() || value.isEmpty())) { m_env.insert(name, value); } } } /*! sends len bytes through the line */ void MyPty::send(const QByteArray& ar) { #ifdef VERBOSE_DEBUG // verbose debug printf("sending bytes:\n"); for (uint i = 0; i < ar.count(); i++) printf("%c", ar[i]); printf("\n"); #endif ::write(m_fd, ar.data(), ar.count()); } /*! indicates that a block of data is received */ void MyPty::readPty() { QByteArray buf(4096); int len = ::read( m_fd, buf.data(), 4096 ); if (len == -1 || len == 0) { donePty(); return; } if (len < 0) return; buf.resize(len); emit received(buf); #ifdef VERBOSE_DEBUG // verbose debug printf("read bytes:\n"); for (uint i = 0; i < buf.count(); i++) printf("%c", buf[i]); printf("\n"); #endif } QBitArray MyPty::supports()const { QBitArray ar(3); //autoconnect ar[0] = 1; // ar[1] = 0; ar[2] = 0; return ar; } diff --git a/noncore/apps/opie-console/consoleconfigwidget.cpp b/noncore/apps/opie-console/consoleconfigwidget.cpp index 70e2e78..3f2d154 100644 --- a/noncore/apps/opie-console/consoleconfigwidget.cpp +++ b/noncore/apps/opie-console/consoleconfigwidget.cpp @@ -1,95 +1,100 @@ #include <qlabel.h> #include <qlayout.h> #include <qcombobox.h> #include <qlineedit.h> #include <qpushbutton.h> #include <qlistview.h> #include <qhbox.h> #include <qregexp.h> #include <stdio.h> #include "consoleconfigwidget.h" ConsoleConfigWidget::ConsoleConfigWidget( const QString& name, QWidget* parent, const char* na ) : ProfileDialogConnectionWidget( name, parent, na ) { m_lay = new QVBoxLayout( this ); QLabel *label = new QLabel(tr("Command to execute"), this); m_lay->addWidget(label); m_cmd = new QLineEdit(this); m_lay->addWidget(m_cmd); label = new QLabel(tr("Environment Variables"), this); m_lay->addWidget(label); m_env = new QListView(this); m_env->addColumn(tr("Name")); m_env->addColumn(tr("Value")); m_lay->addWidget(m_env); QHBox *hbox = new QHBox(this); label = new QLabel(tr("Name :"), hbox); m_name = new QLineEdit(hbox); m_lay->addWidget(hbox); hbox = new QHBox(this); label = new QLabel(tr("Value :"), hbox); m_value = new QLineEdit(hbox); m_lay->addWidget(hbox); hbox = new QHBox(this); hbox->setSpacing(10); m_remove = new QPushButton(tr("Remove"), hbox); connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove())); m_add = new QPushButton(tr("Add"), hbox); connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd())); m_lay->addWidget(hbox); } void ConsoleConfigWidget::slotAdd() { if (!(m_name->text().isEmpty() || m_value->text().isEmpty())) { QListViewItem *item = new QListViewItem(m_env); item->setText(0, m_name->text()); item->setText(1, m_value->text()); m_env->insertItem(item); } } void ConsoleConfigWidget::slotRemove() { QListViewItem *item = m_env->currentItem(); if (item) { m_env->takeItem(item); } } ConsoleConfigWidget::~ConsoleConfigWidget() { } void ConsoleConfigWidget::load( const Profile& prof ) { + /* + * we will use /bin/bash as default + * but will fallback in MyPty to /bin/sh + * if necessary + */ m_cmd->setText(prof.readEntry("Command", "/bin/bash")); int envcount = prof.readNumEntry("EnvVars", 0); for (int i=0; i<envcount; i++) { QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); if (!(name.isEmpty() || value.isEmpty())) { QListViewItem *item = new QListViewItem(m_env); item->setText(0, name); item->setText(1, value); m_env->insertItem(item); } } } void ConsoleConfigWidget::save( Profile& prof ) { prof.writeEntry( "Command", m_cmd->text()); QListViewItem *item = m_env->firstChild(); int counter = 0; while (item) { QString name = item->text(0); QString value = item->text(1); prof.writeEntry("Env_Name_" + QString::number(counter), name); prof.writeEntry("Env_Value_" + QString::number(counter), value); item = item->nextSibling(); counter++; } prof.writeEntry("EnvVars", QString::number(counter)); } diff --git a/noncore/apps/opie-console/profileeditordialog.cpp b/noncore/apps/opie-console/profileeditordialog.cpp index fd04b6b..6b607df 100644 --- a/noncore/apps/opie-console/profileeditordialog.cpp +++ b/noncore/apps/opie-console/profileeditordialog.cpp @@ -75,165 +75,165 @@ void ProfileEditorDialog::initUI() /* base layout for tabs */ m_layCon = new QHBoxLayout( m_tabCon , 2 ); m_layTerm = new QHBoxLayout( m_tabTerm, 2 ); m_layKey = new QHBoxLayout( m_tabKey, 2 ); m_layCon->addWidget( m_svCon ); m_layTerm->addWidget( m_svTerm ); // profile tab QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof); m_name = new QLineEdit(tabprof); QLabel *con = new QLabel(tr("Connection"), tabprof ); QLabel *term = new QLabel(tr("Terminal"), tabprof ); m_conCmb = new QComboBox( tabprof ); m_termCmb = new QComboBox( tabprof ); m_autoConnect = new QCheckBox(tr("Auto connect after load"), tabprof); // layouting QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2); vbox3->add(name); vbox3->add(m_name); vbox3->add(con ); vbox3->add(m_conCmb ); vbox3->add(term ); vbox3->add(m_termCmb ); vbox3->add(m_autoConnect); vbox3->addStretch(1); m_showconntab = 0; tabWidget->addTab(tabprof, "", QObject::tr("Profile")); tabWidget->addTab(m_tabCon, "", QObject::tr("Connection")); tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal")); tabWidget->addTab(m_tabKey, "", QObject::tr("Special Keys")); tabWidget->setCurrentTab( tabprof ); // fill the comboboxes QStringList list = m_fact->connectionWidgets(); QStringList::Iterator it; for (it =list.begin(); it != list.end(); ++it ) { m_conCmb->insertItem( (*it) ); } list = m_fact->terminalWidgets(); for (it =list.begin(); it != list.end(); ++it ) { m_termCmb->insertItem( (*it) ); } // load profile values m_name->setText(m_prof.name()); slotConActivated( m_fact->external(m_prof.ioLayerName() ) ); slotTermActivated( m_fact->external(m_prof.terminalName() ) ); slotKeyActivated( "Default Keyboard" ); setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb ); setCurrent( m_fact->external(m_prof.terminalName() ), m_termCmb ); m_autoConnect->setChecked(m_prof.autoConnect()); // signal and slots connect(m_conCmb, SIGNAL(activated(const QString& ) ), this, SLOT(slotConActivated(const QString&) ) ); connect(m_termCmb, SIGNAL(activated(const QString& ) ), this, SLOT(slotTermActivated(const QString& ) ) ); } ProfileEditorDialog::~ProfileEditorDialog() { } void ProfileEditorDialog::accept() { if(profName().isEmpty()) { QMessageBox::information(this, QObject::tr("Invalid profile"), QObject::tr("Please enter a profile name.")); return; } // Save profile and plugin profile //if(plugin_plugin) plugin_plugin->save(); // Save general values m_prof.setName( profName() ); m_prof.setIOLayer( m_fact->internal(m_conCmb ->currentText() ) ); m_prof.setTerminalName( m_fact->internal(m_termCmb->currentText() ) ); m_prof.setAutoConnect( m_autoConnect->isChecked() ); if (m_con ) m_con->save( m_prof ); if (m_term ) m_term->save( m_prof ); if (m_key) m_key->save( m_prof ); QDialog::accept(); } QString ProfileEditorDialog::profName()const { return m_name->text(); } QCString ProfileEditorDialog::profType()const { /*QStringList w = m_fact->configWidgets(); for(QStringList::Iterator it = w.begin(); it != w.end(); it++) if(device_box->currentText() == m_fact->name((*it))) return (*it); */ return QCString(); } /* * we need to switch the widget */ void ProfileEditorDialog::slotConActivated( const QString& str ) { delete m_con; m_con = m_fact->newConnectionPlugin( str, m_svCon->viewport() ); if ( !m_con ) { m_con = new NoOptions( str, m_svCon->viewport(), "name"); } // FIXME ugly hack right. Right solution would be to look into the layer and see if it // supports auto connect and then set it as prefered //if ( ( )->layer()->supports()[0] == 1 ) { - if ( m_conCmb ->currentText() == tr("local Console") ) { + if ( m_conCmb ->currentText() == tr("Local Console") ) { m_autoConnect->setChecked( true ); } else { m_autoConnect->setChecked( false ); } m_con->load( m_prof ); m_svCon->addChild( m_con ); } /* * we need to switch the widget */ void ProfileEditorDialog::slotTermActivated( const QString& str ) { delete m_term; m_term = m_fact->newTerminalPlugin( str, m_svTerm->viewport() ); if (m_term) { m_term->load( m_prof ); m_svTerm->addChild( m_term ); } } void ProfileEditorDialog::slotKeyActivated(const QString &str) { delete m_key; m_key = m_fact->newKeyboardPlugin( str, m_tabKey ); if (m_key) { m_key->load(m_prof); m_layKey->addWidget(m_key); } } |