#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistheader.h"
#include "kitemviews/kitemlistselectionmanager.h"
-#include "renamedialog.h"
#include "versioncontrol/versioncontrolobserver.h"
#include "viewproperties.h"
#include "views/tooltips/tooltipmanager.h"
#include <KIO/Paste>
#include <KIO/PasteJob>
#include <KIO/PreviewJob>
+#include <KIO/RenameFileDialog>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
#include <QDropEvent>
#include <QGraphicsSceneDragDropEvent>
#include <QMenu>
+#include <QMimeDatabase>
#include <QPixmapCache>
#include <QPointer>
#include <QScrollBar>
+#include <QSize>
#include <QTimer>
#include <QVBoxLayout>
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
- m_topLayout->setMargin(0);
+ m_topLayout->setContentsMargins(0, 0, 0, 0);
// When a new item has been created by the "Create New..." menu, the item should
// get selected and it must be assured that the item will get visible. As the
m_container = new KItemListContainer(controller, this);
m_container->installEventFilter(this);
setFocusProxy(m_container);
- connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip);
- connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip);
+ connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); });
+ connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); });
controller->setSelectionBehavior(KItemListController::MultiSelection);
connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated);
connect(selectionManager, &KItemListSelectionManager::selectionChanged,
this, &DolphinView::slotSelectionChanged);
+#ifdef HAVE_BALOO
m_toolTipManager = new ToolTipManager(this);
connect(m_toolTipManager, &ToolTipManager::urlActivated, this, &DolphinView::urlActivated);
+#endif
m_versionControlObserver = new VersionControlObserver(this);
+ m_versionControlObserver->setView(this);
m_versionControlObserver->setModel(m_model);
connect(m_versionControlObserver, &VersionControlObserver::infoMessage, this, &DolphinView::infoMessage);
connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, &DolphinView::errorMessage);
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)
connect(m_view, &DolphinItemListView::roleEditingFinished,
this, &DolphinView::slotRoleEditingFinished);
} else {
- RenameDialog* dialog = new RenameDialog(this, items);
-
- connect(dialog, &RenameDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished);
+ KIO::RenameFileDialog* dialog = new KIO::RenameFileDialog(items, this);
+ connect(dialog, &KIO::RenameFileDialog::renamingFinished,
+ this, &DolphinView::slotRenameDialogRenamingFinished);
- dialog->setAttribute(Qt::WA_DeleteOnClose);
- dialog->show();
- dialog->raise();
- dialog->activateWindow();
+ dialog->open();
}
// Assure that the current index remains visible when KFileItemModel
QApplication::clipboard()->setMimeData(mimeData);
}
-void DolphinView::copySelectedItems()
+void DolphinView::copySelectedItemsToClipboard()
{
QMimeData* mimeData = selectionMimeData();
QApplication::clipboard()->setMimeData(mimeData);
}
}
+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, KIO::HideProgressInfo);
+ KJobWidgets::setWindow(job, this);
+
+ if (job) {
+ newSelection << duplicateURL;
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+ }
+ }
+
+ forceUrlsSelection(newSelection.first(), newSelection);
+}
+
void DolphinView::stopLoading()
{
m_model->cancelDirectoryLoading();
void DolphinView::updatePalette()
{
- QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
+ QColor color = KColorScheme(isActiveWindow() ? QPalette::Active : QPalette::Inactive, KColorScheme::View).background().color();
if (!m_active) {
color.setAlpha(150);
}
QPixmapCache::clear();
break;
+ case QEvent::WindowActivate:
+ case QEvent::WindowDeactivate:
+ updatePalette();
+ break;
+
case QEvent::KeyPress:
+ hideToolTip(ToolTipManager::HideBehavior::Instantly);
if (GeneralSettings::useTabForSwitchingSplitView()) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers() == Qt::NoModifier) {
case QEvent::GraphicsSceneDragEnter:
if (watched == m_view) {
m_dragging = true;
+ abortTwoClicksRenaming();
}
break;
const QUrl& url = openItemAsFolderUrl(item);
if (!url.isEmpty()) { // Open folders in new tabs
- emit tabRequested(url);
+ emit tabRequested(url, DolphinTabWidget::AfterLastTab);
} else {
items.append(item);
}
const KFileItem& item = m_model->fileItem(index);
const QUrl& url = openItemAsFolderUrl(item);
if (!url.isEmpty()) {
- emit tabRequested(url);
+ emit tabRequested(url, DolphinTabWidget::AfterCurrentTab);
} else if (isTabsForFilesEnabled()) {
- emit tabRequested(item.url());
+ emit tabRequested(item.url(), DolphinTabWidget::AfterCurrentTab);
}
}
const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
itemRect.moveTo(pos);
+#ifdef HAVE_BALOO
m_toolTipManager->showToolTip(item, itemRect, nativeParentWidget()->windowHandle());
+#endif
}
emit requestItemInfo(item);
void DolphinView::slotItemUnhovered(int index)
{
- Q_UNUSED(index);
+ Q_UNUSED(index)
hideToolTip();
emit requestItemInfo(KFileItem());
}
void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons)
{
- Q_UNUSED(itemIndex);
+ Q_UNUSED(itemIndex)
hideToolTip();
void DolphinView::slotSelectedItemTextPressed(int index)
{
- if (GeneralSettings::renameInline()) {
+ if (GeneralSettings::renameInline() && !m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
const KFileItem item = m_model->fileItem(index);
const KFileItemListProperties capabilities(KFileItemList() << item);
if (capabilities.supportsMoving()) {
emit errorMessage(job->errorString());
}
if (!m_selectedUrls.isEmpty()) {
- m_selectedUrls << KDirModel::simplifiedUrlList(m_selectedUrls);
+ m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls);
}
}
return QUrl();
}
+void DolphinView::resetZoomLevel()
+{
+ ViewModeSettings::ViewMode mode;
+
+ switch (m_mode) {
+ case IconsView: mode = ViewModeSettings::IconsMode; break;
+ case CompactView: mode = ViewModeSettings::CompactMode; break;
+ case DetailsView: mode = ViewModeSettings::DetailsMode; break;
+ }
+ const ViewModeSettings settings(mode);
+ const QSize iconSize = QSize(settings.iconSize(), settings.iconSize());
+ setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(iconSize));
+}
+
void DolphinView::observeCreatedItem(const QUrl& url)
{
if (m_active) {
}
}
-void DolphinView::hideToolTip()
+void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
{
+#ifdef HAVE_BALOO
if (GeneralSettings::showToolTips()) {
- m_toolTipManager->hideToolTip();
+ m_toolTipManager->hideToolTip(behavior);
}
+#endif
}
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();
+ }
}
}
}
{
const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
- // verify that only one item is selected and that no item is dragged
- if (selectionManager->selectedItems().count() == 1 && !m_dragging) {
+ // verify that only one item is selected
+ if (selectionManager->selectedItems().count() == 1) {
const int index = selectionManager->currentItem();
const QUrl fileItemUrl = m_model->fileItem(index).url();
void DolphinView::slotDirectoryLoadingStarted()
{
// Disable the writestate temporary until it can be determined in a fast way
- // in DolphinView::slotLoadingCompleted()
+ // in DolphinView::slotDirectoryLoadingCompleted()
if (m_isFolderWritable) {
m_isFolderWritable = false;
emit writeStateChanged(m_isFolderWritable);
void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous)
{
- Q_UNUSED(previous);
+ Q_UNUSED(previous)
Q_ASSERT(m_model->sortOrder() == current);
ViewProperties props(viewPropertiesUrl());
void DolphinView::slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous)
{
- Q_UNUSED(previous);
+ Q_UNUSED(previous)
Q_ASSERT(m_model->sortRole() == current);
ViewProperties props(viewPropertiesUrl());
void DolphinView::slotVisibleRolesChangedByHeader(const QList<QByteArray>& current,
const QList<QByteArray>& previous)
{
- Q_UNUSED(previous);
+ Q_UNUSED(previous)
Q_ASSERT(m_container->controller()->view()->visibleRoles() == current);
const QList<QByteArray> previousVisibleRoles = m_visibleRoles;
if (role == "text") {
const KFileItem oldItem = m_model->fileItem(index);
const QString newName = value.toString();
- if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
+ if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1Char('.') && newName != QLatin1String("..")) {
const QUrl oldUrl = oldItem.url();
QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
+#ifndef Q_OS_WIN
+ //Confirm hiding file/directory by renaming inline
+ if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) {
+ KGuiItem yesGuiItem(KStandardGuiItem::yes());
+ yesGuiItem.setText(i18nc("@action:button", "Rename and Hide"));
+
+ const auto code = KMessageBox::questionYesNo(this,
+ oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
+ "Do you still want to rename it?")
+ : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
+ "Do you still want to rename it?"),
+ oldItem.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
+ yesGuiItem,
+ KStandardGuiItem::cancel(),
+ QStringLiteral("ConfirmHide")
+ );
+
+ if (code == KMessageBox::No) {
+ return;
+ }
+ }
+#endif
+
const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
if (!newNameExistsAlready) {
// Only change the data in the model if no item with the new name