More fixes for Qt5
[harmattan/cameraplus] / declarative / videoplayer.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef VIDEO_PLAYER_H
24 #define VIDEO_PLAYER_H
25
26 #if defined(QT4)
27 #include <QDeclarativeItem>
28 #elif defined(QT5)
29 #include <QQuickPaintedItem>
30 #endif
31 #include <gst/gst.h>
32
33 class CameraConfig;
34 class QtCamViewfinderRenderer;
35
36 #if defined(QT4)
37 class VideoPlayer : public QDeclarativeItem {
38 #elif defined(QT5)
39 class VideoPlayer : public QQuickPaintedItem {
40 #endif
41
42   Q_OBJECT
43
44   Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged);
45   Q_PROPERTY(CameraConfig *cameraConfig READ cameraConfig WRITE setCameraConfig NOTIFY cameraConfigChanged);
46   Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged);
47   Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged);
48   Q_PROPERTY(State state READ state NOTIFY stateChanged);
49   Q_ENUMS(State);
50
51 public:
52
53 #if defined(QT4)
54   VideoPlayer(QDeclarativeItem *parent = 0);
55 #elif defined(QT5)
56   VideoPlayer(QQuickItem *parent = 0);
57 #endif
58
59   ~VideoPlayer();
60
61   virtual void componentComplete();
62   virtual void classBegin();
63
64 #if defined(QT4)
65   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
66 #elif defined(QT5)
67   void paint(QPainter *painter);
68 #endif
69
70   QUrl source() const;
71   void setSource(const QUrl& source);
72
73   CameraConfig *cameraConfig() const;
74   void setCameraConfig(CameraConfig *config);
75
76   qint64 duration() const;
77   qint64 position();
78   void setPosition(qint64 position);
79
80   Q_INVOKABLE bool pause();
81   Q_INVOKABLE bool play();
82   Q_INVOKABLE bool seek(qint64 offset);
83   Q_INVOKABLE bool stop();
84
85   typedef enum {
86     StateStopped,
87     StatePaused,
88     StatePlaying,
89   } State;
90
91   State state() const;
92
93 signals:
94   void sourceChanged();
95   void cameraConfigChanged();
96
97   void durationChanged();
98   void positionChanged();
99   void error(const QString& message, int code, const QString& debug);
100   void stateChanged();
101
102 protected:
103   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
104
105 private slots:
106   void updateRequested();
107
108 private:
109   static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data);
110
111   bool setState(const State& state);
112
113   CameraConfig *m_config;
114   QtCamViewfinderRenderer *m_renderer;
115   QUrl m_url;
116
117   GstElement *m_bin;
118   State m_state;
119   QTimer *m_timer;
120   qint64 m_pos;
121 };
122
123 #endif /* VIDEO_PLAYER_H */