Changeset 9243


Ignore:
Timestamp:
Oct 5, 2009, 7:53:38 PM (13 years ago)
Author:
charles
Message:

(trunk qt) sync the Qt client's "New Torrent" dialog with the GTK+ client's rewrite

Location:
trunk/qt
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/hig.cc

    r8570 r9243  
    1111 */
    1212
     13#include <iostream>
     14
    1315#include <QCheckBox>
    1416#include <QGridLayout>
     
    2224    QWidget( parent ),
    2325    myRow( 0 ),
     26    myHasTall( false ),
    2427    myGrid( new QGridLayout( this ) )
    2528{
     
    127130HIG :: addLabel( const QString& text )
    128131{
    129     QLabel * label = new QLabel( this );
    130     label->setText( text );
    131     label->setAlignment( Qt::AlignLeft );
     132    QLabel * label = new QLabel( text, this );
    132133    addLabel( label );
     134    return label;
     135}
     136
     137void
     138HIG :: addTallLabel( QWidget * w )
     139{
     140    QHBoxLayout * h = new QHBoxLayout( );
     141    h->addSpacing( 18 );
     142    h->addWidget( w );
     143    myGrid->addLayout( h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignTop );
     144}
     145
     146QLabel*
     147HIG :: addTallLabel( const QString& text )
     148{
     149    QLabel * label = new QLabel( text, this );
     150    addTallLabel( label );
    133151    return label;
    134152}
     
    152170    addControl( control );
    153171    label->setBuddy( buddy ? buddy : control );
     172    ++myRow;
     173    return label;
     174}
     175
     176QLabel *
     177HIG :: addTallRow( const QString& text, QWidget * control, QWidget * buddy )
     178{
     179    QLabel* label = addTallLabel( text );
     180    label->setBuddy( buddy ? buddy : control );
     181    addControl( control );
     182    myHasTall = true;
     183    myGrid->setRowStretch ( myRow, 1 );
    154184    ++myRow;
    155185    return label;
     
    196226HIG :: finish( )
    197227{
    198     QWidget * w = new QWidget( this );
    199     myGrid->addWidget( w, myRow, 0, 1, 2 );
    200     myGrid->setRowStretch( myRow, 100 );
    201     ++myRow;
    202 }
     228    if( !myHasTall ) {
     229        QWidget * w = new QWidget( this );
     230        myGrid->addWidget( w, myRow, 0, 1, 2 );
     231        myGrid->setRowStretch( myRow, 100 );
     232        ++myRow;
     233    }
     234}
  • trunk/qt/hig.h

    r8570 r9243  
    4747        QCheckBox* addWideCheckBox( const QString&, bool isChecked );
    4848        QLabel* addLabel( const QString& );
     49        QLabel* addTallLabel( const QString& );
    4950        void addLabel( QWidget * );
     51        void addTallLabel( QWidget * );
    5052        void addControl( QWidget * );
    5153        void addControl( QLayout * );
     
    5456        void addRow( QWidget * label, QWidget * control, QWidget * buddy=0 );
    5557        void addRow( QWidget * label, QLayout * control, QWidget * buddy );
     58        QLabel* addTallRow( const QString & label, QWidget * control, QWidget * buddy=0 );
    5659        void finish( );
    5760
     
    6164    private:
    6265        int myRow;
     66        bool myHasTall;
    6367        QGridLayout * myGrid;
    6468};
  • trunk/qt/mainwin.cc

    r9178 r9243  
    10631063TrMainWindow :: newTorrent( )
    10641064{
    1065     MakeDialog * d = new MakeDialog( mySession, this );
    1066     d->show( );
     1065    MakeDialog * dialog = new MakeDialog( mySession, this );
     1066    dialog->show( );
    10671067}
    10681068
  • trunk/qt/make-dialog.cc

    r8570 r9243  
    1414#include <iostream>
    1515
     16#include <QCheckBox>
    1617#include <QDialogButtonBox>
     18#include <QFileDialog>
     19#include <QFileIconProvider>
     20#include <QHBoxLayout>
     21#include <QLabel>
     22#include <QLineEdit>
     23#include <QList>
     24#include <QPlainTextEdit>
     25#include <QProgressBar>
     26#include <QPushButton>
     27#include <QRadioButton>
     28#include <QSize>
     29#include <QStyle>
    1730#include <QTimer>
    18 #include <QFileDialog>
    19 #include <QLabel>
    20 #include <QStyle>
    21 #include <QPushButton>
    22 #include <QLineEdit>
    23 #include <QPlainTextEdit>
    24 #include <QCheckBox>
    25 #include <QHBoxLayout>
    2631#include <QVBoxLayout>
    27 #include <QList>
    28 #include <QProgressBar>
    2932
    3033#include <libtransmission/transmission.h>
     
    3437#include "hig.h"
    3538#include "make-dialog.h"
    36 #include "squeezelabel.h"
    37 #include "qticonloader.h"
     39#include "session.h"
    3840#include "utils.h"
    39 
    40 MakeDialog :: MakeDialog( Session & mySession, QWidget * parent ):
    41     QDialog( parent, Qt::Dialog ),
    42     myBuilder( 0 ),
    43     myIsBuilding( 0 )
    44 {
    45     Q_UNUSED( mySession );
    46     connect( &myTimer, SIGNAL(timeout()), this, SLOT(onProgress()) );
    47 
    48     setWindowTitle( tr( "New Torrent" ) );
    49     QVBoxLayout * top = new QVBoxLayout( this );
    50     top->setSpacing( HIG :: PAD );
    51 
    52     HIG * hig = new HIG;
    53     hig->setContentsMargins( 0, 0, 0, 0 );
    54     hig->addSectionTitle( tr( "Source" ) );
    55     hig->addWideControl( mySourceEdit = new QLineEdit );
    56     connect( mySourceEdit, SIGNAL(textChanged(const QString&)), this, SLOT(refresh()));
    57     connect( mySourceEdit, SIGNAL(editingFinished()), this, SLOT(onSourceChanged()));
    58     QHBoxLayout * h = new QHBoxLayout;
    59     h->setContentsMargins( 0, 0, 0, 0 );
    60     h->addWidget( mySourceLabel = new QLabel( tr( "<i>No source selected</i>" ) ) );
    61     mySourceLabel->setMinimumWidth( fontMetrics().size( 0, "420 KB in 412 Files; 402 Pieces @ 42 KB each" ).width( ) );
    62     h->addStretch( 1 );
    63     h->setSpacing( HIG :: PAD );
    64     QPushButton * b = new QPushButton( style()->standardIcon( QStyle::SP_DirIcon ), tr( "F&older" ) );
    65     connect( b, SIGNAL(clicked(bool)), this, SLOT(onFolderButtonPressed()));
    66     h->addWidget( b );
    67     b = new QPushButton( style()->standardIcon( QStyle::SP_FileIcon ), tr( "&File" ) );
    68     connect( b, SIGNAL(clicked(bool)), this, SLOT(onFileButtonPressed()));
    69     h->addWidget( b );
    70     hig->addWideControl( h );
    71     hig->addSectionDivider( );
    72     hig->addSectionTitle( tr( "Trackers" ) );
    73     hig->addWideControl( myTrackerEdit = new QPlainTextEdit );
    74     connect( myTrackerEdit, SIGNAL(textChanged()), this, SLOT(refresh()) );
    75     const int height = fontMetrics().size( 0, "\n\n\n\n" ).height( );
    76     myTrackerEdit->setMinimumHeight( height );
    77     myTrackerEdit->setMaximumHeight( height );
    78     hig->addWideControl( new QLabel( tr( "Separate tiers with an empty line" ) ) );
    79     hig->addSectionDivider( );
    80     hig->addSectionTitle( tr( "Options" ) );
    81     hig->addRow( tr( "Commen&t:" ), myCommentEdit = new QLineEdit );
    82     hig->addWideControl( myPrivateCheck = new QCheckBox( "&Private torrent" ) );
    83     hig->addSectionDivider( );
    84     hig->addSectionDivider( );
    85     hig->addSectionTitle( tr( "Progress" ) );
    86     QProgressBar * p = myProgressBar = new QProgressBar;
    87     p->setTextVisible( false );
    88     p->setMinimum( 0 );
    89     p->setMaximum( 100 );
    90     p->setValue( 0 );
    91     hig->addWideControl( p );
    92     hig->addWideControl( myProgressLabel = new QLabel( "<i>No source selected</i>" ) );
    93     hig->finish( );
    94     top->addWidget( hig, 1 );
    95 
    96     //QFrame * f = new QFrame;
    97     //f->setFrameShape( QFrame :: HLine );
    98     //top->addWidget( f );
    99 
    100 
    101     QIcon icon;
    102     QDialogButtonBox * buttons = new QDialogButtonBox( this );
    103 
    104     icon = style()->standardIcon( QStyle::SP_FileDialogNewFolder );
    105     icon = QtIconLoader :: icon( "document-new", icon );
    106     b = myMakeButton = new QPushButton( icon, tr( "&New Torrent" ) );
    107     buttons->addButton( b, QDialogButtonBox::ActionRole );
    108 
    109     icon = style()->standardIcon( QStyle::SP_DialogCancelButton );
    110     icon = QtIconLoader :: icon( "process-stop", icon );
    111     b = myStopButton = new QPushButton( icon, tr( "&Stop" ) );
    112     buttons->addButton( b, QDialogButtonBox::RejectRole );
    113 
    114     icon = style()->standardIcon( QStyle::SP_DialogCloseButton );
    115     icon = QtIconLoader :: icon( "window-close", icon );
    116     b = myCloseButton = new QPushButton( icon, tr( "&Close" ) );
    117     buttons->addButton( b, QDialogButtonBox::AcceptRole );
    118 
    119     connect( buttons, SIGNAL(clicked(QAbstractButton*)),
    120              this, SLOT(onButtonBoxClicked(QAbstractButton*)) );
    121 
    122     top->addWidget( buttons );
    123     refresh( );
    124 }
    125 
    126 MakeDialog :: ~MakeDialog( )
    127 {
    128     if( myBuilder )
    129         tr_metaInfoBuilderFree( myBuilder );
    130 }
    13141
    13242/***
     
    13444***/
    13545
    136 QString
    137 MakeDialog :: getResult( ) const
    138 {
     46void
     47MakeDialog :: onNewDialogDestroyed( QObject * o )
     48{
     49    Q_UNUSED( o );
     50
     51    myTimer.stop( );
     52}
     53
     54void
     55MakeDialog :: onNewButtonBoxClicked( QAbstractButton * button )
     56{
     57    switch( myNewButtonBox->standardButton( button ) )
     58    {
     59        case QDialogButtonBox::Open:
     60std::cerr << "calling mySession.addTorrent( " << qPrintable(myTarget) << ", " << qPrintable(QFileInfo(myBuilder->top).dir().path()) << ')' << std::endl;
     61            mySession.addTorrent( myTarget, QFileInfo(myBuilder->top).dir().path() );
     62            break;
     63        case QDialogButtonBox::Abort:
     64            myBuilder->abortFlag = true;
     65            break;
     66        default: // QDialogButtonBox::Ok:
     67            break;
     68
     69    }
     70    myNewDialog->deleteLater( );
     71}
     72
     73void
     74MakeDialog :: onProgress( )
     75{
     76    // progress bar
     77    const tr_metainfo_builder * b = myBuilder;
     78    const double denom = b->pieceCount ? b->pieceCount : 1;
     79    myNewProgress->setValue( (int) ((100.0 * b->pieceIndex) / denom ) );
     80
     81    // progress label
     82    const QString base( QFileInfo(b->top).baseName() );
    13983    QString str;
    140 
    141     switch( myBuilder->result )
    142     {
    143         case TR_MAKEMETA_OK:
    144             str = tr( "%1.torrent created!" ).arg( myBuilder->top );
    145             break;
    146 
    147         case TR_MAKEMETA_URL:
    148             str = tr( "Error: Invalid URL" );
    149             break;
    150 
    151         case TR_MAKEMETA_CANCELLED:
    152             str = tr( "Torrent creation cancelled" );
    153             break;
    154 
    155         case TR_MAKEMETA_IO_READ:
    156             str = tr( "Error: Couldn't read \"%1\": %2" )
    157                      .arg( myBuilder->errfile )
    158                      .arg( tr_strerror( myBuilder->my_errno ) );
    159             break;
    160 
    161         case TR_MAKEMETA_IO_WRITE:
    162             str = tr( "Error: Couldn't create \"%1\": %2" )
    163                      .arg( myBuilder->errfile )
    164                      .arg( tr_strerror( myBuilder->my_errno ) );
    165             break;
    166     }
    167 
    168     return str;
    169 }
    170 
    171 void
    172 MakeDialog :: refresh( )
    173 {
    174     QString progressText;
    175     bool canBuild = true;
    176 
    177     if( myIsBuilding ) {
    178         progressText = tr( "Creating %1.torrent" ).arg( myBuilder->top );
    179         canBuild = false;
    180     } else if( mySourceEdit->text().trimmed().isEmpty() ) {
    181         progressText = tr( "<i>No source selected<i>" );
    182         canBuild = false;
    183     } else if( myTrackerEdit->toPlainText().isEmpty() ) {
    184         progressText = tr( "<i>No tracker announce URLs listed</i>" );
    185         canBuild = false;
    186     } else if( myBuilder && myBuilder->isDone ) {
    187         progressText = getResult( );
    188         canBuild = true;
    189     }
    190 
    191     myProgressLabel->setText( progressText );
    192     myMakeButton->setEnabled( canBuild && myBuilder );
    193     myCloseButton->setEnabled( !myIsBuilding );
    194     myStopButton->setEnabled( myIsBuilding );
    195 }
    196 
    197 void
    198 MakeDialog :: setIsBuilding( bool isBuilding )
    199 {
    200     myIsBuilding = isBuilding;
    201 
    202     if( myBuilder )
    203         myBuilder->result = TR_MAKEMETA_OK;
    204 
    205     if( isBuilding )
    206         myProgressBar->setValue( 0 );
    207 
    208     if( isBuilding )
    209         myTimer.start( 100 );
    210     else
    211         myTimer.stop( );
    212 
    213     refresh( );
    214 }
    215 
    216 void
    217 MakeDialog :: onProgress( )
    218 {
    219     const double denom = myBuilder->pieceCount ? myBuilder->pieceCount : 1;
    220     myProgressBar->setValue( (int) ((100.0 * myBuilder->pieceIndex) / denom ) );
    221 
    222     refresh( );
    223 
    224     if( myBuilder->isDone )
    225         setIsBuilding( false );
    226 
    227     //tr_metainfo_builder_err    result;
    228 }
     84    if( !b->isDone )
     85        str = tr( "Creating \"%1\"" ).arg( base );
     86    else if( b->result == TR_MAKEMETA_OK )
     87        str = tr( "Created \"%1\"!" ).arg( base );
     88    else if( b->result == TR_MAKEMETA_URL )
     89        str = tr( "Error: invalid announce URL \"%1\"" ).arg( b->errfile );
     90    else if( b->result == TR_MAKEMETA_CANCELLED )
     91        str = tr( "Cancelled" );
     92    else if( b->result == TR_MAKEMETA_IO_READ )
     93        str = tr( "Error reading \"%1\": %2" ).arg( b->errfile ).arg( strerror(b->my_errno) );
     94    else if( b->result == TR_MAKEMETA_IO_WRITE )
     95        str = tr( "Error writing \"%1\": %2" ).arg( b->errfile ).arg( strerror(b->my_errno) );
     96    myNewLabel->setText( str );
     97
     98    // buttons
     99    (myNewButtonBox->button(QDialogButtonBox::Abort))->setEnabled( !b->isDone );
     100    (myNewButtonBox->button(QDialogButtonBox::Ok))->setEnabled( b->isDone );
     101    (myNewButtonBox->button(QDialogButtonBox::Open))->setEnabled( b->isDone && !b->result );
     102}
     103
    229104
    230105void
     
    234109        return;
    235110
     111    // get the tiers
    236112    int tier = 0;
    237113    QList<tr_tracker_info> trackers;
     
    244120            tmp.announce = tr_strdup( line.toUtf8().constData( ) );
    245121            tmp.tier = tier;
    246             std::cerr << "tier [" << tmp.tier << "] announce [" << tmp.announce << ']' << std::endl;
    247122            trackers.append( tmp );
    248123        }
    249124    }
    250125
     126    // pop up the dialog
     127    QDialog * dialog = new QDialog( this );
     128    dialog->setWindowTitle( tr( "New Torrent" ) );
     129    myNewDialog = dialog;
     130    QVBoxLayout * top = new QVBoxLayout( dialog );
     131    top->addWidget(( myNewLabel = new QLabel));
     132    top->addWidget(( myNewProgress = new QProgressBar ));
     133    QDialogButtonBox * buttons = new QDialogButtonBox( dialog );
     134    buttons->setStandardButtons( QDialogButtonBox::Ok
     135                               | QDialogButtonBox::Open
     136                               | QDialogButtonBox::Abort );
     137    myNewButtonBox = buttons;
     138    connect( buttons, SIGNAL(clicked(QAbstractButton*)),
     139             this, SLOT(onNewButtonBoxClicked(QAbstractButton*)) );
     140    top->addWidget( buttons );
     141    onProgress( );
     142    dialog->show( );
     143    connect( dialog, SIGNAL(destroyed(QObject*)),
     144             this, SLOT(onNewDialogDestroyed(QObject*)) );
     145    myTimer.start( 100 );
     146
     147    // the file to create
     148    myTarget = QDir( myDestination ).filePath( QFileInfo(myBuilder->top).baseName() + ".torrent" );
     149    std::cerr << qPrintable(myTarget) << std::endl;
     150
     151    // comment
     152    QString comment;
     153    if( myCommentCheck->isChecked() )
     154        comment = myCommentEdit->text().toUtf8().constData();
     155
     156    // start making the torrent
    251157    tr_makeMetaInfo( myBuilder,
    252                      NULL,
    253                      &trackers.front(),
     158                     myTarget.toUtf8().constData(),
     159                     (trackers.isEmpty() ? 0 : &trackers.front()),
    254160                     trackers.size(),
    255                      myCommentEdit->text().toUtf8().constData(),
     161                     (comment.isEmpty() ? NULL : comment.toUtf8().constData()),
    256162                     myPrivateCheck->isChecked() );
    257    
    258     refresh( );
    259     setIsBuilding( true );
    260 }
    261 
    262 void
    263 MakeDialog :: onButtonBoxClicked( QAbstractButton * button )
    264 {
    265     if( button == myMakeButton )
    266         makeTorrent( );
    267 
    268     if( button == myStopButton )
    269         myBuilder->abortFlag = true;
    270 
    271     if( button == myCloseButton )
    272         deleteLater( );
    273163}
    274164
     
    278168
    279169void
     170MakeDialog :: onFileClicked( )
     171{
     172    QFileDialog * d = new QFileDialog( this, tr( "Select File" ) );
     173    d->setFileMode( QFileDialog::ExistingFile );
     174    connect( d, SIGNAL(filesSelected(const QStringList&)),
     175             this, SLOT(onFileSelected(const QStringList&)) );
     176    d->show( );
     177}
     178void
     179MakeDialog :: onFileSelected( const QStringList& list )
     180{
     181    if( list.size() == 1 )
     182    {
     183        myFile = list.first( );
     184        myFileButton->setText( QFileInfo(myFile).fileName() );
     185        onSourceChanged( );
     186    }
     187}
     188
     189void
     190MakeDialog :: onFolderClicked( )
     191{
     192    QFileDialog * d = new QFileDialog( this, tr( "Select Folder" ) );
     193    d->setFileMode( QFileDialog::Directory );
     194    connect( d, SIGNAL(filesSelected(const QStringList&)),
     195             this, SLOT(onFolderSelected(const QStringList&)) );
     196    d->show( );
     197}
     198void
     199MakeDialog :: onFolderSelected( const QStringList& list )
     200{
     201    if( list.size() == 1 )
     202    {
     203        myFolder = list.first();
     204        myFolderButton->setText( QFileInfo(myFolder).fileName() );
     205        onSourceChanged( );
     206    }
     207}
     208
     209void
     210MakeDialog :: onDestinationClicked( )
     211{
     212    QFileDialog * d = new QFileDialog( this, tr( "Select Folder" ) );
     213    d->setFileMode( QFileDialog::Directory );
     214    connect( d, SIGNAL(filesSelected(const QStringList&)),
     215             this, SLOT(onDestinationSelected(const QStringList&)) );
     216    d->show( );
     217}
     218void
     219MakeDialog :: onDestinationSelected( const QStringList& list )
     220{
     221    if( list.size() == 1 )
     222    {
     223        myDestination = list.first( );
     224        myDestinationButton->setText( QFileInfo(myDestination).fileName() );
     225    }
     226}
     227
     228void
     229MakeDialog :: enableBuddyWhenChecked( QRadioButton * box, QWidget * buddy )
     230{
     231    connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
     232    buddy->setEnabled( box->isChecked( ) );
     233}
     234void
     235MakeDialog :: enableBuddyWhenChecked( QCheckBox * box, QWidget * buddy )
     236{
     237    connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
     238    buddy->setEnabled( box->isChecked( ) );
     239}
     240
     241QString
     242MakeDialog :: getSource( ) const
     243{
     244    return myFileRadio->isChecked( ) ? myFile : myFolder;
     245}
     246
     247void
     248MakeDialog :: onButtonBoxClicked( QAbstractButton * button )
     249{
     250    switch( myButtonBox->standardButton( button ) )
     251    {
     252        case QDialogButtonBox::Ok:
     253            makeTorrent( );
     254            break;
     255
     256        default: // QDialogButtonBox::Close:
     257            deleteLater( );
     258            break;
     259    }
     260}
     261
     262/***
     263****
     264***/
     265
     266void
    280267MakeDialog :: onSourceChanged( )
    281268{
    282     if( myBuilder ) {
     269    if( myBuilder )
     270    {
    283271        tr_metaInfoBuilderFree( myBuilder );
    284272        myBuilder = 0;
    285273    }
    286274
    287     const QString filename = mySourceEdit->text( );
     275    const QString filename = getSource( );
    288276    if( !filename.isEmpty( ) )
    289277        myBuilder = tr_metaInfoBuilderCreate( filename.toUtf8().constData() );
     
    301289                 .arg( Utils::sizeToString( myBuilder->pieceSize ) );
    302290    }
     291
    303292    mySourceLabel->setText( text );
    304 
    305     refresh( );
    306 }
    307 
    308 void
    309 MakeDialog :: onFileSelectedInDialog( const QString& path )
    310 {
    311     mySourceEdit->setText( path );
     293}
     294
     295
     296// bah, there doesn't seem to be any cleaner way to override
     297// QPlainTextEdit's default desire to be 12 lines tall
     298class ShortPlainTextEdit: public QPlainTextEdit {
     299    public:
     300        virtual ~ShortPlainTextEdit( ) { }
     301        ShortPlainTextEdit( QWidget * parent = 0 ): QPlainTextEdit(parent) { }
     302        virtual QSize sizeHint ( ) const { return QSize( 256, 50 ); }
     303};
     304
     305MakeDialog :: MakeDialog( Session & session, QWidget * parent ):
     306    QDialog( parent, Qt::Dialog ),
     307    mySession( session ),
     308    myBuilder( 0 )
     309{
     310    connect( &myTimer, SIGNAL(timeout()), this, SLOT(onProgress()) );
     311
     312    setWindowTitle( tr( "New Torrent" ) );
     313    QVBoxLayout * top = new QVBoxLayout( this );
     314    top->setSpacing( HIG :: PAD );
     315
     316    HIG * hig = new HIG;
     317    hig->setContentsMargins( 0, 0, 0, 0 );
     318    hig->addSectionTitle( tr( "Files" ) );
     319
     320        QFileIconProvider iconProvider;
     321        const int iconSize( style()->pixelMetric( QStyle::PM_SmallIconSize ) );
     322        const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder );
     323        const QPixmap folderPixmap = folderIcon.pixmap( iconSize );
     324        QPushButton * b = new QPushButton;
     325        b->setIcon( folderPixmap );
     326        b->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
     327        myDestination = QDir::homePath();
     328        b->setText( myDestination );
     329        connect( b, SIGNAL(clicked(bool)),
     330                 this, SLOT(onDestinationClicked(void)) );
     331        myDestinationButton = b;
     332        hig->addRow( tr( "Sa&ve to:" ), b );
     333
     334        myFolderRadio = new QRadioButton( tr( "Source F&older:" ) );
     335        connect( myFolderRadio, SIGNAL(toggled(bool)),
     336                 this, SLOT(onSourceChanged()) );
     337        myFolderButton = new QPushButton;
     338        myFolderButton->setIcon( folderPixmap );
     339        myFolderButton->setText( tr( "(None)" ) );
     340        myFolderButton->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
     341        connect( myFolderButton, SIGNAL(clicked(bool)),
     342                 this, SLOT(onFolderClicked(void)) );
     343        hig->addRow( myFolderRadio, myFolderButton );
     344        enableBuddyWhenChecked( myFolderRadio, myFolderButton );
     345
     346        const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File );
     347        const QPixmap filePixmap = fileIcon.pixmap( iconSize );
     348        myFileRadio = new QRadioButton( tr( "Source &File:" ) );
     349        myFileRadio->setChecked( true );
     350        connect( myFileRadio, SIGNAL(toggled(bool)),
     351                 this, SLOT(onSourceChanged()) );
     352        myFileButton = new QPushButton;
     353        myFileButton->setText( tr( "(None)" ) );
     354        myFileButton->setIcon( filePixmap );
     355        myFileButton->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
     356        connect( myFileButton, SIGNAL(clicked(bool)),
     357                 this, SLOT(onFileClicked(void)) );
     358        hig->addRow( myFileRadio, myFileButton );
     359        enableBuddyWhenChecked( myFileRadio, myFileButton );
     360
     361        mySourceLabel = new QLabel( this );
     362        hig->addRow( tr( "" ), mySourceLabel );
     363
     364    hig->addSectionDivider( );
     365    hig->addSectionTitle( tr( "Properties" ) );
     366
     367        hig->addWideControl( myTrackerEdit = new ShortPlainTextEdit );
     368        const int height = fontMetrics().size( 0, "\n\n\n\n" ).height( );
     369        myTrackerEdit->setMinimumHeight( height );
     370        hig->addTallRow( tr( "&Trackers:" ), myTrackerEdit );
     371        QLabel * l = new QLabel( tr( "To add a backup URL, add it on the line after the primary URL.\nTo add another primary URL, add it after a blank line." ) );
     372        l->setAlignment( Qt::AlignLeft );
     373        hig->addRow( tr( "" ), l );
     374        myTrackerEdit->resize( 500, height );
     375
     376        myCommentCheck = new QCheckBox( tr( "Co&mment" ) );
     377        myCommentEdit = new QLineEdit( );
     378        hig->addRow( myCommentCheck, myCommentEdit );
     379        enableBuddyWhenChecked( myCommentCheck, myCommentEdit );
     380
     381        myPrivateCheck = hig->addWideCheckBox( tr( "&Private torrent" ), false );
     382
     383    hig->finish( );
     384    top->addWidget( hig, 1 );
     385
     386    myButtonBox = new QDialogButtonBox( this );
     387    myButtonBox->setStandardButtons( QDialogButtonBox::Ok
     388                               | QDialogButtonBox::Close );
     389    connect( myButtonBox, SIGNAL(clicked(QAbstractButton*)),
     390             this, SLOT(onButtonBoxClicked(QAbstractButton*)) );
     391
     392    top->addWidget( myButtonBox );
    312393    onSourceChanged( );
    313394}
    314395
    315 void
    316 MakeDialog :: onFolderButtonPressed( )
    317 {
    318     QFileDialog * f = new QFileDialog( this );
    319     f->setFileMode( QFileDialog :: Directory );
    320     connect( f, SIGNAL(fileSelected(const QString&)), this, SLOT(onFileSelectedInDialog(const QString&)));
    321     f->show( );
    322 }
    323 
    324 void
    325 MakeDialog :: onFileButtonPressed( )
    326 {
    327     QFileDialog * f = new QFileDialog( this );
    328     f->setFileMode( QFileDialog :: ExistingFile );
    329     connect( f, SIGNAL(fileSelected(const QString&)), this, SLOT(onFileSelectedInDialog(const QString&)));
    330     f->show( );
    331 }
     396MakeDialog :: ~MakeDialog( )
     397{
     398    if( myBuilder )
     399        tr_metaInfoBuilderFree( myBuilder );
     400}
  • trunk/qt/make-dialog.h

    r8570 r9243  
    2222struct QCheckBox;
    2323struct QLabel;
     24struct QPushButton;
     25struct QRadioButton;
     26struct Session;
    2427struct QProgressBar;
    25 struct QPushButton;
    26 struct Session;
     28struct QDialogButtonBox;
    2729
    2830extern "C"
     
    3638
    3739    private slots:
    38         void onFolderButtonPressed( );
    39         void onFileButtonPressed( );
    40         void onFileSelectedInDialog( const QString& path );
    4140        void onSourceChanged( );
    4241        void onButtonBoxClicked( QAbstractButton* );
     42        void onNewButtonBoxClicked( QAbstractButton* );
     43        void onNewDialogDestroyed( QObject* );
    4344        void onProgress( );
    44         void refresh( );
     45
     46        void onFolderClicked( );
     47        void onFolderSelected( const QStringList& );
     48        void onFileClicked( );
     49        void onFileSelected( const QStringList& );
     50        void onDestinationClicked( );
     51        void onDestinationSelected( const QStringList& );
    4552
    4653    private:
    4754        void makeTorrent( );
    48         void refreshButtons( );
    49         void setIsBuilding( bool );
    50         QString getResult( ) const;
    51 
     55        QString getSource( ) const;
     56        void enableBuddyWhenChecked( QCheckBox *, QWidget * );
     57        void enableBuddyWhenChecked( QRadioButton *, QWidget * );
    5258
    5359    private:
     60        Session& mySession;
     61        QString myDestination;
     62        QString myTarget;
     63        QString myFile;
     64        QString myFolder;
    5465        QTimer myTimer;
    55         QLineEdit * mySourceEdit;
    56         QLabel * mySourceLabel;
     66        QRadioButton * myFolderRadio;
     67        QRadioButton * myFileRadio;
     68        QPushButton * myDestinationButton;
     69        QPushButton * myFileButton;
     70        QPushButton * myFolderButton;
    5771        QPlainTextEdit * myTrackerEdit;
     72        QCheckBox * myCommentCheck;
    5873        QLineEdit * myCommentEdit;
    5974        QCheckBox * myPrivateCheck;
    60         QProgressBar * myProgressBar;
    61         QLabel * myProgressLabel;
    62         QPushButton * myMakeButton;
    63         QPushButton * myCloseButton;
    64         QPushButton * myStopButton;
     75        QLabel * mySourceLabel;
     76        QDialogButtonBox * myButtonBox;
     77        QProgressBar * myNewProgress;
     78        QLabel * myNewLabel;
     79        QDialogButtonBox * myNewButtonBox;
     80        QDialog * myNewDialog;
    6581        struct tr_metainfo_builder * myBuilder;
    66         bool myIsBuilding;
    6782
    6883    public:
  • trunk/qt/session.cc

    r8588 r9243  
    551551    if( mySession  )
    552552    {
     553std::cerr << request << std::endl;
    553554        tr_rpc_request_exec_json( mySession, request, strlen( request ), localSessionCallback, this );
    554555    }
     
    823824Session :: addTorrent( QString filename )
    824825{
     826    addTorrent( filename, myPrefs.getString( Prefs::DOWNLOAD_DIR ) );
     827}
     828
     829void
     830Session :: addTorrent( QString filename, QString localPath )
     831{
    825832    QFile file( filename );
    826833    file.open( QIODevice::ReadOnly );
     
    837844        tr_bencDictAddStr( &top, "method", "torrent-add" );
    838845        args = tr_bencDictAddDict( &top, "arguments", 3 );
    839         tr_bencDictAddStr( args, "download-dir", qPrintable(myPrefs.getString(Prefs::DOWNLOAD_DIR)) );
     846        tr_bencDictAddStr( args, "download-dir", qPrintable(localPath) );
    840847        tr_bencDictAddRaw( args, "metainfo", b64, b64len  );
    841848        tr_bencDictAddInt( args, "paused", !myPrefs.getBool( Prefs::START ) );
  • trunk/qt/session.h

    r8570 r9243  
    105105        void initTorrents( const QSet<int>& ids = QSet<int>() );
    106106        void addTorrent( QString filename );
     107        void addTorrent( QString filename, QString localPath );
    107108        void removeTorrents( const QSet<int>& torrentIds, bool deleteFiles=false );
    108109        void verifyTorrents( const QSet<int>& torrentIds );
Note: See TracChangeset for help on using the changeset viewer.