Changeset 2464


Ignore:
Timestamp:
Jul 23, 2007, 5:43:16 AM (15 years ago)
Author:
charles
Message:

added a taskbar icon for Xmission, showing the total ul/dl speed in its tooltip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wx/xmission.cc

    r2461 r2464  
    1919#include <wx/config.h>
    2020#include <wx/listctrl.h>
     21#include <wx/taskbar.h>
    2122#include <wx/toolbar.h>
    2223#include <wx/splitter.h>
     
    5859    void repopulateTorrentList ();
    5960    void refreshTorrentList ();
    60     wxListCtrl * myTorrentList;
    6161    typedef std::vector<tr_torrent_t*> torrents_t;
    6262    torrents_t myTorrents;
     
    6767    /** torrent hash -> the torrent's row in myTorrentList */
    6868    str2int_t myHashToRow;
     69
     70    wxListCtrl * myTorrentList;
     71    wxTaskBarIcon * myTaskBarIcon;
     72    wxIcon * myLogoIcon;
     73    wxIcon * myTrayLogo;
    6974};
    7075
     
    120125
    121126    frame->Connect( wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnOpen );
     127    frame->Connect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnAbout );
    122128    frame->Connect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnQuit );
    123     frame->Connect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnAbout );
    124129    frame->Connect( ID_Pulse, wxEVT_TIMER, (wxObjectEventFunction) &MyFrame::OnTimer );
    125130
     
    217222    }
    218223
    219     std::string getReadableSize( uint64_t size )
     224    wxString toWxStr( const std::string& s )
     225    {
     226        return wxString( s.c_str(), wxConvUTF8 );
     227    }
     228
     229    wxString toWxStr( const char * s )
     230    {
     231        return wxString( s, wxConvUTF8 );
     232    }
     233
     234    wxString getReadableSize( uint64_t size )
    220235    {
    221236        int i;
    222237        static const char *sizestrs[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" };
    223             //N_("B"), N_("KiB"), N_("MiB"), N_("GiB"), N_("TiB"), N_("PiB"), N_("EiB") };
    224         for ( i=0; size>>10; ++i )
    225             size = size>>10;
     238        for ( i=0; size>>10; ++i ) size = size>>10;
    226239        char buf[512];
    227240        snprintf( buf, sizeof(buf), "%.*f %s", bestDecimal(size), (double)size, sizestrs[i] );
    228         return buf;
    229     }
    230     std::string getReadableSize( float f )
     241        return toWxStr( buf );
     242    }
     243
     244    wxString getReadableSize( float f )
    231245    {
    232246        return getReadableSize( (uint64_t)f );
    233247    }
    234248
    235     std::string getReadableTime( int i /*seconds*/ )  /*FIXME*/
     249    wxString getReadableSpeed( float f )
     250    {
     251        wxString xstr = getReadableSize(f);
     252        xstr += _T("/s");
     253        return xstr;
     254    }
     255
     256    wxString getReadableTime( int i /*seconds*/ )  /*FIXME*/
    236257    {
    237258        const int s = i % 60; i /= 60;
    238259        const int m = i % 60; i /= 60;
    239260        const int h = i;
    240         char buf[64];
    241         snprintf( buf, sizeof(buf), "%d:%02d:%02d", h, m, s);
    242         return buf;
    243     }
    244 
    245     wxString toWxStr( const std::string& s )
    246     {
    247         return wxString( s.c_str(), wxConvUTF8 );
    248     }
    249 
    250     wxString toWxStr( const char * s )
    251     {
    252         return wxString( s, wxConvUTF8 );
     261        return wxString::Format( _T("%d:%02d:%02d"), h, m, s );
    253262    }
    254263}
     
    299308
    300309            case COL_DOWNLOAD_SPEED: break;
    301                 xstr = toWxStr( getReadableSize( s->rateDownload ) + "/s" );
     310                xstr = getReadableSpeed( s->rateDownload );
    302311                break;
    303312
     
    308317                    xstr = toWxStr( "\xE2\x88\x9E" ); /* infinity, in utf-8 */
    309318                else
    310                     xstr = toWxStr( getReadableTime( s->eta ) );
     319                    xstr = getReadableTime( s->eta );
    311320                break;
    312321               
     
    331340
    332341            case COL_RECEIVED:
    333                 xstr = toWxStr( getReadableSize( s->downloaded ) );
     342                xstr = getReadableSize( s->downloaded );
    334343                break;
    335344
    336345            case COL_REMAINING:
    337                 xstr = toWxStr( getReadableSize( s->left ) );
     346                xstr = getReadableSize( s->left );
    338347                break;
    339348
     
    344353
    345354            case COL_SENT:
    346                 xstr = toWxStr( getReadableSize( s->uploaded ) );
     355                xstr = getReadableSize( s->uploaded );
    347356                break;
    348357
    349358            case COL_SIZE:
    350                 xstr = toWxStr( getReadableSize( info->totalSize ) );
     359                xstr = getReadableSize( info->totalSize );
    351360                break;
    352361
     
    364373
    365374            case COL_UPLOAD_SPEED:
    366                 xstr = toWxStr( getReadableSize( s->rateUpload ) + "/s" );
     375                xstr = getReadableSpeed( s->rateUpload );
    367376                break;
    368377
     
    413422MyFrame :: repopulateTorrentList ()
    414423{
    415 std::cerr << __FILE__ << ':' << __LINE__ << " clearing all items from list" << std::endl;
    416424    myTorrentList->DeleteAllItems();
    417425    myHashToRow.clear ();
     
    474482{
    475483    refreshTorrentList ();
     484
     485
     486    float dl, ul;
     487    tr_torrentRates( handle, &dl, &ul );
     488    wxString s = _("Download: ");
     489    s += getReadableSpeed( dl );
     490    s += _T("\n");
     491    s +=_("Upload: ");
     492    s +=  getReadableSpeed( ul );
     493    myTaskBarIcon->SetIcon( *myTrayLogo, s );
    476494}
    477495
     
    488506    wxImage::AddHandler( new wxPNGHandler );
    489507    wxImage transmission_logo ( _T("images/transmission.png"), wxBITMAP_TYPE_PNG );
    490     wxIcon ico;
    491     ico.CopyFromBitmap( wxBitmap( transmission_logo ) );
    492     SetIcon( ico );
     508    myLogoIcon = new wxIcon;
     509    myLogoIcon->CopyFromBitmap( wxBitmap( transmission_logo ) );
     510    SetIcon( *myLogoIcon );
     511#if wxCHECK_VERSION(2,8,0)
     512    transmission_logo.Rescale( 24, 24, wxIMAGE_QUALITY_HIGH );
     513#else
     514    transmission_logo.Rescale( 24, 24 );
     515#endif
     516    myTrayLogo = new wxIcon;
     517    myTrayLogo->CopyFromBitmap( wxBitmap( transmission_logo ) );
    493518
    494519    /**
     
    615640
    616641    myPulseTimer.Start( 1500 );
     642
     643    myTaskBarIcon = new wxTaskBarIcon( );
    617644}
    618645
    619646void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
    620647{
    621     Close(TRUE);
     648    Close( true );
    622649}
    623650
Note: See TracChangeset for help on using the changeset viewer.