author | erik <erik> | 2007-01-26 21:43:58 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-26 21:43:58 (UTC) |
commit | 3cd37427b5c5f26f62cff583fbde914467ddafe3 (patch) (unidiff) | |
tree | 664a2c1cf2198b69f94e9aa683133a3d92c98511 | |
parent | f77da1ae08512b02a3c50a124f823ed77e53dd64 (diff) | |
download | opie-3cd37427b5c5f26f62cff583fbde914467ddafe3.zip opie-3cd37427b5c5f26f62cff583fbde914467ddafe3.tar.gz opie-3cd37427b5c5f26f62cff583fbde914467ddafe3.tar.bz2 |
Both files in this commit exhibit the wrong way to use temporary files.
For TEHistory.cpp, it uses tmpfile() which produces a file which has a
name that can be guessed.
For vmemo.cpp, it uses tmpname() which only creates a predictable string.
Both uses have been switched to using mkstemp() wrapped around umask(). This
produces a much less predictable file that also has guaranteed restrictive
permissions.
I went a little farther in vmemo because it calls out to the shell using
system to 'mv' the new file. That is kinda wasteful so I switched it to use
rename instead.
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 73 | ||||
-rw-r--r-- | noncore/apps/opie-console/TEHistory.cpp | 27 |
2 files changed, 72 insertions, 28 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 8ba1eb7..1a8f154 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,662 +1,685 @@ | |||
1 | /************************************************************************************ | 1 | /************************************************************************************ |
2 | ** | 2 | ** |
3 | ** This file may be distributed and/or modified under the terms of the | 3 | ** This file may be distributed and/or modified under the terms of the |
4 | ** GNU General Public License version 2 as published by the Free Software | 4 | ** GNU General Public License version 2 as published by the Free Software |
5 | ** Foundation and appearing in the file LICENSE.GPL included in the | 5 | ** Foundation and appearing in the file LICENSE.GPL included in the |
6 | ** packaging of this file. | 6 | ** packaging of this file. |
7 | ** | 7 | ** |
8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
10 | ** | 10 | ** |
11 | ************************************************************************************/ | 11 | ************************************************************************************/ |
12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> | 12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> |
13 | // copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> | 13 | // copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> |
14 | 14 | ||
15 | /* OPIE */ | 15 | /* OPIE */ |
16 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | using namespace Opie::Core; | 17 | using namespace Opie::Core; |
18 | 18 | ||
19 | extern "C" { | 19 | extern "C" { |
20 | #include "adpcm.h" | 20 | #include "adpcm.h" |
21 | } | 21 | } |
22 | 22 | ||
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <fcntl.h> | 25 | #include <fcntl.h> |
26 | #include <sys/ioctl.h> | 26 | #include <sys/ioctl.h> |
27 | #include <linux/soundcard.h> | 27 | #include <linux/soundcard.h> |
28 | 28 | ||
29 | #include <errno.h> | 29 | #include <errno.h> |
30 | 30 | ||
31 | typedef struct _waveheader { | 31 | typedef struct _waveheader { |
32 | u_long main_chunk; /* 'RIFF' */ | 32 | u_long main_chunk; /* 'RIFF' */ |
33 | u_long length; /* filelen */ | 33 | u_long length; /* filelen */ |
34 | u_long chunk_type; /* 'WAVE' */ | 34 | u_long chunk_type; /* 'WAVE' */ |
35 | u_long sub_chunk; /* 'fmt ' */ | 35 | u_long sub_chunk; /* 'fmt ' */ |
36 | u_long sc_len; /* length of sub_chunk, =16 | 36 | u_long sc_len; /* length of sub_chunk, =16 |
37 | (chunckSize) format len */ | 37 | (chunckSize) format len */ |
38 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 38 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
39 | 39 | ||
40 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 40 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
41 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 41 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
42 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 42 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
43 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 43 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
44 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 44 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
45 | 45 | ||
46 | u_long data_chunk; /* 'data' */ | 46 | u_long data_chunk; /* 'data' */ |
47 | 47 | ||
48 | u_long data_length;/* samplecount */ | 48 | u_long data_length;/* samplecount */ |
49 | } WaveHeader; | 49 | } WaveHeader; |
50 | 50 | ||
51 | #define RIFF 0x46464952 | 51 | #define RIFF 0x46464952 |
52 | #define WAVE 0x45564157 | 52 | #define WAVE 0x45564157 |
53 | #define FMT 0x20746D66 | 53 | #define FMT 0x20746D66 |
54 | #define DATA 0x61746164 | 54 | #define DATA 0x61746164 |
55 | #define PCM_CODE 1 | 55 | #define PCM_CODE 1 |
56 | #define WAVE_MONO 1 | 56 | #define WAVE_MONO 1 |
57 | #define WAVE_STEREO 2 | 57 | #define WAVE_STEREO 2 |
58 | 58 | ||
59 | struct adpcm_state encoder_state; | 59 | struct adpcm_state encoder_state; |
60 | //struct adpcm_state decoder_state; | 60 | //struct adpcm_state decoder_state; |
61 | 61 | ||
62 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) | 62 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) |
63 | #define WAVE_FORMAT_PCM (0x0001) | 63 | #define WAVE_FORMAT_PCM (0x0001) |
64 | 64 | ||
65 | 65 | ||
66 | #include "vmemo.h" | 66 | #include "vmemo.h" |
67 | 67 | ||
68 | #include <opie2/otaskbarapplet.h> | 68 | #include <opie2/otaskbarapplet.h> |
69 | #include <qpe/qpeapplication.h> | 69 | #include <qpe/qpeapplication.h> |
70 | #include <qpe/config.h> | 70 | #include <qpe/config.h> |
71 | 71 | ||
72 | #include <qpainter.h> | 72 | #include <qpainter.h> |
73 | #include <qmessagebox.h> | 73 | #include <qmessagebox.h> |
74 | 74 | ||
75 | int seq = 0; | 75 | int seq = 0; |
76 | 76 | ||
77 | /* XPM */ | 77 | /* XPM */ |
78 | static char * vmemo_xpm[] = { | 78 | static char * vmemo_xpm[] = { |
79 | "16 16 102 2", | 79 | "16 16 102 2", |
80 | " c None", | 80 | " c None", |
81 | ". c #60636A", | 81 | ". c #60636A", |
82 | "+ c #6E6E72", | 82 | "+ c #6E6E72", |
83 | "@ c #68696E", | 83 | "@ c #68696E", |
84 | "# c #4D525C", | 84 | "# c #4D525C", |
85 | "$ c #6B6C70", | 85 | "$ c #6B6C70", |
86 | "% c #E3E3E8", | 86 | "% c #E3E3E8", |
87 | "& c #EEEEF2", | 87 | "& c #EEEEF2", |
88 | "* c #EAEAEF", | 88 | "* c #EAEAEF", |
89 | "= c #CACAD0", | 89 | "= c #CACAD0", |
90 | "- c #474A51", | 90 | "- c #474A51", |
91 | "; c #171819", | 91 | "; c #171819", |
92 | "> c #9B9B9F", | 92 | "> c #9B9B9F", |
93 | ", c #EBEBF0", | 93 | ", c #EBEBF0", |
94 | "' c #F4F4F7", | 94 | "' c #F4F4F7", |
95 | ") c #F1F1F5", | 95 | ") c #F1F1F5", |
96 | "! c #DEDEE4", | 96 | "! c #DEDEE4", |
97 | "~ c #57575C", | 97 | "~ c #57575C", |
98 | "{ c #010101", | 98 | "{ c #010101", |
99 | "] c #A2A2A6", | 99 | "] c #A2A2A6", |
100 | "^ c #747477", | 100 | "^ c #747477", |
101 | "/ c #B5B5B8", | 101 | "/ c #B5B5B8", |
102 | "( c #AEAEB2", | 102 | "( c #AEAEB2", |
103 | "_ c #69696D", | 103 | "_ c #69696D", |
104 | ": c #525256", | 104 | ": c #525256", |
105 | "< c #181C24", | 105 | "< c #181C24", |
106 | "[ c #97979B", | 106 | "[ c #97979B", |
107 | "} c #A7A7AC", | 107 | "} c #A7A7AC", |
108 | "| c #B0B0B4", | 108 | "| c #B0B0B4", |
109 | "1 c #C8C8D1", | 109 | "1 c #C8C8D1", |
110 | "2 c #75757B", | 110 | "2 c #75757B", |
111 | "3 c #46464A", | 111 | "3 c #46464A", |
112 | "4 c #494A4F", | 112 | "4 c #494A4F", |
113 | "5 c #323234", | 113 | "5 c #323234", |
114 | "6 c #909095", | 114 | "6 c #909095", |
115 | "7 c #39393B", | 115 | "7 c #39393B", |
116 | "8 c #757578", | 116 | "8 c #757578", |
117 | "9 c #87878E", | 117 | "9 c #87878E", |
118 | "0 c #222224", | 118 | "0 c #222224", |
119 | "a c #414144", | 119 | "a c #414144", |
120 | "b c #6A6A6E", | 120 | "b c #6A6A6E", |
121 | "c c #020C16", | 121 | "c c #020C16", |
122 | "d c #6B6B6F", | 122 | "d c #6B6B6F", |
123 | "e c #68686D", | 123 | "e c #68686D", |
124 | "f c #5B5B60", | 124 | "f c #5B5B60", |
125 | "g c #8A8A8F", | 125 | "g c #8A8A8F", |
126 | "h c #6B6B6E", | 126 | "h c #6B6B6E", |
127 | "i c #ADADB2", | 127 | "i c #ADADB2", |
128 | "j c #828289", | 128 | "j c #828289", |
129 | "k c #3E3E41", | 129 | "k c #3E3E41", |
130 | "l c #CFCFD7", | 130 | "l c #CFCFD7", |
131 | "m c #4C4C50", | 131 | "m c #4C4C50", |
132 | "n c #000000", | 132 | "n c #000000", |
133 | "o c #66666A", | 133 | "o c #66666A", |
134 | "p c #505054", | 134 | "p c #505054", |
135 | "q c #838388", | 135 | "q c #838388", |
136 | "r c #A1A1A7", | 136 | "r c #A1A1A7", |
137 | "s c #A9A9AE", | 137 | "s c #A9A9AE", |
138 | "t c #A8A8B0", | 138 | "t c #A8A8B0", |
139 | "u c #5E5E63", | 139 | "u c #5E5E63", |
140 | "v c #3A3A3E", | 140 | "v c #3A3A3E", |
141 | "w c #BDBDC6", | 141 | "w c #BDBDC6", |
142 | "x c #59595E", | 142 | "x c #59595E", |
143 | "y c #76767C", | 143 | "y c #76767C", |
144 | "z c #373738", | 144 | "z c #373738", |
145 | "A c #717174", | 145 | "A c #717174", |
146 | "B c #727278", | 146 | "B c #727278", |
147 | "C c #1C1C1E", | 147 | "C c #1C1C1E", |
148 | "D c #3C3C3F", | 148 | "D c #3C3C3F", |
149 | "E c #ADADB6", | 149 | "E c #ADADB6", |
150 | "F c #54555A", | 150 | "F c #54555A", |
151 | "G c #8B8C94", | 151 | "G c #8B8C94", |
152 | "H c #5A5A5F", | 152 | "H c #5A5A5F", |
153 | "I c #BBBBC3", | 153 | "I c #BBBBC3", |
154 | "J c #C4C4CB", | 154 | "J c #C4C4CB", |
155 | "K c #909098", | 155 | "K c #909098", |
156 | "L c #737379", | 156 | "L c #737379", |
157 | "M c #343437", | 157 | "M c #343437", |
158 | "N c #8F8F98", | 158 | "N c #8F8F98", |
159 | "O c #000407", | 159 | "O c #000407", |
160 | "P c #2D3137", | 160 | "P c #2D3137", |
161 | "Q c #B0B1BC", | 161 | "Q c #B0B1BC", |
162 | "R c #3B3C40", | 162 | "R c #3B3C40", |
163 | "S c #6E6E74", | 163 | "S c #6E6E74", |
164 | "T c #95959C", | 164 | "T c #95959C", |
165 | "U c #74747A", | 165 | "U c #74747A", |
166 | "V c #1D1D1E", | 166 | "V c #1D1D1E", |
167 | "W c #91929A", | 167 | "W c #91929A", |
168 | "X c #42444A", | 168 | "X c #42444A", |
169 | "Y c #22282E", | 169 | "Y c #22282E", |
170 | "Z c #B0B2BC", | 170 | "Z c #B0B2BC", |
171 | "` c #898A90", | 171 | "` c #898A90", |
172 | " . c #65656A", | 172 | " . c #65656A", |
173 | ".. c #999AA2", | 173 | ".. c #999AA2", |
174 | "+. c #52535A", | 174 | "+. c #52535A", |
175 | "@. c #151B21", | 175 | "@. c #151B21", |
176 | "#. c #515257", | 176 | "#. c #515257", |
177 | "$. c #B5B5BE", | 177 | "$. c #B5B5BE", |
178 | "%. c #616167", | 178 | "%. c #616167", |
179 | "&. c #1A1D22", | 179 | "&. c #1A1D22", |
180 | "*. c #000713", | 180 | "*. c #000713", |
181 | "=. c #1F1F21", | 181 | "=. c #1F1F21", |
182 | " ", | 182 | " ", |
183 | " . + @ # ", | 183 | " . + @ # ", |
184 | " $ % & * = - ", | 184 | " $ % & * = - ", |
185 | " ; > , ' ) ! ~ ", | 185 | " ; > , ' ) ! ~ ", |
186 | " { ] ^ / ( _ : ", | 186 | " { ] ^ / ( _ : ", |
187 | " < [ } | 1 2 3 ", | 187 | " < [ } | 1 2 3 ", |
188 | " 4 5 6 7 8 9 0 a b c ", | 188 | " 4 5 6 7 8 9 0 a b c ", |
189 | " d e f g h i j 3 k l m n ", | 189 | " d e f g h i j 3 k l m n ", |
190 | " o p q r s t u v w n ", | 190 | " o p q r s t u v w n ", |
191 | " o x y z A B C D E n ", | 191 | " o x y z A B C D E n ", |
192 | " F G H I J K L M N O ", | 192 | " F G H I J K L M N O ", |
193 | " P Q R S T U V W X ", | 193 | " P Q R S T U V W X ", |
194 | " Y Z ` b ...+. ", | 194 | " Y Z ` b ...+. ", |
195 | " @.#.$.%.&. ", | 195 | " @.#.$.%.&. ", |
196 | " *.B =. ", | 196 | " *.B =. ", |
197 | " n n n n n n n n n "}; | 197 | " n n n n n n n n n "}; |
198 | 198 | ||
199 | 199 | ||
200 | using namespace Opie::Ui; | 200 | using namespace Opie::Ui; |
201 | VMemo::VMemo( QWidget *parent, const char *_name ) | 201 | VMemo::VMemo( QWidget *parent, const char *_name ) |
202 | : QWidget( parent, _name ) { | 202 | : QWidget( parent, _name ) { |
203 | setFixedHeight( 18 ); | 203 | setFixedHeight( 18 ); |
204 | setFixedWidth( 14 ); | 204 | setFixedWidth( 14 ); |
205 | 205 | ||
206 | t_timer = new QTimer( this ); | 206 | t_timer = new QTimer( this ); |
207 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 207 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
208 | 208 | ||
209 | Config vmCfg("Vmemo"); | 209 | Config vmCfg("Vmemo"); |
210 | vmCfg.setGroup("Defaults"); | 210 | vmCfg.setGroup("Defaults"); |
211 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 211 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
212 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 212 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
213 | 213 | ||
214 | owarn <<"VMemo toggleKey" << toggleKey << oendl; | 214 | owarn <<"VMemo toggleKey" << toggleKey << oendl; |
215 | 215 | ||
216 | systemZaurus = false; | 216 | systemZaurus = false; |
217 | 217 | ||
218 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 218 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
219 | 219 | ||
220 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 220 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
221 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 221 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
222 | 222 | ||
223 | 223 | ||
224 | if( toggleKey != -1 ) { | 224 | if( toggleKey != -1 ) { |
225 | owarn << "Register key " << toggleKey << "" << oendl; | 225 | owarn << "Register key " << toggleKey << "" << oendl; |
226 | 226 | ||
227 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); | 227 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); |
228 | // e << 4096; // Key_Escape | 228 | // e << 4096; // Key_Escape |
229 | // e << Key_F5; //4148 | 229 | // e << Key_F5; //4148 |
230 | e << toggleKey; | 230 | e << toggleKey; |
231 | e << QCString("QPE/VMemo"); | 231 | e << QCString("QPE/VMemo"); |
232 | e << QCString("toggleRecord()"); | 232 | e << QCString("toggleRecord()"); |
233 | } | 233 | } |
234 | if(toggleKey == 0) | 234 | if(toggleKey == 0) |
235 | usingIcon = true; | 235 | usingIcon = true; |
236 | else | 236 | else |
237 | usingIcon = false; | 237 | usingIcon = false; |
238 | if (!usingIcon) | 238 | if (!usingIcon) |
239 | hide(); | 239 | hide(); |
240 | recording = false; | 240 | recording = false; |
241 | } | 241 | } |
242 | 242 | ||
243 | VMemo::~VMemo() { | 243 | VMemo::~VMemo() { |
244 | } | 244 | } |
245 | 245 | ||
246 | int VMemo::position() | 246 | int VMemo::position() |
247 | { | 247 | { |
248 | return 1; | 248 | return 1; |
249 | } | 249 | } |
250 | 250 | ||
251 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 251 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
252 | QDataStream stream( data, IO_ReadOnly ); | 252 | QDataStream stream( data, IO_ReadOnly ); |
253 | 253 | ||
254 | if (msg == "toggleRecord()") { | 254 | if (msg == "toggleRecord()") { |
255 | if (recording) { | 255 | if (recording) { |
256 | fromToggle = true; | 256 | fromToggle = true; |
257 | stopRecording(); | 257 | stopRecording(); |
258 | } else { | 258 | } else { |
259 | fromToggle = true; | 259 | fromToggle = true; |
260 | startRecording(); | 260 | startRecording(); |
261 | } | 261 | } |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | void VMemo::paintEvent( QPaintEvent* ) { | 265 | void VMemo::paintEvent( QPaintEvent* ) { |
266 | QPainter p(this); | 266 | QPainter p(this); |
267 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 267 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
268 | } | 268 | } |
269 | 269 | ||
270 | void VMemo::mousePressEvent( QMouseEvent * /*me*/) { | 270 | void VMemo::mousePressEvent( QMouseEvent * /*me*/) { |
271 | 271 | ||
272 | if(!recording) { | 272 | if(!recording) { |
273 | if(!startRecording() ){ | 273 | if(!startRecording() ){ |
274 | QMessageBox::critical(0, "vmemo", "Abort Recording", "Abort Recording"); | 274 | QMessageBox::critical(0, "vmemo", "Abort Recording", "Abort Recording"); |
275 | } | 275 | } |
276 | } else { | 276 | } else { |
277 | stopRecording(); | 277 | stopRecording(); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | 280 | ||
281 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 281 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
282 | } | 282 | } |
283 | 283 | ||
284 | bool VMemo::startRecording() { | 284 | bool VMemo::startRecording() { |
285 | Config config( "Vmemo" ); | 285 | Config config( "Vmemo" ); |
286 | config.setGroup( "System" ); | 286 | config.setGroup( "System" ); |
287 | 287 | ||
288 | 288 | ||
289 | odebug << "Start recording engines" << oendl; | 289 | odebug << "Start recording engines" << oendl; |
290 | recording = true; | 290 | recording = true; |
291 | 291 | ||
292 | if (openDSP() == -1) { | 292 | if (openDSP() == -1) { |
293 | recording = false; | 293 | recording = false; |
294 | return false; | 294 | return false; |
295 | } | 295 | } |
296 | 296 | ||
297 | config.setGroup("Defaults"); | 297 | config.setGroup("Defaults"); |
298 | 298 | ||
299 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); | 299 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); |
300 | date.replace(QRegExp("'"),""); | 300 | date.replace(QRegExp("'"),""); |
301 | date.replace(QRegExp(" "),"_"); | 301 | date.replace(QRegExp(" "),"_"); |
302 | date.replace(QRegExp(":"),"-"); | 302 | date.replace(QRegExp(":"),"-"); |
303 | date.replace(QRegExp(","),""); | 303 | date.replace(QRegExp(","),""); |
304 | 304 | ||
305 | QString fName; | 305 | QString fName; |
306 | config.setGroup( "System" ); | 306 | config.setGroup( "System" ); |
307 | fName = QPEApplication::documentDir() ; | 307 | fName = QPEApplication::documentDir() ; |
308 | fileName = config.readEntry("RecLocation", fName); | 308 | fileName = config.readEntry("RecLocation", fName); |
309 | 309 | ||
310 | int s; | 310 | int s; |
311 | s=fileName.find(':'); | 311 | s=fileName.find(':'); |
312 | if(s) | 312 | if(s) |
313 | fileName=fileName.right(fileName.length()-s-2); | 313 | fileName=fileName.right(fileName.length()-s-2); |
314 | odebug << "pathname will be "+fileName << oendl; | 314 | odebug << "pathname will be "+fileName << oendl; |
315 | 315 | ||
316 | if( fileName.left(1).find('/') == -1) | 316 | if( fileName.left(1).find('/') == -1) |
317 | fileName="/"+fileName; | 317 | fileName="/"+fileName; |
318 | if( fileName.right(1).find('/') == -1) | 318 | if( fileName.right(1).find('/') == -1) |
319 | fileName+="/"; | 319 | fileName+="/"; |
320 | fName = "vm_"+ date + ".wav"; | 320 | fName = "vm_"+ date + ".wav"; |
321 | 321 | ||
322 | fileName += fName; | 322 | fileName += fName; |
323 | odebug << "filename is " + fileName << oendl; | 323 | odebug << "filename is " + fileName << oendl; |
324 | 324 | ||
325 | useAlerts = config.readBoolEntry("Alert",1); | 325 | useAlerts = config.readBoolEntry("Alert",1); |
326 | if(useAlerts) { | 326 | if(useAlerts) { |
327 | msgLabel = new QLabel( 0, "alertLabel" ); | 327 | msgLabel = new QLabel( 0, "alertLabel" ); |
328 | msgLabel->setText( tr("<B><P><font size=+2>VMemo-Recording</font></B><p>%1</p>").arg("vm_"+ date)); | 328 | msgLabel->setText( tr("<B><P><font size=+2>VMemo-Recording</font></B><p>%1</p>").arg("vm_"+ date)); |
329 | msgLabel->show(); | 329 | msgLabel->show(); |
330 | } | 330 | } |
331 | 331 | ||
332 | // open tmp file here | 332 | // open tmp file here |
333 | char *pointer; | 333 | char *tmpFilePath = 0; |
334 | pointer=tmpnam(NULL); | 334 | char *tmpDir = getenv("TMPDIR"); |
335 | odebug << "Opening tmp file " << pointer << "" << oendl; | 335 | if (tmpDir && *tmpDir != '\0') { |
336 | tmpFilePath = new char[strlen(tmpDir) + strlen("/vmemo-wav-XXXXXX") + 1]; | ||
337 | strcpy(tmpFilePath, tmpDir); | ||
338 | free(tmpDir); | ||
339 | } else { | ||
340 | tmpFilePath = new char[strlen("/tmp/vmemo-wav-XXXXXX") + 1]; | ||
341 | strcpy(tmpFilePath, "/tmp"); | ||
342 | } | ||
343 | strcat(tmpFilePath, "/vmemo-wav-XXXXXX"); | ||
344 | mode_t currUmask = umask(S_IRWXO | S_IRWXG); | ||
345 | int tmpFd = mkstemp(tmpFilePath); | ||
346 | umask(currUmask); | ||
347 | if (tmpFd == -1) { | ||
348 | owarn << "Could not open temp file with template " << tmpFilePath | ||
349 | << oendl; | ||
350 | delete [] tmpFilePath; | ||
351 | return false; | ||
352 | } else | ||
353 | odebug << "Opened temp file " << tmpFilePath << "" << oendl; | ||
354 | |||
355 | close(tmpFd); | ||
336 | 356 | ||
337 | if(openWAV(pointer ) == -1) { | 357 | if(openWAV(tmpFilePath ) == -1) { |
338 | 358 | ||
339 | QString err("Could not open the temp file\n"); | 359 | QString err("Could not open the temp file\n"); |
340 | err += fileName; | 360 | err += fileName; |
341 | QMessageBox::critical(0, "vmemo", err, "Abort"); | 361 | QMessageBox::critical(0, "vmemo", err, "Abort"); |
342 | ::close(dsp); | 362 | ::close(dsp); |
343 | return false; | 363 | return false; |
344 | } | 364 | } |
345 | if( record() ) { | 365 | if( record() ) { |
346 | 366 | ||
347 | QString cmd; | 367 | if( fileName.find(".wav",0,true) == -1) |
348 | if( fileName.find(".wav",0,true) == -1) | 368 | fileName += ".wav"; |
349 | fileName += ".wav"; | ||
350 | 369 | ||
351 | cmd.sprintf("mv %s "+fileName, pointer); | 370 | int retVal = rename(tmpFilePath, fileName.local8Bit()); |
352 | // move tmp file to regular file here | 371 | if (retVal == -1) { |
353 | 372 | owarn << "Could not move " << tmpFilePath << " to " << fileName | |
354 | system(cmd.latin1()); | 373 | << oendl; |
355 | 374 | delete [] tmpFilePath; | |
356 | QArray<int> cats(1); | 375 | return false; |
357 | cats[0] = config.readNumEntry("Category", 0); | 376 | } |
358 | 377 | delete [] tmpFilePath; | |
359 | QString dlName("vm_"); | 378 | |
360 | dlName += date; | 379 | QArray<int> cats(1); |
361 | DocLnk l; | 380 | cats[0] = config.readNumEntry("Category", 0); |
362 | l.setFile(fileName); | 381 | |
363 | l.setName(dlName); | 382 | QString dlName("vm_"); |
364 | l.setType("audio/x-wav"); | 383 | dlName += date; |
365 | l.setCategories(cats); | 384 | DocLnk l; |
366 | l.writeLink(); | 385 | l.setFile(fileName); |
367 | return true; | 386 | l.setName(dlName); |
387 | l.setType("audio/x-wav"); | ||
388 | l.setCategories(cats); | ||
389 | l.writeLink(); | ||
390 | return true; | ||
368 | } else | 391 | } else |
369 | return false; | 392 | return false; |
370 | 393 | ||
371 | } | 394 | } |
372 | 395 | ||
373 | void VMemo::stopRecording() { | 396 | void VMemo::stopRecording() { |
374 | // show(); | 397 | // show(); |
375 | odebug << "Stopped recording" << oendl; | 398 | odebug << "Stopped recording" << oendl; |
376 | recording = false; | 399 | recording = false; |
377 | if(useAlerts) { | 400 | if(useAlerts) { |
378 | msgLabel->close(); | 401 | msgLabel->close(); |
379 | msgLabel=0; | 402 | msgLabel=0; |
380 | delete msgLabel; | 403 | delete msgLabel; |
381 | } | 404 | } |
382 | t_timer->stop(); | 405 | t_timer->stop(); |
383 | Config cfg("Vmemo"); | 406 | Config cfg("Vmemo"); |
384 | cfg.setGroup("Defaults"); | 407 | cfg.setGroup("Defaults"); |
385 | // if( cfg.readNumEntry("hideIcon",0) == 1 ) | 408 | // if( cfg.readNumEntry("hideIcon",0) == 1 ) |
386 | // hide(); | 409 | // hide(); |
387 | } | 410 | } |
388 | 411 | ||
389 | int VMemo::openDSP() { | 412 | int VMemo::openDSP() { |
390 | Config cfg("Vmemo"); | 413 | Config cfg("Vmemo"); |
391 | cfg.setGroup("Record"); | 414 | cfg.setGroup("Record"); |
392 | 415 | ||
393 | speed = cfg.readNumEntry("SampleRate", 22050); | 416 | speed = cfg.readNumEntry("SampleRate", 22050); |
394 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 417 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
395 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 418 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
396 | format = AFMT_S16_LE; | 419 | format = AFMT_S16_LE; |
397 | resolution = 16; | 420 | resolution = 16; |
398 | } else { | 421 | } else { |
399 | format = AFMT_U8; | 422 | format = AFMT_U8; |
400 | resolution = 8; | 423 | resolution = 8; |
401 | } | 424 | } |
402 | 425 | ||
403 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; | 426 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; |
404 | 427 | ||
405 | if(systemZaurus) { | 428 | if(systemZaurus) { |
406 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 429 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
407 | channels=1; //zaurus has one input channel | 430 | channels=1; //zaurus has one input channel |
408 | } else { | 431 | } else { |
409 | #ifdef QT_QWS_DEVFS | 432 | #ifdef QT_QWS_DEVFS |
410 | dsp = open("/dev/sound/dsp", O_RDONLY); | 433 | dsp = open("/dev/sound/dsp", O_RDONLY); |
411 | #else | 434 | #else |
412 | dsp = open("/dev/dsp", O_RDONLY); | 435 | dsp = open("/dev/dsp", O_RDONLY); |
413 | #endif | 436 | #endif |
414 | } | 437 | } |
415 | 438 | ||
416 | if (dsp == -1) { | 439 | if (dsp == -1) { |
417 | msgLabel->close(); | 440 | msgLabel->close(); |
418 | msgLabel=0; | 441 | msgLabel=0; |
419 | delete msgLabel; | 442 | delete msgLabel; |
420 | 443 | ||
421 | perror("open(\"/dev/dsp\")"); | 444 | perror("open(\"/dev/dsp\")"); |
422 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 445 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
423 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 446 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
424 | return -1; | 447 | return -1; |
425 | } | 448 | } |
426 | 449 | ||
427 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 450 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
428 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 451 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
429 | // return -1; | 452 | // return -1; |
430 | } | 453 | } |
431 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 454 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
432 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 455 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
433 | // return -1; | 456 | // return -1; |
434 | } | 457 | } |
435 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 458 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
436 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 459 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
437 | // return -1; | 460 | // return -1; |
438 | } | 461 | } |
439 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 462 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
440 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 463 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
441 | // return -1; | 464 | // return -1; |
442 | } | 465 | } |
443 | 466 | ||
444 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; //mute | 467 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; //mute |
445 | 468 | ||
446 | return 1; | 469 | return 1; |
447 | } | 470 | } |
448 | 471 | ||
449 | int VMemo::openWAV(const char *filename) { | 472 | int VMemo::openWAV(const char *filename) { |
450 | track.setName(filename); | 473 | track.setName(filename); |
451 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 474 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
452 | errorMsg=filename; | 475 | errorMsg=filename; |
453 | return -1; | 476 | return -1; |
454 | } | 477 | } |
455 | 478 | ||
456 | wav=track.handle(); | 479 | wav=track.handle(); |
457 | Config vmCfg("Vmemo"); | 480 | Config vmCfg("Vmemo"); |
458 | vmCfg.setGroup("Defaults"); | 481 | vmCfg.setGroup("Defaults"); |
459 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 482 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
460 | 483 | ||
461 | WaveHeader wh; | 484 | WaveHeader wh; |
462 | 485 | ||
463 | wh.main_chunk = RIFF; | 486 | wh.main_chunk = RIFF; |
464 | wh.length=0; | 487 | wh.length=0; |
465 | wh.chunk_type = WAVE; | 488 | wh.chunk_type = WAVE; |
466 | wh.sub_chunk = FMT; | 489 | wh.sub_chunk = FMT; |
467 | wh.sc_len = 16; | 490 | wh.sc_len = 16; |
468 | if(useADPCM) | 491 | if(useADPCM) |
469 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 492 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
470 | else | 493 | else |
471 | wh.format = PCM_CODE; | 494 | wh.format = PCM_CODE; |
472 | wh.modus = channels; | 495 | wh.modus = channels; |
473 | wh.sample_fq = speed; | 496 | wh.sample_fq = speed; |
474 | wh.byte_p_sec = speed * channels * resolution/8; | 497 | wh.byte_p_sec = speed * channels * resolution/8; |
475 | wh.byte_p_spl = channels * (resolution / 8); | 498 | wh.byte_p_spl = channels * (resolution / 8); |
476 | wh.bit_p_spl = resolution; | 499 | wh.bit_p_spl = resolution; |
477 | wh.data_chunk = DATA; | 500 | wh.data_chunk = DATA; |
478 | wh.data_length= 0; | 501 | wh.data_length= 0; |
479 | // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s " | 502 | // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s " |
480 | // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl; | 503 | // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl; |
481 | write (wav, &wh, sizeof(WaveHeader)); | 504 | write (wav, &wh, sizeof(WaveHeader)); |
482 | 505 | ||
483 | return 1; | 506 | return 1; |
484 | } | 507 | } |
485 | 508 | ||
486 | bool VMemo::record() { | 509 | bool VMemo::record() { |
487 | length = 0; | 510 | length = 0; |
488 | int bytesWritten = 0; | 511 | int bytesWritten = 0; |
489 | int result = 0; | 512 | int result = 0; |
490 | int value = 0; | 513 | int value = 0; |
491 | 514 | ||
492 | QString msg; | 515 | QString msg; |
493 | msg.sprintf("Recording format %d", format); | 516 | msg.sprintf("Recording format %d", format); |
494 | odebug << msg << oendl; | 517 | odebug << msg << oendl; |
495 | 518 | ||
496 | Config config("Vmemo"); | 519 | Config config("Vmemo"); |
497 | config.setGroup("Record"); | 520 | config.setGroup("Record"); |
498 | int sRate = config.readNumEntry("SizeLimit", 30); | 521 | int sRate = config.readNumEntry("SizeLimit", 30); |
499 | odebug << "VMEMO rate" << sRate << oendl; | 522 | odebug << "VMEMO rate" << sRate << oendl; |
500 | 523 | ||
501 | if(sRate > 0) { | 524 | if(sRate > 0) { |
502 | t_timer->start( sRate * 1000+1000, true); | 525 | t_timer->start( sRate * 1000+1000, true); |
503 | } | 526 | } |
504 | 527 | ||
505 | msg.sprintf("Recording format other"); | 528 | msg.sprintf("Recording format other"); |
506 | odebug << msg << oendl; | 529 | odebug << msg << oendl; |
507 | 530 | ||
508 | config.setGroup("Defaults"); | 531 | config.setGroup("Defaults"); |
509 | useADPCM = config.readBoolEntry("use_ADPCM", 0); | 532 | useADPCM = config.readBoolEntry("use_ADPCM", 0); |
510 | 533 | ||
511 | int bufsize = config.readNumEntry("BufferSize",1024); | 534 | int bufsize = config.readNumEntry("BufferSize",1024); |
512 | unsigned short sound[bufsize]; //, monoBuffer[bufsize]; | 535 | unsigned short sound[bufsize]; //, monoBuffer[bufsize]; |
513 | char abuf[bufsize / 2]; | 536 | char abuf[bufsize / 2]; |
514 | short sbuf[bufsize]; | 537 | short sbuf[bufsize]; |
515 | odebug << "ready to record"<< oendl; | 538 | odebug << "ready to record"<< oendl; |
516 | if(useADPCM) { | 539 | if(useADPCM) { |
517 | odebug << "usr ADPCM" << oendl; | 540 | odebug << "usr ADPCM" << oendl; |
518 | 541 | ||
519 | while(recording) { | 542 | while(recording) { |
520 | result = ::read(dsp, sbuf, bufsize); // adpcm read | 543 | result = ::read(dsp, sbuf, bufsize); // adpcm read |
521 | if( result <= 0) { | 544 | if( result <= 0) { |
522 | perror("recording error "); | 545 | perror("recording error "); |
523 | QMessageBox::message(tr("Note"),tr("error recording")); | 546 | QMessageBox::message(tr("Note"),tr("error recording")); |
524 | recording = false; | 547 | recording = false; |
525 | break; | 548 | break; |
526 | return false; | 549 | return false; |
527 | } | 550 | } |
528 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 551 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
529 | bytesWritten = ::write(wav, abuf, result/4); // adpcm write | 552 | bytesWritten = ::write(wav, abuf, result/4); // adpcm write |
530 | length += bytesWritten; | 553 | length += bytesWritten; |
531 | 554 | ||
532 | if(length < 0) { | 555 | if(length < 0) { |
533 | recording = false; | 556 | recording = false; |
534 | perror("dev/dsp's is a lookin' messy"); | 557 | perror("dev/dsp's is a lookin' messy"); |
535 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | 558 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
536 | break; | 559 | break; |
537 | return false; | 560 | return false; |
538 | } | 561 | } |
539 | printf("%d\r", length); | 562 | printf("%d\r", length); |
540 | fflush(stdout); | 563 | fflush(stdout); |
541 | qApp->processEvents(); | 564 | qApp->processEvents(); |
542 | } | 565 | } |
543 | } else { | 566 | } else { |
544 | odebug << "use regular wav" << oendl; | 567 | odebug << "use regular wav" << oendl; |
545 | while(recording) { | 568 | while(recording) { |
546 | result = ::read(dsp, sound, bufsize); // read | 569 | result = ::read(dsp, sound, bufsize); // read |
547 | if( result <= 0) { | 570 | if( result <= 0) { |
548 | perror("recording error "); | 571 | perror("recording error "); |
549 | QMessageBox::message(tr("Note"),tr("error recording")); | 572 | QMessageBox::message(tr("Note"),tr("error recording")); |
550 | recording = false; | 573 | recording = false; |
551 | break; | 574 | break; |
552 | return false; | 575 | return false; |
553 | } | 576 | } |
554 | 577 | ||
555 | bytesWritten = ::write(wav, sound, result); // write | 578 | bytesWritten = ::write(wav, sound, result); // write |
556 | length += bytesWritten; | 579 | length += bytesWritten; |
557 | 580 | ||
558 | if(length < 0) { | 581 | if(length < 0) { |
559 | recording = false; | 582 | recording = false; |
560 | perror("dev/dsp's is a lookin' messy"); | 583 | perror("dev/dsp's is a lookin' messy"); |
561 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | 584 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
562 | break; | 585 | break; |
563 | return false; | 586 | return false; |
564 | } | 587 | } |
565 | // printf("%d\r", length); | 588 | // printf("%d\r", length); |
566 | // fflush(stdout); | 589 | // fflush(stdout); |
567 | qApp->processEvents(); | 590 | qApp->processEvents(); |
568 | } | 591 | } |
569 | } | 592 | } |
570 | owarn << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl; | 593 | owarn << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl; |
571 | 594 | ||
572 | value = length + 36; | 595 | value = length + 36; |
573 | 596 | ||
574 | lseek(wav, 4, SEEK_SET); | 597 | lseek(wav, 4, SEEK_SET); |
575 | write(wav, &value, 4); | 598 | write(wav, &value, 4); |
576 | lseek(wav, 40, SEEK_SET); | 599 | lseek(wav, 40, SEEK_SET); |
577 | 600 | ||
578 | write(wav, &length, 4); | 601 | write(wav, &length, 4); |
579 | 602 | ||
580 | track.close(); | 603 | track.close(); |
581 | 604 | ||
582 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 605 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
583 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 606 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
584 | 607 | ||
585 | ::close(dsp); | 608 | ::close(dsp); |
586 | 609 | ||
587 | Config cfgO("OpieRec"); | 610 | Config cfgO("OpieRec"); |
588 | cfgO.setGroup("Sounds"); | 611 | cfgO.setGroup("Sounds"); |
589 | 612 | ||
590 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); | 613 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); |
591 | 614 | ||
592 | QString currentFileName = fileName; | 615 | QString currentFileName = fileName; |
593 | QString currentFile = "vm_"+ date; | 616 | QString currentFile = "vm_"+ date; |
594 | 617 | ||
595 | float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; | 618 | float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; |
596 | 619 | ||
597 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); | 620 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); |
598 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); | 621 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); |
599 | cfgO.writeEntry( currentFile, currentFileName); | 622 | cfgO.writeEntry( currentFile, currentFileName); |
600 | 623 | ||
601 | QString time; | 624 | QString time; |
602 | time.sprintf("%.2f", numberOfRecordedSeconds); | 625 | time.sprintf("%.2f", numberOfRecordedSeconds); |
603 | cfgO.writeEntry( currentFileName, time ); | 626 | cfgO.writeEntry( currentFileName, time ); |
604 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; | 627 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
605 | 628 | ||
606 | cfgO.write(); | 629 | cfgO.write(); |
607 | 630 | ||
608 | odebug << "done recording "+fileName << oendl; | 631 | odebug << "done recording "+fileName << oendl; |
609 | 632 | ||
610 | Config cfg("qpe"); | 633 | Config cfg("qpe"); |
611 | cfg.setGroup("Volume"); | 634 | cfg.setGroup("Volume"); |
612 | QString foo = cfg.readEntry("Mute","true"); | 635 | QString foo = cfg.readEntry("Mute","true"); |
613 | if(foo.find("true",0,true) != -1) | 636 | if(foo.find("true",0,true) != -1) |
614 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; //mute | 637 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; //mute |
615 | return true; | 638 | return true; |
616 | } | 639 | } |
617 | 640 | ||
618 | int VMemo::setToggleButton(int tog) { | 641 | int VMemo::setToggleButton(int tog) { |
619 | 642 | ||
620 | for( int i=0; i < 10;i++) { | 643 | for( int i=0; i < 10;i++) { |
621 | switch (tog) { | 644 | switch (tog) { |
622 | case 0: | 645 | case 0: |
623 | return -1; | 646 | return -1; |
624 | break; | 647 | break; |
625 | case 1: | 648 | case 1: |
626 | return 0; | 649 | return 0; |
627 | break; | 650 | break; |
628 | case 2: | 651 | case 2: |
629 | return Key_F24; //was Escape | 652 | return Key_F24; //was Escape |
630 | break; | 653 | break; |
631 | case 3: | 654 | case 3: |
632 | return Key_Space; | 655 | return Key_Space; |
633 | break; | 656 | break; |
634 | case 4: | 657 | case 4: |
635 | return Key_F12; | 658 | return Key_F12; |
636 | break; | 659 | break; |
637 | case 5: | 660 | case 5: |
638 | return Key_F9; | 661 | return Key_F9; |
639 | break; | 662 | break; |
640 | case 6: | 663 | case 6: |
641 | return Key_F10; | 664 | return Key_F10; |
642 | break; | 665 | break; |
643 | case 7: | 666 | case 7: |
644 | return Key_F11; | 667 | return Key_F11; |
645 | break; | 668 | break; |
646 | case 8: | 669 | case 8: |
647 | return Key_F13; | 670 | return Key_F13; |
648 | break; | 671 | break; |
649 | }; | 672 | }; |
650 | } | 673 | } |
651 | return -1; | 674 | return -1; |
652 | } | 675 | } |
653 | 676 | ||
654 | void VMemo::timerBreak() { | 677 | void VMemo::timerBreak() { |
655 | //stop | 678 | //stop |
656 | stopRecording(); | 679 | stopRecording(); |
657 | QMessageBox::message("Vmemo","Vmemo recording has ended"); | 680 | QMessageBox::message("Vmemo","Vmemo recording has ended"); |
658 | } | 681 | } |
659 | 682 | ||
660 | 683 | ||
661 | EXPORT_OPIE_APPLET_v1( VMemo ) | 684 | EXPORT_OPIE_APPLET_v1( VMemo ) |
662 | 685 | ||
diff --git a/noncore/apps/opie-console/TEHistory.cpp b/noncore/apps/opie-console/TEHistory.cpp index 317ce57..e2be42a 100644 --- a/noncore/apps/opie-console/TEHistory.cpp +++ b/noncore/apps/opie-console/TEHistory.cpp | |||
@@ -1,212 +1,233 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [TEHistory.C] History Buffer */ | 3 | /* [TEHistory.C] History Buffer */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* -------------------------------------------------------------------------- */ | 11 | /* -------------------------------------------------------------------------- */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | 18 | ||
19 | #include "TEHistory.h" | 19 | #include "TEHistory.h" |
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <assert.h> | 21 | #include <assert.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <sys/types.h> | 23 | #include <sys/types.h> |
24 | #include <sys/stat.h> | ||
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | #include <errno.h> | 26 | #include <errno.h> |
26 | 27 | ||
27 | #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) | 28 | #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) |
28 | 29 | ||
29 | /* | 30 | /* |
30 | An arbitrary long scroll. | 31 | An arbitrary long scroll. |
31 | 32 | ||
32 | One can modify the scroll only by adding either cells | 33 | One can modify the scroll only by adding either cells |
33 | or newlines, but access it randomly. | 34 | or newlines, but access it randomly. |
34 | 35 | ||
35 | The model is that of an arbitrary wide typewriter scroll | 36 | The model is that of an arbitrary wide typewriter scroll |
36 | in that the scroll is a serie of lines and each line is | 37 | in that the scroll is a serie of lines and each line is |
37 | a serie of cells with no overwriting permitted. | 38 | a serie of cells with no overwriting permitted. |
38 | 39 | ||
39 | The implementation provides arbitrary length and numbers | 40 | The implementation provides arbitrary length and numbers |
40 | of cells and line/column indexed read access to the scroll | 41 | of cells and line/column indexed read access to the scroll |
41 | at constant costs. | 42 | at constant costs. |
42 | 43 | ||
43 | FIXME: some complain about the history buffer comsuming the | 44 | FIXME: some complain about the history buffer comsuming the |
44 | memory of their machines. This problem is critical | 45 | memory of their machines. This problem is critical |
45 | since the history does not behave gracefully in cases | 46 | since the history does not behave gracefully in cases |
46 | where the memory is used up completely. | 47 | where the memory is used up completely. |
47 | 48 | ||
48 | I put in a workaround that should handle it problem | 49 | I put in a workaround that should handle it problem |
49 | now gracefully. I'm not satisfied with the solution. | 50 | now gracefully. I'm not satisfied with the solution. |
50 | 51 | ||
51 | FIXME: Terminating the history is not properly indicated | 52 | FIXME: Terminating the history is not properly indicated |
52 | in the menu. We should throw a signal. | 53 | in the menu. We should throw a signal. |
53 | 54 | ||
54 | FIXME: There is noticable decrease in speed, also. Perhaps, | 55 | FIXME: There is noticable decrease in speed, also. Perhaps, |
55 | there whole feature needs to be revisited therefore. | 56 | there whole feature needs to be revisited therefore. |
56 | Disadvantage of a more elaborated, say block-oriented | 57 | Disadvantage of a more elaborated, say block-oriented |
57 | scheme with wrap around would be it's complexity. | 58 | scheme with wrap around would be it's complexity. |
58 | */ | 59 | */ |
59 | 60 | ||
60 | //FIXME: tempory replacement for tmpfile | 61 | //FIXME: tempory replacement for tmpfile |
61 | // this is here one for debugging purpose. | 62 | // this is here one for debugging purpose. |
62 | 63 | ||
63 | //#define tmpfile xTmpFile | 64 | //#define tmpfile xTmpFile |
64 | 65 | ||
65 | FILE* xTmpFile() | 66 | FILE* xTmpFile() |
66 | { | 67 | { |
67 | static int fid = 0; | 68 | static int fid = 0; |
68 | char fname[80]; | 69 | char fname[80]; |
69 | sprintf(fname,"TmpFile.%d",fid++); | 70 | sprintf(fname,"TmpFile.%d",fid++); |
70 | return fopen(fname,"w"); | 71 | return fopen(fname,"w"); |
71 | } | 72 | } |
72 | 73 | ||
73 | 74 | ||
74 | // History Buffer /////////////////////////////////////////// | 75 | // History Buffer /////////////////////////////////////////// |
75 | 76 | ||
76 | /* | 77 | /* |
77 | A Row(X) data type which allows adding elements to the end. | 78 | A Row(X) data type which allows adding elements to the end. |
78 | */ | 79 | */ |
79 | 80 | ||
80 | HistoryBuffer::HistoryBuffer() | 81 | HistoryBuffer::HistoryBuffer() |
81 | { | 82 | { |
82 | ion = -1; | 83 | ion = -1; |
83 | length = 0; | 84 | length = 0; |
84 | } | 85 | } |
85 | 86 | ||
86 | HistoryBuffer::~HistoryBuffer() | 87 | HistoryBuffer::~HistoryBuffer() |
87 | { | 88 | { |
88 | setScroll(FALSE); | 89 | setScroll(FALSE); |
89 | } | 90 | } |
90 | 91 | ||
91 | void HistoryBuffer::setScroll(bool on) | 92 | void HistoryBuffer::setScroll(bool on) |
92 | { | 93 | { |
93 | if (on == hasScroll()) return; | 94 | if (on == hasScroll()) return; |
94 | 95 | ||
95 | if (on) | 96 | if (on) |
96 | { | 97 | { |
97 | assert( ion < 0 ); | 98 | assert( ion < 0 ); |
98 | assert( length == 0); | 99 | assert( length == 0); |
99 | FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); return; } | 100 | char* tmpDir = getenv("TMPDIR"); |
100 | ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp file.\n"); | 101 | char* tmpFilePath = 0; |
101 | fclose(tmp); | 102 | if (tmpDir && *tmpDir != '\0') { |
103 | tmpFilePath = new char[strlen(tmpDir) + strlen("/opie-console-HistoryBuffer-XXXXXX") + 1]; | ||
104 | strcpy(tmpFilePath, tmpDir); | ||
105 | free(tmpDir); | ||
106 | } else { | ||
107 | tmpFilePath = new char[strlen("/tmp/opie-console-HistoryBuffer-XXXXXX") + 1]; | ||
108 | strcpy(tmpFilePath, "/tmp"); | ||
109 | } | ||
110 | strcat(tmpFilePath, "/opie-console-HistoryBuffer-XXXXXX"); | ||
111 | mode_t currUmask = umask(S_IRWXO | S_IRWXG); | ||
112 | int tmpfd = mkstemp(tmpFilePath); | ||
113 | delete [] tmpFilePath; | ||
114 | umask(currUmask); | ||
115 | if (tmpfd == -1) { | ||
116 | perror("konsole: cannot open temp file.\n"); | ||
117 | return; | ||
118 | } | ||
119 | ion = dup(tmpfd); | ||
120 | if (ion<0) | ||
121 | perror("konsole: cannot dup temp file.\n"); | ||
122 | close(tmpfd); | ||
102 | } | 123 | } |
103 | else | 124 | else |
104 | { | 125 | { |
105 | assert( ion >= 0 ); | 126 | assert( ion >= 0 ); |
106 | close(ion); | 127 | close(ion); |
107 | ion = -1; | 128 | ion = -1; |
108 | length = 0; | 129 | length = 0; |
109 | } | 130 | } |
110 | } | 131 | } |
111 | 132 | ||
112 | bool HistoryBuffer::hasScroll() | 133 | bool HistoryBuffer::hasScroll() |
113 | { | 134 | { |
114 | return ion >= 0; | 135 | return ion >= 0; |
115 | } | 136 | } |
116 | 137 | ||
117 | void HistoryBuffer::add(const unsigned char* bytes, int len) | 138 | void HistoryBuffer::add(const unsigned char* bytes, int len) |
118 | { int rc; | 139 | { int rc; |
119 | assert(hasScroll()); | 140 | assert(hasScroll()); |
120 | rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); setScroll(FALSE); return; } | 141 | rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); setScroll(FALSE); return; } |
121 | rc = write(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::add.write"); setScroll(FALSE); return; } | 142 | rc = write(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::add.write"); setScroll(FALSE); return; } |
122 | length += rc; | 143 | length += rc; |
123 | } | 144 | } |
124 | 145 | ||
125 | void HistoryBuffer::get(unsigned char* bytes, int len, int loc) | 146 | void HistoryBuffer::get(unsigned char* bytes, int len, int loc) |
126 | { int rc; | 147 | { int rc; |
127 | assert(hasScroll()); | 148 | assert(hasScroll()); |
128 | if (loc < 0 || len < 0 || loc + len > length) | 149 | if (loc < 0 || len < 0 || loc + len > length) |
129 | fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc); | 150 | fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc); |
130 | rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::get.seek"); setScroll(FALSE); return; } | 151 | rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::get.seek"); setScroll(FALSE); return; } |
131 | rc = read(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::get.read"); setScroll(FALSE); return; } | 152 | rc = read(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::get.read"); setScroll(FALSE); return; } |
132 | } | 153 | } |
133 | 154 | ||
134 | int HistoryBuffer::len() | 155 | int HistoryBuffer::len() |
135 | { | 156 | { |
136 | return length; | 157 | return length; |
137 | } | 158 | } |
138 | 159 | ||
139 | // History Scroll ////////////////////////////////////// | 160 | // History Scroll ////////////////////////////////////// |
140 | 161 | ||
141 | /* | 162 | /* |
142 | The history scroll makes a Row(Row(Cell)) from | 163 | The history scroll makes a Row(Row(Cell)) from |
143 | two history buffers. The index buffer contains | 164 | two history buffers. The index buffer contains |
144 | start of line positions which refere to the cells | 165 | start of line positions which refere to the cells |
145 | buffer. | 166 | buffer. |
146 | 167 | ||
147 | Note that index[0] addresses the second line | 168 | Note that index[0] addresses the second line |
148 | (line #1), while the first line (line #0) starts | 169 | (line #1), while the first line (line #0) starts |
149 | at 0 in cells. | 170 | at 0 in cells. |
150 | */ | 171 | */ |
151 | 172 | ||
152 | HistoryScroll::HistoryScroll() | 173 | HistoryScroll::HistoryScroll() |
153 | { | 174 | { |
154 | } | 175 | } |
155 | 176 | ||
156 | HistoryScroll::~HistoryScroll() | 177 | HistoryScroll::~HistoryScroll() |
157 | { | 178 | { |
158 | } | 179 | } |
159 | 180 | ||
160 | void HistoryScroll::setScroll(bool on) | 181 | void HistoryScroll::setScroll(bool on) |
161 | { | 182 | { |
162 | index.setScroll(on); | 183 | index.setScroll(on); |
163 | cells.setScroll(on); | 184 | cells.setScroll(on); |
164 | } | 185 | } |
165 | 186 | ||
166 | bool HistoryScroll::hasScroll() | 187 | bool HistoryScroll::hasScroll() |
167 | { | 188 | { |
168 | return index.hasScroll() && cells.hasScroll(); | 189 | return index.hasScroll() && cells.hasScroll(); |
169 | } | 190 | } |
170 | 191 | ||
171 | int HistoryScroll::getLines() | 192 | int HistoryScroll::getLines() |
172 | { | 193 | { |
173 | if (!hasScroll()) return 0; | 194 | if (!hasScroll()) return 0; |
174 | return index.len() / sizeof(int); | 195 | return index.len() / sizeof(int); |
175 | } | 196 | } |
176 | 197 | ||
177 | int HistoryScroll::getLineLen(int lineno) | 198 | int HistoryScroll::getLineLen(int lineno) |
178 | { | 199 | { |
179 | if (!hasScroll()) return 0; | 200 | if (!hasScroll()) return 0; |
180 | return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(ca); | 201 | return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(ca); |
181 | } | 202 | } |
182 | 203 | ||
183 | int HistoryScroll::startOfLine(int lineno) | 204 | int HistoryScroll::startOfLine(int lineno) |
184 | { | 205 | { |
185 | if (lineno <= 0) return 0; | 206 | if (lineno <= 0) return 0; |
186 | if (!hasScroll()) return 0; | 207 | if (!hasScroll()) return 0; |
187 | if (lineno <= getLines()) | 208 | if (lineno <= getLines()) |
188 | { int res; | 209 | { int res; |
189 | index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int)); | 210 | index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int)); |
190 | return res; | 211 | return res; |
191 | } | 212 | } |
192 | return cells.len(); | 213 | return cells.len(); |
193 | } | 214 | } |
194 | 215 | ||
195 | void HistoryScroll::getCells(int lineno, int colno, int count, ca res[]) | 216 | void HistoryScroll::getCells(int lineno, int colno, int count, ca res[]) |
196 | { | 217 | { |
197 | assert(hasScroll()); | 218 | assert(hasScroll()); |
198 | cells.get((unsigned char*)res,count*sizeof(ca),startOfLine(lineno)+colno*sizeof(ca)); | 219 | cells.get((unsigned char*)res,count*sizeof(ca),startOfLine(lineno)+colno*sizeof(ca)); |
199 | } | 220 | } |
200 | 221 | ||
201 | void HistoryScroll::addCells(ca text[], int count) | 222 | void HistoryScroll::addCells(ca text[], int count) |
202 | { | 223 | { |
203 | if (!hasScroll()) return; | 224 | if (!hasScroll()) return; |
204 | cells.add((unsigned char*)text,count*sizeof(ca)); | 225 | cells.add((unsigned char*)text,count*sizeof(ca)); |
205 | } | 226 | } |
206 | 227 | ||
207 | void HistoryScroll::addLine() | 228 | void HistoryScroll::addLine() |
208 | { | 229 | { |
209 | if (!hasScroll()) return; | 230 | if (!hasScroll()) return; |
210 | int locn = cells.len(); | 231 | int locn = cells.len(); |
211 | index.add((unsigned char*)&locn,sizeof(int)); | 232 | index.add((unsigned char*)&locn,sizeof(int)); |
212 | } | 233 | } |