summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index d6128a6..6867e82 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -46,385 +46,386 @@ typedef struct _waveheader {
46 u_long sample_fq; /* samples per second (samplesPerSecond) */ 46 u_long sample_fq; /* samples per second (samplesPerSecond) */
47 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 47 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
48 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 48 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
49 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 49 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
50 50
51 u_long data_chunk; /* 'data' */ 51 u_long data_chunk; /* 'data' */
52 52
53 u_long data_length;/* samplecount */ 53 u_long data_length;/* samplecount */
54} WaveHeader; 54} WaveHeader;
55 55
56#define RIFF 0x46464952 56#define RIFF 0x46464952
57#define WAVE 0x45564157 57#define WAVE 0x45564157
58#define FMT 0x20746D66 58#define FMT 0x20746D66
59#define DATA 0x61746164 59#define DATA 0x61746164
60#define PCM_CODE 1 60#define PCM_CODE 1
61#define WAVE_MONO 1 61#define WAVE_MONO 1
62#define WAVE_STEREO 2 62#define WAVE_STEREO 2
63 63
64struct adpcm_state encoder_state; 64struct adpcm_state encoder_state;
65//struct adpcm_state decoder_state; 65//struct adpcm_state decoder_state;
66 66
67#define WAVE_FORMAT_DVI_ADPCM (0x0011) 67#define WAVE_FORMAT_DVI_ADPCM (0x0011)
68#define WAVE_FORMAT_PCM (0x0001) 68#define WAVE_FORMAT_PCM (0x0001)
69 69
70 70
71#include "vmemo.h" 71#include "vmemo.h"
72 72
73#include <qpe/qpeapplication.h> 73#include <qpe/qpeapplication.h>
74#include <qpe/resource.h> 74#include <qpe/resource.h>
75#include <qpe/config.h> 75#include <qpe/config.h>
76 76
77#include <qpainter.h> 77#include <qpainter.h>
78#include <qdatetime.h> 78#include <qdatetime.h>
79#include <qregexp.h> 79#include <qregexp.h>
80#include <qsound.h> 80#include <qsound.h>
81#include <qfile.h> 81#include <qfile.h>
82#include <qmessagebox.h> 82#include <qmessagebox.h>
83 83
84int seq = 0; 84int seq = 0;
85 85
86/* XPM */ 86/* XPM */
87static char * vmemo_xpm[] = { 87static char * vmemo_xpm[] = {
88 "16 16 102 2", 88 "16 16 102 2",
89 " c None", 89 " c None",
90 ". c #60636A", 90 ". c #60636A",
91 "+ c #6E6E72", 91 "+ c #6E6E72",
92 "@ c #68696E", 92 "@ c #68696E",
93 "# c #4D525C", 93 "# c #4D525C",
94 "$ c #6B6C70", 94 "$ c #6B6C70",
95 "% c #E3E3E8", 95 "% c #E3E3E8",
96 "& c #EEEEF2", 96 "& c #EEEEF2",
97 "* c #EAEAEF", 97 "* c #EAEAEF",
98 "= c #CACAD0", 98 "= c #CACAD0",
99 "- c #474A51", 99 "- c #474A51",
100 "; c #171819", 100 "; c #171819",
101 "> c #9B9B9F", 101 "> c #9B9B9F",
102 ", c #EBEBF0", 102 ", c #EBEBF0",
103 "' c #F4F4F7", 103 "' c #F4F4F7",
104 ") c #F1F1F5", 104 ") c #F1F1F5",
105 "! c #DEDEE4", 105 "! c #DEDEE4",
106 "~ c #57575C", 106 "~ c #57575C",
107 "{ c #010101", 107 "{ c #010101",
108 "] c #A2A2A6", 108 "] c #A2A2A6",
109 "^ c #747477", 109 "^ c #747477",
110 "/ c #B5B5B8", 110 "/ c #B5B5B8",
111 "( c #AEAEB2", 111 "( c #AEAEB2",
112 "_ c #69696D", 112 "_ c #69696D",
113 ": c #525256", 113 ": c #525256",
114 "< c #181C24", 114 "< c #181C24",
115 "[ c #97979B", 115 "[ c #97979B",
116 "} c #A7A7AC", 116 "} c #A7A7AC",
117 "| c #B0B0B4", 117 "| c #B0B0B4",
118 "1 c #C8C8D1", 118 "1 c #C8C8D1",
119 "2 c #75757B", 119 "2 c #75757B",
120 "3 c #46464A", 120 "3 c #46464A",
121 "4 c #494A4F", 121 "4 c #494A4F",
122 "5 c #323234", 122 "5 c #323234",
123 "6 c #909095", 123 "6 c #909095",
124 "7 c #39393B", 124 "7 c #39393B",
125 "8 c #757578", 125 "8 c #757578",
126 "9 c #87878E", 126 "9 c #87878E",
127 "0 c #222224", 127 "0 c #222224",
128 "a c #414144", 128 "a c #414144",
129 "b c #6A6A6E", 129 "b c #6A6A6E",
130 "c c #020C16", 130 "c c #020C16",
131 "d c #6B6B6F", 131 "d c #6B6B6F",
132 "e c #68686D", 132 "e c #68686D",
133 "f c #5B5B60", 133 "f c #5B5B60",
134 "g c #8A8A8F", 134 "g c #8A8A8F",
135 "h c #6B6B6E", 135 "h c #6B6B6E",
136 "i c #ADADB2", 136 "i c #ADADB2",
137 "j c #828289", 137 "j c #828289",
138 "k c #3E3E41", 138 "k c #3E3E41",
139 "l c #CFCFD7", 139 "l c #CFCFD7",
140 "m c #4C4C50", 140 "m c #4C4C50",
141 "n c #000000", 141 "n c #000000",
142 "o c #66666A", 142 "o c #66666A",
143 "p c #505054", 143 "p c #505054",
144 "q c #838388", 144 "q c #838388",
145 "r c #A1A1A7", 145 "r c #A1A1A7",
146 "s c #A9A9AE", 146 "s c #A9A9AE",
147 "t c #A8A8B0", 147 "t c #A8A8B0",
148 "u c #5E5E63", 148 "u c #5E5E63",
149 "v c #3A3A3E", 149 "v c #3A3A3E",
150 "w c #BDBDC6", 150 "w c #BDBDC6",
151 "x c #59595E", 151 "x c #59595E",
152 "y c #76767C", 152 "y c #76767C",
153 "z c #373738", 153 "z c #373738",
154 "A c #717174", 154 "A c #717174",
155 "B c #727278", 155 "B c #727278",
156 "C c #1C1C1E", 156 "C c #1C1C1E",
157 "D c #3C3C3F", 157 "D c #3C3C3F",
158 "E c #ADADB6", 158 "E c #ADADB6",
159 "F c #54555A", 159 "F c #54555A",
160 "G c #8B8C94", 160 "G c #8B8C94",
161 "H c #5A5A5F", 161 "H c #5A5A5F",
162 "I c #BBBBC3", 162 "I c #BBBBC3",
163 "J c #C4C4CB", 163 "J c #C4C4CB",
164 "K c #909098", 164 "K c #909098",
165 "L c #737379", 165 "L c #737379",
166 "M c #343437", 166 "M c #343437",
167 "N c #8F8F98", 167 "N c #8F8F98",
168 "O c #000407", 168 "O c #000407",
169 "P c #2D3137", 169 "P c #2D3137",
170 "Q c #B0B1BC", 170 "Q c #B0B1BC",
171 "R c #3B3C40", 171 "R c #3B3C40",
172 "S c #6E6E74", 172 "S c #6E6E74",
173 "T c #95959C", 173 "T c #95959C",
174 "U c #74747A", 174 "U c #74747A",
175 "V c #1D1D1E", 175 "V c #1D1D1E",
176 "W c #91929A", 176 "W c #91929A",
177 "X c #42444A", 177 "X c #42444A",
178 "Y c #22282E", 178 "Y c #22282E",
179 "Z c #B0B2BC", 179 "Z c #B0B2BC",
180 "` c #898A90", 180 "` c #898A90",
181 " . c #65656A", 181 " . c #65656A",
182 ".. c #999AA2", 182 ".. c #999AA2",
183 "+. c #52535A", 183 "+. c #52535A",
184 "@. c #151B21", 184 "@. c #151B21",
185 "#. c #515257", 185 "#. c #515257",
186 "$. c #B5B5BE", 186 "$. c #B5B5BE",
187 "%. c #616167", 187 "%. c #616167",
188 "&. c #1A1D22", 188 "&. c #1A1D22",
189 "*. c #000713", 189 "*. c #000713",
190 "=. c #1F1F21", 190 "=. c #1F1F21",
191 " ", 191 " ",
192 " . + @ # ", 192 " . + @ # ",
193 " $ % & * = - ", 193 " $ % & * = - ",
194 " ; > , ' ) ! ~ ", 194 " ; > , ' ) ! ~ ",
195 " { ] ^ / ( _ : ", 195 " { ] ^ / ( _ : ",
196 " < [ } | 1 2 3 ", 196 " < [ } | 1 2 3 ",
197 " 4 5 6 7 8 9 0 a b c ", 197 " 4 5 6 7 8 9 0 a b c ",
198 " d e f g h i j 3 k l m n ", 198 " d e f g h i j 3 k l m n ",
199 " o p q r s t u v w n ", 199 " o p q r s t u v w n ",
200 " o x y z A B C D E n ", 200 " o x y z A B C D E n ",
201 " F G H I J K L M N O ", 201 " F G H I J K L M N O ",
202 " P Q R S T U V W X ", 202 " P Q R S T U V W X ",
203 " Y Z ` b ...+. ", 203 " Y Z ` b ...+. ",
204 " @.#.$.%.&. ", 204 " @.#.$.%.&. ",
205 " *.B =. ", 205 " *.B =. ",
206 " n n n n n n n n n "}; 206 " n n n n n n n n n "};
207 207
208 208
209VMemo::VMemo( QWidget *parent, const char *_name ) 209VMemo::VMemo( QWidget *parent, const char *_name )
210 : QWidget( parent, _name ) { 210 : QWidget( parent, _name ) {
211 setFixedHeight( 18 ); 211 setFixedHeight( 18 );
212 setFixedWidth( 14 ); 212 setFixedWidth( 14 );
213 213
214 t_timer = new QTimer( this ); 214 t_timer = new QTimer( this );
215 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 215 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) );
216 216
217 struct utsname name; /* check for embedix kernel running on the zaurus*/ 217 struct utsname name; /* check for embedix kernel running on the zaurus*/
218 if (uname(&name) != -1) { 218 if (uname(&name) != -1) {
219 QString release=name.release; 219 QString release=name.release;
220 220
221 Config vmCfg("Vmemo"); 221 Config vmCfg("Vmemo");
222 vmCfg.setGroup("Defaults"); 222 vmCfg.setGroup("Defaults");
223 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); 223 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
224 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 224 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
225 225
226 qDebug("toggleKey %d", toggleKey); 226 qDebug("toggleKey %d", toggleKey);
227 227
228 if(release.find("embedix",0,TRUE) !=-1) 228 if(release.find("embedix",0,TRUE) !=-1)
229 systemZaurus=TRUE; 229 systemZaurus=TRUE;
230 else 230 else
231 systemZaurus=FALSE; 231 systemZaurus=FALSE;
232 232
233 myChannel = new QCopChannel( "QPE/VMemo", this ); 233 myChannel = new QCopChannel( "QPE/VMemo", this );
234 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 234 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
235 this, SLOT(receive(const QCString&, const QByteArray&)) ); 235 this, SLOT(receive(const QCString&, const QByteArray&)) );
236 236
237 if( toggleKey != -1 ) { 237 if( toggleKey != -1 ) {
238 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 238 // keyRegister(key, channel, message)
239 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)");
239 // e << 4096; // Key_Escape 240 // e << 4096; // Key_Escape
240 // e << Key_F5; //4148 241 // e << Key_F5; //4148
241 e << toggleKey; 242 e << toggleKey;
242 e << QString("QPE/VMemo"); 243 e << QString("QPE/VMemo");
243 e << QString("toggleRecord()"); 244 e << QString("toggleRecord()");
244 } 245 }
245 if(toggleKey == 1) 246 if(toggleKey == 1)
246 usingIcon=TRUE; 247 usingIcon=TRUE;
247 else 248 else
248 usingIcon=FALSE; 249 usingIcon=FALSE;
249 if( vmCfg.readNumEntry("hideIcon",0) == 1) 250 if( vmCfg.readNumEntry("hideIcon",0) == 1)
250 hide(); 251 hide();
251 recording = FALSE; 252 recording = FALSE;
252 } 253 }
253} 254}
254 255
255VMemo::~VMemo() { 256VMemo::~VMemo() {
256} 257}
257 258
258void VMemo::receive( const QCString &msg, const QByteArray &data ) { 259void VMemo::receive( const QCString &msg, const QByteArray &data ) {
259 qDebug("receive"); 260 qDebug("receive");
260 QDataStream stream( data, IO_ReadOnly ); 261 QDataStream stream( data, IO_ReadOnly );
261 262
262 if (msg == "toggleRecord()") { 263 if (msg == "toggleRecord()") {
263 if (recording) { 264 if (recording) {
264 fromToggle = TRUE; 265 fromToggle = TRUE;
265 stopRecording(); 266 stopRecording();
266 } else { 267 } else {
267 fromToggle = TRUE; 268 fromToggle = TRUE;
268 startRecording(); 269 startRecording();
269 } 270 }
270 } 271 }
271} 272}
272 273
273void VMemo::paintEvent( QPaintEvent* ) { 274void VMemo::paintEvent( QPaintEvent* ) {
274 QPainter p(this); 275 QPainter p(this);
275 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 276 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
276} 277}
277 278
278void VMemo::mousePressEvent( QMouseEvent * me) { 279void VMemo::mousePressEvent( QMouseEvent * me) {
279 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 280 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
280 mousePressEvent and mouseReleaseEvent with a NULL parameter. */ 281 mousePressEvent and mouseReleaseEvent with a NULL parameter. */
281 282
282// if (!systemZaurus && me != NULL) 283// if (!systemZaurus && me != NULL)
283// return; 284// return;
284// } 285// }
285 286
286 if(!recording) 287 if(!recording)
287 startRecording(); 288 startRecording();
288 else 289 else
289 stopRecording(); 290 stopRecording();
290} 291}
291 292
292void VMemo::mouseReleaseEvent( QMouseEvent * ) { 293void VMemo::mouseReleaseEvent( QMouseEvent * ) {
293} 294}
294 295
295bool VMemo::startRecording() { 296bool VMemo::startRecording() {
296 Config config( "Vmemo" ); 297 Config config( "Vmemo" );
297 config.setGroup( "System" ); 298 config.setGroup( "System" );
298 299
299 useAlerts = config.readBoolEntry("Alert",1); 300 useAlerts = config.readBoolEntry("Alert",1);
300 if(useAlerts) { 301 if(useAlerts) {
301 302
302 msgLabel = new QLabel( 0, "alertLabel" ); 303 msgLabel = new QLabel( 0, "alertLabel" );
303 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); 304 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
304 msgLabel->show(); 305 msgLabel->show();
305 } 306 }
306 307
307 qDebug("Start recording engines"); 308 qDebug("Start recording engines");
308 recording = TRUE; 309 recording = TRUE;
309 310
310 if (openDSP() == -1) { 311 if (openDSP() == -1) {
311 recording = FALSE; 312 recording = FALSE;
312 return FALSE; 313 return FALSE;
313 } 314 }
314 315
315 config.setGroup("Defaults"); 316 config.setGroup("Defaults");
316 317
317 QDateTime dt = QDateTime::currentDateTime(); 318 QDateTime dt = QDateTime::currentDateTime();
318 319
319 QString fName; 320 QString fName;
320 config.setGroup( "System" ); 321 config.setGroup( "System" );
321 fName = QPEApplication::documentDir() ; 322 fName = QPEApplication::documentDir() ;
322 fileName = config.readEntry("RecLocation", fName); 323 fileName = config.readEntry("RecLocation", fName);
323 324
324 int s; 325 int s;
325 s=fileName.find(':'); 326 s=fileName.find(':');
326 if(s) 327 if(s)
327 fileName=fileName.right(fileName.length()-s-2); 328 fileName=fileName.right(fileName.length()-s-2);
328 qDebug("pathname will be "+fileName); 329 qDebug("pathname will be "+fileName);
329 330
330 if( fileName.left(1).find('/') == -1) 331 if( fileName.left(1).find('/') == -1)
331 fileName="/"+fileName; 332 fileName="/"+fileName;
332 if( fileName.right(1).find('/') == -1) 333 if( fileName.right(1).find('/') == -1)
333 fileName+="/"; 334 fileName+="/";
334 fName = "vm_"+ dt.toString()+ ".wav"; 335 fName = "vm_"+ dt.toString()+ ".wav";
335 336
336 fileName+=fName; 337 fileName+=fName;
337 // No spaces in the filename 338 // No spaces in the filename
338 fileName.replace(QRegExp("'"),""); 339 fileName.replace(QRegExp("'"),"");
339 fileName.replace(QRegExp(" "),"_"); 340 fileName.replace(QRegExp(" "),"_");
340 fileName.replace(QRegExp(":"),"."); 341 fileName.replace(QRegExp(":"),".");
341 fileName.replace(QRegExp(","),""); 342 fileName.replace(QRegExp(","),"");
342 343
343 344
344 qDebug("filename is "+fileName); 345 qDebug("filename is "+fileName);
345// open tmp file here 346// open tmp file here
346 char *pointer; 347 char *pointer;
347 pointer=tmpnam(NULL); 348 pointer=tmpnam(NULL);
348 qDebug("Opening tmp file %s",pointer); 349 qDebug("Opening tmp file %s",pointer);
349 350
350 if(openWAV(pointer ) == -1) { 351 if(openWAV(pointer ) == -1) {
351 352
352// if(openWAV(fileName.latin1()) == -1) { 353// if(openWAV(fileName.latin1()) == -1) {
353 QString err("Could not open the temp file\n"); 354 QString err("Could not open the temp file\n");
354 err += fileName; 355 err += fileName;
355 QMessageBox::critical(0, "vmemo", err, "Abort"); 356 QMessageBox::critical(0, "vmemo", err, "Abort");
356 ::close(dsp); 357 ::close(dsp);
357 return FALSE; 358 return FALSE;
358 } 359 }
359 if( record() ) { 360 if( record() ) {
360 361
361 QString cmd; 362 QString cmd;
362 if( fileName.find(".wav",0,TRUE) == -1) 363 if( fileName.find(".wav",0,TRUE) == -1)
363 fileName += ".wav"; 364 fileName += ".wav";
364 365
365 cmd.sprintf("mv %s "+fileName, pointer); 366 cmd.sprintf("mv %s "+fileName, pointer);
366// move tmp file to regular file here 367// move tmp file to regular file here
367 368
368 system(cmd.latin1()); 369 system(cmd.latin1());
369 370
370 QArray<int> cats(1); 371 QArray<int> cats(1);
371 cats[0] = config.readNumEntry("Category", 0); 372 cats[0] = config.readNumEntry("Category", 0);
372 373
373 QString dlName("vm_"); 374 QString dlName("vm_");
374 dlName += dt.toString(); 375 dlName += dt.toString();
375 DocLnk l; 376 DocLnk l;
376 l.setFile(fileName); 377 l.setFile(fileName);
377 l.setName(dlName); 378 l.setName(dlName);
378 l.setType("audio/x-wav"); 379 l.setType("audio/x-wav");
379 l.setCategories(cats); 380 l.setCategories(cats);
380 l.writeLink(); 381 l.writeLink();
381 return TRUE; 382 return TRUE;
382 } else 383 } else
383 return FALSE; 384 return FALSE;
384 385
385} 386}
386 387
387void VMemo::stopRecording() { 388void VMemo::stopRecording() {
388 show(); 389 show();
389 qDebug("Stopped recording"); 390 qDebug("Stopped recording");
390 recording = FALSE; 391 recording = FALSE;
391 if(useAlerts) { 392 if(useAlerts) {
392 msgLabel->close(); 393 msgLabel->close();
393 msgLabel=0; 394 msgLabel=0;
394 delete msgLabel; 395 delete msgLabel;
395 } 396 }
396 t_timer->stop(); 397 t_timer->stop();
397 Config cfg("Vmemo"); 398 Config cfg("Vmemo");
398 cfg.setGroup("Defaults"); 399 cfg.setGroup("Defaults");
399 if( cfg.readNumEntry("hideIcon",0) == 1 ) 400 if( cfg.readNumEntry("hideIcon",0) == 1 )
400 hide(); 401 hide();
401} 402}
402 403
403int VMemo::openDSP() { 404int VMemo::openDSP() {
404 Config cfg("Vmemo"); 405 Config cfg("Vmemo");
405 cfg.setGroup("Record"); 406 cfg.setGroup("Record");
406 407
407 speed = cfg.readNumEntry("SampleRate", 22050); 408 speed = cfg.readNumEntry("SampleRate", 22050);
408 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 409 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
409 if (cfg.readNumEntry("SixteenBit", 1)==1) { 410 if (cfg.readNumEntry("SixteenBit", 1)==1) {
410 format = AFMT_S16_LE; 411 format = AFMT_S16_LE;
411 resolution = 16; 412 resolution = 16;
412 } else { 413 } else {
413 format = AFMT_U8; 414 format = AFMT_U8;
414 resolution = 8; 415 resolution = 8;
415 } 416 }
416 417
417 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 418 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
418 419
419 if(systemZaurus) { 420 if(systemZaurus) {
420 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 421 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
421 channels=1; //zaurus has one input channel 422 channels=1; //zaurus has one input channel
422 } else { 423 } else {
423 dsp = open("/dev/dsp", O_RDONLY); 424 dsp = open("/dev/dsp", O_RDONLY);
424 } 425 }
425 426
426 if(dsp == -1) { 427 if(dsp == -1) {
427 msgLabel->close(); 428 msgLabel->close();
428 msgLabel=0; 429 msgLabel=0;
429 delete msgLabel; 430 delete msgLabel;
430 431