]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Find out the main window by calling the parent widget's window() member
authorFrank Reininghaus <frank78ac@googlemail.com>
Sat, 29 Sep 2012 17:47:00 +0000 (19:47 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sat, 29 Sep 2012 17:53:14 +0000 (19:53 +0200)
KFileItemModel calls the dir lister's setMainWindow() method to make
sure that the dir lister caches authentication data. However, the method
used to determine the main window (qApp->activeWindow()) is not
guaranteed to yield the DolphinMainWindow or the KonqMainWindow. In
particular, if "Split View" is enabled in Dolphin's settings dialog, the
active window is the dialog, and when it is closed, any later access to
the stored pointer leads to a crash.

A better method is to verify that the model's parent is a QWidget and
then use this widget's window(). I had to make a small modification in
DolphinMainWindow to make sure that it also works correctly when the
view is split (the new view container had been created with a 0 parent
previously).

I tested it in Dolphin and Konqueror and verified that the "main window"
passed to the dir lister is really the application's main window.

BUG: 306459
FIXED-IN: 4.9.3

src/dolphinmainwindow.cpp
src/kitemviews/kfileitemmodel.cpp

index 17268297c5dcd336469efe44d7a51c1933fd2c82..babaf1486ebe577ad60743d4b6447a77e0d172eb 100644 (file)
@@ -2057,7 +2057,13 @@ void DolphinMainWindow::createSecondaryView(int tabIndex)
     const int newWidth = (viewTab.primaryView->width() - splitter->handleWidth()) / 2;
 
     const DolphinView* view = viewTab.primaryView->view();
-    viewTab.secondaryView = createViewContainer(view->url(), 0);
+    // The final parent of the new view container will be set by adding it
+    // to the splitter. However, we must make sure that the DolphinMainWindow
+    // is a parent of the view container already when it is constructed
+    // because this enables the container's KFileItemModel to assign its
+    // dir lister to the right main window. The dir lister can then cache
+    // authentication data.
+    viewTab.secondaryView = createViewContainer(view->url(), this);
     splitter->addWidget(viewTab.secondaryView);
     splitter->setSizes(QList<int>() << newWidth << newWidth);
 
index 752bc9365f39a0e8036f8501dce77c63d39c9869..61f512a8e5505a110a351525ee6592e8b2093f96 100644 (file)
@@ -31,6 +31,7 @@
 #include <QApplication>
 #include <QMimeData>
 #include <QTimer>
+#include <QWidget>
 
 // #define KFILEITEMMODEL_DEBUG
 
@@ -59,7 +60,11 @@ KFileItemModel::KFileItemModel(QObject* parent) :
     m_dirLister = new KFileItemModelDirLister(this);
     m_dirLister->setAutoUpdate(true);
     m_dirLister->setDelayedMimeTypes(true);
-    m_dirLister->setMainWindow(qApp->activeWindow());
+
+    const QWidget* parentWidget = qobject_cast<QWidget*>(parent);
+    if (parentWidget) {
+        m_dirLister->setMainWindow(parentWidget->window());
+    }
 
     connect(m_dirLister, SIGNAL(started(KUrl)), this, SIGNAL(directoryLoadingStarted()));
     connect(m_dirLister, SIGNAL(canceled()), this, SLOT(slotCanceled()));