2007-07-19 20:35:01 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2007-07-19 14:06:50 +00:00
|
|
|
#include <iostream>
|
2007-07-22 02:24:13 +00:00
|
|
|
#include <stdint.h>
|
2007-07-19 14:06:50 +00:00
|
|
|
#include <wx/artprov.h>
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/config.h>
|
|
|
|
#include <wx/toolbar.h>
|
2007-07-19 19:05:55 +00:00
|
|
|
#include <wx/splitter.h>
|
|
|
|
#include <wx/notebook.h>
|
2007-07-19 14:06:50 +00:00
|
|
|
#include <wx/wx.h>
|
2007-07-20 02:12:07 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,0)
|
|
|
|
#include <wx/aboutdlg.h>
|
|
|
|
#endif
|
2007-07-19 14:06:50 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <libtransmission/transmission.h>
|
2007-07-22 02:24:13 +00:00
|
|
|
#include <libtransmission/utils.h>
|
2007-07-19 14:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
tr_handle_t * handle = NULL;
|
|
|
|
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
|
|
|
virtual ~MyFrame();
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnOpen(wxCommandEvent& event);
|
2007-07-22 19:37:43 +00:00
|
|
|
void OnTimer(wxTimerEvent& event);
|
2007-07-19 14:06:50 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
wxConfig * myConfig;
|
2007-07-22 19:37:43 +00:00
|
|
|
wxTimer myPulseTimer;
|
2007-07-19 20:35:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void rebuildTorrentList();
|
2007-07-22 02:24:13 +00:00
|
|
|
void repopulateTorrentList ();
|
2007-07-22 19:37:43 +00:00
|
|
|
void refreshTorrentList ();
|
2007-07-19 20:35:01 +00:00
|
|
|
wxListCtrl * myTorrentList;
|
2007-07-22 02:24:13 +00:00
|
|
|
typedef std::vector<tr_torrent_t*> torrents_t;
|
|
|
|
torrents_t myTorrents;
|
2007-07-22 19:37:43 +00:00
|
|
|
void refreshTorrent( tr_torrent_t*, int, const std::vector<int>& );
|
|
|
|
|
|
|
|
typedef std::map<std::string,int> str2int_t;
|
|
|
|
|
|
|
|
/** torrent hash -> the torrent's row in myTorrentList */
|
|
|
|
str2int_t myHashToRow;
|
2007-07-19 14:06:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID_START,
|
|
|
|
ID_STOP,
|
|
|
|
ID_REMOVE,
|
|
|
|
ID_QUIT,
|
|
|
|
ID_TORRENT_INFO,
|
|
|
|
ID_EDIT_PREFS,
|
|
|
|
ID_SHOW_DEBUG_WINDOW,
|
|
|
|
ID_ABOUT,
|
2007-07-22 19:37:43 +00:00
|
|
|
ID_Pulse,
|
2007-07-19 14:06:50 +00:00
|
|
|
N_IDS
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame :: OnOpen( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
const wxString key = _T("LastDirectory");
|
|
|
|
wxString directory;
|
|
|
|
myConfig->Read( key, &directory );
|
|
|
|
wxFileDialog * w = new wxFileDialog( this, _T("message"),
|
|
|
|
directory,
|
|
|
|
_T(""), /* default file */
|
|
|
|
_T("Torrent files|*.torrent"),
|
|
|
|
wxOPEN|wxMULTIPLE );
|
|
|
|
|
|
|
|
if( w->ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
wxArrayString paths;
|
|
|
|
w->GetPaths( paths );
|
|
|
|
size_t nPaths = paths.GetCount();
|
|
|
|
for( size_t i=0; i<nPaths; ++i )
|
|
|
|
{
|
|
|
|
const wxString& w = paths[i];
|
|
|
|
std::cerr << w.ToAscii() << std::endl;
|
|
|
|
}
|
|
|
|
myConfig->Write( key, w->GetDirectory() );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
handle = tr_init( "wx" );
|
|
|
|
|
2007-07-19 14:50:42 +00:00
|
|
|
MyFrame * frame = new MyFrame( _T("Xmission"),
|
2007-07-19 14:06:50 +00:00
|
|
|
wxPoint(50,50),
|
|
|
|
wxSize(450,350));
|
|
|
|
|
|
|
|
frame->Connect( wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnOpen );
|
|
|
|
frame->Connect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnQuit );
|
|
|
|
frame->Connect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnAbout );
|
2007-07-22 19:37:43 +00:00
|
|
|
frame->Connect( ID_Pulse, wxEVT_TIMER, (wxObjectEventFunction) &MyFrame::OnTimer );
|
2007-07-19 14:06:50 +00:00
|
|
|
|
|
|
|
frame->Show( true );
|
|
|
|
SetTopWindow( frame );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2007-07-19 20:35:01 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COL_NUMBER,
|
|
|
|
COL_DONE,
|
|
|
|
COL_DOWNLOAD_SPEED,
|
|
|
|
COL_ETA,
|
|
|
|
COL_HASH,
|
|
|
|
COL_NAME,
|
|
|
|
COL_PEERS,
|
|
|
|
COL_RATIO,
|
|
|
|
COL_RECEIVED,
|
|
|
|
COL_REMAINING,
|
|
|
|
COL_SEEDS,
|
2007-07-22 02:24:13 +00:00
|
|
|
COL_SENT,
|
2007-07-19 20:35:01 +00:00
|
|
|
COL_SIZE,
|
|
|
|
COL_STATE,
|
|
|
|
COL_STATUS,
|
|
|
|
COL_TOTAL,
|
|
|
|
COL_UPLOAD_SPEED,
|
|
|
|
N_COLS
|
|
|
|
};
|
|
|
|
|
2007-07-20 02:12:07 +00:00
|
|
|
int getTorrentColumn( const wxString& key )
|
2007-07-19 20:35:01 +00:00
|
|
|
{
|
2007-07-20 02:12:07 +00:00
|
|
|
typedef std::map<wxString,int> string2key_t;
|
2007-07-19 20:35:01 +00:00
|
|
|
static string2key_t columns;
|
|
|
|
|
|
|
|
if( columns.empty() )
|
|
|
|
{
|
2007-07-20 02:12:07 +00:00
|
|
|
columns[_T("#")] = COL_NUMBER;
|
|
|
|
columns[_T("done")] = COL_DONE;
|
|
|
|
columns[_T("dspeed")] = COL_DOWNLOAD_SPEED;
|
|
|
|
columns[_T("eta")] = COL_ETA;
|
|
|
|
columns[_T("hash")] = COL_HASH;
|
|
|
|
columns[_T("name")] = COL_NAME;
|
|
|
|
columns[_T("peers")] = COL_PEERS;
|
|
|
|
columns[_T("ratio")] = COL_RATIO;
|
|
|
|
columns[_T("received")] = COL_RECEIVED;
|
|
|
|
columns[_T("remaining")] = COL_REMAINING;
|
|
|
|
columns[_T("seeds")] = COL_SEEDS;
|
2007-07-22 02:24:13 +00:00
|
|
|
columns[_T("sent")] = COL_SENT;
|
2007-07-20 02:12:07 +00:00
|
|
|
columns[_T("size")] = COL_SIZE;
|
|
|
|
columns[_T("state")] = COL_STATE;
|
|
|
|
columns[_T("status")] = COL_STATUS;
|
|
|
|
columns[_T("total")] = COL_TOTAL;
|
|
|
|
columns[_T("uspeed")] = COL_UPLOAD_SPEED;
|
2007-07-19 20:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int i = -1;
|
|
|
|
string2key_t::const_iterator it = columns.find( key );
|
|
|
|
if( it != columns.end() )
|
|
|
|
i = it->second;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-07-22 02:24:13 +00:00
|
|
|
typedef std::vector<int> int_v;
|
|
|
|
|
|
|
|
int_v getTorrentColumns( wxConfig * config )
|
2007-07-19 20:35:01 +00:00
|
|
|
{
|
|
|
|
const wxString key = _T("TorrentListColumns");
|
|
|
|
wxString columnStr;
|
|
|
|
if( !config->Read( key, &columnStr ) )
|
2007-07-22 19:37:43 +00:00
|
|
|
columnStr = _T("name|dspeed|uspeed|eta|peers|size|done|status|seeds");
|
2007-07-19 20:35:01 +00:00
|
|
|
|
2007-07-22 02:24:13 +00:00
|
|
|
int_v cols;
|
2007-07-19 20:35:01 +00:00
|
|
|
while( !columnStr.IsEmpty() )
|
|
|
|
{
|
|
|
|
const wxString key = columnStr.BeforeFirst(_T('|'));
|
|
|
|
columnStr.Remove( 0, key.Len() + 1 );
|
|
|
|
cols.push_back( getTorrentColumn( key ) );
|
|
|
|
}
|
|
|
|
return cols;
|
|
|
|
}
|
2007-07-22 02:24:13 +00:00
|
|
|
|
|
|
|
int bestDecimal( double num ) {
|
|
|
|
if ( num < 10 ) return 2;
|
|
|
|
if ( num < 100 ) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getReadableSize( uint64_t size )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
static const char *sizestrs[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" };
|
|
|
|
//N_("B"), N_("KiB"), N_("MiB"), N_("GiB"), N_("TiB"), N_("PiB"), N_("EiB") };
|
|
|
|
for ( i=0; size>>10; ++i )
|
|
|
|
size = size>>10;
|
|
|
|
char buf[512];
|
|
|
|
snprintf( buf, sizeof(buf), "%.*f %s", bestDecimal(size), (double)size, sizestrs[i] );
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
std::string getReadableSize( float f )
|
|
|
|
{
|
|
|
|
return getReadableSize( (uint64_t)f );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getReadableTime( int i /*seconds*/ ) /*FIXME*/
|
|
|
|
{
|
|
|
|
const int s = i % 60; i /= 60;
|
|
|
|
const int m = i % 60; i /= 60;
|
|
|
|
const int h = i;
|
|
|
|
char buf[64];
|
|
|
|
snprintf( buf, sizeof(buf), "%d:%02d:%02d", h, m, s);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString toWxStr( const std::string& s )
|
|
|
|
{
|
|
|
|
return wxString( s.c_str(), wxConvUTF8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString toWxStr( const char * s )
|
|
|
|
{
|
|
|
|
return wxString( s, wxConvUTF8 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
2007-07-22 19:37:43 +00:00
|
|
|
**** PEERS LIST
|
|
|
|
****
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** TORRENT LIST
|
|
|
|
****
|
|
|
|
****
|
2007-07-22 02:24:13 +00:00
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2007-07-22 19:37:43 +00:00
|
|
|
MyFrame :: refreshTorrent( tr_torrent_t * tor,
|
|
|
|
int myTorrents_index,
|
|
|
|
const int_v & cols )
|
2007-07-22 02:24:13 +00:00
|
|
|
{
|
|
|
|
int row = -1;
|
|
|
|
int col = 0;
|
|
|
|
char buf[512];
|
|
|
|
std::string str;
|
|
|
|
const tr_stat_t * s = tr_torrentStat( tor );
|
|
|
|
const tr_info_t* info = tr_torrentInfo( tor );
|
|
|
|
|
|
|
|
for( int_v::const_iterator it(cols.begin()), end(cols.end()); it!=end; ++it )
|
|
|
|
{
|
|
|
|
wxString xstr;
|
|
|
|
|
|
|
|
switch( *it )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
snprintf( buf, sizeof(buf), "%d", 666 );
|
|
|
|
xstr = toWxStr( buf );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DONE:
|
2007-07-22 19:37:43 +00:00
|
|
|
snprintf( buf, sizeof(buf), "%d%%", (int)(s->percentDone*100.0) );
|
2007-07-22 02:24:13 +00:00
|
|
|
xstr = toWxStr( buf );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_DOWNLOAD_SPEED: break;
|
|
|
|
xstr = toWxStr( getReadableSize( s->rateDownload ) + "/s" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_ETA:
|
2007-07-22 19:37:43 +00:00
|
|
|
if( (int)(s->percentDone*100) >= 100 )
|
|
|
|
xstr = wxString ();
|
|
|
|
else if( s->eta < 0 )
|
|
|
|
xstr = toWxStr( "\xE2\x88\x9E" ); /* infinity, in utf-8 */
|
|
|
|
else
|
|
|
|
xstr = toWxStr( getReadableTime( s->eta ) );
|
2007-07-22 02:24:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_HASH:
|
|
|
|
xstr = toWxStr( info->hashString );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_NAME:
|
|
|
|
xstr = toWxStr( info->name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_PEERS:
|
|
|
|
/* FIXME: this is all peers, not just leechers */
|
|
|
|
snprintf( buf, sizeof(buf), "%d (%d)", s->peersTotal, s->peersConnected );
|
|
|
|
xstr = toWxStr( buf );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_RATIO:
|
|
|
|
snprintf( buf, sizeof(buf), "%%%d", (int)(s->uploaded / (double)s->downloadedValid) );
|
|
|
|
xstr = toWxStr( buf );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_RECEIVED:
|
|
|
|
xstr = toWxStr( getReadableSize( s->downloaded ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_REMAINING:
|
|
|
|
xstr = toWxStr( getReadableSize( s->left ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_SEEDS:
|
|
|
|
snprintf( buf, sizeof(buf), "%d", s->seeders ); /* FIXME: %d (%d) */
|
|
|
|
xstr = toWxStr( buf );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_SENT:
|
|
|
|
xstr = toWxStr( getReadableSize( s->uploaded ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_SIZE:
|
|
|
|
xstr = toWxStr( getReadableSize( info->totalSize ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_STATE:
|
|
|
|
xstr = _T("Fixme");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_STATUS:
|
|
|
|
xstr = _T("Fixme");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_TOTAL:
|
|
|
|
xstr = _T("Fixme");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_UPLOAD_SPEED:
|
|
|
|
xstr = toWxStr( getReadableSize( s->rateUpload ) + "/s" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
xstr = _T("Fixme");
|
|
|
|
}
|
|
|
|
|
2007-07-22 19:37:43 +00:00
|
|
|
if( col ) {
|
|
|
|
myTorrentList->SetItem( row, col++, xstr );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// first column... find the right row to put the info in.
|
|
|
|
// if the torrent's in the list already, update that row.
|
|
|
|
// otherwise, add a new row.
|
|
|
|
if( row < 0 ) {
|
|
|
|
str2int_t::const_iterator it = myHashToRow.find( info->hashString );
|
|
|
|
if( it != myHashToRow.end() ) {
|
|
|
|
row = it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( row >= 0 ) {
|
|
|
|
myTorrentList->SetItem( row, col++, xstr );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
row = myTorrentList->InsertItem( myTorrentList->GetItemCount(), xstr );
|
|
|
|
col = 1;
|
|
|
|
myHashToRow[info->hashString] = row;
|
|
|
|
myTorrentList->SetItemData( row, myTorrents_index );
|
|
|
|
}
|
|
|
|
}
|
2007-07-22 02:24:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-22 19:37:43 +00:00
|
|
|
void
|
|
|
|
MyFrame :: refreshTorrentList ()
|
|
|
|
{
|
|
|
|
const int_v cols = getTorrentColumns( myConfig );
|
|
|
|
const int rowCount = myTorrentList->GetItemCount();
|
|
|
|
for( int row=0; row<rowCount; ++row )
|
|
|
|
{
|
|
|
|
int array_index = myTorrentList->GetItemData( row );
|
|
|
|
tr_torrent_t * tor = myTorrents[array_index];
|
|
|
|
refreshTorrent( tor, array_index, cols );
|
|
|
|
}
|
|
|
|
}
|
2007-07-22 02:24:13 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
MyFrame :: repopulateTorrentList ()
|
|
|
|
{
|
2007-07-22 19:37:43 +00:00
|
|
|
std::cerr << __FILE__ << ':' << __LINE__ << " clearing all items from list" << std::endl;
|
2007-07-22 02:24:13 +00:00
|
|
|
myTorrentList->DeleteAllItems();
|
2007-07-22 19:37:43 +00:00
|
|
|
myHashToRow.clear ();
|
2007-07-22 02:24:13 +00:00
|
|
|
|
|
|
|
const int_v cols = getTorrentColumns( myConfig );
|
2007-07-22 19:37:43 +00:00
|
|
|
int i = 0;
|
2007-07-22 02:24:13 +00:00
|
|
|
for( torrents_t::const_iterator it(myTorrents.begin()),
|
|
|
|
end(myTorrents.end()); it!=end; ++it )
|
2007-07-22 19:37:43 +00:00
|
|
|
refreshTorrent( *it, i++, cols );
|
2007-07-19 20:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MyFrame :: rebuildTorrentList()
|
|
|
|
{
|
|
|
|
myTorrentList->ClearAll( );
|
2007-07-22 19:37:43 +00:00
|
|
|
myHashToRow.clear ();
|
2007-07-19 20:35:01 +00:00
|
|
|
|
|
|
|
int i = 0;
|
2007-07-22 02:24:13 +00:00
|
|
|
const int_v cols = getTorrentColumns( myConfig );
|
|
|
|
for( int_v ::const_iterator it(cols.begin()), end(cols.end()); it!=end; ++it )
|
2007-07-19 20:35:01 +00:00
|
|
|
{
|
2007-07-22 19:37:43 +00:00
|
|
|
int format = wxLIST_FORMAT_LEFT;
|
|
|
|
int width = -1;
|
2007-07-19 20:35:01 +00:00
|
|
|
wxString h;
|
|
|
|
|
|
|
|
switch( *it )
|
|
|
|
{
|
2007-07-22 19:37:43 +00:00
|
|
|
case COL_NUMBER: h = _T("#"); format = wxLIST_FORMAT_CENTRE; break;
|
|
|
|
case COL_DONE: h = _T("Done"); format = wxLIST_FORMAT_RIGHT; break;
|
2007-07-19 20:35:01 +00:00
|
|
|
case COL_DOWNLOAD_SPEED: h = _T("Download"); break;
|
2007-07-22 19:37:43 +00:00
|
|
|
case COL_ETA: h = _T("ETA"); format = wxLIST_FORMAT_RIGHT; break;
|
2007-07-19 20:35:01 +00:00
|
|
|
case COL_HASH: h = _T("SHA1 Hash"); break;
|
2007-07-22 19:37:43 +00:00
|
|
|
case COL_NAME: h = _T("Name"); width = 500; break;
|
|
|
|
case COL_PEERS: h = _T("Peers"); format = wxLIST_FORMAT_RIGHT; break;
|
|
|
|
case COL_RATIO: h = _T("Ratio"); format = wxLIST_FORMAT_RIGHT; break;
|
|
|
|
case COL_RECEIVED: h = _T("Received"); format = wxLIST_FORMAT_RIGHT; break;
|
|
|
|
case COL_REMAINING: h = _T("Remaining"); format = wxLIST_FORMAT_RIGHT; break;
|
|
|
|
case COL_SEEDS: h = _T("Seeds"); format = wxLIST_FORMAT_RIGHT; break;
|
|
|
|
case COL_SENT: h = _T("Sent"); format = wxLIST_FORMAT_RIGHT; break;
|
|
|
|
case COL_SIZE: h = _T("Size"); format = wxLIST_FORMAT_RIGHT; break;
|
2007-07-19 20:35:01 +00:00
|
|
|
case COL_STATE: h = _T("State"); break;
|
|
|
|
case COL_STATUS: h = _T("Status"); break;
|
|
|
|
case COL_TOTAL: h = _T("Total"); break;
|
2007-07-22 19:37:43 +00:00
|
|
|
case COL_UPLOAD_SPEED: h = _T("Upload"); format = wxLIST_FORMAT_RIGHT;break;
|
2007-07-19 20:35:01 +00:00
|
|
|
default: h = _T("Error"); break;
|
|
|
|
}
|
|
|
|
|
2007-07-22 19:37:43 +00:00
|
|
|
myTorrentList->InsertColumn( i++, h, format, width );
|
2007-07-19 20:35:01 +00:00
|
|
|
}
|
2007-07-22 02:24:13 +00:00
|
|
|
|
|
|
|
repopulateTorrentList ();
|
2007-07-19 20:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2007-07-22 19:37:43 +00:00
|
|
|
void
|
|
|
|
MyFrame :: OnTimer(wxTimerEvent& event)
|
|
|
|
{
|
|
|
|
refreshTorrentList ();
|
|
|
|
}
|
|
|
|
|
2007-07-19 14:06:50 +00:00
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
delete myConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size):
|
|
|
|
wxFrame((wxFrame*)NULL,-1,title,pos,size),
|
2007-07-22 19:37:43 +00:00
|
|
|
myConfig( new wxConfig( _T("xmission") ) ),
|
|
|
|
myPulseTimer( this, ID_Pulse )
|
2007-07-19 14:06:50 +00:00
|
|
|
{
|
2007-07-19 14:50:42 +00:00
|
|
|
wxImage::AddHandler( new wxPNGHandler );
|
2007-07-19 14:57:21 +00:00
|
|
|
wxImage transmission_logo ( _T("images/transmission.png"), wxBITMAP_TYPE_PNG );
|
2007-07-19 14:50:42 +00:00
|
|
|
wxIcon ico;
|
|
|
|
ico.CopyFromBitmap( wxBitmap( transmission_logo ) );
|
|
|
|
SetIcon( ico );
|
2007-07-19 14:06:50 +00:00
|
|
|
|
2007-07-22 02:24:13 +00:00
|
|
|
/**
|
|
|
|
*** Torrents
|
|
|
|
**/
|
|
|
|
|
|
|
|
const int flags = TR_FLAG_PAUSED;
|
2007-07-22 19:37:43 +00:00
|
|
|
const char * destination = "/home/charles/torrents";
|
2007-07-22 02:24:13 +00:00
|
|
|
int count = 0;
|
|
|
|
tr_torrent_t ** torrents = tr_loadTorrents ( handle, destination, flags, &count );
|
|
|
|
myTorrents.insert( myTorrents.end(), torrents, torrents+count );
|
|
|
|
tr_free( torrents );
|
|
|
|
|
|
|
|
|
2007-07-19 14:06:50 +00:00
|
|
|
/**
|
|
|
|
*** Menu
|
|
|
|
**/
|
|
|
|
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
|
|
|
|
wxMenu * m = new wxMenu;
|
|
|
|
m->Append( wxID_OPEN, _T("&Open") );
|
|
|
|
m->Append( ID_START, _T("&Start") );
|
|
|
|
m->Append( wxID_STOP, _T("Sto&p") ) ;
|
|
|
|
m->Append( wxID_REFRESH, _T("Re&check") );
|
|
|
|
m->Append( wxID_REMOVE, _T("&Remove") );
|
|
|
|
m->AppendSeparator();
|
|
|
|
m->Append( wxID_NEW, _T("Create &New Torrent") );
|
|
|
|
m->AppendSeparator();
|
|
|
|
m->Append( wxID_CLOSE, _T("&Close") );
|
|
|
|
m->Append( wxID_EXIT, _T("&Exit") );
|
|
|
|
menuBar->Append( m, _T("&File") );
|
|
|
|
|
|
|
|
m = new wxMenu;
|
|
|
|
m->Append( ID_TORRENT_INFO, _T("Torrent &Info") );
|
|
|
|
m->Append( wxID_PREFERENCES, _T("Edit &Preferences") );
|
|
|
|
menuBar->Append( m, _T("&Edit") );
|
|
|
|
|
|
|
|
m = new wxMenu;
|
|
|
|
m->Append( ID_SHOW_DEBUG_WINDOW, _T("Show &Debug Window") );
|
|
|
|
m->AppendSeparator();
|
2007-07-19 14:50:42 +00:00
|
|
|
m->Append( wxID_ABOUT, _T("&About Xmission") );
|
2007-07-19 14:06:50 +00:00
|
|
|
menuBar->Append( m, _T("&Help") );
|
|
|
|
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Toolbar
|
|
|
|
**/
|
|
|
|
|
2007-07-19 14:57:21 +00:00
|
|
|
wxImage open_image( _T("images/fileopen.png"), wxBITMAP_TYPE_PNG );
|
|
|
|
wxImage exec_image( _T("images/exec.png"), wxBITMAP_TYPE_PNG );
|
|
|
|
wxImage stop_image( _T("images/stop.png"), wxBITMAP_TYPE_PNG );
|
|
|
|
wxImage drop_image( _T("images/gtk-remove.png"), wxBITMAP_TYPE_PNG );
|
|
|
|
wxImage info_image( _T("images/gtk-properties.png"), wxBITMAP_TYPE_PNG );
|
2007-07-19 14:50:42 +00:00
|
|
|
|
2007-07-19 14:06:50 +00:00
|
|
|
wxToolBar* toolbar = CreateToolBar( wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | wxTB_TEXT );
|
|
|
|
toolbar->SetToolBitmapSize( wxSize( 16, 16 ) );
|
2007-07-19 14:50:42 +00:00
|
|
|
toolbar->AddTool( wxID_OPEN, _T("Open"), open_image );
|
|
|
|
toolbar->AddTool( ID_START, _T("Start"), exec_image );
|
|
|
|
toolbar->AddTool( wxID_STOP, _T("Stop"), stop_image );
|
|
|
|
toolbar->AddTool( wxID_REMOVE, _T("Remove"), drop_image );
|
2007-07-19 14:06:50 +00:00
|
|
|
toolbar->AddSeparator();
|
2007-07-19 14:50:42 +00:00
|
|
|
toolbar->AddTool( ID_TORRENT_INFO, _("Torrent Info"), info_image );
|
2007-07-19 14:06:50 +00:00
|
|
|
toolbar->Realize();
|
|
|
|
|
|
|
|
/**
|
2007-07-19 19:05:55 +00:00
|
|
|
*** Row 1
|
|
|
|
**/
|
|
|
|
|
|
|
|
wxSplitterWindow * hsplit = new wxSplitterWindow( this );
|
|
|
|
|
|
|
|
wxPanel * row1 = new wxPanel( hsplit, wxID_ANY );
|
|
|
|
wxFlexGridSizer * row_sizer = new wxFlexGridSizer( 2, 0, 5 );
|
|
|
|
row_sizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_ALL );
|
|
|
|
row_sizer->SetFlexibleDirection( wxHORIZONTAL );
|
|
|
|
row1->SetSizer( row_sizer );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Filters
|
|
|
|
**/
|
|
|
|
|
|
|
|
wxListCtrl * filters = new wxListCtrl( row1, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_NO_HEADER );
|
|
|
|
filters->InsertColumn( wxLIST_FORMAT_LEFT, _T("YYZ") );
|
|
|
|
int i = 0;
|
|
|
|
filters->InsertItem( i++, _T("All") );
|
|
|
|
filters->InsertItem( i++, _T("Downloading (1)") );
|
|
|
|
filters->InsertItem( i++, _T("Completed") );
|
|
|
|
filters->InsertItem( i++, _T("Active (1)") );
|
|
|
|
filters->InsertItem( i++, _T("Inactive") );
|
|
|
|
row_sizer->Add( filters, wxSizerFlags().Expand() );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Torrent List
|
|
|
|
**/
|
|
|
|
|
2007-07-19 20:35:01 +00:00
|
|
|
myTorrentList = new wxListCtrl( row1, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxLC_REPORT|wxLC_SINGLE_SEL );
|
|
|
|
rebuildTorrentList();
|
|
|
|
row_sizer->Add( myTorrentList, wxSizerFlags().Expand() );
|
2007-07-19 19:05:55 +00:00
|
|
|
row_sizer->AddGrowableCol( 1, 1 );
|
|
|
|
|
|
|
|
|
|
|
|
wxNotebook * notebook = new wxNotebook( hsplit, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
|
|
|
|
|
|
|
|
wxButton * tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
|
|
|
notebook->AddPage( tmp, _T("General"), false );
|
|
|
|
tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
|
|
|
notebook->AddPage( tmp, _T("Peers"), false );
|
|
|
|
tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
|
|
|
notebook->AddPage( tmp, _T("Pieces"), false );
|
|
|
|
tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
|
|
|
notebook->AddPage( tmp, _T("Files"), false );
|
|
|
|
tmp = new wxButton( notebook, wxID_ANY, _T("Hello World"));
|
|
|
|
notebook->AddPage( tmp, _T("Logger"), false );
|
|
|
|
|
|
|
|
hsplit->SplitHorizontally( row1, notebook );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Statusbar
|
2007-07-19 14:06:50 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
CreateStatusBar();
|
2007-07-19 14:50:42 +00:00
|
|
|
SetStatusText(_T("Welcome to Xmission!"));
|
2007-07-22 19:37:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** Refresh
|
|
|
|
**/
|
|
|
|
|
|
|
|
myPulseTimer.Start( 1500 );
|
2007-07-19 14:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2007-07-19 14:57:21 +00:00
|
|
|
wxImage transmission_logo ( _T("images/transmission.png"), wxBITMAP_TYPE_PNG );
|
2007-07-19 14:50:42 +00:00
|
|
|
wxIcon ico;
|
|
|
|
ico.CopyFromBitmap( wxBitmap( transmission_logo ) );
|
|
|
|
|
2007-07-20 02:12:07 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,0)
|
2007-07-19 14:06:50 +00:00
|
|
|
wxAboutDialogInfo info;
|
2007-07-19 14:50:42 +00:00
|
|
|
info.SetName(_T("Xmission"));
|
2007-07-19 14:06:50 +00:00
|
|
|
info.SetVersion(_T(LONG_VERSION_STRING));
|
|
|
|
info.SetCopyright(_T("Copyright 2005-2007 The Transmission Project"));
|
|
|
|
info.SetDescription(_T("A fast, lightweight bittorrent client"));
|
|
|
|
info.SetWebSite( _T( "http://transmission.m0k.org/" ) );
|
2007-07-19 14:50:42 +00:00
|
|
|
info.SetIcon( ico );
|
2007-07-19 14:06:50 +00:00
|
|
|
info.AddDeveloper( "Josh Elsasser (Back-end; GTK+)" );
|
|
|
|
info.AddDeveloper ("Charles Kerr (Back-end, GTK+, wxWidgets)");
|
|
|
|
info.AddDeveloper( "Mitchell Livingston (Back-end; OS X)" );
|
|
|
|
info.AddDeveloper( "Eric Petit (Back-end; OS X)" );
|
|
|
|
info.AddDeveloper( "Bryan Varner (BeOS)" );
|
|
|
|
wxAboutBox( info );
|
2007-07-20 02:12:07 +00:00
|
|
|
#else
|
|
|
|
wxMessageBox(_T("Xmission " LONG_VERSION_STRING "\n"
|
|
|
|
"Copyright 2005-2007 The Transmission Project"),
|
|
|
|
_T("About Xmission"),
|
|
|
|
wxOK|wxICON_INFORMATION, this);
|
|
|
|
#endif
|
|
|
|
|
2007-07-19 14:06:50 +00:00
|
|
|
}
|