7
7
* This exemption does not extend to derived works not owned by
8
8
* the Transmission project.
10
* $Id: mainwin.cc 8890 2009-08-11 18:57:49Z charles $
10
* $Id: mainwin.cc 9671 2009-12-05 02:19:24Z charles $
14
14
#include <iostream>
16
16
#include <QCheckBox>
17
#include <QCloseEvent>
17
18
#include <QDesktopServices>
18
19
#include <QFileDialog>
20
#include <QHBoxLayout>
21
#include <QInputDialog>
23
#include <QSignalMapper>
22
#include <QHBoxLayout>
23
26
#include <QSystemTrayIcon>
25
#include <QSignalMapper>
27
29
#include <libtransmission/version.h>
109
111
const QSize smallIconSize( i, i );
112
ui.action_Add->setIcon( getStockIcon( "list-add", QStyle::SP_DialogOpenButton ) );
114
ui.action_AddFile->setIcon( getStockIcon( "list-add", QStyle::SP_DialogOpenButton ) );
113
115
ui.action_New->setIcon( getStockIcon( "document-new", QStyle::SP_DesktopIcon ) );
114
116
ui.action_Properties->setIcon( getStockIcon( "document-properties", QStyle::SP_DesktopIcon ) );
115
117
ui.action_OpenFolder->setIcon( getStockIcon( "folder-open", QStyle::SP_DirOpenIcon ) );
151
153
connect( ui.action_Announce, SIGNAL(triggered()), this, SLOT(reannounceSelected()) );
152
154
connect( ui.action_StartAll, SIGNAL(triggered()), this, SLOT(startAll()));
153
155
connect( ui.action_PauseAll, SIGNAL(triggered()), this, SLOT(pauseAll()));
154
connect( ui.action_Add, SIGNAL(triggered()), this, SLOT(openTorrent()));
156
connect( ui.action_AddFile, SIGNAL(triggered()), this, SLOT(openTorrent()));
157
connect( ui.action_AddURL, SIGNAL(triggered()), this, SLOT(openURL()));
155
158
connect( ui.action_New, SIGNAL(triggered()), this, SLOT(newTorrent()));
156
159
connect( ui.action_Preferences, SIGNAL(triggered()), myPrefsDialog, SLOT(show()));
157
160
connect( ui.action_Statistics, SIGNAL(triggered()), myStatsDialog, SLOT(show()));
158
161
connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show()));
159
162
connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
160
163
connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder()));
164
connect( ui.action_CopyMagnetToClipboard, SIGNAL(triggered()), this, SLOT(copyMagnetLinkToClipboard()));
161
165
connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation()));
162
166
connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
163
167
connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show()));
166
170
QAction * sep2 = new QAction( this );
167
171
sep2->setSeparator( true );
172
QAction * sep3 = new QAction( this );
173
sep3->setSeparator( true );
170
176
QList<QAction*> actions;
171
177
actions << ui.action_Properties
172
178
<< ui.action_OpenFolder
173
<< ui.action_SetLocation
175
180
<< ui.action_Start
181
<< ui.action_Announce
176
182
<< ui.action_Pause
183
<< ui.action_CopyMagnetToClipboard
177
185
<< ui.action_Verify
178
<< ui.action_Announce
186
<< ui.action_SetLocation
180
188
<< ui.action_Remove
181
189
<< ui.action_Delete;
213
221
actionGroup->addAction( ui.action_SortByTracker );
215
223
QMenu * menu = new QMenu( );
216
menu->addAction( ui.action_Add );
224
menu->addAction( ui.action_AddFile );
225
menu->addAction( ui.action_AddURL );
217
226
menu->addSeparator( );
218
227
menu->addAction( ui.action_ShowMainWindow );
219
228
menu->addAction( ui.action_ShowMessageLog );
298
TrMainWindow :: closeEvent( QCloseEvent * event )
300
// if they're using a tray icon, close to the tray
301
// instead of exiting
302
if( !myPrefs.getBool( Prefs :: SHOW_TRAY_ICON ) )
305
toggleWindows( false );
289
315
TrMainWindow :: onSessionSourceChanged( )
291
317
myModel.clear( );
460
486
connect( ui.action_SessionRatio, SIGNAL(triggered()), this, SLOT(showSessionRatio()));
461
487
connect( ui.action_SessionTransfer, SIGNAL(triggered()), this, SLOT(showSessionTransfer()));
462
488
p = myStatsModeButton = new TrIconPushButton( this );
463
p->setIcon( getStockIcon( "view-refresh", QStyle::SP_BrowserReload ) );
489
p->setIcon( QIcon( ":/icons/ratio.png" ) );
464
490
p->setFlat( true );
466
492
h->addWidget( p );
664
TrMainWindow :: copyMagnetLinkToClipboard( )
666
const int id( *getSelectedTorrents().begin() );
667
mySession.copyMagnetLinkToClipboard( id );
638
671
TrMainWindow :: openHelp( )
640
673
const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
700
733
str = tr( "Down: %1, Up: %2" ).arg( Utils :: sizeToString( stats.downloadedBytes ) )
701
734
.arg( Utils :: sizeToString( stats.uploadedBytes ) );
703
else /* default is "total-ratio" */
736
else // default is "total-ratio"
705
738
str = tr( "Ratio: %1" ).arg( Utils :: ratioToString( mySession.getCumulativeStats().ratio ) );
719
752
const QItemSelectionModel * selectionModel( ui.listView->selectionModel( ) );
720
753
const int rowCount( model->rowCount( ) );
722
/* count how many torrents are selected, paused, etc */
755
// count how many torrents are selected, paused, etc
723
756
for( int row=0; row<rowCount; ++row ) {
724
757
const QModelIndex modelIndex( model->index( row, 0 ) );
725
758
assert( model == modelIndex.model( ) );
726
759
const Torrent * tor( model->data( modelIndex, TorrentModel::TorrentRole ).value<const Torrent*>( ) );
727
const bool isSelected( selectionModel->isSelected( modelIndex ) );
728
const bool isPaused( tor->isPaused( ) );
733
if( isSelected && isPaused )
735
if( tor->canManualAnnounce( ) )
761
const bool isSelected( selectionModel->isSelected( modelIndex ) );
762
const bool isPaused( tor->isPaused( ) );
767
if( isSelected && isPaused )
769
if( tor->canManualAnnounce( ) )
739
774
const bool haveSelection( selected > 0 );
747
782
const bool oneSelection( selected == 1 );
748
783
ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) );
784
ui.action_CopyMagnetToClipboard->setEnabled( oneSelection );
750
786
ui.action_SelectAll->setEnabled( selected < rowCount );
751
787
ui.action_StartAll->setEnabled( paused > 0 );
1060
1096
myFileDialog->setFileMode( QFileDialog::ExistingFiles );
1063
QCheckBox * button = new QCheckBox( tr( "Display &options dialog" ) );
1099
QCheckBox * button = new QCheckBox( tr( "Show &options dialog" ) );
1064
1100
button->setChecked( myPrefs.getBool( Prefs::OPTIONS_PROMPT ) );
1065
1101
QGridLayout * layout = dynamic_cast<QGridLayout*>(myFileDialog->layout());
1066
1102
layout->addWidget( button, layout->rowCount( ), 0, 1, -1, Qt::AlignLeft );
1067
1103
myFileDialogOptionsCheck = button;
1069
connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)), this, SLOT(addTorrents(const QStringList&)));
1105
connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)),
1106
this, SLOT(addTorrents(const QStringList&)));
1072
1109
myFileDialog->show( );
1113
TrMainWindow :: openURL( )
1116
const QString key = QInputDialog::getText( this,
1117
tr( "Add URL or Magnet Link" ),
1118
tr( "Add URL or Magnet Link" ),
1122
if( ok && !key.isEmpty( ) )
1123
mySession.addTorrent( key );
1076
1127
TrMainWindow :: addTorrents( const QStringList& filenames )
1078
1129
foreach( const QString& filename, filenames )