Remove the "Server Log" tab from the Remote GUI
[amule.git] / src / amuleDlg.cpp
blob24294f5cadabe7437d5475a3bf14932134ef1d5b
2 //
3 // This file is part of the aMule Project.
4 //
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 //
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include <wx/app.h>
29 #include <wx/archive.h>
30 #include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
31 #include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
32 #include <wx/html/htmlwin.h>
33 #include <wx/mimetype.h> // Do_not_auto_remove (win32)
34 #include <wx/stattext.h>
35 #include <wx/stdpaths.h>
36 #include <wx/textfile.h> // Do_not_auto_remove (win32)
37 #include <wx/tokenzr.h>
38 #include <wx/wfstream.h>
39 #include <wx/zipstrm.h>
40 #include <wx/sysopt.h>
41 #include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker
43 #include <common/EventIDs.h>
45 #ifdef HAVE_CONFIG_H
46 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
47 #else
48 #include <common/ClientVersion.h>
49 #endif // HAVE_CONFIG_H
51 #include "amuleDlg.h" // Interface declarations.
53 #include <common/Format.h> // Needed for CFormat
54 #include "amule.h" // Needed for theApp
55 #include "ChatWnd.h" // Needed for CChatWnd
56 #include "SourceListCtrl.h" // Needed for CSourceListCtrl
57 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
58 #include "DownloadQueue.h" // Needed for CDownloadQueue
59 #include "KadDlg.h" // Needed for CKadDlg
60 #include "Logger.h"
61 #include "MuleTrayIcon.h"
62 #include "muuli_wdr.h" // Needed for ID_BUTTON*
63 #include "Preferences.h" // Needed for CPreferences
64 #include "PrefsUnifiedDlg.h"
65 #include "SearchDlg.h" // Needed for CSearchDlg
66 #include "Server.h" // Needed for CServer
67 #include "ServerConnect.h" // Needed for CServerConnect
68 #include "ServerWnd.h" // Needed for CServerWnd
69 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
70 #include "SharedFilePeersListCtrl.h" // Needed for CSharedFilePeersListCtrl
71 #include "Statistics.h" // Needed for theStats
72 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
73 #include "TerminationProcess.h" // Needed for CTerminationProcess
74 #include "TransferWnd.h" // Needed for CTransferWnd
75 #include "PartFileConvertDlg.h"
76 #include "IPFilter.h"
78 #ifndef __WXMSW__
79 #include "aMule.xpm"
80 #endif
82 #include "kademlia/kademlia/Kademlia.h"
84 #ifdef ENABLE_IP2COUNTRY
85 #include "IP2Country.h" // Needed for IP2Country
86 #endif
88 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
89 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
90 void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
92 m_IP2Country->DownloadFinished(result);
95 void CamuleDlg::EnableIP2Country()
97 if (thePrefs::IsGeoIPEnabled()) {
98 m_IP2Country->Enable();
102 #else
104 void CamuleDlg::IP2CountryDownloadFinished(uint32){}
105 void CamuleDlg::EnableIP2Country(){}
107 #endif
109 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
111 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
112 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
113 EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)
114 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
115 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
116 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
117 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
119 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
120 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
122 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
124 EVT_CLOSE(CamuleDlg::OnClose)
125 EVT_ICONIZE(CamuleDlg::OnMinimize)
127 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
129 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
131 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
133 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
135 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
137 END_EVENT_TABLE()
139 #ifndef wxCLOSE_BOX
140 #define wxCLOSE_BOX 0
141 #endif
143 CamuleDlg::CamuleDlg(
144 wxWindow* pParent,
145 const wxString &title,
146 wxPoint where,
147 wxSize dlg_size)
149 wxFrame(
150 pParent, -1, title, where, dlg_size,
151 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
152 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
153 wxT("aMule")),
154 m_activewnd(NULL),
155 m_transferwnd(NULL),
156 m_serverwnd(NULL),
157 m_sharedfileswnd(NULL),
158 m_searchwnd(NULL),
159 m_chatwnd(NULL),
160 m_statisticswnd(NULL),
161 m_kademliawnd(NULL),
162 m_prefsDialog(NULL),
163 m_srv_split_pos(0),
164 m_imagelist(16,16),
165 m_tblist(32,32),
166 m_prefsVisible(false),
167 m_wndToolbar(NULL),
168 m_wndTaskbarNotifier(NULL),
169 m_nActiveDialog(DT_NETWORKS_WND),
170 m_is_safe_state(false),
171 m_BlinkMessages(false),
172 m_CurrentBlinkBitmap(24),
173 m_last_iconizing(0),
174 m_skinFileName(),
175 m_clientSkinNames(CLIENT_SKIN_SIZE)
177 // Initialize skin names
178 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
179 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
180 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
181 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
182 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
183 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
184 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
185 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
186 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
187 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
188 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
189 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
190 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
191 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
192 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
193 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
194 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
195 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
196 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
197 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
198 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
199 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
200 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
201 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
202 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
203 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
204 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
206 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
207 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
208 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
209 wxInitAllImageHandlers();
210 Apply_Clients_Skin();
212 #ifdef __WXMSW__
213 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
214 #endif
216 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
217 // this crashes on Mac with wx 2.9
218 SetIcon(wxICON(aMule));
219 #endif
221 srand(time(NULL));
223 // Create new sizer and stuff a wxPanel in there.
224 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
225 s_main->AddGrowableCol(0);
226 s_main->AddGrowableRow(0);
228 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
229 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
230 muleDlg(p_cnt, false, true);
231 SetSizer(s_main, true);
233 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
234 AddLogLineN(wxEmptyString);
235 AddLogLineN(wxT(" - ") +
236 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
237 AddLogLineN(wxT(" ") +
238 CFormat(_("Running on %s")) % wxGetOsDescription());
239 AddLogLineN(wxT(" - ") +
240 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
241 AddLogLineN(wxEmptyString);
243 #ifdef ENABLE_IP2COUNTRY
244 m_GeoIPavailable = true;
245 m_IP2Country = new CIP2Country(theApp->ConfigDir);
246 #else
247 m_GeoIPavailable = false;
248 #endif
249 m_searchwnd = new CSearchDlg(p_cnt);
250 m_transferwnd = new CTransferWnd(p_cnt);
251 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
252 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
253 m_chatwnd = new CChatWnd(p_cnt);
254 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
256 m_serverwnd->Show(false);
257 m_searchwnd->Show(false);
258 m_transferwnd->Show(false);
259 m_sharedfileswnd->Show(false);
260 m_statisticswnd->Show(false);
261 m_chatwnd->Show(false);
263 // Create the GUI timer
264 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
265 if (!gui_timer) {
266 AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
267 exit(1);
270 // Set transfers as active window
271 Create_Toolbar(thePrefs::VerticalToolbar());
272 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
273 m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true );
275 bool override_where = (where != wxDefaultPosition);
276 bool override_size = (
277 (dlg_size.x != DEFAULT_SIZE_X) ||
278 (dlg_size.y != DEFAULT_SIZE_Y) );
279 if (!LoadGUIPrefs(override_where, override_size)) {
280 // Prefs not loaded for some reason, exit
281 AddLogLineC(wxT("Error! Unable to load Preferences") );
282 return;
285 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
286 m_transferwnd->Prepare();
288 m_is_safe_state = true;
290 // Init statistics stuff, better do it asap
291 m_statisticswnd->Init();
292 m_kademliawnd->Init();
293 m_searchwnd->UpdateCatChoice();
294 if (thePrefs::UseTrayIcon()) {
295 CreateSystray();
298 Show(true);
299 // Must we start minimized?
300 if (thePrefs::GetStartMinimized()) {
301 DoIconize(true);
304 // Set shortcut keys
305 wxAcceleratorEntry entries[] = {
306 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
309 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
310 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
312 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
313 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
315 wxASSERT(logs_notebook->GetPageCount() == 4);
316 wxASSERT(networks_notebook->GetPageCount() == 2);
318 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
319 m_logpages[i].page = logs_notebook->GetPage(i);
320 m_logpages[i].name = logs_notebook->GetPageText(i);
323 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
324 m_networkpages[i].page = networks_notebook->GetPage(i);
325 m_networkpages[i].name = networks_notebook->GetPageText(i);
328 DoNetworkRearrange();
332 // Madcat - Sets Fast ED2K Links Handler on/off.
333 void CamuleDlg::ShowED2KLinksHandler( bool show )
335 // Errorchecking in case the pointer becomes invalid ...
336 if (s_fed2klh == NULL) {
337 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
338 return;
341 s_dlgcnt->Show( s_fed2klh, show );
342 s_dlgcnt->Layout();
345 // Toogles ed2k link handler.
346 void CamuleDlg::ToogleED2KLinksHandler()
348 // Errorchecking in case the pointer becomes invalid ...
349 if (s_fed2klh == NULL) {
350 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
351 return;
353 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
356 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
358 m_nActiveDialog = type;
360 if ( type == DT_TRANSFER_WND ) {
361 if (thePrefs::ShowCatTabInfos()) {
362 m_transferwnd->UpdateCatTabTitles();
366 if ( m_activewnd ) {
367 m_activewnd->Show(false);
368 contentSizer->Detach(m_activewnd);
371 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
372 dlg->Show(true);
373 m_activewnd=dlg;
374 s_dlgcnt->Layout();
376 // Since we might be suspending redrawing while hiding the dialog
377 // we have to refresh it once it is visible again
378 dlg->Refresh( true );
379 dlg->SetFocus();
381 if ( type == DT_SHARED_WND ) {
382 // set up splitter now that window sizes are defined
383 m_sharedfileswnd->Prepare();
388 void CamuleDlg::UpdateTrayIcon(int percent)
390 // set trayicon-icon
391 if(!theApp->IsConnected()) {
392 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
393 } else {
394 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
395 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
396 } else {
397 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
403 void CamuleDlg::CreateSystray()
405 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
406 wxT("Systray already created"));
408 m_wndTaskbarNotifier = new CMuleTrayIcon();
409 // This will effectively show the Tray Icon.
410 UpdateTrayIcon(0);
414 void CamuleDlg::RemoveSystray()
416 delete m_wndTaskbarNotifier;
417 m_wndTaskbarNotifier = NULL;
421 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
423 static int lastbutton = ID_BUTTONDOWNLOADS;
425 // Kry - just if the GUI is ready for it
426 if ( m_is_safe_state ) {
428 // Rehide the handler if needed
429 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
430 if (ev.GetId() != ID_BUTTONSEARCH) {
431 ShowED2KLinksHandler( false );
432 } else {
433 // Toogle ED2K handler.
434 ToogleED2KLinksHandler();
438 if ( lastbutton != ev.GetId() ) {
439 switch ( ev.GetId() ) {
440 case ID_BUTTONNETWORKS:
441 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
442 // Set serverlist splitter position
443 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
444 break;
446 case ID_BUTTONSEARCH:
447 // The search dialog should always display the handler
448 if ( !thePrefs::GetFED2KLH() )
449 ShowED2KLinksHandler( true );
451 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
452 break;
454 case ID_BUTTONDOWNLOADS:
455 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
456 // Prepare the dialog, sets the splitter-position
457 m_transferwnd->Prepare();
458 break;
460 case ID_BUTTONSHARED:
461 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
462 break;
464 case ID_BUTTONMESSAGES:
465 m_BlinkMessages = false;
466 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
467 break;
469 case ID_BUTTONSTATISTICS:
470 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
471 break;
473 // This shouldn't happen, but just in case
474 default:
475 AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
476 break;
480 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
481 lastbutton = ev.GetId();
486 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
488 wxString msg = wxT(" ");
489 #ifdef CLIENT_GUI
490 msg << _("aMule remote control ") << wxT(VERSION);
491 #else
492 msg << wxT("aMule ") << wxT(VERSION);
493 #endif
494 msg << wxT(" ");
495 #ifdef SVNDATE
496 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
497 #endif
498 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
499 _("Website: http://www.amule.org \n") <<
500 _("Forum: http://forum.amule.org \n") <<
501 _("FAQ: http://wiki.amule.org \n\n") <<
502 _("Contact: admin@amule.org (administrative issues) \n") <<
503 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
504 _("Part of aMule is based on \n") <<
505 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
506 _(" Copyright (c) 2002-2008 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
507 _("http://kademlia.scs.cs.nyu.edu\n");
509 if (m_is_safe_state) {
510 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
515 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
517 if (m_is_safe_state) {
518 if (m_prefsDialog == NULL) {
519 m_prefsDialog = new PrefsUnifiedDlg(this);
522 m_prefsDialog->TransferToWindow();
523 m_prefsDialog->Show(true);
524 m_prefsDialog->Raise();
529 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
531 if (m_is_safe_state) {
532 CPartFileConvertDlg::ShowGUI(NULL);
537 CamuleDlg::~CamuleDlg()
539 theApp->amuledlg = NULL;
541 #ifdef ENABLE_IP2COUNTRY
542 delete m_IP2Country;
543 #endif
545 AddLogLineN(_("aMule dialog destroyed"));
549 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
552 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
553 #ifdef CLIENT_GUI
554 || theApp->IsConnectedKad() // there's no Kad running state atm
555 #else
556 || (Kademlia::CKademlia::IsRunning())
557 #endif
559 if (thePrefs::GetNetworkED2K()) {
560 if (disconnect) {
561 //disconnect if currently connected
562 if (theApp->serverconnect->IsConnecting()) {
563 theApp->serverconnect->StopConnectionTry();
564 } else {
565 theApp->serverconnect->Disconnect();
567 } else {
568 //connect if not currently connected
569 AddLogLineC(_("Connecting"));
570 theApp->serverconnect->ConnectToAnyServer();
572 } else {
573 wxASSERT(!theApp->IsConnectedED2K());
576 // Connect Kad also
577 if (thePrefs::GetNetworkKademlia()) {
578 if( disconnect ) {
579 theApp->StopKad();
580 } else {
581 theApp->StartKad();
583 } else {
584 #ifndef CLIENT_GUI
585 wxASSERT(!Kademlia::CKademlia::IsRunning());
586 #endif
589 ShowConnectionState();
593 void CamuleDlg::ResetLog(int id)
595 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
596 wxCHECK_RET(ct, wxT("Resetting unknown log"));
598 ct->Clear();
600 if (id == ID_LOGVIEW) {
601 // Also clear the log line
602 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
603 text->SetLabel(wxEmptyString);
604 text->GetParent()->Layout();
609 void CamuleDlg::AddLogLine(const wxString& line)
611 bool addtostatusbar = line[0] == '!';
612 wxString bufferline = line.Mid(1);
614 // Add the message to the log-view
615 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
616 if ( ct ) {
617 // Bold critical log-lines
618 // Works in Windows too thanks to wxTE_RICH2 style in muuli
619 wxTextAttr style = ct->GetDefaultStyle();
620 wxFont font = style.GetFont();
621 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
622 style.SetFont(font);
623 ct->SetDefaultStyle(style);
624 ct->AppendText(bufferline);
625 ct->ShowPosition( ct->GetLastPosition() - 1 );
629 // Set the status-bar if the event warrents it
630 if ( addtostatusbar ) {
631 // Escape "&"s, which would otherwise not show up
632 bufferline.Replace( wxT("&"), wxT("&&") );
633 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
634 // Only show the first line if multiple lines
635 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
636 text->SetToolTip( bufferline );
637 text->GetParent()->Layout();
643 void CamuleDlg::AddServerMessageLine(wxString& message)
645 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
646 if(cv) {
647 if (message.Length() > 500) {
648 cv->AppendText(message.Left(500) + wxT("\n"));
649 } else {
650 cv->AppendText(message + wxT("\n"));
652 cv->ShowPosition(cv->GetLastPosition()-1);
657 void CamuleDlg::ShowConnectionState(bool skinChanged)
659 static wxImageList status_arrows(16,16,true,0);
660 if (!status_arrows.GetImageCount()) {
661 // Generate the image list (This is only done once)
662 for (int t = 0; t < 7; ++t) {
663 status_arrows.Add(connImages(t));
667 m_serverwnd->UpdateED2KInfo();
668 m_serverwnd->UpdateKadInfo();
671 ////////////////////////////////////////////////////////////
672 // Determine the status of the networks
674 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
675 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
677 ED2KState ed2kState = ED2KOff;
678 EKadState kadState = EKadOff;
680 ////////////////////////////////////////////////////////////
681 // Update the label on the status-bar and determine
682 // the states of the two networks.
684 wxString msgED2K;
685 if (theApp->IsConnectedED2K()) {
686 CServer* server = theApp->serverconnect->GetCurrentServer();
687 if (server) {
688 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
691 if (theApp->serverconnect->IsLowID()) {
692 ed2kState = ED2KLowID;
693 } else {
694 ed2kState = ED2KHighID;
696 } else if (theApp->serverconnect->IsConnecting()) {
697 msgED2K = _("eD2k: Connecting");
699 ed2kState = ED2KConnecting;
700 } else if (thePrefs::GetNetworkED2K()) {
701 msgED2K = _("eD2k: Disconnected");
704 wxString msgKad;
705 if (theApp->IsConnectedKad()) {
706 if (theApp->IsFirewalledKad()) {
707 msgKad = _("Kad: Firewalled");
709 kadState = EKadFW;
710 } else {
711 msgKad = _("Kad: Connected");
713 kadState = EKadOK;
715 } else if (theApp->IsKadRunning()) {
716 msgKad = _("Kad: Connecting");
718 kadState = EKadConnecting;
719 } else if (thePrefs::GetNetworkKademlia()) {
720 msgKad = _("Kad: Off");
723 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
724 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
726 wxString labelMsg;
727 if (msgED2K.Length() && msgKad.Length()) {
728 labelMsg = msgED2K + wxT(" | ") + msgKad;
729 } else {
730 labelMsg = msgED2K + msgKad;
733 connLabel->SetLabel(labelMsg);
734 connLabel->GetParent()->Layout();
737 ////////////////////////////////////////////////////////////
738 // Update the connect/disconnect/cancel button.
740 enum EConnState {
741 ECS_Unknown,
742 ECS_Connected,
743 ECS_Connecting,
744 ECS_Disconnected
747 static EConnState s_oldState = ECS_Unknown;
748 EConnState currentState = ECS_Disconnected;
750 if (theApp->serverconnect->IsConnecting() ||
751 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
752 currentState = ECS_Connecting;
753 } else if (theApp->IsConnected()) {
754 currentState = ECS_Connected;
755 } else {
756 currentState = ECS_Disconnected;
759 if ( (true == skinChanged) || (currentState != s_oldState) ) {
760 wxWindowUpdateLocker freezer(m_wndToolbar);
762 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
764 switch (currentState) {
765 case ECS_Connecting:
766 toolbarTool->SetLabel(_("Cancel"));
767 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
768 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
769 break;
771 case ECS_Connected:
772 toolbarTool->SetLabel(_("Disconnect"));
773 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
774 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
775 break;
777 default:
778 toolbarTool->SetLabel(_("Connect"));
779 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
780 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
783 m_wndToolbar->InsertTool(0, toolbarTool);
784 m_wndToolbar->Realize();
785 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
787 s_oldState = currentState;
791 ////////////////////////////////////////////////////////////
792 // Update the globe-icon in the lower-right corner.
793 // (only if connection state has changed)
795 static ED2KState s_ED2KOldState = ED2KUndef;
796 static EKadState s_EKadOldState = EKadUndef;
797 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
798 s_ED2KOldState = ed2kState;
799 s_EKadOldState = kadState;
800 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
801 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
803 wxBitmap statusIcon = connBitmap->GetBitmap();
804 // Sanity check - otherwise there's a crash here if aMule runs out of resources
805 if (statusIcon.GetRefData() == NULL) {
806 return;
809 wxMemoryDC bitmapDC(statusIcon);
811 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
812 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
814 connBitmap->SetBitmap(statusIcon);
819 void CamuleDlg::ShowUserCount(const wxString& info)
821 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
823 // Update Kad tab
824 m_serverwnd->UpdateKadInfo();
826 label->SetLabel(info);
827 label->GetParent()->Layout();
831 void CamuleDlg::ShowTransferRate()
833 float kBpsUp = theStats::GetUploadRate() / 1024.0;
834 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
835 wxString buffer;
836 if( thePrefs::ShowOverhead() )
838 buffer = CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp % (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown % (theStats::GetDownOverheadRate() / 1024.0);
839 } else {
840 buffer = CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
842 buffer.Truncate(50); // Max size 50
844 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
845 label->SetLabel(buffer);
846 label->GetParent()->Layout();
848 // Show upload/download speed in title
849 if (thePrefs::GetShowRatesOnTitle()) {
850 wxString UpDownSpeed = CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
851 if (thePrefs::GetShowRatesOnTitle() == 1) {
852 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
853 } else {
854 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
858 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
859 if (m_wndTaskbarNotifier) {
860 // set trayicon-icon
861 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
862 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
864 wxString buffer2;
865 if ( theApp->IsConnected() ) {
866 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
867 } else {
868 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
870 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
873 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
874 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
877 void CamuleDlg::DlgShutDown()
879 // Are we already shutting down or still on init?
880 if ( m_is_safe_state == false ) {
881 return;
884 // we are going DOWN
885 m_is_safe_state = false;
887 // Stop the GUI Timer
888 delete gui_timer;
889 m_transferwnd->downloadlistctrl->DeleteAllItems();
891 // We want to delete the systray too!
892 RemoveSystray();
895 void CamuleDlg::OnClose(wxCloseEvent& evt)
897 // This will be here till the core close is != app close
898 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
899 if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
900 wxString(_("Exit confirmation")), wxYES_NO, this)) {
901 evt.Veto();
902 return;
906 SaveGUIPrefs();
908 Enable(false);
909 Show(false);
911 theApp->ShutDown(evt);
915 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
917 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
919 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
920 wxString strlink = ctl->GetLineText(i);
921 strlink.Trim(true);
922 strlink.Trim(false);
923 if ( !strlink.IsEmpty() ) {
924 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
928 ctl->SetValue(wxEmptyString);
932 // Formerly known as LoadRazorPrefs()
933 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
935 // Create a config base for loading razor preferences
936 wxConfigBase *config = wxConfigBase::Get();
937 // If config haven't been created exit without loading
938 if (config == NULL) {
939 return false;
942 // The section where to save in in file
943 wxString section = wxT("/Razor_Preferences/");
945 // Get window size and position
946 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
947 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
948 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
949 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
951 int maximized = config->Read(section + wxT("Maximized"), 01);
953 // Kry - Random usable pos for m_srv_split_pos
954 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
955 if (!override_size) {
956 if (x2 > 0 && y2 > 0) {
957 SetSize(x2, y2);
958 } else {
959 #ifndef __WXGTK__
960 // Probably first run.
961 Maximize();
962 #endif
966 if (!override_pos) {
967 // If x1 and y1 != -1 Redefine location
968 if(x1 != -1 && y1 != -1) {
969 wxRect display = wxGetClientDisplayRect();
970 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
971 Move(x1, y1);
972 } else {
973 // It's offscreen... so let's not.
978 if (!override_size && !override_pos && maximized) {
979 Maximize();
982 return true;
986 bool CamuleDlg::SaveGUIPrefs()
988 /* Razor 1a - Modif by MikaelB
989 Save client size and position */
991 // Create a config base for saving razor preferences
992 wxConfigBase *config = wxConfigBase::Get();
993 // If config haven't been created exit without saving
994 if (config == NULL) {
995 return false;
997 // The section where to save in in file
998 wxString section = wxT("/Razor_Preferences/");
1000 if (!IsIconized()) {
1001 // Main window location and size
1002 int x1, y1, x2, y2;
1003 GetPosition(&x1, &y1);
1004 GetSize(&x2, &y2);
1006 // Saving window size and position
1007 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1008 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1010 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1011 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1013 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1016 // Saving sash position of splitter in server window
1017 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1019 config->Flush(true);
1021 /* End modif */
1023 return true;
1027 void CamuleDlg::DoIconize(bool iconize)
1029 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1030 if (iconize) {
1031 // Skip() will do it.
1032 //Iconize(true);
1033 if (SafeState()) {
1034 Show(false);
1036 } else {
1037 Show(true);
1038 Raise();
1040 } else {
1041 // Will be done by Skip();
1042 //Iconize(iconize);
1046 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1048 // Evil Hack: check if the mouse is inside the window
1049 #ifndef __WXMSW__
1050 if (GetScreenRect().Contains(wxGetMousePosition()))
1051 #endif
1053 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1054 // Veto.
1055 } else {
1056 if (m_wndTaskbarNotifier) {
1057 #if wxCHECK_VERSION(2, 9, 0)
1058 DoIconize(evt.IsIconized());
1059 #else
1060 DoIconize(evt.Iconized());
1061 #endif
1063 evt.Skip();
1068 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1070 // Former TimerProc section
1072 static uint32 msPrev1, msPrev5;
1074 uint32 msCur = theStats::GetUptimeMillis();
1076 // can this actually happen under wxwin ?
1077 if (!SafeState()) {
1078 return;
1081 #ifndef CLIENT_GUI
1082 static uint32 msPrevGraph, msPrevStats;
1083 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1084 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1085 // trying to get the graph shifts evenly spaced after a change in the update period
1086 msPrevGraph = msCur;
1088 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1090 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1091 m_kademliawnd->UpdateGraph(update);
1094 int sStatsUpdate = thePrefs::GetStatsInterval();
1095 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1096 if (m_statisticswnd->IsShownOnScreen()) {
1097 msPrevStats = msCur;
1098 m_statisticswnd->ShowStatistics();
1101 #endif
1103 if (msCur-msPrev5 > 5000) { // every 5 seconds
1104 msPrev5 = msCur;
1105 ShowTransferRate();
1106 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1107 m_transferwnd->UpdateCatTabTitles();
1109 if (thePrefs::AutoSortDownload()) {
1110 m_transferwnd->downloadlistctrl->SortList();
1111 m_transferwnd->clientlistctrl->SortList();
1112 m_sharedfileswnd->peerslistctrl->SortList();
1116 if (msCur-msPrev1 > 1000) { // every second
1117 msPrev1 = msCur;
1118 if (m_CurrentBlinkBitmap == 12) {
1119 m_CurrentBlinkBitmap = 7;
1120 SetMessagesTool();
1121 } else {
1122 if (m_BlinkMessages) {
1123 m_CurrentBlinkBitmap = 12;
1124 SetMessagesTool();
1132 void CamuleDlg::SetMessagesTool()
1134 wxWindowUpdateLocker freezer(m_wndToolbar);
1135 #ifdef __WXCOCOA__
1136 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1137 #else
1138 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1139 #endif
1142 void CamuleDlg::LaunchUrl( const wxString& url )
1144 wxString cmd;
1146 cmd = thePrefs::GetBrowser();
1147 wxString tmp = url;
1148 // Pipes cause problems, so escape them
1149 tmp.Replace( wxT("|"), wxT("%7C") );
1151 if ( !cmd.IsEmpty() ) {
1152 if (!cmd.Replace(wxT("%s"), tmp)) {
1153 // No %s found, just append the url
1154 cmd += wxT(" ") + tmp;
1157 CTerminationProcess *p = new CTerminationProcess(cmd);
1158 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1159 AddLogLineN(_("Launch Command: ") + cmd);
1160 return;
1161 } else {
1162 delete p;
1164 } else {
1165 wxLaunchDefaultBrowser(tmp);
1166 return;
1168 // Unable to execute browser. But this error message doesn't make sense,
1169 // cosidering that you _can't_ set the browser executable path... =/
1170 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1174 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1176 wxString URL;
1177 switch (wsProvider) {
1178 case WS_FILEHASH:
1179 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1180 break;
1181 default:
1182 wxFAIL;
1184 URL.Replace(wxT("FILENAME"), filename);
1186 return URL;
1190 bool CamuleDlg::Check_and_Init_Skin()
1192 bool ret = true;
1193 wxString skinFileName(thePrefs::GetSkin());
1195 if (skinFileName.IsEmpty()) {
1196 return false;
1199 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1201 wxStandardPathsBase &spb(wxStandardPaths::Get());
1202 #ifdef __WXMSW__
1203 wxString dataDir(spb.GetPluginsDir());
1204 #elif defined(__WXMAC__)
1205 wxString dataDir(spb.GetDataDir());
1206 #else
1207 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1208 #endif
1209 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1212 skinFileName.Replace(wxT("User:"), userDir );
1213 skinFileName.Replace(wxT("System:"), systemDir );
1215 m_skinFileName.Assign(skinFileName);
1216 if (!m_skinFileName.FileExists()) {
1217 AddLogLineC(CFormat(
1218 _("Skin directory '%s' does not exist")) %
1219 skinFileName );
1220 ret = false;
1221 } else if (!m_skinFileName.IsFileReadable()) {
1222 AddLogLineC(CFormat(
1223 _("WARNING: Unable to open skin file '%s' for read")) %
1224 skinFileName);
1225 ret = false;
1228 wxFFileInputStream in(m_skinFileName.GetFullPath());
1229 wxZipInputStream zip(in);
1231 while ((entry = zip.GetNextEntry()) != NULL) {
1232 wxZipEntry*& current = cat[entry->GetInternalName()];
1233 delete current;
1234 current = entry;
1237 return ret;
1241 void CamuleDlg::Add_Skin_Icon(
1242 const wxString &iconName,
1243 const wxBitmap &stdIcon,
1244 bool useSkins)
1246 wxImage new_image;
1247 if (useSkins) {
1248 wxFFileInputStream in(m_skinFileName.GetFullPath());
1249 wxZipInputStream zip(in);
1251 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1252 if ( it != cat.end() ) {
1253 zip.OpenEntry(*it->second);
1254 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1255 AddLogLineN(wxT("Warning: Error loading icon for ") +
1256 iconName);
1257 useSkins = false;
1259 }else {
1260 AddLogLineN(wxT("Warning: Can't load icon for ") +
1261 iconName);
1262 useSkins = false;
1267 wxBitmap bmp(useSkins ? new_image : stdIcon);
1268 if (iconName.StartsWith(wxT("Client_"))) {
1269 m_imagelist.Add(bmp);
1270 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1271 m_tblist.Add(bmp);
1276 void CamuleDlg::Apply_Clients_Skin()
1278 bool useSkins = Check_and_Init_Skin();
1280 // Clear the client image list
1281 m_imagelist.RemoveAll();
1283 // Add the images to the image list
1284 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1285 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1286 clientImages(i), useSkins);
1291 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1293 bool useSkins = Check_and_Init_Skin();
1296 // Clear the toolbar image list
1297 m_tblist.RemoveAll();
1299 // Add the images to the image list
1300 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1301 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1302 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1303 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1304 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1305 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1306 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1307 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1311 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1312 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1314 // Build aMule toolbar
1315 wndToolbar->SetMargins(0, 0);
1317 // Placeholder. Gets updated by ShowConnectionState
1318 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1320 wndToolbar->AddSeparator();
1321 wndToolbar->AddTool(ID_BUTTONNETWORKS, _("Networks"), m_tblist.GetBitmap(3), wxNullBitmap, wxITEM_CHECK, _("Networks Window"));
1322 wndToolbar->AddTool(ID_BUTTONSEARCH, _("Searches"), m_tblist.GetBitmap(5), wxNullBitmap, wxITEM_CHECK, _("Searches Window"));
1323 wndToolbar->AddTool(ID_BUTTONDOWNLOADS, _("Downloads"), m_tblist.GetBitmap(4), wxNullBitmap, wxITEM_CHECK, _("Downloads Window"));
1324 wndToolbar->AddTool(ID_BUTTONSHARED, _("Shared files"), m_tblist.GetBitmap(6), wxNullBitmap, wxITEM_CHECK, _("Shared Files Window"));
1325 wndToolbar->AddTool(ID_BUTTONMESSAGES, _("Messages"), m_tblist.GetBitmap(7), wxNullBitmap, wxITEM_CHECK, _("Messages Window"));
1326 wndToolbar->AddTool(ID_BUTTONSTATISTICS, _("Statistics"), m_tblist.GetBitmap(8), wxNullBitmap, wxITEM_CHECK, _("Statistics Graph Window"));
1327 wndToolbar->AddSeparator();
1328 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES, _("Preferences"), m_tblist.GetBitmap(9), wxNullBitmap, wxITEM_NORMAL, _("Preferences Settings Window"));
1329 wndToolbar->AddTool(ID_BUTTONIMPORT, _("Import"), m_tblist.GetBitmap(10), wxNullBitmap, wxITEM_NORMAL, _("The partfile importer tool"));
1330 wndToolbar->AddTool(ID_ABOUT, _("About"), m_tblist.GetBitmap(11), wxNullBitmap, wxITEM_NORMAL, _("About/Help"));
1332 wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true);
1334 // Needed for non-GTK platforms, where the
1335 // items don't get added immediatly.
1336 wndToolbar->Realize();
1338 // Updates the "Connect" button, and so on.
1339 ShowConnectionState(true);
1343 void CamuleDlg::Create_Toolbar(bool orientation)
1345 Freeze();
1346 // Create ToolBar from the one designed by wxDesigner (BigBob)
1347 wxToolBar *current = GetToolBar();
1349 wxASSERT(current == m_wndToolbar);
1351 if (current) {
1352 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1353 if (oldorientation != orientation) {
1354 current->Destroy();
1355 SetToolBar(NULL); // Remove old one if present
1356 m_wndToolbar = NULL;
1357 } else {
1358 current->ClearTools();
1362 if (!m_wndToolbar) {
1363 m_wndToolbar = CreateToolBar(
1364 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1365 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1366 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1369 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1372 Apply_Toolbar_Skin(m_wndToolbar);
1374 Thaw();
1378 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1380 wxFrame::OnSize(evt);
1381 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1382 // Transfer window's splitter set again if it's hidden.
1383 if (!m_transferwnd->clientlistctrl->GetShowing()) {
1384 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1385 wxSplitterWindow* splitter =
1386 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1387 height += splitter->GetWindow1()->GetSize().GetHeight();
1388 splitter->SetSashPosition( height );
1395 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1397 if (event.GetKeyCode() == WXK_F1) {
1398 // Ctrl/Alt/Shift must not be pressed, to avoid
1399 // conflicts with other (global) shortcuts.
1400 if (!event.HasModifiers() && !event.ShiftDown()) {
1401 LaunchUrl(wxT("http://wiki.amule.org"));
1402 return;
1406 event.Skip();
1410 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1412 Close();
1415 void CamuleDlg::DoNetworkRearrange()
1418 wxWindowUpdateLocker freezer(this);
1420 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1422 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1423 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1425 while (logs_notebook->GetPageCount() > 1) {
1426 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1429 while (networks_notebook->GetPageCount() > 0) {
1430 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1433 if (thePrefs::GetNetworkED2K()) {
1434 #ifndef CLIENT_GUI
1435 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1436 #endif
1437 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1440 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1442 if (thePrefs::GetNetworkKademlia()) {
1443 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1446 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1448 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1450 wxWindow* replacement = NULL;
1452 m_networknotebooksizer->Clear();
1454 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1455 toolbarTool->SetLabel(_("Networks"));
1457 m_networkpages[0].page->Reparent(networks_notebook);
1458 m_networkpages[1].page->Reparent(networks_notebook);
1460 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1461 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1463 replacement = networks_notebook;
1465 } else if (thePrefs::GetNetworkED2K()) {
1466 toolbarTool->SetLabel(_("eD2k network"));
1467 replacement = m_networkpages[0].page;
1468 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1469 } else if (thePrefs::GetNetworkKademlia()) {
1470 toolbarTool->SetLabel(_("Kad network"));
1471 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1472 replacement = m_networkpages[1].page;
1473 } else {
1474 // No networks.
1475 toolbarTool->SetLabel(_("No network"));
1478 if (replacement) {
1479 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1480 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1481 m_networknotebooksizer->Layout();
1484 m_wndToolbar->InsertTool(2, toolbarTool);
1486 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1487 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
1489 m_wndToolbar->Realize();
1491 m_searchwnd->FixSearchTypes();
1494 // File_checked_for_headers