Quick hakcish port of the QtBrowserPlugin from QApplication -> KApplication
[plasmaplugin.git] / qtbrowserplugin / qtbrowserplugin_x11.cpp
blobe166117725955689c4708ed81bbdb372fc6cecd4
1 /****************************************************************************
2 **
3 ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of a Qt Solutions component.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** Trolltech sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
23 #include <QtGui>
24 #include <QtGui/QX11EmbedWidget>
26 #include <kapplication.h>
27 #include <kaboutdata.h>
28 #include <KCmdLineArgs>
30 #include "qtbrowserplugin.h"
31 #include "qtbrowserplugin_p.h"
33 #include "qtnpapi.h"
35 #include <stdlib.h>
37 static bool ownsqapp = false;
38 static QMap<QtNPInstance*, QX11EmbedWidget*> clients;
40 extern "C" bool qtns_event(QtNPInstance *, NPEvent *)
42 return false;
45 extern "C" void qtns_initialize(QtNPInstance* This)
47 if (!qApp) {
48 ownsqapp = true;
49 static int argc = 1;
50 static char **argv = new char*;
51 argv[0] = "b";
53 // Workaround to avoid re-initilaziation of glib
54 char* envvar = qstrdup("QT_NO_THREADED_GLIB=1");
55 // Unavoidable memory leak; the variable must survive plugin unloading
56 ::putenv(envvar);
57 //BEGIN: PLASMAPLUGIN ALTERED CODE
58 KAboutData aboutData( "plasmoidviewer", 0, ki18n( "Plasma Applet Viewer" ),
59 "1.0", ki18n( "blaaaaaa" ), KAboutData::License_BSD,
60 ki18n( "(C) 2007, The KDE Team" ) );
61 aboutData.setProgramIconName( "plasma" );
62 aboutData.addAuthor( ki18n( "Frerich Raabe" ),
63 ki18n( "Original author" ),
64 "raabe@kde.org" );
65 KCmdLineArgs::init( argc, argv, &aboutData );
66 (void)new KApplication;
67 //END: PLASMAPLUGIN ALTERED CODE
69 if (!clients.contains(This)) {
70 QX11EmbedWidget* client = new QX11EmbedWidget;
71 QHBoxLayout* layout = new QHBoxLayout(client);
72 layout->setMargin(0);
73 clients.insert(This, client);
77 extern "C" void qtns_destroy(QtNPInstance* This)
79 QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
80 if (it == clients.end())
81 return;
82 delete it.value();
83 clients.erase(it);
86 extern "C" void qtns_shutdown()
88 if (clients.count() > 0) {
89 QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.begin();
90 while (it != clients.end()) {
91 delete it.value();
92 ++it;
94 clients.clear();
97 if (!ownsqapp)
98 return;
100 // check if qApp still runs widgets (in other DLLs)
101 QWidgetList widgets = qApp->allWidgets();
102 int count = widgets.count();
103 for (int w = 0; w < widgets.count(); ++w) {
104 // ignore all Qt generated widgets
105 QWidget *widget = widgets.at(w);
106 if (widget->windowFlags() & Qt::Desktop)
107 count--;
109 if (count) // qApp still used
110 return;
112 delete qApp;
113 ownsqapp = false;
116 extern "C" void qtns_embed(QtNPInstance *This)
118 Q_ASSERT(qobject_cast<QWidget*>(This->qt.object));
120 QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
121 if (it == clients.end())
122 return;
123 QX11EmbedWidget* client = it.value();
124 This->qt.widget->setParent(client);
125 client->layout()->addWidget(This->qt.widget);
126 client->embedInto(This->window);
127 client->show();
130 extern "C" void qtns_setGeometry(QtNPInstance *This, const QRect &rect, const QRect &)
132 Q_ASSERT(qobject_cast<QWidget*>(This->qt.object));
134 QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
135 if (it == clients.end())
136 return;
137 QX11EmbedWidget* client = it.value();
138 client->setGeometry(QRect(0, 0, rect.width(), rect.height()));
142 extern "C" void qtns_print(QtNPInstance * This, NPPrint *printInfo)
144 NPWindow* printWindow = &(printInfo->print.embedPrint.window);
145 void* platformPrint = printInfo->print.embedPrint.platformPrint;
146 // #### Nothing yet.