]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.cpp
Merge remote-tracking branch 'origin/KDE/4.9'
[dolphin.git] / src / panels / places / placespanel.cpp
index ccc10d205338bdf8e9d73274353957ff5110aecc..61c15a7a12631d0a8d36e96e0298cd96646f5d32 100644 (file)
@@ -35,7 +35,6 @@
 #include <kitemviews/kitemlistcontroller.h>
 #include <kitemviews/kitemlistselectionmanager.h>
 #include <kitemviews/kstandarditem.h>
-#include <kitemviews/kstandarditemlistview.h>
 #include <KMenu>
 #include <KMessageBox>
 #include <KNotification>
@@ -44,6 +43,7 @@
 #include "placesitemlistgroupheader.h"
 #include "placesitemlistwidget.h"
 #include "placesitemmodel.h"
+#include "placesview.h"
 #include <views/draganddrophelper.h>
 #include <QGraphicsSceneDragDropEvent>
 #include <QVBoxLayout>
@@ -54,7 +54,10 @@ PlacesPanel::PlacesPanel(QWidget* parent) :
     m_controller(0),
     m_model(0),
     m_storageSetupFailedUrl(),
-    m_triggerStorageSetupButton()
+    m_triggerStorageSetupButton(),
+    m_itemDropEventIndex(-1),
+    m_itemDropEventMimeData(0),
+    m_itemDropEvent(0)
 {
 }
 
@@ -101,11 +104,11 @@ void PlacesPanel::showEvent(QShowEvent* event)
         connect(m_model, SIGNAL(errorMessage(QString)),
                 this, SIGNAL(errorMessage(QString)));
 
-        KStandardItemListView* view = new KStandardItemListView();
-        view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>());
-        view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>());
+        m_view = new PlacesView();
+        m_view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>());
+        m_view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>());
 
-        m_controller = new KItemListController(m_model, view, this);
+        m_controller = new KItemListController(m_model, m_view, this);
         m_controller->setSelectionBehavior(KItemListController::SingleSelection);
         m_controller->setSingleClickActivation(true);
 
@@ -213,6 +216,41 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
         showAllAction->setChecked(m_model->hiddenItemsShown());
     }
 
+    menu.addSeparator();
+    KMenu* iconSizeSubMenu = new KMenu(i18nc("@item:inmenu", "Icon Size"), &menu);
+
+    struct IconSizeInfo
+    {
+        int size;
+        const char* context;
+        const char* text;
+    };
+
+    const int iconSizeCount = 4;
+    static const IconSizeInfo iconSizes[iconSizeCount] = {
+        {KIconLoader::SizeSmall,        I18N_NOOP2_NOSTRIP("Small icon size", "Small (%1x%2)")},
+        {KIconLoader::SizeSmallMedium,  I18N_NOOP2_NOSTRIP("Medium icon size", "Medium (%1x%2)")},
+        {KIconLoader::SizeMedium,       I18N_NOOP2_NOSTRIP("Large icon size", "Large (%1x%2)")},
+        {KIconLoader::SizeLarge,        I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")}
+    };
+
+    QMap<QAction*, int> iconSizeActionMap;
+    QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu);
+
+    for (int i = 0; i < iconSizeCount; ++i) {
+        const int size = iconSizes[i].size;
+        const QString text = i18nc(iconSizes[i].context, iconSizes[i].text,
+                                   size, size);
+
+        QAction* action = iconSizeSubMenu->addAction(text);
+        iconSizeActionMap.insert(action, size);
+        action->setActionGroup(iconSizeGroup);
+        action->setCheckable(true);
+        action->setChecked(m_view->iconSize() == size);
+    }
+
+    menu.addMenu(iconSizeSubMenu);
+
     menu.addSeparator();
     foreach (QAction* action, customContextMenuActions()) {
         menu.addAction(action);
@@ -239,6 +277,8 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
             m_model->requestTeardown(index);
         } else if (action == ejectAction) {
             m_model->requestEject(index);
+        } else if (iconSizeActionMap.contains(action)) {
+            m_view->setIconSize(iconSizeActionMap.value(action));
         }
     }
 
@@ -281,6 +321,30 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
         return;
     }
 
+    if (m_model->storageSetupNeeded(index)) {
+        connect(m_model, SIGNAL(storageSetupDone(int,bool)),
+                this, SLOT(slotItemDropEventStorageSetupDone(int,bool)));
+
+        m_itemDropEventIndex = index;
+
+        // Make a full copy of the Mime-Data
+        m_itemDropEventMimeData = new QMimeData;
+        m_itemDropEventMimeData->setText(event->mimeData()->text());
+        m_itemDropEventMimeData->setHtml(event->mimeData()->html());
+        m_itemDropEventMimeData->setUrls(event->mimeData()->urls());
+        m_itemDropEventMimeData->setImageData(event->mimeData()->imageData());
+        m_itemDropEventMimeData->setColorData(event->mimeData()->colorData());
+
+        m_itemDropEvent = new QDropEvent(event->pos().toPoint(),
+                                         event->possibleActions(),
+                                         m_itemDropEventMimeData,
+                                         event->buttons(),
+                                         event->modifiers());
+
+        m_model->requestStorageSetup(index);
+        return;
+    }
+
     KUrl destUrl = m_model->placesItem(index)->url();
     QDropEvent dropEvent(event->pos().toPoint(),
                          event->possibleActions(),
@@ -291,6 +355,27 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
     DragAndDropHelper::dropUrls(KFileItem(), destUrl, &dropEvent);
 }
 
+void PlacesPanel::slotItemDropEventStorageSetupDone(int index, bool success)
+{
+    disconnect(m_model, SIGNAL(storageSetupDone(int,bool)),
+               this, SLOT(slotItemDropEventStorageSetupDone(int,bool)));
+
+    if ((index == m_itemDropEventIndex) && m_itemDropEvent && m_itemDropEventMimeData) {
+        if (success) {
+            KUrl destUrl = m_model->placesItem(index)->url();
+
+            DragAndDropHelper::dropUrls(KFileItem(), destUrl, m_itemDropEvent);
+        }
+
+        delete m_itemDropEventMimeData;
+        delete m_itemDropEvent;
+
+        m_itemDropEventIndex = -1;
+        m_itemDropEventMimeData = 0;
+        m_itemDropEvent = 0;
+    }
+}
+
 void PlacesPanel::slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
 {
     m_model->dropMimeDataBefore(index, event->mimeData());