author | hash <hash> | 2002-10-18 19:50:27 (UTC) |
---|---|---|
committer | hash <hash> | 2002-10-18 19:50:27 (UTC) |
commit | bb98ac35db9807efbcc1b59dd8abbdb05ad7656b (patch) (side-by-side diff) | |
tree | 60f83f4c10c68da1ca7641b26b91b8970ef0eaa3 | |
parent | 081001a515f23626b6299e39af4511f36db46d07 (diff) | |
download | opie-bb98ac35db9807efbcc1b59dd8abbdb05ad7656b.zip opie-bb98ac35db9807efbcc1b59dd8abbdb05ad7656b.tar.gz opie-bb98ac35db9807efbcc1b59dd8abbdb05ad7656b.tar.bz2 |
added autoconnect support. feel free to revert if i messed something up.
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/profile.cpp | 11 | ||||
-rw-r--r-- | noncore/apps/opie-console/profile.h | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/profileeditordialog.cpp | 7 | ||||
-rw-r--r-- | noncore/apps/opie-console/profileeditordialog.h | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/profilemanager.cpp | 2 |
6 files changed, 25 insertions, 3 deletions
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index cf1fbc3..5900785 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp @@ -387,97 +387,98 @@ void MainWindow::slotClose() { m_terminate->setEnabled( false ); m_transfer->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); m_runScript->setEnabled( false ); m_fullscreen->setEnabled( false ); m_closewindow->setEnabled( false ); } } /* * We will get the name * Then the profile * and then we will make a profile */ void MainWindow::slotProfile( int id) { Profile prof = manager()->profile( m_sessionsPop->text( id) ); create( prof ); } void MainWindow::create( const Profile& prof ) { Session *ses = manager()->fromProfile( prof, tabWidget() ); if((!ses) || (!ses->layer()) || (!ses->widgetStack())) { QMessageBox::warning(this, QObject::tr("Session failed"), QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); //if(ses) delete ses; return; } m_sessions.append( ses ); tabWidget()->add( ses ); m_curSession = ses; // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( true ); m_transfer->setEnabled( true ); m_recordScript->setEnabled( true ); m_saveScript->setEnabled( true ); m_runScript->setEnabled( true ); m_fullscreen->setEnabled( true ); m_closewindow->setEnabled( true ); // is io_layer wants direct connection, then autoconnect - if ( ( m_curSession->layer() )->supports()[0] == 1 ) { + //if ( ( m_curSession->layer() )->supports()[0] == 1 ) { + if (prof.autoConnect()) { slotConnect(); } } void MainWindow::slotTransfer() { if ( currentSession() ) { TransferDialog dlg(currentSession()->widgetStack(), this); dlg.showMaximized(); //currentSession()->widgetStack()->add(dlg); dlg.exec(); } } void MainWindow::slotOpenKeb(bool state) { if (state) m_keyBar->show(); else m_keyBar->hide(); } void MainWindow::slotOpenButtons( bool state ) { if ( state ) { m_buttonBar->show(); } else { m_buttonBar->hide(); } } void MainWindow::slotSessionChanged( Session* ses ) { qWarning("changed!"); if ( ses ) { m_curSession = ses; qDebug(QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) ); if ( m_curSession->layer()->isConnected() ) { m_connect->setEnabled( false ); m_disconnect->setEnabled( true ); } else { m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); } } } diff --git a/noncore/apps/opie-console/profile.cpp b/noncore/apps/opie-console/profile.cpp index 1a94619..51d1aa8 100644 --- a/noncore/apps/opie-console/profile.cpp +++ b/noncore/apps/opie-console/profile.cpp @@ -1,114 +1,123 @@ #include "profile.h" Profile::Profile() { } Profile::Profile( const QString& name, const QCString& iolayerName, const QCString& termName, int background, int foreground, int terminal ) - : m_name( name ), m_ioLayer( iolayerName ), m_term( termName), + : m_name( name ), m_ioLayer( iolayerName ), m_term( termName), m_autoConnect(0), m_back( background ), m_fore( foreground ), m_terminal( terminal ) {} Profile::Profile( const Profile& prof ) { (*this) = prof; } bool Profile::operator==( const Profile& prof ) { if ( m_name == prof.m_name ) return true; return false; } Profile &Profile::operator=( const Profile& prof ) { m_name = prof.m_name; m_ioLayer = prof.m_ioLayer; + m_autoConnect = prof.m_autoConnect; m_back = prof.m_back; m_fore = prof.m_fore; m_terminal = prof.m_terminal; m_conf = prof.m_conf; m_term = prof.m_term; return *this; } Profile::~Profile() { } QMap<QString, QString> Profile::conf()const { return m_conf; } QString Profile::name()const { return m_name; } QCString Profile::ioLayerName()const { return m_ioLayer; } QCString Profile::terminalName( )const { return m_term; } +bool Profile::autoConnect()const { + + return m_autoConnect; +} int Profile::foreground()const { return m_fore; } int Profile::background()const { return m_back; } int Profile::terminal()const { return m_terminal; } void Profile::setName( const QString& str ) { m_name = str; } void Profile::setIOLayer( const QCString& name ) { m_ioLayer = name; } void Profile::setTerminalName( const QCString& str ) { m_term = str; } +void Profile::setAutoConnect( const bool c) { + + m_autoConnect = c; +} void Profile::setBackground( int back ) { m_back = back; } void Profile::setForeground( int fore ) { m_fore = fore; } void Profile::setTerminal( int term ) { m_terminal = term; } /* config stuff */ void Profile::clearConf() { m_conf.clear(); } void Profile::writeEntry( const QString& key, const QString& value ) { m_conf.replace( key, value ); } void Profile::writeEntry( const QString& key, int num ) { writeEntry( key, QString::number( num ) ); } void Profile::writeEntry( const QString& key, bool b ) { writeEntry( key, QString::number(b) ); } void Profile::writeEntry( const QString& key, const QStringList& lis, const QChar& sep ) { writeEntry( key, lis.join(sep) ); } QString Profile::readEntry( const QString& key, const QString& deflt )const { QMap<QString, QString>::ConstIterator it; it = m_conf.find( key ); if ( it != m_conf.end() ) return it.data(); return deflt; } int Profile::readNumEntry( const QString& key, int def )const { QMap<QString, QString>::ConstIterator it; it = m_conf.find( key ); if ( it != m_conf.end() ) { bool ok; int val = it.data().toInt(&ok); if (ok) return val; } return def; } bool Profile::readBoolEntry( const QString& key, bool def )const { diff --git a/noncore/apps/opie-console/profile.h b/noncore/apps/opie-console/profile.h index 64eb022..4f9e9c2 100644 --- a/noncore/apps/opie-console/profile.h +++ b/noncore/apps/opie-console/profile.h @@ -1,73 +1,76 @@ #ifndef OPIE_PROFILE_H #define OPIE_PROFILE_H #include <qmap.h> #include <qstring.h> #include <qstringlist.h> #include <qvaluelist.h> /** * A session will be generated from a saved * profile. A profile contains the iolayername * a name. * We can generate a Session from a Profile * Configuration is contained here too */ class Profile { public: typedef QValueList<Profile> ValueList; enum Color { Black = 0, White, Gray, Green, Orange}; enum Terminal {VT102 = 0, VT100 }; enum Font { Micro = 0, Small, Medium }; Profile(); Profile( const QString& name, const QCString& iolayerName, const QCString& termName, int background, int foreground, int terminal); Profile( const Profile& ); Profile &operator=( const Profile& ); bool operator==( const Profile& prof ); ~Profile(); QString name()const; QCString ioLayerName()const; QCString terminalName()const; + bool autoConnect()const; int foreground()const; int background()const; int terminal()const; /* * config stuff */ QMap<QString, QString> conf()const; void clearConf(); void writeEntry( const QString& key, const QString& value ); void writeEntry( const QString& key, int num ); void writeEntry( const QString& key, bool b ); void writeEntry( const QString& key, const QStringList&, const QChar& ); QString readEntry( const QString& key, const QString& deflt = QString::null)const; int readNumEntry( const QString& key, int = -1 )const; bool readBoolEntry( const QString& key, bool = FALSE )const; void setName( const QString& ); void setIOLayer( const QCString& ); void setTerminalName( const QCString& ); + void setAutoConnect( const bool ); void setBackground( int back ); void setForeground( int fore ); void setTerminal( int term ); void setConf( const QMap<QString, QString>& ); private: QMap<QString, QString> m_conf; QString m_name; QCString m_ioLayer, m_term; + bool m_autoConnect; int m_back; int m_fore; int m_terminal; }; #endif diff --git a/noncore/apps/opie-console/profileeditordialog.cpp b/noncore/apps/opie-console/profileeditordialog.cpp index 5c5c2b3..c48ea53 100644 --- a/noncore/apps/opie-console/profileeditordialog.cpp +++ b/noncore/apps/opie-console/profileeditordialog.cpp @@ -1,191 +1,196 @@ #include <qlayout.h> #include <qlineedit.h> #include <qlabel.h> #include <qmessagebox.h> #include <qstringlist.h> #include <qcombobox.h> +#include <qcheckbox.h> -#include "profileeditorplugins.h" +//#include "profileeditorplugins.h" #include "metafactory.h" #include "profileeditordialog.h" namespace { void setCurrent( const QString& str, QComboBox* bo ) { for (uint i = 0; i < bo->count(); i++ ) { if ( bo->text(i) == str ) { bo->setCurrentItem( i ); } } } } ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact, const Profile& prof ) : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof ) { initUI(); // Apply current profile // plugin_plugin->load(profile); // ... (reset profile name line edit etc.) } ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact ) : QDialog(0, 0, TRUE), m_fact( fact ) { // Default profile m_prof = Profile("New Profile", "serial", "default", Profile::Black, Profile::White, Profile::VT102); initUI(); // Apply current profile // plugin_plugin->load(profile); } Profile ProfileEditorDialog::profile() const { return m_prof; } void ProfileEditorDialog::initUI() { m_con = m_term = 0l; QVBoxLayout *mainLayout = new QVBoxLayout( this ); tabWidget = new OTabWidget( this ); tabWidget->setTabStyle(OTabWidget::TextTab); mainLayout->add(tabWidget); QWidget *tabprof; /* base tabs */ tabprof = new QWidget(this); m_tabTerm = new QWidget(this); m_tabCon = new QWidget(this); /* base layout for tabs */ m_layCon = new QHBoxLayout( m_tabCon , 2 ); m_layTerm = new QHBoxLayout( m_tabTerm, 2 ); // 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); tabWidget->addTab(tabprof, "", QObject::tr("Profile")); tabWidget->addTab(m_tabCon, "", QObject::tr("Connection")); tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal")); 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() ) ); 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 ); 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_tabCon ); if ( m_con ) { m_con->load( m_prof ); m_layCon->addWidget( m_con ); } else { tabWidget->removePage( m_tabCon ); } } /* * we need to switch the widget */ void ProfileEditorDialog::slotTermActivated( const QString& str ) { delete m_term; m_term = m_fact->newTerminalPlugin( str, m_tabTerm ); if (m_term) { m_term->load(m_prof ); m_layTerm->addWidget( m_term ); } diff --git a/noncore/apps/opie-console/profileeditordialog.h b/noncore/apps/opie-console/profileeditordialog.h index 6fde839..e01e636 100644 --- a/noncore/apps/opie-console/profileeditordialog.h +++ b/noncore/apps/opie-console/profileeditordialog.h @@ -1,53 +1,55 @@ #ifndef PROFILE_EDITOR_DIALOG #define PROFILE_EDITOR_DIALOG #include <qdialog.h> #include <opie/otabwidget.h> #include "profile.h" class MetaFactory; class EditBase; class QTabWidget; class QHBoxLayout; class QLineEdit; class QComboBox; +class QCheckBox; class QLabel; class ProfileDialogWidget; class ProfileEditorDialog : public QDialog { Q_OBJECT public: ProfileEditorDialog(MetaFactory* fact, const Profile& prof ); ProfileEditorDialog(MetaFactory* fact ); ~ProfileEditorDialog(); Profile profile()const; public slots: void accept(); private slots: void slotConActivated(const QString& ); void slotTermActivated( const QString& ); private: void initUI(); QString profName()const; QCString profType()const; MetaFactory* m_fact; QHBoxLayout* m_lay; Profile m_prof; QLineEdit *m_name; QComboBox *m_conCmb, *m_termCmb; + QCheckBox *m_autoConnect; QWidget *m_tabCon, *m_tabTerm; ProfileDialogWidget* m_con, *m_term; QHBoxLayout *m_layCon, *m_layTerm; OTabWidget *tabWidget; }; #endif diff --git a/noncore/apps/opie-console/profilemanager.cpp b/noncore/apps/opie-console/profilemanager.cpp index 7c15560..5d39d96 100644 --- a/noncore/apps/opie-console/profilemanager.cpp +++ b/noncore/apps/opie-console/profilemanager.cpp @@ -1,135 +1,137 @@ #include <stdio.h> #include <stdlib.h> #include <qfile.h> #include <qhbox.h> #include <qlayout.h> #include <qwidgetstack.h> #include <qpe/config.h> #include "emulation_handler.h" #include "widget_layer.h" #include "emulation_widget.h" #include "metafactory.h" #include "profileconfig.h" #include "profilemanager.h" ProfileManager::ProfileManager( MetaFactory* fact ) : m_fact( fact ) { } ProfileManager::~ProfileManager() { } void ProfileManager::load() { m_list.clear(); ProfileConfig conf("opie-console-profiles"); QStringList groups = conf.groups(); QStringList::Iterator it; /* * for each profile */ for ( it = groups.begin(); it != groups.end(); ++it ) { conf.setGroup( (*it) ); Profile prof; prof.setName( conf.readEntry("name") ); prof.setIOLayer( conf.readEntry("iolayer").utf8() ); prof.setTerminalName( conf.readEntry("term").utf8() ); + prof.setAutoConnect( conf.readBoolEntry("autoConnect") ); prof.setBackground( conf.readNumEntry("back") ); prof.setForeground( conf.readNumEntry("fore") ); prof.setTerminal( conf.readNumEntry("terminal") ); // THIS is evil because all data get's reset prof.setConf( conf.items( (*it) ) ); /* now add it */ m_list.append( prof ); } } void ProfileManager::clear() { m_list.clear(); } Profile::ValueList ProfileManager::all()const { return m_list; } /* * Our goal is to create a Session * We will load the the IOLayer and EmulationLayer * from the factory * we will generate a QWidgetStack * add a dummy widget with layout * add "Widget" to the layout * add the dummy to the stack * raise the dummy * call session->connect(= * this way we only need to reparent * in TabWidget */ Session* ProfileManager::fromProfile( const Profile& prof, QWidget* parent) { /* TEST PROFILE!!! Profile prof; QString str = "/dev/ttyS0"; prof.writeEntry("Device",str ); prof.writeEntry("Baud", 115200 ); prof.setIOLayer("serial"); prof.setName( "test"); */ Session* session = new Session(); session->setName( prof.name() ); /* translate the internal name to the external */ session->setIOLayer(m_fact->newIOLayer( m_fact->external(prof.ioLayerName()) , prof) ); QWidgetStack *stack = new QWidgetStack( parent ); session->setWidgetStack( stack ); QWidget* dummy = new QHBox( stack ); stack->raiseWidget( dummy ); EmulationHandler* handler = new EmulationHandler(prof,dummy ); session->setEmulationHandler( handler ); session->connect(); return session; } void ProfileManager::save( ) { QFile::remove( (QString(getenv("HOME") )+ "/Settings/opie-console-profiles.conf" ) ); ProfileConfig conf("opie-console-profiles"); Profile::ValueList::Iterator it2; for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { conf.setGroup( (*it2).name() ); /* now the config stuff */ QMap<QString, QString> map = (*it2).conf(); QMap<QString, QString>::Iterator confIt; for ( confIt = map.begin(); confIt != map.end(); ++confIt ) { conf.writeEntry( confIt.key(), confIt.data() ); } conf.writeEntry( "name", (*it2).name() ); QString str = QString::fromUtf8( (*it2).ioLayerName() ); conf.writeEntry( "iolayer", str ); conf.writeEntry( "term", QString::fromUtf8( (*it2).terminalName() ) ); + conf.writeEntry( "autoConnect", (*it2).autoConnect()); conf.writeEntry( "back", (*it2).background() ); conf.writeEntry( "fore", (*it2).foreground() ); conf.writeEntry( "terminal", (*it2).terminal() ); } } void ProfileManager::setProfiles( const Profile::ValueList& list ) { m_list = list; }; Profile ProfileManager::profile( const QString& name )const { Profile prof; Profile::ValueList::ConstIterator it; for ( it = m_list.begin(); it != m_list.end(); ++it ) { if ( name == (*it).name() ) { prof = (*it); break; } } return prof; } |