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

List:       kfm-devel
Subject:    [PATCH] devicenotifier and dolphin interactive problem
From:       sonald <sycao () redflag-linux ! com>
Date:       2009-12-28 7:47:02
Message-ID: 4B386276.7050405 () redflag-linux ! com
[Download RAW message or body]

Hi, all
      I found a problem concerning devicenotifier and dolphin. the 
scenario is quite easy to produce,
when you plug in a flash drive, devicenotifier applet popup and you 
click it and open with file
manager ( dolphin ),  it shows mounted state in dolphin. then you click 
devicenotifier to unmount
it. now dolphin keeps the view of dity content. I believe the problem is 
that no device change event
reports, so dolphin has no idea how to do this nicely.
      In the middle of my fix, I found another related problem of 
dolphin. it's also quite easy to show .
You just click flash drive icon on the places panel in dolphin to mount 
it, and right-click and choose
'safely remove' to eject it, then click it again. At this time, no mount 
activated any more.

I made some changes to kdelibs/kfile and then dolphin to make it all 
work. Is it ok to commit, or any suggestions ?

ps: I've made changes against kde 4.3.x, I believe it applies to trunk too.

Sian Cao


["0001-Fix-for-the-awareness-of-accessibility-change-for-do.patch" (text/plain)]

>From 89612e96575bb2d81665381c1a55e89d93106b73 Mon Sep 17 00:00:00 2001
From: Sian Cao <sycao@redflag-linux.com>
Date: Mon, 28 Dec 2009 15:39:01 +0800
Subject: [PATCH] Fix for the awareness of accessibility change for dolphin

this patch provide an interface to inform outside the changes
of device accessibilities. so app like dolphin know how to do
the correct thing when this happens, like reloading the view.

Signed-off-by: Sian Cao <sycao@redflag-linux.com>
---
 kfile/kfileplacesitem.cpp  |   11 +++++++++++
 kfile/kfileplacesitem_p.h  |    1 +
 kfile/kfileplacesmodel.cpp |   32 +++++++++++++++++++++++++++++++-
 kfile/kfileplacesmodel.h   |    6 ++++--
 kfile/kfileplacesview.cpp  |    4 +++-
 kfile/kfileplacesview.h    |    6 +++++-
 6 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/kfile/kfileplacesitem.cpp b/kfile/kfileplacesitem.cpp
index 240ac49..298ace0 100644
--- a/kfile/kfileplacesitem.cpp
+++ b/kfile/kfileplacesitem.cpp
@@ -54,6 +54,7 @@ KFilePlacesItem::KFilePlacesItem(KBookmarkManager *manager,
         Solid::Device dev(udi);
         Solid::StorageAccess *access = dev.as<Solid::StorageAccess>();
         if (access!=0) {
+            m_bookmark.setMetaDataItem("lastMountPoint", access->filePath());
             connect(access, SIGNAL(accessibilityChanged(bool, const QString &)),
                     this, SLOT(onAccessibilityChanged()));
         }
@@ -267,7 +268,17 @@ QString KFilePlacesItem::generateNewId()
 
 void KFilePlacesItem::onAccessibilityChanged()
 {
+    if ( isDevice() ) {
+        Solid::Device dev = device();
+        if ( dev.as<Solid::StorageAccess>()->isAccessible() ) {
+            const QString path = m_access->filePath();			
+            if ( m_bookmark.metaDataItem("lastMountPoint") != path )
+                m_bookmark.setMetaDataItem("lastMountPoint", path);
+        }
+    }
+	
     emit itemChanged(id());
+    emit accessibilityChanged(id());
 }
 
 bool KFilePlacesItem::hasFullIcon(const KBookmark &bookmark) const
diff --git a/kfile/kfileplacesitem_p.h b/kfile/kfileplacesitem_p.h
index 49339f2..f16a5cd 100644
--- a/kfile/kfileplacesitem_p.h
+++ b/kfile/kfileplacesitem_p.h
@@ -66,6 +66,7 @@ public:
 
 Q_SIGNALS:
     void itemChanged(const QString &id);
+    void accessibilityChanged(const QString &id);	
 
 private Q_SLOTS:
     void onAccessibilityChanged();
diff --git a/kfile/kfileplacesmodel.cpp b/kfile/kfileplacesmodel.cpp
index 7fe5bcc..51e16e6 100644
--- a/kfile/kfileplacesmodel.cpp
+++ b/kfile/kfileplacesmodel.cpp
@@ -69,7 +69,7 @@ public:
     Solid::Predicate predicate;
     KBookmarkManager *bookmarkManager;
     KFilePlacesSharedBookmarks * sharedBookmarks;
-
+	
     void reloadAndSignal();
     QList<KFilePlacesItem *> loadBookmarkList();
 
@@ -80,6 +80,7 @@ public:
     void _k_reloadBookmarks();
     void _k_storageSetupDone(Solid::ErrorType error, QVariant errorData);
     void _k_storageTeardownDone(Solid::ErrorType error, QVariant errorData);
+	void _k_storageChanged(const QString& id);
 };
 
 KFilePlacesModel::KFilePlacesModel(QObject *parent)
@@ -434,6 +435,8 @@ QList<KFilePlacesItem *> KFilePlacesModel::Private::loadBookmarkList()
             }
             connect(item, SIGNAL(itemChanged(const QString&)),
                     q, SLOT(_k_itemChanged(const QString&)));
+            connect(item, SIGNAL(accessibilityChanged(const QString&)),
+                    q, SLOT(_k_storageChanged(const QString&)));
             items << item;
         }
 
@@ -448,6 +451,8 @@ QList<KFilePlacesItem *> KFilePlacesModel::Private::loadBookmarkList()
                                                         bookmark.address(), udi);
             connect(item, SIGNAL(itemChanged(const QString&)),
                     q, SLOT(_k_itemChanged(const QString&)));
+            connect(item, SIGNAL(accessibilityChanged(const QString&)),
+                    q, SLOT(_k_storageChanged(const QString&)));
             // TODO: Update bookmark internal element
             items << item;
         }
@@ -822,4 +827,29 @@ void KFilePlacesModel::Private::_k_storageTeardownDone(Solid::ErrorType error, Q
     }
 }
 
+void KFilePlacesModel::Private::_k_storageChanged(const QString& id)
+{
+    bool removed = false;
+    QModelIndex index;
+    KUrl url("");
+    for ( int row = 0; row < items.size(); ++row ) {
+        if ( items.at(row)->id() == id ) {
+            QModelIndex index = q->index(row, 0);
+            Solid::Device dev = q->deviceForIndex(index);
+            if (dev.is<Solid::StorageAccess>() && dev.as<Solid::StorageAccess>()->isAccessible()) {
+                url = q->url(index);
+                removed = false;
+            } else {
+                removed = true;
+                const KBookmark bookmark = items.at(row)->bookmark();
+                url = bookmark.metaDataItem("lastMountPoint");
+            }
+            break;
+        }
+    }
+
+    kDebug() << "id " << id << ", url " << url;
+    emit q->accessibilityChanged(url, removed);
+}
+
 #include "kfileplacesmodel.moc"
diff --git a/kfile/kfileplacesmodel.h b/kfile/kfileplacesmodel.h
index 6637267..30e6fb8 100644
--- a/kfile/kfileplacesmodel.h
+++ b/kfile/kfileplacesmodel.h
@@ -130,7 +130,8 @@ public:
 Q_SIGNALS:
     void errorMessage(const QString &message);
     void setupDone(const QModelIndex &index, bool success);
-
+	void accessibilityChanged(const KUrl& url, bool removed);
+	
 private:
     Q_PRIVATE_SLOT(d, void _k_initDeviceList())
     Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString&))
@@ -139,7 +140,8 @@ private:
     Q_PRIVATE_SLOT(d, void _k_reloadBookmarks())
     Q_PRIVATE_SLOT(d, void _k_storageSetupDone(Solid::ErrorType, QVariant))
     Q_PRIVATE_SLOT(d, void _k_storageTeardownDone(Solid::ErrorType, QVariant))
-
+    Q_PRIVATE_SLOT(d, void _k_storageChanged(const QString& id))
+		
     class Private;
     Private * const d;
     friend class Private;
diff --git a/kfile/kfileplacesview.cpp b/kfile/kfileplacesview.cpp
index 07baca8..4b8e47d 100644
--- a/kfile/kfileplacesview.cpp
+++ b/kfile/kfileplacesview.cpp
@@ -835,6 +835,8 @@ void KFilePlacesView::setModel(QAbstractItemModel *model)
             this, SLOT(adaptItemSize()));
     connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
             d->watcher, SLOT(currentIndexChanged(const QModelIndex&)));
+	connect(model, SIGNAL(accessibilityChanged(const KUrl&, bool)),
+			this, SIGNAL(placeAccessabilityChange(const KUrl&, bool)));
 }
 
 void KFilePlacesView::rowsInserted(const QModelIndex &parent, int start, int end)
@@ -890,7 +892,7 @@ void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index)
 
     KUrl url = placesModel->url(index);
 
-    if (url.isValid()) {
+    if (url.isValid() && currentUrl != url ) {
         currentUrl = url;
         updateHiddenRows();
         emit q->urlChanged(url);
diff --git a/kfile/kfileplacesview.h b/kfile/kfileplacesview.h
index 88ba8dd..8e1bb93 100644
--- a/kfile/kfileplacesview.h
+++ b/kfile/kfileplacesview.h
@@ -90,7 +90,11 @@ Q_SIGNALS:
      * corresponding action like copying or moving.
      */
     void urlsDropped(const KUrl &dest, QDropEvent *event, QWidget *parent);
-
+	/**
+	 * Is emitted if device(removable) accessability changed
+	 */
+	void placeAccessabilityChange(const KUrl &url, bool removed);
+	
 private:
     Q_PRIVATE_SLOT(d, void adaptItemSize())
     Q_PRIVATE_SLOT(d, void _k_placeClicked(const QModelIndex &))
-- 
1.6.5.2



["0001-Some-fixes-for-mount-umount-removables.patch" (text/plain)]

>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




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

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