2009-05-13 15:54:04 +00:00
|
|
|
/*
|
2015-06-10 21:27:11 +00:00
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
2009-05-13 15:54:04 +00:00
|
|
|
*
|
2014-12-21 23:49:39 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-05-13 15:54:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
bool RelocateDialog::myMoveFlag = 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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
mySession.torrentSetLocation(myIds, newLocation(), myMoveFlag);
|
|
|
|
close();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void RelocateDialog::onMoveToggled(bool b)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myMoveFlag = b;
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
RelocateDialog::RelocateDialog(Session& session, TorrentModel const& model, QSet<int> const& ids, QWidget* parent) :
|
2017-04-19 12:04:45 +00:00
|
|
|
BaseDialog(parent),
|
|
|
|
mySession(session),
|
|
|
|
myIds(ids)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.setupUi(this);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString path;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (int const id : myIds)
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (mySession.isServer())
|
|
|
|
{
|
|
|
|
path = QDir::homePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = QDir::rootPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2010-06-04 01:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (mySession.isServer())
|
2015-01-01 05:02:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.newLocationStack->setCurrentWidget(ui.newLocationEdit);
|
|
|
|
ui.newLocationEdit->setText(path);
|
|
|
|
ui.newLocationEdit->selectAll();
|
2015-01-01 05:02:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.newLocationStack->setFixedHeight(ui.newLocationStack->currentWidget()->sizeHint().height());
|
|
|
|
ui.newLocationLabel->setBuddy(ui.newLocationStack->currentWidget());
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (myMoveFlag)
|
|
|
|
{
|
|
|
|
ui.moveDataRadio->setChecked(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.findDataRadio->setChecked(true);
|
|
|
|
}
|
2014-12-26 10:35:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(ui.moveDataRadio, SIGNAL(toggled(bool)), this, SLOT(onMoveToggled(bool)));
|
|
|
|
connect(ui.dialogButtons, SIGNAL(rejected()), this, SLOT(close()));
|
|
|
|
connect(ui.dialogButtons, SIGNAL(accepted()), this, SLOT(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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return ui.newLocationStack->currentWidget() == ui.newLocationButton ? ui.newLocationButton->path() :
|
|
|
|
ui.newLocationEdit->text();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|