mirror of
https://github.com/transmission/transmission
synced 2025-01-30 10:52:00 +00:00
Qt: Allow piece size selection on torrent creation (#3768)
This commit is contained in:
parent
488d4a993f
commit
4e22109113
3 changed files with 62 additions and 13 deletions
|
@ -220,24 +220,14 @@ void MakeDialog::onSourceChanged()
|
|||
builder_.emplace(filename.toStdString());
|
||||
}
|
||||
|
||||
QString text;
|
||||
|
||||
if (!builder_)
|
||||
{
|
||||
text = tr("<i>No source selected</i>");
|
||||
updatePiecesLabel();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const files = tr("%Ln File(s)", nullptr, builder_->fileCount());
|
||||
auto const pieces = tr("%Ln Piece(s)", nullptr, builder_->pieceCount());
|
||||
text = tr("%1 in %2; %3 @ %4")
|
||||
.arg(Formatter::get().sizeToString(builder_->totalSize()))
|
||||
.arg(files)
|
||||
.arg(pieces)
|
||||
.arg(Formatter::get().sizeToString(static_cast<uint64_t>(builder_->pieceSize())));
|
||||
ui_.pieceSizeSlider->setValue(log2(builder_->pieceSize()));
|
||||
}
|
||||
|
||||
ui_.sourceSizeLabel->setText(text);
|
||||
}
|
||||
|
||||
MakeDialog::MakeDialog(Session& session, QWidget* parent)
|
||||
|
@ -266,6 +256,7 @@ MakeDialog::MakeDialog(Session& session, QWidget* parent)
|
|||
|
||||
connect(ui_.dialogButtons, &QDialogButtonBox::accepted, this, &MakeDialog::makeTorrent);
|
||||
connect(ui_.dialogButtons, &QDialogButtonBox::rejected, this, &MakeDialog::close);
|
||||
connect(ui_.pieceSizeSlider, &QSlider::valueChanged, this, &MakeDialog::onPieceSizeUpdated);
|
||||
|
||||
onSourceChanged();
|
||||
}
|
||||
|
@ -303,3 +294,34 @@ void MakeDialog::dropEvent(QDropEvent* event)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MakeDialog::updatePiecesLabel()
|
||||
{
|
||||
QString text;
|
||||
|
||||
if (!builder_)
|
||||
{
|
||||
text = tr("<i>No source selected</i>");
|
||||
ui_.pieceSizeSlider->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const files = tr("%Ln File(s)", nullptr, builder_->fileCount());
|
||||
auto const pieces = tr("%Ln Piece(s)", nullptr, builder_->pieceCount());
|
||||
text = tr("%1 in %2; %3 @ %4")
|
||||
.arg(Formatter::get().sizeToString(builder_->totalSize()))
|
||||
.arg(files)
|
||||
.arg(pieces)
|
||||
.arg(Formatter::get().memToString(static_cast<uint64_t>(builder_->pieceSize())));
|
||||
ui_.pieceSizeSlider->setEnabled(true);
|
||||
}
|
||||
|
||||
ui_.sourceSizeLabel->setText(text);
|
||||
}
|
||||
|
||||
void MakeDialog::onPieceSizeUpdated(int value)
|
||||
{
|
||||
auto new_size = static_cast<uint64_t>(pow(2, value));
|
||||
builder_->setPieceSize(new_size);
|
||||
updatePiecesLabel();
|
||||
}
|
||||
|
|
|
@ -32,10 +32,11 @@ protected:
|
|||
private slots:
|
||||
void onSourceChanged();
|
||||
void makeTorrent();
|
||||
void onPieceSizeUpdated(int);
|
||||
|
||||
private:
|
||||
QString getSource() const;
|
||||
|
||||
void updatePiecesLabel();
|
||||
Session& session_;
|
||||
|
||||
Ui::MakeDialog ui_ = {};
|
||||
|
|
|
@ -79,6 +79,32 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QSlider" name="pieceSizeSlider">
|
||||
<property name="minimum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>26</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="pieceSizeLabel">
|
||||
<property name="text">
|
||||
<string>Piece s&ize:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>pieceSizeSlider</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
Loading…
Reference in a new issue