┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-03-25 06:44:28 +0000
committerPeter Penz <[email protected]>2007-03-25 06:44:28 +0000
commit8f9baef848c3056cd1df772f0774decad509cff3 (patch)
treeadcad2dcf4d15e0102d0c466b4d4a38ccd4ff875
parent3b4d05893b4023338d8484dc5c6812bbe0fb0ceb (diff)
Patch by Luca Gugelmann: get rid of any mainwindow dependency from the sidebars.
svn path=/trunk/KDE/kdebase/apps/; revision=646256
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/bookmarkssidebarpage.cpp32
-rw-r--r--src/bookmarkssidebarpage.h22
-rw-r--r--src/dolphincontextmenu.cpp136
-rw-r--r--src/dolphincontextmenu.h32
-rw-r--r--src/dolphinmainwindow.cpp73
-rw-r--r--src/dolphinmainwindow.h63
-rw-r--r--src/dolphinview.cpp33
-rw-r--r--src/dolphinview.h14
-rw-r--r--src/infosidebarpage.cpp105
-rw-r--r--src/infosidebarpage.h24
-rw-r--r--src/sidebarpage.cpp19
-rw-r--r--src/sidebarpage.h55
-rw-r--r--src/sidebartreeview.cpp6
-rw-r--r--src/sidebartreeview.h6
-rw-r--r--src/treeviewcontextmenu.cpp160
-rw-r--r--src/treeviewcontextmenu.h80
-rw-r--r--src/treeviewsidebarpage.cpp110
-rw-r--r--src/treeviewsidebarpage.h25
-rw-r--r--src/urlnavigatorbutton.cpp30
20 files changed, 557 insertions, 471 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bf5679ef3..2ad4814e2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
diff --git a/src/bookmarkssidebarpage.cpp b/src/bookmarkssidebarpage.cpp
index 2d24ac783..677d0bd06 100644
--- a/src/bookmarkssidebarpage.cpp
+++ b/src/bookmarkssidebarpage.cpp
@@ -36,11 +36,10 @@
#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)
{
diff --git a/src/bookmarkssidebarpage.h b/src/bookmarkssidebarpage.h
index 3eb9a55a0..c50585ccb 100644
--- a/src/bookmarkssidebarpage.h
+++ b/src/bookmarkssidebarpage.h
@@ -19,12 +19,13 @@
#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;
};
diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp
index 44c842fe7..e78f3ec1c 100644
--- a/src/dolphincontextmenu.cpp
+++ b/src/dolphincontextmenu.cpp
@@ -50,25 +50,17 @@
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);
}
}
diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h
index 2a678d9a2..f3f075717 100644
--- a/src/dolphincontextmenu.h
+++ b/src/dolphincontextmenu.h
@@ -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;
};
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index deb418681..775ef9864 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -244,13 +244,23 @@ void DolphinMainWindow::refreshViews()
emit activeViewChanged();
}
-void DolphinMainWindow::changeUrl(const QString& url)
+void DolphinMainWindow::changeUrl(const KUrl& url)
{
if (activeView() != 0) {
- activeView()->setUrl(KUrl(url));
+ activeView()->setUrl(url);
+ updateEditActions();
+ updateViewActions();
+ updateGoActions();
+ setCaption(url.fileName());
+ emit urlChanged(url);
}
}
+void DolphinMainWindow::changeSelection(const KFileItemList& selection)
+{
+ activeView()->changeSelection(selection);
+}
+
void DolphinMainWindow::slotViewModeChanged()
{
updateViewActions();
@@ -338,7 +348,7 @@ void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::AdditionalI
}
}
-void DolphinMainWindow::slotSelectionChanged()
+void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
{
updateEditActions();
@@ -353,7 +363,7 @@ void DolphinMainWindow::slotSelectionChanged()
m_activeView->updateStatusBar();
- emit selectionChanged();
+ emit selectionChanged(selection);
}
void DolphinMainWindow::slotHistoryChanged()
@@ -361,14 +371,6 @@ void DolphinMainWindow::slotHistoryChanged()
updateHistory();
}
-void DolphinMainWindow::slotUrlChanged(const KUrl& url)
-{
- updateEditActions();
- updateViewActions();
- updateGoActions();
- setCaption(url.fileName());
-}
-
void DolphinMainWindow::updateFilterBarAction(bool show)
{
KToggleAction* showFilterBarAction =
@@ -776,6 +778,7 @@ void DolphinMainWindow::toggleSplitView()
connectViewSignals(SecondaryIdx);
m_splitter->addWidget(m_view[SecondaryIdx]);
m_splitter->setSizes(QList<int>() << newWidth << newWidth);
+ m_view[SecondaryIdx]->reload();
m_view[SecondaryIdx]->show();
}
else {
@@ -1010,10 +1013,11 @@ void DolphinMainWindow::init()
homeUrl,
props.viewMode(),
props.showHiddenFiles());
- connectViewSignals(PrimaryIdx);
- m_view[PrimaryIdx]->show();
m_activeView = m_view[PrimaryIdx];
+ connectViewSignals(PrimaryIdx);
+ m_view[PrimaryIdx]->reload();
+ m_view[PrimaryIdx]->show();
setCentralWidget(m_splitter);
setupDockWidgets();
@@ -1040,6 +1044,8 @@ void DolphinMainWindow::init()
if ( !MetaDataWidget::metaDataAvailable() )
activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);
#endif
+
+ emit urlChanged(homeUrl);
}
void DolphinMainWindow::loadSettings()
@@ -1292,37 +1298,45 @@ void DolphinMainWindow::setupDockWidgets()
// after the dock concept has been finalized.
// setup "Bookmarks"
- QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"));
+ QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"), this);
shortcutsDock->setObjectName("bookmarksDock");
shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
- shortcutsDock->setWidget(new BookmarksSidebarPage(this));
+ SidebarPage* shortcutsWidget = new BookmarksSidebarPage(shortcutsDock);
+ shortcutsDock->setWidget(shortcutsWidget);
+
shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel"));
actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction());
addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
+ connectSidebarPage(shortcutsWidget);
// setup "Information"
- QDockWidget* infoDock = new QDockWidget(i18n("Information"));
+ QDockWidget* infoDock = new QDockWidget(i18n("Information"), this);
infoDock->setObjectName("infoDock");
infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
- infoDock->setWidget(new InfoSidebarPage(this));
+ SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
+ infoDock->setWidget(infoWidget);
+
infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
addDockWidget(Qt::RightDockWidgetArea, infoDock);
+ connectSidebarPage(infoWidget);
// setup "Tree View"
QDockWidget* treeViewDock = new QDockWidget(i18n("Folders")); // TODO: naming?
treeViewDock->setObjectName("treeViewDock");
treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
- treeViewDock->setWidget(new TreeViewSidebarPage(this));
+ TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
+ treeViewDock->setWidget(treeWidget);
treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel"));
actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
+ connectSidebarPage(treeWidget);
const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
if (firstRun) {
@@ -1479,17 +1493,32 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::AdditionalInformation)),
this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation)));
- connect(view, SIGNAL(selectionChanged()),
- this, SLOT(slotSelectionChanged()));
+ connect(view, SIGNAL(selectionChanged(KFileItemList)),
+ this, SLOT(slotSelectionChanged(KFileItemList)));
connect(view, SIGNAL(showFilterBarChanged(bool)),
this, SLOT(updateFilterBarAction(bool)));
+ connect(view, SIGNAL(urlChanged(KUrl)),
+ this, SLOT(changeUrl(KUrl)));
const UrlNavigator* navigator = view->urlNavigator();
connect(navigator, SIGNAL(urlChanged(const KUrl&)),
- this, SLOT(slotUrlChanged(const KUrl&)));
+ this, SLOT(changeUrl(const KUrl&)));
connect(navigator, SIGNAL(historyChanged()),
this, SLOT(slotHistoryChanged()));
+}
+void DolphinMainWindow::connectSidebarPage(SidebarPage* page)
+{
+ connect(page, SIGNAL(changeUrl(KUrl)),
+ this, SLOT(changeUrl(KUrl)));
+ connect(page, SIGNAL(changeSelection(KFileItemList)),
+ this, SLOT(changeSelection(KFileItemList)));
+ connect(page, SIGNAL(urlsDropped(KUrl::List,KUrl)),
+ this, SLOT(dropUrls(KUrl::List,KUrl)));
+ connect(this, SIGNAL(urlChanged(KUrl)),
+ page, SLOT(setUrl(KUrl)));
+ connect(this, SIGNAL(selectionChanged(KFileItemList)),
+ page, SLOT(setSelection(KFileItemList)));
}
DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h
index d481a9e31..d8c64da7c 100644
--- a/src/dolphinmainwindow.h
+++ b/src/dolphinmainwindow.h
@@ -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);
@@ -95,14 +82,35 @@ public:
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
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp
index 6dfdd3d7b..99757bac7 100644
--- a/src/dolphinview.cpp
+++ b/src/dolphinview.cpp
@@ -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()
diff --git a/src/dolphinview.h b/src/dolphinview.h
index c2d0a1cc8..aee10bcad 100644
--- a/src/dolphinview.h
+++ b/src/dolphinview.h
@@ -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.
diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp
index 4a3a387bb..50f9eb0f8 100644
--- a/src/infosidebarpage.cpp
+++ b/src/infosidebarpage.cpp
@@ -20,19 +20,18 @@
#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>
@@ -44,22 +43,22 @@
#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);
diff --git a/src/infosidebarpage.h b/src/infosidebarpage.h
index 7cb996327..938b86959 100644
--- a/src/infosidebarpage.h
+++ b/src/infosidebarpage.h
@@ -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:
/**
@@ -75,14 +74,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.
*/
@@ -114,12 +105,6 @@ private slots:
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.
* @return True, if the Url represents exactly a bookmark.
@@ -154,6 +139,7 @@ private:
QTimer* m_timer;
KUrl m_shownUrl;
KUrl m_urlCandidate;
+ KFileItemList m_currentSelection;
PixmapViewer* m_preview;
QLabel* m_name;
diff --git a/src/sidebarpage.cpp b/src/sidebarpage.cpp
index ce3b8cc34..5b0e68f28 100644
--- a/src/sidebarpage.cpp
+++ b/src/sidebarpage.cpp
@@ -18,26 +18,29 @@
***************************************************************************/
#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"
diff --git a/src/sidebarpage.h b/src/sidebarpage.h
index 0399796b7..e992955a2 100644
--- a/src/sidebarpage.h
+++ b/src/sidebarpage.h
@@ -21,36 +21,61 @@
#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_
diff --git a/src/sidebartreeview.cpp b/src/sidebartreeview.cpp
index c3b255f21..9390e5672 100644
--- a/src/sidebartreeview.cpp
+++ b/src/sidebartreeview.cpp
@@ -26,10 +26,8 @@
#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);
diff --git a/src/sidebartreeview.h b/src/sidebartreeview.h
index f7360e9c4..d4560fb44 100644
--- a/src/sidebartreeview.h
+++ b/src/sidebartreeview.h
@@ -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
index 000000000..c04fc746e
--- /dev/null
+++ b/src/treeviewcontextmenu.cpp
@@ -0,0 +1,160 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Peter Penz ([email protected]) 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
index 000000000..88e1b03e9
--- /dev/null
+++ b/src/treeviewcontextmenu.h
@@ -0,0 +1,80 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Peter Penz <[email protected]> *
+ * *
+ * 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
diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp
index 42e07c38f..19feb5874 100644
--- a/src/treeviewsidebarpage.cpp
+++ b/src/treeviewsidebarpage.cpp
@@ -20,11 +20,11 @@
#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>
@@ -40,17 +40,13 @@
// 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"
diff --git a/src/treeviewsidebarpage.h b/src/treeviewsidebarpage.h
index c8aec9e4e..badc94484 100644
--- a/src/treeviewsidebarpage.h
+++ b/src/treeviewsidebarpage.h
@@ -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);
@@ -57,12 +60,6 @@ protected:
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()
* if the dir lister has been completed.
@@ -82,18 +79,10 @@ private slots:
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
diff --git a/src/urlnavigatorbutton.cpp b/src/urlnavigatorbutton.cpp
index c97a560ba..6c89e5098 100644
--- a/src/urlnavigatorbutton.cpp
+++ b/src/urlnavigatorbutton.cpp
@@ -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());
+ QLinearGradient gradient(textRect.topLeft(), textRect.topRight());
+ gradient.setColorAt(0.8, foregroundColor);
+ gradient.setColorAt(1.0, backgroundColor);
- blendColor.setRgb(blendColor.red() + redInc,
- blendColor.green() + greenInc,
- blendColor.blue() + blueInc);
- }
+ QPen pen;
+ pen.setBrush(QBrush(gradient));
+ painter.setPen(pen);
+ painter.drawText(textRect, align, text());
+ }
+ else {
+ painter.drawText(textRect, align, text());
}
}