aboutsummaryrefslogtreecommitdiff
path: root/src/extensions/applicationextension/mextensionrunner.h
blob: b13d2210cedc6e89d3421c2a82ee318cef6c1f9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef MEXTENSIONRUNNER_H_
#define MEXTENSIONRUNNER_H_

#include <QObject>
#include <QRectF>
#include <QPixmap>

#include <mnamespace.h>
#include <mexport.h>

class MWidget;
class MScene;
class MWindow;
class QGraphicsWidget;
class MAppletClient;
class MAppletMessage;
class MAppletMouseMessage;
class MAppletCancelMessage;
class MAppletMetaData;
class MAppletInterface;
class MAppletSharedMutex;
class QAction;
#ifdef QT_OPENGL_LIB
class QGLContext;
#endif
#ifdef HAVE_CONTEXTSUBSCRIBER
class ContextProperty;
#endif

//! \internal
/**
 * MExtensionRunner is a class that is used to start and run oop (out of process)
 * extension widgets.
 *
 * W A R N I N G
 * -------------
 * This file is not part of the libmeegotouch API. It should only be used by applet runner developers.
 */
class M_EXTENSIONS_EXPORT MExtensionRunner : public QObject
{
    Q_OBJECT

public:
    /*!
     * MExtensionRunner constructor
     */
    MExtensionRunner();

    //! MExtensionRunner destructor
    virtual ~MExtensionRunner();

    /*!
     * Initialize the extension and establish an IPC connection between the runner and
     * the host application.
     *
     * \param serverName the name of the host process's server.
     * \return \c true if the extension and IPC connection were initialized correctly,
     *         \c false if something went wrong.
     */
    virtual bool init(const QString &serverName);

    /*!
     * Sends a message of type MAppletUpdateGeometryMessage to the host.
     */
    virtual void sendUpdateGeometryMessage();

Q_SIGNALS:
    /*!
     * \brief A signal that is emitted when item is shown/hidden
     * TODO: Remove this redundant signal during next API/ABI break
     */
    void visibilityChanged(bool visibility);

    /*!
     * \brief A signal that is emitted when item is shown/hidden
     */
    void visibilityChanged();

protected slots:
    /*!
     * \brief A slot for receiving messages from the host application
     */
    virtual void messageReceived(const MAppletMessage &message);

    /*!
     * \brief A slot for notifying that the scene has changed and needs to be painted
     */
    virtual void sceneChanged(const QList<QRectF> &region);

    /*!
     * \brief Slot to be called when the host process has not sent any messages in ALIVE_TIMER_TIMEOUT milliseconds
     */
    virtual void hostProcessNotAlive();

    /*!
     * \brief Stops or starts the alive timer depending on the display blanking state
     */
    void updateDisplayState();

protected:
    //! AppletClient for communicating between the runner and the host processes.
    MAppletClient *communicator;

    //! A parent widget for the actual extension widget
    QGraphicsWidget *parentWidget;

    //! The extension widget instantiated from shared library
    QGraphicsWidget *widget;

    //! Scene where the widget is inserted.
    MScene *scene;

    //! View into the scene.
    MWindow *view;

    /*! Pixmap in which the extension is painted. The underlying X pixmap is
        shared between the host and runner processes. */
    QPixmap pixmap;

    //! List to hold object menu actions received from widget.
    QList<QAction *> widgetObjectMenuActions;

#ifdef HAVE_CONTEXTSUBSCRIBER
    //! Context property for getting the screen blanking status
    ContextProperty *screenBlankProperty;
#endif

    //! True if the display is currently blanked
    bool displayBlanked;

#ifdef QT_OPENGL_LIB
    //! OpenGL context
    QGLContext *context;
#endif

    //! Timer for checking that the host process is alive
    QTimer *aliveTimer;

    //! Shared mutex for locking the pixmap
    MAppletSharedMutex *pixmapMutex;

    //! Combined changed rect for the scene
    QRectF changedRect;

    //! Visibility status of the extension
    bool visible;

    /*!
     * Frees all resources that have been reserved by this object currently.
     */
    virtual void teardown();

    /*!
     * Handles an AppletMouseMessage.
     *
     * \param message the AppletMouseMessage to handle
     */
    virtual void handleMouseEvent(const MAppletMouseMessage *message);

    /*!
     * Handles an AppletCancelMessage.
     *
     * \param message to be handled
     */
    virtual void handleCancelEvent(const MAppletCancelMessage *message);

    /*!
     * Sets pixmap to use the received X pixmap handle
     *
     * \param handle the X pixmap handle to use
     */
    virtual void createAppletPixmap(Qt::HANDLE handle);

#ifdef UNIT_TEST
    friend class Ut_MExtensionRunner;
#endif
};
//! \internal_end

#endif /* MEXTENSIONRUNNER_H_ */