author | mickeyl <mickeyl> | 2003-04-23 22:33:01 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-23 22:33:01 (UTC) |
commit | 545bc71ee282f93b993ae680fbe9ec135162dd21 (patch) (side-by-side diff) | |
tree | ba23be7854b2bc017130b7e9814d2e0815292553 /noncore/multimedia/camera/mainwindow.cpp | |
parent | 79b22a18f68b5f39bc14eb28a175d22208d6853a (diff) | |
download | opie-545bc71ee282f93b993ae680fbe9ec135162dd21.zip opie-545bc71ee282f93b993ae680fbe9ec135162dd21.tar.gz opie-545bc71ee282f93b993ae680fbe9ec135162dd21.tar.bz2 |
add customization of output folder and filename
Diffstat (limited to 'noncore/multimedia/camera/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 125 |
1 files changed, 117 insertions, 8 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 @@ -16,27 +16,29 @@ #include "mainwindow.h" #include "previewwidget.h" #include "zcameraio.h" #include "imageio.h" #include "avi.h" #include <qapplication.h> #include <qaction.h> #include <qvbox.h> #include <qcombobox.h> #include <qcursor.h> #include <qdatastream.h> +#include <qdir.h> #include <qfile.h> #include <qimage.h> #include <qlabel.h> +#include <qlineedit.h> #include <qpopupmenu.h> #include <qprogressbar.h> #include <qpushbutton.h> #include <qmessagebox.h> #include <qlayout.h> #include <qdirectpainter_qws.h> #include <qpe/global.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <opie/ofiledialog.h> #include <opie/odevice.h> using namespace Opie; @@ -44,29 +46,32 @@ using namespace Opie; #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <errno.h> #include <unistd.h> #define CAPTUREFILE "/tmp/capture.dat" #define OUTPUTFILE "/tmp/output.avi" +#define OUTPUT_TO_CUSTOM 250 +#define OUTPUT_TO_DOCFOLDER 251 + CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) :QMainWindow( parent, name, f ), _rotation( 270 ), // FIXME: get this from current settings (ODevice?) _capturing( false ), - _pics( 0 ), _videos( 0 ) + _pics( 1 ), _videos( 1 ) { #ifdef QT_NO_DEBUG if ( !ZCameraIO::instance()->isOpen() ) { QVBox* v = new QVBox( this ); v->setMargin( 10 ); QLabel* l1 = new QLabel( v ); l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); QLabel* l2 = new QLabel( v ); l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" "* Is the sharpzdc_cs module loaded ?<br>" "* Is /dev/sharpzdc read/writable ?<p>" ); @@ -104,70 +109,83 @@ CameraMainWindow::~CameraMainWindow() } void CameraMainWindow::init() { // TODO: Save this stuff in config flip = 'A'; // auto quality = 50; zoom = 1; captureX = 480; captureY = 640; captureFormat = "JPEG"; + outputTo = "Documents Folder"; + prefix = "Untitled"; + appendSettings = true; resog = new QActionGroup( 0, "reso", true ); resog->setToggleAction( true ); new QAction( " 64 x 48", 0, 0, resog, 0, true ); new QAction( "128 x 96", 0, 0, resog, 0, true ); new QAction( "192 x 144", 0, 0, resog, 0, true ); new QAction( "256 x 192", 0, 0, resog, 0, true ); new QAction( "320 x 240", 0, 0, resog, 0, true ); new QAction( "384 x 288", 0, 0, resog, 0, true ); new QAction( "448 x 336", 0, 0, resog, 0, true ); new QAction( "512 x 384", 0, 0, resog, 0, true ); new QAction( "576 x 432", 0, 0, resog, 0, true ); ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true ); qualityg = new QActionGroup( 0, "quality", true ); qualityg->setToggleAction( true ); - new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); - new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); - ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); - new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); - new QAction( "100 (best)", 0, 0, qualityg, 0, true ); + new QAction( " 0 (&minimal)", 0, 0, qualityg, 0, true ); + new QAction( " 25 (&low)", 0, 0, qualityg, 0, true ); + ( new QAction( " 50 (&good)", 0, 0, qualityg, 0, true ) )->setOn( true ); + new QAction( " 75 (&better)", 0, 0, qualityg, 0, true ); + new QAction( "100 (bes&t)", 0, 0, qualityg, 0, true ); zoomg = new QActionGroup( 0, "zoom", true ); zoomg->setToggleAction( true ); ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true ); new QAction( "x 2", 0, 0, zoomg, 0, true ); flipg = new QActionGroup( 0, "flip", true ); flipg->setToggleAction( true ); ( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true ); new QAction( "0 (always off)", 0, 0, flipg, 0, true ); new QAction( "X (always horizontal)", 0, 0, flipg, 0, true ); new QAction( "Y (always vertical)", 0, 0, flipg, 0, true ); new QAction( "* (always both)", 0, 0, flipg, 0, true ); + outputTog = new QActionGroup( 0, "output", true ); + outputTog->setToggleAction( true ); + new QAction( "/tmp", 0, 0, outputTog, 0, true ); + new QAction( "/mnt/card/", 0, 0, outputTog, 0, true ); + new QAction( "/mnt/sd/", 0, 0, outputTog, 0, true ); + docfolder = new QAction( "Documents Folder", 0, 0, outputTog, 0, true ); + docfolder->setOn( true ); + custom = new QAction( "&Custom...", 0, 0, outputTog, 0, true ); + outputg = new QActionGroup( 0, "output", true ); outputg->setToggleAction( true ); ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); new QAction( "PNG", 0, 0, outputg, 0, true ); new QAction( "BMP", 0, 0, outputg, 0, true ); new QAction( "AVI", 0, 0, outputg, 0, true ); connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) ); + connect( outputTog, SIGNAL( selected(QAction*) ), this, SLOT( outputToMenuItemClicked(QAction*) ) ); connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); } void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) { int _newrotation; QDataStream stream( data, IO_ReadOnly ); odebug << "received system message: " << msg << oendl; if ( msg == "setCurrentRotation(int)" ) @@ -222,33 +240,45 @@ void CameraMainWindow::showContextMenu() QPopupMenu quality; quality.setCheckable( true ); qualityg->addTo( &quality ); QPopupMenu flip; flip.setCheckable( true ); flipg->addTo( &flip ); QPopupMenu zoom; zoom.setCheckable( true ); zoomg->addTo( &zoom ); + QPopupMenu prefix; + prefix.insertItem( "&Choose...", this, SLOT( prefixItemChoosen() ) ); + int id = prefix.insertItem( "&Append Settings", this, SLOT( appendSettingsChoosen() ) ); + prefix.setItemChecked( id, appendSettings ); + + QPopupMenu outputTo; + outputTo.setCheckable( true ); + outputTog->addTo( &outputTo ); + QPopupMenu output; output.setCheckable( true ); outputg->addTo( &output ); QPopupMenu m( this ); m.insertItem( "&Resolution", &reso ); m.insertItem( "&Zoom", &zoom ); m.insertItem( "&Flip", &flip ); m.insertItem( "&Quality", &quality ); + m.insertSeparator(); + m.insertItem( "&Prefix", &prefix ); + m.insertItem( "Output &To", &outputTo ); m.insertItem( "&Output As", &output ); #ifndef QT_NO_DEBUG m.insertItem( "&Debug!", this, SLOT( doSomething() ) ); #endif m.exec( QCursor::pos() ); } void CameraMainWindow::resoMenuItemClicked( QAction* a ) { @@ -298,55 +328,120 @@ void CameraMainWindow::flipMenuItemClicked( QAction* a ) ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP ); else if ( flip == "X" ) ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP ); else if ( flip == "Y" ) ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP ); else if ( flip == "*" ) ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP ); updateCaption(); } +void CameraMainWindow::outputToMenuItemClicked( QAction* a ) +{ + if ( a->text() == "&Custom..." ) + { + QMap<QString, QStringList> map; + map.insert( tr("All"), QStringList() ); + QStringList text; + text << "text/*"; + map.insert(tr("Text"), text ); + text << "*"; + map.insert(tr("All"), text ); + + QString str; + str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); + if ( str.isEmpty() || !QFileInfo(str).isDir() ) + { + docfolder->setOn( true ); + outputTo = "Documents Folder"; + } + else + { + outputTo = str; + } + } + else + { + outputTo = a->text(); + } + odebug << "Output to now: " << outputTo << oendl; +} + + void CameraMainWindow::outputMenuItemClicked( QAction* a ) { captureFormat = a->text(); odebug << "Output format now: " << captureFormat << oendl; updateCaption(); } +void CameraMainWindow::prefixItemChoosen() +{ + QDialog* d = new QDialog( this, "dialog", true ); + d->setCaption( "Enter Prefix..." ); + QVBoxLayout* v = new QVBoxLayout( d ); + QLineEdit* le = new QLineEdit( prefix, d ); + v->addWidget( le ); + le->setFixedWidth( 150 ); //FIXME: 'tis a bit dirty + if ( d->exec() == QDialog::Accepted ) + prefix = le->text(); + odebug << "Prefix now: " << prefix << oendl; +} + + +void CameraMainWindow::appendSettingsChoosen() +{ + appendSettings = !appendSettings; + odebug << "appendSettings now: " << appendSettings << oendl; +} + + void CameraMainWindow::shutterClicked() { if ( captureFormat != "AVI" ) // capture one photo per shutterClick { Global::statusMessage( "CAPTURING..." ); qApp->processEvents(); odebug << "Shutter has been pressed" << oendl; ODevice::inst()->touchSound(); performCapture( captureFormat ); } else // capture video! start with one shutter click and stop with the next { !_capturing ? startVideoCapture() : stopVideoCapture(); } } void CameraMainWindow::performCapture( const QString& format ) { QString name; - name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); + + if ( outputTo == "Documents Folder" ) + name.sprintf( "%s/Documents/image/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() ); + else + name = outputTo; + + name.append( prefix ); + if ( appendSettings ) + { + name.append( QString().sprintf( "_%d_%d_q%d", captureX, captureY, quality ) ); + } + name.append( QString().sprintf( "-%d.%s", _pics++, (const char*) captureFormat.lower() ) ); + QImage i; ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); QImage im = i.convertDepth( 32 ); bool result = im.save( name, format, quality ); if ( !result ) { oerr << "imageio-Problem while writing." << oendl; Global::statusMessage( "Error!" ); } else { odebug << captureFormat << "-image has been successfully captured" << oendl; @@ -397,25 +492,30 @@ void CameraMainWindow::timerEvent( QTimerEvent* ) void CameraMainWindow::stopVideoCapture() { killTimers(); //ODevice::inst()->touchSound(); ODevice::inst()->setLedState( Led_Mail, Led_Off ); _capturing = false; updateCaption(); ::close( _capturefd ); _framerate = 1000.0 / (_time.elapsed()/_videopics); - postProcessVideo( CAPTUREFILE, QString().sprintf( "/tmp/video-%d_%d_%d_q%d-%dfps.avi", _videos++, captureX, captureY, quality, _framerate ) ); + QString name( outputTo ); + name.append( "/prefix" ); + if ( appendSettings ) + name.append( QString().sprintf( "_%d_%d_q%d_%dfps", captureX, captureY, quality, _framerate ) ); + name.append( QString().sprintf( "-%d.%s", _videos++, (const char*) captureFormat.lower() ) ); + postProcessVideo( CAPTUREFILE, name ); #ifndef QT_NO_DEBUG preview->setRefreshingRate( 1500 ); #else preview->setRefreshingRate( 200 ); #endif //delete[] _capturebuf; //FIXME: close memory leak } void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile ) { @@ -511,27 +611,32 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o oerr << "can't process file: %s" << strerror(errno) << oendl; return; // TODO: clean up temp ressources } int filesize = framefile.size(); odebug << "filesize for frame " << i << " = " << filesize << oendl; unsigned char* tempbuffer = new unsigned char[ filesize ]; framefile.readBlock( (char*) tempbuffer, filesize ); avi_add( outfd, tempbuffer, filesize ); delete tempbuffer; framefile.close(); + + odebug << "deleting temporary capturefile " << infile << oendl; + ::close( infd ); + QFile::remove( infile ); } avi_end( outfd, captureX, captureY, _framerate ); + ::close( outfd ); fr->hide(); delete fr; updateCaption(); } void CameraMainWindow::updateCaption() { if ( !_capturing ) @@ -542,14 +647,18 @@ void CameraMainWindow::updateCaption() #ifndef QT_NO_DEBUG void CameraMainWindow::doSomething() { captureX = 240; captureY = 320; _videopics = 50; _framerate = 5; postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat", "/tmp/output.avi" ); } +#else +void CameraMainWindow::doSomething() +{ +} #endif |