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