#include <kactioncollection.h>
#include <kcolorscheme.h>
#include <kdirlister.h>
-#include <kfileitemdelegate.h>
#include <kfilepreviewgenerator.h>
#include <kiconeffect.h>
+#include <kfileitem.h>
#include <klocale.h>
#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <konq_fileitemcapabilities.h>
#include <konq_operations.h>
#include <konqmimedata.h>
+#include <kstringhandler.h>
#include <ktoggleaction.h>
#include <kurl.h>
-#include "dolphindropcontroller.h"
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphindetailsview.h"
#include "dolphin_detailsmodesettings.h"
#include "dolphiniconsview.h"
#include "dolphinsettings.h"
#include "dolphin_generalsettings.h"
+#include "draganddrophelper.h"
#include "folderexpander.h"
#include "renamedialog.h"
#include "tooltipmanager.h"
#include "viewproperties.h"
#include "zoomlevelinfo.h"
+/**
+ * Helper function for sorting items with qSort() in
+ * DolphinView::renameSelectedItems().
+ */
+bool lessThan(const KFileItem& item1, const KFileItem& item2)
+{
+ return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0;
+}
+
DolphinView::DolphinView(QWidget* parent,
const KUrl& url,
KDirLister* dirLister,
m_previewGenerator(0),
m_toolTipManager(0),
m_rootUrl(),
- m_currentItemUrl()
+ m_currentItemUrl(),
+ m_expandedViews()
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
this, SLOT(clearHoverInformation()));
connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
- this, SLOT(slotRedirection(KUrl, KUrl)));
+ this, SIGNAL(redirection(KUrl, KUrl)));
connect(m_dirLister, SIGNAL(completed()),
this, SLOT(restoreCurrentItem()));
DolphinView::~DolphinView()
{
+ deleteExpandedViews();
}
const KUrl& DolphinView::url() const
}
emit modeChanged();
+
updateZoomLevel(oldZoomLevel);
+ if (m_showPreview) {
+ loadDirectory(viewPropsUrl);
+ }
}
DolphinView::Mode DolphinView::mode() const
} else if (level > ZoomLevelInfo::maximumLevel()) {
level = ZoomLevelInfo::maximumLevel();
}
-
+
if (level != zoomLevel()) {
m_controller->setZoomLevel(level);
m_previewGenerator->updatePreviews();
void DolphinView::refresh()
{
const bool oldActivationState = m_active;
+ const int oldZoomLevel = m_controller->zoomLevel();
m_active = true;
createView();
reload();
setActive(oldActivationState);
+ updateZoomLevel(oldZoomLevel);
}
void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
}
}
-void DolphinView::calculateItemCount(int& fileCount, int& folderCount) const
+void DolphinView::calculateItemCount(int& fileCount,
+ int& folderCount,
+ KIO::filesize_t& totalFileSize) const
{
foreach (const KFileItem& item, m_dirLister->items()) {
if (item.isDir()) {
++folderCount;
} else {
++fileCount;
+ totalFileSize += item.size();
}
}
}
QString DolphinView::statusBarText() const
-{
+{
+ QString text;
+ int folderCount = 0;
+ int fileCount = 0;
+ KIO::filesize_t totalFileSize = 0;
+
if (hasSelection()) {
// give a summary of the status of the selected files
- 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();
+ return text;
}
- 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) {
++folderCount;
} else {
++fileCount;
- byteSize += item.size();
+ totalFileSize += item.size();
}
++it;
}
- if (folderCount > 0) {
- text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
- if (fileCount > 0) {
- text += ", ";
+ if (folderCount + fileCount == 1) {
+ // if only one item is selected, show the filename
+ const QString name = list.first().name();
+ text = (folderCount == 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name) :
+ i18nc("@info:status", "<filename>%1</filename> selected (%2)",
+ name, KIO::convertSize(totalFileSize));
+ } else {
+ // at least 2 items are selected
+ const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
+ const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
+ if ((folderCount > 0) && (fileCount > 0)) {
+ text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
+ foldersText, filesText, KIO::convertSize(totalFileSize));
+ } else if (fileCount > 0) {
+ text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize));
+ } else {
+ Q_ASSERT(folderCount > 0);
+ text = foldersText;
}
}
-
- if (fileCount > 0) {
- const QString sizeText(KIO::convertSize(byteSize));
- text += i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
- }
- return text;
} else {
- // Give a summary of the status of the current folder.
- int folderCount = 0;
- int fileCount = 0;
- calculateItemCount(fileCount, folderCount);
- return KIO::itemsSummaryString(fileCount + folderCount,
- fileCount,
- folderCount,
- 0, false);
+ calculateItemCount(fileCount, folderCount, totalFileSize);
+ text = KIO::itemsSummaryString(fileCount + folderCount,
+ fileCount, folderCount,
+ totalFileSize, true);
}
+
+ return text;
}
void DolphinView::setUrl(const KUrl& url)
void DolphinView::renameSelectedItems()
{
- const KFileItemList items = selectedItems();
+ KFileItemList items = selectedItems();
const int itemCount = items.count();
if (itemCount < 1) {
return;
}
-
+
if (itemCount > 1) {
// More than one item has been selected for renaming. Open
// a rename dialog and rename all items afterwards.
// as one operation instead of n rename operations like it is done now...
Q_ASSERT(newName.contains('#'));
+ // currently the items are sorted by the selection order, resort
+ // them by the file name
+ qSort(items.begin(), items.end(), lessThan);
+
// iterate through all selected items and rename them...
int index = 1;
- foreach (const KFileItem &item, items) {
+ foreach (const KFileItem& item, items) {
const KUrl& oldUrl = item.url();
QString number;
number.setNum(index++);
}
} else if (DolphinSettings::instance().generalSettings()->renameInline()) {
Q_ASSERT(itemCount == 1);
-
+
if (isColumnViewActive()) {
m_columnView->editItem(items.first());
} else {
}
} else {
Q_ASSERT(itemCount == 1);
-
+
RenameDialog dialog(this, items);
if (dialog.exec() == QDialog::Rejected) {
return;
void DolphinView::cutSelectedItems()
{
- QMimeData* mimeData = new QMimeData();
- const KUrl::List kdeUrls = simplifiedSelectedUrls();
- const KUrl::List mostLocalUrls;
- KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
+ QMimeData* mimeData = selectionMimeData();
+ KonqMimeData::addIsCutSelection(mimeData, true);
QApplication::clipboard()->setMimeData(mimeData);
}
void DolphinView::copySelectedItems()
{
- QMimeData* mimeData = new QMimeData();
- const KUrl::List kdeUrls = selectedUrls();
- const KUrl::List mostLocalUrls;
- KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
+ QMimeData* mimeData = selectionMimeData();
QApplication::clipboard()->setMimeData(mimeData);
}
m_showPreview = show;
m_previewGenerator->setPreviewShown(show);
-
+
const int oldZoomLevel = m_controller->zoomLevel();
emit showPreviewChanged();
-
+
// Enabling or disabling the preview might change the icon size of the view.
// As the view does not emit a signal when the icon size has been changed,
// the used zoom level of the controller must be adjusted manually:
bool DolphinView::eventFilter(QObject* watched, QEvent* event)
{
- if ((watched == itemView()) && (event->type() == QEvent::FocusIn)) {
- m_controller->requestActivation();
+ switch (event->type()) {
+ case QEvent::FocusIn:
+ if (watched == itemView()) {
+ m_controller->requestActivation();
+ }
+ break;
+
+ case QEvent::MouseButtonPress:
+ if ((watched == itemView()->viewport()) && (m_expandedViews.count() > 0)) {
+ // Listening to a mousebutton press event to delete expanded views is a
+ // workaround, as it seems impossible for the FolderExpander to know when
+ // a dragging outside a view has been finished. However it works quite well:
+ // A mousebutton press event indicates that a drag operation must be
+ // finished already.
+ deleteExpandedViews();
+ }
+ break;
+
+ case QEvent::DragEnter:
+ if (watched == itemView()->viewport()) {
+ setActive(true);
+ }
+ break;
+
+ default:
+ break;
}
return QWidget::eventFilter(watched, event);
const KUrl& destPath,
QDropEvent* event)
{
- DolphinDropController::dropUrls(destItem, destPath, event, this);
+ DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
}
void DolphinView::updateSorting(DolphinView::Sorting sorting)
return m_tabsForFiles;
}
+bool DolphinView::itemsExpandable() const
+{
+ return (m_detailsView != 0) && m_detailsView->itemsExpandable();
+}
+
void DolphinView::emitContentsMoved()
{
// only emit the contents moved signal if:
}
}
-void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
-{
- if (oldUrl == m_controller->url()) {
- m_controller->setUrl(newUrl);
- }
-}
-
void DolphinView::slotRequestUrlChange(const KUrl& url)
{
emit requestUrlChange(url);
}
}
+void DolphinView::enterDir(const QModelIndex& index, QAbstractItemView* view)
+{
+ // Deleting a view that is the root of a drag operation is not allowed, otherwise
+ // the dragging gets automatically cancelled by Qt. So before entering a new
+ // directory, the current view is remembered in m_expandedViews and deleted
+ // later when the drag operation has been finished (see DolphinView::eventFilter()).
+ m_expandedViews.append(view);
+ m_controller->triggerItem(index);
+}
+
void DolphinView::loadDirectory(const KUrl& url, bool reload)
{
if (!url.isValid()) {
const Mode mode = props.viewMode();
if (m_mode != mode) {
const int oldZoomLevel = m_controller->zoomLevel();
-
+
m_mode = mode;
createView();
emit modeChanged();
-
+
updateZoomLevel(oldZoomLevel);
}
if (itemView() == 0) {
if (showPreview != m_showPreview) {
m_showPreview = showPreview;
m_previewGenerator->setPreviewShown(showPreview);
-
+
const int oldZoomLevel = m_controller->zoomLevel();
emit showPreviewChanged();
-
+
// Enabling or disabling the preview might change the icon size of the view.
// As the view does not emit a signal when the icon size has been changed,
// the used zoom level of the controller must be adjusted manually:
Q_ASSERT(view != 0);
view->installEventFilter(this);
+ view->viewport()->installEventFilter(this);
if (m_mode != ColumnView) {
// Give the view the ability to auto-expand its directories on hovering
FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel);
folderExpander->setEnabled(enabled);
- connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
- m_controller, SLOT(triggerItem(const QModelIndex&)));
+ connect(folderExpander, SIGNAL(enterDir(const QModelIndex&, QAbstractItemView*)),
+ this, SLOT(enterDir(const QModelIndex&, QAbstractItemView*)));
}
m_controller->setItemView(view);
- m_fileItemDelegate = new KFileItemDelegate(view);
+ m_fileItemDelegate = new DolphinFileItemDelegate(view);
m_fileItemDelegate->setShowToolTipWhenElided(false);
+ m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView);
view->setItemDelegate(m_fileItemDelegate);
view->setModel(m_proxyModel);
if (DolphinSettings::instance().generalSettings()->showToolTips()) {
m_toolTipManager = new ToolTipManager(view, m_proxyModel);
+ connect(m_controller, SIGNAL(hideToolTip()),
+ m_toolTipManager, SLOT(hideTip()));
}
m_topLayout->insertWidget(1, view);
m_topLayout->removeWidget(view);
view->close();
- view->deleteLater();
+
+ disconnect(view);
+ m_controller->disconnect(view);
+ view->disconnect();
+
+ bool deleteView = true;
+ foreach (const QAbstractItemView* expandedView, m_expandedViews) {
+ if (view == expandedView) {
+ // the current view got already expanded and must stay alive
+ // until the dragging has been completed
+ deleteView = false;
+ break;
+ }
+ }
+ if (deleteView) {
+ view->deleteLater();
+ }
view = 0;
+
m_iconsView = 0;
m_detailsView = 0;
m_columnView = 0;
{
KUrl::List list = selectedUrls();
if (itemsExpandable() ) {
- list = KonqOperations::simplifiedUrlList(list);
+ list = KDirModel::simplifiedUrlList(list);
}
return list;
}
-bool DolphinView::itemsExpandable() const
+void DolphinView::deleteExpandedViews()
{
- return (m_detailsView != 0) && m_detailsView->itemsExpandable();
+ const QAbstractItemView* view = itemView();
+ foreach (QAbstractItemView* expandedView, m_expandedViews) {
+ if (expandedView != view) {
+ expandedView->deleteLater();
+ }
+ }
+ m_expandedViews.clear();
+}
+
+QMimeData* DolphinView::selectionMimeData() const
+{
+ if (isColumnViewActive()) {
+ return m_columnView->selectionMimeData();
+ }
+
+ const QAbstractItemView* view = itemView();
+ Q_ASSERT((view != 0) && (view->selectionModel() != 0));
+ const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
+ return m_dolphinModel->mimeData(selection.indexes());
}
#include "dolphinview.moc"