1 | #include <iostream> |
---|
2 | #include <wx/aboutdlg.h> |
---|
3 | #include <wx/artprov.h> |
---|
4 | #include <wx/defs.h> |
---|
5 | #include <wx/config.h> |
---|
6 | #include <wx/toolbar.h> |
---|
7 | #include <wx/wx.h> |
---|
8 | extern "C" { |
---|
9 | #include <libtransmission/transmission.h> |
---|
10 | } |
---|
11 | |
---|
12 | class MyApp : public wxApp |
---|
13 | { |
---|
14 | virtual bool OnInit(); |
---|
15 | }; |
---|
16 | |
---|
17 | IMPLEMENT_APP(MyApp) |
---|
18 | |
---|
19 | tr_handle_t * handle = NULL; |
---|
20 | |
---|
21 | class MyFrame : public wxFrame |
---|
22 | { |
---|
23 | public: |
---|
24 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); |
---|
25 | virtual ~MyFrame(); |
---|
26 | void OnQuit(wxCommandEvent& event); |
---|
27 | void OnAbout(wxCommandEvent& event); |
---|
28 | void OnOpen(wxCommandEvent& event); |
---|
29 | |
---|
30 | protected: |
---|
31 | wxConfig * myConfig; |
---|
32 | }; |
---|
33 | |
---|
34 | enum |
---|
35 | { |
---|
36 | ID_START, |
---|
37 | ID_STOP, |
---|
38 | ID_REMOVE, |
---|
39 | ID_QUIT, |
---|
40 | ID_TORRENT_INFO, |
---|
41 | ID_EDIT_PREFS, |
---|
42 | ID_SHOW_DEBUG_WINDOW, |
---|
43 | ID_ABOUT, |
---|
44 | N_IDS |
---|
45 | }; |
---|
46 | |
---|
47 | void MyFrame :: OnOpen( wxCommandEvent& event ) |
---|
48 | { |
---|
49 | const wxString key = _T("LastDirectory"); |
---|
50 | wxString directory; |
---|
51 | myConfig->Read( key, &directory ); |
---|
52 | wxFileDialog * w = new wxFileDialog( this, _T("message"), |
---|
53 | directory, |
---|
54 | _T(""), /* default file */ |
---|
55 | _T("Torrent files|*.torrent"), |
---|
56 | wxOPEN|wxMULTIPLE ); |
---|
57 | |
---|
58 | if( w->ShowModal() == wxID_OK ) |
---|
59 | { |
---|
60 | wxArrayString paths; |
---|
61 | w->GetPaths( paths ); |
---|
62 | size_t nPaths = paths.GetCount(); |
---|
63 | for( size_t i=0; i<nPaths; ++i ) |
---|
64 | { |
---|
65 | const wxString& w = paths[i]; |
---|
66 | std::cerr << w.ToAscii() << std::endl; |
---|
67 | } |
---|
68 | myConfig->Write( key, w->GetDirectory() ); |
---|
69 | } |
---|
70 | |
---|
71 | delete w; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | bool MyApp::OnInit() |
---|
76 | { |
---|
77 | handle = tr_init( "wx" ); |
---|
78 | |
---|
79 | MyFrame * frame = new MyFrame( _T("Xmission"), |
---|
80 | wxPoint(50,50), |
---|
81 | wxSize(450,350)); |
---|
82 | |
---|
83 | frame->Connect( wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnOpen ); |
---|
84 | frame->Connect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnQuit ); |
---|
85 | frame->Connect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) &MyFrame::OnAbout ); |
---|
86 | |
---|
87 | frame->Show( true ); |
---|
88 | SetTopWindow( frame ); |
---|
89 | return true; |
---|
90 | } |
---|
91 | |
---|
92 | /*** |
---|
93 | **** |
---|
94 | ***/ |
---|
95 | |
---|
96 | MyFrame::~MyFrame() |
---|
97 | { |
---|
98 | delete myConfig; |
---|
99 | } |
---|
100 | |
---|
101 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size): |
---|
102 | wxFrame((wxFrame*)NULL,-1,title,pos,size), |
---|
103 | myConfig( new wxConfig( _T("xmission") ) ) |
---|
104 | { |
---|
105 | wxImage::AddHandler( new wxPNGHandler ); |
---|
106 | wxImage transmission_logo ( _T("xpm/transmission.png"), wxBITMAP_TYPE_PNG ); |
---|
107 | wxIcon ico; |
---|
108 | ico.CopyFromBitmap( wxBitmap( transmission_logo ) ); |
---|
109 | SetIcon( ico ); |
---|
110 | //SetIcon( wxImage( _T("xpm/transmission.png"), wxBITMAP_TYPE_PNG ) ); |
---|
111 | |
---|
112 | /** |
---|
113 | *** Menu |
---|
114 | **/ |
---|
115 | |
---|
116 | wxMenuBar *menuBar = new wxMenuBar; |
---|
117 | |
---|
118 | wxMenu * m = new wxMenu; |
---|
119 | m->Append( wxID_OPEN, _T("&Open") ); |
---|
120 | m->Append( ID_START, _T("&Start") ); |
---|
121 | m->Append( wxID_STOP, _T("Sto&p") ) ; |
---|
122 | m->Append( wxID_REFRESH, _T("Re&check") ); |
---|
123 | m->Append( wxID_REMOVE, _T("&Remove") ); |
---|
124 | m->AppendSeparator(); |
---|
125 | m->Append( wxID_NEW, _T("Create &New Torrent") ); |
---|
126 | m->AppendSeparator(); |
---|
127 | m->Append( wxID_CLOSE, _T("&Close") ); |
---|
128 | m->Append( wxID_EXIT, _T("&Exit") ); |
---|
129 | menuBar->Append( m, _T("&File") ); |
---|
130 | |
---|
131 | m = new wxMenu; |
---|
132 | m->Append( ID_TORRENT_INFO, _T("Torrent &Info") ); |
---|
133 | m->Append( wxID_PREFERENCES, _T("Edit &Preferences") ); |
---|
134 | menuBar->Append( m, _T("&Edit") ); |
---|
135 | |
---|
136 | m = new wxMenu; |
---|
137 | m->Append( ID_SHOW_DEBUG_WINDOW, _T("Show &Debug Window") ); |
---|
138 | m->AppendSeparator(); |
---|
139 | m->Append( wxID_ABOUT, _T("&About Xmission") ); |
---|
140 | menuBar->Append( m, _T("&Help") ); |
---|
141 | |
---|
142 | SetMenuBar(menuBar); |
---|
143 | |
---|
144 | /** |
---|
145 | *** Toolbar |
---|
146 | **/ |
---|
147 | |
---|
148 | wxImage open_image( _T("xpm/fileopen.png"), wxBITMAP_TYPE_PNG ); |
---|
149 | wxImage exec_image( _T("xpm/exec.png"), wxBITMAP_TYPE_PNG ); |
---|
150 | wxImage stop_image( _T("xpm/stop.png"), wxBITMAP_TYPE_PNG ); |
---|
151 | wxImage drop_image( _T("xpm/gtk-remove.png"), wxBITMAP_TYPE_PNG ); |
---|
152 | wxImage info_image( _T("xpm/gtk-properties.png"), wxBITMAP_TYPE_PNG ); |
---|
153 | |
---|
154 | wxToolBar* toolbar = CreateToolBar( wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | wxTB_TEXT ); |
---|
155 | toolbar->SetToolBitmapSize( wxSize( 16, 16 ) ); |
---|
156 | toolbar->AddTool( wxID_OPEN, _T("Open"), open_image ); |
---|
157 | toolbar->AddTool( ID_START, _T("Start"), exec_image ); |
---|
158 | toolbar->AddTool( wxID_STOP, _T("Stop"), stop_image ); |
---|
159 | toolbar->AddTool( wxID_REMOVE, _T("Remove"), drop_image ); |
---|
160 | toolbar->AddSeparator(); |
---|
161 | toolbar->AddTool( ID_TORRENT_INFO, _("Torrent Info"), info_image ); |
---|
162 | toolbar->Realize(); |
---|
163 | |
---|
164 | /** |
---|
165 | *** Status Bar |
---|
166 | **/ |
---|
167 | |
---|
168 | CreateStatusBar(); |
---|
169 | SetStatusText(_T("Welcome to Xmission!")); |
---|
170 | } |
---|
171 | |
---|
172 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
---|
173 | { |
---|
174 | Close(TRUE); |
---|
175 | } |
---|
176 | |
---|
177 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
---|
178 | { |
---|
179 | wxImage transmission_logo ( _T("xpm/transmission.png"), wxBITMAP_TYPE_PNG ); |
---|
180 | wxIcon ico; |
---|
181 | ico.CopyFromBitmap( wxBitmap( transmission_logo ) ); |
---|
182 | |
---|
183 | wxAboutDialogInfo info; |
---|
184 | info.SetName(_T("Xmission")); |
---|
185 | info.SetVersion(_T(LONG_VERSION_STRING)); |
---|
186 | info.SetCopyright(_T("Copyright 2005-2007 The Transmission Project")); |
---|
187 | info.SetDescription(_T("A fast, lightweight bittorrent client")); |
---|
188 | info.SetWebSite( _T( "http://transmission.m0k.org/" ) ); |
---|
189 | info.SetIcon( ico ); |
---|
190 | info.AddDeveloper( "Josh Elsasser (Back-end; GTK+)" ); |
---|
191 | info.AddDeveloper ("Charles Kerr (Back-end, GTK+, wxWidgets)"); |
---|
192 | info.AddDeveloper( "Mitchell Livingston (Back-end; OS X)" ); |
---|
193 | info.AddDeveloper( "Eric Petit (Back-end; OS X)" ); |
---|
194 | info.AddDeveloper( "Bryan Varner (BeOS)" ); |
---|
195 | wxAboutBox( info ); |
---|
196 | } |
---|