2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "MakeDialog.h"
|
|
|
|
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-12-31 22:27:46 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2013-07-27 21:58:14 +00:00
|
|
|
#include <QMimeData>
|
2009-10-05 19:53:38 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTimer>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
#include <libtransmission/makemeta.h>
|
2020-08-11 18:11:55 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "ColumnResizer.h"
|
|
|
|
#include "Formatter.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "ui_MakeProgressDialog.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2014-12-31 22:27:46 +00:00
|
|
|
namespace
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class MakeProgressDialog : public BaseDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MakeProgressDialog(Session& session, tr_metainfo_builder& builder, QWidget* parent = nullptr);
|
|
|
|
|
|
|
|
private slots:
|
2020-05-20 01:32:51 +00:00
|
|
|
void onButtonBoxClicked(QAbstractButton* button);
|
2017-04-19 12:04:45 +00:00
|
|
|
void onProgress();
|
|
|
|
|
|
|
|
private:
|
2020-05-27 21:53:12 +00:00
|
|
|
Session& session_;
|
|
|
|
tr_metainfo_builder& builder_;
|
2020-06-05 19:02:11 +00:00
|
|
|
Ui::MakeProgressDialog ui_ = {};
|
2020-05-27 21:53:12 +00:00
|
|
|
QTimer timer_;
|
2017-04-19 12:04:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
MakeProgressDialog::MakeProgressDialog(Session& session, tr_metainfo_builder& builder, QWidget* parent)
|
|
|
|
: BaseDialog(parent)
|
|
|
|
, session_(session)
|
|
|
|
, builder_(builder)
|
2014-12-31 22:27:46 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::clicked, this, &MakeProgressDialog::onButtonBoxClicked);
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&timer_, &QTimer::timeout, this, &MakeProgressDialog::onProgress);
|
2020-05-27 21:53:12 +00:00
|
|
|
timer_.start(100);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
onProgress();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MakeProgressDialog::onButtonBoxClicked(QAbstractButton* button)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
switch (ui_.dialogButtons->standardButton(button))
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case QDialogButtonBox::Open:
|
2021-08-15 09:41:48 +00:00
|
|
|
session_.addNewlyCreatedTorrent(
|
|
|
|
QString::fromUtf8(builder_.outputFile),
|
2020-05-27 21:53:12 +00:00
|
|
|
QFileInfo(QString::fromUtf8(builder_.top)).dir().path());
|
2013-09-14 22:45:04 +00:00
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case QDialogButtonBox::Abort:
|
2020-05-27 21:53:12 +00:00
|
|
|
builder_.abortFlag = true;
|
2013-09-14 22:45:04 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default: // QDialogButtonBox::Ok:
|
2013-09-14 22:45:04 +00:00
|
|
|
break;
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
close();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MakeProgressDialog::onProgress()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
// progress bar
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_metainfo_builder const& b = builder_;
|
2017-04-30 16:25:26 +00:00
|
|
|
double const denom = b.pieceCount != 0 ? b.pieceCount : 1;
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.progressBar->setValue(static_cast<int>((100.0 * b.pieceIndex) / denom));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// progress label
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const top = QString::fromUtf8(b.top);
|
|
|
|
QString const base(QFileInfo(top).completeBaseName());
|
2017-04-19 12:04:45 +00:00
|
|
|
QString str;
|
|
|
|
|
|
|
|
if (!b.isDone)
|
|
|
|
{
|
|
|
|
str = tr("Creating \"%1\"").arg(base);
|
|
|
|
}
|
|
|
|
else if (b.result == TR_MAKEMETA_OK)
|
|
|
|
{
|
|
|
|
str = tr("Created \"%1\"!").arg(base);
|
|
|
|
}
|
|
|
|
else if (b.result == TR_MAKEMETA_URL)
|
|
|
|
{
|
|
|
|
str = tr("Error: invalid announce URL \"%1\"").arg(QString::fromUtf8(b.errfile));
|
|
|
|
}
|
|
|
|
else if (b.result == TR_MAKEMETA_CANCELLED)
|
|
|
|
{
|
|
|
|
str = tr("Cancelled");
|
|
|
|
}
|
|
|
|
else if (b.result == TR_MAKEMETA_IO_READ)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
str = tr("Error reading \"%1\": %2").arg(QString::fromUtf8(b.errfile)).arg(QString::fromUtf8(tr_strerror(b.my_errno)));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (b.result == TR_MAKEMETA_IO_WRITE)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
str = tr("Error writing \"%1\": %2").arg(QString::fromUtf8(b.errfile)).arg(QString::fromUtf8(tr_strerror(b.my_errno)));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.progressLabel->setText(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// buttons
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.dialogButtons->button(QDialogButtonBox::Abort)->setEnabled(!b.isDone);
|
|
|
|
ui_.dialogButtons->button(QDialogButtonBox::Ok)->setEnabled(b.isDone);
|
|
|
|
ui_.dialogButtons->button(QDialogButtonBox::Open)->setEnabled(b.isDone && b.result == TR_MAKEMETA_OK);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "MakeDialog.moc"
|
2014-12-31 22:27:46 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2009-10-05 19:53:38 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MakeDialog::makeTorrent()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (builder_ == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// get the tiers
|
|
|
|
int tier = 0;
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
std::vector<tr_tracker_info> trackers;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QString const& line : ui_.trackersEdit->toPlainText().split(QLatin1Char('\n')))
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const announce_url = line.trimmed();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (announce_url.isEmpty())
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
++tier;
|
2013-09-14 22:45:04 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2021-10-06 14:26:07 +00:00
|
|
|
auto tmp = tr_tracker_info{};
|
2020-05-27 21:53:12 +00:00
|
|
|
tmp.announce = tr_strdup(announce_url.toUtf8().constData());
|
2017-04-19 12:04:45 +00:00
|
|
|
tmp.tier = tier;
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
trackers.push_back(tmp);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// the file to create
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const path = QString::fromUtf8(builder_->top);
|
2020-05-29 17:40:07 +00:00
|
|
|
auto const torrent_name = QFileInfo(path).completeBaseName() + QStringLiteral(".torrent");
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const target = QDir(ui_.destinationButton->path()).filePath(torrent_name);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// comment
|
|
|
|
QString comment;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (ui_.commentCheck->isChecked())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
comment = ui_.commentEdit->text();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 23:05:39 +00:00
|
|
|
// source
|
|
|
|
QString source;
|
|
|
|
|
|
|
|
if (ui_.sourceCheck->isChecked())
|
|
|
|
{
|
|
|
|
source = ui_.sourceEdit->text();
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// start making the torrent
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_makeMetaInfo(
|
|
|
|
builder_.get(),
|
|
|
|
target.toUtf8().constData(),
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
trackers.empty() ? nullptr : trackers.data(),
|
2021-08-15 09:41:48 +00:00
|
|
|
trackers.size(),
|
|
|
|
comment.isEmpty() ? nullptr : comment.toUtf8().constData(),
|
2021-10-18 23:05:39 +00:00
|
|
|
ui_.privateCheck->isChecked(),
|
|
|
|
source.isNull() ? nullptr : source.toUtf8().constData());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// pop up the dialog
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* dialog = new MakeProgressDialog(session_, *builder_, this);
|
2017-04-19 12:04:45 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->open();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString MakeDialog::getSource() const
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return (ui_.sourceFileRadio->isChecked() ? ui_.sourceFileButton : ui_.sourceFolderButton)->path();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MakeDialog::onSourceChanged()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
builder_.reset();
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const filename = getSource();
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!filename.isEmpty())
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
builder_.reset(tr_metaInfoBuilderCreate(filename.toUtf8().constData()));
|
2013-09-14 22:45:04 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
QString text;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (builder_ == nullptr)
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
text = tr("<i>No source selected</i>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QString files = tr("%Ln File(s)", nullptr, builder_->fileCount);
|
|
|
|
QString pieces = tr("%Ln Piece(s)", nullptr, builder_->pieceCount);
|
2020-11-09 03:31:02 +00:00
|
|
|
text = tr("%1 in %2; %3 @ %4")
|
2021-08-15 09:41:48 +00:00
|
|
|
.arg(Formatter::get().sizeToString(builder_->totalSize))
|
|
|
|
.arg(files)
|
|
|
|
.arg(pieces)
|
|
|
|
.arg(Formatter::get().sizeToString(static_cast<uint64_t>(builder_->pieceSize)));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceSizeLabel->setText(text);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
MakeDialog::MakeDialog(Session& session, QWidget* parent)
|
|
|
|
: BaseDialog(parent)
|
|
|
|
, session_(session)
|
|
|
|
, builder_(nullptr, &tr_metaInfoBuilderFree)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.destinationButton->setMode(PathButton::DirectoryMode);
|
|
|
|
ui_.destinationButton->setPath(QDir::homePath());
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceFolderButton->setMode(PathButton::DirectoryMode);
|
|
|
|
ui_.sourceFileButton->setMode(PathButton::FileMode);
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* cr = new ColumnResizer(this);
|
2020-05-27 21:53:12 +00:00
|
|
|
cr->addLayout(ui_.filesSectionLayout);
|
|
|
|
cr->addLayout(ui_.propertiesSectionLayout);
|
2017-04-19 12:04:45 +00:00
|
|
|
cr->update();
|
2015-01-21 21:14:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
resize(minimumSizeHint());
|
2015-01-21 21:14:00 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.sourceFolderRadio, &QAbstractButton::toggled, this, &MakeDialog::onSourceChanged);
|
|
|
|
connect(ui_.sourceFolderButton, &PathButton::pathChanged, this, &MakeDialog::onSourceChanged);
|
|
|
|
connect(ui_.sourceFileRadio, &QAbstractButton::toggled, this, &MakeDialog::onSourceChanged);
|
|
|
|
connect(ui_.sourceFileButton, &PathButton::pathChanged, this, &MakeDialog::onSourceChanged);
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::accepted, this, &MakeDialog::makeTorrent);
|
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::rejected, this, &MakeDialog::close);
|
2014-12-31 22:27:46 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
onSourceChanged();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2010-08-02 20:55:11 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MakeDialog::dragEnterEvent(QDragEnterEvent* event)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QMimeData const* mime = event->mimeData();
|
2010-08-02 20:55:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!mime->urls().isEmpty() && QFileInfo(mime->urls().front().path()).exists())
|
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void MakeDialog::dropEvent(QDropEvent* event)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const filename = event->mimeData()->urls().front().path();
|
2020-05-27 21:53:12 +00:00
|
|
|
QFileInfo const file_info(filename);
|
2010-08-02 20:55:11 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (file_info.exists())
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (file_info.isDir())
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceFolderRadio->setChecked(true);
|
|
|
|
ui_.sourceFolderButton->setPath(filename);
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else // it's a file
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.sourceFileRadio->setChecked(true);
|
|
|
|
ui_.sourceFileButton->setPath(filename);
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|