summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/profileeditordialog.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/profileeditordialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/profileeditordialog.cpp203
1 files changed, 102 insertions, 101 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,19 +1,31 @@
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
12#include "profileeditorplugins.h" 11#include "profileeditorplugins.h"
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
15ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact, 27ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact,
16 const Profile& prof ) 28 const Profile& prof )
17 : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof ) 29 : QDialog(0, 0, TRUE), m_fact( fact ), m_prof( prof )
18{ 30{
19 initUI(); 31 initUI();
@@ -24,13 +36,13 @@ ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact,
24} 36}
25 37
26ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact ) 38ProfileEditorDialog::ProfileEditorDialog( MetaFactory* fact )
27 : QDialog(0, 0, TRUE), m_fact( fact ) 39 : QDialog(0, 0, TRUE), m_fact( fact )
28{ 40{
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
32 initUI(); 44 initUI();
33 45
34 // Apply current profile 46 // Apply current profile
35 // plugin_plugin->load(profile); 47 // plugin_plugin->load(profile);
36} 48}
@@ -39,151 +51,140 @@ Profile ProfileEditorDialog::profile() const
39{ 51{
40 return m_prof; 52 return m_prof;
41} 53}
42 54
43void ProfileEditorDialog::initUI() 55void ProfileEditorDialog::initUI()
44{ 56{
57 m_con = m_term = 0l;
45 58
46 QVBoxLayout *mainLayout = new QVBoxLayout( this ); 59 QVBoxLayout *mainLayout = new QVBoxLayout( this );
47 OTabWidget *tabWidget = new OTabWidget( this ); 60 OTabWidget *tabWidget = new OTabWidget( this );
48 mainLayout->add(tabWidget); 61 mainLayout->add(tabWidget);
49 62
50 QWidget *tabterm, *tabconn, *tabprof; 63 QWidget *tabprof;
51 64
65 /* base tabs */
52 tabprof = new QWidget(this); 66 tabprof = new QWidget(this);
53 tabterm = new QWidget(this); 67 m_tabTerm = new QWidget(this);
54 tabconn = new QWidget(this); 68 m_tabCon = new QWidget(this);
55 69
56 // for the time being: fake factory 70 /* base layout for tabs */
57 71 m_layCon = new QHBoxLayout( m_tabCon , 2 );
58 m_fact->addConfigWidgetFactory("serial", QObject::tr("Serial cable"), factory_serial); 72 m_layTerm = new QHBoxLayout( m_tabTerm, 2 );
59 m_fact->addConfigWidgetFactory("irda", QObject::tr("IrDA port"), factory_irda);
60 m_fact->addConfigWidgetFactory("modem", QObject::tr("Serial via modem"), factory_modem);
61 73
62 // profile tab 74 // profile tab
63 75
64 QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof); 76 QLabel *name = new QLabel(QObject::tr("Profile name"), tabprof);
65 77 m_name = new QLineEdit(tabprof);
66 name_line = new QLineEdit(tabprof); 78 QLabel *con = new QLabel(tr("Connection"), tabprof );
67 79 QLabel *term = new QLabel(tr("Terminal"), tabprof );
68 // connection tab, fixed part 80 m_conCmb = new QComboBox( tabprof );
69 81 m_termCmb = new QComboBox( tabprof );
70 QLabel *device = new QLabel(QObject::tr("Device"), tabconn);
71
72 device_box = new QComboBox(tabconn);
73
74 QStringList w = m_fact->configWidgets();
75 for(QStringList::Iterator it = w.begin(); it != w.end(); it++)
76 device_box->insertItem(m_fact->name((*it)));
77
78 // connection tab, factory part
79 plugin_base = new QWidget(tabconn);
80 plugin_layout = new QHBoxLayout(plugin_base, 0);
81
82 plugin_plugin = m_fact->newConfigPlugin("serial", plugin_base, &m_prof);
83 plugin_layout->add(plugin_plugin->widget());
84
85 // connection tab, general part
86
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 82
95 // layouting 83 // layouting
96
97 QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2); 84 QVBoxLayout *vbox3 = new QVBoxLayout(tabprof, 2);
98 vbox3->add(name); 85 vbox3->add(name);
99 vbox3->add(name_line); 86 vbox3->add(m_name);
87 vbox3->add(con );
88 vbox3->add(m_conCmb );
89 vbox3->add(term );
90 vbox3->add(m_termCmb );
100 vbox3->addStretch(1); 91 vbox3->addStretch(1);
101 92
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")); 93 tabWidget->addTab(tabprof, "", QObject::tr("Profile"));
116 tabWidget->addTab(tabconn, "", QObject::tr("Connection")); 94 tabWidget->addTab(m_tabCon, "", QObject::tr("Connection"));
117 tabWidget->addTab(tabterm, "", QObject::tr("Terminal")); 95 tabWidget->addTab(m_tabTerm, "", QObject::tr("Terminal"));
118 tabWidget->setCurrentTab( tabprof ); 96 tabWidget->setCurrentTab( tabprof );
119 97
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 98
132 // signals 99 // fill the comboboxes
133 connect(device_box, SIGNAL(activated(int)), SLOT(slotDevice(int))); 100 QStringList list = m_fact->connectionWidgets();
101 QStringList::Iterator it;
102 for (it =list.begin(); it != list.end(); ++it ) {
103 m_conCmb->insertItem( (*it) );
134} 104}
135 105 list = m_fact->terminalWidgets();
136ProfileEditorDialog::~ProfileEditorDialog() { 106 for (it =list.begin(); it != list.end(); ++it ) {
137 107 m_termCmb->insertItem( (*it) );
138} 108}
139 109
140void ProfileEditorDialog::slotDevice(int id) 110 // load profile values
141{ 111 m_name->setText(m_prof.name());
142 delete plugin_plugin; 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& ) ) );
143 127
144 plugin_plugin = m_fact->newConfigPlugin(prof_type(), plugin_base, &m_prof); 128}
145 plugin_layout->add(plugin_plugin->widget());
146 129
147 // Reload profile associated to device, including e.g. conn_device() 130ProfileEditorDialog::~ProfileEditorDialog() {
148 // m_prof = plugin_plugin->profile()
149 // or, keeping the profile name: m_prof->reload(plugin_plugin->profile())
150 131
151 //plugin_plugin->show();
152 plugin_plugin->widget()->show();
153} 132}
154
155void ProfileEditorDialog::accept() 133void ProfileEditorDialog::accept()
156{ 134{
157 if(prof_name().isEmpty()) 135 if(profName().isEmpty())
158 { 136 {
159 QMessageBox::information(this, 137 QMessageBox::information(this,
160 QObject::tr("Invalid profile"), 138 QObject::tr("Invalid profile"),
161 QObject::tr("Please enter a profile name.")); 139 QObject::tr("Please enter a profile name."));
162 return; 140 return;
163 } 141 }
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
171 QDialog::accept(); 152 QDialog::accept();
172} 153}
173 154
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