-/***************************************************************************
- * Copyright (C) 2006-2009 by Peter Penz <peter.penz19@gmail.com> *
- * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2006 Gregor Kališnik <gregor@podnapisi.net>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "dolphinview.h"
#include <QDropEvent>
#include <QGraphicsSceneDragDropEvent>
#include <QMenu>
+#include <QMimeDatabase>
#include <QPixmapCache>
#include <QPointer>
#include <QScrollBar>
connect(controller, &KItemListController::escapePressed, this, &DolphinView::stopLoading);
connect(controller, &KItemListController::modelChanged, this, &DolphinView::slotModelChanged);
connect(controller, &KItemListController::selectedItemTextPressed, this, &DolphinView::slotSelectedItemTextPressed);
+ connect(controller, &KItemListController::increaseZoom, this, &DolphinView::slotIncreaseZoom);
+ connect(controller, &KItemListController::decreaseZoom, this, &DolphinView::slotDecreaseZoom);
+ connect(controller, &KItemListController::swipeUp, this, &DolphinView::slotSwipeUp);
connect(m_model, &KFileItemModel::directoryLoadingStarted, this, &DolphinView::slotDirectoryLoadingStarted);
connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted);
m_scrollToCurrentItem = true;
}
-void DolphinView::selectItems(const QRegExp& pattern, bool enabled)
+void DolphinView::selectItems(const QRegularExpression ®exp, bool enabled)
{
const KItemListSelectionManager::SelectionMode mode = enabled
? KItemListSelectionManager::Select
for (int index = 0; index < m_model->count(); index++) {
const KFileItem item = m_model->fileItem(index);
- if (pattern.exactMatch(item.text())) {
+ if (regexp.match(item.text()).hasMatch()) {
// An alternative approach would be to store the matching items in a KItemSet and
// select them in one go after the loop, but we'd need a new function
// KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
if (m_container->controller()->selectionManager()->hasSelection()) {
// Give a summary of the status of the selected files
const KFileItemList list = selectedItems();
- foreach (const KFileItem& item, list) {
+ for (const KFileItem& item : list) {
if (item.isDir()) {
++folderCount;
} else {
}
}
-void DolphinView::cutSelectedItems()
+void DolphinView::cutSelectedItemsToClipboard()
{
QMimeData* mimeData = selectionMimeData();
KIO::setClipboardDataCut(mimeData, true);
QApplication::clipboard()->setMimeData(mimeData);
}
-void DolphinView::copySelectedItems()
+void DolphinView::copySelectedItemsToClipboard()
{
QMimeData* mimeData = selectionMimeData();
QApplication::clipboard()->setMimeData(mimeData);
}
+void DolphinView::copySelectedItems(const KFileItemList &selection, const QUrl &destinationUrl)
+{
+ KIO::CopyJob* job = KIO::copy(selection.urlList(), destinationUrl, KIO::DefaultFlags);
+ KJobWidgets::setWindow(job, this);
+
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotCopyingDone);
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+}
+
+void DolphinView::moveSelectedItems(const KFileItemList &selection, const QUrl &destinationUrl)
+{
+ KIO::CopyJob* job = KIO::move(selection.urlList(), destinationUrl, KIO::DefaultFlags);
+ KJobWidgets::setWindow(job, this);
+
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotCopyingDone);
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+
+}
+
void DolphinView::paste()
{
pasteToUrl(url());
}
}
+void DolphinView::duplicateSelectedItems()
+{
+ const KFileItemList itemList = selectedItems();
+ if (itemList.isEmpty()) {
+ return;
+ }
+
+ const QMimeDatabase db;
+
+ // Duplicate all selected items and append "copy" to the end of the file name
+ // but before the filename extension, if present
+ QList<QUrl> newSelection;
+ for (const auto &item : itemList) {
+ const QUrl originalURL = item.url();
+ const QString originalDirectoryPath = originalURL.adjusted(QUrl::RemoveFilename).path();
+ const QString originalFileName = item.name();
+
+ QString extension = db.suffixForFileName(originalFileName);
+
+ QUrl duplicateURL = originalURL;
+
+ // No extension; new filename is "<oldfilename> copy"
+ if (extension.isEmpty()) {
+ duplicateURL.setPath(originalDirectoryPath + i18nc("<filename> copy", "%1 copy", originalFileName));
+ // There's an extension; new filename is "<oldfilename> copy.<extension>"
+ } else {
+ // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
+ extension = QLatin1String(".") + extension;
+ const QString originalFilenameWithoutExtension = originalFileName.chopped(extension.size());
+ // Preserve file's original filename extension in case the casing differs
+ // from what QMimeDatabase::suffixForFileName() returned
+ const QString originalExtension = originalFileName.right(extension.size());
+ duplicateURL.setPath(originalDirectoryPath + i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension) + originalExtension);
+ }
+
+ KIO::CopyJob* job = KIO::copyAs(originalURL, duplicateURL);
+ KJobWidgets::setWindow(job, this);
+
+ if (job) {
+ newSelection << duplicateURL;
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+ }
+ }
+
+ forceUrlsSelection(newSelection.first(), newSelection);
+}
+
void DolphinView::stopLoading()
{
m_model->cancelDirectoryLoading();
QPointer<QMenu> menu = new QMenu(QApplication::activeWindow());
KItemListView* view = m_container->controller()->view();
- const QSet<QByteArray> visibleRolesSet = view->visibleRoles().toSet();
+ const QList<QByteArray> visibleRolesSet = view->visibleRoles();
bool indexingEnabled = false;
#ifdef HAVE_BALOO
// Add all roles to the menu that can be shown or hidden by the user
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
- foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+ for (const KFileItemModel::RoleInfo& info : rolesInfo) {
if (info.role == "text") {
// It should not be possible to hide the "text" role
continue;
// Apply the current column-widths as custom column-widths and turn
// off the automatic resizing of the columns
QList<int> columnWidths;
- columnWidths.reserve(view->visibleRoles().count());
- foreach (const QByteArray& role, view->visibleRoles()) {
+ const auto visibleRoles = view->visibleRoles();
+ columnWidths.reserve(visibleRoles.count());
+ for (const QByteArray& role : visibleRoles) {
columnWidths.append(header->columnWidth(role));
}
props.setHeaderColumnWidths(columnWidths);
QList<int> columnWidths;
if (!header->automaticColumnResizing()) {
- columnWidths.reserve(view->visibleRoles().count());
- foreach (const QByteArray& role, view->visibleRoles()) {
+ const auto visibleRoles = view->visibleRoles();
+ columnWidths.reserve(visibleRoles.count());
+ for (const QByteArray& role : visibleRoles) {
columnWidths.append(header->columnWidth(role));
}
}
columnWidths.clear();
columnWidths.reserve(visibleRoles.count());
const KItemListHeader* header = m_view->header();
- foreach (const QByteArray& role, visibleRoles) {
+ for (const QByteArray& role : visibleRoles) {
const int width = header->columnWidth(role);
columnWidths.append(width);
}
KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, dropWidget);
if (job) {
- connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult);
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
if (destUrl == url()) {
// Mark the dropped urls as selected.
}
}
+void DolphinView::slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to)
+{
+ slotItemCreated(to);
+}
+
void DolphinView::slotItemCreated(const QUrl& url)
{
if (m_markFirstNewlySelectedItemAsCurrent) {
m_selectedUrls << url;
}
-void DolphinView::slotPasteJobResult(KJob *job)
+void DolphinView::slotJobResult(KJob *job)
{
if (job->error()) {
emit errorMessage(job->errorString());
}
if (!m_selectedUrls.isEmpty()) {
- m_selectedUrls << KDirModel::simplifiedUrlList(m_selectedUrls);
+ m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls);
}
}
if (GeneralSettings::showToolTips()) {
m_toolTipManager->hideToolTip(behavior);
}
+#else
+ Q_UNUSED(behavior)
#endif
}
KIO::filesize_t& totalFileSize) const
{
const int itemCount = m_model->count();
+
+ bool countFileSize = true;
+
+ if (!m_model->rootItem().url().isValid()) {
+ return;
+ }
+
+ // In case we have a precomputed value
+ const auto job = KIO::statDetails(m_model->rootItem().url(), KIO::StatJob::SourceSide, KIO::StatRecursiveSize, KIO::HideProgressInfo);
+ job->exec();
+ const auto entry = job->statResult();
+ if (entry.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE)) {
+ totalFileSize = static_cast<KIO::filesize_t>(entry.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE));
+ countFileSize = false;
+ }
+
for (int i = 0; i < itemCount; ++i) {
const KFileItem item = m_model->fileItem(i);
if (item.isDir()) {
++folderCount;
} else {
++fileCount;
- totalFileSize += item.size();
+ if (countFileSize) {
+ totalFileSize += item.size();
+ }
}
}
}
m_clearSelectionBeforeSelectingNewItems = true;
m_markFirstNewlySelectedItemAsCurrent = true;
connect(job, &KIO::PasteJob::itemCreated, this, &DolphinView::slotItemCreated);
- connect(job, &KIO::PasteJob::result, this, &DolphinView::slotPasteJobResult);
+ connect(job, &KIO::PasteJob::result, this, &DolphinView::slotJobResult);
}
QList<QUrl> DolphinView::simplifiedSelectedUrls() const
const KFileItemList items = selectedItems();
urls.reserve(items.count());
- foreach (const KFileItem& item, items) {
+ for (const KFileItem& item : items) {
urls.append(item.url());
}
markUrlAsCurrent(current);
markUrlsAsSelected(selected);
}
+
+void DolphinView::copyPathToClipboard()
+{
+ const KFileItemList list = selectedItems();
+ if (list.isEmpty()) {
+ return;
+ }
+ const KFileItem& item = list.at(0);
+ QString path = item.localPath();
+ if (path.isEmpty()) {
+ path = item.url().toDisplayString();
+ }
+ QClipboard* clipboard = QApplication::clipboard();
+ if (clipboard == nullptr) {
+ return;
+ }
+ clipboard->setText(path);
+}
+
+void DolphinView::slotIncreaseZoom()
+{
+ setZoomLevel(zoomLevel() + 1);
+}
+
+void DolphinView::slotDecreaseZoom()
+{
+ setZoomLevel(zoomLevel() - 1);
+}
+
+void DolphinView::slotSwipeUp()
+{
+ emit goUpRequested();
+}