-rw-r--r-- | noncore/apps/opie-console/emulation_handler.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp index bb3dd28..b2b107e 100644 --- a/noncore/apps/opie-console/emulation_handler.cpp +++ b/noncore/apps/opie-console/emulation_handler.cpp | |||
@@ -1,200 +1,199 @@ | |||
1 | #include <qwidget.h> | 1 | #include <qwidget.h> |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | 3 | ||
4 | #include "TEWidget.h" | 4 | #include "TEWidget.h" |
5 | #include "TEmuVt102.h" | 5 | #include "TEmuVt102.h" |
6 | 6 | ||
7 | #include "profile.h" | 7 | #include "profile.h" |
8 | #include "emulation_handler.h" | 8 | #include "emulation_handler.h" |
9 | #include "script.h" | 9 | #include "script.h" |
10 | 10 | ||
11 | EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) | 11 | EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) |
12 | : QObject(0, name ) | 12 | : QObject(0, name ) |
13 | { | 13 | { |
14 | m_teWid = new TEWidget( parent, "TerminalMain"); | 14 | m_teWid = new TEWidget( parent, "TerminalMain"); |
15 | m_teWid->setMinimumSize(150, 70 ); | 15 | m_teWid->setMinimumSize(150, 70 ); |
16 | m_script = 0; | 16 | m_script = 0; |
17 | parent->resize( m_teWid->calcSize(80, 24 ) ); | 17 | parent->resize( m_teWid->calcSize(80, 24 ) ); |
18 | m_teEmu = new TEmuVt102(m_teWid ); | 18 | m_teEmu = new TEmuVt102(m_teWid ); |
19 | 19 | ||
20 | connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), | 20 | connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), |
21 | this, SIGNAL(changeSize(int, int) ) ); | 21 | this, SIGNAL(changeSize(int, int) ) ); |
22 | connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), | 22 | connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), |
23 | this, SLOT(recvEmulation(const char*, int) ) ); | 23 | this, SLOT(recvEmulation(const char*, int) ) ); |
24 | m_teEmu->setConnect( true ); | 24 | m_teEmu->setConnect( true ); |
25 | m_teEmu->setHistory( TRUE ); | 25 | m_teEmu->setHistory( TRUE ); |
26 | load( prof ); | 26 | load( prof ); |
27 | 27 | ||
28 | 28 | ||
29 | 29 | ||
30 | } | 30 | } |
31 | EmulationHandler::~EmulationHandler() { | 31 | EmulationHandler::~EmulationHandler() { |
32 | if (isRecording()) | 32 | if (isRecording()) |
33 | clearScript(); | 33 | clearScript(); |
34 | delete m_teEmu; | 34 | delete m_teEmu; |
35 | delete m_teWid; | 35 | delete m_teWid; |
36 | } | 36 | } |
37 | 37 | ||
38 | void EmulationHandler::load( const Profile& prof) { | 38 | void EmulationHandler::load( const Profile& prof) { |
39 | m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); | 39 | m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); |
40 | int num = prof.readNumEntry("Color"); | 40 | int num = prof.readNumEntry("Color"); |
41 | setColor( foreColor(num), backColor(num) ); | 41 | setColor( foreColor(num), backColor(num) ); |
42 | m_teWid->setBackgroundColor(backColor(num) ); | 42 | m_teWid->setBackgroundColor(backColor(num) ); |
43 | 43 | ||
44 | int term = prof.readNumEntry("Terminal", 0) ; | 44 | int term = prof.readNumEntry("Terminal", 0) ; |
45 | switch(term) { | 45 | switch(term) { |
46 | default: | 46 | default: |
47 | case Profile::VT102: | 47 | case Profile::VT102: |
48 | case Profile::VT100: | 48 | case Profile::VT100: |
49 | m_teEmu->setKeytrans("vt100.keytab"); | 49 | m_teEmu->setKeytrans("vt100.keytab"); |
50 | break; | 50 | break; |
51 | case Profile::Linux: | 51 | case Profile::Linux: |
52 | m_teEmu->setKeytrans("linux.keytab"); | 52 | m_teEmu->setKeytrans("linux.keytab"); |
53 | break; | 53 | break; |
54 | case Profile::XTerm: | 54 | case Profile::XTerm: |
55 | m_teEmu->setKeytrans("default.Keytab"); | 55 | m_teEmu->setKeytrans("default.Keytab"); |
56 | break; | 56 | break; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | void EmulationHandler::recv( const QByteArray& ar) { | 59 | void EmulationHandler::recv( const QByteArray& ar) { |
60 | m_teEmu->onRcvBlock(ar.data(), ar.count() ); | 60 | m_teEmu->onRcvBlock(ar.data(), ar.count() ); |
61 | } | 61 | } |
62 | void EmulationHandler::recvEmulation(const char* src, int len ) { | 62 | void EmulationHandler::recvEmulation(const char* src, int len ) { |
63 | QByteArray ar(len); | 63 | QByteArray ar(len); |
64 | 64 | ||
65 | memcpy(ar.data(), src, sizeof(char) * len ); | 65 | memcpy(ar.data(), src, sizeof(char) * len ); |
66 | 66 | ||
67 | if (isRecording()) | 67 | if (isRecording()) |
68 | m_script->append(ar); | 68 | m_script->append(ar); |
69 | emit send(ar); | 69 | emit send(ar); |
70 | } | 70 | } |
71 | QWidget* EmulationHandler::widget() { | 71 | QWidget* EmulationHandler::widget() { |
72 | return m_teWid; | 72 | return m_teWid; |
73 | } | 73 | } |
74 | /* | 74 | /* |
75 | * allocate a new table of colors | 75 | * allocate a new table of colors |
76 | */ | 76 | */ |
77 | void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { | 77 | void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { |
78 | ColorEntry table[TABLE_COLORS]; | 78 | ColorEntry table[TABLE_COLORS]; |
79 | const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); | 79 | const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); |
80 | 80 | ||
81 | for (int i = 0; i < TABLE_COLORS; i++ ) { | 81 | for (int i = 0; i < TABLE_COLORS; i++ ) { |
82 | if ( i == 0 || i == 10 ) { | 82 | if ( i == 0 || i == 10 ) { |
83 | table[i].color = fore; | 83 | table[i].color = fore; |
84 | }else if ( i == 1 || i == 11 ) { | 84 | }else if ( i == 1 || i == 11 ) { |
85 | table[i].color = back; | 85 | table[i].color = back; |
86 | table[i].transparent = 0; | 86 | table[i].transparent = 0; |
87 | }else { | 87 | }else { |
88 | table[i].color = defaultCt[i].color; | 88 | table[i].color = defaultCt[i].color; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | m_teWid->setColorTable(table ); | 91 | m_teWid->setColorTable(table ); |
92 | m_teWid->update(); | 92 | m_teWid->update(); |
93 | } | 93 | } |
94 | QFont EmulationHandler::font( int id ) { | 94 | QFont EmulationHandler::font( int id ) { |
95 | QString name; | 95 | QString name; |
96 | int size = 0; | 96 | int size = 0; |
97 | switch(id ) { | 97 | switch(id ) { |
98 | default: // fall through | 98 | default: // fall through |
99 | case 0: | 99 | case 0: |
100 | name = QString::fromLatin1("Micro"); | 100 | name = QString::fromLatin1("Micro"); |
101 | size = 4; | 101 | size = 4; |
102 | break; | 102 | break; |
103 | case 1: | 103 | case 1: |
104 | name = QString::fromLatin1("Fixed"); | 104 | name = QString::fromLatin1("Fixed"); |
105 | size = 7; | 105 | size = 7; |
106 | break; | 106 | break; |
107 | case 2: | 107 | case 2: |
108 | name = QString::fromLatin1("Fixed"); | 108 | name = QString::fromLatin1("Fixed"); |
109 | size = 12; | 109 | size = 12; |
110 | break; | 110 | break; |
111 | } | 111 | } |
112 | QFont font(name, size, QFont::Normal ); | 112 | QFont font(name, size, QFont::Normal ); |
113 | font.setFixedPitch(TRUE ); | 113 | font.setFixedPitch(TRUE ); |
114 | return font; | 114 | return font; |
115 | } | 115 | } |
116 | QColor EmulationHandler::foreColor(int col) { | 116 | QColor EmulationHandler::foreColor(int col) { |
117 | QColor co; | 117 | QColor co; |
118 | /* we need to switch it */ | 118 | /* we need to switch it */ |
119 | switch( col ) { | 119 | switch( col ) { |
120 | default: | 120 | default: |
121 | case Profile::White: | 121 | case Profile::White: |
122 | /* color is black */ | 122 | /* color is black */ |
123 | co = Qt::white; | 123 | co = Qt::white; |
124 | break; | 124 | break; |
125 | case Profile::Black: | 125 | case Profile::Black: |
126 | co = Qt::black; | 126 | co = Qt::black; |
127 | break; | 127 | break; |
128 | case Profile::Green: | 128 | case Profile::Green: |
129 | qWarning("Foreground green"); | 129 | qWarning("Foreground green"); |
130 | co = Qt::green; | 130 | co = Qt::green; |
131 | break; | 131 | break; |
132 | case Profile::Orange: | 132 | case Profile::Orange: |
133 | qWarning("Foreground orange"); | 133 | qWarning("Foreground orange"); |
134 | // FIXME needs better color here | 134 | co.setRgb( 231, 184, 98 ); |
135 | co = Qt::darkYellow; | ||
136 | break; | 135 | break; |
137 | } | 136 | } |
138 | 137 | ||
139 | return co; | 138 | return co; |
140 | } | 139 | } |
141 | QColor EmulationHandler::backColor(int col ) { | 140 | QColor EmulationHandler::backColor(int col ) { |
142 | QColor co; | 141 | QColor co; |
143 | /* we need to switch it */ | 142 | /* we need to switch it */ |
144 | switch( col ) { | 143 | switch( col ) { |
145 | default: | 144 | default: |
146 | case Profile::White: | 145 | case Profile::White: |
147 | /* color is white */ | 146 | /* color is white */ |
148 | co = Qt::black; | 147 | co = Qt::black; |
149 | break; | 148 | break; |
150 | case Profile::Black: | 149 | case Profile::Black: |
151 | co = Qt::white; | 150 | co = Qt::white; |
152 | break; | 151 | break; |
153 | case Profile::Green: | 152 | case Profile::Green: |
154 | qWarning("Background black"); | 153 | qWarning("Background black"); |
155 | co = Qt::black; | 154 | co = Qt::black; |
156 | break; | 155 | break; |
157 | case Profile::Orange: | 156 | case Profile::Orange: |
158 | qWarning("Background black"); | 157 | qWarning("Background black"); |
159 | co = Qt::black; | 158 | co = Qt::black; |
160 | break; | 159 | break; |
161 | } | 160 | } |
162 | 161 | ||
163 | return co; | 162 | return co; |
164 | } | 163 | } |
165 | 164 | ||
166 | QPushButton* EmulationHandler::cornerButton() { | 165 | QPushButton* EmulationHandler::cornerButton() { |
167 | return m_teWid->cornerButton(); | 166 | return m_teWid->cornerButton(); |
168 | } | 167 | } |
169 | 168 | ||
170 | 169 | ||
171 | Script *EmulationHandler::script() { | 170 | Script *EmulationHandler::script() { |
172 | return m_script; | 171 | return m_script; |
173 | } | 172 | } |
174 | 173 | ||
175 | bool EmulationHandler::isRecording() { | 174 | bool EmulationHandler::isRecording() { |
176 | return (m_script != 0); | 175 | return (m_script != 0); |
177 | } | 176 | } |
178 | 177 | ||
179 | void EmulationHandler::startRecording() { | 178 | void EmulationHandler::startRecording() { |
180 | if (!isRecording()) | 179 | if (!isRecording()) |
181 | m_script = new Script(); | 180 | m_script = new Script(); |
182 | } | 181 | } |
183 | 182 | ||
184 | void EmulationHandler::clearScript() { | 183 | void EmulationHandler::clearScript() { |
185 | if (isRecording()) { | 184 | if (isRecording()) { |
186 | delete m_script; | 185 | delete m_script; |
187 | m_script = 0; | 186 | m_script = 0; |
188 | } | 187 | } |
189 | } | 188 | } |
190 | 189 | ||
191 | void EmulationHandler::runScript(const Script *script) { | 190 | void EmulationHandler::runScript(const Script *script) { |
192 | emit send(script->script()); | 191 | emit send(script->script()); |
193 | } | 192 | } |
194 | 193 | ||
195 | void EmulationHandler::copy() { | 194 | void EmulationHandler::copy() { |
196 | m_teWid->emitSelection(); | 195 | m_teWid->emitSelection(); |
197 | } | 196 | } |
198 | void EmulationHandler::paste() { | 197 | void EmulationHandler::paste() { |
199 | m_teWid->pasteClipboard(); | 198 | m_teWid->pasteClipboard(); |
200 | } | 199 | } |