Browse Source

Enable drag n drop to create torrent on mainwindow

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
908481885c
  1. 32
      src/gui/mainwindow.cpp
  2. 1
      src/gui/mainwindow.h

32
src/gui/mainwindow.cpp

@ -1068,11 +1068,16 @@ void MainWindow::closeEvent(QCloseEvent *e) @@ -1068,11 +1068,16 @@ void MainWindow::closeEvent(QCloseEvent *e)
// Display window to create a torrent
void MainWindow::on_actionCreateTorrent_triggered()
{
createTorrentTriggered();
}
void MainWindow::createTorrentTriggered(const QString &path)
{
if (m_createTorrentDlg)
m_createTorrentDlg->setFocus();
else
m_createTorrentDlg = new TorrentCreatorDlg(this);
m_createTorrentDlg = new TorrentCreatorDlg(this, path);
}
bool MainWindow::event(QEvent *e)
@ -1126,6 +1131,8 @@ bool MainWindow::event(QEvent *e) @@ -1126,6 +1131,8 @@ bool MainWindow::event(QEvent *e)
void MainWindow::dropEvent(QDropEvent *event)
{
event->acceptProposedAction();
// remove scheme
QStringList files;
if (event->mimeData()->hasUrls()) {
const QList<QUrl> urls = event->mimeData()->urls();
@ -1142,15 +1149,34 @@ void MainWindow::dropEvent(QDropEvent *event) @@ -1142,15 +1149,34 @@ void MainWindow::dropEvent(QDropEvent *event)
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();
foreach (QString file, files) {
foreach (const QString &file, torrentFiles) {
qDebug("Dropped file %s on download list", qPrintable(file));
if (useTorrentAdditionDialog)
AddNewTorrentDialog::show(file, this);
else
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

1
src/gui/mainwindow.h

@ -202,6 +202,7 @@ private: @@ -202,6 +202,7 @@ private:
bool event(QEvent *e) override;
void displayRSSTab(bool enable);
void displaySearchTab(bool enable);
void createTorrentTriggered(const QString &path = QString());
Ui::MainWindow *m_ui;

Loading…
Cancel
Save