X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/056ac9a271f3a8fec02326ed0b478c3a71baaf0c..6422ae393ed378f8dcde0bf35e1f8d67a5df2295:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 767db820d..eed6da4ea 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -22,7 +22,6 @@ #include #include "dolphinmainwindow.h" -#include "bookmarkssidebarpage.h" #include "dolphinapplication.h" #include "dolphinnewmenu.h" #include "dolphinsettings.h" @@ -32,16 +31,16 @@ #include "metadatawidget.h" #include "mainwindowadaptor.h" #include "treeviewsidebarpage.h" -#include "urlnavigator.h" +#include "kurlnavigator.h" #include "viewpropertiesdialog.h" #include "viewproperties.h" #include "kfileplacesmodel.h" +#include "kfileplacesview.h" #include "dolphin_generalsettings.h" #include #include -#include #include #include #include @@ -74,11 +73,11 @@ #include DolphinMainWindow::DolphinMainWindow(int id) : - KMainWindow(0), - m_newMenu(0), - m_splitter(0), - m_activeView(0), - m_id(id) + KMainWindow(0), + m_newMenu(0), + m_splitter(0), + m_activeView(0), + m_id(id) { setObjectName("Dolphin"); m_view[PrimaryIdx] = 0; @@ -134,16 +133,13 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls, if (shiftPressed && controlPressed) { // shortcut for 'Link Here' is used action = Qt::LinkAction; - } - else if (shiftPressed) { + } else if (shiftPressed) { // shortcut for 'Move Here' is used action = Qt::MoveAction; - } - else if (controlPressed) { + } else if (controlPressed) { // shortcut for 'Copy Here' is used action = Qt::CopyAction; - } - else { + } else { // open a context menu which offers the following actions: // - Move Here // - Copy Here @@ -173,33 +169,30 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls, QAction* activatedAction = popup.exec(QCursor::pos()); if (activatedAction == moveAction) { action = Qt::MoveAction; - } - else if (activatedAction == copyAction) { + } else if (activatedAction == copyAction) { action = Qt::CopyAction; - } - else if (activatedAction == linkAction) { + } else if (activatedAction == linkAction) { action = Qt::LinkAction; - } - else { + } else { return; } } switch (action) { - case Qt::MoveAction: - moveUrls(urls, destination); - break; + case Qt::MoveAction: + moveUrls(urls, destination); + break; - case Qt::CopyAction: - copyUrls(urls, destination); - break; + case Qt::CopyAction: + copyUrls(urls, destination); + break; - case Qt::LinkAction: - linkUrls(urls, destination); - break; + case Qt::LinkAction: + linkUrls(urls, destination); + break; - default: - break; + default: + break; } } @@ -216,7 +209,7 @@ void DolphinMainWindow::refreshViews() const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]); KUrl url; for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) { - if (m_view[i] != 0) { + if (m_view[i] != 0) { url = m_view[i]->url(); // delete view instance... @@ -282,30 +275,38 @@ void DolphinMainWindow::slotShowHiddenFilesChanged() showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles()); } +void DolphinMainWindow::slotCategorizedSortingChanged() +{ + KToggleAction* categorizedSortingAction = + static_cast(actionCollection()->action("categorized")); + categorizedSortingAction->setChecked(m_activeView->categorizedSorting()); + categorizedSortingAction->setEnabled(m_activeView->supportsCategorizedSorting()); +} + void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) { QAction* action = 0; switch (sorting) { - case DolphinView::SortByName: - action = actionCollection()->action("by_name"); - break; - case DolphinView::SortBySize: - action = actionCollection()->action("by_size"); - break; - case DolphinView::SortByDate: - action = actionCollection()->action("by_date"); - break; - case DolphinView::SortByPermissions: - action = actionCollection()->action("by_permissions"); - break; - case DolphinView::SortByOwner: - action = actionCollection()->action("by_owner"); - break; - case DolphinView::SortByGroup: - action = actionCollection()->action("by_group"); - break; - default: - break; + case DolphinView::SortByName: + action = actionCollection()->action("by_name"); + break; + case DolphinView::SortBySize: + action = actionCollection()->action("by_size"); + break; + case DolphinView::SortByDate: + action = actionCollection()->action("by_date"); + break; + case DolphinView::SortByPermissions: + action = actionCollection()->action("by_permissions"); + break; + case DolphinView::SortByOwner: + action = actionCollection()->action("by_owner"); + break; + case DolphinView::SortByGroup: + action = actionCollection()->action("by_group"); + break; + default: + break; } if (action != 0) { @@ -317,7 +318,7 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) { KToggleAction* descending = static_cast(actionCollection()->action("descending")); - const bool sortDescending = (order == Qt::Descending); + const bool sortDescending = (order == Qt::DescendingOrder); descending->setChecked(sortDescending); } @@ -325,19 +326,19 @@ void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::AdditionalI { QAction* action = 0; switch (info) { - case KFileItemDelegate::FriendlyMimeType: - action = actionCollection()->action("show_mime_info"); - break; - case KFileItemDelegate::Size: - action = actionCollection()->action("show_size_info"); - break; - case KFileItemDelegate::ModificationTime: - action = actionCollection()->action("show_date_info"); - break; - case KFileItemDelegate::NoInformation: - default: - action = actionCollection()->action("clear_info"); - break; + case KFileItemDelegate::FriendlyMimeType: + action = actionCollection()->action("show_mime_info"); + break; + case KFileItemDelegate::Size: + action = actionCollection()->action("show_size_info"); + break; + case KFileItemDelegate::ModificationTime: + action = actionCollection()->action("show_date_info"); + break; + case KFileItemDelegate::NoInformation: + default: + action = actionCollection()->action("clear_info"); + break; } if (action != 0) { @@ -431,8 +432,7 @@ void DolphinMainWindow::readProperties(KConfig* config) } m_view[SecondaryIdx]->setUrl(secondaryView.readEntry("Url")); m_view[SecondaryIdx]->setUrlEditable(secondaryView.readEntry("Editable Url", false)); - } - else if (m_view[SecondaryIdx] != 0) { + } else if (m_view[SecondaryIdx] != 0) { toggleSplitView(); } } @@ -463,9 +463,9 @@ void DolphinMainWindow::deleteItems() const KUrl::List list = m_activeView->selectedUrls(); const bool del = KonqOperations::askDeleteConfirmation(list, - KonqOperations::DEL, - KonqOperations::FORCE_CONFIRMATION, - this); + KonqOperations::DEL, + KonqOperations::DEFAULT_CONFIRMATION, + this); if (del) { KIO::Job* job = KIO::del(list); @@ -516,34 +516,34 @@ void DolphinMainWindow::slotUndoAvailable(bool available) const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst(); DolphinStatusBar* statusBar = m_activeView->statusBar(); switch (command) { - case KonqUndoManager::COPY: - statusBar->setMessage(i18n("Copy operation completed."), - DolphinStatusBar::OperationCompleted); - break; - case KonqUndoManager::MOVE: - statusBar->setMessage(i18n("Move operation completed."), - DolphinStatusBar::OperationCompleted); - break; - case KonqUndoManager::LINK: - statusBar->setMessage(i18n("Link operation completed."), - DolphinStatusBar::OperationCompleted); - break; - case KonqUndoManager::TRASH: - statusBar->setMessage(i18n("Move to trash operation completed."), - DolphinStatusBar::OperationCompleted); - break; - case KonqUndoManager::RENAME: - statusBar->setMessage(i18n("Renaming operation completed."), - DolphinStatusBar::OperationCompleted); - break; - - case KonqUndoManager::MKDIR: - statusBar->setMessage(i18n("Created directory."), - DolphinStatusBar::OperationCompleted); - break; - - default: - break; + case KonqUndoManager::COPY: + statusBar->setMessage(i18n("Copy operation completed."), + DolphinStatusBar::OperationCompleted); + break; + case KonqUndoManager::MOVE: + statusBar->setMessage(i18n("Move operation completed."), + DolphinStatusBar::OperationCompleted); + break; + case KonqUndoManager::LINK: + statusBar->setMessage(i18n("Link operation completed."), + DolphinStatusBar::OperationCompleted); + break; + case KonqUndoManager::TRASH: + statusBar->setMessage(i18n("Move to trash operation completed."), + DolphinStatusBar::OperationCompleted); + break; + case KonqUndoManager::RENAME: + statusBar->setMessage(i18n("Renaming operation completed."), + DolphinStatusBar::OperationCompleted); + break; + + case KonqUndoManager::MKDIR: + statusBar->setMessage(i18n("Created directory."), + DolphinStatusBar::OperationCompleted); + break; + + default: + break; } } @@ -611,8 +611,7 @@ void DolphinMainWindow::paste() if (KonqMimeData::decodeIsCutSelection(mimeData)) { moveUrls(sourceUrls, destUrl); clipboard->clear(); - } - else { + } else { copyUrls(sourceUrls, destUrl); } } @@ -633,8 +632,7 @@ void DolphinMainWindow::updatePasteAction() pasteAction->setEnabled(true); pasteAction->setText(i18np("Paste One File", "Paste %1 Files", urls.count())); - } - else { + } else { pasteAction->setEnabled(false); pasteAction->setText(i18n("Paste")); } @@ -646,8 +644,7 @@ void DolphinMainWindow::updatePasteAction() // pasting should not be allowed when more than one file // is selected pasteAction->setEnabled(false); - } - else if (count == 1) { + } else if (count == 1) { // 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 @@ -719,12 +716,18 @@ void DolphinMainWindow::sortByGroup() void DolphinMainWindow::toggleSortOrder() { - const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ? - Qt::Descending : - Qt::Ascending; + const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::AscendingOrder) ? + Qt::DescendingOrder : + Qt::AscendingOrder; m_activeView->setSortOrder(order); } +void DolphinMainWindow::toggleSortCategorization() +{ + const bool categorizedSorting = m_activeView->categorizedSorting(); + m_activeView->setCategorizedSorting(!categorizedSorting); +} + void DolphinMainWindow::clearInfo() { m_activeView->setAdditionalInfo(KFileItemDelegate::NoInformation); @@ -763,16 +766,14 @@ void DolphinMainWindow::toggleSplitView() m_splitter->setSizes(QList() << newWidth << newWidth); m_view[SecondaryIdx]->reload(); m_view[SecondaryIdx]->show(); - } - else { + } else { // remove secondary view if (m_activeView == m_view[PrimaryIdx]) { m_view[SecondaryIdx]->close(); m_view[SecondaryIdx]->deleteLater(); m_view[SecondaryIdx] = 0; setActiveView(m_view[PrimaryIdx]); - } - else { + } else { // The secondary view is active, hence from the users point of view // the content of the secondary view should be moved to the primary view. // From an implementation point of view it is more efficient to close @@ -794,8 +795,7 @@ void DolphinMainWindow::reloadView() } void DolphinMainWindow::stopLoading() -{ -} +{} void DolphinMainWindow::togglePreview() { @@ -912,35 +912,35 @@ void DolphinMainWindow::compareFiles() KUrl::List urls = m_view[PrimaryIdx]->selectedUrls(); switch (urls.count()) { - case 0: { - Q_ASSERT(m_view[SecondaryIdx] != 0); - urls = m_view[SecondaryIdx]->selectedUrls(); - Q_ASSERT(urls.count() == 2); - urlA = urls[0]; - urlB = urls[1]; - break; - } + case 0: { + Q_ASSERT(m_view[SecondaryIdx] != 0); + urls = m_view[SecondaryIdx]->selectedUrls(); + Q_ASSERT(urls.count() == 2); + urlA = urls[0]; + urlB = urls[1]; + break; + } - case 1: { - urlA = urls[0]; - Q_ASSERT(m_view[SecondaryIdx] != 0); - urls = m_view[SecondaryIdx]->selectedUrls(); - Q_ASSERT(urls.count() == 1); - urlB = urls[0]; - break; - } + case 1: { + urlA = urls[0]; + Q_ASSERT(m_view[SecondaryIdx] != 0); + urls = m_view[SecondaryIdx]->selectedUrls(); + Q_ASSERT(urls.count() == 1); + urlB = urls[0]; + break; + } - case 2: { - urlA = urls[0]; - urlB = urls[1]; - break; - } + case 2: { + urlA = urls[0]; + urlB = urls[1]; + break; + } - default: { - // may not happen: compareFiles may only get invoked if 2 - // files are selected - Q_ASSERT(false); - } + default: { + // may not happen: compareFiles may only get invoked if 2 + // files are selected + Q_ASSERT(false); + } } QString command("kompare -c \""); @@ -975,17 +975,6 @@ void DolphinMainWindow::init() DolphinSettings& settings = DolphinSettings::instance(); - KBookmarkManager* manager = settings.bookmarkManager(); - Q_ASSERT(manager != 0); - KBookmarkGroup root = manager->root(); - if (root.first().isNull()) { - root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder-home"); - root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "hdd-mount"); - root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network-local"); - root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder-red"); - root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "user-trash"); - } - setupActions(); const KUrl& homeUrl = settings.generalSettings()->homeUrl(); @@ -1005,7 +994,7 @@ void DolphinMainWindow::init() setCentralWidget(m_splitter); setupDockWidgets(); - setupGUI(Keys|Save|Create|ToolBar); + setupGUI(Keys | Save | Create | ToolBar); createGUI(); stateChanged("new_file"); @@ -1023,10 +1012,10 @@ void DolphinMainWindow::init() // assure a proper default size if Dolphin runs the first time resize(640, 480); } - #ifdef HAVE_KMETADATA - if ( !MetaDataWidget::metaDataAvailable() ) +#ifdef HAVE_KMETADATA + if (!MetaDataWidget::metaDataAvailable()) activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error); - #endif +#endif emit urlChanged(homeUrl); } @@ -1060,7 +1049,7 @@ void DolphinMainWindow::setupActions() // setup 'File' menu m_newMenu = new DolphinNewMenu(this); KMenu* menu = m_newMenu->menu(); - menu->setTitle(i18n("Create New...")); + menu->setTitle(i18n("Create New")); menu->setIcon(KIcon("document-new")); connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); @@ -1072,7 +1061,7 @@ void DolphinMainWindow::setupActions() connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); QAction* rename = actionCollection()->addAction("rename"); - rename->setText(i18n("Rename")); + rename->setText(i18n("Rename...")); rename->setShortcut(Qt::Key_F2); connect(rename, SIGNAL(triggered()), this, SLOT(rename())); @@ -1116,12 +1105,12 @@ void DolphinMainWindow::setupActions() // setup 'View' menu KStandardAction::zoomIn(this, - SLOT(zoomIn()), - actionCollection()); + SLOT(zoomIn()), + actionCollection()); KStandardAction::zoomOut(this, - SLOT(zoomOut()), - actionCollection()); + SLOT(zoomOut()), + actionCollection()); KToggleAction* iconsView = actionCollection()->add("icons"); iconsView->setText(i18n("Icons")); @@ -1182,6 +1171,10 @@ void DolphinMainWindow::setupActions() sortDescending->setText(i18n("Descending")); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); + KToggleAction* sortCategorized = actionCollection()->add("categorized"); + sortCategorized->setText(i18n("Categorized")); + connect(sortCategorized, SIGNAL(triggered()), this, SLOT(toggleSortCategorization())); + KToggleAction* clearInfo = actionCollection()->add("clear_info"); clearInfo->setText(i18n("No Information")); connect(clearInfo, SIGNAL(triggered()), this, SLOT(clearInfo())); @@ -1287,20 +1280,6 @@ void DolphinMainWindow::setupDockWidgets() // TODO: there's a lot copy/paste code here. Provide a generic approach // after the dock concept has been finalized. - // setup "Bookmarks" - QDockWidget* shortcutsDock = new QDockWidget(i18n("Bookmarks"), this); - shortcutsDock->setObjectName("bookmarksDock"); - shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - SidebarPage* shortcutsWidget = new BookmarksSidebarPage(shortcutsDock); - shortcutsDock->setWidget(shortcutsWidget); - - - shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel")); - actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction()); - - addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock); - connectSidebarPage(shortcutsWidget); - // setup "Information" QDockWidget* infoDock = new QDockWidget(i18n("Information"), this); infoDock->setObjectName("infoDock"); @@ -1334,23 +1313,27 @@ void DolphinMainWindow::setupDockWidgets() treeViewDock->hide(); } - // FIXME: To merge with the current bookmark sidebar QDockWidget *placesDock = new QDockWidget(i18n("Places")); placesDock->setObjectName("placesDock"); placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - QListView *listView = new QListView(placesDock); + KFilePlacesView *listView = new KFilePlacesView(placesDock); placesDock->setWidget(listView); - listView->setModel(new KFilePlacesModel(listView)); + listView->setModel(DolphinSettings::instance().placesModel()); addDockWidget(Qt::LeftDockWidgetArea, placesDock); + connect(listView, SIGNAL(urlChanged(KUrl)), + this, SLOT(changeUrl(KUrl))); + connect(this, SIGNAL(urlChanged(KUrl)), + listView, SLOT(setUrl(KUrl))); } void DolphinMainWindow::updateHistory() { - int index = 0; + const KUrlNavigator* urlNavigator = m_activeView->urlNavigator(); + const int index = urlNavigator->historyIndex(); QAction* backAction = actionCollection()->action("go_back"); if (backAction != 0) { - backAction->setEnabled(index < m_activeView->urlNavigator()->historySize() - 1); + backAction->setEnabled(index < urlNavigator->historySize() - 1); } QAction* forwardAction = actionCollection()->action("go_forward"); @@ -1364,8 +1347,7 @@ void DolphinMainWindow::updateEditActions() const KFileItemList list = m_activeView->selectedItems(); if (list.isEmpty()) { stateChanged("has_no_selection"); - } - else { + } else { stateChanged("has_selection"); QAction* renameAction = actionCollection()->action("rename"); @@ -1407,17 +1389,17 @@ void DolphinMainWindow::updateViewActions() QAction* action = 0; switch (m_activeView->mode()) { - case DolphinView::IconsView: - action = actionCollection()->action("icons"); - break; - case DolphinView::DetailsView: - action = actionCollection()->action("details"); - break; - case DolphinView::ColumnView: - action = actionCollection()->action("columns"); - break; - default: - break; + case DolphinView::IconsView: + action = actionCollection()->action("icons"); + break; + case DolphinView::DetailsView: + action = actionCollection()->action("details"); + break; + case DolphinView::ColumnView: + action = actionCollection()->action("columns"); + break; + default: + break; } if (action != 0) { @@ -1427,6 +1409,7 @@ void DolphinMainWindow::updateViewActions() slotSortingChanged(m_activeView->sorting()); slotSortOrderChanged(m_activeView->sortOrder()); + slotCategorizedSortingChanged(); slotAdditionalInfoChanged(m_activeView->additionalInfo()); KToggleAction* showFilterBarAction = @@ -1488,6 +1471,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) 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)), @@ -1501,7 +1486,7 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) connect(view, SIGNAL(urlChanged(KUrl)), this, SLOT(changeUrl(KUrl))); - const UrlNavigator* navigator = view->urlNavigator(); + const KUrlNavigator* navigator = view->urlNavigator(); connect(navigator, SIGNAL(urlChanged(const KUrl&)), this, SLOT(changeUrl(const KUrl&))); connect(navigator, SIGNAL(historyChanged()), @@ -1513,25 +1498,24 @@ void DolphinMainWindow::connectSidebarPage(SidebarPage* page) this, SLOT(changeUrl(KUrl))); connect(page, SIGNAL(changeSelection(KFileItemList)), this, SLOT(changeSelection(KFileItemList))); - connect(page, SIGNAL(urlsDropped(KUrl::List,KUrl)), - this, SLOT(dropUrls(KUrl::List,KUrl))); + connect(page, SIGNAL(urlsDropped(KUrl::List, KUrl)), + this, SLOT(dropUrls(KUrl::List, KUrl))); connect(this, SIGNAL(urlChanged(KUrl)), page, SLOT(setUrl(KUrl))); - connect(this, SIGNAL(selectionChanged(KFileItemList)), - page, SLOT(setSelection(KFileItemList))); + connect(this, SIGNAL(selectionChanged(KFileItemList)), + page, SLOT(setSelection(KFileItemList))); } DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) : - KonqUndoManager::UiInterface(mainWin), - m_mainWin(mainWin) + KonqUndoManager::UiInterface(mainWin), + m_mainWin(mainWin) { Q_ASSERT(m_mainWin != 0); } DolphinMainWindow::UndoUiInterface::~UndoUiInterface() -{ -} +{} void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) {