Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

profileeditordialog.cpp

Go to the documentation of this file.
00001 #include "profileeditordialog.h"
00002 #include "metafactory.h"
00003 #include "comboboxhelper.h"
00004 
00005 
00006 #include <qlayout.h>
00007 #include <qlineedit.h>
00008 #include <qlabel.h>
00009 #include <qmessagebox.h>
00010 #include <qcombobox.h>
00011 #include <qcheckbox.h>
00012 #include <qscrollview.h>
00013 
00014 
00015 
00016 using namespace Opie::Ui;
00017 
00018 
00019 ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact,
00020                                           const Profile& prof )
00021     : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof )
00022 {
00023     initUI();
00024 
00025         // Apply current profile
00026         // plugin_plugin->load(profile);
00027         // ... (reset profile name line edit etc.)
00028 }
00029 
00030 ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact )
00031     : QDialog(0, 0, TRUE), m_fact( fact )
00032 {
00033     // Default profile
00034     m_prof = Profile(tr("New Profile"), "serial", "default", Profile::Black, Profile::White, Profile::VT102);
00035 
00036     initUI();
00037 
00038     // Apply current profile
00039     // plugin_plugin->load(profile);
00040 }
00041 
00042 Profile ProfileEditorDialog::profile() const
00043 {
00044         return m_prof;
00045 }
00046 
00047 void ProfileEditorDialog::initUI()
00048 {
00049     m_con = m_term = m_key = 0l;
00050 
00051 
00052     QVBoxLayout *mainLayout = new QVBoxLayout( this );
00053     tabWidget = new OTabWidget( this );
00054     tabWidget->setTabStyle(OTabWidget::TextTab);
00055     mainLayout->add(tabWidget);
00056 
00057     /* base tabs */
00058     tabprof   = new QWidget(this);
00059     m_tabTerm = new QWidget(this);
00060     m_tabCon  = new QWidget(this);
00061     m_tabKey  = new QWidget(this);
00062 
00063     m_svCon = new QScrollView( m_tabCon );
00064     m_svCon->setResizePolicy( QScrollView::AutoOneFit );
00065     //m_svCon->setHScrollBarMode( QScrollView::AlwaysOff );
00066     m_svCon->setFrameShape( QFrame::NoFrame );
00067     m_svTerm = new QScrollView( m_tabTerm );
00068     m_svTerm->setResizePolicy( QScrollView::AutoOneFit );
00069     //m_svTerm->setHScrollBarMode( QScrollView::AlwaysOff );
00070     m_svTerm->setFrameShape( QFrame::NoFrame );
00071 
00072     /* base layout for tabs */
00073     m_layCon  = new QHBoxLayout( m_tabCon , 2 );
00074     m_layTerm = new QHBoxLayout( m_tabTerm, 2 );
00075     m_layKey = new QHBoxLayout( m_tabKey, 2 );
00076 
00077     m_layCon->addWidget( m_svCon );
00078     m_layTerm->addWidget( m_svTerm );
00079 
00080     // profile tab
00081 
00082     QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof);
00083     m_name = new QLineEdit(tabprof);
00084     QLabel *con = new QLabel(tr("Connection"), tabprof );
00085     QLabel *term = new QLabel(tr("Terminal"), tabprof );
00086     m_conCmb = new QComboBox( tabprof );
00087     m_termCmb = new QComboBox( tabprof );
00088     m_autoConnect = new QCheckBox(tr("Auto connect after load"), tabprof);
00089 
00090     // layouting
00091     QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2);
00092     vbox3->add(name);
00093     vbox3->add(m_name);
00094     vbox3->add(con );
00095     vbox3->add(m_conCmb );
00096     vbox3->add(term );
00097     vbox3->add(m_termCmb );
00098     vbox3->add(m_autoConnect);
00099     vbox3->addStretch(1);
00100 
00101     m_showconntab = 0;
00102     tabWidget->addTab(tabprof, "", QObject::tr("Profile"));
00103     tabWidget->addTab(m_tabCon, "", QObject::tr("Connection"));
00104     tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal"));
00105     tabWidget->addTab(m_tabKey, "", QObject::tr("Special Keys"));
00106     tabWidget->setCurrentTab( tabprof );
00107 
00108 
00109     // fill the comboboxes
00110     QStringList list = m_fact->connectionWidgets();
00111     QStringList::Iterator it;
00112     for (it =list.begin(); it != list.end(); ++it ) {
00113         m_conCmb->insertItem( (*it) );
00114     }
00115     list = m_fact->terminalWidgets();
00116     for (it =list.begin(); it != list.end(); ++it ) {
00117         m_termCmb->insertItem( (*it) );
00118     }
00119 
00120     // load profile values
00121     m_name->setText(m_prof.name());
00122     slotKeyActivated( "Default Keyboard" );
00123     ComboboxHelper::setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb );
00124     ComboboxHelper::setCurrent( m_fact->external(m_prof.terminalName() ), m_termCmb );
00125     slotConActivated(  m_fact->external(m_prof.ioLayerName()  ) );
00126     slotTermActivated( m_fact->external(m_prof.terminalName() ) );
00127     m_autoConnect->setChecked(m_prof.autoConnect());
00128 
00129 
00130     // signal and slots
00131     connect(m_conCmb, SIGNAL(activated(const QString&) ),
00132             this, SLOT(slotConActivated(const QString&) ) );
00133     connect(m_termCmb, SIGNAL(activated(const QString&) ),
00134             this, SLOT(slotTermActivated(const QString&) ) );
00135 
00136 }
00137 
00138 ProfileEditorDialog::~ProfileEditorDialog() {
00139 
00140 }
00141 void ProfileEditorDialog::accept()
00142 {
00143         if(profName().isEmpty())
00144         {
00145                 QMessageBox::information(this,
00146                         QObject::tr("Invalid profile"),
00147                         QObject::tr("Please enter a profile name."));
00148                 return;
00149         }
00150         // Save profile and plugin profile
00151         //if(plugin_plugin) plugin_plugin->save();
00152 
00153         // Save general values
00154         m_prof.setName( profName() );
00155         m_prof.setIOLayer( m_fact->internal(m_conCmb ->currentText()  ) );
00156         m_prof.setTerminalName( m_fact->internal(m_termCmb->currentText()  ) );
00157         m_prof.setAutoConnect( m_autoConnect->isChecked() );
00158 
00159         if (m_con )
00160             m_con->save( m_prof );
00161         if (m_term )
00162             m_term->save( m_prof );
00163         if (m_key)
00164             m_key->save( m_prof );
00165 
00166         QDialog::accept();
00167 }
00168 
00169 
00170 QString ProfileEditorDialog::profName()const
00171 {
00172         return m_name->text();
00173 }
00174 
00175 QCString ProfileEditorDialog::profType()const
00176 {
00177     /*QStringList w = m_fact->configWidgets();
00178         for(QStringList::Iterator it = w.begin(); it != w.end(); it++)
00179                 if(device_box->currentText() == m_fact->name((*it))) return (*it);
00180     */
00181     return QCString();
00182 }
00183 /*
00184  * we need to switch the widget
00185  */
00186 void ProfileEditorDialog::slotConActivated( const QString& str ) {
00187 
00188     delete m_con;
00189 
00190     m_con = m_fact->newConnectionPlugin( str, m_svCon->viewport() );
00191 
00192     if ( !m_con ) {
00193         m_con = new NoOptions( str, m_svCon->viewport(), "name");
00194     }
00195 
00196     // FIXME ugly hack right. Right solution would be to look into the layer and see if it
00197     // supports auto connect and then set it as prefered
00198     if ( m_conCmb ->currentText() == tr("Local Console") ) {
00199         m_autoConnect->setChecked( true );
00200         m_prof.writeEntry("Terminal", Profile::Linux );
00201         slotTermActivated( m_fact->external (m_prof.terminalName() ) );
00202     } else {
00203         m_prof.writeEntry("Terminal", Profile::VT102 );
00204         slotTermActivated( m_fact->external (m_prof.terminalName() ) );
00205         m_autoConnect->setChecked( false );
00206     }
00207 
00208     m_con->load( m_prof );
00209     m_svCon->addChild( m_con );
00210 }
00211 
00212 
00213 /*
00214  * we need to switch the widget
00215  */
00216 void ProfileEditorDialog::slotTermActivated( const QString& str ) {
00217 
00218     delete m_term;
00219 
00220     m_term = m_fact->newTerminalPlugin( str, m_svTerm->viewport() );
00221 
00222     if ( m_term ) {
00223         m_term->load( m_prof );
00224         m_svTerm->addChild( m_term );
00225     }
00226 }
00227 
00228 void ProfileEditorDialog::slotKeyActivated(const QString &str) {
00229     delete m_key;
00230     m_key = m_fact->newKeyboardPlugin( str, m_tabKey );
00231 
00232     if (m_key) {
00233 
00234         m_key->load(m_prof);
00235         m_layKey->addWidget(m_key);
00236     }
00237 
00238 }

Generated on Sat Nov 5 16:16:50 2005 for OPIE by  doxygen 1.4.2