[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: nsplugins patch (KDE4)
From:       Urs Wolfer <uwolfer () kde ! org>
Date:       2008-04-24 19:22:16
Message-ID: 200804242122.20434.uwolfer () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


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 
possible, ported the test also to clean Qt 4 code, removed linking against Qt 
/ KDE 3 support libs, cleaned some tab-mess, ...). Patch works here and also 
fixes crash at exit.

I will commit this patch soon if nobody objects.

Bye
urs

["ns.patch" (text/x-patch)]

Index: test/testnsplugin.cpp
===================================================================
--- test/testnsplugin.cpp	(revision 800743)
+++ test/testnsplugin.cpp	(working copy)
@@ -24,8 +24,9 @@
 
 #include <stdio.h>
 
+#include <QHBoxLayout>
+
 #include <kactioncollection.h>
-//Added by qt3to4:
 #include <kapplication.h>
 #include <kcmdlineargs.h>
 #include <kdebug.h>
@@ -107,7 +108,7 @@
    QWidget *win = m_plugins.last();
    if ( win )
    {
-      m_plugins.remove( win );
+      m_plugins.removeAll( win );
       delete win;
    } else
    {
@@ -119,7 +120,7 @@
 void TestNSPlugin::viewDestroyed( NSPluginInstance *inst )
 {
    kDebug() << "TestNSPlugin::viewDestroyed";
-   m_plugins.remove( inst );
+   m_plugins.removeAll( inst );
 }
 
 
Index: test/testnsplugin.h
===================================================================
--- test/testnsplugin.h	(revision 800743)
+++ test/testnsplugin.h	(working copy)
@@ -20,11 +20,10 @@
 */
 
 
-#ifndef __TESTNSPLUGIN_H__
-#define __TESTNSPLUGIN_H__
+#ifndef TESTNSPLUGIN_H
+#define TESTNSPLUGIN_H
 
 #include <QWidget>
-#include <Q3PtrList>
 #include <kxmlguiwindow.h>
 #include <QList>
 
@@ -47,7 +46,7 @@
 
 protected:
   NSPluginLoader *m_loader;
-  Q3PtrList<QWidget> m_plugins;
+  QList<QWidget *> m_plugins;
   QWidget *m_client;
   QBoxLayout *m_layout;
 };
Index: viewer/nsplugin.cpp
===================================================================
--- viewer/nsplugin.cpp	(revision 800743)
+++ viewer/nsplugin.cpp	(working copy)
@@ -37,7 +37,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <Qt3Support/Q3Dict>
 #include <QDir>
 #include <QFile>
 #include <QTimer>
@@ -611,9 +610,6 @@
    _npp->ndata = this;
    _destroyed = false;
    _handle = handle;
-   _tempFiles.setAutoDelete( true );
-   _streams.setAutoDelete( true );
-   _waitingRequests.setAutoDelete( true );
    _callback = new org::kde::nsplugins::CallBack( appId, callbackId, \
QDBusConnection::sessionBus() );  
    KUrl base(src);
@@ -659,17 +655,18 @@
     if ( !_destroyed ) {
 
         kDebug(1431) << "delete streams";
-        _waitingRequests.clear();
+        qDeleteAll( _waitingRequests );
 
 	shutdown();
 
-        for( NSPluginStreamBase *s=_streams.first(); s!=0; ) {
-            NSPluginStreamBase *next = _streams.next();
+	while ( !_streams.isEmpty() ) {
+	    NSPluginStreamBase *s = _streams.takeFirst();
             s->stop();
-            s = next;
+	    delete s;
         }
 
-        _streams.clear();
+        kDebug(1431) << "delete tempfiles";
+        qDeleteAll( _tempFiles );
 
         kDebug(1431) << "delete callbacks";
         delete _callback;
@@ -728,10 +725,10 @@
 
     // start queued requests
     kDebug(1431) << "looking for waiting requests";
-    while ( _waitingRequests.head() ) {
+    while ( !_waitingRequests.isEmpty() ) {
         kDebug(1431) << "request found";
         Request req( *_waitingRequests.head() );
-        _waitingRequests.remove();
+        delete _waitingRequests.dequeue();
 
         QString url;
 
@@ -880,9 +877,7 @@
 {
    kDebug(1431) << "-> NSPluginInstance::streamFinished";
    emitStatus( QString() );
-   _streams.setAutoDelete(false);
-   _streams.remove(strm);
-   _streams.setAutoDelete(true);
+   _streams.removeOne(strm);
    strm->deleteLater();
    _timer->setSingleShot( true );
    _timer->start( 100 );
@@ -1219,7 +1214,6 @@
     _libname = library;
     _constructed = false;
     _error = true;
-    _instances.setAutoDelete( true );
     _NP_GetMIMEDescription = 0;
     _NP_Initialize = 0;
     _NP_Shutdown = 0;
@@ -1274,8 +1268,9 @@
 
 NSPluginClass::~NSPluginClass()
 {
-    _instances.clear();
-    _trash.clear();
+    qDeleteAll( _instances );
+    qDeleteAll( _trash );
+
     shutdown();
     if (_handle)
       _handle->unload();
@@ -1285,10 +1280,14 @@
 void NSPluginClass::timer()
 {
     // delete instances
-    for ( NSPluginInstance *it=_trash.first(); it!=0; it=_trash.next() )
-        _instances.remove(it);
-
-    _trash.clear();
+    while ( !_trash.isEmpty() ) {
+        NSPluginInstance *it = _trash.takeFirst();
+        int i = _instances.indexOf(it);
+        if ( i != -1 )
+            delete _instances.takeAt(i);
+        
+        delete it;
+    }
 }
 
 
Index: viewer/viewer.cpp
===================================================================
--- viewer/viewer.cpp	(revision 800743)
+++ viewer/viewer.cpp	(working copy)
@@ -35,10 +35,8 @@
 #include <kglobal.h>
 #include <klocale.h>
 #include <kmessagebox.h>
-#include <Qt3Support/Q3PtrList>
 #include <QSocketNotifier>
-//Added by qt3to4:
-#include <QEvent>
+
 #include <stdlib.h>
 #include <sys/resource.h>
 #include <sys/time.h>
Index: viewer/nsplugin.h
===================================================================
--- viewer/nsplugin.h	(revision 800743)
+++ viewer/nsplugin.h	(working copy)
@@ -28,12 +28,10 @@
 
 #include <QObject>
 
-#include <Qt3Support/Q3PtrQueue>
 #include <QMap>
-#include <Qt3Support/Q3IntDict>
 #include <QPointer>
-//Added by qt3to4:
-#include <Q3PtrList>
+#include <QQueue>
+#include <QList>
 
 #include <KDebug>
 
@@ -221,9 +219,9 @@
   bool _destroyed;
   bool _embedded;
   void addTempFile(KTemporaryFile *tmpFile);
-  Q3PtrList<KTemporaryFile> _tempFiles;
+  QList<KTemporaryFile *> _tempFiles;
   OrgKdeNspluginsCallBackInterface *_callback;
-  Q3PtrList<NSPluginStreamBase> _streams;
+  QList<NSPluginStreamBase *> _streams;
   KLibrary *_handle;
   QTimer *_timer;
 
@@ -267,7 +265,7 @@
       KParts::BrowserArguments browserArgs;
   };
 
-  Q3PtrQueue<Request> _waitingRequests;
+  QQueue<Request *> _waitingRequests;
   QMap<int, Request*> _jsrequests;
 };
 
@@ -307,8 +305,8 @@
   NP_InitializeUPP *_NP_Initialize;
   NP_ShutdownUPP *_NP_Shutdown;
 
-  Q3PtrList<NSPluginInstance> _instances;
-  Q3PtrList<NSPluginInstance> _trash;
+  QList<NSPluginInstance *> _instances;
+  QList<NSPluginInstance *> _trash;
 
   QByteArray _app;
   NPPluginFuncs _pluginFuncs;
Index: viewer/pluginhost_xt.cpp
===================================================================
--- viewer/pluginhost_xt.cpp	(revision 800743)
+++ viewer/pluginhost_xt.cpp	(working copy)
@@ -52,7 +52,8 @@
 
 PluginHostXt::PluginHostXt(NSPluginInstance* plugin):
     _plugin(plugin), _outside(0), _toplevel(0), _form(0)
-{}
+{
+}
 
 
 void PluginHostXt::setupWindow(int winId, int width, int height)
Index: viewer/qxteventloop.cpp
===================================================================
--- viewer/qxteventloop.cpp	(revision 800743)
+++ viewer/qxteventloop.cpp	(working copy)
@@ -41,9 +41,8 @@
 #include <kglobal.h>
 
 #include <qwidgetintdict.h>
-//Added by qt3to4:
-#include <QEventLoop>
-#include <Q3MemArray>
+#include <QVector>
+#include <QHash>
 
 // resolve the conflict between X11's FocusIn and QEvent::FocusIn
 const int XFocusOut = FocusOut;
@@ -67,10 +66,10 @@
     void unhook();
 
     XtAppContext appContext, ownContext;
-    Q3MemArray<XtEventDispatchProc> dispatchers;
+    QVector<XtEventDispatchProc> dispatchers;
     QWidgetIntDict mapper;
 
-    Q3IntDict<QSocketNotifier> socknotDict;
+    QHash<int, QSocketNotifier> socknotDict;
     bool activate_timers;
     XtIntervalId timerid;
 
@@ -354,7 +353,7 @@
 void qmotif_socknot_handler( XtPointer pointer, int *, XtInputId *id )
 {
     QXtEventLoop *eventloop = (QXtEventLoop *) pointer;
-    QSocketNotifier *socknot = static_d->socknotDict.find( *id );
+    QSocketNotifier *socknot = static_d->socknotDict.value( *id );
     if ( ! socknot ) // this shouldn't happen
 	return;
     eventloop->setSocketNotifierPending( socknot );
@@ -395,17 +394,16 @@
  */
 void QXtEventLoop::unregisterSocketNotifier( QSocketNotifier *notifier )
 {
-    Q3IntDictIterator<QSocketNotifier> it( d->socknotDict );
-    while ( it.current() && notifier != it.current() )
-	++it;
-    if ( ! it.current() ) {
+
+    int key = d->socknotDict.key(notifier);
+    if ( ! key ) {
 	// this shouldn't happen
 	qWarning( "QXtEventLoopEventLoop: failed to unregister socket notifier" );
 	return;
     }
 
-    XtRemoveInput( it.currentKey() );
-    d->socknotDict.remove( it.currentKey() );
+    XtRemoveInput( key );
+    d->socknotDict.remove( key );
 
     QEventLoop::unregisterSocketNotifier( notifier );
 }
Index: nspluginloader.cpp
===================================================================
--- nspluginloader.cpp	(revision 800743)
+++ nspluginloader.cpp	(working copy)
@@ -32,7 +32,7 @@
 
 
 #include <kapplication.h>
-#include <k3process.h>
+#include <kprocess.h>
 #include <kdebug.h>
 #include <kglobal.h>
 #include <klocale.h>
@@ -174,11 +174,9 @@
 
 
 NSPluginLoader::NSPluginLoader()
-   : QObject(), _mapping(7, false), _viewer(0)
+   : QObject(), _mapping(), _viewer(0)
 {
   scanPlugins();
-  _mapping.setAutoDelete( true );
-  _filetype.setAutoDelete(true);
 }
 
 
@@ -250,7 +248,7 @@
       if (!mime.isEmpty())
         {
           // insert the mimetype -> plugin mapping
-          _mapping.insert(mime, new QString(plugin));
+          _mapping.insert(mime, QString(plugin).toLower());
 
           // insert the suffix -> mimetype mapping
           QStringList::Iterator suffix;
@@ -266,8 +264,8 @@
               stripped = stripped.right( stripped.length()-p );
 
               // add filetype to list
-              if ( !stripped.isEmpty() && !_filetype.find(stripped) )
-                  _filetype.insert( stripped, new QString(mime));
+              if ( !stripped.isEmpty() && !_filetype.contains(stripped) )
+                  _filetype.insert( stripped, QString(mime));
           }
         }
     }
@@ -276,27 +274,30 @@
 
 QString NSPluginLoader::lookupMimeType(const QString &url)
 {
-  Q3DictIterator<QString> dit2(_filetype);
-  while (dit2.current())
-    {
-      QString ext = QString(".")+dit2.currentKey();
-      if (url.right(ext.length()) == ext)
-        return *dit2.current();
-      ++dit2;
+   QString result;
+   QHashIterator<QString, QString> dit2(_filetype);
+   while ( dit2.hasNext() ) {
+    dit2.next();
+    QString ext = QString(".")+dit2.key();
+    if (url.right(ext.length()) == ext) {
+        result = dit2.value();
+        break;
     }
-  return QString();
+    }
+    
+   return result;
 }
 
 
 QString NSPluginLoader::lookup(const QString &mimeType)
 {
     QString plugin;
-    if (  _mapping[mimeType] )
-        plugin = *_mapping[mimeType];
-
-  kDebug() << "Looking up plugin for mimetype " << mimeType << ": " << plugin;
-
-  return plugin;
+    if (  _mapping.contains(mimeType) )
+        plugin = _mapping.value(mimeType);
+    
+    kDebug() << "Looking up plugin for mimetype " << mimeType << ": " << plugin;
+    
+    return plugin;
 }
 
 
@@ -304,35 +305,32 @@
 {
    kDebug() << "NSPluginLoader::loadViewer";
 
-   _process = new K3Process;
-
+   _process.clearProgram();
    // get the dbus app id
    int pid = (int)getpid();
    QString tmp;
    tmp.sprintf("org.kde.nspluginviewer-%d",pid);
    _viewerDBusId =tmp.toLatin1();
 
-   connect( _process, SIGNAL(processExited(K3Process*)),
-            this, SLOT(processTerminated(K3Process*)) );
+   connect( &_process, SIGNAL(finished(int, QProcess::ExitStatus)),
+            this, SLOT(processTerminated(int , QProcess::ExitStatus)) );
 
    // find the external viewer process
    QString viewer = KGlobal::dirs()->findExe("nspluginviewer");
    if (viewer.isEmpty())
    {
       kDebug() << "can't find nspluginviewer";
-      delete _process;
       return false;
    }
 
-   *_process << viewer;
+   _process << viewer;
 
-   // tell the process it's parameters
-   *_process << "-dbusservice";
-   *_process << _viewerDBusId;
+   _process << "-dbusservice";
+   _process << _viewerDBusId;
 
    // run the process
    kDebug() << "Running nspluginviewer";
-   _process->start();
+   _process.start();
 
    // wait for the process to run
    int cnt = 0;
@@ -352,14 +350,13 @@
 #endif
       {
          kDebug() << "timeout";
-         delete _process;
+         _process.kill();
          return false;
       }
 
-      if (!_process->isRunning())
+      if (_process.state() == QProcess::NotRunning)
       {
          kDebug() << "nspluginviewer terminated";
-         delete _process;
          return false;
       }
    }
@@ -380,9 +377,8 @@
       _viewer->shutdown();
       kDebug() << "Shutdown viewer";
       delete _viewer;
-      delete _process;
+      _process.kill();
       _viewer = 0;
-      _process = 0;
    }
 
    kDebug() << "<- NSPluginLoader::unloadViewer";
@@ -391,16 +387,11 @@
 
 
 
-void NSPluginLoader::processTerminated(K3Process *proc)
+void NSPluginLoader::processTerminated(int exitCode, QProcess::ExitStatus \
exitStatus)  {
-   if ( _process == proc)
-   {
       kDebug() << "Viewer process  terminated";
       delete _viewer;
-      delete _process;
       _viewer = 0;
-      _process = 0;
-   }
 }
 
 
Index: nspluginloader.h
===================================================================
--- nspluginloader.h	(revision 800743)
+++ nspluginloader.h	(working copy)
@@ -24,24 +24,20 @@
 */
 
 
-#ifndef __NS_PLUGINLOADER_H__
-#define __NS_PLUGINLOADER_H__
+#ifndef NS_PLUGINLOADER_H
+#define NS_PLUGINLOADER_H
 
-
-
-#include <Qt3Support/Q3Dict>
+#include <QHash>
 #include <QObject>
 #include <QWidget>
 #include <QtGui/QX11EmbedContainer>
-//Added by qt3to4:
-#include <QGridLayout>
-#include <QResizeEvent>
+
 #include <kdemacros.h>
+#include <kprocess.h>
 
 #define EMBEDCLASS QX11EmbedContainer
 
 class OrgKdeNspluginsViewerInterface;
-class K3Process;
 class QPushButton;
 class QGridLayout;
 class OrgKdeNspluginsInstanceInterface;
@@ -104,13 +100,14 @@
   void unloadViewer();
 
 protected Q_SLOTS:
-  void processTerminated( K3Process *proc );
+  void processTerminated( int exitCode, QProcess::ExitStatus exitStatus );
 
 private:
   QStringList _searchPaths;
-  Q3Dict<QString> _mapping, _filetype;
+  QMultiHash<QString, QString> _mapping;
+  QHash<QString, QString> _filetype;
 
-  K3Process *_process;
+  KProcess _process;
   QString _viewerDBusId;
   OrgKdeNspluginsViewerInterface *_viewer;
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 800743)
+++ CMakeLists.txt	(working copy)
@@ -26,7 +26,7 @@
 
   kde4_add_plugin(libnsplugin ${nsplugins_PART_SRCS})
 
-  target_link_libraries(libnsplugin  ${KDE4_KDE3SUPPORT_LIBS} ${KDE4_KPARTS_LIBS} \
${QT_QT3SUPPORT_LIBRARY} ${QT_QTGUI_LIBRARY} ) +  target_link_libraries(libnsplugin \
${KDE4_KPARTS_LIBS} ${QT_QTGUI_LIBRARY})  
   install(TARGETS libnsplugin  DESTINATION ${PLUGIN_INSTALL_DIR} )
 
@@ -38,7 +38,7 @@
 
   kde4_add_plugin(kcminit_nsplugins WITH_PREFIX  ${kcminit_nsplugins_SRCS})
 
-  target_link_libraries(kcminit_nsplugins ${KDE4_KDE3SUPPORT_LIBS} \
${KDE4_KDECORE_LIBS} ) +  target_link_libraries(kcminit_nsplugins \
${KDE4_KDECORE_LIBS} )  
   install(TARGETS kcminit_nsplugins  DESTINATION ${PLUGIN_INSTALL_DIR} )
 
@@ -68,7 +68,3 @@
   message(STATUS "libXt not found - browser plugin support disabled")
 
 endif (X11_Xt_LIB)
-
-
-
-


["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic