summaryrefslogtreecommitdiff
authorar <ar>2004-05-02 14:59:14 (UTC)
committer ar <ar>2004-05-02 14:59:14 (UTC)
commit4e7ab937501b6495ce5635a7515e66a75e04d37e (patch) (unidiff)
tree6cecc2081d0a15a101b7fca0a7a61c6c992d73bc
parentbb9c5e1bbf2692dc9b669e5f573edcdd92615476 (diff)
downloadopie-4e7ab937501b6495ce5635a7515e66a75e04d37e.zip
opie-4e7ab937501b6495ce5635a7515e66a75e04d37e.tar.gz
opie-4e7ab937501b6495ce5635a7515e66a75e04d37e.tar.bz2
- convert qDebug to odebug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp6
-rw-r--r--core/applets/vmemo/vmemo.cpp221
2 files changed, 112 insertions, 115 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 3a6ad27..3af3d03 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -1,420 +1,418 @@
1/* 1/*
2* cardmon.cpp 2* cardmon.cpp
3* 3*
4* --------------------- 4* ---------------------
5* 5*
6* copyright : (c) 2002 by Maximilian Reiss 6* copyright : (c) 2002 by Maximilian Reiss
7* email : max.reiss@gmx.de 7* email : max.reiss@gmx.de
8* based on two apps by Devin Butterfield 8* based on two apps by Devin Butterfield
9*/ 9*/
10/*************************************************************************** 10/***************************************************************************
11 * * 11 * *
12 * This program is free software; you can redistribute it and/or modify * 12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by * 13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or * 14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. * 15 * (at your option) any later version. *
16 * * 16 * *
17 ***************************************************************************/ 17 ***************************************************************************/
18 18
19#include "cardmon.h" 19#include "cardmon.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/odebug.h> 22#include <opie2/odebug.h>
23#include <opie2/odevice.h> 23#include <opie2/odevice.h>
24#include <opie2/otaskbarapplet.h> 24#include <opie2/otaskbarapplet.h>
25#include <qpe/applnk.h> 25#include <qpe/applnk.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27using namespace Opie::Core; 27using namespace Opie::Core;
28using namespace Opie::Ui; 28using namespace Opie::Ui;
29 29
30/* QT */ 30/* QT */
31#include <qcopchannel_qws.h> 31#include <qcopchannel_qws.h>
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35#include <qsound.h> 35#include <qsound.h>
36#include <qtimer.h> 36#include <qtimer.h>
37 37
38/* STD */ 38/* STD */
39#include <stdio.h> 39#include <stdio.h>
40#include <unistd.h> 40#include <unistd.h>
41#include <stdlib.h> 41#include <stdlib.h>
42#include <string.h> 42#include <string.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 44#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
45#include <sys/vfs.h> 45#include <sys/vfs.h>
46#include <mntent.h> 46#include <mntent.h>
47#endif 47#endif
48 48
49CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), 49CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ),
50 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) 50 pm( Resource::loadPixmap( "cardmon/pcmcia" ) )
51{ 51{
52 52
53 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); 53 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this );
54 connect( pcmciaChannel, 54 connect( pcmciaChannel,
55 SIGNAL( received(const QCString&,const QByteArray&) ), this, 55 SIGNAL( received(const QCString&,const QByteArray&) ), this,
56 SLOT( cardMessage(const QCString&,const QByteArray&) ) ); 56 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
57 57
58 QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); 58 QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this );
59 connect( sdChannel, 59 connect( sdChannel,
60 SIGNAL( received(const QCString&,const QByteArray&) ), this, 60 SIGNAL( received(const QCString&,const QByteArray&) ), this,
61 SLOT( cardMessage(const QCString&,const QByteArray&) ) ); 61 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
62 62
63 cardInPcmcia0 = FALSE; 63 cardInPcmcia0 = FALSE;
64 cardInPcmcia1 = FALSE; 64 cardInPcmcia1 = FALSE;
65 cardInSd = FALSE; 65 cardInSd = FALSE;
66 66
67 setFocusPolicy( NoFocus ); 67 setFocusPolicy( NoFocus );
68 68
69 setFixedWidth ( AppLnk::smallIconSize() ); 69 setFixedWidth ( AppLnk::smallIconSize() );
70 setFixedHeight ( AppLnk::smallIconSize() ); 70 setFixedHeight ( AppLnk::smallIconSize() );
71 71
72 getStatusPcmcia( TRUE ); 72 getStatusPcmcia( TRUE );
73 getStatusSd( TRUE ); 73 getStatusSd( TRUE );
74 repaint( FALSE ); 74 repaint( FALSE );
75 popupMenu = 0; 75 popupMenu = 0;
76} 76}
77 77
78CardMonitor::~CardMonitor() 78CardMonitor::~CardMonitor()
79{ 79{
80 if ( popupMenu ) 80 if ( popupMenu )
81 { 81 {
82 delete popupMenu; 82 delete popupMenu;
83 } 83 }
84} 84}
85 85
86void CardMonitor::popUp( QString message, QString icon ) 86void CardMonitor::popUp( QString message, QString icon )
87{ 87{
88 if ( !popupMenu ) 88 if ( !popupMenu )
89 { 89 {
90 popupMenu = new QPopupMenu( this ); 90 popupMenu = new QPopupMenu( this );
91 } 91 }
92 92
93 popupMenu->clear(); 93 popupMenu->clear();
94 if ( icon.isEmpty() ) 94 if ( icon.isEmpty() )
95 { 95 {
96 popupMenu->insertItem( message, 0 ); 96 popupMenu->insertItem( message, 0 );
97 } 97 }
98 else 98 else
99 { 99 {
100 popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), 100 popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ),
101 message, 0 ); 101 message, 0 );
102 } 102 }
103 103
104 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 104 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
105 QSize s = popupMenu->sizeHint(); 105 QSize s = popupMenu->sizeHint();
106 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 106 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
107 p.y() - s.height() ), 0 ); 107 p.y() - s.height() ), 0 );
108 108
109 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 109 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
110} 110}
111 111
112void CardMonitor::popupTimeout() 112void CardMonitor::popupTimeout()
113{ 113{
114 popupMenu->hide(); 114 popupMenu->hide();
115} 115}
116 116
117void CardMonitor::mousePressEvent( QMouseEvent * ) 117void CardMonitor::mousePressEvent( QMouseEvent * )
118{ 118{
119 QPopupMenu * menu = new QPopupMenu( this ); 119 QPopupMenu * menu = new QPopupMenu( this );
120 QString cmd; 120 QString cmd;
121 int err = 0; 121 int err = 0;
122 122
123 if ( cardInSd ) 123 if ( cardInSd )
124 { 124 {
125 menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), 125 menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ),
126 tr( "Eject SD/MMC card" ), 0 ); 126 tr( "Eject SD/MMC card" ), 0 );
127 } 127 }
128 128
129 if ( cardInPcmcia0 ) 129 if ( cardInPcmcia0 )
130 { 130 {
131 menu-> 131 menu->
132 insertItem( QIconSet 132 insertItem( QIconSet
133 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), 133 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ),
134 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); 134 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 );
135 } 135 }
136 136
137 if ( cardInPcmcia1 ) 137 if ( cardInPcmcia1 )
138 { 138 {
139 menu-> 139 menu->
140 insertItem( QIconSet 140 insertItem( QIconSet
141 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), 141 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ),
142 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); 142 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
143 } 143 }
144 144
145 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 145 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
146 QSize s = menu->sizeHint(); 146 QSize s = menu->sizeHint();
147 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 147 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
148 p.y() - s.height() ), 0 ); 148 p.y() - s.height() ), 0 );
149 149
150 if ( opt == 1 ) 150 if ( opt == 1 )
151 { 151 {
152 cmd = "/sbin/cardctl eject 0"; 152 cmd = "/sbin/cardctl eject 0";
153 err = system( ( const char * ) cmd ); 153 err = system( ( const char * ) cmd );
154 if ( err != 0 ) 154 if ( err != 0 )
155 { 155 {
156 qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", 156 odebug << "Could not execute `/sbin/cardctl eject 0'! err=" << err << oendl;
157 err );
158 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 157 popUp( tr( "CF/PCMCIA card eject failed!" ) );
159 } 158 }
160 } 159 }
161 else if ( opt == 0 ) 160 else if ( opt == 0 )
162 { 161 {
163 if ( ODevice::inst() ->system() == System_Familiar ) 162 if ( ODevice::inst() ->system() == System_Familiar )
164 { 163 {
165 cmd = "umount /dev/mmc/part1"; 164 cmd = "umount /dev/mmc/part1";
166 } 165 }
167 else 166 else
168 { 167 {
169 cmd = "umount /dev/mmcda1"; 168 cmd = "umount /dev/mmcda1";
170 } 169 }
171 err = system( ( const char * ) cmd ); 170 err = system( ( const char * ) cmd );
172 if ( err != 0 ) 171 if ( err != 0 )
173 { 172 {
174 popUp( tr( "SD/MMC card eject failed!" ) ); 173 popUp( tr( "SD/MMC card eject failed!" ) );
175 } 174 }
176 } 175 }
177 else if ( opt == 2 ) 176 else if ( opt == 2 )
178 { 177 {
179 cmd = "/sbin/cardctl eject 1"; 178 cmd = "/sbin/cardctl eject 1";
180 err = system( ( const char * ) cmd ); 179 err = system( ( const char * ) cmd );
181 if ( err != 0 ) 180 if ( err != 0 )
182 { 181 {
183 qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", 182 odebug << "Could not execute `/sbin/cardctl eject 1'! err=" << err << oendl;
184 err );
185 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 183 popUp( tr( "CF/PCMCIA card eject failed!" ) );
186 } 184 }
187 } 185 }
188 delete menu; 186 delete menu;
189} 187}
190 188
191 189
192void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) 190void CardMonitor::cardMessage( const QCString & msg, const QByteArray & )
193{ 191{
194 if ( msg == "stabChanged()" ) 192 if ( msg == "stabChanged()" )
195 { 193 {
196 // odebug << "Pcmcia: stabchanged" << oendl; 194 // odebug << "Pcmcia: stabchanged" << oendl;
197 getStatusPcmcia(); 195 getStatusPcmcia();
198 } 196 }
199 else if ( msg == "mtabChanged()" ) 197 else if ( msg == "mtabChanged()" )
200 { 198 {
201 // odebug << "CARDMONAPPLET: mtabchanged" << oendl; 199 // odebug << "CARDMONAPPLET: mtabchanged" << oendl;
202 getStatusSd(); 200 getStatusSd();
203 } 201 }
204} 202}
205 203
206bool CardMonitor::getStatusPcmcia( int showPopUp ) 204bool CardMonitor::getStatusPcmcia( int showPopUp )
207{ 205{
208 206
209 bool cardWas0 = cardInPcmcia0; // remember last state 207 bool cardWas0 = cardInPcmcia0; // remember last state
210 bool cardWas1 = cardInPcmcia1; 208 bool cardWas1 = cardInPcmcia1;
211 209
212 QString fileName; 210 QString fileName;
213 211
214 // one of these 3 files should exist 212 // one of these 3 files should exist
215 if ( QFile::exists( "/var/run/stab" ) ) 213 if ( QFile::exists( "/var/run/stab" ) )
216 { 214 {
217 fileName = "/var/run/stab"; 215 fileName = "/var/run/stab";
218 } 216 }
219 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) 217 else if ( QFile::exists( "/var/state/pcmcia/stab" ) )
220 { 218 {
221 fileName = "/var/state/pcmcia/stab"; 219 fileName = "/var/state/pcmcia/stab";
222 } 220 }
223 else 221 else
224 { 222 {
225 fileName = "/var/lib/pcmcia/stab"; 223 fileName = "/var/lib/pcmcia/stab";
226 } 224 }
227 225
228 QFile f( fileName ); 226 QFile f( fileName );
229 227
230 if ( f.open( IO_ReadOnly ) ) 228 if ( f.open( IO_ReadOnly ) )
231 { 229 {
232 QStringList list; 230 QStringList list;
233 QTextStream stream( &f ); 231 QTextStream stream( &f );
234 QString streamIn; 232 QString streamIn;
235 streamIn = stream.read(); 233 streamIn = stream.read();
236 list = QStringList::split( "\n", streamIn ); 234 list = QStringList::split( "\n", streamIn );
237 for ( QStringList::Iterator line = list.begin(); line != list.end(); 235 for ( QStringList::Iterator line = list.begin(); line != list.end();
238 line++ ) 236 line++ )
239 { 237 {
240 if ( ( *line ).startsWith( "Socket 0:" ) ) 238 if ( ( *line ).startsWith( "Socket 0:" ) )
241 { 239 {
242 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) 240 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 )
243 { 241 {
244 cardInPcmcia0 = FALSE; 242 cardInPcmcia0 = FALSE;
245 } 243 }
246 else if ( !( *line ).startsWith( "Socket 0: empty" ) 244 else if ( !( *line ).startsWith( "Socket 0: empty" )
247 && !cardInPcmcia0 ) 245 && !cardInPcmcia0 )
248 { 246 {
249 cardInPcmcia0Name = 247 cardInPcmcia0Name =
250 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), 248 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
251 ( *line ).length() - 9 ); 249 ( *line ).length() - 9 );
252 cardInPcmcia0Name.stripWhiteSpace(); 250 cardInPcmcia0Name.stripWhiteSpace();
253 cardInPcmcia0 = TRUE; 251 cardInPcmcia0 = TRUE;
254 show(); 252 show();
255 line++; 253 line++;
256 int pos = ( *line ).find( '\t' ) + 1; 254 int pos = ( *line ).find( '\t' ) + 1;
257 cardInPcmcia0Type = 255 cardInPcmcia0Type =
258 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); 256 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
259 } 257 }
260 } 258 }
261 else if ( ( *line ).startsWith( "Socket 1:" ) ) 259 else if ( ( *line ).startsWith( "Socket 1:" ) )
262 { 260 {
263 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) 261 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 )
264 { 262 {
265 cardInPcmcia1 = FALSE; 263 cardInPcmcia1 = FALSE;
266 } 264 }
267 else if ( !( *line ).startsWith( "Socket 1: empty" ) 265 else if ( !( *line ).startsWith( "Socket 1: empty" )
268 && !cardInPcmcia1 ) 266 && !cardInPcmcia1 )
269 { 267 {
270 cardInPcmcia1Name = 268 cardInPcmcia1Name =
271 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), 269 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
272 ( *line ).length() - 9 ); 270 ( *line ).length() - 9 );
273 cardInPcmcia1Name.stripWhiteSpace(); 271 cardInPcmcia1Name.stripWhiteSpace();
274 cardInPcmcia1 = TRUE; 272 cardInPcmcia1 = TRUE;
275 show(); 273 show();
276 line++; 274 line++;
277 int pos = ( *line ).find( '\t' ) + 1; 275 int pos = ( *line ).find( '\t' ) + 1;
278 cardInPcmcia1Type = 276 cardInPcmcia1Type =
279 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); 277 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
280 } 278 }
281 } 279 }
282 } 280 }
283 f.close(); 281 f.close();
284 282
285 if ( !showPopUp 283 if ( !showPopUp
286 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) 284 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) )
287 { 285 {
288 QString text = QString::null; 286 QString text = QString::null;
289 QString what = QString::null; 287 QString what = QString::null;
290 if ( cardWas0 != cardInPcmcia0 ) 288 if ( cardWas0 != cardInPcmcia0 )
291 { 289 {
292 if ( cardInPcmcia0 ) 290 if ( cardInPcmcia0 )
293 { 291 {
294 text += tr( "New card: " ); 292 text += tr( "New card: " );
295 what = "on"; 293 what = "on";
296 } 294 }
297 else 295 else
298 { 296 {
299 text += tr( "Ejected: " ); 297 text += tr( "Ejected: " );
300 what = "off"; 298 what = "off";
301 } 299 }
302 text += cardInPcmcia0Name; 300 text += cardInPcmcia0Name;
303 popUp( text, "cardmon/" + cardInPcmcia0Type ); 301 popUp( text, "cardmon/" + cardInPcmcia0Type );
304 } 302 }
305 303
306 if ( cardWas1 != cardInPcmcia1 ) 304 if ( cardWas1 != cardInPcmcia1 )
307 { 305 {
308 if ( cardInPcmcia1 ) 306 if ( cardInPcmcia1 )
309 { 307 {
310 text += tr( "New card: " ); 308 text += tr( "New card: " );
311 what = "on"; 309 what = "on";
312 } 310 }
313 else 311 else
314 { 312 {
315 text += tr( "Ejected: " ); 313 text += tr( "Ejected: " );
316 what = "off"; 314 what = "off";
317 } 315 }
318 text += cardInPcmcia1Name; 316 text += cardInPcmcia1Name;
319 popUp( text, "cardmon/" + cardInPcmcia1Type ); 317 popUp( text, "cardmon/" + cardInPcmcia1Type );
320 } 318 }
321#ifndef QT_NO_SOUND 319#ifndef QT_NO_SOUND
322 QSound::play( Resource::findSound( "cardmon/card" + what ) ); 320 QSound::play( Resource::findSound( "cardmon/card" + what ) );
323#endif 321#endif
324 322
325 } 323 }
326 } 324 }
327 else 325 else
328 { 326 {
329 // no file found 327 // no file found
330 odebug << "no file found" << oendl; 328 odebug << "no file found" << oendl;
331 cardInPcmcia0 = FALSE; 329 cardInPcmcia0 = FALSE;
332 cardInPcmcia1 = FALSE; 330 cardInPcmcia1 = FALSE;
333 } 331 }
334 repaint( FALSE ); 332 repaint( FALSE );
335 return ( ( cardWas0 == cardInPcmcia0 333 return ( ( cardWas0 == cardInPcmcia0
336 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); 334 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
337 335
338} 336}
339 337
340 338
341bool CardMonitor::getStatusSd( int showPopUp ) 339bool CardMonitor::getStatusSd( int showPopUp )
342{ 340{
343 341
344 bool cardWas = cardInSd; // remember last state 342 bool cardWas = cardInSd; // remember last state
345 cardInSd = FALSE; 343 cardInSd = FALSE;
346 344
347#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 345#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
348 struct mntent *me; 346 struct mntent *me;
349 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 347 FILE *mntfp = setmntent( "/etc/mtab", "r" );
350 348
351 if ( mntfp ) 349 if ( mntfp )
352 { 350 {
353 while ( ( me = getmntent( mntfp ) ) != 0 ) 351 while ( ( me = getmntent( mntfp ) ) != 0 )
354 { 352 {
355 QString fs = me->mnt_fsname; 353 QString fs = me->mnt_fsname;
356 //odebug << fs << oendl; 354 //odebug << fs << oendl;
357 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" 355 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd"
358 || fs.left( 9 ) == "/dev/mmcd" ) 356 || fs.left( 9 ) == "/dev/mmcd" )
359 { 357 {
360 cardInSd = TRUE; 358 cardInSd = TRUE;
361 show(); 359 show();
362 } 360 }
363 // else { 361 // else {
364 // cardInSd = FALSE; 362 // cardInSd = FALSE;
365 // } 363 // }
366 } 364 }
367 endmntent( mntfp ); 365 endmntent( mntfp );
368 } 366 }
369 367
370 if ( !showPopUp && cardWas != cardInSd ) 368 if ( !showPopUp && cardWas != cardInSd )
371 { 369 {
372 QString text = QString::null; 370 QString text = QString::null;
373 QString what = QString::null; 371 QString what = QString::null;
374 if ( cardInSd ) 372 if ( cardInSd )
375 { 373 {
376 text += "New card: SD/MMC"; 374 text += "New card: SD/MMC";
377 what = "on"; 375 what = "on";
378 } 376 }
379 else 377 else
380 { 378 {
381 text += "Ejected: SD/MMC"; 379 text += "Ejected: SD/MMC";
382 what = "off"; 380 what = "off";
383 } 381 }
384 //odebug << "TEXT: " + text << oendl; 382 //odebug << "TEXT: " + text << oendl;
385#ifndef QT_NO_SOUND 383#ifndef QT_NO_SOUND
386 QSound::play( Resource::findSound( "cardmon/card" + what ) ); 384 QSound::play( Resource::findSound( "cardmon/card" + what ) );
387#endif 385#endif
388 popUp( text, "cardmon/ide" ); // XX add SD pic 386 popUp( text, "cardmon/ide" ); // XX add SD pic
389 } 387 }
390#else 388#else
391#error "Not on Linux" 389#error "Not on Linux"
392#endif 390#endif
393 repaint( FALSE ); 391 repaint( FALSE );
394 return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); 392 return ( ( cardWas == cardInSd ) ? FALSE : TRUE );
395} 393}
396 394
397void CardMonitor::paintEvent( QPaintEvent * ) 395void CardMonitor::paintEvent( QPaintEvent * )
398{ 396{
399 397
400 QPainter p( this ); 398 QPainter p( this );
401 399
402 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) 400 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd )
403 { 401 {
404 p.drawPixmap( 0, 0, pm ); 402 p.drawPixmap( 0, 0, pm );
405 show(); 403 show();
406 } 404 }
407 else 405 else
408 { 406 {
409 //p.eraseRect(rect()); 407 //p.eraseRect(rect());
410 hide(); 408 hide();
411 } 409 }
412} 410}
413 411
414int CardMonitor::position() 412int CardMonitor::position()
415{ 413{
416 return 7; 414 return 7;
417} 415}
418 416
419EXPORT_OPIE_APPLET_v1( CardMonitor ) 417EXPORT_OPIE_APPLET_v1( CardMonitor )
420 418
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 835f63a..f088bef 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,656 +1,655 @@
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>
17using namespace Opie::Core; 17using namespace Opie::Core;
18 18
19extern "C" { 19extern "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
31typedef struct _waveheader { 31typedef 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
59struct adpcm_state encoder_state; 59struct 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
75int seq = 0; 75int seq = 0;
76 76
77/* XPM */ 77/* XPM */
78static char * vmemo_xpm[] = { 78static 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
200using namespace Opie::Ui; 200using namespace Opie::Ui;
201VMemo::VMemo( QWidget *parent, const char *_name ) 201VMemo::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 odebug << "toggleKey " << toggleKey << "" << oendl; 214 odebug << "toggleKey " << toggleKey << "" << oendl;
215 215
216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
217// systemZaurus=TRUE; 217// systemZaurus=TRUE;
218// else 218// else
219 systemZaurus = FALSE; 219 systemZaurus = FALSE;
220 220
221 myChannel = new QCopChannel( "QPE/VMemo", this ); 221 myChannel = new QCopChannel( "QPE/VMemo", this );
222 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), 222 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)),
223 this, SLOT(receive(const QCString&,const QByteArray&)) ); 223 this, SLOT(receive(const QCString&,const QByteArray&)) );
224 224
225 if( toggleKey != -1 ) { 225 if( toggleKey != -1 ) {
226 qDebug("Register key %d", toggleKey); 226 odebug << "Register key " << toggleKey << "" << oendl;
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 << QString("QPE/VMemo"); 231 e << QString("QPE/VMemo");
232 e << QString("toggleRecord()"); 232 e << QString("toggleRecord()");
233 } 233 }
234 if(toggleKey == 1) 234 if(toggleKey == 1)
235 usingIcon = TRUE; 235 usingIcon = TRUE;
236 else 236 else
237 usingIcon = FALSE; 237 usingIcon = FALSE;
238// if( vmCfg.readNumEntry("hideIcon",0) == 1) 238// if( vmCfg.readNumEntry("hideIcon",0) == 1)
239// hide(); 239// hide();
240 recording = FALSE; 240 recording = FALSE;
241 // } 241 // }
242} 242}
243 243
244VMemo::~VMemo() { 244VMemo::~VMemo() {
245} 245}
246 246
247int VMemo::position() 247int VMemo::position()
248{ 248{
249 return 6; 249 return 6;
250} 250}
251 251
252void VMemo::receive( const QCString &msg, const QByteArray &data ) { 252void VMemo::receive( const QCString &msg, const QByteArray &data ) {
253 odebug << "Vmemo receive" << oendl; 253 odebug << "Vmemo receive" << oendl;
254 QDataStream stream( data, IO_ReadOnly ); 254 QDataStream stream( data, IO_ReadOnly );
255 255
256 if (msg == "toggleRecord()") { 256 if (msg == "toggleRecord()") {
257 if (recording) { 257 if (recording) {
258 fromToggle = TRUE; 258 fromToggle = TRUE;
259 stopRecording(); 259 stopRecording();
260 } else { 260 } else {
261 fromToggle = TRUE; 261 fromToggle = TRUE;
262 startRecording(); 262 startRecording();
263 } 263 }
264 } 264 }
265} 265}
266 266
267void VMemo::paintEvent( QPaintEvent* ) { 267void VMemo::paintEvent( QPaintEvent* ) {
268 QPainter p(this); 268 QPainter p(this);
269 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 269 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
270} 270}
271 271
272void VMemo::mousePressEvent( QMouseEvent * /*me*/) { 272void VMemo::mousePressEvent( QMouseEvent * /*me*/) {
273 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 273 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
274 mousePressEvent and mouseReleaseEvent with a NULL parameter. */ 274 mousePressEvent and mouseReleaseEvent with a NULL parameter. */
275 275
276// if (!systemZaurus && me != NULL) 276// if (!systemZaurus && me != NULL)
277// return; 277// return;
278// } 278// }
279 279
280 if(!recording) 280 if(!recording)
281 startRecording(); 281 startRecording();
282 else 282 else
283 stopRecording(); 283 stopRecording();
284} 284}
285 285
286void VMemo::mouseReleaseEvent( QMouseEvent * ) { 286void VMemo::mouseReleaseEvent( QMouseEvent * ) {
287} 287}
288 288
289bool VMemo::startRecording() { 289bool VMemo::startRecording() {
290 Config config( "Vmemo" ); 290 Config config( "Vmemo" );
291 config.setGroup( "System" ); 291 config.setGroup( "System" );
292 292
293 useAlerts = config.readBoolEntry("Alert",1); 293 useAlerts = config.readBoolEntry("Alert",1);
294 if(useAlerts) { 294 if(useAlerts) {
295 295
296 msgLabel = new QLabel( 0, "alertLabel" ); 296 msgLabel = new QLabel( 0, "alertLabel" );
297 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); 297 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
298 msgLabel->show(); 298 msgLabel->show();
299 } 299 }
300 300
301 odebug << "Start recording engines" << oendl; 301 odebug << "Start recording engines" << oendl;
302 recording = TRUE; 302 recording = TRUE;
303 303
304 if (openDSP() == -1) { 304 if (openDSP() == -1) {
305 recording = FALSE; 305 recording = FALSE;
306 return FALSE; 306 return FALSE;
307 } 307 }
308 308
309 config.setGroup("Defaults"); 309 config.setGroup("Defaults");
310 310
311 date = TimeString::dateString( QDateTime::currentDateTime(),false,true); 311 date = TimeString::dateString( QDateTime::currentDateTime(),false,true);
312 date.replace(QRegExp("'"),""); 312 date.replace(QRegExp("'"),"");
313 date.replace(QRegExp(" "),"_"); 313 date.replace(QRegExp(" "),"_");
314 date.replace(QRegExp(":"),"."); 314 date.replace(QRegExp(":"),".");
315 date.replace(QRegExp(","),""); 315 date.replace(QRegExp(","),"");
316 316
317 QString fName; 317 QString fName;
318 config.setGroup( "System" ); 318 config.setGroup( "System" );
319 fName = QPEApplication::documentDir() ; 319 fName = QPEApplication::documentDir() ;
320 fileName = config.readEntry("RecLocation", fName); 320 fileName = config.readEntry("RecLocation", fName);
321 321
322 int s; 322 int s;
323 s=fileName.find(':'); 323 s=fileName.find(':');
324 if(s) 324 if(s)
325 fileName=fileName.right(fileName.length()-s-2); 325 fileName=fileName.right(fileName.length()-s-2);
326 odebug << "pathname will be "+fileName << oendl; 326 odebug << "pathname will be "+fileName << oendl;
327 327
328 if( fileName.left(1).find('/') == -1) 328 if( fileName.left(1).find('/') == -1)
329 fileName="/"+fileName; 329 fileName="/"+fileName;
330 if( fileName.right(1).find('/') == -1) 330 if( fileName.right(1).find('/') == -1)
331 fileName+="/"; 331 fileName+="/";
332 fName = "vm_"+ date + ".wav"; 332 fName = "vm_"+ date + ".wav";
333 333
334 fileName+=fName; 334 fileName+=fName;
335 odebug << "filename is " + fileName << oendl; 335 odebug << "filename is " + fileName << oendl;
336// open tmp file here 336// open tmp file here
337 char *pointer; 337 char *pointer;
338 pointer=tmpnam(NULL); 338 pointer=tmpnam(NULL);
339 odebug << "Opening tmp file " << pointer << "" << oendl; 339 odebug << "Opening tmp file " << pointer << "" << oendl;
340 340
341 if(openWAV(pointer ) == -1) { 341 if(openWAV(pointer ) == -1) {
342 342
343 QString err("Could not open the temp file\n"); 343 QString err("Could not open the temp file\n");
344 err += fileName; 344 err += fileName;
345 QMessageBox::critical(0, "vmemo", err, "Abort"); 345 QMessageBox::critical(0, "vmemo", err, "Abort");
346 ::close(dsp); 346 ::close(dsp);
347 return FALSE; 347 return FALSE;
348 } 348 }
349 if( record() ) { 349 if( record() ) {
350 350
351 QString cmd; 351 QString cmd;
352 if( fileName.find(".wav",0,TRUE) == -1) 352 if( fileName.find(".wav",0,TRUE) == -1)
353 fileName += ".wav"; 353 fileName += ".wav";
354 354
355 cmd.sprintf("mv %s "+fileName, pointer); 355 cmd.sprintf("mv %s "+fileName, pointer);
356// move tmp file to regular file here 356// move tmp file to regular file here
357 357
358 system(cmd.latin1()); 358 system(cmd.latin1());
359 359
360 QArray<int> cats(1); 360 QArray<int> cats(1);
361 cats[0] = config.readNumEntry("Category", 0); 361 cats[0] = config.readNumEntry("Category", 0);
362 362
363 QString dlName("vm_"); 363 QString dlName("vm_");
364 dlName += date; 364 dlName += date;
365 DocLnk l; 365 DocLnk l;
366 l.setFile(fileName); 366 l.setFile(fileName);
367 l.setName(dlName); 367 l.setName(dlName);
368 l.setType("audio/x-wav"); 368 l.setType("audio/x-wav");
369 l.setCategories(cats); 369 l.setCategories(cats);
370 l.writeLink(); 370 l.writeLink();
371 return TRUE; 371 return TRUE;
372 } else 372 } else
373 return FALSE; 373 return FALSE;
374 374
375} 375}
376 376
377void VMemo::stopRecording() { 377void VMemo::stopRecording() {
378 show(); 378 show();
379 odebug << "Stopped recording" << oendl; 379 odebug << "Stopped recording" << oendl;
380 recording = FALSE; 380 recording = FALSE;
381 if(useAlerts) { 381 if(useAlerts) {
382 msgLabel->close(); 382 msgLabel->close();
383 msgLabel=0; 383 msgLabel=0;
384 delete msgLabel; 384 delete msgLabel;
385 } 385 }
386 t_timer->stop(); 386 t_timer->stop();
387 Config cfg("Vmemo"); 387 Config cfg("Vmemo");
388 cfg.setGroup("Defaults"); 388 cfg.setGroup("Defaults");
389// if( cfg.readNumEntry("hideIcon",0) == 1 ) 389// if( cfg.readNumEntry("hideIcon",0) == 1 )
390// hide(); 390// hide();
391} 391}
392 392
393int VMemo::openDSP() { 393int VMemo::openDSP() {
394 Config cfg("Vmemo"); 394 Config cfg("Vmemo");
395 cfg.setGroup("Record"); 395 cfg.setGroup("Record");
396 396
397 speed = cfg.readNumEntry("SampleRate", 22050); 397 speed = cfg.readNumEntry("SampleRate", 22050);
398 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 398 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
399 if (cfg.readNumEntry("SixteenBit", 1)==1) { 399 if (cfg.readNumEntry("SixteenBit", 1)==1) {
400 format = AFMT_S16_LE; 400 format = AFMT_S16_LE;
401 resolution = 16; 401 resolution = 16;
402 } else { 402 } else {
403 format = AFMT_U8; 403 format = AFMT_U8;
404 resolution = 8; 404 resolution = 8;
405 } 405 }
406 406
407 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; 407 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl;
408 408
409 if(systemZaurus) { 409 if(systemZaurus) {
410 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 410 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
411 channels=1; //zaurus has one input channel 411 channels=1; //zaurus has one input channel
412 } else { 412 } else {
413 dsp = open("/dev/dsp", O_RDONLY); 413 dsp = open("/dev/dsp", O_RDONLY);
414 } 414 }
415 415
416 if(dsp == -1) { 416 if(dsp == -1) {
417 msgLabel->close(); 417 msgLabel->close();
418 msgLabel=0; 418 msgLabel=0;
419 delete msgLabel; 419 delete msgLabel;
420 420
421 perror("open(\"/dev/dsp\")"); 421 perror("open(\"/dev/dsp\")");
422 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 422 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
423 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 423 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
424 return -1; 424 return -1;
425 } 425 }
426 426
427 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 427 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
428 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 428 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
429 return -1; 429 return -1;
430 } 430 }
431 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 431 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
432 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 432 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
433 return -1; 433 return -1;
434 } 434 }
435 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 435 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
436 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 436 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
437 return -1; 437 return -1;
438 } 438 }
439 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 439 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
440 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 440 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
441 return -1; 441 return -1;
442 } 442 }
443 443
444 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute 444 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute
445 445
446 return 1; 446 return 1;
447} 447}
448 448
449int VMemo::openWAV(const char *filename) { 449int VMemo::openWAV(const char *filename) {
450 track.setName(filename); 450 track.setName(filename);
451 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 451 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
452 errorMsg=filename; 452 errorMsg=filename;
453 return -1; 453 return -1;
454 } 454 }
455 455
456 wav=track.handle(); 456 wav=track.handle();
457 Config vmCfg("Vmemo"); 457 Config vmCfg("Vmemo");
458 vmCfg.setGroup("Defaults"); 458 vmCfg.setGroup("Defaults");
459 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 459 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
460 460
461 WaveHeader wh; 461 WaveHeader wh;
462 462
463 wh.main_chunk = RIFF; 463 wh.main_chunk = RIFF;
464 wh.length=0; 464 wh.length=0;
465 wh.chunk_type = WAVE; 465 wh.chunk_type = WAVE;
466 wh.sub_chunk = FMT; 466 wh.sub_chunk = FMT;
467 wh.sc_len = 16; 467 wh.sc_len = 16;
468 if(useADPCM) 468 if(useADPCM)
469 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; 469 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE;
470 else 470 else
471 wh.format = PCM_CODE; 471 wh.format = PCM_CODE;
472 wh.modus = channels; 472 wh.modus = channels;
473 wh.sample_fq = speed; 473 wh.sample_fq = speed;
474 wh.byte_p_sec = speed * channels * resolution/8; 474 wh.byte_p_sec = speed * channels * resolution/8;
475 wh.byte_p_spl = channels * (resolution / 8); 475 wh.byte_p_spl = channels * (resolution / 8);
476 wh.bit_p_spl = resolution; 476 wh.bit_p_spl = resolution;
477 wh.data_chunk = DATA; 477 wh.data_chunk = DATA;
478 wh.data_length= 0; 478 wh.data_length= 0;
479 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 479 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s "
480 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 480 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl;
481 write (wav, &wh, sizeof(WaveHeader)); 481 write (wav, &wh, sizeof(WaveHeader));
482 482
483 return 1; 483 return 1;
484} 484}
485 485
486bool VMemo::record() { 486bool VMemo::record() {
487 length = 0; 487 length = 0;
488 int bytesWritten = 0; 488 int bytesWritten = 0;
489 int result = 0; 489 int result = 0;
490 int value = 0; 490 int value = 0;
491 QString msg; 491 QString msg;
492 msg.sprintf("Recording format %d", format); 492 msg.sprintf("Recording format %d", format);
493 odebug << msg << oendl; 493 odebug << msg << oendl;
494 Config config("Vmemo"); 494 Config config("Vmemo");
495 config.setGroup("Record"); 495 config.setGroup("Record");
496 int sRate = config.readNumEntry("SizeLimit", 30); 496 int sRate = config.readNumEntry("SizeLimit", 30);
497 if(sRate > 0) 497 if(sRate > 0)
498 t_timer->start( sRate * 1000+1000, TRUE); 498 t_timer->start( sRate * 1000+1000, TRUE);
499 499
500 msg.sprintf("Recording format other"); 500 msg.sprintf("Recording format other");
501 odebug << msg << oendl; 501 odebug << msg << oendl;
502 502
503 config.setGroup("Defaults"); 503 config.setGroup("Defaults");
504 useADPCM = config.readBoolEntry("use_ADPCM", 0); 504 useADPCM = config.readBoolEntry("use_ADPCM", 0);
505 505
506 int bufsize = config.readNumEntry("BufferSize",1024); 506 int bufsize = config.readNumEntry("BufferSize",1024);
507 unsigned short sound[bufsize]; //, monoBuffer[bufsize]; 507 unsigned short sound[bufsize]; //, monoBuffer[bufsize];
508 char abuf[bufsize / 2]; 508 char abuf[bufsize / 2];
509 short sbuf[bufsize]; 509 short sbuf[bufsize];
510 510
511 if(useADPCM) { 511 if(useADPCM) {
512 while(recording) { 512 while(recording) {
513 result = ::read(dsp, sbuf, bufsize); // adpcm read 513 result = ::read(dsp, sbuf, bufsize); // adpcm read
514 if( result <= 0) { 514 if( result <= 0) {
515 perror("recording error "); 515 perror("recording error ");
516 QMessageBox::message(tr("Note"),tr("error recording")); 516 QMessageBox::message(tr("Note"),tr("error recording"));
517 recording = FALSE; 517 recording = FALSE;
518 break; 518 break;
519 return FALSE; 519 return FALSE;
520 } 520 }
521 adpcm_coder( sbuf, abuf, result/2, &encoder_state); 521 adpcm_coder( sbuf, abuf, result/2, &encoder_state);
522 bytesWritten = ::write(wav, abuf, result/4); // adpcm write 522 bytesWritten = ::write(wav, abuf, result/4); // adpcm write
523 length += bytesWritten; 523 length += bytesWritten;
524 524
525 if(length < 0) { 525 if(length < 0) {
526 recording = false; 526 recording = false;
527 perror("dev/dsp's is a lookin' messy"); 527 perror("dev/dsp's is a lookin' messy");
528 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 528 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
529 break; 529 break;
530 return FALSE; 530 return FALSE;
531 } 531 }
532 // printf("%d\r", length); 532 // printf("%d\r", length);
533 // fflush(stdout); 533 // fflush(stdout);
534 qApp->processEvents(); 534 qApp->processEvents();
535 } 535 }
536 } else { 536 } else {
537 while(recording) { 537 while(recording) {
538 result = ::read(dsp, sound, bufsize); // read 538 result = ::read(dsp, sound, bufsize); // read
539 if( result <= 0) { 539 if( result <= 0) {
540 perror("recording error "); 540 perror("recording error ");
541 QMessageBox::message(tr("Note"),tr("error recording")); 541 QMessageBox::message(tr("Note"),tr("error recording"));
542 recording = FALSE; 542 recording = FALSE;
543 break; 543 break;
544 return FALSE; 544 return FALSE;
545 545
546 bytesWritten = ::write(wav, sound, result); // write 546 bytesWritten = ::write(wav, sound, result); // write
547 length += bytesWritten; 547 length += bytesWritten;
548 548
549 if(length < 0) { 549 if(length < 0) {
550 recording = false; 550 recording = false;
551 perror("dev/dsp's is a lookin' messy"); 551 perror("dev/dsp's is a lookin' messy");
552 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 552 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
553 break; 553 break;
554 return FALSE; 554 return FALSE;
555 } 555 }
556 // printf("%d\r", length); 556 // printf("%d\r", length);
557 // fflush(stdout); 557 // fflush(stdout);
558 qApp->processEvents(); 558 qApp->processEvents();
559 } 559 }
560 } 560 }
561 } 561 }
562 // qDebug("file has length of %d lasting %d seconds", 562 // odebug << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 ) << " seconds" << oendl;
563 // length, (( length / speed) / channels) / 2 ); 563
564 564 value = length + 36;
565 value = length + 36; 565
566 566 lseek(wav, 4, SEEK_SET);
567 lseek(wav, 4, SEEK_SET); 567 write(wav, &value, 4);
568 write(wav, &value, 4); 568 lseek(wav, 40, SEEK_SET);
569 lseek(wav, 40, SEEK_SET); 569
570 570 write(wav, &length, 4);
571 write(wav, &length, 4); 571
572 572 track.close();
573 track.close(); 573 odebug << "Track closed" << oendl;
574 odebug << "Track closed" << oendl; 574
575 575 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
576 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 576 perror("ioctl(\"SNDCTL_DSP_RESET\")");
577 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 577
578 578 ::close(dsp);
579 ::close(dsp); 579
580 580 Config cfgO("OpieRec");
581 Config cfgO("OpieRec"); 581 cfgO.setGroup("Sounds");
582 cfgO.setGroup("Sounds"); 582
583 583 int nFiles = cfgO.readNumEntry( "NumberofFiles",0);
584 int nFiles = cfgO.readNumEntry( "NumberofFiles",0); 584
585 585 QString currentFileName = fileName;
586 QString currentFileName = fileName; 586 QString currentFile = "vm_"+ date;
587 QString currentFile = "vm_"+ date; 587
588 588 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2;
589 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; 589
590 590 cfgO.writeEntry( "NumberofFiles", nFiles + 1);
591 cfgO.writeEntry( "NumberofFiles", nFiles + 1); 591 cfgO.writeEntry( QString::number( nFiles + 1), currentFile);
592 cfgO.writeEntry( QString::number( nFiles + 1), currentFile); 592 cfgO.writeEntry( currentFile, currentFileName);
593 cfgO.writeEntry( currentFile, currentFileName); 593
594 594 QString time;
595 QString time; 595 time.sprintf("%.2f", numberOfRecordedSeconds);
596 time.sprintf("%.2f", numberOfRecordedSeconds); 596 cfgO.writeEntry( currentFileName, time );
597 cfgO.writeEntry( currentFileName, time );
598 // odebug << "writing config numberOfRecordedSeconds "+time << oendl; 597 // odebug << "writing config numberOfRecordedSeconds "+time << oendl;
599 598
600 cfgO.write(); 599 cfgO.write();
601 600
602 odebug << "done recording "+fileName << oendl; 601 odebug << "done recording "+fileName << oendl;
603 602
604 Config cfg("qpe"); 603 Config cfg("qpe");
605 cfg.setGroup("Volume"); 604 cfg.setGroup("Volume");
606 QString foo = cfg.readEntry("Mute","TRUE"); 605 QString foo = cfg.readEntry("Mute","TRUE");
607 if(foo.find("TRUE",0,TRUE) != -1) 606 if(foo.find("TRUE",0,TRUE) != -1)
608 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute 607 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute
609 return TRUE; 608 return TRUE;
610} 609}
611 610
612int VMemo::setToggleButton(int tog) { 611int VMemo::setToggleButton(int tog) {
613 612
614 for( int i=0; i < 10;i++) { 613 for( int i=0; i < 10;i++) {
615 switch (tog) { 614 switch (tog) {
616 case 0: 615 case 0:
617 return -1; 616 return -1;
618 break; 617 break;
619 case 1: 618 case 1:
620 return 0; 619 return 0;
621 break; 620 break;
622 case 2: 621 case 2:
623 return Key_F24; //was Escape 622 return Key_F24; //was Escape
624 break; 623 break;
625 case 3: 624 case 3:
626 return Key_Space; 625 return Key_Space;
627 break; 626 break;
628 case 4: 627 case 4:
629 return Key_F12; 628 return Key_F12;
630 break; 629 break;
631 case 5: 630 case 5:
632 return Key_F9; 631 return Key_F9;
633 break; 632 break;
634 case 6: 633 case 6:
635 return Key_F10; 634 return Key_F10;
636 break; 635 break;
637 case 7: 636 case 7:
638 return Key_F11; 637 return Key_F11;
639 break; 638 break;
640 case 8: 639 case 8:
641 return Key_F13; 640 return Key_F13;
642 break; 641 break;
643 }; 642 };
644 } 643 }
645 return -1; 644 return -1;
646} 645}
647 646
648void VMemo::timerBreak() { 647void VMemo::timerBreak() {
649 //stop 648 //stop
650 stopRecording(); 649 stopRecording();
651 QMessageBox::message("Vmemo","Vmemo recording has ended"); 650 QMessageBox::message("Vmemo","Vmemo recording has ended");
652} 651}
653 652
654 653
655EXPORT_OPIE_APPLET_v1( VMemo ) 654EXPORT_OPIE_APPLET_v1( VMemo )
656 655