2009-05-13 15:54:04 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 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-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
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
|
|
|
|
2009-05-13 15:54:04 +00:00
|
|
|
#include "relocate.h"
|
|
|
|
#include "session.h"
|
2010-06-04 01:00:27 +00:00
|
|
|
#include "torrent.h"
|
|
|
|
#include "torrent-model.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
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
RelocateDialog::onSetLocation ()
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2015-01-01 05:02:13 +00:00
|
|
|
mySession.torrentSetLocation (myIds, newLocation (), myMoveFlag);
|
2014-12-26 10:35:00 +00:00
|
|
|
close ();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
RelocateDialog::onMoveToggled (bool b)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
myMoveFlag = b;
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
2014-12-26 10:35:00 +00:00
|
|
|
RelocateDialog::RelocateDialog (Session & session,
|
|
|
|
const TorrentModel & model,
|
|
|
|
const QSet<int> & ids,
|
|
|
|
QWidget * parent):
|
2013-02-03 19:40:20 +00:00
|
|
|
QDialog (parent),
|
|
|
|
mySession (session),
|
|
|
|
myIds (ids)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2014-12-26 10:35:00 +00:00
|
|
|
ui.setupUi (this);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2015-01-01 05:02:13 +00:00
|
|
|
QString path;
|
2013-02-03 19:40:20 +00:00
|
|
|
foreach (int id, myIds)
|
|
|
|
{
|
2014-12-26 10:35:00 +00:00
|
|
|
const Torrent * tor = model.getTorrentFromId (id);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2015-01-01 05:02:13 +00:00
|
|
|
if (path.isEmpty ())
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2015-01-01 05:02:13 +00:00
|
|
|
path = tor->getPath ();
|
2013-02-03 19:40:20 +00:00
|
|
|
}
|
2015-01-01 05:02:13 +00:00
|
|
|
else if (path != tor->getPath ())
|
2010-06-04 01:00:27 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
if (mySession.isServer ())
|
2015-01-01 05:02:13 +00:00
|
|
|
path = QDir::homePath ();
|
2013-02-03 19:40:20 +00:00
|
|
|
else
|
2015-01-01 05:02:13 +00:00
|
|
|
path = QDir::rootPath ();
|
2014-12-26 10:35:00 +00:00
|
|
|
break;
|
2010-06-04 01:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2015-01-01 05:02:13 +00:00
|
|
|
if (mySession.isServer ())
|
|
|
|
{
|
|
|
|
ui.newLocationStack->setCurrentWidget (ui.newLocationButton);
|
|
|
|
ui.newLocationButton->setMode (TrPathButton::DirectoryMode);
|
|
|
|
ui.newLocationButton->setTitle (tr ("Select Location"));
|
|
|
|
ui.newLocationButton->setPath (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.newLocationStack->setCurrentWidget (ui.newLocationEdit);
|
|
|
|
ui.newLocationEdit->setText (path);
|
|
|
|
ui.newLocationEdit->selectAll ();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.newLocationStack->setFixedHeight (ui.newLocationStack->currentWidget ()->sizeHint ().height ());
|
|
|
|
ui.newLocationLabel->setBuddy (ui.newLocationStack->currentWidget ());
|
2013-02-03 19:40:20 +00:00
|
|
|
|
|
|
|
if (myMoveFlag)
|
2014-12-26 10:35:00 +00:00
|
|
|
ui.moveDataRadio->setChecked (true);
|
2013-02-03 19:40:20 +00:00
|
|
|
else
|
2014-12-26 10:35:00 +00:00
|
|
|
ui.findDataRadio->setChecked (true);
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-01-01 05:02:13 +00:00
|
|
|
QString
|
|
|
|
RelocateDialog::newLocation () const
|
|
|
|
{
|
|
|
|
return ui.newLocationStack->currentWidget () == ui.newLocationButton ?
|
|
|
|
ui.newLocationButton->path () : ui.newLocationEdit->text ();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|