Ticket #1982: 1982_TransferSpeed.patch

File 1982_TransferSpeed.patch, 5.8 KB (added by David, 11 years ago)
  • src/interface/led.cpp

     
    66#define new DEBUG_NEW
    77#endif
    88
     9DEFINE_EVENT_TYPE(fzEVT_UPDATE_LED_TOOLTIP)
     10
    911BEGIN_EVENT_TABLE(CLed, wxWindow)
    1012    EVT_PAINT(CLed::OnPaint)
    1113    EVT_TIMER(wxID_ANY, CLed::OnTimer)
     14    EVT_ENTER_WINDOW(CLed::OnEnterWindow)
    1215#ifdef __WXMSW__
    1316    EVT_ERASE_BACKGROUND(CLed::OnEraseBackground)
    1417#endif
     
    9497    return;
    9598}
    9699
     100void CLed::OnEnterWindow(wxMouseEvent& event)
     101{
     102    wxCommandEvent requestUpdateEvent(fzEVT_UPDATE_LED_TOOLTIP, GetId());
     103    requestUpdateEvent.SetEventObject(this);
     104    GetEventHandler()->ProcessEvent(requestUpdateEvent);
     105}
     106
    97107void CLed::Ping()
    98108{
    99109    if (!m_loaded)
  • src/interface/led.h

     
    11#ifndef __LED_H__
    22#define __LED_H__
    33
     4#include "wx/event.h"
     5
    46class CFileZillaEngine;
     7
     8DECLARE_EVENT_TYPE(fzEVT_UPDATE_LED_TOOLTIP, -1)
     9
    510class CLed : public wxWindow
    611{
    712public:
     
    2530    DECLARE_EVENT_TABLE()
    2631    void OnPaint(wxPaintEvent& event);
    2732    void OnTimer(wxTimerEvent& event);
     33    void OnEnterWindow(wxMouseEvent& event);
    2834#ifdef __WXMSW__
    2935    void OnEraseBackground(wxEraseEvent& event);
    3036#endif
  • src/interface/Mainfrm.cpp

     
    7373    EVT_SIZE(CMainFrame::OnSize)
    7474    EVT_MENU(wxID_ANY, CMainFrame::OnMenuHandler)
    7575    EVT_FZ_NOTIFICATION(wxID_ANY, CMainFrame::OnEngineEvent)
     76    EVT_COMMAND(wxID_ANY, fzEVT_UPDATE_LED_TOOLTIP, CMainFrame::OnUpdateLedTooltip)
    7677    EVT_TOOL(XRCID("ID_TOOLBAR_DISCONNECT"), CMainFrame::OnDisconnect)
    7778    EVT_MENU(XRCID("ID_MENU_SERVER_DISCONNECT"), CMainFrame::OnDisconnect)
    7879    EVT_TOOL(XRCID("ID_TOOLBAR_CANCEL"), CMainFrame::OnCancel)
     
    10501051    }
    10511052}
    10521053
     1054void CMainFrame::OnUpdateLedTooltip(wxCommandEvent& event)
     1055{
     1056    wxString tooltipText;
     1057
     1058    wxFileOffset downloadSpeed = m_pQueueView->GetCurrentDownloadSpeed();
     1059    wxFileOffset uploadSpeed = m_pQueueView->GetCurrentUploadSpeed();
     1060
     1061    CSizeFormat::_format format = static_cast<CSizeFormat::_format>(COptions::Get()->GetOptionVal(OPTION_SIZE_FORMAT));
     1062    if (format == CSizeFormat::bytes)
     1063        format = CSizeFormat::iec;
     1064
     1065    const wxString downloadSpeedStr = CSizeFormat::Format(downloadSpeed, true, format,
     1066                                                          COptions::Get()->GetOptionVal(OPTION_SIZE_USETHOUSANDSEP) != 0,
     1067                                                          COptions::Get()->GetOptionVal(OPTION_SIZE_DECIMALPLACES));
     1068    const wxString uploadSpeedStr = CSizeFormat::Format(uploadSpeed, true, format,
     1069                                                        COptions::Get()->GetOptionVal(OPTION_SIZE_USETHOUSANDSEP) != 0,
     1070                                                        COptions::Get()->GetOptionVal(OPTION_SIZE_DECIMALPLACES));
     1071    tooltipText.Printf(_("Download speed: %s/s\nUpload speed: %s/s"), downloadSpeedStr.c_str(), uploadSpeedStr.c_str());
     1072
     1073    m_pActivityLed[0]->SetToolTip(tooltipText);
     1074    m_pActivityLed[1]->SetToolTip(tooltipText);
     1075}
     1076
    10531077bool CMainFrame::CreateToolBar()
    10541078{
    10551079    if (m_pToolBar)
  • src/interface/Mainfrm.h

     
    109109    void OnSize(wxSizeEvent& event);
    110110    void OnMenuHandler(wxCommandEvent& event);
    111111    void OnEngineEvent(wxEvent& event);
     112    void OnUpdateLedTooltip(wxCommandEvent& event);
    112113    void OnDisconnect(wxCommandEvent& event);
    113114    void OnCancel(wxCommandEvent& event);
    114115    void OnClose(wxCloseEvent& event);
  • src/interface/QueueView.cpp

     
    34903490    return result;
    34913491}
    34923492
     3493wxFileOffset CQueueView::GetCurrentDownloadSpeed(void)
     3494{
     3495    wxFileOffset speed = GetCurrentSpeed(true, false);
     3496    return speed;
     3497}
     3498
     3499wxFileOffset CQueueView::GetCurrentUploadSpeed(void)
     3500{
     3501    wxFileOffset speed = GetCurrentSpeed(false, true);
     3502    return speed;
     3503}
     3504
     3505wxFileOffset CQueueView::GetCurrentSpeed(bool countDownload, bool countUpload)
     3506{
     3507    wxFileOffset speed = 0;
     3508
     3509    for (std::list<CStatusLineCtrl*>::iterator iter = m_statusLineList.begin(); iter != m_statusLineList.end(); ++iter)
     3510    {
     3511        CStatusLineCtrl *pCtrl = *iter;
     3512        const CFileItem *pItem = pCtrl->GetItem();
     3513        bool isDownload = pItem->Download();
     3514
     3515        if ((isDownload && countDownload) || (!isDownload && countUpload))
     3516        {
     3517            speed += pCtrl->GetCurrentSpeed();
     3518        }
     3519    }
     3520
     3521    return speed;
     3522}
     3523
    34933524void CQueueView::ReleaseExclusiveEngineLock(CFileZillaEngine* pEngine)
    34943525{
    34953526    wxASSERT(pEngine);
  • src/interface/QueueView.h

     
    143143
    144144    static wxString ReplaceInvalidCharacters(const wxString& filename);
    145145
     146    // Get the current download speed as the sum of all active downloads.
     147    // Unit is byte/s.
     148    wxFileOffset GetCurrentDownloadSpeed(void);
     149
     150    // Get the current upload speed as the sum of all active uploads.
     151    // Unit is byte/s.
     152    wxFileOffset GetCurrentUploadSpeed(void);
     153
    146154protected:
    147155
    148156#ifdef __WXMSW__
     
    282290
    283291    CQueueStorage m_queue_storage;
    284292
     293    // Get the current transfer speed.
     294    // Unit is byte/s.
     295    wxFileOffset GetCurrentSpeed(bool countDownload, bool countUpload);
     296
    285297    DECLARE_EVENT_TABLE();
    286298    void OnEngineEvent(wxEvent &event);
    287299    void OnFolderThreadComplete(wxCommandEvent& event);