mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 06:57:24 -06:00
Allow drop action only on transfer list
Now drop action is only allowed on transfer list, previously it was on main window. Having drop action on the whole main window is not preferred because it could allow drop action on other unrelated widgets, such as execution log or RSS widget which is unexpected behavior. PR #21332.
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <QList>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMimeData>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QShortcut>
|
||||
@@ -57,11 +58,13 @@
|
||||
#include "base/utils/string.h"
|
||||
#include "autoexpandabledialog.h"
|
||||
#include "deletionconfirmationdialog.h"
|
||||
#include "interfaces/iguiapplication.h"
|
||||
#include "mainwindow.h"
|
||||
#include "optionsdialog.h"
|
||||
#include "previewselectdialog.h"
|
||||
#include "speedlimitdialog.h"
|
||||
#include "torrentcategorydialog.h"
|
||||
#include "torrentcreatordialog.h"
|
||||
#include "torrentoptionsdialog.h"
|
||||
#include "trackerentriesdialog.h"
|
||||
#include "transferlistdelegate.h"
|
||||
@@ -123,11 +126,10 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
|
||||
: QTreeView {parent}
|
||||
TransferListWidget::TransferListWidget(IGUIApplication *app, QWidget *parent)
|
||||
: GUIApplicationComponent(app, parent)
|
||||
, m_listModel {new TransferListModel {this}}
|
||||
, m_sortFilterModel {new TransferListSortModel {this}}
|
||||
, m_mainWindow {mainWindow}
|
||||
{
|
||||
// Load settings
|
||||
const bool columnLoaded = loadSettings();
|
||||
@@ -151,7 +153,9 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
setItemsExpandable(false);
|
||||
setAutoScroll(true);
|
||||
setDragDropMode(QAbstractItemView::DragOnly);
|
||||
setAcceptDrops(true);
|
||||
setDragDropMode(QAbstractItemView::DropOnly);
|
||||
setDropIndicatorShown(true);
|
||||
#if defined(Q_OS_MACOS)
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
#endif
|
||||
@@ -431,7 +435,7 @@ void TransferListWidget::permDeleteSelectedTorrents()
|
||||
|
||||
void TransferListWidget::deleteSelectedTorrents(const bool deleteLocalFiles)
|
||||
{
|
||||
if (m_mainWindow->currentTabWidget() != this) return;
|
||||
if (app()->mainWindow()->currentTabWidget() != this) return;
|
||||
|
||||
const QList<BitTorrent::Torrent *> torrents = getSelectedTorrents();
|
||||
if (torrents.empty()) return;
|
||||
@@ -480,26 +484,26 @@ void TransferListWidget::deleteVisibleTorrents()
|
||||
void TransferListWidget::increaseQueuePosSelectedTorrents()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if (m_mainWindow->currentTabWidget() == this)
|
||||
if (app()->mainWindow()->currentTabWidget() == this)
|
||||
BitTorrent::Session::instance()->increaseTorrentsQueuePos(extractIDs(getSelectedTorrents()));
|
||||
}
|
||||
|
||||
void TransferListWidget::decreaseQueuePosSelectedTorrents()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if (m_mainWindow->currentTabWidget() == this)
|
||||
if (app()->mainWindow()->currentTabWidget() == this)
|
||||
BitTorrent::Session::instance()->decreaseTorrentsQueuePos(extractIDs(getSelectedTorrents()));
|
||||
}
|
||||
|
||||
void TransferListWidget::topQueuePosSelectedTorrents()
|
||||
{
|
||||
if (m_mainWindow->currentTabWidget() == this)
|
||||
if (app()->mainWindow()->currentTabWidget() == this)
|
||||
BitTorrent::Session::instance()->topTorrentsQueuePos(extractIDs(getSelectedTorrents()));
|
||||
}
|
||||
|
||||
void TransferListWidget::bottomQueuePosSelectedTorrents()
|
||||
{
|
||||
if (m_mainWindow->currentTabWidget() == this)
|
||||
if (app()->mainWindow()->currentTabWidget() == this)
|
||||
BitTorrent::Session::instance()->bottomTorrentsQueuePos(extractIDs(getSelectedTorrents()));
|
||||
}
|
||||
|
||||
@@ -1354,6 +1358,79 @@ bool TransferListWidget::loadSettings()
|
||||
return header()->restoreState(Preferences::instance()->getTransHeaderState());
|
||||
}
|
||||
|
||||
void TransferListWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (const QMimeData *data = event->mimeData(); data->hasText() || data->hasUrls())
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
event->acceptProposedAction(); // required, otherwise we won't get `dropEvent`
|
||||
}
|
||||
|
||||
void TransferListWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
// remove scheme
|
||||
QStringList files;
|
||||
if (const QMimeData *data = event->mimeData(); data->hasUrls())
|
||||
{
|
||||
const QList<QUrl> urls = data->urls();
|
||||
files.reserve(urls.size());
|
||||
|
||||
for (const QUrl &url : urls)
|
||||
{
|
||||
if (url.isEmpty())
|
||||
continue;
|
||||
|
||||
files.append(url.isLocalFile()
|
||||
? url.toLocalFile()
|
||||
: url.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
files = data->text().split(u'\n', Qt::SkipEmptyParts);
|
||||
}
|
||||
|
||||
// differentiate ".torrent" files/links & magnet links from others
|
||||
QStringList torrentFiles, otherFiles;
|
||||
torrentFiles.reserve(files.size());
|
||||
otherFiles.reserve(files.size());
|
||||
for (const QString &file : asConst(files))
|
||||
{
|
||||
if (Utils::Misc::isTorrentLink(file))
|
||||
torrentFiles << file;
|
||||
else
|
||||
otherFiles << file;
|
||||
}
|
||||
|
||||
// Download torrents
|
||||
if (!torrentFiles.isEmpty())
|
||||
{
|
||||
for (const QString &file : asConst(torrentFiles))
|
||||
app()->addTorrentManager()->addTorrent(file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create torrent
|
||||
for (const QString &file : asConst(otherFiles))
|
||||
{
|
||||
auto torrentCreator = new TorrentCreatorDialog(this, Path(file));
|
||||
torrentCreator->setAttribute(Qt::WA_DeleteOnClose);
|
||||
torrentCreator->show();
|
||||
|
||||
// currently only handle the first entry
|
||||
// this is a stub that can be expanded later to create many torrents at once
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListWidget::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (event->modifiers() & Qt::ShiftModifier)
|
||||
|
||||
Reference in New Issue
Block a user