2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
|
2010-07-31 23:11:05 +00:00
|
|
|
#include <QtGui>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2009-12-12 15:38:14 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h>
|
2009-04-13 19:04:21 +00:00
|
|
|
#include <libtransmission/version.h>
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "about.h"
|
2011-01-21 21:51:50 +00:00
|
|
|
#include "add-data.h"
|
2010-07-31 23:11:05 +00:00
|
|
|
#include "app.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "details.h"
|
2010-07-30 22:31:31 +00:00
|
|
|
#include "filterbar.h"
|
2009-04-11 18:25:12 +00:00
|
|
|
#include "filters.h"
|
2010-07-03 01:10:36 +00:00
|
|
|
#include "formatter.h"
|
2009-04-15 01:59:54 +00:00
|
|
|
#include "hig.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "mainwin.h"
|
|
|
|
#include "make-dialog.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "prefs-dialog.h"
|
2009-05-13 15:54:04 +00:00
|
|
|
#include "relocate.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "session.h"
|
2009-05-03 17:37:39 +00:00
|
|
|
#include "session-dialog.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "speed.h"
|
|
|
|
#include "stats-dialog.h"
|
|
|
|
#include "torrent-delegate.h"
|
|
|
|
#include "torrent-delegate-min.h"
|
|
|
|
#include "torrent-filter.h"
|
|
|
|
#include "torrent-model.h"
|
2009-04-15 01:59:54 +00:00
|
|
|
#include "triconpushbutton.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "ui_mainwin.h"
|
|
|
|
|
|
|
|
#define PREFS_KEY "prefs-key";
|
|
|
|
|
|
|
|
QIcon
|
2010-08-06 20:21:35 +00:00
|
|
|
TrMainWindow :: getStockIcon( const QString& name, int fallback )
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2010-08-06 20:21:35 +00:00
|
|
|
QIcon icon = QIcon::fromTheme( name );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2010-08-06 20:21:35 +00:00
|
|
|
if( icon.isNull( ) && ( fallback >= 0 ) )
|
|
|
|
icon = style()->standardIcon( QStyle::StandardPixmap( fallback ), 0, this );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2010-08-06 20:21:35 +00:00
|
|
|
return icon;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-05-06 13:39:48 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
QSize calculateTextButtonSizeHint( QPushButton * button )
|
|
|
|
{
|
|
|
|
QStyleOptionButton opt;
|
|
|
|
opt.initFrom( button );
|
|
|
|
QString s( button->text( ) );
|
|
|
|
if( s.isEmpty( ) )
|
|
|
|
s = QString::fromLatin1( "XXXX" );
|
|
|
|
QFontMetrics fm = button->fontMetrics( );
|
|
|
|
QSize sz = fm.size( Qt::TextShowMnemonic, s );
|
|
|
|
return button->style()->sizeFromContents( QStyle::CT_PushButton, &opt, sz, button ).expandedTo( QApplication::globalStrut( ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& model, bool minimized ):
|
|
|
|
myLastFullUpdateTime( 0 ),
|
2009-05-03 22:00:56 +00:00
|
|
|
mySessionDialog( new SessionDialog( session, prefs, this ) ),
|
2010-05-06 04:49:10 +00:00
|
|
|
myPrefsDialog( 0 ),
|
2009-04-09 18:55:47 +00:00
|
|
|
myAboutDialog( new AboutDialog( this ) ),
|
|
|
|
myStatsDialog( new StatsDialog( session, this ) ),
|
2009-04-18 23:18:28 +00:00
|
|
|
myDetailsDialog( 0 ),
|
2009-04-09 18:55:47 +00:00
|
|
|
myFilterModel( prefs ),
|
|
|
|
myTorrentDelegate( new TorrentDelegate( this ) ),
|
|
|
|
myTorrentDelegateMin( new TorrentDelegateMin( this ) ),
|
|
|
|
mySession( session ),
|
|
|
|
myPrefs( prefs ),
|
|
|
|
myModel( model ),
|
|
|
|
mySpeedModeOffIcon( ":/icons/alt-limit-off.png" ),
|
|
|
|
mySpeedModeOnIcon( ":/icons/alt-limit-on.png" ),
|
|
|
|
myLastSendTime( 0 ),
|
|
|
|
myLastReadTime( 0 ),
|
2011-07-13 17:22:01 +00:00
|
|
|
myNetworkTimer( this ),
|
2011-07-19 21:19:18 +00:00
|
|
|
myRefreshTrayIconTimer( this ),
|
|
|
|
myRefreshActionSensitivityTimer( this )
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2010-07-31 23:11:05 +00:00
|
|
|
setAcceptDrops( true );
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
QAction * sep = new QAction( this );
|
|
|
|
sep->setSeparator( true );
|
|
|
|
|
|
|
|
ui.setupUi( this );
|
|
|
|
|
|
|
|
QStyle * style = this->style();
|
|
|
|
|
|
|
|
int i = style->pixelMetric( QStyle::PM_SmallIconSize, 0, this );
|
|
|
|
const QSize smallIconSize( i, i );
|
|
|
|
|
|
|
|
// icons
|
2011-01-20 19:48:13 +00:00
|
|
|
ui.action_OpenFile->setIcon( getStockIcon( "folder-open", QStyle::SP_DialogOpenButton ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.action_New->setIcon( getStockIcon( "document-new", QStyle::SP_DesktopIcon ) );
|
|
|
|
ui.action_Properties->setIcon( getStockIcon( "document-properties", QStyle::SP_DesktopIcon ) );
|
|
|
|
ui.action_OpenFolder->setIcon( getStockIcon( "folder-open", QStyle::SP_DirOpenIcon ) );
|
|
|
|
ui.action_Start->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) );
|
2011-08-01 22:24:24 +00:00
|
|
|
ui.action_StartNow->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.action_Announce->setIcon( getStockIcon( "network-transmit-receive" ) );
|
|
|
|
ui.action_Pause->setIcon( getStockIcon( "media-playback-pause", QStyle::SP_MediaPause ) );
|
|
|
|
ui.action_Remove->setIcon( getStockIcon( "list-remove", QStyle::SP_TrashIcon ) );
|
|
|
|
ui.action_Delete->setIcon( getStockIcon( "edit-delete", QStyle::SP_TrashIcon ) );
|
|
|
|
ui.action_StartAll->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) );
|
|
|
|
ui.action_PauseAll->setIcon( getStockIcon( "media-playback-pause", QStyle::SP_MediaPause ) );
|
|
|
|
ui.action_Quit->setIcon( getStockIcon( "application-exit" ) );
|
|
|
|
ui.action_SelectAll->setIcon( getStockIcon( "edit-select-all" ) );
|
|
|
|
ui.action_ReverseSortOrder->setIcon( getStockIcon( "view-sort-ascending", QStyle::SP_ArrowDown ) );
|
|
|
|
ui.action_Preferences->setIcon( getStockIcon( "preferences-system" ) );
|
|
|
|
ui.action_Contents->setIcon( getStockIcon( "help-contents", QStyle::SP_DialogHelpButton ) );
|
|
|
|
ui.action_About->setIcon( getStockIcon( "help-about" ) );
|
2011-08-01 22:24:24 +00:00
|
|
|
ui.action_QueueMoveTop->setIcon( getStockIcon( "go-top" ) );
|
|
|
|
ui.action_QueueMoveUp->setIcon( getStockIcon( "go-up", QStyle::SP_ArrowUp ) );
|
|
|
|
ui.action_QueueMoveDown->setIcon( getStockIcon( "go-down", QStyle::SP_ArrowDown ) );
|
|
|
|
ui.action_QueueMoveBottom->setIcon( getStockIcon( "go-bottom" ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
// ui signals
|
|
|
|
connect( ui.action_Toolbar, SIGNAL(toggled(bool)), this, SLOT(setToolbarVisible(bool)));
|
|
|
|
connect( ui.action_Filterbar, SIGNAL(toggled(bool)), this, SLOT(setFilterbarVisible(bool)));
|
|
|
|
connect( ui.action_Statusbar, SIGNAL(toggled(bool)), this, SLOT(setStatusbarVisible(bool)));
|
2010-03-15 14:42:56 +00:00
|
|
|
connect( ui.action_CompactView, SIGNAL(toggled(bool)), this, SLOT(setCompactView(bool)));
|
2009-04-11 18:25:12 +00:00
|
|
|
connect( ui.action_SortByActivity, SIGNAL(toggled(bool)), this, SLOT(onSortByActivityToggled(bool)));
|
|
|
|
connect( ui.action_SortByAge, SIGNAL(toggled(bool)), this, SLOT(onSortByAgeToggled(bool)));
|
|
|
|
connect( ui.action_SortByETA, SIGNAL(toggled(bool)), this, SLOT(onSortByETAToggled(bool)));
|
|
|
|
connect( ui.action_SortByName, SIGNAL(toggled(bool)), this, SLOT(onSortByNameToggled(bool)));
|
|
|
|
connect( ui.action_SortByProgress, SIGNAL(toggled(bool)), this, SLOT(onSortByProgressToggled(bool)));
|
2011-08-02 03:59:54 +00:00
|
|
|
connect( ui.action_SortByQueue, SIGNAL(toggled(bool)), this, SLOT(onSortByQueueToggled(bool)));
|
2009-04-11 18:25:12 +00:00
|
|
|
connect( ui.action_SortByRatio, SIGNAL(toggled(bool)), this, SLOT(onSortByRatioToggled(bool)));
|
|
|
|
connect( ui.action_SortBySize, SIGNAL(toggled(bool)), this, SLOT(onSortBySizeToggled(bool)));
|
|
|
|
connect( ui.action_SortByState, SIGNAL(toggled(bool)), this, SLOT(onSortByStateToggled(bool)));
|
|
|
|
connect( ui.action_ReverseSortOrder, SIGNAL(toggled(bool)), this, SLOT(setSortAscendingPref(bool)));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.action_Start, SIGNAL(triggered()), this, SLOT(startSelected()));
|
2011-08-01 22:24:24 +00:00
|
|
|
connect( ui.action_QueueMoveTop, SIGNAL(triggered()), this, SLOT(queueMoveTop()));
|
|
|
|
connect( ui.action_QueueMoveUp, SIGNAL(triggered()), this, SLOT(queueMoveUp()));
|
|
|
|
connect( ui.action_QueueMoveDown, SIGNAL(triggered()), this, SLOT(queueMoveDown()));
|
|
|
|
connect( ui.action_QueueMoveBottom, SIGNAL(triggered()), this, SLOT(queueMoveBottom()));
|
|
|
|
connect( ui.action_StartNow, SIGNAL(triggered()), this, SLOT(startSelectedNow()));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.action_Pause, SIGNAL(triggered()), this, SLOT(pauseSelected()));
|
|
|
|
connect( ui.action_Remove, SIGNAL(triggered()), this, SLOT(removeSelected()));
|
|
|
|
connect( ui.action_Delete, SIGNAL(triggered()), this, SLOT(deleteSelected()));
|
|
|
|
connect( ui.action_Verify, SIGNAL(triggered()), this, SLOT(verifySelected()) );
|
|
|
|
connect( ui.action_Announce, SIGNAL(triggered()), this, SLOT(reannounceSelected()) );
|
|
|
|
connect( ui.action_StartAll, SIGNAL(triggered()), this, SLOT(startAll()));
|
|
|
|
connect( ui.action_PauseAll, SIGNAL(triggered()), this, SLOT(pauseAll()));
|
2011-01-20 19:48:13 +00:00
|
|
|
connect( ui.action_OpenFile, SIGNAL(triggered()), this, SLOT(openTorrent()));
|
2009-12-03 17:23:53 +00:00
|
|
|
connect( ui.action_AddURL, SIGNAL(triggered()), this, SLOT(openURL()));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.action_New, SIGNAL(triggered()), this, SLOT(newTorrent()));
|
2010-05-06 04:49:10 +00:00
|
|
|
connect( ui.action_Preferences, SIGNAL(triggered()), this, SLOT(openPreferences()));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.action_Statistics, SIGNAL(triggered()), myStatsDialog, SLOT(show()));
|
2010-08-02 03:07:42 +00:00
|
|
|
connect( ui.action_Donate, SIGNAL(triggered()), this, SLOT(openDonate()));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show()));
|
|
|
|
connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
|
|
|
|
connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder()));
|
2009-12-03 15:23:43 +00:00
|
|
|
connect( ui.action_CopyMagnetToClipboard, SIGNAL(triggered()), this, SLOT(copyMagnetLinkToClipboard()));
|
2009-05-13 15:54:04 +00:00
|
|
|
connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation()));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
|
2009-05-03 22:00:56 +00:00
|
|
|
connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show()));
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( ui.listView, SIGNAL(activated(const QModelIndex&)), ui.action_Properties, SLOT(trigger()));
|
|
|
|
|
|
|
|
// signals
|
|
|
|
connect( ui.action_SelectAll, SIGNAL(triggered()), ui.listView, SLOT(selectAll()));
|
|
|
|
connect( ui.action_DeselectAll, SIGNAL(triggered()), ui.listView, SLOT(clearSelection()));
|
|
|
|
|
|
|
|
connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount()));
|
|
|
|
connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount()));
|
2011-07-19 21:19:18 +00:00
|
|
|
connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon()));
|
|
|
|
connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon()));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
connect( ui.action_Quit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()) );
|
|
|
|
|
|
|
|
// torrent view
|
|
|
|
myFilterModel.setSourceModel( &myModel );
|
2009-05-03 18:35:33 +00:00
|
|
|
connect( &myModel, SIGNAL(modelReset()), this, SLOT(onModelReset()));
|
|
|
|
connect( &myModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(onModelReset()));
|
|
|
|
connect( &myModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(onModelReset()));
|
2011-07-13 17:22:01 +00:00
|
|
|
connect( &myModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(refreshTrayIconSoon()));
|
2010-08-05 15:01:40 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.listView->setModel( &myFilterModel );
|
2011-07-19 21:19:18 +00:00
|
|
|
connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivitySoon()));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
QActionGroup * actionGroup = new QActionGroup( this );
|
|
|
|
actionGroup->addAction( ui.action_SortByActivity );
|
|
|
|
actionGroup->addAction( ui.action_SortByAge );
|
|
|
|
actionGroup->addAction( ui.action_SortByETA );
|
|
|
|
actionGroup->addAction( ui.action_SortByName );
|
|
|
|
actionGroup->addAction( ui.action_SortByProgress );
|
2011-08-03 03:47:17 +00:00
|
|
|
actionGroup->addAction( ui.action_SortByQueue );
|
2009-04-09 18:55:47 +00:00
|
|
|
actionGroup->addAction( ui.action_SortByRatio );
|
|
|
|
actionGroup->addAction( ui.action_SortBySize );
|
|
|
|
actionGroup->addAction( ui.action_SortByState );
|
|
|
|
|
2009-04-15 01:59:54 +00:00
|
|
|
QMenu * menu = new QMenu( );
|
2011-01-20 19:48:13 +00:00
|
|
|
menu->addAction( ui.action_OpenFile );
|
2009-12-03 17:23:53 +00:00
|
|
|
menu->addAction( ui.action_AddURL );
|
2009-04-09 18:55:47 +00:00
|
|
|
menu->addSeparator( );
|
|
|
|
menu->addAction( ui.action_ShowMainWindow );
|
|
|
|
menu->addAction( ui.action_ShowMessageLog );
|
|
|
|
menu->addAction( ui.action_About );
|
|
|
|
menu->addSeparator( );
|
|
|
|
menu->addAction( ui.action_StartAll );
|
|
|
|
menu->addAction( ui.action_PauseAll );
|
|
|
|
menu->addSeparator( );
|
|
|
|
menu->addAction( ui.action_Quit );
|
|
|
|
myTrayIcon.setContextMenu( menu );
|
|
|
|
myTrayIcon.setIcon( QApplication::windowIcon( ) );
|
|
|
|
|
|
|
|
connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)) );
|
2009-08-11 18:57:49 +00:00
|
|
|
connect( ui.action_ShowMainWindow, SIGNAL(toggled(bool)), this, SLOT(toggleWindows(bool)));
|
2009-04-14 22:05:11 +00:00
|
|
|
connect( &myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
|
|
this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
ui.action_ShowMainWindow->setChecked( !minimized );
|
|
|
|
ui.action_TrayIcon->setChecked( minimized || prefs.getBool( Prefs::SHOW_TRAY_ICON ) );
|
|
|
|
|
2009-04-15 01:59:54 +00:00
|
|
|
ui.verticalLayout->addWidget( createStatusBar( ) );
|
2010-07-30 22:31:31 +00:00
|
|
|
ui.verticalLayout->insertWidget( 0, myFilterBar = new FilterBar( myPrefs, myModel, myFilterModel ) );
|
2009-04-15 01:59:54 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
QList<int> initKeys;
|
|
|
|
initKeys << Prefs :: MAIN_WINDOW_X
|
|
|
|
<< Prefs :: SHOW_TRAY_ICON
|
|
|
|
<< Prefs :: SORT_REVERSED
|
|
|
|
<< Prefs :: SORT_MODE
|
|
|
|
<< Prefs :: FILTERBAR
|
|
|
|
<< Prefs :: STATUSBAR
|
|
|
|
<< Prefs :: STATUSBAR_STATS
|
|
|
|
<< Prefs :: TOOLBAR
|
|
|
|
<< Prefs :: ALT_SPEED_LIMIT_ENABLED
|
2010-03-15 14:42:56 +00:00
|
|
|
<< Prefs :: COMPACT_VIEW
|
2009-04-14 22:05:11 +00:00
|
|
|
<< Prefs :: DSPEED
|
|
|
|
<< Prefs :: DSPEED_ENABLED
|
|
|
|
<< Prefs :: USPEED
|
|
|
|
<< Prefs :: USPEED_ENABLED
|
|
|
|
<< Prefs :: RATIO
|
|
|
|
<< Prefs :: RATIO_ENABLED;
|
2009-04-09 18:55:47 +00:00
|
|
|
foreach( int key, initKeys )
|
|
|
|
refreshPref( key );
|
|
|
|
|
2009-05-03 17:37:39 +00:00
|
|
|
connect( &mySession, SIGNAL(sourceChanged()), this, SLOT(onSessionSourceChanged()) );
|
2009-04-09 18:55:47 +00:00
|
|
|
connect( &mySession, SIGNAL(statsUpdated()), this, SLOT(refreshStatusBar()) );
|
|
|
|
connect( &mySession, SIGNAL(dataReadProgress()), this, SLOT(dataReadProgress()) );
|
|
|
|
connect( &mySession, SIGNAL(dataSendProgress()), this, SLOT(dataSendProgress()) );
|
2009-05-03 22:00:56 +00:00
|
|
|
connect( &mySession, SIGNAL(httpAuthenticationRequired()), this, SLOT(wrongAuthentication()) );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
if( mySession.isServer( ) )
|
2009-04-15 01:59:54 +00:00
|
|
|
myNetworkLabel->hide( );
|
2009-04-09 18:55:47 +00:00
|
|
|
else {
|
|
|
|
connect( &myNetworkTimer, SIGNAL(timeout()), this, SLOT(onNetworkTimer()));
|
|
|
|
myNetworkTimer.start( 1000 );
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:22:01 +00:00
|
|
|
connect( &myRefreshTrayIconTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIcon()) );
|
2011-07-19 21:19:18 +00:00
|
|
|
connect( &myRefreshActionSensitivityTimer, SIGNAL(timeout()), this, SLOT(refreshActionSensitivity()) );
|
2011-07-13 17:22:01 +00:00
|
|
|
|
|
|
|
|
2011-07-19 21:19:18 +00:00
|
|
|
refreshActionSensitivitySoon( );
|
2011-07-13 17:22:01 +00:00
|
|
|
refreshTrayIconSoon( );
|
2009-04-09 18:55:47 +00:00
|
|
|
refreshStatusBar( );
|
2009-05-03 17:37:39 +00:00
|
|
|
refreshTitle( );
|
2009-04-09 18:55:47 +00:00
|
|
|
refreshVisibleCount( );
|
|
|
|
}
|
|
|
|
|
|
|
|
TrMainWindow :: ~TrMainWindow( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2009-09-26 04:39:58 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: closeEvent( QCloseEvent * event )
|
|
|
|
{
|
|
|
|
// if they're using a tray icon, close to the tray
|
|
|
|
// instead of exiting
|
|
|
|
if( !myPrefs.getBool( Prefs :: SHOW_TRAY_ICON ) )
|
|
|
|
event->accept( );
|
|
|
|
else {
|
|
|
|
toggleWindows( false );
|
|
|
|
event->ignore( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2009-05-03 17:37:39 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: onSessionSourceChanged( )
|
|
|
|
{
|
|
|
|
myModel.clear( );
|
2009-05-03 18:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: onModelReset( )
|
|
|
|
{
|
2009-05-03 17:37:39 +00:00
|
|
|
refreshTitle( );
|
|
|
|
refreshVisibleCount( );
|
2011-07-19 21:19:18 +00:00
|
|
|
refreshActionSensitivitySoon( );
|
2009-05-03 17:37:39 +00:00
|
|
|
refreshStatusBar( );
|
2011-07-13 17:22:01 +00:00
|
|
|
refreshTrayIconSoon( );
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2009-04-14 22:05:11 +00:00
|
|
|
#define PREF_VARIANTS_KEY "pref-variants-list"
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: onSetPrefs( )
|
|
|
|
{
|
|
|
|
const QVariantList p = sender()->property( PREF_VARIANTS_KEY ).toList( );
|
|
|
|
assert( ( p.size( ) % 2 ) == 0 );
|
|
|
|
for( int i=0, n=p.size(); i<n; i+=2 )
|
|
|
|
myPrefs.set( p[i].toInt(), p[i+1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: onSetPrefs( bool isChecked )
|
|
|
|
{
|
|
|
|
if( isChecked )
|
|
|
|
onSetPrefs( );
|
|
|
|
}
|
|
|
|
|
2009-05-06 13:39:48 +00:00
|
|
|
#define SHOW_KEY "show-mode"
|
|
|
|
|
2009-04-15 01:59:54 +00:00
|
|
|
QWidget *
|
|
|
|
TrMainWindow :: createStatusBar( )
|
|
|
|
{
|
|
|
|
QMenu * m;
|
2010-06-25 21:04:33 +00:00
|
|
|
QLabel * l;
|
2009-04-15 01:59:54 +00:00
|
|
|
QHBoxLayout * h;
|
|
|
|
QPushButton * p;
|
|
|
|
QActionGroup * a;
|
|
|
|
const int i = style( )->pixelMetric( QStyle::PM_SmallIconSize, 0, this );
|
|
|
|
const QSize smallIconSize( i, i );
|
|
|
|
|
|
|
|
QWidget * top = myStatusBar = new QWidget;
|
|
|
|
h = new QHBoxLayout( top );
|
|
|
|
h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL );
|
2009-05-02 14:25:18 +00:00
|
|
|
h->setSpacing( HIG::PAD_SMALL );
|
2009-04-15 01:59:54 +00:00
|
|
|
|
|
|
|
p = myOptionsButton = new TrIconPushButton( this );
|
2010-09-24 15:22:53 +00:00
|
|
|
p->setIcon( QIcon( ":/icons/utilities.png" ) );
|
|
|
|
p->setIconSize( QPixmap( ":/icons/utilities.png" ).size() );
|
2009-04-15 01:59:54 +00:00
|
|
|
p->setFlat( true );
|
|
|
|
p->setMenu( createOptionsMenu( ) );
|
|
|
|
h->addWidget( p );
|
|
|
|
|
2010-06-05 10:47:41 +00:00
|
|
|
p = myAltSpeedButton = new QPushButton( this );
|
2009-04-15 01:59:54 +00:00
|
|
|
p->setIcon( myPrefs.get<bool>(Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon );
|
2010-06-05 10:47:41 +00:00
|
|
|
p->setIconSize( QPixmap( ":/icons/alt-limit-on.png" ).size() );
|
|
|
|
p->setCheckable( true );
|
|
|
|
p->setFixedWidth( p->height() );
|
2009-04-15 01:59:54 +00:00
|
|
|
p->setFlat( true );
|
|
|
|
h->addWidget( p );
|
|
|
|
connect( p, SIGNAL(clicked()), this, SLOT(toggleSpeedMode()));
|
|
|
|
|
|
|
|
l = myNetworkLabel = new QLabel;
|
|
|
|
h->addWidget( l );
|
|
|
|
|
|
|
|
h->addStretch( 1 );
|
|
|
|
|
|
|
|
l = myVisibleCountLabel = new QLabel( this );
|
|
|
|
h->addWidget( l );
|
|
|
|
|
|
|
|
h->addStretch( 1 );
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2009-04-15 01:59:54 +00:00
|
|
|
a = new QActionGroup( this );
|
|
|
|
a->addAction( ui.action_TotalRatio );
|
|
|
|
a->addAction( ui.action_TotalTransfer );
|
|
|
|
a->addAction( ui.action_SessionRatio );
|
|
|
|
a->addAction( ui.action_SessionTransfer );
|
|
|
|
m = new QMenu( );
|
|
|
|
m->addAction( ui.action_TotalRatio );
|
|
|
|
m->addAction( ui.action_TotalTransfer );
|
|
|
|
m->addAction( ui.action_SessionRatio );
|
|
|
|
m->addAction( ui.action_SessionTransfer );
|
|
|
|
connect( ui.action_TotalRatio, SIGNAL(triggered()), this, SLOT(showTotalRatio()));
|
|
|
|
connect( ui.action_TotalTransfer, SIGNAL(triggered()), this, SLOT(showTotalTransfer()));
|
|
|
|
connect( ui.action_SessionRatio, SIGNAL(triggered()), this, SLOT(showSessionRatio()));
|
|
|
|
connect( ui.action_SessionTransfer, SIGNAL(triggered()), this, SLOT(showSessionTransfer()));
|
|
|
|
p = myStatsModeButton = new TrIconPushButton( this );
|
2009-12-03 14:46:54 +00:00
|
|
|
p->setIcon( QIcon( ":/icons/ratio.png" ) );
|
2010-06-05 10:47:41 +00:00
|
|
|
p->setIconSize( QPixmap( ":/icons/ratio.png" ).size() );
|
2009-04-15 01:59:54 +00:00
|
|
|
p->setFlat( true );
|
|
|
|
p->setMenu( m );
|
2010-01-05 23:47:50 +00:00
|
|
|
h->addWidget( p );
|
2009-04-15 01:59:54 +00:00
|
|
|
l = myStatsLabel = new QLabel( this );
|
2010-01-05 23:47:50 +00:00
|
|
|
h->addWidget( l );
|
|
|
|
|
2010-08-06 05:57:41 +00:00
|
|
|
h->addStretch( 1 );
|
2010-06-25 21:04:33 +00:00
|
|
|
|
|
|
|
l = myDownloadSpeedLabel = new QLabel( this );
|
2010-07-31 06:20:17 +00:00
|
|
|
const int minimumSpeedWidth = l->fontMetrics().width( Formatter::speedToString(Speed::fromKBps(999.99)));
|
|
|
|
l->setMinimumWidth( minimumSpeedWidth );
|
|
|
|
l->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
|
2010-06-25 21:04:33 +00:00
|
|
|
h->addWidget( l );
|
2009-04-15 01:59:54 +00:00
|
|
|
l = new QLabel( this );
|
|
|
|
l->setPixmap( getStockIcon( "go-down", QStyle::SP_ArrowDown ).pixmap( smallIconSize ) );
|
|
|
|
h->addWidget( l );
|
2010-06-25 21:04:33 +00:00
|
|
|
|
2010-08-06 05:57:41 +00:00
|
|
|
h->addStretch( 1 );
|
2009-05-02 14:25:18 +00:00
|
|
|
|
2010-06-25 21:04:33 +00:00
|
|
|
l = myUploadSpeedLabel = new QLabel;
|
2010-07-31 06:20:17 +00:00
|
|
|
l->setMinimumWidth( minimumSpeedWidth );
|
|
|
|
l->setAlignment( Qt::AlignRight|Qt::AlignVCenter );
|
2010-06-25 21:04:33 +00:00
|
|
|
h->addWidget( l );
|
2009-04-15 01:59:54 +00:00
|
|
|
l = new QLabel;
|
|
|
|
l->setPixmap( getStockIcon( "go-up", QStyle::SP_ArrowUp ).pixmap( smallIconSize ) );
|
|
|
|
h->addWidget( l );
|
|
|
|
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
2009-04-14 22:05:11 +00:00
|
|
|
QMenu *
|
|
|
|
TrMainWindow :: createOptionsMenu( )
|
|
|
|
{
|
|
|
|
QMenu * menu;
|
|
|
|
QMenu * sub;
|
|
|
|
QAction * a;
|
|
|
|
QActionGroup * g;
|
|
|
|
|
|
|
|
QList<int> stockSpeeds;
|
|
|
|
stockSpeeds << 5 << 10 << 20 << 30 << 40 << 50 << 75 << 100 << 150 << 200 << 250 << 500 << 750;
|
|
|
|
QList<double> stockRatios;
|
|
|
|
stockRatios << 0.25 << 0.50 << 0.75 << 1 << 1.5 << 2 << 3;
|
|
|
|
|
|
|
|
menu = new QMenu;
|
|
|
|
sub = menu->addMenu( tr( "Limit Download Speed" ) );
|
|
|
|
int currentVal = myPrefs.get<int>( Prefs::DSPEED );
|
|
|
|
g = new QActionGroup( this );
|
|
|
|
a = myDlimitOffAction = sub->addAction( tr( "Unlimited" ) );
|
|
|
|
a->setCheckable( true );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED_ENABLED << false );
|
|
|
|
g->addAction( a );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
2010-07-04 06:07:21 +00:00
|
|
|
a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( currentVal ) ) ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
a->setCheckable( true );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << currentVal << Prefs::DSPEED_ENABLED << true );
|
|
|
|
g->addAction( a );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
|
|
|
sub->addSeparator( );
|
|
|
|
foreach( int i, stockSpeeds ) {
|
2010-07-04 06:07:21 +00:00
|
|
|
a = sub->addAction( Formatter::speedToString( Speed::fromKBps( i ) ) );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true );
|
2009-04-14 22:05:11 +00:00
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub = menu->addMenu( tr( "Limit Upload Speed" ) );
|
|
|
|
currentVal = myPrefs.get<int>( Prefs::USPEED );
|
|
|
|
g = new QActionGroup( this );
|
|
|
|
a = myUlimitOffAction = sub->addAction( tr( "Unlimited" ) );
|
|
|
|
a->setCheckable( true );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED_ENABLED << false );
|
|
|
|
g->addAction( a );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
2010-07-04 06:07:21 +00:00
|
|
|
a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( currentVal ) ) ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
a->setCheckable( true );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << currentVal << Prefs::USPEED_ENABLED << true );
|
|
|
|
g->addAction( a );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
|
|
|
sub->addSeparator( );
|
|
|
|
foreach( int i, stockSpeeds ) {
|
2010-07-04 06:07:21 +00:00
|
|
|
a = sub->addAction( Formatter::speedToString( Speed::fromKBps( i ) ) );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true );
|
2009-04-14 22:05:11 +00:00
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->addSeparator( );
|
|
|
|
sub = menu->addMenu( tr( "Stop Seeding at Ratio" ) );
|
|
|
|
|
|
|
|
double d = myPrefs.get<double>( Prefs::RATIO );
|
|
|
|
g = new QActionGroup( this );
|
|
|
|
a = myRatioOffAction = sub->addAction( tr( "Seed Forever" ) );
|
|
|
|
a->setCheckable( true );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO_ENABLED << false );
|
|
|
|
g->addAction( a );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
2010-07-03 01:10:36 +00:00
|
|
|
a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Formatter::ratioToString( d ) ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
a->setCheckable( true );
|
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << d << Prefs::RATIO_ENABLED << true );
|
|
|
|
g->addAction( a );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
|
|
|
sub->addSeparator( );
|
|
|
|
foreach( double i, stockRatios ) {
|
2010-07-03 01:10:36 +00:00
|
|
|
a = sub->addAction( Formatter::ratioToString( i ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true );
|
|
|
|
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2009-04-11 18:25:12 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: setSortPref( int i )
|
|
|
|
{
|
|
|
|
myPrefs.set( Prefs::SORT_MODE, SortMode( i ) );
|
|
|
|
}
|
|
|
|
void TrMainWindow :: onSortByActivityToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ACTIVITY ); }
|
|
|
|
void TrMainWindow :: onSortByAgeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_AGE ); }
|
|
|
|
void TrMainWindow :: onSortByETAToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ETA ); }
|
|
|
|
void TrMainWindow :: onSortByNameToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_NAME ); }
|
|
|
|
void TrMainWindow :: onSortByProgressToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_PROGRESS ); }
|
2011-08-02 03:59:54 +00:00
|
|
|
void TrMainWindow :: onSortByQueueToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_QUEUE ); }
|
2009-04-11 18:25:12 +00:00
|
|
|
void TrMainWindow :: onSortByRatioToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_RATIO ); }
|
|
|
|
void TrMainWindow :: onSortBySizeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_SIZE ); }
|
|
|
|
void TrMainWindow :: onSortByStateToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_STATE ); }
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: setSortAscendingPref( bool b )
|
|
|
|
{
|
|
|
|
myPrefs.set( Prefs::SORT_REVERSED, b );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2010-05-06 04:49:10 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: onPrefsDestroyed( )
|
|
|
|
{
|
|
|
|
myPrefsDialog = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: openPreferences( )
|
|
|
|
{
|
|
|
|
if( myPrefsDialog == 0 ) {
|
|
|
|
myPrefsDialog = new PrefsDialog( mySession, myPrefs, this );
|
|
|
|
connect( myPrefsDialog, SIGNAL(destroyed(QObject*)), this, SLOT(onPrefsDestroyed()));
|
|
|
|
}
|
|
|
|
|
|
|
|
myPrefsDialog->show( );
|
|
|
|
}
|
|
|
|
|
2009-04-18 23:18:28 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: onDetailsDestroyed( )
|
|
|
|
{
|
|
|
|
myDetailsDialog = 0;
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: openProperties( )
|
|
|
|
{
|
2009-04-18 23:18:28 +00:00
|
|
|
if( myDetailsDialog == 0 ) {
|
2010-04-03 14:23:29 +00:00
|
|
|
myDetailsDialog = new Details( mySession, myPrefs, myModel, this );
|
2009-04-18 23:18:28 +00:00
|
|
|
connect( myDetailsDialog, SIGNAL(destroyed(QObject*)), this, SLOT(onDetailsDestroyed()));
|
|
|
|
}
|
|
|
|
|
|
|
|
myDetailsDialog->setIds( getSelectedTorrents( ) );
|
|
|
|
myDetailsDialog->show( );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-05-13 15:54:04 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: setLocation( )
|
|
|
|
{
|
2010-06-04 01:00:27 +00:00
|
|
|
QDialog * d = new RelocateDialog( mySession, myModel, getSelectedTorrents(), this );
|
2009-05-13 15:54:04 +00:00
|
|
|
d->show( );
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: openFolder( )
|
|
|
|
{
|
|
|
|
const int torrentId( *getSelectedTorrents().begin() );
|
|
|
|
const Torrent * tor( myModel.getTorrentFromId( torrentId ) );
|
|
|
|
const QString path( tor->getPath( ) );
|
|
|
|
QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) );
|
|
|
|
}
|
|
|
|
|
2009-12-03 15:23:43 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: copyMagnetLinkToClipboard( )
|
|
|
|
{
|
|
|
|
const int id( *getSelectedTorrents().begin() );
|
|
|
|
mySession.copyMagnetLinkToClipboard( id );
|
|
|
|
}
|
|
|
|
|
2010-08-02 03:07:42 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: openDonate( )
|
|
|
|
{
|
|
|
|
QDesktopServices :: openUrl( QUrl( "http://www.transmissionbt.com/donate.php" ) );
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: openHelp( )
|
|
|
|
{
|
|
|
|
const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
|
|
|
|
int major, minor;
|
|
|
|
sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor );
|
|
|
|
char url[128];
|
2009-12-11 20:26:40 +00:00
|
|
|
tr_snprintf( url, sizeof( url ), fmt, major, minor/10 );
|
2010-08-02 03:07:42 +00:00
|
|
|
QDesktopServices :: openUrl( QUrl( url ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-05-03 17:37:39 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: refreshTitle( )
|
|
|
|
{
|
|
|
|
QString title( "Transmission" );
|
|
|
|
const QUrl url( mySession.getRemoteUrl( ) );
|
|
|
|
if( !url.isEmpty() )
|
2010-06-16 02:58:44 +00:00
|
|
|
title += tr( " - %1:%2" ).arg( url.host() ).arg( url.port() );
|
2009-05-03 17:37:39 +00:00
|
|
|
setWindowTitle( title );
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: refreshVisibleCount( )
|
|
|
|
{
|
|
|
|
const int visibleCount( myFilterModel.rowCount( ) );
|
|
|
|
const int totalCount( visibleCount + myFilterModel.hiddenRowCount( ) );
|
|
|
|
QString str;
|
|
|
|
if( visibleCount == totalCount )
|
|
|
|
str = tr( "%Ln Torrent(s)", 0, totalCount );
|
|
|
|
else
|
|
|
|
str = tr( "%L1 of %Ln Torrent(s)", 0, totalCount ).arg( visibleCount );
|
2009-04-15 01:59:54 +00:00
|
|
|
myVisibleCountLabel->setText( str );
|
2009-05-02 14:25:18 +00:00
|
|
|
myVisibleCountLabel->setVisible( totalCount > 0 );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-13 17:22:01 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: refreshTrayIconSoon( )
|
|
|
|
{
|
|
|
|
if( !myRefreshTrayIconTimer.isActive( ) )
|
|
|
|
{
|
|
|
|
myRefreshTrayIconTimer.setSingleShot( true );
|
2011-07-26 02:56:06 +00:00
|
|
|
myRefreshTrayIconTimer.start( 100 );
|
2011-07-13 17:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-05 15:01:40 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: refreshTrayIcon( )
|
|
|
|
{
|
|
|
|
Speed u, d;
|
|
|
|
const QString idle = tr( "Idle" );
|
|
|
|
|
|
|
|
foreach( int id, myModel.getIds( ) ) {
|
|
|
|
const Torrent * tor = myModel.getTorrentFromId( id );
|
|
|
|
u += tor->uploadSpeed( );
|
|
|
|
d += tor->downloadSpeed( );
|
|
|
|
}
|
|
|
|
|
|
|
|
myTrayIcon.setToolTip( tr( "Transmission\nUp: %1\nDown: %2" )
|
|
|
|
.arg( u.isZero() ? idle : Formatter::speedToString( u ) )
|
|
|
|
.arg( d.isZero() ? idle : Formatter::speedToString( d ) ) );
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: refreshStatusBar( )
|
|
|
|
{
|
|
|
|
const Speed up( myModel.getUploadSpeed( ) );
|
|
|
|
const Speed down( myModel.getDownloadSpeed( ) );
|
2010-07-03 01:10:36 +00:00
|
|
|
myUploadSpeedLabel->setText( Formatter:: speedToString( up ) );
|
|
|
|
myDownloadSpeedLabel->setText( Formatter:: speedToString( down ) );
|
2009-05-02 14:25:18 +00:00
|
|
|
|
2009-05-06 13:46:10 +00:00
|
|
|
myNetworkLabel->setVisible( !mySession.isServer( ) );
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
const QString mode( myPrefs.getString( Prefs::STATUSBAR_STATS ) );
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
if( mode == "session-ratio" )
|
|
|
|
{
|
2010-07-03 01:10:36 +00:00
|
|
|
str = tr( "Ratio: %1" ).arg( Formatter:: ratioToString( mySession.getStats().ratio ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
else if( mode == "session-transfer" )
|
|
|
|
{
|
|
|
|
const tr_session_stats& stats( mySession.getStats( ) );
|
2010-07-03 01:10:36 +00:00
|
|
|
str = tr( "Down: %1, Up: %2" ).arg( Formatter:: sizeToString( stats.downloadedBytes ) )
|
|
|
|
.arg( Formatter:: sizeToString( stats.uploadedBytes ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
else if( mode == "total-transfer" )
|
|
|
|
{
|
|
|
|
const tr_session_stats& stats( mySession.getCumulativeStats( ) );
|
2010-07-03 01:10:36 +00:00
|
|
|
str = tr( "Down: %1, Up: %2" ).arg( Formatter:: sizeToString( stats.downloadedBytes ) )
|
|
|
|
.arg( Formatter:: sizeToString( stats.uploadedBytes ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2009-10-10 00:39:38 +00:00
|
|
|
else // default is "total-ratio"
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2010-07-03 01:10:36 +00:00
|
|
|
str = tr( "Ratio: %1" ).arg( Formatter:: ratioToString( mySession.getCumulativeStats().ratio ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 01:59:54 +00:00
|
|
|
myStatsLabel->setText( str );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-19 21:19:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: refreshActionSensitivitySoon( )
|
|
|
|
{
|
|
|
|
if( !myRefreshActionSensitivityTimer.isActive( ) )
|
|
|
|
{
|
|
|
|
myRefreshActionSensitivityTimer.setSingleShot( true );
|
2011-07-26 02:56:06 +00:00
|
|
|
myRefreshActionSensitivityTimer.start( 100 );
|
2011-07-19 21:19:18 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: refreshActionSensitivity( )
|
|
|
|
{
|
|
|
|
int selected( 0 );
|
|
|
|
int paused( 0 );
|
2011-08-01 22:24:24 +00:00
|
|
|
int queued( 0 );
|
2009-04-09 18:55:47 +00:00
|
|
|
int selectedAndPaused( 0 );
|
2011-08-01 22:24:24 +00:00
|
|
|
int selectedAndQueued( 0 );
|
2009-04-09 18:55:47 +00:00
|
|
|
int canAnnounce( 0 );
|
|
|
|
const QAbstractItemModel * model( ui.listView->model( ) );
|
|
|
|
const QItemSelectionModel * selectionModel( ui.listView->selectionModel( ) );
|
|
|
|
const int rowCount( model->rowCount( ) );
|
|
|
|
|
2009-10-10 00:39:38 +00:00
|
|
|
// count how many torrents are selected, paused, etc
|
2009-04-09 18:55:47 +00:00
|
|
|
for( int row=0; row<rowCount; ++row ) {
|
|
|
|
const QModelIndex modelIndex( model->index( row, 0 ) );
|
|
|
|
assert( model == modelIndex.model( ) );
|
|
|
|
const Torrent * tor( model->data( modelIndex, TorrentModel::TorrentRole ).value<const Torrent*>( ) );
|
2009-10-10 00:39:38 +00:00
|
|
|
if( tor ) {
|
|
|
|
const bool isSelected( selectionModel->isSelected( modelIndex ) );
|
|
|
|
const bool isPaused( tor->isPaused( ) );
|
2011-08-01 22:24:24 +00:00
|
|
|
const bool isQueued( tor->isQueued( ) );
|
|
|
|
if( isSelected ) ++selected;
|
|
|
|
if( isQueued ) ++queued;
|
|
|
|
if( isPaused ) ++ paused;
|
|
|
|
if( isSelected && isPaused ) ++selectedAndPaused;
|
|
|
|
if( isSelected && isQueued ) ++selectedAndQueued;
|
|
|
|
if( tor->canManualAnnounce( ) ) ++canAnnounce;
|
2009-10-10 00:39:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const bool haveSelection( selected > 0 );
|
|
|
|
ui.action_Verify->setEnabled( haveSelection );
|
|
|
|
ui.action_Remove->setEnabled( haveSelection );
|
|
|
|
ui.action_Delete->setEnabled( haveSelection );
|
2009-04-18 23:18:28 +00:00
|
|
|
ui.action_Properties->setEnabled( haveSelection );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.action_DeselectAll->setEnabled( haveSelection );
|
2009-05-13 19:16:31 +00:00
|
|
|
ui.action_SetLocation->setEnabled( haveSelection );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
const bool oneSelection( selected == 1 );
|
2009-05-08 18:36:41 +00:00
|
|
|
ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) );
|
2009-12-03 15:23:43 +00:00
|
|
|
ui.action_CopyMagnetToClipboard->setEnabled( oneSelection );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
ui.action_SelectAll->setEnabled( selected < rowCount );
|
|
|
|
ui.action_StartAll->setEnabled( paused > 0 );
|
|
|
|
ui.action_PauseAll->setEnabled( paused < rowCount );
|
|
|
|
ui.action_Start->setEnabled( selectedAndPaused > 0 );
|
2011-08-01 22:24:24 +00:00
|
|
|
ui.action_StartNow->setEnabled( selectedAndPaused + selectedAndQueued > 0 );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.action_Pause->setEnabled( selectedAndPaused < selected );
|
|
|
|
ui.action_Announce->setEnabled( selected > 0 && ( canAnnounce == selected ) );
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2011-08-02 03:59:54 +00:00
|
|
|
ui.action_QueueMoveTop->setEnabled( haveSelection );
|
|
|
|
ui.action_QueueMoveUp->setEnabled( haveSelection );
|
|
|
|
ui.action_QueueMoveDown->setEnabled( haveSelection );
|
|
|
|
ui.action_QueueMoveBottom->setEnabled( haveSelection );
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2009-04-18 23:18:28 +00:00
|
|
|
if( myDetailsDialog )
|
|
|
|
myDetailsDialog->setIds( getSelectedTorrents( ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: clearSelection( )
|
|
|
|
{
|
|
|
|
ui.action_DeselectAll->trigger( );
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<int>
|
|
|
|
TrMainWindow :: getSelectedTorrents( ) const
|
|
|
|
{
|
|
|
|
QSet<int> ids;
|
|
|
|
|
|
|
|
foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ) )
|
|
|
|
{
|
2010-07-30 22:31:31 +00:00
|
|
|
const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>( ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
ids.insert( tor->id( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: startSelected( )
|
|
|
|
{
|
2009-05-03 17:37:39 +00:00
|
|
|
mySession.startTorrents( getSelectedTorrents( ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
2011-08-01 22:24:24 +00:00
|
|
|
TrMainWindow :: startSelectedNow( )
|
|
|
|
{
|
|
|
|
mySession.startTorrentsNow( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
void
|
2009-04-09 18:55:47 +00:00
|
|
|
TrMainWindow :: pauseSelected( )
|
|
|
|
{
|
2009-05-03 17:37:39 +00:00
|
|
|
mySession.pauseTorrents( getSelectedTorrents( ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
2011-08-01 22:24:24 +00:00
|
|
|
TrMainWindow :: queueMoveTop( )
|
|
|
|
{
|
|
|
|
mySession.queueMoveTop( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: queueMoveUp( )
|
|
|
|
{
|
|
|
|
mySession.queueMoveUp( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: queueMoveDown( )
|
|
|
|
{
|
|
|
|
mySession.queueMoveDown( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: queueMoveBottom( )
|
|
|
|
{
|
|
|
|
mySession.queueMoveBottom( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
void
|
2009-04-09 18:55:47 +00:00
|
|
|
TrMainWindow :: startAll( )
|
|
|
|
{
|
2009-05-03 17:37:39 +00:00
|
|
|
mySession.startTorrents( );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: pauseAll( )
|
|
|
|
{
|
2009-05-03 17:37:39 +00:00
|
|
|
mySession.pauseTorrents( );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: removeSelected( )
|
|
|
|
{
|
2010-04-23 03:58:42 +00:00
|
|
|
removeTorrents( false );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: deleteSelected( )
|
|
|
|
{
|
2010-04-23 03:58:42 +00:00
|
|
|
removeTorrents( true );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: verifySelected( )
|
|
|
|
{
|
|
|
|
mySession.verifyTorrents( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: reannounceSelected( )
|
|
|
|
{
|
|
|
|
mySession.reannounceTorrents( getSelectedTorrents( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2009-04-11 18:25:12 +00:00
|
|
|
void TrMainWindow :: showTotalRatio ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "total-ratio"); }
|
|
|
|
void TrMainWindow :: showTotalTransfer ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "total-transfer"); }
|
|
|
|
void TrMainWindow :: showSessionRatio ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "session-ratio"); }
|
|
|
|
void TrMainWindow :: showSessionTransfer ( ) { myPrefs.set( Prefs::STATUSBAR_STATS, "session-transfer"); }
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
void
|
2010-03-15 14:42:56 +00:00
|
|
|
TrMainWindow :: setCompactView( bool visible )
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2010-03-15 14:42:56 +00:00
|
|
|
myPrefs.set( Prefs :: COMPACT_VIEW, visible );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: toggleSpeedMode( )
|
|
|
|
{
|
|
|
|
myPrefs.toggleBool( Prefs :: ALT_SPEED_LIMIT_ENABLED );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: setToolbarVisible( bool visible )
|
|
|
|
{
|
|
|
|
myPrefs.set( Prefs::TOOLBAR, visible );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: setFilterbarVisible( bool visible )
|
|
|
|
{
|
|
|
|
myPrefs.set( Prefs::FILTERBAR, visible );
|
|
|
|
}
|
|
|
|
void
|
|
|
|
TrMainWindow :: setStatusbarVisible( bool visible )
|
|
|
|
{
|
|
|
|
myPrefs.set( Prefs::STATUSBAR, visible );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
void
|
2009-08-11 18:57:49 +00:00
|
|
|
TrMainWindow :: toggleWindows( bool doShow )
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2009-08-11 18:57:49 +00:00
|
|
|
if( !doShow )
|
|
|
|
{
|
|
|
|
hide( );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !isVisible( ) ) show( );
|
|
|
|
if ( isMinimized( ) ) showNormal( );
|
2010-07-30 22:31:31 +00:00
|
|
|
//activateWindow( );
|
2009-08-11 18:57:49 +00:00
|
|
|
raise( );
|
2010-07-30 22:31:31 +00:00
|
|
|
QApplication::setActiveWindow( this );
|
2009-08-11 18:57:49 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: trayActivated( QSystemTrayIcon::ActivationReason reason )
|
|
|
|
{
|
|
|
|
if( reason == QSystemTrayIcon::Trigger )
|
2009-08-11 18:57:49 +00:00
|
|
|
{
|
|
|
|
if( isMinimized ( ) )
|
|
|
|
toggleWindows( true );
|
|
|
|
else
|
|
|
|
ui.action_ShowMainWindow->toggle( );
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: refreshPref( int key )
|
|
|
|
{
|
|
|
|
bool b;
|
2009-04-10 03:48:19 +00:00
|
|
|
int i;
|
2009-04-09 18:55:47 +00:00
|
|
|
QString str;
|
|
|
|
|
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
case Prefs::STATUSBAR_STATS:
|
|
|
|
str = myPrefs.getString( key );
|
|
|
|
ui.action_TotalRatio->setChecked ( str == "total-ratio" );
|
|
|
|
ui.action_TotalTransfer->setChecked ( str == "total-transfer" );
|
|
|
|
ui.action_SessionRatio->setChecked ( str == "session-ratio" );
|
|
|
|
ui.action_SessionTransfer->setChecked( str == "session-transfer" );
|
|
|
|
refreshStatusBar( );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::SORT_REVERSED:
|
|
|
|
ui.action_ReverseSortOrder->setChecked( myPrefs.getBool( key ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::SORT_MODE:
|
2009-04-11 18:25:12 +00:00
|
|
|
i = myPrefs.get<SortMode>(key).mode( );
|
|
|
|
ui.action_SortByActivity->setChecked ( i == SortMode::SORT_BY_ACTIVITY );
|
|
|
|
ui.action_SortByAge->setChecked ( i == SortMode::SORT_BY_AGE );
|
|
|
|
ui.action_SortByETA->setChecked ( i == SortMode::SORT_BY_ETA );
|
|
|
|
ui.action_SortByName->setChecked ( i == SortMode::SORT_BY_NAME );
|
|
|
|
ui.action_SortByProgress->setChecked ( i == SortMode::SORT_BY_PROGRESS );
|
2011-08-02 03:59:54 +00:00
|
|
|
ui.action_SortByQueue->setChecked ( i == SortMode::SORT_BY_QUEUE );
|
2009-04-11 18:25:12 +00:00
|
|
|
ui.action_SortByRatio->setChecked ( i == SortMode::SORT_BY_RATIO );
|
|
|
|
ui.action_SortBySize->setChecked ( i == SortMode::SORT_BY_SIZE );
|
|
|
|
ui.action_SortByState->setChecked ( i == SortMode::SORT_BY_STATE );
|
2009-04-10 03:48:19 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-14 22:05:11 +00:00
|
|
|
case Prefs::DSPEED_ENABLED:
|
|
|
|
(myPrefs.get<bool>(key) ? myDlimitOnAction : myDlimitOffAction)->setChecked( true );
|
|
|
|
break;
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2009-04-14 22:05:11 +00:00
|
|
|
case Prefs::DSPEED:
|
2010-07-04 06:07:21 +00:00
|
|
|
myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( myPrefs.get<int>(key) ) ) ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::USPEED_ENABLED:
|
|
|
|
(myPrefs.get<bool>(key) ? myUlimitOnAction : myUlimitOffAction)->setChecked( true );
|
|
|
|
break;
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2009-04-14 22:05:11 +00:00
|
|
|
case Prefs::USPEED:
|
2010-07-04 06:07:21 +00:00
|
|
|
myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( myPrefs.get<int>(key) ) ) ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RATIO_ENABLED:
|
|
|
|
(myPrefs.get<bool>(key) ? myRatioOnAction : myRatioOffAction)->setChecked( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RATIO:
|
2010-07-03 01:10:36 +00:00
|
|
|
myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Formatter::ratioToString( myPrefs.get<double>(key) ) ) );
|
2009-04-14 22:05:11 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
case Prefs::FILTERBAR:
|
|
|
|
b = myPrefs.getBool( key );
|
2009-04-15 01:59:54 +00:00
|
|
|
myFilterBar->setVisible( b );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.action_Filterbar->setChecked( b );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::STATUSBAR:
|
|
|
|
b = myPrefs.getBool( key );
|
2009-04-15 01:59:54 +00:00
|
|
|
myStatusBar->setVisible( b );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.action_Statusbar->setChecked( b );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::TOOLBAR:
|
|
|
|
b = myPrefs.getBool( key );
|
|
|
|
ui.toolBar->setVisible( b );
|
|
|
|
ui.action_Toolbar->setChecked( b );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::SHOW_TRAY_ICON:
|
|
|
|
b = myPrefs.getBool( key );
|
|
|
|
ui.action_TrayIcon->setChecked( b );
|
|
|
|
myTrayIcon.setVisible( b );
|
2011-07-13 17:22:01 +00:00
|
|
|
refreshTrayIconSoon( );
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-18 15:51:38 +00:00
|
|
|
case Prefs::COMPACT_VIEW: {
|
|
|
|
QItemSelectionModel * selectionModel( ui.listView->selectionModel( ) );
|
|
|
|
const QItemSelection selection( selectionModel->selection( ) );
|
|
|
|
const QModelIndex currentIndex( selectionModel->currentIndex( ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
b = myPrefs.getBool( key );
|
2010-03-15 14:42:56 +00:00
|
|
|
ui.action_CompactView->setChecked( b );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.listView->setItemDelegate( b ? myTorrentDelegateMin : myTorrentDelegate );
|
2010-09-18 15:51:38 +00:00
|
|
|
selectionModel->clear( );
|
2009-04-09 18:55:47 +00:00
|
|
|
ui.listView->reset( ); // force the rows to resize
|
2010-09-18 15:51:38 +00:00
|
|
|
selectionModel->select( selection, QItemSelectionModel::Select );
|
|
|
|
selectionModel->setCurrentIndex( currentIndex, QItemSelectionModel::NoUpdate );
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
2010-09-18 15:51:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
case Prefs::MAIN_WINDOW_X:
|
|
|
|
case Prefs::MAIN_WINDOW_Y:
|
|
|
|
case Prefs::MAIN_WINDOW_WIDTH:
|
|
|
|
case Prefs::MAIN_WINDOW_HEIGHT:
|
|
|
|
setGeometry( myPrefs.getInt( Prefs::MAIN_WINDOW_X ),
|
|
|
|
myPrefs.getInt( Prefs::MAIN_WINDOW_Y ),
|
|
|
|
myPrefs.getInt( Prefs::MAIN_WINDOW_WIDTH ),
|
|
|
|
myPrefs.getInt( Prefs::MAIN_WINDOW_HEIGHT ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs :: ALT_SPEED_LIMIT_ENABLED:
|
2009-06-27 05:23:13 +00:00
|
|
|
case Prefs :: ALT_SPEED_LIMIT_UP:
|
|
|
|
case Prefs :: ALT_SPEED_LIMIT_DOWN: {
|
2009-07-01 23:40:07 +00:00
|
|
|
b = myPrefs.getBool( Prefs :: ALT_SPEED_LIMIT_ENABLED );
|
2009-04-15 01:59:54 +00:00
|
|
|
myAltSpeedButton->setChecked( b );
|
|
|
|
myAltSpeedButton->setIcon( b ? mySpeedModeOnIcon : mySpeedModeOffIcon );
|
2009-06-27 05:23:13 +00:00
|
|
|
const QString fmt = b ? tr( "Click to disable Temporary Speed Limits\n(%1 down, %2 up)" )
|
|
|
|
: tr( "Click to enable Temporary Speed Limits\n(%1 down, %2 up)" );
|
2010-07-04 06:07:21 +00:00
|
|
|
const Speed d = Speed::fromKBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) );
|
|
|
|
const Speed u = Speed::fromKBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) );
|
2010-07-03 01:10:36 +00:00
|
|
|
myAltSpeedButton->setToolTip( fmt.arg( Formatter::speedToString( d ) )
|
|
|
|
.arg( Formatter::speedToString( u ) ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
2009-06-27 05:23:13 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: newTorrent( )
|
|
|
|
{
|
2009-10-05 19:53:38 +00:00
|
|
|
MakeDialog * dialog = new MakeDialog( mySession, this );
|
|
|
|
dialog->show( );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: openTorrent( )
|
|
|
|
{
|
2010-06-17 05:56:48 +00:00
|
|
|
QFileDialog * myFileDialog;
|
|
|
|
myFileDialog = new QFileDialog( this,
|
2011-01-20 19:48:13 +00:00
|
|
|
tr( "Open Torrent" ),
|
2010-06-17 05:56:48 +00:00
|
|
|
myPrefs.getString( Prefs::OPEN_DIALOG_FOLDER ),
|
|
|
|
tr( "Torrent Files (*.torrent);;All Files (*.*)" ) );
|
|
|
|
myFileDialog->setFileMode( QFileDialog::ExistingFiles );
|
|
|
|
|
|
|
|
QCheckBox * button = new QCheckBox( tr( "Show &options dialog" ) );
|
|
|
|
button->setChecked( myPrefs.getBool( Prefs::OPTIONS_PROMPT ) );
|
|
|
|
QGridLayout * layout = dynamic_cast<QGridLayout*>(myFileDialog->layout());
|
|
|
|
layout->addWidget( button, layout->rowCount( ), 0, 1, -1, Qt::AlignLeft );
|
|
|
|
myFileDialogOptionsCheck = button;
|
|
|
|
|
|
|
|
connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)),
|
|
|
|
this, SLOT(addTorrents(const QStringList&)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
myFileDialog->show( );
|
|
|
|
}
|
|
|
|
|
2009-12-03 17:23:53 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: openURL( )
|
2010-04-27 03:10:32 +00:00
|
|
|
{
|
2011-01-21 21:51:50 +00:00
|
|
|
QString str = QApplication::clipboard()->text( QClipboard::Selection );
|
|
|
|
|
|
|
|
if( !AddData::isSupported( str ) )
|
|
|
|
str = QApplication::clipboard()->text( QClipboard::Clipboard );
|
|
|
|
|
|
|
|
if( !AddData::isSupported( str ) )
|
|
|
|
str.clear();
|
|
|
|
|
|
|
|
openURL( str );
|
2010-04-27 03:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: openURL( QString url )
|
2009-12-03 17:23:53 +00:00
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
const QString key = QInputDialog::getText( this,
|
2011-01-20 20:12:24 +00:00
|
|
|
tr( "Open URL or Magnet Link" ),
|
|
|
|
tr( "Open URL or Magnet Link" ),
|
2009-12-03 17:23:53 +00:00
|
|
|
QLineEdit::Normal,
|
2010-04-27 03:10:32 +00:00
|
|
|
url,
|
2009-12-03 17:23:53 +00:00
|
|
|
&ok );
|
|
|
|
if( ok && !key.isEmpty( ) )
|
|
|
|
mySession.addTorrent( key );
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: addTorrents( const QStringList& filenames )
|
|
|
|
{
|
|
|
|
foreach( const QString& filename, filenames )
|
|
|
|
addTorrent( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: addTorrent( const QString& filename )
|
|
|
|
{
|
|
|
|
if( !myFileDialogOptionsCheck->isChecked( ) ) {
|
|
|
|
mySession.addTorrent( filename );
|
|
|
|
QApplication :: alert ( this );
|
|
|
|
} else {
|
|
|
|
Options * o = new Options( mySession, myPrefs, filename, this );
|
|
|
|
o->show( );
|
|
|
|
QApplication :: alert( o );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-23 03:58:42 +00:00
|
|
|
void
|
|
|
|
TrMainWindow :: removeTorrents( const bool deleteFiles )
|
|
|
|
{
|
|
|
|
QSet<int> ids;
|
2010-06-18 04:22:39 +00:00
|
|
|
QMessageBox msgBox( this );
|
2010-04-23 03:58:42 +00:00
|
|
|
QString primary_text, secondary_text;
|
|
|
|
int incomplete = 0;
|
|
|
|
int connected = 0;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ) )
|
|
|
|
{
|
2010-07-30 22:31:31 +00:00
|
|
|
const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>( ) );
|
2010-04-23 03:58:42 +00:00
|
|
|
ids.insert( tor->id( ) );
|
|
|
|
if( tor->connectedPeers( ) )
|
|
|
|
++connected;
|
|
|
|
if( !tor->isDone( ) )
|
|
|
|
++incomplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ids.isEmpty() )
|
|
|
|
return;
|
|
|
|
count = ids.size();
|
|
|
|
|
|
|
|
if( !deleteFiles )
|
|
|
|
{
|
|
|
|
primary_text = ( count == 1 )
|
|
|
|
? tr( "Remove torrent?" )
|
|
|
|
: tr( "Remove %1 torrents?" ).arg( count );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
primary_text = ( count == 1 )
|
|
|
|
? tr( "Delete this torrent's downloaded files?" )
|
|
|
|
: tr( "Delete these %1 torrents' downloaded files?" ).arg( count );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !incomplete && !connected )
|
|
|
|
{
|
|
|
|
secondary_text = ( count == 1 )
|
|
|
|
? tr( "Once removed, continuing the transfer will require the torrent file or magnet link." )
|
|
|
|
: tr( "Once removed, continuing the transfers will require the torrent files or magnet links." );
|
|
|
|
}
|
|
|
|
else if( count == incomplete )
|
|
|
|
{
|
|
|
|
secondary_text = ( count == 1 )
|
|
|
|
? tr( "This torrent has not finished downloading." )
|
|
|
|
: tr( "These torrents have not finished downloading." );
|
|
|
|
}
|
|
|
|
else if( count == connected )
|
|
|
|
{
|
|
|
|
secondary_text = ( count == 1 )
|
|
|
|
? tr( "This torrent is connected to peers." )
|
|
|
|
: tr( "These torrents are connected to peers." );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( connected )
|
|
|
|
{
|
|
|
|
secondary_text = ( connected == 1 )
|
|
|
|
? tr( "One of these torrents is connected to peers." )
|
|
|
|
: tr( "Some of these torrents are connected to peers." );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connected && incomplete )
|
|
|
|
{
|
|
|
|
secondary_text += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if( incomplete )
|
|
|
|
{
|
|
|
|
secondary_text += ( incomplete == 1 )
|
|
|
|
? tr( "One of these torrents has not finished downloading." )
|
|
|
|
: tr( "Some of these torrents have not finished downloading." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-18 04:22:39 +00:00
|
|
|
msgBox.setWindowTitle( QString(" ") );
|
|
|
|
msgBox.setText( QString( "<big><b>%1</big></b>" ).arg( primary_text ) );
|
|
|
|
msgBox.setInformativeText( secondary_text );
|
|
|
|
msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
|
|
|
|
msgBox.setDefaultButton( QMessageBox::Cancel );
|
|
|
|
msgBox.setIcon( QMessageBox::Question );
|
2010-04-23 03:58:42 +00:00
|
|
|
/* hack needed to keep the dialog from being too narrow */
|
2010-06-18 04:22:39 +00:00
|
|
|
QGridLayout* layout = (QGridLayout*)msgBox.layout();
|
2010-04-23 03:58:42 +00:00
|
|
|
QSpacerItem* spacer = new QSpacerItem( 450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
|
|
|
|
layout->addItem( spacer, layout->rowCount(), 0, 1, layout->columnCount() );
|
|
|
|
|
2010-06-18 04:22:39 +00:00
|
|
|
if( msgBox.exec() == QMessageBox::Ok )
|
2010-06-16 03:01:09 +00:00
|
|
|
{
|
|
|
|
ui.listView->selectionModel()->clear();
|
2010-04-23 03:58:42 +00:00
|
|
|
mySession.removeTorrents( ids, deleteFiles );
|
2010-06-16 03:01:09 +00:00
|
|
|
}
|
2010-04-23 03:58:42 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: updateNetworkIcon( )
|
|
|
|
{
|
|
|
|
const time_t now = time( NULL );
|
|
|
|
const int period = 3;
|
|
|
|
const bool isSending = now - myLastSendTime <= period;
|
|
|
|
const bool isReading = now - myLastReadTime <= period;
|
|
|
|
const char * key;
|
|
|
|
|
|
|
|
if( isSending && isReading )
|
|
|
|
key = "network-transmit-receive";
|
|
|
|
else if( isSending )
|
|
|
|
key = "network-transmit";
|
|
|
|
else if( isReading )
|
|
|
|
key = "network-receive";
|
|
|
|
else
|
|
|
|
key = "network-idle";
|
|
|
|
|
|
|
|
QIcon icon = getStockIcon( key, QStyle::SP_DriveNetIcon );
|
|
|
|
QPixmap pixmap = icon.pixmap ( 16, 16 );
|
2009-04-15 01:59:54 +00:00
|
|
|
myNetworkLabel->setPixmap( pixmap );
|
|
|
|
myNetworkLabel->setToolTip( isSending || isReading
|
2009-04-09 18:55:47 +00:00
|
|
|
? tr( "Transmission server is responding" )
|
2010-07-03 01:10:36 +00:00
|
|
|
: tr( "Last response from server was %1 ago" ).arg( Formatter::timeToString( now-std::max(myLastReadTime,myLastSendTime))));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: onNetworkTimer( )
|
|
|
|
{
|
|
|
|
updateNetworkIcon( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: dataReadProgress( )
|
|
|
|
{
|
|
|
|
myLastReadTime = time( NULL );
|
|
|
|
updateNetworkIcon( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: dataSendProgress( )
|
|
|
|
{
|
|
|
|
myLastSendTime = time( NULL );
|
|
|
|
updateNetworkIcon( );
|
|
|
|
}
|
2009-05-03 22:00:56 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: wrongAuthentication( )
|
|
|
|
{
|
|
|
|
mySession.stop( );
|
|
|
|
mySessionDialog->show( );
|
|
|
|
}
|
2010-07-31 23:11:05 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: dragEnterEvent( QDragEnterEvent * event )
|
|
|
|
{
|
|
|
|
const QMimeData * mime = event->mimeData( );
|
|
|
|
|
|
|
|
if( mime->hasFormat("application/x-bittorrent")
|
|
|
|
|| mime->text().trimmed().endsWith(".torrent", Qt::CaseInsensitive) )
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: dropEvent( QDropEvent * event )
|
|
|
|
{
|
|
|
|
QString key = event->mimeData()->text().trimmed();
|
|
|
|
|
|
|
|
const QUrl url( key );
|
|
|
|
if( url.scheme() == "file" )
|
|
|
|
key = QUrl::fromPercentEncoding( url.path().toUtf8( ) );
|
|
|
|
|
|
|
|
dynamic_cast<MyApp*>(QApplication::instance())->addTorrent( key );
|
|
|
|
}
|
2011-08-01 22:24:24 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
|
|
|
TrMainWindow :: contextMenuEvent( QContextMenuEvent * event )
|
|
|
|
{
|
|
|
|
QMenu * menu = new QMenu( this );
|
|
|
|
|
|
|
|
menu->addAction( ui.action_Properties );
|
|
|
|
menu->addAction( ui.action_OpenFolder );
|
|
|
|
|
|
|
|
QAction * sep = new QAction( this );
|
|
|
|
sep->setSeparator( true );
|
|
|
|
menu->addAction( sep );
|
|
|
|
menu->addAction( ui.action_Start );
|
|
|
|
menu->addAction( ui.action_StartNow );
|
|
|
|
menu->addAction( ui.action_Announce );
|
|
|
|
QMenu * queueMenu = menu->addMenu( tr( "Queue" ) );
|
|
|
|
queueMenu->addAction( ui.action_QueueMoveTop );
|
|
|
|
queueMenu->addAction( ui.action_QueueMoveUp );
|
|
|
|
queueMenu->addAction( ui.action_QueueMoveDown );
|
|
|
|
queueMenu->addAction( ui.action_QueueMoveBottom );
|
|
|
|
menu->addAction( ui.action_Pause );
|
|
|
|
|
|
|
|
sep = new QAction( this );
|
|
|
|
sep->setSeparator( true );
|
|
|
|
menu->addAction( sep );
|
|
|
|
menu->addAction( ui.action_Verify );
|
|
|
|
menu->addAction( ui.action_SetLocation );
|
|
|
|
menu->addAction( ui.action_CopyMagnetToClipboard );
|
|
|
|
|
|
|
|
sep = new QAction( this );
|
|
|
|
sep->setSeparator( true );
|
|
|
|
menu->addAction( sep );
|
|
|
|
menu->addAction( ui.action_Remove );
|
|
|
|
menu->addAction( ui.action_Delete );
|
|
|
|
|
|
|
|
menu->popup( event->globalPos( ) );
|
|
|
|
}
|