]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Patch by Luca Gugelmann: get rid of any mainwindow dependency from the sidebars.
authorPeter Penz <peter.penz19@gmail.com>
Sun, 25 Mar 2007 06:44:28 +0000 (06:44 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 25 Mar 2007 06:44:28 +0000 (06:44 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=646256

20 files changed:
src/CMakeLists.txt
src/bookmarkssidebarpage.cpp
src/bookmarkssidebarpage.h
src/dolphincontextmenu.cpp
src/dolphincontextmenu.h
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/dolphinview.h
src/infosidebarpage.cpp
src/infosidebarpage.h
src/sidebarpage.cpp
src/sidebarpage.h
src/sidebartreeview.cpp
src/sidebartreeview.h
src/treeviewcontextmenu.cpp [new file with mode: 0644]
src/treeviewcontextmenu.h [new file with mode: 0644]
src/treeviewsidebarpage.cpp
src/treeviewsidebarpage.h
src/urlnavigatorbutton.cpp

index bf5679ef3cedf8da657634be155bb007800fb01e..2ad4814e20eb7ec2c73463fa4d0d6717494adbeb 100644 (file)
@@ -16,7 +16,7 @@ set(dolphinprivate_LIB_SRCS
        )
 
 kde4_add_kcfg_files(dolphinprivate_LIB_SRCS
-   dolphin_directoryviewpropertysettings.kcfgc 
+   dolphin_directoryviewpropertysettings.kcfgc
    dolphin_detailsmodesettings.kcfgc
    dolphin_iconsmodesettings.kcfgc
    dolphin_generalsettings.kcfgc)
@@ -64,6 +64,7 @@ set(dolphin_SRCS
    sidebarpage.cpp
    statusbarspaceinfo.cpp
    statusbarmessagelabel.cpp
+   treeviewcontextmenu.cpp
    treeviewsidebarpage.cpp
    sidebartreeview.cpp
    urlbutton.cpp
index 2d24ac783097ace2cde788bfa1cf3f078ba0e7ed..677d0bd064c489735b7136081c65bab7a24b823f 100644 (file)
 #include <klocale.h>
 
 #include "dolphinsettings.h"
-#include "dolphinmainwindow.h"
 #include "editbookmarkdialog.h"
 
-BookmarksSidebarPage::BookmarksSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
-    SidebarPage(mainWindow, parent)
+BookmarksSidebarPage::BookmarksSidebarPage(QWidget* parent) :
+    SidebarPage(parent)
 {
     Q3VBoxLayout* layout = new Q3VBoxLayout(this);
     m_bookmarksList = new BookmarksListBox(this);
@@ -63,9 +62,12 @@ BookmarksSidebarPage::~BookmarksSidebarPage()
 {
 }
 
-void BookmarksSidebarPage::activeViewChanged()
+void BookmarksSidebarPage::setUrl(const KUrl& url)
 {
-    connectToActiveView();
+    if (!m_url.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+        m_url = url;
+        adjustSelection(m_url);
+    }
 }
 
 void BookmarksSidebarPage::updateBookmarks()
@@ -85,8 +87,6 @@ void BookmarksSidebarPage::updateBookmarks()
 
         bookmark = root.next(bookmark);
     }
-
-    connectToActiveView();
 }
 
 void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* item)
@@ -97,7 +97,7 @@ void BookmarksSidebarPage::slotMouseButtonClicked(int button, Q3ListBoxItem* ite
 
     const int index = m_bookmarksList->index(item);
     KBookmark bookmark = DolphinSettings::instance().bookmark(index);
-    mainWindow()->activeView()->setUrl(bookmark.url());
+    emit changeUrl(bookmark.url());
 }
 
 void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item,
@@ -191,9 +191,6 @@ void BookmarksSidebarPage::slotContextMenuRequested(Q3ListBoxItem* item,
    }
     delete popup;
     popup = 0;
-
-    DolphinView* view = mainWindow()->activeView();
-    adjustSelection(view->url());
 }
 
 
@@ -239,19 +236,6 @@ void BookmarksSidebarPage::adjustSelection(const KUrl& url)
     m_bookmarksList->blockSignals(block);
 }
 
-void BookmarksSidebarPage::slotUrlChanged(const KUrl& url)
-{
-    adjustSelection(url);
-}
-
-void BookmarksSidebarPage::connectToActiveView()
-{
-    DolphinView* view = mainWindow()->activeView();
-    adjustSelection(view->url());
-    connect(view, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(slotUrlChanged(const KUrl&)));
-}
-
 BookmarksListBox::BookmarksListBox(QWidget* parent) :
     Q3ListBox(parent)
 {
index 3eb9a55a0df9fcfee0d8aefb0ea21cb4be46f5a5..c50585ccbbd98141c53edac23dae4d3fb5101d50 100644 (file)
 #ifndef _BOOKMARKSSIDEBARPAGE_H_
 #define _BOOKMARKSSIDEBARPAGE_H_
 
-#include <sidebarpage.h>
 #include <q3listbox.h>
 //Added by qt3to4:
 #include <QPaintEvent>
 #include <QPixmap>
 
+#include "sidebarpage.h"
+
 class KUrl;
 class BookmarksListBox;
 
@@ -41,12 +42,11 @@ class BookmarksSidebarPage : public SidebarPage
         Q_OBJECT
 
 public:
-    BookmarksSidebarPage(DolphinMainWindow *mainWindow, QWidget* parent=0);
+    BookmarksSidebarPage(QWidget* parent=0);
     virtual ~BookmarksSidebarPage();
 
-protected:
-    /** @see SidebarPage::activeViewChanged() */
-    virtual void activeViewChanged();
+public slots:
+       void setUrl(const KUrl& url);
 
 private slots:
     /** Fills the listbox with the bookmarks stored in DolphinSettings. */
@@ -61,12 +61,6 @@ private slots:
     /** @see QListBox::slotContextMenuRequested */
     void slotContextMenuRequested(Q3ListBoxItem* item, const QPoint& pos);
 
-    /**
-     * Is invoked whenever the Url of the active view has been changed. Adjusts
-     * the selection of the listbox to the bookmark which is part of the current Url.
-     */
-    void slotUrlChanged(const KUrl& url);
-
 private:
     /**
      * Updates the selection dependent from the given Url \a url. The
@@ -77,12 +71,6 @@ private:
      */
     void adjustSelection(const KUrl& url);
 
-    /**
-     * Connects to signals from the currently active Dolphin view to get
-     * informed about Url and bookmark changes.
-     */
-    void connectToActiveView();
-
     BookmarksListBox* m_bookmarksList;
 };
 
index 44c842fe71463cfafd4bedbba4963f4041820c6b..e78f3ec1c4358f4c280100f61ee8055a10d10084 100644 (file)
 
 DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
                                        KFileItem* fileInfo,
-                                       const KUrl& baseUrl,
-                                       ViewType viewType) :
+                                       const KUrl& baseUrl) :
     m_mainWindow(parent),
     m_fileInfo(fileInfo),
     m_baseUrl(baseUrl),
-    m_viewType(viewType),
     m_context(NoContext)
 {
-    if (viewType == ItemsView) {
-        // The context menu either accesses the URLs of the selected items
-        // or the items itself. To increase the performance both lists are cached.
-        DolphinView* view = m_mainWindow->activeView();
-        m_selectedUrls = view->selectedUrls();
-        m_selectedItems = view->selectedItems();
-    }
-    else if (fileInfo != 0) {
-        m_selectedUrls.append(fileInfo->url());
-        m_selectedItems.append(fileInfo);
-    }
+    // The context menu either accesses the URLs of the selected items
+    // or the items itself. To increase the performance both lists are cached.
+    DolphinView* view = m_mainWindow->activeView();
+    m_selectedUrls = view->selectedUrls();
+    m_selectedItems = view->selectedItems();
 }
 
 DolphinContextMenu::~DolphinContextMenu()
@@ -105,59 +97,6 @@ void DolphinContextMenu::open()
     }
 }
 
-void DolphinContextMenu::cut()
-{
-    QMimeData* mimeData = new QMimeData();
-    KUrl::List kdeUrls;
-    kdeUrls.append(m_fileInfo->url());
-    KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), true);
-    QApplication::clipboard()->setMimeData(mimeData);
-}
-
-void DolphinContextMenu::copy()
-{
-    QMimeData* mimeData = new QMimeData();
-    KUrl::List kdeUrls;
-    kdeUrls.append(m_fileInfo->url());
-    KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), false);
-    QApplication::clipboard()->setMimeData(mimeData);
-}
-
-void DolphinContextMenu::paste()
-{
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-
-    const KUrl::List source = KUrl::List::fromMimeData(mimeData);
-    const KUrl& dest = m_fileInfo->url();
-    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
-        KonqOperations::copy(m_mainWindow, KonqOperations::MOVE, source, dest);
-        clipboard->clear();
-    }
-    else {
-        KonqOperations::copy(m_mainWindow, KonqOperations::COPY, source, dest);
-    }
-}
-
-void DolphinContextMenu::rename()
-{
-    // TODO
-}
-
-void DolphinContextMenu::moveToTrash()
-{
-    // TODO
-}
-
-void DolphinContextMenu::deleteItem()
-{
-    // TODO
-}
-
-void DolphinContextMenu::showProperties()
-{
-    new KPropertiesDialog(m_fileInfo->url());
-}
 
 void DolphinContextMenu::openTrashContextMenu()
 {
@@ -236,14 +175,7 @@ void DolphinContextMenu::openItemContextMenu()
     popup->addSeparator();
 
     // insert 'Properties...' entry
-    QAction* propertiesAction = 0;
-    if (m_viewType == SidebarView) {
-        propertiesAction = new QAction(i18n("Properties..."), this);
-        connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
-    }
-    else {
-        propertiesAction = m_mainWindow->actionCollection()->action("properties");
-    }
+    QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
     popup->addAction(propertiesAction);
 
     QAction* activatedAction = popup->exec(QCursor::pos());
@@ -344,29 +276,11 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
 {
     Q_ASSERT(popup != 0);
     const KActionCollection* collection = m_mainWindow->actionCollection();
-    const bool insertSidebarActions = (m_viewType == SidebarView);
 
     // insert 'Cut', 'Copy' and 'Paste'
-    QAction* cutAction = 0;
-    QAction* copyAction = 0;
-    QAction* pasteAction = 0;
-    if (insertSidebarActions) {
-        cutAction   = new QAction(KIcon("edit-cut"), i18n("Cut"), this);
-        connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
-
-        copyAction  = new QAction(KIcon("edit-copy"), i18n("Copy"), this);
-        connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
-
-        const QAction* menuPasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
-        pasteAction = new QAction(KIcon("edit-paste"), menuPasteAction->text(), this);
-        pasteAction->setEnabled(menuPasteAction->isEnabled());
-        connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
-    }
-    else {
-        cutAction   = collection->action(KStandardAction::stdName(KStandardAction::Cut));
-        copyAction  = collection->action(KStandardAction::stdName(KStandardAction::Copy));
-        pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
-    }
+    QAction* cutAction = collection->action(KStandardAction::stdName(KStandardAction::Cut));
+    QAction* copyAction  = collection->action(KStandardAction::stdName(KStandardAction::Copy));
+    QAction* pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
 
     popup->addAction(cutAction);
     popup->addAction(copyAction);
@@ -374,31 +288,16 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     popup->addSeparator();
 
     // insert 'Rename'
-    QAction* renameAction = 0;
-    if (insertSidebarActions) {
-        renameAction = new QAction(i18n("Rename"), this);
-        connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
-    }
-    else {
-        renameAction = collection->action("rename");
-    }
+    QAction* renameAction = collection->action("rename");
     popup->addAction(renameAction);
 
     // insert 'Move to Trash' and (optionally) 'Delete'
     const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
     const KConfigGroup kdeConfig(globalConfig, "KDE");
     bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
-    const KUrl& url = insertSidebarActions ? m_fileInfo->url():
-                                             m_mainWindow->activeView()->url();
+    const KUrl& url = m_mainWindow->activeView()->url();
     if (url.isLocalFile()) {
-        QAction* moveToTrashAction = 0;
-        if (insertSidebarActions) {
-            moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
-            connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
-        }
-        else {
-            moveToTrashAction = collection->action("move_to_trash");
-        }
+        QAction* moveToTrashAction = collection->action("move_to_trash");
         popup->addAction(moveToTrashAction);
     }
     else {
@@ -406,14 +305,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     }
 
     if (showDeleteCommand) {
-        QAction* deleteAction = 0;
-        if (insertSidebarActions) {
-            deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this);
-            connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
-        }
-        else {
-            deleteAction = collection->action("delete");
-        }
+        QAction* deleteAction = collection->action("delete");
         popup->addAction(deleteAction);
     }
 }
index 2a678d9a2b08c61fa2755e8cb934b9b4c1270e0f..f3f075717c8f6d7c62a12cfa22d8fd87d90430eb 100644 (file)
@@ -51,12 +51,6 @@ class DolphinContextMenu : public QObject
     Q_OBJECT
 
 public:
-    enum ViewType
-    {
-        ItemsView,
-        SidebarView
-    };
-
     /**
      * @parent        Pointer to the main window the context menu
      *                belongs to.
@@ -69,36 +63,13 @@ public:
      */
     DolphinContextMenu(DolphinMainWindow* parent,
                        KFileItem* fileInfo,
-                       const KUrl& baseUrl,
-                       ViewType viewType = ItemsView);
+                       const KUrl& baseUrl);
 
     virtual ~DolphinContextMenu();
 
     /** Opens the context menu modal. */
     void open();
 
-private slots:
-    /** Cuts the item m_fileInfo. */
-    void cut();
-
-    /** Copies the item m_fileInfo. */
-    void copy();
-
-    /** Paste the clipboard to m_fileInfo. */
-    void paste();
-
-    /** Renames the item m_fileInfo. */
-    void rename();
-
-    /** Moves the item m_fileInfo to the trash. */
-    void moveToTrash();
-
-    /** Deletes the item m_fileInfo. */
-    void deleteItem();
-
-    /** Shows the properties of the item m_fileInfo. */
-    void showProperties();
-
 private:
     void openTrashContextMenu();
     void openTrashItemContextMenu();
@@ -158,7 +129,6 @@ private:
     KUrl m_baseUrl;
     KFileItemList m_selectedItems;
     KUrl::List m_selectedUrls;
-    ViewType m_viewType;
     int m_context;
 };
 
index deb418681db4f7daf2d1b6895f5b4c841c8a1286..775ef9864f75a3fd6396eb5fe06a4260cf6c1461 100644 (file)
@@ -244,13 +244,23 @@ void DolphinMainWindow::refreshViews()
     emit activeViewChanged();\r
 }\r
 \r
-void DolphinMainWindow::changeUrl(const QString& url)\r
+void DolphinMainWindow::changeUrl(const KUrl& url)\r
 {\r
     if (activeView() != 0) {\r
-        activeView()->setUrl(KUrl(url));\r
+        activeView()->setUrl(url);\r
+        updateEditActions();\r
+        updateViewActions();\r
+        updateGoActions();\r
+        setCaption(url.fileName());\r
+        emit urlChanged(url);\r
     }\r
 }\r
 \r
+void DolphinMainWindow::changeSelection(const KFileItemList& selection)\r
+{\r
+    activeView()->changeSelection(selection);\r
+}\r
+\r
 void DolphinMainWindow::slotViewModeChanged()\r
 {\r
     updateViewActions();\r
@@ -338,7 +348,7 @@ void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::AdditionalI
     }\r
 }\r
 \r
-void DolphinMainWindow::slotSelectionChanged()\r
+void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)\r
 {\r
     updateEditActions();\r
 \r
@@ -353,7 +363,7 @@ void DolphinMainWindow::slotSelectionChanged()
 \r
     m_activeView->updateStatusBar();\r
 \r
-    emit selectionChanged();\r
+    emit selectionChanged(selection);\r
 }\r
 \r
 void DolphinMainWindow::slotHistoryChanged()\r
@@ -361,14 +371,6 @@ void DolphinMainWindow::slotHistoryChanged()
     updateHistory();\r
 }\r
 \r
-void DolphinMainWindow::slotUrlChanged(const KUrl& url)\r
-{\r
-    updateEditActions();\r
-    updateViewActions();\r
-    updateGoActions();\r
-    setCaption(url.fileName());\r
-}\r
-\r
 void DolphinMainWindow::updateFilterBarAction(bool show)\r
 {\r
     KToggleAction* showFilterBarAction =\r
@@ -776,6 +778,7 @@ void DolphinMainWindow::toggleSplitView()
         connectViewSignals(SecondaryIdx);\r
         m_splitter->addWidget(m_view[SecondaryIdx]);\r
         m_splitter->setSizes(QList<int>() << newWidth << newWidth);\r
+        m_view[SecondaryIdx]->reload();\r
         m_view[SecondaryIdx]->show();\r
     }\r
     else {\r
@@ -1010,10 +1013,11 @@ void DolphinMainWindow::init()
                                          homeUrl,\r
                                          props.viewMode(),\r
                                          props.showHiddenFiles());\r
-    connectViewSignals(PrimaryIdx);\r
-    m_view[PrimaryIdx]->show();\r
 \r
     m_activeView = m_view[PrimaryIdx];\r
+    connectViewSignals(PrimaryIdx);\r
+    m_view[PrimaryIdx]->reload();\r
+    m_view[PrimaryIdx]->show();\r
 \r
     setCentralWidget(m_splitter);\r
     setupDockWidgets();\r
@@ -1040,6 +1044,8 @@ void DolphinMainWindow::init()
     if ( !MetaDataWidget::metaDataAvailable() )\r
         activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);\r
     #endif\r
+\r
+    emit urlChanged(homeUrl);\r
 }\r
 \r
 void DolphinMainWindow::loadSettings()\r
@@ -1292,37 +1298,45 @@ void DolphinMainWindow::setupDockWidgets()
     // after the dock concept has been finalized.\r
 \r
     // setup "Bookmarks"\r
-    QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"));\r
+    QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"), this);\r
     shortcutsDock->setObjectName("bookmarksDock");\r
     shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);\r
-    shortcutsDock->setWidget(new BookmarksSidebarPage(this));\r
+    SidebarPage* shortcutsWidget = new BookmarksSidebarPage(shortcutsDock);\r
+    shortcutsDock->setWidget(shortcutsWidget);\r
+\r
 \r
     shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));\r
     actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction());\r
 \r
     addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);\r
+    connectSidebarPage(shortcutsWidget);\r
 \r
     // setup "Information"\r
-    QDockWidget* infoDock = new QDockWidget(i18n("Information"));\r
+    QDockWidget* infoDock = new QDockWidget(i18n("Information"), this);\r
     infoDock->setObjectName("infoDock");\r
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);\r
-    infoDock->setWidget(new InfoSidebarPage(this));\r
+    SidebarPage* infoWidget = new InfoSidebarPage(infoDock);\r
+    infoDock->setWidget(infoWidget);\r
+\r
 \r
     infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));\r
     actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());\r
 \r
     addDockWidget(Qt::RightDockWidgetArea, infoDock);\r
+    connectSidebarPage(infoWidget);\r
 \r
     // setup "Tree View"\r
     QDockWidget* treeViewDock = new QDockWidget(i18n("Folders")); // TODO: naming?\r
     treeViewDock->setObjectName("treeViewDock");\r
     treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);\r
-    treeViewDock->setWidget(new TreeViewSidebarPage(this));\r
+    TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);\r
+    treeViewDock->setWidget(treeWidget);\r
 \r
     treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel"));\r
     actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());\r
 \r
     addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);\r
+    connectSidebarPage(treeWidget);\r
 \r
     const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();\r
     if (firstRun) {\r
@@ -1479,17 +1493,32 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
             this, SLOT(slotSortOrderChanged(Qt::SortOrder)));\r
     connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::AdditionalInformation)),\r
             this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation)));\r
-    connect(view, SIGNAL(selectionChanged()),\r
-            this, SLOT(slotSelectionChanged()));\r
+    connect(view, SIGNAL(selectionChanged(KFileItemList)),\r
+            this, SLOT(slotSelectionChanged(KFileItemList)));\r
     connect(view, SIGNAL(showFilterBarChanged(bool)),\r
             this, SLOT(updateFilterBarAction(bool)));\r
+    connect(view, SIGNAL(urlChanged(KUrl)),\r
+            this, SLOT(changeUrl(KUrl)));\r
 \r
     const UrlNavigator* navigator = view->urlNavigator();\r
     connect(navigator, SIGNAL(urlChanged(const KUrl&)),\r
-            this, SLOT(slotUrlChanged(const KUrl&)));\r
+            this, SLOT(changeUrl(const KUrl&)));\r
     connect(navigator, SIGNAL(historyChanged()),\r
             this, SLOT(slotHistoryChanged()));\r
+}\r
+void DolphinMainWindow::connectSidebarPage(SidebarPage* page)\r
+{\r
+    connect(page, SIGNAL(changeUrl(KUrl)),\r
+            this, SLOT(changeUrl(KUrl)));\r
+    connect(page, SIGNAL(changeSelection(KFileItemList)),\r
+            this, SLOT(changeSelection(KFileItemList)));\r
+    connect(page, SIGNAL(urlsDropped(KUrl::List,KUrl)),\r
+            this, SLOT(dropUrls(KUrl::List,KUrl)));\r
 \r
+    connect(this, SIGNAL(urlChanged(KUrl)),\r
+            page, SLOT(setUrl(KUrl)));\r
+     connect(this, SIGNAL(selectionChanged(KFileItemList)),\r
+             page, SLOT(setSelection(KFileItemList)));\r
 }\r
 \r
 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :\r
index d481a9e317e7ebdbb0edaf091343304e9c98f0cb..d8c64da7c1a81be55e8f9398abbbdf9aadee8611 100644 (file)
@@ -23,6 +23,7 @@
 #define DOLPHIN_MAINWINDOW_H
 
 #include "dolphinview.h"
+#include "sidebarpage.h"
 
 #include <kmainwindow.h>
 #include <ksortablelist.h>
@@ -64,20 +65,6 @@ public:
      */
     DolphinView* activeView() const { return m_activeView; }
 
-    /**
-     * Handles the dropping of URLs to the given
-     * destination. A context menu with the options
-     * 'Move Here', 'Copy Here', 'Link Here' and
-     * 'Cancel' is offered to the user.
-     * @param urls        List of URLs which have been
-     *                    dropped.
-     * @param destination Destination URL, where the
-     *                    list or URLs should be moved,
-     *                    copied or linked to.
-     */
-    void dropUrls(const KUrl::List& urls,
-                  const KUrl& destination);
-
     /** Renames the item represented by \a oldUrl to \a newUrl. */
     void rename(const KUrl& oldUrl, const KUrl& newUrl);
 
@@ -94,15 +81,36 @@ public:
     KNewMenu* newMenu() const { return m_newMenu; }
 
 public slots:
+    /**
+     * Handles the dropping of URLs to the given
+     * destination. A context menu with the options
+     * 'Move Here', 'Copy Here', 'Link Here' and
+     * 'Cancel' is offered to the user.
+     * @param urls        List of URLs which have been
+     *                    dropped.
+     * @param destination Destination URL, where the
+     *                    list or URLs should be moved,
+     *                    copied or linked to.
+     */
+    void dropUrls(const KUrl::List& urls,
+                  const KUrl& destination);
+
     /**
      * Returns the main window ID used through DBus.
      */
     int getId() const { return m_id; }
 
     /**
-     * Changes the URL of the current active DolphinView to \a url.
+     * Inform all affected dolphin components (sidebars, views) of an URL
+     * change.
+     */
+    void changeUrl(const KUrl& url);
+
+    /**
+     * Inform all affected dolphin components that a selection change is
+     * requested.
      */
-    void changeUrl(const QString& url);
+    void changeSelection(const KFileItemList& selection);
 
     /** Stores all settings and quits Dolphin. */
     void quit();
@@ -115,10 +123,16 @@ signals:
     void activeViewChanged();
 
     /**
-     * Is send if the selection of the currently active view has
+     * Is sent if the selection of the currently active view has
      * been changed.
      */
-    void selectionChanged();
+    void selectionChanged(const KFileItemList& selection);
+
+    /**
+     * Is sent if the url of the currently active view has
+     * been changed.
+     */
+    void urlChanged(const KUrl& url);
 
 protected:
     /** @see QMainWindow::closeEvent */
@@ -348,7 +362,7 @@ private slots:
     void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
 
     /** Updates the state of the 'Edit' menu actions. */
-    void slotSelectionChanged();
+    void slotSelectionChanged(const KFileItemList& selection);
 
     /**
      * Updates the state of the 'Back' and 'Forward' menu
@@ -356,12 +370,6 @@ private slots:
      */
     void slotHistoryChanged();
 
-    /**
-     * Updates the caption of the main window and the state
-     * of all menu actions which depend from a changed URL.
-     */
-    void slotUrlChanged(const KUrl& url);
-
     /** Updates the state of the 'Show filter bar' menu action. */
     void updateFilterBarAction(bool show);
 
@@ -393,6 +401,11 @@ private:
      */
     void connectViewSignals(int viewIndex);
 
+    /**
+     * Helper function to connect all signal/slots of the given \sidebar.
+     */
+    void connectSidebarPage(SidebarPage* sidebar);
+
 private:
     /**
      * DolphinMainWindowsupports only one or two views, which
index 6dfdd3d7bdb84c9c9f3d25d6418ff9bfcf547265..99757bac7510015391bd6c6bc5340e34b847a258 100644 (file)
@@ -164,8 +164,6 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
     m_topLayout->addWidget(itemView());
     m_topLayout->addWidget(m_filterBar);
     m_topLayout->addWidget(m_statusBar);
-
-    loadDirectory(m_urlNavigator->url());
 }
 
 DolphinView::~DolphinView()
@@ -596,6 +594,10 @@ DolphinMainWindow* DolphinView::mainWindow() const
 
 void DolphinView::loadDirectory(const KUrl& url)
 {
+    if(!isActive()) {
+        requestActivation();
+    }
+
     const ViewProperties props(url);
 
     const Mode mode = props.viewMode();
@@ -793,7 +795,7 @@ void DolphinView::showErrorMessage(const QString& msg)
 
 void DolphinView::emitSelectionChangedSignal()
 {
-    emit selectionChanged();
+    emit selectionChanged(DolphinView::selectedItems());
 }
 
 void DolphinView::closeFilterBar()
@@ -922,6 +924,27 @@ void DolphinView::requestActivation()
     m_mainWindow->setActiveView(this);
 }
 
+void DolphinView::changeSelection(const KFileItemList& selection)
+{
+    clearSelection();
+    if (selection.isEmpty()) {
+        return;
+    }
+    KUrl baseUrl = url();
+    KUrl url;
+    QItemSelection new_selection;
+    foreach (KFileItem* item, selection) {
+        url = item->url().upUrl();
+        if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+            QModelIndex index = m_proxyModel->mapFromSource(m_dirModel->indexForItem(*item));
+            new_selection.select(index, index);
+        }
+    }
+    itemView()->selectionModel()->select(new_selection,
+                                         QItemSelectionModel::ClearAndSelect
+                                         | QItemSelectionModel::Current);
+}
+
 void DolphinView::changeNameFilter(const QString& nameFilter)
 {
     // The name filter of KDirLister does a 'hard' filtering, which
@@ -1021,6 +1044,10 @@ void DolphinView::emitContentsMoved()
 void DolphinView::updateActivationState()
 {
     m_urlNavigator->setActive(isActive());
+    if(isActive()) {
+        emit urlChanged(url());
+        emit selectionChanged(selectedItems());
+    }
 }
 
 void DolphinView::updateCutItems()
index c2d0a1cc869025d9633cf4fee5653e36fc741233..aee10bcad5684d680a6908027d538b256b5aeca8 100644 (file)
@@ -353,6 +353,14 @@ public slots:
      */
     void requestActivation();
 
+    /**
+     * Request of a selection change. The view will do its best to accomodate
+     * the request, but it is not guaranteed that all items in \a selection
+     * will actually get selected. The view will e.g. not select items which
+     * are not in the currently displayed folder.
+     */
+    void changeSelection(const KFileItemList& selection);
+
 signals:
     /** Is emitted if URL of the view has been changed to \a url. */
     void urlChanged(const KUrl& url);
@@ -388,11 +396,9 @@ signals:
     void contentsMoved(int x, int y);
 
     /**
-     * Is emitted whenever the selection has been changed. The current selection can
-     * be retrieved by mainWindow()->activeView()->selectedItems() or by
-     * mainWindow()->activeView()->selectedUrls().
+     * Is emitted whenever the selection has been changed.
      */
-    void selectionChanged();
+    void selectionChanged(const KFileItemList& selection);
 
     /**
      * Is emitted whenever the filter bar has been turned show or hidden.
index 4a3a387bb86f6bdfb5f75ce67ceca57f7fe6a806..50f9eb0f8a7c7000174198a1829a43dd263cf39b 100644 (file)
 #include <config-kmetadata.h>
 
 #include "infosidebarpage.h"
-#include <assert.h>
 
-#include <qlayout.h>
-#include <qpixmap.h>
-#include <qlabel.h>
-#include <qtimer.h>
-#include <qpushbutton.h>
-
-#include <qmenu.h>
-#include <qpainter.h>
-#include <qfontmetrics.h>
+#include <QLayout>
+#include <QPixmap>
+#include <QLabel>
+#include <QTimer>
+#include <QPushButton>
+#include <QMenu>
+#include <QPainter>
+#include <QFontMetrics>
 #include <QEvent>
 #include <QInputDialog>
+#include <QDir>
 
 #include <kbookmarkmanager.h>
 #include <klocale.h>
 #include <kfilemetainfo.h>
 #include <kvbox.h>
 #include <kseparator.h>
+#include <kiconloader.h>
 
 #ifdef HAVE_KMETADATA
 #include <kratingwidget.h>
 #endif
 
-#include "dolphinmainwindow.h"
-#include "dolphinapplication.h"
 #include "pixmapviewer.h"
 #include "dolphinsettings.h"
 #include "metadatawidget.h"
 
-InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
-    SidebarPage(mainWindow, parent),
-    m_multipleSelection(false),
+InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
+    SidebarPage(parent),
+    m_multipleSelection(false), //TODO:check if I'm needed
     m_pendingPreview(false),
     m_timer(0),
+    m_currentSelection(KFileItemList()),
     m_preview(0),
     m_name(0),
     m_infos(0)
@@ -121,39 +120,37 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent)
     layout->addWidget(m_actionBox);
     layout->addWidget(dummy);
     setLayout(layout);
-    connect(mainWindow, SIGNAL(selectionChanged()),
-            this, SLOT(showItemInfo()));
-
-    connectToActiveView();
 }
 
 InfoSidebarPage::~InfoSidebarPage()
 {
 }
 
-void InfoSidebarPage::activeViewChanged()
+void InfoSidebarPage::setUrl(const KUrl& url)
 {
-    connectToActiveView();
+    if (!m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+        cancelRequest();
+        m_shownUrl = url;
+        showItemInfo();
+    }
 }
 
-void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url)
+void InfoSidebarPage::setSelection(const KFileItemList& selection)
 {
     cancelRequest();
-
-    if (!url.isEmpty() && !m_multipleSelection) {
-        m_urlCandidate = url;
-        m_timer->setSingleShot(true);
-        m_timer->start(300);
-    }
+    m_currentSelection = selection;
+    m_multipleSelection = (m_currentSelection.size() > 1);
+    showItemInfo();
 }
 
-void InfoSidebarPage::requestItemInfo(const KUrl& url)
+void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url)
 {
     cancelRequest();
 
     if (!url.isEmpty() && !m_multipleSelection) {
-        m_shownUrl = url;
-        showItemInfo();
+        m_urlCandidate = url;
+        m_timer->setSingleShot(true);
+        m_timer->start(300);
     }
 }
 
@@ -161,15 +158,9 @@ void InfoSidebarPage::showItemInfo()
 {
     cancelRequest();
 
-    m_multipleSelection = false;
-
-    // show the preview...
-    DolphinView* view = mainWindow()->activeView();
-    const KFileItemList selectedItems = view->selectedItems();
+    KFileItemList selectedItems = m_currentSelection;
     KUrl file;
-    if (selectedItems.count() > 1) {
-        m_multipleSelection = true;
-    } else if(selectedItems.count() == 0) {
+    if(selectedItems.count() == 0) {
         file = m_shownUrl;
     } else {
         file = selectedItems[0]->url();
@@ -228,9 +219,10 @@ void InfoSidebarPage::slotPreviewFailed(const KFileItem* item)
     }
 }
 
-void InfoSidebarPage::gotPreview(const KFileItem* /* item */,
+void InfoSidebarPage::gotPreview(const KFileItem* item,
                                  const QPixmap& pixmap)
 {
+    Q_UNUSED(item);
     if (m_pendingPreview) {
         m_preview->setPixmap(pixmap);
         m_pendingPreview = false;
@@ -239,11 +231,9 @@ void InfoSidebarPage::gotPreview(const KFileItem* /* item */,
 
 void InfoSidebarPage::startService(int index)
 {
-    DolphinView* view = mainWindow()->activeView();
-    if (view->hasSelection()) {
-        KUrl::List selectedUrls = view->selectedUrls();
+    if (m_currentSelection.count() > 0) {
         // TODO: Use "at()" as soon as executeService is fixed to take a const param (BIC)
-        KDEDesktopMimeType::executeService(selectedUrls, m_actionsVector[index]);
+        KDEDesktopMimeType::executeService(m_currentSelection.urlList(), m_actionsVector[index]);
     }
     else {
         // TODO: likewise
@@ -251,20 +241,6 @@ void InfoSidebarPage::startService(int index)
     }
 }
 
-void InfoSidebarPage::connectToActiveView()
-{
-    cancelRequest();
-
-    DolphinView* view = mainWindow()->activeView();
-    connect(view, SIGNAL(requestItemInfo(const KUrl&)),
-            this, SLOT(requestDelayedItemInfo(const KUrl&)));
-    connect(view, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(requestItemInfo(const KUrl&)));
-
-    m_shownUrl = view->url();
-    showItemInfo();
-}
-
 bool InfoSidebarPage::applyBookmark(const KUrl& url)
 {
     KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root();
@@ -298,8 +274,7 @@ void InfoSidebarPage::cancelRequest()
 void InfoSidebarPage::createMetaInfo()
 {
     beginInfoLines();
-    DolphinView* view = mainWindow()->activeView();
-    if (!view->hasSelection()) {
+    if(m_currentSelection.size() == 0) {
         KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
         fileItem.refresh();
 
@@ -309,8 +284,8 @@ void InfoSidebarPage::createMetaInfo()
         if ( MetaDataWidget::metaDataAvailable() )
             m_metadataWidget->setFile( fileItem.url() );
     }
-    else if (view->selectedItems().count() == 1) {
-        KFileItem* fileItem = view->selectedItems()[0];
+    else if (m_currentSelection.count() == 1) {
+        KFileItem* fileItem = m_currentSelection.at(0);
         addInfoLine(i18n("Type:"), fileItem->mimeComment());
 
         QString sizeText(KIO::convertSize(fileItem->size()));
@@ -332,9 +307,9 @@ void InfoSidebarPage::createMetaInfo()
     }
     else {
         if ( MetaDataWidget::metaDataAvailable() )
-            m_metadataWidget->setFiles( view->selectedItems().urlList() );
+            m_metadataWidget->setFiles( m_currentSelection.urlList() );
         unsigned long int totSize = 0;
-        foreach(KFileItem* item, view->selectedItems()) {
+        foreach(KFileItem* item, m_currentSelection) {
             totSize += item->size(); //FIXME what to do with directories ? (same with the one-item-selected-code), item->size() does not return the size of the content : not very instinctive for users
         }
         addInfoLine(i18n("Total size:"), KIO::convertSize(totSize));
@@ -415,7 +390,7 @@ void InfoSidebarPage::insertActions()
     // of KFileItems. If no selection is given, a temporary KFileItem
     // by the given Url 'url' is created and added to the list.
     KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
-    KFileItemList itemList = mainWindow()->activeView()->selectedItems();
+    KFileItemList itemList = m_currentSelection;
     if (itemList.isEmpty()) {
         fileItem.refresh();
         itemList.append(&fileItem);
index 7cb996327fe74bec90455a82e66c3defebed1d51..938b869597568c16ef05ca639b252706090111b7 100644 (file)
@@ -44,7 +44,6 @@ class QPainter;
 class KFileItem;
 class QLabel;
 class KVBox;
-class Q3Grid;
 class PixmapViewer;
 class MetaDataWidget;
 
@@ -58,12 +57,12 @@ class InfoSidebarPage : public SidebarPage
        Q_OBJECT
 
 public:
-    explicit InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent = 0);
+    explicit InfoSidebarPage(QWidget* parent = 0);
     virtual ~InfoSidebarPage();
 
-protected:
-    /** @see SidebarPage::activeViewChanged() */
-    virtual void activeViewChanged();
+public slots:
+    void setUrl(const KUrl& url);
+    void setSelection(const KFileItemList& selection);
 
 private slots:
     /**
@@ -74,14 +73,6 @@ private slots:
      */
     void requestDelayedItemInfo(const KUrl& url);
 
-    /**
-     * Does a request of information for the item of the given Url and
-     * provides default actions.
-     *
-     * @see InfoSidebarPage::showItemInfo()
-     */
-    void requestItemInfo(const KUrl& url);
-
     /**
      * Shows the information for the item of the Url which has been provided by
      * InfoSidebarPage::requestItemInfo() and provides default actions.
@@ -113,12 +104,6 @@ private slots:
     void startService(int index);
 
 private:
-    /**
-     * Connects to signals from the currently active Dolphin view to get
-     * informed about highlighting changes.
-     */
-    void connectToActiveView();
-
     /**
      * Checks whether the an Url is repesented by a bookmark. If yes,
      * then the bookmark icon and name are shown instead of a preview.
@@ -154,6 +139,7 @@ private:
     QTimer* m_timer;
     KUrl m_shownUrl;
     KUrl m_urlCandidate;
+       KFileItemList m_currentSelection;
 
     PixmapViewer* m_preview;
     QLabel* m_name;
index ce3b8cc341d15bd53595fcacb5f1f9305ffe9aa0..5b0e68f288a2fd7ca788b7b4b9eefced76097bd9 100644 (file)
  ***************************************************************************/
 
 #include "sidebarpage.h"
-#include "dolphinmainwindow.h"
+#include <QWidget>
+#include <kfileitem.h>
+#include <kurl.h>
 
-SidebarPage::SidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) :
+SidebarPage::SidebarPage(QWidget* parent) :
     QWidget(parent),
-    m_mainWindow(mainWindow)
+    m_url(KUrl()),
+    m_currentSelection(KFileItemList())
 {
-    connect(mainWindow, SIGNAL(activeViewChanged()),
-            this, SLOT(activeViewChanged()));
 }
 
 SidebarPage::~SidebarPage()
 {
 }
 
-void SidebarPage::activeViewChanged()
+void SidebarPage::setUrl(const KUrl& url)
 {
+    m_url = url;
 }
 
-DolphinMainWindow* SidebarPage::mainWindow() const {
-    return m_mainWindow;
+void SidebarPage::setSelection(const KFileItemList& selection)
+{
+    m_currentSelection = selection;
 }
 
 #include "sidebarpage.moc"
index 0399796b7018436080fe7697c7e798674df9c12c..e992955a24720ac98e7f1a6892d15a292e446243 100644 (file)
 #ifndef _SIDEBARPAGE_H_
 #define _SIDEBARPAGE_H_
 
-#include <qwidget.h>
-
-class DolphinMainWindow;
-class Sidebar;
+#include <QWidget>
+#include <kurl.h>
+#include <kfileitem.h>
 
 /**
  * @brief Base widget for all pages that can be embedded into the Sidebar.
  *
- * TODO
  */
 class SidebarPage : public QWidget
 {
        Q_OBJECT
-
 public:
-    explicit SidebarPage(DolphinMainWindow* mainwindow, QWidget* parent=0);
+    explicit SidebarPage(QWidget* parent=0);
     virtual ~SidebarPage();
 
-protected slots:
+public slots:
     /**
-     * Is invoked whenever the active view from Dolphin has been changed.
-     * The active view can be retrieved by mainWindow()->activeView();
+     * This is invoked every time the folder being displayed in the
+     * file-management views changes.
      */
-    virtual void activeViewChanged();
+       virtual void setUrl(const KUrl& url);
 
-protected:
-    DolphinMainWindow* mainWindow() const;
+    /**
+     * This is invoked to inform the sidebar that the user has selected a new
+     * set of files.
+     */
+    virtual void setSelection(const KFileItemList& selection);
+
+signals:
+    /**
+     * This signal is emited when the sidebar requests an URL-change in the
+     * currently active file-management view. The view is not requested to
+     * accept this change, if it is accepted the sidebar will be informed via
+     * the setUrl() slot.
+     */
+    void changeUrl(const KUrl& url);
 
-private:
-    DolphinMainWindow *m_mainWindow;
+    /**
+     * This signal is emitted when the sidebar requests a change in the
+     * current selection. The file-management view recieving this signal is
+     * not required to select all listed files, limiting the selection to
+     * e.g. the current folder. The new selection will be reported via the
+     * setSelection slot.
+     */
+    void changeSelection(const KFileItemList& selection);
+
+    /**
+     * This signal is emitted whenever a drop action on this widget needs the
+     * MainWindow's attention.
+     */
+    void urlsDropped(const KUrl::List& urls, const KUrl& destination);
+
+protected:
+    KUrl m_url;
+    KFileItemList m_currentSelection;
 };
 
 #endif // _SIDEBARPAGE_H_
index c3b255f21b822532d1b3a5489b1b9c705ef4b8c3..9390e5672eab7d4701accdd371bfb6b7e077e353 100644 (file)
 #include <QDropEvent>
 #include <QHeaderView>
 
-SidebarTreeView::SidebarTreeView(DolphinMainWindow* mainWindow,
-                                 QWidget* parent) :
-    QTreeView(parent),
-    m_mainWindow(mainWindow)
+SidebarTreeView::SidebarTreeView(QWidget* parent) :
+    QTreeView(parent)
 {
     setAcceptDrops(true);
     setUniformRowHeights(true);
index f7360e9c4ee8e1b40d09b9ab2c96c4aec0cc8511..d4560fb4460a33db3bdfcf1efc6da8552f790a38 100644 (file)
@@ -23,8 +23,6 @@
 #include <kurl.h>
 #include <QTreeView>
 
-class DolphinMainWindow;
-
 /**
  * @brief Tree view widget which is used for the sidebar panel.
  *
@@ -35,7 +33,7 @@ class SidebarTreeView : public QTreeView
     Q_OBJECT
 
 public:
-    explicit SidebarTreeView(DolphinMainWindow* mainWindow, QWidget* parent = 0);
+    explicit SidebarTreeView(QWidget* parent = 0);
     virtual ~SidebarTreeView();
 
 signals:
@@ -51,8 +49,6 @@ protected:
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dropEvent(QDropEvent* event);
 
-private:
-    DolphinMainWindow* m_mainWindow;
 };
 
 #endif
diff --git a/src/treeviewcontextmenu.cpp b/src/treeviewcontextmenu.cpp
new file mode 100644 (file)
index 0000000..c04fc74
--- /dev/null
@@ -0,0 +1,160 @@
+/***************************************************************************
+ *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and              *
+ *   Cvetoslav Ludmiloff                                                   *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "treeviewcontextmenu.h"
+
+#include <kiconloader.h>
+#include <kmenu.h>
+#include <konqmimedata.h>
+#include <konq_operations.h>
+#include <klocale.h>
+#include <kpropertiesdialog.h>
+
+#include <QApplication>
+#include <QClipboard>
+
+TreeViewContextMenu::TreeViewContextMenu(QWidget* parent,
+                                         KFileItem* fileInfo) :
+    m_parent(parent),
+    m_fileInfo(fileInfo)
+{
+}
+
+TreeViewContextMenu::~TreeViewContextMenu()
+{
+}
+
+void TreeViewContextMenu::open()
+{
+    Q_ASSERT(m_fileInfo != 0);
+
+    KMenu* popup = new KMenu(m_parent);
+
+    // insert 'Cut', 'Copy' and 'Paste'
+    QAction* cutAction   = new QAction(KIcon("edit-cut"), i18n("Cut"), this);
+    connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
+
+    QAction* copyAction  = new QAction(KIcon("edit-copy"), i18n("Copy"), this);
+    connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
+
+    QAction* pasteAction = new QAction(KIcon("edit-paste"), i18n("Paste"), this);
+
+    QClipboard* clipboard = QApplication::clipboard();
+    const QMimeData* mimeData = clipboard->mimeData();
+    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
+    pasteAction->setEnabled(sourceUrls.isEmpty());
+    connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
+
+    popup->addAction(cutAction);
+    popup->addAction(copyAction);
+    popup->addAction(pasteAction);
+    popup->addSeparator();
+
+    // insert 'Rename'
+    QAction* renameAction = new QAction(i18n("Rename"), this);
+    connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
+    popup->addAction(renameAction);
+
+    // insert 'Move to Trash' and (optionally) 'Delete'
+    const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
+    const KConfigGroup kdeConfig(globalConfig, "KDE");
+    bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
+    const KUrl& url = m_fileInfo->url();
+    if (url.isLocalFile()) {
+        QAction* moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
+        connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
+        popup->addAction(moveToTrashAction);
+    }
+    else {
+        showDeleteCommand = true;
+    }
+
+    if (showDeleteCommand) {
+        QAction* deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this);
+        connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
+        popup->addAction(deleteAction);
+    }
+
+    popup->addSeparator();
+
+    // insert 'Properties...' entry
+    QAction* propertiesAction = new QAction(i18n("Properties..."), this);
+    connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
+    popup->addAction(propertiesAction);
+
+    popup->exec(QCursor::pos());
+    popup->deleteLater();
+}
+
+void TreeViewContextMenu::cut()
+{
+    QMimeData* mimeData = new QMimeData();
+    KUrl::List kdeUrls;
+    kdeUrls.append(m_fileInfo->url());
+    KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), true);
+    QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void TreeViewContextMenu::copy()
+{
+    QMimeData* mimeData = new QMimeData();
+    KUrl::List kdeUrls;
+    kdeUrls.append(m_fileInfo->url());
+    KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), false);
+    QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void TreeViewContextMenu::paste()
+{
+    QClipboard* clipboard = QApplication::clipboard();
+    const QMimeData* mimeData = clipboard->mimeData();
+
+    const KUrl::List source = KUrl::List::fromMimeData(mimeData);
+    const KUrl& dest = m_fileInfo->url();
+    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
+        KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest);
+        clipboard->clear();
+    }
+    else {
+        KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest);
+    }
+}
+
+void TreeViewContextMenu::rename()
+{
+    // TODO
+}
+
+void TreeViewContextMenu::moveToTrash()
+{
+    // TODO
+}
+
+void TreeViewContextMenu::deleteItem()
+{
+    // TODO
+}
+
+void TreeViewContextMenu::showProperties()
+{
+    new KPropertiesDialog(m_fileInfo->url());
+}
+
+#include "treeviewcontextmenu.moc"
diff --git a/src/treeviewcontextmenu.h b/src/treeviewcontextmenu.h
new file mode 100644 (file)
index 0000000..88e1b03
--- /dev/null
@@ -0,0 +1,80 @@
+/***************************************************************************
+ *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef TREEVIEWCONTEXTMENU_H
+#define TREEVIEWCONTEXTMENU_H
+
+#include <QObject>
+
+class KMenu;
+class KFileItem;
+class QAction;
+
+/**
+ * @brief Represents the context menu which appears when doing a right
+ *        click on an item of the treeview.
+ */
+class TreeViewContextMenu : public QObject
+{
+    Q_OBJECT
+
+public:
+    /**
+     * @parent        Pointer to the parent widget the context menu
+     *                belongs to.
+     * @fileInfo      Pointer to the file item the context menu
+     *                is applied. If 0 is passed, the context menu
+     *                is above the viewport.
+     */
+    TreeViewContextMenu(QWidget* parent,
+                        KFileItem* fileInfo);
+
+    virtual ~TreeViewContextMenu();
+
+    /** Opens the context menu modal. */
+    void open();
+
+private slots:
+    /** Cuts the item m_fileInfo. */
+    void cut();
+
+    /** Copies the item m_fileInfo. */
+    void copy();
+
+    /** Paste the clipboard to m_fileInfo. */
+    void paste();
+
+    /** Renames the item m_fileInfo. */
+    void rename();
+
+    /** Moves the item m_fileInfo to the trash. */
+    void moveToTrash();
+
+    /** Deletes the item m_fileInfo. */
+    void deleteItem();
+
+    /** Shows the properties of the item m_fileInfo. */
+    void showProperties();
+
+private:
+    QWidget* m_parent;
+    KFileItem* m_fileInfo;
+};
+
+#endif
index 42e07c38f6fbec56b481ea7374cc881d9eb59efc..19feb58745b5290a86dbf3dae6581723af4d8d1a 100644 (file)
 #include "treeviewsidebarpage.h"
 
 #include "bookmarkselector.h"
-#include "dolphincontextmenu.h"
 #include "dolphinmainwindow.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
 #include "sidebartreeview.h"
+#include "treeviewcontextmenu.h"
 
 #include <kdirlister.h>
 #include <kdirmodel.h>
 // model:
 //#define USE_PROXY_MODEL
 
-TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow,
-                                         QWidget* parent) :
-    SidebarPage(mainWindow, parent),
+TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
+    SidebarPage(parent),
     m_dirLister(0),
     m_dirModel(0),
     m_proxyModel(0),
-    m_treeView(0),
-    m_selectedUrl()
+    m_treeView(0)
 {
-    Q_ASSERT(mainWindow != 0);
-
     m_dirLister = new KDirLister();
     m_dirLister->setDirOnlyMode(true);
     m_dirLister->setAutoUpdate(true);
@@ -67,13 +63,13 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow,
     m_proxyModel = new DolphinSortFilterProxyModel(this);
     m_proxyModel->setSourceModel(m_dirModel);
 
-    m_treeView = new SidebarTreeView(mainWindow, this);
+    m_treeView = new SidebarTreeView(this);
     m_treeView->setModel(m_proxyModel);
 
     m_proxyModel->setSorting(DolphinView::SortByName);
     m_proxyModel->setSortOrder(Qt::Ascending);
 #else
-    m_treeView = new SidebarTreeView(mainWindow, this);
+    m_treeView = new SidebarTreeView(this);
     m_treeView->setModel(m_dirModel);
 #endif
 
@@ -93,49 +89,13 @@ TreeViewSidebarPage::~TreeViewSidebarPage()
     m_dirLister = 0;
 }
 
-void TreeViewSidebarPage::activeViewChanged()
-{
-    connectToActiveView();
-}
-
-void TreeViewSidebarPage::showEvent(QShowEvent* event)
-{
-    SidebarPage::showEvent(event);
-    connectToActiveView();
-}
-
-void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
-{
-    SidebarPage::contextMenuEvent(event);
-
-    const QModelIndex index = m_treeView->indexAt(event->pos());
-    if (!index.isValid()) {
-        // only open a context menu above a directory item
-        return;
-    }
-
-#if defined(USE_PROXY_MODEL)
-    const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
-    KFileItem* item = m_dirModel->itemForIndex(dirModelIndex);
-#else
-    KFileItem* item = m_dirModel->itemForIndex(index);
-#endif
-
-    mainWindow()->activeView()->clearSelection();
-    DolphinContextMenu contextMenu(mainWindow(),
-                                   item,
-                                   m_dirLister->url(),
-                                   DolphinContextMenu::SidebarView);
-    contextMenu.open();
-}
-
-void TreeViewSidebarPage::updateSelection(const KUrl& url)
+void TreeViewSidebarPage::setUrl(const KUrl& url)
 {
-    if (!url.isValid() || (url == m_selectedUrl)) {
+    if (!url.isValid() || (url == m_url)) {
         return;
     }
 
-    m_selectedUrl = url;
+    m_url = url;
 
     // adjust the root of the tree to the base bookmark
     const KUrl baseUrl = BookmarkSelector::baseBookmark(url).url();
@@ -173,6 +133,34 @@ void TreeViewSidebarPage::updateSelection(const KUrl& url)
             parentUrl = parentUrl.upUrl();
         }
     }
+
+}
+
+void TreeViewSidebarPage::showEvent(QShowEvent* event)
+{
+    SidebarPage::showEvent(event);
+}
+
+void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
+{
+    SidebarPage::contextMenuEvent(event);
+
+    const QModelIndex index = m_treeView->indexAt(event->pos());
+    if (!index.isValid()) {
+        // only open a context menu above a directory item
+        return;
+    }
+
+#if defined(USE_PROXY_MODEL)
+    const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
+    KFileItem* item = m_dirModel->itemForIndex(dirModelIndex);
+#else
+    KFileItem* item = m_dirModel->itemForIndex(index);
+#endif
+
+    emit changeSelection(KFileItemList());
+    TreeViewContextMenu contextMenu(this, item);
+    contextMenu.open();
 }
 
 void TreeViewSidebarPage::expandSelectionParent()
@@ -181,7 +169,7 @@ void TreeViewSidebarPage::expandSelectionParent()
                this, SLOT(expandSelectionParent()));
 
     // expand the parent folder of the selected item
-    KUrl parentUrl = m_selectedUrl.upUrl();
+    KUrl parentUrl = m_url.upUrl();
     if (!m_dirLister->url().isParentOf(parentUrl)) {
         return;
     }
@@ -196,7 +184,7 @@ void TreeViewSidebarPage::expandSelectionParent()
 #endif
 
         // select the item and assure that the item is visible
-        index = m_dirModel->indexForUrl(m_selectedUrl);
+        index = m_dirModel->indexForUrl(m_url);
         if (index.isValid()) {
 #if defined(USE_PROXY_MODEL)
             proxyIndex = m_proxyModel->mapFromSource(index);
@@ -224,7 +212,7 @@ void TreeViewSidebarPage::updateActiveView(const QModelIndex& index)
 #endif
     if (item != 0) {
         const KUrl& url = item->url();
-        mainWindow()->activeView()->setUrl(url);
+        emit changeUrl(url);
     }
 }
 
@@ -240,25 +228,9 @@ void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
 #endif
         Q_ASSERT(item != 0);
         if (item->isDir()) {
-            mainWindow()->dropUrls(urls, item->url());
+            emit urlsDropped(urls, item->url());
         }
     }
 }
 
-void TreeViewSidebarPage::connectToActiveView()
-{
-    const QWidget* parent = parentWidget();
-    if ((parent == 0) || parent->isHidden()) {
-        return;
-    }
-
-    const DolphinView* view = mainWindow()->activeView();
-    const KUrl& url = view->url();
-
-    connect(view, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(updateSelection(const KUrl&)));
-
-    updateSelection(url);
-}
-
 #include "treeviewsidebarpage.moc"
index c8aec9e4e023b8d4282ab69133da88c627984968..badc94484142decedfe4e21596ee1764da85ed0c 100644 (file)
@@ -42,13 +42,16 @@ class TreeViewSidebarPage : public SidebarPage
     Q_OBJECT
 
 public:
-    TreeViewSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent = 0);
+    TreeViewSidebarPage(QWidget* parent = 0);
     virtual ~TreeViewSidebarPage();
 
-protected:
-    /** @see SidebarPage::activeViewChanged() */
-    virtual void activeViewChanged();
+public slots:
+    /**
+     * Changes the current selection inside the tree to \a url.
+     */
+    void setUrl(const KUrl& url);
 
+protected:
     /** @see QWidget::showEvent() */
     virtual void showEvent(QShowEvent* event);
 
@@ -56,12 +59,6 @@ protected:
     virtual void contextMenuEvent(QContextMenuEvent* event);
 
 private slots:
-    /**
-     * Updates the current selection inside the tree to
-     * \a url.
-     */
-    void updateSelection(const KUrl& url);
-
     /**
      * Expands the tree in a way that the item with the URL m_selectedUrl
      * gets visible. Is called by TreeViewSidebarPage::updateSelection()
@@ -81,19 +78,11 @@ private slots:
     void dropUrls(const KUrl::List& urls,
                   const QModelIndex& index);
 
-private:
-    /**
-     * Connects to signals from the currently active Dolphin view to get
-     * informed about highlighting changes.
-     */
-    void connectToActiveView();
-
 private:
     KDirLister* m_dirLister;
     KDirModel* m_dirModel;
     DolphinSortFilterProxyModel* m_proxyModel;
     SidebarTreeView* m_treeView;
-    KUrl m_selectedUrl;
 };
 
 #endif // TREEVIEWSIDEBARPAGE_H
index c97a560ba6447e43d681ac61c1b7c12d565e5ac6..6c89e5098f1bf996d59375fef6a46245889af3b6 100644 (file)
@@ -152,27 +152,19 @@ void UrlNavigatorButton::paintEvent(QPaintEvent* event)
 
     const bool clipped = isTextClipped();
     const int align = clipped ? Qt::AlignVCenter : Qt::AlignCenter;
-    painter.drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
-
+    const QRect textRect(0, 0, textWidth, buttonHeight);
     if (clipped) {
-        // Blend the right area of the text with the background, as the
-        // text is clipped.
-        // TODO: use alpha blending in Qt4 instead of drawing the text that often
-        const int blendSteps = 16;
-
-        QColor blendColor(backgroundColor);
-        const int redInc   = (foregroundColor.red()   - backgroundColor.red())   / blendSteps;
-        const int greenInc = (foregroundColor.green() - backgroundColor.green()) / blendSteps;
-        const int blueInc  = (foregroundColor.blue()  - backgroundColor.blue())  / blendSteps;
-        for (int i = 0; i < blendSteps; ++i) {
-            painter.setClipRect(QRect(textWidth - i, 0, 1, buttonHeight));
-            painter.setPen(blendColor);
-            painter.drawText(QRect(0, 0, textWidth, buttonHeight), align, text());
-
-            blendColor.setRgb(blendColor.red()   + redInc,
-                              blendColor.green() + greenInc,
-                              blendColor.blue()  + blueInc);
-        }
+        QLinearGradient gradient(textRect.topLeft(), textRect.topRight());
+        gradient.setColorAt(0.8, foregroundColor);
+        gradient.setColorAt(1.0, backgroundColor);
+
+        QPen pen;
+        pen.setBrush(QBrush(gradient));
+        painter.setPen(pen);
+        painter.drawText(textRect, align, text());
+    }
+    else {
+        painter.drawText(textRect, align, text());
     }
 }