-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch newest releases of ytdlp and mpv automagically
- Loading branch information
1 parent
0367e3d
commit 8537efc
Showing
4 changed files
with
105 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,26 +47,6 @@ FeedsProxyModel::~FeedsProxyModel() { | |
qDebugNN << LOGSEC_FEEDMODEL << "Destroying FeedsProxyModel instance"; | ||
} | ||
|
||
bool FeedsProxyModel::canDropMimeData(const QMimeData* data, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Qt::DropAction action, | ||
int row, | ||
int column, | ||
const QModelIndex& parent) const { | ||
|
||
auto src_idx = row < 0 ? mapToSource(parent) : mapToSource(index(row, column, parent)); | ||
auto* src_item = m_sourceModel->itemForIndex(src_idx); | ||
|
||
if (src_item != nullptr) { | ||
auto can_drop = src_item->kind() == RootItem::Kind::ServiceRoot || src_item->kind() == RootItem::Kind::Category || | ||
src_item->kind() == RootItem::Kind::Feed; | ||
|
||
return QSortFilterProxyModel::canDropMimeData(data, action, row, column, parent) && can_drop; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
QModelIndexList FeedsProxyModel::match(const QModelIndex& start, | ||
int role, | ||
const QVariant& value, | ||
|
@@ -183,6 +163,75 @@ QModelIndexList FeedsProxyModel::match(const QModelIndex& start, | |
return result; | ||
} | ||
|
||
bool FeedsProxyModel::canDropMimeData(const QMimeData* data, | ||
This comment has been minimized.
Sorry, something went wrong.
martinrotter
Author
Owner
|
||
Qt::DropAction action, | ||
int row, | ||
int column, | ||
const QModelIndex& parent) const { | ||
QByteArray dragged_items_data = data->data(QSL(MIME_TYPE_ITEM_POINTER)); | ||
QDataStream stream(&dragged_items_data, QIODevice::OpenModeFlag::ReadOnly); | ||
const bool order_change = row >= 0 && !m_sortAlphabetically; | ||
const QModelIndex target_parent = mapToSource(parent); | ||
|
||
if (stream.atEnd()) { | ||
return false; | ||
} | ||
|
||
quintptr pointer_to_item; | ||
stream >> pointer_to_item; | ||
|
||
RootItem* dragged_item = RootItemPtr(pointer_to_item); | ||
|
||
// Dragged item must service root, feed or category. | ||
// | ||
// If row is less then zero, it means we are moving dragged item into new parent. | ||
// | ||
// Otherwise the target row identifies the item just below the drop target placement insertion line. | ||
QModelIndex target_idx = order_change ? mapToSource(index(row, 0, parent)) : target_parent; | ||
RootItem* target_item = m_sourceModel->itemForIndex(target_idx); | ||
RootItem* target_parent_item = m_sourceModel->itemForIndex(target_parent); | ||
|
||
if (target_item != nullptr) { | ||
qDebugNN << LOGSEC_FEEDMODEL << "Considering target for drop operation:" << QUOTE_W_SPACE(target_item->title()) | ||
<< "with index" << QUOTE_W_SPACE(target_idx) | ||
<< "and target parent:" << QUOTE_W_SPACE_DOT(target_parent_item->title()); | ||
|
||
switch (dragged_item->kind()) { | ||
case RootItem::Kind::Feed: | ||
// Feeds can be reordered or inserted under service root or category. | ||
return target_parent_item->kind() == RootItem::Kind::Category || | ||
target_parent_item->kind() == RootItem::Kind::ServiceRoot; | ||
|
||
case RootItem::Kind::Category: | ||
// Categories can be reordered or inserted under service root or another category. | ||
break; | ||
|
||
case RootItem::Kind::ServiceRoot: | ||
// Service root cannot be inserted under different parent, can only be reordered. | ||
if (!order_change) { | ||
return false; | ||
} | ||
else { | ||
return target_parent_item->kind() == RootItem::Kind::Root; | ||
} | ||
|
||
default: | ||
return false; | ||
} | ||
|
||
return false; | ||
/* | ||
auto can_drop = target_item->kind() == RootItem::Kind::ServiceRoot || | ||
target_item->kind() == RootItem::Kind::Category || target_item->kind() == RootItem::Kind::Feed; | ||
return QSortFilterProxyModel::canDropMimeData(data, action, row, column, parent) && can_drop; | ||
*/ | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
bool FeedsProxyModel::dropMimeData(const QMimeData* data, | ||
Qt::DropAction action, | ||
int row, | ||
|
@@ -212,7 +261,7 @@ bool FeedsProxyModel::dropMimeData(const QMimeData* data, | |
stream >> pointer_to_item; | ||
|
||
// We have item we want to drag, we also determine the target item. | ||
auto* dragged_item = RootItemPtr(pointer_to_item); | ||
RootItemPtr dragged_item = RootItemPtr(pointer_to_item); | ||
RootItem* target_item = m_sourceModel->itemForIndex(source_parent); | ||
ServiceRoot* dragged_item_root = dragged_item->getParentServiceRoot(); | ||
ServiceRoot* target_item_root = target_item->getParentServiceRoot(); | ||
|
@@ -240,16 +289,26 @@ bool FeedsProxyModel::dropMimeData(const QMimeData* data, | |
// Drag & drop is supported by the dragged item and was | ||
// completed on data level and in item hierarchy. | ||
emit requireItemValidationAfterDragDrop(m_sourceModel->indexForItem(dragged_item)); | ||
|
||
qDebugNN << LOGSEC_FEEDMODEL << "Dropping item" << QUOTE_W_SPACE(dragged_item->title()) << "under new parent" | ||
<< QUOTE_W_SPACE_DOT(target_item->title()); | ||
} | ||
|
||
if (order_change) { | ||
auto db = qApp->database()->driver()->connection(metaObject()->className()); | ||
RootItem* place_above_item = m_sourceModel->itemForIndex(mapToSource(index(row, 0, parent))); | ||
int target_sort_order = place_above_item->sortOrder(); | ||
|
||
qDebugNN << LOGSEC_FEEDMODEL << "Resorting/placing item" << QUOTE_W_SPACE(dragged_item->title()) | ||
<< "with sord order" << QUOTE_W_SPACE(dragged_item->sortOrder()) << "above item" | ||
<< QUOTE_W_SPACE(place_above_item->title()) << "with new sort order" | ||
<< QUOTE_W_SPACE_DOT(target_sort_order); | ||
|
||
if (row > dragged_item->sortOrder()) { | ||
row--; | ||
if (target_sort_order > dragged_item->sortOrder()) { | ||
target_sort_order--; | ||
} | ||
|
||
DatabaseQueries::moveItem(dragged_item, false, false, row, db); | ||
DatabaseQueries::moveItem(dragged_item, false, false, target_sort_order, db); | ||
} | ||
|
||
invalidate(); | ||
|
This is here by mistake, the fix for drag/drop is not done, will be soon.