]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Setup storage device if needed
authorPeter Penz <peter.penz19@gmail.com>
Thu, 7 Jun 2012 20:59:16 +0000 (22:59 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 7 Jun 2012 21:00:57 +0000 (23:00 +0200)
BUG: 301071
FIXED-IN: 4.9.0

src/panels/places/placesitem.cpp
src/panels/places/placesitem.h
src/panels/places/placesitemmodel.cpp
src/panels/places/placesitemmodel.h
src/panels/places/placespanel.cpp
src/panels/places/placespanel.h

index 191f8b2779fb869d51c07f0c57a44a7bd00f5491..10bebc231793a294ec67f4a69d688d1ea672ed39 100644 (file)
@@ -180,6 +180,11 @@ PlacesItem::GroupType PlacesItem::groupType() const
     return DevicesType;
 }
 
+bool PlacesItem::storageSetupNeeded() const
+{
+    return m_access ? !m_access->isAccessible() : false;
+}
+
 KBookmark PlacesItem::createBookmark(KBookmarkManager* manager,
                                      const QString& text,
                                      const KUrl& url,
index 1d221170cca47ae7a569f67e45c707669cb6bce0..5a24a526867f6649e6f156bedb3e0ab69b6fa898 100644 (file)
@@ -69,6 +69,8 @@ public:
 
     GroupType groupType() const;
 
+    bool storageSetupNeeded() const;
+
     static KBookmark createBookmark(KBookmarkManager* manager,
                                     const QString& text,
                                     const KUrl& url,
index 1138f13788f44156100341143aca35390da91336..8530b92f56f36fee2b3e2880f0094b35369b30ec 100644 (file)
@@ -83,7 +83,8 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
     m_bookmarkedItems(),
     m_hiddenItemToRemove(-1),
     m_saveBookmarksTimer(0),
-    m_updateBookmarksTimer(0)
+    m_updateBookmarksTimer(0),
+    m_storageSetupInProgress()
 {
 #ifdef HAVE_NEPOMUK
     m_nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized());
@@ -338,6 +339,35 @@ void PlacesItemModel::requestTeardown(int index)
     }
 }
 
+bool PlacesItemModel::storageSetupNeeded(int index) const
+{
+    const PlacesItem* item = placesItem(index);
+    return item ? item->storageSetupNeeded() : false;
+}
+
+void PlacesItemModel::requestStorageSetup(int index)
+{
+    const PlacesItem* item = placesItem(index);
+    if (!item) {
+        return;
+    }
+
+    Solid::Device device = item->device();
+    const bool setup = device.is<Solid::StorageAccess>()
+                       && !m_storageSetupInProgress.contains(device.as<Solid::StorageAccess>())
+                       && !device.as<Solid::StorageAccess>()->isAccessible();
+    if (setup) {
+        Solid::StorageAccess* access = device.as<Solid::StorageAccess>();
+
+        m_storageSetupInProgress[access] = index;
+
+        connect(access, SIGNAL(setupDone(Solid::ErrorType,QVariant,QString)),
+                this, SLOT(slotStorageSetupDone(Solid::ErrorType,QVariant,QString)));
+
+        access->setup();
+    }
+}
+
 QMimeData* PlacesItemModel::createMimeData(const QSet<int>& indexes) const
 {
     KUrl::List urls;
@@ -552,6 +582,37 @@ void PlacesItemModel::slotStorageTeardownDone(Solid::ErrorType error, const QVar
     }
 }
 
+void PlacesItemModel::slotStorageSetupDone(Solid::ErrorType error,
+                                           const QVariant& errorData,
+                                           const QString& udi)
+{
+    Q_UNUSED(udi);
+
+    const int index = m_storageSetupInProgress.take(sender());
+    const PlacesItem*  item = placesItem(index);
+    if (!item) {
+        return;
+    }
+
+    if (error) {
+        // TODO: Request message-freeze exception
+        if (errorData.isValid()) {
+        //    emit errorMessage(i18nc("@info", "An error occurred while accessing '%1', the system responded: %2",
+        //                            item->text(),
+        //                            errorData.toString()));
+            emit errorMessage(QString("An error occurred while accessing '%1', the system responded: %2")
+                              .arg(item->text()).arg(errorData.toString()));
+        } else {
+        //    emit errorMessage(i18nc("@info", "An error occurred while accessing '%1'",
+        //                            item->text()));
+            emit errorMessage(QString("An error occurred while accessing '%1'").arg(item->text()));
+        }
+        emit storageSetupDone(index, false);
+    } else {
+        emit storageSetupDone(index, true);
+    }
+}
+
 void PlacesItemModel::hideItem()
 {
     hideItem(m_hiddenItemToRemove);
@@ -565,7 +626,7 @@ void PlacesItemModel::updateBookmarks()
     KBookmarkGroup root = m_bookmarkManager->root();
     KBookmark newBookmark = root.first();
     while (!newBookmark.isNull()) {
-        if (acceptBookmark(newBookmark)) {
+        if (acceptBookmark(newBookmark, m_availableDevices)) {
             bool found = false;
             int modelIndex = 0;
             for (int i = 0; i < m_bookmarkedItems.count(); ++i) {
@@ -663,7 +724,7 @@ void PlacesItemModel::loadBookmarks()
     QList<PlacesItem*> devicesItems;
 
     while (!bookmark.isNull()) {
-        if (acceptBookmark(bookmark)) {
+        if (acceptBookmark(bookmark, devices)) {
             PlacesItem* item = new PlacesItem(bookmark);
             if (item->groupType() == PlacesItem::DevicesType) {
                 devices.remove(item->udi());
@@ -736,12 +797,13 @@ void PlacesItemModel::loadBookmarks()
 #endif
 }
 
-bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark) const
+bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark,
+                                     const QSet<QString>& availableDevices) const
 {
     const QString udi = bookmark.metaDataItem("UDI");
     const KUrl url = bookmark.url();
     const QString appName = bookmark.metaDataItem("OnlyInApp");
-    const bool deviceAvailable = m_availableDevices.contains(udi);
+    const bool deviceAvailable = availableDevices.contains(udi);
 
     const bool allowedHere = (appName.isEmpty()
                               || appName == KGlobal::mainComponent().componentName()
index 89a111730bdc491a89c5a1f92ff311e119a8b790..b0f66d652a6447b5635b117a1dc653372e96d579 100644 (file)
@@ -114,6 +114,9 @@ public:
     void requestEject(int index);
     void requestTeardown(int index);
 
+    bool storageSetupNeeded(int index) const;
+    void requestStorageSetup(int index);
+
     /** @reimp */
     virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
 
@@ -129,6 +132,7 @@ public:
 
 signals:
     void errorMessage(const QString& message);
+    void storageSetupDone(int index, bool success);
 
 protected:
     virtual void onItemInserted(int index);
@@ -139,6 +143,7 @@ private slots:
     void slotDeviceAdded(const QString& udi);
     void slotDeviceRemoved(const QString& udi);
     void slotStorageTeardownDone(Solid::ErrorType error, const QVariant& errorData);
+    void slotStorageSetupDone(Solid::ErrorType error, const QVariant& errorData, const QString& udi);
     void hideItem();
 
     /**
@@ -169,7 +174,8 @@ private:
      *         current application (e.g. bookmarks from other applications
      *         will be ignored).
      */
-    bool acceptBookmark(const KBookmark& bookmark) const;
+    bool acceptBookmark(const KBookmark& bookmark,
+                        const QSet<QString>& availableDevices) const;
 
     /**
      * Creates a PlacesItem for a system-bookmark:
@@ -290,6 +296,8 @@ private:
 
     QTimer* m_saveBookmarksTimer;
     QTimer* m_updateBookmarksTimer;
+
+    QHash<QObject*, int> m_storageSetupInProgress;
 };
 
 #endif
index 7016b039ddd6ab9727c81b8fe7b0b1b33211ee90..64de516fae78d9160a063adeb23a51b260cd22d7 100644 (file)
@@ -50,7 +50,9 @@
 PlacesPanel::PlacesPanel(QWidget* parent) :
     Panel(parent),
     m_controller(0),
-    m_model(0)
+    m_model(0),
+    m_storageSetupFailedUrl(),
+    m_triggerStorageSetupButton()
 {
 }
 
@@ -107,18 +109,12 @@ void PlacesPanel::showEvent(QShowEvent* event)
 
 void PlacesPanel::slotItemActivated(int index)
 {
-    const KUrl url = m_model->data(index).value("url").value<KUrl>();
-    if (!url.isEmpty()) {
-        emit placeActivated(PlacesItemModel::convertedUrl(url));
-    }
+    triggerItem(index, Qt::LeftButton);
 }
 
 void PlacesPanel::slotItemMiddleClicked(int index)
 {
-    const KUrl url = m_model->data(index).value("url").value<KUrl>();
-    if (!url.isEmpty()) {
-        emit placeMiddleClicked(PlacesItemModel::convertedUrl(url));
-    }
+    triggerItem(index, Qt::MiddleButton);
 }
 
 void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
@@ -278,6 +274,25 @@ void PlacesPanel::slotTrashUpdated(KJob* job)
     org::kde::KDirNotify::emitFilesAdded("trash:/");
 }
 
+void PlacesPanel::slotStorageSetupDone(int index, bool success)
+{
+    disconnect(m_model, SIGNAL(storageSetupDone(int,bool)),
+               this, SLOT(slotStorageSetupDone(int,bool)));
+
+    if (m_triggerStorageSetupButton == Qt::NoButton) {
+        return;
+    }
+
+    if (success) {
+        Q_ASSERT(!m_model->storageSetupNeeded(index));
+        triggerItem(index, m_triggerStorageSetupButton);
+        m_triggerStorageSetupButton = Qt::NoButton;
+    } else {
+        setUrl(m_storageSetupFailedUrl);
+        m_storageSetupFailedUrl = KUrl();
+    }
+}
+
 void PlacesPanel::emptyTrash()
 {
     const QString text = i18nc("@info", "Do you really want to empty the Trash? All items will be deleted.");
@@ -346,4 +361,34 @@ void PlacesPanel::selectClosestItem()
     selectionManager->setSelected(index);
 }
 
+void PlacesPanel::triggerItem(int index, Qt::MouseButton button)
+{
+    const PlacesItem* item = m_model->placesItem(index);
+    if (!item) {
+        return;
+    }
+
+    if (m_model->storageSetupNeeded(index)) {
+        m_triggerStorageSetupButton = button;
+        m_storageSetupFailedUrl = url();
+
+        connect(m_model, SIGNAL(storageSetupDone(int,bool)),
+                this, SLOT(slotStorageSetupDone(int,bool)));
+
+        m_model->requestStorageSetup(index);
+    } else {
+        m_triggerStorageSetupButton = Qt::NoButton;
+
+        const KUrl url = m_model->data(index).value("url").value<KUrl>();
+        if (!url.isEmpty()) {
+            if (button == Qt::MiddleButton) {
+                emit placeMiddleClicked(PlacesItemModel::convertedUrl(url));
+            } else {
+                emit placeActivated(PlacesItemModel::convertedUrl(url));
+            }
+        }
+    }
+}
+
+
 #include "placespanel.moc"
index d78b4ba610ed602a03010f917c760066c5d57703..427b01248fba5da9be583ea82587f27cfa672951 100644 (file)
@@ -58,6 +58,7 @@ private slots:
     void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
     void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
     void slotTrashUpdated(KJob* job);
+    void slotStorageSetupDone(int index, bool success);
 
 private:
     void emptyTrash();
@@ -70,9 +71,14 @@ private:
      */
     void selectClosestItem();
 
+    void triggerItem(int index, Qt::MouseButton button);
+
 private:
     KItemListController* m_controller;
     PlacesItemModel* m_model;
+
+    KUrl m_storageSetupFailedUrl;
+    Qt::MouseButton m_triggerStorageSetupButton;
 };
 
 #endif // PLACESPANEL_H