~x2go/x2go/x2goclient_master

« back to all changes in this revision

Viewing changes to qtbrowserplugin-2.4_1-opensource/src/qtbrowserplugin_x11.cpp

  • Committer: Reinhard Tartler
  • Author(s): Oleksander Schneyder
  • Date: 2011-01-27 20:43:11 UTC
  • Revision ID: git-v1:af42fa37d555c1031810a868db687f39c2f9e574
Imported x2goclient_3.01-16.tar.gz

Summary: Imported x2goclient_3.01-16.tar.gz
Keywords:

Imported x2goclient_3.01-16.tar.gz
into Git repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
 
5
** Contact: Nokia Corporation (qt-info@nokia.com)
 
6
**
 
7
** This file is part of a Qt Solutions component.
 
8
**
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
 
21
**     the names of its contributors may be used to endorse or promote
 
22
**     products derived from this software without specific prior written
 
23
**     permission.
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
36
**
 
37
****************************************************************************/
 
38
 
 
39
#include <QtGui>
 
40
#include <QtGui/QX11EmbedWidget>
 
41
 
 
42
#include "qtbrowserplugin.h"
 
43
#include "qtbrowserplugin_p.h"
 
44
 
 
45
#include "qtnpapi.h"
 
46
 
 
47
#include <stdlib.h>
 
48
 
 
49
static bool ownsqapp = false;
 
50
static QMap<QtNPInstance*, QX11EmbedWidget*> clients;
 
51
 
 
52
extern "C" bool qtns_event(QtNPInstance *, NPEvent *)
 
53
{
 
54
    return false;
 
55
}
 
56
 
 
57
extern "C" void qtns_initialize(QtNPInstance* This)
 
58
{
 
59
    if (!qApp) {
 
60
        ownsqapp = true;
 
61
        static int argc = 0;
 
62
        static char **argv = {0};
 
63
 
 
64
        // Workaround to avoid re-initilaziation of glib
 
65
        char* envvar = qstrdup("QT_NO_THREADED_GLIB=1");
 
66
        // Unavoidable memory leak; the variable must survive plugin unloading
 
67
        ::putenv(envvar);
 
68
 
 
69
        (void)new QApplication(argc, argv);
 
70
    }
 
71
    if (!clients.contains(This)) {
 
72
        QX11EmbedWidget* client = new QX11EmbedWidget;
 
73
        QHBoxLayout* layout = new QHBoxLayout(client);
 
74
        layout->setMargin(0);
 
75
        clients.insert(This, client);
 
76
    }
 
77
}
 
78
 
 
79
extern "C" void qtns_destroy(QtNPInstance* This)
 
80
{
 
81
    QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
 
82
    if (it == clients.end())
 
83
        return;
 
84
    delete it.value();
 
85
    clients.erase(it);
 
86
}
 
87
 
 
88
extern "C" void qtns_shutdown()
 
89
{
 
90
    if (clients.count() > 0) {
 
91
        QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.begin();
 
92
        while (it != clients.end()) {
 
93
            delete it.value();
 
94
            ++it;
 
95
        }
 
96
        clients.clear();
 
97
    }
 
98
 
 
99
    if (!ownsqapp)
 
100
        return;
 
101
 
 
102
    // check if qApp still runs widgets (in other DLLs)
 
103
    QWidgetList widgets = qApp->allWidgets();
 
104
    int count = widgets.count();
 
105
    for (int w = 0; w < widgets.count(); ++w) {
 
106
        // ignore all Qt generated widgets
 
107
        QWidget *widget = widgets.at(w);
 
108
        if (widget->windowFlags() & Qt::Desktop)
 
109
            count--;
 
110
    }
 
111
    if (count) // qApp still used
 
112
        return;
 
113
 
 
114
    delete qApp;
 
115
    ownsqapp = false;
 
116
}
 
117
 
 
118
extern "C" void qtns_embed(QtNPInstance *This)
 
119
{
 
120
    Q_ASSERT(qobject_cast<QWidget*>(This->qt.object));
 
121
 
 
122
    QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
 
123
    if (it == clients.end())
 
124
        return;
 
125
    QX11EmbedWidget* client = it.value();
 
126
    This->qt.widget->setParent(client);
 
127
    client->layout()->addWidget(This->qt.widget);
 
128
    client->embedInto(This->window);
 
129
    client->show();
 
130
}
 
131
 
 
132
extern "C" void qtns_setGeometry(QtNPInstance *This, const QRect &rect, const QRect &)
 
133
{
 
134
    Q_ASSERT(qobject_cast<QWidget*>(This->qt.object));
 
135
 
 
136
    QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
 
137
    if (it == clients.end())
 
138
        return;
 
139
    QX11EmbedWidget* client = it.value();
 
140
    client->setGeometry(QRect(0, 0, rect.width(), rect.height()));
 
141
}
 
142
 
 
143
/*
 
144
extern "C" void qtns_print(QtNPInstance * This, NPPrint *printInfo)
 
145
{
 
146
    NPWindow* printWindow = &(printInfo->print.embedPrint.window);
 
147
    void* platformPrint = printInfo->print.embedPrint.platformPrint;
 
148
    // #### Nothing yet.
 
149
}
 
150
*/