From kde-devel Thu Apr 24 19:22:16 2008 From: Urs Wolfer Date: Thu, 24 Apr 2008 19:22:16 +0000 To: kde-devel Subject: Re: nsplugins patch (KDE4) Message-Id: <200804242122.20434.uwolfer () kde ! org> X-MARC-Message: https://marc.info/?l=kde-devel&m=120906645512082 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1014949606==" --===============1014949606== Content-Type: multipart/signed; boundary="nextPart1977874.kFUZMYb1X5"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1977874.kFUZMYb1X5 Content-Type: multipart/mixed; boundary="Boundary-01=_p3NEIFqLP60da1c" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_p3NEIFqLP60da1c Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday 24 April 2008 12:04:19 Sergey Saukh wrote: > Hello, > > Replaced all Qt3/KDE3 support classes with proper ones from Qt4/KDE4. > This fixed nspluginviewer crash on window close. > > Hope it will be useful. I have done a little more work (simplified code (e.g. use qDeleteAll where= =20 possible, ported the test also to clean Qt 4 code, removed linking against = Qt=20 / KDE 3 support libs, cleaned some tab-mess, ...). Patch works here and als= o=20 fixes crash at exit. I will commit this patch soon if nobody objects. Bye urs --Boundary-01=_p3NEIFqLP60da1c Content-Type: text/x-patch; charset="iso-8859-6"; name="ns.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ns.patch" Index: test/testnsplugin.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- test/testnsplugin.cpp (revision 800743) +++ test/testnsplugin.cpp (working copy) @@ -24,8 +24,9 @@ =20 #include =20 +#include + #include =2D//Added by qt3to4: #include #include #include @@ -107,7 +108,7 @@ QWidget *win =3D m_plugins.last(); if ( win ) { =2D m_plugins.remove( win ); + m_plugins.removeAll( win ); delete win; } else { @@ -119,7 +120,7 @@ void TestNSPlugin::viewDestroyed( NSPluginInstance *inst ) { kDebug() << "TestNSPlugin::viewDestroyed"; =2D m_plugins.remove( inst ); + m_plugins.removeAll( inst ); } =20 =20 Index: test/testnsplugin.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- test/testnsplugin.h (revision 800743) +++ test/testnsplugin.h (working copy) @@ -20,11 +20,10 @@ */ =20 =20 =2D#ifndef __TESTNSPLUGIN_H__ =2D#define __TESTNSPLUGIN_H__ +#ifndef TESTNSPLUGIN_H +#define TESTNSPLUGIN_H =20 #include =2D#include #include #include =20 @@ -47,7 +46,7 @@ =20 protected: NSPluginLoader *m_loader; =2D Q3PtrList m_plugins; + QList m_plugins; QWidget *m_client; QBoxLayout *m_layout; }; Index: viewer/nsplugin.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- viewer/nsplugin.cpp (revision 800743) +++ viewer/nsplugin.cpp (working copy) @@ -37,7 +37,6 @@ #include #include =20 =2D#include #include #include #include @@ -611,9 +610,6 @@ _npp->ndata =3D this; _destroyed =3D false; _handle =3D handle; =2D _tempFiles.setAutoDelete( true ); =2D _streams.setAutoDelete( true ); =2D _waitingRequests.setAutoDelete( true ); _callback =3D new org::kde::nsplugins::CallBack( appId, callbackId, QDB= usConnection::sessionBus() ); =20 KUrl base(src); @@ -659,17 +655,18 @@ if ( !_destroyed ) { =20 kDebug(1431) << "delete streams"; =2D _waitingRequests.clear(); + qDeleteAll( _waitingRequests ); =20 shutdown(); =20 =2D for( NSPluginStreamBase *s=3D_streams.first(); s!=3D0; ) { =2D NSPluginStreamBase *next =3D _streams.next(); + while ( !_streams.isEmpty() ) { + NSPluginStreamBase *s =3D _streams.takeFirst(); s->stop(); =2D s =3D next; + delete s; } =20 =2D _streams.clear(); + kDebug(1431) << "delete tempfiles"; + qDeleteAll( _tempFiles ); =20 kDebug(1431) << "delete callbacks"; delete _callback; @@ -728,10 +725,10 @@ =20 // start queued requests kDebug(1431) << "looking for waiting requests"; =2D while ( _waitingRequests.head() ) { + while ( !_waitingRequests.isEmpty() ) { kDebug(1431) << "request found"; Request req( *_waitingRequests.head() ); =2D _waitingRequests.remove(); + delete _waitingRequests.dequeue(); =20 QString url; =20 @@ -880,9 +877,7 @@ { kDebug(1431) << "-> NSPluginInstance::streamFinished"; emitStatus( QString() ); =2D _streams.setAutoDelete(false); =2D _streams.remove(strm); =2D _streams.setAutoDelete(true); + _streams.removeOne(strm); strm->deleteLater(); _timer->setSingleShot( true ); _timer->start( 100 ); @@ -1219,7 +1214,6 @@ _libname =3D library; _constructed =3D false; _error =3D true; =2D _instances.setAutoDelete( true ); _NP_GetMIMEDescription =3D 0; _NP_Initialize =3D 0; _NP_Shutdown =3D 0; @@ -1274,8 +1268,9 @@ =20 NSPluginClass::~NSPluginClass() { =2D _instances.clear(); =2D _trash.clear(); + qDeleteAll( _instances ); + qDeleteAll( _trash ); + shutdown(); if (_handle) _handle->unload(); @@ -1285,10 +1280,14 @@ void NSPluginClass::timer() { // delete instances =2D for ( NSPluginInstance *it=3D_trash.first(); it!=3D0; it=3D_trash.ne= xt() ) =2D _instances.remove(it); =2D =2D _trash.clear(); + while ( !_trash.isEmpty() ) { + NSPluginInstance *it =3D _trash.takeFirst(); + int i =3D _instances.indexOf(it); + if ( i !=3D -1 ) + delete _instances.takeAt(i); + =20 + delete it; + } } =20 =20 Index: viewer/viewer.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- viewer/viewer.cpp (revision 800743) +++ viewer/viewer.cpp (working copy) @@ -35,10 +35,8 @@ #include #include #include =2D#include #include =2D//Added by qt3to4: =2D#include + #include #include #include Index: viewer/nsplugin.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- viewer/nsplugin.h (revision 800743) +++ viewer/nsplugin.h (working copy) @@ -28,12 +28,10 @@ =20 #include =20 =2D#include #include =2D#include #include =2D//Added by qt3to4: =2D#include +#include +#include =20 #include =20 @@ -221,9 +219,9 @@ bool _destroyed; bool _embedded; void addTempFile(KTemporaryFile *tmpFile); =2D Q3PtrList _tempFiles; + QList _tempFiles; OrgKdeNspluginsCallBackInterface *_callback; =2D Q3PtrList _streams; + QList _streams; KLibrary *_handle; QTimer *_timer; =20 @@ -267,7 +265,7 @@ KParts::BrowserArguments browserArgs; }; =20 =2D Q3PtrQueue _waitingRequests; + QQueue _waitingRequests; QMap _jsrequests; }; =20 @@ -307,8 +305,8 @@ NP_InitializeUPP *_NP_Initialize; NP_ShutdownUPP *_NP_Shutdown; =20 =2D Q3PtrList _instances; =2D Q3PtrList _trash; + QList _instances; + QList _trash; =20 QByteArray _app; NPPluginFuncs _pluginFuncs; Index: viewer/pluginhost_xt.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- viewer/pluginhost_xt.cpp (revision 800743) +++ viewer/pluginhost_xt.cpp (working copy) @@ -52,7 +52,8 @@ =20 PluginHostXt::PluginHostXt(NSPluginInstance* plugin): _plugin(plugin), _outside(0), _toplevel(0), _form(0) =2D{} +{ +} =20 =20 void PluginHostXt::setupWindow(int winId, int width, int height) Index: viewer/qxteventloop.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- viewer/qxteventloop.cpp (revision 800743) +++ viewer/qxteventloop.cpp (working copy) @@ -41,9 +41,8 @@ #include =20 #include =2D//Added by qt3to4: =2D#include =2D#include +#include +#include =20 // resolve the conflict between X11's FocusIn and QEvent::FocusIn const int XFocusOut =3D FocusOut; @@ -67,10 +66,10 @@ void unhook(); =20 XtAppContext appContext, ownContext; =2D Q3MemArray dispatchers; + QVector dispatchers; QWidgetIntDict mapper; =20 =2D Q3IntDict socknotDict; + QHash socknotDict; bool activate_timers; XtIntervalId timerid; =20 @@ -354,7 +353,7 @@ void qmotif_socknot_handler( XtPointer pointer, int *, XtInputId *id ) { QXtEventLoop *eventloop =3D (QXtEventLoop *) pointer; =2D QSocketNotifier *socknot =3D static_d->socknotDict.find( *id ); + QSocketNotifier *socknot =3D static_d->socknotDict.value( *id ); if ( ! socknot ) // this shouldn't happen return; eventloop->setSocketNotifierPending( socknot ); @@ -395,17 +394,16 @@ */ void QXtEventLoop::unregisterSocketNotifier( QSocketNotifier *notifier ) { =2D Q3IntDictIterator it( d->socknotDict ); =2D while ( it.current() && notifier !=3D it.current() ) =2D ++it; =2D if ( ! it.current() ) { + + int key =3D d->socknotDict.key(notifier); + if ( ! key ) { // this shouldn't happen qWarning( "QXtEventLoopEventLoop: failed to unregister socket notifier" ); return; } =20 =2D XtRemoveInput( it.currentKey() ); =2D d->socknotDict.remove( it.currentKey() ); + XtRemoveInput( key ); + d->socknotDict.remove( key ); =20 QEventLoop::unregisterSocketNotifier( notifier ); } Index: nspluginloader.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- nspluginloader.cpp (revision 800743) +++ nspluginloader.cpp (working copy) @@ -32,7 +32,7 @@ =20 =20 #include =2D#include +#include #include #include #include @@ -174,11 +174,9 @@ =20 =20 NSPluginLoader::NSPluginLoader() =2D : QObject(), _mapping(7, false), _viewer(0) + : QObject(), _mapping(), _viewer(0) { scanPlugins(); =2D _mapping.setAutoDelete( true ); =2D _filetype.setAutoDelete(true); } =20 =20 @@ -250,7 +248,7 @@ if (!mime.isEmpty()) { // insert the mimetype -> plugin mapping =2D _mapping.insert(mime, new QString(plugin)); + _mapping.insert(mime, QString(plugin).toLower()); =20 // insert the suffix -> mimetype mapping QStringList::Iterator suffix; @@ -266,8 +264,8 @@ stripped =3D stripped.right( stripped.length()-p ); =20 // add filetype to list =2D if ( !stripped.isEmpty() && !_filetype.find(stripped) ) =2D _filetype.insert( stripped, new QString(mime)); + if ( !stripped.isEmpty() && !_filetype.contains(stripped) ) + _filetype.insert( stripped, QString(mime)); } } } @@ -276,27 +274,30 @@ =20 QString NSPluginLoader::lookupMimeType(const QString &url) { =2D Q3DictIterator dit2(_filetype); =2D while (dit2.current()) =2D { =2D QString ext =3D QString(".")+dit2.currentKey(); =2D if (url.right(ext.length()) =3D=3D ext) =2D return *dit2.current(); =2D ++dit2; + QString result; + QHashIterator dit2(_filetype); + while ( dit2.hasNext() ) { + dit2.next(); + QString ext =3D QString(".")+dit2.key(); + if (url.right(ext.length()) =3D=3D ext) { + result =3D dit2.value(); + break; } =2D return QString(); + } + =20 + return result; } =20 =20 QString NSPluginLoader::lookup(const QString &mimeType) { QString plugin; =2D if ( _mapping[mimeType] ) =2D plugin =3D *_mapping[mimeType]; =2D =2D kDebug() << "Looking up plugin for mimetype " << mimeType << ": " << p= lugin; =2D =2D return plugin; + if ( _mapping.contains(mimeType) ) + plugin =3D _mapping.value(mimeType); + =20 + kDebug() << "Looking up plugin for mimetype " << mimeType << ": " << p= lugin; + =20 + return plugin; } =20 =20 @@ -304,35 +305,32 @@ { kDebug() << "NSPluginLoader::loadViewer"; =20 =2D _process =3D new K3Process; =2D + _process.clearProgram(); // get the dbus app id int pid =3D (int)getpid(); QString tmp; tmp.sprintf("org.kde.nspluginviewer-%d",pid); _viewerDBusId =3Dtmp.toLatin1(); =20 =2D connect( _process, SIGNAL(processExited(K3Process*)), =2D this, SLOT(processTerminated(K3Process*)) ); + connect( &_process, SIGNAL(finished(int, QProcess::ExitStatus)), + this, SLOT(processTerminated(int , QProcess::ExitStatus)) ); =20 // find the external viewer process QString viewer =3D KGlobal::dirs()->findExe("nspluginviewer"); if (viewer.isEmpty()) { kDebug() << "can't find nspluginviewer"; =2D delete _process; return false; } =20 =2D *_process << viewer; + _process << viewer; =20 =2D // tell the process it's parameters =2D *_process << "-dbusservice"; =2D *_process << _viewerDBusId; + _process << "-dbusservice"; + _process << _viewerDBusId; =20 // run the process kDebug() << "Running nspluginviewer"; =2D _process->start(); + _process.start(); =20 // wait for the process to run int cnt =3D 0; @@ -352,14 +350,13 @@ #endif { kDebug() << "timeout"; =2D delete _process; + _process.kill(); return false; } =20 =2D if (!_process->isRunning()) + if (_process.state() =3D=3D QProcess::NotRunning) { kDebug() << "nspluginviewer terminated"; =2D delete _process; return false; } } @@ -380,9 +377,8 @@ _viewer->shutdown(); kDebug() << "Shutdown viewer"; delete _viewer; =2D delete _process; + _process.kill(); _viewer =3D 0; =2D _process =3D 0; } =20 kDebug() << "<- NSPluginLoader::unloadViewer"; @@ -391,16 +387,11 @@ =20 =20 =20 =2Dvoid NSPluginLoader::processTerminated(K3Process *proc) +void NSPluginLoader::processTerminated(int exitCode, QProcess::ExitStatus = exitStatus) { =2D if ( _process =3D=3D proc) =2D { kDebug() << "Viewer process terminated"; delete _viewer; =2D delete _process; _viewer =3D 0; =2D _process =3D 0; =2D } } =20 =20 Index: nspluginloader.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- nspluginloader.h (revision 800743) +++ nspluginloader.h (working copy) @@ -24,24 +24,20 @@ */ =20 =20 =2D#ifndef __NS_PLUGINLOADER_H__ =2D#define __NS_PLUGINLOADER_H__ +#ifndef NS_PLUGINLOADER_H +#define NS_PLUGINLOADER_H =20 =2D =2D =2D#include +#include #include #include #include =2D//Added by qt3to4: =2D#include =2D#include + #include +#include =20 #define EMBEDCLASS QX11EmbedContainer =20 class OrgKdeNspluginsViewerInterface; =2Dclass K3Process; class QPushButton; class QGridLayout; class OrgKdeNspluginsInstanceInterface; @@ -104,13 +100,14 @@ void unloadViewer(); =20 protected Q_SLOTS: =2D void processTerminated( K3Process *proc ); + void processTerminated( int exitCode, QProcess::ExitStatus exitStatus ); =20 private: QStringList _searchPaths; =2D Q3Dict _mapping, _filetype; + QMultiHash _mapping; + QHash _filetype; =20 =2D K3Process *_process; + KProcess _process; QString _viewerDBusId; OrgKdeNspluginsViewerInterface *_viewer; =20 Index: CMakeLists.txt =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- CMakeLists.txt (revision 800743) +++ CMakeLists.txt (working copy) @@ -26,7 +26,7 @@ =20 kde4_add_plugin(libnsplugin ${nsplugins_PART_SRCS}) =20 =2D target_link_libraries(libnsplugin ${KDE4_KDE3SUPPORT_LIBS} ${KDE4_KPA= RTS_LIBS} ${QT_QT3SUPPORT_LIBRARY} ${QT_QTGUI_LIBRARY} ) + target_link_libraries(libnsplugin ${KDE4_KPARTS_LIBS} ${QT_QTGUI_LIBRARY= }) =20 install(TARGETS libnsplugin DESTINATION ${PLUGIN_INSTALL_DIR} ) =20 @@ -38,7 +38,7 @@ =20 kde4_add_plugin(kcminit_nsplugins WITH_PREFIX ${kcminit_nsplugins_SRCS}) =20 =2D target_link_libraries(kcminit_nsplugins ${KDE4_KDE3SUPPORT_LIBS} ${KDE= 4_KDECORE_LIBS} ) + target_link_libraries(kcminit_nsplugins ${KDE4_KDECORE_LIBS} ) =20 install(TARGETS kcminit_nsplugins DESTINATION ${PLUGIN_INSTALL_DIR} ) =20 @@ -68,7 +68,3 @@ message(STATUS "libXt not found - browser plugin support disabled") =20 endif (X11_Xt_LIB) =2D =2D =2D =2D --Boundary-01=_p3NEIFqLP60da1c-- --nextPart1977874.kFUZMYb1X5 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkgQ3ekACgkQooBDqI2Jn8hY4ACbBBCVJFpmJk87w3cvhNHx9aNT MbMAn0kgDZLuzEnpjIL1OiRr40COYsYb =xVZa -----END PGP SIGNATURE----- --nextPart1977874.kFUZMYb1X5-- --===============1014949606== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --===============1014949606==--