diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31e6779a3b..d7cd886c31 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ set(dolphin_SRCS dolphinmainwindow.cpp dolphinnewmenu.cpp dolphinview.cpp + dolphinviewcontainer.cpp dolphinstatusbar.cpp dolphindirlister.cpp dolphincontextmenu.cpp diff --git a/src/dolphinapplication.cpp b/src/dolphinapplication.cpp index 4c3273bff0..e0e1c59404 100644 --- a/src/dolphinapplication.cpp +++ b/src/dolphinapplication.cpp @@ -20,6 +20,7 @@ #include "dolphinapplication.h" #include "dolphinmainwindow.h" +#include "dolphinviewcontainer.h" #include #include @@ -90,8 +91,8 @@ int DolphinApplication::newInstance() int DolphinApplication::openWindow(const KUrl& url) { DolphinMainWindow* win = createMainWindow(); - if ((win->activeView() != 0) && url.isValid()) { - win->activeView()->setUrl(url); + if ((win->activeViewContainer() != 0) && url.isValid()) { + win->activeViewContainer()->setUrl(url); } win->show(); return win->getId(); diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index ba0954b83f..72173538e3 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -88,10 +88,10 @@ void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event) m_controller->triggerContextMenuRequest(event->pos()); } -void DolphinColumnView::mouseReleaseEvent(QMouseEvent* event) +void DolphinColumnView::mousePressEvent(QMouseEvent* event) { - QColumnView::mouseReleaseEvent(event); m_controller->triggerActivation(); + QColumnView::mousePressEvent(event); } void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event) diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index a2e49ae539..500da74ac0 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -39,7 +39,7 @@ public: protected: virtual QStyleOptionViewItem viewOptions() const; virtual void contextMenuEvent(QContextMenuEvent* event); - virtual void mouseReleaseEvent(QMouseEvent* event); + virtual void mousePressEvent(QMouseEvent* event); virtual void dragEnterEvent(QDragEnterEvent* event); virtual void dropEvent(QDropEvent* event); diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 468b7d69d0..ce14c37ef9 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -23,6 +23,7 @@ #include "dolphinmainwindow.h" #include "dolphinsettings.h" #include "dolphinview.h" +#include "dolphinviewcontainer.h" #include #include @@ -57,7 +58,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, { // 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(); + DolphinView* view = m_mainWindow->activeViewContainer()->view(); m_selectedUrls = view->selectedUrls(); m_selectedItems = view->selectedItems(); } @@ -242,11 +243,11 @@ void DolphinContextMenu::openViewportContextMenu() QAction* activatedAction = popup->exec(QCursor::pos()); if (activatedAction == propertiesAction) { - const KUrl& url = m_mainWindow->activeView()->url(); + const KUrl& url = m_mainWindow->activeViewContainer()->url(); KPropertiesDialog dialog(url); dialog.exec(); } else if (activatedAction == bookmarkAction) { - const KUrl& url = m_mainWindow->activeView()->url(); + const KUrl& url = m_mainWindow->activeViewContainer()->url(); if (url.isValid()) { DolphinSettings::instance().placesModel()->addPlace(url.fileName(), url); } @@ -278,7 +279,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals); const KConfigGroup kdeConfig(globalConfig, "KDE"); bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false); - const KUrl& url = m_mainWindow->activeView()->url(); + const KUrl& url = m_mainWindow->activeViewContainer()->url(); if (url.isLocalFile()) { QAction* moveToTrashAction = collection->action("move_to_trash"); popup->addAction(moveToTrashAction); diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 098fc46a06..6a3f4bf187 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -155,6 +155,8 @@ void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event) void DolphinDetailsView::mousePressEvent(QMouseEvent* event) { + m_controller->triggerActivation(); + QTreeView::mousePressEvent(event); const QModelIndex index = indexAt(event->pos()); @@ -191,7 +193,6 @@ void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event) updateElasticBand(); m_showElasticBand = false; } - m_controller->triggerActivation(); } void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event) diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index b2ac029ce7..d21ffba327 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -106,6 +106,7 @@ void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) void DolphinIconsView::mousePressEvent(QMouseEvent* event) { + m_controller->triggerActivation(); if (!indexAt(event->pos()).isValid()) { const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) { @@ -116,12 +117,6 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event) KListView::mousePressEvent(event); } -void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event) -{ - KListView::mouseReleaseEvent(event); - m_controller->triggerActivation(); -} - void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) { if (event->mimeData()->hasUrls()) { diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index c58cd4c532..83ca615f0a 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -45,7 +45,6 @@ protected: virtual QStyleOptionViewItem viewOptions() const; virtual void contextMenuEvent(QContextMenuEvent* event); virtual void mousePressEvent(QMouseEvent* event); - virtual void mouseReleaseEvent(QMouseEvent* event); virtual void dragEnterEvent(QDragEnterEvent* event); virtual void dragLeaveEvent(QDragLeaveEvent* event); virtual void dragMoveEvent(QDragMoveEvent* event); diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 536da2a472..ebc0bd43ef 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -28,6 +28,7 @@ #include "dolphinsettings.h" #include "dolphinsettingsdialog.h" #include "dolphinstatusbar.h" +#include "dolphinviewcontainer.h" #include "infosidebarpage.h" #include "metadatawidget.h" #include "mainwindowadaptor.h" @@ -78,12 +79,12 @@ DolphinMainWindow::DolphinMainWindow(int id) : KXmlGuiWindow(0), m_newMenu(0), m_splitter(0), - m_activeView(0), + m_activeViewContainer(0), m_id(id) { setObjectName("Dolphin"); - m_view[PrimaryIdx] = 0; - m_view[SecondaryIdx] = 0; + m_viewContainer[PrimaryIdx] = 0; + m_viewContainer[SecondaryIdx] = 0; new MainWindowAdaptor(this); QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this); @@ -105,21 +106,23 @@ DolphinMainWindow::~DolphinMainWindow() DolphinApplication::app()->removeMainWindow(this); } -void DolphinMainWindow::setActiveView(DolphinView* view) +void DolphinMainWindow::setActiveView(DolphinViewContainer* view) { - Q_ASSERT((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx])); - if (m_activeView == view) { + Q_ASSERT((view == m_viewContainer[PrimaryIdx]) || (view == m_viewContainer[SecondaryIdx])); + if (m_activeViewContainer == view) { return; } - m_activeView = view; + m_activeViewContainer->setActive(false); + m_activeViewContainer = view; + m_activeViewContainer->setActive(true); updateHistory(); updateEditActions(); updateViewActions(); updateGoActions(); - setCaption(m_activeView->url().fileName()); + setCaption(m_activeViewContainer->url().fileName()); emit activeViewChanged(); } @@ -207,25 +210,25 @@ void DolphinMainWindow::rename(const KUrl& oldUrl, const KUrl& newUrl) void DolphinMainWindow::refreshViews() { - Q_ASSERT(m_view[PrimaryIdx] != 0); + Q_ASSERT(m_viewContainer[PrimaryIdx] != 0); // remember the current active view, as because of // the refreshing the active view might change to // the secondary view - DolphinView* activeView = m_activeView; + DolphinViewContainer* activeViewContainer = m_activeViewContainer; - m_view[PrimaryIdx]->refresh(); - if (m_view[SecondaryIdx] != 0) { - m_view[SecondaryIdx]->refresh(); + m_viewContainer[PrimaryIdx]->view()->refresh(); + if (m_viewContainer[SecondaryIdx] != 0) { + m_viewContainer[SecondaryIdx]->view()->refresh(); } - setActiveView(activeView); + setActiveView(activeViewContainer); } void DolphinMainWindow::changeUrl(const KUrl& url) { - if (activeView() != 0) { - activeView()->setUrl(url); + if (activeViewContainer() != 0) { + activeViewContainer()->setUrl(url); updateEditActions(); updateViewActions(); updateGoActions(); @@ -236,7 +239,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url) void DolphinMainWindow::changeSelection(const KFileItemList& selection) { - activeView()->changeSelection(selection); + activeViewContainer()->view()->changeSelection(selection); } void DolphinMainWindow::slotViewModeChanged() @@ -255,15 +258,17 @@ void DolphinMainWindow::slotShowHiddenFilesChanged() { KToggleAction* showHiddenFilesAction = static_cast(actionCollection()->action("show_hidden_files")); - showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles()); + const DolphinView* view = m_activeViewContainer->view(); + showHiddenFilesAction->setChecked(view->showHiddenFiles()); } void DolphinMainWindow::slotCategorizedSortingChanged() { KToggleAction* categorizedSortingAction = static_cast(actionCollection()->action("categorized")); - categorizedSortingAction->setChecked(m_activeView->categorizedSorting()); - categorizedSortingAction->setEnabled(m_activeView->supportsCategorizedSorting()); + const DolphinView* view = m_activeViewContainer->view(); + categorizedSortingAction->setChecked(view->categorizedSorting()); + categorizedSortingAction->setEnabled(view->supportsCategorizedSorting()); } void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) @@ -332,7 +337,8 @@ void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::AdditionalI QActionGroup* group = toggleAction->actionGroup(); Q_ASSERT(group != 0); - group->setEnabled(m_activeView->mode() == DolphinView::IconsView); + const DolphinView* view = m_activeViewContainer->view(); + group->setEnabled(view->mode() == DolphinView::IconsView); } } @@ -340,16 +346,16 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) { updateEditActions(); - Q_ASSERT(m_view[PrimaryIdx] != 0); - int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count(); - if (m_view[SecondaryIdx] != 0) { - selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count(); + Q_ASSERT(m_viewContainer[PrimaryIdx] != 0); + int selectedUrlsCount = m_viewContainer[PrimaryIdx]->view()->selectedUrls().count(); + if (m_viewContainer[SecondaryIdx] != 0) { + selectedUrlsCount += m_viewContainer[SecondaryIdx]->view()->selectedUrls().count(); } QAction* compareFilesAction = actionCollection()->action("compare_files"); compareFilesAction->setEnabled(selectedUrlsCount == 2); - m_activeView->updateStatusBar(); + m_activeViewContainer->updateStatusBar(); emit selectionChanged(selection); } @@ -376,6 +382,15 @@ void DolphinMainWindow::openNewMainWindow() DolphinApplication::app()->createMainWindow()->show(); } +void DolphinMainWindow::toggleActiveView() +{ + if (m_activeViewContainer == m_viewContainer[PrimaryIdx]) { + setActiveView(m_viewContainer[SecondaryIdx]); + } else { + setActiveView(m_viewContainer[PrimaryIdx]); + } +} + void DolphinMainWindow::closeEvent(QCloseEvent* event) { DolphinSettings& settings = DolphinSettings::instance(); @@ -390,28 +405,31 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) void DolphinMainWindow::saveProperties(KConfig* config) { KConfigGroup primaryView = config->group("Primary view"); - primaryView.writeEntry("Url", m_view[PrimaryIdx]->url().url()); - primaryView.writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable()); - if (m_view[SecondaryIdx] != 0) { + primaryView.writeEntry("Url", m_viewContainer[PrimaryIdx]->url().url()); + primaryView.writeEntry("Editable Url", m_viewContainer[PrimaryIdx]->isUrlEditable()); + if (m_viewContainer[SecondaryIdx] != 0) { KConfigGroup secondaryView = config->group("Secondary view"); - secondaryView.writeEntry("Url", m_view[SecondaryIdx]->url().url()); - secondaryView.writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable()); + secondaryView.writeEntry("Url", m_viewContainer[SecondaryIdx]->url().url()); + secondaryView.writeEntry("Editable Url", m_viewContainer[SecondaryIdx]->isUrlEditable()); } } void DolphinMainWindow::readProperties(KConfig* config) { - const KConfigGroup primaryView = config->group("Primary view"); - m_view[PrimaryIdx]->setUrl(primaryView.readEntry("Url")); - m_view[PrimaryIdx]->setUrlEditable(primaryView.readEntry("Editable Url", false)); + const KConfigGroup primaryViewGroup = config->group("Primary view"); + m_viewContainer[PrimaryIdx]->setUrl(primaryViewGroup.readEntry("Url")); + bool editable = primaryViewGroup.readEntry("Editable Url", false); + m_viewContainer[PrimaryIdx]->urlNavigator()->setUrlEditable(editable); + if (config->hasGroup("Secondary view")) { - const KConfigGroup secondaryView = config->group("Secondary view"); - if (m_view[SecondaryIdx] == 0) { + const KConfigGroup secondaryViewGroup = config->group("Secondary view"); + if (m_viewContainer[PrimaryIdx] == 0) { toggleSplitView(); } - m_view[SecondaryIdx]->setUrl(secondaryView.readEntry("Url")); - m_view[SecondaryIdx]->setUrlEditable(secondaryView.readEntry("Editable Url", false)); - } else if (m_view[SecondaryIdx] != 0) { + m_viewContainer[PrimaryIdx]->setUrl(secondaryViewGroup.readEntry("Url")); + editable = secondaryViewGroup.readEntry("Editable Url", false); + m_viewContainer[PrimaryIdx]->urlNavigator()->setUrlEditable(editable); + } else if (m_viewContainer[SecondaryIdx] != 0) { toggleSplitView(); } } @@ -419,19 +437,19 @@ void DolphinMainWindow::readProperties(KConfig* config) void DolphinMainWindow::updateNewMenu() { m_newMenu->slotCheckUpToDate(); - m_newMenu->setPopupFiles(activeView()->url()); + m_newMenu->setPopupFiles(activeViewContainer()->url()); } void DolphinMainWindow::rename() { clearStatusBar(); - m_activeView->renameSelectedItems(); + m_activeViewContainer->renameSelectedItems(); } void DolphinMainWindow::moveToTrash() { clearStatusBar(); - const KUrl::List selectedUrls = m_activeView->selectedUrls(); + const KUrl::List selectedUrls = m_activeViewContainer->view()->selectedUrls(); KonqOperations::del(this, KonqOperations::TRASH, selectedUrls); m_undoCommandTypes.append(KonqUndoManager::TRASH); } @@ -440,7 +458,7 @@ void DolphinMainWindow::deleteItems() { clearStatusBar(); - const KUrl::List list = m_activeView->selectedUrls(); + const KUrl::List list = m_activeViewContainer->view()->selectedUrls(); const bool del = KonqOperations::askDeleteConfirmation(list, KonqOperations::DEL, KonqOperations::DEFAULT_CONFIRMATION, @@ -457,7 +475,7 @@ void DolphinMainWindow::deleteItems() void DolphinMainWindow::properties() { - const KFileItemList list = m_activeView->selectedItems(); + const KFileItemList list = m_activeViewContainer->view()->selectedItems(); KPropertiesDialog dialog(list, this); dialog.exec(); } @@ -470,7 +488,7 @@ void DolphinMainWindow::quit() void DolphinMainWindow::slotHandleJobError(KJob* job) { if (job->error() != 0) { - DolphinStatusBar* statusBar = m_activeView->statusBar(); + DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); } @@ -479,7 +497,7 @@ void DolphinMainWindow::slotHandleJobError(KJob* job) void DolphinMainWindow::slotDeleteFileFinished(KJob* job) { if (job->error() == 0) { - DolphinStatusBar* statusBar = m_activeView->statusBar(); + DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); statusBar->setMessage(i18n("Delete operation completed."), DolphinStatusBar::OperationCompleted); } @@ -494,7 +512,7 @@ void DolphinMainWindow::slotUndoAvailable(bool available) if (available && (m_undoCommandTypes.count() > 0)) { const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst(); - DolphinStatusBar* statusBar = m_activeView->statusBar(); + DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); switch (command) { case KonqUndoManager::COPY: statusBar->setMessage(i18n("Copy operation completed."), @@ -546,7 +564,7 @@ void DolphinMainWindow::undo() void DolphinMainWindow::cut() { QMimeData* mimeData = new QMimeData(); - const KUrl::List kdeUrls = m_activeView->selectedUrls(); + const KUrl::List kdeUrls = m_activeViewContainer->view()->selectedUrls(); const KUrl::List mostLocalUrls; KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true); QApplication::clipboard()->setMimeData(mimeData); @@ -555,7 +573,7 @@ void DolphinMainWindow::cut() void DolphinMainWindow::copy() { QMimeData* mimeData = new QMimeData(); - const KUrl::List kdeUrls = m_activeView->selectedUrls(); + const KUrl::List kdeUrls = m_activeViewContainer->view()->selectedUrls(); const KUrl::List mostLocalUrls; KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false); @@ -572,10 +590,10 @@ void DolphinMainWindow::paste() const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData); // per default the pasting is done into the current Url of the view - KUrl destUrl(m_activeView->url()); + KUrl destUrl(m_activeViewContainer->url()); // check whether the pasting should be done into a selected directory - KUrl::List selectedUrls = m_activeView->selectedUrls(); + KUrl::List selectedUrls = m_activeViewContainer->view()->selectedUrls(); if (selectedUrls.count() == 1) { const KFileItem fileItem(S_IFDIR, KFileItem::Unknown, @@ -618,7 +636,7 @@ void DolphinMainWindow::updatePasteAction() } if (pasteAction->isEnabled()) { - KUrl::List urls = m_activeView->selectedUrls(); + KUrl::List urls = m_activeViewContainer->view()->selectedUrls(); const uint count = urls.count(); if (count > 1) { // pasting should not be allowed when more than one file @@ -628,7 +646,7 @@ void DolphinMainWindow::updatePasteAction() // Only one file is selected. Pasting is only allowed if this // file is a directory. // TODO: this doesn't work with remote protocols; instead we need a - // m_activeView->selectedFileItems() to get the real KFileItems + // m_activeViewContainer->selectedFileItems() to get the real KFileItems const KFileItem fileItem(S_IFDIR, KFileItem::Unknown, urls.first(), @@ -641,130 +659,134 @@ void DolphinMainWindow::updatePasteAction() void DolphinMainWindow::selectAll() { clearStatusBar(); - m_activeView->selectAll(); + m_activeViewContainer->view()->selectAll(); } void DolphinMainWindow::invertSelection() { clearStatusBar(); - m_activeView->invertSelection(); + m_activeViewContainer->view()->invertSelection(); } void DolphinMainWindow::setIconsView() { - m_activeView->setMode(DolphinView::IconsView); + m_activeViewContainer->view()->setMode(DolphinView::IconsView); } void DolphinMainWindow::setDetailsView() { - m_activeView->setMode(DolphinView::DetailsView); + m_activeViewContainer->view()->setMode(DolphinView::DetailsView); } void DolphinMainWindow::setColumnView() { - m_activeView->setMode(DolphinView::ColumnView); + m_activeViewContainer->view()->setMode(DolphinView::ColumnView); } void DolphinMainWindow::sortByName() { - m_activeView->setSorting(DolphinView::SortByName); + m_activeViewContainer->view()->setSorting(DolphinView::SortByName); } void DolphinMainWindow::sortBySize() { - m_activeView->setSorting(DolphinView::SortBySize); + m_activeViewContainer->view()->setSorting(DolphinView::SortBySize); } void DolphinMainWindow::sortByDate() { - m_activeView->setSorting(DolphinView::SortByDate); + m_activeViewContainer->view()->setSorting(DolphinView::SortByDate); } void DolphinMainWindow::sortByPermissions() { - m_activeView->setSorting(DolphinView::SortByPermissions); + m_activeViewContainer->view()->setSorting(DolphinView::SortByPermissions); } void DolphinMainWindow::sortByOwner() { - m_activeView->setSorting(DolphinView::SortByOwner); + m_activeViewContainer->view()->setSorting(DolphinView::SortByOwner); } void DolphinMainWindow::sortByGroup() { - m_activeView->setSorting(DolphinView::SortByGroup); + m_activeViewContainer->view()->setSorting(DolphinView::SortByGroup); } void DolphinMainWindow::sortByType() { - m_activeView->setSorting(DolphinView::SortByType); + m_activeViewContainer->view()->setSorting(DolphinView::SortByType); } void DolphinMainWindow::toggleSortOrder() { - const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::AscendingOrder) ? + DolphinView* view = m_activeViewContainer->view(); + const Qt::SortOrder order = (view->sortOrder() == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder; - m_activeView->setSortOrder(order); + view->setSortOrder(order); } void DolphinMainWindow::toggleSortCategorization() { - const bool categorizedSorting = m_activeView->categorizedSorting(); - m_activeView->setCategorizedSorting(!categorizedSorting); + DolphinView* view = m_activeViewContainer->view(); + const bool categorizedSorting = view->categorizedSorting(); + view->setCategorizedSorting(!categorizedSorting); } void DolphinMainWindow::clearInfo() { - m_activeView->setAdditionalInfo(KFileItemDelegate::NoInformation); + m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::NoInformation); } void DolphinMainWindow::showMimeInfo() { clearStatusBar(); - m_activeView->setAdditionalInfo(KFileItemDelegate::FriendlyMimeType); + m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::FriendlyMimeType); } void DolphinMainWindow::showSizeInfo() { clearStatusBar(); - m_activeView->setAdditionalInfo(KFileItemDelegate::Size); + m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::Size); } void DolphinMainWindow::showDateInfo() { clearStatusBar(); - m_activeView->setAdditionalInfo(KFileItemDelegate::ModificationTime); + m_activeViewContainer->view()->setAdditionalInfo(KFileItemDelegate::ModificationTime); } void DolphinMainWindow::toggleSplitView() { - if (m_view[SecondaryIdx] == 0) { - const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2; + if (m_viewContainer[SecondaryIdx] == 0) { + const int newWidth = (m_viewContainer[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2; // create a secondary view - m_view[SecondaryIdx] = new DolphinView(this, - 0, - m_view[PrimaryIdx]->rootUrl(), - m_view[PrimaryIdx]->mode(), - m_view[PrimaryIdx]->showHiddenFiles()); + const DolphinView* view = m_viewContainer[PrimaryIdx]->view(); + m_viewContainer[SecondaryIdx] = new DolphinViewContainer(this, + 0, + view->rootUrl(), + view->mode(), + view->showHiddenFiles()); connectViewSignals(SecondaryIdx); - m_splitter->addWidget(m_view[SecondaryIdx]); + m_splitter->addWidget(m_viewContainer[SecondaryIdx]); m_splitter->setSizes(QList() << newWidth << newWidth); - m_view[SecondaryIdx]->reload(); - m_view[SecondaryIdx]->show(); + m_viewContainer[SecondaryIdx]->view()->reload(); + m_viewContainer[SecondaryIdx]->setActive(false); + m_viewContainer[SecondaryIdx]->show(); } else { // remove secondary view - m_view[SecondaryIdx]->close(); - m_view[SecondaryIdx]->deleteLater(); - m_view[SecondaryIdx] = 0; + m_viewContainer[SecondaryIdx]->close(); + m_viewContainer[SecondaryIdx]->deleteLater(); + m_viewContainer[SecondaryIdx] = 0; } - setActiveView(m_view[PrimaryIdx]); + setActiveView(m_viewContainer[PrimaryIdx]); emit activeViewChanged(); } void DolphinMainWindow::reloadView() { clearStatusBar(); - m_activeView->reload(); + m_activeViewContainer->view()->reload(); } void DolphinMainWindow::stopLoading() @@ -777,7 +799,7 @@ void DolphinMainWindow::togglePreview() const KToggleAction* showPreviewAction = static_cast(actionCollection()->action("show_preview")); const bool show = showPreviewAction->isChecked(); - m_activeView->setShowPreview(show); + m_activeViewContainer->view()->setShowPreview(show); } void DolphinMainWindow::toggleShowHiddenFiles() @@ -787,7 +809,7 @@ void DolphinMainWindow::toggleShowHiddenFiles() const KToggleAction* showHiddenFilesAction = static_cast(actionCollection()->action("show_hidden_files")); const bool show = showHiddenFilesAction->isChecked(); - m_activeView->setShowHiddenFiles(show); + m_activeViewContainer->view()->setShowHiddenFiles(show); } void DolphinMainWindow::toggleFilterBarVisibility() @@ -795,18 +817,18 @@ void DolphinMainWindow::toggleFilterBarVisibility() const KToggleAction* showFilterBarAction = static_cast(actionCollection()->action("show_filter_bar")); const bool show = showFilterBarAction->isChecked(); - m_activeView->showFilterBar(show); + m_activeViewContainer->showFilterBar(show); } void DolphinMainWindow::zoomIn() { - m_activeView->zoomIn(); + m_activeViewContainer->view()->zoomIn(); updateViewActions(); } void DolphinMainWindow::zoomOut() { - m_activeView->zoomOut(); + m_activeViewContainer->view()->zoomOut(); updateViewActions(); } @@ -817,48 +839,49 @@ void DolphinMainWindow::toggleEditLocation() KToggleAction* action = static_cast(actionCollection()->action("editable_location")); bool editOrBrowse = action->isChecked(); - m_activeView->setUrlEditable(editOrBrowse); + KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); + urlNavigator->setUrlEditable(editOrBrowse); } void DolphinMainWindow::editLocation() { - m_activeView->setUrlEditable(true); + m_activeViewContainer->urlNavigator()->setUrlEditable(true); } void DolphinMainWindow::adjustViewProperties() { clearStatusBar(); - ViewPropertiesDialog dlg(m_activeView); + ViewPropertiesDialog dlg(m_activeViewContainer->view()); dlg.exec(); } void DolphinMainWindow::goBack() { clearStatusBar(); - m_activeView->goBack(); + m_activeViewContainer->urlNavigator()->goBack(); } void DolphinMainWindow::goForward() { clearStatusBar(); - m_activeView->goForward(); + m_activeViewContainer->urlNavigator()->goForward(); } void DolphinMainWindow::goUp() { clearStatusBar(); - m_activeView->goUp(); + m_activeViewContainer->urlNavigator()->goUp(); } void DolphinMainWindow::goHome() { clearStatusBar(); - m_activeView->goHome(); + m_activeViewContainer->urlNavigator()->goHome(); } void DolphinMainWindow::findFile() { - KRun::run("kfind", m_activeView->url(), this); + KRun::run("kfind", m_activeViewContainer->url(), this); } void DolphinMainWindow::compareFiles() @@ -869,16 +892,16 @@ void DolphinMainWindow::compareFiles() // - both in the secondary view // - one in the primary view and the other in the secondary // view - Q_ASSERT(m_view[PrimaryIdx] != 0); + Q_ASSERT(m_viewContainer[PrimaryIdx] != 0); KUrl urlA; KUrl urlB; - KUrl::List urls = m_view[PrimaryIdx]->selectedUrls(); + KUrl::List urls = m_viewContainer[PrimaryIdx]->view()->selectedUrls(); switch (urls.count()) { case 0: { - Q_ASSERT(m_view[SecondaryIdx] != 0); - urls = m_view[SecondaryIdx]->selectedUrls(); + Q_ASSERT(m_viewContainer[SecondaryIdx] != 0); + urls = m_viewContainer[SecondaryIdx]->view()->selectedUrls(); Q_ASSERT(urls.count() == 2); urlA = urls[0]; urlB = urls[1]; @@ -887,8 +910,8 @@ void DolphinMainWindow::compareFiles() case 1: { urlA = urls[0]; - Q_ASSERT(m_view[SecondaryIdx] != 0); - urls = m_view[SecondaryIdx]->selectedUrls(); + Q_ASSERT(m_viewContainer[SecondaryIdx] != 0); + urls = m_viewContainer[SecondaryIdx]->view()->selectedUrls(); Q_ASSERT(urls.count() == 1); urlB = urls[0]; break; @@ -943,16 +966,16 @@ void DolphinMainWindow::init() const KUrl& homeUrl = settings.generalSettings()->homeUrl(); setCaption(homeUrl.fileName()); ViewProperties props(homeUrl); - m_view[PrimaryIdx] = new DolphinView(this, - m_splitter, - homeUrl, - props.viewMode(), - props.showHiddenFiles()); + m_viewContainer[PrimaryIdx] = new DolphinViewContainer(this, + m_splitter, + homeUrl, + props.viewMode(), + props.showHiddenFiles()); - m_activeView = m_view[PrimaryIdx]; + m_activeViewContainer = m_viewContainer[PrimaryIdx]; connectViewSignals(PrimaryIdx); - m_view[PrimaryIdx]->reload(); - m_view[PrimaryIdx]->show(); + m_viewContainer[PrimaryIdx]->view()->reload(); + m_viewContainer[PrimaryIdx]->show(); setCentralWidget(m_splitter); setupDockWidgets(); @@ -973,11 +996,11 @@ void DolphinMainWindow::init() if (firstRun) { // assure a proper default size if Dolphin runs the first time - resize(640, 480); + resize(700, 500); } #ifdef HAVE_KMETADATA if (!MetaDataWidget::metaDataAvailable()) - activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error); + activeViewContainer()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error); #endif emit urlChanged(homeUrl); @@ -1299,7 +1322,7 @@ void DolphinMainWindow::setupDockWidgets() void DolphinMainWindow::updateHistory() { - const KUrlNavigator* urlNavigator = m_activeView->urlNavigator(); + const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); const int index = urlNavigator->historyIndex(); QAction* backAction = actionCollection()->action("go_back"); @@ -1315,7 +1338,7 @@ void DolphinMainWindow::updateHistory() void DolphinMainWindow::updateEditActions() { - const KFileItemList list = m_activeView->selectedItems(); + const KFileItemList list = m_activeViewContainer->view()->selectedItems(); if (list.isEmpty()) { stateChanged("has_no_selection"); } else { @@ -1348,18 +1371,19 @@ void DolphinMainWindow::updateEditActions() void DolphinMainWindow::updateViewActions() { + const DolphinView* view = m_activeViewContainer->view(); QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn)); if (zoomInAction != 0) { - zoomInAction->setEnabled(m_activeView->isZoomInPossible()); + zoomInAction->setEnabled(view->isZoomInPossible()); } QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut)); if (zoomOutAction != 0) { - zoomOutAction->setEnabled(m_activeView->isZoomOutPossible()); + zoomOutAction->setEnabled(view->isZoomOutPossible()); } QAction* action = 0; - switch (m_activeView->mode()) { + switch (view->mode()) { case DolphinView::IconsView: action = actionCollection()->action("icons"); break; @@ -1378,34 +1402,35 @@ void DolphinMainWindow::updateViewActions() toggleAction->setChecked(true); } - slotSortingChanged(m_activeView->sorting()); - slotSortOrderChanged(m_activeView->sortOrder()); + slotSortingChanged(view->sorting()); + slotSortOrderChanged(view->sortOrder()); slotCategorizedSortingChanged(); - slotAdditionalInfoChanged(m_activeView->additionalInfo()); + slotAdditionalInfoChanged(view->additionalInfo()); KToggleAction* showFilterBarAction = static_cast(actionCollection()->action("show_filter_bar")); - showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); + showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); KToggleAction* showPreviewAction = static_cast(actionCollection()->action("show_preview")); - showPreviewAction->setChecked(m_activeView->showPreview()); + showPreviewAction->setChecked(view->showPreview()); KToggleAction* showHiddenFilesAction = static_cast(actionCollection()->action("show_hidden_files")); - showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles()); + showHiddenFilesAction->setChecked(view->showHiddenFiles()); - updateSplitAction(m_view[SecondaryIdx] != 0); + updateSplitAction(m_viewContainer[SecondaryIdx] != 0); KToggleAction* editableLocactionAction = static_cast(actionCollection()->action("editable_location")); - editableLocactionAction->setChecked(m_activeView->isUrlEditable()); + const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); + editableLocactionAction->setChecked(urlNavigator->isUrlEditable()); } void DolphinMainWindow::updateGoActions() { QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up)); - const KUrl& currentUrl = m_activeView->url(); + const KUrl& currentUrl = m_activeViewContainer->url(); goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); } @@ -1429,12 +1454,16 @@ void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest) void DolphinMainWindow::clearStatusBar() { - m_activeView->statusBar()->clear(); + m_activeViewContainer->statusBar()->clear(); } void DolphinMainWindow::connectViewSignals(int viewIndex) { - DolphinView* view = m_view[viewIndex]; + DolphinViewContainer* container = m_viewContainer[viewIndex]; + connect(container, SIGNAL(showFilterBarChanged(bool)), + this, SLOT(updateFilterBarAction(bool))); + + DolphinView* view = container->view(); connect(view, SIGNAL(modeChanged()), this, SLOT(slotViewModeChanged())); connect(view, SIGNAL(showPreviewChanged()), @@ -1453,12 +1482,10 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) this, SLOT(slotSelectionChanged(KFileItemList))); connect(view, SIGNAL(requestItemInfo(KUrl)), this, SLOT(slotRequestItemInfo(KUrl))); - connect(view, SIGNAL(showFilterBarChanged(bool)), - this, SLOT(updateFilterBarAction(bool))); - connect(view, SIGNAL(urlChanged(KUrl)), - this, SLOT(changeUrl(KUrl))); + connect(view, SIGNAL(activated()), + this, SLOT(toggleActiveView())); - const KUrlNavigator* navigator = view->urlNavigator(); + const KUrlNavigator* navigator = container->urlNavigator(); connect(navigator, SIGNAL(urlChanged(const KUrl&)), this, SLOT(changeUrl(const KUrl&))); connect(navigator, SIGNAL(historyChanged()), @@ -1490,7 +1517,7 @@ DolphinMainWindow::UndoUiInterface::~UndoUiInterface() void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) { - DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar(); + DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar(); statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 6838b61b02..c4e303be3f 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -32,6 +32,7 @@ #include class DolphinApplication; +class DolphinViewContainer; class KNewMenu; class KUrl; class QSplitter; @@ -52,20 +53,20 @@ public: virtual ~DolphinMainWindow(); /** - * Activates the given view, which means that - * all menu actions are applied to this view. When - * having a split view setup the nonactive view - * is usually shown in darker colors. - */ - void setActiveView(DolphinView* view); + * Activates the given view, which means that + * all menu actions are applied to this view. When + * having a split view setup the nonactive view + * is usually shown in darker colors. + */ + void setActiveView(DolphinViewContainer* view); /** * Returns the currently active view. See * DolphinMainWindow::setActiveView() for more details. */ - DolphinView* activeView() const + DolphinViewContainer* activeViewContainer() const { - return m_activeView; + return m_activeViewContainer; } /** Renames the item represented by \a oldUrl to \a newUrl. */ @@ -406,6 +407,9 @@ private slots: /** Open a new main window. */ void openNewMainWindow(); + /** Toggles the active view if two views are shown within the main window. */ + void toggleActiveView(); + private: DolphinMainWindow(int id); void init(); @@ -468,10 +472,10 @@ class UndoUiInterface : public KonqUndoManager::UiInterface KNewMenu* m_newMenu; QSplitter* m_splitter; - DolphinView* m_activeView; + DolphinViewContainer* m_activeViewContainer; int m_id; - DolphinView* m_view[SecondaryIdx + 1]; + DolphinViewContainer* m_viewContainer[SecondaryIdx + 1]; /// remember pending undo operations until they are finished QList m_undoCommandTypes; diff --git a/src/dolphinnewmenu.cpp b/src/dolphinnewmenu.cpp index 5cd8a4d09a..100f20a52e 100644 --- a/src/dolphinnewmenu.cpp +++ b/src/dolphinnewmenu.cpp @@ -22,6 +22,7 @@ #include "dolphinmainwindow.h" #include "dolphinstatusbar.h" #include "dolphinview.h" +#include "dolphinviewcontainer.h" #include #include @@ -39,7 +40,7 @@ DolphinNewMenu::~DolphinNewMenu() void DolphinNewMenu::slotResult(KJob* job) { if (job->error()) { - DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar(); + DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar(); statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); } else { KNewMenu::slotResult(job); diff --git a/src/dolphinstatusbar.cpp b/src/dolphinstatusbar.cpp index b0bb8e871f..edf242e669 100644 --- a/src/dolphinstatusbar.cpp +++ b/src/dolphinstatusbar.cpp @@ -30,7 +30,7 @@ #include #include -DolphinStatusBar::DolphinStatusBar(DolphinView* parent) : +DolphinStatusBar::DolphinStatusBar(QWidget* parent, const KUrl& url) : KHBox(parent), m_messageLabel(0), m_spaceInfo(0), @@ -43,7 +43,7 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) : m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_spaceInfo = new StatusBarSpaceInfo(this); - m_spaceInfo->setUrl(parent->url()); + m_spaceInfo->setUrl(url); m_progressText = new QLabel(this); m_progressText->hide(); diff --git a/src/dolphinstatusbar.h b/src/dolphinstatusbar.h index 1824dccc7f..1a9aaa4c17 100644 --- a/src/dolphinstatusbar.h +++ b/src/dolphinstatusbar.h @@ -53,7 +53,9 @@ public: Error }; - DolphinStatusBar(DolphinView* parent = 0); + DolphinStatusBar(QWidget* parent, + const KUrl& url); + virtual ~DolphinStatusBar(); /** diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 16f06f2716..8d3bf1e2f7 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -20,17 +20,17 @@ #include "dolphinview.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include -#include #include #include #include @@ -44,109 +44,55 @@ #include "dolphincolumnview.h" #include "dolphincontroller.h" -#include "dolphinstatusbar.h" -#include "dolphinmainwindow.h" -#include "dolphindirlister.h" #include "dolphinsortfilterproxymodel.h" #include "dolphindetailsview.h" #include "dolphiniconsview.h" -#include "dolphincontextmenu.h" #include "dolphinitemcategorizer.h" -#include "filterbar.h" #include "renamedialog.h" -#include "kurlnavigator.h" #include "viewproperties.h" #include "dolphinsettings.h" #include "dolphin_generalsettings.h" -DolphinView::DolphinView(DolphinMainWindow* mainWindow, - QWidget* parent, +DolphinView::DolphinView(QWidget* parent, const KUrl& url, + KDirLister* dirLister, + KDirModel* dirModel, + DolphinSortFilterProxyModel* proxyModel, Mode mode, bool showHiddenFiles) : QWidget(parent), - m_showProgress(false), + m_active(true), m_blockContentsMovedSignal(false), m_initializeColumnView(false), m_mode(mode), - m_iconSize(0), - m_folderCount(0), - m_fileCount(0), - m_mainWindow(mainWindow), m_topLayout(0), - m_urlNavigator(0), m_controller(0), m_iconsView(0), m_detailsView(0), m_columnView(0), m_fileItemDelegate(0), - m_filterBar(0), - m_statusBar(0), - m_dirModel(0), - m_dirLister(0), - m_proxyModel(0) + m_dirModel(dirModel), + m_dirLister(dirLister), + m_proxyModel(proxyModel) { - hide(); setFocusPolicy(Qt::StrongFocus); m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); m_topLayout->setMargin(0); - connect(m_mainWindow, SIGNAL(activeViewChanged()), - this, SLOT(updateActivationState())); - QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), this, SLOT(updateCutItems())); - m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this); - - const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - m_urlNavigator->setUrlEditable(settings->editableUrl()); - m_urlNavigator->setHomeUrl(settings->homeUrl()); - - connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(changeDirectory(const KUrl&))); - connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)), - this, SLOT(dropUrls(const KUrl::List&, const KUrl&))); - connect(m_urlNavigator, SIGNAL(activated()), - this, SLOT(requestActivation())); - connect(this, SIGNAL(contentsMoved(int, int)), - m_urlNavigator, SLOT(savePosition(int, int))); - - m_statusBar = new DolphinStatusBar(this); - - m_dirLister = new DolphinDirLister(); - m_dirLister->setAutoUpdate(true); - m_dirLister->setMainWindow(this); - m_dirLister->setShowingDotFiles(showHiddenFiles); - m_dirLister->setDelayedMimeTypes(true); - - connect(m_dirLister, SIGNAL(clear()), - this, SLOT(updateStatusBar())); - connect(m_dirLister, SIGNAL(percent(int)), - this, SLOT(updateProgress(int))); - connect(m_dirLister, SIGNAL(deleteItem(KFileItem*)), - this, SLOT(updateStatusBar())); connect(m_dirLister, SIGNAL(completed()), - this, SLOT(updateItemCount())); + this, SLOT(restoreContentsPos())); connect(m_dirLister, SIGNAL(completed()), this, SLOT(updateCutItems())); connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), this, SLOT(generatePreviews(const KFileItemList&))); - connect(m_dirLister, SIGNAL(infoMessage(const QString&)), - this, SLOT(showInfoMessage(const QString&))); - connect(m_dirLister, SIGNAL(errorMessage(const QString&)), - this, SLOT(showErrorMessage(const QString&))); - - m_dirModel = new KDirModel(); - m_dirModel->setDirLister(m_dirLister); - m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory); - - m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dirModel); m_controller = new DolphinController(this); + m_controller->setUrl(url); connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)), this, SLOT(openContextMenu(const QPoint&))); connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&, QWidget*)), @@ -158,44 +104,23 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow, connect(m_controller, SIGNAL(itemTriggered(const QModelIndex&)), this, SLOT(triggerItem(const QModelIndex&))); connect(m_controller, SIGNAL(activated()), - this, SLOT(requestActivation())); + this, SLOT(activate())); connect(m_controller, SIGNAL(itemEntered(const QModelIndex&)), this, SLOT(showHoverInformation(const QModelIndex&))); connect(m_controller, SIGNAL(viewportEntered()), this, SLOT(clearHoverInformation())); createView(); - - m_iconSize = K3Icon::SizeMedium; - - m_filterBar = new FilterBar(this); - m_filterBar->setVisible(settings->filterBar()); - connect(m_filterBar, SIGNAL(filterChanged(const QString&)), - this, SLOT(changeNameFilter(const QString&))); - connect(m_filterBar, SIGNAL(closeRequest()), - this, SLOT(closeFilterBar())); - - m_topLayout->addWidget(m_urlNavigator); m_topLayout->addWidget(itemView()); - m_topLayout->addWidget(m_filterBar); - m_topLayout->addWidget(m_statusBar); } DolphinView::~DolphinView() { - delete m_dirLister; - m_dirLister = 0; -} - -void DolphinView::setUrl(const KUrl& url) -{ - m_urlNavigator->setUrl(url); - m_controller->setUrl(url); } const KUrl& DolphinView::url() const { - return m_urlNavigator->url(); + return m_controller->url(); } KUrl DolphinView::rootUrl() const @@ -203,9 +128,37 @@ KUrl DolphinView::rootUrl() const return isColumnViewActive() ? m_dirLister->url() : url(); } +void DolphinView::setActive(bool active) +{ + if (active == m_active) { + return; + } + + m_active = active; + + QColor color = KGlobalSettings::baseColor(); + if (active) { + emit urlChanged(url()); + emit selectionChanged(selectedItems()); + } else { + color.setAlpha(0); + } + + QWidget* viewport = itemView()->viewport(); + QPalette palette; + palette.setColor(viewport->backgroundRole(), color); + viewport->setPalette(palette); + + update(); + + if (active) { + emit activated(); + } +} + bool DolphinView::isActive() const { - return m_mainWindow->activeView() == this; + return m_active; } void DolphinView::setMode(Mode mode) @@ -221,14 +174,16 @@ void DolphinView::setMode(Mode mode) // to go back to the root URL of the column view automatically. // Otherwise there it would not be possible to turn off the column view // without focusing the first column. - setUrl(m_dirLister->url()); + // TODO: reactivate again after DolphinView/DolphinViewController split works + //setUrl(m_dirLister->url()); + //m_controller->setUrl(m_dirLister->url()); } - ViewProperties props(m_urlNavigator->url()); + ViewProperties props(url()); props.setViewMode(m_mode); createView(); - startDirLister(m_urlNavigator->url()); + startDirLister(url()); emit modeChanged(); } @@ -240,13 +195,13 @@ DolphinView::Mode DolphinView::mode() const void DolphinView::setShowPreview(bool show) { - ViewProperties props(m_urlNavigator->url()); + ViewProperties props(url()); props.setShowPreview(show); m_controller->setShowPreview(show); emit showPreviewChanged(); - startDirLister(m_urlNavigator->url(), true); + startDirLister(url(), true); } bool DolphinView::showPreview() const @@ -260,13 +215,13 @@ void DolphinView::setShowHiddenFiles(bool show) return; } - ViewProperties props(m_urlNavigator->url()); + ViewProperties props(url()); props.setShowHiddenFiles(show); m_dirLister->setShowingDotFiles(show); emit showHiddenFilesChanged(); - startDirLister(m_urlNavigator->url(), true); + startDirLister(url(), true); } bool DolphinView::showHiddenFiles() const @@ -290,7 +245,7 @@ void DolphinView::setCategorizedSorting(bool categorized) delete categorizer; } - ViewProperties props(m_urlNavigator->url()); + ViewProperties props(url()); props.setCategorizedSorting(categorized); props.save(); @@ -314,7 +269,9 @@ bool DolphinView::supportsCategorizedSorting() const void DolphinView::renameSelectedItems() { - DolphinView* view = mainWindow()->activeView(); + // TODO: temporary deactivate due to DolphinView/DolphinViewController split + + /*DolphinView* view = 0; //mainWindow()->activeView(); const KUrl::List urls = selectedUrls(); if (urls.count() > 1) { // More than one item has been selected for renaming. Open @@ -379,7 +336,7 @@ void DolphinView::renameSelectedItems() newUrl.setFileName(newName); m_mainWindow->rename(oldUrl, newUrl); } - } + }*/ } void DolphinView::selectAll() @@ -392,11 +349,6 @@ void DolphinView::invertSelection() selectAll(QItemSelectionModel::Toggle); } -DolphinStatusBar* DolphinView::statusBar() const -{ - return m_statusBar; -} - int DolphinView::contentsX() const { return itemView()->horizontalScrollBar()->value(); @@ -407,16 +359,6 @@ int DolphinView::contentsY() const return itemView()->verticalScrollBar()->value(); } -bool DolphinView::isFilterBarVisible() const -{ - return m_filterBar->isVisible(); -} - -bool DolphinView::isUrlEditable() const -{ - return m_urlNavigator->isUrlEditable(); -} - void DolphinView::zoomIn() { m_controller->triggerZoomIn(); @@ -463,14 +405,14 @@ Qt::SortOrder DolphinView::sortOrder() const void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info) { - ViewProperties props(m_urlNavigator->url()); + ViewProperties props(url()); props.setAdditionalInfo(info); m_controller->setShowAdditionalInfo(info != KFileItemDelegate::NoInformation); m_fileItemDelegate->setAdditionalInformation(info); emit additionalInfoChanged(info); - startDirLister(m_urlNavigator->url(), true); + startDirLister(url(), true); } KFileItemDelegate::AdditionalInformation DolphinView::additionalInfo() const @@ -478,31 +420,6 @@ KFileItemDelegate::AdditionalInformation DolphinView::additionalInfo() const return m_fileItemDelegate->additionalInformation(); } -void DolphinView::goBack() -{ - m_urlNavigator->goBack(); -} - -void DolphinView::goForward() -{ - m_urlNavigator->goForward(); -} - -void DolphinView::goUp() -{ - m_urlNavigator->goUp(); -} - -void DolphinView::goHome() -{ - m_urlNavigator->goHome(); -} - -void DolphinView::setUrlEditable(bool editable) -{ - m_urlNavigator->setUrlEditable(editable); -} - bool DolphinView::hasSelection() const { return itemView()->selectionModel()->hasSelection(); @@ -571,9 +488,7 @@ void DolphinView::rename(const KUrl& source, const QString& newName) KUrl dest(source.upUrl()); dest.addPath(newName); - const bool destExists = KIO::NetAccess::exists(dest, - false, - mainWindow()->activeView()); + const bool destExists = KIO::NetAccess::exists(dest, false, this); if (destExists) { // the destination already exists, hence ask the user // how to proceed... @@ -607,21 +522,22 @@ void DolphinView::rename(const KUrl& source, const QString& newName) const QString destFileName = dest.fileName(); if (ok) { - m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.", source.fileName(), destFileName), - DolphinStatusBar::OperationCompleted); + // XYDZ + //m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.", source.fileName(), destFileName), + // DolphinStatusBar::OperationCompleted); KonqOperations::rename(this, source, destFileName); } else { - m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName), - DolphinStatusBar::Error); + // XYDZ + //m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName), + // DolphinStatusBar::Error); } } void DolphinView::reload() { - const KUrl& url = m_urlNavigator->url(); - changeDirectory(url); - startDirLister(url, true); + setUrl(url()); + startDirLister(url(), true); } void DolphinView::refresh() @@ -633,20 +549,203 @@ void DolphinView::refresh() void DolphinView::mouseReleaseEvent(QMouseEvent* event) { QWidget::mouseReleaseEvent(event); - mainWindow()->setActiveView(this); + setActive(true);; +} +void DolphinView::activate() +{ + setActive(true); } -DolphinMainWindow* DolphinView::mainWindow() const +void DolphinView::triggerItem(const QModelIndex& index) { - return m_mainWindow; -} - -void DolphinView::changeDirectory(const KUrl& url) -{ - if (!isActive()) { - requestActivation(); + if (!isValidNameIndex(index)) { + clearSelection(); + showHoverInformation(index); + return; } + const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); + if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) { + // items are selected by the user, hence don't trigger the + // item specified by 'index' + return; + } + + KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index)); + if (item == 0) { + return; + } + + // Prefer the local path over the URL. This assures that the + // volume space information is correct. Assuming that the URL is media:/sda1, + // and the local path is /windows/C: For the URL the space info is related + // to the root partition (and hence wrong) and for the local path the space + // info is related to the windows partition (-> correct). + const QString localPath(item->localPath()); + KUrl url; + if (localPath.isEmpty()) { + url = item->url(); + } else { + url = localPath; + } + + if (item->isDir()) { + setUrl(url); + } else if (item->isFile()) { + // allow to browse through ZIP and tar files + KMimeType::Ptr mime = item->mimeTypePtr(); + if (mime->is("application/zip")) { + url.setProtocol("zip"); + setUrl(url); + } else if (mime->is("application/x-tar") || + mime->is("application/x-tarz") || + mime->is("application/x-bzip-compressed-tar") || + mime->is("application/x-compressed-tar") || + mime->is("application/x-tzo")) { + url.setProtocol("tar"); + setUrl(url); + } else { + item->run(); + } + } else { + item->run(); + } +} + +void DolphinView::generatePreviews(const KFileItemList& items) +{ + if (m_controller->showPreview()) { + + // Must turn QList to QList... + QList itemsToPreview; + foreach( KFileItem* it, items ) + itemsToPreview.append( *it ); + + KIO::PreviewJob* job = KIO::filePreview(itemsToPreview, 128); + connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(showPreview(const KFileItem&, const QPixmap&))); + } +} + +void DolphinView::showPreview(const KFileItem& item, const QPixmap& pixmap) +{ + Q_ASSERT(!item.isNull()); + if (item.url().directory() != m_dirLister->url().path()) { + // the preview job is still working on items of an older URL, hence + // the item is not part of the directory model anymore + return; + } + + const QModelIndex idx = m_dirModel->indexForItem(item); + if (idx.isValid() && (idx.column() == 0)) { + const QMimeData* mimeData = QApplication::clipboard()->mimeData(); + if (KonqMimeData::decodeIsCutSelection(mimeData) && isCutItem(item)) { + KIconEffect iconEffect; + const QPixmap cutPixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState); + m_dirModel->setData(idx, QIcon(cutPixmap), Qt::DecorationRole); + } else { + m_dirModel->setData(idx, QIcon(pixmap), Qt::DecorationRole); + } + } +} + +void DolphinView::restoreContentsPos() +{ + m_blockContentsMovedSignal = false; + if (!url().isEmpty()) { + QAbstractItemView* view = itemView(); + // TODO #1: view->setCurrentItem(m_urlNavigator->currentFileName()); + // TODO #2: temporary deactivated due to DolphinView/DolphinViewController split + //QPoint pos = m_urlNavigator->savedPosition(); + QPoint pos(0, 0); + view->horizontalScrollBar()->setValue(pos.x()); + view->verticalScrollBar()->setValue(pos.y()); + } +} + +void DolphinView::emitSelectionChangedSignal() +{ + emit selectionChanged(DolphinView::selectedItems()); +} + +void DolphinView::startDirLister(const KUrl& url, bool reload) +{ + if (!url.isValid()) { + // TODO: temporary deactivated due to DolphinView/DolphinViewController split + + //const QString location(url.pathOrUrl()); + //if (location.isEmpty()) { + // m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error); + //} else { + // m_statusBar->setMessage(i18n("The location '%1' is invalid.", location), + // DolphinStatusBar::Error); + //} + return; + } + + // Only show the directory loading progress if the status bar does + // not contain another progress information. This means that + // the directory loading progress information has the lowest priority. + + // TODO: temporary deactivated due to DolphinView/DolphinViewController split + //const QString progressText(m_statusBar->progressText()); + //m_showProgress = progressText.isEmpty() || + // (progressText == i18n("Loading folder...")); + //if (m_showProgress) { + // m_statusBar->setProgressText(i18n("Loading folder...")); + // m_statusBar->setProgress(0); + //} + + m_cutItemsCache.clear(); + m_blockContentsMovedSignal = true; + m_dirLister->stop(); + + bool openDir = true; + bool keepOldDirs = isColumnViewActive() && !m_initializeColumnView; + m_initializeColumnView = false; + + if (keepOldDirs) { + if (reload) { + keepOldDirs = false; + + const KUrl& dirListerUrl = m_dirLister->url(); + if (dirListerUrl.isValid()) { + const KUrl::List dirs = m_dirLister->directories(); + KUrl url; + foreach(url, dirs) { + m_dirLister->updateDirectory(url); + } + openDir = false; + } + } else if (m_dirLister->directories().contains(url)) { + // The dir lister contains the directory already, so + // KDirLister::openUrl() may not been invoked twice. + m_dirLister->updateDirectory(url); + openDir = false; + } else { + const KUrl& dirListerUrl = m_dirLister->url(); + if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) { + // The current URL is not a child of the dir lister + // URL. This may happen when e. g. a bookmark has been selected + // and hence the view must be reset. + keepOldDirs = false; + } + } + } + + if (openDir) { + m_dirLister->openUrl(url, keepOldDirs, reload); + } +} + +void DolphinView::setUrl(const KUrl& url) +{ + if (m_controller->url() == url) { + return; + } + + m_controller->setUrl(url); + const ViewProperties props(url); const Mode mode = props.viewMode(); @@ -723,324 +822,8 @@ void DolphinView::changeDirectory(const KUrl& url) startDirLister(url); emit urlChanged(url); - m_statusBar->clear(); -} - -void DolphinView::triggerItem(const QModelIndex& index) -{ - if (!isValidNameIndex(index)) { - clearSelection(); - showHoverInformation(index); - return; - } - - const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); - if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) { - // items are selected by the user, hence don't trigger the - // item specified by 'index' - return; - } - - KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index)); - if (item == 0) { - return; - } - - // Prefer the local path over the URL. This assures that the - // volume space information is correct. Assuming that the URL is media:/sda1, - // and the local path is /windows/C: For the URL the space info is related - // to the root partition (and hence wrong) and for the local path the space - // info is related to the windows partition (-> correct). - const QString localPath(item->localPath()); - KUrl url; - if (localPath.isEmpty()) { - url = item->url(); - } else { - url = localPath; - } - - if (item->isDir()) { - setUrl(url); - } else if (item->isFile()) { - // allow to browse through ZIP and tar files - KMimeType::Ptr mime = item->mimeTypePtr(); - if (mime->is("application/zip")) { - url.setProtocol("zip"); - setUrl(url); - } else if (mime->is("application/x-tar") || - mime->is("application/x-tarz") || - mime->is("application/x-bzip-compressed-tar") || - mime->is("application/x-compressed-tar") || - mime->is("application/x-tzo")) { - url.setProtocol("tar"); - setUrl(url); - } else { - item->run(); - } - } else { - item->run(); - } -} - -void DolphinView::updateProgress(int percent) -{ - if (m_showProgress) { - m_statusBar->setProgress(percent); - } -} - -void DolphinView::updateItemCount() -{ - if (m_showProgress) { - m_statusBar->setProgressText(QString()); - m_statusBar->setProgress(100); - m_showProgress = false; - } - - KFileItemList items(m_dirLister->items()); - KFileItemList::const_iterator it = items.begin(); - const KFileItemList::const_iterator end = items.end(); - - m_fileCount = 0; - m_folderCount = 0; - - while (it != end) { - KFileItem* item = *it; - if (item->isDir()) { - ++m_folderCount; - } else { - ++m_fileCount; - } - ++it; - } - - updateStatusBar(); - - m_blockContentsMovedSignal = false; - QTimer::singleShot(0, this, SLOT(restoreContentsPos())); -} - -void DolphinView::generatePreviews(const KFileItemList& items) -{ - if (m_controller->showPreview()) { - - // Must turn QList to QList... - QList itemsToPreview; - foreach( KFileItem* it, items ) - itemsToPreview.append( *it ); - - KIO::PreviewJob* job = KIO::filePreview(itemsToPreview, 128); - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(showPreview(const KFileItem&, const QPixmap&))); - } -} - -void DolphinView::showPreview(const KFileItem& item, const QPixmap& pixmap) -{ - Q_ASSERT(!item.isNull()); - if (item.url().directory() != m_dirLister->url().path()) { - // the preview job is still working on items of an older URL, hence - // the item is not part of the directory model anymore - return; - } - - const QModelIndex idx = m_dirModel->indexForItem(item); - if (idx.isValid() && (idx.column() == 0)) { - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - if (KonqMimeData::decodeIsCutSelection(mimeData) && isCutItem(item)) { - KIconEffect iconEffect; - const QPixmap cutPixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState); - m_dirModel->setData(idx, QIcon(cutPixmap), Qt::DecorationRole); - } else { - m_dirModel->setData(idx, QIcon(pixmap), Qt::DecorationRole); - } - } -} - -void DolphinView::restoreContentsPos() -{ - KUrl currentUrl = m_urlNavigator->url(); - if (!currentUrl.isEmpty()) { - QAbstractItemView* view = itemView(); - // TODO: view->setCurrentItem(m_urlNavigator->currentFileName()); - QPoint pos = m_urlNavigator->savedPosition(); - view->horizontalScrollBar()->setValue(pos.x()); - view->verticalScrollBar()->setValue(pos.y()); - } -} - -void DolphinView::showInfoMessage(const QString& msg) -{ - m_statusBar->setMessage(msg, DolphinStatusBar::Information); -} - -void DolphinView::showErrorMessage(const QString& msg) -{ - m_statusBar->setMessage(msg, DolphinStatusBar::Error); -} - -void DolphinView::emitSelectionChangedSignal() -{ - emit selectionChanged(DolphinView::selectedItems()); -} - -void DolphinView::closeFilterBar() -{ - m_filterBar->hide(); - emit showFilterBarChanged(false); -} - -void DolphinView::startDirLister(const KUrl& url, bool reload) -{ - if (!url.isValid()) { - const QString location(url.pathOrUrl()); - if (location.isEmpty()) { - m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error); - } else { - m_statusBar->setMessage(i18n("The location '%1' is invalid.", location), - DolphinStatusBar::Error); - } - return; - } - - // Only show the directory loading progress if the status bar does - // not contain another progress information. This means that - // the directory loading progress information has the lowest priority. - const QString progressText(m_statusBar->progressText()); - m_showProgress = progressText.isEmpty() || - (progressText == i18n("Loading folder...")); - if (m_showProgress) { - m_statusBar->setProgressText(i18n("Loading folder...")); - m_statusBar->setProgress(0); - } - - m_cutItemsCache.clear(); - m_blockContentsMovedSignal = true; - m_dirLister->stop(); - - bool openDir = true; - bool keepOldDirs = isColumnViewActive() && !m_initializeColumnView; - m_initializeColumnView = false; - - if (keepOldDirs) { - if (reload) { - keepOldDirs = false; - - const KUrl& dirListerUrl = m_dirLister->url(); - if (dirListerUrl.isValid()) { - const KUrl::List dirs = m_dirLister->directories(); - KUrl url; - foreach(url, dirs) { - m_dirLister->updateDirectory(url); - } - openDir = false; - } - } else if (m_dirLister->directories().contains(url)) { - // The dir lister contains the directory already, so - // KDirLister::openUrl() may not been invoked twice. - m_dirLister->updateDirectory(url); - openDir = false; - } else { - const KUrl& dirListerUrl = m_dirLister->url(); - if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) { - // The current URL is not a child of the dir lister - // URL. This may happen when e. g. a bookmark has been selected - // and hence the view must be reset. - keepOldDirs = false; - } - } - } - - if (openDir) { - m_dirLister->openUrl(url, keepOldDirs, reload); - } -} - -QString DolphinView::defaultStatusBarText() const -{ - return KIO::itemsSummaryString(m_fileCount + m_folderCount, - m_fileCount, - m_folderCount, - 0, false); -} - -QString DolphinView::selectionStatusBarText() const -{ - QString text; - const KFileItemList list = selectedItems(); - if (list.isEmpty()) { - // when an item is triggered, it is temporary selected but selectedItems() - // will return an empty list - return QString(); - } - - int fileCount = 0; - int folderCount = 0; - KIO::filesize_t byteSize = 0; - KFileItemList::const_iterator it = list.begin(); - const KFileItemList::const_iterator end = list.end(); - while (it != end) { - KFileItem* item = *it; - if (item->isDir()) { - ++folderCount; - } else { - ++fileCount; - byteSize += item->size(); - } - ++it; - } - - if (folderCount > 0) { - text = i18np("1 Folder selected", "%1 Folders selected", folderCount); - if (fileCount > 0) { - text += ", "; - } - } - - if (fileCount > 0) { - const QString sizeText(KIO::convertSize(byteSize)); - text += i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText); - } - - return text; -} - -void DolphinView::showFilterBar(bool show) -{ - Q_ASSERT(m_filterBar != 0); - if (show) { - m_filterBar->show(); - } else { - m_filterBar->hide(); - } -} - -void DolphinView::updateStatusBar() -{ - // As the item count information is less important - // in comparison with other messages, it should only - // be shown if: - // - the status bar is empty or - // - shows already the item count information or - // - shows only a not very important information - // - if any progress is given don't show the item count info at all - const QString msg(m_statusBar->message()); - const bool updateStatusBarMsg = (msg.isEmpty() || - (msg == m_statusBar->defaultText()) || - (m_statusBar->type() == DolphinStatusBar::Information)) && - (m_statusBar->progress() == 100); - - const QString text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText()); - m_statusBar->setDefaultText(text); - - if (updateStatusBarMsg) { - m_statusBar->setMessage(text, DolphinStatusBar::Default); - } -} - -void DolphinView::requestActivation() -{ - m_mainWindow->setActiveView(this); + // TODO: temporary deactivated due to DolphinView/DolphinViewController split + //m_statusBar->clear(); } void DolphinView::changeSelection(const KFileItemList& selection) @@ -1049,7 +832,7 @@ void DolphinView::changeSelection(const KFileItemList& selection) if (selection.isEmpty()) { return; } - KUrl baseUrl = url(); + const KUrl& baseUrl = url(); KUrl url; QItemSelection new_selection; foreach(KFileItem* item, selection) { @@ -1064,31 +847,6 @@ void DolphinView::changeSelection(const KFileItemList& selection) | QItemSelectionModel::Current); } -void DolphinView::changeNameFilter(const QString& nameFilter) -{ - // The name filter of KDirLister does a 'hard' filtering, which - // means that only the items are shown where the names match - // exactly the filter. This is non-transparent for the user, which - // just wants to have a 'soft' filtering: does the name contain - // the filter string? - QString adjustedFilter(nameFilter); - adjustedFilter.insert(0, '*'); - adjustedFilter.append('*'); - - // Use the ProxyModel to filter: - // This code is #ifdefed as setNameFilter behaves - // slightly different than the QSortFilterProxyModel - // as it will not remove directories. I will ask - // our beloved usability experts for input - // -- z. -#if 0 - m_dirLister->setNameFilter(adjustedFilter); - m_dirLister->emitChanges(); -#else - m_proxyModel->setFilterRegExp(nameFilter); -#endif -} - void DolphinView::openContextMenu(const QPoint& pos) { KFileItem* item = 0; @@ -1098,8 +856,7 @@ void DolphinView::openContextMenu(const QPoint& pos) item = fileItem(index); } - DolphinContextMenu contextMenu(m_mainWindow, item, url()); - contextMenu.open(); + emit requestContextMenu(item, url()); } void DolphinView::dropUrls(const KUrl::List& urls, @@ -1122,15 +879,15 @@ void DolphinView::dropUrls(const KUrl::List& urls, return; } - const KUrl& destination = (directory == 0) ? url() : - directory->url(); + const KUrl& destination = (directory == 0) ? + url() : directory->url(); dropUrls(urls, destination); } void DolphinView::dropUrls(const KUrl::List& urls, const KUrl& destination) { - m_mainWindow->dropUrls(urls, destination); + emit urlsDropped(urls, destination); } void DolphinView::updateSorting(DolphinView::Sorting sorting) @@ -1160,26 +917,6 @@ void DolphinView::emitContentsMoved() } } -void DolphinView::updateActivationState() -{ - m_urlNavigator->setActive(isActive()); - - QColor color = KGlobalSettings::baseColor(); - if (isActive()) { - emit urlChanged(url()); - emit selectionChanged(selectedItems()); - } else { - color.setAlpha(0); - } - - QWidget* viewport = itemView()->viewport(); - QPalette palette; - palette.setColor(viewport->backgroundRole(), color); - viewport->setPalette(palette); - - update(); -} - void DolphinView::updateCutItems() { // restore the icons of all previously selected items to the @@ -1207,14 +944,16 @@ void DolphinView::showHoverInformation(const QModelIndex& index) const KFileItem* item = fileItem(index); if (item != 0) { - m_statusBar->setMessage(item->getStatusBarInfo(), DolphinStatusBar::Default); + // TODO: temporary deactivated due to DolphinView/DolphinViewController split + //m_statusBar->setMessage(item->getStatusBarInfo(), DolphinStatusBar::Default); emit requestItemInfo(item->url()); } } void DolphinView::clearHoverInformation() { - m_statusBar->clear(); + // TODO: temporary deactivated due to DolphinView/DolphinViewController split + //m_statusBar->clear(); emit requestItemInfo(KUrl()); } diff --git a/src/dolphinview.h b/src/dolphinview.h index d26f62dc7d..24c4f60a14 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -19,50 +19,46 @@ ***************************************************************************/ -#ifndef _DOLPHINVIEW_H_ -#define _DOLPHINVIEW_H_ +#ifndef DOLPHINVIEW_H +#define DOLPHINVIEW_H #include #include #include #include -#include - -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include class DolphinController; -class FilterBar; +class KDirLister; class KFileItemDelegate; class KUrl; class KDirModel; -class KUrlNavigator; class DolphinColumnView; class DolphinDetailsView; -class DolphinDirLister; class DolphinIconsView; class DolphinMainWindow; class DolphinSortFilterProxyModel; -class DolphinStatusBar; class QModelIndex; class ViewProperties; /** - * @short Represents a view for the directory content - * including the navigation bar, filter bar and status bar. + * @short Represents a view for the directory content. * - * View modes for icons, details and columns are supported. Currently - * Dolphin allows to have up to two views inside the main window. + * View modes for icons, details and columns are supported. It's + * possible to adjust: + * - sort order + * - sort type + * - show hidden files + * - show previews * * @see DolphinIconsView * @see DolphinDetailsView * @see DolphinColumnView - * @see KUrlNavigator - * @see DolphinStatusBar */ class DolphinView : public QWidget { @@ -109,23 +105,29 @@ public: MaxSortEnum = SortByType }; - DolphinView(DolphinMainWindow* mainwindow, - QWidget *parent, + /** + * @param parent Parent widget of the view. + * @param url Specifies the content which should be shown. + * @param dirLister Used directory lister. The lister is not owned + * by the view and won't get deleted. + * @param dirModel Used directory model. The model is not owned + * by the view and won't get deleted. + * @param proxyModel Used proxy model which specifies the sorting. The + * model is not owned by the view and won't get + * deleted. + * @param mode Used display mode (IconsView, DetailsView or ColumnsView). + * @param showHiddenFiles If true, hidden files will be shown in the view. + */ + DolphinView(QWidget* parent, const KUrl& url, + KDirLister* dirLister, + KDirModel* dirModel, + DolphinSortFilterProxyModel* proxyModel, Mode mode = IconsView, bool showHiddenFiles = false); virtual ~DolphinView(); - /** - * Sets the current active URL, where all actions are applied. The - * URL navigator is synchronized with this URL. The signals - * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged() - * are emitted. - * @see DolphinView::urlNavigator() - */ - void setUrl(const KUrl& url); - /** * Returns the current active URL, where all actions are applied. * The URL navigator is synchronized with this URL. @@ -144,9 +146,10 @@ public: KUrl rootUrl() const; /** - * Returns true if the view is active and hence all actions are - * applied to this view. + * If \a active is true, the view will marked as active. The active + * view is defined as view where all actions are applied to. */ + void setActive(bool active); bool isActive() const; /** @@ -215,40 +218,6 @@ public: */ void invertSelection(); - /** - * Goes back one step in the URL history. The signals - * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged() - * are submitted. - */ - void goBack(); - - /** - * Goes forward one step in the Url history. The signals - * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged() - * are submitted. - */ - void goForward(); - - /** - * Goes up one step of the Url path. The signals - * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged() - * are submitted. - */ - void goUp(); - - /** - * Goes to the home URL. The signals KUrlNavigator::urlChanged() - * and KUrlNavigator::historyChanged() are submitted. - */ - void goHome(); - - /** - * Sets the URL of the navigation bar to an editable state - * if \a editable is true. If \a editable is false, each part of - * the location is presented by a button for a fast navigation. - */ - void setUrlEditable(bool editable); - /** Returns true, if at least one item is selected. */ bool hasSelection() const; @@ -280,8 +249,6 @@ public: */ void rename(const KUrl& source, const QString& newName); - DolphinStatusBar* statusBar() const; - /** * Returns the x-position of the view content. * The content of the view might be larger than the visible area @@ -296,12 +263,6 @@ public: */ int contentsY() const; - /** - * Returns true, if the URL shown by the navigation bar is editable. - * @see KUrlNavigator - */ - bool isUrlEditable() const; - /** Increases the size of the current set view mode. */ void zoomIn(); @@ -338,21 +299,6 @@ public: /** Returns the additional information which should be shown for the items. */ KFileItemDelegate::AdditionalInformation additionalInfo() const; - /** Returns the KUrlNavigator of the view for read access. */ - const KUrlNavigator* urlNavigator() const - { - return m_urlNavigator; - } - - /** Returns true, if the filter bar is visible. */ - bool isFilterBarVisible() const; - - /** - * Return the DolphinMainWindow this View belongs to. It is guranteed - * that we have one. - */ - DolphinMainWindow* mainWindow() const ; - /** Reloads the current directory. */ void reload(); @@ -365,22 +311,10 @@ public: public slots: /** - * Popups the filter bar above the status bar if \a show is true. + * Changes the directory to \a url. If the current directory is equal to + * \a url, nothing will be done (use DolphinView::reload() instead). */ - void showFilterBar(bool show); - - /** - * Updates the number of items (= number of files + number of - * directories) in the statusbar. If files are selected, the number - * of selected files and the sum of the filesize is shown. - */ - void updateStatusBar(); - - /** - * Requests the main window to set this view as active view, which - * means that all actions are applied to this view. - */ - void requestActivation(); + void setUrl(const KUrl& url); /** * Request of a selection change. The view will do its best to accommodate @@ -391,6 +325,11 @@ public slots: void changeSelection(const KFileItemList& selection); signals: + /** + * Is emitted if the view has been activated by e. g. a mouse click. + */ + void activated(); + /** Is emitted if URL of the view has been changed to \a url. */ void urlChanged(const KUrl& url); @@ -437,20 +376,38 @@ signals: */ void showFilterBarChanged(bool shown); + /** + * Is emitted if a context menu is requested for the item \a item, + * which is part of \a url. If the item is 0, the context menu + * for the URL should be shown. + */ + void requestContextMenu(KFileItem* item, const KUrl& url); + + /** + * Is emitted if the URLs \a are dropped to the destination URL + * \a destination. No operation is done within the DolphinView, the + * receiver of the signal has to take care about the corresponding + * operation. + */ + void urlsDropped(const KUrl::List& urls, const KUrl& destination); + protected: /** @see QWidget::mouseReleaseEvent */ virtual void mouseReleaseEvent(QMouseEvent* event); private slots: - void changeDirectory(const KUrl& url); - void triggerItem(const QModelIndex& index); - void updateProgress(int percent); + /** + * Marks the view as active (DolphinView:isActive() will return true) + * and emits the 'activated' signal if it is not already active. + */ + void activate(); /** - * Updates the number of items (= number of directories + number of files) - * and shows this information in the statusbar. + * If the item specified by \a index is a directory, then this + * directory will be loaded. If the item is a file, the corresponding + * application will get started. */ - void updateItemCount(); + void triggerItem(const QModelIndex& index); /** * Generates a preview image for each file item in \a items. @@ -471,20 +428,7 @@ private slots: */ void restoreContentsPos(); - /** Shows the information \a msg inside the statusbar. */ - void showInfoMessage(const QString& msg); - - /** Shows the error message \a msg inside the statusbar. */ - void showErrorMessage(const QString& msg); - void emitSelectionChangedSignal(); - void closeFilterBar(); - - /** - * Filters the currently shown items by \a nameFilter. All items - * which contain the given filter string will be shown. - */ - void changeNameFilter(const QString& nameFilter); /** * Opens the context menu on position \a pos. The position @@ -525,12 +469,6 @@ private slots: */ void emitContentsMoved(); - /** - * Updates the activation state of the view by checking whether - * the currently active view is this view. - */ - void updateActivationState(); - /** Applies an item effect to all cut items of the clipboard. */ void updateCutItems(); @@ -551,18 +489,6 @@ private slots: private: void startDirLister(const KUrl& url, bool reload = false); - /** - * Returns the default text of the status bar, if no item is - * selected. - */ - QString defaultStatusBarText() const; - - /** - * Returns the text for the status bar, if at least one item - * is selected. - */ - QString selectionStatusBarText() const; - /** * Creates a new view representing the given view mode (DolphinView::mode()). * The current view will get deleted. @@ -617,18 +543,13 @@ private: QPixmap pixmap; }; - bool m_showProgress; + bool m_active; bool m_blockContentsMovedSignal; bool m_initializeColumnView; Mode m_mode; - int m_iconSize; - int m_folderCount; - int m_fileCount; - DolphinMainWindow* m_mainWindow; QVBoxLayout* m_topLayout; - KUrlNavigator* m_urlNavigator; DolphinController* m_controller; DolphinIconsView* m_iconsView; @@ -636,14 +557,11 @@ private: DolphinColumnView* m_columnView; KFileItemDelegate* m_fileItemDelegate; - FilterBar* m_filterBar; - DolphinStatusBar* m_statusBar; - KDirModel* m_dirModel; - DolphinDirLister* m_dirLister; + KDirLister* m_dirLister; DolphinSortFilterProxyModel* m_proxyModel; QList m_cutItemsCache; }; -#endif // _DOLPHINVIEW_H_ +#endif // DOLPHINVIEW_H diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp new file mode 100644 index 0000000000..0b2812a7ce --- /dev/null +++ b/src/dolphinviewcontainer.cpp @@ -0,0 +1,503 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz * + * * + * 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 "dolphinviewcontainer.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dolphincolumnview.h" +#include "dolphincontroller.h" +#include "dolphinstatusbar.h" +#include "dolphinmainwindow.h" +#include "dolphindirlister.h" +#include "dolphinsortfilterproxymodel.h" +#include "dolphindetailsview.h" +#include "dolphiniconsview.h" +#include "dolphincontextmenu.h" +#include "dolphinitemcategorizer.h" +#include "filterbar.h" +#include "renamedialog.h" +#include "kurlnavigator.h" +#include "viewproperties.h" +#include "dolphinsettings.h" +#include "dolphin_generalsettings.h" + +DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, + QWidget* parent, + const KUrl& url, + DolphinView::Mode mode, + bool showHiddenFiles) : + QWidget(parent), + m_showProgress(false), + m_folderCount(0), + m_fileCount(0), + m_mainWindow(mainWindow), + m_topLayout(0), + m_urlNavigator(0), + m_view(0), + m_filterBar(0), + m_statusBar(0), + m_dirModel(0), + m_dirLister(0), + m_proxyModel(0) +{ + hide(); + setFocusPolicy(Qt::StrongFocus); + m_topLayout = new QVBoxLayout(this); + m_topLayout->setSpacing(0); + m_topLayout->setMargin(0); + + connect(m_mainWindow, SIGNAL(activeViewChanged()), + this, SLOT(updateActivationState())); + + QClipboard* clipboard = QApplication::clipboard(); + connect(clipboard, SIGNAL(dataChanged()), + this, SLOT(updateCutItems())); + + m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this); + + const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + m_urlNavigator->setUrlEditable(settings->editableUrl()); + m_urlNavigator->setHomeUrl(settings->homeUrl()); + + m_dirLister = new DolphinDirLister(); + m_dirLister->setAutoUpdate(true); + m_dirLister->setMainWindow(this); + m_dirLister->setShowingDotFiles(showHiddenFiles); + m_dirLister->setDelayedMimeTypes(true); + + m_dirModel = new KDirModel(); + m_dirModel->setDirLister(m_dirLister); + m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory); + + m_proxyModel = new DolphinSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_dirModel); + + connect(m_dirLister, SIGNAL(clear()), + this, SLOT(updateStatusBar())); + connect(m_dirLister, SIGNAL(percent(int)), + this, SLOT(updateProgress(int))); + connect(m_dirLister, SIGNAL(deleteItem(KFileItem*)), + this, SLOT(updateStatusBar())); + connect(m_dirLister, SIGNAL(completed()), + this, SLOT(updateItemCount())); + connect(m_dirLister, SIGNAL(completed()), + this, SLOT(updateCutItems())); + connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), + this, SLOT(generatePreviews(const KFileItemList&))); + connect(m_dirLister, SIGNAL(infoMessage(const QString&)), + this, SLOT(showInfoMessage(const QString&))); + connect(m_dirLister, SIGNAL(errorMessage(const QString&)), + this, SLOT(showErrorMessage(const QString&))); + + m_view = new DolphinView(this, + url, + m_dirLister, + m_dirModel, + m_proxyModel, + mode, + showHiddenFiles); + connect(m_view, SIGNAL(urlChanged(const KUrl&)), + m_urlNavigator, SLOT(setUrl(const KUrl&))); + connect(m_view, SIGNAL(requestContextMenu(KFileItem*, const KUrl&)), + this, SLOT(openContextMenu(KFileItem*, const KUrl&))); + connect(m_view, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)), + m_mainWindow, SLOT(dropUrls(const KUrl::List&, const KUrl&))); + + connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), + m_view, SLOT(setUrl(const KUrl&))); + + m_statusBar = new DolphinStatusBar(this, url); + + m_filterBar = new FilterBar(this); + m_filterBar->setVisible(settings->filterBar()); + connect(m_filterBar, SIGNAL(filterChanged(const QString&)), + this, SLOT(changeNameFilter(const QString&))); + connect(m_filterBar, SIGNAL(closeRequest()), + this, SLOT(closeFilterBar())); + + m_topLayout->addWidget(m_urlNavigator); + m_topLayout->addWidget(m_view); + m_topLayout->addWidget(m_filterBar); + m_topLayout->addWidget(m_statusBar); +} + +DolphinViewContainer::~DolphinViewContainer() +{ + delete m_dirLister; + m_dirLister = 0; +} + +void DolphinViewContainer::setUrl(const KUrl& url) +{ + m_urlNavigator->setUrl(url); +} + +const KUrl& DolphinViewContainer::url() const +{ + return m_urlNavigator->url(); +} + +void DolphinViewContainer::setActive(bool active) +{ + m_urlNavigator->setActive(active); + m_view->setActive(active); +} + +bool DolphinViewContainer::isActive() const +{ + Q_ASSERT(m_view->isActive() == m_urlNavigator->isActive()); + return m_view->isActive(); +} + +void DolphinViewContainer::renameSelectedItems() +{ + DolphinViewContainer* view = m_mainWindow->activeViewContainer(); + const KUrl::List urls = m_view->selectedUrls(); + if (urls.count() > 1) { + // More than one item has been selected for renaming. Open + // a rename dialog and rename all items afterwards. + RenameDialog dialog(urls); + if (dialog.exec() == QDialog::Rejected) { + return; + } + + const QString& newName = dialog.newName(); + if (newName.isEmpty()) { + view->statusBar()->setMessage(dialog.errorString(), + DolphinStatusBar::Error); + } else { + // TODO: check how this can be integrated into KonqUndoManager/KonqOperations + // as one operation instead of n rename operations like it is done now... + Q_ASSERT(newName.contains('#')); + + // iterate through all selected items and rename them... + const int replaceIndex = newName.indexOf('#'); + Q_ASSERT(replaceIndex >= 0); + int index = 1; + + KUrl::List::const_iterator it = urls.begin(); + KUrl::List::const_iterator end = urls.end(); + while (it != end) { + const KUrl& oldUrl = *it; + QString number; + number.setNum(index++); + + QString name(newName); + name.replace(replaceIndex, 1, number); + + if (oldUrl.fileName() != name) { + KUrl newUrl = oldUrl; + newUrl.setFileName(name); + m_mainWindow->rename(oldUrl, newUrl); + } + ++it; + } + } + } else { + // Only one item has been selected for renaming. Use the custom + // renaming mechanism from the views. + Q_ASSERT(urls.count() == 1); + + // TODO: Think about using KFileItemDelegate as soon as it supports editing. + // Currently the RenameDialog is used, but I'm not sure whether inline renaming + // is a benefit for the user at all -> let's wait for some input first... + RenameDialog dialog(urls); + if (dialog.exec() == QDialog::Rejected) { + return; + } + + const QString& newName = dialog.newName(); + if (newName.isEmpty()) { + view->statusBar()->setMessage(dialog.errorString(), + DolphinStatusBar::Error); + } else { + const KUrl& oldUrl = urls.first(); + KUrl newUrl = oldUrl; + newUrl.setFileName(newName); + m_mainWindow->rename(oldUrl, newUrl); + } + } +} + +DolphinStatusBar* DolphinViewContainer::statusBar() const +{ + return m_statusBar; +} + +bool DolphinViewContainer::isFilterBarVisible() const +{ + return m_filterBar->isVisible(); +} + +bool DolphinViewContainer::isUrlEditable() const +{ + return m_urlNavigator->isUrlEditable(); +} + +KFileItem* DolphinViewContainer::fileItem(const QModelIndex index) const +{ + const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index); + return m_dirModel->itemForIndex(dirModelIndex); +} + +void DolphinViewContainer::rename(const KUrl& source, const QString& newName) +{ + bool ok = false; + + if (newName.isEmpty() || (source.fileName() == newName)) { + return; + } + + KUrl dest(source.upUrl()); + dest.addPath(newName); + + const bool destExists = KIO::NetAccess::exists(dest, false, this); + if (destExists) { + // the destination already exists, hence ask the user + // how to proceed... + KIO::RenameDialog renameDialog(this, + i18n("File Already Exists"), + source.path(), + dest.path(), + KIO::M_OVERWRITE); + switch (renameDialog.exec()) { + case KIO::R_OVERWRITE: + // the destination should be overwritten + ok = KIO::NetAccess::file_move(source, dest, -1, true); + break; + + case KIO::R_RENAME: { + // a new name for the destination has been used + KUrl newDest(renameDialog.newDestUrl()); + ok = KIO::NetAccess::file_move(source, newDest); + break; + } + + default: + // the renaming operation has been canceled + return; + } + } else { + // no destination exists, hence just move the file to + // do the renaming + ok = KIO::NetAccess::file_move(source, dest); + } + + const QString destFileName = dest.fileName(); + if (ok) { + m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.", source.fileName(), destFileName), + DolphinStatusBar::OperationCompleted); + + KonqOperations::rename(this, source, destFileName); + } else { + m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName), + DolphinStatusBar::Error); + } +} + +DolphinMainWindow* DolphinViewContainer::mainWindow() const +{ + return m_mainWindow; +} + +void DolphinViewContainer::updateProgress(int percent) +{ + if (m_showProgress) { + m_statusBar->setProgress(percent); + } +} + +void DolphinViewContainer::updateItemCount() +{ + if (m_showProgress) { + m_statusBar->setProgressText(QString()); + m_statusBar->setProgress(100); + m_showProgress = false; + } + + KFileItemList items(m_dirLister->items()); + KFileItemList::const_iterator it = items.begin(); + const KFileItemList::const_iterator end = items.end(); + + m_fileCount = 0; + m_folderCount = 0; + + while (it != end) { + KFileItem* item = *it; + if (item->isDir()) { + ++m_folderCount; + } else { + ++m_fileCount; + } + ++it; + } + + updateStatusBar(); + + QTimer::singleShot(0, this, SLOT(restoreContentsPos())); +} + +void DolphinViewContainer::showInfoMessage(const QString& msg) +{ + m_statusBar->setMessage(msg, DolphinStatusBar::Information); +} + +void DolphinViewContainer::showErrorMessage(const QString& msg) +{ + m_statusBar->setMessage(msg, DolphinStatusBar::Error); +} + +void DolphinViewContainer::closeFilterBar() +{ + m_filterBar->hide(); + emit showFilterBarChanged(false); +} + +QString DolphinViewContainer::defaultStatusBarText() const +{ + return KIO::itemsSummaryString(m_fileCount + m_folderCount, + m_fileCount, + m_folderCount, + 0, false); +} + +QString DolphinViewContainer::selectionStatusBarText() const +{ + QString text; + const KFileItemList list = m_view->selectedItems(); + if (list.isEmpty()) { + // when an item is triggered, it is temporary selected but selectedItems() + // will return an empty list + return QString(); + } + + int fileCount = 0; + int folderCount = 0; + KIO::filesize_t byteSize = 0; + KFileItemList::const_iterator it = list.begin(); + const KFileItemList::const_iterator end = list.end(); + while (it != end) { + KFileItem* item = *it; + if (item->isDir()) { + ++folderCount; + } else { + ++fileCount; + byteSize += item->size(); + } + ++it; + } + + if (folderCount > 0) { + text = i18np("1 Folder selected", "%1 Folders selected", folderCount); + if (fileCount > 0) { + text += ", "; + } + } + + if (fileCount > 0) { + const QString sizeText(KIO::convertSize(byteSize)); + text += i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText); + } + + return text; +} + +void DolphinViewContainer::showFilterBar(bool show) +{ + Q_ASSERT(m_filterBar != 0); + m_filterBar->setVisible(show); +} + +void DolphinViewContainer::updateStatusBar() +{ + // As the item count information is less important + // in comparison with other messages, it should only + // be shown if: + // - the status bar is empty or + // - shows already the item count information or + // - shows only a not very important information + // - if any progress is given don't show the item count info at all + const QString msg(m_statusBar->message()); + const bool updateStatusBarMsg = (msg.isEmpty() || + (msg == m_statusBar->defaultText()) || + (m_statusBar->type() == DolphinStatusBar::Information)) && + (m_statusBar->progress() == 100); + + const QString text(m_view->hasSelection() ? selectionStatusBarText() : defaultStatusBarText()); + m_statusBar->setDefaultText(text); + + if (updateStatusBarMsg) { + m_statusBar->setMessage(text, DolphinStatusBar::Default); + } +} + +void DolphinViewContainer::changeNameFilter(const QString& nameFilter) +{ + // The name filter of KDirLister does a 'hard' filtering, which + // means that only the items are shown where the names match + // exactly the filter. This is non-transparent for the user, which + // just wants to have a 'soft' filtering: does the name contain + // the filter string? + QString adjustedFilter(nameFilter); + adjustedFilter.insert(0, '*'); + adjustedFilter.append('*'); + + // Use the ProxyModel to filter: + // This code is #ifdefed as setNameFilter behaves + // slightly different than the QSortFilterProxyModel + // as it will not remove directories. I will ask + // our beloved usability experts for input + // -- z. +#if 0 + m_dirLister->setNameFilter(adjustedFilter); + m_dirLister->emitChanges(); +#else + m_proxyModel->setFilterRegExp(nameFilter); +#endif +} + +void DolphinViewContainer::openContextMenu(KFileItem* item, + const KUrl& url) +{ + DolphinContextMenu contextMenu(m_mainWindow, item, url); + contextMenu.open(); +} + +#include "dolphinviewcontainer.moc" diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h new file mode 100644 index 0000000000..5652e4b4a6 --- /dev/null +++ b/src/dolphinviewcontainer.h @@ -0,0 +1,232 @@ +/*************************************************************************** + * Copyright (C) 2007 by Peter Penz * + * * + * 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 DOLPHINVIEWCONTAINER_H +#define DOLPHINVIEWCONTAINER_H + +#include "dolphinview.h" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +class DolphinController; +class FilterBar; +class KFileItemDelegate; +class KUrl; +class KDirModel; +class KUrlNavigator; +class DolphinColumnView; +class DolphinDetailsView; +class DolphinDirLister; +class DolphinIconsView; +class DolphinMainWindow; +class DolphinSortFilterProxyModel; +class DolphinStatusBar; +class QModelIndex; +class ViewProperties; + +/** + * @short Represents a view for the directory content + * including the navigation bar, filter bar and status bar. + * + * View modes for icons, details and columns are supported. Currently + * Dolphin allows to have up to two views inside the main window. + * + * @see DolphinView + * @see FilterBar + * @see KUrlNavigator + * @see DolphinStatusBar + */ +class DolphinViewContainer : public QWidget +{ + Q_OBJECT + +public: + DolphinViewContainer(DolphinMainWindow* mainwindow, + QWidget *parent, + const KUrl& url, + DolphinView::Mode mode = DolphinView::IconsView, + bool showHiddenFiles = false); + + virtual ~DolphinViewContainer(); + + /** + * Sets the current active URL, where all actions are applied. The + * URL navigator is synchronized with this URL. The signals + * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged() + * are emitted. + * @see DolphinViewContainer::urlNavigator() + */ + void setUrl(const KUrl& url); + + /** + * Returns the current active URL, where all actions are applied. + * The URL navigator is synchronized with this URL. + */ + const KUrl& url() const; + + /** + * If \a active is true, the view container will marked as active. The active + * view container is defined as view where all actions are applied to. + */ + void setActive(bool active); + bool isActive() const; + + /** + * Triggers the renaming of the currently selected items, where + * the user must input a new name for the items. + */ + void renameSelectedItems(); + + KFileItem* fileItem(const QModelIndex index) const; + + /** + * Renames the filename of the source URL by the new file name. + * If the new file name already exists, a dialog is opened which + * asks the user to enter a new name. + */ + void rename(const KUrl& source, const QString& newName); + + DolphinStatusBar* statusBar() const; + + /** + * Returns true, if the URL shown by the navigation bar is editable. + * @see KUrlNavigator + */ + bool isUrlEditable() const; + + inline KUrlNavigator* urlNavigator() const; + + inline DolphinView* view() const; + + /** Returns true, if the filter bar is visible. */ + bool isFilterBarVisible() const; + + /** + * Return the DolphinMainWindow this View belongs to. It is guaranteed + * that we have one. + */ + DolphinMainWindow* mainWindow() const ; + +public slots: + /** + * Popups the filter bar above the status bar if \a show is true. + */ + void showFilterBar(bool show); + + /** + * Updates the number of items (= number of files + number of + * directories) in the statusbar. If files are selected, the number + * of selected files and the sum of the filesize is shown. + */ + void updateStatusBar(); + +signals: + /** + * Is emitted whenever the filter bar has changed its visibility state. + */ + void showFilterBarChanged(bool shown); + +private slots: + void updateProgress(int percent); + + /** + * Updates the number of items (= number of directories + number of files) + * and shows this information in the statusbar. + */ + void updateItemCount(); + + /** Shows the information \a msg inside the statusbar. */ + void showInfoMessage(const QString& msg); + + /** Shows the error message \a msg inside the statusbar. */ + void showErrorMessage(const QString& msg); + + void closeFilterBar(); + + /** + * Filters the currently shown items by \a nameFilter. All items + * which contain the given filter string will be shown. + */ + void changeNameFilter(const QString& nameFilter); + + /** + * Opens the context menu on the current mouse postition. + * @item File item context. If item is 0, the context menu + * should be applied to \a url. + * @url URL which contains \a item. + */ + void openContextMenu(KFileItem* item, const KUrl& url); + +private: + /** + * Returns the default text of the status bar, if no item is + * selected. + */ + QString defaultStatusBarText() const; + + /** + * Returns the text for the status bar, if at least one item + * is selected. + */ + QString selectionStatusBarText() const; + +private: + bool m_showProgress; + + int m_iconSize; + int m_folderCount; + int m_fileCount; + + DolphinMainWindow* m_mainWindow; + QVBoxLayout* m_topLayout; + KUrlNavigator* m_urlNavigator; + + DolphinView* m_view; + + FilterBar* m_filterBar; + DolphinStatusBar* m_statusBar; + + KDirModel* m_dirModel; + DolphinDirLister* m_dirLister; + DolphinSortFilterProxyModel* m_proxyModel; +}; + +KUrlNavigator* DolphinViewContainer::urlNavigator() const +{ + return m_urlNavigator; +} + +DolphinView* DolphinViewContainer::view() const +{ + return m_view; +} + +#endif // DOLPHINVIEWCONTAINER_H diff --git a/src/generalsettingspage.cpp b/src/generalsettingspage.cpp index e862cf5f32..ccb06cd09c 100644 --- a/src/generalsettingspage.cpp +++ b/src/generalsettingspage.cpp @@ -20,23 +20,24 @@ #include "generalsettingspage.h" +#include "dolphinsettings.h" +#include "dolphinmainwindow.h" +#include "dolphinview.h" +#include "dolphinviewcontainer.h" + +#include "dolphin_generalsettings.h" + #include #include #include #include -#include -#include -#include -#include -#include -#include - -#include "dolphinsettings.h" -#include "dolphinmainwindow.h" -#include "dolphinview.h" - -#include "dolphin_generalsettings.h" +#include +#include +#include +#include +#include +#include GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) : SettingsPageBase(parent), @@ -180,7 +181,7 @@ void GeneralSettingsPage::selectHomeUrl() void GeneralSettingsPage::useCurrentLocation() { - const DolphinView* view = m_mainWindow->activeView(); + const DolphinView* view = m_mainWindow->activeViewContainer()->view(); m_homeUrl->setText(view->url().prettyUrl()); } diff --git a/src/generalviewsettingspage.cpp b/src/generalviewsettingspage.cpp index 48b9b653be..6b484f1200 100644 --- a/src/generalviewsettingspage.cpp +++ b/src/generalviewsettingspage.cpp @@ -20,15 +20,17 @@ #include "generalviewsettingspage.h" #include "dolphinmainwindow.h" #include "dolphinsettings.h" -#include "dolphin_generalsettings.h" +#include "dolphinviewcontainer.h" #include "viewproperties.h" -#include -#include -#include -#include -#include -#include +#include "dolphin_generalsettings.h" + +#include +#include +#include +#include +#include +#include #include #include @@ -100,7 +102,7 @@ GeneralViewSettingsPage::~GeneralViewSettingsPage() void GeneralViewSettingsPage::applySettings() { - const KUrl& url = m_mainWindow->activeView()->url(); + const KUrl& url = m_mainWindow->activeViewContainer()->url(); ViewProperties props(url); // read current view properties const bool useGlobalProps = m_globalProps->isChecked();