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