]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Move the VersionControlObserver from the DolphinView to the ViewExtensionsFactory...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 30 Aug 2009 18:39:03 +0000 (18:39 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 30 Aug 2009 18:39:03 +0000 (18:39 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1017482

src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphinview.cpp
src/dolphinview.h
src/viewextensionsfactory.cpp
src/viewextensionsfactory.h

index b3801bda8d0aa977f68d61083380d8eadcc5cda8..a7c91def54713e0aa74e979c0202248ecaaf7634 100644 (file)
@@ -34,7 +34,8 @@ DolphinController::DolphinController(DolphinView* dolphinView) :
     m_nameFilter(),
     m_url(),
     m_dolphinView(dolphinView),
-    m_itemView(0)
+    m_itemView(0),
+    m_versionControlActions()
 {
 }
 
@@ -144,6 +145,20 @@ void DolphinController::setZoomLevel(int level)
     }
 }
 
+void DolphinController::setVersionControlActions(QList<QAction*> actions)
+{
+    m_versionControlActions = actions;
+}
+
+QList<QAction*> DolphinController::versionControlActions(const KFileItemList& items)
+{
+    emit requestVersionControlActions(items);
+    // All view implementations are connected with the signal requestVersionControlActions()
+    // (see ViewExtensionFactory) and will invoke DolphinController::setVersionControlActions(),
+    // so that the context dependent actions can be returned.
+    return m_versionControlActions;
+}
+
 void DolphinController::handleKeyPressEvent(QKeyEvent* event)
 {
     Q_ASSERT(m_itemView != 0);
index ccfef53064289b12e94ab6d31298d0dc2a6a67bd..355cff8cfc12bbbe7930c2a83e3cf3bdadffcbe7 100644 (file)
@@ -64,12 +64,14 @@ class QPoint;
  * - emitViewportEntered()
  * - replaceUrlByClipboard()
  * - hideToolTip()
+ * - setVersionControlActions()
  *
  * The communication of the abstract view to the view implementations is done by:
  * - setUrl()
  * - indicateActivationChange()
  * - setNameFilter()
  * - setZoomLevel()
+ * - versionControlActions()
  */
 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
 {
@@ -195,6 +197,20 @@ public:
     void setZoomLevel(int level);
     int zoomLevel() const;
 
+    /**
+     * Sets the available version control actions. Is called by the view
+     * implementation as soon as the controller has send the signal
+     * requestVersionControlActions().
+     */
+    void setVersionControlActions(QList<QAction*> actions);
+
+    /**
+     * Returns the version control actions that are provided for the items \p items.
+     * Is called by the abstract Dolphin view to show the version control actions
+     * inside the context menu.
+     */
+    QList<QAction*> versionControlActions(const KFileItemList& items);
+
     /**
      * Sets the name filter to \a and emits the signal nameFilterChanged().
      */
@@ -400,6 +416,13 @@ signals:
      */
     void cancelPreviews();
 
+    /**
+     * Requests the view implementation to invoke DolphinController::setVersionControlActions(),
+     * so that they can be returned with DolphinController::versionControlActions() for
+     * the abstract Dolphin view.
+     */
+    void requestVersionControlActions(const KFileItemList& items);
+
 private slots:
     void updateMouseButtonState();
 
@@ -410,6 +433,7 @@ private:
     KUrl m_url;
     DolphinView* m_dolphinView;
     QAbstractItemView* m_itemView;
+    QList<QAction*> m_versionControlActions;
 };
 
 inline const DolphinView* DolphinController::dolphinView() const
index 09b4f3e1652e2c8c04cf826b772215865189bdee..2c3c6c38d88554fe615e73dbeaa81fdaff5e63d2 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2006-2009 by Peter Penz <peter.penz@gmx.at>             *
  *   Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net>          *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -63,7 +63,6 @@
 #include "folderexpander.h"
 #include "renamedialog.h"
 #include "settings/dolphinsettings.h"
-#include "versioncontrolobserver.h"
 #include "viewproperties.h"
 #include "zoomlevelinfo.h"
 
@@ -94,7 +93,6 @@ DolphinView::DolphinView(QWidget* parent,
     m_viewAccessor(proxyModel),
     m_selectionModel(0),
     m_selectionChangedTimer(0),
-    m_versionControlObserver(0),
     m_rootUrl(),
     m_activeItemUrl(),
     m_createdItemUrl(),
@@ -576,9 +574,7 @@ QString DolphinView::statusBarText() const
 
 QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
 {
-    return items.isEmpty()
-           ? m_versionControlObserver->contextMenuActions(url().path(KUrl::AddTrailingSlash))
-           : m_versionControlObserver->contextMenuActions(items);
+    return m_controller->versionControlActions(items);
 }
 
 void DolphinView::setUrl(const KUrl& url)
@@ -1340,14 +1336,6 @@ void DolphinView::createView()
     }
     m_selectionModel->setParent(this);
 
-    m_versionControlObserver = new VersionControlObserver(view);
-    connect(m_versionControlObserver, SIGNAL(infoMessage(const QString&)),
-            this, SIGNAL(infoMessage(const QString&)));
-    connect(m_versionControlObserver, SIGNAL(errorMessage(const QString&)),
-            this, SIGNAL(errorMessage(const QString&)));
-    connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(const QString&)),
-            this, SIGNAL(operationCompletedMessage(const QString&)));
-
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
             this, SLOT(emitDelayedSelectionChangedSignal()));
     connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
index b8c91333d0bfa2d79fdb79c2b4580d95ba038e74..822eb52b01281de855946db981ae0969984808f5 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2006-2009 by Peter Penz <peter.penz@gmx.at>             *
  *   Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net>          *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -53,7 +53,6 @@ class KAction;
 class KActionCollection;
 class KDirLister;
 class KUrl;
-class VersionControlObserver;
 class ViewProperties;
 
 /**
@@ -826,8 +825,6 @@ private:
     QItemSelectionModel* m_selectionModel; // allow to switch views without losing the selection
     QTimer* m_selectionChangedTimer;
 
-    VersionControlObserver* m_versionControlObserver;
-
     KUrl m_rootUrl;
     KUrl m_activeItemUrl;
     KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
index 0f51489bcfe8e474cc440d9bcf1bc670e8c14f0e..0974e21261389ad87e9d7514c8d9ad9cc299f9e9 100644 (file)
@@ -27,6 +27,7 @@
 #include "selectionmanager.h"
 #include "settings/dolphinsettings.h"
 #include "tooltips/tooltipmanager.h"
+#include "versioncontrolobserver.h"
 
 #include "dolphin_generalsettings.h"
 
@@ -44,7 +45,8 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
     m_previewGenerator(0),
     m_selectionManager(0),
     m_autoScroller(0),
-    m_fileItemDelegate(0)
+    m_fileItemDelegate(0),
+    m_versionControlObserver(0)
 {   
     view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
@@ -86,8 +88,19 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
     m_fileItemDelegate->setShowToolTipWhenElided(false);
     view->setItemDelegate(m_fileItemDelegate);
 
-    // react on view property changes
+    // initialize version control observer
     const DolphinView* dolphinView = controller->dolphinView();
+    m_versionControlObserver = new VersionControlObserver(view);
+    connect(m_versionControlObserver, SIGNAL(infoMessage(const QString&)),
+            dolphinView, SIGNAL(infoMessage(const QString&)));
+    connect(m_versionControlObserver, SIGNAL(errorMessage(const QString&)),
+            dolphinView, SIGNAL(errorMessage(const QString&)));
+    connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(const QString&)),
+            dolphinView, SIGNAL(operationCompletedMessage(const QString&)));
+    connect(controller, SIGNAL(requestVersionControlActions(const KFileItemList&)),
+            this, SLOT(slotRequestVersionControlActions(const KFileItemList&)));
+
+    // react on view property changes
     connect(dolphinView, SIGNAL(showHiddenFilesChanged()),
             this, SLOT(slotShowHiddenFilesChanged()));
     connect(dolphinView, SIGNAL(sortingChanged(DolphinView::Sorting)),
@@ -181,6 +194,19 @@ void ViewExtensionsFactory::slotNameFilterChanged(const QString& nameFilter)
     proxyModel()->setFilterRegExp(nameFilter);
 }
 
+void ViewExtensionsFactory::slotRequestVersionControlActions(const KFileItemList& items)
+{
+    QList<QAction*> actions;
+    if (items.isEmpty()) {
+        const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel()->sourceModel());
+        const KUrl url = dirModel->dirLister()->url();
+        actions = m_versionControlObserver->contextMenuActions(url.path(KUrl::AddTrailingSlash));
+    } else {
+        actions = m_versionControlObserver->contextMenuActions(items);
+    }
+    m_controller->setVersionControlActions(actions);
+}
+
 void ViewExtensionsFactory::requestActivation()
 {
     m_controller->requestActivation();
index 65549a55a1ffeaa33bebbad5f801ae4778f694d6..ddc1cf581c1519a4f573145c3197164c747fcc7b 100644 (file)
@@ -33,6 +33,7 @@ class QModelIndex;
 class SelectionManager;
 class ToolTipManager;
 class QAbstractItemView;
+class VersionControlObserver;
 
 /**
  * @brief Responsible for creating extensions like tooltips and previews
@@ -73,6 +74,7 @@ private slots:
     void slotSortOrderChanged(Qt::SortOrder order);
     void slotSortFoldersFirstChanged(bool foldersFirst);
     void slotNameFilterChanged(const QString& nameFilter);
+    void slotRequestVersionControlActions(const KFileItemList& items);
     void requestActivation();
 
 private:
@@ -85,7 +87,8 @@ private:
     KFilePreviewGenerator* m_previewGenerator;
     SelectionManager* m_selectionManager;
     DolphinViewAutoScroller* m_autoScroller;
-    DolphinFileItemDelegate* m_fileItemDelegate;
+    DolphinFileItemDelegate* m_fileItemDelegate;   
+    VersionControlObserver* m_versionControlObserver;
 };
 
 #endif