From: David Faure Date: Mon, 11 Feb 2008 12:44:46 +0000 (+0000) Subject: Forwardport 773570: X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/846b21edf57e7aeb83e84ee68e9f61c5981fbacd?hp=-c Forwardport 773570: Factorize all the view-related action handling to DolphinViewActionHandler, to remove code duplication between mainwindow and part, and to remove my code-splitting with the static createFooAction methods in the view. svn path=/trunk/KDE/kdebase/apps/; revision=773572 --- 846b21edf57e7aeb83e84ee68e9f61c5981fbacd diff --combined src/CMakeLists.txt index deb1b3bb6,b2cdfd582..f5a6c3ed9 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@@ -2,8 -2,6 +2,8 @@@ add_subdirectory( pics ) add_subdirectory( tests ) +macro_optional_find_package(Soprano) + include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ${BLITZ_INCLUDES} ) if (Soprano_FOUND) include_directories( ${SOPRANO_INCLUDE_DIR} ) @@@ -17,19 -15,19 +17,20 @@@ set(dolphinprivate_LIB_SRC dolphiniconsview.cpp dolphincolumnview.cpp dolphincolumnwidget.cpp + dolphindropcontroller.cpp + dolphinsortfilterproxymodel.cpp draganddrophelper.cpp - kcategorizedview.cpp - kcategorydrawer.cpp dolphinmodel.cpp dolphinsettings.cpp dolphincategorydrawer.cpp - viewproperties.cpp - dolphinsortfilterproxymodel.cpp - renamedialog.cpp dolphinview.cpp + dolphinviewactionhandler.cpp + iconmanager.cpp ratingpainter.cpp - dolphindropcontroller.cpp + renamedialog.cpp + selectiontoggle.cpp + selectionmanager.cpp + viewproperties.cpp ) kde4_add_kcfg_files(dolphinprivate_LIB_SRCS @@@ -90,7 -88,6 +91,7 @@@ set(dolphin_SRC dolphinstatusbar.cpp dolphindirlister.cpp dolphincontextmenu.cpp + dolphinfileplacesview.cpp dolphinsettingsdialog.cpp draganddrophelper.cpp filterbar.cpp @@@ -104,7 -101,6 +105,7 @@@ pixmapviewer.cpp settingspagebase.cpp sidebarpage.cpp + startupsettingspage.cpp statusbarspaceinfo.cpp statusbarmessagelabel.cpp terminalsidebarpage.cpp diff --combined src/dolphinmainwindow.cpp index afabdf983,c1d6cef39..160c423ec --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@@ -20,12 -20,12 +20,13 @@@ ***************************************************************************/ #include "dolphinmainwindow.h" + #include "dolphinviewactionhandler.h" #include "dolphindropcontroller.h" #include #include "dolphinapplication.h" +#include "dolphinfileplacesview.h" #include "dolphinnewmenu.h" #include "dolphinsettings.h" #include "dolphinsettingsdialog.h" @@@ -36,8 -36,11 +37,8 @@@ #include "mainwindowadaptor.h" #include "terminalsidebarpage.h" #include "treeviewsidebarpage.h" -#include "kurlnavigator.h" #include "viewpropertiesdialog.h" #include "viewproperties.h" -#include "kfileplacesmodel.h" -#include "kfileplacesview.h" #include "dolphin_generalsettings.h" #include "dolphin_iconsmodesettings.h" @@@ -48,7 -51,6 +49,7 @@@ #include #include #include +#include #include #include #include @@@ -58,9 -60,7 +59,8 @@@ #include #include #include +#include #include - #include #include #include #include @@@ -182,28 -182,6 +182,6 @@@ void DolphinMainWindow::slotViewModeCha updateViewActions(); } - void DolphinMainWindow::slotShowPreviewChanged() - { - // It is not enough to update the 'Show Preview' action, also - // the 'Zoom In' and 'Zoom Out' actions must be adapted. - updateViewActions(); - } - - void DolphinMainWindow::slotShowHiddenFilesChanged() - { - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - const DolphinView* view = m_activeViewContainer->view(); - showHiddenFilesAction->setChecked(view->showHiddenFiles()); - } - - void DolphinMainWindow::slotCategorizedSortingChanged() - { - QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); - const DolphinView* view = m_activeViewContainer->view(); - showInGroupsAction->setChecked(view->categorizedSorting()); - showInGroupsAction->setEnabled(view->supportsCategorizedSorting()); - } - void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) { QAction* action = 0; @@@ -246,26 -224,6 +224,13 @@@ } } - void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) - { - QAction* descending = actionCollection()->action("descending"); - const bool sortDescending = (order == Qt::DescendingOrder); - descending->setChecked(sortDescending); - } - - void DolphinMainWindow::slotAdditionalInfoChanged() - { - DolphinView* view = m_activeViewContainer->view(); - view->updateAdditionalInfoActions(actionCollection()); - } - +void DolphinMainWindow::slotEditableStateChanged(bool editable) +{ + KToggleAction* editableLocationAction = + static_cast(actionCollection()->action("editable_location")); + editableLocationAction->setChecked(editable); +} + void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) { updateEditActions(); @@@ -378,43 -336,12 +343,12 @@@ void DolphinMainWindow::readProperties( } } - void DolphinMainWindow::createDir() - { - const KUrl& url = m_activeViewContainer->view()->url(); - KonqOperations::newDir(this, url); - } - void DolphinMainWindow::updateNewMenu() { m_newMenu->slotCheckUpToDate(); m_newMenu->setPopupFiles(activeViewContainer()->url()); } - void DolphinMainWindow::rename() - { - clearStatusBar(); - m_activeViewContainer->view()->renameSelectedItems(); - } - - void DolphinMainWindow::moveToTrash() - { - clearStatusBar(); - - DolphinView* view = m_activeViewContainer->view(); - - if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { - view->deleteSelectedItems(); - } else { - view->trashSelectedItems(); - } - } - - void DolphinMainWindow::deleteItems() - { - clearStatusBar(); - m_activeViewContainer->view()->deleteSelectedItems(); - } - void DolphinMainWindow::properties() { const KFileItemList list = m_activeViewContainer->view()->selectedItems(); @@@ -441,7 -368,7 +375,7 @@@ void DolphinMainWindow::slotHandlePlace void DolphinMainWindow::slotUndoAvailable(bool available) { - QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo)); + QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); if (undoAction != 0) { undoAction->setEnabled(available); } @@@ -485,7 -412,7 +419,7 @@@ void DolphinMainWindow::slotUndoTextChanged(const QString& text) { - QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo)); + QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); if (undoAction != 0) { undoAction->setText(text); } @@@ -514,7 -441,7 +448,7 @@@ void DolphinMainWindow::paste( void DolphinMainWindow::updatePasteAction() { - QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste)); + QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); if (pasteAction == 0) { return; } @@@ -603,17 -530,6 +537,6 @@@ void DolphinMainWindow::sortByTags( #endif } - void DolphinMainWindow::toggleSortOrder() - { - m_activeViewContainer->view()->toggleSortOrder(); - } - - void DolphinMainWindow::toggleSortCategorization(bool categorizedSorting) - { - DolphinView* view = m_activeViewContainer->view(); - view->setCategorizedSorting(categorizedSorting); - } - void DolphinMainWindow::toggleSplitView() { if (m_viewContainer[SecondaryView] == 0) { @@@ -646,7 -562,7 +569,7 @@@ setActiveViewContainer(m_viewContainer[PrimaryView]); updateViewActions(); - emit activeViewChanged(); + emit activeViewChanged(); // TODO unused; remove? } void DolphinMainWindow::reloadView() @@@ -659,35 -575,11 +582,11 @@@ void DolphinMainWindow::stopLoading( { } - void DolphinMainWindow::togglePreview(bool show) - { - clearStatusBar(); - m_activeViewContainer->view()->setShowPreview(show); - } - - void DolphinMainWindow::toggleShowHiddenFiles(bool show) - { - clearStatusBar(); - m_activeViewContainer->view()->setShowHiddenFiles(show); - } - void DolphinMainWindow::toggleFilterBarVisibility(bool show) { m_activeViewContainer->showFilterBar(show); } - void DolphinMainWindow::zoomIn() - { - m_activeViewContainer->view()->zoomIn(); - updateViewActions(); - } - - void DolphinMainWindow::zoomOut() - { - m_activeViewContainer->view()->zoomOut(); - updateViewActions(); - } - void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); @@@ -827,6 -719,8 +726,8 @@@ void DolphinMainWindow::init( const KUrl& homeUrl = settings.generalSettings()->homeUrl(); setCaption(homeUrl.fileName()); + m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); + connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar())); ViewProperties props(homeUrl); m_viewContainer[PrimaryView] = new DolphinViewContainer(this, m_splitter, @@@ -834,8 -728,10 +735,10 @@@ m_activeViewContainer = m_viewContainer[PrimaryView]; connectViewSignals(PrimaryView); - m_viewContainer[PrimaryView]->view()->reload(); + DolphinView* view = m_viewContainer[PrimaryView]->view(); + view->reload(); m_viewContainer[PrimaryView]->show(); + m_actionHandler->setCurrentView(view); setCentralWidget(m_splitter); setupDockWidgets(); @@@ -865,16 -761,16 +768,16 @@@ emit urlChanged(homeUrl); } - void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* view) + void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) { - Q_ASSERT(view != 0); - Q_ASSERT((view == m_viewContainer[PrimaryView]) || (view == m_viewContainer[SecondaryView])); - if (m_activeViewContainer == view) { + Q_ASSERT(viewContainer != 0); + Q_ASSERT((viewContainer == m_viewContainer[PrimaryView]) || (viewContainer == m_viewContainer[SecondaryView])); + if (m_activeViewContainer == viewContainer) { return; } m_activeViewContainer->setActive(false); - m_activeViewContainer = view; + m_activeViewContainer = viewContainer; m_activeViewContainer->setActive(true); updateHistory(); @@@ -885,7 -781,9 +788,9 @@@ const KUrl& url = m_activeViewContainer->url(); setCaption(url.fileName()); - emit activeViewChanged(); + m_actionHandler->setCurrentView(viewContainer->view()); + + emit activeViewChanged(); // TODO unused; remove? emit urlChanged(url); } @@@ -899,24 -797,12 +804,12 @@@ void DolphinMainWindow::setupActions( connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); - KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); - connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); - KAction* newWindow = actionCollection()->addAction("new_window"); newWindow->setIcon(KIcon("window-new")); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); newWindow->setShortcut(Qt::CTRL | Qt::Key_N); connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); - KAction* rename = DolphinView::createRenameAction(actionCollection()); - connect(rename, SIGNAL(triggered()), this, SLOT(rename())); - - KAction* moveToTrash = DolphinView::createMoveToTrashAction(actionCollection()); - connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash())); - - KAction* deleteAction = DolphinView::createDeleteAction(actionCollection()); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems())); - KAction* properties = actionCollection()->addAction("properties"); properties->setText(i18nc("@action:inmenu File", "Properties")); properties->setShortcut(Qt::ALT | Qt::Key_Return); @@@ -929,8 -815,8 +822,8 @@@ SLOT(undo()), actionCollection()); - //Need to remove shift+del from cut action, else the shortcut for deletejob - //doesn't work + // need to remove shift+del from cut action, else the shortcut for deletejob + // doesn't work KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection()); KShortcut cutShortcut = cut->shortcut(); cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty); @@@ -949,13 -835,6 +842,6 @@@ connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection())); // setup 'View' menu - KStandardAction::zoomIn(this, - SLOT(zoomIn()), - actionCollection()); - - KStandardAction::zoomOut(this, - SLOT(zoomOut()), - actionCollection()); KToggleAction* iconsView = DolphinView::iconsModeAction(actionCollection()); KToggleAction* detailsView = DolphinView::detailsModeAction(actionCollection()); @@@ -967,6 -846,9 +853,9 @@@ viewModeGroup->addAction(columnView); connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*))); + //QActionGroup* sortActionGroup = DolphinView::createSortActionGroup(actionCollection()); + //connect(sortActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(sortActionGroupTriggered(QAction*))); + // TODO use a QActionGroup KToggleAction* sortByName = actionCollection()->add("sort_by_name"); @@@ -1034,21 -916,6 +923,6 @@@ //sortGroup->addAction(sortByRating); //sortGroup->addAction(sortByTags); - KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); - connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - - KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); - connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); - - QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); - connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); - - KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); - connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); - - KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); - connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); - KAction* split = actionCollection()->addAction("split_view"); split->setShortcut(Qt::Key_F3); updateSplitAction(); @@@ -1065,7 -932,9 +939,7 @@@ stop->setIcon(KIcon("process-stop")); connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading())); - // TODO: the URL navigator must emit a signal if the editable state has been - // changed, so that the corresponding showFullLocation action is updated. Also - // the naming "Show full Location" is currently confusing... + // TODO: the naming "Show full Location" is currently confusing... KToggleAction* showFullLocation = actionCollection()->add("editable_location"); showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Show Full Location")); showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L); @@@ -1182,8 -1051,7 +1056,8 @@@ void DolphinMainWindow::setupDockWidget QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places")); placesDock->setObjectName("placesDock"); placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - KFilePlacesView* placesView = new KFilePlacesView(placesDock); + + DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock); placesDock->setWidget(placesView); placesView->setModel(DolphinSettings::instance().placesModel()); placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@@ -1249,36 -1117,19 +1123,19 @@@ void DolphinMainWindow::updateEditActio void DolphinMainWindow::updateViewActions() { - const DolphinView* view = m_activeViewContainer->view(); - QAction* zoomInAction = actionCollection()->action(KStandardAction::name(KStandardAction::ZoomIn)); - if (zoomInAction != 0) { - zoomInAction->setEnabled(view->isZoomInPossible()); - } - - QAction* zoomOutAction = actionCollection()->action(KStandardAction::name(KStandardAction::ZoomOut)); - if (zoomOutAction != 0) { - zoomOutAction->setEnabled(view->isZoomOutPossible()); - } + m_actionHandler->updateViewActions(); + const DolphinView* view = m_activeViewContainer->view(); QAction* action = actionCollection()->action(view->currentViewModeActionName()); if (action != 0) { action->setChecked(true); } slotSortingChanged(view->sorting()); - slotSortOrderChanged(view->sortOrder()); - slotCategorizedSortingChanged(); - slotAdditionalInfoChanged(); QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - QAction* showPreviewAction = actionCollection()->action("show_preview"); - showPreviewAction->setChecked(view->showPreview()); - - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - showHiddenFilesAction->setChecked(view->showHiddenFiles()); - updateSplitAction(); QAction* editableLocactionAction = actionCollection()->action("editable_location"); @@@ -1288,7 -1139,7 +1145,7 @@@ void DolphinMainWindow::updateGoActions() { - QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up)); + QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up)); const KUrl& currentUrl = m_activeViewContainer->url(); goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); } @@@ -1307,18 -1158,8 +1164,8 @@@ void DolphinMainWindow::connectViewSign DolphinView* view = container->view(); connect(view, SIGNAL(modeChanged()), this, SLOT(slotViewModeChanged())); - connect(view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - connect(view, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(view, SIGNAL(categorizedSortingChanged()), - this, SLOT(slotCategorizedSortingChanged())); connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), this, SLOT(slotSortingChanged(DolphinView::Sorting))); - connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); connect(view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(slotSelectionChanged(KFileItemList))); connect(view, SIGNAL(requestItemInfo(KFileItem)), @@@ -1333,8 -1174,6 +1180,8 @@@ this, SLOT(changeUrl(const KUrl&))); connect(navigator, SIGNAL(historyChanged()), this, SLOT(slotHistoryChanged())); + connect(navigator, SIGNAL(editableStateChanged(bool)), + this, SLOT(slotEditableStateChanged(bool))); } void DolphinMainWindow::updateSplitAction() @@@ -1354,12 -1193,6 +1201,6 @@@ } } - void DolphinMainWindow::toggleAdditionalInfo(QAction* action) - { - clearStatusBar(); - m_activeViewContainer->view()->toggleAdditionalInfo(action); - } - DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) : KonqFileUndoManager::UiInterface(mainWin), m_mainWin(mainWin) diff --combined src/dolphinmainwindow.h index edc5c1bd6,b1694c323..bddeba7b1 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@@ -34,6 -34,7 +34,7 @@@ #include + class DolphinViewActionHandler; class DolphinApplication; class DolphinViewContainer; class KNewMenu; @@@ -163,27 -164,11 +164,11 @@@ protected virtual void readProperties(const KConfigGroup& group); private slots: - /** - * Opens the dialog for creating a directory. Is connected - * with the key shortcut for "new directory" (F10). - */ - void createDir(); + void clearStatusBar(); /** Updates the 'Create New...' sub menu. */ void updateNewMenu(); - /** - * Let the user input a name for the selected item(s) and trigger - * a renaming afterwards. - */ - void rename(); - - /** Moves the selected items of the active view to the trash. */ - void moveToTrash(); - - /** Deletes the selected items of the active view. */ - void deleteItems(); - /** * Opens the properties window for the selected items of the * active view. The properties windows shows information @@@ -267,18 -252,6 +252,6 @@@ /** The sorting of the current view should be done by tags. */ void sortByTags(); - /** Switches between an ascending and descending sorting order. */ - void toggleSortOrder(); - - /** Switches between sorting by categories or not. */ - void toggleSortCategorization(bool); - - /** - * Switches on or off the displaying of additional information - * as specified by \a action. - */ - void toggleAdditionalInfo(QAction* action); - /** * Switches between one and two views: * If one view is visible, it will get split into two views. @@@ -292,27 -265,13 +265,13 @@@ /** Stops the loading process for the current active view. */ void stopLoading(); - /** Switches between showing a preview of the file content and showing the icon. */ - void togglePreview(bool); - - /** - * Switches between showing and hiding of hidden marked files - */ - void toggleShowHiddenFiles(bool); - /** * Toggles between showing and hiding of the filter bar */ void toggleFilterBarVisibility(bool show); - /** Increases the size of the current set view mode. */ - void zoomIn(); - - /** Decreases the size of the current set view mode. */ - void zoomOut(); - /** - * Toggles between edit and brose mode of the navigation bar. + * Toggles between edit and browse mode of the navigation bar. */ void toggleEditLocation(); @@@ -358,27 -317,9 +317,12 @@@ /** Updates the state of all 'View' menu actions. */ void slotViewModeChanged(); - /** Updates the state of the 'Show preview' menu action. */ - void slotShowPreviewChanged(); - - /** Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); - - /** Updates the state of the 'Categorized sorting' menu action. */ - void slotCategorizedSortingChanged(); - /** Updates the state of the 'Sort by' actions. */ void slotSortingChanged(DolphinView::Sorting sorting); - /** Updates the state of the 'Sort Ascending/Descending' action. */ - void slotSortOrderChanged(Qt::SortOrder order); - - /** Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(); - + /** Updates the state of the 'Show Full Location' action. */ + void slotEditableStateChanged(bool editable); + /** * Updates the state of the 'Edit' menu actions and emits * the signal selectionChanged(). @@@ -424,7 -365,6 +368,6 @@@ private void updateEditActions(); void updateViewActions(); void updateGoActions(); - void clearStatusBar(); /** * Connects the signals from the created DolphinView with @@@ -476,6 -416,8 +419,8 @@@ private DolphinViewContainer* m_viewContainer[SecondaryView + 1]; + DolphinViewActionHandler* m_actionHandler; + /// remember pending undo operations until they are finished QList m_undoCommandTypes; }; diff --combined src/dolphinview.cpp index c94a4ea7f,7979b06c3..1ed8310a6 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@@ -32,16 -32,16 +32,16 @@@ #include #include #include -#include #include +#include #include #include #include #include #include #include -#include #include +#include #include #include @@@ -52,11 -52,10 +52,11 @@@ #include "dolphinsortfilterproxymodel.h" #include "dolphindetailsview.h" #include "dolphiniconsview.h" -#include "renamedialog.h" -#include "viewproperties.h" #include "dolphinsettings.h" #include "dolphin_generalsettings.h" +#include "iconmanager.h" +#include "renamedialog.h" +#include "viewproperties.h" DolphinView::DolphinView(QWidget* parent, const KUrl& url, @@@ -79,15 -78,21 +79,15 @@@ m_dolphinModel(dolphinModel), m_dirLister(dirLister), m_proxyModel(proxyModel), - m_previewJob(0) + m_iconManager(0) { setFocusPolicy(Qt::StrongFocus); m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); m_topLayout->setMargin(0); - QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(updateCutItems())); - connect(m_dirLister, SIGNAL(completed()), this, SLOT(updateCutItems())); - connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), - this, SLOT(generatePreviews(const KFileItemList&))); m_controller = new DolphinController(this); m_controller->setUrl(url); @@@ -126,6 -131,10 +126,6 @@@ DolphinView::~DolphinView() { - if (m_previewJob != 0) { - m_previewJob->kill(); - m_previewJob = 0; - } } const KUrl& DolphinView::url() const @@@ -185,6 -194,16 +185,6 @@@ void DolphinView::setMode(Mode mode m_mode = mode; - if (isColumnViewActive()) { - // When changing the mode in the column view, it makes sense - // 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. - const KUrl root = rootUrl(); - setUrl(root); - m_controller->setUrl(root); - } - deleteView(); const KUrl viewPropsUrl = viewPropertiesUrl(); @@@ -227,7 -246,7 +227,7 @@@ void DolphinView::setShowPreview(bool s props.setShowPreview(show); m_showPreview = show; - + m_iconManager->setShowPreview(show); emit showPreviewChanged(); loadDirectory(viewPropsUrl, true); @@@ -400,13 -419,11 +400,13 @@@ QPoint DolphinView::contentsPosition() void DolphinView::zoomIn() { m_controller->triggerZoomIn(); + reload(); } void DolphinView::zoomOut() { m_controller->triggerZoomOut(); + reload(); } bool DolphinView::isZoomInPossible() const @@@ -558,6 -575,45 +558,6 @@@ void DolphinView::triggerItem(const KFi emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart } -void DolphinView::generatePreviews(const KFileItemList& items) -{ - if (m_controller->dolphinView()->showPreview()) { - if (m_previewJob != 0) { - m_previewJob->kill(); - m_previewJob = 0; - } - - m_previewJob = KIO::filePreview(items, 128); - connect(m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(replaceIcon(const KFileItem&, const QPixmap&))); - connect(m_previewJob, SIGNAL(finished(KJob*)), - this, SLOT(slotPreviewJobFinished(KJob*))); - } -} - -void DolphinView::replaceIcon(const KFileItem& item, const QPixmap& pixmap) -{ - Q_ASSERT(!item.isNull()); - if (!m_showPreview || (item.url().directory() != m_dirLister->url().path())) { - // the preview has been deactivated in the meanwhile or 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_dolphinModel->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, KIconLoader::Desktop, KIconLoader::DisabledState); - m_dolphinModel->setData(idx, QIcon(cutPixmap), Qt::DecorationRole); - } else { - m_dolphinModel->setData(idx, QIcon(pixmap), Qt::DecorationRole); - } - } -} - void DolphinView::emitSelectionChangedSignal() { emit selectionChanged(DolphinView::selectedItems()); @@@ -575,6 -631,7 +575,6 @@@ void DolphinView::loadDirectory(const K return; } - m_cutItemsCache.clear(); m_loadingDirectory = true; m_dirLister->stop(); @@@ -657,7 -714,6 +657,7 @@@ void DolphinView::applyViewProperties(c const bool showPreview = props.showPreview(); if (showPreview != m_showPreview) { m_showPreview = showPreview; + m_iconManager->setShowPreview(showPreview); emit showPreviewChanged(); } } @@@ -754,7 -810,7 +754,7 @@@ void DolphinView::updateAdditionalInfo( m_fileItemDelegate->setShowInformation(info); - emit additionalInfoChanged(); // will call updateAdditionalInfoActions just below + emit additionalInfoChanged(); } void DolphinView::updateAdditionalInfoActions(KActionCollection* collection) @@@ -843,6 -899,25 +843,6 @@@ void DolphinView::emitContentsMoved( } } -void DolphinView::updateCutItems() -{ - // restore the icons of all previously selected items to the - // original state... - QList::const_iterator it = m_cutItemsCache.begin(); - QList::const_iterator end = m_cutItemsCache.end(); - while (it != end) { - const QModelIndex index = m_dolphinModel->indexForUrl((*it).url); - if (index.isValid()) { - m_dolphinModel->setData(index, QIcon((*it).pixmap), Qt::DecorationRole); - } - ++it; - } - m_cutItemsCache.clear(); - - // ... and apply an item effect to all currently cut items - applyCutItemEffect(); -} - void DolphinView::showHoverInformation(const KFileItem& item) { if (hasSelection() || !m_active) { @@@ -859,6 -934,7 +859,6 @@@ void DolphinView::clearHoverInformation } } - void DolphinView::createView() { deleteView(); @@@ -904,9 -980,6 +904,9 @@@ view->setSelectionMode(QAbstractItemView::ExtendedSelection); new KMimeTypeResolver(view, m_dolphinModel); + m_iconManager = new IconManager(view, m_proxyModel); + m_iconManager->setShowPreview(m_showPreview); + m_topLayout->insertWidget(1, view); connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), @@@ -929,7 -1002,6 +929,7 @@@ void DolphinView::deleteView( m_detailsView = 0; m_columnView = 0; m_fileItemDelegate = 0; + m_iconManager = 0; } } @@@ -962,6 -1034,42 +962,6 @@@ bool DolphinView::isCutItem(const KFile return false; } -void DolphinView::applyCutItemEffect() -{ - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - if (!KonqMimeData::decodeIsCutSelection(mimeData)) { - return; - } - - KFileItemList items(m_dirLister->items()); - KFileItemList::const_iterator it = items.begin(); - const KFileItemList::const_iterator end = items.end(); - while (it != end) { - const KFileItem item = *it; - if (isCutItem(item)) { - const QModelIndex index = m_dolphinModel->indexForItem(item); - const QVariant value = m_dolphinModel->data(index, Qt::DecorationRole); - if (value.type() == QVariant::Icon) { - const QIcon icon(qvariant_cast(value)); - QPixmap pixmap = icon.pixmap(128, 128); - - // remember current pixmap for the item to be able - // to restore it when other items get cut - CutItem cutItem; - cutItem.url = item.url(); - cutItem.pixmap = pixmap; - m_cutItemsCache.append(cutItem); - - // apply icon effect to the cut item - KIconEffect iconEffect; - pixmap = iconEffect.apply(pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); - m_dolphinModel->setData(index, QIcon(pixmap), Qt::DecorationRole); - } - } - ++it; - } -} - KToggleAction* DolphinView::iconsModeAction(KActionCollection* actionCollection) { KToggleAction* iconsView = actionCollection->add("icons"); @@@ -1025,14 -1133,19 +1025,14 @@@ void DolphinView::renameSelectedItems( Q_ASSERT(newName.contains('#')); // iterate through all selected items and rename them... - const int replaceIndex = newName.indexOf('#'); - Q_ASSERT(replaceIndex >= 0); int index = 1; - - KFileItemList::const_iterator it = items.begin(); - const KFileItemList::const_iterator end = items.end(); - while (it != end) { - const KUrl& oldUrl = (*it).url(); + foreach (KFileItem item, items) { + const KUrl& oldUrl = item.url(); QString number; number.setNum(index++); - QString name(newName); - name.replace(replaceIndex, 1, number); + QString name = newName; + name.replace('#', number); if (oldUrl.fileName() != name) { KUrl newUrl = oldUrl; @@@ -1040,6 -1153,7 +1040,6 @@@ KonqOperations::rename(this, oldUrl, newUrl); emit doingOperation(KonqFileUndoManager::RENAME); } - ++it; } } } else { @@@ -1098,6 -1212,12 +1098,6 @@@ void DolphinView::slotDeleteFileFinishe } } -void DolphinView::slotPreviewJobFinished(KJob* job) -{ - Q_ASSERT(job == m_previewJob); - m_previewJob = 0; -} - void DolphinView::cutSelectedItems() { QMimeData* mimeData = new QMimeData(); @@@ -1181,108 -1301,4 +1181,4 @@@ QPair DolphinView::paste return ret; } - KAction* DolphinView::createRenameAction(KActionCollection* collection) - { - KAction* rename = collection->addAction("rename"); - rename->setText(i18nc("@action:inmenu File", "Rename...")); - rename->setShortcut(Qt::Key_F2); - return rename; - } - - KAction* DolphinView::createMoveToTrashAction(KActionCollection* collection) - { - KAction* moveToTrash = collection->addAction("move_to_trash"); - moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash")); - moveToTrash->setIcon(KIcon("user-trash")); - moveToTrash->setShortcut(QKeySequence::Delete); - return moveToTrash; - } - - KAction* DolphinView::createDeleteAction(KActionCollection* collection) - { - KAction* deleteAction = collection->addAction("delete"); - deleteAction->setIcon(KIcon("edit-delete")); - deleteAction->setText(i18nc("@action:inmenu File", "Delete")); - deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete); - return deleteAction; - } - - KAction* DolphinView::createNewDirAction(KActionCollection* collection) - { - // This action doesn't appear in the GUI, it's for the shortcut only. - // KNewMenu takes care of the GUI stuff. - KAction* newDirAction = collection->addAction("create_dir"); - newDirAction->setText(i18n("Create Folder...")); - newDirAction->setShortcut(Qt::Key_F10); - return newDirAction; - } - - KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) - { - KToggleAction* sortDescending = collection->add("descending"); - sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); - return sortDescending; - } - - KAction* DolphinView::createShowPreviewAction(KActionCollection* collection) - { - KToggleAction* showPreview = collection->add("show_preview"); - showPreview->setText(i18nc("@action:intoolbar", "Preview")); - showPreview->setIcon(KIcon("view-preview")); - return showPreview; - } - - KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection) - { - KToggleAction* showInGroups = collection->add("show_in_groups"); - showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); - return showInGroups; - } - - KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection) - { - KToggleAction* showHiddenFiles = collection->add("show_hidden_files"); - showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); - return showHiddenFiles; - } - - QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) - { - QActionGroup* showInformationGroup = new QActionGroup(collection); - showInformationGroup->setExclusive(false); - - KToggleAction* showSizeInfo = collection->add("show_size_info"); - showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); - showSizeInfo->setData(KFileItemDelegate::Size); - showSizeInfo->setActionGroup(showInformationGroup); - - KToggleAction* showDateInfo = collection->add("show_date_info"); - showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); - showDateInfo->setData(KFileItemDelegate::ModificationTime); - showDateInfo->setActionGroup(showInformationGroup); - - KToggleAction* showPermissionsInfo = collection->add("show_permissions_info"); - showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); - showPermissionsInfo->setData(KFileItemDelegate::Permissions); - showPermissionsInfo->setActionGroup(showInformationGroup); - - KToggleAction* showOwnerInfo = collection->add("show_owner_info"); - showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); - showOwnerInfo->setData(KFileItemDelegate::Owner); - showOwnerInfo->setActionGroup(showInformationGroup); - - KToggleAction* showGroupInfo = collection->add("show_group_info"); - showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); - showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); - showGroupInfo->setActionGroup(showInformationGroup); - - KToggleAction* showMimeInfo = collection->add("show_mime_info"); - showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); - showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); - showMimeInfo->setActionGroup(showInformationGroup); - - return showInformationGroup; - } - #include "dolphinview.moc" diff --combined src/dolphinview.h index 201cc0785,6f0289f62..215a2a23c --- a/src/dolphinview.h +++ b/src/dolphinview.h @@@ -39,22 -39,24 +39,22 @@@ #include class QActionGroup; -class KAction; -class KToggleAction; class DolphinController; -class KDirLister; -class KFileItemDelegate; -class KUrl; -class DolphinModel; class DolphinColumnView; class DolphinDetailsView; class DolphinIconsView; class DolphinMainWindow; +class DolphinModel; class DolphinSortFilterProxyModel; +class IconManager; +class KAction; +class KActionCollection; +class KDirLister; +class KFileItemDelegate; +class KUrl; +class KToggleAction; class QModelIndex; class ViewProperties; -namespace KIO -{ - class PreviewJob; -} /** * @short Represents a view for the directory content. @@@ -322,60 -324,6 +322,6 @@@ public */ static KToggleAction* columnsModeAction(KActionCollection* collection); - /** - * Creates the rename action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createRenameAction(KActionCollection* collection); - - /** - * Creates the "move to trash" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createMoveToTrashAction(KActionCollection* collection); - - /** - * Creates the delete action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createDeleteAction(KActionCollection* collection); - - /** - * Creates the "new directory" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createNewDirAction(KActionCollection* collection); - - /** - * Creates the "sort descending" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createSortDescendingAction(KActionCollection* collection); - - /** - * Creates an action group with all the "show additional information" actions in it. - * This code is here to share it between the mainwindow and the part - */ - static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); - - /** - * Creates the "show preview" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowPreviewAction(KActionCollection* collection); - - /** - * Creates the "show in groups" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowInGroupsAction(KActionCollection* collection); - - /** - * Creates the "show hidden files" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowHiddenFilesAction(KActionCollection* collection); - /** * Updates the state of the 'Additional Information' actions in \a collection. */ @@@ -581,6 -529,19 +527,6 @@@ private slots */ void triggerItem(const KFileItem& index); - /** - * Generates a preview image for each file item in \a items. - * The current preview settings (maximum size, 'Show Preview' menu) - * are respected. - */ - void generatePreviews(const KFileItemList& items); - - /** - * Replaces the icon of the item \a item by the preview pixmap - * \a pixmap. - */ - void replaceIcon(const KFileItem& item, const QPixmap& pixmap); - void emitSelectionChangedSignal(); /** @@@ -629,6 -590,9 +575,6 @@@ */ void emitContentsMoved(); - /** Applies an item effect to all cut items of the clipboard. */ - void updateCutItems(); - /** * Updates the status bar to show hover information for the * item \a item. If currently other items are selected, @@@ -649,6 -613,12 +595,6 @@@ */ void slotDeleteFileFinished(KJob* job); - /** - * Is invoked when the preview job has been finished and - * set m_previewJob to 0. - */ - void slotPreviewJobFinished(KJob* job); - private: void loadDirectory(const KUrl& url, bool reload = false); @@@ -687,6 -657,9 +633,6 @@@ */ bool isCutItem(const KFileItem& item) const; - /** Applies an item effect to all cut items. */ - void applyCutItemEffect(); - /** * Returns true, if the ColumnView is activated. As the column view * requires some special handling for iterating through directories, @@@ -698,6 -671,16 +644,6 @@@ } private: - /** - * Remembers the original pixmap for an item before - * the cut effect is applied. - */ - struct CutItem - { - KUrl url; - QPixmap pixmap; - }; - bool m_active; bool m_showPreview; bool m_loadingDirectory; @@@ -718,7 -701,9 +664,7 @@@ KDirLister* m_dirLister; DolphinSortFilterProxyModel* m_proxyModel; - KIO::PreviewJob* m_previewJob; - - QList m_cutItemsCache; + IconManager* m_iconManager; KUrl m_rootUrl; };