mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-15 12:41:36 +03:00
Enable drag n drop to create torrent on mainwindow
This commit is contained in:
parent
386b93bb0f
commit
908481885c
2 changed files with 30 additions and 3 deletions
|
@ -1068,11 +1068,16 @@ void MainWindow::closeEvent(QCloseEvent *e)
|
||||||
|
|
||||||
// Display window to create a torrent
|
// Display window to create a torrent
|
||||||
void MainWindow::on_actionCreateTorrent_triggered()
|
void MainWindow::on_actionCreateTorrent_triggered()
|
||||||
|
{
|
||||||
|
createTorrentTriggered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createTorrentTriggered(const QString &path)
|
||||||
{
|
{
|
||||||
if (m_createTorrentDlg)
|
if (m_createTorrentDlg)
|
||||||
m_createTorrentDlg->setFocus();
|
m_createTorrentDlg->setFocus();
|
||||||
else
|
else
|
||||||
m_createTorrentDlg = new TorrentCreatorDlg(this);
|
m_createTorrentDlg = new TorrentCreatorDlg(this, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::event(QEvent *e)
|
bool MainWindow::event(QEvent *e)
|
||||||
|
@ -1126,6 +1131,8 @@ bool MainWindow::event(QEvent *e)
|
||||||
void MainWindow::dropEvent(QDropEvent *event)
|
void MainWindow::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
|
|
||||||
|
// remove scheme
|
||||||
QStringList files;
|
QStringList files;
|
||||||
if (event->mimeData()->hasUrls()) {
|
if (event->mimeData()->hasUrls()) {
|
||||||
const QList<QUrl> urls = event->mimeData()->urls();
|
const QList<QUrl> urls = event->mimeData()->urls();
|
||||||
|
@ -1142,15 +1149,34 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||||
files = event->mimeData()->text().split('\n');
|
files = event->mimeData()->text().split('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add file to download list
|
// differentiate ".torrent" files and others
|
||||||
|
QStringList torrentFiles, otherFiles;
|
||||||
|
foreach (const QString &file, files) {
|
||||||
|
if (file.endsWith(".torrent", Qt::CaseInsensitive))
|
||||||
|
torrentFiles << file;
|
||||||
|
else
|
||||||
|
otherFiles << file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download torrents
|
||||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||||
foreach (QString file, files) {
|
foreach (const QString &file, torrentFiles) {
|
||||||
qDebug("Dropped file %s on download list", qPrintable(file));
|
qDebug("Dropped file %s on download list", qPrintable(file));
|
||||||
if (useTorrentAdditionDialog)
|
if (useTorrentAdditionDialog)
|
||||||
AddNewTorrentDialog::show(file, this);
|
AddNewTorrentDialog::show(file, this);
|
||||||
else
|
else
|
||||||
BitTorrent::Session::instance()->addTorrent(file);
|
BitTorrent::Session::instance()->addTorrent(file);
|
||||||
}
|
}
|
||||||
|
if (!torrentFiles.isEmpty()) return;
|
||||||
|
|
||||||
|
// Create torrent
|
||||||
|
foreach (const QString &file, otherFiles) {
|
||||||
|
createTorrentTriggered(file);
|
||||||
|
|
||||||
|
// currently only hande the first entry
|
||||||
|
// this is a stub that can be expanded later to create many torrents at once
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode if we accept drag 'n drop or not
|
// Decode if we accept drag 'n drop or not
|
||||||
|
|
|
@ -202,6 +202,7 @@ private:
|
||||||
bool event(QEvent *e) override;
|
bool event(QEvent *e) override;
|
||||||
void displayRSSTab(bool enable);
|
void displayRSSTab(bool enable);
|
||||||
void displaySearchTab(bool enable);
|
void displaySearchTab(bool enable);
|
||||||
|
void createTorrentTriggered(const QString &path = QString());
|
||||||
|
|
||||||
Ui::MainWindow *m_ui;
|
Ui::MainWindow *m_ui;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue