]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
DolphinView: rename copySelectedItems to copySelectedItemsToClipboard
[dolphin.git] / src / views / dolphinview.cpp
index 776436032e1e0815e29866febed011ef8b770c35..c98929ead97dbfc545bb6bf783d339f7317c1604 100644 (file)
@@ -364,7 +364,7 @@ void DolphinView::markUrlAsCurrent(const QUrl &url)
     m_scrollToCurrentItem = true;
 }
 
-void DolphinView::selectItems(const QRegExp& pattern, bool enabled)
+void DolphinView::selectItems(const QRegularExpression &regexp, bool enabled)
 {
     const KItemListSelectionManager::SelectionMode mode = enabled
                                                         ? KItemListSelectionManager::Select
@@ -373,7 +373,7 @@ void DolphinView::selectItems(const QRegExp& pattern, bool enabled)
 
     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)
@@ -686,7 +686,7 @@ void DolphinView::cutSelectedItems()
     QApplication::clipboard()->setMimeData(mimeData);
 }
 
-void DolphinView::copySelectedItems()
+void DolphinView::copySelectedItemsToClipboard()
 {
     QMimeData* mimeData = selectionMimeData();
     QApplication::clipboard()->setMimeData(mimeData);
@@ -719,24 +719,25 @@ void DolphinView::duplicateSelectedItems()
     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(i18nc("<file path> copy", "%1 copy", originalURL.path()));
+            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 directoryPath = originalURL.adjusted(QUrl::RemoveFilename).path();
             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(i18nc("<file path><filename> copy.<extension>", "%1%2 copy%3", directoryPath, originalFilenameWithoutExtension, originalExtension));
+            duplicateURL.setPath(originalDirectoryPath + i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension) + originalExtension);
         }
 
         KIO::CopyJob* job = KIO::copyAs(originalURL, duplicateURL, KIO::HideProgressInfo);
@@ -747,6 +748,8 @@ void DolphinView::duplicateSelectedItems()
             KIO::FileUndoManager::self()->recordCopyJob(job);
         }
     }
+
+    forceUrlsSelection(newSelection.first(), newSelection);
 }
 
 void DolphinView::stopLoading()
@@ -1197,7 +1200,7 @@ void DolphinView::slotPasteJobResult(KJob *job)
         emit errorMessage(job->errorString());
     }
     if (!m_selectedUrls.isEmpty()) {
-        m_selectedUrls << KDirModel::simplifiedUrlList(m_selectedUrls);
+        m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls);
     }
 }
 
@@ -1490,13 +1493,27 @@ void DolphinView::calculateItemCount(int& fileCount,
                                      KIO::filesize_t& totalFileSize) const
 {
     const int itemCount = m_model->count();
+
+    bool countFileSize = true;
+
+    // In case we have a precomputed value
+    const auto job = KIO::statDetails(m_model->rootItem().url(), KIO::StatJob::SourceSide, KIO::StatRecursiveSize);
+    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();
+            }
         }
     }
 }