+void DolphinView::calculateItemCount(int& fileCount,
+ int& folderCount,
+ KIO::filesize_t& totalFileSize) const
+{
+ foreach (const KFileItem& item, m_viewAccessor.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
+ const KFileItemList list = selectedItems();
+ if (list.isEmpty()) {
+ // when an item is triggered, it is temporary selected but selectedItems()
+ // will return an empty list
+ return text;
+ }
+
+ KFileItemList::const_iterator it = list.begin();
+ const KFileItemList::const_iterator end = list.end();
+ while (it != end) {
+ const KFileItem& item = *it;
+ if (item.isDir()) {
+ ++folderCount;
+ } else {
+ ++fileCount;
+ totalFileSize += item.size();
+ }
+ ++it;
+ }
+
+ 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;
+ }
+ }
+ } else {
+ calculateItemCount(fileCount, folderCount, totalFileSize);
+ text = KIO::itemsSummaryString(fileCount + folderCount,
+ fileCount, folderCount,
+ totalFileSize, true);
+ }
+
+ return text;
+}
+
+QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
+{
+ return m_controller->versionControlActions(items);
+}
+
+void DolphinView::setUrl(const KUrl& url)
+{
+ m_newFileNames.clear();
+ updateView(url, KUrl());
+}
+
+void DolphinView::changeSelection(const KFileItemList& selection)
+{
+ clearSelection();
+ if (selection.isEmpty()) {
+ return;
+ }
+ const KUrl& baseUrl = url();
+ KUrl url;
+ QItemSelection newSelection;
+ foreach(const KFileItem& item, selection) {
+ url = item.url().upUrl();
+ if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
+ newSelection.select(index, index);
+ }
+ }
+ m_viewAccessor.itemView()->selectionModel()->select(newSelection,
+ QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Current);
+}
+
+void DolphinView::renameSelectedItems()
+{
+ 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.
+ QPointer<RenameDialog> dialog = new RenameDialog(this, items);
+ if (dialog->exec() == QDialog::Rejected) {
+ delete dialog;
+ return;
+ }
+
+ const QString newName = dialog->newName();
+ if (newName.isEmpty()) {
+ emit errorMessage(dialog->errorString());
+ delete dialog;
+ return;
+ }
+ delete dialog;
+
+ // the selection would be invalid after renaming the items, so just clear
+ // it before
+ clearSelection();
+
+ // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
+ // 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) {
+ const KUrl& oldUrl = item.url();
+ QString number;
+ number.setNum(index++);
+
+ QString name = newName;
+ name.replace('#', number);
+
+ if (oldUrl.fileName() != name) {
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(name);
+ KonqOperations::rename(this, oldUrl, newUrl);
+ }
+ }
+ } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
+ Q_ASSERT(itemCount == 1);
+ const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first());
+ const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
+ m_viewAccessor.itemView()->edit(proxyIndex);
+ } else {
+ Q_ASSERT(itemCount == 1);
+
+ QPointer<RenameDialog> dialog = new RenameDialog(this, items);
+ if (dialog->exec() == QDialog::Rejected) {
+ delete dialog;
+ return;
+ }
+
+ const QString newName = dialog->newName();
+ if (newName.isEmpty()) {
+ emit errorMessage(dialog->errorString());
+ delete dialog;
+ return;
+ }
+ delete dialog;
+
+ const KUrl& oldUrl = items.first().url();
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(newName);
+ KonqOperations::rename(this, oldUrl, newUrl);
+ }
+
+ // assure that the current index remains visible when KDirLister
+ // will notify the view about changed items
+ m_assureVisibleCurrentIndex = true;
+}
+
+void DolphinView::trashSelectedItems()
+{
+ const KUrl::List list = simplifiedSelectedUrls();
+ KonqOperations::del(this, KonqOperations::TRASH, list);
+}
+
+void DolphinView::deleteSelectedItems()
+{
+ const KUrl::List list = simplifiedSelectedUrls();
+ const bool del = KonqOperations::askDeleteConfirmation(list,
+ KonqOperations::DEL,
+ KonqOperations::DEFAULT_CONFIRMATION,
+ this);
+
+ if (del) {
+ KIO::Job* job = KIO::del(list);
+ connect(job, SIGNAL(result(KJob*)),
+ this, SLOT(slotDeleteFileFinished(KJob*)));
+ }
+}
+
+void DolphinView::cutSelectedItems()
+{
+ QMimeData* mimeData = selectionMimeData();
+ KonqMimeData::addIsCutSelection(mimeData, true);
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void DolphinView::copySelectedItems()
+{
+ QMimeData* mimeData = selectionMimeData();
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void DolphinView::paste()
+{
+ pasteToUrl(url());
+}
+
+void DolphinView::pasteIntoFolder()
+{
+ const KFileItemList items = selectedItems();
+ if ((items.count() == 1) && items.first().isDir()) {
+ pasteToUrl(items.first().url());
+ }
+}
+
+void DolphinView::setShowPreview(bool show)
+{
+ if (m_showPreview == show) {
+ return;
+ }
+
+ const KUrl viewPropsUrl = rootUrl();
+ ViewProperties props(viewPropsUrl);
+ props.setShowPreview(show);
+
+ m_showPreview = 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:
+ updateZoomLevel(oldZoomLevel);
+}
+
+void DolphinView::setShowHiddenFiles(bool show)
+{
+ if (m_viewAccessor.dirLister()->showingDotFiles() == show) {
+ return;
+ }
+
+ const KUrl viewPropsUrl = rootUrl();
+ ViewProperties props(viewPropsUrl);
+ props.setShowHiddenFiles(show);
+
+ m_viewAccessor.dirLister()->setShowingDotFiles(show);
+ emit showHiddenFilesChanged();
+}
+
+void DolphinView::setCategorizedSorting(bool categorized)
+{
+ if (categorized == categorizedSorting()) {
+ return;
+ }
+
+ // setCategorizedSorting(true) may only get invoked
+ // if the view supports categorized sorting
+ Q_ASSERT(!categorized || supportsCategorizedSorting());
+
+ ViewProperties props(rootUrl());
+ props.setCategorizedSorting(categorized);
+ props.save();
+
+ m_storedCategorizedSorting = categorized;
+ m_viewAccessor.proxyModel()->setCategorizedModel(categorized);
+
+ emit categorizedSortingChanged();
+}
+
+void DolphinView::toggleSortOrder()
+{
+ const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ?
+ Qt::DescendingOrder :
+ Qt::AscendingOrder;
+ setSortOrder(order);
+}
+
+void DolphinView::toggleSortFoldersFirst()
+{
+ setSortFoldersFirst(!sortFoldersFirst());
+}
+
+void DolphinView::toggleAdditionalInfo(QAction* action)
+{
+ const KFileItemDelegate::Information info =
+ static_cast<KFileItemDelegate::Information>(action->data().toInt());
+
+ KFileItemDelegate::InformationList list = additionalInfo();
+
+ const bool show = action->isChecked();
+
+ const int index = list.indexOf(info);
+ const bool containsInfo = (index >= 0);
+ if (show && !containsInfo) {
+ list.append(info);
+ setAdditionalInfo(list);
+ } else if (!show && containsInfo) {
+ list.removeAt(index);
+ setAdditionalInfo(list);
+ Q_ASSERT(list.indexOf(info) < 0);
+ }