Browse Source

Merge pull request #3291 from ngosang/torrent_creator

Add 16 KiB, 8 MiB and 16 MiB piece sizes in Torrent Creator. Closes #2656
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
f94214ae14
  1. 2
      src/gui/gui.pri
  2. 80
      src/gui/torrentcreatordlg.cpp
  3. 5
      src/gui/torrentcreatordlg.h
  4. 17
      src/gui/torrentcreatordlg.ui

2
src/gui/gui.pri

@ -95,6 +95,6 @@ FORMS += \ @@ -95,6 +95,6 @@ FORMS += \
$$PWD/autoexpandabledialog.ui \
$$PWD/statsdialog.ui \
$$PWD/options.ui \
$$PWD/createtorrent.ui
$$PWD/torrentcreatordlg.ui
RESOURCES += $$PWD/about.qrc

80
src/gui/torrentcreatordlg.cpp

@ -44,7 +44,10 @@ @@ -44,7 +44,10 @@
const uint NB_PIECES_MIN = 1200;
const uint NB_PIECES_MAX = 2200;
TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent): QDialog(parent), m_creatorThread(0) {
TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent)
: QDialog(parent)
, m_creatorThread(0)
{
setupUi(this);
// Icons
addFile_button->setIcon(GuiIconProvider::instance()->getIcon("document-new"));
@ -57,20 +60,22 @@ TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent): QDialog(parent), m_creato @@ -57,20 +60,22 @@ TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent): QDialog(parent), m_creato
showProgressBar(false);
loadTrackerList();
// Piece sizes
m_pieceSizes << 32 << 64 << 128 << 256 << 512 << 1024 << 2048 << 4096;
m_pieceSizes << 16 << 32 << 64 << 128 << 256 << 512 << 1024 << 2048 << 4096 << 8192 << 16384;
loadSettings();
show();
}
TorrentCreatorDlg::~TorrentCreatorDlg() {
TorrentCreatorDlg::~TorrentCreatorDlg()
{
if (m_creatorThread)
delete m_creatorThread;
}
void TorrentCreatorDlg::on_addFolder_button_clicked() {
void TorrentCreatorDlg::on_addFolder_button_clicked()
{
Preferences* const pref = Preferences::instance();
QString last_path = pref->getCreateTorLastAddPath();
QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), last_path, QFileDialog::ShowDirsOnly);
QString lastPath = pref->getCreateTorLastAddPath();
QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), lastPath, QFileDialog::ShowDirsOnly);
if (!dir.isEmpty()) {
pref->setCreateTorLastAddPath(dir);
textInputPath->setText(Utils::Fs::toNativePath(dir));
@ -80,10 +85,11 @@ void TorrentCreatorDlg::on_addFolder_button_clicked() { @@ -80,10 +85,11 @@ void TorrentCreatorDlg::on_addFolder_button_clicked() {
}
}
void TorrentCreatorDlg::on_addFile_button_clicked() {
void TorrentCreatorDlg::on_addFile_button_clicked()
{
Preferences* const pref = Preferences::instance();
QString last_path = pref->getCreateTorLastAddPath();
QString file = QFileDialog::getOpenFileName(this, tr("Select a file to add to the torrent"), last_path);
QString lastPath = pref->getCreateTorLastAddPath();
QString file = QFileDialog::getOpenFileName(this, tr("Select a file to add to the torrent"), lastPath);
if (!file.isEmpty()) {
pref->setCreateTorLastAddPath(Utils::Fs::branchPath(file));
textInputPath->setText(Utils::Fs::toNativePath(file));
@ -93,12 +99,14 @@ void TorrentCreatorDlg::on_addFile_button_clicked() { @@ -93,12 +99,14 @@ void TorrentCreatorDlg::on_addFile_button_clicked() {
}
}
int TorrentCreatorDlg::getPieceSize() const {
return m_pieceSizes.at(comboPieceSize->currentIndex())*1024;
int TorrentCreatorDlg::getPieceSize() const
{
return m_pieceSizes.at(comboPieceSize->currentIndex()) * 1024;
}
// Main function that create a .torrent file
void TorrentCreatorDlg::on_createButton_clicked() {
void TorrentCreatorDlg::on_createButton_clicked()
{
QString input = Utils::Fs::fromNativePath(textInputPath->text()).trimmed();
if (input.endsWith("/"))
input.chop(1);
@ -111,33 +119,34 @@ void TorrentCreatorDlg::on_createButton_clicked() { @@ -111,33 +119,34 @@ void TorrentCreatorDlg::on_createButton_clicked() {
saveTrackerList();
Preferences* const pref = Preferences::instance();
QString last_path = pref->getCreateTorLastSavePath();
QString lastPath = pref->getCreateTorLastSavePath();
QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), lastPath, tr("Torrent Files")+QString::fromUtf8(" (*.torrent)"));
if (destination.isEmpty())
return;
QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), last_path, tr("Torrent Files")+QString::fromUtf8(" (*.torrent)"));
if (!destination.isEmpty()) {
pref->setCreateTorLastSavePath(Utils::Fs::branchPath(destination));
if (!destination.toUpper().endsWith(".TORRENT"))
destination += QString::fromUtf8(".torrent");
} else {
return;
}
// Disable dialog
setInteractionEnabled(false);
showProgressBar(true);
// Set busy cursor
setCursor(QCursor(Qt::WaitCursor));
// Actually create the torrent
QStringList url_seeds = URLSeeds_list->toPlainText().split("\n");
QStringList urlSeeds = URLSeeds_list->toPlainText().split("\n");
QString comment = txt_comment->toPlainText();
// Create the creator thread
m_creatorThread = new BitTorrent::TorrentCreatorThread(this);
connect(m_creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString)));
connect(m_creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString)));
connect(m_creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int)));
m_creatorThread->create(input, destination, trackers, url_seeds, comment, check_private->isChecked(), getPieceSize());
m_creatorThread->create(input, destination, trackers, urlSeeds, comment, check_private->isChecked(), getPieceSize());
}
void TorrentCreatorDlg::handleCreationFailure(QString msg) {
void TorrentCreatorDlg::handleCreationFailure(QString msg)
{
// Remove busy cursor
setCursor(QCursor(Qt::ArrowCursor));
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent creation was unsuccessful, reason: %1").arg(msg));
@ -145,7 +154,8 @@ void TorrentCreatorDlg::handleCreationFailure(QString msg) { @@ -145,7 +154,8 @@ void TorrentCreatorDlg::handleCreationFailure(QString msg) {
showProgressBar(false);
}
void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) {
void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path)
{
// Remove busy cursor
setCursor(QCursor(Qt::ArrowCursor));
if (checkStartSeeding->isChecked()) {
@ -163,12 +173,12 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) @@ -163,12 +173,12 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path)
BitTorrent::Session::instance()->addTorrent(t, params);
}
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+Utils::Fs::toNativePath(path));
close();
}
void TorrentCreatorDlg::on_cancelButton_clicked() {
void TorrentCreatorDlg::on_cancelButton_clicked()
{
// End torrent creation thread
if (m_creatorThread && m_creatorThread->isRunning()) {
m_creatorThread->abortCreation();
@ -180,7 +190,8 @@ void TorrentCreatorDlg::on_cancelButton_clicked() { @@ -180,7 +190,8 @@ void TorrentCreatorDlg::on_cancelButton_clicked() {
close();
}
void TorrentCreatorDlg::updateProgressBar(int progress) {
void TorrentCreatorDlg::updateProgressBar(int progress)
{
progressBar->setValue(progress);
}
@ -198,7 +209,6 @@ void TorrentCreatorDlg::setInteractionEnabled(bool enabled) @@ -198,7 +209,6 @@ void TorrentCreatorDlg::setInteractionEnabled(bool enabled)
checkStartSeeding->setEnabled(enabled);
createButton->setEnabled(enabled);
checkIgnoreShareLimits->setEnabled(enabled && checkStartSeeding->isChecked());
//cancelButton->setEnabled(!enabled);
}
void TorrentCreatorDlg::showProgressBar(bool show)
@ -210,32 +220,32 @@ void TorrentCreatorDlg::showProgressBar(bool show) @@ -210,32 +220,32 @@ void TorrentCreatorDlg::showProgressBar(bool show)
void TorrentCreatorDlg::on_checkAutoPieceSize_clicked(bool checked)
{
comboPieceSize->setEnabled(!checked);
if (checked) {
if (checked)
updateOptimalPieceSize();
}
}
void TorrentCreatorDlg::updateOptimalPieceSize()
{
qint64 torrent_size = Utils::Fs::computePathSize(textInputPath->text());
qDebug("Torrent size is %lld", torrent_size);
if (torrent_size < 0) return;
qint64 torrentSize = Utils::Fs::computePathSize(textInputPath->text());
qDebug("Torrent size is %lld", torrentSize);
if (torrentSize < 0)
return;
int i = 0;
qulonglong nb_pieces = 0;
do {
nb_pieces = (double)torrent_size/(m_pieceSizes.at(i)*1024.);
nb_pieces = (double)torrentSize/(m_pieceSizes.at(i) * 1024.);
qDebug("nb_pieces=%lld with piece_size=%s", nb_pieces, qPrintable(comboPieceSize->itemText(i)));
if (nb_pieces <= NB_PIECES_MIN) {
if (i > 1)
--i;
break;
}
if (nb_pieces < NB_PIECES_MAX) {
qDebug("Good, nb_pieces=%lld < %d", nb_pieces, NB_PIECES_MAX);
else if (nb_pieces < NB_PIECES_MAX) {
qDebug("Good, nb_pieces=%lld < %d", nb_pieces + 1, NB_PIECES_MAX);
break;
}
++i;
}while(i<(m_pieceSizes.size()-1));
} while (i < (m_pieceSizes.size() - 1));
comboPieceSize->setCurrentIndex(i);
}

5
src/gui/torrentcreatordlg.h

@ -31,14 +31,15 @@ @@ -31,14 +31,15 @@
#ifndef CREATE_TORRENT_IMP_H
#define CREATE_TORRENT_IMP_H
#include "ui_createtorrent.h"
#include "ui_torrentcreatordlg.h"
namespace BitTorrent
{
class TorrentCreatorThread;
}
class TorrentCreatorDlg : public QDialog, private Ui::createTorrentDialog{
class TorrentCreatorDlg : public QDialog, private Ui::createTorrentDialog
{
Q_OBJECT
public:

17
src/gui/createtorrent.ui → src/gui/torrentcreatordlg.ui

@ -158,8 +158,13 @@ @@ -158,8 +158,13 @@
<bool>false</bool>
</property>
<property name="currentIndex">
<number>3</number>
<number>4</number>
</property>
<item>
<property name="text">
<string>16 KiB</string>
</property>
</item>
<item>
<property name="text">
<string>32 KiB</string>
@ -200,6 +205,16 @@ @@ -200,6 +205,16 @@
<string>4 MiB</string>
</property>
</item>
<item>
<property name="text">
<string>8 MiB</string>
</property>
</item>
<item>
<property name="text">
<string>16 MiB</string>
</property>
</item>
</widget>
</item>
<item>
Loading…
Cancel
Save