summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-11-06 09:56:49 (UTC)
committer mickeyl <mickeyl>2003-11-06 09:56:49 (UTC)
commit56ad1eb7fb39ddc78026a0df096703fcf42f5a94 (patch) (unidiff)
tree25d1ba2c7c3bdef72592b8d2de3e2a54f3294c2e
parent2f974fea9a432e9dd7b7a8ad235a4e6bc2ef51fe (diff)
downloadopie-56ad1eb7fb39ddc78026a0df096703fcf42f5a94.zip
opie-56ad1eb7fb39ddc78026a0df096703fcf42f5a94.tar.gz
opie-56ad1eb7fb39ddc78026a0df096703fcf42f5a94.tar.bz2
merge core/applets/*
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp8
-rw-r--r--core/applets/vmemo/vmemo.cpp3
2 files changed, 4 insertions, 7 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index 5936b5d..64e0499 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,255 +1,255 @@
1 1
2#include "batterystatus.h" 2#include "batterystatus.h"
3 3
4#include <qpe/power.h> 4#include <qpe/power.h>
5 5
6#include <opie/odevice.h> 6#include <opie/odevice.h>
7 7
8#include <qpainter.h> 8#include <qpainter.h>
9#include <qpushbutton.h> 9#include <qpushbutton.h>
10#include <qdrawutil.h> 10#include <qdrawutil.h>
11#include <qfile.h> 11#include <qfile.h>
12#include <qlayout.h> 12#include <qlayout.h>
13#include <qtextstream.h> 13#include <qtextstream.h>
14#include <qapplication.h> 14#include <qapplication.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16 16
17using namespace Opie; 17using namespace Opie;
18 18
19BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 19BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
20 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { 20 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) {
21 setCaption( tr("Battery status") ); 21 setCaption( tr("Battery status") );
22 QPushButton *pb = new QPushButton( tr("Close"), this ); 22 QPushButton *pb = new QPushButton( tr("Close"), this );
23 QVBoxLayout *layout = new QVBoxLayout ( this ); 23 QVBoxLayout *layout = new QVBoxLayout ( this );
24 24
25 jackPercent = 0; 25 jackPercent = 0;
26 26
27 pb->setMaximumHeight(40); 27 pb->setMaximumHeight(40);
28 pb->setMaximumWidth( 120 ); 28 pb->setMaximumWidth( 120 );
29 29
30 pb->show(); 30 pb->show();
31 31
32 layout->addStretch( 0 ); 32 layout->addStretch( 0 );
33 layout->addWidget( pb ); 33 layout->addWidget( pb );
34 34
35 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 35 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
36 getProcApmStatusIpaq(); 36 getProcApmStatusIpaq();
37 } 37 }
38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); 38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
39 percent = ps->batteryPercentRemaining(); 39 percent = ps->batteryPercentRemaining();
40 show(); 40 show();
41} 41}
42 42
43BatteryStatus::~BatteryStatus() 43BatteryStatus::~BatteryStatus()
44{ 44{
45} 45}
46 46
47/* 47/*
48 * Make use of the advanced apm interface of the ipaq 48 * Make use of the advanced apm interface of the ipaq
49 */ 49 */
50bool BatteryStatus::getProcApmStatusIpaq() { 50bool BatteryStatus::getProcApmStatusIpaq() {
51 51
52 bat2 = false; 52 bat2 = false;
53 53
54 QFile procApmIpaq("/proc/hal/battery"); 54 QFile procApmIpaq("/proc/hal/battery");
55 55
56 if (procApmIpaq.open(IO_ReadOnly) ) { 56 if (procApmIpaq.open(IO_ReadOnly) ) {
57 QStringList list; 57 QStringList list;
58 // since it is /proc we _must_ use QTextStream 58 // since it is /proc we _must_ use QTextStream
59 QTextStream stream ( &procApmIpaq); 59 QTextStream stream ( &procApmIpaq);
60 QString streamIn; 60 QString streamIn;
61 streamIn = stream.read(); 61 streamIn = stream.read();
62 list = QStringList::split("\n", streamIn); 62 list = QStringList::split("\n", streamIn);
63 63
64 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 64 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
65 // not nice, need a rewrite later 65 // not nice, need a rewrite later
66 if( (*line).startsWith(" Percentage") ){ 66 if( (*line).startsWith(" Percentage") ){
67 if (bat2 == true) { 67 if (bat2 == true) {
68 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 68 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
69 } else { 69 } else {
70 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 70 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
71 } 71 }
72 }else if( (*line).startsWith(" Life") ){ 72 }else if( (*line).startsWith(" Life") ){
73 if (bat2 == true) { 73 if (bat2 == true) {
74 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 74 sec2 = (*line).mid(((*line).find(':')+2), 5 );
75 } else { 75 } else {
76 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 76 sec1 = (*line).mid(((*line).find(':')+2), 5 );
77 } 77 }
78 }else if( (*line).startsWith("Battery #1") ){ 78 }else if( (*line).startsWith("Battery #1") ){
79 bat2 = true; 79 bat2 = true;
80 }else if( (*line).startsWith(" Status") ){ 80 }else if( (*line).startsWith(" Status") ){
81 if (bat2 == true) { 81 if (bat2 == true) {
82 jackStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1); 82 jackStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1);
83 } else { 83 } else {
84 ipaqStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1); 84 ipaqStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1);
85 } 85 }
86 }else if( (*line).startsWith(" Chemistry") ) { 86 }else if( (*line).startsWith(" Chemistry") ) {
87 if (bat2 == true) { 87 if (bat2 == true) {
88 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 88 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
89 } else { 89 } else {
90 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 90 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
91 } 91 }
92 } 92 }
93 } 93 }
94 } else { 94 } else {
95 QMessageBox::warning(this, tr("Failure"),tr("could not open file")); 95 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
96 } 96 }
97 97
98 procApmIpaq.close(); 98 procApmIpaq.close();
99 99
100 jackPercent = perc2.toInt(); 100 jackPercent = perc2.toInt();
101 ipaqPercent = perc1.toInt(); 101 ipaqPercent = perc1.toInt();
102 102
103 if (perc2.isEmpty()) { 103 if (perc2.isEmpty()) {
104 perc2 = "no data"; 104 perc2 = tr("no data");
105 } else { 105 } else {
106 perc2 += " %"; 106 perc2 += " %";
107 } 107 }
108 108
109 109
110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
111 sec2 = "no data"; 111 sec2 = tr("no data");
112 } else { 112 } else {
113 sec2 += " min"; 113 sec2 += " min";
114 } 114 }
115 115
116 jackStatus == (" ( " + jackStatus + " )"); 116 jackStatus == (" ( " + jackStatus + " )");
117 117
118 return true; 118 return true;
119} 119}
120 120
121 121
122void BatteryStatus::updatePercent( int pc ) { 122void BatteryStatus::updatePercent( int pc ) {
123 percent = pc; 123 percent = pc;
124 repaint(FALSE); 124 repaint(FALSE);
125} 125}
126 126
127void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 127void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
128 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 128 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
129 topgrad.hsv( &h1, &s1, &v1 ); 129 topgrad.hsv( &h1, &s1, &v1 );
130 botgrad.hsv( &h2, &s2, &v2 ); 130 botgrad.hsv( &h2, &s2, &v2 );
131 for ( int j = 0; j < hy-2; j++ ) { 131 for ( int j = 0; j < hy-2; j++ ) {
132 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 132 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
133 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 133 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
134 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 134 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
135 } 135 }
136 for ( int j = 0; j < hh; j++ ) { 136 for ( int j = 0; j < hh; j++ ) {
137 p->setPen( highlight ); 137 p->setPen( highlight );
138 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 138 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
139 } 139 }
140 for ( int j = 0; j < ng-hy-hh; j++ ) { 140 for ( int j = 0; j < ng-hy-hh; j++ ) {
141 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 141 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
142 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 142 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
143 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); 143 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
144 } 144 }
145} 145}
146 146
147void BatteryStatus::paintEvent( QPaintEvent * ) { 147void BatteryStatus::paintEvent( QPaintEvent * ) {
148 148
149 149
150 int screenWidth = qApp->desktop()->width(); 150 int screenWidth = qApp->desktop()->width();
151 int screenHeight = qApp->desktop()->height(); 151 int screenHeight = qApp->desktop()->height();
152 152
153 QPainter p(this); 153 QPainter p(this);
154 QString text; 154 QString text;
155 if ( ps->batteryStatus() == PowerStatus::Charging ) { 155 if ( ps->batteryStatus() == PowerStatus::Charging ) {
156 if (bat2) { 156 if (bat2) {
157 text = tr("Charging both devices"); 157 text = tr("Charging both devices");
158 } else { 158 } else {
159 text = tr("Charging"); 159 text = tr("Charging");
160 } 160 }
161 } else if ( ps->batteryPercentAccurate() ) { 161 } else if ( ps->batteryPercentAccurate() ) {
162 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); 162 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent );
163 } else { 163 } else {
164 text = tr("Battery status: "); 164 text = tr("Battery status: ");
165 switch ( ps->batteryStatus() ) { 165 switch ( ps->batteryStatus() ) {
166 case PowerStatus::High: 166 case PowerStatus::High:
167 text += tr("Good"); 167 text += tr("Good");
168 break; 168 break;
169 case PowerStatus::Low: 169 case PowerStatus::Low:
170 text += tr("Low"); 170 text += tr("Low");
171 break; 171 break;
172 case PowerStatus::VeryLow: 172 case PowerStatus::VeryLow:
173 text += tr("Very Low"); 173 text += tr("Very Low");
174 break; 174 break;
175 case PowerStatus::Critical: 175 case PowerStatus::Critical:
176 text += tr("Critical"); 176 text += tr("Critical");
177 break; 177 break;
178 default: // NotPresent, etc. 178 default: // NotPresent, etc.
179 text += tr("Unknown"); 179 text += tr("Unknown");
180 } 180 }
181 } 181 }
182 p.drawText( 10, 90, text ); 182 p.drawText( 10, 90, text );
183 183
184 if ( ps->acStatus() == PowerStatus::Backup ) 184 if ( ps->acStatus() == PowerStatus::Backup )
185 p.drawText( 10, 110, tr("On backup power") ); 185 p.drawText( 10, 110, tr("On backup power") );
186 else if ( ps->acStatus() == PowerStatus::Online ) 186 else if ( ps->acStatus() == PowerStatus::Online )
187 p.drawText( 10, 110, tr("Power on-line") ); 187 p.drawText( 10, 110, tr("Power on-line") );
188 else if ( ps->acStatus() == PowerStatus::Offline ) 188 else if ( ps->acStatus() == PowerStatus::Offline )
189 p.drawText( 10, 110, tr("External power disconnected") ); 189 p.drawText( 10, 110, tr("External power disconnected") );
190 190
191 if ( ps->batteryTimeRemaining() >= 0 ) { 191 if ( ps->batteryTimeRemaining() >= 0 ) {
192 text.sprintf( tr("Battery time remaining") + ": %im %02is", 192 text.sprintf( tr("Battery time remaining") + ": %im %02is",
193 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); 193 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
194 p.drawText( 10, 130, text ); 194 p.drawText( 10, 130, text );
195 } 195 }
196 196
197 QColor c; 197 QColor c;
198 QColor darkc; 198 QColor darkc;
199 QColor lightc; 199 QColor lightc;
200 if ( ps->acStatus() == PowerStatus::Offline ) { 200 if ( ps->acStatus() == PowerStatus::Offline ) {
201 c = blue.light(120); 201 c = blue.light(120);
202 darkc = c.dark(280); 202 darkc = c.dark(280);
203 lightc = c.light(145); 203 lightc = c.light(145);
204 } else if ( ps->acStatus() == PowerStatus::Online ) { 204 } else if ( ps->acStatus() == PowerStatus::Online ) {
205 c = green.dark(130); 205 c = green.dark(130);
206 darkc = c.dark(200); 206 darkc = c.dark(200);
207 lightc = c.light(220); 207 lightc = c.light(220);
208 } else { 208 } else {
209 c = red; 209 c = red;
210 darkc = c.dark(280); 210 darkc = c.dark(280);
211 lightc = c.light(140); 211 lightc = c.light(140);
212 } 212 }
213 if ( percent < 0 ) 213 if ( percent < 0 )
214 return; 214 return;
215 215
216 int rightEnd1 = screenWidth - 47; 216 int rightEnd1 = screenWidth - 47;
217 int rightEnd2 = screenWidth - 35; 217 int rightEnd2 = screenWidth - 35;
218 int percent2 = ( percent / 100.0 ) * rightEnd1 ; 218 int percent2 = ( percent / 100.0 ) * rightEnd1 ;
219 p.setPen( black ); 219 p.setPen( black );
220 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); 220 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL);
221 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL); 221 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL);
222 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); 222 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
223 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); 223 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
224 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); 224 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 );
225 p.setPen( black); 225 p.setPen( black);
226 226
227 227
228 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 228 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
229 229
230 p.drawText(15, 50, tr ("Ipaq " + ipaqChem)); 230 p.drawText(15, 50, tr ("Ipaq ") + ipaqChem);
231 231
232 QString jacketMsg; 232 QString jacketMsg;
233 if (bat2) { 233 if (bat2) {
234 p.setPen(black); 234 p.setPen(black);
235 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus); 235 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus);
236 p.drawText(10,240, tr("Battery time remaining: ") + sec2); 236 p.drawText(10,240, tr("Battery time remaining: ") + sec2);
237 jacketMsg = tr("Jacket " + jackChem); 237 jacketMsg = tr("Jacket ") + jackChem;
238 } else { 238 } else {
239 jackPercent = 0; 239 jackPercent = 0;
240 jacketMsg = tr("No jacket with battery inserted"); 240 jacketMsg = tr("No jacket with battery inserted");
241 } 241 }
242 242
243 int jackPerc = ( jackPercent / 100.0 ) * ( screenWidth - 47 ) ; 243 int jackPerc = ( jackPercent / 100.0 ) * ( screenWidth - 47 ) ;
244 244
245 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); 245 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL);
246 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL); 246 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL);
247 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); 247 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 );
248 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); 248 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 );
249 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 ); 249 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 );
250 p.setPen( black ); 250 p.setPen( black );
251 p.drawText(15, 180, jacketMsg); 251 p.drawText(15, 180, jacketMsg);
252 } 252 }
253 253
254} 254}
255 255
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 83c148f..fe8ebfd 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,636 +1,633 @@
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/*
14 * $Id$
15*/
16// copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> 13// copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com>
17 14
18extern "C" { 15extern "C" {
19#include "adpcm.h" 16#include "adpcm.h"
20} 17}
21 18
22#include <unistd.h> 19#include <unistd.h>
23#include <stdio.h> 20#include <stdio.h>
24#include <fcntl.h> 21#include <fcntl.h>
25#include <sys/ioctl.h> 22#include <sys/ioctl.h>
26#include <linux/soundcard.h> 23#include <linux/soundcard.h>
27 24
28#include <errno.h> 25#include <errno.h>
29 26
30typedef struct _waveheader { 27typedef struct _waveheader {
31 u_long main_chunk; /* 'RIFF' */ 28 u_long main_chunk; /* 'RIFF' */
32 u_long length; /* filelen */ 29 u_long length; /* filelen */
33 u_long chunk_type; /* 'WAVE' */ 30 u_long chunk_type; /* 'WAVE' */
34 u_long sub_chunk; /* 'fmt ' */ 31 u_long sub_chunk; /* 'fmt ' */
35 u_long sc_len; /* length of sub_chunk, =16 32 u_long sc_len; /* length of sub_chunk, =16
36 (chunckSize) format len */ 33 (chunckSize) format len */
37 u_short format; /* should be 1 for PCM-code (formatTag) */ 34 u_short format; /* should be 1 for PCM-code (formatTag) */
38 35
39 u_short modus; /* 1 Mono, 2 Stereo (channels) */ 36 u_short modus; /* 1 Mono, 2 Stereo (channels) */
40 u_long sample_fq; /* samples per second (samplesPerSecond) */ 37 u_long sample_fq; /* samples per second (samplesPerSecond) */
41 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 38 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
42 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 39 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
43 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 40 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
44 41
45 u_long data_chunk; /* 'data' */ 42 u_long data_chunk; /* 'data' */
46 43
47 u_long data_length;/* samplecount */ 44 u_long data_length;/* samplecount */
48} WaveHeader; 45} WaveHeader;
49 46
50#define RIFF 0x46464952 47#define RIFF 0x46464952
51#define WAVE 0x45564157 48#define WAVE 0x45564157
52#define FMT 0x20746D66 49#define FMT 0x20746D66
53#define DATA 0x61746164 50#define DATA 0x61746164
54#define PCM_CODE 1 51#define PCM_CODE 1
55#define WAVE_MONO 1 52#define WAVE_MONO 1
56#define WAVE_STEREO 2 53#define WAVE_STEREO 2
57 54
58struct adpcm_state encoder_state; 55struct adpcm_state encoder_state;
59//struct adpcm_state decoder_state; 56//struct adpcm_state decoder_state;
60 57
61#define WAVE_FORMAT_DVI_ADPCM (0x0011) 58#define WAVE_FORMAT_DVI_ADPCM (0x0011)
62#define WAVE_FORMAT_PCM (0x0001) 59#define WAVE_FORMAT_PCM (0x0001)
63 60
64 61
65#include "vmemo.h" 62#include "vmemo.h"
66 63
67#include <qpe/qpeapplication.h> 64#include <qpe/qpeapplication.h>
68#include <qpe/config.h> 65#include <qpe/config.h>
69 66
70#include <qpainter.h> 67#include <qpainter.h>
71#include <qmessagebox.h> 68#include <qmessagebox.h>
72 69
73int seq = 0; 70int seq = 0;
74 71
75/* XPM */ 72/* XPM */
76static char * vmemo_xpm[] = { 73static char * vmemo_xpm[] = {
77 "16 16 102 2", 74 "16 16 102 2",
78 " c None", 75 " c None",
79 ". c #60636A", 76 ". c #60636A",
80 "+ c #6E6E72", 77 "+ c #6E6E72",
81 "@ c #68696E", 78 "@ c #68696E",
82 "# c #4D525C", 79 "# c #4D525C",
83 "$ c #6B6C70", 80 "$ c #6B6C70",
84 "% c #E3E3E8", 81 "% c #E3E3E8",
85 "& c #EEEEF2", 82 "& c #EEEEF2",
86 "* c #EAEAEF", 83 "* c #EAEAEF",
87 "= c #CACAD0", 84 "= c #CACAD0",
88 "- c #474A51", 85 "- c #474A51",
89 "; c #171819", 86 "; c #171819",
90 "> c #9B9B9F", 87 "> c #9B9B9F",
91 ", c #EBEBF0", 88 ", c #EBEBF0",
92 "' c #F4F4F7", 89 "' c #F4F4F7",
93 ") c #F1F1F5", 90 ") c #F1F1F5",
94 "! c #DEDEE4", 91 "! c #DEDEE4",
95 "~ c #57575C", 92 "~ c #57575C",
96 "{ c #010101", 93 "{ c #010101",
97 "] c #A2A2A6", 94 "] c #A2A2A6",
98 "^ c #747477", 95 "^ c #747477",
99 "/ c #B5B5B8", 96 "/ c #B5B5B8",
100 "( c #AEAEB2", 97 "( c #AEAEB2",
101 "_ c #69696D", 98 "_ c #69696D",
102 ": c #525256", 99 ": c #525256",
103 "< c #181C24", 100 "< c #181C24",
104 "[ c #97979B", 101 "[ c #97979B",
105 "} c #A7A7AC", 102 "} c #A7A7AC",
106 "| c #B0B0B4", 103 "| c #B0B0B4",
107 "1 c #C8C8D1", 104 "1 c #C8C8D1",
108 "2 c #75757B", 105 "2 c #75757B",
109 "3 c #46464A", 106 "3 c #46464A",
110 "4 c #494A4F", 107 "4 c #494A4F",
111 "5 c #323234", 108 "5 c #323234",
112 "6 c #909095", 109 "6 c #909095",
113 "7 c #39393B", 110 "7 c #39393B",
114 "8 c #757578", 111 "8 c #757578",
115 "9 c #87878E", 112 "9 c #87878E",
116 "0 c #222224", 113 "0 c #222224",
117 "a c #414144", 114 "a c #414144",
118 "b c #6A6A6E", 115 "b c #6A6A6E",
119 "c c #020C16", 116 "c c #020C16",
120 "d c #6B6B6F", 117 "d c #6B6B6F",
121 "e c #68686D", 118 "e c #68686D",
122 "f c #5B5B60", 119 "f c #5B5B60",
123 "g c #8A8A8F", 120 "g c #8A8A8F",
124 "h c #6B6B6E", 121 "h c #6B6B6E",
125 "i c #ADADB2", 122 "i c #ADADB2",
126 "j c #828289", 123 "j c #828289",
127 "k c #3E3E41", 124 "k c #3E3E41",
128 "l c #CFCFD7", 125 "l c #CFCFD7",
129 "m c #4C4C50", 126 "m c #4C4C50",
130 "n c #000000", 127 "n c #000000",
131 "o c #66666A", 128 "o c #66666A",
132 "p c #505054", 129 "p c #505054",
133 "q c #838388", 130 "q c #838388",
134 "r c #A1A1A7", 131 "r c #A1A1A7",
135 "s c #A9A9AE", 132 "s c #A9A9AE",
136 "t c #A8A8B0", 133 "t c #A8A8B0",
137 "u c #5E5E63", 134 "u c #5E5E63",
138 "v c #3A3A3E", 135 "v c #3A3A3E",
139 "w c #BDBDC6", 136 "w c #BDBDC6",
140 "x c #59595E", 137 "x c #59595E",
141 "y c #76767C", 138 "y c #76767C",
142 "z c #373738", 139 "z c #373738",
143 "A c #717174", 140 "A c #717174",
144 "B c #727278", 141 "B c #727278",
145 "C c #1C1C1E", 142 "C c #1C1C1E",
146 "D c #3C3C3F", 143 "D c #3C3C3F",
147 "E c #ADADB6", 144 "E c #ADADB6",
148 "F c #54555A", 145 "F c #54555A",
149 "G c #8B8C94", 146 "G c #8B8C94",
150 "H c #5A5A5F", 147 "H c #5A5A5F",
151 "I c #BBBBC3", 148 "I c #BBBBC3",
152 "J c #C4C4CB", 149 "J c #C4C4CB",
153 "K c #909098", 150 "K c #909098",
154 "L c #737379", 151 "L c #737379",
155 "M c #343437", 152 "M c #343437",
156 "N c #8F8F98", 153 "N c #8F8F98",
157 "O c #000407", 154 "O c #000407",
158 "P c #2D3137", 155 "P c #2D3137",
159 "Q c #B0B1BC", 156 "Q c #B0B1BC",
160 "R c #3B3C40", 157 "R c #3B3C40",
161 "S c #6E6E74", 158 "S c #6E6E74",
162 "T c #95959C", 159 "T c #95959C",
163 "U c #74747A", 160 "U c #74747A",
164 "V c #1D1D1E", 161 "V c #1D1D1E",
165 "W c #91929A", 162 "W c #91929A",
166 "X c #42444A", 163 "X c #42444A",
167 "Y c #22282E", 164 "Y c #22282E",
168 "Z c #B0B2BC", 165 "Z c #B0B2BC",
169 "` c #898A90", 166 "` c #898A90",
170 " . c #65656A", 167 " . c #65656A",
171 ".. c #999AA2", 168 ".. c #999AA2",
172 "+. c #52535A", 169 "+. c #52535A",
173 "@. c #151B21", 170 "@. c #151B21",
174 "#. c #515257", 171 "#. c #515257",
175 "$. c #B5B5BE", 172 "$. c #B5B5BE",
176 "%. c #616167", 173 "%. c #616167",
177 "&. c #1A1D22", 174 "&. c #1A1D22",
178 "*. c #000713", 175 "*. c #000713",
179 "=. c #1F1F21", 176 "=. c #1F1F21",
180 " ", 177 " ",
181 " . + @ # ", 178 " . + @ # ",
182 " $ % & * = - ", 179 " $ % & * = - ",
183 " ; > , ' ) ! ~ ", 180 " ; > , ' ) ! ~ ",
184 " { ] ^ / ( _ : ", 181 " { ] ^ / ( _ : ",
185 " < [ } | 1 2 3 ", 182 " < [ } | 1 2 3 ",
186 " 4 5 6 7 8 9 0 a b c ", 183 " 4 5 6 7 8 9 0 a b c ",
187 " d e f g h i j 3 k l m n ", 184 " d e f g h i j 3 k l m n ",
188 " o p q r s t u v w n ", 185 " o p q r s t u v w n ",
189 " o x y z A B C D E n ", 186 " o x y z A B C D E n ",
190 " F G H I J K L M N O ", 187 " F G H I J K L M N O ",
191 " P Q R S T U V W X ", 188 " P Q R S T U V W X ",
192 " Y Z ` b ...+. ", 189 " Y Z ` b ...+. ",
193 " @.#.$.%.&. ", 190 " @.#.$.%.&. ",
194 " *.B =. ", 191 " *.B =. ",
195 " n n n n n n n n n "}; 192 " n n n n n n n n n "};
196 193
197 194
198VMemo::VMemo( QWidget *parent, const char *_name ) 195VMemo::VMemo( QWidget *parent, const char *_name )
199 : QWidget( parent, _name ) { 196 : QWidget( parent, _name ) {
200 setFixedHeight( 18 ); 197 setFixedHeight( 18 );
201 setFixedWidth( 14 ); 198 setFixedWidth( 14 );
202 199
203 t_timer = new QTimer( this ); 200 t_timer = new QTimer( this );
204 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 201 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) );
205 202
206 Config vmCfg("Vmemo"); 203 Config vmCfg("Vmemo");
207 vmCfg.setGroup("Defaults"); 204 vmCfg.setGroup("Defaults");
208 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); 205 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
209 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 206 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
210 207
211 qDebug("toggleKey %d", toggleKey); 208 qDebug("toggleKey %d", toggleKey);
212 if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 209 if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
213 systemZaurus=TRUE; 210 systemZaurus=TRUE;
214 else 211 else
215 systemZaurus=FALSE; 212 systemZaurus=FALSE;
216 213
217 myChannel = new QCopChannel( "QPE/VMemo", this ); 214 myChannel = new QCopChannel( "QPE/VMemo", this );
218 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 215 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
219 this, SLOT(receive(const QCString&, const QByteArray&)) ); 216 this, SLOT(receive(const QCString&, const QByteArray&)) );
220 217
221 if( toggleKey != -1 ) { 218 if( toggleKey != -1 ) {
222 // keyRegister(key, channel, message) 219 // keyRegister(key, channel, message)
223 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); 220 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)");
224 // e << 4096; // Key_Escape 221 // e << 4096; // Key_Escape
225 // e << Key_F5; //4148 222 // e << Key_F5; //4148
226 e << toggleKey; 223 e << toggleKey;
227 e << QString("QPE/VMemo"); 224 e << QString("QPE/VMemo");
228 e << QString("toggleRecord()"); 225 e << QString("toggleRecord()");
229 } 226 }
230 if(toggleKey == 1) 227 if(toggleKey == 1)
231 usingIcon=TRUE; 228 usingIcon=TRUE;
232 else 229 else
233 usingIcon=FALSE; 230 usingIcon=FALSE;
234 if( vmCfg.readNumEntry("hideIcon",0) == 1) 231 if( vmCfg.readNumEntry("hideIcon",0) == 1)
235 hide(); 232 hide();
236 recording = FALSE; 233 recording = FALSE;
237 // } 234 // }
238} 235}
239 236
240VMemo::~VMemo() { 237VMemo::~VMemo() {
241} 238}
242 239
243void VMemo::receive( const QCString &msg, const QByteArray &data ) { 240void VMemo::receive( const QCString &msg, const QByteArray &data ) {
244 qDebug("receive"); 241 qDebug("receive");
245 QDataStream stream( data, IO_ReadOnly ); 242 QDataStream stream( data, IO_ReadOnly );
246 243
247 if (msg == "toggleRecord()") { 244 if (msg == "toggleRecord()") {
248 if (recording) { 245 if (recording) {
249 fromToggle = TRUE; 246 fromToggle = TRUE;
250 stopRecording(); 247 stopRecording();
251 } else { 248 } else {
252 fromToggle = TRUE; 249 fromToggle = TRUE;
253 startRecording(); 250 startRecording();
254 } 251 }
255 } 252 }
256} 253}
257 254
258void VMemo::paintEvent( QPaintEvent* ) { 255void VMemo::paintEvent( QPaintEvent* ) {
259 QPainter p(this); 256 QPainter p(this);
260 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 257 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
261} 258}
262 259
263void VMemo::mousePressEvent( QMouseEvent * me) { 260void VMemo::mousePressEvent( QMouseEvent * me) {
264 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 261 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
265 mousePressEvent and mouseReleaseEvent with a NULL parameter. */ 262 mousePressEvent and mouseReleaseEvent with a NULL parameter. */
266 263
267// if (!systemZaurus && me != NULL) 264// if (!systemZaurus && me != NULL)
268// return; 265// return;
269// } 266// }
270 267
271 if(!recording) 268 if(!recording)
272 startRecording(); 269 startRecording();
273 else 270 else
274 stopRecording(); 271 stopRecording();
275} 272}
276 273
277void VMemo::mouseReleaseEvent( QMouseEvent * ) { 274void VMemo::mouseReleaseEvent( QMouseEvent * ) {
278} 275}
279 276
280bool VMemo::startRecording() { 277bool VMemo::startRecording() {
281 Config config( "Vmemo" ); 278 Config config( "Vmemo" );
282 config.setGroup( "System" ); 279 config.setGroup( "System" );
283 280
284 useAlerts = config.readBoolEntry("Alert",1); 281 useAlerts = config.readBoolEntry("Alert",1);
285 if(useAlerts) { 282 if(useAlerts) {
286 283
287 msgLabel = new QLabel( 0, "alertLabel" ); 284 msgLabel = new QLabel( 0, "alertLabel" );
288 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); 285 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
289 msgLabel->show(); 286 msgLabel->show();
290 } 287 }
291 288
292 qDebug("Start recording engines"); 289 qDebug("Start recording engines");
293 recording = TRUE; 290 recording = TRUE;
294 291
295 if (openDSP() == -1) { 292 if (openDSP() == -1) {
296 recording = FALSE; 293 recording = FALSE;
297 return FALSE; 294 return FALSE;
298 } 295 }
299 296
300 config.setGroup("Defaults"); 297 config.setGroup("Defaults");
301 298
302 date = TimeString::dateString( QDateTime::currentDateTime(),false,true); 299 date = TimeString::dateString( QDateTime::currentDateTime(),false,true);
303 date.replace(QRegExp("'"),""); 300 date.replace(QRegExp("'"),"");
304 date.replace(QRegExp(" "),"_"); 301 date.replace(QRegExp(" "),"_");
305 date.replace(QRegExp(":"),"."); 302 date.replace(QRegExp(":"),".");
306 date.replace(QRegExp(","),""); 303 date.replace(QRegExp(","),"");
307 304
308 QString fName; 305 QString fName;
309 config.setGroup( "System" ); 306 config.setGroup( "System" );
310 fName = QPEApplication::documentDir() ; 307 fName = QPEApplication::documentDir() ;
311 fileName = config.readEntry("RecLocation", fName); 308 fileName = config.readEntry("RecLocation", fName);
312 309
313 int s; 310 int s;
314 s=fileName.find(':'); 311 s=fileName.find(':');
315 if(s) 312 if(s)
316 fileName=fileName.right(fileName.length()-s-2); 313 fileName=fileName.right(fileName.length()-s-2);
317 qDebug("pathname will be "+fileName); 314 qDebug("pathname will be "+fileName);
318 315
319 if( fileName.left(1).find('/') == -1) 316 if( fileName.left(1).find('/') == -1)
320 fileName="/"+fileName; 317 fileName="/"+fileName;
321 if( fileName.right(1).find('/') == -1) 318 if( fileName.right(1).find('/') == -1)
322 fileName+="/"; 319 fileName+="/";
323 fName = "vm_"+ date+ ".wav"; 320 fName = "vm_"+ date+ ".wav";
324 321
325 fileName+=fName; 322 fileName+=fName;
326 qDebug("filename is "+fileName); 323 qDebug("filename is "+fileName);
327// open tmp file here 324// open tmp file here
328 char *pointer; 325 char *pointer;
329 pointer=tmpnam(NULL); 326 pointer=tmpnam(NULL);
330 qDebug("Opening tmp file %s",pointer); 327 qDebug("Opening tmp file %s",pointer);
331 328
332 if(openWAV(pointer ) == -1) { 329 if(openWAV(pointer ) == -1) {
333 330
334 QString err("Could not open the temp file\n"); 331 QString err("Could not open the temp file\n");
335 err += fileName; 332 err += fileName;
336 QMessageBox::critical(0, "vmemo", err, "Abort"); 333 QMessageBox::critical(0, "vmemo", err, "Abort");
337 ::close(dsp); 334 ::close(dsp);
338 return FALSE; 335 return FALSE;
339 } 336 }
340 if( record() ) { 337 if( record() ) {
341 338
342 QString cmd; 339 QString cmd;
343 if( fileName.find(".wav",0,TRUE) == -1) 340 if( fileName.find(".wav",0,TRUE) == -1)
344 fileName += ".wav"; 341 fileName += ".wav";
345 342
346 cmd.sprintf("mv %s "+fileName, pointer); 343 cmd.sprintf("mv %s "+fileName, pointer);
347// move tmp file to regular file here 344// move tmp file to regular file here
348 345
349 system(cmd.latin1()); 346 system(cmd.latin1());
350 347
351 QArray<int> cats(1); 348 QArray<int> cats(1);
352 cats[0] = config.readNumEntry("Category", 0); 349 cats[0] = config.readNumEntry("Category", 0);
353 350
354 QString dlName("vm_"); 351 QString dlName("vm_");
355 dlName += date; 352 dlName += date;
356 DocLnk l; 353 DocLnk l;
357 l.setFile(fileName); 354 l.setFile(fileName);
358 l.setName(dlName); 355 l.setName(dlName);
359 l.setType("audio/x-wav"); 356 l.setType("audio/x-wav");
360 l.setCategories(cats); 357 l.setCategories(cats);
361 l.writeLink(); 358 l.writeLink();
362 return TRUE; 359 return TRUE;
363 } else 360 } else
364 return FALSE; 361 return FALSE;
365 362
366} 363}
367 364
368void VMemo::stopRecording() { 365void VMemo::stopRecording() {
369 show(); 366 show();
370 qDebug("Stopped recording"); 367 qDebug("Stopped recording");
371 recording = FALSE; 368 recording = FALSE;
372 if(useAlerts) { 369 if(useAlerts) {
373 msgLabel->close(); 370 msgLabel->close();
374 msgLabel=0; 371 msgLabel=0;
375 delete msgLabel; 372 delete msgLabel;
376 } 373 }
377 t_timer->stop(); 374 t_timer->stop();
378 Config cfg("Vmemo"); 375 Config cfg("Vmemo");
379 cfg.setGroup("Defaults"); 376 cfg.setGroup("Defaults");
380 if( cfg.readNumEntry("hideIcon",0) == 1 ) 377 if( cfg.readNumEntry("hideIcon",0) == 1 )
381 hide(); 378 hide();
382} 379}
383 380
384int VMemo::openDSP() { 381int VMemo::openDSP() {
385 Config cfg("Vmemo"); 382 Config cfg("Vmemo");
386 cfg.setGroup("Record"); 383 cfg.setGroup("Record");
387 384
388 speed = cfg.readNumEntry("SampleRate", 22050); 385 speed = cfg.readNumEntry("SampleRate", 22050);
389 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 386 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
390 if (cfg.readNumEntry("SixteenBit", 1)==1) { 387 if (cfg.readNumEntry("SixteenBit", 1)==1) {
391 format = AFMT_S16_LE; 388 format = AFMT_S16_LE;
392 resolution = 16; 389 resolution = 16;
393 } else { 390 } else {
394 format = AFMT_U8; 391 format = AFMT_U8;
395 resolution = 8; 392 resolution = 8;
396 } 393 }
397 394
398 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 395 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
399 396
400 if(systemZaurus) { 397 if(systemZaurus) {
401 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 398 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
402 channels=1; //zaurus has one input channel 399 channels=1; //zaurus has one input channel
403 } else { 400 } else {
404 dsp = open("/dev/dsp", O_RDONLY); 401 dsp = open("/dev/dsp", O_RDONLY);
405 } 402 }
406 403
407 if(dsp == -1) { 404 if(dsp == -1) {
408 msgLabel->close(); 405 msgLabel->close();
409 msgLabel=0; 406 msgLabel=0;
410 delete msgLabel; 407 delete msgLabel;
411 408
412 perror("open(\"/dev/dsp\")"); 409 perror("open(\"/dev/dsp\")");
413 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 410 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
414 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 411 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
415 return -1; 412 return -1;
416 } 413 }
417 414
418 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 415 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
419 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 416 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
420 return -1; 417 return -1;
421 } 418 }
422 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 419 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
423 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 420 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
424 return -1; 421 return -1;
425 } 422 }
426 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 423 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
427 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 424 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
428 return -1; 425 return -1;
429 } 426 }
430 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 427 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
431 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 428 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
432 return -1; 429 return -1;
433 } 430 }
434 431
435 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute 432 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute
436 433
437 return 1; 434 return 1;
438} 435}
439 436
440int VMemo::openWAV(const char *filename) { 437int VMemo::openWAV(const char *filename) {
441 track.setName(filename); 438 track.setName(filename);
442 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 439 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
443 errorMsg=filename; 440 errorMsg=filename;
444 return -1; 441 return -1;
445 } 442 }
446 443
447 wav=track.handle(); 444 wav=track.handle();
448 Config vmCfg("Vmemo"); 445 Config vmCfg("Vmemo");
449 vmCfg.setGroup("Defaults"); 446 vmCfg.setGroup("Defaults");
450 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 447 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
451 448
452 WaveHeader wh; 449 WaveHeader wh;
453 450
454 wh.main_chunk = RIFF; 451 wh.main_chunk = RIFF;
455 wh.length=0; 452 wh.length=0;
456 wh.chunk_type = WAVE; 453 wh.chunk_type = WAVE;
457 wh.sub_chunk = FMT; 454 wh.sub_chunk = FMT;
458 wh.sc_len = 16; 455 wh.sc_len = 16;
459 if(useADPCM) 456 if(useADPCM)
460 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; 457 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE;
461 else 458 else
462 wh.format = PCM_CODE; 459 wh.format = PCM_CODE;
463 wh.modus = channels; 460 wh.modus = channels;
464 wh.sample_fq = speed; 461 wh.sample_fq = speed;
465 wh.byte_p_sec = speed * channels * resolution/8; 462 wh.byte_p_sec = speed * channels * resolution/8;
466 wh.byte_p_spl = channels * (resolution / 8); 463 wh.byte_p_spl = channels * (resolution / 8);
467 wh.bit_p_spl = resolution; 464 wh.bit_p_spl = resolution;
468 wh.data_chunk = DATA; 465 wh.data_chunk = DATA;
469 wh.data_length= 0; 466 wh.data_length= 0;
470 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 467 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
471 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 468 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
472 write (wav, &wh, sizeof(WaveHeader)); 469 write (wav, &wh, sizeof(WaveHeader));
473 470
474 return 1; 471 return 1;
475} 472}
476 473
477bool VMemo::record() { 474bool VMemo::record() {
478 length=0; 475 length=0;
479 int result, value; 476 int result, value;
480 QString msg; 477 QString msg;
481 msg.sprintf("Recording format %d", format); 478 msg.sprintf("Recording format %d", format);
482 qDebug(msg); 479 qDebug(msg);
483 Config config("Vmemo"); 480 Config config("Vmemo");
484 config.setGroup("Record"); 481 config.setGroup("Record");
485 int sRate=config.readNumEntry("SizeLimit", 30); 482 int sRate=config.readNumEntry("SizeLimit", 30);
486 if(sRate > 0) 483 if(sRate > 0)
487 t_timer->start( sRate * 1000+1000, TRUE); 484 t_timer->start( sRate * 1000+1000, TRUE);
488 485
489// if(systemZaurus) { 486// if(systemZaurus) {
490// } else { // 16 bit only capabilities 487// } else { // 16 bit only capabilities
491 488
492 msg.sprintf("Recording format other"); 489 msg.sprintf("Recording format other");
493 qDebug(msg); 490 qDebug(msg);
494 491
495 int bufsize=1024; 492 int bufsize=1024;
496 int bytesWritten=0; 493 int bytesWritten=0;
497 signed short sound[1024], monoBuffer[1024]; 494 signed short sound[1024], monoBuffer[1024];
498 char abuf[bufsize/2]; 495 char abuf[bufsize/2];
499 short sbuf[bufsize]; 496 short sbuf[bufsize];
500 Config vmCfg("Vmemo"); 497 Config vmCfg("Vmemo");
501 vmCfg.setGroup("Defaults"); 498 vmCfg.setGroup("Defaults");
502 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 499 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
503 500
504 while(recording) { 501 while(recording) {
505 502
506 if(useADPCM) 503 if(useADPCM)
507 result = read( dsp, sbuf, bufsize); // 8192 504 result = read( dsp, sbuf, bufsize); // 8192
508 else 505 else
509 result = read(dsp, sound, 1024); // 8192 506 result = read(dsp, sound, 1024); // 8192
510 if( result <= 0) { 507 if( result <= 0) {
511 perror("recording error "); 508 perror("recording error ");
512// qDebug(currentFileName); 509// qDebug(currentFileName);
513 QMessageBox::message(tr("Note"),tr("error recording")); 510 QMessageBox::message(tr("Note"),tr("error recording"));
514 recording=FALSE; 511 recording=FALSE;
515 break; 512 break;
516 return FALSE; 513 return FALSE;
517 } 514 }
518 515
519 if(useADPCM) { 516 if(useADPCM) {
520 adpcm_coder( sbuf, abuf, result/2, &encoder_state); 517 adpcm_coder( sbuf, abuf, result/2, &encoder_state);
521 bytesWritten = ::write(wav, abuf, result/4); 518 bytesWritten = ::write(wav, abuf, result/4);
522 519
523 } else { 520 } else {
524 for (int i = 0; i < result; i++) { //since Z is mono do normally 521 for (int i = 0; i < result; i++) { //since Z is mono do normally
525 monoBuffer[i] = sound[i]; 522 monoBuffer[i] = sound[i];
526 } 523 }
527 524
528 length+=write(wav, monoBuffer, result); 525 length+=write(wav, monoBuffer, result);
529 } 526 }
530 length +=bytesWritten; 527 length +=bytesWritten;
531 528
532 if(length<0) { 529 if(length<0) {
533 recording=false; 530 recording=false;
534 perror("dev/dsp's is a lookin' messy"); 531 perror("dev/dsp's is a lookin' messy");
535 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 532 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
536 break; 533 break;
537 return FALSE; 534 return FALSE;
538 } 535 }
539 // printf("%d\r",length); 536 // printf("%d\r",length);
540 // fflush(stdout); 537 // fflush(stdout);
541 qApp->processEvents(); 538 qApp->processEvents();
542 } 539 }
543 // qDebug("file has length of %d lasting %d seconds", 540 // qDebug("file has length of %d lasting %d seconds",
544 // length, (( length / speed) / channels) / 2 ); 541 // length, (( length / speed) / channels) / 2 );
545 // } 542 // }
546 543
547 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// 544 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<//
548 545
549 value = length+36; 546 value = length+36;
550 547
551 lseek(wav, 4, SEEK_SET); 548 lseek(wav, 4, SEEK_SET);
552 write(wav, &value, 4); 549 write(wav, &value, 4);
553 lseek(wav, 40, SEEK_SET); 550 lseek(wav, 40, SEEK_SET);
554 551
555 write(wav, &length, 4); 552 write(wav, &length, 4);
556 553
557 track.close(); 554 track.close();
558 qDebug("Track closed"); 555 qDebug("Track closed");
559 556
560 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 557 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
561 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 558 perror("ioctl(\"SNDCTL_DSP_RESET\")");
562 559
563 ::close(dsp); 560 ::close(dsp);
564 561
565 Config cfgO("OpieRec"); 562 Config cfgO("OpieRec");
566 cfgO.setGroup("Sounds"); 563 cfgO.setGroup("Sounds");
567 564
568 int nFiles = cfgO.readNumEntry( "NumberofFiles",0); 565 int nFiles = cfgO.readNumEntry( "NumberofFiles",0);
569 566
570 QString currentFileName = fileName; 567 QString currentFileName = fileName;
571 QString currentFile = "vm_"+ date; 568 QString currentFile = "vm_"+ date;
572 569
573 float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; 570 float numberOfRecordedSeconds=(float) length / (float)speed * (float)2;
574 571
575 cfgO.writeEntry( "NumberofFiles", nFiles + 1); 572 cfgO.writeEntry( "NumberofFiles", nFiles + 1);
576 cfgO.writeEntry( QString::number( nFiles + 1), currentFile); 573 cfgO.writeEntry( QString::number( nFiles + 1), currentFile);
577 cfgO.writeEntry( currentFile, currentFileName); 574 cfgO.writeEntry( currentFile, currentFileName);
578 575
579 QString time; 576 QString time;
580 time.sprintf("%.2f", numberOfRecordedSeconds); 577 time.sprintf("%.2f", numberOfRecordedSeconds);
581 cfgO.writeEntry( currentFileName, time ); 578 cfgO.writeEntry( currentFileName, time );
582 // qDebug("writing config numberOfRecordedSeconds "+time); 579 // qDebug("writing config numberOfRecordedSeconds "+time);
583 580
584 cfgO.write(); 581 cfgO.write();
585 582
586 qDebug("done recording "+fileName); 583 qDebug("done recording "+fileName);
587 584
588 Config cfg("qpe"); 585 Config cfg("qpe");
589 cfg.setGroup("Volume"); 586 cfg.setGroup("Volume");
590 QString foo = cfg.readEntry("Mute","TRUE"); 587 QString foo = cfg.readEntry("Mute","TRUE");
591 if(foo.find("TRUE",0,TRUE) != -1) 588 if(foo.find("TRUE",0,TRUE) != -1)
592 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute 589 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute
593return TRUE; 590return TRUE;
594} 591}
595 592
596int VMemo::setToggleButton(int tog) { 593int VMemo::setToggleButton(int tog) {
597 594
598 for( int i=0; i < 10;i++) { 595 for( int i=0; i < 10;i++) {
599 switch (tog) { 596 switch (tog) {
600 case 0: 597 case 0:
601 return -1; 598 return -1;
602 break; 599 break;
603 case 1: 600 case 1:
604 return 0; 601 return 0;
605 break; 602 break;
606 case 2: 603 case 2:
607 return Key_F24; //was Escape 604 return Key_F24; //was Escape
608 break; 605 break;
609 case 3: 606 case 3:
610 return Key_Space; 607 return Key_Space;
611 break; 608 break;
612 case 4: 609 case 4:
613 return Key_F12; 610 return Key_F12;
614 break; 611 break;
615 case 5: 612 case 5:
616 return Key_F9; 613 return Key_F9;
617 break; 614 break;
618 case 6: 615 case 6:
619 return Key_F10; 616 return Key_F10;
620 break; 617 break;
621 case 7: 618 case 7:
622 return Key_F11; 619 return Key_F11;
623 break; 620 break;
624 case 8: 621 case 8:
625 return Key_F13; 622 return Key_F13;
626 break; 623 break;
627 }; 624 };
628 } 625 }
629 return -1; 626 return -1;
630} 627}
631 628
632void VMemo::timerBreak() { 629void VMemo::timerBreak() {
633 //stop 630 //stop
634 stopRecording(); 631 stopRecording();
635 QMessageBox::message("Vmemo","Vmemo recording has ended"); 632 QMessageBox::message("Vmemo","Vmemo recording has ended");
636} 633}