~ubuntu-branches/ubuntu/maverick/transmission/maverick-updates

« back to all changes in this revision

Viewing changes to qt/make-dialog.cc

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-12-08 10:49:11 UTC
  • mfrom: (1.1.29 upstream) (2.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20091208104911-06gio45n2nla3vpg
Tags: 1.80~b1-0ubuntu1
* New upstream release (LP: #460620), rebased on debian unstable
  remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
      Can be removed in lucid+1
    + Added quilt, liblaunchpad-integration-dev and lsb-release to Build-Depends
  - debian/rules:
    + create a po template during package build.
  - debian/patches/01_lpi.patch:
    + integrate transmission with launchpad
  - debian/patches/20_add_x-ubuntu-gettext-domain.diff:
    + add x-ubuntu-gettext-domain to .desktop file.
  - debian/transmission-daemon.default:
    - remove --auth from OPTIONS
* Fixes bugs:
  - tray menu shows wrong status for "main window" when started minimized
    (LP: #451415)
* Refreshed patches:
  - dont_build_libevent.patch
  - 99_autoreconf.patch
* Removed patches:
  - 21_onPortTested.diff, 23_tr_torrentNext.diff and
    24_tr_torrentDeleteLocalData_do_move.diff
* debian/patches/21_fix_inhibition.patch:
  - The right value for suspend inhibition is 4
* debian/control:
  - Build-Depend on libgconf2-dev to enable magnet link registration and on
    libcanberra-gtk-dev for notification sound.
* debian/watch:
  - make it detect beta versions, to be removed after 1.80 is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
 
2
 * This file Copyright (C) 2009 Mnemosyne LLC
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: make-dialog.cc 8570 2009-05-31 19:33:48Z charles $
 
10
 * $Id: make-dialog.cc 9671 2009-12-05 02:19:24Z charles $
11
11
 */
12
12
 
13
13
#include <cassert>
14
14
#include <iostream>
15
15
 
 
16
#include <QCheckBox>
16
17
#include <QDialogButtonBox>
17
 
#include <QTimer>
18
18
#include <QFileDialog>
 
19
#include <QFileIconProvider>
 
20
#include <QHBoxLayout>
19
21
#include <QLabel>
20
 
#include <QStyle>
21
 
#include <QPushButton>
22
22
#include <QLineEdit>
 
23
#include <QList>
23
24
#include <QPlainTextEdit>
24
 
#include <QCheckBox>
25
 
#include <QHBoxLayout>
 
25
#include <QProgressBar>
 
26
#include <QPushButton>
 
27
#include <QRadioButton>
 
28
#include <QSize>
 
29
#include <QStyle>
 
30
#include <QTimer>
26
31
#include <QVBoxLayout>
27
 
#include <QList>
28
 
#include <QProgressBar>
29
32
 
30
33
#include <libtransmission/transmission.h>
31
34
#include <libtransmission/makemeta.h>
33
36
 
34
37
#include "hig.h"
35
38
#include "make-dialog.h"
36
 
#include "squeezelabel.h"
37
 
#include "qticonloader.h"
 
39
#include "session.h"
38
40
#include "utils.h"
39
41
 
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
 
}
131
 
 
132
42
/***
133
43
****
134
44
***/
135
45
 
136
 
QString
137
 
MakeDialog :: getResult( ) const
138
 
{
 
46
void
 
47
MakeDialog :: onNewDialogDestroyed( QObject * o )
 
48
{
 
49
    Q_UNUSED( o );
 
50
 
 
51
    myTimer.stop( );
 
52
}
 
53
 
 
54
void
 
55
MakeDialog :: onNewButtonBoxClicked( QAbstractButton * button )
 
56
{
 
57
    switch( myNewButtonBox->standardButton( button ) )
 
58
    {
 
59
        case QDialogButtonBox::Open:
 
60
std::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
 
 
73
void
 
74
MakeDialog :: 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() );
139
83
    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
 
229
104
 
230
105
void
231
106
MakeDialog :: makeTorrent( )
233
108
    if( !myBuilder )
234
109
        return;
235
110
 
 
111
    // get the tiers
236
112
    int tier = 0;
237
113
    QList<tr_tracker_info> trackers;
238
114
    foreach( QString line, myTrackerEdit->toPlainText().split("\n") ) {
243
119
            tr_tracker_info tmp;
244
120
            tmp.announce = tr_strdup( line.toUtf8().constData( ) );
245
121
            tmp.tier = tier;
246
 
            std::cerr << "tier [" << tmp.tier << "] announce [" << tmp.announce << ']' << std::endl;
247
122
            trackers.append( tmp );
248
123
        }
249
124
    }
250
125
 
 
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( QDialogButtonBox::Ok
 
134
                                                     | QDialogButtonBox::Open
 
135
                                                     | QDialogButtonBox::Abort );
 
136
    myNewButtonBox = buttons;
 
137
    connect( buttons, SIGNAL(clicked(QAbstractButton*)),
 
138
             this, SLOT(onNewButtonBoxClicked(QAbstractButton*)) );
 
139
    top->addWidget( buttons );
 
140
    onProgress( );
 
141
    dialog->show( );
 
142
    connect( dialog, SIGNAL(destroyed(QObject*)),
 
143
             this, SLOT(onNewDialogDestroyed(QObject*)) );
 
144
    myTimer.start( 100 );
 
145
 
 
146
    // the file to create
 
147
    myTarget = QDir( myDestination ).filePath( QFileInfo(myBuilder->top).baseName() + ".torrent" );
 
148
    std::cerr << qPrintable(myTarget) << std::endl;
 
149
 
 
150
    // comment
 
151
    QString comment;
 
152
    if( myCommentCheck->isChecked() )
 
153
        comment = myCommentEdit->text().toUtf8().constData();
 
154
 
 
155
    // start making the torrent
251
156
    tr_makeMetaInfo( myBuilder,
252
 
                     NULL,
253
 
                     &trackers.front(),
 
157
                     myTarget.toUtf8().constData(),
 
158
                     (trackers.isEmpty() ? 0 : &trackers.front()),
254
159
                     trackers.size(),
255
 
                     myCommentEdit->text().toUtf8().constData(),
 
160
                     (comment.isEmpty() ? NULL : comment.toUtf8().constData()),
256
161
                     myPrivateCheck->isChecked() );
257
 
    
258
 
    refresh( );
259
 
    setIsBuilding( true );
 
162
}
 
163
 
 
164
/***
 
165
****
 
166
***/
 
167
 
 
168
void
 
169
MakeDialog :: onFileClicked( )
 
170
{
 
171
    QFileDialog * d = new QFileDialog( this, tr( "Select File" ) );
 
172
    d->setFileMode( QFileDialog::ExistingFile );
 
173
    connect( d, SIGNAL(filesSelected(const QStringList&)),
 
174
             this, SLOT(onFileSelected(const QStringList&)) );
 
175
    d->show( );
 
176
}
 
177
void
 
178
MakeDialog :: onFileSelected( const QStringList& list )
 
179
{
 
180
    if( list.size() == 1 )
 
181
    {
 
182
        myFile = list.first( );
 
183
        myFileButton->setText( QFileInfo(myFile).fileName() );
 
184
        onSourceChanged( );
 
185
    }
 
186
}
 
187
 
 
188
void
 
189
MakeDialog :: onFolderClicked( )
 
190
{
 
191
    QFileDialog * d = new QFileDialog( this, tr( "Select Folder" ) );
 
192
    d->setFileMode( QFileDialog::Directory );
 
193
    connect( d, SIGNAL(filesSelected(const QStringList&)),
 
194
             this, SLOT(onFolderSelected(const QStringList&)) );
 
195
    d->show( );
 
196
}
 
197
void
 
198
MakeDialog :: onFolderSelected( const QStringList& list )
 
199
{
 
200
    if( list.size() == 1 )
 
201
    {
 
202
        myFolder = list.first();
 
203
        myFolderButton->setText( QFileInfo(myFolder).fileName() );
 
204
        onSourceChanged( );
 
205
    }
 
206
}
 
207
 
 
208
void
 
209
MakeDialog :: onDestinationClicked( )
 
210
{
 
211
    QFileDialog * d = new QFileDialog( this, tr( "Select Folder" ) );
 
212
    d->setFileMode( QFileDialog::Directory );
 
213
    connect( d, SIGNAL(filesSelected(const QStringList&)),
 
214
             this, SLOT(onDestinationSelected(const QStringList&)) );
 
215
    d->show( );
 
216
}
 
217
void
 
218
MakeDialog :: onDestinationSelected( const QStringList& list )
 
219
{
 
220
    if( list.size() == 1 )
 
221
    {
 
222
        myDestination = list.first( );
 
223
        myDestinationButton->setText( QFileInfo(myDestination).fileName() );
 
224
    }
 
225
}
 
226
 
 
227
void
 
228
MakeDialog :: enableBuddyWhenChecked( QRadioButton * box, QWidget * buddy )
 
229
{
 
230
    connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
 
231
    buddy->setEnabled( box->isChecked( ) );
 
232
}
 
233
void
 
234
MakeDialog :: enableBuddyWhenChecked( QCheckBox * box, QWidget * buddy )
 
235
{
 
236
    connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
 
237
    buddy->setEnabled( box->isChecked( ) );
 
238
}
 
239
 
 
240
QString
 
241
MakeDialog :: getSource( ) const
 
242
{
 
243
    return myFileRadio->isChecked( ) ? myFile : myFolder;
260
244
}
261
245
 
262
246
void
263
247
MakeDialog :: onButtonBoxClicked( QAbstractButton * button )
264
248
{
265
 
    if( button == myMakeButton )
266
 
        makeTorrent( );
267
 
 
268
 
    if( button == myStopButton )
269
 
        myBuilder->abortFlag = true;
270
 
 
271
 
    if( button == myCloseButton )
272
 
        deleteLater( );
 
249
    switch( myButtonBox->standardButton( button ) )
 
250
    {
 
251
        case QDialogButtonBox::Ok:
 
252
            makeTorrent( );
 
253
            break;
 
254
 
 
255
        default: // QDialogButtonBox::Close:
 
256
            deleteLater( );
 
257
            break;
 
258
    }
273
259
}
274
260
 
275
261
/***
279
265
void
280
266
MakeDialog :: onSourceChanged( )
281
267
{
282
 
    if( myBuilder ) {
 
268
    if( myBuilder )
 
269
    {
283
270
        tr_metaInfoBuilderFree( myBuilder );
284
271
        myBuilder = 0;
285
272
    }
286
273
 
287
 
    const QString filename = mySourceEdit->text( );
 
274
    const QString filename = getSource( );
288
275
    if( !filename.isEmpty( ) )
289
276
        myBuilder = tr_metaInfoBuilderCreate( filename.toUtf8().constData() );
290
277
 
300
287
                 .arg( pieces )
301
288
                 .arg( Utils::sizeToString( myBuilder->pieceSize ) );
302
289
    }
 
290
 
303
291
    mySourceLabel->setText( text );
304
 
 
305
 
    refresh( );
306
292
}
307
293
 
308
 
void
309
 
MakeDialog :: onFileSelectedInDialog( const QString& path )
 
294
 
 
295
// bah, there doesn't seem to be any cleaner way to override
 
296
// QPlainTextEdit's default desire to be 12 lines tall
 
297
class ShortPlainTextEdit: public QPlainTextEdit {
 
298
    public:
 
299
        virtual ~ShortPlainTextEdit( ) { }
 
300
        ShortPlainTextEdit( QWidget * parent = 0 ): QPlainTextEdit(parent) { }
 
301
        virtual QSize sizeHint ( ) const { return QSize( 256, 50 ); }
 
302
};
 
303
 
 
304
MakeDialog :: MakeDialog( Session & session, QWidget * parent ):
 
305
    QDialog( parent, Qt::Dialog ),
 
306
    mySession( session ),
 
307
    myBuilder( 0 )
310
308
{
311
 
    mySourceEdit->setText( path );
 
309
    connect( &myTimer, SIGNAL(timeout()), this, SLOT(onProgress()) );
 
310
 
 
311
    setWindowTitle( tr( "New Torrent" ) );
 
312
    QVBoxLayout * top = new QVBoxLayout( this );
 
313
    top->setSpacing( HIG :: PAD );
 
314
 
 
315
    HIG * hig = new HIG;
 
316
    hig->setContentsMargins( 0, 0, 0, 0 );
 
317
    hig->addSectionTitle( tr( "Files" ) );
 
318
 
 
319
        QFileIconProvider iconProvider;
 
320
        const int iconSize( style()->pixelMetric( QStyle::PM_SmallIconSize ) );
 
321
        const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder );
 
322
        const QPixmap folderPixmap = folderIcon.pixmap( iconSize );
 
323
        QPushButton * b = new QPushButton;
 
324
        b->setIcon( folderPixmap );
 
325
        b->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
 
326
        myDestination = QDir::homePath();
 
327
        b->setText( myDestination );
 
328
        connect( b, SIGNAL(clicked(bool)),
 
329
                 this, SLOT(onDestinationClicked(void)) );
 
330
        myDestinationButton = b;
 
331
        hig->addRow( tr( "Sa&ve to:" ), b );
 
332
 
 
333
        myFolderRadio = new QRadioButton( tr( "Source F&older:" ) );
 
334
        connect( myFolderRadio, SIGNAL(toggled(bool)),
 
335
                 this, SLOT(onSourceChanged()) );
 
336
        myFolderButton = new QPushButton;
 
337
        myFolderButton->setIcon( folderPixmap );
 
338
        myFolderButton->setText( tr( "(None)" ) );
 
339
        myFolderButton->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
 
340
        connect( myFolderButton, SIGNAL(clicked(bool)),
 
341
                 this, SLOT(onFolderClicked(void)) );
 
342
        hig->addRow( myFolderRadio, myFolderButton );
 
343
        enableBuddyWhenChecked( myFolderRadio, myFolderButton );
 
344
 
 
345
        const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File );
 
346
        const QPixmap filePixmap = fileIcon.pixmap( iconSize );
 
347
        myFileRadio = new QRadioButton( tr( "Source &File:" ) );
 
348
        myFileRadio->setChecked( true );
 
349
        connect( myFileRadio, SIGNAL(toggled(bool)),
 
350
                 this, SLOT(onSourceChanged()) );
 
351
        myFileButton = new QPushButton;
 
352
        myFileButton->setText( tr( "(None)" ) );
 
353
        myFileButton->setIcon( filePixmap );
 
354
        myFileButton->setStyleSheet( "text-align: left; padding-left: 5; padding-right: 5" );
 
355
        connect( myFileButton, SIGNAL(clicked(bool)),
 
356
                 this, SLOT(onFileClicked(void)) );
 
357
        hig->addRow( myFileRadio, myFileButton );
 
358
        enableBuddyWhenChecked( myFileRadio, myFileButton );
 
359
 
 
360
        mySourceLabel = new QLabel( this );
 
361
        hig->addRow( tr( "" ), mySourceLabel );
 
362
 
 
363
    hig->addSectionDivider( );
 
364
    hig->addSectionTitle( tr( "Properties" ) );
 
365
 
 
366
        hig->addWideControl( myTrackerEdit = new ShortPlainTextEdit );
 
367
        const int height = fontMetrics().size( 0, "\n\n\n\n" ).height( );
 
368
        myTrackerEdit->setMinimumHeight( height );
 
369
        hig->addTallRow( tr( "&Trackers:" ), myTrackerEdit );
 
370
        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." ) );
 
371
        l->setAlignment( Qt::AlignLeft );
 
372
        hig->addRow( tr( "" ), l );
 
373
        myTrackerEdit->resize( 500, height );
 
374
 
 
375
        myCommentCheck = new QCheckBox( tr( "Co&mment" ) );
 
376
        myCommentEdit = new QLineEdit( );
 
377
        hig->addRow( myCommentCheck, myCommentEdit );
 
378
        enableBuddyWhenChecked( myCommentCheck, myCommentEdit );
 
379
 
 
380
        myPrivateCheck = hig->addWideCheckBox( tr( "&Private torrent" ), false );
 
381
 
 
382
    hig->finish( );
 
383
    top->addWidget( hig, 1 );
 
384
 
 
385
    myButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok
 
386
                                      | QDialogButtonBox::Close );
 
387
    connect( myButtonBox, SIGNAL(clicked(QAbstractButton*)),
 
388
             this, SLOT(onButtonBoxClicked(QAbstractButton*)) );
 
389
 
 
390
    top->addWidget( myButtonBox );
312
391
    onSourceChanged( );
313
392
}
314
393
 
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( );
 
394
MakeDialog :: ~MakeDialog( )
 
395
{
 
396
    if( myBuilder )
 
397
        tr_metaInfoBuilderFree( myBuilder );
331
398
}