summaryrefslogtreecommitdiff
authorhash <hash>2002-10-24 17:39:47 (UTC)
committer hash <hash>2002-10-24 17:39:47 (UTC)
commitb01703c4b1de7006c88aa814ca00472b966b2464 (patch) (unidiff)
tree9d0f4e708646ddbf1a0198f1ac2dd4b67e2c45fa
parent1364899f2b250d1605e1a49cb7c65ce950c57fda (diff)
downloadopie-b01703c4b1de7006c88aa814ca00472b966b2464.zip
opie-b01703c4b1de7006c88aa814ca00472b966b2464.tar.gz
opie-b01703c4b1de7006c88aa814ca00472b966b2464.tar.bz2
i think it loads according to the session properly now
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp43
-rw-r--r--noncore/apps/opie-console/function_keyboard.h7
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp6
3 files changed, 48 insertions, 8 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
index 3da8d61..ce65052 100644
--- a/noncore/apps/opie-console/function_keyboard.cpp
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -1,388 +1,425 @@
1#include "function_keyboard.h" 1#include "function_keyboard.h"
2 2
3#include <qpe/resource.h> 3#include <qpe/resource.h>
4#include <qpe/qpeapplication.h> 4#include <qpe/qpeapplication.h>
5#include <qsizepolicy.h> 5#include <qsizepolicy.h>
6#include <qevent.h> 6#include <qevent.h>
7#include <qwindowsystem_qws.h> 7#include <qwindowsystem_qws.h>
8#include <qapplication.h> 8#include <qapplication.h>
9#include <qlayout.h> 9#include <qlayout.h>
10#include <qspinbox.h> 10#include <qspinbox.h>
11#include <qlistbox.h> 11#include <qlistbox.h>
12#include <qlabel.h> 12#include <qlabel.h>
13#include <qcombobox.h> 13#include <qcombobox.h>
14#include <qdir.h> 14#include <qdir.h>
15 15
16/* FunctionKeyboard {{{1 */ 16/* FunctionKeyboard {{{1 */
17 17
18FunctionKeyboard::FunctionKeyboard(QWidget *parent) : 18FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
19 QFrame(parent), numRows(2), numCols(11), 19 QFrame(parent), numRows(2), numCols(11),
20 pressedRow(0), pressedCol(0) { 20 pressedRow(0), pressedCol(0) {
21 21
22 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); 22 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
23 23
24 /* 24 /*
25 * all the saving/loading is now done in a profile. downside is that you cant modify 25 * all the saving/loading is now done in a profile. downside is that you cant modify
26 * the keyboard for all profiles, but must do it on a profile-basis 26 * the keyboard for all profiles, but must do it on a profile-basis
27 * 27 *
28 28
29 Config conf("opie-console-keys"); 29 Config conf("opie-console-keys");
30 conf.setGroup("keys"); 30 conf.setGroup("keys");
31 for (uint r = 0; r < numRows; r++) 31 for (uint r = 0; r < numRows; r++)
32 for (uint c = 0; c < numCols; c++) { 32 for (uint c = 0; c < numCols; c++) {
33 33
34 QString handle = "r" + QString::number(r) + "c" + QString::number(c); 34 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
35 QStringList value_list = conf.readListEntry( handle, '|'); 35 QStringList value_list = conf.readListEntry( handle, '|');
36 36
37 if (value_list.isEmpty()) continue; 37 if (value_list.isEmpty()) continue;
38 38
39 keys.insert( 39 keys.insert(
40 40
41 handle, 41 handle,
42 FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort()) 42 FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort())
43 ); 43 );
44 } 44 }
45 //qWarning("loaded %d keys", keys.count()); 45 //qWarning("loaded %d keys", keys.count());
46 */ 46 */
47 if (keys.isEmpty()) loadDefaults(); 47 if (keys.isEmpty()) loadDefaults();
48 48
49 49
50 50
51} 51}
52 52
53FunctionKeyboard::~FunctionKeyboard() {} 53FunctionKeyboard::~FunctionKeyboard() {}
54 54
55void FunctionKeyboard::changeRows(int r) { 55void FunctionKeyboard::changeRows(int r) {
56 56
57 numRows = r; 57 numRows = r;
58 repaint(false); 58
59 // have to do this so the whole thing gets redrawn
60 hide(); show();
59} 61}
60void FunctionKeyboard::changeCols(int c) { 62void FunctionKeyboard::changeCols(int c) {
61 63
62 numCols = c; 64 numCols = c;
63 keyWidth = (double)width()/numCols; // have to reset this thing too 65 keyWidth = (double)width()/numCols; // have to reset this thing too
64 repaint(false); 66 repaint(false);
65} 67}
68void FunctionKeyboard::load (const Profile& prof) {
69
70 keys.clear();
71
72 numRows = prof.readNumEntry("keb_rows", 2);
73 numCols = prof.readNumEntry("keb_cols", 10);
74 keyWidth = (double)width()/numCols; // have to reset this thing too
75
76 /* load all the keys to the keyboard */
77 for (ushort i = 0; i <= numRows - 1; i++)
78 for (ushort j = 0; j <= numCols - 1; j++) {
79
80 QString h = "r" + QString::number(i) + "c" + QString::number(j);
81 QString values = prof.readEntry("keb_" + h);
82
83 if (!values.isEmpty()) {
84
85 QStringList l = QStringList::split(QChar('|'), values, TRUE);
86 keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt());
87
88 // load pixmap if used
89 if (!l[1].isEmpty()) {
90
91 keys[h].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + l[1] ) );
92 }
93 }
94 }
95
96 if (keys.isEmpty()) loadDefaults();
97
98 hide();
99 show();
100
101}
66 102
67void FunctionKeyboard::paintEvent(QPaintEvent *e) { 103void FunctionKeyboard::paintEvent(QPaintEvent *e) {
68 104
69 QPainter p(this); 105 QPainter p(this);
70 p.setClipRect(e->rect()); 106 p.setClipRect(e->rect());
71 p.fillRect(0, 0, width(), height(), QColor(255,255,255)); 107 p.fillRect(0, 0, width(), height(), QColor(255,255,255));
72 108
73 p.setPen(QColor(0,0,0)); 109 p.setPen(QColor(0,0,0));
74 110
75 /* those decimals do count! becomes short if use plain int */ 111 /* those decimals do count! becomes short if use plain int */
76 for (double i = 0; i <= width(); i += keyWidth) { 112 for (double i = 0; i <= width(); i += keyWidth) {
77 113
78 p.drawLine((int)i, 0, (int)i, height()); 114 p.drawLine((int)i, 0, (int)i, height());
79 } 115 }
80 116
81 // sometimes the last line doesnt get drawn 117 // sometimes the last line doesnt get drawn
82 p.drawLine(width() -1, 0, width() -1, height()); 118 p.drawLine(width() -1, 0, width() -1, height());
83 119
84 for (int i = 0; i <= height(); i += keyHeight) { 120 for (int i = 0; i <= height(); i += keyHeight) {
85 121
86 p.drawLine(0, i, width(), i); 122 p.drawLine(0, i, width(), i);
87 } 123 }
88 124
89 for (uint r = 0; r < numRows; r++) { 125 for (uint r = 0; r < numRows; r++) {
90 for (uint c = 0; c < numCols; c++) { 126 for (uint c = 0; c < numCols; c++) {
91 127
92 QString handle = "r" + QString::number(r) + "c" + QString::number(c); 128 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
93 if (keys.contains(handle)) { 129 if (keys.contains(handle)) {
94 130
95 if (keys[handle].pixFile.isEmpty()) 131 if (keys[handle].pixFile.isEmpty())
96 p.drawText( c * keyWidth + 1, r * keyHeight + 1, 132 p.drawText( c * keyWidth + 1, r * keyHeight + 1,
97 keyWidth, keyHeight, 133 keyWidth, keyHeight,
98 Qt::AlignHCenter | Qt::AlignVCenter, 134 Qt::AlignHCenter | Qt::AlignVCenter,
99 keys[handle].label 135 keys[handle].label
100 ); 136 );
101 else { 137 else {
102 138
103 ushort centerX = (ushort)(c *keyWidth) + (ushort)(keyWidth - keys[handle].pix->width()) / 2; 139 ushort centerX = (ushort)(c *keyWidth) + (ushort)(keyWidth - keys[handle].pix->width()) / 2;
104 ushort centerY = r * keyHeight + (keyHeight - keys[handle].pix->height()) / 2; 140 ushort centerY = r * keyHeight + (keyHeight - keys[handle].pix->height()) / 2;
105 p.drawPixmap(centerX, centerY, *keys[handle].pix); 141 p.drawPixmap(centerX, centerY, *keys[handle].pix);
106 } 142 }
107 } 143 }
108 } 144 }
109 } 145 }
110} 146}
111 147
112void FunctionKeyboard::paintKey(uint row, uint col) { 148void FunctionKeyboard::paintKey(uint row, uint col) {
113 149
114 QPainter p(this); 150 QPainter p(this);
115 151
116 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), 152 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1),
117 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), 153 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)),
118 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); 154 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255));
119 155
120 QString handle ("r" + QString::number(row) + "c" + QString::number(col)); 156 QString handle ("r" + QString::number(row) + "c" + QString::number(col));
121 if (keys[handle].pixFile.isEmpty()) 157 if (keys[handle].pixFile.isEmpty())
122 p.drawText( 158 p.drawText(
123 col * keyWidth + 1, row * keyHeight + 1, 159 col * keyWidth + 1, row * keyHeight + 1,
124 keyWidth, keyHeight, 160 keyWidth, keyHeight,
125 Qt::AlignHCenter | Qt::AlignVCenter, 161 Qt::AlignHCenter | Qt::AlignVCenter,
126 keys[handle].label 162 keys[handle].label
127 ); 163 );
128 else { 164 else {
129 165
130 ushort centerX = (ushort)(col *keyWidth) + (ushort)(keyWidth - keys[handle].pix->width()) / 2; 166 ushort centerX = (ushort)(col *keyWidth) + (ushort)(keyWidth - keys[handle].pix->width()) / 2;
131 ushort centerY = row * keyHeight + (keyHeight - keys[handle].pix->height()) / 2; 167 ushort centerY = row * keyHeight + (keyHeight - keys[handle].pix->height()) / 2;
132 p.drawPixmap(centerX, centerY, *keys[handle].pix); 168 p.drawPixmap(centerX, centerY, *keys[handle].pix);
133 } 169 }
134 170
135 if (col == numCols - 1) { 171 if (col == numCols - 1) {
136 172
137 // sometimes it doesnt draw the last line 173 // sometimes it doesnt draw the last line
138 174
139 p.drawLine((col+1) * keyWidth -1, row * keyHeight, 175 p.drawLine((col+1) * keyWidth -1, row * keyHeight,
140 (col+1) * keyWidth -1, (row + 1) * keyHeight 176 (col+1) * keyWidth -1, (row + 1) * keyHeight
141 ); 177 );
142 } 178 }
143 179
144} 180}
145 181
146void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { 182void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
147 183
148 pressedRow = e->y() / keyHeight; 184 pressedRow = e->y() / keyHeight;
149 pressedCol = (int) (e->x() / keyWidth); 185 pressedCol = (int) (e->x() / keyWidth);
150 186
151 paintKey(pressedRow, pressedCol); 187 paintKey(pressedRow, pressedCol);
152 188
153 // emit that sucker! 189 // emit that sucker!
154 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; 190 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)];
155 emit keyPressed(k, pressedRow, pressedCol, 1); 191 emit keyPressed(k, pressedRow, pressedCol, 1);
156 192
157} 193}
158 194
159void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { 195void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
160 196
161 if (pressedRow != -1 && pressedRow != -1) { 197 if (pressedRow != -1 && pressedRow != -1) {
162 198
163 int row = pressedRow; pressedRow = -1; 199 int row = pressedRow; pressedRow = -1;
164 int col = pressedCol; pressedCol = -1; 200 int col = pressedCol; pressedCol = -1;
165 paintKey(row, col); 201 paintKey(row, col);
166 202
167 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; 203 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)];
168 emit keyPressed(k, row, col, 0); 204 emit keyPressed(k, row, col, 0);
169 } 205 }
170 206
171} 207}
172 208
173 209
174void FunctionKeyboard::resizeEvent(QResizeEvent*) { 210void FunctionKeyboard::resizeEvent(QResizeEvent*) {
175 211
176 /* set he default font height/width */ 212 /* set he default font height/width */
177 QFontMetrics fm=fontMetrics(); 213 QFontMetrics fm=fontMetrics();
178 keyHeight = fm.lineSpacing() + 2; 214 keyHeight = fm.lineSpacing() + 2;
179 keyWidth = (double)width()/numCols; 215 keyWidth = (double)width()/numCols;
180 216
181} 217}
182 218
183QSize FunctionKeyboard::sizeHint() const { 219QSize FunctionKeyboard::sizeHint() const {
184 220
185 return QSize(width(), keyHeight * numRows + 1); 221 return QSize(width(), keyHeight * numRows + 1);
186} 222}
187 223
188void FunctionKeyboard::loadDefaults() { 224void FunctionKeyboard::loadDefaults() {
189 225
190 keys.insert( "r0c0", FKey ("Enter", "enter", Qt::Key_Enter, 0)); 226 keys.insert( "r0c0", FKey ("Enter", "enter", Qt::Key_Enter, 0));
191 keys.insert( "r0c1", FKey ("Space", "space", Qt::Key_Space, Qt::Key_Space)); 227 keys.insert( "r0c1", FKey ("Space", "space", Qt::Key_Space, Qt::Key_Space));
192 keys.insert( "r0c2", FKey ("Tab", "tab", Qt::Key_Tab, 0)); 228 keys.insert( "r0c2", FKey ("Tab", "tab", Qt::Key_Tab, 0));
193 keys.insert( "r0c3", FKey ("Up", "up", Qt::Key_Up, 0)); 229 keys.insert( "r0c3", FKey ("Up", "up", Qt::Key_Up, 0));
194 keys.insert( "r0c4", FKey ("Down", "down", Qt::Key_Down, 0)); 230 keys.insert( "r0c4", FKey ("Down", "down", Qt::Key_Down, 0));
195 231
196 keys.insert( "r0c7", FKey ("Ho", 0, 4112, 0)); 232 keys.insert( "r0c7", FKey ("Ho", 0, 4112, 0));
197 keys.insert( "r0c8", FKey ("End", 0, 4113, 0)); 233 keys.insert( "r0c8", FKey ("End", 0, 4113, 0));
198 keys.insert( "r0c9", FKey ("PU", 0, 4118, 0)); 234 keys.insert( "r0c9", FKey ("PU", 0, 4118, 0));
199 keys.insert( "r0c10", FKey ("PD", 0, 4119, 0)); 235 keys.insert( "r0c10", FKey ("PD", 0, 4119, 0));
200 236
201 keys.insert( "r1c0", FKey ("F1", 0, 4144, 0)); 237 keys.insert( "r1c0", FKey ("F1", 0, 4144, 0));
202 keys.insert( "r1c1", FKey ("F2", 0, 4145, 0)); 238 keys.insert( "r1c1", FKey ("F2", 0, 4145, 0));
203 keys.insert( "r1c2", FKey ("F3", 0, 4146, 0)); 239 keys.insert( "r1c2", FKey ("F3", 0, 4146, 0));
204 keys.insert( "r1c3", FKey ("F4", 0, 4147, 0)); 240 keys.insert( "r1c3", FKey ("F4", 0, 4147, 0));
205 keys.insert( "r1c4", FKey ("F5", 0, 4148, 0)); 241 keys.insert( "r1c4", FKey ("F5", 0, 4148, 0));
206 keys.insert( "r1c5", FKey ("F6", 0, 4149, 0)); 242 keys.insert( "r1c5", FKey ("F6", 0, 4149, 0));
207 keys.insert( "r1c6", FKey ("F7", 0, 4150, 0)); 243 keys.insert( "r1c6", FKey ("F7", 0, 4150, 0));
208 keys.insert( "r1c7", FKey ("F8", 0, 4151, 0)); 244 keys.insert( "r1c7", FKey ("F8", 0, 4151, 0));
209 keys.insert( "r1c8", FKey ("F9", 0, 4152, 0)); 245 keys.insert( "r1c8", FKey ("F9", 0, 4152, 0));
210 keys.insert( "r1c9", FKey ("F10", 0, 4153, 0)); 246 keys.insert( "r1c9", FKey ("F10", 0, 4153, 0));
211 keys.insert( "r1c10", FKey ("F11", 0, 4154, 0)); 247 keys.insert( "r1c10", FKey ("F11", 0, 4154, 0));
212 248
213 249
214} 250}
215 251
216/* FunctionKeyboardConfig {{{1 */ 252/* FunctionKeyboardConfig {{{1 */
217 253
218FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na ) 254FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na )
219 : ProfileDialogKeyWidget(name, parent, na), 255 : ProfileDialogKeyWidget(name, parent, na),
220 selectedRow(0), selectedCol(0) 256 selectedRow(0), selectedCol(0)
221{ 257{
222 qWarning("FunctionKeyboardConfig"); 258 qWarning("FunctionKeyboardConfig");
223 259
224 260
225 kb = new FunctionKeyboard(this); 261 kb = new FunctionKeyboard(this);
226 connect (kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), 262 connect (kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)),
227 this, SLOT(slotKeyPressed(FKey, ushort, ushort, bool))); 263 this, SLOT(slotKeyPressed(FKey, ushort, ushort, bool)));
228 264
229 QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimentions"), this); 265 QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimentions"), this);
230 QLabel *l = new QLabel("Rows", dimentions); 266 QLabel *l = new QLabel("Rows", dimentions);
231 m_rowBox = new QSpinBox(1, 15, 1, dimentions); 267 m_rowBox = new QSpinBox(1, 15, 1, dimentions);
232 connect (m_rowBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeRows(int))); 268 connect (m_rowBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeRows(int)));
233 l = new QLabel("Columns", dimentions); 269 l = new QLabel("Columns", dimentions);
234 m_colBox = new QSpinBox(1, 15, 1, dimentions); 270 m_colBox = new QSpinBox(1, 15, 1, dimentions);
235 connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int))); 271 connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int)));
236 272
237 QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this); 273 QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this);
238 l = new QLabel("Label", editKey); 274 l = new QLabel("Label", editKey);
239 m_labels = new QComboBox(true, editKey); 275 m_labels = new QComboBox(true, editKey);
240 m_labels->setInsertionPolicy(QComboBox::AtCurrent); 276 m_labels->setInsertionPolicy(QComboBox::AtCurrent);
241 m_labels->insertItem(""); 277 m_labels->insertItem("");
242 278
243 QStringList files = QDir( QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList(); 279 QStringList files = QDir( QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList();
244 280
245 for (uint i = 0; i < files.count(); i++) { 281 for (uint i = 0; i < files.count(); i++) {
246 282
247 m_labels->insertItem( Resource::loadPixmap("console/keys/" + files[i]), files[i]); 283 m_labels->insertItem( Resource::loadPixmap("console/keys/" + files[i]), files[i]);
248 } 284 }
249 connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int))); 285 connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int)));
250 connect (m_labels, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeLabelText(const QString&))); 286 connect (m_labels, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeLabelText(const QString&)));
251 287
252 l = new QLabel("Q Keycode", editKey); 288 l = new QLabel("Q Keycode", editKey);
253 m_qvalues = new QComboBox(true, editKey); 289 m_qvalues = new QComboBox(true, editKey);
254 m_qvalues->setInsertionPolicy(QComboBox::AtTop); 290 m_qvalues->setInsertionPolicy(QComboBox::AtTop);
255 m_qvalues->setDuplicatesEnabled(false); 291 m_qvalues->setDuplicatesEnabled(false);
256 m_qvalues->insertItem(""); 292 m_qvalues->insertItem("");
257 connect (m_qvalues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeQCode(const QString&))); 293 connect (m_qvalues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeQCode(const QString&)));
258 294
259 l = new QLabel("Unicode Value", editKey); 295 l = new QLabel("Unicode Value", editKey);
260 m_uniValues = new QComboBox(true, editKey); 296 m_uniValues = new QComboBox(true, editKey);
261 m_uniValues->setInsertionPolicy(QComboBox::AtTop); 297 m_uniValues->setInsertionPolicy(QComboBox::AtTop);
262 m_uniValues->setDuplicatesEnabled(false); 298 m_uniValues->setDuplicatesEnabled(false);
263 m_uniValues->insertItem(""); 299 m_uniValues->insertItem("");
264 connect (m_uniValues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeUnicode(const QString&))); 300 connect (m_uniValues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeUnicode(const QString&)));
265 301
266 QVBoxLayout *root = new QVBoxLayout(this, 2); 302 QVBoxLayout *root = new QVBoxLayout(this, 2);
267 root->addWidget(kb); 303 root->addWidget(kb);
268 root->addWidget(dimentions); 304 root->addWidget(dimentions);
269 root->addWidget(editKey); 305 root->addWidget(editKey);
270} 306}
271FunctionKeyboardConfig::~FunctionKeyboardConfig() { 307FunctionKeyboardConfig::~FunctionKeyboardConfig() {
272 308
273} 309}
274void FunctionKeyboardConfig::load (const Profile& prof) { 310void FunctionKeyboardConfig::load (const Profile& prof) {
275 311
312 kb->keys.clear();
313 kb->loadDefaults();
314
276 m_rowBox->setValue(prof.readNumEntry("keb_rows", 2)); 315 m_rowBox->setValue(prof.readNumEntry("keb_rows", 2));
277 m_colBox->setValue(prof.readNumEntry("keb_cols", 10)); 316 m_colBox->setValue(prof.readNumEntry("keb_cols", 10));
278 317
279 /* load all the keys to the keyboard */ 318 /* load all the keys to the keyboard */
280 for (int i = 0; i <= m_rowBox->value() -1; i++) 319 for (int i = 0; i <= m_rowBox->value() -1; i++)
281 for (int j = 0; j <= m_colBox->value() -1; j++) { 320 for (int j = 0; j <= m_colBox->value() -1; j++) {
282 321
283 QString h = "r" + QString::number(i) + "c" + QString::number(j); 322 QString h = "r" + QString::number(i) + "c" + QString::number(j);
284 QString values = prof.readEntry("keb_" + h); 323 QString values = prof.readEntry("keb_" + h);
285 324
286 if (!values.isEmpty()) { 325 if (!values.isEmpty()) {
287 326
288 QStringList l = QStringList::split(QChar('|'), values, TRUE); 327 QStringList l = QStringList::split(QChar('|'), values, TRUE);
289 kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt()); 328 kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt());
290 329
291 // load pixmap if used 330 // load pixmap if used
292 if (!l[1].isEmpty()) { 331 if (!l[1].isEmpty()) {
293 332
294 kb->keys[h].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + l[1] ) ); 333 kb->keys[h].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + l[1] ) );
295 } 334 }
296 } 335 }
297 } 336 }
298 337
299} 338}
300void FunctionKeyboardConfig::save (Profile& prof) { 339void FunctionKeyboardConfig::save (Profile& prof) {
301 340
302 prof.writeEntry("keb_rows", m_rowBox->value()); 341 prof.writeEntry("keb_rows", m_rowBox->value());
303 prof.writeEntry("keb_cols", m_colBox->value()); 342 prof.writeEntry("keb_cols", m_colBox->value());
304 343
305 QMap<QString, FKey>::Iterator it; 344 QMap<QString, FKey>::Iterator it;
306 for ( it = kb->keys.begin(); it != kb->keys.end(); it++) { 345 for ( it = kb->keys.begin(); it != kb->keys.end(); it++) {
307 346
308 FKey k = it.data(); 347 FKey k = it.data();
309 QString entry = k.label + "|" 348 QString entry = k.label + "|"
310 + k.pixFile + "|" 349 + k.pixFile + "|"
311 + QString::number(k.qcode) + "|" 350 + QString::number(k.qcode) + "|"
312 + QString::number(k.unicode); 351 + QString::number(k.unicode);
313 352
314 prof.writeEntry("keb_" + it.key(), entry); 353 prof.writeEntry("keb_" + it.key(), entry);
315 354
316 } 355 }
317 356
318} 357}
319void FunctionKeyboardConfig::slotChangeRows(int r) { 358void FunctionKeyboardConfig::slotChangeRows(int r) {
320 359
321 kb->changeRows(r); 360 kb->changeRows(r);
322 361
323 // have to do this so the whole thing gets redrawn
324 kb->hide(); kb->show();
325} 362}
326void FunctionKeyboardConfig::slotChangeCols(int c) { 363void FunctionKeyboardConfig::slotChangeCols(int c) {
327 364
328 kb->changeCols(c); 365 kb->changeCols(c);
329} 366}
330void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) { 367void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) {
331 368
332 if (!pressed) return; 369 if (!pressed) return;
333 370
334 selectedHandle = "r" + QString::number(r) + 371 selectedHandle = "r" + QString::number(r) +
335 "c" + QString::number(c); 372 "c" + QString::number(c);
336 selectedRow = r; 373 selectedRow = r;
337 selectedCol = c; 374 selectedCol = c;
338 375
339 if (k.pixFile.isEmpty()) { 376 if (k.pixFile.isEmpty()) {
340 377
341 m_labels->setEditable(true); 378 m_labels->setEditable(true);
342 m_labels->setCurrentItem(0); 379 m_labels->setCurrentItem(0);
343 m_labels->changeItem(k.label, 0); 380 m_labels->changeItem(k.label, 0);
344 381
345 } else { 382 } else {
346 383
347 // any better way to select the pixmap? 384 // any better way to select the pixmap?
348 m_labels->setCurrentItem((m_labels->listBox())->index((m_labels->listBox())->findItem(kb->keys[selectedHandle].pixFile))); 385 m_labels->setCurrentItem((m_labels->listBox())->index((m_labels->listBox())->findItem(kb->keys[selectedHandle].pixFile)));
349 m_labels->setEditable(false); 386 m_labels->setEditable(false);
350 } 387 }
351 m_qvalues->changeItem(QString::number(k.qcode), 0); 388 m_qvalues->changeItem(QString::number(k.qcode), 0);
352 m_uniValues->changeItem(QString::number(k.unicode), 0); 389 m_uniValues->changeItem(QString::number(k.unicode), 0);
353} 390}
354void FunctionKeyboardConfig::slotChangeIcon(int index) { 391void FunctionKeyboardConfig::slotChangeIcon(int index) {
355 392
356 if (index == 0) { 393 if (index == 0) {
357 394
358 // is text 395 // is text
359 m_labels->setEditable(true); 396 m_labels->setEditable(true);
360 // why tf does the text get erased unless i do this? 397 // why tf does the text get erased unless i do this?
361 m_labels->changeItem(m_labels->text(0), 0); 398 m_labels->changeItem(m_labels->text(0), 0);
362 399
363 kb->keys[selectedHandle].pixFile = ""; 400 kb->keys[selectedHandle].pixFile = "";
364 delete kb->keys[selectedHandle].pix; 401 delete kb->keys[selectedHandle].pix;
365 402
366 } else { 403 } else {
367 404
368 // is a pixmap 405 // is a pixmap
369 m_labels->setEditable(false); 406 m_labels->setEditable(false);
370 kb->keys[selectedHandle].pixFile = m_labels->currentText(); 407 kb->keys[selectedHandle].pixFile = m_labels->currentText();
371 kb->keys[selectedHandle].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + m_labels->currentText() ) ); 408 kb->keys[selectedHandle].pix = new QPixmap( Resource::loadPixmap( "console/keys/" + m_labels->currentText() ) );
372 } 409 }
373 kb->paintKey(selectedRow, selectedCol); 410 kb->paintKey(selectedRow, selectedCol);
374} 411}
375void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) { 412void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) {
376 413
377 kb->keys[selectedHandle].label = label; 414 kb->keys[selectedHandle].label = label;
378 415
379 kb->paintKey(selectedRow, selectedCol); 416 kb->paintKey(selectedRow, selectedCol);
380} 417}
381void FunctionKeyboardConfig::slotChangeQCode(const QString& qcode) { 418void FunctionKeyboardConfig::slotChangeQCode(const QString& qcode) {
382 419
383 kb->keys[selectedHandle].qcode = qcode.toUInt(); 420 kb->keys[selectedHandle].qcode = qcode.toUInt();
384} 421}
385void FunctionKeyboardConfig::slotChangeUnicode(const QString& uni) { 422void FunctionKeyboardConfig::slotChangeUnicode(const QString& uni) {
386 423
387 kb->keys[selectedHandle].unicode = uni.toUInt(); 424 kb->keys[selectedHandle].unicode = uni.toUInt();
388} 425}
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h
index 80d9f29..a60ff4b 100644
--- a/noncore/apps/opie-console/function_keyboard.h
+++ b/noncore/apps/opie-console/function_keyboard.h
@@ -1,115 +1,112 @@
1#ifndef OPIE_FUNCTION_KEYBOARD_H 1#ifndef OPIE_FUNCTION_KEYBOARD_H
2#define OPIE_FUNCTION_KEYBOARD_H 2#define OPIE_FUNCTION_KEYBOARD_H
3 3
4#include <qpe/config.h> 4#include <qpe/config.h>
5#include <qpe/resource.h> 5#include <qpe/resource.h>
6#include <qpe/qpeapplication.h> 6#include <qpe/qpeapplication.h>
7#include <qframe.h> 7#include <qframe.h>
8#include <qpainter.h> 8#include <qpainter.h>
9#include <qvbox.h> 9#include <qvbox.h>
10#include <qgroupbox.h> 10#include <qgroupbox.h>
11#include <qmap.h> 11#include <qmap.h>
12#include <qspinbox.h> 12#include <qspinbox.h>
13#include <qcombobox.h> 13#include <qcombobox.h>
14#include "profiledialogwidget.h" 14#include "profiledialogwidget.h"
15 15
16 16
17struct FKey { 17struct FKey {
18 18
19 FKey(): qcode(0), unicode(0) {}; 19 FKey(): qcode(0), unicode(0) {};
20 FKey(const QString &l, const QString &f, ushort q, ushort u): 20 FKey(const QString &l, const QString &f, ushort q, ushort u):
21 label(l), pixFile(f), qcode(q), unicode(u) { 21 label(l), pixFile(f), qcode(q), unicode(u) {
22 22
23 if (!f.isEmpty()) { 23 if (!f.isEmpty()) {
24 24
25 pix = new QPixmap ( Resource::loadPixmap("console/keys/" + f ) ); 25 pix = new QPixmap ( Resource::loadPixmap("console/keys/" + f ) );
26 } 26 }
27 }; 27 };
28 28
29 QString label; 29 QString label;
30 QPixmap *pix; 30 QPixmap *pix;
31 QString pixFile; 31 QString pixFile;
32 ushort qcode; 32 ushort qcode;
33 ushort unicode; 33 ushort unicode;
34}; 34};
35 35
36class FunctionKeyboard : public QFrame { 36class FunctionKeyboard : public QFrame {
37 Q_OBJECT 37 Q_OBJECT
38 38
39public: 39public:
40 FunctionKeyboard(QWidget *parent = 0); 40 FunctionKeyboard(QWidget *parent = 0);
41 ~FunctionKeyboard(); 41 ~FunctionKeyboard();
42 42
43 friend class FunctionKeyboardConfig; 43 friend class FunctionKeyboardConfig;
44 44
45 void changeRows(int); 45 void changeRows(int);
46 void changeCols(int); 46 void changeCols(int);
47 47
48 //Key getKey(int, int); 48 void load(const Profile &);
49 void loadDefaults();
49 50
50 void paintEvent(QPaintEvent *); 51 void paintEvent(QPaintEvent *);
51 void paintKey(uint, uint); 52 void paintKey(uint, uint);
52 void mousePressEvent(QMouseEvent*); 53 void mousePressEvent(QMouseEvent*);
53 void mouseReleaseEvent(QMouseEvent*); 54 void mouseReleaseEvent(QMouseEvent*);
54 void resizeEvent(QResizeEvent*); 55 void resizeEvent(QResizeEvent*);
55 QSize sizeHint() const; 56 QSize sizeHint() const;
56 57
57signals: 58signals:
58 59
59 void keyPressed(FKey, ushort, ushort, bool); 60 void keyPressed(FKey, ushort, ushort, bool);
60 61
61private:
62
63 void loadDefaults();
64
65 62
66private: 63private:
67 64
68 // thie key for the map is the row/col 65 // thie key for the map is the row/col
69 QMap<QString, FKey> keys; 66 QMap<QString, FKey> keys;
70 67
71 uint numRows; 68 uint numRows;
72 int test; 69 int test;
73 uint numCols; 70 uint numCols;
74 uint keyHeight; 71 uint keyHeight;
75 double keyWidth; // decimal point matters! 72 double keyWidth; // decimal point matters!
76 73
77 int pressedRow, pressedCol; 74 int pressedRow, pressedCol;
78 75
79 QObject *parent; 76 QObject *parent;
80 77
81}; 78};
82 79
83class FunctionKeyboardConfig : public ProfileDialogKeyWidget { 80class FunctionKeyboardConfig : public ProfileDialogKeyWidget {
84 81
85 Q_OBJECT 82 Q_OBJECT
86 83
87public: 84public:
88 FunctionKeyboardConfig(const QString& name, QWidget *wid, const char* name = 0l ); 85 FunctionKeyboardConfig(const QString& name, QWidget *wid, const char* name = 0l );
89 ~FunctionKeyboardConfig(); 86 ~FunctionKeyboardConfig();
90 87
91 void load(const Profile&); 88 void load(const Profile&);
92 void save(Profile&); 89 void save(Profile&);
93 90
94private slots: 91private slots:
95 92
96 void slotKeyPressed(FKey, ushort, ushort, bool); 93 void slotKeyPressed(FKey, ushort, ushort, bool);
97 void slotChangeRows(int); 94 void slotChangeRows(int);
98 void slotChangeCols(int); 95 void slotChangeCols(int);
99 void slotChangeIcon(int); 96 void slotChangeIcon(int);
100 void slotChangeLabelText(const QString &); 97 void slotChangeLabelText(const QString &);
101 void slotChangeQCode(const QString &); 98 void slotChangeQCode(const QString &);
102 void slotChangeUnicode(const QString &); 99 void slotChangeUnicode(const QString &);
103 100
104private: 101private:
105 102
106 QString selectedHandle; 103 QString selectedHandle;
107 ushort selectedRow, selectedCol; 104 ushort selectedRow, selectedCol;
108 105
109 FunctionKeyboard *kb; 106 FunctionKeyboard *kb;
110 QSpinBox *m_rowBox, *m_colBox; 107 QSpinBox *m_rowBox, *m_colBox;
111 QComboBox *m_labels, *m_qvalues, *m_uniValues; 108 QComboBox *m_labels, *m_qvalues, *m_uniValues;
112 109
113}; 110};
114 111
115#endif 112#endif
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index b177fa5..745efaf 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -218,374 +218,380 @@ void MainWindow::initUI() {
218 this, SLOT(slotCopy() ) ); 218 this, SLOT(slotCopy() ) );
219 219
220 a = new QAction(tr("Paste"), 220 a = new QAction(tr("Paste"),
221 Resource::loadPixmap("paste"), QString::null, 221 Resource::loadPixmap("paste"), QString::null,
222 0, this, 0 ); 222 0, this, 0 );
223 a->addTo( m_icons ); 223 a->addTo( m_icons );
224 connect( a, SIGNAL(activated() ), 224 connect( a, SIGNAL(activated() ),
225 this, SLOT(slotPaste() ) ); 225 this, SLOT(slotPaste() ) );
226 226
227 227
228 m_connect->setEnabled( false ); 228 m_connect->setEnabled( false );
229 m_disconnect->setEnabled( false ); 229 m_disconnect->setEnabled( false );
230 m_terminate->setEnabled( false ); 230 m_terminate->setEnabled( false );
231 m_transfer->setEnabled( false ); 231 m_transfer->setEnabled( false );
232 m_recordScript->setEnabled( false ); 232 m_recordScript->setEnabled( false );
233 m_saveScript->setEnabled( false ); 233 m_saveScript->setEnabled( false );
234 m_runScript->setEnabled( false ); 234 m_runScript->setEnabled( false );
235 m_fullscreen->setEnabled( false ); 235 m_fullscreen->setEnabled( false );
236 m_closewindow->setEnabled( false ); 236 m_closewindow->setEnabled( false );
237 237
238 /* 238 /*
239 * connect to the menu activation 239 * connect to the menu activation
240 */ 240 */
241 connect( m_sessionsPop, SIGNAL(activated( int ) ), 241 connect( m_sessionsPop, SIGNAL(activated( int ) ),
242 this, SLOT(slotProfile( int ) ) ); 242 this, SLOT(slotProfile( int ) ) );
243 243
244 m_consoleWindow = new TabWidget( this, "blah"); 244 m_consoleWindow = new TabWidget( this, "blah");
245 connect(m_consoleWindow, SIGNAL(activated(Session*) ), 245 connect(m_consoleWindow, SIGNAL(activated(Session*) ),
246 this, SLOT(slotSessionChanged(Session*) ) ); 246 this, SLOT(slotSessionChanged(Session*) ) );
247 setCentralWidget( m_consoleWindow ); 247 setCentralWidget( m_consoleWindow );
248 248
249} 249}
250 250
251ProfileManager* MainWindow::manager() { 251ProfileManager* MainWindow::manager() {
252 return m_manager; 252 return m_manager;
253} 253}
254TabWidget* MainWindow::tabWidget() { 254TabWidget* MainWindow::tabWidget() {
255 return m_consoleWindow; 255 return m_consoleWindow;
256} 256}
257void MainWindow::populateProfiles() { 257void MainWindow::populateProfiles() {
258 m_sessionsPop->clear(); 258 m_sessionsPop->clear();
259 Profile::ValueList list = manager()->all(); 259 Profile::ValueList list = manager()->all();
260 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { 260 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
261 m_sessionsPop->insertItem( (*it).name() ); 261 m_sessionsPop->insertItem( (*it).name() );
262 } 262 }
263 263
264} 264}
265MainWindow::~MainWindow() { 265MainWindow::~MainWindow() {
266 delete m_factory; 266 delete m_factory;
267 manager()->save(); 267 manager()->save();
268} 268}
269 269
270MetaFactory* MainWindow::factory() { 270MetaFactory* MainWindow::factory() {
271 return m_factory; 271 return m_factory;
272} 272}
273 273
274Session* MainWindow::currentSession() { 274Session* MainWindow::currentSession() {
275 return m_curSession; 275 return m_curSession;
276} 276}
277 277
278QList<Session> MainWindow::sessions() { 278QList<Session> MainWindow::sessions() {
279 return m_sessions; 279 return m_sessions;
280} 280}
281 281
282void MainWindow::slotNew() { 282void MainWindow::slotNew() {
283 ProfileEditorDialog dlg(factory() ); 283 ProfileEditorDialog dlg(factory() );
284 dlg.showMaximized(); 284 dlg.showMaximized();
285 int ret = dlg.exec(); 285 int ret = dlg.exec();
286 286
287 if ( ret == QDialog::Accepted ) { 287 if ( ret == QDialog::Accepted ) {
288 create( dlg.profile() ); 288 create( dlg.profile() );
289 } 289 }
290} 290}
291 291
292void MainWindow::slotRecordScript() { 292void MainWindow::slotRecordScript() {
293 if (currentSession()) { 293 if (currentSession()) {
294 currentSession()->emulationHandler()->startRecording(); 294 currentSession()->emulationHandler()->startRecording();
295 } 295 }
296} 296}
297 297
298void MainWindow::slotSaveScript() { 298void MainWindow::slotSaveScript() {
299 if (currentSession() && currentSession()->emulationHandler()->isRecording()) { 299 if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
300 MimeTypes types; 300 MimeTypes types;
301 QStringList script; 301 QStringList script;
302 script << "text/plain"; 302 script << "text/plain";
303 script << "text/all"; 303 script << "text/all";
304 script << "application/octet-stream"; 304 script << "application/octet-stream";
305 types.insert("Script", script); 305 types.insert("Script", script);
306 QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); 306 QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types);
307 if (!filename.isEmpty()) { 307 if (!filename.isEmpty()) {
308 currentSession()->emulationHandler()->script()->saveTo(filename); 308 currentSession()->emulationHandler()->script()->saveTo(filename);
309 currentSession()->emulationHandler()->clearScript(); 309 currentSession()->emulationHandler()->clearScript();
310 } 310 }
311 } 311 }
312} 312}
313 313
314void MainWindow::slotRunScript() { 314void MainWindow::slotRunScript() {
315 if (currentSession()) { 315 if (currentSession()) {
316 MimeTypes types; 316 MimeTypes types;
317 QStringList script; 317 QStringList script;
318 script << "text/plain"; 318 script << "text/plain";
319 script << "text/all"; 319 script << "text/all";
320 script << "application/octet-stream"; 320 script << "application/octet-stream";
321 types.insert("Script", script); 321 types.insert("Script", script);
322 QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); 322 QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types);
323 if (!filename.isEmpty()) { 323 if (!filename.isEmpty()) {
324 Script script(DocLnk(filename).file()); 324 Script script(DocLnk(filename).file());
325 currentSession()->emulationHandler()->runScript(&script); 325 currentSession()->emulationHandler()->runScript(&script);
326 } 326 }
327 } 327 }
328} 328}
329 329
330void MainWindow::slotConnect() { 330void MainWindow::slotConnect() {
331 if ( currentSession() ) { 331 if ( currentSession() ) {
332 bool ret = currentSession()->layer()->open(); 332 bool ret = currentSession()->layer()->open();
333 if(!ret) QMessageBox::warning(currentSession()->widgetStack(), 333 if(!ret) QMessageBox::warning(currentSession()->widgetStack(),
334 QObject::tr("Failed"), 334 QObject::tr("Failed"),
335 QObject::tr("Connecting failed for this session.")); 335 QObject::tr("Connecting failed for this session."));
336 else { 336 else {
337 m_connect->setEnabled( false ); 337 m_connect->setEnabled( false );
338 m_disconnect->setEnabled( true ); 338 m_disconnect->setEnabled( true );
339 m_transfer->setEnabled( true ); 339 m_transfer->setEnabled( true );
340 m_recordScript->setEnabled( true ); 340 m_recordScript->setEnabled( true );
341 m_saveScript->setEnabled( true ); 341 m_saveScript->setEnabled( true );
342 m_runScript->setEnabled( true ); 342 m_runScript->setEnabled( true );
343 } 343 }
344 } 344 }
345} 345}
346 346
347void MainWindow::slotDisconnect() { 347void MainWindow::slotDisconnect() {
348 if ( currentSession() ) { 348 if ( currentSession() ) {
349 currentSession()->layer()->close(); 349 currentSession()->layer()->close();
350 m_connect->setEnabled( true ); 350 m_connect->setEnabled( true );
351 m_disconnect->setEnabled( false ); 351 m_disconnect->setEnabled( false );
352 m_transfer->setEnabled( false ); 352 m_transfer->setEnabled( false );
353 m_recordScript->setEnabled( false); 353 m_recordScript->setEnabled( false);
354 m_saveScript->setEnabled( false ); 354 m_saveScript->setEnabled( false );
355 m_runScript->setEnabled( false ); 355 m_runScript->setEnabled( false );
356 } 356 }
357} 357}
358 358
359void MainWindow::slotTerminate() { 359void MainWindow::slotTerminate() {
360 if ( currentSession() ) 360 if ( currentSession() )
361 currentSession()->layer()->close(); 361 currentSession()->layer()->close();
362 362
363 slotClose(); 363 slotClose();
364 /* FIXME move to the next session */ 364 /* FIXME move to the next session */
365} 365}
366 366
367void MainWindow::slotConfigure() { 367void MainWindow::slotConfigure() {
368 ConfigDialog conf( manager()->all(), factory() ); 368 ConfigDialog conf( manager()->all(), factory() );
369 conf.showMaximized(); 369 conf.showMaximized();
370 370
371 int ret = conf.exec(); 371 int ret = conf.exec();
372 372
373 if ( QDialog::Accepted == ret ) { 373 if ( QDialog::Accepted == ret ) {
374 manager()->setProfiles( conf.list() ); 374 manager()->setProfiles( conf.list() );
375 manager()->save(); 375 manager()->save();
376 populateProfiles(); 376 populateProfiles();
377 } 377 }
378} 378}
379/* 379/*
380 * we will remove 380 * we will remove
381 * this window from the tabwidget 381 * this window from the tabwidget
382 * remove it from the list 382 * remove it from the list
383 * delete it 383 * delete it
384 * and set the currentSession() 384 * and set the currentSession()
385 */ 385 */
386void MainWindow::slotClose() { 386void MainWindow::slotClose() {
387 if (!currentSession() ) 387 if (!currentSession() )
388 return; 388 return;
389 389
390 Session* ses = currentSession(); 390 Session* ses = currentSession();
391 qWarning("removing! currentSession %s", currentSession()->name().latin1() ); 391 qWarning("removing! currentSession %s", currentSession()->name().latin1() );
392 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ 392 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */
393 m_curSession = NULL; 393 m_curSession = NULL;
394 tabWidget()->remove( /*currentSession()*/ses ); 394 tabWidget()->remove( /*currentSession()*/ses );
395 /*it's autodelete */ 395 /*it's autodelete */
396 m_sessions.remove( ses ); 396 m_sessions.remove( ses );
397 qWarning("after remove!!"); 397 qWarning("after remove!!");
398 398
399 if (!currentSession() ) { 399 if (!currentSession() ) {
400 m_connect->setEnabled( false ); 400 m_connect->setEnabled( false );
401 m_disconnect->setEnabled( false ); 401 m_disconnect->setEnabled( false );
402 m_terminate->setEnabled( false ); 402 m_terminate->setEnabled( false );
403 m_transfer->setEnabled( false ); 403 m_transfer->setEnabled( false );
404 m_recordScript->setEnabled( false ); 404 m_recordScript->setEnabled( false );
405 m_saveScript->setEnabled( false ); 405 m_saveScript->setEnabled( false );
406 m_runScript->setEnabled( false ); 406 m_runScript->setEnabled( false );
407 m_fullscreen->setEnabled( false ); 407 m_fullscreen->setEnabled( false );
408 m_closewindow->setEnabled( false ); 408 m_closewindow->setEnabled( false );
409 } 409 }
410
411 m_kb->loadDefaults();
410} 412}
411 413
412/* 414/*
413 * We will get the name 415 * We will get the name
414 * Then the profile 416 * Then the profile
415 * and then we will make a profile 417 * and then we will make a profile
416 */ 418 */
417void MainWindow::slotProfile( int id) { 419void MainWindow::slotProfile( int id) {
418 Profile prof = manager()->profile( m_sessionsPop->text( id) ); 420 Profile prof = manager()->profile( m_sessionsPop->text( id) );
419 create( prof ); 421 create( prof );
420} 422}
421void MainWindow::create( const Profile& prof ) { 423void MainWindow::create( const Profile& prof ) {
422 Session *ses = manager()->fromProfile( prof, tabWidget() ); 424 Session *ses = manager()->fromProfile( prof, tabWidget() );
423 425
424 if((!ses) || (!ses->layer()) || (!ses->widgetStack())) 426 if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
425 { 427 {
426 QMessageBox::warning(this, 428 QMessageBox::warning(this,
427 QObject::tr("Session failed"), 429 QObject::tr("Session failed"),
428 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); 430 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
429 //if(ses) delete ses; 431 //if(ses) delete ses;
430 return; 432 return;
431 } 433 }
432 434
433 m_sessions.append( ses ); 435 m_sessions.append( ses );
434 tabWidget()->add( ses ); 436 tabWidget()->add( ses );
435 tabWidget()->repaint(); 437 tabWidget()->repaint();
436 m_curSession = ses; 438 m_curSession = ses;
437 439
438 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it 440 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it
439 m_connect->setEnabled( true ); 441 m_connect->setEnabled( true );
440 m_disconnect->setEnabled( false ); 442 m_disconnect->setEnabled( false );
441 m_terminate->setEnabled( true ); 443 m_terminate->setEnabled( true );
442 m_fullscreen->setEnabled( true ); 444 m_fullscreen->setEnabled( true );
443 m_closewindow->setEnabled( true ); 445 m_closewindow->setEnabled( true );
444 m_transfer->setEnabled( false ); 446 m_transfer->setEnabled( false );
445 m_recordScript->setEnabled( false ); 447 m_recordScript->setEnabled( false );
446 m_saveScript->setEnabled( false ); 448 m_saveScript->setEnabled( false );
447 m_runScript->setEnabled( false ); 449 m_runScript->setEnabled( false );
448 450
449 // is io_layer wants direct connection, then autoconnect 451 // is io_layer wants direct connection, then autoconnect
450 //if ( ( m_curSession->layer() )->supports()[0] == 1 ) { 452 //if ( ( m_curSession->layer() )->supports()[0] == 1 ) {
451 if (prof.autoConnect()) { 453 if (prof.autoConnect()) {
452 slotConnect(); 454 slotConnect();
453 } 455 }
454 456
455 457
456 458
457 QWidget *w = currentSession()->widget(); 459 QWidget *w = currentSession()->widget();
458 if(w) w->setFocus(); 460 if(w) w->setFocus();
461
462 m_kb->load(currentSession()->profile());
459} 463}
460 464
461void MainWindow::slotTransfer() 465void MainWindow::slotTransfer()
462{ 466{
463 if ( currentSession() ) { 467 if ( currentSession() ) {
464 TransferDialog dlg(currentSession()->widgetStack(), this); 468 TransferDialog dlg(currentSession()->widgetStack(), this);
465 dlg.showMaximized(); 469 dlg.showMaximized();
466 //currentSession()->widgetStack()->add(dlg); 470 //currentSession()->widgetStack()->add(dlg);
467 dlg.exec(); 471 dlg.exec();
468 } 472 }
469} 473}
470 474
471 475
472void MainWindow::slotOpenKeb(bool state) { 476void MainWindow::slotOpenKeb(bool state) {
473 477
474 if (state) m_keyBar->show(); 478 if (state) m_keyBar->show();
475 else m_keyBar->hide(); 479 else m_keyBar->hide();
476 480
477} 481}
478 482
479 483
480void MainWindow::slotOpenButtons( bool state ) { 484void MainWindow::slotOpenButtons( bool state ) {
481 485
482 if ( state ) { 486 if ( state ) {
483 m_buttonBar->show(); 487 m_buttonBar->show();
484 } else { 488 } else {
485 m_buttonBar->hide(); 489 m_buttonBar->hide();
486 } 490 }
487} 491}
488 492
489 493
490 494
491void MainWindow::slotSessionChanged( Session* ses ) { 495void MainWindow::slotSessionChanged( Session* ses ) {
492 qWarning("changed!"); 496 qWarning("changed!");
493 if ( ses ) { 497 if ( ses ) {
494 m_curSession = ses; 498 m_curSession = ses;
495 qDebug(QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) ); 499 qDebug(QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) );
496 if ( m_curSession->layer()->isConnected() ) { 500 if ( m_curSession->layer()->isConnected() ) {
497 m_connect->setEnabled( false ); 501 m_connect->setEnabled( false );
498 m_disconnect->setEnabled( true ); 502 m_disconnect->setEnabled( true );
499 m_recordScript->setEnabled( true ); 503 m_recordScript->setEnabled( true );
500 m_saveScript->setEnabled( true ); 504 m_saveScript->setEnabled( true );
501 m_runScript->setEnabled( true ); 505 m_runScript->setEnabled( true );
502 } else { 506 } else {
503 m_connect->setEnabled( true ); 507 m_connect->setEnabled( true );
504 m_disconnect->setEnabled( false ); 508 m_disconnect->setEnabled( false );
505 m_recordScript->setEnabled( false ); 509 m_recordScript->setEnabled( false );
506 m_saveScript->setEnabled( false ); 510 m_saveScript->setEnabled( false );
507 m_runScript->setEnabled( false ); 511 m_runScript->setEnabled( false );
508 } 512 }
509 513
510 if ( ( m_curSession->layer() )->supports()[1] == 0 ) { 514 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
511 m_transfer->setEnabled( false ); 515 m_transfer->setEnabled( false );
512 } else { 516 } else {
513 m_transfer->setEnabled( true ); 517 m_transfer->setEnabled( true );
514 } 518 }
515 519
516 520
517 521
518 522
519 523
520 QWidget *w = m_curSession->widget(); 524 QWidget *w = m_curSession->widget();
521 if(w) w->setFocus(); 525 if(w) w->setFocus();
526
527 m_kb->load(currentSession()->profile());
522 } 528 }
523} 529}
524 530
525void MainWindow::slotFullscreen() { 531void MainWindow::slotFullscreen() {
526 532
527 533
528 534
529 if ( m_isFullscreen ) { 535 if ( m_isFullscreen ) {
530 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true ); 536 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true );
531 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() ); 537 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() );
532 ( m_curSession->emulationHandler() )->cornerButton()->hide(); 538 ( m_curSession->emulationHandler() )->cornerButton()->hide();
533 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 539 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
534 540
535 } else { 541 } else {
536 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget(); 542 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget();
537 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame ); 543 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame );
538 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop 544 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop
539 , QPoint(0,0), false ); 545 , QPoint(0,0), false );
540 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() ); 546 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() );
541 ( m_curSession->widgetStack() )->setFocus(); 547 ( m_curSession->widgetStack() )->setFocus();
542 ( m_curSession->widgetStack() )->show(); 548 ( m_curSession->widgetStack() )->show();
543 549
544 ( ( m_curSession->emulationHandler() )->cornerButton() )->show(); 550 ( ( m_curSession->emulationHandler() )->cornerButton() )->show();
545 551
546 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 552 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
547 } 553 }
548 554
549 m_isFullscreen = !m_isFullscreen; 555 m_isFullscreen = !m_isFullscreen;
550} 556}
551 557
552 558
553void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) { 559void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) {
554 560
555 if ( m_curSession ) { 561 if ( m_curSession ) {
556 562
557 QEvent::Type state; 563 QEvent::Type state;
558 564
559 if (pressed) state = QEvent::KeyPress; 565 if (pressed) state = QEvent::KeyPress;
560 else state = QEvent::KeyRelease; 566 else state = QEvent::KeyRelease;
561 567
562 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode))); 568 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode)));
563 569
564 // is this the best way to do this? cant figure out any other way to work 570 // is this the best way to do this? cant figure out any other way to work
565 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke); 571 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke);
566 ke.ignore(); 572 ke.ignore();
567 } 573 }
568} 574}
569void MainWindow::slotCopy() { 575void MainWindow::slotCopy() {
570 if (!currentSession() ) return; 576 if (!currentSession() ) return;
571 currentSession()->emulationHandler()->copy(); 577 currentSession()->emulationHandler()->copy();
572} 578}
573void MainWindow::slotPaste() { 579void MainWindow::slotPaste() {
574 if (!currentSession() ) return; 580 if (!currentSession() ) return;
575 currentSession()->emulationHandler()->paste(); 581 currentSession()->emulationHandler()->paste();
576} 582}
577 583
578/* 584/*
579 * Save the session 585 * Save the session
580 */ 586 */
581 587
582void MainWindow::slotSaveSession() { 588void MainWindow::slotSaveSession() {
583 if (!currentSession() ) { 589 if (!currentSession() ) {
584 QMessageBox::information(this, tr("Save Connection"), 590 QMessageBox::information(this, tr("Save Connection"),
585 tr("<qt>There is no Connection.</qt>"), 1 ); 591 tr("<qt>There is no Connection.</qt>"), 1 );
586 return; 592 return;
587 } 593 }
588 manager()->add( currentSession()->profile() ); 594 manager()->add( currentSession()->profile() );
589 manager()->save(); 595 manager()->save();
590 populateProfiles(); 596 populateProfiles();
591} 597}