-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 8 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 3 |
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 | ||
17 | using namespace Opie; | 17 | using namespace Opie; |
18 | 18 | ||
19 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) | 19 | BatteryStatus::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 | ||
43 | BatteryStatus::~BatteryStatus() | 43 | BatteryStatus::~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 | */ |
50 | bool BatteryStatus::getProcApmStatusIpaq() { | 50 | bool 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 | ||
122 | void BatteryStatus::updatePercent( int pc ) { | 122 | void BatteryStatus::updatePercent( int pc ) { |
123 | percent = pc; | 123 | percent = pc; |
124 | repaint(FALSE); | 124 | repaint(FALSE); |
125 | } | 125 | } |
126 | 126 | ||
127 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { | 127 | void 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 | ||
147 | void BatteryStatus::paintEvent( QPaintEvent * ) { | 147 | void 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,399 +1,396 @@ | |||
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 | ||
18 | extern "C" { | 15 | extern "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 | ||
30 | typedef struct _waveheader { | 27 | typedef 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 | ||
58 | struct adpcm_state encoder_state; | 55 | struct 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 | ||
73 | int seq = 0; | 70 | int seq = 0; |
74 | 71 | ||
75 | /* XPM */ | 72 | /* XPM */ |
76 | static char * vmemo_xpm[] = { | 73 | static 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 | ||
198 | VMemo::VMemo( QWidget *parent, const char *_name ) | 195 | VMemo::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 | ||
240 | VMemo::~VMemo() { | 237 | VMemo::~VMemo() { |
241 | } | 238 | } |
242 | 239 | ||
243 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 240 | void 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 | ||
258 | void VMemo::paintEvent( QPaintEvent* ) { | 255 | void 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 | ||
263 | void VMemo::mousePressEvent( QMouseEvent * me) { | 260 | void 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 | ||
277 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 274 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
278 | } | 275 | } |
279 | 276 | ||
280 | bool VMemo::startRecording() { | 277 | bool 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 | ||
368 | void VMemo::stopRecording() { | 365 | void 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 | ||
384 | int VMemo::openDSP() { | 381 | int 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 | ||