mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Prevent dragging on non-writable directories
KFileItemModel::supportsDroppin now returns the rootItem when -1 is passed and checks for write access.
This commit is contained in:
parent
43c2963b52
commit
9967a5cdee
|
@ -324,8 +324,13 @@ int KFileItemModel::indexForKeyboardSearch(const QString &text, int startFromInd
|
|||
|
||||
bool KFileItemModel::supportsDropping(int index) const
|
||||
{
|
||||
const KFileItem item = fileItem(index);
|
||||
return !item.isNull() && (item.isDir() || item.isDesktopFile());
|
||||
KFileItem item;
|
||||
if (index == -1) {
|
||||
item = rootItem();
|
||||
} else {
|
||||
item = fileItem(index);
|
||||
}
|
||||
return !item.isNull() && ((item.isDir() && item.isWritable()) || item.isDesktopFile());
|
||||
}
|
||||
|
||||
QString KFileItemModel::roleDescription(const QByteArray &role) const
|
||||
|
|
|
@ -534,7 +534,7 @@ void KItemListController::slotAutoActivationTimeout()
|
|||
*
|
||||
* See Bug 293200 and 305783
|
||||
*/
|
||||
if (m_model->supportsDropping(index) && m_view->isUnderMouse()) {
|
||||
if (m_view->isUnderMouse()) {
|
||||
if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) {
|
||||
const bool expanded = m_model->isExpanded(index);
|
||||
m_model->setExpanded(index, !expanded);
|
||||
|
@ -738,6 +738,7 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
|
|||
|
||||
const QPointF pos = transform.map(event->pos());
|
||||
KItemListWidget *newHoveredWidget = widgetForDropPos(pos);
|
||||
int index = -1;
|
||||
|
||||
if (oldHoveredWidget != newHoveredWidget) {
|
||||
m_autoActivationTimer->stop();
|
||||
|
@ -755,25 +756,23 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
|
|||
droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0);
|
||||
}
|
||||
|
||||
const int index = newHoveredWidget->index();
|
||||
index = newHoveredWidget->index();
|
||||
|
||||
if (m_model->isDir(index)) {
|
||||
hoveredDir = m_model->url(index);
|
||||
}
|
||||
|
||||
if (!droppingBetweenItems) {
|
||||
if (m_model->supportsDropping(index)) {
|
||||
// Something has been dragged on an item.
|
||||
m_view->hideDropIndicator();
|
||||
if (!newHoveredWidget->isHovered()) {
|
||||
newHoveredWidget->setHovered(true);
|
||||
Q_EMIT itemHovered(index);
|
||||
}
|
||||
// Something has been dragged on an item.
|
||||
m_view->hideDropIndicator();
|
||||
if (!newHoveredWidget->isHovered()) {
|
||||
newHoveredWidget->setHovered(true);
|
||||
Q_EMIT itemHovered(index);
|
||||
}
|
||||
|
||||
if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
|
||||
m_autoActivationTimer->setProperty("index", index);
|
||||
m_autoActivationTimer->start();
|
||||
}
|
||||
if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
|
||||
m_autoActivationTimer->setProperty("index", index);
|
||||
m_autoActivationTimer->start();
|
||||
}
|
||||
} else {
|
||||
m_autoActivationTimer->stop();
|
||||
|
@ -790,8 +789,13 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
|
|||
event->setDropAction(Qt::IgnoreAction);
|
||||
event->ignore();
|
||||
} else {
|
||||
event->setDropAction(event->proposedAction());
|
||||
event->accept();
|
||||
if (m_model->supportsDropping(index)) {
|
||||
event->setDropAction(event->proposedAction());
|
||||
event->accept();
|
||||
} else {
|
||||
event->setDropAction(Qt::IgnoreAction);
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue