summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-23 22:33:01 (UTC)
committer mickeyl <mickeyl>2003-04-23 22:33:01 (UTC)
commit545bc71ee282f93b993ae680fbe9ec135162dd21 (patch) (unidiff)
treeba23be7854b2bc017130b7e9814d2e0815292553
parent79b22a18f68b5f39bc14eb28a175d22208d6853a (diff)
downloadopie-545bc71ee282f93b993ae680fbe9ec135162dd21.zip
opie-545bc71ee282f93b993ae680fbe9ec135162dd21.tar.gz
opie-545bc71ee282f93b993ae680fbe9ec135162dd21.tar.bz2
add customization of output folder and filename
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
@@ -22,15 +22,17 @@
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>
@@ -50,17 +52,20 @@ using namespace Opie;
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 );
@@ -110,12 +115,15 @@ void CameraMainWindow::init()
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 );
@@ -126,17 +134,17 @@ void CameraMainWindow::init()
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
@@ -145,23 +153,33 @@ void CameraMainWindow::init()
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 )
@@ -228,21 +246,33 @@ void CameraMainWindow::showContextMenu()
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
@@ -304,20 +334,73 @@ void CameraMainWindow::flipMenuItemClicked( QAction* a )
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();
@@ -334,13 +417,25 @@ void CameraMainWindow::shutterClicked()
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 {
@@ -403,13 +498,18 @@ void CameraMainWindow::stopVideoCapture()
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
@@ -517,15 +617,20 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o
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
@@ -548,8 +653,12 @@ void CameraMainWindow::doSomething()
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
@@ -45,13 +45,16 @@ class CameraMainWindow: public QMainWindow
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();
@@ -60,34 +63,39 @@ class CameraMainWindow: public QMainWindow
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;