From 86fd8546575205bdc117fa1b21d63877e8fcfd0e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 14 Apr 2009 22:05:11 +0000 Subject: [PATCH] (trunk qt) #1522: add upload/download/ratio limits popup menu at the bottom of the main window --- qt/application.qrc | 1 + qt/mainwin.cc | 140 ++++++++- qt/mainwin.h | 38 ++- qt/mainwin.ui | 729 ++++++++++++++++++++++++--------------------- qt/session.cc | 2 + 5 files changed, 561 insertions(+), 349 deletions(-) diff --git a/qt/application.qrc b/qt/application.qrc index 5d67b7830..35dbb02bc 100644 --- a/qt/application.qrc +++ b/qt/application.qrc @@ -9,5 +9,6 @@ icons/turtle-blue.png icons/lock.png icons/dance.gif + icons/info-options.png diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 90b971ea6..35174cdd7 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -275,9 +275,12 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode myTrayIcon.setContextMenu( menu ); myTrayIcon.setIcon( QApplication::windowIcon( ) ); - connect( ui.action_ShowMainWindow, SIGNAL(toggled(bool)), this, SLOT(toggleWindows())); - connect( &myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); + ui.optionsButton->setMenu( createOptionsMenu( ) ); + connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)) ); + connect( ui.action_ShowMainWindow, SIGNAL(toggled(bool)), this, SLOT(toggleWindows())); + connect( &myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); ui.action_ShowMainWindow->setChecked( !minimized ); ui.action_TrayIcon->setChecked( minimized || prefs.getBool( Prefs::SHOW_TRAY_ICON ) ); @@ -293,7 +296,13 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode << Prefs :: STATUSBAR_STATS << Prefs :: TOOLBAR << Prefs :: ALT_SPEED_LIMIT_ENABLED - << Prefs :: MINIMAL_VIEW; + << Prefs :: MINIMAL_VIEW + << Prefs :: DSPEED + << Prefs :: DSPEED_ENABLED + << Prefs :: USPEED + << Prefs :: USPEED_ENABLED + << Prefs :: RATIO + << Prefs :: RATIO_ENABLED; foreach( int key, initKeys ) refreshPref( key ); @@ -321,6 +330,107 @@ TrMainWindow :: ~TrMainWindow( ) ***** ****/ +#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 stockSpeeds; + stockSpeeds << 5 << 10 << 20 << 30 << 40 << 50 << 75 << 100 << 150 << 200 << 250 << 500 << 750; + QList 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( 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)) ); + a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( currentVal ) ) ) ); + 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 ) { + a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) ); + a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true ); + connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); + } + + sub = menu->addMenu( tr( "Limit Upload Speed" ) ); + currentVal = myPrefs.get( 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)) ); + a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( currentVal ) ) ) ); + 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 ) { + a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) ); + a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true ); + connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); + } + + menu->addSeparator( ); + sub = menu->addMenu( tr( "Stop Seeding at Ratio" ) ); + + double d = myPrefs.get( 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)) ); + a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Utils::ratioToString( d ) ) ); + 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 ) { + a = sub->addAction( Utils::ratioToString( i ) ); + a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true ); + connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); + } + + return menu; +} + +/**** +***** +****/ + void TrMainWindow :: setSortPref( int i ) { @@ -642,6 +752,30 @@ TrMainWindow :: refreshPref( int key ) ui.action_SortByTracker->setChecked ( i == SortMode::SORT_BY_TRACKER ); break; + case Prefs::DSPEED_ENABLED: + (myPrefs.get(key) ? myDlimitOnAction : myDlimitOffAction)->setChecked( true ); + break; + + case Prefs::DSPEED: + myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( myPrefs.get(key) ) ) ) ); + break; + + case Prefs::USPEED_ENABLED: + (myPrefs.get(key) ? myUlimitOnAction : myUlimitOffAction)->setChecked( true ); + break; + + case Prefs::USPEED: + myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( myPrefs.get(key) ) ) ) ); + break; + + case Prefs::RATIO_ENABLED: + (myPrefs.get(key) ? myRatioOnAction : myRatioOffAction)->setChecked( true ); + break; + + case Prefs::RATIO: + myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Utils::ratioToString( myPrefs.get(key) ) ) ); + break; + case Prefs::FILTER_MODE: i = myPrefs.get(key).mode( ); ui.filterAll->setChecked ( i == FilterMode::SHOW_ALL ); diff --git a/qt/mainwin.h b/qt/mainwin.h index 03f7616f7..8c8565a47 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -36,6 +36,8 @@ class Session; class TorrentDelegate; class TorrentDelegateMin; class TorrentModel; +class QAction; +class QMenu; class QModelIndex; class QSortFilterProxyModel; @@ -63,6 +65,12 @@ class TrMainWindow: public QMainWindow time_t myLastSendTime; time_t myLastReadTime; QTimer myNetworkTimer; + QAction * myDlimitOffAction; + QAction * myDlimitOnAction; + QAction * myUlimitOffAction; + QAction * myUlimitOnAction; + QAction * myRatioOffAction; + QAction * myRatioOnAction; private: QIcon getStockIcon( const QString&, int fallback=-1 ); @@ -100,22 +108,26 @@ class TrMainWindow: public QMainWindow void dataReadProgress( ); void dataSendProgress( ); void toggleWindows( ); + void onSetPrefs( ); + void onSetPrefs( bool ); - private slots: - void setSortPref( int ); - void setSortAscendingPref( bool ); - void onSortByActivityToggled ( bool b ); - void onSortByAgeToggled ( bool b ); - void onSortByETAToggled ( bool b ); - void onSortByNameToggled ( bool b ); - void onSortByProgressToggled ( bool b ); - void onSortByRatioToggled ( bool b ); - void onSortBySizeToggled ( bool b ); - void onSortByStateToggled ( bool b ); - void onSortByTrackerToggled ( bool b ); + private slots: + void setSortPref ( int ); + void setSortAscendingPref ( bool ); + void onSortByActivityToggled ( bool ); + void onSortByAgeToggled ( bool ); + void onSortByETAToggled ( bool ); + void onSortByNameToggled ( bool ); + void onSortByProgressToggled ( bool ); + void onSortByRatioToggled ( bool ); + void onSortBySizeToggled ( bool ); + void onSortByStateToggled ( bool ); + void onSortByTrackerToggled ( bool ); + private: + QMenu* createOptionsMenu( void ); - public slots: + public slots: void startAll( ); void startSelected( ); void pauseAll( ); diff --git a/qt/mainwin.ui b/qt/mainwin.ui index 1cdfbd9e5..c7489d87a 100644 --- a/qt/mainwin.ui +++ b/qt/mainwin.ui @@ -1,157 +1,158 @@ - + + MainWindow - - + + 0 0 792 - 393 + 390 - + Transmission - - - + + + 0 - + 0 - - - + + + 0 0 - - + + 3 - + QLayout::SetDefaultConstraint - + 2 - - + + Show all torrents - + A&ll - + true - + true - - - + + + 0 0 - + Show active torrents - + &Active - + true - + true - - - + + + 0 0 - + 0 0 - + Show torrents being downloaded - + &Downloading - + true - + true - - - + + + 0 0 - + Show torrents being seeded - + &Seeding - + true - + true - - - + + + 0 0 - + Show paused torrents - + &Paused - + true - + true - - - + + + 1 0 @@ -159,46 +160,46 @@ - - - + + + 0 0 - + Set text filter mode - + - + true - - - + + + 3 0 - + Show torrents matching this text - - + + Clear the filter text - + - + true @@ -216,74 +217,104 @@ - - - + + + 0 0 - + Qt::ScrollBarAlwaysOff - + true - + QAbstractItemView::ExtendedSelection - + false - - - + + + 0 0 - - + + 3 - + 3 - - + + + + 0 + 0 + + + + + 30 + 24 + + + + + 24 + 50 + + + true - - + + + + 0 + 0 + + + - 16 - 16 + 30 + 28 - - + + + 1000 + 1000 + - - Qt::PlainText + + Options + + + true - - + + Qt::Horizontal - + QSizePolicy::Expanding - + 1 1 @@ -292,21 +323,21 @@ - - + + TextLabel - - + + Qt::Horizontal - + QSizePolicy::Expanding - + 1 1 @@ -315,37 +346,37 @@ - - + + - + 16 16 - + true - - + + TextLabel - - + + Qt::Horizontal - + QSizePolicy::Fixed - + 20 0 @@ -354,31 +385,31 @@ - - + + TextLabel - - + + Overall download speed - + TextLabel - - + + Qt::Horizontal - + QSizePolicy::Fixed - + 20 0 @@ -387,22 +418,54 @@ - - + + TextLabel - - + + Overall upload speed - + TextLabel + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 0 + + + + + + + + + 16 + 16 + + + + + + + Qt::PlainText + + + @@ -411,8 +474,8 @@ statusbar filterbar - - + + 0 0 @@ -420,475 +483,475 @@ 25 - - + + 0 0 - - + + &Torrent - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + &Edit - - - - + + + + - - + + &Help - - - - - + + + + + - - + + &View - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + - - + + toolBar - + false - + Qt::TopToolBarArea - + 24 24 - + Qt::ToolButtonTextUnderIcon - + false - + TopToolBarArea - + false - - - - - - + + + + + + - - + + &Add... - + Add a torrent - + Ctrl+D - - + + &New... - + Create a new torrent - + Ctrl+N - - + + &Properties - + Show torrent properties - + Alt+Enter - - + + &Open Folder - + Open the torrent's folder - + Ctrl+O - - + + &Start - + Start torrent - + Ctrl+S - - + + Ask Tracker for &More Peers - + Ask tracker for more peers - - + + &Pause - + Pause torrent - + Ctrl+P - - + + &Verify Local Data - + Verify local data - - + + &Remove - + Remove torrent - + Del - - + + &Delete Files and Remove - + Remove torrent and delete its files - + Shift+Del - - + + &Start All - - + + &Pause All - - + + &Quit - + Ctrl+Q - - + + &Select All - + Ctrl+A - - + + &Deselect All - + Ctrl+Shift+A - - + + &Preferences - - + + true - + &Minimal View - + Alt+M - - + + true - + &Toolbar - - + + true - + &Filterbar - - + + true - + &Statusbar - - + + true - + Sort by &Activity - - + + true - + Sort by A&ge - - + + true - + Sort by &ETA - - + + true - + Sort by &Name - - + + true - + Sort by &Progress - - + + true - + Sort by &Ratio - - + + true - + Sort by Si&ze - - + + true - + Sort by &State - - + + true - + Sort by &Tracker - - + + false - + Message &Log - - + + false - + &Statistics - - + + &Contents - - + + &About - - + + true - + &Reverse Sort Order - - + + true - + &Name - - + + true - + &Files - - + + true - + &Tracker - - + + true - + Total Ratio - - + + true - + Session Ratio - - + + true - + Total Transfer - - + + true - + Session Transfer - - + + true - + &Main Window - - + + true - + Tray &Icon - + diff --git a/qt/session.cc b/qt/session.cc index 300cef24e..eead9d2b6 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -131,6 +131,8 @@ Session :: updatePref( int key ) case Prefs :: PORT_FORWARDING: case Prefs :: PEER_PORT: case Prefs :: PEER_PORT_RANDOM_ON_START: + case Prefs :: RATIO: + case Prefs :: RATIO_ENABLED: sessionSet( myPrefs.keyStr(key), myPrefs.variant(key) ); break;