summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp125
-rw-r--r--noncore/multimedia/camera/mainwindow.h14
2 files changed, 128 insertions, 11 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 7e60e16..16ee8bc 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -4,81 +4,86 @@
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "mainwindow.h" 16#include "mainwindow.h"
17#include "previewwidget.h" 17#include "previewwidget.h"
18#include "zcameraio.h" 18#include "zcameraio.h"
19#include "imageio.h" 19#include "imageio.h"
20#include "avi.h" 20#include "avi.h"
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qaction.h> 23#include <qaction.h>
24#include <qvbox.h> 24#include <qvbox.h>
25#include <qcombobox.h> 25#include <qcombobox.h>
26#include <qcursor.h> 26#include <qcursor.h>
27#include <qdatastream.h> 27#include <qdatastream.h>
28#include <qdir.h>
28#include <qfile.h> 29#include <qfile.h>
29#include <qimage.h> 30#include <qimage.h>
30#include <qlabel.h> 31#include <qlabel.h>
32#include <qlineedit.h>
31#include <qpopupmenu.h> 33#include <qpopupmenu.h>
32#include <qprogressbar.h> 34#include <qprogressbar.h>
33#include <qpushbutton.h> 35#include <qpushbutton.h>
34#include <qmessagebox.h> 36#include <qmessagebox.h>
35#include <qlayout.h> 37#include <qlayout.h>
36#include <qdirectpainter_qws.h> 38#include <qdirectpainter_qws.h>
37#include <qpe/global.h> 39#include <qpe/global.h>
38#include <qpe/resource.h> 40#include <qpe/resource.h>
39#include <qpe/qcopenvelope_qws.h> 41#include <qpe/qcopenvelope_qws.h>
40#include <opie/ofiledialog.h> 42#include <opie/ofiledialog.h>
41#include <opie/odevice.h> 43#include <opie/odevice.h>
42using namespace Opie; 44using namespace Opie;
43#include <opie2/odebug.h> 45#include <opie2/odebug.h>
44 46
45#include <assert.h> 47#include <assert.h>
46#include <sys/types.h> 48#include <sys/types.h>
47#include <sys/stat.h> 49#include <sys/stat.h>
48#include <fcntl.h> 50#include <fcntl.h>
49#include <string.h> 51#include <string.h>
50#include <errno.h> 52#include <errno.h>
51#include <unistd.h> 53#include <unistd.h>
52 54
53#define CAPTUREFILE "/tmp/capture.dat" 55#define CAPTUREFILE "/tmp/capture.dat"
54#define OUTPUTFILE "/tmp/output.avi" 56#define OUTPUTFILE "/tmp/output.avi"
55 57
58#define OUTPUT_TO_CUSTOM 250
59#define OUTPUT_TO_DOCFOLDER 251
60
56CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 61CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
57 :QMainWindow( parent, name, f ), 62 :QMainWindow( parent, name, f ),
58 _rotation( 270 ), // FIXME: get this from current settings (ODevice?) 63 _rotation( 270 ), // FIXME: get this from current settings (ODevice?)
59 _capturing( false ), 64 _capturing( false ),
60 _pics( 0 ), _videos( 0 ) 65 _pics( 1 ), _videos( 1 )
61{ 66{
62 #ifdef QT_NO_DEBUG 67 #ifdef QT_NO_DEBUG
63 if ( !ZCameraIO::instance()->isOpen() ) 68 if ( !ZCameraIO::instance()->isOpen() )
64 { 69 {
65 QVBox* v = new QVBox( this ); 70 QVBox* v = new QVBox( this );
66 v->setMargin( 10 ); 71 v->setMargin( 10 );
67 QLabel* l1 = new QLabel( v ); 72 QLabel* l1 = new QLabel( v );
68 l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); 73 l1->setPixmap( Resource::loadPixmap( "camera/error" ) );
69 QLabel* l2 = new QLabel( v ); 74 QLabel* l2 = new QLabel( v );
70 l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" 75 l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>"
71 "* Is the sharpzdc_cs module loaded ?<br>" 76 "* Is the sharpzdc_cs module loaded ?<br>"
72 "* Is /dev/sharpzdc read/writable ?<p>" ); 77 "* Is /dev/sharpzdc read/writable ?<p>" );
73 connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) ); 78 connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) );
74 setCentralWidget( v ); 79 setCentralWidget( v );
75 return; 80 return;
76 } 81 }
77 #endif 82 #endif
78 83
79 init(); 84 init();
80 85
81 _rotation = 270; //TODO: grab these from the actual settings 86 _rotation = 270; //TODO: grab these from the actual settings
82 87
83 preview = new PreviewWidget( this, "camera preview widget" ); 88 preview = new PreviewWidget( this, "camera preview widget" );
84 //setCentralWidget( preview ); <--- don't do this! 89 //setCentralWidget( preview ); <--- don't do this!
@@ -92,94 +97,107 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags
92 97
93 connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); 98 connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) );
94 99
95 connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); 100 connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) );
96 101
97 updateCaption(); 102 updateCaption();
98 103
99}; 104};
100 105
101 106
102CameraMainWindow::~CameraMainWindow() 107CameraMainWindow::~CameraMainWindow()
103{ 108{
104} 109}
105 110
106 111
107void CameraMainWindow::init() 112void CameraMainWindow::init()
108{ 113{
109 // TODO: Save this stuff in config 114 // TODO: Save this stuff in config
110 flip = 'A'; // auto 115 flip = 'A'; // auto
111 quality = 50; 116 quality = 50;
112 zoom = 1; 117 zoom = 1;
113 captureX = 480; 118 captureX = 480;
114 captureY = 640; 119 captureY = 640;
115 captureFormat = "JPEG"; 120 captureFormat = "JPEG";
121 outputTo = "Documents Folder";
122 prefix = "Untitled";
123 appendSettings = true;
116 124
117 resog = new QActionGroup( 0, "reso", true ); 125 resog = new QActionGroup( 0, "reso", true );
118 resog->setToggleAction( true ); 126 resog->setToggleAction( true );
119 new QAction( " 64 x 48", 0, 0, resog, 0, true ); 127 new QAction( " 64 x 48", 0, 0, resog, 0, true );
120 new QAction( "128 x 96", 0, 0, resog, 0, true ); 128 new QAction( "128 x 96", 0, 0, resog, 0, true );
121 new QAction( "192 x 144", 0, 0, resog, 0, true ); 129 new QAction( "192 x 144", 0, 0, resog, 0, true );
122 new QAction( "256 x 192", 0, 0, resog, 0, true ); 130 new QAction( "256 x 192", 0, 0, resog, 0, true );
123 new QAction( "320 x 240", 0, 0, resog, 0, true ); 131 new QAction( "320 x 240", 0, 0, resog, 0, true );
124 new QAction( "384 x 288", 0, 0, resog, 0, true ); 132 new QAction( "384 x 288", 0, 0, resog, 0, true );
125 new QAction( "448 x 336", 0, 0, resog, 0, true ); 133 new QAction( "448 x 336", 0, 0, resog, 0, true );
126 new QAction( "512 x 384", 0, 0, resog, 0, true ); 134 new QAction( "512 x 384", 0, 0, resog, 0, true );
127 new QAction( "576 x 432", 0, 0, resog, 0, true ); 135 new QAction( "576 x 432", 0, 0, resog, 0, true );
128 ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true ); 136 ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true );
129 137
130 qualityg = new QActionGroup( 0, "quality", true ); 138 qualityg = new QActionGroup( 0, "quality", true );
131 qualityg->setToggleAction( true ); 139 qualityg->setToggleAction( true );
132 new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); 140 new QAction( " 0 (&minimal)", 0, 0, qualityg, 0, true );
133 new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); 141 new QAction( " 25 (&low)", 0, 0, qualityg, 0, true );
134 ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); 142 ( new QAction( " 50 (&good)", 0, 0, qualityg, 0, true ) )->setOn( true );
135 new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); 143 new QAction( " 75 (&better)", 0, 0, qualityg, 0, true );
136 new QAction( "100 (best)", 0, 0, qualityg, 0, true ); 144 new QAction( "100 (bes&t)", 0, 0, qualityg, 0, true );
137 145
138 zoomg = new QActionGroup( 0, "zoom", true ); 146 zoomg = new QActionGroup( 0, "zoom", true );
139 zoomg->setToggleAction( true ); 147 zoomg->setToggleAction( true );
140 ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true ); 148 ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true );
141 new QAction( "x 2", 0, 0, zoomg, 0, true ); 149 new QAction( "x 2", 0, 0, zoomg, 0, true );
142 150
143 flipg = new QActionGroup( 0, "flip", true ); 151 flipg = new QActionGroup( 0, "flip", true );
144 flipg->setToggleAction( true ); 152 flipg->setToggleAction( true );
145 ( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true ); 153 ( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true );
146 new QAction( "0 (always off)", 0, 0, flipg, 0, true ); 154 new QAction( "0 (always off)", 0, 0, flipg, 0, true );
147 new QAction( "X (always horizontal)", 0, 0, flipg, 0, true ); 155 new QAction( "X (always horizontal)", 0, 0, flipg, 0, true );
148 new QAction( "Y (always vertical)", 0, 0, flipg, 0, true ); 156 new QAction( "Y (always vertical)", 0, 0, flipg, 0, true );
149 new QAction( "* (always both)", 0, 0, flipg, 0, true ); 157 new QAction( "* (always both)", 0, 0, flipg, 0, true );
150 158
159 outputTog = new QActionGroup( 0, "output", true );
160 outputTog->setToggleAction( true );
161 new QAction( "/tmp", 0, 0, outputTog, 0, true );
162 new QAction( "/mnt/card/", 0, 0, outputTog, 0, true );
163 new QAction( "/mnt/sd/", 0, 0, outputTog, 0, true );
164 docfolder = new QAction( "Documents Folder", 0, 0, outputTog, 0, true );
165 docfolder->setOn( true );
166 custom = new QAction( "&Custom...", 0, 0, outputTog, 0, true );
167
151 outputg = new QActionGroup( 0, "output", true ); 168 outputg = new QActionGroup( 0, "output", true );
152 outputg->setToggleAction( true ); 169 outputg->setToggleAction( true );
153 ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); 170 ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true );
154 new QAction( "PNG", 0, 0, outputg, 0, true ); 171 new QAction( "PNG", 0, 0, outputg, 0, true );
155 new QAction( "BMP", 0, 0, outputg, 0, true ); 172 new QAction( "BMP", 0, 0, outputg, 0, true );
156 new QAction( "AVI", 0, 0, outputg, 0, true ); 173 new QAction( "AVI", 0, 0, outputg, 0, true );
157 174
158 connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); 175 connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) );
159 connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); 176 connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) );
160 connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); 177 connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) );
161 connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) ); 178 connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) );
179 connect( outputTog, SIGNAL( selected(QAction*) ), this, SLOT( outputToMenuItemClicked(QAction*) ) );
162 connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); 180 connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) );
163 181
164} 182}
165 183
166 184
167void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) 185void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data )
168{ 186{
169 int _newrotation; 187 int _newrotation;
170 188
171 QDataStream stream( data, IO_ReadOnly ); 189 QDataStream stream( data, IO_ReadOnly );
172 odebug << "received system message: " << msg << oendl; 190 odebug << "received system message: " << msg << oendl;
173 if ( msg == "setCurrentRotation(int)" ) 191 if ( msg == "setCurrentRotation(int)" )
174 { 192 {
175 stream >> _newrotation; 193 stream >> _newrotation;
176 odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl; 194 odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl;
177 195
178 switch ( _newrotation ) 196 switch ( _newrotation )
179 { 197 {
180 case 270: preview->resize( QSize( 240, 288 ) ); break; 198 case 270: preview->resize( QSize( 240, 288 ) ); break;
181 case 180: preview->resize( QSize( 320, 208 ) ); break; 199 case 180: preview->resize( QSize( 320, 208 ) ); break;
182 default: QMessageBox::warning( this, "opie-camera", 200 default: QMessageBox::warning( this, "opie-camera",
183 "This rotation is not supported.\n" 201 "This rotation is not supported.\n"
184 "Supported are 180° and 270°" ); 202 "Supported are 180° and 270°" );
185 } 203 }
@@ -210,57 +228,69 @@ void CameraMainWindow::changeZoom( int zoom )
210 } 228 }
211 229
212 ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); 230 ZCameraIO::instance()->setCaptureFrame( 240, 160, z );
213} 231}
214 232
215 233
216void CameraMainWindow::showContextMenu() 234void CameraMainWindow::showContextMenu()
217{ 235{
218 QPopupMenu reso; 236 QPopupMenu reso;
219 reso.setCheckable( true ); 237 reso.setCheckable( true );
220 resog->addTo( &reso ); 238 resog->addTo( &reso );
221 239
222 QPopupMenu quality; 240 QPopupMenu quality;
223 quality.setCheckable( true ); 241 quality.setCheckable( true );
224 qualityg->addTo( &quality ); 242 qualityg->addTo( &quality );
225 243
226 QPopupMenu flip; 244 QPopupMenu flip;
227 flip.setCheckable( true ); 245 flip.setCheckable( true );
228 flipg->addTo( &flip ); 246 flipg->addTo( &flip );
229 247
230 QPopupMenu zoom; 248 QPopupMenu zoom;
231 zoom.setCheckable( true ); 249 zoom.setCheckable( true );
232 zoomg->addTo( &zoom ); 250 zoomg->addTo( &zoom );
233 251
252 QPopupMenu prefix;
253 prefix.insertItem( "&Choose...", this, SLOT( prefixItemChoosen() ) );
254 int id = prefix.insertItem( "&Append Settings", this, SLOT( appendSettingsChoosen() ) );
255 prefix.setItemChecked( id, appendSettings );
256
257 QPopupMenu outputTo;
258 outputTo.setCheckable( true );
259 outputTog->addTo( &outputTo );
260
234 QPopupMenu output; 261 QPopupMenu output;
235 output.setCheckable( true ); 262 output.setCheckable( true );
236 outputg->addTo( &output ); 263 outputg->addTo( &output );
237 264
238 QPopupMenu m( this ); 265 QPopupMenu m( this );
239 m.insertItem( "&Resolution", &reso ); 266 m.insertItem( "&Resolution", &reso );
240 m.insertItem( "&Zoom", &zoom ); 267 m.insertItem( "&Zoom", &zoom );
241 m.insertItem( "&Flip", &flip ); 268 m.insertItem( "&Flip", &flip );
242 m.insertItem( "&Quality", &quality ); 269 m.insertItem( "&Quality", &quality );
270 m.insertSeparator();
271 m.insertItem( "&Prefix", &prefix );
272 m.insertItem( "Output &To", &outputTo );
243 m.insertItem( "&Output As", &output ); 273 m.insertItem( "&Output As", &output );
244 274
245 #ifndef QT_NO_DEBUG 275 #ifndef QT_NO_DEBUG
246 m.insertItem( "&Debug!", this, SLOT( doSomething() ) ); 276 m.insertItem( "&Debug!", this, SLOT( doSomething() ) );
247 #endif 277 #endif
248 278
249 m.exec( QCursor::pos() ); 279 m.exec( QCursor::pos() );
250} 280}
251 281
252 282
253void CameraMainWindow::resoMenuItemClicked( QAction* a ) 283void CameraMainWindow::resoMenuItemClicked( QAction* a )
254{ 284{
255 switch ( _rotation ) 285 switch ( _rotation )
256 { 286 {
257 case 270: 287 case 270:
258 captureY = a->text().left(3).toInt(); 288 captureY = a->text().left(3).toInt();
259 captureX = a->text().right(3).toInt(); 289 captureX = a->text().right(3).toInt();
260 break; 290 break;
261 case 180: 291 case 180:
262 captureX = a->text().left(3).toInt(); 292 captureX = a->text().left(3).toInt();
263 captureY = a->text().right(3).toInt(); 293 captureY = a->text().right(3).toInt();
264 break; 294 break;
265 default: QMessageBox::warning( this, "opie-camera", 295 default: QMessageBox::warning( this, "opie-camera",
266 "This rotation is not supported.\n" 296 "This rotation is not supported.\n"
@@ -286,79 +316,144 @@ void CameraMainWindow::zoomMenuItemClicked( QAction* a )
286 ZCameraIO::instance()->setZoom( zoom ); 316 ZCameraIO::instance()->setZoom( zoom );
287 updateCaption(); 317 updateCaption();
288} 318}
289 319
290 320
291void CameraMainWindow::flipMenuItemClicked( QAction* a ) 321void CameraMainWindow::flipMenuItemClicked( QAction* a )
292{ 322{
293 flip = QString( a->text().at(0) ); 323 flip = QString( a->text().at(0) );
294 odebug << "Flip now: " << flip << oendl; 324 odebug << "Flip now: " << flip << oendl;
295 if ( flip == "A" ) 325 if ( flip == "A" )
296 ZCameraIO::instance()->setFlip( ZCameraIO::AUTOMATICFLIP ); 326 ZCameraIO::instance()->setFlip( ZCameraIO::AUTOMATICFLIP );
297 else if ( flip == "0" ) 327 else if ( flip == "0" )
298 ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP ); 328 ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP );
299 else if ( flip == "X" ) 329 else if ( flip == "X" )
300 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP ); 330 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP );
301 else if ( flip == "Y" ) 331 else if ( flip == "Y" )
302 ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP ); 332 ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP );
303 else if ( flip == "*" ) 333 else if ( flip == "*" )
304 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP ); 334 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP );
305 335
306 updateCaption(); 336 updateCaption();
307} 337}
308 338
309 339
340void CameraMainWindow::outputToMenuItemClicked( QAction* a )
341{
342 if ( a->text() == "&Custom..." )
343 {
344 QMap<QString, QStringList> map;
345 map.insert( tr("All"), QStringList() );
346 QStringList text;
347 text << "text/*";
348 map.insert(tr("Text"), text );
349 text << "*";
350 map.insert(tr("All"), text );
351
352 QString str;
353 str = OFileDialog::getSaveFileName( 2, "/", QString::null, map );
354 if ( str.isEmpty() || !QFileInfo(str).isDir() )
355 {
356 docfolder->setOn( true );
357 outputTo = "Documents Folder";
358 }
359 else
360 {
361 outputTo = str;
362 }
363 }
364 else
365 {
366 outputTo = a->text();
367 }
368 odebug << "Output to now: " << outputTo << oendl;
369}
370
371
310void CameraMainWindow::outputMenuItemClicked( QAction* a ) 372void CameraMainWindow::outputMenuItemClicked( QAction* a )
311{ 373{
312 captureFormat = a->text(); 374 captureFormat = a->text();
313 odebug << "Output format now: " << captureFormat << oendl; 375 odebug << "Output format now: " << captureFormat << oendl;
314 updateCaption(); 376 updateCaption();
315} 377}
316 378
317 379
380void CameraMainWindow::prefixItemChoosen()
381{
382 QDialog* d = new QDialog( this, "dialog", true );
383 d->setCaption( "Enter Prefix..." );
384 QVBoxLayout* v = new QVBoxLayout( d );
385 QLineEdit* le = new QLineEdit( prefix, d );
386 v->addWidget( le );
387 le->setFixedWidth( 150 ); //FIXME: 'tis a bit dirty
388 if ( d->exec() == QDialog::Accepted )
389 prefix = le->text();
390 odebug << "Prefix now: " << prefix << oendl;
391}
392
393
394void CameraMainWindow::appendSettingsChoosen()
395{
396 appendSettings = !appendSettings;
397 odebug << "appendSettings now: " << appendSettings << oendl;
398}
399
400
318void CameraMainWindow::shutterClicked() 401void CameraMainWindow::shutterClicked()
319{ 402{
320 if ( captureFormat != "AVI" ) // capture one photo per shutterClick 403 if ( captureFormat != "AVI" ) // capture one photo per shutterClick
321 { 404 {
322 Global::statusMessage( "CAPTURING..." ); 405 Global::statusMessage( "CAPTURING..." );
323 qApp->processEvents(); 406 qApp->processEvents();
324 407
325 odebug << "Shutter has been pressed" << oendl; 408 odebug << "Shutter has been pressed" << oendl;
326 ODevice::inst()->touchSound(); 409 ODevice::inst()->touchSound();
327 410
328 performCapture( captureFormat ); 411 performCapture( captureFormat );
329 } 412 }
330 else // capture video! start with one shutter click and stop with the next 413 else // capture video! start with one shutter click and stop with the next
331 { 414 {
332 !_capturing ? startVideoCapture() : stopVideoCapture(); 415 !_capturing ? startVideoCapture() : stopVideoCapture();
333 } 416 }
334} 417}
335 418
336 419
337void CameraMainWindow::performCapture( const QString& format ) 420void CameraMainWindow::performCapture( const QString& format )
338{ 421{
339 QString name; 422 QString name;
340 name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); 423
424 if ( outputTo == "Documents Folder" )
425 name.sprintf( "%s/Documents/image/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() );
426 else
427 name = outputTo;
428
429 name.append( prefix );
430 if ( appendSettings )
431 {
432 name.append( QString().sprintf( "_%d_%d_q%d", captureX, captureY, quality ) );
433 }
434 name.append( QString().sprintf( "-%d.%s", _pics++, (const char*) captureFormat.lower() ) );
435
341 QImage i; 436 QImage i;
342 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); 437 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i );
343 QImage im = i.convertDepth( 32 ); 438 QImage im = i.convertDepth( 32 );
344 bool result = im.save( name, format, quality ); 439 bool result = im.save( name, format, quality );
345 if ( !result ) 440 if ( !result )
346 { 441 {
347 oerr << "imageio-Problem while writing." << oendl; 442 oerr << "imageio-Problem while writing." << oendl;
348 Global::statusMessage( "Error!" ); 443 Global::statusMessage( "Error!" );
349 } 444 }
350 else 445 else
351 { 446 {
352 odebug << captureFormat << "-image has been successfully captured" << oendl; 447 odebug << captureFormat << "-image has been successfully captured" << oendl;
353 Global::statusMessage( "Ok." ); 448 Global::statusMessage( "Ok." );
354 } 449 }
355} 450}
356 451
357 452
358void CameraMainWindow::startVideoCapture() 453void CameraMainWindow::startVideoCapture()
359{ 454{
360 //ODevice::inst()->touchSound(); 455 //ODevice::inst()->touchSound();
361 ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow ); 456 ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow );
362 457
363 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC ); 458 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC );
364 if ( _capturefd == -1 ) 459 if ( _capturefd == -1 )
@@ -385,49 +480,54 @@ void CameraMainWindow::timerEvent( QTimerEvent* )
385 odebug << "timer event in CameraMainWindow without capturing video ?" << oendl; 480 odebug << "timer event in CameraMainWindow without capturing video ?" << oendl;
386 return; 481 return;
387 } 482 }
388 483
389 odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl; 484 odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl;
390 485
391 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); 486 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf );
392 _videopics++; 487 _videopics++;
393 ::write( _capturefd, _capturebuf, captureX*captureY*2 ); 488 ::write( _capturefd, _capturebuf, captureX*captureY*2 );
394 setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d", 489 setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d",
395 captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) ); 490 captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) );
396} 491}
397 492
398 493
399void CameraMainWindow::stopVideoCapture() 494void CameraMainWindow::stopVideoCapture()
400{ 495{
401 killTimers(); 496 killTimers();
402 //ODevice::inst()->touchSound(); 497 //ODevice::inst()->touchSound();
403 ODevice::inst()->setLedState( Led_Mail, Led_Off ); 498 ODevice::inst()->setLedState( Led_Mail, Led_Off );
404 _capturing = false; 499 _capturing = false;
405 updateCaption(); 500 updateCaption();
406 ::close( _capturefd ); 501 ::close( _capturefd );
407 _framerate = 1000.0 / (_time.elapsed()/_videopics); 502 _framerate = 1000.0 / (_time.elapsed()/_videopics);
408 503
409 postProcessVideo( CAPTUREFILE, QString().sprintf( "/tmp/video-%d_%d_%d_q%d-%dfps.avi", _videos++, captureX, captureY, quality, _framerate ) ); 504 QString name( outputTo );
505 name.append( "/prefix" );
506 if ( appendSettings )
507 name.append( QString().sprintf( "_%d_%d_q%d_%dfps", captureX, captureY, quality, _framerate ) );
508 name.append( QString().sprintf( "-%d.%s", _videos++, (const char*) captureFormat.lower() ) );
509 postProcessVideo( CAPTUREFILE, name );
410 510
411 #ifndef QT_NO_DEBUG 511 #ifndef QT_NO_DEBUG
412 preview->setRefreshingRate( 1500 ); 512 preview->setRefreshingRate( 1500 );
413 #else 513 #else
414 preview->setRefreshingRate( 200 ); 514 preview->setRefreshingRate( 200 );
415 #endif 515 #endif
416 516
417 //delete[] _capturebuf; //FIXME: close memory leak 517 //delete[] _capturebuf; //FIXME: close memory leak
418} 518}
419 519
420void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile ) 520void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile )
421{ 521{
422 preview->setRefreshingRate( 0 ); 522 preview->setRefreshingRate( 0 );
423 523
424 /* 524 /*
425 unsigned char buf[153600]; 525 unsigned char buf[153600];
426 526
427 int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY ); 527 int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY );
428 ::read( fd, &buf, 153600 ); 528 ::read( fd, &buf, 153600 );
429 QImage i; 529 QImage i;
430 bufferToImage( 240, 320, (unsigned char*) &buf, &i ); 530 bufferToImage( 240, 320, (unsigned char*) &buf, &i );
431 QPixmap p; 531 QPixmap p;
432 p.convertFromImage( i ); 532 p.convertFromImage( i );
433 preview->setPixmap( p ); 533 preview->setPixmap( p );
@@ -499,57 +599,66 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o
499 #ifndef QT_NO_DEBUG 599 #ifndef QT_NO_DEBUG
500 QString tmpfilename; 600 QString tmpfilename;
501 tmpfilename.sprintf( "/tmp/test/%04d.jpg", i ); 601 tmpfilename.sprintf( "/tmp/test/%04d.jpg", i );
502 #else 602 #else
503 QString tmpfilename( "/tmp/tempfile" ); 603 QString tmpfilename( "/tmp/tempfile" );
504 #endif 604 #endif
505 605
506 imageToFile( &image, tmpfilename, "JPEG", quality ); 606 imageToFile( &image, tmpfilename, "JPEG", quality );
507 607
508 QFile framefile( tmpfilename ); 608 QFile framefile( tmpfilename );
509 if ( !framefile.open( IO_ReadOnly ) ) 609 if ( !framefile.open( IO_ReadOnly ) )
510 { 610 {
511 oerr << "can't process file: %s" << strerror(errno) << oendl; 611 oerr << "can't process file: %s" << strerror(errno) << oendl;
512 return; // TODO: clean up temp ressources 612 return; // TODO: clean up temp ressources
513 } 613 }
514 614
515 int filesize = framefile.size(); 615 int filesize = framefile.size();
516 odebug << "filesize for frame " << i << " = " << filesize << oendl; 616 odebug << "filesize for frame " << i << " = " << filesize << oendl;
517 617
518 unsigned char* tempbuffer = new unsigned char[ filesize ]; 618 unsigned char* tempbuffer = new unsigned char[ filesize ];
519 framefile.readBlock( (char*) tempbuffer, filesize ); 619 framefile.readBlock( (char*) tempbuffer, filesize );
520 avi_add( outfd, tempbuffer, filesize ); 620 avi_add( outfd, tempbuffer, filesize );
521 delete tempbuffer; 621 delete tempbuffer;
522 framefile.close(); 622 framefile.close();
623
624 odebug << "deleting temporary capturefile " << infile << oendl;
625 ::close( infd );
626 QFile::remove( infile );
523 } 627 }
524 628
525 avi_end( outfd, captureX, captureY, _framerate ); 629 avi_end( outfd, captureX, captureY, _framerate );
630 ::close( outfd );
526 631
527 fr->hide(); 632 fr->hide();
528 delete fr; 633 delete fr;
529 634
530 updateCaption(); 635 updateCaption();
531 636
532} 637}
533 638
534 639
535void CameraMainWindow::updateCaption() 640void CameraMainWindow::updateCaption()
536{ 641{
537 if ( !_capturing ) 642 if ( !_capturing )
538 setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) ); 643 setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) );
539 else 644 else
540 setCaption( "Opie-Camera: => CAPTURING <=" ); 645 setCaption( "Opie-Camera: => CAPTURING <=" );
541} 646}
542 647
543 648
544#ifndef QT_NO_DEBUG 649#ifndef QT_NO_DEBUG
545void CameraMainWindow::doSomething() 650void CameraMainWindow::doSomething()
546{ 651{
547 captureX = 240; 652 captureX = 240;
548 captureY = 320; 653 captureY = 320;
549 _videopics = 50; 654 _videopics = 50;
550 _framerate = 5; 655 _framerate = 5;
551 postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat", 656 postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat",
552 "/tmp/output.avi" ); 657 "/tmp/output.avi" );
553} 658}
659#else
660void CameraMainWindow::doSomething()
661{
662}
554#endif 663#endif
555 664
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h
index 1d844da..451ad5f 100644
--- a/noncore/multimedia/camera/mainwindow.h
+++ b/noncore/multimedia/camera/mainwindow.h
@@ -27,73 +27,81 @@ class QActionGroup;
27class QIconSet; 27class QIconSet;
28class QTimerEvent; 28class QTimerEvent;
29class QToolButton; 29class QToolButton;
30class QLabel; 30class QLabel;
31class MainWindowBase; 31class MainWindowBase;
32class QCopChannel; 32class QCopChannel;
33class PreviewWidget; 33class PreviewWidget;
34 34
35class CameraMainWindow: public QMainWindow 35class CameraMainWindow: public QMainWindow
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 38
39 public: 39 public:
40 CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); 40 CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 );
41 virtual ~CameraMainWindow(); 41 virtual ~CameraMainWindow();
42 42
43 public slots: 43 public slots:
44 void changeZoom( int ); 44 void changeZoom( int );
45 void systemMessage( const QCString&, const QByteArray& ); 45 void systemMessage( const QCString&, const QByteArray& );
46 void showContextMenu(); 46 void showContextMenu();
47 void resoMenuItemClicked( QAction* ); 47 void resoMenuItemClicked( QAction* );
48 void qualityMenuItemClicked( QAction* ); 48 void qualityMenuItemClicked( QAction* );
49 void zoomMenuItemClicked( QAction* ); 49 void zoomMenuItemClicked( QAction* );
50 void flipMenuItemClicked( QAction* ); 50 void flipMenuItemClicked( QAction* );
51 void outputToMenuItemClicked( QAction* );
51 void outputMenuItemClicked( QAction* ); 52 void outputMenuItemClicked( QAction* );
53 void prefixItemChoosen();
54 void appendSettingsChoosen();
52 void shutterClicked(); 55 void shutterClicked();
53 56
54 void updateCaption(); 57 void updateCaption();
55 58
56 protected: 59 protected:
57 void init(); 60 void init();
58 void startVideoCapture(); 61 void startVideoCapture();
59 void stopVideoCapture(); 62 void stopVideoCapture();
60 void postProcessVideo( const QString&, const QString& ); 63 void postProcessVideo( const QString&, const QString& );
61 void performCapture( const QString& ); 64 void performCapture( const QString& );
62 65
63 virtual void timerEvent( QTimerEvent* ); 66 virtual void timerEvent( QTimerEvent* );
64 67
65 protected slots: 68 protected slots:
66 #ifndef QT_NO_DEBUG 69 void doSomething(); // solely for debugging purposes
67 //void doSomething(); // solely for debugging purposes
68 #endif
69 70
70 private: 71 private:
71 PreviewWidget* preview; 72 PreviewWidget* preview;
72 int _rotation; 73 int _rotation;
73 QCopChannel* _sysChannel; 74 QCopChannel* _sysChannel;
74 75
75 QActionGroup* resog; 76 QActionGroup* resog;
76 QActionGroup* qualityg; 77 QActionGroup* qualityg;
77 QActionGroup* zoomg; 78 QActionGroup* zoomg;
78 QActionGroup* flipg; 79 QActionGroup* flipg;
80 QActionGroup* outputTog;
81 QAction* custom;
82 QAction* docfolder;
79 QActionGroup* outputg; 83 QActionGroup* outputg;
80 84
81 QString flip; 85 QString flip;
82 int quality; 86 int quality;
83 int zoom; 87 int zoom;
84 int captureX; 88 int captureX;
85 int captureY; 89 int captureY;
86 QString captureFormat; 90 QString captureFormat;
87 91
92 QString outputTo;
93 QString prefix;
94 bool appendSettings;
95
88 bool _capturing; 96 bool _capturing;
89 int _pics; 97 int _pics;
90 int _videos; 98 int _videos;
91 99
92 QTime _time; 100 QTime _time;
93 int _videopics; 101 int _videopics;
94 int _capturefd; 102 int _capturefd;
95 int _framerate; 103 int _framerate;
96 unsigned char* _capturebuf; 104 unsigned char* _capturebuf;
97}; 105};
98 106
99#endif 107#endif