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

List:       kde-devel
Subject:    nsplugins patch (KDE4)
From:       Sergey Saukh <thelich () yandex ! ru>
Date:       2008-04-24 10:04:19
Message-ID: 200804241704.33040.thelich () yandex ! ru
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


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.

-- 
Best regards,
Sergey A Saukh

["nsplugins.diff" (text/x-diff)]

diff -ubEr kdebase.orig/apps/nsplugins/nspluginloader.cpp \
                kdebase/apps/nsplugins/nspluginloader.cpp
--- kdebase.orig/apps/nsplugins/nspluginloader.cpp	2008-03-09 19:39:11.000000000 \
                +0600
+++ kdebase/apps/nsplugins/nspluginloader.cpp	2008-04-24 16:38:45.000000000 +0700
@@ -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,23 +274,26 @@
 
 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];
+  if (  _mapping.contains(mimeType) )
+	plugin = _mapping.value(mimeType);
 
   kDebug() << "Looking up plugin for mimetype " << mimeType << ": " << 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;
-   }
 }
 
 
diff -ubEr kdebase.orig/apps/nsplugins/nspluginloader.h \
                kdebase/apps/nsplugins/nspluginloader.h
--- kdebase.orig/apps/nsplugins/nspluginloader.h	2008-03-09 19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/nspluginloader.h	2008-04-24 15:56:44.000000000 +0700
@@ -29,7 +29,8 @@
 
 
 
-#include <Qt3Support/Q3Dict>
+#include <QProcess>
+#include <QHash>
 #include <QObject>
 #include <QWidget>
 #include <QtGui/QX11EmbedContainer>
@@ -37,11 +38,11 @@
 #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 +105,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;
 
diff -ubEr kdebase.orig/apps/nsplugins/viewer/nsplugin.cpp \
                kdebase/apps/nsplugins/viewer/nsplugin.cpp
--- kdebase.orig/apps/nsplugins/viewer/nsplugin.cpp	2008-03-09 19:39:11.000000000 \
                +0600
+++ kdebase/apps/nsplugins/viewer/nsplugin.cpp	2008-04-24 16:40:21.000000000 +0700
@@ -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,20 @@
     if ( !_destroyed ) {
 
         kDebug(1431) << "delete streams";
-        _waitingRequests.clear();
+        while ( !_waitingRequests.isEmpty() )
+	    delete _waitingRequests.dequeue();
 
 	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";
+	while ( !_tempFiles.isEmpty() )
+	    delete _tempFiles.takeFirst();
 
         kDebug(1431) << "delete callbacks";
         delete _callback;
@@ -728,10 +727,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 +879,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 +1216,6 @@
     _libname = library;
     _constructed = false;
     _error = true;
-    _instances.setAutoDelete( true );
     _NP_GetMIMEDescription = 0;
     _NP_Initialize = 0;
     _NP_Shutdown = 0;
@@ -1274,8 +1270,12 @@
 
 NSPluginClass::~NSPluginClass()
 {
-    _instances.clear();
-    _trash.clear();
+    while ( !_instances.isEmpty() )
+	delete _instances.takeFirst();
+
+    while ( !_trash.isEmpty() )
+	delete _trash.takeFirst();
+
     shutdown();
     if (_handle)
       _handle->unload();
@@ -1285,10 +1285,14 @@
 void NSPluginClass::timer()
 {
     // delete instances
-    for ( NSPluginInstance *it=_trash.first(); it!=0; it=_trash.next() )
-        _instances.remove(it);
+    while ( !_trash.isEmpty() ) {
+	NSPluginInstance *it = _trash.takeFirst();
+	int i = _instances.indexOf(it);
+	if ( i != -1 )
+	    delete _instances.takeAt(i);
 
-    _trash.clear();
+	delete it;
+    }
 }
 
 
diff -ubEr kdebase.orig/apps/nsplugins/viewer/nsplugin.h \
                kdebase/apps/nsplugins/viewer/nsplugin.h
--- kdebase.orig/apps/nsplugins/viewer/nsplugin.h	2008-03-09 19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/nsplugin.h	2008-04-24 16:06:50.000000000 +0700
@@ -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;
diff -ubEr kdebase.orig/apps/nsplugins/viewer/pluginhost_xt.cpp \
                kdebase/apps/nsplugins/viewer/pluginhost_xt.cpp
--- kdebase.orig/apps/nsplugins/viewer/pluginhost_xt.cpp	2008-03-09 \
                19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/pluginhost_xt.cpp	2008-04-24 16:44:15.000000000 \
+0700 @@ -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)
diff -ubEr kdebase.orig/apps/nsplugins/viewer/qxteventloop.cpp \
                kdebase/apps/nsplugins/viewer/qxteventloop.cpp
--- kdebase.orig/apps/nsplugins/viewer/qxteventloop.cpp	2008-03-09 19:39:11.000000000 \
                +0600
+++ kdebase/apps/nsplugins/viewer/qxteventloop.cpp	2008-04-24 16:46:09.000000000 \
+0700 @@ -43,7 +43,8 @@
 #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 +68,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 +355,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 +396,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 );
 }
diff -ubEr kdebase.orig/apps/nsplugins/viewer/viewer.cpp \
                kdebase/apps/nsplugins/viewer/viewer.cpp
--- kdebase.orig/apps/nsplugins/viewer/viewer.cpp	2008-03-09 19:39:11.000000000 +0600
+++ kdebase/apps/nsplugins/viewer/viewer.cpp	2008-04-24 16:10:39.000000000 +0700
@@ -35,7 +35,6 @@
 #include <kglobal.h>
 #include <klocale.h>
 #include <kmessagebox.h>
-#include <Qt3Support/Q3PtrList>
 #include <QSocketNotifier>
 //Added by qt3to4:
 #include <QEvent>


["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