summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/profileeditordialog.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/profileeditordialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/profileeditordialog.cpp239
1 files changed, 120 insertions, 119 deletions
diff --git a/noncore/apps/opie-console/profileeditordialog.cpp b/noncore/apps/opie-console/profileeditordialog.cpp
index 3843943..061b1c2 100644
--- a/noncore/apps/opie-console/profileeditordialog.cpp
+++ b/noncore/apps/opie-console/profileeditordialog.cpp
@@ -1,11 +1,10 @@
1#include <qlayout.h>
2#include <qlineedit.h>
3#include <qlabel.h>
4#include <qmessagebox.h>
5#include <qstringlist.h>
6#include <qcombobox.h>
1 7
2#include <opie/otabwidget.h>
3#include "profileeditordialog.h"
4 8
5#include "qlayout.h" 9#include <opie/otabwidget.h>
6#include "qlineedit.h"
7#include "qlabel.h"
8#include "qmessagebox.h"
9#include "qstringlist.h"
10#include "qcombobox.h"
11 10
@@ -13,2 +12,15 @@
13#include "metafactory.h" 12#include "metafactory.h"
13#include "profileeditordialog.h"
14
15namespace {
16 void setCurrent( const QString& str, QComboBox* bo ) {
17 for (uint i = 0; i < bo->count(); i++ ) {
18 if ( bo->text(i) == str ) {
19 bo->setCurrentItem( i );
20 }
21 }
22 }
23
24
25}
14 26
@@ -29,3 +41,3 @@ ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact )
29 // Default profile 41 // Default profile
30 m_prof = Profile(QString::null, "serial", Profile::Black, Profile::White, Profile::VT102); 42 m_prof = Profile("New Profile", "serial", "default", Profile::Black, Profile::White, Profile::VT102);
31 43
@@ -44,2 +56,3 @@ void ProfileEditorDialog::initUI()
44{ 56{
57 m_con = m_term = 0l;
45 58
@@ -49,86 +62,67 @@ void ProfileEditorDialog::initUI()
49 62
50 QWidget *tabterm, *tabconn, *tabprof; 63 QWidget *tabprof;
51 64
52 tabprof = new QWidget(this); 65 /* base tabs */
53 tabterm = new QWidget(this); 66 tabprof = new QWidget(this);
54 tabconn = new QWidget(this); 67 m_tabTerm = new QWidget(this);
55 68 m_tabCon = new QWidget(this);
56 // for the time being: fake factory 69
57 70 /* base layout for tabs */
58 m_fact->addConfigWidgetFactory("serial", QObject::tr("Serial cable"), factory_serial); 71 m_layCon = new QHBoxLayout( m_tabCon , 2 );
59 m_fact->addConfigWidgetFactory("irda", QObject::tr("IrDA port"), factory_irda); 72 m_layTerm = new QHBoxLayout( m_tabTerm, 2 );
60 m_fact->addConfigWidgetFactory("modem", QObject::tr("Serial via modem"), factory_modem); 73
61 74 // profile tab
62 // profile tab 75
63 76 QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof);
64 QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof); 77 m_name = new QLineEdit(tabprof);
65 78 QLabel *con = new QLabel(tr("Connection"), tabprof );
66 name_line = new QLineEdit(tabprof); 79 QLabel *term = new QLabel(tr("Terminal"), tabprof );
67 80 m_conCmb = new QComboBox( tabprof );
68 // connection tab, fixed part 81 m_termCmb = new QComboBox( tabprof );
69 82
70 QLabel *device = new QLabel(QObject::tr("Device"), tabconn); 83 // layouting
71 84 QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2);
72 device_box = new QComboBox(tabconn); 85 vbox3->add(name);
73 86 vbox3->add(m_name);
74 QStringList w = m_fact->configWidgets(); 87 vbox3->add(con );
75 for(QStringList::Iterator it = w.begin(); it != w.end(); it++) 88 vbox3->add(m_conCmb );
76 device_box->insertItem(m_fact->name((*it))); 89 vbox3->add(term );
77 90 vbox3->add(m_termCmb );
78 // connection tab, factory part 91 vbox3->addStretch(1);
79 plugin_base = new QWidget(tabconn); 92
80 plugin_layout = new QHBoxLayout(plugin_base, 0); 93 tabWidget->addTab(tabprof, "", QObject::tr("Profile"));
81 94 tabWidget->addTab(m_tabCon, "", QObject::tr("Connection"));
82 plugin_plugin = m_fact->newConfigPlugin("serial", plugin_base, &m_prof); 95 tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal"));
83 plugin_layout->add(plugin_plugin->widget()); 96 tabWidget->setCurrentTab( tabprof );
84 97
85 // connection tab, general part 98
99 // fill the comboboxes
100 QStringList list = m_fact->connectionWidgets();
101 QStringList::Iterator it;
102 for (it =list.begin(); it != list.end(); ++it ) {
103 m_conCmb->insertItem( (*it) );
104 }
105 list = m_fact->terminalWidgets();
106 for (it =list.begin(); it != list.end(); ++it ) {
107 m_termCmb->insertItem( (*it) );
108 }
109
110 // load profile values
111 m_name->setText(m_prof.name());
112 slotConActivated( m_fact->external(m_prof.ioLayerName() ) );
113 slotTermActivated( m_fact->external(m_prof.terminalName() ) );
114 setCurrent( m_fact->external(m_prof.ioLayerName() ), m_conCmb );
115 setCurrent( m_fact->external(m_prof.terminalName() ), m_termCmb );
116
117 qWarning("Layer: %s %s", m_prof.ioLayerName().data(),
118 m_fact->external(m_prof.ioLayerName() ).latin1() );
119 qWarning("Term: %s %s", m_prof.terminalName().data(),
120 m_fact->external(m_prof.terminalName() ).latin1() );
121
122 // signal and slots
123 connect(m_conCmb, SIGNAL(activated(const QString& ) ),
124 this, SLOT(slotConActivated(const QString&) ) );
125 connect(m_termCmb, SIGNAL(activated(const QString& ) ),
126 this, SLOT(slotTermActivated(const QString& ) ) );
86 127
87 QWidget *conn_widget = plugin_plugin->connection_widget();
88 conn_widget->reparent(tabconn, 0, QPoint(), true);
89
90 // terminal tab
91
92 QWidget *term_widget = plugin_plugin->terminal_widget();
93 term_widget->reparent(tabterm, 0, QPoint(), true);
94
95 // layouting
96
97 QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2);
98 vbox3->add(name);
99 vbox3->add(name_line);
100 vbox3->addStretch(1);
101
102 QVBoxLayout *vbox = new QVBoxLayout(tabconn, 2);
103 vbox->add(device);
104 vbox->add(device_box);
105 vbox->add(plugin_base);
106 vbox->add(conn_widget);
107 vbox->setStretchFactor(device, 1);
108 vbox->setStretchFactor(device_box, 1);
109 vbox->setStretchFactor(plugin_base, 1);
110 vbox->setStretchFactor(conn_widget, 7);
111
112 QVBoxLayout *vbox2 = new QVBoxLayout(tabterm, 2);
113 vbox2->add(term_widget);
114
115 tabWidget->addTab(tabprof, "", QObject::tr("Profile"));
116 tabWidget->addTab(tabconn, "", QObject::tr("Connection"));
117 tabWidget->addTab(tabterm, "", QObject::tr("Terminal"));
118 tabWidget->setCurrentTab( tabprof );
119
120 // load profile values
121 name_line->setText(m_prof.name());
122 for(int i = 0; i < device_box->count(); i++)
123 {
124 device_box->setCurrentItem(i);
125 if(prof_type() == m_prof.ioLayerName())
126 {
127 slotDevice(i);
128 break;
129 }
130 }
131
132 // signals
133 connect(device_box, SIGNAL(activated(int)), SLOT(slotDevice(int)));
134} 128}
@@ -138,21 +132,5 @@ ProfileEditorDialog::~ProfileEditorDialog() {
138} 132}
139
140void ProfileEditorDialog::slotDevice(int id)
141{
142 delete plugin_plugin;
143
144 plugin_plugin = m_fact->newConfigPlugin(prof_type(), plugin_base, &m_prof);
145 plugin_layout->add(plugin_plugin->widget());
146
147 // Reload profile associated to device, including e.g. conn_device()
148 // m_prof = plugin_plugin->profile()
149 // or, keeping the profile name: m_prof->reload(plugin_plugin->profile())
150
151 //plugin_plugin->show();
152 plugin_plugin->widget()->show();
153}
154
155void ProfileEditorDialog::accept() 133void ProfileEditorDialog::accept()
156{ 134{
157 if(prof_name().isEmpty()) 135 if(profName().isEmpty())
158 { 136 {
@@ -164,7 +142,10 @@ void ProfileEditorDialog::accept()
164 // Save profile and plugin profile 142 // Save profile and plugin profile
165 if(plugin_plugin) plugin_plugin->save(); 143 //if(plugin_plugin) plugin_plugin->save();
166 144
167 // Save general values 145 // Save general values
168 m_prof.setName(prof_name()); 146 m_prof.setName(profName());
169 m_prof.setIOLayer(prof_type()); 147 m_prof.setIOLayer( m_fact->internal(m_conCmb ->currentText() ) );
148 m_prof.setTerminalName( m_fact->internal(m_termCmb->currentText() ) );
149 qWarning("Term %s %s", m_fact->internal(m_termCmb->currentText() ).data(),
150 m_termCmb->currentText().latin1() );
170 151
@@ -174,16 +155,36 @@ void ProfileEditorDialog::accept()
174 155
175QString ProfileEditorDialog::prof_name() 156QString ProfileEditorDialog::profName()const
176{ 157{
177 return name_line->text(); 158 return m_name->text();
178} 159}
179 160
180QString ProfileEditorDialog::prof_type() 161QCString ProfileEditorDialog::profType()const
181{ 162{
182 QStringList w = m_fact->configWidgets(); 163 /*QStringList w = m_fact->configWidgets();
183 for(QStringList::Iterator it = w.begin(); it != w.end(); it++) 164 for(QStringList::Iterator it = w.begin(); it != w.end(); it++)
184 if(device_box->currentText() == m_fact->name((*it))) return (*it); 165 if(device_box->currentText() == m_fact->name((*it))) return (*it);
185 166 */
186 return QString::null; 167 return QCString();
168}
169/*
170 * we need to switch the widget
171 */
172void ProfileEditorDialog::slotConActivated( const QString& str ) {
173 delete m_con;
174 m_con = m_fact->newConnectionPlugin( str, m_tabCon );
175
176 if (m_con )
177 m_layCon->addWidget( m_con );
178}
179/*
180 * we need to switch the widget
181 */
182void ProfileEditorDialog::slotTermActivated( const QString& str ) {
183 delete m_term;
184 m_term = m_fact->newTerminalPlugin( str, 0l );
185 qWarning("past");
186
187 if (m_term)
188 m_layTerm->addWidget( m_term );
187} 189}
188
189 190