2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2009-2023 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QDir>
|
2014-12-26 10:35:00 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "RelocateDialog.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Torrent.h"
|
|
|
|
#include "TorrentModel.h"
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2020-09-09 14:24:39 +00:00
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
2020-06-05 19:02:11 +00:00
|
|
|
bool RelocateDialog::move_flag = true;
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void RelocateDialog::onSetLocation()
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
session_.torrentSetLocation(ids_, newLocation(), move_flag);
|
2017-04-19 12:04:45 +00:00
|
|
|
close();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
void RelocateDialog::onMoveToggled(bool b) const
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
move_flag = b;
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
RelocateDialog::RelocateDialog(Session& session, TorrentModel const& model, torrent_ids_t ids, QWidget* parent)
|
|
|
|
: BaseDialog(parent)
|
|
|
|
, session_(session)
|
|
|
|
, ids_(std::move(ids))
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString path;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (int const id : ids_)
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
Torrent const* tor = model.getTorrentFromId(id);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (path.isEmpty())
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
path = tor->getPath();
|
2013-02-03 19:40:20 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (path != tor->getPath())
|
2010-06-04 01:00:27 +00:00
|
|
|
{
|
2021-08-07 14:08:37 +00:00
|
|
|
if (session_.isLocal())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
path = QDir::homePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = QDir::rootPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2010-06-04 01:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2021-08-07 14:08:37 +00:00
|
|
|
if (session_.isLocal())
|
2015-01-01 05:02:13 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.newLocationStack->setCurrentWidget(ui_.newLocationButton);
|
|
|
|
ui_.newLocationButton->setMode(PathButton::DirectoryMode);
|
|
|
|
ui_.newLocationButton->setTitle(tr("Select Location"));
|
|
|
|
ui_.newLocationButton->setPath(path);
|
2015-01-01 05:02:13 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2015-01-01 05:02:13 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.newLocationStack->setCurrentWidget(ui_.newLocationEdit);
|
|
|
|
ui_.newLocationEdit->setText(path);
|
|
|
|
ui_.newLocationEdit->selectAll();
|
2015-01-01 05:02:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.newLocationStack->setFixedHeight(ui_.newLocationStack->currentWidget()->sizeHint().height());
|
|
|
|
ui_.newLocationLabel->setBuddy(ui_.newLocationStack->currentWidget());
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
if (move_flag)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.moveDataRadio->setChecked(true);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.findDataRadio->setChecked(true);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2014-12-26 10:35:00 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.moveDataRadio, &QAbstractButton::toggled, this, &RelocateDialog::onMoveToggled);
|
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::rejected, this, &RelocateDialog::close);
|
|
|
|
connect(ui_.dialogButtons, &QDialogButtonBox::accepted, this, &RelocateDialog::onSetLocation);
|
2015-01-01 05:02:13 +00:00
|
|
|
}
|
2014-12-26 10:35:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString RelocateDialog::newLocation() const
|
2015-01-01 05:02:13 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return ui_.newLocationStack->currentWidget() == ui_.newLocationButton ? ui_.newLocationButton->path() :
|
2021-08-15 09:41:48 +00:00
|
|
|
ui_.newLocationEdit->text();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|