X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/fca6867fea49edb4134332562f518ddddd3fc2a1..e8686083b9de4e83a448ddfd36ea57de7b9e2cd8:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 50f56a478..da8aa3c82 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -20,8 +20,6 @@ #include "dolphinview.h" -#include - #include #include #include @@ -71,6 +69,7 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow, m_controller(0), m_iconsView(0), m_detailsView(0), + m_fileItemDelegate(0), m_filterBar(0), m_statusBar(0), m_dirModel(0), @@ -132,8 +131,8 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow, m_controller = new DolphinController(this); connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)), this, SLOT(openContextMenu(const QPoint&))); - connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QPoint&)), - this, SLOT(dropUrls(const KUrl::List&, const QPoint&))); + connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&, QWidget*)), + this, SLOT(dropUrls(const KUrl::List&, const QModelIndex&, QWidget*))); connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)), this, SLOT(updateSorting(DolphinView::Sorting))); connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)), @@ -249,6 +248,7 @@ bool DolphinView::showHiddenFiles() const void DolphinView::renameSelectedItems() { + DolphinView* view = mainWindow()->activeView(); const KUrl::List urls = selectedUrls(); if (urls.count() > 1) { // More than one item has been selected for renaming. Open @@ -258,80 +258,64 @@ void DolphinView::renameSelectedItems() return; } - DolphinView* view = mainWindow()->activeView(); const QString& newName = dialog.newName(); if (newName.isEmpty()) { - view->statusBar()->setMessage(i18n("The new item name is invalid."), + view->statusBar()->setMessage(dialog.errorString(), DolphinStatusBar::Error); } else { // TODO: check how this can be integrated into KonqUndoManager/KonqOperations - - //UndoManager& undoMan = UndoManager::instance(); - //undoMan.beginMacro(); - - assert(newName.contains('#')); - - const int urlsCount = urls.count(); + // 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('#'); - assert(replaceIndex >= 0); - for (int i = 0; i < urlsCount; ++i) { - const KUrl& source = urls[i]; + 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(i + 1); + number.setNum(index++); QString name(newName); name.replace(replaceIndex, 1, number); - if (source.fileName() != name) { - KUrl dest(source.upUrl()); - dest.addPath(name); - - const bool destExists = KIO::NetAccess::exists(dest, false, view); - if (destExists) { - view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name), - DolphinStatusBar::Error); - break; - } - else if (KIO::NetAccess::file_move(source, dest)) { - // TODO: From the users point of view he executed one 'rename n files' operation, - // but internally we store it as n 'rename 1 file' operations for the undo mechanism. - //DolphinCommand command(DolphinCommand::Rename, source, dest); - //undoMan.addCommand(command); - } + if (oldUrl.fileName() != name) { + KUrl newUrl(oldUrl.upUrl()); + newUrl.addPath(name); + m_mainWindow->rename(oldUrl, newUrl); } + ++it; } - - //undoMan.endMacro(); } } else { // Only one item has been selected for renaming. Use the custom // renaming mechanism from the views. - assert(urls.count() == 1); - // TODO: - /*if (m_mode == DetailsView) { - Q3ListViewItem* item = m_iconsView->firstChild(); - while (item != 0) { - if (item->isSelected()) { - m_iconsView->rename(item, DolphinDetailsView::NameColumn); - break; - } - item = item->nextSibling(); - } + 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 { - KFileIconViewItem* item = static_cast(m_iconsView->firstItem()); - while (item != 0) { - if (item->isSelected()) { - item->rename(); - break; - } - item = static_cast(item->nextItem()); - } - }*/ + const KUrl& oldUrl = urls.first(); + KUrl newUrl = oldUrl.upUrl(); + newUrl.addPath(newName); + m_mainWindow->rename(oldUrl, newUrl); + } } } @@ -425,6 +409,22 @@ Qt::SortOrder DolphinView::sortOrder() const return m_proxyModel->sortOrder(); } +void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info) +{ + ViewProperties props(m_urlNavigator->url()); + props.setAdditionalInfo(info); + + m_fileItemDelegate->setAdditionalInformation(info); + + emit additionalInfoChanged(info); + reload(); +} + +KFileItemDelegate::AdditionalInformation DolphinView::additionalInfo() const +{ + return m_fileItemDelegate->additionalInformation(); +} + void DolphinView::goBack() { m_urlNavigator->goBack(); @@ -613,6 +613,13 @@ void DolphinView::loadDirectory(const KUrl& url) emit sortOrderChanged(sortOrder); } + KFileItemDelegate::AdditionalInformation info = props.additionalInfo(); + if (info != m_fileItemDelegate->additionalInformation()) { + m_fileItemDelegate->setAdditionalInformation(info); + + emit additionalInfoChanged(info); + } + const bool showPreview = props.showPreview(); if (showPreview != m_controller->showPreview()) { m_controller->setShowPreview(showPreview); @@ -732,7 +739,7 @@ void DolphinView::generatePreviews(const KFileItemList& items) const QMimeData* mimeData = QApplication::clipboard()->mimeData(); if (KonqMimeData::decodeIsCutSelection(mimeData)) { - QTimer::singleShot(1000, this, SLOT(applyCutEffect())); + QTimer::singleShot(0, this, SLOT(applyCutEffect())); } } @@ -870,7 +877,7 @@ QString DolphinView::selectionStatusBarText() const void DolphinView::showFilterBar(bool show) { - assert(m_filterBar != 0); + Q_ASSERT(m_filterBar != 0); if (show) { m_filterBar->show(); } @@ -971,21 +978,30 @@ void DolphinView::openContextMenu(const QPoint& pos) } void DolphinView::dropUrls(const KUrl::List& urls, - const QPoint& pos) + const QModelIndex& index, + QWidget* source) { KFileItem* directory = 0; - const QModelIndex index = itemView()->indexAt(pos); if (isValidNameIndex(index)) { KFileItem* item = fileItem(index); - assert(item != 0); + Q_ASSERT(item != 0); if (item->isDir()) { // the URLs are dropped above a directory directory = item; } } + if ((directory == 0) && (source == itemView())) { + // The dropping is done into the same viewport where + // the dragging has been started. Just ignore this... + return; + } + const KUrl& destination = (directory == 0) ? url() : directory->url(); + + kDebug() << "DolphinView::dropUrls() - destination: " << destination.prettyUrl() << endl; + dropUrls(urls, destination); } @@ -1034,12 +1050,14 @@ void DolphinView::createView() m_topLayout->removeWidget(view); view->close(); view->deleteLater(); + view = 0; m_iconsView = 0; m_detailsView = 0; + m_fileItemDelegate = 0; } - assert(m_iconsView == 0); - assert(m_detailsView == 0); + Q_ASSERT(m_iconsView == 0); + Q_ASSERT(m_detailsView == 0); // ... and recreate it representing the current mode switch (m_mode) { @@ -1054,6 +1072,11 @@ void DolphinView::createView() break; } + Q_ASSERT(view != 0); + + m_fileItemDelegate = new KFileItemDelegate(view); + view->setItemDelegate(m_fileItemDelegate); + view->setModel(m_proxyModel); view->setSelectionMode(QAbstractItemView::ExtendedSelection);