1 /****************************************************************************
3 ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
5 ** This file is part of a Qt Solutions component.
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 ****************************************************************************/
24 #include <QtGui/QX11EmbedWidget>
26 #include <kapplication.h>
27 #include <kaboutdata.h>
28 #include <KCmdLineArgs>
30 #include "qtbrowserplugin.h"
31 #include "qtbrowserplugin_p.h"
37 static bool ownsqapp
= false;
38 static QMap
<QtNPInstance
*, QX11EmbedWidget
*> clients
;
40 extern "C" bool qtns_event(QtNPInstance
*, NPEvent
*)
45 extern "C" void qtns_initialize(QtNPInstance
* This
)
50 static char **argv
= new char*;
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
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" ),
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
);
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())
86 extern "C" void qtns_shutdown()
88 if (clients
.count() > 0) {
89 QMap
<QtNPInstance
*, QX11EmbedWidget
*>::iterator it
= clients
.begin();
90 while (it
!= clients
.end()) {
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
)
109 if (count
) // qApp still used
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())
123 QX11EmbedWidget
* client
= it
.value();
124 This
->qt
.widget
->setParent(client
);
125 client
->layout()->addWidget(This
->qt
.widget
);
126 client
->embedInto(This
->window
);
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())
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;