-bool DolphinView::hasSelection() const
-{
- return itemView()->selectionModel()->hasSelection();
-}
-
-void DolphinView::clearSelection()
-{
- itemView()->selectionModel()->clear();
-}
-
-KFileItemList DolphinView::selectedItems() const
-{
- const QAbstractItemView* view = itemView();
-
- // Our view has a selection, we will map them back to the DirModel
- // and then fill the KFileItemList.
- Q_ASSERT((view != 0) && (view->selectionModel() != 0));
-
- const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
- KFileItemList itemList;
-
- const QModelIndexList indexList = selection.indexes();
- QModelIndexList::const_iterator end = indexList.end();
- for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
- Q_ASSERT((*it).isValid());
-
- KFileItem* item = m_dirModel->itemForIndex(*it);
- if (item != 0) {
- itemList.append(item);
- }
- }
-
- return itemList;
-}
-
-KUrl::List DolphinView::selectedUrls() const
-{
- KUrl::List urls;
-
- const KFileItemList list = selectedItems();
- KFileItemList::const_iterator it = list.begin();
- const KFileItemList::const_iterator end = list.end();
- while (it != end) {
- KFileItem* item = *it;
- urls.append(item->url());
- ++it;
- }
-
- return urls;
-}
-
-KFileItem* DolphinView::fileItem(const QModelIndex index) const
-{
- const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
- return m_dirModel->itemForIndex(dirModelIndex);
-}
-
-void DolphinView::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) {
- // XYDZ
- //m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.", source.fileName(), destFileName),
- // DolphinStatusBar::OperationCompleted);
-
- KonqOperations::rename(this, source, destFileName);
- } else {
- // XYDZ
- //m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName),
- // DolphinStatusBar::Error);
- }
-}
-