]> granicus.if.org Git - transmission/commitdiff
(qt) #3255: Don't use filebrowser in remote sessions
authorDaniel Lee <Longinus00@gmail.com>
Fri, 4 Jun 2010 01:00:27 +0000 (01:00 +0000)
committerDaniel Lee <Longinus00@gmail.com>
Fri, 4 Jun 2010 01:00:27 +0000 (01:00 +0000)
NEWS
qt/mainwin.cc
qt/prefs-dialog.cc
qt/prefs-dialog.h
qt/relocate.cc
qt/relocate.h
qt/utils.cc
qt/utils.h

diff --git a/NEWS b/NEWS
index 5697255e4df768cd35141c96eb745d4aa203e0ca..7d2807d1173912589727cf5161dcb79ad95af12e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@
   * Show file sizes in the file tree
   * Added a confirm dialog when removing torrents
   * Properties and torrent options no longer jump around while editing
+  * Allow setting locations for remote sessions
+  * Miscellaneous UI fixes
 ==== Daemon ====
   * Let users specify a script to be invoked when a torrent finishes downloading
   * Better support for adding per-torrent settings when adding a new torrent
index 6703c7aa6dedd5b6f0034f967c90425e02ce9625..336b25e9b0be8a15f779d8a232198c0d8b5041ed 100644 (file)
@@ -667,7 +667,7 @@ TrMainWindow :: openProperties( )
 void
 TrMainWindow :: setLocation( )
 {
-    QDialog * d = new RelocateDialog( mySession, getSelectedTorrents(), this );
+    QDialog * d = new RelocateDialog( mySession, myModel, getSelectedTorrents(), this );
     d->show( );
 }
 
@@ -1174,7 +1174,7 @@ void
 TrMainWindow :: removeTorrents( const bool deleteFiles )
 {
     QSet<int> ids;
-    QMessageBox msgBox( this );
+    QMessageBox * msgBox = new QMessageBox( this );
     QString primary_text, secondary_text;
     int incomplete = 0;
     int connected  = 0;
@@ -1247,18 +1247,18 @@ TrMainWindow :: removeTorrents( const bool deleteFiles )
         }
     }
 
-    msgBox.setWindowTitle( QString(" ") );
-    msgBox.setText( QString( "<big><b>%1</big></b>" ).arg( primary_text ) );
-    msgBox.setInformativeText( secondary_text );
-    msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
-    msgBox.setDefaultButton( QMessageBox::Cancel );
-    msgBox.setIcon( QMessageBox::Question );
+    msgBox->setWindowTitle( QString(" ") );
+    msgBox->setText( QString( "<big><b>%1</big></b>" ).arg( primary_text ) );
+    msgBox->setInformativeText( secondary_text );
+    msgBox->setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
+    msgBox->setDefaultButton( QMessageBox::Cancel );
+    msgBox->setIcon( QMessageBox::Question );
     /* hack needed to keep the dialog from being too narrow */
-    QGridLayout* layout = (QGridLayout*)msgBox.layout();
+    QGridLayout* layout = (QGridLayout*)msgBox->layout();
     QSpacerItem* spacer = new QSpacerItem( 450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
     layout->addItem( spacer, layout->rowCount(), 0, 1, layout->columnCount() );
 
-    if( msgBox.exec() == QMessageBox::Ok )
+    if( msgBox->exec() == QMessageBox::Ok )
         mySession.removeTorrents( ids, deleteFiles );
 }
 
index 4bea6913dbe13c0008af8fe73e89ba947ee521c6..b47d10c9e515489573b662c08c776b94878d94b0 100644 (file)
@@ -18,7 +18,6 @@
 #include <QCoreApplication>
 #include <QDialogButtonBox>
 #include <QDoubleSpinBox>
-#include <QFileDialog>
 #include <QFileIconProvider>
 #include <QFileInfo>
 #include <QHBoxLayout>
@@ -42,6 +41,7 @@
 #include "prefs-dialog.h"
 #include "qticonloader.h"
 #include "session.h"
+#include "utils.h"
 
 /***
 ****
@@ -493,78 +493,51 @@ void
 PrefsDialog :: onScriptClicked( void )
 {
     const QString title = tr( "Select \"Torrent Done\" Script" );
-    const QString path = myPrefs.getString( Prefs::SCRIPT_TORRENT_DONE_FILENAME );
-    QFileDialog * d = new QFileDialog( this, title, path );
-    d->setFileMode( QFileDialog::ExistingFiles );
-    connect( d, SIGNAL(filesSelected(const QStringList&)),
-             this, SLOT(onScriptSelected(const QStringList&)) );
-    d->show( );
-}
+    const QString myPath = myPrefs.getString( Prefs::SCRIPT_TORRENT_DONE_FILENAME );
+    const QString path = Utils::remoteFileChooser( this, title, myPath, false, mySession.isServer() );
 
-void
-PrefsDialog :: onScriptSelected( const QStringList& list )
-{
-    if( list.size() == 1 )
-        myPrefs.set( Prefs::Prefs::SCRIPT_TORRENT_DONE_FILENAME, list.first( ) );
+    if( !path.isEmpty() )
+        onLocationSelected( path, Prefs::SCRIPT_TORRENT_DONE_FILENAME );
 }
 
-
 void
 PrefsDialog :: onIncompleteClicked( void )
 {
     const QString title = tr( "Select Incomplete Directory" );
-    const QString path = myPrefs.getString( Prefs::INCOMPLETE_DIR );
-    QFileDialog * d = new QFileDialog( this, title, path );
-    d->setFileMode( QFileDialog::Directory );
-    connect( d, SIGNAL(filesSelected(const QStringList&)),
-             this, SLOT(onIncompleteSelected(const QStringList&)) );
-    d->show( );
-}
+    const QString myPath = myPrefs.getString( Prefs::INCOMPLETE_DIR );
+    const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() );
 
-void
-PrefsDialog :: onIncompleteSelected( const QStringList& list )
-{
-    if( list.size() == 1 )
-        myPrefs.set( Prefs::INCOMPLETE_DIR, list.first( ) );
+    if( !path.isEmpty() )
+        onLocationSelected( path, Prefs::INCOMPLETE_DIR );
 }
 
-
 void
 PrefsDialog :: onWatchClicked( void )
 {
     const QString title = tr( "Select Watch Directory" );
-    const QString path = myPrefs.getString( Prefs::DIR_WATCH );
-    QFileDialog * d = new QFileDialog( this, title, path );
-    d->setFileMode( QFileDialog::Directory );
-    connect( d, SIGNAL(filesSelected(const QStringList&)),
-             this, SLOT(onWatchSelected(const QStringList&)) );
-    d->show( );
-}
+    const QString myPath = myPrefs.getString( Prefs::DIR_WATCH );
+    const QString path = Utils::remoteFileChooser( this, title, myPath, true, true );
 
-void
-PrefsDialog :: onWatchSelected( const QStringList& list )
-{
-    if( list.size() == 1 )
-        myPrefs.set( Prefs::DIR_WATCH, list.first( ) );
+    if( !path.isEmpty() )
+        onLocationSelected( path, Prefs::DIR_WATCH );
 }
 
 void
 PrefsDialog :: onDestinationClicked( void )
 {
     const QString title = tr( "Select Destination" );
-    const QString path = myPrefs.getString( Prefs::DOWNLOAD_DIR );
-    QFileDialog * d = new QFileDialog( this, title, path );
-    d->setFileMode( QFileDialog::Directory );
-    connect( d, SIGNAL(filesSelected(const QStringList&)),
-             this, SLOT(onDestinationSelected(const QStringList&)) );
-    d->show( );
+    const QString myPath = myPrefs.getString( Prefs::DOWNLOAD_DIR );
+    const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() );
+
+    if( !path.isEmpty() )
+        onLocationSelected( path, Prefs::DOWNLOAD_DIR );
 }
 
 void
-PrefsDialog :: onDestinationSelected( const QStringList& list )
+PrefsDialog :: onLocationSelected( const QString& path, int key )
 {
-    if( list.size() == 1 )
-        myPrefs.set( Prefs::DOWNLOAD_DIR, list.first( ) );
+    myPrefs.set( key, path );
+    updatePref( key );
 }
 
 QWidget *
@@ -603,7 +576,7 @@ PrefsDialog :: createTorrentsTab( )
         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b );
 
         l = myTorrentDoneScriptCheckbox = checkBoxNew( tr( "Call scrip&t when torrent is completed" ), Prefs::SCRIPT_TORRENT_DONE_ENABLED );
-        b = myTorrentDoneScriptFilename = new QPushButton;
+        b = myTorrentDoneScriptButton = new QPushButton;
         b->setIcon( filePixmap );
         b->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
         connect( b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked(void)) );
index 9ab5752079b798018f51e15c020be0bc5059ba03..3a89323e2bf3cb9bc0bec8d0704ec10e13baa418 100644 (file)
@@ -51,13 +51,10 @@ class PrefsDialog: public QDialog
         void altSpeedDaysEdited( int );
         void sessionUpdated( );
         void onWatchClicked( );
-        void onWatchSelected( const QStringList& );
         void onScriptClicked( );
-        void onScriptSelected( const QStringList& );
         void onIncompleteClicked( );
-        void onIncompleteSelected( const QStringList& );
         void onDestinationClicked( );
-        void onDestinationSelected( const QStringList& );
+        void onLocationSelected( const QString&, int key );
         void onPortTested( bool );
         void onPortTest( );
 
@@ -98,7 +95,7 @@ class PrefsDialog: public QDialog
         QLabel * myPortLabel;
         QPushButton * myPortButton;
         QPushButton * myWatchButton;
-        QPushButton * myTorrentDoneScriptFilename;
+        QPushButton * myTorrentDoneScriptButton;
         QCheckBox * myTorrentDoneScriptCheckbox;
         QCheckBox * myIncompleteCheckbox;
         QPushButton * myIncompleteButton;
index 4902b645a2596cf711cf429156a8500e9d73b9a2..5cdace953f18dcada8a5d12fb461c3525987eeb1 100644 (file)
@@ -13,7 +13,6 @@
 #include <QApplication>
 #include <QDialogButtonBox>
 #include <QDir>
-#include <QFileDialog>
 #include <QFileIconProvider>
 #include <QLabel>
 #include <QPushButton>
@@ -26,8 +25,9 @@
 #include "hig.h"
 #include "relocate.h"
 #include "session.h"
-
-QString RelocateDialog :: myPath;
+#include "torrent.h"
+#include "torrent-model.h"
+#include "utils.h"
 
 bool RelocateDialog :: myMoveFlag = true;
 
@@ -48,11 +48,11 @@ RelocateDialog :: onFileSelected( const QString& path )
 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&)));
+    const QString title = tr( "Select Location" );
+    const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() );
+
+    if( !path.isEmpty() )
+        onFileSelected( path );
 }
 
 void
@@ -61,9 +61,10 @@ RelocateDialog :: onMoveToggled( bool b )
     myMoveFlag = b;
 }
 
-RelocateDialog :: RelocateDialog( Session& session, const QSet<int>& ids, QWidget * parent ):
+RelocateDialog :: RelocateDialog( Session& session, TorrentModel& model, const QSet<int>& ids, QWidget * parent ):
     QDialog( parent ),
     mySession( session ),
+    myModel( model ),
     myIds( ids )
 {
     const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) );
@@ -74,8 +75,18 @@ RelocateDialog :: RelocateDialog( Session& session, const QSet<int>& ids, QWidge
     QRadioButton * find_rb;
     setWindowTitle( tr( "Set Torrent Location" ) );
 
-    if( myPath.isEmpty( ) )
-        myPath = QDir::homePath( );
+    foreach( int id, myIds ) {
+        const Torrent * tor = myModel.getTorrentFromId( id );
+        if( myPath.isEmpty() )
+            myPath = tor->getPath();
+        else if( myPath != tor->getPath() )
+        {
+            if( mySession.isServer() )
+                myPath = QDir::homePath( );
+            else
+                myPath = QString( "/" );
+        }
+    }
 
     HIG * hig = new HIG( );
     hig->addSectionTitle( tr( "Set Location" ) );
@@ -98,4 +109,5 @@ RelocateDialog :: RelocateDialog( Session& session, const QSet<int>& ids, QWidge
     connect( buttons, SIGNAL(rejected()), this, SLOT(deleteLater()));
     connect( buttons, SIGNAL(accepted()), this, SLOT(onSetLocation()));
     layout->addWidget( buttons );
+    QWidget::setAttribute( Qt::WA_DeleteOnClose, true );
 }
index 97d8fbcf8799ceb8ffab931eec615a069722fdf3..e8a1f1c37666c5cc8f5a5f3406bffcdaeab5a16f 100644 (file)
 class QPushButton;
 class QRadioButton;
 class Session;
+class Torrent;
+class TorrentModel;
 
 class RelocateDialog: public QDialog
 {
         Q_OBJECT
 
     private:
-        static QString myPath;
+        QString myPath;
         static bool myMoveFlag;
 
     private:
         Session & mySession;
+        TorrentModel& myModel;
         QSet<int> myIds;
         QPushButton * myDirButton;
         QRadioButton * myMoveRadio;
@@ -42,7 +45,7 @@ class RelocateDialog: public QDialog
         void onMoveToggled( bool );
 
     public:
-        RelocateDialog( Session&, const QSet<int>& ids, QWidget * parent = 0 );
+        RelocateDialog( Session&, TorrentModel&, const QSet<int>& ids, QWidget * parent = 0 );
         ~RelocateDialog( ) { }
 };
 
index cc4252991e943672663c0ab796af85ae12063a11..a1eff980ab4e08b187b21a67e3d1a3dea7ec26fe 100644 (file)
@@ -15,7 +15,9 @@
 #include <QApplication>
 #include <QDataStream>
 #include <QFile>
+#include <QFileDialog>
 #include <QFileInfo>
+#include <QInputDialog>
 #include <QObject>
 #include <QSet>
 #include <QStyle>
 #include "qticonloader.h"
 #include "utils.h"
 
+QString
+Utils :: remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local )
+{
+    QString path;
+
+    if( local )
+    {
+        if( dir )
+            path = QFileDialog::getExistingDirectory( parent, title, myPath );
+        else
+            path = QFileDialog::getOpenFileName( parent, title, myPath );
+    }
+    else
+        path = QInputDialog::getText( parent, title, tr( "Enter a location:" ), QLineEdit::Normal, myPath, NULL );
+
+    return path;
+}
+
 #define KILOBYTE_FACTOR 1024.0
 #define MEGABYTE_FACTOR ( 1024.0 * 1024.0 )
 #define GIGABYTE_FACTOR ( 1024.0 * 1024.0 * 1024.0 )
index d6fada5867d9acd1db35aab17eeb19941e41ebe2..0dc85c2b3cec23c4ddb90557ad75819ecbf07cb7 100644 (file)
@@ -27,7 +27,7 @@ class Utils: public QObject
         Utils( ) { }
         virtual ~Utils( ) { }
     public:
-
+        static QString remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local );
         static QString sizeToString( double size );
         static QString speedToString( const Speed& speed );
         static QString ratioToString( double ratio );