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