summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-13 00:11:53 (UTC)
committer mickeyl <mickeyl>2003-04-13 00:11:53 (UTC)
commit33088e3bc0af16b6d000433cb3f73161e86a5bf5 (patch) (unidiff)
tree4113ab8c293486d7f0438d4fd4ae1037aaeaa519
parent6d62efcd8964194cae47dc3dfe71b7cc41cbf3e2 (diff)
downloadopie-33088e3bc0af16b6d000433cb3f73161e86a5bf5.zip
opie-33088e3bc0af16b6d000433cb3f73161e86a5bf5.tar.gz
opie-33088e3bc0af16b6d000433cb3f73161e86a5bf5.tar.bz2
add error message of camera is not found
remove inlines (for now) because of link-problems
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp36
-rw-r--r--noncore/multimedia/camera/mainwindow.h2
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp10
-rw-r--r--noncore/multimedia/camera/zcameraio.h2
4 files changed, 42 insertions, 8 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 7080e63..34ebe9e 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -1,89 +1,121 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
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 19
20#include <qvbox.h> 20#include <qvbox.h>
21#include <qcombobox.h> 21#include <qcombobox.h>
22#include <qcursor.h>
22#include <qdatastream.h> 23#include <qdatastream.h>
23#include <qpushbutton.h>
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qpopupmenu.h>
26#include <qpushbutton.h>
27#include <qmessagebox.h>
25#include <qdirectpainter_qws.h> 28#include <qdirectpainter_qws.h>
26#include <qpe/resource.h> 29#include <qpe/resource.h>
27#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
28#include <opie/ofiledialog.h> 31#include <opie/ofiledialog.h>
29 32
30#include <opie2/odebug.h> 33#include <opie2/odebug.h>
31 34
32#include <assert.h> 35#include <assert.h>
33 36
34CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 37CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
35 :QMainWindow( parent, name, f ) 38 :QMainWindow( parent, name, f )
36{ 39{
40 if ( !ZCameraIO::instance()->isOpen() )
41 {
42 QVBox* v = new QVBox( this );
43 v->setMargin( 10 );
44 QLabel* l1 = new QLabel( v );
45 l1->setPixmap( Resource::loadPixmap( "camera/error" ) );
46 QLabel* l2 = new QLabel( v );
47 l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>"
48 "* Is the sharpzdc_cs module loaded ?<br>"
49 "* Is /dev/sharpzdc read/writable ?<p>" );
50 connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) );
51 setCentralWidget( v );
52 return;
53 }
54
37 _rotation = 270; //TODO: grab these from the actual settings 55 _rotation = 270; //TODO: grab these from the actual settings
38 56
39 preview = new PreviewWidget( this, "camera preview widget" ); 57 preview = new PreviewWidget( this, "camera preview widget" );
40 //setCentralWidget( preview ); <--- don't do this! 58 //setCentralWidget( preview ); <--- don't do this!
41 preview->resize( QSize( 240, 288 ) ); 59 preview->resize( QSize( 240, 288 ) );
42 preview->show(); 60 preview->show();
43 61
44 // construct a System Channel to receive setRotation messages 62 // construct a System Channel to receive setRotation messages
45 _sysChannel = new QCopChannel( "QPE/System", this ); 63 _sysChannel = new QCopChannel( "QPE/System", this );
46 connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), 64 connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ),
47 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); 65 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
48 66
67 connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) );
49}; 68};
50 69
51 70
52CameraMainWindow::~CameraMainWindow() 71CameraMainWindow::~CameraMainWindow()
53{ 72{
54} 73}
55 74
56 75
57void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) 76void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data )
58{ 77{
59 QDataStream stream( data, IO_ReadOnly ); 78 QDataStream stream( data, IO_ReadOnly );
60 odebug << "received system message: " << msg << oendl; 79 odebug << "received system message: " << msg << oendl;
61 if ( msg == "setCurrentRotation(int)" ) 80 if ( msg == "setCurrentRotation(int)" )
62 { 81 {
63 stream >> _rotation; 82 stream >> _rotation;
64 odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; 83 odebug << "received setCurrentRotation(" << _rotation << ")" << oendl;
65 84
66 switch ( _rotation ) 85 switch ( _rotation )
67 { 86 {
68 case 270: preview->resize( QSize( 240, 288 ) ); break; 87 case 270: preview->resize( QSize( 240, 288 ) ); break;
69 case 180: preview->resize( QSize( 320, 208 ) ); break; 88 case 180: preview->resize( QSize( 320, 208 ) ); break;
70 default: assert( 0 ); // not yet handled 89 default: QMessageBox::warning( this, "opie-camera",
90 "This rotation is not supported.\n"
91 "Supported are 180� and 270�" );
71 } 92 }
72 } 93 }
73} 94}
74 95
75 96
76void CameraMainWindow::changeZoom( int zoom ) 97void CameraMainWindow::changeZoom( int zoom )
77{ 98{
78 int z; 99 int z;
79 switch ( zoom ) 100 switch ( zoom )
80 { 101 {
81 case 0: z = 128; break; 102 case 0: z = 128; break;
82 case 1: z = 256; break; 103 case 1: z = 256; break;
83 case 2: z = 512; break; 104 case 2: z = 512; break;
84 default: assert( 0 ); break; 105 default: assert( 0 ); break;
85 } 106 }
86 107
87 ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); 108 ZCameraIO::instance()->setCaptureFrame( 240, 160, z );
88} 109}
89 110
111
112void CameraMainWindow::showContextMenu()
113{
114 QPopupMenu m( this );
115 m.insertItem( "Item 1" );
116 m.insertItem( "Item 1" );
117 m.insertItem( "Item 1" );
118 m.insertItem( "Item 1" );
119 m.exec( QCursor::pos() );
120}
121
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h
index cc12840..df66204 100644
--- a/noncore/multimedia/camera/mainwindow.h
+++ b/noncore/multimedia/camera/mainwindow.h
@@ -1,51 +1,53 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
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#ifndef MAINWINDOW_H 16#ifndef MAINWINDOW_H
17#define MAINWINDOW_H 17#define MAINWINDOW_H
18 18
19#include <qmainwindow.h> 19#include <qmainwindow.h>
20#include <qdatetime.h> 20#include <qdatetime.h>
21#include <qimage.h> 21#include <qimage.h>
22#include <qpixmap.h> 22#include <qpixmap.h>
23 23
24class QIconSet; 24class QIconSet;
25class QToolButton; 25class QToolButton;
26class QLabel; 26class QLabel;
27class MainWindowBase; 27class MainWindowBase;
28class QCopChannel; 28class QCopChannel;
29class PreviewWidget; 29class PreviewWidget;
30 30
31class CameraMainWindow: public QMainWindow 31class CameraMainWindow: public QMainWindow
32{ 32{
33 Q_OBJECT 33 Q_OBJECT
34 34
35 public: 35 public:
36 CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); 36 CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 );
37 virtual ~CameraMainWindow(); 37 virtual ~CameraMainWindow();
38 38
39 public slots: 39 public slots:
40 void changeZoom( int ); 40 void changeZoom( int );
41 void systemMessage( const QCString&, const QByteArray& ); 41 void systemMessage( const QCString&, const QByteArray& );
42 42
43 void showContextMenu();
44
43 protected: 45 protected:
44 46
45 private: 47 private:
46 PreviewWidget* preview; 48 PreviewWidget* preview;
47 int _rotation; 49 int _rotation;
48 QCopChannel* _sysChannel; 50 QCopChannel* _sysChannel;
49}; 51};
50 52
51#endif 53#endif
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp
index 51771a5..b37ae8c 100644
--- a/noncore/multimedia/camera/zcameraio.cpp
+++ b/noncore/multimedia/camera/zcameraio.cpp
@@ -14,154 +14,154 @@
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "zcameraio.h" 16#include "zcameraio.h"
17 17
18#include <sys/types.h> 18#include <sys/types.h>
19#include <sys/stat.h> 19#include <sys/stat.h>
20#include <errno.h> 20#include <errno.h>
21#include <string.h> 21#include <string.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdio.h> 24#include <stdio.h>
25 25
26#include <qimage.h> 26#include <qimage.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28 28
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30 30
31#define SHARPZDC "/dev/sharp_zdc" 31#define SHARPZDC "/dev/sharp_zdc"
32 32
33ZCameraIO* ZCameraIO::_instance = 0; 33ZCameraIO* ZCameraIO::_instance = 0;
34 34
35ZCameraIO* ZCameraIO::instance() 35ZCameraIO* ZCameraIO::instance()
36{ 36{
37 if ( !ZCameraIO::_instance ) 37 if ( !ZCameraIO::_instance )
38 { 38 {
39 odebug << "Creating ZCameraIO::_instance" << oendl; 39 odebug << "Creating ZCameraIO::_instance" << oendl;
40 ZCameraIO::_instance = new ZCameraIO(); 40 ZCameraIO::_instance = new ZCameraIO();
41 } 41 }
42 return ZCameraIO::_instance; 42 return ZCameraIO::_instance;
43} 43}
44 44
45 45
46ZCameraIO::ZCameraIO() 46ZCameraIO::ZCameraIO()
47 :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 ) 47 :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 )
48{ 48{
49 _driver = ::open( SHARPZDC, O_RDWR ); 49 _driver = ::open( SHARPZDC, O_RDWR );
50 if ( _driver == -1 ) 50 if ( _driver == -1 )
51 oerr << "Can't open camera driver: " << strerror(errno) << oendl; 51 oerr << "Can't open camera driver: " << strerror(errno) << oendl;
52 else 52 else
53 init(); 53 init();
54} 54}
55 55
56 56
57void ZCameraIO::init() 57void ZCameraIO::init()
58{ 58{
59 if ( ZCameraIO::_instance ) 59 if ( ZCameraIO::_instance )
60 ofatal << "Don't create more than one ZCameraIO instances." << oendl; 60 ofatal << "Don't create more than one ZCameraIO instances." << oendl;
61 else 61 else
62 { 62 {
63 setReadMode( STATUS ); 63 setReadMode( STATUS );
64 } 64 }
65} 65}
66 66
67 67
68ZCameraIO::~ZCameraIO() 68ZCameraIO::~ZCameraIO()
69{ 69{
70 if ( _driver != -1 ) 70 if ( _driver != -1 )
71 { 71 {
72 setReadMode( 0 ); 72 setReadMode( 0 );
73 ::close( _driver ); 73 ::close( _driver );
74 } 74 }
75} 75}
76 76
77 77
78inline bool ZCameraIO::isOpen() const 78bool ZCameraIO::isOpen() const
79{ 79{
80 return _driver != -1; 80 return _driver != -1;
81} 81}
82 82
83 83
84inline bool ZCameraIO::isShutterPressed() 84bool ZCameraIO::isShutterPressed()
85{ 85{
86 return _status[0] == 'S'; 86 return _status[0] == 'S';
87 clearShutterLatch(); 87 clearShutterLatch();
88} 88}
89 89
90 90
91inline bool ZCameraIO::isFinderReversed() const 91bool ZCameraIO::isFinderReversed() const
92{ 92{
93 return _status[1] == 'M'; 93 return _status[1] == 'M';
94} 94}
95 95
96 96
97inline bool ZCameraIO::isCapturing() const 97bool ZCameraIO::isCapturing() const
98{ 98{
99 return _status[2] == 'C'; 99 return _status[2] == 'C';
100} 100}
101 101
102 102
103inline bool ZCameraIO::isAvailable() const 103bool ZCameraIO::isAvailable() const
104{ 104{
105 return _status[3] == 'A'; 105 return _status[3] == 'A';
106} 106}
107 107
108 108
109bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) 109bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
110{ 110{
111 odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl; 111 odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl;
112 char b[100]; 112 char b[100];
113 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); 113 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
114 if ( write( b ) ) 114 if ( write( b ) )
115 { 115 {
116 _width = width; 116 _width = width;
117 _height = height; 117 _height = height;
118 _zoom = zoom; 118 _zoom = zoom;
119 _rot = rot; 119 _rot = rot;
120 _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel 120 _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel
121 return true; 121 return true;
122 } 122 }
123 return false; 123 return false;
124} 124}
125 125
126 126
127void ZCameraIO::setReadMode( int mode ) 127void ZCameraIO::setReadMode( int mode )
128{ 128{
129 char b[10]; 129 char b[10];
130 sprintf( b, "M=%d", mode ); 130 sprintf( b, "M=%d", mode );
131 write( b, mode <= 9 ? 3 : 4 ); 131 write( b, mode <= 9 ? 3 : 4 );
132 if ( mode & 1 ) // STATUS bit is set 132 if ( mode & 1 ) // STATUS bit is set
133 read( _status, 4 ); 133 read( _status, 4 );
134} 134}
135 135
136 136
137void ZCameraIO::clearShutterLatch() 137void ZCameraIO::clearShutterLatch()
138{ 138{
139 char b = 'B'; 139 char b = 'B';
140 write( &b, 1 ); 140 write( &b, 1 );
141} 141}
142 142
143 143
144bool ZCameraIO::read( char* b, int len ) 144bool ZCameraIO::read( char* b, int len )
145{ 145{
146 #ifndef NO_TIMING 146 #ifndef NO_TIMING
147 QTime t; 147 QTime t;
148 t.start(); 148 t.start();
149 #endif 149 #endif
150 int rlen = ::read( _driver, b, len ); 150 int rlen = ::read( _driver, b, len );
151 #ifndef NO_TIMING 151 #ifndef NO_TIMING
152 int time = t.elapsed(); 152 int time = t.elapsed();
153 #else 153 #else
154 int time = -1; 154 int time = -1;
155 #endif 155 #endif
156 if ( rlen ) 156 if ( rlen )
157 odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl; 157 odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl;
158 else 158 else
159 odebug << "read nothing from driver." << oendl; 159 odebug << "read nothing from driver." << oendl;
160 return rlen == len; 160 return rlen == len;
161} 161}
162 162
163 163
164bool ZCameraIO::write( char* buf, int len ) 164bool ZCameraIO::write( char* buf, int len )
165{ 165{
166 if ( !len ) 166 if ( !len )
167 len = strlen( buf ); 167 len = strlen( buf );
diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h
index bc4926b..9d4b1d7 100644
--- a/noncore/multimedia/camera/zcameraio.h
+++ b/noncore/multimedia/camera/zcameraio.h
@@ -1,65 +1,65 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
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#ifndef ZCAMERAIO_H 16#ifndef ZCAMERAIO_H
17#define ZCAMERAIO_H 17#define ZCAMERAIO_H
18 18
19class QImage; 19class QImage;
20 20
21class ZCameraIO 21class ZCameraIO
22{ 22{
23 public: 23 public:
24 virtual ~ZCameraIO(); 24 virtual ~ZCameraIO();
25 25
26 enum ReadMode 26 enum ReadMode
27 { 27 {
28 IMAGE = 0, STATUS = 1, 28 IMAGE = 0, STATUS = 1,
29 FASTER = 0, BETTER = 2, 29 FASTER = 0, BETTER = 2,
30 XNOFLIP = 0, XFLIP = 4, 30 XNOFLIP = 0, XFLIP = 4,
31 YNOFLIP = 0, YFLIP = 8 31 YNOFLIP = 0, YFLIP = 8
32 }; 32 };
33 33
34 bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); 34 bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
35 void setReadMode( int = IMAGE | XFLIP | YFLIP ); 35 void setReadMode( int = IMAGE | XFLIP | YFLIP );
36 36
37 bool isShutterPressed(); // not const, because it calls clearShutterLatch 37 bool isShutterPressed(); // not const, because it calls clearShutterLatch
38 bool isAvailable() const; 38 bool isAvailable() const;
39 bool isCapturing() const; 39 bool isCapturing() const;
40 bool isFinderReversed() const; 40 bool isFinderReversed() const;
41
42 bool isOpen() const; 41 bool isOpen() const;
42
43 bool snapshot( QImage* ); 43 bool snapshot( QImage* );
44 bool snapshot( unsigned char* ); 44 bool snapshot( unsigned char* );
45 static ZCameraIO* instance(); 45 static ZCameraIO* instance();
46 46
47 protected: 47 protected:
48 ZCameraIO(); 48 ZCameraIO();
49 void clearShutterLatch(); 49 void clearShutterLatch();
50 void init(); 50 void init();
51 bool read( char*, int ); 51 bool read( char*, int );
52 bool write( char*, int = 0 ); 52 bool write( char*, int = 0 );
53 53
54 private: 54 private:
55 int _driver; 55 int _driver;
56 char _status[4]; 56 char _status[4];
57 static ZCameraIO* _instance; 57 static ZCameraIO* _instance;
58 int _height; 58 int _height;
59 int _width; 59 int _width;
60 int _zoom; 60 int _zoom;
61 bool _rot; 61 bool _rot;
62 int _readlen; 62 int _readlen;
63}; 63};
64 64
65#endif 65#endif