author | mickeyl <mickeyl> | 2003-04-13 00:11:53 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-13 00:11:53 (UTC) |
commit | 33088e3bc0af16b6d000433cb3f73161e86a5bf5 (patch) (unidiff) | |
tree | 4113ab8c293486d7f0438d4fd4ae1037aaeaa519 | |
parent | 6d62efcd8964194cae47dc3dfe71b7cc41cbf3e2 (diff) | |
download | opie-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
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 36 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 2 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 10 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 2 |
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 | ||
34 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 37 | CameraMainWindow::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 | ||
52 | CameraMainWindow::~CameraMainWindow() | 71 | CameraMainWindow::~CameraMainWindow() |
53 | { | 72 | { |
54 | } | 73 | } |
55 | 74 | ||
56 | 75 | ||
57 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) | 76 | void 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 | ||
76 | void CameraMainWindow::changeZoom( int zoom ) | 97 | void 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 | |||
112 | void 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 | |||
@@ -11,41 +11,43 @@ | |||
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 | ||
24 | class QIconSet; | 24 | class QIconSet; |
25 | class QToolButton; | 25 | class QToolButton; |
26 | class QLabel; | 26 | class QLabel; |
27 | class MainWindowBase; | 27 | class MainWindowBase; |
28 | class QCopChannel; | 28 | class QCopChannel; |
29 | class PreviewWidget; | 29 | class PreviewWidget; |
30 | 30 | ||
31 | class CameraMainWindow: public QMainWindow | 31 | class 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 | |||
@@ -46,90 +46,90 @@ ZCameraIO* ZCameraIO::instance() | |||
46 | ZCameraIO::ZCameraIO() | 46 | ZCameraIO::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 | ||
57 | void ZCameraIO::init() | 57 | void 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 | ||
68 | ZCameraIO::~ZCameraIO() | 68 | ZCameraIO::~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 | ||
78 | inline bool ZCameraIO::isOpen() const | 78 | bool ZCameraIO::isOpen() const |
79 | { | 79 | { |
80 | return _driver != -1; | 80 | return _driver != -1; |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | inline bool ZCameraIO::isShutterPressed() | 84 | bool ZCameraIO::isShutterPressed() |
85 | { | 85 | { |
86 | return _status[0] == 'S'; | 86 | return _status[0] == 'S'; |
87 | clearShutterLatch(); | 87 | clearShutterLatch(); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | inline bool ZCameraIO::isFinderReversed() const | 91 | bool ZCameraIO::isFinderReversed() const |
92 | { | 92 | { |
93 | return _status[1] == 'M'; | 93 | return _status[1] == 'M'; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | inline bool ZCameraIO::isCapturing() const | 97 | bool ZCameraIO::isCapturing() const |
98 | { | 98 | { |
99 | return _status[2] == 'C'; | 99 | return _status[2] == 'C'; |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | inline bool ZCameraIO::isAvailable() const | 103 | bool ZCameraIO::isAvailable() const |
104 | { | 104 | { |
105 | return _status[3] == 'A'; | 105 | return _status[3] == 'A'; |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) | 109 | bool 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 | ||
127 | void ZCameraIO::setReadMode( int mode ) | 127 | void 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 | ||
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 | |||
@@ -9,57 +9,57 @@ | |||
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 | ||
19 | class QImage; | 19 | class QImage; |
20 | 20 | ||
21 | class ZCameraIO | 21 | class 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 |