>From 5f37d8fbbaab234380aaa9391908b7d1965cb552 Mon Sep 17 00:00:00 2001
From: Sian Cao <sycao@redflag-linux.com>
Date: Mon, 28 Dec 2009 15:19:56 +0800
Subject: [PATCH] Some fixes for mount/umount removables
     a. when a removable removed, jump to home url and refresh view
     b. when click on a place, unmount it, and then click again,
        the icon indicates that device has been mounted, but content
        does not refresh. so fix it.
     c. popup dolphin from devicenotifier applet, then umount it from
        devicenotifier. after that try mount it by clicking on the
        corresponding place in dolphin, the behaviour is incorrect. so
        fix it.
     ps. this fix needs some changes of KFilePlacesView/Model from kdelibs.

Signed-off-by: Sian Cao <sycao@redflag-linux.com>
---
 apps/dolphin/src/dolphinapplication.cpp |    3 ++-
 apps/dolphin/src/dolphinmainwindow.cpp  |   21 ++++++++++++++++++++-
 apps/dolphin/src/dolphinmainwindow.h    |    5 +++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/apps/dolphin/src/dolphinapplication.cpp b/apps/dolphin/src/dolphinapplication.cpp
index f61bf79..cf5613a 100644
--- a/apps/dolphin/src/dolphinapplication.cpp
+++ b/apps/dolphin/src/dolphinapplication.cpp
@@ -104,7 +104,8 @@ int DolphinApplication::openWindow(const KUrl& url)
 {
     DolphinMainWindow* win = createMainWindow();
     if ((win->activeViewContainer() != 0) && url.isValid()) {
-        win->activeViewContainer()->setUrl(url);
+//        win->activeViewContainer()->setUrl(url);
+        win->changeUrl(url);		
     }
     win->show();
     return win->getId();
diff --git a/apps/dolphin/src/dolphinmainwindow.cpp b/apps/dolphin/src/dolphinmainwindow.cpp
index fdf5542..711b3cf 100644
--- a/apps/dolphin/src/dolphinmainwindow.cpp
+++ b/apps/dolphin/src/dolphinmainwindow.cpp
@@ -230,7 +230,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     }
 
     DolphinViewContainer* view = activeViewContainer();
-    if (view != 0) {
+    if ( view != 0 && (url != view->url()) ) {
         view->setUrl(url);
         updateEditActions();
         updateViewActions();
@@ -245,6 +245,23 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     }
 }
 
+void DolphinMainWindow::updatePlaceContent(const KUrl& url, bool removed)
+{
+//  kDebug() << "Url " << url << " is " << (removed? "removed": "mounted");
+    DolphinViewContainer* view = activeViewContainer();
+    if (view ) {
+        if ( removed ) {
+            const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
+            kDebug() << "go back to home " << generalSettings->homeUrl();
+            changeUrl( generalSettings->homeUrl() );
+            
+        } else {
+            if ( url == view->url() )
+                reloadView();
+        }
+    }
+}
+
 void DolphinMainWindow::changeSelection(const KFileItemList& selection)
 {
     activeViewContainer()->view()->changeSelection(selection);
@@ -1381,6 +1398,8 @@ void DolphinMainWindow::setupDockWidgets()
     addDockWidget(Qt::LeftDockWidgetArea, placesDock);
     connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
             this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
+	connect(placesPanel, SIGNAL(placeAccessabilityChange(const KUrl&, bool)),
+			this, SLOT(updatePlaceContent(const KUrl&, bool)));
     connect(this, SIGNAL(urlChanged(KUrl)),
             placesPanel, SLOT(setUrl(KUrl)));
 }
diff --git a/apps/dolphin/src/dolphinmainwindow.h b/apps/dolphin/src/dolphinmainwindow.h
index c1e0ffc..cbce2e0 100644
--- a/apps/dolphin/src/dolphinmainwindow.h
+++ b/apps/dolphin/src/dolphinmainwindow.h
@@ -134,6 +134,11 @@ public slots:
      */
     void changeSelection(const KFileItemList& selection);
 
+	/**
+	 * Gets Called when a place (removable devices) changed accessibility
+	 */
+	void updatePlaceContent(const KUrl& url, bool removed);
+	
     /** Stores all settings and quits Dolphin. */
     void quit();
 
-- 
1.6.5.2

