mirror of
https://github.com/transmission/transmission
synced 2024-12-23 08:13:27 +00:00
make speed tab's colors user-configurable
This commit is contained in:
parent
6323a59c6a
commit
3ce8d7bfd6
3 changed files with 82 additions and 12 deletions
|
@ -61,6 +61,36 @@ SpeedStats :: ~SpeedStats()
|
|||
delete myBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
|
||||
void
|
||||
SpeedStats :: SetColor( int i, const wxColour& c )
|
||||
{
|
||||
assert( 0<=i && i<N_COLORS );
|
||||
|
||||
myColors[i] = c;
|
||||
}
|
||||
|
||||
wxString
|
||||
SpeedStats :: GetColorName( int i )
|
||||
{
|
||||
static const wxString xstr[N_COLORS] = {
|
||||
_T("background"), _T("frame"),
|
||||
_T("torrent-up"), _T("torrent-down"),
|
||||
_T("all-up"), _T("all-down")
|
||||
};
|
||||
|
||||
wxString ret = _T("speed-color-");
|
||||
ret += xstr[i];
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
|
||||
void
|
||||
SpeedStats :: OnSize( wxSizeEvent& event )
|
||||
{
|
||||
|
|
|
@ -51,6 +51,22 @@ class SpeedStats: public wxPanel
|
|||
|
||||
void Pulse( tr_handle_t * handle );
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
BACKGROUND,
|
||||
FRAME,
|
||||
TORRENT_UP,
|
||||
TORRENT_DOWN,
|
||||
ALL_UP,
|
||||
ALL_DOWN,
|
||||
N_COLORS
|
||||
};
|
||||
|
||||
void SetColor( int, const wxColour& );
|
||||
|
||||
static wxString GetColorName( int );
|
||||
|
||||
private:
|
||||
|
||||
virtual void OnSize( wxSizeEvent& event );
|
||||
|
@ -85,16 +101,6 @@ class SpeedStats: public wxPanel
|
|||
|
||||
int myHistory;
|
||||
|
||||
enum {
|
||||
BACKGROUND,
|
||||
FRAME,
|
||||
TORRENT_UP,
|
||||
TORRENT_DOWN,
|
||||
ALL_UP,
|
||||
ALL_DOWN,
|
||||
N_COLORS
|
||||
};
|
||||
|
||||
wxColour myColors[N_COLORS];
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
@ -499,6 +500,10 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
|
|||
myTrayIcon = new wxTaskBarIcon;
|
||||
SetIcon( myLogoIcon );
|
||||
|
||||
/**
|
||||
*** Prefs
|
||||
**/
|
||||
|
||||
long port;
|
||||
wxString key = _T("port");
|
||||
if( !myConfig->Read( key, &port, 9090 ) )
|
||||
|
@ -508,9 +513,36 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
|
|||
key = _T("save-path");
|
||||
wxString wxstr;
|
||||
if( !myConfig->Read( key, &wxstr, wxFileName::GetHomeDir() ) )
|
||||
myConfig->Write( key, wxstr );
|
||||
myConfig->Write( key, wxstr );
|
||||
mySavePath = toStr( wxstr );
|
||||
std::cerr << __FILE__ << ':' << __LINE__ << " save-path is [" << mySavePath << ']' << std::endl;
|
||||
|
||||
const wxString default_colors[SpeedStats::N_COLORS] = {
|
||||
_T("#000000"), // background
|
||||
_T("#32cd32"), // frame
|
||||
_T("#ff0000"), // all up
|
||||
_T("#ff00ff"), // all down
|
||||
_T("#ffff00"), // torrent up
|
||||
_T("#00ff88") // torrent down
|
||||
};
|
||||
wxColor speedColors[SpeedStats::N_COLORS];
|
||||
for( int i=0; i<SpeedStats::N_COLORS; ++i )
|
||||
{
|
||||
key = SpeedStats::GetColorName( i );
|
||||
myConfig->Read( key, &wxstr, _T("") );
|
||||
std::string str = toStr( wxstr );
|
||||
if( (str.size()!=7)
|
||||
|| (str[0]!='#')
|
||||
|| !isxdigit(str[1]) || !isxdigit(str[2])
|
||||
|| !isxdigit(str[3]) || !isxdigit(str[4])
|
||||
|| !isxdigit(str[5]) || !isxdigit(str[6]))
|
||||
{
|
||||
myConfig->Write( key, default_colors[i] );
|
||||
str = toStr( default_colors[i] );
|
||||
}
|
||||
int r, g, b;
|
||||
sscanf( str.c_str()+1, "%02x%02x%02x", &r, &g, &b );
|
||||
speedColors[i].Set( r, g, b );
|
||||
}
|
||||
|
||||
/**
|
||||
*** Menu
|
||||
|
@ -614,6 +646,8 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
|
|||
tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
||||
notebook->AddPage( tmp, _T("Files") );
|
||||
mySpeedStats = new SpeedStats( notebook, wxID_ANY );
|
||||
for( int i=0; i<SpeedStats::N_COLORS; ++i )
|
||||
mySpeedStats->SetColor( i, speedColors[i] );
|
||||
notebook->AddPage( mySpeedStats, _T("Speed"), true );
|
||||
tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
||||
notebook->AddPage( tmp, _T("Logger") );
|
||||
|
|
Loading…
Reference in a new issue