1 | /* |
---|
2 | * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com> |
---|
3 | * |
---|
4 | * This file is licensed by the GPL version 2. Works owned by the |
---|
5 | * Transmission project are granted a special exemption to clause 2(b) |
---|
6 | * so that the bulk of its code can remain under the MIT license. |
---|
7 | * This exemption does not extend to derived works not owned by |
---|
8 | * the Transmission project. |
---|
9 | * |
---|
10 | * $Id: mainwin.cc 9247 2009-10-06 00:27:26Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #include <cassert> |
---|
14 | #include <iostream> |
---|
15 | |
---|
16 | #include <QCheckBox> |
---|
17 | #include <QCloseEvent> |
---|
18 | #include <QDesktopServices> |
---|
19 | #include <QFileDialog> |
---|
20 | #include <QHBoxLayout> |
---|
21 | #include <QLabel> |
---|
22 | #include <QSignalMapper> |
---|
23 | #include <QSize> |
---|
24 | #include <QStyle> |
---|
25 | #include <QSystemTrayIcon> |
---|
26 | #include <QUrl> |
---|
27 | |
---|
28 | #include <libtransmission/version.h> |
---|
29 | |
---|
30 | #include "about.h" |
---|
31 | #include "details.h" |
---|
32 | #include "filters.h" |
---|
33 | #include "hig.h" |
---|
34 | #include "mainwin.h" |
---|
35 | #include "make-dialog.h" |
---|
36 | #include "options.h" |
---|
37 | #include "prefs.h" |
---|
38 | #include "prefs-dialog.h" |
---|
39 | #include "relocate.h" |
---|
40 | #include "session.h" |
---|
41 | #include "session-dialog.h" |
---|
42 | #include "speed.h" |
---|
43 | #include "stats-dialog.h" |
---|
44 | #include "torrent-delegate.h" |
---|
45 | #include "torrent-delegate-min.h" |
---|
46 | #include "torrent-filter.h" |
---|
47 | #include "torrent-model.h" |
---|
48 | #include "triconpushbutton.h" |
---|
49 | #include "ui_mainwin.h" |
---|
50 | #include "utils.h" |
---|
51 | #include "qticonloader.h" |
---|
52 | |
---|
53 | #define PREFS_KEY "prefs-key"; |
---|
54 | |
---|
55 | QIcon |
---|
56 | TrMainWindow :: getStockIcon( const QString& freedesktop_name, int fallback ) |
---|
57 | { |
---|
58 | QIcon fallbackIcon; |
---|
59 | |
---|
60 | if( fallback > 0 ) |
---|
61 | fallbackIcon = style()->standardIcon( QStyle::StandardPixmap( fallback ), 0, this ); |
---|
62 | |
---|
63 | return QtIconLoader::icon( freedesktop_name, fallbackIcon ); |
---|
64 | } |
---|
65 | |
---|
66 | namespace |
---|
67 | { |
---|
68 | QSize calculateTextButtonSizeHint( QPushButton * button ) |
---|
69 | { |
---|
70 | QStyleOptionButton opt; |
---|
71 | opt.initFrom( button ); |
---|
72 | QString s( button->text( ) ); |
---|
73 | if( s.isEmpty( ) ) |
---|
74 | s = QString::fromLatin1( "XXXX" ); |
---|
75 | QFontMetrics fm = button->fontMetrics( ); |
---|
76 | QSize sz = fm.size( Qt::TextShowMnemonic, s ); |
---|
77 | return button->style()->sizeFromContents( QStyle::CT_PushButton, &opt, sz, button ).expandedTo( QApplication::globalStrut( ) ); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& model, bool minimized ): |
---|
83 | myLastFullUpdateTime( 0 ), |
---|
84 | mySessionDialog( new SessionDialog( session, prefs, this ) ), |
---|
85 | myPrefsDialog( new PrefsDialog( session, prefs, this ) ), |
---|
86 | myAboutDialog( new AboutDialog( this ) ), |
---|
87 | myStatsDialog( new StatsDialog( session, this ) ), |
---|
88 | myDetailsDialog( 0 ), |
---|
89 | myFileDialog( 0 ), |
---|
90 | myFilterModel( prefs ), |
---|
91 | myTorrentDelegate( new TorrentDelegate( this ) ), |
---|
92 | myTorrentDelegateMin( new TorrentDelegateMin( this ) ), |
---|
93 | mySession( session ), |
---|
94 | myPrefs( prefs ), |
---|
95 | myModel( model ), |
---|
96 | mySpeedModeOffIcon( ":/icons/alt-limit-off.png" ), |
---|
97 | mySpeedModeOnIcon( ":/icons/alt-limit-on.png" ), |
---|
98 | myLastSendTime( 0 ), |
---|
99 | myLastReadTime( 0 ), |
---|
100 | myNetworkTimer( this ) |
---|
101 | { |
---|
102 | QAction * sep = new QAction( this ); |
---|
103 | sep->setSeparator( true ); |
---|
104 | |
---|
105 | ui.setupUi( this ); |
---|
106 | |
---|
107 | QStyle * style = this->style(); |
---|
108 | |
---|
109 | int i = style->pixelMetric( QStyle::PM_SmallIconSize, 0, this ); |
---|
110 | const QSize smallIconSize( i, i ); |
---|
111 | |
---|
112 | // icons |
---|
113 | ui.action_Add->setIcon( getStockIcon( "list-add", QStyle::SP_DialogOpenButton ) ); |
---|
114 | ui.action_New->setIcon( getStockIcon( "document-new", QStyle::SP_DesktopIcon ) ); |
---|
115 | ui.action_Properties->setIcon( getStockIcon( "document-properties", QStyle::SP_DesktopIcon ) ); |
---|
116 | ui.action_OpenFolder->setIcon( getStockIcon( "folder-open", QStyle::SP_DirOpenIcon ) ); |
---|
117 | ui.action_Start->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) ); |
---|
118 | ui.action_Announce->setIcon( getStockIcon( "network-transmit-receive" ) ); |
---|
119 | ui.action_Pause->setIcon( getStockIcon( "media-playback-pause", QStyle::SP_MediaPause ) ); |
---|
120 | ui.action_Remove->setIcon( getStockIcon( "list-remove", QStyle::SP_TrashIcon ) ); |
---|
121 | ui.action_Delete->setIcon( getStockIcon( "edit-delete", QStyle::SP_TrashIcon ) ); |
---|
122 | ui.action_StartAll->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) ); |
---|
123 | ui.action_PauseAll->setIcon( getStockIcon( "media-playback-pause", QStyle::SP_MediaPause ) ); |
---|
124 | ui.action_Quit->setIcon( getStockIcon( "application-exit" ) ); |
---|
125 | ui.action_SelectAll->setIcon( getStockIcon( "edit-select-all" ) ); |
---|
126 | ui.action_ReverseSortOrder->setIcon( getStockIcon( "view-sort-ascending", QStyle::SP_ArrowDown ) ); |
---|
127 | ui.action_Preferences->setIcon( getStockIcon( "preferences-system" ) ); |
---|
128 | ui.action_Contents->setIcon( getStockIcon( "help-contents", QStyle::SP_DialogHelpButton ) ); |
---|
129 | ui.action_About->setIcon( getStockIcon( "help-about" ) ); |
---|
130 | |
---|
131 | // ui signals |
---|
132 | connect( ui.action_Toolbar, SIGNAL(toggled(bool)), this, SLOT(setToolbarVisible(bool))); |
---|
133 | connect( ui.action_TrayIcon, SIGNAL(toggled(bool)), this, SLOT(setTrayIconVisible(bool))); |
---|
134 | connect( ui.action_Filterbar, SIGNAL(toggled(bool)), this, SLOT(setFilterbarVisible(bool))); |
---|
135 | connect( ui.action_Statusbar, SIGNAL(toggled(bool)), this, SLOT(setStatusbarVisible(bool))); |
---|
136 | connect( ui.action_MinimalView, SIGNAL(toggled(bool)), this, SLOT(setMinimalView(bool))); |
---|
137 | connect( ui.action_SortByActivity, SIGNAL(toggled(bool)), this, SLOT(onSortByActivityToggled(bool))); |
---|
138 | connect( ui.action_SortByAge, SIGNAL(toggled(bool)), this, SLOT(onSortByAgeToggled(bool))); |
---|
139 | connect( ui.action_SortByETA, SIGNAL(toggled(bool)), this, SLOT(onSortByETAToggled(bool))); |
---|
140 | connect( ui.action_SortByName, SIGNAL(toggled(bool)), this, SLOT(onSortByNameToggled(bool))); |
---|
141 | connect( ui.action_SortByProgress, SIGNAL(toggled(bool)), this, SLOT(onSortByProgressToggled(bool))); |
---|
142 | connect( ui.action_SortByRatio, SIGNAL(toggled(bool)), this, SLOT(onSortByRatioToggled(bool))); |
---|
143 | connect( ui.action_SortBySize, SIGNAL(toggled(bool)), this, SLOT(onSortBySizeToggled(bool))); |
---|
144 | connect( ui.action_SortByState, SIGNAL(toggled(bool)), this, SLOT(onSortByStateToggled(bool))); |
---|
145 | connect( ui.action_SortByTracker, SIGNAL(toggled(bool)), this, SLOT(onSortByTrackerToggled(bool))); |
---|
146 | connect( ui.action_ReverseSortOrder, SIGNAL(toggled(bool)), this, SLOT(setSortAscendingPref(bool))); |
---|
147 | connect( ui.action_Start, SIGNAL(triggered()), this, SLOT(startSelected())); |
---|
148 | connect( ui.action_Pause, SIGNAL(triggered()), this, SLOT(pauseSelected())); |
---|
149 | connect( ui.action_Remove, SIGNAL(triggered()), this, SLOT(removeSelected())); |
---|
150 | connect( ui.action_Delete, SIGNAL(triggered()), this, SLOT(deleteSelected())); |
---|
151 | connect( ui.action_Verify, SIGNAL(triggered()), this, SLOT(verifySelected()) ); |
---|
152 | connect( ui.action_Announce, SIGNAL(triggered()), this, SLOT(reannounceSelected()) ); |
---|
153 | connect( ui.action_StartAll, SIGNAL(triggered()), this, SLOT(startAll())); |
---|
154 | connect( ui.action_PauseAll, SIGNAL(triggered()), this, SLOT(pauseAll())); |
---|
155 | connect( ui.action_Add, SIGNAL(triggered()), this, SLOT(openTorrent())); |
---|
156 | connect( ui.action_New, SIGNAL(triggered()), this, SLOT(newTorrent())); |
---|
157 | connect( ui.action_Preferences, SIGNAL(triggered()), myPrefsDialog, SLOT(show())); |
---|
158 | connect( ui.action_Statistics, SIGNAL(triggered()), myStatsDialog, SLOT(show())); |
---|
159 | connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show())); |
---|
160 | connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp())); |
---|
161 | connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder())); |
---|
162 | connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation())); |
---|
163 | connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties())); |
---|
164 | connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show())); |
---|
165 | connect( ui.listView, SIGNAL(activated(const QModelIndex&)), ui.action_Properties, SLOT(trigger())); |
---|
166 | |
---|
167 | QAction * sep2 = new QAction( this ); |
---|
168 | sep2->setSeparator( true ); |
---|
169 | |
---|
170 | // context menu |
---|
171 | QList<QAction*> actions; |
---|
172 | actions << ui.action_Properties |
---|
173 | << ui.action_OpenFolder |
---|
174 | << ui.action_SetLocation |
---|
175 | << sep2 |
---|
176 | << ui.action_Start |
---|
177 | << ui.action_Pause |
---|
178 | << ui.action_Verify |
---|
179 | << ui.action_Announce |
---|
180 | << sep |
---|
181 | << ui.action_Remove |
---|
182 | << ui.action_Delete; |
---|
183 | addActions( actions ); |
---|
184 | setContextMenuPolicy( Qt::ActionsContextMenu ); |
---|
185 | |
---|
186 | // signals |
---|
187 | connect( ui.action_SelectAll, SIGNAL(triggered()), ui.listView, SLOT(selectAll())); |
---|
188 | connect( ui.action_DeselectAll, SIGNAL(triggered()), ui.listView, SLOT(clearSelection())); |
---|
189 | |
---|
190 | connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); |
---|
191 | connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); |
---|
192 | connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivity())); |
---|
193 | connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivity())); |
---|
194 | |
---|
195 | connect( ui.action_Quit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()) ); |
---|
196 | |
---|
197 | // torrent view |
---|
198 | myFilterModel.setSourceModel( &myModel ); |
---|
199 | connect( &myModel, SIGNAL(modelReset()), this, SLOT(onModelReset())); |
---|
200 | connect( &myModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(onModelReset())); |
---|
201 | connect( &myModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(onModelReset())); |
---|
202 | ui.listView->setModel( &myFilterModel ); |
---|
203 | connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivity())); |
---|
204 | |
---|
205 | QActionGroup * actionGroup = new QActionGroup( this ); |
---|
206 | actionGroup->addAction( ui.action_SortByActivity ); |
---|
207 | actionGroup->addAction( ui.action_SortByAge ); |
---|
208 | actionGroup->addAction( ui.action_SortByETA ); |
---|
209 | actionGroup->addAction( ui.action_SortByName ); |
---|
210 | actionGroup->addAction( ui.action_SortByProgress ); |
---|
211 | actionGroup->addAction( ui.action_SortByRatio ); |
---|
212 | actionGroup->addAction( ui.action_SortBySize ); |
---|
213 | actionGroup->addAction( ui.action_SortByState ); |
---|
214 | actionGroup->addAction( ui.action_SortByTracker ); |
---|
215 | |
---|
216 | QMenu * menu = new QMenu( ); |
---|
217 | menu->addAction( ui.action_Add ); |
---|
218 | menu->addSeparator( ); |
---|
219 | menu->addAction( ui.action_ShowMainWindow ); |
---|
220 | menu->addAction( ui.action_ShowMessageLog ); |
---|
221 | menu->addAction( ui.action_About ); |
---|
222 | menu->addSeparator( ); |
---|
223 | menu->addAction( ui.action_StartAll ); |
---|
224 | menu->addAction( ui.action_PauseAll ); |
---|
225 | menu->addSeparator( ); |
---|
226 | menu->addAction( ui.action_Quit ); |
---|
227 | myTrayIcon.setContextMenu( menu ); |
---|
228 | myTrayIcon.setIcon( QApplication::windowIcon( ) ); |
---|
229 | |
---|
230 | connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)) ); |
---|
231 | connect( ui.action_ShowMainWindow, SIGNAL(toggled(bool)), this, SLOT(toggleWindows(bool))); |
---|
232 | connect( &myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), |
---|
233 | this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); |
---|
234 | |
---|
235 | ui.action_ShowMainWindow->setChecked( !minimized ); |
---|
236 | ui.action_TrayIcon->setChecked( minimized || prefs.getBool( Prefs::SHOW_TRAY_ICON ) ); |
---|
237 | |
---|
238 | ui.verticalLayout->addWidget( createStatusBar( ) ); |
---|
239 | ui.verticalLayout->insertWidget( 0, createFilterBar( ) ); |
---|
240 | |
---|
241 | QList<int> initKeys; |
---|
242 | initKeys << Prefs :: MAIN_WINDOW_X |
---|
243 | << Prefs :: SHOW_TRAY_ICON |
---|
244 | << Prefs :: SORT_REVERSED |
---|
245 | << Prefs :: SORT_MODE |
---|
246 | << Prefs :: FILTER_MODE |
---|
247 | << Prefs :: FILTERBAR |
---|
248 | << Prefs :: STATUSBAR |
---|
249 | << Prefs :: STATUSBAR_STATS |
---|
250 | << Prefs :: TOOLBAR |
---|
251 | << Prefs :: ALT_SPEED_LIMIT_ENABLED |
---|
252 | << Prefs :: MINIMAL_VIEW |
---|
253 | << Prefs :: DSPEED |
---|
254 | << Prefs :: DSPEED_ENABLED |
---|
255 | << Prefs :: USPEED |
---|
256 | << Prefs :: USPEED_ENABLED |
---|
257 | << Prefs :: RATIO |
---|
258 | << Prefs :: RATIO_ENABLED; |
---|
259 | foreach( int key, initKeys ) |
---|
260 | refreshPref( key ); |
---|
261 | |
---|
262 | connect( &mySession, SIGNAL(sourceChanged()), this, SLOT(onSessionSourceChanged()) ); |
---|
263 | connect( &mySession, SIGNAL(statsUpdated()), this, SLOT(refreshStatusBar()) ); |
---|
264 | connect( &mySession, SIGNAL(dataReadProgress()), this, SLOT(dataReadProgress()) ); |
---|
265 | connect( &mySession, SIGNAL(dataSendProgress()), this, SLOT(dataSendProgress()) ); |
---|
266 | connect( &mySession, SIGNAL(httpAuthenticationRequired()), this, SLOT(wrongAuthentication()) ); |
---|
267 | |
---|
268 | if( mySession.isServer( ) ) |
---|
269 | myNetworkLabel->hide( ); |
---|
270 | else { |
---|
271 | connect( &myNetworkTimer, SIGNAL(timeout()), this, SLOT(onNetworkTimer())); |
---|
272 | myNetworkTimer.start( 1000 ); |
---|
273 | } |
---|
274 | |
---|
275 | refreshActionSensitivity( ); |
---|
276 | refreshStatusBar( ); |
---|
277 | refreshTitle( ); |
---|
278 | refreshVisibleCount( ); |
---|
279 | } |
---|
280 | |
---|
281 | TrMainWindow :: ~TrMainWindow( ) |
---|
282 | { |
---|
283 | } |
---|
284 | |
---|
285 | /**** |
---|
286 | ***** |
---|
287 | ****/ |
---|
288 | |
---|
289 | void |
---|
290 | TrMainWindow :: closeEvent( QCloseEvent * event ) |
---|
291 | { |
---|
292 | // if they're using a tray icon, close to the tray |
---|
293 | // instead of exiting |
---|
294 | if( !myPrefs.getBool( Prefs :: SHOW_TRAY_ICON ) ) |
---|
295 | event->accept( ); |
---|
296 | else { |
---|
297 | toggleWindows( false ); |
---|
298 | event->ignore( ); |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | /**** |
---|
303 | ***** |
---|
304 | ****/ |
---|
305 | |
---|
306 | void |
---|
307 | TrMainWindow :: onSessionSourceChanged( ) |
---|
308 | { |
---|
309 | myModel.clear( ); |
---|
310 | } |
---|
311 | |
---|
312 | void |
---|
313 | TrMainWindow :: onModelReset( ) |
---|
314 | { |
---|
315 | refreshTitle( ); |
---|
316 | refreshVisibleCount( ); |
---|
317 | refreshActionSensitivity( ); |
---|
318 | refreshStatusBar( ); |
---|
319 | } |
---|
320 | |
---|
321 | /**** |
---|
322 | ***** |
---|
323 | ****/ |
---|
324 | |
---|
325 | #define PREF_VARIANTS_KEY "pref-variants-list" |
---|
326 | |
---|
327 | void |
---|
328 | TrMainWindow :: onSetPrefs( ) |
---|
329 | { |
---|
330 | const QVariantList p = sender()->property( PREF_VARIANTS_KEY ).toList( ); |
---|
331 | assert( ( p.size( ) % 2 ) == 0 ); |
---|
332 | for( int i=0, n=p.size(); i<n; i+=2 ) |
---|
333 | myPrefs.set( p[i].toInt(), p[i+1] ); |
---|
334 | } |
---|
335 | |
---|
336 | void |
---|
337 | TrMainWindow :: onSetPrefs( bool isChecked ) |
---|
338 | { |
---|
339 | if( isChecked ) |
---|
340 | onSetPrefs( ); |
---|
341 | } |
---|
342 | |
---|
343 | #define SHOW_KEY "show-mode" |
---|
344 | |
---|
345 | void |
---|
346 | TrMainWindow :: onShowModeClicked( ) |
---|
347 | { |
---|
348 | setShowMode( sender()->property(SHOW_KEY).toInt() ); |
---|
349 | } |
---|
350 | |
---|
351 | QWidget * |
---|
352 | TrMainWindow :: createFilterBar( ) |
---|
353 | { |
---|
354 | int i; |
---|
355 | QMenu * m; |
---|
356 | QLineEdit * e; |
---|
357 | QPushButton * p; |
---|
358 | QHBoxLayout * h; |
---|
359 | QActionGroup * a; |
---|
360 | const int smallSize = style( )->pixelMetric( QStyle::PM_SmallIconSize, 0, this ); |
---|
361 | const QSize smallIconSize( smallSize, smallSize ); |
---|
362 | |
---|
363 | QWidget * top = myFilterBar = new QWidget; |
---|
364 | h = new QHBoxLayout( top ); |
---|
365 | h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL ); |
---|
366 | h->setSpacing( HIG::PAD_SMALL ); |
---|
367 | #ifdef Q_OS_MAC |
---|
368 | top->setStyleSheet( "QPushButton{ " |
---|
369 | " border-radius: 10px; " |
---|
370 | " padding: 0 5px; " |
---|
371 | " border: 1px none; " |
---|
372 | "} " |
---|
373 | "QPushButton:pressed, QPushButton:checked{ " |
---|
374 | " border-width: 1px; " |
---|
375 | " border-style: solid; " |
---|
376 | " border-color: #5f5f5f #979797 #979797; " |
---|
377 | " background-color: #979797; " |
---|
378 | " color: white; " |
---|
379 | "} "); |
---|
380 | #endif |
---|
381 | |
---|
382 | QList<QString> titles; |
---|
383 | titles << tr( "A&ll" ) << tr( "&Active" ) << tr( "&Downloading" ) << tr( "&Seeding" ) << tr( "&Paused" ); |
---|
384 | for( i=0; i<titles.size(); ++i ) { |
---|
385 | p = myFilterButtons[i] = new QPushButton( titles[i] ); |
---|
386 | p->setProperty( SHOW_KEY, i ); |
---|
387 | p->setFlat( true ); |
---|
388 | p->setCheckable( true ); |
---|
389 | p->setMaximumSize( calculateTextButtonSizeHint( p ) ); |
---|
390 | connect( p, SIGNAL(clicked()), this, SLOT(onShowModeClicked())); |
---|
391 | h->addWidget( p ); |
---|
392 | } |
---|
393 | |
---|
394 | h->addStretch( 1 ); |
---|
395 | |
---|
396 | a = new QActionGroup( this ); |
---|
397 | a->addAction( ui.action_FilterByName ); |
---|
398 | a->addAction( ui.action_FilterByFiles ); |
---|
399 | a->addAction( ui.action_FilterByTracker ); |
---|
400 | m = new QMenu( ); |
---|
401 | m->addAction( ui.action_FilterByName ); |
---|
402 | m->addAction( ui.action_FilterByFiles ); |
---|
403 | m->addAction( ui.action_FilterByTracker ); |
---|
404 | connect( ui.action_FilterByName, SIGNAL(triggered()), this, SLOT(filterByName())); |
---|
405 | connect( ui.action_FilterByFiles, SIGNAL(triggered()), this, SLOT(filterByFiles())); |
---|
406 | connect( ui.action_FilterByTracker, SIGNAL(triggered()), this, SLOT(filterByTracker())); |
---|
407 | ui.action_FilterByName->setChecked( true ); |
---|
408 | p = myFilterTextButton = new TrIconPushButton; |
---|
409 | p->setIcon( getStockIcon( "edit-find", QStyle::SP_ArrowForward ) ); |
---|
410 | p->setFlat( true ); |
---|
411 | p->setMenu( m ); |
---|
412 | h->addWidget( p ); |
---|
413 | |
---|
414 | e = myFilterTextLineEdit = new QLineEdit; |
---|
415 | connect( e, SIGNAL(textChanged(QString)), &myFilterModel, SLOT(setText(QString))); |
---|
416 | h->addWidget( e ); |
---|
417 | |
---|
418 | p = myFilterTextButton = new TrIconPushButton; |
---|
419 | p->setIcon( getStockIcon( "edit-clear", QStyle::SP_DialogCloseButton ) ); |
---|
420 | p->setFlat( true ); |
---|
421 | connect( p, SIGNAL(clicked()), myFilterTextLineEdit, SLOT(clear())); |
---|
422 | h->addWidget( p ); |
---|
423 | |
---|
424 | return top; |
---|
425 | } |
---|
426 | |
---|
427 | QWidget * |
---|
428 | TrMainWindow :: createStatusBar( ) |
---|
429 | { |
---|
430 | QMenu * m; |
---|
431 | QLabel *l, *l2; |
---|
432 | QWidget *w; |
---|
433 | QHBoxLayout * h; |
---|
434 | QPushButton * p; |
---|
435 | QActionGroup * a; |
---|
436 | const int i = style( )->pixelMetric( QStyle::PM_SmallIconSize, 0, this ); |
---|
437 | const QSize smallIconSize( i, i ); |
---|
438 | |
---|
439 | QWidget * top = myStatusBar = new QWidget; |
---|
440 | h = new QHBoxLayout( top ); |
---|
441 | h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL ); |
---|
442 | h->setSpacing( HIG::PAD_SMALL ); |
---|
443 | |
---|
444 | p = myOptionsButton = new TrIconPushButton( this ); |
---|
445 | p->setIcon( QIcon( ":/icons/options.png" ) ); |
---|
446 | p->setFlat( true ); |
---|
447 | p->setMenu( createOptionsMenu( ) ); |
---|
448 | h->addWidget( p ); |
---|
449 | |
---|
450 | p = myAltSpeedButton = new TrIconPushButton( this ); |
---|
451 | p->setIcon( myPrefs.get<bool>(Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon ); |
---|
452 | p->setFlat( true ); |
---|
453 | h->addWidget( p ); |
---|
454 | connect( p, SIGNAL(clicked()), this, SLOT(toggleSpeedMode())); |
---|
455 | |
---|
456 | l = myNetworkLabel = new QLabel; |
---|
457 | h->addWidget( l ); |
---|
458 | |
---|
459 | h->addStretch( 1 ); |
---|
460 | |
---|
461 | l = myVisibleCountLabel = new QLabel( this ); |
---|
462 | h->addWidget( l ); |
---|
463 | |
---|
464 | h->addStretch( 1 ); |
---|
465 | |
---|
466 | a = new QActionGroup( this ); |
---|
467 | a->addAction( ui.action_TotalRatio ); |
---|
468 | a->addAction( ui.action_TotalTransfer ); |
---|
469 | a->addAction( ui.action_SessionRatio ); |
---|
470 | a->addAction( ui.action_SessionTransfer ); |
---|
471 | m = new QMenu( ); |
---|
472 | m->addAction( ui.action_TotalRatio ); |
---|
473 | m->addAction( ui.action_TotalTransfer ); |
---|
474 | m->addAction( ui.action_SessionRatio ); |
---|
475 | m->addAction( ui.action_SessionTransfer ); |
---|
476 | connect( ui.action_TotalRatio, SIGNAL(triggered()), this, SLOT(showTotalRatio())); |
---|
477 | connect( ui.action_TotalTransfer, SIGNAL(triggered()), this, SLOT(showTotalTransfer())); |
---|
478 | connect( ui.action_SessionRatio, SIGNAL(triggered()), this, SLOT(showSessionRatio())); |
---|
479 | connect( ui.action_SessionTransfer, SIGNAL(triggered()), this, SLOT(showSessionTransfer())); |
---|
480 | p = myStatsModeButton = new TrIconPushButton( this ); |
---|
481 | p->setIcon( getStockIcon( "view-refresh", QStyle::SP_BrowserReload ) ); |
---|
482 | p->setFlat( true ); |
---|
483 | p->setMenu( m ); |
---|
484 | h->addWidget( p ); |
---|
485 | l = myStatsLabel = new QLabel( this ); |
---|
486 | h->addWidget( l ); |
---|
487 | |
---|
488 | w = new QWidget( this ); |
---|
489 | w->setMinimumSize( HIG::PAD_BIG, 1 ); |
---|
490 | w->setMaximumSize( HIG::PAD_BIG, 1 ); |
---|
491 | h->addWidget( w ); |
---|
492 | l = new QLabel( this ); |
---|
493 | l->setPixmap( getStockIcon( "go-down", QStyle::SP_ArrowDown ).pixmap( smallIconSize ) ); |
---|
494 | h->addWidget( l ); |
---|
495 | l2 = myDownloadSpeedLabel = new QLabel( this ); |
---|
496 | h->addWidget( l2 ); |
---|
497 | myDownStatusWidgets << w << l << l2; |
---|
498 | |
---|
499 | w = new QWidget( this ); |
---|
500 | w->setMinimumSize( HIG::PAD_BIG, 1 ); |
---|
501 | w->setMaximumSize( HIG::PAD_BIG, 1 ); |
---|
502 | h->addWidget( w ); |
---|
503 | l = new QLabel; |
---|
504 | l->setPixmap( getStockIcon( "go-up", QStyle::SP_ArrowUp ).pixmap( smallIconSize ) ); |
---|
505 | h->addWidget( l ); |
---|
506 | l2 = myUploadSpeedLabel = new QLabel; |
---|
507 | h->addWidget( l2 ); |
---|
508 | myUpStatusWidgets << w << l << l2; |
---|
509 | |
---|
510 | return top; |
---|
511 | } |
---|
512 | |
---|
513 | QMenu * |
---|
514 | TrMainWindow :: createOptionsMenu( ) |
---|
515 | { |
---|
516 | QMenu * menu; |
---|
517 | QMenu * sub; |
---|
518 | QAction * a; |
---|
519 | QActionGroup * g; |
---|
520 | |
---|
521 | QList<int> stockSpeeds; |
---|
522 | stockSpeeds << 5 << 10 << 20 << 30 << 40 << 50 << 75 << 100 << 150 << 200 << 250 << 500 << 750; |
---|
523 | QList<double> stockRatios; |
---|
524 | stockRatios << 0.25 << 0.50 << 0.75 << 1 << 1.5 << 2 << 3; |
---|
525 | |
---|
526 | menu = new QMenu; |
---|
527 | sub = menu->addMenu( tr( "Limit Download Speed" ) ); |
---|
528 | int currentVal = myPrefs.get<int>( Prefs::DSPEED ); |
---|
529 | g = new QActionGroup( this ); |
---|
530 | a = myDlimitOffAction = sub->addAction( tr( "Unlimited" ) ); |
---|
531 | a->setCheckable( true ); |
---|
532 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED_ENABLED << false ); |
---|
533 | g->addAction( a ); |
---|
534 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); |
---|
535 | a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( currentVal ) ) ) ); |
---|
536 | a->setCheckable( true ); |
---|
537 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << currentVal << Prefs::DSPEED_ENABLED << true ); |
---|
538 | g->addAction( a ); |
---|
539 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); |
---|
540 | sub->addSeparator( ); |
---|
541 | foreach( int i, stockSpeeds ) { |
---|
542 | a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) ); |
---|
543 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true ); |
---|
544 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); |
---|
545 | } |
---|
546 | |
---|
547 | sub = menu->addMenu( tr( "Limit Upload Speed" ) ); |
---|
548 | currentVal = myPrefs.get<int>( Prefs::USPEED ); |
---|
549 | g = new QActionGroup( this ); |
---|
550 | a = myUlimitOffAction = sub->addAction( tr( "Unlimited" ) ); |
---|
551 | a->setCheckable( true ); |
---|
552 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED_ENABLED << false ); |
---|
553 | g->addAction( a ); |
---|
554 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); |
---|
555 | a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( currentVal ) ) ) ); |
---|
556 | a->setCheckable( true ); |
---|
557 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << currentVal << Prefs::USPEED_ENABLED << true ); |
---|
558 | g->addAction( a ); |
---|
559 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); |
---|
560 | sub->addSeparator( ); |
---|
561 | foreach( int i, stockSpeeds ) { |
---|
562 | a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) ); |
---|
563 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true ); |
---|
564 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); |
---|
565 | } |
---|
566 | |
---|
567 | menu->addSeparator( ); |
---|
568 | sub = menu->addMenu( tr( "Stop Seeding at Ratio" ) ); |
---|
569 | |
---|
570 | double d = myPrefs.get<double>( Prefs::RATIO ); |
---|
571 | g = new QActionGroup( this ); |
---|
572 | a = myRatioOffAction = sub->addAction( tr( "Seed Forever" ) ); |
---|
573 | a->setCheckable( true ); |
---|
574 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO_ENABLED << false ); |
---|
575 | g->addAction( a ); |
---|
576 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); |
---|
577 | a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Utils::ratioToString( d ) ) ); |
---|
578 | a->setCheckable( true ); |
---|
579 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << d << Prefs::RATIO_ENABLED << true ); |
---|
580 | g->addAction( a ); |
---|
581 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); |
---|
582 | sub->addSeparator( ); |
---|
583 | foreach( double i, stockRatios ) { |
---|
584 | a = sub->addAction( Utils::ratioToString( i ) ); |
---|
585 | a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true ); |
---|
586 | connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); |
---|
587 | } |
---|
588 | |
---|
589 | return menu; |
---|
590 | } |
---|
591 | |
---|
592 | /**** |
---|
593 | ***** |
---|
594 | ****/ |
---|
595 | |
---|
596 | void |
---|
597 | TrMainWindow :: setSortPref( int i ) |
---|
598 | { |
---|
599 | myPrefs.set( Prefs::SORT_MODE, SortMode( i ) ); |
---|
600 | } |
---|
601 | void TrMainWindow :: onSortByActivityToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ACTIVITY ); } |
---|
602 | void TrMainWindow :: onSortByAgeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_AGE ); } |
---|
603 | void TrMainWindow :: onSortByETAToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ETA ); } |
---|
604 | void TrMainWindow :: onSortByNameToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_NAME ); } |
---|
605 | void TrMainWindow :: onSortByProgressToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_PROGRESS ); } |
---|
606 | void TrMainWindow :: onSortByRatioToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_RATIO ); } |
---|
607 | void TrMainWindow :: onSortBySizeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_SIZE ); } |
---|
608 | void TrMainWindow :: onSortByStateToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_STATE ); } |
---|
609 | void TrMainWindow :: onSortByTrackerToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_TRACKER ); } |
---|
610 | |
---|
611 | void |
---|
612 | TrMainWindow :: setSortAscendingPref( bool b ) |
---|
613 | { |
---|
614 | myPrefs.set( Prefs::SORT_REVERSED, b ); |
---|
615 | } |
---|
616 | |
---|
617 | /**** |
---|
618 | ***** |
---|
619 | ****/ |
---|
620 | |
---|
621 | void |
---|
622 | TrMainWindow :: onDetailsDestroyed( ) |
---|
623 | { |
---|
624 | myDetailsDialog = 0; |
---|
625 | } |
---|
626 | |
---|
627 | void |
---|
628 | TrMainWindow :: openProperties( ) |
---|
629 | { |
---|
630 | if( myDetailsDialog == 0 ) { |
---|
631 | myDetailsDialog = new Details( mySession, myModel, this ); |
---|
632 | connect( myDetailsDialog, SIGNAL(destroyed(QObject*)), this, SLOT(onDetailsDestroyed())); |
---|
633 | } |
---|
634 | |
---|
635 | myDetailsDialog->setIds( getSelectedTorrents( ) ); |
---|
636 | myDetailsDialog->show( ); |
---|
637 | } |
---|
638 | |
---|
639 | void |
---|
640 | TrMainWindow :: setLocation( ) |
---|
641 | { |
---|
642 | QDialog * d = new RelocateDialog( mySession, getSelectedTorrents(), this ); |
---|
643 | d->show( ); |
---|
644 | } |
---|
645 | |
---|
646 | void |
---|
647 | TrMainWindow :: openFolder( ) |
---|
648 | { |
---|
649 | const int torrentId( *getSelectedTorrents().begin() ); |
---|
650 | const Torrent * tor( myModel.getTorrentFromId( torrentId ) ); |
---|
651 | const QString path( tor->getPath( ) ); |
---|
652 | QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) ); |
---|
653 | } |
---|
654 | |
---|
655 | void |
---|
656 | TrMainWindow :: openHelp( ) |
---|
657 | { |
---|
658 | const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx"; |
---|
659 | int major, minor; |
---|
660 | sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor ); |
---|
661 | char url[128]; |
---|
662 | snprintf( url, sizeof( url ), fmt, major, minor/10 ); |
---|
663 | QDesktopServices :: openUrl( QUrl( QString( url ) ) ); |
---|
664 | } |
---|
665 | |
---|
666 | void |
---|
667 | TrMainWindow :: refreshTitle( ) |
---|
668 | { |
---|
669 | QString title( "Transmission" ); |
---|
670 | const QUrl url( mySession.getRemoteUrl( ) ); |
---|
671 | if( !url.isEmpty() ) |
---|
672 | title += tr( " - %1" ).arg( url.toString(QUrl::RemoveUserInfo) ); |
---|
673 | setWindowTitle( title ); |
---|
674 | } |
---|
675 | |
---|
676 | void |
---|
677 | TrMainWindow :: refreshVisibleCount( ) |
---|
678 | { |
---|
679 | const int visibleCount( myFilterModel.rowCount( ) ); |
---|
680 | const int totalCount( visibleCount + myFilterModel.hiddenRowCount( ) ); |
---|
681 | QString str; |
---|
682 | if( visibleCount == totalCount ) |
---|
683 | str = tr( "%Ln Torrent(s)", 0, totalCount ); |
---|
684 | else |
---|
685 | str = tr( "%L1 of %Ln Torrent(s)", 0, totalCount ).arg( visibleCount ); |
---|
686 | myVisibleCountLabel->setText( str ); |
---|
687 | myVisibleCountLabel->setVisible( totalCount > 0 ); |
---|
688 | } |
---|
689 | |
---|
690 | void |
---|
691 | TrMainWindow :: refreshStatusBar( ) |
---|
692 | { |
---|
693 | const Speed up( myModel.getUploadSpeed( ) ); |
---|
694 | const Speed down( myModel.getDownloadSpeed( ) ); |
---|
695 | myUploadSpeedLabel->setText( Utils :: speedToString( up ) ); |
---|
696 | myDownloadSpeedLabel->setText( Utils :: speedToString( down ) ); |
---|
697 | foreach( QWidget * w, myUpStatusWidgets ) w->setVisible( !up.isZero( ) ); |
---|
698 | foreach( QWidget * w, myDownStatusWidgets ) w->setVisible( !down.isZero( ) ); |
---|
699 | |
---|
700 | myNetworkLabel->setVisible( !mySession.isServer( ) ); |
---|
701 | |
---|
702 | const QString mode( myPrefs.getString( Prefs::STATUSBAR_STATS ) ); |
---|
703 | QString str; |
---|
704 | |
---|
705 | if( mode == "session-ratio" ) |
---|
706 | { |
---|
707 | str = tr( "Ratio: %1" ).arg( Utils :: ratioToString( mySession.getStats().ratio ) ); |
---|
708 | } |
---|
709 | else if( mode == "session-transfer" ) |
---|
710 | { |
---|
711 | const tr_session_stats& stats( mySession.getStats( ) ); |
---|
712 | str = tr( "Down: %1, Up: %2" ).arg( Utils :: sizeToString( stats.downloadedBytes ) ) |
---|
713 | .arg( Utils :: sizeToString( stats.uploadedBytes ) ); |
---|
714 | } |
---|
715 | else if( mode == "total-transfer" ) |
---|
716 | { |
---|
717 | const tr_session_stats& stats( mySession.getCumulativeStats( ) ); |
---|
718 | str = tr( "Down: %1, Up: %2" ).arg( Utils :: sizeToString( stats.downloadedBytes ) ) |
---|
719 | .arg( Utils :: sizeToString( stats.uploadedBytes ) ); |
---|
720 | } |
---|
721 | else /* default is "total-ratio" */ |
---|
722 | { |
---|
723 | str = tr( "Ratio: %1" ).arg( Utils :: ratioToString( mySession.getCumulativeStats().ratio ) ); |
---|
724 | } |
---|
725 | |
---|
726 | myStatsLabel->setText( str ); |
---|
727 | } |
---|
728 | |
---|
729 | void |
---|
730 | TrMainWindow :: refreshActionSensitivity( ) |
---|
731 | { |
---|
732 | int selected( 0 ); |
---|
733 | int paused( 0 ); |
---|
734 | int selectedAndPaused( 0 ); |
---|
735 | int canAnnounce( 0 ); |
---|
736 | const QAbstractItemModel * model( ui.listView->model( ) ); |
---|
737 | const QItemSelectionModel * selectionModel( ui.listView->selectionModel( ) ); |
---|
738 | const int rowCount( model->rowCount( ) ); |
---|
739 | |
---|
740 | /* count how many torrents are selected, paused, etc */ |
---|
741 | for( int row=0; row<rowCount; ++row ) { |
---|
742 | const QModelIndex modelIndex( model->index( row, 0 ) ); |
---|
743 | assert( model == modelIndex.model( ) ); |
---|
744 | const Torrent * tor( model->data( modelIndex, TorrentModel::TorrentRole ).value<const Torrent*>( ) ); |
---|
745 | const bool isSelected( selectionModel->isSelected( modelIndex ) ); |
---|
746 | const bool isPaused( tor->isPaused( ) ); |
---|
747 | if( isSelected ) |
---|
748 | ++selected; |
---|
749 | if( isPaused ) |
---|
750 | ++ paused; |
---|
751 | if( isSelected && isPaused ) |
---|
752 | ++selectedAndPaused; |
---|
753 | if( tor->canManualAnnounce( ) ) |
---|
754 | ++canAnnounce; |
---|
755 | } |
---|
756 | |
---|
757 | const bool haveSelection( selected > 0 ); |
---|
758 | ui.action_Verify->setEnabled( haveSelection ); |
---|
759 | ui.action_Remove->setEnabled( haveSelection ); |
---|
760 | ui.action_Delete->setEnabled( haveSelection ); |
---|
761 | ui.action_Properties->setEnabled( haveSelection ); |
---|
762 | ui.action_DeselectAll->setEnabled( haveSelection ); |
---|
763 | ui.action_SetLocation->setEnabled( haveSelection ); |
---|
764 | |
---|
765 | const bool oneSelection( selected == 1 ); |
---|
766 | ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) ); |
---|
767 | |
---|
768 | ui.action_SelectAll->setEnabled( selected < rowCount ); |
---|
769 | ui.action_StartAll->setEnabled( paused > 0 ); |
---|
770 | ui.action_PauseAll->setEnabled( paused < rowCount ); |
---|
771 | ui.action_Start->setEnabled( selectedAndPaused > 0 ); |
---|
772 | ui.action_Pause->setEnabled( selectedAndPaused < selected ); |
---|
773 | ui.action_Announce->setEnabled( selected > 0 && ( canAnnounce == selected ) ); |
---|
774 | |
---|
775 | if( myDetailsDialog ) |
---|
776 | myDetailsDialog->setIds( getSelectedTorrents( ) ); |
---|
777 | } |
---|
778 | |
---|
779 | /** |
---|
780 | *** |
---|
781 | **/ |
---|
782 | |
---|
783 | void |
---|
784 | TrMainWindow :: clearSelection( ) |
---|
785 | { |
---|
786 | ui.action_DeselectAll->trigger( ); |
---|
787 | } |
---|
788 | |
---|
789 | QSet<int> |
---|
790 | TrMainWindow :: getSelectedTorrents( ) const |
---|
791 | { |
---|
792 | QSet<int> ids; |
---|
793 | |
---|
794 | foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ) ) |
---|
795 | { |
---|
796 | const Torrent * tor( index.model()->data( index, TorrentModel::TorrentRole ).value<const Torrent*>( ) ); |
---|
797 | ids.insert( tor->id( ) ); |
---|
798 | } |
---|
799 | |
---|
800 | return ids; |
---|
801 | } |
---|
802 | |
---|
803 | void |
---|
804 | TrMainWindow :: startSelected( ) |
---|
805 | { |
---|
806 | mySession.startTorrents( getSelectedTorrents( ) ); |
---|
807 | } |
---|
808 | void |
---|
809 | TrMainWindow :: pauseSelected( ) |
---|
810 | { |
---|
811 | mySession.pauseTorrents( getSelectedTorrents( ) ); |
---|
812 | } |
---|
813 | void |
---|
814 | TrMainWindow :: startAll( ) |
---|
815 | { |
---|
816 | mySession.startTorrents( ); |
---|
817 | } |
---|
818 | void |
---|
819 | TrMainWindow :: pauseAll( ) |
---|
820 | { |
---|
821 | mySession.pauseTorrents( ); |
---|
822 | } |
---|
823 | void |
---|
824 | TrMainWindow :: removeSelected( ) |
---|
825 | { |
---|
826 | mySession.removeTorrents( getSelectedTorrents( ), false ); |
---|
827 | } |
---|
828 | void |
---|
829 | TrMainWindow :: deleteSelected( ) |
---|
830 | { |
---|
831 | mySession.removeTorrents( getSelectedTorrents( ), true ); |
---|
832 | } |
---|
833 | void |
---|
834 | TrMainWindow :: verifySelected( ) |
---|
835 | { |
---|
836 | mySession.verifyTorrents( getSelectedTorrents( ) ); |
---|
837 | } |
---|
838 | void |
---|
839 | TrMainWindow :: reannounceSelected( ) |
---|
840 | { |
---|
841 | mySession.reannounceTorrents( getSelectedTorrents( ) ); |
---|
842 | } |
---|
843 | |
---|
844 | /** |
---|
845 | *** |
---|
846 | **/ |
---|
847 | |
---|
848 | void TrMainWindow :: setShowMode ( int i ) { myPrefs.set( Prefs::FILTER_MODE, FilterMode( i ) ); } |
---|
849 | void TrMainWindow :: showAll ( ) { setShowMode( FilterMode :: SHOW_ALL ); } |
---|
850 | void TrMainWindow :: showActive ( ) { setShowMode( FilterMode :: SHOW_ACTIVE ); } |
---|
851 | void TrMainWindow :: showDownloading ( ) { setShowMode( FilterMode :: SHOW_DOWNLOADING ); } |
---|
852 | void TrMainWindow :: showSeeding ( ) { setShowMode( FilterMode :: SHOW_SEEDING ); } |
---|
853 | void TrMainWindow :: showPaused ( ) { setShowMode( FilterMode :: SHOW_PAUSED ); } |
---|
854 | |
---|
855 | void TrMainWindow :: filterByName ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_NAME ); } |
---|
856 | void TrMainWindow :: filterByTracker ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_TRACKER ); } |
---|
857 | void TrMainWindow :: filterByFiles ( ) { myFilterModel.setTextMode( TorrentFilter :: FILTER_BY_FILES ); } |
---|
858 | |
---|
859 | void TrMainWindow :: showTotalRatio ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "total-ratio"); } |
---|
860 | void TrMainWindow :: showTotalTransfer ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "total-transfer"); } |
---|
861 | void TrMainWindow :: showSessionRatio ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "session-ratio"); } |
---|
862 | void TrMainWindow :: showSessionTransfer ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "session-transfer"); } |
---|
863 | |
---|
864 | /** |
---|
865 | *** |
---|
866 | **/ |
---|
867 | |
---|
868 | void |
---|
869 | TrMainWindow :: setMinimalView( bool visible ) |
---|
870 | { |
---|
871 | myPrefs.set( Prefs :: MINIMAL_VIEW, visible ); |
---|
872 | } |
---|
873 | void |
---|
874 | TrMainWindow :: setTrayIconVisible( bool visible ) |
---|
875 | { |
---|
876 | myPrefs.set( Prefs :: SHOW_TRAY_ICON, visible ); |
---|
877 | } |
---|
878 | void |
---|
879 | TrMainWindow :: toggleSpeedMode( ) |
---|
880 | { |
---|
881 | myPrefs.toggleBool( Prefs :: ALT_SPEED_LIMIT_ENABLED ); |
---|
882 | } |
---|
883 | void |
---|
884 | TrMainWindow :: setToolbarVisible( bool visible ) |
---|
885 | { |
---|
886 | myPrefs.set( Prefs::TOOLBAR, visible ); |
---|
887 | } |
---|
888 | void |
---|
889 | TrMainWindow :: setFilterbarVisible( bool visible ) |
---|
890 | { |
---|
891 | myPrefs.set( Prefs::FILTERBAR, visible ); |
---|
892 | } |
---|
893 | void |
---|
894 | TrMainWindow :: setStatusbarVisible( bool visible ) |
---|
895 | { |
---|
896 | myPrefs.set( Prefs::STATUSBAR, visible ); |
---|
897 | } |
---|
898 | |
---|
899 | /** |
---|
900 | *** |
---|
901 | **/ |
---|
902 | |
---|
903 | void |
---|
904 | TrMainWindow :: toggleWindows( bool doShow ) |
---|
905 | { |
---|
906 | if( !doShow ) |
---|
907 | { |
---|
908 | hide( ); |
---|
909 | } |
---|
910 | else |
---|
911 | { |
---|
912 | if ( !isVisible( ) ) show( ); |
---|
913 | if ( isMinimized( ) ) showNormal( ); |
---|
914 | activateWindow( ); |
---|
915 | raise( ); |
---|
916 | } |
---|
917 | } |
---|
918 | |
---|
919 | void |
---|
920 | TrMainWindow :: trayActivated( QSystemTrayIcon::ActivationReason reason ) |
---|
921 | { |
---|
922 | if( reason == QSystemTrayIcon::Trigger ) |
---|
923 | { |
---|
924 | if( isMinimized ( ) ) |
---|
925 | toggleWindows( true ); |
---|
926 | else |
---|
927 | ui.action_ShowMainWindow->toggle( ); |
---|
928 | } |
---|
929 | } |
---|
930 | |
---|
931 | |
---|
932 | void |
---|
933 | TrMainWindow :: refreshPref( int key ) |
---|
934 | { |
---|
935 | bool b; |
---|
936 | int i; |
---|
937 | QString str; |
---|
938 | |
---|
939 | switch( key ) |
---|
940 | { |
---|
941 | case Prefs::STATUSBAR_STATS: |
---|
942 | str = myPrefs.getString( key ); |
---|
943 | ui.action_TotalRatio->setChecked ( str == "total-ratio" ); |
---|
944 | ui.action_TotalTransfer->setChecked ( str == "total-transfer" ); |
---|
945 | ui.action_SessionRatio->setChecked ( str == "session-ratio" ); |
---|
946 | ui.action_SessionTransfer->setChecked( str == "session-transfer" ); |
---|
947 | refreshStatusBar( ); |
---|
948 | break; |
---|
949 | |
---|
950 | case Prefs::SORT_REVERSED: |
---|
951 | ui.action_ReverseSortOrder->setChecked( myPrefs.getBool( key ) ); |
---|
952 | break; |
---|
953 | |
---|
954 | case Prefs::SORT_MODE: |
---|
955 | i = myPrefs.get<SortMode>(key).mode( ); |
---|
956 | ui.action_SortByActivity->setChecked ( i == SortMode::SORT_BY_ACTIVITY ); |
---|
957 | ui.action_SortByAge->setChecked ( i == SortMode::SORT_BY_AGE ); |
---|
958 | ui.action_SortByETA->setChecked ( i == SortMode::SORT_BY_ETA ); |
---|
959 | ui.action_SortByName->setChecked ( i == SortMode::SORT_BY_NAME ); |
---|
960 | ui.action_SortByProgress->setChecked ( i == SortMode::SORT_BY_PROGRESS ); |
---|
961 | ui.action_SortByRatio->setChecked ( i == SortMode::SORT_BY_RATIO ); |
---|
962 | ui.action_SortBySize->setChecked ( i == SortMode::SORT_BY_SIZE ); |
---|
963 | ui.action_SortByState->setChecked ( i == SortMode::SORT_BY_STATE ); |
---|
964 | ui.action_SortByTracker->setChecked ( i == SortMode::SORT_BY_TRACKER ); |
---|
965 | break; |
---|
966 | |
---|
967 | case Prefs::DSPEED_ENABLED: |
---|
968 | (myPrefs.get<bool>(key) ? myDlimitOnAction : myDlimitOffAction)->setChecked( true ); |
---|
969 | break; |
---|
970 | |
---|
971 | case Prefs::DSPEED: |
---|
972 | myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( myPrefs.get<int>(key) ) ) ) ); |
---|
973 | break; |
---|
974 | |
---|
975 | case Prefs::USPEED_ENABLED: |
---|
976 | (myPrefs.get<bool>(key) ? myUlimitOnAction : myUlimitOffAction)->setChecked( true ); |
---|
977 | break; |
---|
978 | |
---|
979 | case Prefs::USPEED: |
---|
980 | myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( myPrefs.get<int>(key) ) ) ) ); |
---|
981 | break; |
---|
982 | |
---|
983 | case Prefs::RATIO_ENABLED: |
---|
984 | (myPrefs.get<bool>(key) ? myRatioOnAction : myRatioOffAction)->setChecked( true ); |
---|
985 | break; |
---|
986 | |
---|
987 | case Prefs::RATIO: |
---|
988 | myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Utils::ratioToString( myPrefs.get<double>(key) ) ) ); |
---|
989 | break; |
---|
990 | |
---|
991 | case Prefs::FILTER_MODE: |
---|
992 | i = myPrefs.get<FilterMode>(key).mode( ); |
---|
993 | for( int j=0; j<FilterMode::NUM_MODES; ++j ) |
---|
994 | myFilterButtons[j]->setChecked( i==j ); |
---|
995 | break; |
---|
996 | |
---|
997 | case Prefs::FILTERBAR: |
---|
998 | b = myPrefs.getBool( key ); |
---|
999 | myFilterBar->setVisible( b ); |
---|
1000 | ui.action_Filterbar->setChecked( b ); |
---|
1001 | break; |
---|
1002 | |
---|
1003 | case Prefs::STATUSBAR: |
---|
1004 | b = myPrefs.getBool( key ); |
---|
1005 | myStatusBar->setVisible( b ); |
---|
1006 | ui.action_Statusbar->setChecked( b ); |
---|
1007 | break; |
---|
1008 | |
---|
1009 | case Prefs::TOOLBAR: |
---|
1010 | b = myPrefs.getBool( key ); |
---|
1011 | ui.toolBar->setVisible( b ); |
---|
1012 | ui.action_Toolbar->setChecked( b ); |
---|
1013 | break; |
---|
1014 | |
---|
1015 | case Prefs::SHOW_TRAY_ICON: |
---|
1016 | b = myPrefs.getBool( key ); |
---|
1017 | ui.action_TrayIcon->setChecked( b ); |
---|
1018 | myTrayIcon.setVisible( b ); |
---|
1019 | break; |
---|
1020 | |
---|
1021 | case Prefs::MINIMAL_VIEW: |
---|
1022 | b = myPrefs.getBool( key ); |
---|
1023 | ui.action_MinimalView->setChecked( b ); |
---|
1024 | ui.listView->setItemDelegate( b ? myTorrentDelegateMin : myTorrentDelegate ); |
---|
1025 | ui.listView->reset( ); // force the rows to resize |
---|
1026 | break; |
---|
1027 | |
---|
1028 | case Prefs::MAIN_WINDOW_X: |
---|
1029 | case Prefs::MAIN_WINDOW_Y: |
---|
1030 | case Prefs::MAIN_WINDOW_WIDTH: |
---|
1031 | case Prefs::MAIN_WINDOW_HEIGHT: |
---|
1032 | setGeometry( myPrefs.getInt( Prefs::MAIN_WINDOW_X ), |
---|
1033 | myPrefs.getInt( Prefs::MAIN_WINDOW_Y ), |
---|
1034 | myPrefs.getInt( Prefs::MAIN_WINDOW_WIDTH ), |
---|
1035 | myPrefs.getInt( Prefs::MAIN_WINDOW_HEIGHT ) ); |
---|
1036 | break; |
---|
1037 | |
---|
1038 | case Prefs :: ALT_SPEED_LIMIT_ENABLED: |
---|
1039 | case Prefs :: ALT_SPEED_LIMIT_UP: |
---|
1040 | case Prefs :: ALT_SPEED_LIMIT_DOWN: { |
---|
1041 | b = myPrefs.getBool( Prefs :: ALT_SPEED_LIMIT_ENABLED ); |
---|
1042 | myAltSpeedButton->setChecked( b ); |
---|
1043 | myAltSpeedButton->setIcon( b ? mySpeedModeOnIcon : mySpeedModeOffIcon ); |
---|
1044 | const QString fmt = b ? tr( "Click to disable Temporary Speed Limits\n(%1 down, %2 up)" ) |
---|
1045 | : tr( "Click to enable Temporary Speed Limits\n(%1 down, %2 up)" ); |
---|
1046 | const Speed d = Speed::fromKbps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) ); |
---|
1047 | const Speed u = Speed::fromKbps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) ); |
---|
1048 | myAltSpeedButton->setToolTip( fmt.arg( Utils::speedToString( d ) ) |
---|
1049 | .arg( Utils::speedToString( u ) ) ); |
---|
1050 | break; |
---|
1051 | } |
---|
1052 | |
---|
1053 | default: |
---|
1054 | break; |
---|
1055 | } |
---|
1056 | } |
---|
1057 | |
---|
1058 | /*** |
---|
1059 | **** |
---|
1060 | ***/ |
---|
1061 | |
---|
1062 | void |
---|
1063 | TrMainWindow :: newTorrent( ) |
---|
1064 | { |
---|
1065 | MakeDialog * dialog = new MakeDialog( mySession, this ); |
---|
1066 | dialog->show( ); |
---|
1067 | } |
---|
1068 | |
---|
1069 | void |
---|
1070 | TrMainWindow :: openTorrent( ) |
---|
1071 | { |
---|
1072 | if( myFileDialog == 0 ) |
---|
1073 | { |
---|
1074 | myFileDialog = new QFileDialog( this, |
---|
1075 | tr( "Add Torrent" ), |
---|
1076 | myPrefs.getString( Prefs::OPEN_DIALOG_FOLDER ), |
---|
1077 | tr( "Torrent Files (*.torrent);;All Files (*.*)" ) ); |
---|
1078 | myFileDialog->setFileMode( QFileDialog::ExistingFiles ); |
---|
1079 | |
---|
1080 | |
---|
1081 | QCheckBox * button = new QCheckBox( tr( "Display &options dialog" ) ); |
---|
1082 | button->setChecked( myPrefs.getBool( Prefs::OPTIONS_PROMPT ) ); |
---|
1083 | QGridLayout * layout = dynamic_cast<QGridLayout*>(myFileDialog->layout()); |
---|
1084 | layout->addWidget( button, layout->rowCount( ), 0, 1, -1, Qt::AlignLeft ); |
---|
1085 | myFileDialogOptionsCheck = button; |
---|
1086 | |
---|
1087 | connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)), this, SLOT(addTorrents(const QStringList&))); |
---|
1088 | } |
---|
1089 | |
---|
1090 | myFileDialog->show( ); |
---|
1091 | } |
---|
1092 | |
---|
1093 | void |
---|
1094 | TrMainWindow :: addTorrents( const QStringList& filenames ) |
---|
1095 | { |
---|
1096 | foreach( const QString& filename, filenames ) |
---|
1097 | addTorrent( filename ); |
---|
1098 | } |
---|
1099 | |
---|
1100 | void |
---|
1101 | TrMainWindow :: addTorrent( const QString& filename ) |
---|
1102 | { |
---|
1103 | if( !myFileDialogOptionsCheck->isChecked( ) ) { |
---|
1104 | mySession.addTorrent( filename ); |
---|
1105 | QApplication :: alert ( this ); |
---|
1106 | } else { |
---|
1107 | Options * o = new Options( mySession, myPrefs, filename, this ); |
---|
1108 | o->show( ); |
---|
1109 | QApplication :: alert( o ); |
---|
1110 | } |
---|
1111 | } |
---|
1112 | |
---|
1113 | /*** |
---|
1114 | **** |
---|
1115 | ***/ |
---|
1116 | |
---|
1117 | void |
---|
1118 | TrMainWindow :: updateNetworkIcon( ) |
---|
1119 | { |
---|
1120 | const time_t now = time( NULL ); |
---|
1121 | const int period = 3; |
---|
1122 | const bool isSending = now - myLastSendTime <= period; |
---|
1123 | const bool isReading = now - myLastReadTime <= period; |
---|
1124 | const char * key; |
---|
1125 | |
---|
1126 | if( isSending && isReading ) |
---|
1127 | key = "network-transmit-receive"; |
---|
1128 | else if( isSending ) |
---|
1129 | key = "network-transmit"; |
---|
1130 | else if( isReading ) |
---|
1131 | key = "network-receive"; |
---|
1132 | else |
---|
1133 | key = "network-idle"; |
---|
1134 | |
---|
1135 | QIcon icon = getStockIcon( key, QStyle::SP_DriveNetIcon ); |
---|
1136 | QPixmap pixmap = icon.pixmap ( 16, 16 ); |
---|
1137 | myNetworkLabel->setPixmap( pixmap ); |
---|
1138 | myNetworkLabel->setToolTip( isSending || isReading |
---|
1139 | ? tr( "Transmission server is responding" ) |
---|
1140 | : tr( "Last response from server was %1 ago" ).arg( Utils::timeToString( now-std::max(myLastReadTime,myLastSendTime)))); |
---|
1141 | } |
---|
1142 | |
---|
1143 | void |
---|
1144 | TrMainWindow :: onNetworkTimer( ) |
---|
1145 | { |
---|
1146 | updateNetworkIcon( ); |
---|
1147 | } |
---|
1148 | |
---|
1149 | void |
---|
1150 | TrMainWindow :: dataReadProgress( ) |
---|
1151 | { |
---|
1152 | myLastReadTime = time( NULL ); |
---|
1153 | updateNetworkIcon( ); |
---|
1154 | } |
---|
1155 | |
---|
1156 | void |
---|
1157 | TrMainWindow :: dataSendProgress( ) |
---|
1158 | { |
---|
1159 | myLastSendTime = time( NULL ); |
---|
1160 | updateNetworkIcon( ); |
---|
1161 | } |
---|
1162 | |
---|
1163 | void |
---|
1164 | TrMainWindow :: wrongAuthentication( ) |
---|
1165 | { |
---|
1166 | mySession.stop( ); |
---|
1167 | mySessionDialog->show( ); |
---|
1168 | } |
---|