author | llornkcor <llornkcor> | 2002-06-28 23:37:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-28 23:37:17 (UTC) |
commit | 0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5 (patch) (unidiff) | |
tree | f1414fe0a921700e616b52c01ff84ea250e168b4 | |
parent | 05a76394214a0066325c71f91eb44ed7412df67c (diff) | |
download | opie-0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5.zip opie-0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5.tar.gz opie-0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5.tar.bz2 |
changed O_RDWR to O_RDONLY
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 84d53e0..2d694d2 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,629 +1,640 @@ | |||
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 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> | 16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> |
17 | #include <sys/utsname.h> | 17 | #include <sys/utsname.h> |
18 | #include <sys/time.h> | 18 | #include <sys/time.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
24 | #include <sys/ioctl.h> | 24 | #include <sys/ioctl.h> |
25 | #include <linux/soundcard.h> | 25 | #include <linux/soundcard.h> |
26 | 26 | ||
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <errno.h> | 29 | #include <errno.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | 31 | ||
32 | typedef struct _waveheader { | 32 | typedef struct _waveheader { |
33 | u_long main_chunk; /* 'RIFF' */ | 33 | u_long main_chunk; /* 'RIFF' */ |
34 | u_long length; /* filelen */ | 34 | u_long length; /* filelen */ |
35 | u_long chunk_type; /* 'WAVE' */ | 35 | u_long chunk_type; /* 'WAVE' */ |
36 | u_long sub_chunk; /* 'fmt ' */ | 36 | u_long sub_chunk; /* 'fmt ' */ |
37 | u_long sc_len; /* length of sub_chunk, =16 | 37 | u_long sc_len; /* length of sub_chunk, =16 |
38 | (chunckSize) format len */ | 38 | (chunckSize) format len */ |
39 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 39 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
40 | 40 | ||
41 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 41 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
42 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 42 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
43 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 43 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
44 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 44 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
45 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 45 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
46 | 46 | ||
47 | u_long data_chunk; /* 'data' */ | 47 | u_long data_chunk; /* 'data' */ |
48 | 48 | ||
49 | u_long data_length;/* samplecount */ | 49 | u_long data_length;/* samplecount */ |
50 | } WaveHeader; | 50 | } WaveHeader; |
51 | 51 | ||
52 | #define RIFF 0x46464952 | 52 | #define RIFF 0x46464952 |
53 | #define WAVE 0x45564157 | 53 | #define WAVE 0x45564157 |
54 | #define FMT 0x20746D66 | 54 | #define FMT 0x20746D66 |
55 | #define DATA 0x61746164 | 55 | #define DATA 0x61746164 |
56 | #define PCM_CODE 1 | 56 | #define PCM_CODE 1 |
57 | #define WAVE_MONO 1 | 57 | #define WAVE_MONO 1 |
58 | #define WAVE_STEREO 2 | 58 | #define WAVE_STEREO 2 |
59 | 59 | ||
60 | #include "vmemo.h" | 60 | #include "vmemo.h" |
61 | 61 | ||
62 | #include <qpe/qpeapplication.h> | 62 | #include <qpe/qpeapplication.h> |
63 | #include <qpe/resource.h> | 63 | #include <qpe/resource.h> |
64 | #include <qpe/config.h> | 64 | #include <qpe/config.h> |
65 | 65 | ||
66 | #include <qpainter.h> | 66 | #include <qpainter.h> |
67 | #include <qdatetime.h> | 67 | #include <qdatetime.h> |
68 | #include <qregexp.h> | 68 | #include <qregexp.h> |
69 | #include <qsound.h> | 69 | #include <qsound.h> |
70 | #include <qfile.h> | 70 | #include <qfile.h> |
71 | #include <qmessagebox.h> | 71 | #include <qmessagebox.h> |
72 | 72 | ||
73 | int seq = 0; | 73 | int seq = 0; |
74 | 74 | ||
75 | /* XPM */ | 75 | /* XPM */ |
76 | static char * vmemo_xpm[] = { | 76 | static char * vmemo_xpm[] = { |
77 | "16 16 102 2", | 77 | "16 16 102 2", |
78 | " c None", | 78 | " c None", |
79 | ". c #60636A", | 79 | ". c #60636A", |
80 | "+ c #6E6E72", | 80 | "+ c #6E6E72", |
81 | "@ c #68696E", | 81 | "@ c #68696E", |
82 | "# c #4D525C", | 82 | "# c #4D525C", |
83 | "$ c #6B6C70", | 83 | "$ c #6B6C70", |
84 | "% c #E3E3E8", | 84 | "% c #E3E3E8", |
85 | "& c #EEEEF2", | 85 | "& c #EEEEF2", |
86 | "* c #EAEAEF", | 86 | "* c #EAEAEF", |
87 | "= c #CACAD0", | 87 | "= c #CACAD0", |
88 | "- c #474A51", | 88 | "- c #474A51", |
89 | "; c #171819", | 89 | "; c #171819", |
90 | "> c #9B9B9F", | 90 | "> c #9B9B9F", |
91 | ", c #EBEBF0", | 91 | ", c #EBEBF0", |
92 | "' c #F4F4F7", | 92 | "' c #F4F4F7", |
93 | ") c #F1F1F5", | 93 | ") c #F1F1F5", |
94 | "! c #DEDEE4", | 94 | "! c #DEDEE4", |
95 | "~ c #57575C", | 95 | "~ c #57575C", |
96 | "{ c #010101", | 96 | "{ c #010101", |
97 | "] c #A2A2A6", | 97 | "] c #A2A2A6", |
98 | "^ c #747477", | 98 | "^ c #747477", |
99 | "/ c #B5B5B8", | 99 | "/ c #B5B5B8", |
100 | "( c #AEAEB2", | 100 | "( c #AEAEB2", |
101 | "_ c #69696D", | 101 | "_ c #69696D", |
102 | ": c #525256", | 102 | ": c #525256", |
103 | "< c #181C24", | 103 | "< c #181C24", |
104 | "[ c #97979B", | 104 | "[ c #97979B", |
105 | "} c #A7A7AC", | 105 | "} c #A7A7AC", |
106 | "| c #B0B0B4", | 106 | "| c #B0B0B4", |
107 | "1 c #C8C8D1", | 107 | "1 c #C8C8D1", |
108 | "2 c #75757B", | 108 | "2 c #75757B", |
109 | "3 c #46464A", | 109 | "3 c #46464A", |
110 | "4 c #494A4F", | 110 | "4 c #494A4F", |
111 | "5 c #323234", | 111 | "5 c #323234", |
112 | "6 c #909095", | 112 | "6 c #909095", |
113 | "7 c #39393B", | 113 | "7 c #39393B", |
114 | "8 c #757578", | 114 | "8 c #757578", |
115 | "9 c #87878E", | 115 | "9 c #87878E", |
116 | "0 c #222224", | 116 | "0 c #222224", |
117 | "a c #414144", | 117 | "a c #414144", |
118 | "b c #6A6A6E", | 118 | "b c #6A6A6E", |
119 | "c c #020C16", | 119 | "c c #020C16", |
120 | "d c #6B6B6F", | 120 | "d c #6B6B6F", |
121 | "e c #68686D", | 121 | "e c #68686D", |
122 | "f c #5B5B60", | 122 | "f c #5B5B60", |
123 | "g c #8A8A8F", | 123 | "g c #8A8A8F", |
124 | "h c #6B6B6E", | 124 | "h c #6B6B6E", |
125 | "i c #ADADB2", | 125 | "i c #ADADB2", |
126 | "j c #828289", | 126 | "j c #828289", |
127 | "k c #3E3E41", | 127 | "k c #3E3E41", |
128 | "l c #CFCFD7", | 128 | "l c #CFCFD7", |
129 | "m c #4C4C50", | 129 | "m c #4C4C50", |
130 | "n c #000000", | 130 | "n c #000000", |
131 | "o c #66666A", | 131 | "o c #66666A", |
132 | "p c #505054", | 132 | "p c #505054", |
133 | "q c #838388", | 133 | "q c #838388", |
134 | "r c #A1A1A7", | 134 | "r c #A1A1A7", |
135 | "s c #A9A9AE", | 135 | "s c #A9A9AE", |
136 | "t c #A8A8B0", | 136 | "t c #A8A8B0", |
137 | "u c #5E5E63", | 137 | "u c #5E5E63", |
138 | "v c #3A3A3E", | 138 | "v c #3A3A3E", |
139 | "w c #BDBDC6", | 139 | "w c #BDBDC6", |
140 | "x c #59595E", | 140 | "x c #59595E", |
141 | "y c #76767C", | 141 | "y c #76767C", |
142 | "z c #373738", | 142 | "z c #373738", |
143 | "A c #717174", | 143 | "A c #717174", |
144 | "B c #727278", | 144 | "B c #727278", |
145 | "C c #1C1C1E", | 145 | "C c #1C1C1E", |
146 | "D c #3C3C3F", | 146 | "D c #3C3C3F", |
147 | "E c #ADADB6", | 147 | "E c #ADADB6", |
148 | "F c #54555A", | 148 | "F c #54555A", |
149 | "G c #8B8C94", | 149 | "G c #8B8C94", |
150 | "H c #5A5A5F", | 150 | "H c #5A5A5F", |
151 | "I c #BBBBC3", | 151 | "I c #BBBBC3", |
152 | "J c #C4C4CB", | 152 | "J c #C4C4CB", |
153 | "K c #909098", | 153 | "K c #909098", |
154 | "L c #737379", | 154 | "L c #737379", |
155 | "M c #343437", | 155 | "M c #343437", |
156 | "N c #8F8F98", | 156 | "N c #8F8F98", |
157 | "O c #000407", | 157 | "O c #000407", |
158 | "P c #2D3137", | 158 | "P c #2D3137", |
159 | "Q c #B0B1BC", | 159 | "Q c #B0B1BC", |
160 | "R c #3B3C40", | 160 | "R c #3B3C40", |
161 | "S c #6E6E74", | 161 | "S c #6E6E74", |
162 | "T c #95959C", | 162 | "T c #95959C", |
163 | "U c #74747A", | 163 | "U c #74747A", |
164 | "V c #1D1D1E", | 164 | "V c #1D1D1E", |
165 | "W c #91929A", | 165 | "W c #91929A", |
166 | "X c #42444A", | 166 | "X c #42444A", |
167 | "Y c #22282E", | 167 | "Y c #22282E", |
168 | "Z c #B0B2BC", | 168 | "Z c #B0B2BC", |
169 | "` c #898A90", | 169 | "` c #898A90", |
170 | " . c #65656A", | 170 | " . c #65656A", |
171 | ".. c #999AA2", | 171 | ".. c #999AA2", |
172 | "+. c #52535A", | 172 | "+. c #52535A", |
173 | "@. c #151B21", | 173 | "@. c #151B21", |
174 | "#. c #515257", | 174 | "#. c #515257", |
175 | "$. c #B5B5BE", | 175 | "$. c #B5B5BE", |
176 | "%. c #616167", | 176 | "%. c #616167", |
177 | "&. c #1A1D22", | 177 | "&. c #1A1D22", |
178 | "*. c #000713", | 178 | "*. c #000713", |
179 | "=. c #1F1F21", | 179 | "=. c #1F1F21", |
180 | " ", | 180 | " ", |
181 | " . + @ # ", | 181 | " . + @ # ", |
182 | " $ % & * = - ", | 182 | " $ % & * = - ", |
183 | " ; > , ' ) ! ~ ", | 183 | " ; > , ' ) ! ~ ", |
184 | " { ] ^ / ( _ : ", | 184 | " { ] ^ / ( _ : ", |
185 | " < [ } | 1 2 3 ", | 185 | " < [ } | 1 2 3 ", |
186 | " 4 5 6 7 8 9 0 a b c ", | 186 | " 4 5 6 7 8 9 0 a b c ", |
187 | " d e f g h i j 3 k l m n ", | 187 | " d e f g h i j 3 k l m n ", |
188 | " o p q r s t u v w n ", | 188 | " o p q r s t u v w n ", |
189 | " o x y z A B C D E n ", | 189 | " o x y z A B C D E n ", |
190 | " F G H I J K L M N O ", | 190 | " F G H I J K L M N O ", |
191 | " P Q R S T U V W X ", | 191 | " P Q R S T U V W X ", |
192 | " Y Z ` b ...+. ", | 192 | " Y Z ` b ...+. ", |
193 | " @.#.$.%.&. ", | 193 | " @.#.$.%.&. ", |
194 | " *.B =. ", | 194 | " *.B =. ", |
195 | " n n n n n n n n n "}; | 195 | " n n n n n n n n n "}; |
196 | 196 | ||
197 | 197 | ||
198 | VMemo::VMemo( QWidget *parent, const char *_name ) | 198 | VMemo::VMemo( QWidget *parent, const char *_name ) |
199 | : QWidget( parent, _name ) | 199 | : QWidget( parent, _name ) |
200 | { | 200 | { |
201 | setFixedHeight( 18 ); | 201 | setFixedHeight( 18 ); |
202 | setFixedWidth( 14 ); | 202 | setFixedWidth( 14 ); |
203 | 203 | ||
204 | recording = FALSE; | 204 | recording = FALSE; |
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 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 209 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
210 | if (uname(&name) != -1) { | 210 | if (uname(&name) != -1) { |
211 | QString release=name.release; | 211 | QString release=name.release; |
212 | |||
212 | Config vmCfg("Vmemo"); | 213 | Config vmCfg("Vmemo"); |
213 | vmCfg.setGroup("Defaults"); | 214 | vmCfg.setGroup("Defaults"); |
214 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 215 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
215 | 216 | ||
216 | qDebug("toggleKey %d", toggleKey); | 217 | qDebug("toggleKey %d", toggleKey); |
217 | 218 | ||
218 | if(release.find("embedix",0,TRUE) !=-1) | 219 | if(release.find("embedix",0,TRUE) !=-1) |
219 | systemZaurus=TRUE; | 220 | systemZaurus=TRUE; |
220 | else | 221 | else |
221 | systemZaurus=FALSE; | 222 | systemZaurus=FALSE; |
222 | 223 | ||
223 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 224 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
224 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 225 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
225 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 226 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
226 | 227 | ||
227 | if( toggleKey != -1 ) { | 228 | if( toggleKey != -1 ) { |
228 | // QPEApplication::grabKeyboard(); | 229 | // QPEApplication::grabKeyboard(); |
229 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 230 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
230 | // e << 4096; // Key_Escape | 231 | // e << 4096; // Key_Escape |
231 | // e << Key_F5; //4148 | 232 | // e << Key_F5; //4148 |
232 | e << toggleKey; | 233 | e << toggleKey; |
233 | e << QString("QPE/VMemo"); | 234 | e << QString("QPE/VMemo"); |
234 | e << QString("toggleRecord()"); | 235 | e << QString("toggleRecord()"); |
235 | } | 236 | } |
236 | if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) | 237 | |
238 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | ||
237 | hide(); | 239 | hide(); |
238 | } | 240 | } |
239 | } | 241 | } |
240 | 242 | ||
241 | VMemo::~VMemo() | 243 | VMemo::~VMemo() |
242 | { | 244 | { |
243 | } | 245 | } |
244 | 246 | ||
245 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 247 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
246 | { | 248 | { |
249 | qDebug("receive"); | ||
247 | QDataStream stream( data, IO_ReadOnly ); | 250 | QDataStream stream( data, IO_ReadOnly ); |
248 | if (msg == "toggleRecord()") { | 251 | if (msg == "toggleRecord()") { |
249 | if (recording) { | 252 | if (recording) { |
250 | fromToggle = TRUE; | 253 | fromToggle = TRUE; |
251 | stopRecording(); | 254 | stopRecording(); |
252 | } else { | 255 | } else { |
253 | fromToggle = TRUE; | 256 | fromToggle = TRUE; |
254 | startRecording(); | 257 | startRecording(); |
255 | } | 258 | } |
256 | } | 259 | } |
257 | } | 260 | } |
258 | 261 | ||
259 | void VMemo::paintEvent( QPaintEvent* ) | 262 | void VMemo::paintEvent( QPaintEvent* ) |
260 | { | 263 | { |
261 | QPainter p(this); | 264 | QPainter p(this); |
262 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 265 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
263 | } | 266 | } |
264 | 267 | ||
265 | void VMemo::mousePressEvent( QMouseEvent * ) | 268 | void VMemo::mousePressEvent( QMouseEvent * ) |
266 | { | 269 | { |
267 | startRecording(); | 270 | startRecording(); |
268 | } | 271 | } |
269 | 272 | ||
270 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 273 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
271 | { | 274 | { |
272 | stopRecording(); | 275 | stopRecording(); |
273 | } | 276 | } |
274 | 277 | ||
275 | bool VMemo::startRecording() { | 278 | bool VMemo::startRecording() { |
276 | 279 | ||
277 | if ( recording) | 280 | if ( recording) |
278 | return FALSE;; | 281 | return FALSE; |
279 | 282 | ||
280 | Config config( "Vmemo" ); | 283 | Config config( "Vmemo" ); |
281 | config.setGroup( "System" ); | 284 | config.setGroup( "System" ); |
282 | 285 | ||
283 | useAlerts = config.readBoolEntry("Alert"); | 286 | useAlerts = config.readBoolEntry("Alert"); |
284 | if(useAlerts) { | 287 | if(useAlerts) { |
285 | 288 | ||
286 | msgLabel = new QLabel( 0, "alertLabel" ); | 289 | msgLabel = new QLabel( 0, "alertLabel" ); |
287 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 290 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
288 | msgLabel->show(); | 291 | msgLabel->show(); |
289 | } | 292 | } |
290 | 293 | ||
291 | // if(useAlerts) | 294 | // if(useAlerts) |
292 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 295 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
293 | // return; | 296 | // return; |
294 | // } else { | 297 | // } else { |
295 | // if (!systemZaurus ) | 298 | // if (!systemZaurus ) |
296 | // QSound::play(Resource::findSound("vmemob")); | 299 | // QSound::play(Resource::findSound("vmemob")); |
297 | // } | 300 | // } |
298 | qDebug("Start recording engines"); | 301 | qDebug("Start recording engines"); |
299 | recording = TRUE; | 302 | recording = TRUE; |
300 | 303 | ||
301 | if (openDSP() == -1) { | 304 | if (openDSP() == -1) { |
302 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 305 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
303 | // delete msgLabel; | 306 | // delete msgLabel; |
304 | recording = FALSE; | 307 | recording = FALSE; |
305 | return FALSE; | 308 | return FALSE; |
306 | } | 309 | } |
307 | 310 | ||
308 | config.setGroup("Defaults"); | 311 | config.setGroup("Defaults"); |
309 | 312 | ||
310 | QDateTime dt = QDateTime::currentDateTime(); | 313 | QDateTime dt = QDateTime::currentDateTime(); |
311 | 314 | ||
312 | QString fName; | 315 | QString fName; |
313 | config.setGroup( "System" ); | 316 | config.setGroup( "System" ); |
314 | fName = QPEApplication::documentDir() ; | 317 | fName = QPEApplication::documentDir() ; |
315 | fileName = config.readEntry("RecLocation", fName); | 318 | fileName = config.readEntry("RecLocation", fName); |
316 | 319 | ||
317 | int s; | 320 | int s; |
318 | s=fileName.find(':'); | 321 | s=fileName.find(':'); |
319 | if(s) | 322 | if(s) |
320 | fileName=fileName.right(fileName.length()-s-2); | 323 | fileName=fileName.right(fileName.length()-s-2); |
321 | qDebug("filename will be "+fileName); | 324 | qDebug("pathname will be "+fileName); |
325 | |||
322 | if( fileName.left(1).find('/') == -1) | 326 | if( fileName.left(1).find('/') == -1) |
323 | fileName="/"+fileName; | 327 | fileName="/"+fileName; |
324 | if( fileName.right(1).find('/') == -1) | 328 | if( fileName.right(1).find('/') == -1) |
325 | fileName+="/"; | 329 | fileName+="/"; |
326 | fName = "vm_"+ dt.toString()+ ".wav"; | 330 | fName = "vm_"+ dt.toString()+ ".wav"; |
327 | 331 | ||
328 | fileName+=fName; | 332 | fileName+=fName; |
329 | qDebug("filename is "+fileName); | 333 | qDebug("filename is "+fileName); |
330 | // No spaces in the filename | 334 | // No spaces in the filename |
331 | fileName.replace(QRegExp("'"),""); | 335 | fileName.replace(QRegExp("'"),""); |
332 | fileName.replace(QRegExp(" "),"_"); | 336 | fileName.replace(QRegExp(" "),"_"); |
333 | fileName.replace(QRegExp(":"),"."); | 337 | fileName.replace(QRegExp(":"),"."); |
334 | fileName.replace(QRegExp(","),""); | 338 | fileName.replace(QRegExp(","),""); |
335 | 339 | ||
336 | if(openWAV(fileName.latin1()) == -1) { | 340 | if(openWAV(fileName.latin1()) == -1) { |
337 | // QString err("Could not open the output file\n"); | 341 | // QString err("Could not open the output file\n"); |
338 | // err += fileName; | 342 | // err += fileName; |
339 | // QMessageBox::critical(0, "vmemo", err, "Abort"); | 343 | // QMessageBox::critical(0, "vmemo", err, "Abort"); |
340 | close(dsp); | 344 | close(dsp); |
341 | return FALSE; | 345 | return FALSE; |
342 | } | 346 | } |
343 | 347 | ||
344 | QArray<int> cats(1); | 348 | QArray<int> cats(1); |
345 | cats[0] = config.readNumEntry("Category", 0); | 349 | cats[0] = config.readNumEntry("Category", 0); |
346 | 350 | ||
347 | QString dlName("vm_"); | 351 | QString dlName("vm_"); |
348 | dlName += dt.toString(); | 352 | dlName += dt.toString(); |
349 | DocLnk l; | 353 | DocLnk l; |
350 | l.setFile(fileName); | 354 | l.setFile(fileName); |
351 | l.setName(dlName); | 355 | l.setName(dlName); |
352 | l.setType("audio/x-wav"); | 356 | l.setType("audio/x-wav"); |
353 | l.setCategories(cats); | 357 | l.setCategories(cats); |
354 | l.writeLink(); | 358 | l.writeLink(); |
355 | 359 | ||
356 | 360 | ||
357 | record(); | 361 | record(); |
358 | // delete msgLabel; | 362 | // delete msgLabel; |
359 | return TRUE; | 363 | return TRUE; |
360 | } | 364 | } |
361 | 365 | ||
362 | void VMemo::stopRecording() { | 366 | void VMemo::stopRecording() { |
367 | show(); | ||
368 | qDebug("Stopped recording"); | ||
363 | recording = FALSE; | 369 | recording = FALSE; |
364 | if(useAlerts) | 370 | if(useAlerts) |
365 | if( msgLabel) delete msgLabel; | 371 | if( msgLabel) delete msgLabel; |
366 | t_timer->stop(); | 372 | t_timer->stop(); |
373 | Config cfg("Vmemo"); | ||
374 | cfg.setGroup("Defaults"); | ||
375 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | ||
376 | hide(); | ||
367 | } | 377 | } |
368 | 378 | ||
369 | int VMemo::openDSP() | 379 | int VMemo::openDSP() |
370 | { | 380 | { |
371 | Config cfg("Vmemo"); | 381 | Config cfg("Vmemo"); |
372 | cfg.setGroup("Record"); | 382 | cfg.setGroup("Record"); |
373 | 383 | ||
374 | speed = cfg.readNumEntry("SampleRate", 22050); | 384 | speed = cfg.readNumEntry("SampleRate", 22050); |
375 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 385 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
376 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 386 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
377 | format = AFMT_S16_LE; | 387 | format = AFMT_S16_LE; |
378 | resolution = 16; | 388 | resolution = 16; |
379 | } else { | 389 | } else { |
380 | format = AFMT_U8; | 390 | format = AFMT_U8; |
381 | resolution = 8; | 391 | resolution = 8; |
382 | } | 392 | } |
383 | 393 | ||
384 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 394 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
385 | 395 | ||
386 | if(systemZaurus) { | 396 | if(systemZaurus) { |
387 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 397 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
388 | channels=1; //zaurus has one input channel | 398 | channels=1; //zaurus has one input channel |
389 | } else { | 399 | } else { |
390 | dsp = open("/dev/dsp", O_RDWR); | 400 | dsp = open("/dev/dsp", O_RDONLY); |
391 | } | 401 | } |
392 | 402 | ||
393 | if(dsp == -1) { | 403 | if(dsp == -1) { |
394 | perror("open(\"/dev/dsp\")"); | 404 | perror("open(\"/dev/dsp\")"); |
395 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 405 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
396 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 406 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
397 | return -1; | 407 | return -1; |
398 | } | 408 | } |
399 | 409 | ||
400 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 410 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
401 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 411 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
402 | return -1; | 412 | return -1; |
403 | } | 413 | } |
404 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 414 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
405 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 415 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
406 | return -1; | 416 | return -1; |
407 | } | 417 | } |
408 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 418 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
409 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 419 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
410 | return -1; | 420 | return -1; |
411 | } | 421 | } |
412 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 422 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
413 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 423 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
414 | return -1; | 424 | return -1; |
415 | } | 425 | } |
416 | 426 | ||
417 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 427 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
418 | 428 | ||
419 | return 1; | 429 | return 1; |
420 | } | 430 | } |
421 | 431 | ||
422 | int VMemo::openWAV(const char *filename) | 432 | int VMemo::openWAV(const char *filename) |
423 | { | 433 | { |
424 | track.setName(filename); | 434 | track.setName(filename); |
425 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 435 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
426 | errorMsg=filename; | 436 | errorMsg=filename; |
427 | return -1; | 437 | return -1; |
428 | } | 438 | } |
429 | 439 | ||
430 | wav=track.handle(); | 440 | wav=track.handle(); |
431 | 441 | ||
432 | WaveHeader wh; | 442 | WaveHeader wh; |
433 | 443 | ||
434 | wh.main_chunk = RIFF; | 444 | wh.main_chunk = RIFF; |
435 | wh.length=0; | 445 | wh.length=0; |
436 | wh.chunk_type = WAVE; | 446 | wh.chunk_type = WAVE; |
437 | wh.sub_chunk = FMT; | 447 | wh.sub_chunk = FMT; |
438 | wh.sc_len = 16; | 448 | wh.sc_len = 16; |
439 | wh.format = PCM_CODE; | 449 | wh.format = PCM_CODE; |
440 | wh.modus = channels; | 450 | wh.modus = channels; |
441 | wh.sample_fq = speed; | 451 | wh.sample_fq = speed; |
442 | wh.byte_p_sec = speed * channels * resolution/8; | 452 | wh.byte_p_sec = speed * channels * resolution/8; |
443 | wh.byte_p_spl = channels * (resolution / 8); | 453 | wh.byte_p_spl = channels * (resolution / 8); |
444 | wh.bit_p_spl = resolution; | 454 | wh.bit_p_spl = resolution; |
445 | wh.data_chunk = DATA; | 455 | wh.data_chunk = DATA; |
446 | wh.data_length= 0; | 456 | wh.data_length= 0; |
447 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 457 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
448 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 458 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
449 | write (wav, &wh, sizeof(WaveHeader)); | 459 | write (wav, &wh, sizeof(WaveHeader)); |
450 | 460 | ||
451 | return 1; | 461 | return 1; |
452 | } | 462 | } |
453 | 463 | ||
454 | void VMemo::record(void) | 464 | void VMemo::record(void) |
455 | { | 465 | { |
456 | int length=0, result, value; | 466 | int length=0, result, value; |
457 | QString msg; | 467 | QString msg; |
458 | msg.sprintf("Recording format %d", format); | 468 | msg.sprintf("Recording format %d", format); |
459 | qDebug(msg); | 469 | qDebug(msg); |
460 | Config config("Vmemo"); | 470 | Config config("Vmemo"); |
461 | config.setGroup("Record"); | 471 | config.setGroup("Record"); |
462 | int sRate=config.readNumEntry("SizeLimit", 30); | 472 | int sRate=config.readNumEntry("SizeLimit", 30); |
463 | 473 | ||
464 | t_timer->start( sRate * 1000+1000, TRUE); | 474 | t_timer->start( sRate * 1000+1000, TRUE); |
465 | 475 | ||
466 | if(systemZaurus) { | 476 | if(systemZaurus) { |
467 | 477 | ||
468 | msg.sprintf("Recording format zaurus"); | 478 | msg.sprintf("Recording format zaurus"); |
469 | qDebug(msg); | 479 | qDebug(msg); |
470 | signed short sound[512], monoBuffer[512]; | 480 | signed short sound[512], monoBuffer[512]; |
471 | 481 | ||
472 | if(format==AFMT_S16_LE) { | 482 | if(format==AFMT_S16_LE) { |
473 | 483 | ||
474 | 484 | ||
475 | 485 | ||
476 | while(recording) { | 486 | while(recording) { |
477 | 487 | ||
478 | result = read(dsp, sound, 512); // 8192 | 488 | result = read(dsp, sound, 512); // 8192 |
479 | // int j=0; | 489 | // int j=0; |
480 | 490 | ||
481 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 491 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
482 | monoBuffer[i] = sound[i]; | 492 | monoBuffer[i] = sound[i]; |
483 | } | 493 | } |
484 | 494 | ||
485 | length+=write(wav, monoBuffer, result); | 495 | length+=write(wav, monoBuffer, result); |
486 | if(length<0) | 496 | if(length<0) |
487 | recording=false; | 497 | recording=false; |
488 | 498 | ||
489 | // for (int i = 0; i < result; i+=2) { | 499 | // for (int i = 0; i < result; i+=2) { |
490 | // monoBuffer[j] = sound[i]; | 500 | // monoBuffer[j] = sound[i]; |
491 | // // monoBuffer[j] = (sound[i]+sound[i+1])/2; | 501 | // // monoBuffer[j] = (sound[i]+sound[i+1])/2; |
492 | 502 | ||
493 | // j++; | 503 | // j++; |
494 | // } | 504 | // } |
495 | qApp->processEvents(); | 505 | qApp->processEvents(); |
496 | // printf("%d\r",length); | 506 | // printf("%d\r",length); |
497 | // fflush(stdout); | 507 | // fflush(stdout); |
498 | } | 508 | } |
499 | 509 | ||
500 | } else { //AFMT_U8 | 510 | } else { //AFMT_U8 |
501 | // 8bit unsigned | 511 | // 8bit unsigned |
502 | unsigned short sound[512], monoBuffer[512]; | 512 | unsigned short sound[512], monoBuffer[512]; |
503 | while(recording) { | 513 | while(recording) { |
504 | result = read(dsp, sound, 512); // 8192 | 514 | result = read(dsp, sound, 512); // 8192 |
505 | // int j=0; | 515 | // int j=0; |
506 | 516 | ||
507 | // if(systemZaurus) { | 517 | // if(systemZaurus) { |
508 | 518 | ||
509 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 519 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
510 | monoBuffer[i] = sound[i]; | 520 | monoBuffer[i] = sound[i]; |
511 | } | 521 | } |
512 | 522 | ||
513 | length+=write(wav, monoBuffer, result); | 523 | length+=write(wav, monoBuffer, result); |
514 | 524 | ||
515 | // for (int i = 0; i < result; i+=2) { | 525 | // for (int i = 0; i < result; i+=2) { |
516 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; | 526 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; |
517 | // j++; | 527 | // j++; |
518 | // } | 528 | // } |
519 | // length+=write(wav, monoBuffer, result/2); | 529 | // length+=write(wav, monoBuffer, result/2); |
520 | length += result; | 530 | length += result; |
521 | // printf("%d\r",length); | 531 | // printf("%d\r",length); |
522 | // fflush(stdout); | 532 | // fflush(stdout); |
523 | } | 533 | } |
524 | 534 | ||
525 | qApp->processEvents(); | 535 | qApp->processEvents(); |
526 | } | 536 | } |
527 | 537 | ||
528 | } else { // 16 bit only capabilities | 538 | } else { // 16 bit only capabilities |
529 | 539 | ||
530 | 540 | ||
531 | msg.sprintf("Recording format other"); | 541 | msg.sprintf("Recording format other"); |
532 | qDebug(msg); | 542 | qDebug(msg); |
533 | 543 | ||
534 | signed short sound[512];//, monoBuffer[512]; | 544 | signed short sound[512];//, monoBuffer[512]; |
535 | 545 | ||
536 | while(recording) { | 546 | while(recording) { |
537 | 547 | ||
538 | result = read(dsp, sound, 512); // 8192 | 548 | result = read(dsp, sound, 512); // 8192 |
539 | 549 | ||
540 | write(wav, sound, result); | 550 | write(wav, sound, result); |
541 | length += result; | 551 | length += result; |
542 | if(length<0) { | 552 | if(length<0) { |
543 | 553 | ||
544 | recording=false; | 554 | recording=false; |
545 | perror("dev/dsp's is a lookin' messy"); | 555 | perror("dev/dsp's is a lookin' messy"); |
546 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 556 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
547 | } | 557 | } |
548 | // printf("%d\r",length); | 558 | // printf("%d\r",length); |
549 | // fflush(stdout); | 559 | // fflush(stdout); |
550 | qApp->processEvents(); | 560 | qApp->processEvents(); |
551 | } | 561 | } |
552 | // qDebug("file has length of %d lasting %d seconds", | 562 | // qDebug("file has length of %d lasting %d seconds", |
553 | // length, (( length / speed) / channels) / 2 ); | 563 | // length, (( length / speed) / channels) / 2 ); |
554 | // medialplayer states wrong length in secs | 564 | // medialplayer states wrong length in secs |
555 | } | 565 | } |
556 | 566 | ||
557 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 567 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
558 | 568 | ||
559 | value = length+36; | 569 | value = length+36; |
560 | 570 | ||
561 | lseek(wav, 4, SEEK_SET); | 571 | lseek(wav, 4, SEEK_SET); |
562 | write(wav, &value, 4); | 572 | write(wav, &value, 4); |
563 | lseek(wav, 40, SEEK_SET); | 573 | lseek(wav, 40, SEEK_SET); |
564 | 574 | ||
565 | write(wav, &length, 4); | 575 | write(wav, &length, 4); |
566 | 576 | ||
567 | track.close(); | 577 | track.close(); |
568 | qDebug("Tracvk closed"); | 578 | qDebug("Track closed"); |
569 | 579 | ||
570 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 580 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
571 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 581 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
572 | 582 | ||
573 | ::close(dsp); | 583 | ::close(dsp); |
574 | fileName = fileName.left(fileName.length()-4); | 584 | fileName = fileName.left(fileName.length()-4); |
575 | // if(useAlerts) | 585 | // if(useAlerts) |
576 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 586 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
577 | qDebug("done recording "+fileName); | 587 | qDebug("done recording "+fileName); |
588 | |||
578 | QSound::play(Resource::findSound("vmemoe")); | 589 | QSound::play(Resource::findSound("vmemoe")); |
579 | 590 | ||
580 | Config cfg("qpe"); | 591 | Config cfg("qpe"); |
581 | cfg.setGroup("Volume"); | 592 | cfg.setGroup("Volume"); |
582 | QString foo = cfg.readEntry("Mute","TRUE"); | 593 | QString foo = cfg.readEntry("Mute","TRUE"); |
583 | if(foo.find("TRUE",0,TRUE) != -1) | 594 | if(foo.find("TRUE",0,TRUE) != -1) |
584 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 595 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
585 | 596 | ||
586 | } | 597 | } |
587 | 598 | ||
588 | int VMemo::setToggleButton(int tog) { | 599 | int VMemo::setToggleButton(int tog) { |
589 | 600 | ||
590 | for( int i=0; i < 10;i++) { | 601 | for( int i=0; i < 10;i++) { |
591 | switch (tog) { | 602 | switch (tog) { |
592 | case 0: | 603 | case 0: |
593 | return -1; | 604 | return -1; |
594 | break; | 605 | break; |
595 | case 1: | 606 | case 1: |
596 | return 0; | 607 | return 0; |
597 | break; | 608 | break; |
598 | case 2: | 609 | case 2: |
599 | return Key_Escape; | 610 | return Key_Escape; |
600 | break; | 611 | break; |
601 | case 3: | 612 | case 3: |
602 | return Key_Space; | 613 | return Key_Space; |
603 | break; | 614 | break; |
604 | case 4: | 615 | case 4: |
605 | return Key_F12; | 616 | return Key_F12; |
606 | break; | 617 | break; |
607 | case 5: | 618 | case 5: |
608 | return Key_F9; | 619 | return Key_F9; |
609 | break; | 620 | break; |
610 | case 6: | 621 | case 6: |
611 | return Key_F10; | 622 | return Key_F10; |
612 | break; | 623 | break; |
613 | case 7: | 624 | case 7: |
614 | return Key_F11; | 625 | return Key_F11; |
615 | break; | 626 | break; |
616 | case 8: | 627 | case 8: |
617 | return Key_F13; | 628 | return Key_F13; |
618 | break; | 629 | break; |
619 | }; | 630 | }; |
620 | } | 631 | } |
621 | return -1; | 632 | return -1; |
622 | } | 633 | } |
623 | 634 | ||
624 | void VMemo::timerBreak() { | 635 | void VMemo::timerBreak() { |
625 | //stop | 636 | //stop |
626 | recording=false; | 637 | recording=false; |
627 | 638 | ||
628 | QMessageBox::message("Vmemo","Vmemo recording has \ntimed out"); | 639 | QMessageBox::message("Vmemo","Vmemo recording has \ntimed out"); |
629 | } | 640 | } |