summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-19 17:13:43 (UTC)
committer llornkcor <llornkcor>2002-05-19 17:13:43 (UTC)
commit396ca2a131b398b1562fee1cdc8cbe9bc629b37f (patch) (unidiff)
tree77a2bc6bb9a9887acb37ce887ef7bf9ed739002e
parent61a917bec9006516115d94be8c49acadf4eba222 (diff)
downloadopie-396ca2a131b398b1562fee1cdc8cbe9bc629b37f.zip
opie-396ca2a131b398b1562fee1cdc8cbe9bc629b37f.tar.gz
opie-396ca2a131b398b1562fee1cdc8cbe9bc629b37f.tar.bz2
can hide the icon by adding in VMemo.conf [Defaults] hideIcon = 1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 7e91ef0..c27050d 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -146,150 +146,149 @@ static char * vmemo_xpm[] = {
146"E c #ADADB6", 146"E c #ADADB6",
147"F c #54555A", 147"F c #54555A",
148"G c #8B8C94", 148"G c #8B8C94",
149"H c #5A5A5F", 149"H c #5A5A5F",
150"I c #BBBBC3", 150"I c #BBBBC3",
151"J c #C4C4CB", 151"J c #C4C4CB",
152"K c #909098", 152"K c #909098",
153"L c #737379", 153"L c #737379",
154"M c #343437", 154"M c #343437",
155"N c #8F8F98", 155"N c #8F8F98",
156"O c #000407", 156"O c #000407",
157"P c #2D3137", 157"P c #2D3137",
158"Q c #B0B1BC", 158"Q c #B0B1BC",
159"R c #3B3C40", 159"R c #3B3C40",
160"S c #6E6E74", 160"S c #6E6E74",
161"T c #95959C", 161"T c #95959C",
162"U c #74747A", 162"U c #74747A",
163"V c #1D1D1E", 163"V c #1D1D1E",
164"W c #91929A", 164"W c #91929A",
165"X c #42444A", 165"X c #42444A",
166"Y c #22282E", 166"Y c #22282E",
167"Z c #B0B2BC", 167"Z c #B0B2BC",
168"` c #898A90", 168"` c #898A90",
169" . c #65656A", 169" . c #65656A",
170".. c #999AA2", 170".. c #999AA2",
171"+. c #52535A", 171"+. c #52535A",
172"@. c #151B21", 172"@. c #151B21",
173"#. c #515257", 173"#. c #515257",
174"$. c #B5B5BE", 174"$. c #B5B5BE",
175"%. c #616167", 175"%. c #616167",
176"&. c #1A1D22", 176"&. c #1A1D22",
177"*. c #000713", 177"*. c #000713",
178"=. c #1F1F21", 178"=. c #1F1F21",
179" ", 179" ",
180" . + @ # ", 180" . + @ # ",
181" $ % & * = - ", 181" $ % & * = - ",
182" ; > , ' ) ! ~ ", 182" ; > , ' ) ! ~ ",
183" { ] ^ / ( _ : ", 183" { ] ^ / ( _ : ",
184" < [ } | 1 2 3 ", 184" < [ } | 1 2 3 ",
185" 4 5 6 7 8 9 0 a b c ", 185" 4 5 6 7 8 9 0 a b c ",
186" d e f g h i j 3 k l m n ", 186" d e f g h i j 3 k l m n ",
187" o p q r s t u v w n ", 187" o p q r s t u v w n ",
188" o x y z A B C D E n ", 188" o x y z A B C D E n ",
189" F G H I J K L M N O ", 189" F G H I J K L M N O ",
190" P Q R S T U V W X ", 190" P Q R S T U V W X ",
191" Y Z ` b ...+. ", 191" Y Z ` b ...+. ",
192" @.#.$.%.&. ", 192" @.#.$.%.&. ",
193" *.B =. ", 193" *.B =. ",
194" n n n n n n n n n "}; 194" n n n n n n n n n "};
195 195
196 196
197VMemo::VMemo( QWidget *parent, const char *_name ) 197VMemo::VMemo( QWidget *parent, const char *_name )
198 : QWidget( parent, _name ) 198 : QWidget( parent, _name )
199{ 199{
200 setFixedHeight( 18 ); 200 setFixedHeight( 18 );
201 setFixedWidth( 14 ); 201 setFixedWidth( 14 );
202 202
203 recording = FALSE; 203 recording = FALSE;
204 204
205 struct utsname name; /* check for embedix kernel running on the zaurus*/ 205 struct utsname name; /* check for embedix kernel running on the zaurus*/
206 if (uname(&name) != -1) { 206 if (uname(&name) != -1) {
207 QString release=name.release; 207 QString release=name.release;
208 Config vmCfg("VMemo"); 208 Config vmCfg("VMemo");
209 vmCfg.setGroup("Defaults"); 209 vmCfg.setGroup("Defaults");
210 int toggleKey = vmCfg.readNumEntry("toggleKey", -1);
210 211
211 if(release.find("embedix",0,TRUE) !=-1) { 212 if(release.find("embedix",0,TRUE) !=-1)
212 int toggleKey = vmCfg.readNumEntry("toggleKey", -1);
213 systemZaurus=TRUE; 213 systemZaurus=TRUE;
214 } else { 214 else
215 int toggleKey = vmCfg.readNumEntry("toggleKey", 4096);
216//default key for ipaq record button is Key_Escape = 4096
217 systemZaurus=FALSE; 215 systemZaurus=FALSE;
218 }
219 216
220 myChannel = new QCopChannel( "QPE/VMemo", this ); 217 myChannel = new QCopChannel( "QPE/VMemo", this );
221 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 218 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
222 this, SLOT(receive(const QCString&, const QByteArray&)) ); 219 this, SLOT(receive(const QCString&, const QByteArray&)) );
223 220
224 if( toggleKey != -1 ) { 221 if( toggleKey != -1 ) {
225 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 222 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
226// e << 4096; // Key_Escape 223// e << 4096; // Key_Escape
227// e << Key_F5; //4148 224// e << Key_F5; //4148
228 e << toggleKey; 225 e << toggleKey;
229 e << QString("QPE/VMemo"); 226 e << QString("QPE/VMemo");
230 e << QString("toggleRecord()"); 227 e << QString("toggleRecord()");
231 } 228 }
229 if( vmCfg.readNumEntry("hideIcon",0) == 1)
230 hide();
232 } 231 }
233} 232}
234 233
235VMemo::~VMemo() 234VMemo::~VMemo()
236{ 235{
237} 236}
238 237
239void VMemo::receive( const QCString &msg, const QByteArray &data ) 238void VMemo::receive( const QCString &msg, const QByteArray &data )
240{ 239{
241 QDataStream stream( data, IO_ReadOnly ); 240 QDataStream stream( data, IO_ReadOnly );
242 if (msg == "toggleRecord()") { 241 if (msg == "toggleRecord()") {
243 if (recording) { 242 if (recording) {
244 fromToggle = TRUE; 243 fromToggle = TRUE;
245 stopRecording(); 244 stopRecording();
246 } else { 245 } else {
247 fromToggle = TRUE; 246 fromToggle = TRUE;
248 startRecording(); 247 startRecording();
249 } 248 }
250 } 249 }
251} 250}
252 251
253void VMemo::paintEvent( QPaintEvent* ) 252void VMemo::paintEvent( QPaintEvent* )
254{ 253{
255 QPainter p(this); 254 QPainter p(this);
256 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 255 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
257} 256}
258 257
259void VMemo::mousePressEvent( QMouseEvent * ) 258void VMemo::mousePressEvent( QMouseEvent * )
260{ 259{
261 startRecording(); 260 startRecording();
262} 261}
263 262
264void VMemo::mouseReleaseEvent( QMouseEvent * ) 263void VMemo::mouseReleaseEvent( QMouseEvent * )
265{ 264{
266 stopRecording(); 265 stopRecording();
267} 266}
268 267
269bool VMemo::startRecording() { 268bool VMemo::startRecording() {
270 269
271 if ( recording) 270 if ( recording)
272 return FALSE;; 271 return FALSE;;
273 Config config( "Sound" ); 272 Config config( "Sound" );
274 config.setGroup( "System" ); 273 config.setGroup( "System" );
275 useAlerts = config.readBoolEntry("Alert"); 274 useAlerts = config.readBoolEntry("Alert");
276 275
277// if(useAlerts) 276// if(useAlerts)
278// QMessageBox::message("VMemo","Really Record?");//) ==1) 277// QMessageBox::message("VMemo","Really Record?");//) ==1)
279// return; 278// return;
280// } else { 279// } else {
281 if (!systemZaurus ) 280 if (!systemZaurus )
282 QSound::play(Resource::findSound("vmemob")); 281 QSound::play(Resource::findSound("vmemob"));
283// } 282// }
284 qDebug("Start recording"); 283 qDebug("Start recording");
285 recording = TRUE; 284 recording = TRUE;
286 if (openDSP() == -1) { 285 if (openDSP() == -1) {
287 QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); 286 QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort");
288 recording = FALSE; 287 recording = FALSE;
289 return FALSE; 288 return FALSE;
290 } 289 }
291 290
292 Config vmCfg("VMemo"); 291 Config vmCfg("VMemo");
293 vmCfg.setGroup("Defaults"); 292 vmCfg.setGroup("Defaults");
294 293
295 QDateTime dt = QDateTime::currentDateTime(); 294 QDateTime dt = QDateTime::currentDateTime();
@@ -316,144 +315,140 @@ bool VMemo::startRecording() {
316 fileName.replace(QRegExp(" "),"_"); 315 fileName.replace(QRegExp(" "),"_");
317 fileName.replace(QRegExp(":"),"."); 316 fileName.replace(QRegExp(":"),".");
318 fileName.replace(QRegExp(","),""); 317 fileName.replace(QRegExp(","),"");
319 318
320 if(openWAV(fileName.latin1()) == -1) { 319 if(openWAV(fileName.latin1()) == -1) {
321 QString err("Could not open the output file\n"); 320 QString err("Could not open the output file\n");
322 err += fileName; 321 err += fileName;
323 QMessageBox::critical(0, "VMemo", err, "Abort"); 322 QMessageBox::critical(0, "VMemo", err, "Abort");
324 close(dsp); 323 close(dsp);
325 return FALSE; 324 return FALSE;
326 } 325 }
327 326
328 QArray<int> cats(1); 327 QArray<int> cats(1);
329 cats[0] = vmCfg.readNumEntry("Category", 0); 328 cats[0] = vmCfg.readNumEntry("Category", 0);
330 329
331 QString dlName("vm_"); 330 QString dlName("vm_");
332 dlName += dt.toString(); 331 dlName += dt.toString();
333 DocLnk l; 332 DocLnk l;
334 l.setFile(fileName); 333 l.setFile(fileName);
335 l.setName(dlName); 334 l.setName(dlName);
336 l.setType("audio/x-wav"); 335 l.setType("audio/x-wav");
337 l.setCategories(cats); 336 l.setCategories(cats);
338 l.writeLink(); 337 l.writeLink();
339 338
340 record(); 339 record();
341 return TRUE; 340 return TRUE;
342} 341}
343 342
344void VMemo::stopRecording() { 343void VMemo::stopRecording() {
345 recording = FALSE; 344 recording = FALSE;
346} 345}
347 346
348int VMemo::openDSP() 347int VMemo::openDSP()
349{ 348{
350 Config cfg("Sound"); 349 Config cfg("Sound");
351 cfg.setGroup("Record"); 350 cfg.setGroup("Record");
352 351
353 speed = cfg.readNumEntry("SampleRate", 22050); 352 speed = cfg.readNumEntry("SampleRate", 22050);
354 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 353 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
355 if (cfg.readNumEntry("SixteenBit", 1)==1) { 354 if (cfg.readNumEntry("SixteenBit", 1)==1) {
356 format = AFMT_S16_LE; 355 format = AFMT_S16_LE;
357 resolution = 16; 356 resolution = 16;
358 } else { 357 } else {
359 format = AFMT_U8; 358 format = AFMT_U8;
360 resolution = 8; 359 resolution = 8;
361 } 360 }
362 361
363 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 362 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
364 363
365 if(systemZaurus) { 364 if(systemZaurus) {
366 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 365 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
367 channels=1; //zaurus has one input channel 366 channels=1; //zaurus has one input channel
368 } else { 367 } else {
369 dsp = open("/dev/dsp", O_RDWR); 368 dsp = open("/dev/dsp", O_RDWR);
370 } 369 }
371 370
372 if(dsp == -1) { 371 if(dsp == -1) {
373 perror("open(\"/dev/dsp\")"); 372 perror("open(\"/dev/dsp\")");
374 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 373 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
375 return -1; 374 return -1;
376 } 375 }
377 376
378 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 377 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
379 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 378 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
380 errorMsg="ioctl(\"SNDCTL_DSP_SETFMT\")\n%d\n"+(QString)strerror(errno),format;
381 return -1; 379 return -1;
382 } 380 }
383 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 381 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
384 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 382 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
385 errorMsg="ioctl(\"SNDCTL_DSP_CHANNELS\")\n%d\n"+(QString)strerror(errno),channels;
386 return -1; 383 return -1;
387 } 384 }
388 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 385 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
389 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 386 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
390 errorMsg="ioctl(\"SNDCTL_DSP_SPEED\")\n%d\n"+(QString)strerror(errno),speed;
391 return -1; 387 return -1;
392 } 388 }
393 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 389 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
394 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 390 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
395 errorMsg="ioctl(\"SOUND_PCM_READ_RATE\")\n%d\n"+(QString)strerror(errno),rate;
396 return -1; 391 return -1;
397 } 392 }
398 393
399 return 1; 394 return 1;
400} 395}
401 396
402int VMemo::openWAV(const char *filename) 397int VMemo::openWAV(const char *filename)
403{ 398{
404 track.setName(filename); 399 track.setName(filename);
405 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 400 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
406 errorMsg=filename; 401 errorMsg=filename;
407 return -1; 402 return -1;
408 } 403 }
409 404
410 wav=track.handle(); 405 wav=track.handle();
411 406
412 WaveHeader wh; 407 WaveHeader wh;
413 408
414 wh.main_chunk = RIFF; 409 wh.main_chunk = RIFF;
415 wh.length=0; 410 wh.length=0;
416 wh.chunk_type = WAVE; 411 wh.chunk_type = WAVE;
417 wh.sub_chunk = FMT; 412 wh.sub_chunk = FMT;
418 wh.sc_len = 16; 413 wh.sc_len = 16;
419 wh.format = PCM_CODE; 414 wh.format = PCM_CODE;
420 wh.modus = channels; 415 wh.modus = channels;
421 wh.sample_fq = speed; 416 wh.sample_fq = speed;
422 wh.byte_p_sec = speed * channels * resolution/8; 417 wh.byte_p_sec = speed * channels * resolution/8;
423 wh.byte_p_spl = channels * (resolution / 8); 418 wh.byte_p_spl = channels * (resolution / 8);
424 wh.bit_p_spl = resolution; 419 wh.bit_p_spl = resolution;
425 wh.data_chunk = DATA; 420 wh.data_chunk = DATA;
426 wh.data_length= 0; 421 wh.data_length= 0;
427 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 422 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
428 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 423 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
429 write (wav, &wh, sizeof(WaveHeader)); 424 write (wav, &wh, sizeof(WaveHeader));
430 425
431 return 1; 426 return 1;
432} 427}
433 428
434void VMemo::record(void) 429void VMemo::record(void)
435{ 430{
436 int length=0, result, value; 431 int length=0, result, value;
437 qDebug("Recording"); 432 qDebug("Recording");
438 433
439 if(systemZaurus) { 434 if(systemZaurus) {
440 signed short sound[512], monoBuffer[512]; 435 signed short sound[512], monoBuffer[512];
441 if(format==AFMT_S16_LE) { 436 if(format==AFMT_S16_LE) {
442 while(recording) { 437 while(recording) {
443 result = read(dsp, sound, 512); // 8192 438 result = read(dsp, sound, 512); // 8192
444 int j=0; 439 int j=0;
445 if(systemZaurus) { 440 if(systemZaurus) {
446 for (int i = 0; i < result; i++) { //since Z is mono do normally 441 for (int i = 0; i < result; i++) { //since Z is mono do normally
447 monoBuffer[i] = sound[i]; 442 monoBuffer[i] = sound[i];
448 } 443 }
449 length+=write(wav, monoBuffer, result); 444 length+=write(wav, monoBuffer, result);
450 } else { //ipaq /stereo inputs 445 } else { //ipaq /stereo inputs
451 for (int i = 0; i < result; i+=2) { 446 for (int i = 0; i < result; i+=2) {
452 monoBuffer[j] = (sound[i]+sound[i+1])/2; 447 monoBuffer[j] = (sound[i]+sound[i+1])/2;
453 j++; 448 j++;
454 } 449 }
455 length+=write(wav, monoBuffer, result/2); 450 length+=write(wav, monoBuffer, result/2);
456 } 451 }
457// printf("%d\r",length); 452// printf("%d\r",length);
458// fflush(stdout); 453// fflush(stdout);
459 } 454 }