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-01-19 01:09:44 +00:00
|
|
|
* It may be used under the GNU Public License v2 or v3 licenses,
|
|
|
|
* 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 <QApplication>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileIconProvider>
|
2009-05-13 15:54:04 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QSet>
|
2009-05-13 19:16:31 +00:00
|
|
|
#include <QStyle>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QWidget>
|
2009-05-13 15:54:04 +00:00
|
|
|
|
|
|
|
#include "hig.h"
|
|
|
|
#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
|
|
|
|
|
|
|
bool RelocateDialog :: myMoveFlag = true;
|
|
|
|
|
|
|
|
void
|
2013-02-03 19:40:20 +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);
|
|
|
|
deleteLater ();
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-03 19:40:20 +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;
|
|
|
|
myDirButton->setText (myPath);
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-03 19:40:20 +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
|
2013-02-03 19:40:20 +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
|
|
|
}
|
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
RelocateDialog :: RelocateDialog (Session & session,
|
|
|
|
TorrentModel & model,
|
|
|
|
const QSet<int> & ids,
|
|
|
|
QWidget * parent):
|
|
|
|
QDialog (parent),
|
|
|
|
mySession (session),
|
|
|
|
myModel (model),
|
|
|
|
myIds (ids)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
const int iconSize (style ()->pixelMetric (QStyle :: PM_SmallIconSize));
|
|
|
|
const QFileIconProvider iconProvider;
|
|
|
|
const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
|
|
|
|
const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
|
|
|
|
|
|
|
|
QRadioButton * find_rb;
|
|
|
|
setWindowTitle (tr ("Set Torrent Location"));
|
|
|
|
|
|
|
|
foreach (int id, myIds)
|
|
|
|
{
|
|
|
|
const Torrent * tor = myModel.getTorrentFromId (id);
|
|
|
|
|
|
|
|
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 ();
|
2010-06-04 01:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
HIG * hig = new HIG ();
|
|
|
|
hig->addSectionTitle (tr ("Set Location"));
|
|
|
|
hig->addRow (tr ("New &location:"), myDirButton = new QPushButton (folderPixmap, myPath));
|
|
|
|
hig->addWideControl (myMoveRadio = new QRadioButton (tr ("&Move from the current folder"), this));
|
|
|
|
hig->addWideControl (find_rb = new QRadioButton (tr ("Local data is &already there"), this));
|
|
|
|
hig->finish ();
|
|
|
|
|
|
|
|
if (myMoveFlag)
|
|
|
|
myMoveRadio->setChecked (true);
|
|
|
|
else
|
|
|
|
find_rb->setChecked (true);
|
|
|
|
|
|
|
|
connect (myMoveRadio, SIGNAL (toggled (bool)), this, SLOT (onMoveToggled (bool)));
|
|
|
|
connect (myDirButton, SIGNAL (clicked (bool)), this, SLOT (onDirButtonClicked ()));
|
|
|
|
|
|
|
|
QLayout * layout = new QVBoxLayout (this);
|
|
|
|
layout->addWidget (hig);
|
|
|
|
QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
|
|
|
|
connect (buttons, SIGNAL (rejected ()), this, SLOT (deleteLater ()));
|
|
|
|
connect (buttons, SIGNAL (accepted ()), this, SLOT (onSetLocation ()));
|
|
|
|
layout->addWidget (buttons);
|
|
|
|
QWidget::setAttribute (Qt::WA_DeleteOnClose, true);
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|