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
@@ -25,9 +25,11 @@
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>
@@ -53,11 +55,14 @@ using namespace Opie;
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() )
@@ -113,6 +118,9 @@ void CameraMainWindow::init()
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 );
@@ -129,11 +137,11 @@ void CameraMainWindow::init()
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 );
@@ -148,6 +156,15 @@ void CameraMainWindow::init()
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 );
@@ -159,6 +176,7 @@ void CameraMainWindow::init()
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}
@@ -231,6 +249,15 @@ void CameraMainWindow::showContextMenu()
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 );
@@ -240,6 +267,9 @@ void CameraMainWindow::showContextMenu()
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
@@ -307,6 +337,38 @@ void CameraMainWindow::flipMenuItemClicked( QAction* a )
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();
@@ -315,6 +377,27 @@ void CameraMainWindow::outputMenuItemClicked( QAction* a )
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
@@ -337,7 +420,19 @@ void CameraMainWindow::shutterClicked()
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 );
@@ -406,7 +501,12 @@ void CameraMainWindow::stopVideoCapture()
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 );
@@ -520,9 +620,14 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o
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;
@@ -551,5 +656,9 @@ void CameraMainWindow::doSomething()
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
@@ -48,7 +48,10 @@ class CameraMainWindow: public QMainWindow
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();
@@ -63,9 +66,7 @@ class CameraMainWindow: public QMainWindow
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;
@@ -76,6 +77,9 @@ class CameraMainWindow: public QMainWindow
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;
@@ -85,6 +89,10 @@ class CameraMainWindow: public QMainWindow
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;