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>
|
|
|
|
#include <QFileIconProvider>
|
2014-12-26 10:35:00 +00:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
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"
|
|
|
|
#include "utils.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
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
mySession.torrentSetLocation (myIds, myPath, 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::onFileSelected (const QString& path)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
myPath = path;
|
2014-12-26 10:35:00 +00:00
|
|
|
|
|
|
|
const QFileInfo pathInfo (path);
|
|
|
|
const QFileIconProvider iconProvider;
|
|
|
|
|
|
|
|
ui.newLocationButton->setIcon (mySession.isLocal () ?
|
|
|
|
iconProvider.icon (pathInfo) :
|
|
|
|
iconProvider.icon (QFileIconProvider::Folder));
|
|
|
|
ui.newLocationButton->setText (pathInfo.baseName ());
|
|
|
|
ui.newLocationButton->setToolTip (path);
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
RelocateDialog::onDirButtonClicked ()
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
const QString title = tr ("Select Location");
|
|
|
|
const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer ());
|
2010-06-04 01:00:27 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
if (!path.isEmpty ())
|
|
|
|
onFileSelected (path);
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (myPath.isEmpty ())
|
|
|
|
{
|
|
|
|
myPath = tor->getPath ();
|
|
|
|
}
|
|
|
|
else if (myPath != tor->getPath ())
|
2010-06-04 01:00:27 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
if (mySession.isServer ())
|
|
|
|
myPath = QDir::homePath ();
|
|
|
|
else
|
|
|
|
myPath = 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
|
|
|
|
2014-12-26 10:35:00 +00:00
|
|
|
onFileSelected (myPath);
|
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.newLocationButton, SIGNAL (clicked ()), this, SLOT (onDirButtonClicked ()));
|
|
|
|
connect (ui.dialogButtons, SIGNAL (rejected ()), this, SLOT (close ()));
|
|
|
|
connect (ui.dialogButtons, SIGNAL (accepted ()), this, SLOT (onSetLocation ()));
|
|
|
|
|
|
|
|
setAttribute (Qt::WA_DeleteOnClose, true);
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|