Merge lp:~larryprice/ubuntu-terminal-app/update-qmltermwidget into lp:~ubuntu-terminal-dev/ubuntu-terminal-app/reboot
- update-qmltermwidget
- Merge into reboot
Proposed by
Larry Price
Status: | Superseded |
---|---|
Proposed branch: | lp:~larryprice/ubuntu-terminal-app/update-qmltermwidget |
Merge into: | lp:~ubuntu-terminal-dev/ubuntu-terminal-app/reboot |
Prerequisite: | lp:~larryprice/ubuntu-terminal-app/fix-cmake-xenial |
Diff against target: |
27374 lines (+2019/-24346) 109 files modified
src/app/qml/TerminalComponent.qml (+0/-4) src/plugin/konsole/BlockArray.cpp (+0/-377) src/plugin/konsole/BlockArray.h (+0/-126) src/plugin/konsole/CMakeLists.txt (+0/-93) src/plugin/konsole/Character.h (+0/-221) src/plugin/konsole/CharacterColor.h (+0/-294) src/plugin/konsole/ColorScheme.cpp (+0/-774) src/plugin/konsole/ColorScheme.h (+0/-342) src/plugin/konsole/ColorTables.h (+0/-55) src/plugin/konsole/DefaultTranslatorText.h (+0/-2) src/plugin/konsole/Emulation.cpp (+0/-458) src/plugin/konsole/Emulation.h (+0/-467) src/plugin/konsole/ExtendedDefaultTranslator.h (+0/-74) src/plugin/konsole/Filter.cpp (+0/-542) src/plugin/konsole/Filter.h (+0/-380) src/plugin/konsole/History.cpp (+0/-986) src/plugin/konsole/History.h (+0/-490) src/plugin/konsole/KeyboardTranslator.cpp (+0/-892) src/plugin/konsole/KeyboardTranslator.h (+0/-584) src/plugin/konsole/LineFont.h (+0/-21) src/plugin/konsole/LineFont.src (+0/-786) src/plugin/konsole/Pty.cpp (+0/-310) src/plugin/konsole/Pty.h (+0/-206) src/plugin/konsole/Screen.cpp (+0/-1360) src/plugin/konsole/Screen.h (+0/-672) src/plugin/konsole/ScreenWindow.cpp (+0/-292) src/plugin/konsole/ScreenWindow.h (+0/-257) src/plugin/konsole/Session.cpp (+0/-1064) src/plugin/konsole/Session.h (+0/-626) src/plugin/konsole/ShellCommand.cpp (+0/-167) src/plugin/konsole/ShellCommand.h (+0/-90) src/plugin/konsole/TerminalCharacterDecoder.cpp (+0/-251) src/plugin/konsole/TerminalCharacterDecoder.h (+0/-148) src/plugin/konsole/TerminalDisplay.cpp (+0/-2171) src/plugin/konsole/TerminalDisplay.h (+0/-715) src/plugin/konsole/Vt102Emulation.cpp (+0/-1221) src/plugin/konsole/Vt102Emulation.h (+0/-188) src/plugin/konsole/assets/color-schemes/BlackOnLightYellow.schema (+0/-42) src/plugin/konsole/assets/color-schemes/BlackOnRandomLight.colorscheme (+0/-104) src/plugin/konsole/assets/color-schemes/BlackOnWhite.schema (+0/-42) src/plugin/konsole/assets/color-schemes/DarkPastels.colorscheme (+0/-103) src/plugin/konsole/assets/color-schemes/GreenOnBlack.colorscheme (+0/-104) src/plugin/konsole/assets/color-schemes/Linux.colorscheme (+0/-100) src/plugin/konsole/assets/color-schemes/WhiteOnBlack.schema (+0/-42) src/plugin/konsole/assets/color-schemes/historic/BlackOnLightColor.schema (+0/-42) src/plugin/konsole/assets/color-schemes/historic/DarkPicture.schema (+0/-44) src/plugin/konsole/assets/color-schemes/historic/Example.Schema (+0/-47) src/plugin/konsole/assets/color-schemes/historic/GreenOnBlack.schema (+0/-42) src/plugin/konsole/assets/color-schemes/historic/GreenTint.schema (+0/-49) src/plugin/konsole/assets/color-schemes/historic/GreenTint_MC.schema (+0/-49) src/plugin/konsole/assets/color-schemes/historic/LightPicture.schema (+0/-44) src/plugin/konsole/assets/color-schemes/historic/Linux.schema (+0/-47) src/plugin/konsole/assets/color-schemes/historic/README.Schema (+0/-132) src/plugin/konsole/assets/color-schemes/historic/README.default.Schema (+0/-44) src/plugin/konsole/assets/color-schemes/historic/Transparent.schema (+0/-49) src/plugin/konsole/assets/color-schemes/historic/Transparent_MC.schema (+0/-51) src/plugin/konsole/assets/color-schemes/historic/Transparent_darkbg.schema (+0/-42) src/plugin/konsole/assets/color-schemes/historic/Transparent_lightbg.schema (+0/-51) src/plugin/konsole/assets/color-schemes/historic/XTerm.schema (+0/-46) src/plugin/konsole/assets/color-schemes/historic/syscolor.schema (+0/-44) src/plugin/konsole/assets/color-schemes/historic/vim.schema (+0/-40) src/plugin/konsole/assets/kb-layouts/README (+0/-72) src/plugin/konsole/assets/kb-layouts/default.keytab (+0/-169) src/plugin/konsole/assets/kb-layouts/historic/vt100.keytab (+0/-133) src/plugin/konsole/assets/kb-layouts/historic/x11r5.keytab (+0/-71) src/plugin/konsole/assets/kb-layouts/linux.keytab (+0/-164) src/plugin/konsole/assets/kb-layouts/macbook.keytab (+0/-175) src/plugin/konsole/assets/kb-layouts/solaris.keytab (+0/-108) src/plugin/konsole/assets/kb-layouts/vt420pc.keytab (+0/-168) src/plugin/konsole/default.keytab (+0/-128) src/plugin/konsole/konsole_wcwidth.cpp (+0/-224) src/plugin/konsole/konsole_wcwidth.h (+0/-24) src/plugin/konsole/kprocess.cpp (+0/-412) src/plugin/konsole/kprocess.h (+0/-372) src/plugin/konsole/kpty.cpp (+0/-701) src/plugin/konsole/kpty.h (+0/-191) src/plugin/konsole/kpty_p.h (+0/-50) src/plugin/konsole/kptydevice.cpp (+0/-422) src/plugin/konsole/kptydevice.h (+0/-360) src/plugin/konsole/kptyprocess.cpp (+0/-129) src/plugin/konsole/kptyprocess.h (+0/-178) src/plugin/konsole/ksession.cpp (+0/-242) src/plugin/konsole/ksession.h (+0/-132) src/plugin/konsole/plugin.cpp (+0/-63) src/plugin/konsole/plugin.h (+0/-46) src/plugin/konsole/plugins.qmltypes (+0/-169) src/plugin/konsole/qmldir (+0/-3) src/plugin/konsole/tools.cpp (+0/-80) src/plugin/konsole/tools.h (+0/-10) src/plugin/qmltermwidget/.gitignore (+0/-1) src/plugin/qmltermwidget/AUTHORS (+1/-0) src/plugin/qmltermwidget/lib.pri (+2/-1) src/plugin/qmltermwidget/lib/Emulation.cpp (+5/-0) src/plugin/qmltermwidget/lib/Emulation.h (+11/-1) src/plugin/qmltermwidget/lib/KeyboardTranslator.cpp (+1/-1) src/plugin/qmltermwidget/lib/ProcessInfo.cpp (+1174/-0) src/plugin/qmltermwidget/lib/ProcessInfo.h (+460/-0) src/plugin/qmltermwidget/lib/Session.cpp (+41/-4) src/plugin/qmltermwidget/lib/Session.h (+10/-1) src/plugin/qmltermwidget/lib/TerminalDisplay.cpp (+64/-51) src/plugin/qmltermwidget/lib/TerminalDisplay.h (+29/-25) src/plugin/qmltermwidget/lib/Vt102Emulation.cpp (+6/-3) src/plugin/qmltermwidget/lib/color-schemes/Ubuntu.colorscheme (+0/-138) src/plugin/qmltermwidget/lib/kpty.cpp (+6/-1) src/plugin/qmltermwidget/packaging/rpm/qmltermwidget.spec (+59/-0) src/plugin/qmltermwidget/qmltermwidget.pro (+20/-0) src/plugin/qmltermwidget/src/ksession.cpp (+70/-9) src/plugin/qmltermwidget/src/ksession.h (+37/-6) src/plugin/qmltermwidget/test-app/test-app.qml (+23/-2) |
To merge this branch: | bzr merge lp:~larryprice/ubuntu-terminal-app/update-qmltermwidget |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Terminal Developers | Pending | ||
Review via email: mp+297471@code.launchpad.net |
This proposal has been superseded by a proposal from 2016-09-19.
Commit message
Update QMLTermWidget to latest version and remove duplicate konsole application code.
Description of the change
Update QMLTermWidget to latest version and remove duplicate konsole application code.
To post a comment you must log in.
- 203. By Larry Price
-
Update QMLTermWidget and remove unnecessary parts
- 204. By Larry Price
-
Merge
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/app/qml/TerminalComponent.qml' | |||
2 | --- src/app/qml/TerminalComponent.qml 2016-09-19 00:05:02 +0000 | |||
3 | +++ src/app/qml/TerminalComponent.qml 2016-09-19 14:23:50 +0000 | |||
4 | @@ -31,10 +31,6 @@ | |||
5 | 31 | font.family: settings.fontStyle | 31 | font.family: settings.fontStyle |
6 | 32 | font.pixelSize: FontUtils.sizeToPixels("medium") * settings.fontSize / 10 | 32 | font.pixelSize: FontUtils.sizeToPixels("medium") * settings.fontSize / 10 |
7 | 33 | 33 | ||
8 | 34 | // WORKAROUND: Mir/QtMir does not support drag&drop yet, therefore we need | ||
9 | 35 | // to disable this functionality (see lp:1488588). | ||
10 | 36 | dragMode: QMLTermWidget.NoDrag | ||
11 | 37 | |||
12 | 38 | signal sessionFinished(var session); | 34 | signal sessionFinished(var session); |
13 | 39 | 35 | ||
14 | 40 | session: QMLTermSession { | 36 | session: QMLTermSession { |
15 | 41 | 37 | ||
16 | === removed directory 'src/plugin/konsole' | |||
17 | === removed file 'src/plugin/konsole/BlockArray.cpp' | |||
18 | --- src/plugin/konsole/BlockArray.cpp 2014-11-12 00:10:12 +0000 | |||
19 | +++ src/plugin/konsole/BlockArray.cpp 1970-01-01 00:00:00 +0000 | |||
20 | @@ -1,377 +0,0 @@ | |||
21 | 1 | /* | ||
22 | 2 | This file is part of Konsole, an X terminal. | ||
23 | 3 | Copyright (C) 2000 by Stephan Kulow <coolo@kde.org> | ||
24 | 4 | |||
25 | 5 | Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 | ||
26 | 6 | |||
27 | 7 | This program is free software; you can redistribute it and/or modify | ||
28 | 8 | it under the terms of the GNU General Public License as published by | ||
29 | 9 | the Free Software Foundation; either version 2 of the License, or | ||
30 | 10 | (at your option) any later version. | ||
31 | 11 | |||
32 | 12 | This program is distributed in the hope that it will be useful, | ||
33 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
34 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
35 | 15 | GNU General Public License for more details. | ||
36 | 16 | |||
37 | 17 | You should have received a copy of the GNU General Public License | ||
38 | 18 | along with this program; if not, write to the Free Software | ||
39 | 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
40 | 20 | 02110-1301 USA. | ||
41 | 21 | |||
42 | 22 | */ | ||
43 | 23 | |||
44 | 24 | // Own | ||
45 | 25 | #include "BlockArray.h" | ||
46 | 26 | |||
47 | 27 | #include <QtCore> | ||
48 | 28 | |||
49 | 29 | // System | ||
50 | 30 | #include <assert.h> | ||
51 | 31 | #include <sys/mman.h> | ||
52 | 32 | #include <sys/param.h> | ||
53 | 33 | #include <unistd.h> | ||
54 | 34 | #include <stdio.h> | ||
55 | 35 | |||
56 | 36 | |||
57 | 37 | static int blocksize = 0; | ||
58 | 38 | |||
59 | 39 | BlockArray::BlockArray() | ||
60 | 40 | : size(0), | ||
61 | 41 | current(size_t(-1)), | ||
62 | 42 | index(size_t(-1)), | ||
63 | 43 | lastmap(0), | ||
64 | 44 | lastmap_index(size_t(-1)), | ||
65 | 45 | lastblock(0), ion(-1), | ||
66 | 46 | length(0) | ||
67 | 47 | { | ||
68 | 48 | // lastmap_index = index = current = size_t(-1); | ||
69 | 49 | if (blocksize == 0) { | ||
70 | 50 | blocksize = ((sizeof(Block) / getpagesize()) + 1) * getpagesize(); | ||
71 | 51 | } | ||
72 | 52 | |||
73 | 53 | } | ||
74 | 54 | |||
75 | 55 | BlockArray::~BlockArray() | ||
76 | 56 | { | ||
77 | 57 | setHistorySize(0); | ||
78 | 58 | assert(!lastblock); | ||
79 | 59 | } | ||
80 | 60 | |||
81 | 61 | size_t BlockArray::append(Block * block) | ||
82 | 62 | { | ||
83 | 63 | if (!size) { | ||
84 | 64 | return size_t(-1); | ||
85 | 65 | } | ||
86 | 66 | |||
87 | 67 | ++current; | ||
88 | 68 | if (current >= size) { | ||
89 | 69 | current = 0; | ||
90 | 70 | } | ||
91 | 71 | |||
92 | 72 | int rc; | ||
93 | 73 | rc = lseek(ion, current * blocksize, SEEK_SET); | ||
94 | 74 | if (rc < 0) { | ||
95 | 75 | perror("HistoryBuffer::add.seek"); | ||
96 | 76 | setHistorySize(0); | ||
97 | 77 | return size_t(-1); | ||
98 | 78 | } | ||
99 | 79 | rc = write(ion, block, blocksize); | ||
100 | 80 | if (rc < 0) { | ||
101 | 81 | perror("HistoryBuffer::add.write"); | ||
102 | 82 | setHistorySize(0); | ||
103 | 83 | return size_t(-1); | ||
104 | 84 | } | ||
105 | 85 | |||
106 | 86 | length++; | ||
107 | 87 | if (length > size) { | ||
108 | 88 | length = size; | ||
109 | 89 | } | ||
110 | 90 | |||
111 | 91 | ++index; | ||
112 | 92 | |||
113 | 93 | delete block; | ||
114 | 94 | return current; | ||
115 | 95 | } | ||
116 | 96 | |||
117 | 97 | size_t BlockArray::newBlock() | ||
118 | 98 | { | ||
119 | 99 | if (!size) { | ||
120 | 100 | return size_t(-1); | ||
121 | 101 | } | ||
122 | 102 | append(lastblock); | ||
123 | 103 | |||
124 | 104 | lastblock = new Block(); | ||
125 | 105 | return index + 1; | ||
126 | 106 | } | ||
127 | 107 | |||
128 | 108 | Block * BlockArray::lastBlock() const | ||
129 | 109 | { | ||
130 | 110 | return lastblock; | ||
131 | 111 | } | ||
132 | 112 | |||
133 | 113 | bool BlockArray::has(size_t i) const | ||
134 | 114 | { | ||
135 | 115 | if (i == index + 1) { | ||
136 | 116 | return true; | ||
137 | 117 | } | ||
138 | 118 | |||
139 | 119 | if (i > index) { | ||
140 | 120 | return false; | ||
141 | 121 | } | ||
142 | 122 | if (index - i >= length) { | ||
143 | 123 | return false; | ||
144 | 124 | } | ||
145 | 125 | return true; | ||
146 | 126 | } | ||
147 | 127 | |||
148 | 128 | const Block * BlockArray::at(size_t i) | ||
149 | 129 | { | ||
150 | 130 | if (i == index + 1) { | ||
151 | 131 | return lastblock; | ||
152 | 132 | } | ||
153 | 133 | |||
154 | 134 | if (i == lastmap_index) { | ||
155 | 135 | return lastmap; | ||
156 | 136 | } | ||
157 | 137 | |||
158 | 138 | if (i > index) { | ||
159 | 139 | qDebug() << "BlockArray::at() i > index\n"; | ||
160 | 140 | return 0; | ||
161 | 141 | } | ||
162 | 142 | |||
163 | 143 | // if (index - i >= length) { | ||
164 | 144 | // kDebug(1211) << "BlockArray::at() index - i >= length\n"; | ||
165 | 145 | // return 0; | ||
166 | 146 | // } | ||
167 | 147 | |||
168 | 148 | size_t j = i; // (current - (index - i) + (index/size+1)*size) % size ; | ||
169 | 149 | |||
170 | 150 | assert(j < size); | ||
171 | 151 | unmap(); | ||
172 | 152 | |||
173 | 153 | Block * block = (Block *)mmap(0, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize); | ||
174 | 154 | |||
175 | 155 | if (block == (Block *)-1) { | ||
176 | 156 | perror("mmap"); | ||
177 | 157 | return 0; | ||
178 | 158 | } | ||
179 | 159 | |||
180 | 160 | lastmap = block; | ||
181 | 161 | lastmap_index = i; | ||
182 | 162 | |||
183 | 163 | return block; | ||
184 | 164 | } | ||
185 | 165 | |||
186 | 166 | void BlockArray::unmap() | ||
187 | 167 | { | ||
188 | 168 | if (lastmap) { | ||
189 | 169 | int res = munmap((char *)lastmap, blocksize); | ||
190 | 170 | if (res < 0) { | ||
191 | 171 | perror("munmap"); | ||
192 | 172 | } | ||
193 | 173 | } | ||
194 | 174 | lastmap = 0; | ||
195 | 175 | lastmap_index = size_t(-1); | ||
196 | 176 | } | ||
197 | 177 | |||
198 | 178 | bool BlockArray::setSize(size_t newsize) | ||
199 | 179 | { | ||
200 | 180 | return setHistorySize(newsize * 1024 / blocksize); | ||
201 | 181 | } | ||
202 | 182 | |||
203 | 183 | bool BlockArray::setHistorySize(size_t newsize) | ||
204 | 184 | { | ||
205 | 185 | // kDebug(1211) << "setHistorySize " << size << " " << newsize; | ||
206 | 186 | |||
207 | 187 | if (size == newsize) { | ||
208 | 188 | return false; | ||
209 | 189 | } | ||
210 | 190 | |||
211 | 191 | unmap(); | ||
212 | 192 | |||
213 | 193 | if (!newsize) { | ||
214 | 194 | delete lastblock; | ||
215 | 195 | lastblock = 0; | ||
216 | 196 | if (ion >= 0) { | ||
217 | 197 | close(ion); | ||
218 | 198 | } | ||
219 | 199 | ion = -1; | ||
220 | 200 | current = size_t(-1); | ||
221 | 201 | return true; | ||
222 | 202 | } | ||
223 | 203 | |||
224 | 204 | if (!size) { | ||
225 | 205 | FILE * tmp = tmpfile(); | ||
226 | 206 | if (!tmp) { | ||
227 | 207 | perror("konsole: cannot open temp file.\n"); | ||
228 | 208 | } else { | ||
229 | 209 | ion = dup(fileno(tmp)); | ||
230 | 210 | if (ion<0) { | ||
231 | 211 | perror("konsole: cannot dup temp file.\n"); | ||
232 | 212 | fclose(tmp); | ||
233 | 213 | } | ||
234 | 214 | } | ||
235 | 215 | if (ion < 0) { | ||
236 | 216 | return false; | ||
237 | 217 | } | ||
238 | 218 | |||
239 | 219 | assert(!lastblock); | ||
240 | 220 | |||
241 | 221 | lastblock = new Block(); | ||
242 | 222 | size = newsize; | ||
243 | 223 | return false; | ||
244 | 224 | } | ||
245 | 225 | |||
246 | 226 | if (newsize > size) { | ||
247 | 227 | increaseBuffer(); | ||
248 | 228 | size = newsize; | ||
249 | 229 | return false; | ||
250 | 230 | } else { | ||
251 | 231 | decreaseBuffer(newsize); | ||
252 | 232 | ftruncate(ion, length*blocksize); | ||
253 | 233 | size = newsize; | ||
254 | 234 | |||
255 | 235 | return true; | ||
256 | 236 | } | ||
257 | 237 | } | ||
258 | 238 | |||
259 | 239 | void moveBlock(FILE * fion, int cursor, int newpos, char * buffer2) | ||
260 | 240 | { | ||
261 | 241 | int res = fseek(fion, cursor * blocksize, SEEK_SET); | ||
262 | 242 | if (res) { | ||
263 | 243 | perror("fseek"); | ||
264 | 244 | } | ||
265 | 245 | res = fread(buffer2, blocksize, 1, fion); | ||
266 | 246 | if (res != 1) { | ||
267 | 247 | perror("fread"); | ||
268 | 248 | } | ||
269 | 249 | |||
270 | 250 | res = fseek(fion, newpos * blocksize, SEEK_SET); | ||
271 | 251 | if (res) { | ||
272 | 252 | perror("fseek"); | ||
273 | 253 | } | ||
274 | 254 | res = fwrite(buffer2, blocksize, 1, fion); | ||
275 | 255 | if (res != 1) { | ||
276 | 256 | perror("fwrite"); | ||
277 | 257 | } | ||
278 | 258 | // printf("moving block %d to %d\n", cursor, newpos); | ||
279 | 259 | } | ||
280 | 260 | |||
281 | 261 | void BlockArray::decreaseBuffer(size_t newsize) | ||
282 | 262 | { | ||
283 | 263 | if (index < newsize) { // still fits in whole | ||
284 | 264 | return; | ||
285 | 265 | } | ||
286 | 266 | |||
287 | 267 | int offset = (current - (newsize - 1) + size) % size; | ||
288 | 268 | |||
289 | 269 | if (!offset) { | ||
290 | 270 | return; | ||
291 | 271 | } | ||
292 | 272 | |||
293 | 273 | // The Block constructor could do somthing in future... | ||
294 | 274 | char * buffer1 = new char[blocksize]; | ||
295 | 275 | |||
296 | 276 | FILE * fion = fdopen(dup(ion), "w+b"); | ||
297 | 277 | if (!fion) { | ||
298 | 278 | delete [] buffer1; | ||
299 | 279 | perror("fdopen/dup"); | ||
300 | 280 | return; | ||
301 | 281 | } | ||
302 | 282 | |||
303 | 283 | int firstblock; | ||
304 | 284 | if (current <= newsize) { | ||
305 | 285 | firstblock = current + 1; | ||
306 | 286 | } else { | ||
307 | 287 | firstblock = 0; | ||
308 | 288 | } | ||
309 | 289 | |||
310 | 290 | size_t oldpos; | ||
311 | 291 | for (size_t i = 0, cursor=firstblock; i < newsize; i++) { | ||
312 | 292 | oldpos = (size + cursor + offset) % size; | ||
313 | 293 | moveBlock(fion, oldpos, cursor, buffer1); | ||
314 | 294 | if (oldpos < newsize) { | ||
315 | 295 | cursor = oldpos; | ||
316 | 296 | } else { | ||
317 | 297 | cursor++; | ||
318 | 298 | } | ||
319 | 299 | } | ||
320 | 300 | |||
321 | 301 | current = newsize - 1; | ||
322 | 302 | length = newsize; | ||
323 | 303 | |||
324 | 304 | delete [] buffer1; | ||
325 | 305 | |||
326 | 306 | fclose(fion); | ||
327 | 307 | |||
328 | 308 | } | ||
329 | 309 | |||
330 | 310 | void BlockArray::increaseBuffer() | ||
331 | 311 | { | ||
332 | 312 | if (index < size) { // not even wrapped once | ||
333 | 313 | return; | ||
334 | 314 | } | ||
335 | 315 | |||
336 | 316 | int offset = (current + size + 1) % size; | ||
337 | 317 | if (!offset) { // no moving needed | ||
338 | 318 | return; | ||
339 | 319 | } | ||
340 | 320 | |||
341 | 321 | // The Block constructor could do somthing in future... | ||
342 | 322 | char * buffer1 = new char[blocksize]; | ||
343 | 323 | char * buffer2 = new char[blocksize]; | ||
344 | 324 | |||
345 | 325 | int runs = 1; | ||
346 | 326 | int bpr = size; // blocks per run | ||
347 | 327 | |||
348 | 328 | if (size % offset == 0) { | ||
349 | 329 | bpr = size / offset; | ||
350 | 330 | runs = offset; | ||
351 | 331 | } | ||
352 | 332 | |||
353 | 333 | FILE * fion = fdopen(dup(ion), "w+b"); | ||
354 | 334 | if (!fion) { | ||
355 | 335 | perror("fdopen/dup"); | ||
356 | 336 | delete [] buffer1; | ||
357 | 337 | delete [] buffer2; | ||
358 | 338 | return; | ||
359 | 339 | } | ||
360 | 340 | |||
361 | 341 | int res; | ||
362 | 342 | for (int i = 0; i < runs; i++) { | ||
363 | 343 | // free one block in chain | ||
364 | 344 | int firstblock = (offset + i) % size; | ||
365 | 345 | res = fseek(fion, firstblock * blocksize, SEEK_SET); | ||
366 | 346 | if (res) { | ||
367 | 347 | perror("fseek"); | ||
368 | 348 | } | ||
369 | 349 | res = fread(buffer1, blocksize, 1, fion); | ||
370 | 350 | if (res != 1) { | ||
371 | 351 | perror("fread"); | ||
372 | 352 | } | ||
373 | 353 | int newpos = 0; | ||
374 | 354 | for (int j = 1, cursor=firstblock; j < bpr; j++) { | ||
375 | 355 | cursor = (cursor + offset) % size; | ||
376 | 356 | newpos = (cursor - offset + size) % size; | ||
377 | 357 | moveBlock(fion, cursor, newpos, buffer2); | ||
378 | 358 | } | ||
379 | 359 | res = fseek(fion, i * blocksize, SEEK_SET); | ||
380 | 360 | if (res) { | ||
381 | 361 | perror("fseek"); | ||
382 | 362 | } | ||
383 | 363 | res = fwrite(buffer1, blocksize, 1, fion); | ||
384 | 364 | if (res != 1) { | ||
385 | 365 | perror("fwrite"); | ||
386 | 366 | } | ||
387 | 367 | } | ||
388 | 368 | current = size - 1; | ||
389 | 369 | length = size; | ||
390 | 370 | |||
391 | 371 | delete [] buffer1; | ||
392 | 372 | delete [] buffer2; | ||
393 | 373 | |||
394 | 374 | fclose(fion); | ||
395 | 375 | |||
396 | 376 | } | ||
397 | 377 | |||
398 | 378 | 0 | ||
399 | === removed file 'src/plugin/konsole/BlockArray.h' | |||
400 | --- src/plugin/konsole/BlockArray.h 2014-11-12 00:10:12 +0000 | |||
401 | +++ src/plugin/konsole/BlockArray.h 1970-01-01 00:00:00 +0000 | |||
402 | @@ -1,126 +0,0 @@ | |||
403 | 1 | /* | ||
404 | 2 | This file is part of Konsole, an X terminal. | ||
405 | 3 | Copyright (C) 2000 by Stephan Kulow <coolo@kde.org> | ||
406 | 4 | |||
407 | 5 | Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 | ||
408 | 6 | |||
409 | 7 | This program is free software; you can redistribute it and/or modify | ||
410 | 8 | it under the terms of the GNU General Public License as published by | ||
411 | 9 | the Free Software Foundation; either version 2 of the License, or | ||
412 | 10 | (at your option) any later version. | ||
413 | 11 | |||
414 | 12 | This program is distributed in the hope that it will be useful, | ||
415 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
416 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
417 | 15 | GNU General Public License for more details. | ||
418 | 16 | |||
419 | 17 | You should have received a copy of the GNU General Public License | ||
420 | 18 | along with this program; if not, write to the Free Software | ||
421 | 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
422 | 20 | 02110-1301 USA. | ||
423 | 21 | */ | ||
424 | 22 | |||
425 | 23 | #ifndef BLOCKARRAY_H | ||
426 | 24 | #define BLOCKARRAY_H | ||
427 | 25 | |||
428 | 26 | #include <unistd.h> | ||
429 | 27 | |||
430 | 28 | //#error Do not use in KDE 2.1 | ||
431 | 29 | |||
432 | 30 | #define BlockSize (1 << 12) | ||
433 | 31 | #define ENTRIES ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char)) | ||
434 | 32 | |||
435 | 33 | struct Block { | ||
436 | 34 | Block() { | ||
437 | 35 | size = 0; | ||
438 | 36 | } | ||
439 | 37 | unsigned char data[ENTRIES]; | ||
440 | 38 | size_t size; | ||
441 | 39 | }; | ||
442 | 40 | |||
443 | 41 | // /////////////////////////////////////////////////////// | ||
444 | 42 | |||
445 | 43 | class BlockArray { | ||
446 | 44 | public: | ||
447 | 45 | /** | ||
448 | 46 | * Creates a history file for holding | ||
449 | 47 | * maximal size blocks. If more blocks | ||
450 | 48 | * are requested, then it drops earlier | ||
451 | 49 | * added ones. | ||
452 | 50 | */ | ||
453 | 51 | BlockArray(); | ||
454 | 52 | |||
455 | 53 | /// destructor | ||
456 | 54 | ~BlockArray(); | ||
457 | 55 | |||
458 | 56 | /** | ||
459 | 57 | * adds the Block at the end of history. | ||
460 | 58 | * This may drop other blocks. | ||
461 | 59 | * | ||
462 | 60 | * The ownership on the block is transfered. | ||
463 | 61 | * An unique index number is returned for accessing | ||
464 | 62 | * it later (if not yet dropped then) | ||
465 | 63 | * | ||
466 | 64 | * Note, that the block may be dropped completely | ||
467 | 65 | * if history is turned off. | ||
468 | 66 | */ | ||
469 | 67 | size_t append(Block * block); | ||
470 | 68 | |||
471 | 69 | /** | ||
472 | 70 | * gets the block at the index. Function may return | ||
473 | 71 | * 0 if the block isn't available any more. | ||
474 | 72 | * | ||
475 | 73 | * The returned block is strictly readonly as only | ||
476 | 74 | * maped in memory - and will be invalid on the next | ||
477 | 75 | * operation on this class. | ||
478 | 76 | */ | ||
479 | 77 | const Block * at(size_t index); | ||
480 | 78 | |||
481 | 79 | /** | ||
482 | 80 | * reorders blocks as needed. If newsize is null, | ||
483 | 81 | * the history is emptied completely. The indices | ||
484 | 82 | * returned on append won't change their semantic, | ||
485 | 83 | * but they may not be valid after this call. | ||
486 | 84 | */ | ||
487 | 85 | bool setHistorySize(size_t newsize); | ||
488 | 86 | |||
489 | 87 | size_t newBlock(); | ||
490 | 88 | |||
491 | 89 | Block * lastBlock() const; | ||
492 | 90 | |||
493 | 91 | /** | ||
494 | 92 | * Convenient function to set the size in KBytes | ||
495 | 93 | * instead of blocks | ||
496 | 94 | */ | ||
497 | 95 | bool setSize(size_t newsize); | ||
498 | 96 | |||
499 | 97 | size_t len() const { | ||
500 | 98 | return length; | ||
501 | 99 | } | ||
502 | 100 | |||
503 | 101 | bool has(size_t index) const; | ||
504 | 102 | |||
505 | 103 | size_t getCurrent() const { | ||
506 | 104 | return current; | ||
507 | 105 | } | ||
508 | 106 | |||
509 | 107 | private: | ||
510 | 108 | void unmap(); | ||
511 | 109 | void increaseBuffer(); | ||
512 | 110 | void decreaseBuffer(size_t newsize); | ||
513 | 111 | |||
514 | 112 | size_t size; | ||
515 | 113 | // current always shows to the last inserted block | ||
516 | 114 | size_t current; | ||
517 | 115 | size_t index; | ||
518 | 116 | |||
519 | 117 | Block * lastmap; | ||
520 | 118 | size_t lastmap_index; | ||
521 | 119 | Block * lastblock; | ||
522 | 120 | |||
523 | 121 | int ion; | ||
524 | 122 | size_t length; | ||
525 | 123 | |||
526 | 124 | }; | ||
527 | 125 | |||
528 | 126 | #endif | ||
529 | 127 | 0 | ||
530 | === removed file 'src/plugin/konsole/CMakeLists.txt' | |||
531 | --- src/plugin/konsole/CMakeLists.txt 2014-11-12 00:10:12 +0000 | |||
532 | +++ src/plugin/konsole/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
533 | @@ -1,93 +0,0 @@ | |||
534 | 1 | include_directories( | ||
535 | 2 | ${CMAKE_CURRENT_SOURCE_DIR} | ||
536 | 3 | ) | ||
537 | 4 | |||
538 | 5 | set(PLUGIN_DIR org/kde/konsole) | ||
539 | 6 | add_definitions(-DHAVE_POSIX_OPENPT -DHAVE_SYS_TIME_H -DHAVE_UPDWTMPX) | ||
540 | 7 | add_definitions(-DQ_WS_UBUNTU) | ||
541 | 8 | |||
542 | 9 | set(konsole_SRCS | ||
543 | 10 | BlockArray.cpp | ||
544 | 11 | BlockArray.h | ||
545 | 12 | CharacterColor.h | ||
546 | 13 | Character.h | ||
547 | 14 | ColorScheme.cpp | ||
548 | 15 | ColorScheme.h | ||
549 | 16 | ColorTables.h | ||
550 | 17 | DefaultTranslatorText.h | ||
551 | 18 | Emulation.cpp | ||
552 | 19 | Emulation.h | ||
553 | 20 | ExtendedDefaultTranslator.h | ||
554 | 21 | Filter.cpp | ||
555 | 22 | Filter.h | ||
556 | 23 | History.cpp | ||
557 | 24 | History.h | ||
558 | 25 | KeyboardTranslator.cpp | ||
559 | 26 | KeyboardTranslator.h | ||
560 | 27 | konsole_wcwidth.cpp | ||
561 | 28 | konsole_wcwidth.h | ||
562 | 29 | kprocess.cpp | ||
563 | 30 | kprocess.h | ||
564 | 31 | kpty.cpp | ||
565 | 32 | kptydevice.cpp | ||
566 | 33 | kptydevice.h | ||
567 | 34 | kpty.h | ||
568 | 35 | kpty_p.h | ||
569 | 36 | kptyprocess.cpp | ||
570 | 37 | kptyprocess.h | ||
571 | 38 | ksession.cpp | ||
572 | 39 | ksession.h | ||
573 | 40 | LineFont.h | ||
574 | 41 | plugin.cpp | ||
575 | 42 | plugin.h | ||
576 | 43 | Pty.cpp | ||
577 | 44 | Pty.h | ||
578 | 45 | Screen.cpp | ||
579 | 46 | Screen.h | ||
580 | 47 | ScreenWindow.cpp | ||
581 | 48 | ScreenWindow.h | ||
582 | 49 | Session.cpp | ||
583 | 50 | Session.h | ||
584 | 51 | ShellCommand.cpp | ||
585 | 52 | ShellCommand.h | ||
586 | 53 | TerminalCharacterDecoder.cpp | ||
587 | 54 | TerminalCharacterDecoder.h | ||
588 | 55 | TerminalDisplay.cpp | ||
589 | 56 | TerminalDisplay.h | ||
590 | 57 | tools.cpp | ||
591 | 58 | tools.h | ||
592 | 59 | Vt102Emulation.cpp | ||
593 | 60 | Vt102Emulation.h | ||
594 | 61 | ) | ||
595 | 62 | |||
596 | 63 | add_library(kdekonsole MODULE | ||
597 | 64 | ${konsole_SRCS} | ||
598 | 65 | ) | ||
599 | 66 | |||
600 | 67 | qt5_use_modules(kdekonsole Gui Qml Quick Widgets) | ||
601 | 68 | |||
602 | 69 | # Copy the plugin, the qmldir file and other assets to the build dir for running in QtCreator | ||
603 | 70 | if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") | ||
604 | 71 | add_custom_target(konsole-qmldir ALL | ||
605 | 72 | COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR} | ||
606 | 73 | DEPENDS ${QMLFILES} | ||
607 | 74 | ) | ||
608 | 75 | add_custom_target(konsole-layouts-schemes ALL | ||
609 | 76 | COMMAND cp -a ${CMAKE_CURRENT_SOURCE_DIR}/assets/color-schemes ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR} | ||
610 | 77 | COMMAND cp -a ${CMAKE_CURRENT_SOURCE_DIR}/assets/kb-layouts ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR} | ||
611 | 78 | DEPENDS ${QMLFILES} | ||
612 | 79 | ) | ||
613 | 80 | add_custom_command(TARGET kdekonsole POST_BUILD | ||
614 | 81 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR} | ||
615 | 82 | COMMENT "Creating plugin directory layout in the build dir" | ||
616 | 83 | COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:kdekonsole> ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR} | ||
617 | 84 | COMMENT "Copying to output directory" | ||
618 | 85 | ) | ||
619 | 86 | endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") | ||
620 | 87 | |||
621 | 88 | |||
622 | 89 | install(TARGETS kdekonsole DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN_DIR}) | ||
623 | 90 | install(FILES qmldir DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN_DIR}) | ||
624 | 91 | install(DIRECTORY assets/color-schemes DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN_DIR}) | ||
625 | 92 | install(DIRECTORY assets/kb-layouts DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN_DIR}) | ||
626 | 93 | |||
627 | 94 | 0 | ||
628 | === removed file 'src/plugin/konsole/Character.h' | |||
629 | --- src/plugin/konsole/Character.h 2014-11-12 00:10:12 +0000 | |||
630 | +++ src/plugin/konsole/Character.h 1970-01-01 00:00:00 +0000 | |||
631 | @@ -1,221 +0,0 @@ | |||
632 | 1 | /* | ||
633 | 2 | This file is part of Konsole, KDE's terminal. | ||
634 | 3 | |||
635 | 4 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
636 | 5 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> | ||
637 | 6 | |||
638 | 7 | This program is free software; you can redistribute it and/or modify | ||
639 | 8 | it under the terms of the GNU General Public License as published by | ||
640 | 9 | the Free Software Foundation; either version 2 of the License, or | ||
641 | 10 | (at your option) any later version. | ||
642 | 11 | |||
643 | 12 | This program is distributed in the hope that it will be useful, | ||
644 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
645 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
646 | 15 | GNU General Public License for more details. | ||
647 | 16 | |||
648 | 17 | You should have received a copy of the GNU General Public License | ||
649 | 18 | along with this program; if not, write to the Free Software | ||
650 | 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
651 | 20 | 02110-1301 USA. | ||
652 | 21 | */ | ||
653 | 22 | |||
654 | 23 | #ifndef CHARACTER_H | ||
655 | 24 | #define CHARACTER_H | ||
656 | 25 | |||
657 | 26 | // Qt | ||
658 | 27 | #include <QtCore/QHash> | ||
659 | 28 | |||
660 | 29 | // Local | ||
661 | 30 | #include "CharacterColor.h" | ||
662 | 31 | |||
663 | 32 | typedef unsigned char LineProperty; | ||
664 | 33 | |||
665 | 34 | static const int LINE_DEFAULT = 0; | ||
666 | 35 | static const int LINE_WRAPPED = (1 << 0); | ||
667 | 36 | static const int LINE_DOUBLEWIDTH = (1 << 1); | ||
668 | 37 | static const int LINE_DOUBLEHEIGHT = (1 << 2); | ||
669 | 38 | |||
670 | 39 | #define DEFAULT_RENDITION 0 | ||
671 | 40 | #define RE_BOLD (1 << 0) | ||
672 | 41 | #define RE_BLINK (1 << 1) | ||
673 | 42 | #define RE_UNDERLINE (1 << 2) | ||
674 | 43 | #define RE_REVERSE (1 << 3) // Screen only | ||
675 | 44 | #define RE_INTENSIVE (1 << 3) // Widget only | ||
676 | 45 | #define RE_CURSOR (1 << 4) | ||
677 | 46 | #define RE_EXTENDED_CHAR (1 << 5) | ||
678 | 47 | |||
679 | 48 | /** | ||
680 | 49 | * A single character in the terminal which consists of a unicode character | ||
681 | 50 | * value, foreground and background colors and a set of rendition attributes | ||
682 | 51 | * which specify how it should be drawn. | ||
683 | 52 | */ | ||
684 | 53 | class Character | ||
685 | 54 | { | ||
686 | 55 | public: | ||
687 | 56 | /** | ||
688 | 57 | * Constructs a new character. | ||
689 | 58 | * | ||
690 | 59 | * @param _c The unicode character value of this character. | ||
691 | 60 | * @param _f The foreground color used to draw the character. | ||
692 | 61 | * @param _b The color used to draw the character's background. | ||
693 | 62 | * @param _r A set of rendition flags which specify how this character is to be drawn. | ||
694 | 63 | */ | ||
695 | 64 | inline Character(quint16 _c = ' ', | ||
696 | 65 | CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR), | ||
697 | 66 | CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_BACK_COLOR), | ||
698 | 67 | quint8 _r = DEFAULT_RENDITION) | ||
699 | 68 | : character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {} | ||
700 | 69 | |||
701 | 70 | union | ||
702 | 71 | { | ||
703 | 72 | /** The unicode character value for this character. */ | ||
704 | 73 | quint16 character; | ||
705 | 74 | /** | ||
706 | 75 | * Experimental addition which allows a single Character instance to contain more than | ||
707 | 76 | * one unicode character. | ||
708 | 77 | * | ||
709 | 78 | * charSequence is a hash code which can be used to look up the unicode | ||
710 | 79 | * character sequence in the ExtendedCharTable used to create the sequence. | ||
711 | 80 | */ | ||
712 | 81 | quint16 charSequence; | ||
713 | 82 | }; | ||
714 | 83 | |||
715 | 84 | /** A combination of RENDITION flags which specify options for drawing the character. */ | ||
716 | 85 | quint8 rendition; | ||
717 | 86 | |||
718 | 87 | /** The foreground color used to draw this character. */ | ||
719 | 88 | CharacterColor foregroundColor; | ||
720 | 89 | /** The color used to draw this character's background. */ | ||
721 | 90 | CharacterColor backgroundColor; | ||
722 | 91 | |||
723 | 92 | /** | ||
724 | 93 | * Returns true if this character has a transparent background when | ||
725 | 94 | * it is drawn with the specified @p palette. | ||
726 | 95 | */ | ||
727 | 96 | bool isTransparent(const ColorEntry* palette) const; | ||
728 | 97 | /** | ||
729 | 98 | * Returns true if this character should always be drawn in bold when | ||
730 | 99 | * it is drawn with the specified @p palette, independent of whether | ||
731 | 100 | * or not the character has the RE_BOLD rendition flag. | ||
732 | 101 | */ | ||
733 | 102 | ColorEntry::FontWeight fontWeight(const ColorEntry* base) const; | ||
734 | 103 | |||
735 | 104 | /** | ||
736 | 105 | * returns true if the format (color, rendition flag) of the compared characters is equal | ||
737 | 106 | */ | ||
738 | 107 | bool equalsFormat(const Character &other) const; | ||
739 | 108 | |||
740 | 109 | /** | ||
741 | 110 | * Compares two characters and returns true if they have the same unicode character value, | ||
742 | 111 | * rendition and colors. | ||
743 | 112 | */ | ||
744 | 113 | friend bool operator == (const Character& a, const Character& b); | ||
745 | 114 | /** | ||
746 | 115 | * Compares two characters and returns true if they have different unicode character values, | ||
747 | 116 | * renditions or colors. | ||
748 | 117 | */ | ||
749 | 118 | friend bool operator != (const Character& a, const Character& b); | ||
750 | 119 | }; | ||
751 | 120 | |||
752 | 121 | inline bool operator == (const Character& a, const Character& b) | ||
753 | 122 | { | ||
754 | 123 | return a.character == b.character && | ||
755 | 124 | a.rendition == b.rendition && | ||
756 | 125 | a.foregroundColor == b.foregroundColor && | ||
757 | 126 | a.backgroundColor == b.backgroundColor; | ||
758 | 127 | } | ||
759 | 128 | |||
760 | 129 | inline bool operator != (const Character& a, const Character& b) | ||
761 | 130 | { | ||
762 | 131 | return a.character != b.character || | ||
763 | 132 | a.rendition != b.rendition || | ||
764 | 133 | a.foregroundColor != b.foregroundColor || | ||
765 | 134 | a.backgroundColor != b.backgroundColor; | ||
766 | 135 | } | ||
767 | 136 | |||
768 | 137 | inline bool Character::isTransparent(const ColorEntry* base) const | ||
769 | 138 | { | ||
770 | 139 | return ((backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) && | ||
771 | 140 | base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].transparent) | ||
772 | 141 | || ((backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) && | ||
773 | 142 | base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].transparent); | ||
774 | 143 | } | ||
775 | 144 | |||
776 | 145 | inline bool Character::equalsFormat(const Character& other) const | ||
777 | 146 | { | ||
778 | 147 | return | ||
779 | 148 | backgroundColor==other.backgroundColor && | ||
780 | 149 | foregroundColor==other.foregroundColor && | ||
781 | 150 | rendition==other.rendition; | ||
782 | 151 | } | ||
783 | 152 | |||
784 | 153 | inline ColorEntry::FontWeight Character::fontWeight(const ColorEntry* base) const | ||
785 | 154 | { | ||
786 | 155 | if (backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) | ||
787 | 156 | return base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].fontWeight; | ||
788 | 157 | else if (backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) | ||
789 | 158 | return base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].fontWeight; | ||
790 | 159 | else | ||
791 | 160 | return ColorEntry::UseCurrentFormat; | ||
792 | 161 | } | ||
793 | 162 | |||
794 | 163 | extern unsigned short vt100_graphics[32]; | ||
795 | 164 | |||
796 | 165 | |||
797 | 166 | /** | ||
798 | 167 | * A table which stores sequences of unicode characters, referenced | ||
799 | 168 | * by hash keys. The hash key itself is the same size as a unicode | ||
800 | 169 | * character ( ushort ) so that it can occupy the same space in | ||
801 | 170 | * a structure. | ||
802 | 171 | */ | ||
803 | 172 | class ExtendedCharTable | ||
804 | 173 | { | ||
805 | 174 | public: | ||
806 | 175 | /** Constructs a new character table. */ | ||
807 | 176 | ExtendedCharTable(); | ||
808 | 177 | ~ExtendedCharTable(); | ||
809 | 178 | |||
810 | 179 | /** | ||
811 | 180 | * Adds a sequences of unicode characters to the table and returns | ||
812 | 181 | * a hash code which can be used later to look up the sequence | ||
813 | 182 | * using lookupExtendedChar() | ||
814 | 183 | * | ||
815 | 184 | * If the same sequence already exists in the table, the hash | ||
816 | 185 | * of the existing sequence will be returned. | ||
817 | 186 | * | ||
818 | 187 | * @param unicodePoints An array of unicode character points | ||
819 | 188 | * @param length Length of @p unicodePoints | ||
820 | 189 | */ | ||
821 | 190 | ushort createExtendedChar(ushort* unicodePoints , ushort length); | ||
822 | 191 | /** | ||
823 | 192 | * Looks up and returns a pointer to a sequence of unicode characters | ||
824 | 193 | * which was added to the table using createExtendedChar(). | ||
825 | 194 | * | ||
826 | 195 | * @param hash The hash key returned by createExtendedChar() | ||
827 | 196 | * @param length This variable is set to the length of the | ||
828 | 197 | * character sequence. | ||
829 | 198 | * | ||
830 | 199 | * @return A unicode character sequence of size @p length. | ||
831 | 200 | */ | ||
832 | 201 | ushort* lookupExtendedChar(ushort hash , ushort& length) const; | ||
833 | 202 | |||
834 | 203 | /** The global ExtendedCharTable instance. */ | ||
835 | 204 | static ExtendedCharTable instance; | ||
836 | 205 | private: | ||
837 | 206 | // calculates the hash key of a sequence of unicode points of size 'length' | ||
838 | 207 | ushort extendedCharHash(ushort* unicodePoints , ushort length) const; | ||
839 | 208 | // tests whether the entry in the table specified by 'hash' matches the | ||
840 | 209 | // character sequence 'unicodePoints' of size 'length' | ||
841 | 210 | bool extendedCharMatch(ushort hash , ushort* unicodePoints , ushort length) const; | ||
842 | 211 | // internal, maps hash keys to character sequence buffers. The first ushort | ||
843 | 212 | // in each value is the length of the buffer, followed by the ushorts in the buffer | ||
844 | 213 | // themselves. | ||
845 | 214 | QHash<ushort,ushort*> extendedCharTable; | ||
846 | 215 | }; | ||
847 | 216 | |||
848 | 217 | |||
849 | 218 | Q_DECLARE_TYPEINFO(Character, Q_MOVABLE_TYPE); | ||
850 | 219 | |||
851 | 220 | #endif // CHARACTER_H | ||
852 | 221 | |||
853 | 222 | 0 | ||
854 | === removed file 'src/plugin/konsole/CharacterColor.h' | |||
855 | --- src/plugin/konsole/CharacterColor.h 2014-11-12 00:10:12 +0000 | |||
856 | +++ src/plugin/konsole/CharacterColor.h 1970-01-01 00:00:00 +0000 | |||
857 | @@ -1,294 +0,0 @@ | |||
858 | 1 | /* | ||
859 | 2 | This file is part of Konsole, KDE's terminal. | ||
860 | 3 | |||
861 | 4 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
862 | 5 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> | ||
863 | 6 | |||
864 | 7 | This program is free software; you can redistribute it and/or modify | ||
865 | 8 | it under the terms of the GNU General Public License as published by | ||
866 | 9 | the Free Software Foundation; either version 2 of the License, or | ||
867 | 10 | (at your option) any later version. | ||
868 | 11 | |||
869 | 12 | This program is distributed in the hope that it will be useful, | ||
870 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
871 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
872 | 15 | GNU General Public License for more details. | ||
873 | 16 | |||
874 | 17 | You should have received a copy of the GNU General Public License | ||
875 | 18 | along with this program; if not, write to the Free Software | ||
876 | 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
877 | 20 | 02110-1301 USA. | ||
878 | 21 | */ | ||
879 | 22 | |||
880 | 23 | #ifndef CHARACTERCOLOR_H | ||
881 | 24 | #define CHARACTERCOLOR_H | ||
882 | 25 | |||
883 | 26 | // Qt | ||
884 | 27 | #include <QtGui/QColor> | ||
885 | 28 | |||
886 | 29 | //#include <kdemacros.h> | ||
887 | 30 | #define KDE_NO_EXPORT | ||
888 | 31 | |||
889 | 32 | /** | ||
890 | 33 | * An entry in a terminal display's color palette. | ||
891 | 34 | * | ||
892 | 35 | * A color palette is an array of 16 ColorEntry instances which map | ||
893 | 36 | * system color indexes (from 0 to 15) into actual colors. | ||
894 | 37 | * | ||
895 | 38 | * Each entry can be set as bold, in which case any text | ||
896 | 39 | * drawn using the color should be drawn in bold. | ||
897 | 40 | * | ||
898 | 41 | * Each entry can also be transparent, in which case the terminal | ||
899 | 42 | * display should avoid drawing the background for any characters | ||
900 | 43 | * using the entry as a background. | ||
901 | 44 | */ | ||
902 | 45 | class ColorEntry | ||
903 | 46 | { | ||
904 | 47 | public: | ||
905 | 48 | /** Specifies the weight to use when drawing text with this color. */ | ||
906 | 49 | enum FontWeight | ||
907 | 50 | { | ||
908 | 51 | /** Always draw text in this color with a bold weight. */ | ||
909 | 52 | Bold, | ||
910 | 53 | /** Always draw text in this color with a normal weight. */ | ||
911 | 54 | Normal, | ||
912 | 55 | /** | ||
913 | 56 | * Use the current font weight set by the terminal application. | ||
914 | 57 | * This is the default behavior. | ||
915 | 58 | */ | ||
916 | 59 | UseCurrentFormat | ||
917 | 60 | }; | ||
918 | 61 | |||
919 | 62 | /** | ||
920 | 63 | * Constructs a new color palette entry. | ||
921 | 64 | * | ||
922 | 65 | * @param c The color value for this entry. | ||
923 | 66 | * @param tr Specifies that the color should be transparent when used as a background color. | ||
924 | 67 | * @param weight Specifies the font weight to use when drawing text with this color. | ||
925 | 68 | */ | ||
926 | 69 | ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat) | ||
927 | 70 | : color(c), transparent(tr), fontWeight(weight) {} | ||
928 | 71 | |||
929 | 72 | /** | ||
930 | 73 | * Constructs a new color palette entry with an undefined color, and | ||
931 | 74 | * with the transparent and bold flags set to false. | ||
932 | 75 | */ | ||
933 | 76 | ColorEntry() : transparent(false), fontWeight(UseCurrentFormat) {} | ||
934 | 77 | |||
935 | 78 | /** | ||
936 | 79 | * Sets the color, transparency and boldness of this color to those of @p rhs. | ||
937 | 80 | */ | ||
938 | 81 | void operator=(const ColorEntry& rhs) | ||
939 | 82 | { | ||
940 | 83 | color = rhs.color; | ||
941 | 84 | transparent = rhs.transparent; | ||
942 | 85 | fontWeight = rhs.fontWeight; | ||
943 | 86 | } | ||
944 | 87 | |||
945 | 88 | /** The color value of this entry for display. */ | ||
946 | 89 | QColor color; | ||
947 | 90 | |||
948 | 91 | /** | ||
949 | 92 | * If true character backgrounds using this color should be transparent. | ||
950 | 93 | * This is not applicable when the color is used to render text. | ||
951 | 94 | */ | ||
952 | 95 | bool transparent; | ||
953 | 96 | /** | ||
954 | 97 | * Specifies the font weight to use when drawing text with this color. | ||
955 | 98 | * This is not applicable when the color is used to draw a character's background. | ||
956 | 99 | */ | ||
957 | 100 | FontWeight fontWeight; | ||
958 | 101 | }; | ||
959 | 102 | |||
960 | 103 | |||
961 | 104 | // Attributed Character Representations /////////////////////////////// | ||
962 | 105 | |||
963 | 106 | // Colors | ||
964 | 107 | |||
965 | 108 | #define BASE_COLORS (2+8) | ||
966 | 109 | #define INTENSITIES 2 | ||
967 | 110 | #define TABLE_COLORS (INTENSITIES*BASE_COLORS) | ||
968 | 111 | |||
969 | 112 | #define DEFAULT_FORE_COLOR 0 | ||
970 | 113 | #define DEFAULT_BACK_COLOR 1 | ||
971 | 114 | |||
972 | 115 | //a standard set of colors using black text on a white background. | ||
973 | 116 | //defined in TerminalDisplay.cpp | ||
974 | 117 | |||
975 | 118 | extern const ColorEntry base_color_table[TABLE_COLORS] KDE_NO_EXPORT; | ||
976 | 119 | |||
977 | 120 | /* CharacterColor is a union of the various color spaces. | ||
978 | 121 | |||
979 | 122 | Assignment is as follows: | ||
980 | 123 | |||
981 | 124 | Type - Space - Values | ||
982 | 125 | |||
983 | 126 | 0 - Undefined - u: 0, v:0 w:0 | ||
984 | 127 | 1 - Default - u: 0..1 v:intense w:0 | ||
985 | 128 | 2 - System - u: 0..7 v:intense w:0 | ||
986 | 129 | 3 - Index(256) - u: 16..255 v:0 w:0 | ||
987 | 130 | 4 - RGB - u: 0..255 v:0..256 w:0..256 | ||
988 | 131 | |||
989 | 132 | Default colour space has two separate colours, namely | ||
990 | 133 | default foreground and default background colour. | ||
991 | 134 | */ | ||
992 | 135 | |||
993 | 136 | #define COLOR_SPACE_UNDEFINED 0 | ||
994 | 137 | #define COLOR_SPACE_DEFAULT 1 | ||
995 | 138 | #define COLOR_SPACE_SYSTEM 2 | ||
996 | 139 | #define COLOR_SPACE_256 3 | ||
997 | 140 | #define COLOR_SPACE_RGB 4 | ||
998 | 141 | |||
999 | 142 | /** | ||
1000 | 143 | * Describes the color of a single character in the terminal. | ||
1001 | 144 | */ | ||
1002 | 145 | class CharacterColor | ||
1003 | 146 | { | ||
1004 | 147 | friend class Character; | ||
1005 | 148 | |||
1006 | 149 | public: | ||
1007 | 150 | /** Constructs a new CharacterColor whoose color and color space are undefined. */ | ||
1008 | 151 | CharacterColor() | ||
1009 | 152 | : _colorSpace(COLOR_SPACE_UNDEFINED), | ||
1010 | 153 | _u(0), | ||
1011 | 154 | _v(0), | ||
1012 | 155 | _w(0) | ||
1013 | 156 | {} | ||
1014 | 157 | |||
1015 | 158 | /** | ||
1016 | 159 | * Constructs a new CharacterColor using the specified @p colorSpace and with | ||
1017 | 160 | * color value @p co | ||
1018 | 161 | * | ||
1019 | 162 | * The meaning of @p co depends on the @p colorSpace used. | ||
1020 | 163 | * | ||
1021 | 164 | * TODO : Document how @p co relates to @p colorSpace | ||
1022 | 165 | * | ||
1023 | 166 | * TODO : Add documentation about available color spaces. | ||
1024 | 167 | */ | ||
1025 | 168 | CharacterColor(quint8 colorSpace, int co) | ||
1026 | 169 | : _colorSpace(colorSpace), | ||
1027 | 170 | _u(0), | ||
1028 | 171 | _v(0), | ||
1029 | 172 | _w(0) | ||
1030 | 173 | { | ||
1031 | 174 | switch (colorSpace) | ||
1032 | 175 | { | ||
1033 | 176 | case COLOR_SPACE_DEFAULT: | ||
1034 | 177 | _u = co & 1; | ||
1035 | 178 | break; | ||
1036 | 179 | case COLOR_SPACE_SYSTEM: | ||
1037 | 180 | _u = co & 7; | ||
1038 | 181 | _v = (co >> 3) & 1; | ||
1039 | 182 | break; | ||
1040 | 183 | case COLOR_SPACE_256: | ||
1041 | 184 | _u = co & 255; | ||
1042 | 185 | break; | ||
1043 | 186 | case COLOR_SPACE_RGB: | ||
1044 | 187 | _u = co >> 16; | ||
1045 | 188 | _v = co >> 8; | ||
1046 | 189 | _w = co; | ||
1047 | 190 | break; | ||
1048 | 191 | default: | ||
1049 | 192 | _colorSpace = COLOR_SPACE_UNDEFINED; | ||
1050 | 193 | } | ||
1051 | 194 | } | ||
1052 | 195 | |||
1053 | 196 | /** | ||
1054 | 197 | * Returns true if this character color entry is valid. | ||
1055 | 198 | */ | ||
1056 | 199 | bool isValid() | ||
1057 | 200 | { | ||
1058 | 201 | return _colorSpace != COLOR_SPACE_UNDEFINED; | ||
1059 | 202 | } | ||
1060 | 203 | |||
1061 | 204 | /** | ||
1062 | 205 | * Toggles the value of this color between a normal system color and the corresponding intensive | ||
1063 | 206 | * system color. | ||
1064 | 207 | * | ||
1065 | 208 | * This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM | ||
1066 | 209 | * color spaces. | ||
1067 | 210 | */ | ||
1068 | 211 | void toggleIntensive(); | ||
1069 | 212 | |||
1070 | 213 | /** | ||
1071 | 214 | * Returns the color within the specified color @p palette | ||
1072 | 215 | * | ||
1073 | 216 | * The @p palette is only used if this color is one of the 16 system colors, otherwise | ||
1074 | 217 | * it is ignored. | ||
1075 | 218 | */ | ||
1076 | 219 | QColor color(const ColorEntry* palette) const; | ||
1077 | 220 | |||
1078 | 221 | /** | ||
1079 | 222 | * Compares two colors and returns true if they represent the same color value and | ||
1080 | 223 | * use the same color space. | ||
1081 | 224 | */ | ||
1082 | 225 | friend bool operator == (const CharacterColor& a, const CharacterColor& b); | ||
1083 | 226 | /** | ||
1084 | 227 | * Compares two colors and returns true if they represent different color values | ||
1085 | 228 | * or use different color spaces. | ||
1086 | 229 | */ | ||
1087 | 230 | friend bool operator != (const CharacterColor& a, const CharacterColor& b); | ||
1088 | 231 | |||
1089 | 232 | private: | ||
1090 | 233 | quint8 _colorSpace; | ||
1091 | 234 | |||
1092 | 235 | // bytes storing the character color | ||
1093 | 236 | quint8 _u; | ||
1094 | 237 | quint8 _v; | ||
1095 | 238 | quint8 _w; | ||
1096 | 239 | }; | ||
1097 | 240 | |||
1098 | 241 | inline bool operator == (const CharacterColor& a, const CharacterColor& b) | ||
1099 | 242 | { | ||
1100 | 243 | return a._colorSpace == b._colorSpace && | ||
1101 | 244 | a._u == b._u && | ||
1102 | 245 | a._v == b._v && | ||
1103 | 246 | a._w == b._w; | ||
1104 | 247 | } | ||
1105 | 248 | inline bool operator != (const CharacterColor& a, const CharacterColor& b) | ||
1106 | 249 | { | ||
1107 | 250 | return !operator==(a,b); | ||
1108 | 251 | } | ||
1109 | 252 | |||
1110 | 253 | inline const QColor color256(quint8 u, const ColorEntry* base) | ||
1111 | 254 | { | ||
1112 | 255 | // 0.. 16: system colors | ||
1113 | 256 | if (u < 8) return base[u+2 ].color; u -= 8; | ||
1114 | 257 | if (u < 8) return base[u+2+BASE_COLORS].color; u -= 8; | ||
1115 | 258 | |||
1116 | 259 | // 16..231: 6x6x6 rgb color cube | ||
1117 | 260 | if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0, | ||
1118 | 261 | ((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0, | ||
1119 | 262 | ((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0); u -= 216; | ||
1120 | 263 | |||
1121 | 264 | // 232..255: gray, leaving out black and white | ||
1122 | 265 | int gray = u*10+8; return QColor(gray,gray,gray); | ||
1123 | 266 | } | ||
1124 | 267 | |||
1125 | 268 | inline QColor CharacterColor::color(const ColorEntry* base) const | ||
1126 | 269 | { | ||
1127 | 270 | switch (_colorSpace) | ||
1128 | 271 | { | ||
1129 | 272 | case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color; | ||
1130 | 273 | case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color; | ||
1131 | 274 | case COLOR_SPACE_256: return color256(_u,base); | ||
1132 | 275 | case COLOR_SPACE_RGB: return QColor(_u,_v,_w); | ||
1133 | 276 | case COLOR_SPACE_UNDEFINED: return QColor(); | ||
1134 | 277 | } | ||
1135 | 278 | |||
1136 | 279 | Q_ASSERT(false); // invalid color space | ||
1137 | 280 | |||
1138 | 281 | return QColor(); | ||
1139 | 282 | } | ||
1140 | 283 | |||
1141 | 284 | inline void CharacterColor::toggleIntensive() | ||
1142 | 285 | { | ||
1143 | 286 | if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT) | ||
1144 | 287 | { | ||
1145 | 288 | _v = !_v; | ||
1146 | 289 | } | ||
1147 | 290 | } | ||
1148 | 291 | |||
1149 | 292 | |||
1150 | 293 | #endif // CHARACTERCOLOR_H | ||
1151 | 294 | |||
1152 | 295 | 0 | ||
1153 | === removed file 'src/plugin/konsole/ColorScheme.cpp' | |||
1154 | --- src/plugin/konsole/ColorScheme.cpp 2014-11-12 00:10:12 +0000 | |||
1155 | +++ src/plugin/konsole/ColorScheme.cpp 1970-01-01 00:00:00 +0000 | |||
1156 | @@ -1,774 +0,0 @@ | |||
1157 | 1 | /* | ||
1158 | 2 | This source file is part of Konsole, a terminal emulator. | ||
1159 | 3 | |||
1160 | 4 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
1161 | 5 | |||
1162 | 6 | This program is free software; you can redistribute it and/or modify | ||
1163 | 7 | it under the terms of the GNU General Public License as published by | ||
1164 | 8 | the Free Software Foundation; either version 2 of the License, or | ||
1165 | 9 | (at your option) any later version. | ||
1166 | 10 | |||
1167 | 11 | This program is distributed in the hope that it will be useful, | ||
1168 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1169 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1170 | 14 | GNU General Public License for more details. | ||
1171 | 15 | |||
1172 | 16 | You should have received a copy of the GNU General Public License | ||
1173 | 17 | along with this program; if not, write to the Free Software | ||
1174 | 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
1175 | 19 | 02110-1301 USA. | ||
1176 | 20 | */ | ||
1177 | 21 | |||
1178 | 22 | // Own | ||
1179 | 23 | #include "ColorScheme.h" | ||
1180 | 24 | #include "tools.h" | ||
1181 | 25 | |||
1182 | 26 | // Qt | ||
1183 | 27 | #include <QtGui/QBrush> | ||
1184 | 28 | #include <QtCore/QFile> | ||
1185 | 29 | #include <QtCore/QFileInfo> | ||
1186 | 30 | #include <QtDebug> | ||
1187 | 31 | #include <QSettings> | ||
1188 | 32 | #include <QDir> | ||
1189 | 33 | |||
1190 | 34 | |||
1191 | 35 | // KDE | ||
1192 | 36 | //#include <KColorScheme> | ||
1193 | 37 | //#include <KConfig> | ||
1194 | 38 | //#include <KLocale> | ||
1195 | 39 | //#include <KDebug> | ||
1196 | 40 | //#include <KConfigGroup> | ||
1197 | 41 | //#include <KStandardDirs> | ||
1198 | 42 | |||
1199 | 43 | |||
1200 | 44 | const ColorEntry ColorScheme::defaultTable[TABLE_COLORS] = | ||
1201 | 45 | // The following are almost IBM standard color codes, with some slight | ||
1202 | 46 | // gamma correction for the dim colors to compensate for bright X screens. | ||
1203 | 47 | // It contains the 8 ansiterm/xterm colors in 2 intensities. | ||
1204 | 48 | { | ||
1205 | 49 | ColorEntry( QColor(0x00,0x00,0x00), 0), ColorEntry( | ||
1206 | 50 | QColor(0xFF,0xFF,0xFF), 1), // Dfore, Dback | ||
1207 | 51 | ColorEntry( QColor(0x00,0x00,0x00), 0), ColorEntry( | ||
1208 | 52 | QColor(0xB2,0x18,0x18), 0), // Black, Red | ||
1209 | 53 | ColorEntry( QColor(0x18,0xB2,0x18), 0), ColorEntry( | ||
1210 | 54 | QColor(0xB2,0x68,0x18), 0), // Green, Yellow | ||
1211 | 55 | ColorEntry( QColor(0x18,0x18,0xB2), 0), ColorEntry( | ||
1212 | 56 | QColor(0xB2,0x18,0xB2), 0), // Blue, Magenta | ||
1213 | 57 | ColorEntry( QColor(0x18,0xB2,0xB2), 0), ColorEntry( | ||
1214 | 58 | QColor(0xB2,0xB2,0xB2), 0), // Cyan, White | ||
1215 | 59 | // intensive | ||
1216 | 60 | ColorEntry( QColor(0x00,0x00,0x00), 0), ColorEntry( | ||
1217 | 61 | QColor(0xFF,0xFF,0xFF), 1), | ||
1218 | 62 | ColorEntry( QColor(0x68,0x68,0x68), 0), ColorEntry( | ||
1219 | 63 | QColor(0xFF,0x54,0x54), 0), | ||
1220 | 64 | ColorEntry( QColor(0x54,0xFF,0x54), 0), ColorEntry( | ||
1221 | 65 | QColor(0xFF,0xFF,0x54), 0), | ||
1222 | 66 | ColorEntry( QColor(0x54,0x54,0xFF), 0), ColorEntry( | ||
1223 | 67 | QColor(0xFF,0x54,0xFF), 0), | ||
1224 | 68 | ColorEntry( QColor(0x54,0xFF,0xFF), 0), ColorEntry( | ||
1225 | 69 | QColor(0xFF,0xFF,0xFF), 0) | ||
1226 | 70 | }; | ||
1227 | 71 | |||
1228 | 72 | const char* const ColorScheme::colorNames[TABLE_COLORS] = | ||
1229 | 73 | { | ||
1230 | 74 | "Foreground", | ||
1231 | 75 | "Background", | ||
1232 | 76 | "Color0", | ||
1233 | 77 | "Color1", | ||
1234 | 78 | "Color2", | ||
1235 | 79 | "Color3", | ||
1236 | 80 | "Color4", | ||
1237 | 81 | "Color5", | ||
1238 | 82 | "Color6", | ||
1239 | 83 | "Color7", | ||
1240 | 84 | "ForegroundIntense", | ||
1241 | 85 | "BackgroundIntense", | ||
1242 | 86 | "Color0Intense", | ||
1243 | 87 | "Color1Intense", | ||
1244 | 88 | "Color2Intense", | ||
1245 | 89 | "Color3Intense", | ||
1246 | 90 | "Color4Intense", | ||
1247 | 91 | "Color5Intense", | ||
1248 | 92 | "Color6Intense", | ||
1249 | 93 | "Color7Intense" | ||
1250 | 94 | }; | ||
1251 | 95 | // dummy silently comment out the tr_NOOP | ||
1252 | 96 | #define tr_NOOP | ||
1253 | 97 | const char* const ColorScheme::translatedColorNames[TABLE_COLORS] = | ||
1254 | 98 | { | ||
1255 | 99 | tr_NOOP("Foreground"), | ||
1256 | 100 | tr_NOOP("Background"), | ||
1257 | 101 | tr_NOOP("Color 1"), | ||
1258 | 102 | tr_NOOP("Color 2"), | ||
1259 | 103 | tr_NOOP("Color 3"), | ||
1260 | 104 | tr_NOOP("Color 4"), | ||
1261 | 105 | tr_NOOP("Color 5"), | ||
1262 | 106 | tr_NOOP("Color 6"), | ||
1263 | 107 | tr_NOOP("Color 7"), | ||
1264 | 108 | tr_NOOP("Color 8"), | ||
1265 | 109 | tr_NOOP("Foreground (Intense)"), | ||
1266 | 110 | tr_NOOP("Background (Intense)"), | ||
1267 | 111 | tr_NOOP("Color 1 (Intense)"), | ||
1268 | 112 | tr_NOOP("Color 2 (Intense)"), | ||
1269 | 113 | tr_NOOP("Color 3 (Intense)"), | ||
1270 | 114 | tr_NOOP("Color 4 (Intense)"), | ||
1271 | 115 | tr_NOOP("Color 5 (Intense)"), | ||
1272 | 116 | tr_NOOP("Color 6 (Intense)"), | ||
1273 | 117 | tr_NOOP("Color 7 (Intense)"), | ||
1274 | 118 | tr_NOOP("Color 8 (Intense)") | ||
1275 | 119 | }; | ||
1276 | 120 | |||
1277 | 121 | ColorScheme::ColorScheme() | ||
1278 | 122 | { | ||
1279 | 123 | _table = 0; | ||
1280 | 124 | _randomTable = 0; | ||
1281 | 125 | _opacity = 1.0; | ||
1282 | 126 | } | ||
1283 | 127 | ColorScheme::ColorScheme(const ColorScheme& other) | ||
1284 | 128 | : _opacity(other._opacity) | ||
1285 | 129 | ,_table(0) | ||
1286 | 130 | ,_randomTable(0) | ||
1287 | 131 | { | ||
1288 | 132 | setName(other.name()); | ||
1289 | 133 | setDescription(other.description()); | ||
1290 | 134 | |||
1291 | 135 | if ( other._table != 0 ) | ||
1292 | 136 | { | ||
1293 | 137 | for ( int i = 0 ; i < TABLE_COLORS ; i++ ) | ||
1294 | 138 | setColorTableEntry(i,other._table[i]); | ||
1295 | 139 | } | ||
1296 | 140 | |||
1297 | 141 | if ( other._randomTable != 0 ) | ||
1298 | 142 | { | ||
1299 | 143 | for ( int i = 0 ; i < TABLE_COLORS ; i++ ) | ||
1300 | 144 | { | ||
1301 | 145 | const RandomizationRange& range = other._randomTable[i]; | ||
1302 | 146 | setRandomizationRange(i,range.hue,range.saturation,range.value); | ||
1303 | 147 | } | ||
1304 | 148 | } | ||
1305 | 149 | } | ||
1306 | 150 | ColorScheme::~ColorScheme() | ||
1307 | 151 | { | ||
1308 | 152 | delete[] _table; | ||
1309 | 153 | delete[] _randomTable; | ||
1310 | 154 | } | ||
1311 | 155 | |||
1312 | 156 | void ColorScheme::setDescription(const QString& description) { _description = description; } | ||
1313 | 157 | QString ColorScheme::description() const { return _description; } | ||
1314 | 158 | |||
1315 | 159 | void ColorScheme::setName(const QString& name) { _name = name; } | ||
1316 | 160 | QString ColorScheme::name() const { return _name; } | ||
1317 | 161 | |||
1318 | 162 | void ColorScheme::setColorTableEntry(int index , const ColorEntry& entry) | ||
1319 | 163 | { | ||
1320 | 164 | Q_ASSERT( index >= 0 && index < TABLE_COLORS ); | ||
1321 | 165 | |||
1322 | 166 | if ( !_table ) | ||
1323 | 167 | { | ||
1324 | 168 | _table = new ColorEntry[TABLE_COLORS]; | ||
1325 | 169 | |||
1326 | 170 | for (int i=0;i<TABLE_COLORS;i++) | ||
1327 | 171 | _table[i] = defaultTable[i]; | ||
1328 | 172 | } | ||
1329 | 173 | |||
1330 | 174 | _table[index] = entry; | ||
1331 | 175 | } | ||
1332 | 176 | ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const | ||
1333 | 177 | { | ||
1334 | 178 | Q_ASSERT( index >= 0 && index < TABLE_COLORS ); | ||
1335 | 179 | |||
1336 | 180 | if ( randomSeed != 0 ) | ||
1337 | 181 | qsrand(randomSeed); | ||
1338 | 182 | |||
1339 | 183 | ColorEntry entry = colorTable()[index]; | ||
1340 | 184 | |||
1341 | 185 | if ( randomSeed != 0 && | ||
1342 | 186 | _randomTable != 0 && | ||
1343 | 187 | !_randomTable[index].isNull() ) | ||
1344 | 188 | { | ||
1345 | 189 | const RandomizationRange& range = _randomTable[index]; | ||
1346 | 190 | |||
1347 | 191 | |||
1348 | 192 | int hueDifference = range.hue ? (qrand() % range.hue) - range.hue/2 : 0; | ||
1349 | 193 | int saturationDifference = range.saturation ? (qrand() % range.saturation) - range.saturation/2 : 0; | ||
1350 | 194 | int valueDifference = range.value ? (qrand() % range.value) - range.value/2 : 0; | ||
1351 | 195 | |||
1352 | 196 | QColor& color = entry.color; | ||
1353 | 197 | |||
1354 | 198 | int newHue = qAbs( (color.hue() + hueDifference) % MAX_HUE ); | ||
1355 | 199 | int newValue = qMin( qAbs(color.value() + valueDifference) , 255 ); | ||
1356 | 200 | int newSaturation = qMin( qAbs(color.saturation() + saturationDifference) , 255 ); | ||
1357 | 201 | |||
1358 | 202 | color.setHsv(newHue,newSaturation,newValue); | ||
1359 | 203 | } | ||
1360 | 204 | |||
1361 | 205 | return entry; | ||
1362 | 206 | } | ||
1363 | 207 | void ColorScheme::getColorTable(ColorEntry* table , uint randomSeed) const | ||
1364 | 208 | { | ||
1365 | 209 | for ( int i = 0 ; i < TABLE_COLORS ; i++ ) | ||
1366 | 210 | table[i] = colorEntry(i,randomSeed); | ||
1367 | 211 | } | ||
1368 | 212 | bool ColorScheme::randomizedBackgroundColor() const | ||
1369 | 213 | { | ||
1370 | 214 | return _randomTable == 0 ? false : !_randomTable[1].isNull(); | ||
1371 | 215 | } | ||
1372 | 216 | void ColorScheme::setRandomizedBackgroundColor(bool randomize) | ||
1373 | 217 | { | ||
1374 | 218 | // the hue of the background colour is allowed to be randomly | ||
1375 | 219 | // adjusted as much as possible. | ||
1376 | 220 | // | ||
1377 | 221 | // the value and saturation are left alone to maintain read-ability | ||
1378 | 222 | if ( randomize ) | ||
1379 | 223 | { | ||
1380 | 224 | setRandomizationRange( 1 /* background color index */ , MAX_HUE , 255 , 0 ); | ||
1381 | 225 | } | ||
1382 | 226 | else | ||
1383 | 227 | { | ||
1384 | 228 | if ( _randomTable ) | ||
1385 | 229 | setRandomizationRange( 1 /* background color index */ , 0 , 0 , 0 ); | ||
1386 | 230 | } | ||
1387 | 231 | } | ||
1388 | 232 | |||
1389 | 233 | void ColorScheme::setRandomizationRange( int index , quint16 hue , quint8 saturation , | ||
1390 | 234 | quint8 value ) | ||
1391 | 235 | { | ||
1392 | 236 | Q_ASSERT( hue <= MAX_HUE ); | ||
1393 | 237 | Q_ASSERT( index >= 0 && index < TABLE_COLORS ); | ||
1394 | 238 | |||
1395 | 239 | if ( _randomTable == 0 ) | ||
1396 | 240 | _randomTable = new RandomizationRange[TABLE_COLORS]; | ||
1397 | 241 | |||
1398 | 242 | _randomTable[index].hue = hue; | ||
1399 | 243 | _randomTable[index].value = value; | ||
1400 | 244 | _randomTable[index].saturation = saturation; | ||
1401 | 245 | } | ||
1402 | 246 | |||
1403 | 247 | const ColorEntry* ColorScheme::colorTable() const | ||
1404 | 248 | { | ||
1405 | 249 | if ( _table ) | ||
1406 | 250 | return _table; | ||
1407 | 251 | else | ||
1408 | 252 | return defaultTable; | ||
1409 | 253 | } | ||
1410 | 254 | QColor ColorScheme::foregroundColor() const | ||
1411 | 255 | { | ||
1412 | 256 | return colorTable()[0].color; | ||
1413 | 257 | } | ||
1414 | 258 | QColor ColorScheme::backgroundColor() const | ||
1415 | 259 | { | ||
1416 | 260 | return colorTable()[1].color; | ||
1417 | 261 | } | ||
1418 | 262 | bool ColorScheme::hasDarkBackground() const | ||
1419 | 263 | { | ||
1420 | 264 | // value can range from 0 - 255, with larger values indicating higher brightness. | ||
1421 | 265 | // so 127 is in the middle, anything less is deemed 'dark' | ||
1422 | 266 | return backgroundColor().value() < 127; | ||
1423 | 267 | } | ||
1424 | 268 | void ColorScheme::setOpacity(qreal opacity) { _opacity = opacity; } | ||
1425 | 269 | qreal ColorScheme::opacity() const { return _opacity; } | ||
1426 | 270 | |||
1427 | 271 | void ColorScheme::read(const QString & fileName) | ||
1428 | 272 | { | ||
1429 | 273 | QSettings s(fileName, QSettings::IniFormat); | ||
1430 | 274 | s.beginGroup("General"); | ||
1431 | 275 | |||
1432 | 276 | _description = s.value("Description", QObject::tr("Un-named Color Scheme")).toString(); | ||
1433 | 277 | _opacity = s.value("Opacity",qreal(1.0)).toDouble(); | ||
1434 | 278 | s.endGroup(); | ||
1435 | 279 | |||
1436 | 280 | for (int i=0 ; i < TABLE_COLORS ; i++) | ||
1437 | 281 | { | ||
1438 | 282 | readColorEntry(&s, i); | ||
1439 | 283 | } | ||
1440 | 284 | } | ||
1441 | 285 | #if 0 | ||
1442 | 286 | // implemented upstream - user apps | ||
1443 | 287 | void ColorScheme::read(KConfig& config) | ||
1444 | 288 | { | ||
1445 | 289 | KConfigGroup configGroup = config.group("General"); | ||
1446 | 290 | |||
1447 | 291 | QString description = configGroup.readEntry("Description", QObject::tr("Un-named Color Scheme")); | ||
1448 | 292 | |||
1449 | 293 | _description = tr(description.toUtf8()); | ||
1450 | 294 | _opacity = configGroup.readEntry("Opacity",qreal(1.0)); | ||
1451 | 295 | |||
1452 | 296 | for (int i=0 ; i < TABLE_COLORS ; i++) | ||
1453 | 297 | { | ||
1454 | 298 | readColorEntry(config,i); | ||
1455 | 299 | } | ||
1456 | 300 | } | ||
1457 | 301 | void ColorScheme::write(KConfig& config) const | ||
1458 | 302 | { | ||
1459 | 303 | KConfigGroup configGroup = config.group("General"); | ||
1460 | 304 | |||
1461 | 305 | configGroup.writeEntry("Description",_description); | ||
1462 | 306 | configGroup.writeEntry("Opacity",_opacity); | ||
1463 | 307 | |||
1464 | 308 | for (int i=0 ; i < TABLE_COLORS ; i++) | ||
1465 | 309 | { | ||
1466 | 310 | RandomizationRange random = _randomTable != 0 ? _randomTable[i] : RandomizationRange(); | ||
1467 | 311 | writeColorEntry(config,colorNameForIndex(i),colorTable()[i],random); | ||
1468 | 312 | } | ||
1469 | 313 | } | ||
1470 | 314 | #endif | ||
1471 | 315 | |||
1472 | 316 | QString ColorScheme::colorNameForIndex(int index) | ||
1473 | 317 | { | ||
1474 | 318 | Q_ASSERT( index >= 0 && index < TABLE_COLORS ); | ||
1475 | 319 | |||
1476 | 320 | return QString(colorNames[index]); | ||
1477 | 321 | } | ||
1478 | 322 | QString ColorScheme::translatedColorNameForIndex(int index) | ||
1479 | 323 | { | ||
1480 | 324 | Q_ASSERT( index >= 0 && index < TABLE_COLORS ); | ||
1481 | 325 | |||
1482 | 326 | return translatedColorNames[index]; | ||
1483 | 327 | } | ||
1484 | 328 | |||
1485 | 329 | void ColorScheme::readColorEntry(QSettings * s , int index) | ||
1486 | 330 | { | ||
1487 | 331 | s->beginGroup(colorNameForIndex(index)); | ||
1488 | 332 | |||
1489 | 333 | ColorEntry entry; | ||
1490 | 334 | |||
1491 | 335 | QStringList rgbList = s->value("Color", QStringList()).toStringList(); | ||
1492 | 336 | if (rgbList.count() != 3) | ||
1493 | 337 | { | ||
1494 | 338 | Q_ASSERT(0); | ||
1495 | 339 | } | ||
1496 | 340 | int r, g, b; | ||
1497 | 341 | r = rgbList[0].toInt(); | ||
1498 | 342 | g = rgbList[1].toInt(); | ||
1499 | 343 | b = rgbList[2].toInt(); | ||
1500 | 344 | entry.color = QColor(r, g, b); | ||
1501 | 345 | |||
1502 | 346 | entry.transparent = s->value("Transparent",false).toBool(); | ||
1503 | 347 | |||
1504 | 348 | // Deprecated key from KDE 4.0 which set 'Bold' to true to force | ||
1505 | 349 | // a color to be bold or false to use the current format | ||
1506 | 350 | // | ||
1507 | 351 | // TODO - Add a new tri-state key which allows for bold, normal or | ||
1508 | 352 | // current format | ||
1509 | 353 | if (s->contains("Bold")) | ||
1510 | 354 | entry.fontWeight = s->value("Bold",false).toBool() ? ColorEntry::Bold : | ||
1511 | 355 | ColorEntry::UseCurrentFormat; | ||
1512 | 356 | |||
1513 | 357 | quint16 hue = s->value("MaxRandomHue",0).toInt(); | ||
1514 | 358 | quint8 value = s->value("MaxRandomValue",0).toInt(); | ||
1515 | 359 | quint8 saturation = s->value("MaxRandomSaturation",0).toInt(); | ||
1516 | 360 | |||
1517 | 361 | setColorTableEntry( index , entry ); | ||
1518 | 362 | |||
1519 | 363 | if ( hue != 0 || value != 0 || saturation != 0 ) | ||
1520 | 364 | setRandomizationRange( index , hue , saturation , value ); | ||
1521 | 365 | |||
1522 | 366 | s->endGroup(); | ||
1523 | 367 | } | ||
1524 | 368 | #if 0 | ||
1525 | 369 | // implemented upstream - user apps | ||
1526 | 370 | void ColorScheme::writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry , const RandomizationRange& random) const | ||
1527 | 371 | { | ||
1528 | 372 | KConfigGroup configGroup(&config,colorName); | ||
1529 | 373 | |||
1530 | 374 | configGroup.writeEntry("Color",entry.color); | ||
1531 | 375 | configGroup.writeEntry("Transparency",(bool)entry.transparent); | ||
1532 | 376 | if (entry.fontWeight != ColorEntry::UseCurrentFormat) | ||
1533 | 377 | { | ||
1534 | 378 | configGroup.writeEntry("Bold",entry.fontWeight == ColorEntry::Bold); | ||
1535 | 379 | } | ||
1536 | 380 | |||
1537 | 381 | // record randomization if this color has randomization or | ||
1538 | 382 | // if one of the keys already exists | ||
1539 | 383 | if ( !random.isNull() || configGroup.hasKey("MaxRandomHue") ) | ||
1540 | 384 | { | ||
1541 | 385 | configGroup.writeEntry("MaxRandomHue",(int)random.hue); | ||
1542 | 386 | configGroup.writeEntry("MaxRandomValue",(int)random.value); | ||
1543 | 387 | configGroup.writeEntry("MaxRandomSaturation",(int)random.saturation); | ||
1544 | 388 | } | ||
1545 | 389 | } | ||
1546 | 390 | #endif | ||
1547 | 391 | |||
1548 | 392 | // | ||
1549 | 393 | // Work In Progress - A color scheme for use on KDE setups for users | ||
1550 | 394 | // with visual disabilities which means that they may have trouble | ||
1551 | 395 | // reading text with the supplied color schemes. | ||
1552 | 396 | // | ||
1553 | 397 | // This color scheme uses only the 'safe' colors defined by the | ||
1554 | 398 | // KColorScheme class. | ||
1555 | 399 | // | ||
1556 | 400 | // A complication this introduces is that each color provided by | ||
1557 | 401 | // KColorScheme is defined as a 'background' or 'foreground' color. | ||
1558 | 402 | // Only foreground colors are allowed to be used to render text and | ||
1559 | 403 | // only background colors are allowed to be used for backgrounds. | ||
1560 | 404 | // | ||
1561 | 405 | // The ColorEntry and TerminalDisplay classes do not currently | ||
1562 | 406 | // support this restriction. | ||
1563 | 407 | // | ||
1564 | 408 | // Requirements: | ||
1565 | 409 | // - A color scheme which uses only colors from the KColorScheme class | ||
1566 | 410 | // - Ability to restrict which colors the TerminalDisplay widget | ||
1567 | 411 | // uses as foreground and background color | ||
1568 | 412 | // - Make use of KGlobalSettings::allowDefaultBackgroundImages() as | ||
1569 | 413 | // a hint to determine whether this accessible color scheme should | ||
1570 | 414 | // be used by default. | ||
1571 | 415 | // | ||
1572 | 416 | // | ||
1573 | 417 | // -- Robert Knight <robertknight@gmail.com> 21/07/2007 | ||
1574 | 418 | // | ||
1575 | 419 | AccessibleColorScheme::AccessibleColorScheme() | ||
1576 | 420 | : ColorScheme() | ||
1577 | 421 | { | ||
1578 | 422 | #if 0 | ||
1579 | 423 | // It's not finished in konsole and it breaks Qt4 compilation as well | ||
1580 | 424 | // basic attributes | ||
1581 | 425 | setName("accessible"); | ||
1582 | 426 | setDescription(QObject::tr("Accessible Color Scheme")); | ||
1583 | 427 | |||
1584 | 428 | // setup colors | ||
1585 | 429 | const int ColorRoleCount = 8; | ||
1586 | 430 | |||
1587 | 431 | const KColorScheme colorScheme(QPalette::Active); | ||
1588 | 432 | |||
1589 | 433 | QBrush colors[ColorRoleCount] = | ||
1590 | 434 | { | ||
1591 | 435 | colorScheme.foreground( colorScheme.NormalText ), | ||
1592 | 436 | colorScheme.background( colorScheme.NormalBackground ), | ||
1593 | 437 | |||
1594 | 438 | colorScheme.foreground( colorScheme.InactiveText ), | ||
1595 | 439 | colorScheme.foreground( colorScheme.ActiveText ), | ||
1596 | 440 | colorScheme.foreground( colorScheme.LinkText ), | ||
1597 | 441 | colorScheme.foreground( colorScheme.VisitedText ), | ||
1598 | 442 | colorScheme.foreground( colorScheme.NegativeText ), | ||
1599 | 443 | colorScheme.foreground( colorScheme.NeutralText ) | ||
1600 | 444 | }; | ||
1601 | 445 | |||
1602 | 446 | for ( int i = 0 ; i < TABLE_COLORS ; i++ ) | ||
1603 | 447 | { | ||
1604 | 448 | ColorEntry entry; | ||
1605 | 449 | entry.color = colors[ i % ColorRoleCount ].color(); | ||
1606 | 450 | |||
1607 | 451 | setColorTableEntry( i , entry ); | ||
1608 | 452 | } | ||
1609 | 453 | #endif | ||
1610 | 454 | } | ||
1611 | 455 | |||
1612 | 456 | KDE3ColorSchemeReader::KDE3ColorSchemeReader( QIODevice* device ) : | ||
1613 | 457 | _device(device) | ||
1614 | 458 | { | ||
1615 | 459 | } | ||
1616 | 460 | ColorScheme* KDE3ColorSchemeReader::read() | ||
1617 | 461 | { | ||
1618 | 462 | Q_ASSERT( _device->openMode() == QIODevice::ReadOnly || | ||
1619 | 463 | _device->openMode() == QIODevice::ReadWrite ); | ||
1620 | 464 | |||
1621 | 465 | ColorScheme* scheme = new ColorScheme(); | ||
1622 | 466 | |||
1623 | 467 | QRegExp comment("#.*$"); | ||
1624 | 468 | while ( !_device->atEnd() ) | ||
1625 | 469 | { | ||
1626 | 470 | QString line(_device->readLine()); | ||
1627 | 471 | line.remove(comment); | ||
1628 | 472 | line = line.simplified(); | ||
1629 | 473 | |||
1630 | 474 | if ( line.isEmpty() ) | ||
1631 | 475 | continue; | ||
1632 | 476 | |||
1633 | 477 | if ( line.startsWith(QLatin1String("color")) ) | ||
1634 | 478 | { | ||
1635 | 479 | if (!readColorLine(line,scheme)) | ||
1636 | 480 | qDebug() << "Failed to read KDE 3 color scheme line" << line; | ||
1637 | 481 | } | ||
1638 | 482 | else if ( line.startsWith(QLatin1String("title")) ) | ||
1639 | 483 | { | ||
1640 | 484 | if (!readTitleLine(line,scheme)) | ||
1641 | 485 | qDebug() << "Failed to read KDE 3 color scheme title line" << line; | ||
1642 | 486 | } | ||
1643 | 487 | else | ||
1644 | 488 | { | ||
1645 | 489 | qDebug() << "KDE 3 color scheme contains an unsupported feature, '" << | ||
1646 | 490 | line << "'"; | ||
1647 | 491 | } | ||
1648 | 492 | } | ||
1649 | 493 | |||
1650 | 494 | return scheme; | ||
1651 | 495 | } | ||
1652 | 496 | bool KDE3ColorSchemeReader::readColorLine(const QString& line,ColorScheme* scheme) | ||
1653 | 497 | { | ||
1654 | 498 | QStringList list = line.split(QChar(' ')); | ||
1655 | 499 | |||
1656 | 500 | if (list.count() != 7) | ||
1657 | 501 | return false; | ||
1658 | 502 | if (list.first() != "color") | ||
1659 | 503 | return false; | ||
1660 | 504 | |||
1661 | 505 | int index = list[1].toInt(); | ||
1662 | 506 | int red = list[2].toInt(); | ||
1663 | 507 | int green = list[3].toInt(); | ||
1664 | 508 | int blue = list[4].toInt(); | ||
1665 | 509 | int transparent = list[5].toInt(); | ||
1666 | 510 | int bold = list[6].toInt(); | ||
1667 | 511 | |||
1668 | 512 | const int MAX_COLOR_VALUE = 255; | ||
1669 | 513 | |||
1670 | 514 | if( (index < 0 || index >= TABLE_COLORS ) | ||
1671 | 515 | || (red < 0 || red > MAX_COLOR_VALUE ) | ||
1672 | 516 | || (blue < 0 || blue > MAX_COLOR_VALUE ) | ||
1673 | 517 | || (green < 0 || green > MAX_COLOR_VALUE ) | ||
1674 | 518 | || (transparent != 0 && transparent != 1 ) | ||
1675 | 519 | || (bold != 0 && bold != 1) ) | ||
1676 | 520 | return false; | ||
1677 | 521 | |||
1678 | 522 | ColorEntry entry; | ||
1679 | 523 | entry.color = QColor(red,green,blue); | ||
1680 | 524 | entry.transparent = ( transparent != 0 ); | ||
1681 | 525 | entry.fontWeight = ( bold != 0 ) ? ColorEntry::Bold : ColorEntry::UseCurrentFormat; | ||
1682 | 526 | |||
1683 | 527 | scheme->setColorTableEntry(index,entry); | ||
1684 | 528 | return true; | ||
1685 | 529 | } | ||
1686 | 530 | bool KDE3ColorSchemeReader::readTitleLine(const QString& line,ColorScheme* scheme) | ||
1687 | 531 | { | ||
1688 | 532 | if( !line.startsWith(QLatin1String("title")) ) | ||
1689 | 533 | return false; | ||
1690 | 534 | |||
1691 | 535 | int spacePos = line.indexOf(' '); | ||
1692 | 536 | if( spacePos == -1 ) | ||
1693 | 537 | return false; | ||
1694 | 538 | |||
1695 | 539 | QString description = line.mid(spacePos+1); | ||
1696 | 540 | |||
1697 | 541 | scheme->setDescription(description.toUtf8()); | ||
1698 | 542 | return true; | ||
1699 | 543 | } | ||
1700 | 544 | ColorSchemeManager::ColorSchemeManager() | ||
1701 | 545 | : _haveLoadedAll(false) | ||
1702 | 546 | { | ||
1703 | 547 | } | ||
1704 | 548 | ColorSchemeManager::~ColorSchemeManager() | ||
1705 | 549 | { | ||
1706 | 550 | QHashIterator<QString,const ColorScheme*> iter(_colorSchemes); | ||
1707 | 551 | while (iter.hasNext()) | ||
1708 | 552 | { | ||
1709 | 553 | iter.next(); | ||
1710 | 554 | delete iter.value(); | ||
1711 | 555 | } | ||
1712 | 556 | } | ||
1713 | 557 | void ColorSchemeManager::loadAllColorSchemes() | ||
1714 | 558 | { | ||
1715 | 559 | qDebug() << "loadAllColorSchemes"; | ||
1716 | 560 | int success = 0; | ||
1717 | 561 | int failed = 0; | ||
1718 | 562 | |||
1719 | 563 | QList<QString> nativeColorSchemes = listColorSchemes(); | ||
1720 | 564 | |||
1721 | 565 | QListIterator<QString> nativeIter(nativeColorSchemes); | ||
1722 | 566 | while ( nativeIter.hasNext() ) | ||
1723 | 567 | { | ||
1724 | 568 | if ( loadColorScheme( nativeIter.next() ) ) | ||
1725 | 569 | success++; | ||
1726 | 570 | else | ||
1727 | 571 | failed++; | ||
1728 | 572 | } | ||
1729 | 573 | |||
1730 | 574 | QList<QString> kde3ColorSchemes = listKDE3ColorSchemes(); | ||
1731 | 575 | QListIterator<QString> kde3Iter(kde3ColorSchemes); | ||
1732 | 576 | while ( kde3Iter.hasNext() ) | ||
1733 | 577 | { | ||
1734 | 578 | if ( loadKDE3ColorScheme( kde3Iter.next() ) ) | ||
1735 | 579 | success++; | ||
1736 | 580 | else | ||
1737 | 581 | failed++; | ||
1738 | 582 | } | ||
1739 | 583 | |||
1740 | 584 | if ( failed > 0 ) | ||
1741 | 585 | qDebug() << "failed to load " << failed << " color schemes."; | ||
1742 | 586 | |||
1743 | 587 | _haveLoadedAll = true; | ||
1744 | 588 | } | ||
1745 | 589 | QList<const ColorScheme*> ColorSchemeManager::allColorSchemes() | ||
1746 | 590 | { | ||
1747 | 591 | if ( !_haveLoadedAll ) | ||
1748 | 592 | { | ||
1749 | 593 | loadAllColorSchemes(); | ||
1750 | 594 | } | ||
1751 | 595 | |||
1752 | 596 | return _colorSchemes.values(); | ||
1753 | 597 | } | ||
1754 | 598 | bool ColorSchemeManager::loadKDE3ColorScheme(const QString& filePath) | ||
1755 | 599 | { | ||
1756 | 600 | QFile file(filePath); | ||
1757 | 601 | if (!filePath.endsWith(QLatin1String(".schema")) || !file.open(QIODevice::ReadOnly)) | ||
1758 | 602 | return false; | ||
1759 | 603 | |||
1760 | 604 | KDE3ColorSchemeReader reader(&file); | ||
1761 | 605 | ColorScheme* scheme = reader.read(); | ||
1762 | 606 | scheme->setName(QFileInfo(file).baseName()); | ||
1763 | 607 | file.close(); | ||
1764 | 608 | |||
1765 | 609 | if (scheme->name().isEmpty()) | ||
1766 | 610 | { | ||
1767 | 611 | qDebug() << "color scheme name is not valid."; | ||
1768 | 612 | delete scheme; | ||
1769 | 613 | return false; | ||
1770 | 614 | } | ||
1771 | 615 | |||
1772 | 616 | QFileInfo info(filePath); | ||
1773 | 617 | |||
1774 | 618 | if ( !_colorSchemes.contains(info.baseName()) ) | ||
1775 | 619 | _colorSchemes.insert(scheme->name(),scheme); | ||
1776 | 620 | else | ||
1777 | 621 | { | ||
1778 | 622 | qDebug() << "color scheme with name" << scheme->name() << "has already been" << | ||
1779 | 623 | "found, ignoring."; | ||
1780 | 624 | delete scheme; | ||
1781 | 625 | } | ||
1782 | 626 | |||
1783 | 627 | return true; | ||
1784 | 628 | } | ||
1785 | 629 | #if 0 | ||
1786 | 630 | void ColorSchemeManager::addColorScheme(ColorScheme* scheme) | ||
1787 | 631 | { | ||
1788 | 632 | _colorSchemes.insert(scheme->name(),scheme); | ||
1789 | 633 | |||
1790 | 634 | // save changes to disk | ||
1791 | 635 | QString path = KGlobal::dirs()->saveLocation("data","konsole/") + scheme->name() + ".colorscheme"; | ||
1792 | 636 | KConfig config(path , KConfig::NoGlobals); | ||
1793 | 637 | |||
1794 | 638 | scheme->write(config); | ||
1795 | 639 | } | ||
1796 | 640 | #endif | ||
1797 | 641 | bool ColorSchemeManager::loadColorScheme(const QString& filePath) | ||
1798 | 642 | { | ||
1799 | 643 | if ( !filePath.endsWith(QLatin1String(".colorscheme")) || !QFile::exists(filePath) ) | ||
1800 | 644 | return false; | ||
1801 | 645 | |||
1802 | 646 | QFileInfo info(filePath); | ||
1803 | 647 | |||
1804 | 648 | ColorScheme* scheme = new ColorScheme(); | ||
1805 | 649 | scheme->setName(info.baseName()); | ||
1806 | 650 | scheme->read(filePath); | ||
1807 | 651 | |||
1808 | 652 | if (scheme->name().isEmpty()) | ||
1809 | 653 | { | ||
1810 | 654 | qDebug() << "Color scheme in" << filePath << "does not have a valid name and was not loaded."; | ||
1811 | 655 | delete scheme; | ||
1812 | 656 | return false; | ||
1813 | 657 | } | ||
1814 | 658 | |||
1815 | 659 | if ( !_colorSchemes.contains(info.baseName()) ) | ||
1816 | 660 | { | ||
1817 | 661 | _colorSchemes.insert(scheme->name(),scheme); | ||
1818 | 662 | } | ||
1819 | 663 | else | ||
1820 | 664 | { | ||
1821 | 665 | qDebug() << "color scheme with name" << scheme->name() << "has already been" << | ||
1822 | 666 | "found, ignoring."; | ||
1823 | 667 | |||
1824 | 668 | delete scheme; | ||
1825 | 669 | } | ||
1826 | 670 | |||
1827 | 671 | return true; | ||
1828 | 672 | } | ||
1829 | 673 | QList<QString> ColorSchemeManager::listKDE3ColorSchemes() | ||
1830 | 674 | { | ||
1831 | 675 | QString dname(get_color_schemes_dir()); | ||
1832 | 676 | QDir dir(dname); | ||
1833 | 677 | QStringList filters; | ||
1834 | 678 | filters << "*.schema"; | ||
1835 | 679 | dir.setNameFilters(filters); | ||
1836 | 680 | QStringList list = dir.entryList(filters); | ||
1837 | 681 | QStringList ret; | ||
1838 | 682 | foreach(QString i, list) | ||
1839 | 683 | ret << dname + "/" + i; | ||
1840 | 684 | return ret; | ||
1841 | 685 | //return KGlobal::dirs()->findAllResources("data", | ||
1842 | 686 | // "konsole/*.schema", | ||
1843 | 687 | // KStandardDirs::NoDuplicates); | ||
1844 | 688 | // | ||
1845 | 689 | } | ||
1846 | 690 | QList<QString> ColorSchemeManager::listColorSchemes() | ||
1847 | 691 | { | ||
1848 | 692 | QString dname(get_color_schemes_dir()); | ||
1849 | 693 | QDir dir(dname); | ||
1850 | 694 | QStringList filters; | ||
1851 | 695 | filters << "*.colorscheme"; | ||
1852 | 696 | dir.setNameFilters(filters); | ||
1853 | 697 | QStringList list = dir.entryList(filters); | ||
1854 | 698 | QStringList ret; | ||
1855 | 699 | foreach(QString i, list) | ||
1856 | 700 | ret << dname + "/" + i; | ||
1857 | 701 | return ret; | ||
1858 | 702 | // return KGlobal::dirs()->findAllResources("data", | ||
1859 | 703 | // "konsole/*.colorscheme", | ||
1860 | 704 | // KStandardDirs::NoDuplicates); | ||
1861 | 705 | } | ||
1862 | 706 | const ColorScheme ColorSchemeManager::_defaultColorScheme; | ||
1863 | 707 | const ColorScheme* ColorSchemeManager::defaultColorScheme() const | ||
1864 | 708 | { | ||
1865 | 709 | return &_defaultColorScheme; | ||
1866 | 710 | } | ||
1867 | 711 | bool ColorSchemeManager::deleteColorScheme(const QString& name) | ||
1868 | 712 | { | ||
1869 | 713 | Q_ASSERT( _colorSchemes.contains(name) ); | ||
1870 | 714 | |||
1871 | 715 | // lookup the path and delete | ||
1872 | 716 | QString path = findColorSchemePath(name); | ||
1873 | 717 | if ( QFile::remove(path) ) | ||
1874 | 718 | { | ||
1875 | 719 | _colorSchemes.remove(name); | ||
1876 | 720 | return true; | ||
1877 | 721 | } | ||
1878 | 722 | else | ||
1879 | 723 | { | ||
1880 | 724 | qDebug() << "Failed to remove color scheme -" << path; | ||
1881 | 725 | return false; | ||
1882 | 726 | } | ||
1883 | 727 | } | ||
1884 | 728 | QString ColorSchemeManager::findColorSchemePath(const QString& name) const | ||
1885 | 729 | { | ||
1886 | 730 | // QString path = KStandardDirs::locate("data","konsole/"+name+".colorscheme"); | ||
1887 | 731 | QString path(get_color_schemes_dir() + "/"+ name + ".colorscheme"); | ||
1888 | 732 | if ( !path.isEmpty() ) | ||
1889 | 733 | return path; | ||
1890 | 734 | |||
1891 | 735 | //path = KStandardDirs::locate("data","konsole/"+name+".schema"); | ||
1892 | 736 | path = get_color_schemes_dir() + "/"+ name + ".schema"; | ||
1893 | 737 | |||
1894 | 738 | return path; | ||
1895 | 739 | } | ||
1896 | 740 | const ColorScheme* ColorSchemeManager::findColorScheme(const QString& name) | ||
1897 | 741 | { | ||
1898 | 742 | if ( name.isEmpty() ) | ||
1899 | 743 | return defaultColorScheme(); | ||
1900 | 744 | |||
1901 | 745 | if ( _colorSchemes.contains(name) ) | ||
1902 | 746 | return _colorSchemes[name]; | ||
1903 | 747 | else | ||
1904 | 748 | { | ||
1905 | 749 | // look for this color scheme | ||
1906 | 750 | QString path = findColorSchemePath(name); | ||
1907 | 751 | if ( !path.isEmpty() && loadColorScheme(path) ) | ||
1908 | 752 | { | ||
1909 | 753 | return findColorScheme(name); | ||
1910 | 754 | } | ||
1911 | 755 | else | ||
1912 | 756 | { | ||
1913 | 757 | if (!path.isEmpty() && loadKDE3ColorScheme(path)) | ||
1914 | 758 | return findColorScheme(name); | ||
1915 | 759 | } | ||
1916 | 760 | |||
1917 | 761 | qDebug() << "Could not find color scheme - " << name; | ||
1918 | 762 | |||
1919 | 763 | return 0; | ||
1920 | 764 | } | ||
1921 | 765 | } | ||
1922 | 766 | |||
1923 | 767 | ColorSchemeManager* ColorSchemeManager::theColorSchemeManager = 0; | ||
1924 | 768 | //K_GLOBAL_STATIC( ColorSchemeManager , theColorSchemeManager ) | ||
1925 | 769 | ColorSchemeManager* ColorSchemeManager::instance() | ||
1926 | 770 | { | ||
1927 | 771 | if (! theColorSchemeManager) | ||
1928 | 772 | theColorSchemeManager = new ColorSchemeManager(); | ||
1929 | 773 | return theColorSchemeManager; | ||
1930 | 774 | } | ||
1931 | 775 | 0 | ||
1932 | === removed file 'src/plugin/konsole/ColorScheme.h' | |||
1933 | --- src/plugin/konsole/ColorScheme.h 2014-11-12 00:10:12 +0000 | |||
1934 | +++ src/plugin/konsole/ColorScheme.h 1970-01-01 00:00:00 +0000 | |||
1935 | @@ -1,342 +0,0 @@ | |||
1936 | 1 | /* | ||
1937 | 2 | This source file is part of Konsole, a terminal emulator. | ||
1938 | 3 | |||
1939 | 4 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
1940 | 5 | |||
1941 | 6 | This program is free software; you can redistribute it and/or modify | ||
1942 | 7 | it under the terms of the GNU General Public License as published by | ||
1943 | 8 | the Free Software Foundation; either version 2 of the License, or | ||
1944 | 9 | (at your option) any later version. | ||
1945 | 10 | |||
1946 | 11 | This program is distributed in the hope that it will be useful, | ||
1947 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1948 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1949 | 14 | GNU General Public License for more details. | ||
1950 | 15 | |||
1951 | 16 | You should have received a copy of the GNU General Public License | ||
1952 | 17 | along with this program; if not, write to the Free Software | ||
1953 | 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
1954 | 19 | 02110-1301 USA. | ||
1955 | 20 | */ | ||
1956 | 21 | |||
1957 | 22 | #ifndef COLORSCHEME_H | ||
1958 | 23 | #define COLORSCHEME_H | ||
1959 | 24 | |||
1960 | 25 | // Qt | ||
1961 | 26 | #include <QtCore/QHash> | ||
1962 | 27 | #include <QtCore/QList> | ||
1963 | 28 | #include <QtCore/QMetaType> | ||
1964 | 29 | #include <QtCore/QIODevice> | ||
1965 | 30 | #include <QtCore/QSet> | ||
1966 | 31 | #include <QSettings> | ||
1967 | 32 | |||
1968 | 33 | // Konsole | ||
1969 | 34 | #include "CharacterColor.h" | ||
1970 | 35 | |||
1971 | 36 | class QIODevice; | ||
1972 | 37 | //class KConfig; | ||
1973 | 38 | |||
1974 | 39 | |||
1975 | 40 | /** | ||
1976 | 41 | * Represents a color scheme for a terminal display. | ||
1977 | 42 | * | ||
1978 | 43 | * The color scheme includes the palette of colors used to draw the text and character backgrounds | ||
1979 | 44 | * in the display and the opacity level of the display background. | ||
1980 | 45 | */ | ||
1981 | 46 | class ColorScheme | ||
1982 | 47 | { | ||
1983 | 48 | public: | ||
1984 | 49 | /** | ||
1985 | 50 | * Constructs a new color scheme which is initialised to the default color set | ||
1986 | 51 | * for Konsole. | ||
1987 | 52 | */ | ||
1988 | 53 | ColorScheme(); | ||
1989 | 54 | ColorScheme(const ColorScheme& other); | ||
1990 | 55 | ~ColorScheme(); | ||
1991 | 56 | |||
1992 | 57 | /** Sets the descriptive name of the color scheme. */ | ||
1993 | 58 | void setDescription(const QString& description); | ||
1994 | 59 | /** Returns the descriptive name of the color scheme. */ | ||
1995 | 60 | QString description() const; | ||
1996 | 61 | |||
1997 | 62 | /** Sets the name of the color scheme */ | ||
1998 | 63 | void setName(const QString& name); | ||
1999 | 64 | /** Returns the name of the color scheme */ | ||
2000 | 65 | QString name() const; | ||
2001 | 66 | |||
2002 | 67 | #if 0 | ||
2003 | 68 | // Implemented upstream - in user apps | ||
2004 | 69 | /** Reads the color scheme from the specified configuration source */ | ||
2005 | 70 | void read(KConfig& config); | ||
2006 | 71 | /** Writes the color scheme to the specified configuration source */ | ||
2007 | 72 | void write(KConfig& config) const; | ||
2008 | 73 | #endif | ||
2009 | 74 | void read(const QString & filename); | ||
2010 | 75 | |||
2011 | 76 | /** Sets a single entry within the color palette. */ | ||
2012 | 77 | void setColorTableEntry(int index , const ColorEntry& entry); | ||
2013 | 78 | |||
2014 | 79 | /** | ||
2015 | 80 | * Copies the color entries which form the palette for this color scheme | ||
2016 | 81 | * into @p table. @p table should be an array with TABLE_COLORS entries. | ||
2017 | 82 | * | ||
2018 | 83 | * @param table Array into which the color entries for this color scheme | ||
2019 | 84 | * are copied. | ||
2020 | 85 | * @param randomSeed Color schemes may allow certain colors in their | ||
2021 | 86 | * palette to be randomized. The seed is used to pick the random color. | ||
2022 | 87 | */ | ||
2023 | 88 | void getColorTable(ColorEntry* table, uint randomSeed = 0) const; | ||
2024 | 89 | |||
2025 | 90 | /** | ||
2026 | 91 | * Retrieves a single color entry from the table. | ||
2027 | 92 | * | ||
2028 | 93 | * See getColorTable() | ||
2029 | 94 | */ | ||
2030 | 95 | ColorEntry colorEntry(int index , uint randomSeed = 0) const; | ||
2031 | 96 | |||
2032 | 97 | /** | ||
2033 | 98 | * Convenience method. Returns the | ||
2034 | 99 | * foreground color for this scheme, | ||
2035 | 100 | * this is the primary color used to draw the | ||
2036 | 101 | * text in this scheme. | ||
2037 | 102 | */ | ||
2038 | 103 | QColor foregroundColor() const; | ||
2039 | 104 | /** | ||
2040 | 105 | * Convenience method. Returns the background color for | ||
2041 | 106 | * this scheme, this is the primary color used to | ||
2042 | 107 | * draw the terminal background in this scheme. | ||
2043 | 108 | */ | ||
2044 | 109 | QColor backgroundColor() const; | ||
2045 | 110 | |||
2046 | 111 | /** | ||
2047 | 112 | * Returns true if this color scheme has a dark background. | ||
2048 | 113 | * The background color is said to be dark if it has a value of less than 127 | ||
2049 | 114 | * in the HSV color space. | ||
2050 | 115 | */ | ||
2051 | 116 | bool hasDarkBackground() const; | ||
2052 | 117 | |||
2053 | 118 | /** | ||
2054 | 119 | * Sets the opacity level of the display background. @p opacity ranges | ||
2055 | 120 | * between 0 (completely transparent background) and 1 (completely | ||
2056 | 121 | * opaque background). | ||
2057 | 122 | * | ||
2058 | 123 | * Defaults to 1. | ||
2059 | 124 | * | ||
2060 | 125 | * TODO: More documentation | ||
2061 | 126 | */ | ||
2062 | 127 | void setOpacity(qreal opacity); | ||
2063 | 128 | /** | ||
2064 | 129 | * Returns the opacity level for this color scheme, see setOpacity() | ||
2065 | 130 | * TODO: More documentation | ||
2066 | 131 | */ | ||
2067 | 132 | qreal opacity() const; | ||
2068 | 133 | |||
2069 | 134 | /** | ||
2070 | 135 | * Enables randomization of the background color. This will cause | ||
2071 | 136 | * the palette returned by getColorTable() and colorEntry() to | ||
2072 | 137 | * be adjusted depending on the value of the random seed argument | ||
2073 | 138 | * to them. | ||
2074 | 139 | */ | ||
2075 | 140 | void setRandomizedBackgroundColor(bool randomize); | ||
2076 | 141 | |||
2077 | 142 | /** Returns true if the background color is randomized. */ | ||
2078 | 143 | bool randomizedBackgroundColor() const; | ||
2079 | 144 | |||
2080 | 145 | static QString colorNameForIndex(int index); | ||
2081 | 146 | static QString translatedColorNameForIndex(int index); | ||
2082 | 147 | |||
2083 | 148 | private: | ||
2084 | 149 | // specifies how much a particular color can be randomized by | ||
2085 | 150 | class RandomizationRange | ||
2086 | 151 | { | ||
2087 | 152 | public: | ||
2088 | 153 | RandomizationRange() : hue(0) , saturation(0) , value(0) {} | ||
2089 | 154 | |||
2090 | 155 | bool isNull() const | ||
2091 | 156 | { | ||
2092 | 157 | return ( hue == 0 && saturation == 0 && value == 0 ); | ||
2093 | 158 | } | ||
2094 | 159 | |||
2095 | 160 | quint16 hue; | ||
2096 | 161 | quint8 saturation; | ||
2097 | 162 | quint8 value; | ||
2098 | 163 | }; | ||
2099 | 164 | |||
2100 | 165 | // returns the active color table. if none has been set specifically, | ||
2101 | 166 | // this is the default color table. | ||
2102 | 167 | const ColorEntry* colorTable() const; | ||
2103 | 168 | |||
2104 | 169 | #if 0 | ||
2105 | 170 | // implemented upstream - user apps | ||
2106 | 171 | // reads a single colour entry from a KConfig source | ||
2107 | 172 | // and sets the palette entry at 'index' to the entry read. | ||
2108 | 173 | void readColorEntry(KConfig& config , int index); | ||
2109 | 174 | // writes a single colour entry to a KConfig source | ||
2110 | 175 | void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const; | ||
2111 | 176 | #endif | ||
2112 | 177 | void readColorEntry(QSettings *s, int index); | ||
2113 | 178 | |||
2114 | 179 | // sets the amount of randomization allowed for a particular color | ||
2115 | 180 | // in the palette. creates the randomization table if | ||
2116 | 181 | // it does not already exist | ||
2117 | 182 | void setRandomizationRange( int index , quint16 hue , quint8 saturation , quint8 value ); | ||
2118 | 183 | |||
2119 | 184 | QString _description; | ||
2120 | 185 | QString _name; | ||
2121 | 186 | qreal _opacity; | ||
2122 | 187 | ColorEntry* _table; // pointer to custom color table or 0 if the default | ||
2123 | 188 | // color scheme is being used | ||
2124 | 189 | |||
2125 | 190 | |||
2126 | 191 | static const quint16 MAX_HUE = 340; | ||
2127 | 192 | |||
2128 | 193 | RandomizationRange* _randomTable; // pointer to randomization table or 0 | ||
2129 | 194 | // if no colors in the color scheme support | ||
2130 | 195 | // randomization | ||
2131 | 196 | |||
2132 | 197 | static const char* const colorNames[TABLE_COLORS]; | ||
2133 | 198 | static const char* const translatedColorNames[TABLE_COLORS]; | ||
2134 | 199 | |||
2135 | 200 | static const ColorEntry defaultTable[]; // table of default color entries | ||
2136 | 201 | }; | ||
2137 | 202 | |||
2138 | 203 | /** | ||
2139 | 204 | * A color scheme which uses colors from the standard KDE color palette. | ||
2140 | 205 | * | ||
2141 | 206 | * This is designed primarily for the benefit of users who are using specially | ||
2142 | 207 | * designed colors. | ||
2143 | 208 | * | ||
2144 | 209 | * TODO Implement and make it the default on systems with specialized KDE | ||
2145 | 210 | * color schemes. | ||
2146 | 211 | */ | ||
2147 | 212 | class AccessibleColorScheme : public ColorScheme | ||
2148 | 213 | { | ||
2149 | 214 | public: | ||
2150 | 215 | AccessibleColorScheme(); | ||
2151 | 216 | }; | ||
2152 | 217 | |||
2153 | 218 | /** | ||
2154 | 219 | * Reads a color scheme stored in the .schema format used in the KDE 3 incarnation | ||
2155 | 220 | * of Konsole | ||
2156 | 221 | * | ||
2157 | 222 | * Only the basic essentials ( title and color palette entries ) are currently | ||
2158 | 223 | * supported. Additional options such as background image and background | ||
2159 | 224 | * blend colors are ignored. | ||
2160 | 225 | */ | ||
2161 | 226 | class KDE3ColorSchemeReader | ||
2162 | 227 | { | ||
2163 | 228 | public: | ||
2164 | 229 | /** | ||
2165 | 230 | * Constructs a new reader which reads from the specified device. | ||
2166 | 231 | * The device should be open in read-only mode. | ||
2167 | 232 | */ | ||
2168 | 233 | KDE3ColorSchemeReader( QIODevice* device ); | ||
2169 | 234 | |||
2170 | 235 | /** | ||
2171 | 236 | * Reads and parses the contents of the .schema file from the input | ||
2172 | 237 | * device and returns the ColorScheme defined within it. | ||
2173 | 238 | * | ||
2174 | 239 | * Returns a null pointer if an error occurs whilst parsing | ||
2175 | 240 | * the contents of the file. | ||
2176 | 241 | */ | ||
2177 | 242 | ColorScheme* read(); | ||
2178 | 243 | |||
2179 | 244 | private: | ||
2180 | 245 | // reads a line from the file specifying a colour palette entry | ||
2181 | 246 | // format is: color [index] [red] [green] [blue] [transparent] [bold] | ||
2182 | 247 | bool readColorLine(const QString& line , ColorScheme* scheme); | ||
2183 | 248 | bool readTitleLine(const QString& line , ColorScheme* scheme); | ||
2184 | 249 | |||
2185 | 250 | QIODevice* _device; | ||
2186 | 251 | }; | ||
2187 | 252 | |||
2188 | 253 | /** | ||
2189 | 254 | * Manages the color schemes available for use by terminal displays. | ||
2190 | 255 | * See ColorScheme | ||
2191 | 256 | */ | ||
2192 | 257 | class ColorSchemeManager | ||
2193 | 258 | { | ||
2194 | 259 | public: | ||
2195 | 260 | |||
2196 | 261 | /** | ||
2197 | 262 | * Constructs a new ColorSchemeManager and loads the list | ||
2198 | 263 | * of available color schemes. | ||
2199 | 264 | * | ||
2200 | 265 | * The color schemes themselves are not loaded until they are first | ||
2201 | 266 | * requested via a call to findColorScheme() | ||
2202 | 267 | */ | ||
2203 | 268 | ColorSchemeManager(); | ||
2204 | 269 | /** | ||
2205 | 270 | * Destroys the ColorSchemeManager and saves any modified color schemes to disk. | ||
2206 | 271 | */ | ||
2207 | 272 | ~ColorSchemeManager(); | ||
2208 | 273 | |||
2209 | 274 | /** | ||
2210 | 275 | * Returns the default color scheme for Konsole | ||
2211 | 276 | */ | ||
2212 | 277 | const ColorScheme* defaultColorScheme() const; | ||
2213 | 278 | |||
2214 | 279 | /** | ||
2215 | 280 | * Returns the color scheme with the given name or 0 if no | ||
2216 | 281 | * scheme with that name exists. If @p name is empty, the | ||
2217 | 282 | * default color scheme is returned. | ||
2218 | 283 | * | ||
2219 | 284 | * The first time that a color scheme with a particular name is | ||
2220 | 285 | * requested, the configuration information is loaded from disk. | ||
2221 | 286 | */ | ||
2222 | 287 | const ColorScheme* findColorScheme(const QString& name); | ||
2223 | 288 | |||
2224 | 289 | #if 0 | ||
2225 | 290 | /** | ||
2226 | 291 | * Adds a new color scheme to the manager. If @p scheme has the same name as | ||
2227 | 292 | * an existing color scheme, it replaces the existing scheme. | ||
2228 | 293 | * | ||
2229 | 294 | * TODO - Ensure the old color scheme gets deleted | ||
2230 | 295 | */ | ||
2231 | 296 | void addColorScheme(ColorScheme* scheme); | ||
2232 | 297 | #endif | ||
2233 | 298 | /** | ||
2234 | 299 | * Deletes a color scheme. Returns true on successful deletion or false otherwise. | ||
2235 | 300 | */ | ||
2236 | 301 | bool deleteColorScheme(const QString& name); | ||
2237 | 302 | |||
2238 | 303 | /** | ||
2239 | 304 | * Returns a list of the all the available color schemes. | ||
2240 | 305 | * This may be slow when first called because all of the color | ||
2241 | 306 | * scheme resources on disk must be located, read and parsed. | ||
2242 | 307 | * | ||
2243 | 308 | * Subsequent calls will be inexpensive. | ||
2244 | 309 | */ | ||
2245 | 310 | QList<const ColorScheme*> allColorSchemes(); | ||
2246 | 311 | |||
2247 | 312 | /** Returns the global color scheme manager instance. */ | ||
2248 | 313 | static ColorSchemeManager* instance(); | ||
2249 | 314 | |||
2250 | 315 | private: | ||
2251 | 316 | // loads a color scheme from a KDE 4+ .colorscheme file | ||
2252 | 317 | bool loadColorScheme(const QString& path); | ||
2253 | 318 | // loads a color scheme from a KDE 3 .schema file | ||
2254 | 319 | bool loadKDE3ColorScheme(const QString& path); | ||
2255 | 320 | // returns a list of paths of color schemes in the KDE 4+ .colorscheme file format | ||
2256 | 321 | QList<QString> listColorSchemes(); | ||
2257 | 322 | // returns a list of paths of color schemes in the .schema file format | ||
2258 | 323 | // used in KDE 3 | ||
2259 | 324 | QList<QString> listKDE3ColorSchemes(); | ||
2260 | 325 | // loads all of the color schemes | ||
2261 | 326 | void loadAllColorSchemes(); | ||
2262 | 327 | // finds the path of a color scheme | ||
2263 | 328 | QString findColorSchemePath(const QString& name) const; | ||
2264 | 329 | |||
2265 | 330 | QHash<QString,const ColorScheme*> _colorSchemes; | ||
2266 | 331 | QSet<ColorScheme*> _modifiedSchemes; | ||
2267 | 332 | |||
2268 | 333 | bool _haveLoadedAll; | ||
2269 | 334 | |||
2270 | 335 | static const ColorScheme _defaultColorScheme; | ||
2271 | 336 | |||
2272 | 337 | static ColorSchemeManager * theColorSchemeManager; | ||
2273 | 338 | }; | ||
2274 | 339 | |||
2275 | 340 | Q_DECLARE_METATYPE(const ColorScheme*) | ||
2276 | 341 | |||
2277 | 342 | #endif //COLORSCHEME_H | ||
2278 | 343 | 0 | ||
2279 | === removed file 'src/plugin/konsole/ColorTables.h' | |||
2280 | --- src/plugin/konsole/ColorTables.h 2014-11-12 00:10:12 +0000 | |||
2281 | +++ src/plugin/konsole/ColorTables.h 1970-01-01 00:00:00 +0000 | |||
2282 | @@ -1,55 +0,0 @@ | |||
2283 | 1 | #ifndef _COLOR_TABLE_H | ||
2284 | 2 | #define _COLOR_TABLE_H | ||
2285 | 3 | |||
2286 | 4 | #include "CharacterColor.h" | ||
2287 | 5 | |||
2288 | 6 | //using namespace Konsole; | ||
2289 | 7 | #if 0 | ||
2290 | 8 | static const ColorEntry whiteonblack_color_table[TABLE_COLORS] = { | ||
2291 | 9 | // normal | ||
2292 | 10 | ColorEntry(QColor(0xFF,0xFF,0xFF), false ), ColorEntry( QColor(0x00,0x00,0x00), true ), // Dfore, Dback | ||
2293 | 11 | ColorEntry(QColor(0x00,0x00,0x00), false ), ColorEntry( QColor(0xB2,0x18,0x18), false ), // Black, Red | ||
2294 | 12 | ColorEntry(QColor(0x18,0xB2,0x18), false ), ColorEntry( QColor(0xB2,0x68,0x18), false ), // Green, Yellow | ||
2295 | 13 | ColorEntry(QColor(0x18,0x18,0xB2), false ), ColorEntry( QColor(0xB2,0x18,0xB2), false ), // Blue, Magenta | ||
2296 | 14 | ColorEntry(QColor(0x18,0xB2,0xB2), false ), ColorEntry( QColor(0xB2,0xB2,0xB2), false ), // Cyan, White | ||
2297 | 15 | // intensiv | ||
2298 | 16 | ColorEntry(QColor(0x00,0x00,0x00), false ), ColorEntry( QColor(0xFF,0xFF,0xFF), true ), | ||
2299 | 17 | ColorEntry(QColor(0x68,0x68,0x68), false ), ColorEntry( QColor(0xFF,0x54,0x54), false ), | ||
2300 | 18 | ColorEntry(QColor(0x54,0xFF,0x54), false ), ColorEntry( QColor(0xFF,0xFF,0x54), false ), | ||
2301 | 19 | ColorEntry(QColor(0x54,0x54,0xFF), false ), ColorEntry( QColor(0xFF,0x54,0xFF), false ), | ||
2302 | 20 | ColorEntry(QColor(0x54,0xFF,0xFF), false ), ColorEntry( QColor(0xFF,0xFF,0xFF), false ) | ||
2303 | 21 | }; | ||
2304 | 22 | |||
2305 | 23 | static const ColorEntry greenonblack_color_table[TABLE_COLORS] = { | ||
2306 | 24 | ColorEntry(QColor( 24, 240, 24), false), ColorEntry(QColor( 0, 0, 0), true), | ||
2307 | 25 | ColorEntry(QColor( 0, 0, 0), false), ColorEntry(QColor( 178, 24, 24), false), | ||
2308 | 26 | ColorEntry(QColor( 24, 178, 24), false), ColorEntry(QColor( 178, 104, 24), false), | ||
2309 | 27 | ColorEntry(QColor( 24, 24, 178), false), ColorEntry(QColor( 178, 24, 178), false), | ||
2310 | 28 | ColorEntry(QColor( 24, 178, 178), false), ColorEntry(QColor( 178, 178, 178), false), | ||
2311 | 29 | // intensive colors | ||
2312 | 30 | ColorEntry(QColor( 24, 240, 24), false ), ColorEntry(QColor( 0, 0, 0), true ), | ||
2313 | 31 | ColorEntry(QColor( 104, 104, 104), false ), ColorEntry(QColor( 255, 84, 84), false ), | ||
2314 | 32 | ColorEntry(QColor( 84, 255, 84), false ), ColorEntry(QColor( 255, 255, 84), false ), | ||
2315 | 33 | ColorEntry(QColor( 84, 84, 255), false ), ColorEntry(QColor( 255, 84, 255), false ), | ||
2316 | 34 | ColorEntry(QColor( 84, 255, 255), false ), ColorEntry(QColor( 255, 255, 255), false ) | ||
2317 | 35 | }; | ||
2318 | 36 | |||
2319 | 37 | static const ColorEntry blackonlightyellow_color_table[TABLE_COLORS] = { | ||
2320 | 38 | ColorEntry(QColor( 0, 0, 0), false), ColorEntry(QColor( 255, 255, 221), true), | ||
2321 | 39 | ColorEntry(QColor( 0, 0, 0), false), ColorEntry(QColor( 178, 24, 24), false), | ||
2322 | 40 | ColorEntry(QColor( 24, 178, 24), false), ColorEntry(QColor( 178, 104, 24), false), | ||
2323 | 41 | ColorEntry(QColor( 24, 24, 178), false), ColorEntry(QColor( 178, 24, 178), false), | ||
2324 | 42 | ColorEntry(QColor( 24, 178, 178), false), ColorEntry(QColor( 178, 178, 178), false), | ||
2325 | 43 | ColorEntry(QColor( 0, 0, 0), false), ColorEntry(QColor( 255, 255, 221), true), | ||
2326 | 44 | ColorEntry(QColor(104, 104, 104), false), ColorEntry(QColor( 255, 84, 84), false), | ||
2327 | 45 | ColorEntry(QColor( 84, 255, 84), false), ColorEntry(QColor( 255, 255, 84), false), | ||
2328 | 46 | ColorEntry(QColor( 84, 84, 255), false), ColorEntry(QColor( 255, 84, 255), false), | ||
2329 | 47 | ColorEntry(QColor( 84, 255, 255), false), ColorEntry(QColor( 255, 255, 255), false) | ||
2330 | 48 | }; | ||
2331 | 49 | |||
2332 | 50 | |||
2333 | 51 | #endif | ||
2334 | 52 | |||
2335 | 53 | |||
2336 | 54 | #endif | ||
2337 | 55 | |||
2338 | 56 | 0 | ||
2339 | === removed file 'src/plugin/konsole/DefaultTranslatorText.h' | |||
2340 | --- src/plugin/konsole/DefaultTranslatorText.h 2014-11-12 00:10:12 +0000 | |||
2341 | +++ src/plugin/konsole/DefaultTranslatorText.h 1970-01-01 00:00:00 +0000 | |||
2342 | @@ -1,2 +0,0 @@ | |||
2343 | 1 | "keyboard \"Fallback Key Translator\"\n" | ||
2344 | 2 | "key Tab : \"\\t\" \0" | ||
2345 | 3 | 0 | ||
2346 | === removed file 'src/plugin/konsole/Emulation.cpp' | |||
2347 | --- src/plugin/konsole/Emulation.cpp 2014-11-12 00:10:12 +0000 | |||
2348 | +++ src/plugin/konsole/Emulation.cpp 1970-01-01 00:00:00 +0000 | |||
2349 | @@ -1,458 +0,0 @@ | |||
2350 | 1 | /* | ||
2351 | 2 | Copyright 2007-2008 Robert Knight <robertknight@gmail.com> | ||
2352 | 3 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> | ||
2353 | 4 | Copyright 1996 by Matthias Ettrich <ettrich@kde.org> | ||
2354 | 5 | |||
2355 | 6 | This program is free software; you can redistribute it and/or modify | ||
2356 | 7 | it under the terms of the GNU General Public License as published by | ||
2357 | 8 | the Free Software Foundation; either version 2 of the License, or | ||
2358 | 9 | (at your option) any later version. | ||
2359 | 10 | |||
2360 | 11 | This program is distributed in the hope that it will be useful, | ||
2361 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2362 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2363 | 14 | GNU General Public License for more details. | ||
2364 | 15 | |||
2365 | 16 | You should have received a copy of the GNU General Public License | ||
2366 | 17 | along with this program; if not, write to the Free Software | ||
2367 | 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
2368 | 19 | 02110-1301 USA. | ||
2369 | 20 | */ | ||
2370 | 21 | |||
2371 | 22 | // Own | ||
2372 | 23 | #include "Emulation.h" | ||
2373 | 24 | |||
2374 | 25 | // System | ||
2375 | 26 | #include <assert.h> | ||
2376 | 27 | #include <stdio.h> | ||
2377 | 28 | #include <stdlib.h> | ||
2378 | 29 | #include <unistd.h> | ||
2379 | 30 | |||
2380 | 31 | // Qt | ||
2381 | 32 | #include <QGuiApplication> | ||
2382 | 33 | #include <QtGui/QClipboard> | ||
2383 | 34 | #include <QtCore/QHash> | ||
2384 | 35 | #include <QtGui/QKeyEvent> | ||
2385 | 36 | #include <QtCore/QRegExp> | ||
2386 | 37 | #include <QtCore/QTextStream> | ||
2387 | 38 | #include <QtCore/QThread> | ||
2388 | 39 | |||
2389 | 40 | #include <QtCore/QTime> | ||
2390 | 41 | |||
2391 | 42 | // KDE | ||
2392 | 43 | //#include <kdebug.h> | ||
2393 | 44 | |||
2394 | 45 | // Konsole | ||
2395 | 46 | #include "KeyboardTranslator.h" | ||
2396 | 47 | #include "Screen.h" | ||
2397 | 48 | #include "TerminalCharacterDecoder.h" | ||
2398 | 49 | #include "ScreenWindow.h" | ||
2399 | 50 | |||
2400 | 51 | Emulation::Emulation() : | ||
2401 | 52 | _currentScreen(0), | ||
2402 | 53 | _codec(0), | ||
2403 | 54 | _decoder(0), | ||
2404 | 55 | _keyTranslator(0), | ||
2405 | 56 | _usesMouse(false) | ||
2406 | 57 | { | ||
2407 | 58 | // create screens with a default size | ||
2408 | 59 | _screen[0] = new Screen(40,80); | ||
2409 | 60 | _screen[1] = new Screen(40,80); | ||
2410 | 61 | _currentScreen = _screen[0]; | ||
2411 | 62 | |||
2412 | 63 | QObject::connect(&_bulkTimer1, SIGNAL(timeout()), this, SLOT(showBulk()) ); | ||
2413 | 64 | QObject::connect(&_bulkTimer2, SIGNAL(timeout()), this, SLOT(showBulk()) ); | ||
2414 | 65 | |||
2415 | 66 | // listen for mouse status changes | ||
2416 | 67 | connect( this , SIGNAL(programUsesMouseChanged(bool)) , | ||
2417 | 68 | SLOT(usesMouseChanged(bool)) ); | ||
2418 | 69 | } | ||
2419 | 70 | |||
2420 | 71 | bool Emulation::programUsesMouse() const | ||
2421 | 72 | { | ||
2422 | 73 | return _usesMouse; | ||
2423 | 74 | } | ||
2424 | 75 | |||
2425 | 76 | void Emulation::usesMouseChanged(bool usesMouse) | ||
2426 | 77 | { | ||
2427 | 78 | _usesMouse = usesMouse; | ||
2428 | 79 | } | ||
2429 | 80 | |||
2430 | 81 | ScreenWindow* Emulation::createWindow() | ||
2431 | 82 | { | ||
2432 | 83 | ScreenWindow* window = new ScreenWindow(); | ||
2433 | 84 | window->setScreen(_currentScreen); | ||
2434 | 85 | _windows << window; | ||
2435 | 86 | |||
2436 | 87 | connect(window , SIGNAL(selectionChanged()), | ||
2437 | 88 | this , SLOT(bufferedUpdate())); | ||
2438 | 89 | |||
2439 | 90 | connect(this , SIGNAL(outputChanged()), | ||
2440 | 91 | window , SLOT(notifyOutputChanged()) ); | ||
2441 | 92 | return window; | ||
2442 | 93 | } | ||
2443 | 94 | |||
2444 | 95 | Emulation::~Emulation() | ||
2445 | 96 | { | ||
2446 | 97 | QListIterator<ScreenWindow*> windowIter(_windows); | ||
2447 | 98 | |||
2448 | 99 | while (windowIter.hasNext()) | ||
2449 | 100 | { | ||
2450 | 101 | delete windowIter.next(); | ||
2451 | 102 | } | ||
2452 | 103 | |||
2453 | 104 | delete _screen[0]; | ||
2454 | 105 | delete _screen[1]; | ||
2455 | 106 | delete _decoder; | ||
2456 | 107 | } | ||
2457 | 108 | |||
2458 | 109 | void Emulation::setScreen(int n) | ||
2459 | 110 | { | ||
2460 | 111 | Screen *old = _currentScreen; | ||
2461 | 112 | _currentScreen = _screen[n & 1]; | ||
2462 | 113 | if (_currentScreen != old) | ||
2463 | 114 | { | ||
2464 | 115 | // tell all windows onto this emulation to switch to the newly active screen | ||
2465 | 116 | foreach(ScreenWindow* window,_windows) | ||
2466 | 117 | window->setScreen(_currentScreen); | ||
2467 | 118 | } | ||
2468 | 119 | } | ||
2469 | 120 | |||
2470 | 121 | void Emulation::clearHistory() | ||
2471 | 122 | { | ||
2472 | 123 | _screen[0]->setScroll( _screen[0]->getScroll() , false ); | ||
2473 | 124 | } | ||
2474 | 125 | void Emulation::setHistory(const HistoryType& t) | ||
2475 | 126 | { | ||
2476 | 127 | _screen[0]->setScroll(t); | ||
2477 | 128 | |||
2478 | 129 | showBulk(); | ||
2479 | 130 | } | ||
2480 | 131 | |||
2481 | 132 | const HistoryType& Emulation::history() const | ||
2482 | 133 | { | ||
2483 | 134 | return _screen[0]->getScroll(); | ||
2484 | 135 | } | ||
2485 | 136 | |||
2486 | 137 | void Emulation::setCodec(const QTextCodec * qtc) | ||
2487 | 138 | { | ||
2488 | 139 | if (qtc) | ||
2489 | 140 | _codec = qtc; | ||
2490 | 141 | else | ||
2491 | 142 | setCodec(LocaleCodec); | ||
2492 | 143 | |||
2493 | 144 | delete _decoder; | ||
2494 | 145 | _decoder = _codec->makeDecoder(); | ||
2495 | 146 | |||
2496 | 147 | emit useUtf8Request(utf8()); | ||
2497 | 148 | } | ||
2498 | 149 | |||
2499 | 150 | void Emulation::setCodec(EmulationCodec codec) | ||
2500 | 151 | { | ||
2501 | 152 | if ( codec == Utf8Codec ) | ||
2502 | 153 | setCodec( QTextCodec::codecForName("utf8") ); | ||
2503 | 154 | else if ( codec == LocaleCodec ) | ||
2504 | 155 | setCodec( QTextCodec::codecForLocale() ); | ||
2505 | 156 | } | ||
2506 | 157 | |||
2507 | 158 | void Emulation::setKeyBindings(const QString& name) | ||
2508 | 159 | { | ||
2509 | 160 | _keyTranslator = KeyboardTranslatorManager::instance()->findTranslator(name); | ||
2510 | 161 | if (!_keyTranslator) | ||
2511 | 162 | { | ||
2512 | 163 | _keyTranslator = KeyboardTranslatorManager::instance()->defaultTranslator(); | ||
2513 | 164 | } | ||
2514 | 165 | } | ||
2515 | 166 | |||
2516 | 167 | QString Emulation::keyBindings() const | ||
2517 | 168 | { | ||
2518 | 169 | return _keyTranslator->name(); | ||
2519 | 170 | } | ||
2520 | 171 | |||
2521 | 172 | void Emulation::receiveChar(int c) | ||
2522 | 173 | // process application unicode input to terminal | ||
2523 | 174 | // this is a trivial scanner | ||
2524 | 175 | { | ||
2525 | 176 | c &= 0xff; | ||
2526 | 177 | switch (c) | ||
2527 | 178 | { | ||
2528 | 179 | case '\b' : _currentScreen->backspace(); break; | ||
2529 | 180 | case '\t' : _currentScreen->tab(); break; | ||
2530 | 181 | case '\n' : _currentScreen->newLine(); break; | ||
2531 | 182 | case '\r' : _currentScreen->toStartOfLine(); break; | ||
2532 | 183 | case 0x07 : emit stateSet(NOTIFYBELL); | ||
2533 | 184 | break; | ||
2534 | 185 | default : _currentScreen->displayCharacter(c); break; | ||
2535 | 186 | }; | ||
2536 | 187 | } | ||
2537 | 188 | |||
2538 | 189 | void Emulation::sendKeyEvent( QKeyEvent* ev ) | ||
2539 | 190 | { | ||
2540 | 191 | emit stateSet(NOTIFYNORMAL); | ||
2541 | 192 | |||
2542 | 193 | if (!ev->text().isEmpty()) | ||
2543 | 194 | { // A block of text | ||
2544 | 195 | // Note that the text is proper unicode. | ||
2545 | 196 | // We should do a conversion here | ||
2546 | 197 | emit sendData(ev->text().toUtf8(),ev->text().length()); | ||
2547 | 198 | } | ||
2548 | 199 | } | ||
2549 | 200 | |||
2550 | 201 | void Emulation::sendString(const char*,int) | ||
2551 | 202 | { | ||
2552 | 203 | // default implementation does nothing | ||
2553 | 204 | } | ||
2554 | 205 | |||
2555 | 206 | void Emulation::sendMouseEvent(int /*buttons*/, int /*column*/, int /*row*/, int /*eventType*/) | ||
2556 | 207 | { | ||
2557 | 208 | // default implementation does nothing | ||
2558 | 209 | } | ||
2559 | 210 | |||
2560 | 211 | /* | ||
2561 | 212 | We are doing code conversion from locale to unicode first. | ||
2562 | 213 | TODO: Character composition from the old code. See #96536 | ||
2563 | 214 | */ | ||
2564 | 215 | |||
2565 | 216 | void Emulation::receiveData(const char* text, int length) | ||
2566 | 217 | { | ||
2567 | 218 | emit stateSet(NOTIFYACTIVITY); | ||
2568 | 219 | |||
2569 | 220 | bufferedUpdate(); | ||
2570 | 221 | |||
2571 | 222 | QString unicodeText = _decoder->toUnicode(text,length); | ||
2572 | 223 | |||
2573 | 224 | //send characters to terminal emulator | ||
2574 | 225 | for (int i=0;i<unicodeText.length();i++) | ||
2575 | 226 | receiveChar(unicodeText[i].unicode()); | ||
2576 | 227 | |||
2577 | 228 | //look for z-modem indicator | ||
2578 | 229 | //-- someone who understands more about z-modems that I do may be able to move | ||
2579 | 230 | //this check into the above for loop? | ||
2580 | 231 | for (int i=0;i<length;i++) | ||
2581 | 232 | { | ||
2582 | 233 | if (text[i] == '\030') | ||
2583 | 234 | { | ||
2584 | 235 | if ((length-i-1 > 3) && (strncmp(text+i+1, "B00", 3) == 0)) | ||
2585 | 236 | emit zmodemDetected(); | ||
2586 | 237 | } | ||
2587 | 238 | } | ||
2588 | 239 | } | ||
2589 | 240 | |||
2590 | 241 | //OLDER VERSION | ||
2591 | 242 | //This version of onRcvBlock was commented out because | ||
2592 | 243 | // a) It decoded incoming characters one-by-one, which is slow in the current version of Qt (4.2 tech preview) | ||
2593 | 244 | // b) It messed up decoding of non-ASCII characters, with the result that (for example) chinese characters | ||
2594 | 245 | // were not printed properly. | ||
2595 | 246 | // | ||
2596 | 247 | //There is something about stopping the _decoder if "we get a control code halfway a multi-byte sequence" (see below) | ||
2597 | 248 | //which hasn't been ported into the newer function (above). Hopefully someone who understands this better | ||
2598 | 249 | //can find an alternative way of handling the check. | ||
2599 | 250 | |||
2600 | 251 | |||
2601 | 252 | /*void Emulation::onRcvBlock(const char *s, int len) | ||
2602 | 253 | { | ||
2603 | 254 | emit notifySessionState(NOTIFYACTIVITY); | ||
2604 | 255 | |||
2605 | 256 | bufferedUpdate(); | ||
2606 | 257 | for (int i = 0; i < len; i++) | ||
2607 | 258 | { | ||
2608 | 259 | |||
2609 | 260 | QString result = _decoder->toUnicode(&s[i],1); | ||
2610 | 261 | int reslen = result.length(); | ||
2611 | 262 | |||
2612 | 263 | // If we get a control code halfway a multi-byte sequence | ||
2613 | 264 | // we flush the _decoder and continue with the control code. | ||
2614 | 265 | if ((s[i] < 32) && (s[i] > 0)) | ||
2615 | 266 | { | ||
2616 | 267 | // Flush _decoder | ||
2617 | 268 | while(!result.length()) | ||
2618 | 269 | result = _decoder->toUnicode(&s[i],1); | ||
2619 | 270 | reslen = 1; | ||
2620 | 271 | result.resize(reslen); | ||
2621 | 272 | result[0] = QChar(s[i]); | ||
2622 | 273 | } | ||
2623 | 274 | |||
2624 | 275 | for (int j = 0; j < reslen; j++) | ||
2625 | 276 | { | ||
2626 | 277 | if (result[j].characterategory() == QChar::Mark_NonSpacing) | ||
2627 | 278 | _currentScreen->compose(result.mid(j,1)); | ||
2628 | 279 | else | ||
2629 | 280 | onRcvChar(result[j].unicode()); | ||
2630 | 281 | } | ||
2631 | 282 | if (s[i] == '\030') | ||
2632 | 283 | { | ||
2633 | 284 | if ((len-i-1 > 3) && (strncmp(s+i+1, "B00", 3) == 0)) | ||
2634 | 285 | emit zmodemDetected(); | ||
2635 | 286 | } | ||
2636 | 287 | } | ||
2637 | 288 | }*/ | ||
2638 | 289 | |||
2639 | 290 | void Emulation::writeToStream( TerminalCharacterDecoder* _decoder , | ||
2640 | 291 | int startLine , | ||
2641 | 292 | int endLine) | ||
2642 | 293 | { | ||
2643 | 294 | _currentScreen->writeLinesToStream(_decoder,startLine,endLine); | ||
2644 | 295 | } | ||
2645 | 296 | |||
2646 | 297 | int Emulation::lineCount() const | ||
2647 | 298 | { | ||
2648 | 299 | // sum number of lines currently on _screen plus number of lines in history | ||
2649 | 300 | return _currentScreen->getLines() + _currentScreen->getHistLines(); | ||
2650 | 301 | } | ||
2651 | 302 | |||
2652 | 303 | #define BULK_TIMEOUT1 10 | ||
2653 | 304 | #define BULK_TIMEOUT2 40 | ||
2654 | 305 | |||
2655 | 306 | void Emulation::showBulk() | ||
2656 | 307 | { | ||
2657 | 308 | _bulkTimer1.stop(); | ||
2658 | 309 | _bulkTimer2.stop(); | ||
2659 | 310 | |||
2660 | 311 | emit outputChanged(); | ||
2661 | 312 | |||
2662 | 313 | _currentScreen->resetScrolledLines(); | ||
2663 | 314 | _currentScreen->resetDroppedLines(); | ||
2664 | 315 | } | ||
2665 | 316 | |||
2666 | 317 | void Emulation::bufferedUpdate() | ||
2667 | 318 | { | ||
2668 | 319 | _bulkTimer1.setSingleShot(true); | ||
2669 | 320 | _bulkTimer1.start(BULK_TIMEOUT1); | ||
2670 | 321 | if (!_bulkTimer2.isActive()) | ||
2671 | 322 | { | ||
2672 | 323 | _bulkTimer2.setSingleShot(true); | ||
2673 | 324 | _bulkTimer2.start(BULK_TIMEOUT2); | ||
2674 | 325 | } | ||
2675 | 326 | } | ||
2676 | 327 | |||
2677 | 328 | char Emulation::eraseChar() const | ||
2678 | 329 | { | ||
2679 | 330 | return '\b'; | ||
2680 | 331 | } | ||
2681 | 332 | |||
2682 | 333 | void Emulation::setImageSize(int lines, int columns) | ||
2683 | 334 | { | ||
2684 | 335 | if ((lines < 1) || (columns < 1)) | ||
2685 | 336 | return; | ||
2686 | 337 | |||
2687 | 338 | QSize screenSize[2] = { QSize(_screen[0]->getColumns(), | ||
2688 | 339 | _screen[0]->getLines()), | ||
2689 | 340 | QSize(_screen[1]->getColumns(), | ||
2690 | 341 | _screen[1]->getLines()) }; | ||
2691 | 342 | QSize newSize(columns,lines); | ||
2692 | 343 | |||
2693 | 344 | if (newSize == screenSize[0] && newSize == screenSize[1]) | ||
2694 | 345 | return; | ||
2695 | 346 | |||
2696 | 347 | _screen[0]->resizeImage(lines,columns); | ||
2697 | 348 | _screen[1]->resizeImage(lines,columns); | ||
2698 | 349 | |||
2699 | 350 | emit imageSizeChanged(lines,columns); | ||
2700 | 351 | |||
2701 | 352 | bufferedUpdate(); | ||
2702 | 353 | } | ||
2703 | 354 | |||
2704 | 355 | QSize Emulation::imageSize() const | ||
2705 | 356 | { | ||
2706 | 357 | return QSize(_currentScreen->getColumns(), _currentScreen->getLines()); | ||
2707 | 358 | } | ||
2708 | 359 | |||
2709 | 360 | ushort ExtendedCharTable::extendedCharHash(ushort* unicodePoints , ushort length) const | ||
2710 | 361 | { | ||
2711 | 362 | ushort hash = 0; | ||
2712 | 363 | for ( ushort i = 0 ; i < length ; i++ ) | ||
2713 | 364 | { | ||
2714 | 365 | hash = 31*hash + unicodePoints[i]; | ||
2715 | 366 | } | ||
2716 | 367 | return hash; | ||
2717 | 368 | } | ||
2718 | 369 | bool ExtendedCharTable::extendedCharMatch(ushort hash , ushort* unicodePoints , ushort length) const | ||
2719 | 370 | { | ||
2720 | 371 | ushort* entry = extendedCharTable[hash]; | ||
2721 | 372 | |||
2722 | 373 | // compare given length with stored sequence length ( given as the first ushort in the | ||
2723 | 374 | // stored buffer ) | ||
2724 | 375 | if ( entry == 0 || entry[0] != length ) | ||
2725 | 376 | return false; | ||
2726 | 377 | // if the lengths match, each character must be checked. the stored buffer starts at | ||
2727 | 378 | // entry[1] | ||
2728 | 379 | for ( int i = 0 ; i < length ; i++ ) | ||
2729 | 380 | { | ||
2730 | 381 | if ( entry[i+1] != unicodePoints[i] ) | ||
2731 | 382 | return false; | ||
2732 | 383 | } | ||
2733 | 384 | return true; | ||
2734 | 385 | } | ||
2735 | 386 | ushort ExtendedCharTable::createExtendedChar(ushort* unicodePoints , ushort length) | ||
2736 | 387 | { | ||
2737 | 388 | // look for this sequence of points in the table | ||
2738 | 389 | ushort hash = extendedCharHash(unicodePoints,length); | ||
2739 | 390 | |||
2740 | 391 | // check existing entry for match | ||
2741 | 392 | while ( extendedCharTable.contains(hash) ) | ||
2742 | 393 | { | ||
2743 | 394 | if ( extendedCharMatch(hash,unicodePoints,length) ) | ||
2744 | 395 | { | ||
2745 | 396 | // this sequence already has an entry in the table, | ||
2746 | 397 | // return its hash | ||
2747 | 398 | return hash; | ||
2748 | 399 | } | ||
2749 | 400 | else | ||
2750 | 401 | { | ||
2751 | 402 | // if hash is already used by another, different sequence of unicode character | ||
2752 | 403 | // points then try next hash | ||
2753 | 404 | hash++; | ||
2754 | 405 | } | ||
2755 | 406 | } | ||
2756 | 407 | |||
2757 | 408 | |||
2758 | 409 | // add the new sequence to the table and | ||
2759 | 410 | // return that index | ||
2760 | 411 | ushort* buffer = new ushort[length+1]; | ||
2761 | 412 | buffer[0] = length; | ||
2762 | 413 | for ( int i = 0 ; i < length ; i++ ) | ||
2763 | 414 | buffer[i+1] = unicodePoints[i]; | ||
2764 | 415 | |||
2765 | 416 | extendedCharTable.insert(hash,buffer); | ||
2766 | 417 | |||
2767 | 418 | return hash; | ||
2768 | 419 | } | ||
2769 | 420 | |||
2770 | 421 | ushort* ExtendedCharTable::lookupExtendedChar(ushort hash , ushort& length) const | ||
2771 | 422 | { | ||
2772 | 423 | // lookup index in table and if found, set the length | ||
2773 | 424 | // argument and return a pointer to the character sequence | ||
2774 | 425 | |||
2775 | 426 | ushort* buffer = extendedCharTable[hash]; | ||
2776 | 427 | if ( buffer ) | ||
2777 | 428 | { | ||
2778 | 429 | length = buffer[0]; | ||
2779 | 430 | return buffer+1; | ||
2780 | 431 | } | ||
2781 | 432 | else | ||
2782 | 433 | { | ||
2783 | 434 | length = 0; | ||
2784 | 435 | return 0; | ||
2785 | 436 | } | ||
2786 | 437 | } | ||
2787 | 438 | |||
2788 | 439 | ExtendedCharTable::ExtendedCharTable() | ||
2789 | 440 | { | ||
2790 | 441 | } | ||
2791 | 442 | ExtendedCharTable::~ExtendedCharTable() | ||
2792 | 443 | { | ||
2793 | 444 | // free all allocated character buffers | ||
2794 | 445 | QHashIterator<ushort,ushort*> iter(extendedCharTable); | ||
2795 | 446 | while ( iter.hasNext() ) | ||
2796 | 447 | { | ||
2797 | 448 | iter.next(); | ||
2798 | 449 | delete[] iter.value(); | ||
2799 | 450 | } | ||
2800 | 451 | } | ||
2801 | 452 | |||
2802 | 453 | // global instance | ||
2803 | 454 | ExtendedCharTable ExtendedCharTable::instance; | ||
2804 | 455 | |||
2805 | 456 | |||
2806 | 457 | //#include "Emulation.moc" | ||
2807 | 458 | |||
2808 | 459 | 0 | ||
2809 | === removed file 'src/plugin/konsole/Emulation.h' | |||
2810 | --- src/plugin/konsole/Emulation.h 2014-11-12 00:10:12 +0000 | |||
2811 | +++ src/plugin/konsole/Emulation.h 1970-01-01 00:00:00 +0000 | |||
2812 | @@ -1,467 +0,0 @@ | |||
2813 | 1 | /* | ||
2814 | 2 | This file is part of Konsole, an X terminal. | ||
2815 | 3 | |||
2816 | 4 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
2817 | 5 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> | ||
2818 | 6 | |||
2819 | 7 | This program is free software; you can redistribute it and/or modify | ||
2820 | 8 | it under the terms of the GNU General Public License as published by | ||
2821 | 9 | the Free Software Foundation; either version 2 of the License, or | ||
2822 | 10 | (at your option) any later version. | ||
2823 | 11 | |||
2824 | 12 | This program is distributed in the hope that it will be useful, | ||
2825 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2826 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2827 | 15 | GNU General Public License for more details. | ||
2828 | 16 | |||
2829 | 17 | You should have received a copy of the GNU General Public License | ||
2830 | 18 | along with this program; if not, write to the Free Software | ||
2831 | 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
2832 | 20 | 02110-1301 USA. | ||
2833 | 21 | */ | ||
2834 | 22 | |||
2835 | 23 | #ifndef EMULATION_H | ||
2836 | 24 | #define EMULATION_H | ||
2837 | 25 | |||
2838 | 26 | // System | ||
2839 | 27 | #include <stdio.h> | ||
2840 | 28 | |||
2841 | 29 | // Qt | ||
2842 | 30 | #include <QtGui/QKeyEvent> | ||
2843 | 31 | //#include <QPointer> | ||
2844 | 32 | #include <QtCore/QTextCodec> | ||
2845 | 33 | #include <QtCore/QTextStream> | ||
2846 | 34 | #include <QtCore/QTimer> | ||
2847 | 35 | |||
2848 | 36 | // Konsole | ||
2849 | 37 | //#include "konsole_export.h" | ||
2850 | 38 | #define KONSOLEPRIVATE_EXPORT | ||
2851 | 39 | |||
2852 | 40 | class KeyboardTranslator; | ||
2853 | 41 | class HistoryType; | ||
2854 | 42 | class Screen; | ||
2855 | 43 | class ScreenWindow; | ||
2856 | 44 | class TerminalCharacterDecoder; | ||
2857 | 45 | |||
2858 | 46 | /** | ||
2859 | 47 | * This enum describes the available states which | ||
2860 | 48 | * the terminal emulation may be set to. | ||
2861 | 49 | * | ||
2862 | 50 | * These are the values used by Emulation::stateChanged() | ||
2863 | 51 | */ | ||
2864 | 52 | enum | ||
2865 | 53 | { | ||
2866 | 54 | /** The emulation is currently receiving user input. */ | ||
2867 | 55 | NOTIFYNORMAL=0, | ||
2868 | 56 | /** | ||
2869 | 57 | * The terminal program has triggered a bell event | ||
2870 | 58 | * to get the user's attention. | ||
2871 | 59 | */ | ||
2872 | 60 | NOTIFYBELL=1, | ||
2873 | 61 | /** | ||
2874 | 62 | * The emulation is currently receiving data from its | ||
2875 | 63 | * terminal input. | ||
2876 | 64 | */ | ||
2877 | 65 | NOTIFYACTIVITY=2, | ||
2878 | 66 | |||
2879 | 67 | // unused here? | ||
2880 | 68 | NOTIFYSILENCE=3 | ||
2881 | 69 | }; | ||
2882 | 70 | |||
2883 | 71 | /** | ||
2884 | 72 | * Base class for terminal emulation back-ends. | ||
2885 | 73 | * | ||
2886 | 74 | * The back-end is responsible for decoding an incoming character stream and | ||
2887 | 75 | * producing an output image of characters. | ||
2888 | 76 | * | ||
2889 | 77 | * When input from the terminal is received, the receiveData() slot should be called with | ||
2890 | 78 | * the data which has arrived. The emulation will process the data and update the | ||
2891 | 79 | * screen image accordingly. The codec used to decode the incoming character stream | ||
2892 | 80 | * into the unicode characters used internally can be specified using setCodec() | ||
2893 | 81 | * | ||
2894 | 82 | * The size of the screen image can be specified by calling setImageSize() with the | ||
2895 | 83 | * desired number of lines and columns. When new lines are added, old content | ||
2896 | 84 | * is moved into a history store, which can be set by calling setHistory(). | ||
2897 | 85 | * | ||
2898 | 86 | * The screen image can be accessed by creating a ScreenWindow onto this emulation | ||
2899 | 87 | * by calling createWindow(). Screen windows provide access to a section of the | ||
2900 | 88 | * output. Each screen window covers the same number of lines and columns as the | ||
2901 | 89 | * image size returned by imageSize(). The screen window can be moved up and down | ||
2902 | 90 | * and provides transparent access to both the current on-screen image and the | ||
2903 | 91 | * previous output. The screen windows emit an outputChanged signal | ||
2904 | 92 | * when the section of the image they are looking at changes. | ||
2905 | 93 | * Graphical views can then render the contents of a screen window, listening for notifications | ||
2906 | 94 | * of output changes from the screen window which they are associated with and updating | ||
2907 | 95 | * accordingly. | ||
2908 | 96 | * | ||
2909 | 97 | * The emulation also is also responsible for converting input from the connected views such | ||
2910 | 98 | * as keypresses and mouse activity into a character string which can be sent | ||
2911 | 99 | * to the terminal program. Key presses can be processed by calling the sendKeyEvent() slot, | ||
2912 | 100 | * while mouse events can be processed using the sendMouseEvent() slot. When the character | ||
2913 | 101 | * stream has been produced, the emulation will emit a sendData() signal with a pointer | ||
2914 | 102 | * to the character buffer. This data should be fed to the standard input of the terminal | ||
2915 | 103 | * process. The translation of key presses into an output character stream is performed | ||
2916 | 104 | * using a lookup in a set of key bindings which map key sequences to output | ||
2917 | 105 | * character sequences. The name of the key bindings set used can be specified using | ||
2918 | 106 | * setKeyBindings() | ||
2919 | 107 | * | ||
2920 | 108 | * The emulation maintains certain state information which changes depending on the | ||
2921 | 109 | * input received. The emulation can be reset back to its starting state by calling | ||
2922 | 110 | * reset(). | ||
2923 | 111 | * | ||
2924 | 112 | * The emulation also maintains an activity state, which specifies whether | ||
2925 | 113 | * terminal is currently active ( when data is received ), normal | ||
2926 | 114 | * ( when the terminal is idle or receiving user input ) or trying | ||
2927 | 115 | * to alert the user ( also known as a "Bell" event ). The stateSet() signal | ||
2928 | 116 | * is emitted whenever the activity state is set. This can be used to determine | ||
2929 | 117 | * how long the emulation has been active/idle for and also respond to | ||
2930 | 118 | * a 'bell' event in different ways. | ||
2931 | 119 | */ | ||
2932 | 120 | class KONSOLEPRIVATE_EXPORT Emulation : public QObject | ||
2933 | 121 | { | ||
2934 | 122 | Q_OBJECT | ||
2935 | 123 | |||
2936 | 124 | public: | ||
2937 | 125 | |||
2938 | 126 | /** Constructs a new terminal emulation */ | ||
2939 | 127 | Emulation(); | ||
2940 | 128 | ~Emulation(); | ||
2941 | 129 | |||
2942 | 130 | /** | ||
2943 | 131 | * Creates a new window onto the output from this emulation. The contents | ||
2944 | 132 | * of the window are then rendered by views which are set to use this window using the | ||
2945 | 133 | * TerminalDisplay::setScreenWindow() method. | ||
2946 | 134 | */ | ||
2947 | 135 | ScreenWindow* createWindow(); | ||
2948 | 136 | |||
2949 | 137 | /** Returns the size of the screen image which the emulation produces */ | ||
2950 | 138 | QSize imageSize() const; | ||
2951 | 139 | |||
2952 | 140 | /** | ||
2953 | 141 | * Returns the total number of lines, including those stored in the history. | ||
2954 | 142 | */ | ||
2955 | 143 | int lineCount() const; | ||
2956 | 144 | |||
2957 | 145 | /** | ||
2958 | 146 | * Sets the history store used by this emulation. When new lines | ||
2959 | 147 | * are added to the output, older lines at the top of the screen are transferred to a history | ||
2960 | 148 | * store. | ||
2961 | 149 | * | ||
2962 | 150 | * The number of lines which are kept and the storage location depend on the | ||
2963 | 151 | * type of store. | ||
2964 | 152 | */ | ||
2965 | 153 | void setHistory(const HistoryType&); | ||
2966 | 154 | /** Returns the history store used by this emulation. See setHistory() */ | ||
2967 | 155 | const HistoryType& history() const; | ||
2968 | 156 | /** Clears the history scroll. */ | ||
2969 | 157 | void clearHistory(); | ||
2970 | 158 | |||
2971 | 159 | /** | ||
2972 | 160 | * Copies the output history from @p startLine to @p endLine | ||
2973 | 161 | * into @p stream, using @p decoder to convert the terminal | ||
2974 | 162 | * characters into text. | ||
2975 | 163 | * | ||
2976 | 164 | * @param decoder A decoder which converts lines of terminal characters with | ||
2977 | 165 | * appearance attributes into output text. PlainTextDecoder is the most commonly | ||
2978 | 166 | * used decoder. | ||
2979 | 167 | * @param startLine Index of first line to copy | ||
2980 | 168 | * @param endLine Index of last line to copy | ||
2981 | 169 | */ | ||
2982 | 170 | virtual void writeToStream(TerminalCharacterDecoder* decoder,int startLine,int endLine); | ||
2983 | 171 | |||
2984 | 172 | /** Returns the codec used to decode incoming characters. See setCodec() */ | ||
2985 | 173 | const QTextCodec* codec() const { return _codec; } | ||
2986 | 174 | /** Sets the codec used to decode incoming characters. */ | ||
2987 | 175 | void setCodec(const QTextCodec*); | ||
2988 | 176 | |||
2989 | 177 | /** | ||
2990 | 178 | * Convenience method. | ||
2991 | 179 | * Returns true if the current codec used to decode incoming | ||
2992 | 180 | * characters is UTF-8 | ||
2993 | 181 | */ | ||
2994 | 182 | bool utf8() const | ||
2995 | 183 | { Q_ASSERT(_codec); return _codec->mibEnum() == 106; } | ||
2996 | 184 | |||
2997 | 185 | |||
2998 | 186 | /** TODO Document me */ | ||
2999 | 187 | virtual char eraseChar() const; | ||
3000 | 188 | |||
3001 | 189 | /** | ||
3002 | 190 | * Sets the key bindings used to key events | ||
3003 | 191 | * ( received through sendKeyEvent() ) into character | ||
3004 | 192 | * streams to send to the terminal. | ||
3005 | 193 | */ | ||
3006 | 194 | void setKeyBindings(const QString& name); | ||
3007 | 195 | /** | ||
3008 | 196 | * Returns the name of the emulation's current key bindings. | ||
3009 | 197 | * See setKeyBindings() | ||
3010 | 198 | */ | ||
3011 | 199 | QString keyBindings() const; | ||
3012 | 200 | |||
3013 | 201 | /** | ||
3014 | 202 | * Copies the current image into the history and clears the screen. | ||
3015 | 203 | */ | ||
3016 | 204 | virtual void clearEntireScreen() =0; | ||
3017 | 205 | |||
3018 | 206 | /** Resets the state of the terminal. */ | ||
3019 | 207 | virtual void reset() =0; | ||
3020 | 208 | |||
3021 | 209 | /** | ||
3022 | 210 | * Returns true if the active terminal program wants | ||
3023 | 211 | * mouse input events. | ||
3024 | 212 | * | ||
3025 | 213 | * The programUsesMouseChanged() signal is emitted when this | ||
3026 | 214 | * changes. | ||
3027 | 215 | */ | ||
3028 | 216 | bool programUsesMouse() const; | ||
3029 | 217 | |||
3030 | 218 | public slots: | ||
3031 | 219 | |||
3032 | 220 | /** Change the size of the emulation's image */ | ||
3033 | 221 | virtual void setImageSize(int lines, int columns); | ||
3034 | 222 | |||
3035 | 223 | /** | ||
3036 | 224 | * Interprets a sequence of characters and sends the result to the terminal. | ||
3037 | 225 | * This is equivalent to calling sendKeyEvent() for each character in @p text in succession. | ||
3038 | 226 | */ | ||
3039 | 227 | virtual void sendText(const QString& text) = 0; | ||
3040 | 228 | |||
3041 | 229 | /** | ||
3042 | 230 | * Interprets a key press event and emits the sendData() signal with | ||
3043 | 231 | * the resulting character stream. | ||
3044 | 232 | */ | ||
3045 | 233 | virtual void sendKeyEvent(QKeyEvent*); | ||
3046 | 234 | |||
3047 | 235 | /** | ||
3048 | 236 | * Converts information about a mouse event into an xterm-compatible escape | ||
3049 | 237 | * sequence and emits the character sequence via sendData() | ||
3050 | 238 | */ | ||
3051 | 239 | virtual void sendMouseEvent(int buttons, int column, int line, int eventType); | ||
3052 | 240 | |||
3053 | 241 | /** | ||
3054 | 242 | * Sends a string of characters to the foreground terminal process. | ||
3055 | 243 | * | ||
3056 | 244 | * @param string The characters to send. | ||
3057 | 245 | * @param length Length of @p string or if set to a negative value, @p string will | ||
3058 | 246 | * be treated as a null-terminated string and its length will be determined automatically. | ||
3059 | 247 | */ | ||
3060 | 248 | virtual void sendString(const char* string, int length = -1) = 0; | ||
3061 | 249 | |||
3062 | 250 | /** | ||
3063 | 251 | * Processes an incoming stream of characters. receiveData() decodes the incoming | ||
3064 | 252 | * character buffer using the current codec(), and then calls receiveChar() for | ||
3065 | 253 | * each unicode character in the resulting buffer. | ||
3066 | 254 | * | ||
3067 | 255 | * receiveData() also starts a timer which causes the outputChanged() signal | ||
3068 | 256 | * to be emitted when it expires. The timer allows multiple updates in quick | ||
3069 | 257 | * succession to be buffered into a single outputChanged() signal emission. | ||
3070 | 258 | * | ||
3071 | 259 | * @param buffer A string of characters received from the terminal program. | ||
3072 | 260 | * @param len The length of @p buffer | ||
3073 | 261 | */ | ||
3074 | 262 | void receiveData(const char* buffer,int len); | ||
3075 | 263 | |||
3076 | 264 | signals: | ||
3077 | 265 | |||
3078 | 266 | /** | ||
3079 | 267 | * Emitted when a buffer of data is ready to send to the | ||
3080 | 268 | * standard input of the terminal. | ||
3081 | 269 | * | ||
3082 | 270 | * @param data The buffer of data ready to be sent | ||
3083 | 271 | * @param len The length of @p data in bytes | ||
3084 | 272 | */ | ||
3085 | 273 | void sendData(const char* data,int len); | ||
3086 | 274 | |||
3087 | 275 | /** | ||
3088 | 276 | * Requests that sending of input to the emulation | ||
3089 | 277 | * from the terminal process be suspended or resumed. | ||
3090 | 278 | * | ||
3091 | 279 | * @param suspend If true, requests that sending of | ||
3092 | 280 | * input from the terminal process' stdout be | ||
3093 | 281 | * suspended. Otherwise requests that sending of | ||
3094 | 282 | * input be resumed. | ||
3095 | 283 | */ | ||
3096 | 284 | void lockPtyRequest(bool suspend); | ||
3097 | 285 | |||
3098 | 286 | /** | ||
3099 | 287 | * Requests that the pty used by the terminal process | ||
3100 | 288 | * be set to UTF 8 mode. | ||
3101 | 289 | * | ||
3102 | 290 | * TODO: More documentation | ||
3103 | 291 | */ | ||
3104 | 292 | void useUtf8Request(bool); | ||
3105 | 293 | |||
3106 | 294 | /** | ||
3107 | 295 | * Emitted when the activity state of the emulation is set. | ||
3108 | 296 | * | ||
3109 | 297 | * @param state The new activity state, one of NOTIFYNORMAL, NOTIFYACTIVITY | ||
3110 | 298 | * or NOTIFYBELL | ||
3111 | 299 | */ | ||
3112 | 300 | void stateSet(int state); | ||
3113 | 301 | |||
3114 | 302 | /** TODO Document me */ | ||
3115 | 303 | void zmodemDetected(); | ||
3116 | 304 | |||
3117 | 305 | |||
3118 | 306 | /** | ||
3119 | 307 | * Requests that the color of the text used | ||
3120 | 308 | * to represent the tabs associated with this | ||
3121 | 309 | * emulation be changed. This is a Konsole-specific | ||
3122 | 310 | * extension from pre-KDE 4 times. | ||
3123 | 311 | * | ||
3124 | 312 | * TODO: Document how the parameter works. | ||
3125 | 313 | */ | ||
3126 | 314 | void changeTabTextColorRequest(int color); | ||
3127 | 315 | |||
3128 | 316 | /** | ||
3129 | 317 | * This is emitted when the program running in the shell indicates whether or | ||
3130 | 318 | * not it is interested in mouse events. | ||
3131 | 319 | * | ||
3132 | 320 | * @param usesMouse This will be true if the program wants to be informed about | ||
3133 | 321 | * mouse events or false otherwise. | ||
3134 | 322 | */ | ||
3135 | 323 | void programUsesMouseChanged(bool usesMouse); | ||
3136 | 324 | |||
3137 | 325 | /** | ||
3138 | 326 | * Emitted when the contents of the screen image change. | ||
3139 | 327 | * The emulation buffers the updates from successive image changes, | ||
3140 | 328 | * and only emits outputChanged() at sensible intervals when | ||
3141 | 329 | * there is a lot of terminal activity. | ||
3142 | 330 | * | ||
3143 | 331 | * Normally there is no need for objects other than the screen windows | ||
3144 | 332 | * created with createWindow() to listen for this signal. | ||
3145 | 333 | * | ||
3146 | 334 | * ScreenWindow objects created using createWindow() will emit their | ||
3147 | 335 | * own outputChanged() signal in response to this signal. | ||
3148 | 336 | */ | ||
3149 | 337 | void outputChanged(); | ||
3150 | 338 | |||
3151 | 339 | /** | ||
3152 | 340 | * Emitted when the program running in the terminal wishes to update the | ||
3153 | 341 | * session's title. This also allows terminal programs to customize other | ||
3154 | 342 | * aspects of the terminal emulation display. | ||
3155 | 343 | * | ||
3156 | 344 | * This signal is emitted when the escape sequence "\033]ARG;VALUE\007" | ||
3157 | 345 | * is received in the input string, where ARG is a number specifying what | ||
3158 | 346 | * should change and VALUE is a string specifying the new value. | ||
3159 | 347 | * | ||
3160 | 348 | * TODO: The name of this method is not very accurate since this method | ||
3161 | 349 | * is used to perform a whole range of tasks besides just setting | ||
3162 | 350 | * the user-title of the session. | ||
3163 | 351 | * | ||
3164 | 352 | * @param title Specifies what to change. | ||
3165 | 353 | * <ul> | ||
3166 | 354 | * <li>0 - Set window icon text and session title to @p newTitle</li> | ||
3167 | 355 | * <li>1 - Set window icon text to @p newTitle</li> | ||
3168 | 356 | * <li>2 - Set session title to @p newTitle</li> | ||
3169 | 357 | * <li>11 - Set the session's default background color to @p newTitle, | ||
3170 | 358 | * where @p newTitle can be an HTML-style string ("#RRGGBB") or a named | ||
3171 | 359 | * color (eg 'red', 'blue'). | ||
3172 | 360 | * See http://doc.trolltech.com/4.2/qcolor.html#setNamedColor for more | ||
3173 | 361 | * details. | ||
3174 | 362 | * </li> | ||
3175 | 363 | * <li>31 - Supposedly treats @p newTitle as a URL and opens it (NOT IMPLEMENTED)</li> | ||
3176 | 364 | * <li>32 - Sets the icon associated with the session. @p newTitle is the name | ||
3177 | 365 | * of the icon to use, which can be the name of any icon in the current KDE icon | ||
3178 | 366 | * theme (eg: 'konsole', 'kate', 'folder_home')</li> | ||
3179 | 367 | * </ul> | ||
3180 | 368 | * @param newTitle Specifies the new title | ||
3181 | 369 | */ | ||
3182 | 370 | |||
3183 | 371 | void titleChanged(int title,const QString& newTitle); | ||
3184 | 372 | |||
3185 | 373 | /** | ||
3186 | 374 | * Emitted when the program running in the terminal changes the | ||
3187 | 375 | * screen size. | ||
3188 | 376 | */ | ||
3189 | 377 | void imageSizeChanged(int lineCount , int columnCount); | ||
3190 | 378 | |||
3191 | 379 | /** | ||
3192 | 380 | * Emitted when the terminal program requests to change various properties | ||
3193 | 381 | * of the terminal display. | ||
3194 | 382 | * | ||
3195 | 383 | * A profile change command occurs when a special escape sequence, followed | ||
3196 | 384 | * by a string containing a series of name and value pairs is received. | ||
3197 | 385 | * This string can be parsed using a ProfileCommandParser instance. | ||
3198 | 386 | * | ||
3199 | 387 | * @param text A string expected to contain a series of key and value pairs in | ||
3200 | 388 | * the form: name=value;name2=value2 ... | ||
3201 | 389 | */ | ||
3202 | 390 | void profileChangeCommandReceived(const QString& text); | ||
3203 | 391 | |||
3204 | 392 | /** | ||
3205 | 393 | * Emitted when a flow control key combination ( Ctrl+S or Ctrl+Q ) is pressed. | ||
3206 | 394 | * @param suspendKeyPressed True if Ctrl+S was pressed to suspend output or Ctrl+Q to | ||
3207 | 395 | * resume output. | ||
3208 | 396 | */ | ||
3209 | 397 | void flowControlKeyPressed(bool suspendKeyPressed); | ||
3210 | 398 | |||
3211 | 399 | protected: | ||
3212 | 400 | virtual void setMode(int mode) = 0; | ||
3213 | 401 | virtual void resetMode(int mode) = 0; | ||
3214 | 402 | |||
3215 | 403 | /** | ||
3216 | 404 | * Processes an incoming character. See receiveData() | ||
3217 | 405 | * @p ch A unicode character code. | ||
3218 | 406 | */ | ||
3219 | 407 | virtual void receiveChar(int ch); | ||
3220 | 408 | |||
3221 | 409 | /** | ||
3222 | 410 | * Sets the active screen. The terminal has two screens, primary and alternate. | ||
3223 | 411 | * The primary screen is used by default. When certain interactive programs such | ||
3224 | 412 | * as Vim are run, they trigger a switch to the alternate screen. | ||
3225 | 413 | * | ||
3226 | 414 | * @param index 0 to switch to the primary screen, or 1 to switch to the alternate screen | ||
3227 | 415 | */ | ||
3228 | 416 | void setScreen(int index); | ||
3229 | 417 | |||
3230 | 418 | enum EmulationCodec | ||
3231 | 419 | { | ||
3232 | 420 | LocaleCodec = 0, | ||
3233 | 421 | Utf8Codec = 1 | ||
3234 | 422 | }; | ||
3235 | 423 | void setCodec(EmulationCodec codec); // codec number, 0 = locale, 1=utf8 | ||
3236 | 424 | |||
3237 | 425 | |||
3238 | 426 | QList<ScreenWindow*> _windows; | ||
3239 | 427 | |||
3240 | 428 | Screen* _currentScreen; // pointer to the screen which is currently active, | ||
3241 | 429 | // this is one of the elements in the screen[] array | ||
3242 | 430 | |||
3243 | 431 | Screen* _screen[2]; // 0 = primary screen ( used by most programs, including the shell | ||
3244 | 432 | // scrollbars are enabled in this mode ) | ||
3245 | 433 | // 1 = alternate ( used by vi , emacs etc. | ||
3246 | 434 | // scrollbars are not enabled in this mode ) | ||
3247 | 435 | |||
3248 | 436 | |||
3249 | 437 | //decodes an incoming C-style character stream into a unicode QString using | ||
3250 | 438 | //the current text codec. (this allows for rendering of non-ASCII characters in text files etc.) | ||
3251 | 439 | const QTextCodec* _codec; | ||
3252 | 440 | QTextDecoder* _decoder; | ||
3253 | 441 | const KeyboardTranslator* _keyTranslator; // the keyboard layout | ||
3254 | 442 | |||
3255 | 443 | protected slots: | ||
3256 | 444 | /** | ||
3257 | 445 | * Schedules an update of attached views. | ||
3258 | 446 | * Repeated calls to bufferedUpdate() in close succession will result in only a single update, | ||
3259 | 447 | * much like the Qt buffered update of widgets. | ||
3260 | 448 | */ | ||
3261 | 449 | void bufferedUpdate(); | ||
3262 | 450 | |||
3263 | 451 | private slots: | ||
3264 | 452 | |||
3265 | 453 | // triggered by timer, causes the emulation to send an updated screen image to each | ||
3266 | 454 | // view | ||
3267 | 455 | void showBulk(); | ||
3268 | 456 | |||
3269 | 457 | void usesMouseChanged(bool usesMouse); | ||
3270 | 458 | |||
3271 | 459 | private: | ||
3272 | 460 | bool _usesMouse; | ||
3273 | 461 | QTimer _bulkTimer1; | ||
3274 | 462 | QTimer _bulkTimer2; | ||
3275 | 463 | |||
3276 | 464 | }; | ||
3277 | 465 | |||
3278 | 466 | |||
3279 | 467 | #endif // ifndef EMULATION_H | ||
3280 | 468 | 0 | ||
3281 | === removed file 'src/plugin/konsole/ExtendedDefaultTranslator.h' | |||
3282 | --- src/plugin/konsole/ExtendedDefaultTranslator.h 2014-11-12 00:10:12 +0000 | |||
3283 | +++ src/plugin/konsole/ExtendedDefaultTranslator.h 1970-01-01 00:00:00 +0000 | |||
3284 | @@ -1,74 +0,0 @@ | |||
3285 | 1 | "keyboard \"Default (XFree 4)\"" | ||
3286 | 2 | "key Escape : \"\\E\"" | ||
3287 | 3 | "key Tab -Shift : \"\\t\"\n" | ||
3288 | 4 | "key Tab +Shift+Ansi : \"\\E[Z\"\n" | ||
3289 | 5 | "key Tab +Shift-Ansi : \"\\t\"\n" | ||
3290 | 6 | "key Backtab +Ansi : \"\\E[Z\"\n" | ||
3291 | 7 | "key Backtab -Ansi : \"\\t\"\n" | ||
3292 | 8 | "key Return-Shift-NewLine : \"\\r\"\n" | ||
3293 | 9 | "key Return-Shift+NewLine : \"\\r\\n\"\n" | ||
3294 | 10 | "key Return+Shift : \"\\EOM\"\n" | ||
3295 | 11 | "key Backspace : \"\\x7f\"\n" | ||
3296 | 12 | "key Up -Shift-Ansi : \"\\EA\"\n" | ||
3297 | 13 | "key Down -Shift-Ansi : \"\\EB\"\n" | ||
3298 | 14 | "key Right-Shift-Ansi : \"\\EC\"\n" | ||
3299 | 15 | "key Left -Shift-Ansi : \"\\ED\"\n" | ||
3300 | 16 | "key Up -Shift-AnyMod+Ansi+AppCuKeys : \"\\EOA\"\n" | ||
3301 | 17 | "key Down -Shift-AnyMod+Ansi+AppCuKeys : \"\\EOB\"\n" | ||
3302 | 18 | "key Right -Shift-AnyMod+Ansi+AppCuKeys : \"\\EOC\"\n" | ||
3303 | 19 | "key Left -Shift-AnyMod+Ansi+AppCuKeys : \"\\EOD\"\n" | ||
3304 | 20 | "key Up -Shift-AnyMod+Ansi-AppCuKeys : \"\\E[A\"\n" | ||
3305 | 21 | "key Down -Shift-AnyMod+Ansi-AppCuKeys : \"\\E[B\"\n" | ||
3306 | 22 | "key Right -Shift-AnyMod+Ansi-AppCuKeys : \"\\E[C\"\n" | ||
3307 | 23 | "key Left -Shift-AnyMod+Ansi-AppCuKeys : \"\\E[D\"\n" | ||
3308 | 24 | "key Up -Shift+AnyMod+Ansi : \"\\E[1;*A\"\n" | ||
3309 | 25 | "key Down -Shift+AnyMod+Ansi : \"\\E[1;*B\"\n" | ||
3310 | 26 | "key Right -Shift+AnyMod+Ansi : \"\\E[1;*C\"\n" | ||
3311 | 27 | "key Left -Shift+AnyMod+Ansi : \"\\E[1;*D\"\n" | ||
3312 | 28 | "key Enter+NewLine : \"\\r\\n\"\n" | ||
3313 | 29 | "key Enter-NewLine : \"\\r\"\n" | ||
3314 | 30 | "key Home -AnyMod -AppCuKeys : \"\\E[H\" \n" | ||
3315 | 31 | "key End -AnyMod -AppCuKeys : \"\\E[F\" \n" | ||
3316 | 32 | "key Home -AnyMod +AppCuKeys : \"\\EOH\" \n" | ||
3317 | 33 | "key End -AnyMod +AppCuKeys : \"\\EOF\" \n" | ||
3318 | 34 | "key Home +AnyMod : \"\\E[1;*H\"\n" | ||
3319 | 35 | "key End +AnyMod : \"\\E[1;*F\"\n" | ||
3320 | 36 | "key Insert -AnyMod : \"\\E[2~\"\n" | ||
3321 | 37 | "key Delete -AnyMod : \"\\E[3~\"\n" | ||
3322 | 38 | "key Insert +AnyMod : \"\\E[2;*~\"\n" | ||
3323 | 39 | "key Delete +AnyMod : \"\\E[3;*~\"\n" | ||
3324 | 40 | "key Prior -Shift-AnyMod : \"\\E[5~\"\n" | ||
3325 | 41 | "key Next -Shift-AnyMod : \"\\E[6~\"\n" | ||
3326 | 42 | "key Prior -Shift+AnyMod : \"\\E[5;*~\"\n" | ||
3327 | 43 | "key Next -Shift+AnyMod : \"\\E[6;*~\"\n" | ||
3328 | 44 | "key F1 -AnyMod : \"\\EOP\"\n" | ||
3329 | 45 | "key F2 -AnyMod : \"\\EOQ\"\n" | ||
3330 | 46 | "key F3 -AnyMod : \"\\EOR\"\n" | ||
3331 | 47 | "key F4 -AnyMod : \"\\EOS\"\n" | ||
3332 | 48 | "key F5 -AnyMod : \"\\E[15~\"\n" | ||
3333 | 49 | "key F6 -AnyMod : \"\\E[17~\"\n" | ||
3334 | 50 | "key F7 -AnyMod : \"\\E[18~\"\n" | ||
3335 | 51 | "key F8 -AnyMod : \"\\E[19~\"\n" | ||
3336 | 52 | "key F9 -AnyMod : \"\\E[20~\"\n" | ||
3337 | 53 | "key F10 -AnyMod : \"\\E[21~\"\n" | ||
3338 | 54 | "key F11 -AnyMod : \"\\E[23~\"\n" | ||
3339 | 55 | "key F12 -AnyMod : \"\\E[24~\"\n" | ||
3340 | 56 | "key F1 +AnyMod : \"\\EO*P\"\n" | ||
3341 | 57 | "key F2 +AnyMod : \"\\EO*Q\"\n" | ||
3342 | 58 | "key F3 +AnyMod : \"\\EO*R\"\n" | ||
3343 | 59 | "key F4 +AnyMod : \"\\EO*S\"\n" | ||
3344 | 60 | "key F5 +AnyMod : \"\\E[15;*~\"\n" | ||
3345 | 61 | "key F6 +AnyMod : \"\\E[17;*~\"\n" | ||
3346 | 62 | "key F7 +AnyMod : \"\\E[18;*~\"\n" | ||
3347 | 63 | "key F8 +AnyMod : \"\\E[19;*~\"\n" | ||
3348 | 64 | "key F9 +AnyMod : \"\\E[20;*~\"\n" | ||
3349 | 65 | "key F10 +AnyMod : \"\\E[21;*~\"\n" | ||
3350 | 66 | "key F11 +AnyMod : \"\\E[23;*~\"\n" | ||
3351 | 67 | "key F12 +AnyMod : \"\\E[24;*~\"\n" | ||
3352 | 68 | "key Space +Control : \"\\x00\"\n" | ||
3353 | 69 | "key Up +Shift-AppScreen : scrollLineUp\n" | ||
3354 | 70 | "key Prior +Shift-AppScreen : scrollPageUp\n" | ||
3355 | 71 | "key Down +Shift-AppScreen : scrollLineDown\n" | ||
3356 | 72 | "key Next +Shift-AppScreen : scrollPageDown\n" | ||
3357 | 73 | "key ScrollLock : scrollLock\n" | ||
3358 | 74 | "\0" | ||
3359 | 75 | 0 | ||
3360 | === removed file 'src/plugin/konsole/Filter.cpp' | |||
3361 | --- src/plugin/konsole/Filter.cpp 2014-11-12 00:10:12 +0000 | |||
3362 | +++ src/plugin/konsole/Filter.cpp 1970-01-01 00:00:00 +0000 | |||
3363 | @@ -1,542 +0,0 @@ | |||
3364 | 1 | /* | ||
3365 | 2 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
3366 | 3 | |||
3367 | 4 | This program is free software; you can redistribute it and/or modify | ||
3368 | 5 | it under the terms of the GNU General Public License as published by | ||
3369 | 6 | the Free Software Foundation; either version 2 of the License, or | ||
3370 | 7 | (at your option) any later version. | ||
3371 | 8 | |||
3372 | 9 | This program is distributed in the hope that it will be useful, | ||
3373 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3374 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3375 | 12 | GNU General Public License for more details. | ||
3376 | 13 | |||
3377 | 14 | You should have received a copy of the GNU General Public License | ||
3378 | 15 | along with this program; if not, write to the Free Software | ||
3379 | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
3380 | 17 | 02110-1301 USA. | ||
3381 | 18 | */ | ||
3382 | 19 | |||
3383 | 20 | // Own | ||
3384 | 21 | #include "Filter.h" | ||
3385 | 22 | |||
3386 | 23 | // System | ||
3387 | 24 | #include <iostream> | ||
3388 | 25 | |||
3389 | 26 | // Qt | ||
3390 | 27 | #include <QtWidgets/QAction> | ||
3391 | 28 | #include <QtWidgets/QApplication> | ||
3392 | 29 | #include <QtGui/QClipboard> | ||
3393 | 30 | #include <QtCore/QString> | ||
3394 | 31 | #include <QtCore/QTextStream> | ||
3395 | 32 | #include <QtCore/QSharedData> | ||
3396 | 33 | #include <QtCore/QFile> | ||
3397 | 34 | #include <QDesktopServices> | ||
3398 | 35 | #include <QUrl> | ||
3399 | 36 | |||
3400 | 37 | // KDE | ||
3401 | 38 | //#include <KLocale> | ||
3402 | 39 | //#include <KRun> | ||
3403 | 40 | |||
3404 | 41 | // Konsole | ||
3405 | 42 | #include "TerminalCharacterDecoder.h" | ||
3406 | 43 | #include "konsole_wcwidth.h" | ||
3407 | 44 | |||
3408 | 45 | |||
3409 | 46 | FilterChain::~FilterChain() | ||
3410 | 47 | { | ||
3411 | 48 | QMutableListIterator<Filter*> iter(*this); | ||
3412 | 49 | |||
3413 | 50 | while ( iter.hasNext() ) | ||
3414 | 51 | { | ||
3415 | 52 | Filter* filter = iter.next(); | ||
3416 | 53 | iter.remove(); | ||
3417 | 54 | delete filter; | ||
3418 | 55 | } | ||
3419 | 56 | } | ||
3420 | 57 | |||
3421 | 58 | void FilterChain::addFilter(Filter* filter) | ||
3422 | 59 | { | ||
3423 | 60 | append(filter); | ||
3424 | 61 | } | ||
3425 | 62 | void FilterChain::removeFilter(Filter* filter) | ||
3426 | 63 | { | ||
3427 | 64 | removeAll(filter); | ||
3428 | 65 | } | ||
3429 | 66 | bool FilterChain::containsFilter(Filter* filter) | ||
3430 | 67 | { | ||
3431 | 68 | return contains(filter); | ||
3432 | 69 | } | ||
3433 | 70 | void FilterChain::reset() | ||
3434 | 71 | { | ||
3435 | 72 | QListIterator<Filter*> iter(*this); | ||
3436 | 73 | while (iter.hasNext()) | ||
3437 | 74 | iter.next()->reset(); | ||
3438 | 75 | } | ||
3439 | 76 | void FilterChain::setBuffer(const QString* buffer , const QList<int>* linePositions) | ||
3440 | 77 | { | ||
3441 | 78 | QListIterator<Filter*> iter(*this); | ||
3442 | 79 | while (iter.hasNext()) | ||
3443 | 80 | iter.next()->setBuffer(buffer,linePositions); | ||
3444 | 81 | } | ||
3445 | 82 | void FilterChain::process() | ||
3446 | 83 | { | ||
3447 | 84 | QListIterator<Filter*> iter(*this); | ||
3448 | 85 | while (iter.hasNext()) | ||
3449 | 86 | iter.next()->process(); | ||
3450 | 87 | } | ||
3451 | 88 | void FilterChain::clear() | ||
3452 | 89 | { | ||
3453 | 90 | QList<Filter*>::clear(); | ||
3454 | 91 | } | ||
3455 | 92 | Filter::HotSpot* FilterChain::hotSpotAt(int line , int column) const | ||
3456 | 93 | { | ||
3457 | 94 | QListIterator<Filter*> iter(*this); | ||
3458 | 95 | while (iter.hasNext()) | ||
3459 | 96 | { | ||
3460 | 97 | Filter* filter = iter.next(); | ||
3461 | 98 | Filter::HotSpot* spot = filter->hotSpotAt(line,column); | ||
3462 | 99 | if ( spot != 0 ) | ||
3463 | 100 | { | ||
3464 | 101 | return spot; | ||
3465 | 102 | } | ||
3466 | 103 | } | ||
3467 | 104 | |||
3468 | 105 | return 0; | ||
3469 | 106 | } | ||
3470 | 107 | |||
3471 | 108 | QList<Filter::HotSpot*> FilterChain::hotSpots() const | ||
3472 | 109 | { | ||
3473 | 110 | QList<Filter::HotSpot*> list; | ||
3474 | 111 | QListIterator<Filter*> iter(*this); | ||
3475 | 112 | while (iter.hasNext()) | ||
3476 | 113 | { | ||
3477 | 114 | Filter* filter = iter.next(); | ||
3478 | 115 | list << filter->hotSpots(); | ||
3479 | 116 | } | ||
3480 | 117 | return list; | ||
3481 | 118 | } | ||
3482 | 119 | //QList<Filter::HotSpot*> FilterChain::hotSpotsAtLine(int line) const; | ||
3483 | 120 | |||
3484 | 121 | TerminalImageFilterChain::TerminalImageFilterChain() | ||
3485 | 122 | : _buffer(0) | ||
3486 | 123 | , _linePositions(0) | ||
3487 | 124 | { | ||
3488 | 125 | } | ||
3489 | 126 | |||
3490 | 127 | TerminalImageFilterChain::~TerminalImageFilterChain() | ||
3491 | 128 | { | ||
3492 | 129 | delete _buffer; | ||
3493 | 130 | delete _linePositions; | ||
3494 | 131 | } | ||
3495 | 132 | |||
3496 | 133 | void TerminalImageFilterChain::setImage(const Character* const image , int lines , int columns, const QVector<LineProperty>& lineProperties) | ||
3497 | 134 | { | ||
3498 | 135 | if (empty()) | ||
3499 | 136 | return; | ||
3500 | 137 | |||
3501 | 138 | // reset all filters and hotspots | ||
3502 | 139 | reset(); | ||
3503 | 140 | |||
3504 | 141 | PlainTextDecoder decoder; | ||
3505 | 142 | decoder.setTrailingWhitespace(false); | ||
3506 | 143 | |||
3507 | 144 | // setup new shared buffers for the filters to process on | ||
3508 | 145 | QString* newBuffer = new QString(); | ||
3509 | 146 | QList<int>* newLinePositions = new QList<int>(); | ||
3510 | 147 | setBuffer( newBuffer , newLinePositions ); | ||
3511 | 148 | |||
3512 | 149 | // free the old buffers | ||
3513 | 150 | delete _buffer; | ||
3514 | 151 | delete _linePositions; | ||
3515 | 152 | |||
3516 | 153 | _buffer = newBuffer; | ||
3517 | 154 | _linePositions = newLinePositions; | ||
3518 | 155 | |||
3519 | 156 | QTextStream lineStream(_buffer); | ||
3520 | 157 | decoder.begin(&lineStream); | ||
3521 | 158 | |||
3522 | 159 | for (int i=0 ; i < lines ; i++) | ||
3523 | 160 | { | ||
3524 | 161 | _linePositions->append(_buffer->length()); | ||
3525 | 162 | decoder.decodeLine(image + i*columns,columns,LINE_DEFAULT); | ||
3526 | 163 | |||
3527 | 164 | // pretend that each line ends with a newline character. | ||
3528 | 165 | // this prevents a link that occurs at the end of one line | ||
3529 | 166 | // being treated as part of a link that occurs at the start of the next line | ||
3530 | 167 | // | ||
3531 | 168 | // the downside is that links which are spread over more than one line are not | ||
3532 | 169 | // highlighted. | ||
3533 | 170 | // | ||
3534 | 171 | // TODO - Use the "line wrapped" attribute associated with lines in a | ||
3535 | 172 | // terminal image to avoid adding this imaginary character for wrapped | ||
3536 | 173 | // lines | ||
3537 | 174 | if ( !(lineProperties.value(i,LINE_DEFAULT) & LINE_WRAPPED) ) | ||
3538 | 175 | lineStream << QChar('\n'); | ||
3539 | 176 | } | ||
3540 | 177 | decoder.end(); | ||
3541 | 178 | } | ||
3542 | 179 | |||
3543 | 180 | Filter::Filter() : | ||
3544 | 181 | _linePositions(0), | ||
3545 | 182 | _buffer(0) | ||
3546 | 183 | { | ||
3547 | 184 | } | ||
3548 | 185 | |||
3549 | 186 | Filter::~Filter() | ||
3550 | 187 | { | ||
3551 | 188 | QListIterator<HotSpot*> iter(_hotspotList); | ||
3552 | 189 | while (iter.hasNext()) | ||
3553 | 190 | { | ||
3554 | 191 | delete iter.next(); | ||
3555 | 192 | } | ||
3556 | 193 | } | ||
3557 | 194 | void Filter::reset() | ||
3558 | 195 | { | ||
3559 | 196 | _hotspots.clear(); | ||
3560 | 197 | _hotspotList.clear(); | ||
3561 | 198 | } | ||
3562 | 199 | |||
3563 | 200 | void Filter::setBuffer(const QString* buffer , const QList<int>* linePositions) | ||
3564 | 201 | { | ||
3565 | 202 | _buffer = buffer; | ||
3566 | 203 | _linePositions = linePositions; | ||
3567 | 204 | } | ||
3568 | 205 | |||
3569 | 206 | void Filter::getLineColumn(int position , int& startLine , int& startColumn) | ||
3570 | 207 | { | ||
3571 | 208 | Q_ASSERT( _linePositions ); | ||
3572 | 209 | Q_ASSERT( _buffer ); | ||
3573 | 210 | |||
3574 | 211 | |||
3575 | 212 | for (int i = 0 ; i < _linePositions->count() ; i++) | ||
3576 | 213 | { | ||
3577 | 214 | int nextLine = 0; | ||
3578 | 215 | |||
3579 | 216 | if ( i == _linePositions->count()-1 ) | ||
3580 | 217 | nextLine = _buffer->length() + 1; | ||
3581 | 218 | else | ||
3582 | 219 | nextLine = _linePositions->value(i+1); | ||
3583 | 220 | |||
3584 | 221 | if ( _linePositions->value(i) <= position && position < nextLine ) | ||
3585 | 222 | { | ||
3586 | 223 | startLine = i; | ||
3587 | 224 | startColumn = string_width(buffer()->mid(_linePositions->value(i),position - _linePositions->value(i))); | ||
3588 | 225 | return; | ||
3589 | 226 | } | ||
3590 | 227 | } | ||
3591 | 228 | } | ||
3592 | 229 | |||
3593 | 230 | |||
3594 | 231 | /*void Filter::addLine(const QString& text) | ||
3595 | 232 | { | ||
3596 | 233 | _linePositions << _buffer.length(); | ||
3597 | 234 | _buffer.append(text); | ||
3598 | 235 | }*/ | ||
3599 | 236 | |||
3600 | 237 | const QString* Filter::buffer() | ||
3601 | 238 | { | ||
3602 | 239 | return _buffer; | ||
3603 | 240 | } | ||
3604 | 241 | Filter::HotSpot::~HotSpot() | ||
3605 | 242 | { | ||
3606 | 243 | } | ||
3607 | 244 | void Filter::addHotSpot(HotSpot* spot) | ||
3608 | 245 | { | ||
3609 | 246 | _hotspotList << spot; | ||
3610 | 247 | |||
3611 | 248 | for (int line = spot->startLine() ; line <= spot->endLine() ; line++) | ||
3612 | 249 | { | ||
3613 | 250 | _hotspots.insert(line,spot); | ||
3614 | 251 | } | ||
3615 | 252 | } | ||
3616 | 253 | QList<Filter::HotSpot*> Filter::hotSpots() const | ||
3617 | 254 | { | ||
3618 | 255 | return _hotspotList; | ||
3619 | 256 | } | ||
3620 | 257 | QList<Filter::HotSpot*> Filter::hotSpotsAtLine(int line) const | ||
3621 | 258 | { | ||
3622 | 259 | return _hotspots.values(line); | ||
3623 | 260 | } | ||
3624 | 261 | |||
3625 | 262 | Filter::HotSpot* Filter::hotSpotAt(int line , int column) const | ||
3626 | 263 | { | ||
3627 | 264 | QListIterator<HotSpot*> spotIter(_hotspots.values(line)); | ||
3628 | 265 | |||
3629 | 266 | while (spotIter.hasNext()) | ||
3630 | 267 | { | ||
3631 | 268 | HotSpot* spot = spotIter.next(); | ||
3632 | 269 | |||
3633 | 270 | if ( spot->startLine() == line && spot->startColumn() > column ) | ||
3634 | 271 | continue; | ||
3635 | 272 | if ( spot->endLine() == line && spot->endColumn() < column ) | ||
3636 | 273 | continue; | ||
3637 | 274 | |||
3638 | 275 | return spot; | ||
3639 | 276 | } | ||
3640 | 277 | |||
3641 | 278 | return 0; | ||
3642 | 279 | } | ||
3643 | 280 | |||
3644 | 281 | Filter::HotSpot::HotSpot(int startLine , int startColumn , int endLine , int endColumn) | ||
3645 | 282 | : _startLine(startLine) | ||
3646 | 283 | , _startColumn(startColumn) | ||
3647 | 284 | , _endLine(endLine) | ||
3648 | 285 | , _endColumn(endColumn) | ||
3649 | 286 | , _type(NotSpecified) | ||
3650 | 287 | { | ||
3651 | 288 | } | ||
3652 | 289 | QString Filter::HotSpot::tooltip() const | ||
3653 | 290 | { | ||
3654 | 291 | return QString(); | ||
3655 | 292 | } | ||
3656 | 293 | QList<QAction*> Filter::HotSpot::actions() | ||
3657 | 294 | { | ||
3658 | 295 | return QList<QAction*>(); | ||
3659 | 296 | } | ||
3660 | 297 | int Filter::HotSpot::startLine() const | ||
3661 | 298 | { | ||
3662 | 299 | return _startLine; | ||
3663 | 300 | } | ||
3664 | 301 | int Filter::HotSpot::endLine() const | ||
3665 | 302 | { | ||
3666 | 303 | return _endLine; | ||
3667 | 304 | } | ||
3668 | 305 | int Filter::HotSpot::startColumn() const | ||
3669 | 306 | { | ||
3670 | 307 | return _startColumn; | ||
3671 | 308 | } | ||
3672 | 309 | int Filter::HotSpot::endColumn() const | ||
3673 | 310 | { | ||
3674 | 311 | return _endColumn; | ||
3675 | 312 | } | ||
3676 | 313 | Filter::HotSpot::Type Filter::HotSpot::type() const | ||
3677 | 314 | { | ||
3678 | 315 | return _type; | ||
3679 | 316 | } | ||
3680 | 317 | void Filter::HotSpot::setType(Type type) | ||
3681 | 318 | { | ||
3682 | 319 | _type = type; | ||
3683 | 320 | } | ||
3684 | 321 | |||
3685 | 322 | RegExpFilter::RegExpFilter() | ||
3686 | 323 | { | ||
3687 | 324 | } | ||
3688 | 325 | |||
3689 | 326 | RegExpFilter::HotSpot::HotSpot(int startLine,int startColumn,int endLine,int endColumn) | ||
3690 | 327 | : Filter::HotSpot(startLine,startColumn,endLine,endColumn) | ||
3691 | 328 | { | ||
3692 | 329 | setType(Marker); | ||
3693 | 330 | } | ||
3694 | 331 | |||
3695 | 332 | void RegExpFilter::HotSpot::activate(QObject*) | ||
3696 | 333 | { | ||
3697 | 334 | } | ||
3698 | 335 | |||
3699 | 336 | void RegExpFilter::HotSpot::setCapturedTexts(const QStringList& texts) | ||
3700 | 337 | { | ||
3701 | 338 | _capturedTexts = texts; | ||
3702 | 339 | } | ||
3703 | 340 | QStringList RegExpFilter::HotSpot::capturedTexts() const | ||
3704 | 341 | { | ||
3705 | 342 | return _capturedTexts; | ||
3706 | 343 | } | ||
3707 | 344 | |||
3708 | 345 | void RegExpFilter::setRegExp(const QRegExp& regExp) | ||
3709 | 346 | { | ||
3710 | 347 | _searchText = regExp; | ||
3711 | 348 | } | ||
3712 | 349 | QRegExp RegExpFilter::regExp() const | ||
3713 | 350 | { | ||
3714 | 351 | return _searchText; | ||
3715 | 352 | } | ||
3716 | 353 | /*void RegExpFilter::reset(int) | ||
3717 | 354 | { | ||
3718 | 355 | _buffer = QString(); | ||
3719 | 356 | }*/ | ||
3720 | 357 | void RegExpFilter::process() | ||
3721 | 358 | { | ||
3722 | 359 | int pos = 0; | ||
3723 | 360 | const QString* text = buffer(); | ||
3724 | 361 | |||
3725 | 362 | Q_ASSERT( text ); | ||
3726 | 363 | |||
3727 | 364 | // ignore any regular expressions which match an empty string. | ||
3728 | 365 | // otherwise the while loop below will run indefinitely | ||
3729 | 366 | static const QString emptyString(""); | ||
3730 | 367 | if ( _searchText.exactMatch(emptyString) ) | ||
3731 | 368 | return; | ||
3732 | 369 | |||
3733 | 370 | while(pos >= 0) | ||
3734 | 371 | { | ||
3735 | 372 | pos = _searchText.indexIn(*text,pos); | ||
3736 | 373 | |||
3737 | 374 | if ( pos >= 0 ) | ||
3738 | 375 | { | ||
3739 | 376 | int startLine = 0; | ||
3740 | 377 | int endLine = 0; | ||
3741 | 378 | int startColumn = 0; | ||
3742 | 379 | int endColumn = 0; | ||
3743 | 380 | |||
3744 | 381 | getLineColumn(pos,startLine,startColumn); | ||
3745 | 382 | getLineColumn(pos + _searchText.matchedLength(),endLine,endColumn); | ||
3746 | 383 | |||
3747 | 384 | RegExpFilter::HotSpot* spot = newHotSpot(startLine,startColumn, | ||
3748 | 385 | endLine,endColumn); | ||
3749 | 386 | spot->setCapturedTexts(_searchText.capturedTexts()); | ||
3750 | 387 | |||
3751 | 388 | addHotSpot( spot ); | ||
3752 | 389 | pos += _searchText.matchedLength(); | ||
3753 | 390 | |||
3754 | 391 | // if matchedLength == 0, the program will get stuck in an infinite loop | ||
3755 | 392 | if ( _searchText.matchedLength() == 0 ) | ||
3756 | 393 | pos = -1; | ||
3757 | 394 | } | ||
3758 | 395 | } | ||
3759 | 396 | } | ||
3760 | 397 | |||
3761 | 398 | RegExpFilter::HotSpot* RegExpFilter::newHotSpot(int startLine,int startColumn, | ||
3762 | 399 | int endLine,int endColumn) | ||
3763 | 400 | { | ||
3764 | 401 | return new RegExpFilter::HotSpot(startLine,startColumn, | ||
3765 | 402 | endLine,endColumn); | ||
3766 | 403 | } | ||
3767 | 404 | RegExpFilter::HotSpot* UrlFilter::newHotSpot(int startLine,int startColumn,int endLine, | ||
3768 | 405 | int endColumn) | ||
3769 | 406 | { | ||
3770 | 407 | return new UrlFilter::HotSpot(startLine,startColumn, | ||
3771 | 408 | endLine,endColumn); | ||
3772 | 409 | } | ||
3773 | 410 | UrlFilter::HotSpot::HotSpot(int startLine,int startColumn,int endLine,int endColumn) | ||
3774 | 411 | : RegExpFilter::HotSpot(startLine,startColumn,endLine,endColumn) | ||
3775 | 412 | , _urlObject(new FilterObject(this)) | ||
3776 | 413 | { | ||
3777 | 414 | setType(Link); | ||
3778 | 415 | } | ||
3779 | 416 | QString UrlFilter::HotSpot::tooltip() const | ||
3780 | 417 | { | ||
3781 | 418 | QString url = capturedTexts().first(); | ||
3782 | 419 | |||
3783 | 420 | const UrlType kind = urlType(); | ||
3784 | 421 | |||
3785 | 422 | if ( kind == StandardUrl ) | ||
3786 | 423 | return QString(); | ||
3787 | 424 | else if ( kind == Email ) | ||
3788 | 425 | return QString(); | ||
3789 | 426 | else | ||
3790 | 427 | return QString(); | ||
3791 | 428 | } | ||
3792 | 429 | UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const | ||
3793 | 430 | { | ||
3794 | 431 | QString url = capturedTexts().first(); | ||
3795 | 432 | |||
3796 | 433 | if ( FullUrlRegExp.exactMatch(url) ) | ||
3797 | 434 | return StandardUrl; | ||
3798 | 435 | else if ( EmailAddressRegExp.exactMatch(url) ) | ||
3799 | 436 | return Email; | ||
3800 | 437 | else | ||
3801 | 438 | return Unknown; | ||
3802 | 439 | } | ||
3803 | 440 | |||
3804 | 441 | void UrlFilter::HotSpot::activate(QObject* object) | ||
3805 | 442 | { | ||
3806 | 443 | QString url = capturedTexts().first(); | ||
3807 | 444 | |||
3808 | 445 | const UrlType kind = urlType(); | ||
3809 | 446 | |||
3810 | 447 | const QString& actionName = object ? object->objectName() : QString(); | ||
3811 | 448 | |||
3812 | 449 | if ( actionName == "copy-action" ) | ||
3813 | 450 | { | ||
3814 | 451 | QApplication::clipboard()->setText(url); | ||
3815 | 452 | return; | ||
3816 | 453 | } | ||
3817 | 454 | |||
3818 | 455 | if ( !object || actionName == "open-action" ) | ||
3819 | 456 | { | ||
3820 | 457 | if ( kind == StandardUrl ) | ||
3821 | 458 | { | ||
3822 | 459 | // if the URL path does not include the protocol ( eg. "www.kde.org" ) then | ||
3823 | 460 | // prepend http:// ( eg. "www.kde.org" --> "http://www.kde.org" ) | ||
3824 | 461 | if (!url.contains("://")) | ||
3825 | 462 | { | ||
3826 | 463 | url.prepend("http://"); | ||
3827 | 464 | } | ||
3828 | 465 | } | ||
3829 | 466 | else if ( kind == Email ) | ||
3830 | 467 | { | ||
3831 | 468 | url.prepend("mailto:"); | ||
3832 | 469 | } | ||
3833 | 470 | |||
3834 | 471 | QDesktopServices::openUrl(QUrl(url)); | ||
3835 | 472 | //new KRun(url,QApplication::activeWindow()); | ||
3836 | 473 | } | ||
3837 | 474 | } | ||
3838 | 475 | |||
3839 | 476 | // Note: Altering these regular expressions can have a major effect on the performance of the filters | ||
3840 | 477 | // used for finding URLs in the text, especially if they are very general and could match very long | ||
3841 | 478 | // pieces of text. | ||
3842 | 479 | // Please be careful when altering them. | ||
3843 | 480 | |||
3844 | 481 | //regexp matches: | ||
3845 | 482 | // full url: | ||
3846 | 483 | // protocolname:// or www. followed by anything other than whitespaces, <, >, ' or ", and ends before whitespaces, <, >, ', ", ], !, comma and dot | ||
3847 | 484 | const QRegExp UrlFilter::FullUrlRegExp("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]"); | ||
3848 | 485 | // email address: | ||
3849 | 486 | // [word chars, dots or dashes]@[word chars, dots or dashes].[word chars] | ||
3850 | 487 | const QRegExp UrlFilter::EmailAddressRegExp("\\b(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+\\b"); | ||
3851 | 488 | |||
3852 | 489 | // matches full url or email address | ||
3853 | 490 | const QRegExp UrlFilter::CompleteUrlRegExp('('+FullUrlRegExp.pattern()+'|'+ | ||
3854 | 491 | EmailAddressRegExp.pattern()+')'); | ||
3855 | 492 | |||
3856 | 493 | UrlFilter::UrlFilter() | ||
3857 | 494 | { | ||
3858 | 495 | setRegExp( CompleteUrlRegExp ); | ||
3859 | 496 | } | ||
3860 | 497 | UrlFilter::HotSpot::~HotSpot() | ||
3861 | 498 | { | ||
3862 | 499 | delete _urlObject; | ||
3863 | 500 | } | ||
3864 | 501 | void FilterObject::activated() | ||
3865 | 502 | { | ||
3866 | 503 | _filter->activate(sender()); | ||
3867 | 504 | } | ||
3868 | 505 | QList<QAction*> UrlFilter::HotSpot::actions() | ||
3869 | 506 | { | ||
3870 | 507 | QList<QAction*> list; | ||
3871 | 508 | |||
3872 | 509 | const UrlType kind = urlType(); | ||
3873 | 510 | |||
3874 | 511 | QAction* openAction = new QAction(_urlObject); | ||
3875 | 512 | QAction* copyAction = new QAction(_urlObject);; | ||
3876 | 513 | |||
3877 | 514 | Q_ASSERT( kind == StandardUrl || kind == Email ); | ||
3878 | 515 | |||
3879 | 516 | if ( kind == StandardUrl ) | ||
3880 | 517 | { | ||
3881 | 518 | openAction->setText(QObject::tr("Open Link")); | ||
3882 | 519 | copyAction->setText(QObject::tr("Copy Link Address")); | ||
3883 | 520 | } | ||
3884 | 521 | else if ( kind == Email ) | ||
3885 | 522 | { | ||
3886 | 523 | openAction->setText(QObject::tr("Send Email To...")); | ||
3887 | 524 | copyAction->setText(QObject::tr("Copy Email Address")); | ||
3888 | 525 | } | ||
3889 | 526 | |||
3890 | 527 | // object names are set here so that the hotspot performs the | ||
3891 | 528 | // correct action when activated() is called with the triggered | ||
3892 | 529 | // action passed as a parameter. | ||
3893 | 530 | openAction->setObjectName( QLatin1String("open-action" )); | ||
3894 | 531 | copyAction->setObjectName( QLatin1String("copy-action" )); | ||
3895 | 532 | |||
3896 | 533 | QObject::connect( openAction , SIGNAL(triggered()) , _urlObject , SLOT(activated()) ); | ||
3897 | 534 | QObject::connect( copyAction , SIGNAL(triggered()) , _urlObject , SLOT(activated()) ); | ||
3898 | 535 | |||
3899 | 536 | list << openAction; | ||
3900 | 537 | list << copyAction; | ||
3901 | 538 | |||
3902 | 539 | return list; | ||
3903 | 540 | } | ||
3904 | 541 | |||
3905 | 542 | //#include "Filter.moc" | ||
3906 | 543 | 0 | ||
3907 | === removed file 'src/plugin/konsole/Filter.h' | |||
3908 | --- src/plugin/konsole/Filter.h 2014-11-12 00:10:12 +0000 | |||
3909 | +++ src/plugin/konsole/Filter.h 1970-01-01 00:00:00 +0000 | |||
3910 | @@ -1,380 +0,0 @@ | |||
3911 | 1 | /* | ||
3912 | 2 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> | ||
3913 | 3 | |||
3914 | 4 | This program is free software; you can redistribute it and/or modify | ||
3915 | 5 | it under the terms of the GNU General Public License as published by | ||
3916 | 6 | the Free Software Foundation; either version 2 of the License, or | ||
3917 | 7 | (at your option) any later version. | ||
3918 | 8 | |||
3919 | 9 | This program is distributed in the hope that it will be useful, | ||
3920 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3921 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3922 | 12 | GNU General Public License for more details. | ||
3923 | 13 | |||
3924 | 14 | You should have received a copy of the GNU General Public License | ||
3925 | 15 | along with this program; if not, write to the Free Software | ||
3926 | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
3927 | 17 | 02110-1301 USA. | ||
3928 | 18 | */ | ||
3929 | 19 | |||
3930 | 20 | #ifndef FILTER_H | ||
3931 | 21 | #define FILTER_H | ||
3932 | 22 | |||
3933 | 23 | // Qt | ||
3934 | 24 | #include <QtWidgets/QAction> | ||
3935 | 25 | #include <QtCore/QList> | ||
3936 | 26 | #include <QtCore/QObject> | ||
3937 | 27 | #include <QtCore/QStringList> | ||
3938 | 28 | #include <QtCore/QHash> | ||
3939 | 29 | #include <QtCore/QRegExp> | ||
3940 | 30 | |||
3941 | 31 | // Local | ||
3942 | 32 | #include "Character.h" | ||
3943 | 33 | |||
3944 | 34 | |||
3945 | 35 | /** | ||
3946 | 36 | * A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list) | ||
3947 | 37 | * and marks the areas which match the filter's patterns as 'hotspots'. | ||
3948 | 38 | * | ||
3949 | 39 | * Each hotspot has a type identifier associated with it ( such as a link or a highlighted section ), | ||
3950 | 40 | * and an action. When the user performs some activity such as a mouse-click in a hotspot area ( the exact | ||
3951 | 41 | * action will depend on what is displaying the block of text which the filter is processing ), the hotspot's | ||
3952 | 42 | * activate() method should be called. Depending on the type of hotspot this will trigger a suitable response. | ||
3953 | 43 | * | ||
3954 | 44 | * For example, if a hotspot represents a URL then a suitable action would be opening that URL in a web browser. | ||
3955 | 45 | * Hotspots may have more than one action, in which case the list of actions can be obtained using the | ||
3956 | 46 | * actions() method. | ||
3957 | 47 | * | ||
3958 | 48 | * Different subclasses of filter will return different types of hotspot. | ||
3959 | 49 | * Subclasses must reimplement the process() method to examine a block of text and identify sections of interest. | ||
3960 | 50 | * When processing the text they should create instances of Filter::HotSpot subclasses for sections of interest | ||
3961 | 51 | * and add them to the filter's list of hotspots using addHotSpot() | ||
3962 | 52 | */ | ||
3963 | 53 | class Filter | ||
3964 | 54 | { | ||
3965 | 55 | public: | ||
3966 | 56 | /** | ||
3967 | 57 | * Represents an area of text which matched the pattern a particular filter has been looking for. | ||
3968 | 58 | * | ||
3969 | 59 | * Each hotspot has a type identifier associated with it ( such as a link or a highlighted section ), | ||
3970 | 60 | * and an action. When the user performs some activity such as a mouse-click in a hotspot area ( the exact | ||
3971 | 61 | * action will depend on what is displaying the block of text which the filter is processing ), the hotspot's | ||
3972 | 62 | * activate() method should be called. Depending on the type of hotspot this will trigger a suitable response. | ||
3973 | 63 | * | ||
3974 | 64 | * For example, if a hotspot represents a URL then a suitable action would be opening that URL in a web browser. | ||
3975 | 65 | * Hotspots may have more than one action, in which case the list of actions can be obtained using the | ||
3976 | 66 | * actions() method. These actions may then be displayed in a popup menu or toolbar for example. | ||
3977 | 67 | */ | ||
3978 | 68 | class HotSpot | ||
3979 | 69 | { | ||
3980 | 70 | public: | ||
3981 | 71 | /** | ||
3982 | 72 | * Constructs a new hotspot which covers the area from (@p startLine,@p startColumn) to (@p endLine,@p endColumn) | ||
3983 | 73 | * in a block of text. | ||
3984 | 74 | */ | ||
3985 | 75 | HotSpot(int startLine , int startColumn , int endLine , int endColumn); | ||
3986 | 76 | virtual ~HotSpot(); | ||
3987 | 77 | |||
3988 | 78 | enum Type | ||
3989 | 79 | { | ||
3990 | 80 | // the type of the hotspot is not specified | ||
3991 | 81 | NotSpecified, | ||
3992 | 82 | // this hotspot represents a clickable link | ||
3993 | 83 | Link, | ||
3994 | 84 | // this hotspot represents a marker | ||
3995 | 85 | Marker | ||
3996 | 86 | }; | ||
3997 | 87 | |||
3998 | 88 | /** Returns the line when the hotspot area starts */ | ||
3999 | 89 | int startLine() const; | ||
4000 | 90 | /** Returns the line where the hotspot area ends */ | ||
4001 | 91 | int endLine() const; | ||
4002 | 92 | /** Returns the column on startLine() where the hotspot area starts */ | ||
4003 | 93 | int startColumn() const; | ||
4004 | 94 | /** Returns the column on endLine() where the hotspot area ends */ | ||
4005 | 95 | int endColumn() const; | ||
4006 | 96 | /** | ||
4007 | 97 | * Returns the type of the hotspot. This is usually used as a hint for views on how to represent | ||
4008 | 98 | * the hotspot graphically. eg. Link hotspots are typically underlined when the user mouses over them | ||
4009 | 99 | */ | ||
4010 | 100 | Type type() const; | ||
4011 | 101 | /** | ||
4012 | 102 | * Causes the an action associated with a hotspot to be triggered. | ||
4013 | 103 | * | ||
4014 | 104 | * @param object The object which caused the hotspot to be triggered. This is | ||
4015 | 105 | * typically null ( in which case the default action should be performed ) or | ||
4016 | 106 | * one of the objects from the actions() list. In which case the associated | ||
4017 | 107 | * action should be performed. | ||
4018 | 108 | */ | ||
4019 | 109 | virtual void activate(QObject* object = 0) = 0; | ||
4020 | 110 | /** | ||
4021 | 111 | * Returns a list of actions associated with the hotspot which can be used in a | ||
4022 | 112 | * menu or toolbar | ||
4023 | 113 | */ | ||
4024 | 114 | virtual QList<QAction*> actions(); | ||
4025 | 115 | |||
4026 | 116 | /** | ||
4027 | 117 | * Returns the text of a tooltip to be shown when the mouse moves over the hotspot, or | ||
4028 | 118 | * an empty string if there is no tooltip associated with this hotspot. | ||
4029 | 119 | * | ||
4030 | 120 | * The default implementation returns an empty string. | ||
4031 | 121 | */ | ||
4032 | 122 | virtual QString tooltip() const; | ||
4033 | 123 | |||
4034 | 124 | protected: | ||
4035 | 125 | /** Sets the type of a hotspot. This should only be set once */ | ||
4036 | 126 | void setType(Type type); | ||
4037 | 127 | |||
4038 | 128 | private: | ||
4039 | 129 | int _startLine; | ||
4040 | 130 | int _startColumn; | ||
4041 | 131 | int _endLine; | ||
4042 | 132 | int _endColumn; | ||
4043 | 133 | Type _type; | ||
4044 | 134 | |||
4045 | 135 | }; | ||
4046 | 136 | |||
4047 | 137 | /** Constructs a new filter. */ | ||
4048 | 138 | Filter(); | ||
4049 | 139 | virtual ~Filter(); | ||
4050 | 140 | |||
4051 | 141 | /** Causes the filter to process the block of text currently in its internal buffer */ | ||
4052 | 142 | virtual void process() = 0; | ||
4053 | 143 | |||
4054 | 144 | /** | ||
4055 | 145 | * Empties the filters internal buffer and resets the line count back to 0. | ||
4056 | 146 | * All hotspots are deleted. | ||
4057 | 147 | */ | ||
4058 | 148 | void reset(); | ||
4059 | 149 | |||
4060 | 150 | /** Adds a new line of text to the filter and increments the line count */ | ||
4061 | 151 | //void addLine(const QString& string); | ||
4062 | 152 | |||
4063 | 153 | /** Returns the hotspot which covers the given @p line and @p column, or 0 if no hotspot covers that area */ | ||
4064 | 154 | HotSpot* hotSpotAt(int line , int column) const; | ||
4065 | 155 | |||
4066 | 156 | /** Returns the list of hotspots identified by the filter */ | ||
4067 | 157 | QList<HotSpot*> hotSpots() const; | ||
4068 | 158 | |||
4069 | 159 | /** Returns the list of hotspots identified by the filter which occur on a given line */ | ||
4070 | 160 | QList<HotSpot*> hotSpotsAtLine(int line) const; | ||
4071 | 161 | |||
4072 | 162 | /** | ||
4073 | 163 | * TODO: Document me | ||
4074 | 164 | */ | ||
4075 | 165 | void setBuffer(const QString* buffer , const QList<int>* linePositions); | ||
4076 | 166 | |||
4077 | 167 | protected: | ||
4078 | 168 | /** Adds a new hotspot to the list */ | ||
4079 | 169 | void addHotSpot(HotSpot*); | ||
4080 | 170 | /** Returns the internal buffer */ | ||
4081 | 171 | const QString* buffer(); | ||
4082 | 172 | /** Converts a character position within buffer() to a line and column */ | ||
4083 | 173 | void getLineColumn(int position , int& startLine , int& startColumn); | ||
4084 | 174 | |||
4085 | 175 | private: | ||
4086 | 176 | QMultiHash<int,HotSpot*> _hotspots; | ||
4087 | 177 | QList<HotSpot*> _hotspotList; | ||
4088 | 178 | |||
4089 | 179 | const QList<int>* _linePositions; | ||
4090 | 180 | const QString* _buffer; | ||
4091 | 181 | }; | ||
4092 | 182 | |||
4093 | 183 | /** | ||
4094 | 184 | * A filter which searches for sections of text matching a regular expression and creates a new RegExpFilter::HotSpot | ||
4095 | 185 | * instance for them. | ||
4096 | 186 | * | ||
4097 | 187 | * Subclasses can reimplement newHotSpot() to return custom hotspot types when matches for the regular expression | ||
4098 | 188 | * are found. | ||
4099 | 189 | */ | ||
4100 | 190 | class RegExpFilter : public Filter | ||
4101 | 191 | { | ||
4102 | 192 | public: | ||
4103 | 193 | /** | ||
4104 | 194 | * Type of hotspot created by RegExpFilter. The capturedTexts() method can be used to find the text | ||
4105 | 195 | * matched by the filter's regular expression. | ||
4106 | 196 | */ | ||
4107 | 197 | class HotSpot : public Filter::HotSpot | ||
4108 | 198 | { | ||
4109 | 199 | public: | ||
4110 | 200 | HotSpot(int startLine, int startColumn, int endLine , int endColumn); | ||
4111 | 201 | virtual void activate(QObject* object = 0); | ||
4112 | 202 | |||
4113 | 203 | /** Sets the captured texts associated with this hotspot */ | ||
4114 | 204 | void setCapturedTexts(const QStringList& texts); | ||
4115 | 205 | /** Returns the texts found by the filter when matching the filter's regular expression */ | ||
4116 | 206 | QStringList capturedTexts() const; | ||
4117 | 207 | private: | ||
4118 | 208 | QStringList _capturedTexts; | ||
4119 | 209 | }; | ||
4120 | 210 | |||
4121 | 211 | /** Constructs a new regular expression filter */ | ||
4122 | 212 | RegExpFilter(); | ||
4123 | 213 | |||
4124 | 214 | /** | ||
4125 | 215 | * Sets the regular expression which the filter searches for in blocks of text. | ||
4126 | 216 | * | ||
4127 | 217 | * Regular expressions which match the empty string are treated as not matching | ||
4128 | 218 | * anything. | ||
4129 | 219 | */ | ||
4130 | 220 | void setRegExp(const QRegExp& text); | ||
4131 | 221 | /** Returns the regular expression which the filter searches for in blocks of text */ | ||
4132 | 222 | QRegExp regExp() const; | ||
4133 | 223 | |||
4134 | 224 | /** | ||
4135 | 225 | * Reimplemented to search the filter's text buffer for text matching regExp() | ||
4136 | 226 | * | ||
4137 | 227 | * If regexp matches the empty string, then process() will return immediately | ||
4138 | 228 | * without finding results. | ||
4139 | 229 | */ | ||
4140 | 230 | virtual void process(); | ||
4141 | 231 | |||
4142 | 232 | protected: | ||
4143 | 233 | /** | ||
4144 | 234 | * Called when a match for the regular expression is encountered. Subclasses should reimplement this | ||
4145 | 235 | * to return custom hotspot types | ||
4146 | 236 | */ | ||
4147 | 237 | virtual RegExpFilter::HotSpot* newHotSpot(int startLine,int startColumn, | ||
4148 | 238 | int endLine,int endColumn); | ||
4149 | 239 | |||
4150 | 240 | private: | ||
4151 | 241 | QRegExp _searchText; | ||
4152 | 242 | }; | ||
4153 | 243 | |||
4154 | 244 | class FilterObject; | ||
4155 | 245 | |||
4156 | 246 | /** A filter which matches URLs in blocks of text */ | ||
4157 | 247 | class UrlFilter : public RegExpFilter | ||
4158 | 248 | { | ||
4159 | 249 | public: | ||
4160 | 250 | /** | ||
4161 | 251 | * Hotspot type created by UrlFilter instances. The activate() method opens a web browser | ||
4162 | 252 | * at the given URL when called. | ||
4163 | 253 | */ | ||
4164 | 254 | class HotSpot : public RegExpFilter::HotSpot | ||
4165 | 255 | { | ||
4166 | 256 | public: | ||
4167 | 257 | HotSpot(int startLine,int startColumn,int endLine,int endColumn); | ||
4168 | 258 | virtual ~HotSpot(); | ||
4169 | 259 | |||
4170 | 260 | virtual QList<QAction*> actions(); | ||
4171 | 261 | |||
4172 | 262 | /** | ||
4173 | 263 | * Open a web browser at the current URL. The url itself can be determined using | ||
4174 | 264 | * the capturedTexts() method. | ||
4175 | 265 | */ | ||
4176 | 266 | virtual void activate(QObject* object = 0); | ||
4177 | 267 | |||
4178 | 268 | virtual QString tooltip() const; | ||
4179 | 269 | private: | ||
4180 | 270 | enum UrlType | ||
4181 | 271 | { | ||
4182 | 272 | StandardUrl, | ||
4183 | 273 | Email, | ||
4184 | 274 | Unknown | ||
4185 | 275 | }; | ||
4186 | 276 | UrlType urlType() const; | ||
4187 | 277 | |||
4188 | 278 | FilterObject* _urlObject; | ||
4189 | 279 | }; | ||
4190 | 280 | |||
4191 | 281 | UrlFilter(); | ||
4192 | 282 | |||
4193 | 283 | protected: | ||
4194 | 284 | virtual RegExpFilter::HotSpot* newHotSpot(int,int,int,int); | ||
4195 | 285 | |||
4196 | 286 | private: | ||
4197 | 287 | |||
4198 | 288 | static const QRegExp FullUrlRegExp; | ||
4199 | 289 | static const QRegExp EmailAddressRegExp; | ||
4200 | 290 | |||
4201 | 291 | // combined OR of FullUrlRegExp and EmailAddressRegExp | ||
4202 | 292 | static const QRegExp CompleteUrlRegExp; | ||
4203 | 293 | }; | ||
4204 | 294 | |||
4205 | 295 | class FilterObject : public QObject | ||
4206 | 296 | { | ||
4207 | 297 | Q_OBJECT | ||
4208 | 298 | public: | ||
4209 | 299 | FilterObject(Filter::HotSpot* filter) : _filter(filter) {} | ||
4210 | 300 | private slots: | ||
4211 | 301 | void activated(); | ||
4212 | 302 | private: | ||
4213 | 303 | Filter::HotSpot* _filter; | ||
4214 | 304 | }; | ||
4215 | 305 | |||
4216 | 306 | /** | ||
4217 | 307 | * A chain which allows a group of filters to be processed as one. | ||
4218 | 308 | * The chain owns the filters added to it and deletes them when the chain itself is destroyed. | ||
4219 | 309 | * | ||
4220 | 310 | * Use addFilter() to add a new filter to the chain. | ||
4221 | 311 | * When new text to be filtered arrives, use addLine() to add each additional | ||
4222 | 312 | * line of text which needs to be processed and then after adding the last line, use | ||
4223 | 313 | * process() to cause each filter in the chain to process the text. | ||
4224 | 314 | * | ||
4225 | 315 | * After processing a block of text, the reset() method can be used to set the filter chain's | ||
4226 | 316 | * internal cursor back to the first line. | ||
4227 | 317 | * | ||
4228 | 318 | * The hotSpotAt() method will return the first hotspot which covers a given position. | ||
4229 | 319 | * | ||
4230 | 320 | * The hotSpots() and hotSpotsAtLine() method return all of the hotspots in the text and on | ||
4231 | 321 | * a given line respectively. | ||
4232 | 322 | */ | ||
4233 | 323 | class FilterChain : protected QList<Filter*> | ||
4234 | 324 | { | ||
4235 | 325 | public: | ||
4236 | 326 | virtual ~FilterChain(); | ||
4237 | 327 | |||
4238 | 328 | /** Adds a new filter to the chain. The chain will delete this filter when it is destroyed */ | ||
4239 | 329 | void addFilter(Filter* filter); | ||
4240 | 330 | /** Removes a filter from the chain. The chain will no longer delete the filter when destroyed */ | ||
4241 | 331 | void removeFilter(Filter* filter); | ||
4242 | 332 | /** Returns true if the chain contains @p filter */ | ||
4243 | 333 | bool containsFilter(Filter* filter); | ||
4244 | 334 | /** Removes all filters from the chain */ | ||
4245 | 335 | void clear(); | ||
4246 | 336 | |||
4247 | 337 | /** Resets each filter in the chain */ | ||
4248 | 338 | void reset(); | ||
4249 | 339 | /** | ||
4250 | 340 | * Processes each filter in the chain | ||
4251 | 341 | */ | ||
4252 | 342 | void process(); | ||
4253 | 343 | |||
4254 | 344 | /** Sets the buffer for each filter in the chain to process. */ | ||
4255 | 345 | void setBuffer(const QString* buffer , const QList<int>* linePositions); | ||
4256 | 346 | |||
4257 | 347 | /** Returns the first hotspot which occurs at @p line, @p column or 0 if no hotspot was found */ | ||
4258 | 348 | Filter::HotSpot* hotSpotAt(int line , int column) const; | ||
4259 | 349 | /** Returns a list of all the hotspots in all the chain's filters */ | ||
4260 | 350 | QList<Filter::HotSpot*> hotSpots() const; | ||
4261 | 351 | /** Returns a list of all hotspots at the given line in all the chain's filters */ | ||
4262 | 352 | QList<Filter::HotSpot> hotSpotsAtLine(int line) const; | ||
4263 | 353 | |||
4264 | 354 | }; | ||
4265 | 355 | |||
4266 | 356 | /** A filter chain which processes character images from terminal displays */ | ||
4267 | 357 | class TerminalImageFilterChain : public FilterChain | ||
4268 | 358 | { | ||
4269 | 359 | public: | ||
4270 | 360 | TerminalImageFilterChain(); | ||
4271 | 361 | virtual ~TerminalImageFilterChain(); | ||
4272 | 362 | |||
4273 | 363 | /** | ||
4274 | 364 | * Set the current terminal image to @p image. | ||
4275 | 365 | * | ||
4276 | 366 | * @param image The terminal image | ||
4277 | 367 | * @param lines The number of lines in the terminal image | ||
4278 | 368 | * @param columns The number of columns in the terminal image | ||
4279 | 369 | * @param lineProperties The line properties to set for image | ||
4280 | 370 | */ | ||
4281 | 371 | void setImage(const Character* const image , int lines , int columns, | ||
4282 | 372 | const QVector<LineProperty>& lineProperties); | ||
4283 | 373 | |||
4284 | 374 | private: | ||
4285 | 375 | QString* _buffer; | ||
4286 | 376 | QList<int>* _linePositions; | ||
4287 | 377 | }; | ||
4288 | 378 | |||
4289 | 379 | |||
4290 | 380 | #endif //FILTER_H | ||
4291 | 381 | 0 | ||
4292 | === removed file 'src/plugin/konsole/History.cpp' | |||
4293 | --- src/plugin/konsole/History.cpp 2014-11-12 00:10:12 +0000 | |||
4294 | +++ src/plugin/konsole/History.cpp 1970-01-01 00:00:00 +0000 | |||
4295 | @@ -1,986 +0,0 @@ | |||
4296 | 1 | /* | ||
4297 | 2 | This file is part of Konsole, an X terminal. | ||
4298 | 3 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> | ||
4299 | 4 | |||
4300 | 5 | This program is free software; you can redistribute it and/or modify | ||
4301 | 6 | it under the terms of the GNU General Public License as published by | ||
4302 | 7 | the Free Software Foundation; either version 2 of the License, or | ||
4303 | 8 | (at your option) any later version. | ||
4304 | 9 | |||
4305 | 10 | This program is distributed in the hope that it will be useful, | ||
4306 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4307 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4308 | 13 | GNU General Public License for more details. | ||
4309 | 14 | |||
4310 | 15 | You should have received a copy of the GNU General Public License | ||
4311 | 16 | along with this program; if not, write to the Free Software | ||
4312 | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
4313 | 18 | 02110-1301 USA. | ||
4314 | 19 | */ | ||
4315 | 20 | |||
4316 | 21 | // Own | ||
4317 | 22 | #include "History.h" | ||
4318 | 23 | |||
4319 | 24 | // System | ||
4320 | 25 | #include <iostream> | ||
4321 | 26 | #include <stdlib.h> | ||
4322 | 27 | #include <assert.h> | ||
4323 | 28 | #include <stdio.h> | ||
4324 | 29 | #include <sys/types.h> | ||
4325 | 30 | #include <sys/mman.h> | ||
4326 | 31 | #include <unistd.h> | ||
4327 | 32 | #include <errno.h> | ||
4328 | 33 | |||
4329 | 34 | #include <QtDebug> | ||
4330 | 35 | |||
4331 | 36 | // KDE | ||
4332 | 37 | //#include <kde_file.h> | ||
4333 | 38 | //#include <kdebug.h> | ||
4334 | 39 | |||
4335 | 40 | // Reasonable line size | ||
4336 | 41 | #define LINE_SIZE 1024 | ||
4337 | 42 | #define KDE_lseek lseek | ||
4338 | 43 | |||
4339 | 44 | |||
4340 | 45 | /* | ||
4341 | 46 | An arbitrary long scroll. | ||
4342 | 47 | |||
4343 | 48 | One can modify the scroll only by adding either cells | ||
4344 | 49 | or newlines, but access it randomly. | ||
4345 | 50 | |||
4346 | 51 | The model is that of an arbitrary wide typewriter scroll | ||
4347 | 52 | in that the scroll is a serie of lines and each line is | ||
4348 | 53 | a serie of cells with no overwriting permitted. | ||
4349 | 54 | |||
4350 | 55 | The implementation provides arbitrary length and numbers | ||
4351 | 56 | of cells and line/column indexed read access to the scroll | ||
4352 | 57 | at constant costs. | ||
4353 | 58 | |||
4354 | 59 | KDE4: Can we use QTemporaryFile here, instead of KTempFile? | ||
4355 | 60 | |||
4356 | 61 | FIXME: some complain about the history buffer comsuming the | ||
4357 | 62 | memory of their machines. This problem is critical | ||
4358 | 63 | since the history does not behave gracefully in cases | ||
4359 | 64 | where the memory is used up completely. | ||
4360 | 65 | |||
4361 | 66 | I put in a workaround that should handle it problem | ||
4362 | 67 | now gracefully. I'm not satisfied with the solution. | ||
4363 | 68 | |||
4364 | 69 | FIXME: Terminating the history is not properly indicated | ||
4365 | 70 | in the menu. We should throw a signal. | ||
4366 | 71 | |||
4367 | 72 | FIXME: There is noticeable decrease in speed, also. Perhaps, | ||
4368 | 73 | there whole feature needs to be revisited therefore. | ||
4369 | 74 | Disadvantage of a more elaborated, say block-oriented | ||
4370 | 75 | scheme with wrap around would be it's complexity. | ||
4371 | 76 | */ | ||
4372 | 77 | |||
4373 | 78 | //FIXME: tempory replacement for tmpfile | ||
4374 | 79 | // this is here one for debugging purpose. | ||
4375 | 80 | |||
4376 | 81 | //#define tmpfile xTmpFile | ||
4377 | 82 | |||
4378 | 83 | // History File /////////////////////////////////////////// | ||
4379 | 84 | |||
4380 | 85 | /* | ||
4381 | 86 | A Row(X) data type which allows adding elements to the end. | ||
4382 | 87 | */ | ||
4383 | 88 | |||
4384 | 89 | HistoryFile::HistoryFile() | ||
4385 | 90 | : ion(-1), | ||
4386 | 91 | length(0), | ||
4387 | 92 | fileMap(0) | ||
4388 | 93 | { | ||
4389 | 94 | if (tmpFile.open()) | ||
4390 | 95 | { | ||
4391 | 96 | tmpFile.setAutoRemove(true); | ||
4392 | 97 | ion = tmpFile.handle(); | ||
4393 | 98 | } | ||
4394 | 99 | } | ||
4395 | 100 | |||
4396 | 101 | HistoryFile::~HistoryFile() | ||
4397 | 102 | { | ||
4398 | 103 | if (fileMap) | ||
4399 | 104 | unmap(); | ||
4400 | 105 | } | ||
4401 | 106 | |||
4402 | 107 | //TODO: Mapping the entire file in will cause problems if the history file becomes exceedingly large, | ||
4403 | 108 | //(ie. larger than available memory). HistoryFile::map() should only map in sections of the file at a time, | ||
4404 | 109 | //to avoid this. | ||
4405 | 110 | void HistoryFile::map() | ||
4406 | 111 | { | ||
4407 | 112 | assert( fileMap == 0 ); | ||
4408 | 113 | |||
4409 | 114 | fileMap = (char*)mmap( 0 , length , PROT_READ , MAP_PRIVATE , ion , 0 ); | ||
4410 | 115 | |||
4411 | 116 | //if mmap'ing fails, fall back to the read-lseek combination | ||
4412 | 117 | if ( fileMap == MAP_FAILED ) | ||
4413 | 118 | { | ||
4414 | 119 | readWriteBalance = 0; | ||
4415 | 120 | fileMap = 0; | ||
4416 | 121 | qDebug() << __FILE__ << __LINE__ << ": mmap'ing history failed. errno = " << errno; | ||
4417 | 122 | } | ||
4418 | 123 | } | ||
4419 | 124 | |||
4420 | 125 | void HistoryFile::unmap() | ||
4421 | 126 | { | ||
4422 | 127 | int result = munmap( fileMap , length ); | ||
4423 | 128 | assert( result == 0 ); Q_UNUSED( result ); | ||
4424 | 129 | |||
4425 | 130 | fileMap = 0; | ||
4426 | 131 | } | ||
4427 | 132 | |||
4428 | 133 | bool HistoryFile::isMapped() | ||
4429 | 134 | { | ||
4430 | 135 | return (fileMap != 0); | ||
4431 | 136 | } | ||
4432 | 137 | |||
4433 | 138 | void HistoryFile::add(const unsigned char* bytes, int len) | ||
4434 | 139 | { | ||
4435 | 140 | if ( fileMap ) | ||
4436 | 141 | unmap(); | ||
4437 | 142 | |||
4438 | 143 | readWriteBalance++; | ||
4439 | 144 | |||
4440 | 145 | int rc = 0; | ||
4441 | 146 | |||
4442 | 147 | rc = KDE_lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryFile::add.seek"); return; } | ||
4443 | 148 | rc = write(ion,bytes,len); if (rc < 0) { perror("HistoryFile::add.write"); return; } | ||
4444 | 149 | length += rc; | ||
4445 | 150 | } | ||
4446 | 151 | |||
4447 | 152 | void HistoryFile::get(unsigned char* bytes, int len, int loc) | ||
4448 | 153 | { | ||
4449 | 154 | //count number of get() calls vs. number of add() calls. | ||
4450 | 155 | //If there are many more get() calls compared with add() | ||
4451 | 156 | //calls (decided by using MAP_THRESHOLD) then mmap the log | ||
4452 | 157 | //file to improve performance. | ||
4453 | 158 | readWriteBalance--; | ||
4454 | 159 | if ( !fileMap && readWriteBalance < MAP_THRESHOLD ) | ||
4455 | 160 | map(); | ||
4456 | 161 | |||
4457 | 162 | if ( fileMap ) | ||
4458 | 163 | { | ||
4459 | 164 | for (int i=0;i<len;i++) | ||
4460 | 165 | bytes[i]=fileMap[loc+i]; | ||
4461 | 166 | } | ||
4462 | 167 | else | ||
4463 | 168 | { | ||
4464 | 169 | int rc = 0; | ||
4465 | 170 | |||
4466 | 171 | if (loc < 0 || len < 0 || loc + len > length) | ||
4467 | 172 | fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc); | ||
4468 | 173 | rc = KDE_lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryFile::get.seek"); return; } | ||
4469 | 174 | rc = read(ion,bytes,len); if (rc < 0) { perror("HistoryFile::get.read"); return; } | ||
4470 | 175 | } | ||
4471 | 176 | } | ||
4472 | 177 | |||
4473 | 178 | int HistoryFile::len() | ||
4474 | 179 | { | ||
4475 | 180 | return length; | ||
4476 | 181 | } | ||
4477 | 182 | |||
4478 | 183 | |||
4479 | 184 | // History Scroll abstract base class ////////////////////////////////////// | ||
4480 | 185 | |||
4481 | 186 | |||
4482 | 187 | HistoryScroll::HistoryScroll(HistoryType* t) | ||
4483 | 188 | : m_histType(t) | ||
4484 | 189 | { | ||
4485 | 190 | } | ||
4486 | 191 | |||
4487 | 192 | HistoryScroll::~HistoryScroll() | ||
4488 | 193 | { | ||
4489 | 194 | delete m_histType; | ||
4490 | 195 | } | ||
4491 | 196 | |||
4492 | 197 | bool HistoryScroll::hasScroll() | ||
4493 | 198 | { | ||
4494 | 199 | return true; | ||
4495 | 200 | } | ||
4496 | 201 | |||
4497 | 202 | // History Scroll File ////////////////////////////////////// | ||
4498 | 203 | |||
4499 | 204 | /* | ||
4500 | 205 | The history scroll makes a Row(Row(Cell)) from | ||
4501 | 206 | two history buffers. The index buffer contains | ||
4502 | 207 | start of line positions which refere to the cells | ||
4503 | 208 | buffer. | ||
4504 | 209 | |||
4505 | 210 | Note that index[0] addresses the second line | ||
4506 | 211 | (line #1), while the first line (line #0) starts | ||
4507 | 212 | at 0 in cells. | ||
4508 | 213 | */ | ||
4509 | 214 | |||
4510 | 215 | HistoryScrollFile::HistoryScrollFile(const QString &logFileName) | ||
4511 | 216 | : HistoryScroll(new HistoryTypeFile(logFileName)), | ||
4512 | 217 | m_logFileName(logFileName) | ||
4513 | 218 | { | ||
4514 | 219 | } | ||
4515 | 220 | |||
4516 | 221 | HistoryScrollFile::~HistoryScrollFile() | ||
4517 | 222 | { | ||
4518 | 223 | } | ||
4519 | 224 | |||
4520 | 225 | int HistoryScrollFile::getLines() | ||
4521 | 226 | { | ||
4522 | 227 | return index.len() / sizeof(int); | ||
4523 | 228 | } | ||
4524 | 229 | |||
4525 | 230 | int HistoryScrollFile::getLineLen(int lineno) | ||
4526 | 231 | { | ||
4527 | 232 | return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(Character); | ||
4528 | 233 | } | ||
4529 | 234 | |||
4530 | 235 | bool HistoryScrollFile::isWrappedLine(int lineno) | ||
4531 | 236 | { | ||
4532 | 237 | if (lineno>=0 && lineno <= getLines()) { | ||
4533 | 238 | unsigned char flag; | ||
4534 | 239 | lineflags.get((unsigned char*)&flag,sizeof(unsigned char),(lineno)*sizeof(unsigned char)); | ||
4535 | 240 | return flag; | ||
4536 | 241 | } | ||
4537 | 242 | return false; | ||
4538 | 243 | } | ||
4539 | 244 | |||
4540 | 245 | int HistoryScrollFile::startOfLine(int lineno) | ||
4541 | 246 | { | ||
4542 | 247 | if (lineno <= 0) return 0; | ||
4543 | 248 | if (lineno <= getLines()) | ||
4544 | 249 | { | ||
4545 | 250 | |||
4546 | 251 | if (!index.isMapped()) | ||
4547 | 252 | index.map(); | ||
4548 | 253 | |||
4549 | 254 | int res; | ||
4550 | 255 | index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int)); | ||
4551 | 256 | return res; | ||
4552 | 257 | } | ||
4553 | 258 | return cells.len(); | ||
4554 | 259 | } | ||
4555 | 260 | |||
4556 | 261 | void HistoryScrollFile::getCells(int lineno, int colno, int count, Character res[]) | ||
4557 | 262 | { | ||
4558 | 263 | cells.get((unsigned char*)res,count*sizeof(Character),startOfLine(lineno)+colno*sizeof(Character)); | ||
4559 | 264 | } | ||
4560 | 265 | |||
4561 | 266 | void HistoryScrollFile::addCells(const Character text[], int count) | ||
4562 | 267 | { | ||
4563 | 268 | cells.add((unsigned char*)text,count*sizeof(Character)); | ||
4564 | 269 | } | ||
4565 | 270 | |||
4566 | 271 | void HistoryScrollFile::addLine(bool previousWrapped) | ||
4567 | 272 | { | ||
4568 | 273 | if (index.isMapped()) | ||
4569 | 274 | index.unmap(); | ||
4570 | 275 | |||
4571 | 276 | int locn = cells.len(); | ||
4572 | 277 | index.add((unsigned char*)&locn,sizeof(int)); | ||
4573 | 278 | unsigned char flags = previousWrapped ? 0x01 : 0x00; | ||
4574 | 279 | lineflags.add((unsigned char*)&flags,sizeof(unsigned char)); | ||
4575 | 280 | } | ||
4576 | 281 | |||
4577 | 282 | |||
4578 | 283 | // History Scroll Buffer ////////////////////////////////////// | ||
4579 | 284 | HistoryScrollBuffer::HistoryScrollBuffer(unsigned int maxLineCount) | ||
4580 | 285 | : HistoryScroll(new HistoryTypeBuffer(maxLineCount)) | ||
4581 | 286 | ,_historyBuffer() | ||
4582 | 287 | ,_maxLineCount(0) | ||
4583 | 288 | ,_usedLines(0) | ||
4584 | 289 | ,_head(0) | ||
4585 | 290 | { | ||
4586 | 291 | setMaxNbLines(maxLineCount); | ||
4587 | 292 | } | ||
4588 | 293 | |||
4589 | 294 | HistoryScrollBuffer::~HistoryScrollBuffer() | ||
4590 | 295 | { | ||
4591 | 296 | delete[] _historyBuffer; | ||
4592 | 297 | } | ||
4593 | 298 | |||
4594 | 299 | void HistoryScrollBuffer::addCellsVector(const QVector<Character>& cells) | ||
4595 | 300 | { | ||
4596 | 301 | _head++; | ||
4597 | 302 | if ( _usedLines < _maxLineCount ) | ||
4598 | 303 | _usedLines++; | ||
4599 | 304 | |||
4600 | 305 | if ( _head >= _maxLineCount ) | ||
4601 | 306 | { | ||
4602 | 307 | _head = 0; | ||
4603 | 308 | } | ||
4604 | 309 | |||
4605 | 310 | _historyBuffer[bufferIndex(_usedLines-1)] = cells; | ||
4606 | 311 | _wrappedLine[bufferIndex(_usedLines-1)] = false; | ||
4607 | 312 | } | ||
4608 | 313 | void HistoryScrollBuffer::addCells(const Character a[], int count) | ||
4609 | 314 | { | ||
4610 | 315 | HistoryLine newLine(count); | ||
4611 | 316 | qCopy(a,a+count,newLine.begin()); | ||
4612 | 317 | |||
4613 | 318 | addCellsVector(newLine); | ||
4614 | 319 | } | ||
4615 | 320 | |||
4616 | 321 | void HistoryScrollBuffer::addLine(bool previousWrapped) | ||
4617 | 322 | { | ||
4618 | 323 | _wrappedLine[bufferIndex(_usedLines-1)] = previousWrapped; | ||
4619 | 324 | } | ||
4620 | 325 | |||
4621 | 326 | int HistoryScrollBuffer::getLines() | ||
4622 | 327 | { | ||
4623 | 328 | return _usedLines; | ||
4624 | 329 | } | ||
4625 | 330 | |||
4626 | 331 | int HistoryScrollBuffer::getLineLen(int lineNumber) | ||
4627 | 332 | { | ||
4628 | 333 | Q_ASSERT( lineNumber >= 0 && lineNumber < _maxLineCount ); | ||
4629 | 334 | |||
4630 | 335 | if ( lineNumber < _usedLines ) | ||
4631 | 336 | { | ||
4632 | 337 | return _historyBuffer[bufferIndex(lineNumber)].size(); | ||
4633 | 338 | } | ||
4634 | 339 | else | ||
4635 | 340 | { | ||
4636 | 341 | return 0; | ||
4637 | 342 | } | ||
4638 | 343 | } | ||
4639 | 344 | |||
4640 | 345 | bool HistoryScrollBuffer::isWrappedLine(int lineNumber) | ||
4641 | 346 | { | ||
4642 | 347 | Q_ASSERT( lineNumber >= 0 && lineNumber < _maxLineCount ); | ||
4643 | 348 | |||
4644 | 349 | if (lineNumber < _usedLines) | ||
4645 | 350 | { | ||
4646 | 351 | //kDebug() << "Line" << lineNumber << "wrapped is" << _wrappedLine[bufferIndex(lineNumber)]; | ||
4647 | 352 | return _wrappedLine[bufferIndex(lineNumber)]; | ||
4648 | 353 | } | ||
4649 | 354 | else | ||
4650 | 355 | return false; | ||
4651 | 356 | } | ||
4652 | 357 | |||
4653 | 358 | void HistoryScrollBuffer::getCells(int lineNumber, int startColumn, int count, Character buffer[]) | ||
4654 | 359 | { | ||
4655 | 360 | if ( count == 0 ) return; | ||
4656 | 361 | |||
4657 | 362 | Q_ASSERT( lineNumber < _maxLineCount ); | ||
4658 | 363 | |||
4659 | 364 | if (lineNumber >= _usedLines) | ||
4660 | 365 | { | ||
4661 | 366 | memset(buffer, 0, count * sizeof(Character)); | ||
4662 | 367 | return; | ||
4663 | 368 | } | ||
4664 | 369 | |||
4665 | 370 | const HistoryLine& line = _historyBuffer[bufferIndex(lineNumber)]; | ||
4666 | 371 | |||
4667 | 372 | //kDebug() << "startCol " << startColumn; | ||
4668 | 373 | //kDebug() << "line.size() " << line.size(); | ||
4669 | 374 | //kDebug() << "count " << count; | ||
4670 | 375 | |||
4671 | 376 | Q_ASSERT( startColumn <= line.size() - count ); | ||
4672 | 377 | |||
4673 | 378 | memcpy(buffer, line.constData() + startColumn , count * sizeof(Character)); | ||
4674 | 379 | } | ||
4675 | 380 | |||
4676 | 381 | void HistoryScrollBuffer::setMaxNbLines(unsigned int lineCount) | ||
4677 | 382 | { | ||
4678 | 383 | HistoryLine* oldBuffer = _historyBuffer; | ||
4679 | 384 | HistoryLine* newBuffer = new HistoryLine[lineCount]; | ||
4680 | 385 | |||
4681 | 386 | for ( int i = 0 ; i < qMin(_usedLines,(int)lineCount) ; i++ ) | ||
4682 | 387 | { | ||
4683 | 388 | newBuffer[i] = oldBuffer[bufferIndex(i)]; | ||
4684 | 389 | } | ||
4685 | 390 | |||
4686 | 391 | _usedLines = qMin(_usedLines,(int)lineCount); | ||
4687 | 392 | _maxLineCount = lineCount; | ||
4688 | 393 | _head = ( _usedLines == _maxLineCount ) ? 0 : _usedLines-1; | ||
4689 | 394 | |||
4690 | 395 | _historyBuffer = newBuffer; | ||
4691 | 396 | delete[] oldBuffer; | ||
4692 | 397 | |||
4693 | 398 | _wrappedLine.resize(lineCount); | ||
4694 | 399 | dynamic_cast<HistoryTypeBuffer*>(m_histType)->m_nbLines = lineCount; | ||
4695 | 400 | } | ||
4696 | 401 | |||
4697 | 402 | int HistoryScrollBuffer::bufferIndex(int lineNumber) | ||
4698 | 403 | { | ||
4699 | 404 | Q_ASSERT( lineNumber >= 0 ); | ||
4700 | 405 | Q_ASSERT( lineNumber < _maxLineCount ); | ||
4701 | 406 | Q_ASSERT( (_usedLines == _maxLineCount) || lineNumber <= _head ); | ||
4702 | 407 | |||
4703 | 408 | if ( _usedLines == _maxLineCount ) | ||
4704 | 409 | { | ||
4705 | 410 | return (_head+lineNumber+1) % _maxLineCount; | ||
4706 | 411 | } | ||
4707 | 412 | else | ||
4708 | 413 | { | ||
4709 | 414 | return lineNumber; | ||
4710 | 415 | } | ||
4711 | 416 | } | ||
4712 | 417 | |||
4713 | 418 | |||
4714 | 419 | // History Scroll None ////////////////////////////////////// | ||
4715 | 420 | |||
4716 | 421 | HistoryScrollNone::HistoryScrollNone() | ||
4717 | 422 | : HistoryScroll(new HistoryTypeNone()) | ||
4718 | 423 | { | ||
4719 | 424 | } | ||
4720 | 425 | |||
4721 | 426 | HistoryScrollNone::~HistoryScrollNone() | ||
4722 | 427 | { | ||
4723 | 428 | } | ||
4724 | 429 | |||
4725 | 430 | bool HistoryScrollNone::hasScroll() | ||
4726 | 431 | { | ||
4727 | 432 | return false; | ||
4728 | 433 | } | ||
4729 | 434 | |||
4730 | 435 | int HistoryScrollNone::getLines() | ||
4731 | 436 | { | ||
4732 | 437 | return 0; | ||
4733 | 438 | } | ||
4734 | 439 | |||
4735 | 440 | int HistoryScrollNone::getLineLen(int) | ||
4736 | 441 | { | ||
4737 | 442 | return 0; | ||
4738 | 443 | } | ||
4739 | 444 | |||
4740 | 445 | bool HistoryScrollNone::isWrappedLine(int /*lineno*/) | ||
4741 | 446 | { | ||
4742 | 447 | return false; | ||
4743 | 448 | } | ||
4744 | 449 | |||
4745 | 450 | void HistoryScrollNone::getCells(int, int, int, Character []) | ||
4746 | 451 | { | ||
4747 | 452 | } | ||
4748 | 453 | |||
4749 | 454 | void HistoryScrollNone::addCells(const Character [], int) | ||
4750 | 455 | { | ||
4751 | 456 | } | ||
4752 | 457 | |||
4753 | 458 | void HistoryScrollNone::addLine(bool) | ||
4754 | 459 | { | ||
4755 | 460 | } | ||
4756 | 461 | |||
4757 | 462 | // History Scroll BlockArray ////////////////////////////////////// | ||
4758 | 463 | |||
4759 | 464 | HistoryScrollBlockArray::HistoryScrollBlockArray(size_t size) | ||
4760 | 465 | : HistoryScroll(new HistoryTypeBlockArray(size)) | ||
4761 | 466 | { | ||
4762 | 467 | m_blockArray.setHistorySize(size); // nb. of lines. | ||
4763 | 468 | } | ||
4764 | 469 | |||
4765 | 470 | HistoryScrollBlockArray::~HistoryScrollBlockArray() | ||
4766 | 471 | { | ||
4767 | 472 | } | ||
4768 | 473 | |||
4769 | 474 | int HistoryScrollBlockArray::getLines() | ||
4770 | 475 | { | ||
4771 | 476 | return m_lineLengths.count(); | ||
4772 | 477 | } | ||
4773 | 478 | |||
4774 | 479 | int HistoryScrollBlockArray::getLineLen(int lineno) | ||
4775 | 480 | { | ||
4776 | 481 | if ( m_lineLengths.contains(lineno) ) | ||
4777 | 482 | return m_lineLengths[lineno]; | ||
4778 | 483 | else | ||
4779 | 484 | return 0; | ||
4780 | 485 | } | ||
4781 | 486 | |||
4782 | 487 | bool HistoryScrollBlockArray::isWrappedLine(int /*lineno*/) | ||
4783 | 488 | { | ||
4784 | 489 | return false; | ||
4785 | 490 | } | ||
4786 | 491 | |||
4787 | 492 | void HistoryScrollBlockArray::getCells(int lineno, int colno, | ||
4788 | 493 | int count, Character res[]) | ||
4789 | 494 | { | ||
4790 | 495 | if (!count) return; | ||
4791 | 496 | |||
4792 | 497 | const Block *b = m_blockArray.at(lineno); | ||
4793 | 498 | |||
4794 | 499 | if (!b) { | ||
4795 | 500 | memset(res, 0, count * sizeof(Character)); // still better than random data | ||
4796 | 501 | return; | ||
4797 | 502 | } | ||
4798 | 503 | |||
4799 | 504 | assert(((colno + count) * sizeof(Character)) < ENTRIES); | ||
4800 | 505 | memcpy(res, b->data + (colno * sizeof(Character)), count * sizeof(Character)); | ||
4801 | 506 | } | ||
4802 | 507 | |||
4803 | 508 | void HistoryScrollBlockArray::addCells(const Character a[], int count) | ||
4804 | 509 | { | ||
4805 | 510 | Block *b = m_blockArray.lastBlock(); | ||
4806 | 511 | |||
4807 | 512 | if (!b) return; | ||
4808 | 513 | |||
4809 | 514 | // put cells in block's data | ||
4810 | 515 | assert((count * sizeof(Character)) < ENTRIES); | ||
4811 | 516 | |||
4812 | 517 | memset(b->data, 0, ENTRIES); | ||
4813 | 518 | |||
4814 | 519 | memcpy(b->data, a, count * sizeof(Character)); | ||
4815 | 520 | b->size = count * sizeof(Character); | ||
4816 | 521 | |||
4817 | 522 | size_t res = m_blockArray.newBlock(); | ||
4818 | 523 | assert (res > 0); | ||
4819 | 524 | Q_UNUSED( res ); | ||
4820 | 525 | |||
4821 | 526 | m_lineLengths.insert(m_blockArray.getCurrent(), count); | ||
4822 | 527 | } | ||
4823 | 528 | |||
4824 | 529 | void HistoryScrollBlockArray::addLine(bool) | ||
4825 | 530 | { | ||
4826 | 531 | } | ||
4827 | 532 | |||
4828 | 533 | //////////////////////////////////////////////////////////////// | ||
4829 | 534 | // Compact History Scroll ////////////////////////////////////// | ||
4830 | 535 | //////////////////////////////////////////////////////////////// | ||
4831 | 536 | void* CompactHistoryBlock::allocate ( size_t length ) | ||
4832 | 537 | { | ||
4833 | 538 | Q_ASSERT ( length > 0 ); | ||
4834 | 539 | if ( tail-blockStart+length > blockLength ) | ||
4835 | 540 | return NULL; | ||
4836 | 541 | |||
4837 | 542 | void* block = tail; | ||
4838 | 543 | tail += length; | ||
4839 | 544 | //kDebug() << "allocated " << length << " bytes at address " << block; | ||
4840 | 545 | allocCount++; | ||
4841 | 546 | return block; | ||
4842 | 547 | } | ||
4843 | 548 | |||
4844 | 549 | void CompactHistoryBlock::deallocate ( ) | ||
4845 | 550 | { | ||
4846 | 551 | allocCount--; | ||
4847 | 552 | Q_ASSERT ( allocCount >= 0 ); | ||
4848 | 553 | } | ||
4849 | 554 | |||
4850 | 555 | void* CompactHistoryBlockList::allocate(size_t size) | ||
4851 | 556 | { | ||
4852 | 557 | CompactHistoryBlock* block; | ||
4853 | 558 | if ( list.isEmpty() || list.last()->remaining() < size) | ||
4854 | 559 | { | ||
4855 | 560 | block = new CompactHistoryBlock(); | ||
4856 | 561 | list.append ( block ); | ||
4857 | 562 | //kDebug() << "new block created, remaining " << block->remaining() << "number of blocks=" << list.size(); | ||
4858 | 563 | } | ||
4859 | 564 | else | ||
4860 | 565 | { | ||
4861 | 566 | block = list.last(); | ||
4862 | 567 | //kDebug() << "old block used, remaining " << block->remaining(); | ||
4863 | 568 | } | ||
4864 | 569 | return block->allocate(size); | ||
4865 | 570 | } | ||
4866 | 571 | |||
4867 | 572 | void CompactHistoryBlockList::deallocate(void* ptr) | ||
4868 | 573 | { | ||
4869 | 574 | Q_ASSERT( !list.isEmpty()); | ||
4870 | 575 | |||
4871 | 576 | int i=0; | ||
4872 | 577 | CompactHistoryBlock *block = list.at(i); | ||
4873 | 578 | while ( i<list.size() && !block->contains(ptr) ) | ||
4874 | 579 | { | ||
4875 | 580 | i++; | ||
4876 | 581 | block=list.at(i); | ||
4877 | 582 | } | ||
4878 | 583 | |||
4879 | 584 | Q_ASSERT( i<list.size() ); | ||
4880 | 585 | |||
4881 | 586 | block->deallocate(); | ||
4882 | 587 | |||
4883 | 588 | if (!block->isInUse()) | ||
4884 | 589 | { | ||
4885 | 590 | list.removeAt(i); | ||
4886 | 591 | delete block; | ||
4887 | 592 | //kDebug() << "block deleted, new size = " << list.size(); | ||
4888 | 593 | } | ||
4889 | 594 | } | ||
4890 | 595 | |||
4891 | 596 | CompactHistoryBlockList::~CompactHistoryBlockList() | ||
4892 | 597 | { | ||
4893 | 598 | qDeleteAll ( list.begin(), list.end() ); | ||
4894 | 599 | list.clear(); | ||
4895 | 600 | } | ||
4896 | 601 | |||
4897 | 602 | void* CompactHistoryLine::operator new (size_t size, CompactHistoryBlockList& blockList) | ||
4898 | 603 | { | ||
4899 | 604 | return blockList.allocate(size); | ||
4900 | 605 | } | ||
4901 | 606 | |||
4902 | 607 | CompactHistoryLine::CompactHistoryLine ( const TextLine& line, CompactHistoryBlockList& bList ) | ||
4903 | 608 | : blockList(bList), | ||
4904 | 609 | formatLength(0) | ||
4905 | 610 | { | ||
4906 | 611 | length=line.size(); | ||
4907 | 612 | |||
4908 | 613 | if (line.size() > 0) { | ||
4909 | 614 | formatLength=1; | ||
4910 | 615 | int k=1; | ||
4911 | 616 | |||
4912 | 617 | // count number of different formats in this text line | ||
4913 | 618 | Character c = line[0]; | ||
4914 | 619 | while ( k<length ) | ||
4915 | 620 | { | ||
4916 | 621 | if ( !(line[k].equalsFormat(c))) | ||
4917 | 622 | { | ||
4918 | 623 | formatLength++; // format change detected | ||
4919 | 624 | c=line[k]; | ||
4920 | 625 | } | ||
4921 | 626 | k++; | ||
4922 | 627 | } | ||
4923 | 628 | |||
4924 | 629 | //kDebug() << "number of different formats in string: " << formatLength; | ||
4925 | 630 | formatArray = (CharacterFormat*) blockList.allocate(sizeof(CharacterFormat)*formatLength); | ||
4926 | 631 | Q_ASSERT (formatArray!=NULL); | ||
4927 | 632 | text = (quint16*) blockList.allocate(sizeof(quint16)*line.size()); | ||
4928 | 633 | Q_ASSERT (text!=NULL); | ||
4929 | 634 | |||
4930 | 635 | length=line.size(); | ||
4931 | 636 | formatLength=formatLength; | ||
4932 | 637 | wrapped=false; | ||
4933 | 638 | |||
4934 | 639 | // record formats and their positions in the format array | ||
4935 | 640 | c=line[0]; | ||
4936 | 641 | formatArray[0].setFormat ( c ); | ||
4937 | 642 | formatArray[0].startPos=0; // there's always at least 1 format (for the entire line, unless a change happens) | ||
4938 | 643 | |||
4939 | 644 | k=1; // look for possible format changes | ||
4940 | 645 | int j=1; | ||
4941 | 646 | while ( k<length && j<formatLength ) | ||
4942 | 647 | { | ||
4943 | 648 | if (!(line[k].equalsFormat(c))) | ||
4944 | 649 | { | ||
4945 | 650 | c=line[k]; | ||
4946 | 651 | formatArray[j].setFormat(c); | ||
4947 | 652 | formatArray[j].startPos=k; | ||
4948 | 653 | //kDebug() << "format entry " << j << " at pos " << formatArray[j].startPos << " " << &(formatArray[j].startPos) ; | ||
4949 | 654 | j++; | ||
4950 | 655 | } | ||
4951 | 656 | k++; | ||
4952 | 657 | } | ||
4953 | 658 | |||
4954 | 659 | // copy character values | ||
4955 | 660 | for ( int i=0; i<line.size(); i++ ) | ||
4956 | 661 | { | ||
4957 | 662 | text[i]=line[i].character; | ||
4958 | 663 | //kDebug() << "char " << i << " at mem " << &(text[i]); | ||
4959 | 664 | } | ||
4960 | 665 | } | ||
4961 | 666 | //kDebug() << "line created, length " << length << " at " << &(length); | ||
4962 | 667 | } | ||
4963 | 668 | |||
4964 | 669 | CompactHistoryLine::~CompactHistoryLine() | ||
4965 | 670 | { | ||
4966 | 671 | //kDebug() << "~CHL"; | ||
4967 | 672 | if (length>0) { | ||
4968 | 673 | blockList.deallocate(text); | ||
4969 | 674 | blockList.deallocate(formatArray); | ||
4970 | 675 | } | ||
4971 | 676 | blockList.deallocate(this); | ||
4972 | 677 | } | ||
4973 | 678 | |||
4974 | 679 | void CompactHistoryLine::getCharacter ( int index, Character &r ) | ||
4975 | 680 | { | ||
4976 | 681 | Q_ASSERT ( index < length ); | ||
4977 | 682 | int formatPos=0; | ||
4978 | 683 | while ( ( formatPos+1 ) < formatLength && index >= formatArray[formatPos+1].startPos ) | ||
4979 | 684 | formatPos++; | ||
4980 | 685 | |||
4981 | 686 | r.character=text[index]; | ||
4982 | 687 | r.rendition = formatArray[formatPos].rendition; | ||
4983 | 688 | r.foregroundColor = formatArray[formatPos].fgColor; | ||
4984 | 689 | r.backgroundColor = formatArray[formatPos].bgColor; | ||
4985 | 690 | } | ||
4986 | 691 | |||
4987 | 692 | void CompactHistoryLine::getCharacters ( Character* array, int length, int startColumn ) | ||
4988 | 693 | { | ||
4989 | 694 | Q_ASSERT ( startColumn >= 0 && length >= 0 ); | ||
4990 | 695 | Q_ASSERT ( startColumn+length <= ( int ) getLength() ); | ||
4991 | 696 | |||
4992 | 697 | for ( int i=startColumn; i<length+startColumn; i++ ) | ||
4993 | 698 | { | ||
4994 | 699 | getCharacter ( i, array[i-startColumn] ); | ||
4995 | 700 | } | ||
4996 | 701 | } | ||
4997 | 702 | |||
4998 | 703 | CompactHistoryScroll::CompactHistoryScroll ( unsigned int maxLineCount ) | ||
4999 | 704 | : HistoryScroll ( new CompactHistoryType ( maxLineCount ) ) | ||
5000 | 705 | ,lines() |
The diff has been truncated for viewing.