2009-05-13 15:54:04 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
|
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
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 <QFileDialog>
|
|
|
|
#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"
|
|
|
|
|
|
|
|
QString RelocateDialog :: myPath;
|
|
|
|
|
|
|
|
bool RelocateDialog :: myMoveFlag = true;
|
|
|
|
|
|
|
|
void
|
|
|
|
RelocateDialog :: onSetLocation( )
|
|
|
|
{
|
2009-05-13 19:16:31 +00:00
|
|
|
mySession.torrentSetLocation( myIds, myPath, myMoveFlag );
|
2009-05-13 15:54:04 +00:00
|
|
|
deleteLater( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RelocateDialog :: onFileSelected( const QString& path )
|
|
|
|
{
|
|
|
|
myPath = path;
|
|
|
|
myDirButton->setText( myPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RelocateDialog :: onDirButtonClicked( )
|
|
|
|
{
|
|
|
|
QFileDialog * d = new QFileDialog( this );
|
|
|
|
d->setFileMode( QFileDialog::Directory );
|
|
|
|
d->selectFile( myPath );
|
|
|
|
d->show( );
|
|
|
|
connect( d, SIGNAL(fileSelected(const QString&)), this, SLOT(onFileSelected(const QString&)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RelocateDialog :: onMoveToggled( bool b )
|
|
|
|
{
|
|
|
|
myMoveFlag = b;
|
|
|
|
}
|
|
|
|
|
2009-05-13 19:16:31 +00:00
|
|
|
RelocateDialog :: RelocateDialog( Session& session, const QSet<int>& ids, QWidget * parent ):
|
2009-05-13 15:54:04 +00:00
|
|
|
QDialog( parent ),
|
|
|
|
mySession( session ),
|
2009-05-13 19:16:31 +00:00
|
|
|
myIds( ids )
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2009-05-13 19:16:31 +00:00
|
|
|
const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) );
|
2009-10-06 00:27:26 +00:00
|
|
|
const QFileIconProvider iconProvider;
|
|
|
|
const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder );
|
2009-05-13 19:16:31 +00:00
|
|
|
const QPixmap folderPixmap = folderIcon.pixmap( iconSize );
|
|
|
|
|
2009-05-13 15:54:04 +00:00
|
|
|
QRadioButton * find_rb;
|
|
|
|
setWindowTitle( tr( "Set Torrent Location" ) );
|
|
|
|
|
|
|
|
if( myPath.isEmpty( ) )
|
|
|
|
myPath = QDir::homePath( );
|
|
|
|
|
|
|
|
HIG * hig = new HIG( );
|
2009-05-13 19:16:31 +00:00
|
|
|
hig->addSectionTitle( tr( "Set Location" ) );
|
|
|
|
hig->addRow( tr( "New &location:" ), myDirButton = new QPushButton( folderPixmap, myPath ) );
|
2009-05-13 15:54:04 +00:00
|
|
|
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 );
|
|
|
|
}
|