Changeset 13886
- Timestamp:
- Jan 27, 2013, 6:09:49 PM (8 years ago)
- Location:
- trunk/qt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/mainwin.cc
r13883 r13886 55 55 class ListViewProxyStyle: public QProxyStyle 56 56 { 57 public: 58 int styleHint(StyleHint hint, 59 const QStyleOption *option = 0, 60 const QWidget *widget = 0, 61 QStyleHintReturn *returnData = 0) const 62 { 63 if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick) 64 return 0; 65 return QProxyStyle::styleHint(hint, option, widget, returnData); 66 } 57 public: 58 59 int styleHint (StyleHint hint, 60 const QStyleOption * option = 0, 61 const QWidget * widget = 0, 62 QStyleHintReturn * returnData = 0) const 63 { 64 if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick) 65 return 0; 66 return QProxyStyle::styleHint (hint, option, widget, returnData); 67 } 67 68 }; 68 69 69 70 70 71 QIcon 71 TrMainWindow :: getStockIcon ( const QString& name, int fallback)72 { 73 QIcon icon = QIcon::fromTheme( name);74 75 if( icon.isNull( ) && ( fallback >= 0 ))76 icon = style()->standardIcon( QStyle::StandardPixmap( fallback ), 0, this);77 78 72 TrMainWindow :: getStockIcon (const QString& name, int fallback) 73 { 74 QIcon icon = QIcon::fromTheme (name); 75 76 if (icon.isNull () && (fallback >= 0)) 77 icon = style ()->standardIcon (QStyle::StandardPixmap (fallback), 0, this); 78 79 return icon; 79 80 } 80 81 81 82 namespace 82 83 { 83 QSize calculateTextButtonSizeHint( QPushButton * button ) 84 { 85 QStyleOptionButton opt; 86 opt.initFrom( button ); 87 QString s( button->text( ) ); 88 if( s.isEmpty( ) ) 89 s = QString::fromLatin1( "XXXX" ); 90 QFontMetrics fm = button->fontMetrics( ); 91 QSize sz = fm.size( Qt::TextShowMnemonic, s ); 92 return button->style()->sizeFromContents( QStyle::CT_PushButton, &opt, sz, button ).expandedTo( QApplication::globalStrut( ) ); 93 } 94 } 95 96 97 TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& model, bool minimized ): 98 myLastFullUpdateTime( 0 ), 99 mySessionDialog( new SessionDialog( session, prefs, this ) ), 100 myPrefsDialog( 0 ), 101 myAboutDialog( new AboutDialog( this ) ), 102 myStatsDialog( new StatsDialog( session, this ) ), 103 myDetailsDialog( 0 ), 104 myFilterModel( prefs ), 105 myTorrentDelegate( new TorrentDelegate( this ) ), 106 myTorrentDelegateMin( new TorrentDelegateMin( this ) ), 107 mySession( session ), 108 myPrefs( prefs ), 109 myModel( model ), 110 mySpeedModeOffIcon( ":/icons/alt-limit-off.png" ), 111 mySpeedModeOnIcon( ":/icons/alt-limit-on.png" ), 112 myLastSendTime( 0 ), 113 myLastReadTime( 0 ), 114 myNetworkTimer( this ), 115 myRefreshTrayIconTimer( this ), 116 myRefreshActionSensitivityTimer( this ) 117 { 118 setAcceptDrops( true ); 119 120 QAction * sep = new QAction( this ); 121 sep->setSeparator( true ); 122 123 ui.setupUi( this ); 124 125 QStyle * style = this->style(); 126 127 int i = style->pixelMetric( QStyle::PM_SmallIconSize, 0, this ); 128 const QSize smallIconSize( i, i ); 129 130 ui.listView->setStyle(new ListViewProxyStyle); 131 132 // icons 133 ui.action_OpenFile->setIcon( getStockIcon( "folder-open", QStyle::SP_DialogOpenButton ) ); 134 ui.action_New->setIcon( getStockIcon( "document-new", QStyle::SP_DesktopIcon ) ); 135 ui.action_Properties->setIcon( getStockIcon( "document-properties", QStyle::SP_DesktopIcon ) ); 136 ui.action_OpenFolder->setIcon( getStockIcon( "folder-open", QStyle::SP_DirOpenIcon ) ); 137 ui.action_Start->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) ); 138 ui.action_StartNow->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) ); 139 ui.action_Announce->setIcon( getStockIcon( "network-transmit-receive" ) ); 140 ui.action_Pause->setIcon( getStockIcon( "media-playback-pause", QStyle::SP_MediaPause ) ); 141 ui.action_Remove->setIcon( getStockIcon( "list-remove", QStyle::SP_TrashIcon ) ); 142 ui.action_Delete->setIcon( getStockIcon( "edit-delete", QStyle::SP_TrashIcon ) ); 143 ui.action_StartAll->setIcon( getStockIcon( "media-playback-start", QStyle::SP_MediaPlay ) ); 144 ui.action_PauseAll->setIcon( getStockIcon( "media-playback-pause", QStyle::SP_MediaPause ) ); 145 ui.action_Quit->setIcon( getStockIcon( "application-exit" ) ); 146 ui.action_SelectAll->setIcon( getStockIcon( "edit-select-all" ) ); 147 ui.action_ReverseSortOrder->setIcon( getStockIcon( "view-sort-ascending", QStyle::SP_ArrowDown ) ); 148 ui.action_Preferences->setIcon( getStockIcon( "preferences-system" ) ); 149 ui.action_Contents->setIcon( getStockIcon( "help-contents", QStyle::SP_DialogHelpButton ) ); 150 ui.action_About->setIcon( getStockIcon( "help-about" ) ); 151 ui.action_QueueMoveTop->setIcon( getStockIcon( "go-top" ) ); 152 ui.action_QueueMoveUp->setIcon( getStockIcon( "go-up", QStyle::SP_ArrowUp ) ); 153 ui.action_QueueMoveDown->setIcon( getStockIcon( "go-down", QStyle::SP_ArrowDown ) ); 154 ui.action_QueueMoveBottom->setIcon( getStockIcon( "go-bottom" ) ); 155 156 // ui signals 157 connect( ui.action_Toolbar, SIGNAL(toggled(bool)), this, SLOT(setToolbarVisible(bool))); 158 connect( ui.action_Filterbar, SIGNAL(toggled(bool)), this, SLOT(setFilterbarVisible(bool))); 159 connect( ui.action_Statusbar, SIGNAL(toggled(bool)), this, SLOT(setStatusbarVisible(bool))); 160 connect( ui.action_CompactView, SIGNAL(toggled(bool)), this, SLOT(setCompactView(bool))); 161 connect( ui.action_SortByActivity, SIGNAL(toggled(bool)), this, SLOT(onSortByActivityToggled(bool))); 162 connect( ui.action_SortByAge, SIGNAL(toggled(bool)), this, SLOT(onSortByAgeToggled(bool))); 163 connect( ui.action_SortByETA, SIGNAL(toggled(bool)), this, SLOT(onSortByETAToggled(bool))); 164 connect( ui.action_SortByName, SIGNAL(toggled(bool)), this, SLOT(onSortByNameToggled(bool))); 165 connect( ui.action_SortByProgress, SIGNAL(toggled(bool)), this, SLOT(onSortByProgressToggled(bool))); 166 connect( ui.action_SortByQueue, SIGNAL(toggled(bool)), this, SLOT(onSortByQueueToggled(bool))); 167 connect( ui.action_SortByRatio, SIGNAL(toggled(bool)), this, SLOT(onSortByRatioToggled(bool))); 168 connect( ui.action_SortBySize, SIGNAL(toggled(bool)), this, SLOT(onSortBySizeToggled(bool))); 169 connect( ui.action_SortByState, SIGNAL(toggled(bool)), this, SLOT(onSortByStateToggled(bool))); 170 connect( ui.action_ReverseSortOrder, SIGNAL(toggled(bool)), this, SLOT(setSortAscendingPref(bool))); 171 connect( ui.action_Start, SIGNAL(triggered()), this, SLOT(startSelected())); 172 connect( ui.action_QueueMoveTop, SIGNAL(triggered()), this, SLOT(queueMoveTop())); 173 connect( ui.action_QueueMoveUp, SIGNAL(triggered()), this, SLOT(queueMoveUp())); 174 connect( ui.action_QueueMoveDown, SIGNAL(triggered()), this, SLOT(queueMoveDown())); 175 connect( ui.action_QueueMoveBottom, SIGNAL(triggered()), this, SLOT(queueMoveBottom())); 176 connect( ui.action_StartNow, SIGNAL(triggered()), this, SLOT(startSelectedNow())); 177 connect( ui.action_Pause, SIGNAL(triggered()), this, SLOT(pauseSelected())); 178 connect( ui.action_Remove, SIGNAL(triggered()), this, SLOT(removeSelected())); 179 connect( ui.action_Delete, SIGNAL(triggered()), this, SLOT(deleteSelected())); 180 connect( ui.action_Verify, SIGNAL(triggered()), this, SLOT(verifySelected()) ); 181 connect( ui.action_Announce, SIGNAL(triggered()), this, SLOT(reannounceSelected()) ); 182 connect( ui.action_StartAll, SIGNAL(triggered()), this, SLOT(startAll())); 183 connect( ui.action_PauseAll, SIGNAL(triggered()), this, SLOT(pauseAll())); 184 connect( ui.action_OpenFile, SIGNAL(triggered()), this, SLOT(openTorrent())); 185 connect( ui.action_AddURL, SIGNAL(triggered()), this, SLOT(openURL())); 186 connect( ui.action_New, SIGNAL(triggered()), this, SLOT(newTorrent())); 187 connect( ui.action_Preferences, SIGNAL(triggered()), this, SLOT(openPreferences())); 188 connect( ui.action_Statistics, SIGNAL(triggered()), myStatsDialog, SLOT(show())); 189 connect( ui.action_Donate, SIGNAL(triggered()), this, SLOT(openDonate())); 190 connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show())); 191 connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp())); 192 connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder())); 193 connect( ui.action_CopyMagnetToClipboard, SIGNAL(triggered()), this, SLOT(copyMagnetLinkToClipboard())); 194 connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation())); 195 connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties())); 196 connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show())); 197 198 connect( ui.listView, SIGNAL(activated(const QModelIndex&)), ui.action_Properties, SLOT(trigger())); 199 200 // signals 201 connect( ui.action_SelectAll, SIGNAL(triggered()), ui.listView, SLOT(selectAll())); 202 connect( ui.action_DeselectAll, SIGNAL(triggered()), ui.listView, SLOT(clearSelection())); 203 204 connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); 205 connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshVisibleCount())); 206 connect( &myFilterModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon())); 207 connect( &myFilterModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(refreshActionSensitivitySoon())); 208 209 connect( ui.action_Quit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()) ); 210 211 // torrent view 212 myFilterModel.setSourceModel( &myModel ); 213 connect( &myModel, SIGNAL(modelReset()), this, SLOT(onModelReset())); 214 connect( &myModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(onModelReset())); 215 connect( &myModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(onModelReset())); 216 connect( &myModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(refreshTrayIconSoon())); 217 218 ui.listView->setModel( &myFilterModel ); 219 connect( ui.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(refreshActionSensitivitySoon())); 220 221 QActionGroup * actionGroup = new QActionGroup( this ); 222 actionGroup->addAction( ui.action_SortByActivity ); 223 actionGroup->addAction( ui.action_SortByAge ); 224 actionGroup->addAction( ui.action_SortByETA ); 225 actionGroup->addAction( ui.action_SortByName ); 226 actionGroup->addAction( ui.action_SortByProgress ); 227 actionGroup->addAction( ui.action_SortByQueue ); 228 actionGroup->addAction( ui.action_SortByRatio ); 229 actionGroup->addAction( ui.action_SortBySize ); 230 actionGroup->addAction( ui.action_SortByState ); 231 232 myAltSpeedAction = new QAction( tr( "Speed Limits" ), this ); 233 myAltSpeedAction->setIcon( myPrefs.get<bool>(Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon ); 234 connect( myAltSpeedAction, SIGNAL(triggered()), this, SLOT(toggleSpeedMode()) ); 235 236 QMenu * menu = new QMenu( ); 237 menu->addAction( ui.action_OpenFile ); 238 menu->addAction( ui.action_AddURL ); 239 menu->addSeparator( ); 240 menu->addAction( ui.action_ShowMainWindow ); 241 menu->addAction( ui.action_ShowMessageLog ); 242 menu->addAction( ui.action_About ); 243 menu->addSeparator( ); 244 menu->addAction( ui.action_StartAll ); 245 menu->addAction( ui.action_PauseAll ); 246 menu->addAction( myAltSpeedAction ); 247 menu->addSeparator( ); 248 menu->addAction( ui.action_Quit ); 249 myTrayIcon.setContextMenu( menu ); 250 myTrayIcon.setIcon( QApplication::windowIcon( ) ); 251 252 connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)) ); 253 connect( ui.action_ShowMainWindow, SIGNAL(triggered(bool)), this, SLOT(toggleWindows(bool))); 254 connect( &myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), 255 this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); 256 257 toggleWindows( !minimized ); 258 ui.action_TrayIcon->setChecked( minimized || prefs.getBool( Prefs::SHOW_TRAY_ICON ) ); 259 260 ui.verticalLayout->addWidget( createStatusBar( ) ); 261 ui.verticalLayout->insertWidget( 0, myFilterBar = new FilterBar( myPrefs, myModel, myFilterModel ) ); 262 263 QList<int> initKeys; 264 initKeys << Prefs :: MAIN_WINDOW_X 265 << Prefs :: SHOW_TRAY_ICON 266 << Prefs :: SORT_REVERSED 267 << Prefs :: SORT_MODE 268 << Prefs :: FILTERBAR 269 << Prefs :: STATUSBAR 270 << Prefs :: STATUSBAR_STATS 271 << Prefs :: TOOLBAR 272 << Prefs :: ALT_SPEED_LIMIT_ENABLED 273 << Prefs :: COMPACT_VIEW 274 << Prefs :: DSPEED 275 << Prefs :: DSPEED_ENABLED 276 << Prefs :: USPEED 277 << Prefs :: USPEED_ENABLED 278 << Prefs :: RATIO 279 << Prefs :: RATIO_ENABLED; 280 foreach( int key, initKeys ) 281 refreshPref( key ); 282 283 connect( &mySession, SIGNAL(sourceChanged()), this, SLOT(onSessionSourceChanged()) ); 284 connect( &mySession, SIGNAL(statsUpdated()), this, SLOT(refreshStatusBar()) ); 285 connect( &mySession, SIGNAL(sessionUpdated()), this, SLOT(refreshFreeSpace()) ); 286 connect( &mySession, SIGNAL(dataReadProgress()), this, SLOT(dataReadProgress()) ); 287 connect( &mySession, SIGNAL(dataSendProgress()), this, SLOT(dataSendProgress()) ); 288 connect( &mySession, SIGNAL(httpAuthenticationRequired()), this, SLOT(wrongAuthentication()) ); 289 290 if( mySession.isServer( ) ) 291 myNetworkLabel->hide( ); 292 else { 293 connect( &myNetworkTimer, SIGNAL(timeout()), this, SLOT(onNetworkTimer())); 294 myNetworkTimer.start( 1000 ); 295 } 296 297 connect( &myRefreshTrayIconTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIcon()) ); 298 connect( &myRefreshActionSensitivityTimer, SIGNAL(timeout()), this, SLOT(refreshActionSensitivity()) ); 299 300 301 refreshActionSensitivitySoon( ); 302 refreshTrayIconSoon( ); 303 refreshStatusBar( ); 304 refreshFreeSpace( ); 305 refreshTitle( ); 306 refreshVisibleCount( ); 307 } 308 309 TrMainWindow :: ~TrMainWindow( ) 84 QSize calculateTextButtonSizeHint (QPushButton * button) 85 { 86 QStyleOptionButton opt; 87 opt.initFrom (button); 88 QString s (button->text ()); 89 if (s.isEmpty ()) 90 s = QString::fromLatin1 ("XXXX"); 91 QFontMetrics fm = button->fontMetrics (); 92 QSize sz = fm.size (Qt::TextShowMnemonic, s); 93 return button->style ()->sizeFromContents (QStyle::CT_PushButton, &opt, sz, button).expandedTo (QApplication::globalStrut ()); 94 } 95 } 96 97 98 TrMainWindow :: TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, bool minimized): 99 myLastFullUpdateTime (0), 100 mySessionDialog (new SessionDialog (session, prefs, this)), 101 myPrefsDialog (0), 102 myAboutDialog (new AboutDialog (this)), 103 myStatsDialog (new StatsDialog (session, this)), 104 myDetailsDialog (0), 105 myFilterModel (prefs), 106 myTorrentDelegate (new TorrentDelegate (this)), 107 myTorrentDelegateMin (new TorrentDelegateMin (this)), 108 mySession (session), 109 myPrefs (prefs), 110 myModel (model), 111 mySpeedModeOffIcon (":/icons/alt-limit-off.png"), 112 mySpeedModeOnIcon (":/icons/alt-limit-on.png"), 113 myLastSendTime (0), 114 myLastReadTime (0), 115 myNetworkTimer (this), 116 myRefreshTrayIconTimer (this), 117 myRefreshActionSensitivityTimer (this) 118 { 119 setAcceptDrops (true); 120 121 QAction * sep = new QAction (this); 122 sep->setSeparator (true); 123 124 ui.setupUi (this); 125 126 QStyle * style = this->style (); 127 128 int i = style->pixelMetric (QStyle::PM_SmallIconSize, 0, this); 129 const QSize smallIconSize (i, i); 130 131 ui.listView->setStyle (new ListViewProxyStyle); 132 133 // icons 134 ui.action_OpenFile->setIcon (getStockIcon ("folder-open", QStyle::SP_DialogOpenButton)); 135 ui.action_New->setIcon (getStockIcon ("document-new", QStyle::SP_DesktopIcon)); 136 ui.action_Properties->setIcon (getStockIcon ("document-properties", QStyle::SP_DesktopIcon)); 137 ui.action_OpenFolder->setIcon (getStockIcon ("folder-open", QStyle::SP_DirOpenIcon)); 138 ui.action_Start->setIcon (getStockIcon ("media-playback-start", QStyle::SP_MediaPlay)); 139 ui.action_StartNow->setIcon (getStockIcon ("media-playback-start", QStyle::SP_MediaPlay)); 140 ui.action_Announce->setIcon (getStockIcon ("network-transmit-receive")); 141 ui.action_Pause->setIcon (getStockIcon ("media-playback-pause", QStyle::SP_MediaPause)); 142 ui.action_Remove->setIcon (getStockIcon ("list-remove", QStyle::SP_TrashIcon)); 143 ui.action_Delete->setIcon (getStockIcon ("edit-delete", QStyle::SP_TrashIcon)); 144 ui.action_StartAll->setIcon (getStockIcon ("media-playback-start", QStyle::SP_MediaPlay)); 145 ui.action_PauseAll->setIcon (getStockIcon ("media-playback-pause", QStyle::SP_MediaPause)); 146 ui.action_Quit->setIcon (getStockIcon ("application-exit")); 147 ui.action_SelectAll->setIcon (getStockIcon ("edit-select-all")); 148 ui.action_ReverseSortOrder->setIcon (getStockIcon ("view-sort-ascending", QStyle::SP_ArrowDown)); 149 ui.action_Preferences->setIcon (getStockIcon ("preferences-system")); 150 ui.action_Contents->setIcon (getStockIcon ("help-contents", QStyle::SP_DialogHelpButton)); 151 ui.action_About->setIcon (getStockIcon ("help-about")); 152 ui.action_QueueMoveTop->setIcon (getStockIcon ("go-top")); 153 ui.action_QueueMoveUp->setIcon (getStockIcon ("go-up", QStyle::SP_ArrowUp)); 154 ui.action_QueueMoveDown->setIcon (getStockIcon ("go-down", QStyle::SP_ArrowDown)); 155 ui.action_QueueMoveBottom->setIcon (getStockIcon ("go-bottom")); 156 157 // ui signals 158 connect (ui.action_Toolbar, SIGNAL (toggled (bool)), this, SLOT (setToolbarVisible (bool))); 159 connect (ui.action_Filterbar, SIGNAL (toggled (bool)), this, SLOT (setFilterbarVisible (bool))); 160 connect (ui.action_Statusbar, SIGNAL (toggled (bool)), this, SLOT (setStatusbarVisible (bool))); 161 connect (ui.action_CompactView, SIGNAL (toggled (bool)), this, SLOT (setCompactView (bool))); 162 connect (ui.action_SortByActivity, SIGNAL (toggled (bool)), this, SLOT (onSortByActivityToggled (bool))); 163 connect (ui.action_SortByAge, SIGNAL (toggled (bool)), this, SLOT (onSortByAgeToggled (bool))); 164 connect (ui.action_SortByETA, SIGNAL (toggled (bool)), this, SLOT (onSortByETAToggled (bool))); 165 connect (ui.action_SortByName, SIGNAL (toggled (bool)), this, SLOT (onSortByNameToggled (bool))); 166 connect (ui.action_SortByProgress, SIGNAL (toggled (bool)), this, SLOT (onSortByProgressToggled (bool))); 167 connect (ui.action_SortByQueue, SIGNAL (toggled (bool)), this, SLOT (onSortByQueueToggled (bool))); 168 connect (ui.action_SortByRatio, SIGNAL (toggled (bool)), this, SLOT (onSortByRatioToggled (bool))); 169 connect (ui.action_SortBySize, SIGNAL (toggled (bool)), this, SLOT (onSortBySizeToggled (bool))); 170 connect (ui.action_SortByState, SIGNAL (toggled (bool)), this, SLOT (onSortByStateToggled (bool))); 171 connect (ui.action_ReverseSortOrder, SIGNAL (toggled (bool)), this, SLOT (setSortAscendingPref (bool))); 172 connect (ui.action_Start, SIGNAL (triggered ()), this, SLOT (startSelected ())); 173 connect (ui.action_QueueMoveTop, SIGNAL (triggered ()), this, SLOT (queueMoveTop ())); 174 connect (ui.action_QueueMoveUp, SIGNAL (triggered ()), this, SLOT (queueMoveUp ())); 175 connect (ui.action_QueueMoveDown, SIGNAL (triggered ()), this, SLOT (queueMoveDown ())); 176 connect (ui.action_QueueMoveBottom, SIGNAL (triggered ()), this, SLOT (queueMoveBottom ())); 177 connect (ui.action_StartNow, SIGNAL (triggered ()), this, SLOT (startSelectedNow ())); 178 connect (ui.action_Pause, SIGNAL (triggered ()), this, SLOT (pauseSelected ())); 179 connect (ui.action_Remove, SIGNAL (triggered ()), this, SLOT (removeSelected ())); 180 connect (ui.action_Delete, SIGNAL (triggered ()), this, SLOT (deleteSelected ())); 181 connect (ui.action_Verify, SIGNAL (triggered ()), this, SLOT (verifySelected ())); 182 connect (ui.action_Announce, SIGNAL (triggered ()), this, SLOT (reannounceSelected ())); 183 connect (ui.action_StartAll, SIGNAL (triggered ()), this, SLOT (startAll ())); 184 connect (ui.action_PauseAll, SIGNAL (triggered ()), this, SLOT (pauseAll ())); 185 connect (ui.action_OpenFile, SIGNAL (triggered ()), this, SLOT (openTorrent ())); 186 connect (ui.action_AddURL, SIGNAL (triggered ()), this, SLOT (openURL ())); 187 connect (ui.action_New, SIGNAL (triggered ()), this, SLOT (newTorrent ())); 188 connect (ui.action_Preferences, SIGNAL (triggered ()), this, SLOT (openPreferences ())); 189 connect (ui.action_Statistics, SIGNAL (triggered ()), myStatsDialog, SLOT (show ())); 190 connect (ui.action_Donate, SIGNAL (triggered ()), this, SLOT (openDonate ())); 191 connect (ui.action_About, SIGNAL (triggered ()), myAboutDialog, SLOT (show ())); 192 connect (ui.action_Contents, SIGNAL (triggered ()), this, SLOT (openHelp ())); 193 connect (ui.action_OpenFolder, SIGNAL (triggered ()), this, SLOT (openFolder ())); 194 connect (ui.action_CopyMagnetToClipboard, SIGNAL (triggered ()), this, SLOT (copyMagnetLinkToClipboard ())); 195 connect (ui.action_SetLocation, SIGNAL (triggered ()), this, SLOT (setLocation ())); 196 connect (ui.action_Properties, SIGNAL (triggered ()), this, SLOT (openProperties ())); 197 connect (ui.action_SessionDialog, SIGNAL (triggered ()), mySessionDialog, SLOT (show ())); 198 199 connect (ui.listView, SIGNAL (activated (const QModelIndex&)), ui.action_Properties, SLOT (trigger ())); 200 201 // signals 202 connect (ui.action_SelectAll, SIGNAL (triggered ()), ui.listView, SLOT (selectAll ())); 203 connect (ui.action_DeselectAll, SIGNAL (triggered ()), ui.listView, SLOT (clearSelection ())); 204 205 connect (&myFilterModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshVisibleCount ())); 206 connect (&myFilterModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshVisibleCount ())); 207 connect (&myFilterModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (refreshActionSensitivitySoon ())); 208 connect (&myFilterModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (refreshActionSensitivitySoon ())); 209 210 connect (ui.action_Quit, SIGNAL (triggered ()), QCoreApplication::instance (), SLOT (quit ())); 211 212 // torrent view 213 myFilterModel.setSourceModel (&myModel); 214 connect (&myModel, SIGNAL (modelReset ()), this, SLOT (onModelReset ())); 215 connect (&myModel, SIGNAL (rowsRemoved (const QModelIndex&,int,int)), this, SLOT (onModelReset ())); 216 connect (&myModel, SIGNAL (rowsInserted (const QModelIndex&,int,int)), this, SLOT (onModelReset ())); 217 connect (&myModel, SIGNAL (dataChanged (const QModelIndex&,const QModelIndex&)), this, SLOT (refreshTrayIconSoon ())); 218 219 ui.listView->setModel (&myFilterModel); 220 connect (ui.listView->selectionModel (), SIGNAL (selectionChanged (const QItemSelection&,const QItemSelection&)), this, SLOT (refreshActionSensitivitySoon ())); 221 222 QActionGroup * actionGroup = new QActionGroup (this); 223 actionGroup->addAction (ui.action_SortByActivity); 224 actionGroup->addAction (ui.action_SortByAge); 225 actionGroup->addAction (ui.action_SortByETA); 226 actionGroup->addAction (ui.action_SortByName); 227 actionGroup->addAction (ui.action_SortByProgress); 228 actionGroup->addAction (ui.action_SortByQueue); 229 actionGroup->addAction (ui.action_SortByRatio); 230 actionGroup->addAction (ui.action_SortBySize); 231 actionGroup->addAction (ui.action_SortByState); 232 233 myAltSpeedAction = new QAction (tr ("Speed Limits"), this); 234 myAltSpeedAction->setIcon (myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon); 235 connect (myAltSpeedAction, SIGNAL (triggered ()), this, SLOT (toggleSpeedMode ())); 236 237 QMenu * menu = new QMenu (); 238 menu->addAction (ui.action_OpenFile); 239 menu->addAction (ui.action_AddURL); 240 menu->addSeparator (); 241 menu->addAction (ui.action_ShowMainWindow); 242 menu->addAction (ui.action_ShowMessageLog); 243 menu->addAction (ui.action_About); 244 menu->addSeparator (); 245 menu->addAction (ui.action_StartAll); 246 menu->addAction (ui.action_PauseAll); 247 menu->addAction (myAltSpeedAction); 248 menu->addSeparator (); 249 menu->addAction (ui.action_Quit); 250 myTrayIcon.setContextMenu (menu); 251 myTrayIcon.setIcon (QApplication::windowIcon ()); 252 253 connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int))); 254 connect (ui.action_ShowMainWindow, SIGNAL (triggered (bool)), this, SLOT (toggleWindows (bool))); 255 connect (&myTrayIcon, SIGNAL (activated (QSystemTrayIcon::ActivationReason)), 256 this, SLOT (trayActivated (QSystemTrayIcon::ActivationReason))); 257 258 toggleWindows (!minimized); 259 ui.action_TrayIcon->setChecked (minimized || prefs.getBool (Prefs::SHOW_TRAY_ICON)); 260 261 ui.verticalLayout->addWidget (createStatusBar ()); 262 ui.verticalLayout->insertWidget (0, myFilterBar = new FilterBar (myPrefs, myModel, myFilterModel)); 263 264 QList<int> initKeys; 265 initKeys << Prefs :: MAIN_WINDOW_X 266 << Prefs :: SHOW_TRAY_ICON 267 << Prefs :: SORT_REVERSED 268 << Prefs :: SORT_MODE 269 << Prefs :: FILTERBAR 270 << Prefs :: STATUSBAR 271 << Prefs :: STATUSBAR_STATS 272 << Prefs :: TOOLBAR 273 << Prefs :: ALT_SPEED_LIMIT_ENABLED 274 << Prefs :: COMPACT_VIEW 275 << Prefs :: DSPEED 276 << Prefs :: DSPEED_ENABLED 277 << Prefs :: USPEED 278 << Prefs :: USPEED_ENABLED 279 << Prefs :: RATIO 280 << Prefs :: RATIO_ENABLED; 281 foreach (int key, initKeys) 282 refreshPref (key); 283 284 connect (&mySession, SIGNAL (sourceChanged ()), this, SLOT (onSessionSourceChanged ())); 285 connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (refreshStatusBar ())); 286 connect (&mySession, SIGNAL (sessionUpdated ()), this, SLOT (refreshFreeSpace ())); 287 connect (&mySession, SIGNAL (dataReadProgress ()), this, SLOT (dataReadProgress ())); 288 connect (&mySession, SIGNAL (dataSendProgress ()), this, SLOT (dataSendProgress ())); 289 connect (&mySession, SIGNAL (httpAuthenticationRequired ()), this, SLOT (wrongAuthentication ())); 290 291 if (mySession.isServer ()) 292 { 293 myNetworkLabel->hide (); 294 } 295 else 296 { 297 connect (&myNetworkTimer, SIGNAL (timeout ()), this, SLOT (onNetworkTimer ())); 298 myNetworkTimer.start (1000); 299 } 300 301 connect (&myRefreshTrayIconTimer, SIGNAL (timeout ()), this, SLOT (refreshTrayIcon ())); 302 connect (&myRefreshActionSensitivityTimer, SIGNAL (timeout ()), this, SLOT (refreshActionSensitivity ())); 303 304 305 refreshActionSensitivitySoon (); 306 refreshTrayIconSoon (); 307 refreshStatusBar (); 308 refreshFreeSpace (); 309 refreshTitle (); 310 refreshVisibleCount (); 311 } 312 313 TrMainWindow :: ~TrMainWindow () 310 314 { 311 315 } … … 316 320 317 321 void 318 TrMainWindow :: onSessionSourceChanged ()319 { 320 myModel.clear();321 } 322 323 void 324 TrMainWindow :: onModelReset ()325 { 326 refreshTitle();327 refreshVisibleCount();328 refreshActionSensitivitySoon();329 refreshStatusBar();330 refreshTrayIconSoon();322 TrMainWindow :: onSessionSourceChanged () 323 { 324 myModel.clear (); 325 } 326 327 void 328 TrMainWindow :: onModelReset () 329 { 330 refreshTitle (); 331 refreshVisibleCount (); 332 refreshActionSensitivitySoon (); 333 refreshStatusBar (); 334 refreshTrayIconSoon (); 331 335 } 332 336 … … 338 342 339 343 void 340 TrMainWindow :: onSetPrefs ()341 { 342 const QVariantList p = sender()->property( PREF_VARIANTS_KEY ).toList();343 assert( ( p.size( ) % 2 ) == 0);344 for( int i=0, n=p.size(); i<n; i+=2)345 myPrefs.set( p[i].toInt(), p[i+1]);346 } 347 348 void 349 TrMainWindow :: onSetPrefs ( bool isChecked)350 { 351 if( isChecked)352 onSetPrefs();344 TrMainWindow :: onSetPrefs () 345 { 346 const QVariantList p = sender ()->property (PREF_VARIANTS_KEY).toList (); 347 assert ( (p.size () % 2) == 0); 348 for (int i=0, n=p.size (); i<n; i+=2) 349 myPrefs.set (p[i].toInt (), p[i+1]); 350 } 351 352 void 353 TrMainWindow :: onSetPrefs (bool isChecked) 354 { 355 if (isChecked) 356 onSetPrefs (); 353 357 } 354 358 … … 356 360 357 361 QWidget * 358 TrMainWindow :: createStatusBar( ) 359 { 360 QMenu * m; 361 QLabel * l; 362 QHBoxLayout * h; 363 QPushButton * p; 364 QActionGroup * a; 365 const int i = style( )->pixelMetric( QStyle::PM_SmallIconSize, 0, this ); 366 const QSize smallIconSize( i, i ); 367 368 QWidget * top = myStatusBar = new QWidget; 369 h = new QHBoxLayout( top ); 370 h->setContentsMargins( HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL ); 371 h->setSpacing( HIG::PAD_SMALL ); 372 373 p = myOptionsButton = new TrIconPushButton( this ); 374 p->setIcon( QIcon( ":/icons/utilities.png" ) ); 375 p->setIconSize( QPixmap( ":/icons/utilities.png" ).size() ); 376 p->setFlat( true ); 377 p->setMenu( createOptionsMenu( ) ); 378 h->addWidget( p ); 379 380 p = myAltSpeedButton = new QPushButton( this ); 381 p->setIcon( myPrefs.get<bool>(Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon ); 382 p->setIconSize( QPixmap( ":/icons/alt-limit-on.png" ).size() ); 383 p->setCheckable( true ); 384 p->setFixedWidth( p->height() ); 385 p->setFlat( true ); 386 h->addWidget( p ); 387 connect( p, SIGNAL(clicked()), this, SLOT(toggleSpeedMode())); 388 389 l = myNetworkLabel = new QLabel; 390 h->addWidget( l ); 391 392 h->addStretch( 1 ); 393 394 l = myVisibleCountLabel = new QLabel( this ); 395 h->addWidget( l ); 396 397 //h->addStretch( 1 ); 398 h->addSpacing ( HIG::PAD_BIG ); 399 400 l = myFreeSpaceTextLabel = new QLabel (this); 401 const int minimumFreeSpaceWidth = l->fontMetrics().width( Formatter::sizeToString(1024 * 1024)); 402 l->setMinimumWidth( minimumFreeSpaceWidth ); 403 h->addWidget( l ); 404 l = myFreeSpaceIconLabel = new QLabel (this); 405 l->setPixmap( getStockIcon( "drive-harddisk", QStyle::SP_DriveHDIcon ).pixmap( smallIconSize ) ); 406 h->addWidget( l ); 407 408 h->addStretch( 1 ); 409 410 l = myStatsLabel = new QLabel( this ); 411 h->addWidget( l ); 412 a = new QActionGroup( this ); 413 a->addAction( ui.action_TotalRatio ); 414 a->addAction( ui.action_TotalTransfer ); 415 a->addAction( ui.action_SessionRatio ); 416 a->addAction( ui.action_SessionTransfer ); 417 m = new QMenu( ); 418 m->addAction( ui.action_TotalRatio ); 419 m->addAction( ui.action_TotalTransfer ); 420 m->addAction( ui.action_SessionRatio ); 421 m->addAction( ui.action_SessionTransfer ); 422 connect( ui.action_TotalRatio, SIGNAL(triggered()), this, SLOT(showTotalRatio())); 423 connect( ui.action_TotalTransfer, SIGNAL(triggered()), this, SLOT(showTotalTransfer())); 424 connect( ui.action_SessionRatio, SIGNAL(triggered()), this, SLOT(showSessionRatio())); 425 connect( ui.action_SessionTransfer, SIGNAL(triggered()), this, SLOT(showSessionTransfer())); 426 p = myStatsModeButton = new TrIconPushButton( this ); 427 p->setIcon( QIcon( ":/icons/ratio.png" ) ); 428 p->setIconSize( QPixmap( ":/icons/ratio.png" ).size() ); 429 p->setFlat( true ); 430 p->setMenu( m ); 431 h->addWidget( p ); 432 433 //h->addStretch( 1 ); 434 h->addSpacing ( HIG::PAD ); 435 436 l = myDownloadSpeedLabel = new QLabel( this ); 437 const int minimumSpeedWidth = l->fontMetrics().width( Formatter::speedToString(Speed::fromKBps(999.99))); 438 l->setMinimumWidth( minimumSpeedWidth ); 439 l->setAlignment( Qt::AlignRight|Qt::AlignVCenter ); 440 h->addWidget( l ); 441 l = new QLabel( this ); 442 l->setPixmap( getStockIcon( "go-down", QStyle::SP_ArrowDown ).pixmap( smallIconSize ) ); 443 h->addWidget( l ); 444 445 h->addSpacing ( HIG::PAD ); 446 447 l = myUploadSpeedLabel = new QLabel; 448 l->setMinimumWidth( minimumSpeedWidth ); 449 l->setAlignment( Qt::AlignRight|Qt::AlignVCenter ); 450 h->addWidget( l ); 451 l = new QLabel; 452 l->setPixmap( getStockIcon( "go-up", QStyle::SP_ArrowUp ).pixmap( smallIconSize ) ); 453 h->addWidget( l ); 454 455 return top; 362 TrMainWindow :: createStatusBar () 363 { 364 QMenu * m; 365 QLabel * l; 366 QHBoxLayout * h; 367 QPushButton * p; 368 QActionGroup * a; 369 const int i = style ()->pixelMetric (QStyle::PM_SmallIconSize, 0, this); 370 const QSize smallIconSize (i, i); 371 372 QWidget * top = myStatusBar = new QWidget; 373 h = new QHBoxLayout (top); 374 h->setContentsMargins (HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL); 375 h->setSpacing (HIG::PAD_SMALL); 376 377 p = myOptionsButton = new TrIconPushButton (this); 378 p->setIcon (QIcon (":/icons/utilities.png")); 379 p->setIconSize (QPixmap (":/icons/utilities.png").size ()); 380 p->setFlat (true); 381 p->setMenu (createOptionsMenu ()); 382 h->addWidget (p); 383 384 p = myAltSpeedButton = new QPushButton (this); 385 p->setIcon (myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon); 386 p->setIconSize (QPixmap (":/icons/alt-limit-on.png").size ()); 387 p->setCheckable (true); 388 p->setFixedWidth (p->height ()); 389 p->setFlat (true); 390 h->addWidget (p); 391 connect (p, SIGNAL (clicked ()), this, SLOT (toggleSpeedMode ())); 392 393 l = myNetworkLabel = new QLabel; 394 h->addWidget (l); 395 396 h->addStretch (1); 397 398 l = myVisibleCountLabel = new QLabel (this); 399 h->addWidget (l); 400 401 h->addSpacing (HIG::PAD_BIG); 402 403 l = myFreeSpaceTextLabel = new QLabel (this); 404 const int minimumFreeSpaceWidth = l->fontMetrics ().width (Formatter::sizeToString (1024 * 1024)); 405 l->setMinimumWidth (minimumFreeSpaceWidth); 406 h->addWidget (l); 407 l = myFreeSpaceIconLabel = new QLabel (this); 408 l->setPixmap (getStockIcon ("drive-harddisk", QStyle::SP_DriveHDIcon).pixmap (smallIconSize)); 409 h->addWidget (l); 410 411 h->addStretch (1); 412 413 l = myStatsLabel = new QLabel (this); 414 h->addWidget (l); 415 a = new QActionGroup (this); 416 a->addAction (ui.action_TotalRatio); 417 a->addAction (ui.action_TotalTransfer); 418 a->addAction (ui.action_SessionRatio); 419 a->addAction (ui.action_SessionTransfer); 420 m = new QMenu (); 421 m->addAction (ui.action_TotalRatio); 422 m->addAction (ui.action_TotalTransfer); 423 m->addAction (ui.action_SessionRatio); 424 m->addAction (ui.action_SessionTransfer); 425 connect (ui.action_TotalRatio, SIGNAL (triggered ()), this, SLOT (showTotalRatio ())); 426 connect (ui.action_TotalTransfer, SIGNAL (triggered ()), this, SLOT (showTotalTransfer ())); 427 connect (ui.action_SessionRatio, SIGNAL (triggered ()), this, SLOT (showSessionRatio ())); 428 connect (ui.action_SessionTransfer, SIGNAL (triggered ()), this, SLOT (showSessionTransfer ())); 429 p = myStatsModeButton = new TrIconPushButton (this); 430 p->setIcon (QIcon (":/icons/ratio.png")); 431 p->setIconSize (QPixmap (":/icons/ratio.png").size ()); 432 p->setFlat (true); 433 p->setMenu (m); 434 h->addWidget (p); 435 436 h->addSpacing (HIG::PAD); 437 438 l = myDownloadSpeedLabel = new QLabel (this); 439 const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::speedToString (Speed::fromKBps (999.99))); 440 l->setMinimumWidth (minimumSpeedWidth); 441 l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); 442 h->addWidget (l); 443 l = new QLabel (this); 444 l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize)); 445 h->addWidget (l); 446 447 h->addSpacing (HIG::PAD); 448 449 l = myUploadSpeedLabel = new QLabel; 450 l->setMinimumWidth (minimumSpeedWidth); 451 l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); 452 h->addWidget (l); 453 l = new QLabel; 454 l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize)); 455 h->addWidget (l); 456 457 return top; 456 458 } 457 459 458 460 QMenu * 459 TrMainWindow :: createOptionsMenu( ) 460 { 461 QMenu * menu; 462 QMenu * sub; 463 QAction * a; 464 QActionGroup * g; 465 466 QList<int> stockSpeeds; 467 stockSpeeds << 5 << 10 << 20 << 30 << 40 << 50 << 75 << 100 << 150 << 200 << 250 << 500 << 750; 468 QList<double> stockRatios; 469 stockRatios << 0.25 << 0.50 << 0.75 << 1 << 1.5 << 2 << 3; 470 471 menu = new QMenu; 472 sub = menu->addMenu( tr( "Limit Download Speed" ) ); 473 int currentVal = myPrefs.get<int>( Prefs::DSPEED ); 474 g = new QActionGroup( this ); 475 a = myDlimitOffAction = sub->addAction( tr( "Unlimited" ) ); 476 a->setCheckable( true ); 477 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED_ENABLED << false ); 478 g->addAction( a ); 479 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 480 a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( currentVal ) ) ) ); 481 a->setCheckable( true ); 482 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << currentVal << Prefs::DSPEED_ENABLED << true ); 483 g->addAction( a ); 484 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 485 sub->addSeparator( ); 486 foreach( int i, stockSpeeds ) { 487 a = sub->addAction( Formatter::speedToString( Speed::fromKBps( i ) ) ); 488 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true ); 489 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); 490 } 491 492 sub = menu->addMenu( tr( "Limit Upload Speed" ) ); 493 currentVal = myPrefs.get<int>( Prefs::USPEED ); 494 g = new QActionGroup( this ); 495 a = myUlimitOffAction = sub->addAction( tr( "Unlimited" ) ); 496 a->setCheckable( true ); 497 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED_ENABLED << false ); 498 g->addAction( a ); 499 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 500 a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( currentVal ) ) ) ); 501 a->setCheckable( true ); 502 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << currentVal << Prefs::USPEED_ENABLED << true ); 503 g->addAction( a ); 504 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 505 sub->addSeparator( ); 506 foreach( int i, stockSpeeds ) { 507 a = sub->addAction( Formatter::speedToString( Speed::fromKBps( i ) ) ); 508 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true ); 509 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); 510 } 511 512 menu->addSeparator( ); 513 sub = menu->addMenu( tr( "Stop Seeding at Ratio" ) ); 514 515 double d = myPrefs.get<double>( Prefs::RATIO ); 516 g = new QActionGroup( this ); 517 a = myRatioOffAction = sub->addAction( tr( "Seed Forever" ) ); 518 a->setCheckable( true ); 519 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO_ENABLED << false ); 520 g->addAction( a ); 521 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 522 a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Formatter::ratioToString( d ) ) ); 523 a->setCheckable( true ); 524 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << d << Prefs::RATIO_ENABLED << true ); 525 g->addAction( a ); 526 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 527 sub->addSeparator( ); 528 foreach( double i, stockRatios ) { 529 a = sub->addAction( Formatter::ratioToString( i ) ); 530 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true ); 531 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); 532 } 533 534 return menu; 461 TrMainWindow :: createOptionsMenu () 462 { 463 QMenu * menu; 464 QMenu * sub; 465 QAction * a; 466 QActionGroup * g; 467 468 QList<int> stockSpeeds; 469 stockSpeeds << 5 << 10 << 20 << 30 << 40 << 50 << 75 << 100 << 150 << 200 << 250 << 500 << 750; 470 QList<double> stockRatios; 471 stockRatios << 0.25 << 0.50 << 0.75 << 1 << 1.5 << 2 << 3; 472 473 menu = new QMenu; 474 sub = menu->addMenu (tr ("Limit Download Speed")); 475 476 int currentVal = myPrefs.get<int> (Prefs::DSPEED); 477 g = new QActionGroup (this); 478 a = myDlimitOffAction = sub->addAction (tr ("Unlimited")); 479 a->setCheckable (true); 480 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::DSPEED_ENABLED << false); 481 g->addAction (a); 482 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); 483 a = myDlimitOnAction = sub->addAction (tr ("Limited at %1").arg (Formatter::speedToString (Speed::fromKBps (currentVal)))); 484 a->setCheckable (true); 485 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::DSPEED << currentVal << Prefs::DSPEED_ENABLED << true); 486 g->addAction (a); 487 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); 488 sub->addSeparator (); 489 foreach (int i, stockSpeeds) 490 { 491 a = sub->addAction (Formatter::speedToString (Speed::fromKBps (i))); 492 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true); 493 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs ())); 494 } 495 496 sub = menu->addMenu (tr ("Limit Upload Speed")); 497 498 currentVal = myPrefs.get<int> (Prefs::USPEED); 499 g = new QActionGroup (this); 500 a = myUlimitOffAction = sub->addAction (tr ("Unlimited")); 501 a->setCheckable (true); 502 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::USPEED_ENABLED << false); 503 g->addAction (a); 504 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); 505 a = myUlimitOnAction = sub->addAction (tr ("Limited at %1").arg (Formatter::speedToString (Speed::fromKBps (currentVal)))); 506 a->setCheckable (true); 507 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::USPEED << currentVal << Prefs::USPEED_ENABLED << true); 508 g->addAction (a); 509 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); 510 sub->addSeparator (); 511 foreach (int i, stockSpeeds) 512 { 513 a = sub->addAction (Formatter::speedToString (Speed::fromKBps (i))); 514 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true); 515 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs ())); 516 } 517 518 menu->addSeparator (); 519 sub = menu->addMenu (tr ("Stop Seeding at Ratio")); 520 521 double d = myPrefs.get<double> (Prefs::RATIO); 522 g = new QActionGroup (this); 523 a = myRatioOffAction = sub->addAction (tr ("Seed Forever")); 524 a->setCheckable (true); 525 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::RATIO_ENABLED << false); 526 g->addAction (a); 527 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); 528 a = myRatioOnAction = sub->addAction (tr ("Stop at Ratio (%1)").arg (Formatter::ratioToString (d))); 529 a->setCheckable (true); 530 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::RATIO << d << Prefs::RATIO_ENABLED << true); 531 g->addAction (a); 532 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); 533 sub->addSeparator (); 534 foreach (double i, stockRatios) 535 { 536 a = sub->addAction (Formatter::ratioToString (i)); 537 a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true); 538 connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs ())); 539 } 540 541 return menu; 535 542 } 536 543 … … 540 547 541 548 void 542 TrMainWindow :: setSortPref ( int i)543 { 544 myPrefs.set( Prefs::SORT_MODE, SortMode( i ));545 } 546 void TrMainWindow :: onSortByActivityToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ACTIVITY); }547 void TrMainWindow :: onSortByAgeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_AGE );}548 void TrMainWindow :: onSortByETAToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_ETA );}549 void TrMainWindow :: onSortByNameToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_NAME );}550 void TrMainWindow :: onSortByProgressToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_PROGRESS); }551 void TrMainWindow :: onSortByQueueToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_QUEUE );}552 void TrMainWindow :: onSortByRatioToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_RATIO );}553 void TrMainWindow :: onSortBySizeToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_SIZE );}554 void TrMainWindow :: onSortByStateToggled ( bool b ) { if( b ) setSortPref( SortMode::SORT_BY_STATE );}555 556 void 557 TrMainWindow :: setSortAscendingPref ( bool b)558 { 559 myPrefs.set( Prefs::SORT_REVERSED, b);549 TrMainWindow :: setSortPref (int i) 550 { 551 myPrefs.set (Prefs::SORT_MODE, SortMode (i)); 552 } 553 void TrMainWindow :: onSortByActivityToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_ACTIVITY); } 554 void TrMainWindow :: onSortByAgeToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_AGE); } 555 void TrMainWindow :: onSortByETAToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_ETA); } 556 void TrMainWindow :: onSortByNameToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_NAME); } 557 void TrMainWindow :: onSortByProgressToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_PROGRESS); } 558 void TrMainWindow :: onSortByQueueToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_QUEUE); } 559 void TrMainWindow :: onSortByRatioToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_RATIO); } 560 void TrMainWindow :: onSortBySizeToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_SIZE); } 561 void TrMainWindow :: onSortByStateToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_STATE); } 562 563 void 564 TrMainWindow :: setSortAscendingPref (bool b) 565 { 566 myPrefs.set (Prefs::SORT_REVERSED, b); 560 567 } 561 568 … … 565 572 566 573 void 567 TrMainWindow :: showEvent ( QShowEvent * event)568 { 569 570 571 ui.action_ShowMainWindow->setChecked(true);574 TrMainWindow :: showEvent (QShowEvent * event) 575 { 576 Q_UNUSED (event); 577 578 ui.action_ShowMainWindow->setChecked (true); 572 579 } 573 580 … … 577 584 578 585 void 579 TrMainWindow :: hideEvent ( QHideEvent * event)580 { 581 582 583 if (!isVisible())584 ui.action_ShowMainWindow->setChecked(false);586 TrMainWindow :: hideEvent (QHideEvent * event) 587 { 588 Q_UNUSED (event); 589 590 if (!isVisible ()) 591 ui.action_ShowMainWindow->setChecked (false); 585 592 } 586 593 … … 590 597 591 598 void 592 TrMainWindow :: onPrefsDestroyed( ) 593 { 594 myPrefsDialog = 0; 595 } 596 597 void 598 TrMainWindow :: openPreferences( ) 599 { 600 if( myPrefsDialog == 0 ) { 601 myPrefsDialog = new PrefsDialog( mySession, myPrefs, this ); 602 connect( myPrefsDialog, SIGNAL(destroyed(QObject*)), this, SLOT(onPrefsDestroyed())); 603 } 604 605 myPrefsDialog->show( ); 606 } 607 608 void 609 TrMainWindow :: onDetailsDestroyed( ) 610 { 611 myDetailsDialog = 0; 612 } 613 614 void 615 TrMainWindow :: openProperties( ) 616 { 617 if( myDetailsDialog == 0 ) { 618 myDetailsDialog = new Details( mySession, myPrefs, myModel, this ); 619 connect( myDetailsDialog, SIGNAL(destroyed(QObject*)), this, SLOT(onDetailsDestroyed())); 620 } 621 622 myDetailsDialog->setIds( getSelectedTorrents( ) ); 623 myDetailsDialog->show( ); 624 } 625 626 void 627 TrMainWindow :: setLocation( ) 628 { 629 QDialog * d = new RelocateDialog( mySession, myModel, getSelectedTorrents(), this ); 630 d->show( ); 599 TrMainWindow :: onPrefsDestroyed () 600 { 601 myPrefsDialog = 0; 602 } 603 604 void 605 TrMainWindow :: openPreferences () 606 { 607 if (myPrefsDialog == 0) 608 { 609 myPrefsDialog = new PrefsDialog (mySession, myPrefs, this); 610 connect (myPrefsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onPrefsDestroyed ())); 611 } 612 613 myPrefsDialog->show (); 614 } 615 616 void 617 TrMainWindow :: onDetailsDestroyed () 618 { 619 myDetailsDialog = 0; 620 } 621 622 void 623 TrMainWindow :: openProperties () 624 { 625 if (myDetailsDialog == 0) 626 { 627 myDetailsDialog = new Details (mySession, myPrefs, myModel, this); 628 connect (myDetailsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onDetailsDestroyed ())); 629 } 630 631 myDetailsDialog->setIds (getSelectedTorrents ()); 632 myDetailsDialog->show (); 633 } 634 635 void 636 TrMainWindow :: setLocation () 637 { 638 QDialog * d = new RelocateDialog (mySession, myModel, getSelectedTorrents (), this); 639 d->show (); 631 640 } 632 641 633 642 // Open Folder & select torrent's file or top folder 634 643 #undef HAVE_OPEN_SELECT 635 #if defined (Q_OS_WIN)644 #if defined (Q_OS_WIN) 636 645 # define HAVE_OPEN_SELECT 637 646 static 638 void openSelect (const QString& path)639 { 640 641 642 if (!QFileInfo(path).isDir())643 param = QLatin1String("/select,");644 param += QDir::toNativeSeparators(path);645 QProcess::startDetached(explorer, QStringList(param));646 } 647 #elif defined (Q_OS_MAC)647 void openSelect (const QString& path) 648 { 649 const QString explorer = "explorer"; 650 QString param; 651 if (!QFileInfo (path).isDir ()) 652 param = QLatin1String ("/select,"); 653 param += QDir::toNativeSeparators (path); 654 QProcess::startDetached (explorer, QStringList (param)); 655 } 656 #elif defined (Q_OS_MAC) 648 657 # define HAVE_OPEN_SELECT 649 658 static 650 void openSelect (const QString& path)651 { 652 653 scriptArgs << QLatin1String("-e")654 << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")655 .arg(path);656 QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs); 657 scriptArgs.clear();658 scriptArgs << QLatin1String("-e")659 << QLatin1String("tell application \"Finder\" to activate");660 QProcess::execute("/usr/bin/osascript", scriptArgs);659 void openSelect (const QString& path) 660 { 661 QStringList scriptArgs; 662 scriptArgs << QLatin1String ("-e") 663 << QString::fromLatin1 ("tell application \"Finder\" to reveal POSIX file \"%1\"").arg (path); 664 QProcess::execute (QLatin1String ("/usr/bin/osascript"), scriptArgs); 665 666 scriptArgs.clear (); 667 scriptArgs << QLatin1String ("-e") 668 << QLatin1String ("tell application \"Finder\" to activate"); 669 QProcess::execute ("/usr/bin/osascript", scriptArgs); 661 670 } 662 671 #endif 663 672 664 673 void 665 TrMainWindow :: openFolder( ) 666 { 667 const int torrentId( *getSelectedTorrents().begin() ); 668 const Torrent * tor( myModel.getTorrentFromId( torrentId ) ); 669 QString path( tor->getPath( ) ); 670 const FileList files = tor->files(); 671 const QString firstfile = files.at(0).filename; 672 int slashIndex = firstfile.indexOf('/'); 673 if (slashIndex > -1) { 674 path = path + "/" + firstfile.left(slashIndex); 674 TrMainWindow :: openFolder () 675 { 676 const int torrentId (*getSelectedTorrents ().begin ()); 677 const Torrent * tor (myModel.getTorrentFromId (torrentId)); 678 QString path (tor->getPath ()); 679 const FileList files = tor->files (); 680 const QString firstfile = files.at (0).filename; 681 int slashIndex = firstfile.indexOf ('/'); 682 if (slashIndex > -1) 683 { 684 path = path + "/" + firstfile.left (slashIndex); 675 685 } 676 686 #ifdef HAVE_OPEN_SELECT 677 else { 678 openSelect( path + "/" + firstfile ); 679 return; 687 else 688 { 689 openSelect (path + "/" + firstfile); 690 return; 680 691 } 681 692 #endif 682 QDesktopServices :: openUrl( QUrl::fromLocalFile( path ));683 } 684 685 void 686 TrMainWindow :: copyMagnetLinkToClipboard ()687 { 688 const int id( *getSelectedTorrents().begin());689 mySession.copyMagnetLinkToClipboard( id);690 } 691 692 void 693 TrMainWindow :: openDonate ()694 { 695 QDesktopServices :: openUrl( QUrl( "http://www.transmissionbt.com/donate.php" ));696 } 697 698 void 699 TrMainWindow :: openHelp ()700 { 701 702 703 sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor);704 705 tr_snprintf( url, sizeof( url ), fmt, major, minor/10);706 QDesktopServices :: openUrl( QUrl( url ));707 } 708 709 void 710 TrMainWindow :: refreshTitle ()711 { 712 QString title( "Transmission");713 const QUrl url( mySession.getRemoteUrl( ));714 if( !url.isEmpty())715 title += tr( " - %1:%2" ).arg( url.host() ).arg( url.port());716 setWindowTitle( title);717 } 718 719 void 720 TrMainWindow :: refreshVisibleCount ()721 { 722 const int visibleCount( myFilterModel.rowCount( ));723 const int totalCount( visibleCount + myFilterModel.hiddenRowCount( ));724 725 if( visibleCount == totalCount)726 str = tr( "%Ln Torrent(s)", 0, totalCount);727 728 str = tr( "%L1 of %Ln Torrent(s)", 0, totalCount ).arg( visibleCount);729 myVisibleCountLabel->setText( str);730 myVisibleCountLabel->setVisible( totalCount > 0);731 } 732 733 void 734 TrMainWindow :: refreshFreeSpace ()735 { 736 const int64_t bytes (mySession.downloadDirFreeSpace ());693 QDesktopServices :: openUrl (QUrl::fromLocalFile (path)); 694 } 695 696 void 697 TrMainWindow :: copyMagnetLinkToClipboard () 698 { 699 const int id (*getSelectedTorrents ().begin ()); 700 mySession.copyMagnetLinkToClipboard (id); 701 } 702 703 void 704 TrMainWindow :: openDonate () 705 { 706 QDesktopServices :: openUrl (QUrl ("http://www.transmissionbt.com/donate.php")); 707 } 708 709 void 710 TrMainWindow :: openHelp () 711 { 712 const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx"; 713 int major, minor; 714 sscanf (SHORT_VERSION_STRING, "%d.%d", &major, &minor); 715 char url[128]; 716 tr_snprintf (url, sizeof (url), fmt, major, minor/10); 717 QDesktopServices :: openUrl (QUrl (url)); 718 } 719 720 void 721 TrMainWindow :: refreshTitle () 722 { 723 QString title ("Transmission"); 724 const QUrl url (mySession.getRemoteUrl ()); 725 if (!url.isEmpty ()) 726 title += tr (" - %1:%2").arg (url.host ()).arg (url.port ()); 727 setWindowTitle (title); 728 } 729 730 void 731 TrMainWindow :: refreshVisibleCount () 732 { 733 const int visibleCount (myFilterModel.rowCount ()); 734 const int totalCount (visibleCount + myFilterModel.hiddenRowCount ()); 735 QString str; 736 if (visibleCount == totalCount) 737 str = tr ("%Ln Torrent (s)", 0, totalCount); 738 else 739 str = tr ("%L1 of %Ln Torrent (s)", 0, totalCount).arg (visibleCount); 740 myVisibleCountLabel->setText (str); 741 myVisibleCountLabel->setVisible (totalCount > 0); 742 } 743 744 void 745 TrMainWindow :: refreshFreeSpace () 746 { 747 const int64_t bytes (mySession.downloadDirFreeSpace ()); 737 748 738 749 if (bytes >= 0) … … 740 751 const QString text = Formatter::sizeToString (bytes); 741 752 742 const QString tip = tr ("Download directory \"%1\" has %2 space free")743 .arg (myPrefs.getString(Prefs::DOWNLOAD_DIR))744 .arg (text);753 const QString tip = tr ("Download directory \"%1\" has %2 space free") 754 .arg (myPrefs.getString (Prefs::DOWNLOAD_DIR)) 755 .arg (text); 745 756 746 757 myFreeSpaceTextLabel->setText (text); … … 754 765 755 766 void 756 TrMainWindow :: refreshTrayIconSoon( ) 757 { 758 if( !myRefreshTrayIconTimer.isActive( ) ) 759 { 760 myRefreshTrayIconTimer.setSingleShot( true ); 761 myRefreshTrayIconTimer.start( 100 ); 762 } 763 } 764 void 765 TrMainWindow :: refreshTrayIcon( ) 766 { 767 const QString idle = tr( "Idle" ); 768 const Speed u (myModel.getUploadSpeed()); 769 const Speed d (myModel.getDownloadSpeed()); 770 771 myTrayIcon.setToolTip( tr( "Transmission\nUp: %1\nDown: %2" ) 772 .arg( u.isZero() ? idle : Formatter::speedToString( u ) ) 773 .arg( d.isZero() ? idle : Formatter::speedToString( d ) ) ); 774 } 775 776 void 777 TrMainWindow :: refreshStatusBar( ) 778 { 779 const Speed up( myModel.getUploadSpeed( ) ); 780 const Speed down( myModel.getDownloadSpeed( ) ); 781 myUploadSpeedLabel->setText( Formatter:: speedToString( up ) ); 782 myDownloadSpeedLabel->setText( Formatter:: speedToString( down ) ); 783 784 myNetworkLabel->setVisible( !mySession.isServer( ) ); 785 786 const QString mode( myPrefs.getString( Prefs::STATUSBAR_STATS ) ); 787 QString str; 788 789 if( mode == "session-ratio" ) 790 { 791 str = tr( "Ratio: %1" ).arg( Formatter:: ratioToString( mySession.getStats().ratio ) ); 792 } 793 else if( mode == "session-transfer" ) 794 { 795 const tr_session_stats& stats( mySession.getStats( ) ); 796 str = tr( "Down: %1, Up: %2" ).arg( Formatter:: sizeToString( stats.downloadedBytes ) ) 797 .arg( Formatter:: sizeToString( stats.uploadedBytes ) ); 798 } 799 else if( mode == "total-transfer" ) 800 { 801 const tr_session_stats& stats( mySession.getCumulativeStats( ) ); 802 str = tr( "Down: %1, Up: %2" ).arg( Formatter:: sizeToString( stats.downloadedBytes ) ) 803 .arg( Formatter:: sizeToString( stats.uploadedBytes ) ); 804 } 805 else // default is "total-ratio" 806 { 807 str = tr( "Ratio: %1" ).arg( Formatter:: ratioToString( mySession.getCumulativeStats().ratio ) ); 808 } 809 810 myStatsLabel->setText( str ); 811 } 812 813 814 815 void 816 TrMainWindow :: refreshActionSensitivitySoon( ) 817 { 818 if( !myRefreshActionSensitivityTimer.isActive( ) ) 819 { 820 myRefreshActionSensitivityTimer.setSingleShot( true ); 821 myRefreshActionSensitivityTimer.start( 100 ); 822 } 823 } 824 void 825 TrMainWindow :: refreshActionSensitivity( ) 826 { 827 int selected( 0 ); 828 int paused( 0 ); 829 int queued( 0 ); 830 int selectedAndPaused( 0 ); 831 int selectedAndQueued( 0 ); 832 int canAnnounce( 0 ); 833 const QAbstractItemModel * model( ui.listView->model( ) ); 834 const QItemSelectionModel * selectionModel( ui.listView->selectionModel( ) ); 835 const int rowCount( model->rowCount( ) ); 836 837 // count how many torrents are selected, paused, etc 838 for( int row=0; row<rowCount; ++row ) { 839 const QModelIndex modelIndex( model->index( row, 0 ) ); 840 assert( model == modelIndex.model( ) ); 841 const Torrent * tor( model->data( modelIndex, TorrentModel::TorrentRole ).value<const Torrent*>( ) ); 842 if( tor ) { 843 const bool isSelected( selectionModel->isSelected( modelIndex ) ); 844 const bool isPaused( tor->isPaused( ) ); 845 const bool isQueued( tor->isQueued( ) ); 846 if( isSelected ) ++selected; 847 if( isQueued ) ++queued; 848 if( isPaused ) ++ paused; 849 if( isSelected && isPaused ) ++selectedAndPaused; 850 if( isSelected && isQueued ) ++selectedAndQueued; 851 if( tor->canManualAnnounce( ) ) ++canAnnounce; 767 TrMainWindow :: refreshTrayIconSoon () 768 { 769 if (!myRefreshTrayIconTimer.isActive ()) 770 { 771 myRefreshTrayIconTimer.setSingleShot (true); 772 myRefreshTrayIconTimer.start (100); 773 } 774 } 775 void 776 TrMainWindow :: refreshTrayIcon () 777 { 778 const QString idle = tr ("Idle"); 779 const Speed u (myModel.getUploadSpeed ()); 780 const Speed d (myModel.getDownloadSpeed ()); 781 782 myTrayIcon.setToolTip (tr ("Transmission\nUp: %1\nDown: %2") 783 .arg (u.isZero () ? idle : Formatter::speedToString (u)) 784 .arg (d.isZero () ? idle : Formatter::speedToString (d))); 785 } 786 787 void 788 TrMainWindow :: refreshStatusBar () 789 { 790 const Speed up (myModel.getUploadSpeed ()); 791 const Speed down (myModel.getDownloadSpeed ()); 792 myUploadSpeedLabel->setText (Formatter:: speedToString (up)); 793 myDownloadSpeedLabel->setText (Formatter:: speedToString (down)); 794 795 myNetworkLabel->setVisible (!mySession.isServer ()); 796 797 const QString mode (myPrefs.getString (Prefs::STATUSBAR_STATS)); 798 QString str; 799 800 if (mode == "session-ratio") 801 { 802 str = tr ("Ratio: %1").arg (Formatter:: ratioToString (mySession.getStats ().ratio)); 803 } 804 else if (mode == "session-transfer") 805 { 806 const tr_session_stats& stats (mySession.getStats ()); 807 str = tr ("Down: %1, Up: %2").arg (Formatter:: sizeToString (stats.downloadedBytes)) 808 .arg (Formatter:: sizeToString (stats.uploadedBytes)); 809 } 810 else if (mode == "total-transfer") 811 { 812 const tr_session_stats& stats (mySession.getCumulativeStats ()); 813 str = tr ("Down: %1, Up: %2").arg (Formatter:: sizeToString (stats.downloadedBytes)) 814 .arg (Formatter:: sizeToString (stats.uploadedBytes)); 815 } 816 else // default is "total-ratio" 817 { 818 str = tr ("Ratio: %1").arg (Formatter:: ratioToString (mySession.getCumulativeStats ().ratio)); 819 } 820 821 myStatsLabel->setText (str); 822 } 823 824 825 826 void 827 TrMainWindow :: refreshActionSensitivitySoon () 828 { 829 if (!myRefreshActionSensitivityTimer.isActive ()) 830 { 831 myRefreshActionSensitivityTimer.setSingleShot (true); 832 myRefreshActionSensitivityTimer.start (100); 833 } 834 } 835 void 836 TrMainWindow :: refreshActionSensitivity () 837 { 838 int selected (0); 839 int paused (0); 840 int queued (0); 841 int selectedAndPaused (0); 842 int selectedAndQueued (0); 843 int canAnnounce (0); 844 const QAbstractItemModel * model (ui.listView->model ()); 845 const QItemSelectionModel * selectionModel (ui.listView->selectionModel ()); 846 const int rowCount (model->rowCount ()); 847 848 // count how many torrents are selected, paused, etc 849 for (int row=0; row<rowCount; ++row) 850 { 851 const QModelIndex modelIndex (model->index (row, 0)); 852 assert (model == modelIndex.model ()); 853 const Torrent * tor (model->data (modelIndex, TorrentModel::TorrentRole).value<const Torrent*> ()); 854 if (tor) 855 { 856 const bool isSelected (selectionModel->isSelected (modelIndex)); 857 const bool isPaused (tor->isPaused ()); 858 const bool isQueued (tor->isQueued ()); 859 if (isSelected) ++selected; 860 if (isQueued) ++queued; 861 if (isPaused) ++ paused; 862 if (isSelected && isPaused) ++selectedAndPaused; 863 if (isSelected && isQueued) ++selectedAndQueued; 864 if (tor->canManualAnnounce ()) ++canAnnounce; 852 865 } 853 866 } 854 867 855 const bool haveSelection( selected > 0);856 ui.action_Verify->setEnabled( haveSelection);857 ui.action_Remove->setEnabled( haveSelection);858 ui.action_Delete->setEnabled( haveSelection);859 ui.action_Properties->setEnabled( haveSelection);860 ui.action_DeselectAll->setEnabled( haveSelection);861 ui.action_SetLocation->setEnabled( haveSelection);862 863 const bool oneSelection( selected == 1);864 ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ));865 ui.action_CopyMagnetToClipboard->setEnabled( oneSelection);866 867 ui.action_SelectAll->setEnabled( selected < rowCount);868 ui.action_StartAll->setEnabled( paused > 0);869 ui.action_PauseAll->setEnabled( paused < rowCount);870 ui.action_Start->setEnabled( selectedAndPaused > 0);871 ui.action_StartNow->setEnabled( selectedAndPaused + selectedAndQueued > 0);872 ui.action_Pause->setEnabled( selectedAndPaused < selected);873 ui.action_Announce->setEnabled( selected > 0 && ( canAnnounce == selected ));874 875 ui.action_QueueMoveTop->setEnabled( haveSelection);876 ui.action_QueueMoveUp->setEnabled( haveSelection);877 ui.action_QueueMoveDown->setEnabled( haveSelection);878 ui.action_QueueMoveBottom->setEnabled( haveSelection);879 880 if( myDetailsDialog)881 myDetailsDialog->setIds( getSelectedTorrents( ));868 const bool haveSelection (selected > 0); 869 ui.action_Verify->setEnabled (haveSelection); 870 ui.action_Remove->setEnabled (haveSelection); 871 ui.action_Delete->setEnabled (haveSelection); 872 ui.action_Properties->setEnabled (haveSelection); 873 ui.action_DeselectAll->setEnabled (haveSelection); 874 ui.action_SetLocation->setEnabled (haveSelection); 875 876 const bool oneSelection (selected == 1); 877 ui.action_OpenFolder->setEnabled (oneSelection && mySession.isLocal ()); 878 ui.action_CopyMagnetToClipboard->setEnabled (oneSelection); 879 880 ui.action_SelectAll->setEnabled (selected < rowCount); 881 ui.action_StartAll->setEnabled (paused > 0); 882 ui.action_PauseAll->setEnabled (paused < rowCount); 883 ui.action_Start->setEnabled (selectedAndPaused > 0); 884 ui.action_StartNow->setEnabled (selectedAndPaused + selectedAndQueued > 0); 885 ui.action_Pause->setEnabled (selectedAndPaused < selected); 886 ui.action_Announce->setEnabled (selected > 0 && (canAnnounce == selected)); 887 888 ui.action_QueueMoveTop->setEnabled (haveSelection); 889 ui.action_QueueMoveUp->setEnabled (haveSelection); 890 ui.action_QueueMoveDown->setEnabled (haveSelection); 891 ui.action_QueueMoveBottom->setEnabled (haveSelection); 892 893 if (myDetailsDialog) 894 myDetailsDialog->setIds (getSelectedTorrents ()); 882 895 } 883 896 … … 887 900 888 901 void 889 TrMainWindow :: clearSelection ()890 { 891 ui.action_DeselectAll->trigger();902 TrMainWindow :: clearSelection () 903 { 904 ui.action_DeselectAll->trigger (); 892 905 } 893 906 894 907 QSet<int> 895 TrMainWindow :: getSelectedTorrents () const896 { 897 898 899 foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ))900 { 901 const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>( ));902 ids.insert( tor->id( ));903 } 904 905 906 } 907 908 void 909 TrMainWindow :: startSelected ()910 { 911 mySession.startTorrents( getSelectedTorrents( ));912 } 913 void 914 TrMainWindow :: startSelectedNow ()915 { 916 mySession.startTorrentsNow( getSelectedTorrents( ));917 } 918 void 919 TrMainWindow :: pauseSelected ()920 { 921 mySession.pauseTorrents( getSelectedTorrents( ));922 } 923 void 924 TrMainWindow :: queueMoveTop ()925 { 926 mySession.queueMoveTop( getSelectedTorrents( ));927 } 928 void 929 TrMainWindow :: queueMoveUp ()930 { 931 mySession.queueMoveUp( getSelectedTorrents( ));932 } 933 void 934 TrMainWindow :: queueMoveDown ()935 { 936 mySession.queueMoveDown( getSelectedTorrents( ));937 } 938 void 939 TrMainWindow :: queueMoveBottom ()940 { 941 mySession.queueMoveBottom( getSelectedTorrents( ));942 } 943 void 944 TrMainWindow :: startAll ()945 { 946 mySession.startTorrents();947 } 948 void 949 TrMainWindow :: pauseAll ()950 { 951 mySession.pauseTorrents();952 } 953 void 954 TrMainWindow :: removeSelected ()955 { 956 removeTorrents( false);957 } 958 void 959 TrMainWindow :: deleteSelected ()960 { 961 removeTorrents( true);962 } 963 void 964 TrMainWindow :: verifySelected ()965 { 966 mySession.verifyTorrents( getSelectedTorrents( ));967 } 968 void 969 TrMainWindow :: reannounceSelected ()970 { 971 mySession.reannounceTorrents( getSelectedTorrents( ));908 TrMainWindow :: getSelectedTorrents () const 909 { 910 QSet<int> ids; 911 912 foreach (QModelIndex index, ui.listView->selectionModel ()->selectedRows ()) 913 { 914 const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*> ()); 915 ids.insert (tor->id ()); 916 } 917 918 return ids; 919 } 920 921 void 922 TrMainWindow :: startSelected () 923 { 924 mySession.startTorrents (getSelectedTorrents ()); 925 } 926 void 927 TrMainWindow :: startSelectedNow () 928 { 929 mySession.startTorrentsNow (getSelectedTorrents ()); 930 } 931 void 932 TrMainWindow :: pauseSelected () 933 { 934 mySession.pauseTorrents (getSelectedTorrents ()); 935 } 936 void 937 TrMainWindow :: queueMoveTop () 938 { 939 mySession.queueMoveTop (getSelectedTorrents ()); 940 } 941 void 942 TrMainWindow :: queueMoveUp () 943 { 944 mySession.queueMoveUp (getSelectedTorrents ()); 945 } 946 void 947 TrMainWindow :: queueMoveDown () 948 { 949 mySession.queueMoveDown (getSelectedTorrents ()); 950 } 951 void 952 TrMainWindow :: queueMoveBottom () 953 { 954 mySession.queueMoveBottom (getSelectedTorrents ()); 955 } 956 void 957 TrMainWindow :: startAll () 958 { 959 mySession.startTorrents (); 960 } 961 void 962 TrMainWindow :: pauseAll () 963 { 964 mySession.pauseTorrents (); 965 } 966 void 967 TrMainWindow :: removeSelected () 968 { 969 removeTorrents (false); 970 } 971 void 972 TrMainWindow :: deleteSelected () 973 { 974 removeTorrents (true); 975 } 976 void 977 TrMainWindow :: verifySelected () 978 { 979 mySession.verifyTorrents (getSelectedTorrents ()); 980 } 981 void 982 TrMainWindow :: reannounceSelected () 983 { 984 mySession.reannounceTorrents (getSelectedTorrents ()); 972 985 } 973 986 … … 976 989 **/ 977 990 978 void TrMainWindow :: showTotalRatio ( ) { myPrefs.set(Prefs::STATUSBAR_STATS, "total-ratio"); }979 void TrMainWindow :: showTotalTransfer ( ) { myPrefs.set(Prefs::STATUSBAR_STATS, "total-transfer"); }980 void TrMainWindow :: showSessionRatio ( ) { myPrefs.set(Prefs::STATUSBAR_STATS, "session-ratio"); }981 void TrMainWindow :: showSessionTransfer ( ) { myPrefs.set(Prefs::STATUSBAR_STATS, "session-transfer"); }991 void TrMainWindow :: showTotalRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, "total-ratio"); } 992 void TrMainWindow :: showTotalTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, "total-transfer"); } 993 void TrMainWindow :: showSessionRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, "session-ratio"); } 994 void TrMainWindow :: showSessionTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, "session-transfer"); } 982 995 983 996 /** … … 986 999 987 1000 void 988 TrMainWindow :: setCompactView( bool visible ) 989 { 990 myPrefs.set( Prefs :: COMPACT_VIEW, visible ); 991 } 992 void 993 TrMainWindow :: toggleSpeedMode( ) 994 { 995 bool mode; 996 997 myPrefs.toggleBool( Prefs :: ALT_SPEED_LIMIT_ENABLED ); 998 mode = myPrefs.get<bool>( Prefs::ALT_SPEED_LIMIT_ENABLED ); 999 myAltSpeedAction->setIcon( mode ? mySpeedModeOnIcon : mySpeedModeOffIcon ); 1000 } 1001 void 1002 TrMainWindow :: setToolbarVisible( bool visible ) 1003 { 1004 myPrefs.set( Prefs::TOOLBAR, visible ); 1005 } 1006 void 1007 TrMainWindow :: setFilterbarVisible( bool visible ) 1008 { 1009 myPrefs.set( Prefs::FILTERBAR, visible ); 1010 } 1011 void 1012 TrMainWindow :: setStatusbarVisible( bool visible ) 1013 { 1014 myPrefs.set( Prefs::STATUSBAR, visible ); 1001 TrMainWindow :: setCompactView (bool visible) 1002 { 1003 myPrefs.set (Prefs :: COMPACT_VIEW, visible); 1004 } 1005 void 1006 TrMainWindow :: toggleSpeedMode () 1007 { 1008 myPrefs.toggleBool (Prefs :: ALT_SPEED_LIMIT_ENABLED); 1009 const bool mode = myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED); 1010 myAltSpeedAction->setIcon (mode ? mySpeedModeOnIcon : mySpeedModeOffIcon); 1011 } 1012 void 1013 TrMainWindow :: setToolbarVisible (bool visible) 1014 { 1015 myPrefs.set (Prefs::TOOLBAR, visible); 1016 } 1017 void 1018 TrMainWindow :: setFilterbarVisible (bool visible) 1019 { 1020 myPrefs.set (Prefs::FILTERBAR, visible); 1021 } 1022 void 1023 TrMainWindow :: setStatusbarVisible (bool visible) 1024 { 1025 myPrefs.set (Prefs::STATUSBAR, visible); 1015 1026 } 1016 1027 … … 1020 1031 1021 1032 void 1022 TrMainWindow :: toggleWindows ( bool doShow)1023 { 1024 if( !doShow)1025 { 1026 hide();1027 } 1028 1029 { 1030 if ( !isVisible( ) ) show();1031 if ( isMinimized( ) ) showNormal();1032 //activateWindow();1033 raise();1034 QApplication::setActiveWindow( this);1035 } 1036 } 1037 1038 void 1039 TrMainWindow :: trayActivated ( QSystemTrayIcon::ActivationReason reason)1040 { 1041 if( reason == QSystemTrayIcon::Trigger)1042 { 1043 if( isMinimized ( ))1044 toggleWindows( true);1045 1046 toggleWindows( !isVisible());1047 } 1048 } 1049 1050 1051 void 1052 TrMainWindow :: refreshPref ( int key)1053 { 1054 1055 1056 1057 1058 switch( key)1059 { 1060 1061 str = myPrefs.getString( key);1062 ui.action_TotalRatio->setChecked ( str == "total-ratio");1063 ui.action_TotalTransfer->setChecked ( str == "total-transfer");1064 ui.action_SessionRatio->setChecked ( str == "session-ratio");1065 ui.action_SessionTransfer->setChecked( str == "session-transfer");1066 refreshStatusBar();1067 1068 1069 1070 ui.action_ReverseSortOrder->setChecked( myPrefs.getBool( key ));1071 1072 1073 1074 i = myPrefs.get<SortMode>(key).mode();1075 ui.action_SortByActivity->setChecked ( i == SortMode::SORT_BY_ACTIVITY);1076 ui.action_SortByAge->setChecked ( i == SortMode::SORT_BY_AGE);1077 ui.action_SortByETA->setChecked ( i == SortMode::SORT_BY_ETA);1078 ui.action_SortByName->setChecked ( i == SortMode::SORT_BY_NAME);1079 ui.action_SortByProgress->setChecked ( i == SortMode::SORT_BY_PROGRESS);1080 ui.action_SortByQueue->setChecked ( i == SortMode::SORT_BY_QUEUE);1081 ui.action_SortByRatio->setChecked ( i == SortMode::SORT_BY_RATIO);1082 ui.action_SortBySize->setChecked ( i == SortMode::SORT_BY_SIZE);1083 ui.action_SortByState->setChecked ( i == SortMode::SORT_BY_STATE);1084 1085 1086 1087 (myPrefs.get<bool>(key) ? myDlimitOnAction : myDlimitOffAction)->setChecked( true);1088 1089 1090 1091 myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( myPrefs.get<int>(key) ) ) ));1092 1093 1094 1095 (myPrefs.get<bool>(key) ? myUlimitOnAction : myUlimitOffAction)->setChecked( true);1096 1097 1098 1099 myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( myPrefs.get<int>(key) ) ) ));1100 1101 1102 1103 (myPrefs.get<bool>(key) ? myRatioOnAction : myRatioOffAction)->setChecked( true);1104 1105 1106 1107 myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Formatter::ratioToString( myPrefs.get<double>(key) ) ));1108 1109 1110 1111 b = myPrefs.getBool( key);1112 myFilterBar->setVisible( b);1113 ui.action_Filterbar->setChecked( b);1114 1115 1116 1117 b = myPrefs.getBool( key);1118 myStatusBar->setVisible( b);1119 ui.action_Statusbar->setChecked( b);1120 1121 1122 1123 b = myPrefs.getBool( key);1124 ui.toolBar->setVisible( b);1125 ui.action_Toolbar->setChecked( b);1126 1127 1128 1129 b = myPrefs.getBool( key);1130 ui.action_TrayIcon->setChecked( b);1131 myTrayIcon.setVisible( b);1132 dynamic_cast<MyApp*>(QCoreApplication::instance())->setQuitOnLastWindowClosed(!b);1133 refreshTrayIconSoon();1134 1135 1136 1137 QItemSelectionModel * selectionModel ( ui.listView->selectionModel( ));1138 const QItemSelection selection ( selectionModel->selection( ));1139 const QModelIndex currentIndex ( selectionModel->currentIndex( ));1140 b = myPrefs.getBool ( key);1141 ui.action_CompactView->setChecked ( b);1142 ui.listView->setItemDelegate ( b ? myTorrentDelegateMin : myTorrentDelegate);1143 selectionModel->clear ();1144 ui.listView->reset (); // force the rows to resize1145 selectionModel->select ( selection, QItemSelectionModel::Select);1146 selectionModel->setCurrentIndex ( currentIndex, QItemSelectionModel::NoUpdate);1033 TrMainWindow :: toggleWindows (bool doShow) 1034 { 1035 if (!doShow) 1036 { 1037 hide (); 1038 } 1039 else 1040 { 1041 if (!isVisible ()) show (); 1042 if (isMinimized ()) showNormal (); 1043 //activateWindow (); 1044 raise (); 1045 QApplication::setActiveWindow (this); 1046 } 1047 } 1048 1049 void 1050 TrMainWindow :: trayActivated (QSystemTrayIcon::ActivationReason reason) 1051 { 1052 if (reason == QSystemTrayIcon::Trigger) 1053 { 1054 if (isMinimized ()) 1055 toggleWindows (true); 1056 else 1057 toggleWindows (!isVisible ()); 1058 } 1059 } 1060 1061 1062 void 1063 TrMainWindow :: refreshPref (int key) 1064 { 1065 bool b; 1066 int i; 1067 QString str; 1068 1069 switch (key) 1070 { 1071 case Prefs::STATUSBAR_STATS: 1072 str = myPrefs.getString (key); 1073 ui.action_TotalRatio->setChecked (str == "total-ratio"); 1074 ui.action_TotalTransfer->setChecked (str == "total-transfer"); 1075 ui.action_SessionRatio->setChecked (str == "session-ratio"); 1076 ui.action_SessionTransfer->setChecked (str == "session-transfer"); 1077 refreshStatusBar (); 1078 break; 1079 1080 case Prefs::SORT_REVERSED: 1081 ui.action_ReverseSortOrder->setChecked (myPrefs.getBool (key)); 1082 break; 1083 1084 case Prefs::SORT_MODE: 1085 i = myPrefs.get<SortMode> (key).mode (); 1086 ui.action_SortByActivity->setChecked (i == SortMode::SORT_BY_ACTIVITY); 1087 ui.action_SortByAge->setChecked (i == SortMode::SORT_BY_AGE); 1088 ui.action_SortByETA->setChecked (i == SortMode::SORT_BY_ETA); 1089 ui.action_SortByName->setChecked (i == SortMode::SORT_BY_NAME); 1090 ui.action_SortByProgress->setChecked (i == SortMode::SORT_BY_PROGRESS); 1091 ui.action_SortByQueue->setChecked (i == SortMode::SORT_BY_QUEUE); 1092 ui.action_SortByRatio->setChecked (i == SortMode::SORT_BY_RATIO); 1093 ui.action_SortBySize->setChecked (i == SortMode::SORT_BY_SIZE); 1094 ui.action_SortByState->setChecked (i == SortMode::SORT_BY_STATE); 1095 break; 1096 1097 case Prefs::DSPEED_ENABLED: 1098 (myPrefs.get<bool> (key) ? myDlimitOnAction : myDlimitOffAction)->setChecked (true); 1099 break; 1100 1101 case Prefs::DSPEED: 1102 myDlimitOnAction->setText (tr ("Limited at %1").arg (Formatter::speedToString (Speed::fromKBps (myPrefs.get<int> (key))))); 1103 break; 1104 1105 case Prefs::USPEED_ENABLED: 1106 (myPrefs.get<bool> (key) ? myUlimitOnAction : myUlimitOffAction)->setChecked (true); 1107 break; 1108 1109 case Prefs::USPEED: 1110 myUlimitOnAction->setText (tr ("Limited at %1").arg (Formatter::speedToString (Speed::fromKBps (myPrefs.get<int> (key))))); 1111 break; 1112 1113 case Prefs::RATIO_ENABLED: 1114 (myPrefs.get<bool> (key) ? myRatioOnAction : myRatioOffAction)->setChecked (true); 1115 break; 1116 1117 case Prefs::RATIO: 1118 myRatioOnAction->setText (tr ("Stop at Ratio (%1)").arg (Formatter::ratioToString (myPrefs.get<double> (key)))); 1119 break; 1120 1121 case Prefs::FILTERBAR: 1122 b = myPrefs.getBool (key); 1123 myFilterBar->setVisible (b); 1124 ui.action_Filterbar->setChecked (b); 1125 break; 1126 1127 case Prefs::STATUSBAR: 1128 b = myPrefs.getBool (key); 1129 myStatusBar->setVisible (b); 1130 ui.action_Statusbar->setChecked (b); 1131 break; 1132 1133 case Prefs::TOOLBAR: 1134 b = myPrefs.getBool (key); 1135 ui.toolBar->setVisible (b); 1136 ui.action_Toolbar->setChecked (b); 1137 break; 1138 1139 case Prefs::SHOW_TRAY_ICON: 1140 b = myPrefs.getBool (key); 1141 ui.action_TrayIcon->setChecked (b); 1142 myTrayIcon.setVisible (b); 1143 dynamic_cast<MyApp*> (QCoreApplication::instance ())->setQuitOnLastWindowClosed (!b); 1144 refreshTrayIconSoon (); 1145 break; 1146 1147 case Prefs::COMPACT_VIEW: { 1148 QItemSelectionModel * selectionModel (ui.listView->selectionModel ()); 1149 const QItemSelection selection (selectionModel->selection ()); 1150 const QModelIndex currentIndex (selectionModel->currentIndex ()); 1151 b = myPrefs.getBool (key); 1152 ui.action_CompactView->setChecked (b); 1153 ui.listView->setItemDelegate (b ? myTorrentDelegateMin : myTorrentDelegate); 1154 selectionModel->clear (); 1155 ui.listView->reset (); // force the rows to resize 1156 selectionModel->select (selection, QItemSelectionModel::Select); 1157 selectionModel->setCurrentIndex (currentIndex, QItemSelectionModel::NoUpdate); 1147 1158 break; 1148 1159 } 1149 1160 1150 case Prefs::MAIN_WINDOW_X: 1151 case Prefs::MAIN_WINDOW_Y: 1152 case Prefs::MAIN_WINDOW_WIDTH: 1153 case Prefs::MAIN_WINDOW_HEIGHT: 1154 setGeometry( myPrefs.getInt( Prefs::MAIN_WINDOW_X ), 1155 myPrefs.getInt( Prefs::MAIN_WINDOW_Y ), 1156 myPrefs.getInt( Prefs::MAIN_WINDOW_WIDTH ), 1157 myPrefs.getInt( Prefs::MAIN_WINDOW_HEIGHT ) ); 1158 break; 1159 1160 case Prefs :: ALT_SPEED_LIMIT_ENABLED: 1161 case Prefs :: ALT_SPEED_LIMIT_UP: 1162 case Prefs :: ALT_SPEED_LIMIT_DOWN: { 1163 b = myPrefs.getBool( Prefs :: ALT_SPEED_LIMIT_ENABLED ); 1164 myAltSpeedButton->setChecked( b ); 1165 myAltSpeedButton->setIcon( b ? mySpeedModeOnIcon : mySpeedModeOffIcon ); 1166 const QString fmt = b ? tr( "Click to disable Temporary Speed Limits\n(%1 down, %2 up)" ) 1167 : tr( "Click to enable Temporary Speed Limits\n(%1 down, %2 up)" ); 1168 const Speed d = Speed::fromKBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) ); 1169 const Speed u = Speed::fromKBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) ); 1170 myAltSpeedButton->setToolTip( fmt.arg( Formatter::speedToString( d ) ) 1171 .arg( Formatter::speedToString( u ) ) ); 1172 break; 1161 case Prefs::MAIN_WINDOW_X: 1162 case Prefs::MAIN_WINDOW_Y: 1163 case Prefs::MAIN_WINDOW_WIDTH: 1164 case Prefs::MAIN_WINDOW_HEIGHT: 1165 setGeometry (myPrefs.getInt (Prefs::MAIN_WINDOW_X), 1166 myPrefs.getInt (Prefs::MAIN_WINDOW_Y), 1167 myPrefs.getInt (Prefs::MAIN_WINDOW_WIDTH), 1168 myPrefs.getInt (Prefs::MAIN_WINDOW_HEIGHT)); 1169 break; 1170 1171 case Prefs :: ALT_SPEED_LIMIT_ENABLED: 1172 case Prefs :: ALT_SPEED_LIMIT_UP: 1173 case Prefs :: ALT_SPEED_LIMIT_DOWN: 1174 { 1175 b = myPrefs.getBool (Prefs :: ALT_SPEED_LIMIT_ENABLED); 1176 myAltSpeedButton->setChecked (b); 1177 myAltSpeedButton->setIcon (b ? mySpeedModeOnIcon : mySpeedModeOffIcon); 1178 const QString fmt = b ? tr ("Click to disable Temporary Speed Limits\n (%1 down, %2 up)") 1179 : tr ("Click to enable Temporary Speed Limits\n (%1 down, %2 up)"); 1180 const Speed d = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_DOWN)); 1181 const Speed u = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_UP)); 1182 myAltSpeedButton->setToolTip (fmt.arg (Formatter::speedToString (d)) 1183 .arg (Formatter::speedToString (u))); 1184 break; 1173 1185 } 1174 1186 1175 1176 1187 default: 1188 break; 1177 1189 } 1178 1190 } … … 1183 1195 1184 1196 void 1185 TrMainWindow :: newTorrent( ) 1186 { 1187 MakeDialog * dialog = new MakeDialog( mySession, this ); 1188 dialog->show( ); 1189 } 1190 1191 void 1192 TrMainWindow :: openTorrent( ) 1193 { 1194 QFileDialog * myFileDialog; 1195 myFileDialog = new QFileDialog( this, 1196 tr( "Open Torrent" ), 1197 myPrefs.getString( Prefs::OPEN_DIALOG_FOLDER ), 1198 tr( "Torrent Files (*.torrent);;All Files (*.*)" ) ); 1199 myFileDialog->setFileMode( QFileDialog::ExistingFiles ); 1200 myFileDialog->setAttribute( Qt::WA_DeleteOnClose ); 1201 1202 QCheckBox * button = new QCheckBox( tr( "Show &options dialog" ) ); 1203 button->setChecked( myPrefs.getBool( Prefs::OPTIONS_PROMPT ) ); 1204 QGridLayout * layout = dynamic_cast<QGridLayout*>(myFileDialog->layout()); 1205 layout->addWidget( button, layout->rowCount( ), 0, 1, -1, Qt::AlignLeft ); 1206 myFileDialogOptionsCheck = button; 1207 1208 connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)), 1209 this, SLOT(addTorrents(const QStringList&))); 1210 1211 myFileDialog->show( ); 1212 } 1213 1214 void 1215 TrMainWindow :: openURL( ) 1216 { 1217 QString str = QApplication::clipboard()->text( QClipboard::Selection ); 1218 1219 if( !AddData::isSupported( str ) ) 1220 str = QApplication::clipboard()->text( QClipboard::Clipboard ); 1221 1222 if( !AddData::isSupported( str ) ) 1223 str.clear(); 1224 1225 openURL( str ); 1226 } 1227 1228 void 1229 TrMainWindow :: openURL( QString url ) 1230 { 1231 bool ok; 1232 const QString key = QInputDialog::getText( this, 1233 tr( "Open Link" ), 1234 tr( "Open URL or Magnet Link" ), 1235 QLineEdit::Normal, 1236 url, 1237 &ok, 1238 Qt::WindowStaysOnTopHint ); 1239 if( ok && !key.isEmpty( ) ) 1240 mySession.addTorrent( key ); 1241 } 1242 1243 void 1244 TrMainWindow :: addTorrents( const QStringList& filenames ) 1245 { 1246 foreach( const QString& filename, filenames ) 1247 addTorrent( filename ); 1248 } 1249 1250 void 1251 TrMainWindow :: addTorrent( const QString& filename ) 1252 { 1253 if( !myFileDialogOptionsCheck->isChecked( ) ) { 1254 mySession.addTorrent( filename ); 1255 QApplication :: alert ( this ); 1256 } else { 1257 Options * o = new Options( mySession, myPrefs, filename, this ); 1258 o->show( ); 1259 QApplication :: alert( o ); 1260 } 1261 } 1262 1263 void 1264 TrMainWindow :: removeTorrents( const bool deleteFiles ) 1265 { 1266 QSet<int> ids; 1267 QMessageBox msgBox( this ); 1268 QString primary_text, secondary_text; 1269 int incomplete = 0; 1270 int connected = 0; 1271 int count; 1272 1273 foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ) ) 1274 { 1275 const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>( ) ); 1276 ids.insert( tor->id( ) ); 1277 if( tor->connectedPeers( ) ) 1278 ++connected; 1279 if( !tor->isDone( ) ) 1280 ++incomplete; 1281 } 1282 1283 if( ids.isEmpty() ) 1284 return; 1285 count = ids.size(); 1286 1287 if( !deleteFiles ) 1288 { 1289 primary_text = ( count == 1 ) 1290 ? tr( "Remove torrent?" ) 1291 : tr( "Remove %1 torrents?" ).arg( count ); 1292 } 1293 else 1294 { 1295 primary_text = ( count == 1 ) 1296 ? tr( "Delete this torrent's downloaded files?" ) 1297 : tr( "Delete these %1 torrents' downloaded files?" ).arg( count ); 1298 } 1299 1300 if( !incomplete && !connected ) 1301 { 1302 secondary_text = ( count == 1 ) 1303 ? tr( "Once removed, continuing the transfer will require the torrent file or magnet link." ) 1304 : tr( "Once removed, continuing the transfers will require the torrent files or magnet links." ); 1305 } 1306 else if( count == incomplete ) 1307 { 1308 secondary_text = ( count == 1 ) 1309 ? tr( "This torrent has not finished downloading." ) 1310 : tr( "These torrents have not finished downloading." ); 1311 } 1312 else if( count == connected ) 1313 { 1314 secondary_text = ( count == 1 ) 1315 ? tr( "This torrent is connected to peers." ) 1316 : tr( "These torrents are connected to peers." ); 1317 } 1318 else 1319 { 1320 if( connected ) 1197 TrMainWindow :: newTorrent () 1198 { 1199 MakeDialog * dialog = new MakeDialog (mySession, this); 1200 dialog->show (); 1201 } 1202 1203 void 1204 TrMainWindow :: openTorrent () 1205 { 1206 QFileDialog * myFileDialog; 1207 myFileDialog = new QFileDialog (this, 1208 tr ("Open Torrent"), 1209 myPrefs.getString (Prefs::OPEN_DIALOG_FOLDER), 1210 tr ("Torrent Files (*.torrent);;All Files (*.*)")); 1211 myFileDialog->setFileMode (QFileDialog::ExistingFiles); 1212 myFileDialog->setAttribute (Qt::WA_DeleteOnClose); 1213 1214 QCheckBox * button = new QCheckBox (tr ("Show &options dialog")); 1215 button->setChecked (myPrefs.getBool (Prefs::OPTIONS_PROMPT)); 1216 QGridLayout * layout = dynamic_cast<QGridLayout*> (myFileDialog->layout ()); 1217 layout->addWidget (button, layout->rowCount (), 0, 1, -1, Qt::AlignLeft); 1218 myFileDialogOptionsCheck = button; 1219 1220 connect (myFileDialog, SIGNAL (filesSelected (const QStringList&)), 1221 this, SLOT (addTorrents (const QStringList&))); 1222 1223 myFileDialog->show (); 1224 } 1225 1226 void 1227 TrMainWindow :: openURL () 1228 { 1229 QString str = QApplication::clipboard ()->text (QClipboard::Selection); 1230 1231 if (!AddData::isSupported (str)) 1232 str = QApplication::clipboard ()->text (QClipboard::Clipboard); 1233 1234 if (!AddData::isSupported (str)) 1235 str.clear (); 1236 1237 openURL (str); 1238 } 1239 1240 void 1241 TrMainWindow :: openURL (QString url) 1242 { 1243 bool ok; 1244 const QString key = QInputDialog::getText (this, 1245 tr ("Open Link"), 1246 tr ("Open URL or Magnet Link"), 1247 QLineEdit::Normal, 1248 url, 1249 &ok, 1250 Qt::WindowStaysOnTopHint); 1251 if (ok && !key.isEmpty ()) 1252 mySession.addTorrent (key); 1253 } 1254 1255 void 1256 TrMainWindow :: addTorrents (const QStringList& filenames) 1257 { 1258 foreach (const QString& filename, filenames) 1259 addTorrent (filename); 1260 } 1261 1262 void 1263 TrMainWindow :: addTorrent (const QString& filename) 1264 { 1265 if (!myFileDialogOptionsCheck->isChecked ()) 1266 { 1267 mySession.addTorrent (filename); 1268 QApplication :: alert (this); 1269 } 1270 else 1271 { 1272 Options * o = new Options (mySession, myPrefs, filename, this); 1273 o->show (); 1274 QApplication :: alert (o); 1275 } 1276 } 1277 1278 void 1279 TrMainWindow :: removeTorrents (const bool deleteFiles) 1280 { 1281 QSet<int> ids; 1282 QMessageBox msgBox (this); 1283 QString primary_text, secondary_text; 1284 int incomplete = 0; 1285 int connected = 0; 1286 int count; 1287 1288 foreach (QModelIndex index, ui.listView->selectionModel ()->selectedRows ()) 1289 { 1290 const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*> ()); 1291 ids.insert (tor->id ()); 1292 1293 if (tor->connectedPeers ()) 1294 ++connected; 1295 1296 if (!tor->isDone ()) 1297 ++incomplete; 1298 } 1299 1300 if (ids.isEmpty ()) 1301 return; 1302 1303 count = ids.size (); 1304 1305 if (!deleteFiles) 1306 { 1307 primary_text = (count == 1) 1308 ? tr ("Remove torrent?") 1309 : tr ("Remove %1 torrents?").arg (count); 1310 } 1311 else 1312 { 1313 primary_text = (count == 1) 1314 ? tr ("Delete this torrent's downloaded files?") 1315 : tr ("Delete these %1 torrents' downloaded files?").arg (count); 1316 } 1317 1318 if (!incomplete && !connected) 1319 { 1320 secondary_text = (count == 1) 1321 ? tr ("Once removed, continuing the transfer will require the torrent file or magnet link.") 1322 : tr ("Once removed, continuing the transfers will require the torrent files or magnet links."); 1323 } 1324 else if (count == incomplete) 1325 { 1326 secondary_text = (count == 1) 1327 ? tr ("This torrent has not finished downloading.") 1328 : tr ("These torrents have not finished downloading."); 1329 } 1330 else if (count == connected) 1331 { 1332 secondary_text = (count == 1) 1333 ? tr ("This torrent is connected to peers.") 1334 : tr ("These torrents are connected to peers."); 1335 } 1336 else 1337 { 1338 if (connected) 1321 1339 { 1322 secondary_text = ( connected == 1)1323 ? tr( "One of these torrents is connected to peers.")1324 : tr( "Some of these torrents are connected to peers.");1340 secondary_text = (connected == 1) 1341 ? tr ("One of these torrents is connected to peers.") 1342 : tr ("Some of these torrents are connected to peers."); 1325 1343 } 1326 1344 1327 if( connected && incomplete)1345 if (connected && incomplete) 1328 1346 { 1329 1347 secondary_text += "\n"; 1330 1348 } 1331 1349 1332 if( incomplete)1350 if (incomplete) 1333 1351 { 1334 secondary_text += ( incomplete == 1)1335 ? tr( "One of these torrents has not finished downloading.")1336 : tr( "Some of these torrents have not finished downloading.");1352 secondary_text += (incomplete == 1) 1353 ? tr ("One of these torrents has not finished downloading.") 1354 : tr ("Some of these torrents have not finished downloading."); 1337 1355 } 1338 1356 } 1339 1357 1340 msgBox.setWindowTitle( QString(" "));1341 msgBox.setText( QString( "<big><b>%1</big></b>" ).arg( primary_text ));1342 msgBox.setInformativeText( secondary_text);1343 msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel);1344 msgBox.setDefaultButton( QMessageBox::Cancel);1345 msgBox.setIcon( QMessageBox::Question);1346 1347 QGridLayout* layout = (QGridLayout*)msgBox.layout();1348 QSpacerItem* spacer = new QSpacerItem( 450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);1349 layout->addItem( spacer, layout->rowCount(), 0, 1, layout->columnCount());1350 1351 if( msgBox.exec() == QMessageBox::Ok)1352 { 1353 ui.listView->selectionModel()->clear();1354 mySession.removeTorrents( ids, deleteFiles);1358 msgBox.setWindowTitle (QString (" ")); 1359 msgBox.setText (QString ("<big><b>%1</big></b>").arg (primary_text)); 1360 msgBox.setInformativeText (secondary_text); 1361 msgBox.setStandardButtons (QMessageBox::Ok | QMessageBox::Cancel); 1362 msgBox.setDefaultButton (QMessageBox::Cancel); 1363 msgBox.setIcon (QMessageBox::Question); 1364 /* hack needed to keep the dialog from being too narrow */ 1365 QGridLayout* layout = (QGridLayout*)msgBox.layout (); 1366 QSpacerItem* spacer = new QSpacerItem (450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); 1367 layout->addItem (spacer, layout->rowCount (), 0, 1, layout->columnCount ()); 1368 1369 if (msgBox.exec () == QMessageBox::Ok) 1370 { 1371 ui.listView->selectionModel ()->clear (); 1372 mySession.removeTorrents (ids, deleteFiles); 1355 1373 } 1356 1374 } … … 1361 1379 1362 1380 void 1363 TrMainWindow :: updateNetworkIcon ()1364 { 1365 const time_t now = time ( NULL);1381 TrMainWindow :: updateNetworkIcon () 1382 { 1383 const time_t now = time (NULL); 1366 1384 const int period = 3; 1367 1385 const time_t secondsSinceLastSend = now - myLastSendTime; … … 1371 1389 const char * key; 1372 1390 1373 if ( isSending && isReading)1391 if (isSending && isReading) 1374 1392 key = "network-transmit-receive"; 1375 else if ( isSending)1393 else if (isSending) 1376 1394 key = "network-transmit"; 1377 else if ( isReading)1395 else if (isReading) 1378 1396 key = "network-receive"; 1379 1397 else … … 1383 1401 1384 1402 QString tip; 1385 const QString url = mySession.getRemoteUrl ().host();1386 if ( !myLastReadTime)1387 tip = tr ( "%1 has not responded yet").arg (url);1388 else if ( secondsSinceLastRead < 60)1389 tip = tr ( "%1 is responding").arg (url);1390 else if ( secondsSinceLastRead < (60*10))1391 tip = tr ( "%1 last responded %2 ago" ).arg(url).arg(Formatter::timeToString(secondsSinceLastRead));1403 const QString url = mySession.getRemoteUrl ().host (); 1404 if (!myLastReadTime) 1405 tip = tr ("%1 has not responded yet").arg (url); 1406 else if (secondsSinceLastRead < 60) 1407 tip = tr ("%1 is responding").arg (url); 1408 else if (secondsSinceLastRead < (60*10)) 1409 tip = tr ("%1 last responded %2 ago").arg (url).arg (Formatter::timeToString (secondsSinceLastRead)); 1392 1410 else 1393 tip = tr ( "%1 is not responding").arg (url);1411 tip = tr ("%1 is not responding").arg (url); 1394 1412 1395 1413 myNetworkLabel->setPixmap (pixmap); … … 1398 1416 1399 1417 void 1400 TrMainWindow :: onNetworkTimer ()1401 { 1402 updateNetworkIcon();1403 } 1404 1405 void 1406 TrMainWindow :: dataReadProgress ()1407 { 1408 myLastReadTime = time( NULL);1409 updateNetworkIcon();1410 } 1411 1412 void 1413 TrMainWindow :: dataSendProgress ()1414 { 1415 myLastSendTime = time( NULL);1416 updateNetworkIcon();1417 } 1418 1419 void 1420 TrMainWindow :: wrongAuthentication ()1421 { 1422 mySession.stop();1423 mySessionDialog->show();1418 TrMainWindow :: onNetworkTimer () 1419 { 1420 updateNetworkIcon (); 1421 } 1422 1423 void 1424 TrMainWindow :: dataReadProgress () 1425 { 1426 myLastReadTime = time (NULL); 1427 updateNetworkIcon (); 1428 } 1429 1430 void 1431 TrMainWindow :: dataSendProgress () 1432 { 1433 myLastSendTime = time (NULL); 1434 updateNetworkIcon (); 1435 } 1436 1437 void 1438 TrMainWindow :: wrongAuthentication () 1439 { 1440 mySession.stop (); 1441 mySessionDialog->show (); 1424 1442 } 1425 1443 … … 1429 1447 1430 1448 void 1431 TrMainWindow :: dragEnterEvent ( QDragEnterEvent * event)1432 { 1433 const QMimeData * mime = event->mimeData();1434 1435 if( mime->hasFormat("application/x-bittorrent")1436 || mime->text().trimmed().endsWith(".torrent", Qt::CaseInsensitive)1437 || mime->text().startsWith("magnet:", Qt::CaseInsensitive))1438 event->acceptProposedAction();1439 } 1440 1441 void 1442 TrMainWindow :: dropEvent ( QDropEvent * event)1443 { 1444 QString key = event->mimeData()->text().trimmed();1445 1446 const QUrl url( key);1447 if( url.scheme() == "file")1448 key = QUrl::fromPercentEncoding( url.path().toUtf8( ));1449 1450 dynamic_cast<MyApp*>(QApplication::instance())->addTorrent( key);1449 TrMainWindow :: dragEnterEvent (QDragEnterEvent * event) 1450 { 1451 const QMimeData * mime = event->mimeData (); 1452 1453 if (mime->hasFormat ("application/x-bittorrent") 1454 || mime->text ().trimmed ().endsWith (".torrent", Qt::CaseInsensitive) 1455 || mime->text ().startsWith ("magnet:", Qt::CaseInsensitive)) 1456 event->acceptProposedAction (); 1457 } 1458 1459 void 1460 TrMainWindow :: dropEvent (QDropEvent * event) 1461 { 1462 QString key = event->mimeData ()->text ().trimmed (); 1463 1464 const QUrl url (key); 1465 if (url.scheme () == "file") 1466 key = QUrl::fromPercentEncoding (url.path ().toUtf8 ()); 1467 1468 dynamic_cast<MyApp*> (QApplication::instance ())->addTorrent (key); 1451 1469 } 1452 1470 … … 1456 1474 1457 1475 void 1458 TrMainWindow :: contextMenuEvent ( QContextMenuEvent * event)1459 { 1460 QMenu * menu = new QMenu( this);1461 1462 menu->addAction( ui.action_Properties);1463 menu->addAction( ui.action_OpenFolder);1464 1465 QAction * sep = new QAction( this);1466 sep->setSeparator( true);1467 menu->addAction( sep);1468 menu->addAction( ui.action_Start);1469 menu->addAction( ui.action_StartNow);1470 menu->addAction( ui.action_Announce);1471 QMenu * queueMenu = menu->addMenu( tr( "Queue" ));1472 queueMenu->addAction( ui.action_QueueMoveTop);1473 queueMenu->addAction( ui.action_QueueMoveUp);1474 queueMenu->addAction( ui.action_QueueMoveDown);1475 queueMenu->addAction( ui.action_QueueMoveBottom);1476 menu->addAction( ui.action_Pause);1477 1478 sep = new QAction( this);1479 sep->setSeparator( true);1480 menu->addAction( sep);1481 menu->addAction( ui.action_Verify);1482 menu->addAction( ui.action_SetLocation);1483 menu->addAction( ui.action_CopyMagnetToClipboard);1484 1485 sep = new QAction( this);1486 sep->setSeparator( true);1487 menu->addAction( sep);1488 menu->addAction( ui.action_Remove);1489 menu->addAction( ui.action_Delete);1490 1491 menu->popup( event->globalPos( ));1492 } 1476 TrMainWindow :: contextMenuEvent (QContextMenuEvent * event) 1477 { 1478 QMenu * menu = new QMenu (this); 1479 1480 menu->addAction (ui.action_Properties); 1481 menu->addAction (ui.action_OpenFolder); 1482 1483 QAction * sep = new QAction (this); 1484 sep->setSeparator (true); 1485 menu->addAction (sep); 1486 menu->addAction (ui.action_Start); 1487 menu->addAction (ui.action_StartNow); 1488 menu->addAction (ui.action_Announce); 1489 QMenu * queueMenu = menu->addMenu (tr ("Queue")); 1490 queueMenu->addAction (ui.action_QueueMoveTop); 1491 queueMenu->addAction (ui.action_QueueMoveUp); 1492 queueMenu->addAction (ui.action_QueueMoveDown); 1493 queueMenu->addAction (ui.action_QueueMoveBottom); 1494 menu->addAction (ui.action_Pause); 1495 1496 sep = new QAction (this); 1497 sep->setSeparator (true); 1498 menu->addAction (sep); 1499 menu->addAction (ui.action_Verify); 1500 menu->addAction (ui.action_SetLocation); 1501 menu->addAction (ui.action_CopyMagnetToClipboard); 1502 1503 sep = new QAction (this); 1504 sep->setSeparator (true); 1505 menu->addAction (sep); 1506 menu->addAction (ui.action_Remove); 1507 menu->addAction (ui.action_Delete); 1508 1509 menu->popup (event->globalPos ()); 1510 } -
trunk/qt/mainwin.h
r13883 r13886 50 50 class TrMainWindow: public QMainWindow 51 51 { 52 53 54 55 virtual void hideEvent( QHideEvent * event);56 virtual void showEvent( QShowEvent * event);57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 QIcon getStockIcon( const QString&, int fallback=-1);90 91 92 QSet<int> getSelectedTorrents() const;93 void updateNetworkIcon();94 95 96 97 void openURL( QString);98 99 100 void onPrefsDestroyed();101 void openPreferences();102 void onDetailsDestroyed();103 void showTotalRatio();104 void showTotalTransfer();105 void showSessionRatio();106 void showSessionTransfer();107 void refreshVisibleCount();108 void refreshFreeSpace();109 void refreshTitle();110 void refreshStatusBar();111 void refreshTrayIcon();112 void refreshTrayIconSoon();113 void openTorrent();114 void openURL();115 void newTorrent();116 void trayActivated( QSystemTrayIcon::ActivationReason);117 void refreshPref( int key);118 void addTorrents( const QStringList& filenames);119 void removeTorrents( const bool deleteFiles);120 void openDonate();121 void openHelp();122 void openFolder();123 void copyMagnetLinkToClipboard();124 void setLocation();125 void openProperties();126 void toggleSpeedMode();127 void dataReadProgress();128 void dataSendProgress();129 void toggleWindows( bool doShow);130 void onSetPrefs();131 void onSetPrefs( bool);132 void onSessionSourceChanged();133 void onModelReset();134 135 136 void setSortPref ( int);137 void setSortAscendingPref ( bool);138 void onSortByActivityToggled ( bool);139 void onSortByAgeToggled ( bool);140 void onSortByETAToggled ( bool);141 void onSortByNameToggled ( bool);142 void onSortByProgressToggled ( bool);143 void onSortByQueueToggled ( bool);144 void onSortByRatioToggled ( bool);145 void onSortBySizeToggled ( bool);146 void onSortByStateToggled ( bool);147 148 149 150 151 152 QMenu * createOptionsMenu( void);153 QWidget * createStatusBar( void);154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 void startAll();169 void startSelected();170 void startSelectedNow();171 void pauseAll();172 void pauseSelected();173 void removeSelected();174 void deleteSelected();175 void verifySelected();176 void queueMoveTop();177 void queueMoveUp();178 void queueMoveDown();179 void queueMoveBottom();180 void reannounceSelected();181 void addTorrent( const QString& filename);182 void onNetworkTimer();183 184 185 void clearSelection();186 187 188 void setToolbarVisible( bool);189 void setFilterbarVisible( bool);190 void setStatusbarVisible( bool);191 void setCompactView( bool);192 void refreshActionSensitivity();193 void refreshActionSensitivitySoon();194 void wrongAuthentication();195 196 197 TrMainWindow( Session&, Prefs&, TorrentModel&, bool minized);198 virtual ~TrMainWindow();199 200 201 virtual void contextMenuEvent( QContextMenuEvent *);202 virtual void dragEnterEvent( QDragEnterEvent *);203 virtual void dropEvent( QDropEvent *);52 Q_OBJECT 53 54 private: 55 virtual void hideEvent (QHideEvent * event); 56 virtual void showEvent (QShowEvent * event); 57 58 private: 59 time_t myLastFullUpdateTime; 60 QDialog * mySessionDialog; 61 QDialog * myPrefsDialog; 62 QDialog * myAboutDialog; 63 QDialog * myStatsDialog; 64 Details * myDetailsDialog; 65 QCheckBox * myFileDialogOptionsCheck; 66 QSystemTrayIcon myTrayIcon; 67 TorrentFilter myFilterModel; 68 TorrentDelegate * myTorrentDelegate; 69 TorrentDelegateMin * myTorrentDelegateMin; 70 Session& mySession; 71 Prefs& myPrefs; 72 TorrentModel& myModel; 73 Ui_MainWindow ui; 74 QIcon mySpeedModeOffIcon; 75 QIcon mySpeedModeOnIcon; 76 time_t myLastSendTime; 77 time_t myLastReadTime; 78 QTimer myNetworkTimer; 79 QTimer myRefreshTrayIconTimer; 80 QTimer myRefreshActionSensitivityTimer; 81 QAction * myDlimitOffAction; 82 QAction * myDlimitOnAction; 83 QAction * myUlimitOffAction; 84 QAction * myUlimitOnAction; 85 QAction * myRatioOffAction; 86 QAction * myRatioOnAction; 87 88 private: 89 QIcon getStockIcon (const QString&, int fallback=-1); 90 91 private: 92 QSet<int> getSelectedTorrents () const; 93 void updateNetworkIcon (); 94 QWidgetList myHidden; 95 96 public slots: 97 void openURL (QString); 98 99 private slots: 100 void onPrefsDestroyed (); 101 void openPreferences (); 102 void onDetailsDestroyed (); 103 void showTotalRatio (); 104 void showTotalTransfer (); 105 void showSessionRatio (); 106 void showSessionTransfer (); 107 void refreshVisibleCount (); 108 void refreshFreeSpace (); 109 void refreshTitle (); 110 void refreshStatusBar (); 111 void refreshTrayIcon (); 112 void refreshTrayIconSoon (); 113 void openTorrent (); 114 void openURL (); 115 void newTorrent (); 116 void trayActivated (QSystemTrayIcon::ActivationReason); 117 void refreshPref (int key); 118 void addTorrents (const QStringList& filenames); 119 void removeTorrents (const bool deleteFiles); 120 void openDonate (); 121 void openHelp (); 122 void openFolder (); 123 void copyMagnetLinkToClipboard (); 124 void setLocation (); 125 void openProperties (); 126 void toggleSpeedMode (); 127 void dataReadProgress (); 128 void dataSendProgress (); 129 void toggleWindows (bool doShow); 130 void onSetPrefs (); 131 void onSetPrefs (bool); 132 void onSessionSourceChanged (); 133 void onModelReset (); 134 135 private slots: 136 void setSortPref (int); 137 void setSortAscendingPref (bool); 138 void onSortByActivityToggled (bool); 139 void onSortByAgeToggled (bool); 140 void onSortByETAToggled (bool); 141 void onSortByNameToggled (bool); 142 void onSortByProgressToggled (bool); 143 void onSortByQueueToggled (bool); 144 void onSortByRatioToggled (bool); 145 void onSortBySizeToggled (bool); 146 void onSortByStateToggled (bool); 147 148 private: 149 QWidget * myFilterBar; 150 151 private: 152 QMenu * createOptionsMenu (void); 153 QWidget * createStatusBar (void); 154 QWidget * myStatusBar; 155 QPushButton * myAltSpeedButton; 156 QAction * myAltSpeedAction; 157 QPushButton * myOptionsButton; 158 QLabel * myVisibleCountLabel; 159 QPushButton * myStatsModeButton; 160 QLabel * myStatsLabel; 161 QLabel * myDownloadSpeedLabel; 162 QLabel * myUploadSpeedLabel; 163 QLabel * myFreeSpaceTextLabel; 164 QLabel * myFreeSpaceIconLabel; 165 QLabel * myNetworkLabel; 166 167 public slots: 168 void startAll (); 169 void startSelected (); 170 void startSelectedNow (); 171 void pauseAll (); 172 void pauseSelected (); 173 void removeSelected (); 174 void deleteSelected (); 175 void verifySelected (); 176 void queueMoveTop (); 177 void queueMoveUp (); 178 void queueMoveDown (); 179 void queueMoveBottom (); 180 void reannounceSelected (); 181 void addTorrent (const QString& filename); 182 void onNetworkTimer (); 183 184 private: 185 void clearSelection (); 186 187 public slots: 188 void setToolbarVisible (bool); 189 void setFilterbarVisible (bool); 190 void setStatusbarVisible (bool); 191 void setCompactView (bool); 192 void refreshActionSensitivity (); 193 void refreshActionSensitivitySoon (); 194 void wrongAuthentication (); 195 196 public: 197 TrMainWindow (Session&, Prefs&, TorrentModel&, bool minized); 198 virtual ~TrMainWindow (); 199 200 protected: 201 virtual void contextMenuEvent (QContextMenuEvent *); 202 virtual void dragEnterEvent (QDragEnterEvent *); 203 virtual void dropEvent (QDropEvent *); 204 204 }; 205 205
Note: See TracChangeset
for help on using the changeset viewer.