summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -24,11 +24,13 @@
#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>
@@ -52,13 +54,16 @@ using namespace Opie;
#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() )
{
@@ -112,8 +117,11 @@ void CameraMainWindow::init()
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 );
@@ -128,13 +136,13 @@ void CameraMainWindow::init()
( 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 );
@@ -147,8 +155,17 @@ void CameraMainWindow::init()
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 );
@@ -158,8 +175,9 @@ void CameraMainWindow::init()
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*) ) );
}
@@ -230,8 +248,17 @@ void CameraMainWindow::showContextMenu()
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 );
@@ -239,8 +266,11 @@ void CameraMainWindow::showContextMenu()
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() ) );
@@ -306,16 +336,69 @@ void CameraMainWindow::flipMenuItemClicked( QAction* a )
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
{
@@ -336,9 +419,21 @@ void CameraMainWindow::shutterClicked()
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 );
@@ -405,9 +500,14 @@ void CameraMainWindow::stopVideoCapture()
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
@@ -519,11 +619,16 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o
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;
@@ -550,6 +655,10 @@ void CameraMainWindow::doSomething()
_framerate = 5;
postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat",
"/tmp/output.avi" );
}
+#else
+void CameraMainWindow::doSomething()
+{
+}
#endif
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
@@ -47,9 +47,12 @@ class CameraMainWindow: public QMainWindow
void resoMenuItemClicked( QAction* );
void qualityMenuItemClicked( QAction* );
void zoomMenuItemClicked( QAction* );
void flipMenuItemClicked( QAction* );
+ void outputToMenuItemClicked( QAction* );
void outputMenuItemClicked( QAction* );
+ void prefixItemChoosen();
+ void appendSettingsChoosen();
void shutterClicked();
void updateCaption();
@@ -62,11 +65,9 @@ class CameraMainWindow: public QMainWindow
virtual void timerEvent( QTimerEvent* );
protected slots:
- #ifndef QT_NO_DEBUG
- //void doSomething(); // solely for debugging purposes
- #endif
+ void doSomething(); // solely for debugging purposes
private:
PreviewWidget* preview;
int _rotation;
@@ -75,8 +76,11 @@ class CameraMainWindow: public QMainWindow
QActionGroup* resog;
QActionGroup* qualityg;
QActionGroup* zoomg;
QActionGroup* flipg;
+ QActionGroup* outputTog;
+ QAction* custom;
+ QAction* docfolder;
QActionGroup* outputg;
QString flip;
int quality;
@@ -84,8 +88,12 @@ class CameraMainWindow: public QMainWindow
int captureX;
int captureY;
QString captureFormat;
+ QString outputTo;
+ QString prefix;
+ bool appendSettings;
+
bool _capturing;
int _pics;
int _videos;