Whitespace
[amule.git] / src / amuleDlg.cpp
blob744af1acf32f72af5fe93ea651fd2b83a1e7cbef
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <wx/app.h>
28 #include <wx/archive.h>
29 #include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
30 #include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
31 #include <wx/html/htmlwin.h>
32 #include <wx/mimetype.h> // Do_not_auto_remove (win32)
33 #include <wx/stattext.h>
34 #include <wx/stdpaths.h>
35 #include <wx/textfile.h> // Do_not_auto_remove (win32)
36 #include <wx/tokenzr.h>
37 #include <wx/wfstream.h>
38 #include <wx/zipstrm.h>
39 #include <wx/sysopt.h>
40 #include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker
42 #include <common/EventIDs.h>
44 #ifdef HAVE_CONFIG_H
45 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
46 #else
47 #include <common/ClientVersion.h>
48 #endif // HAVE_CONFIG_H
50 #include "amuleDlg.h" // Interface declarations.
52 #include <common/Format.h> // Needed for CFormat
53 #include "amule.h" // Needed for theApp
54 #include "ChatWnd.h" // Needed for CChatWnd
55 #include "SourceListCtrl.h" // Needed for CSourceListCtrl
56 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
57 #include "DownloadQueue.h" // Needed for CDownloadQueue
58 #include "KadDlg.h" // Needed for CKadDlg
59 #include "Logger.h"
60 #include "MuleTrayIcon.h"
61 #include "muuli_wdr.h" // Needed for ID_BUTTON*
62 #include "Preferences.h" // Needed for CPreferences
63 #include "PrefsUnifiedDlg.h"
64 #include "SearchDlg.h" // Needed for CSearchDlg
65 #include "Server.h" // Needed for CServer
66 #include "ServerConnect.h" // Needed for CServerConnect
67 #include "ServerWnd.h" // Needed for CServerWnd
68 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
69 #include "SharedFilePeersListCtrl.h" // Needed for CSharedFilePeersListCtrl
70 #include "Statistics.h" // Needed for theStats
71 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
72 #include "TerminationProcess.h" // Needed for CTerminationProcess
73 #include "TransferWnd.h" // Needed for CTransferWnd
74 #ifndef CLIENT_GUI
75 #include "PartFileConvertDlg.h"
76 #endif
77 #include "IPFilter.h"
79 #ifndef __WINDOWS__
80 #include "aMule.xpm"
81 #endif
83 #include "kademlia/kademlia/Kademlia.h"
85 #ifdef ENABLE_IP2COUNTRY
86 #include "IP2Country.h" // Needed for IP2Country
87 #endif
89 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
90 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
91 void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
93 m_IP2Country->DownloadFinished(result);
96 void CamuleDlg::EnableIP2Country()
98 if (thePrefs::IsGeoIPEnabled()) {
99 m_IP2Country->Enable();
103 #else
105 void CamuleDlg::IP2CountryDownloadFinished(uint32){}
106 void CamuleDlg::EnableIP2Country(){}
108 #endif
110 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
112 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
113 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
114 EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)
115 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
116 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
117 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
118 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
120 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
121 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
123 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
125 EVT_CLOSE(CamuleDlg::OnClose)
126 EVT_ICONIZE(CamuleDlg::OnMinimize)
128 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
130 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
132 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
134 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
136 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
138 END_EVENT_TABLE()
140 #ifndef wxCLOSE_BOX
141 #define wxCLOSE_BOX 0
142 #endif
144 CamuleDlg::CamuleDlg(
145 wxWindow* pParent,
146 const wxString &title,
147 wxPoint where,
148 wxSize dlg_size)
150 wxFrame(
151 pParent, -1, title, where, dlg_size,
152 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
153 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
154 wxT("aMule")),
155 m_activewnd(NULL),
156 m_transferwnd(NULL),
157 m_serverwnd(NULL),
158 m_sharedfileswnd(NULL),
159 m_searchwnd(NULL),
160 m_chatwnd(NULL),
161 m_statisticswnd(NULL),
162 m_kademliawnd(NULL),
163 m_prefsDialog(NULL),
164 m_srv_split_pos(0),
165 m_imagelist(16,16),
166 m_tblist(32,32),
167 m_prefsVisible(false),
168 m_wndToolbar(NULL),
169 m_wndTaskbarNotifier(NULL),
170 m_nActiveDialog(DT_NETWORKS_WND),
171 m_is_safe_state(false),
172 m_BlinkMessages(false),
173 m_CurrentBlinkBitmap(24),
174 m_last_iconizing(0),
175 m_skinFileName(),
176 m_clientSkinNames(CLIENT_SKIN_SIZE)
178 // Initialize skin names
179 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
180 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
181 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
182 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
183 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
184 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
185 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
186 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
187 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
188 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
189 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
190 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
191 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
192 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
193 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
194 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
195 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
196 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
197 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
198 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
199 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
200 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
201 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
202 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
203 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
204 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
205 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
207 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
208 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
209 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
210 wxInitAllImageHandlers();
211 Apply_Clients_Skin();
213 #ifdef __WINDOWS__
214 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
215 #endif
217 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
218 // this crashes on Mac with wx 2.9
219 SetIcon(wxICON(aMule));
220 #endif
222 srand(time(NULL));
224 // Create new sizer and stuff a wxPanel in there.
225 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
226 s_main->AddGrowableCol(0);
227 s_main->AddGrowableRow(0);
229 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
230 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
231 muleDlg(p_cnt, false, true);
232 SetSizer(s_main, true);
234 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
235 AddLogLineN(wxEmptyString);
236 AddLogLineN(wxT(" - ") +
237 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
238 AddLogLineN(wxT(" ") +
239 CFormat(_("Running on %s")) % wxGetOsDescription());
240 AddLogLineN(wxT(" - ") +
241 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
242 AddLogLineN(wxEmptyString);
244 #ifdef ENABLE_IP2COUNTRY
245 m_GeoIPavailable = true;
246 m_IP2Country = new CIP2Country(thePrefs::GetConfigDir());
247 #else
248 m_GeoIPavailable = false;
249 #endif
250 m_searchwnd = new CSearchDlg(p_cnt);
251 m_transferwnd = new CTransferWnd(p_cnt);
252 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
253 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
254 m_chatwnd = new CChatWnd(p_cnt);
255 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
257 m_serverwnd->Show(false);
258 m_searchwnd->Show(false);
259 m_transferwnd->Show(false);
260 m_sharedfileswnd->Show(false);
261 m_statisticswnd->Show(false);
262 m_chatwnd->Show(false);
264 // Create the GUI timer
265 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
266 if (!gui_timer) {
267 AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
268 exit(1);
271 // Set transfers as active window
272 Create_Toolbar(thePrefs::VerticalToolbar());
273 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
274 m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true );
276 bool override_where = (where != wxDefaultPosition);
277 bool override_size = (
278 (dlg_size.x != DEFAULT_SIZE_X) ||
279 (dlg_size.y != DEFAULT_SIZE_Y) );
280 if (!LoadGUIPrefs(override_where, override_size)) {
281 // Prefs not loaded for some reason, exit
282 AddLogLineC(wxT("Error! Unable to load Preferences") );
283 return;
286 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
287 m_transferwnd->Prepare();
289 m_is_safe_state = true;
291 // Init statistics stuff, better do it asap
292 m_statisticswnd->Init();
293 m_kademliawnd->Init();
294 m_searchwnd->UpdateCatChoice();
296 if (thePrefs::UseTrayIcon()) {
297 CreateSystray();
300 Show(true);
301 // Must we start minimized?
302 if (thePrefs::GetStartMinimized()) {
303 DoIconize(true);
306 // Set shortcut keys
307 wxAcceleratorEntry entries[] = {
308 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
311 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
312 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
314 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
315 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
317 wxASSERT(logs_notebook->GetPageCount() == 4);
318 wxASSERT(networks_notebook->GetPageCount() == 2);
320 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
321 m_logpages[i].page = logs_notebook->GetPage(i);
322 m_logpages[i].name = logs_notebook->GetPageText(i);
325 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
326 m_networkpages[i].page = networks_notebook->GetPage(i);
327 m_networkpages[i].name = networks_notebook->GetPageText(i);
330 DoNetworkRearrange();
334 // Madcat - Sets Fast ED2K Links Handler on/off.
335 void CamuleDlg::ShowED2KLinksHandler( bool show )
337 // Errorchecking in case the pointer becomes invalid ...
338 if (s_fed2klh == NULL) {
339 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
340 return;
343 s_dlgcnt->Show( s_fed2klh, show );
344 s_dlgcnt->Layout();
347 // Toogles ed2k link handler.
348 void CamuleDlg::ToogleED2KLinksHandler()
350 // Errorchecking in case the pointer becomes invalid ...
351 if (s_fed2klh == NULL) {
352 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
353 return;
355 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
358 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
360 m_nActiveDialog = type;
362 if ( type == DT_TRANSFER_WND ) {
363 if (thePrefs::ShowCatTabInfos()) {
364 m_transferwnd->UpdateCatTabTitles();
368 if ( m_activewnd ) {
369 m_activewnd->Show(false);
370 contentSizer->Detach(m_activewnd);
373 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
374 dlg->Show(true);
375 m_activewnd=dlg;
376 s_dlgcnt->Layout();
378 // Since we might be suspending redrawing while hiding the dialog
379 // we have to refresh it once it is visible again
380 dlg->Refresh( true );
381 dlg->SetFocus();
383 if ( type == DT_SHARED_WND ) {
384 // set up splitter now that window sizes are defined
385 m_sharedfileswnd->Prepare();
390 void CamuleDlg::UpdateTrayIcon(int percent)
392 // set trayicon-icon
393 if(!theApp->IsConnected()) {
394 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
395 } else {
396 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
397 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
398 } else {
399 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
405 void CamuleDlg::CreateSystray()
407 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
408 wxT("Systray already created"));
410 m_wndTaskbarNotifier = new CMuleTrayIcon();
411 // This will effectively show the Tray Icon.
412 UpdateTrayIcon(0);
416 void CamuleDlg::RemoveSystray()
418 delete m_wndTaskbarNotifier;
419 m_wndTaskbarNotifier = NULL;
423 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
425 static int lastbutton = ID_BUTTONDOWNLOADS;
427 // Kry - just if the GUI is ready for it
428 if ( m_is_safe_state ) {
430 // Rehide the handler if needed
431 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
432 if (ev.GetId() != ID_BUTTONSEARCH) {
433 ShowED2KLinksHandler( false );
434 } else {
435 // Toogle ED2K handler.
436 ToogleED2KLinksHandler();
440 if ( lastbutton != ev.GetId() ) {
441 switch ( ev.GetId() ) {
442 case ID_BUTTONNETWORKS:
443 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
444 // Set serverlist splitter position
445 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
446 break;
448 case ID_BUTTONSEARCH:
449 // The search dialog should always display the handler
450 if ( !thePrefs::GetFED2KLH() )
451 ShowED2KLinksHandler( true );
453 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
454 break;
456 case ID_BUTTONDOWNLOADS:
457 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
458 // Prepare the dialog, sets the splitter-position
459 m_transferwnd->Prepare();
460 break;
462 case ID_BUTTONSHARED:
463 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
464 break;
466 case ID_BUTTONMESSAGES:
467 m_BlinkMessages = false;
468 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
469 break;
471 case ID_BUTTONSTATISTICS:
472 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
473 break;
475 // This shouldn't happen, but just in case
476 default:
477 AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
478 break;
482 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
483 lastbutton = ev.GetId();
488 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
490 wxString msg = wxT(" ");
491 #ifdef CLIENT_GUI
492 msg << _("aMule remote control ") << wxT(VERSION);
493 #else
494 msg << wxT("aMule ") << wxT(VERSION);
495 #endif
496 msg << wxT(" ");
497 #ifdef SVNDATE
498 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
499 #endif
500 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
501 _("Website: http://www.amule.org \n") <<
502 _("Forum: http://forum.amule.org \n") <<
503 _("FAQ: http://wiki.amule.org \n\n") <<
504 _("Contact: admin@amule.org (administrative issues) \n") <<
505 _("Copyright (c) 2003-2011 aMule Team \n\n") <<
506 _("Part of aMule is based on \n") <<
507 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
508 _(" Copyright (c) 2002-2011 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
509 _("http://kademlia.scs.cs.nyu.edu\n");
511 if (m_is_safe_state) {
512 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
517 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
519 if (m_is_safe_state) {
520 if (m_prefsDialog == NULL) {
521 m_prefsDialog = new PrefsUnifiedDlg(this);
524 m_prefsDialog->TransferToWindow();
525 m_prefsDialog->Show(true);
526 m_prefsDialog->Raise();
531 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
533 #ifndef CLIENT_GUI
534 if (m_is_safe_state) {
535 CPartFileConvertDlg::ShowGUI(NULL);
537 #endif
541 CamuleDlg::~CamuleDlg()
543 theApp->amuledlg = NULL;
545 #ifdef ENABLE_IP2COUNTRY
546 delete m_IP2Country;
547 #endif
549 AddLogLineN(_("aMule dialog destroyed"));
553 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
556 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
557 #ifdef CLIENT_GUI
558 || theApp->IsConnectedKad() // there's no Kad running state atm
559 #else
560 || (Kademlia::CKademlia::IsRunning())
561 #endif
563 if (thePrefs::GetNetworkED2K()) {
564 if (disconnect) {
565 //disconnect if currently connected
566 if (theApp->serverconnect->IsConnecting()) {
567 theApp->serverconnect->StopConnectionTry();
568 } else {
569 theApp->serverconnect->Disconnect();
571 } else {
572 //connect if not currently connected
573 AddLogLineC(_("Connecting"));
574 theApp->serverconnect->ConnectToAnyServer();
576 } else {
577 wxASSERT(!theApp->IsConnectedED2K());
580 // Connect Kad also
581 if (thePrefs::GetNetworkKademlia()) {
582 if( disconnect ) {
583 theApp->StopKad();
584 } else {
585 theApp->StartKad();
587 } else {
588 #ifndef CLIENT_GUI
589 wxASSERT(!Kademlia::CKademlia::IsRunning());
590 #endif
593 ShowConnectionState();
597 void CamuleDlg::ResetLog(int id)
599 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
600 wxCHECK_RET(ct, wxT("Resetting unknown log"));
602 ct->Clear();
604 if (id == ID_LOGVIEW) {
605 // Also clear the log line
606 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
607 text->SetLabel(wxEmptyString);
608 text->GetParent()->Layout();
613 void CamuleDlg::AddLogLine(const wxString& line)
615 bool addtostatusbar = line[0] == '!';
616 wxString bufferline = line.Mid(1);
618 // Add the message to the log-view
619 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
620 if ( ct ) {
621 // Bold critical log-lines
622 // Works in Windows too thanks to wxTE_RICH2 style in muuli
623 wxTextAttr style = ct->GetDefaultStyle();
624 wxFont font = style.GetFont();
625 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
626 style.SetFont(font);
627 #if wxCHECK_VERSION(2, 9, 0)
628 style.SetFontSize(8);
629 #endif
630 ct->SetDefaultStyle(style);
631 ct->AppendText(bufferline);
632 ct->ShowPosition( ct->GetLastPosition() - 1 );
636 // Set the status-bar if the event warrents it
637 if ( addtostatusbar ) {
638 // Escape "&"s, which would otherwise not show up
639 bufferline.Replace( wxT("&"), wxT("&&") );
640 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
641 // Only show the first line if multiple lines
642 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
643 text->SetToolTip( bufferline );
644 text->GetParent()->Layout();
650 void CamuleDlg::AddServerMessageLine(wxString& message)
652 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
653 if(cv) {
654 if (message.Length() > 500) {
655 cv->AppendText(message.Left(500) + wxT("\n"));
656 } else {
657 cv->AppendText(message + wxT("\n"));
659 cv->ShowPosition(cv->GetLastPosition()-1);
664 void CamuleDlg::ShowConnectionState(bool skinChanged)
666 static wxImageList status_arrows(16,16,true,0);
667 if (!status_arrows.GetImageCount()) {
668 // Generate the image list (This is only done once)
669 for (int t = 0; t < 7; ++t) {
670 status_arrows.Add(connImages(t));
674 m_serverwnd->UpdateED2KInfo();
675 m_serverwnd->UpdateKadInfo();
678 ////////////////////////////////////////////////////////////
679 // Determine the status of the networks
681 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
682 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
684 ED2KState ed2kState = ED2KOff;
685 EKadState kadState = EKadOff;
687 ////////////////////////////////////////////////////////////
688 // Update the label on the status-bar and determine
689 // the states of the two networks.
691 wxString msgED2K;
692 if (theApp->IsConnectedED2K()) {
693 CServer* server = theApp->serverconnect->GetCurrentServer();
694 if (server) {
695 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
698 if (theApp->serverconnect->IsLowID()) {
699 ed2kState = ED2KLowID;
700 } else {
701 ed2kState = ED2KHighID;
703 } else if (theApp->serverconnect->IsConnecting()) {
704 msgED2K = _("eD2k: Connecting");
706 ed2kState = ED2KConnecting;
707 } else if (thePrefs::GetNetworkED2K()) {
708 msgED2K = _("eD2k: Disconnected");
711 wxString msgKad;
712 if (theApp->IsConnectedKad()) {
713 if (theApp->IsFirewalledKad()) {
714 msgKad = _("Kad: Firewalled");
716 kadState = EKadFW;
717 } else {
718 msgKad = _("Kad: Connected");
720 kadState = EKadOK;
722 } else if (theApp->IsKadRunning()) {
723 msgKad = _("Kad: Connecting");
725 kadState = EKadConnecting;
726 } else if (thePrefs::GetNetworkKademlia()) {
727 msgKad = _("Kad: Off");
730 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
731 { wxCHECK_RET(connLabel, wxT("'connLabel' widget not found")); }
733 wxString labelMsg;
734 if (msgED2K.Length() && msgKad.Length()) {
735 labelMsg = msgED2K + wxT(" | ") + msgKad;
736 } else {
737 labelMsg = msgED2K + msgKad;
740 connLabel->SetLabel(labelMsg);
741 connLabel->GetParent()->Layout();
744 ////////////////////////////////////////////////////////////
745 // Update the connect/disconnect/cancel button.
747 enum EConnState {
748 ECS_Unknown,
749 ECS_Connected,
750 ECS_Connecting,
751 ECS_Disconnected
754 static EConnState s_oldState = ECS_Unknown;
755 EConnState currentState = ECS_Disconnected;
757 if (theApp->serverconnect->IsConnecting() ||
758 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
759 currentState = ECS_Connecting;
760 } else if (theApp->IsConnected()) {
761 currentState = ECS_Connected;
762 } else {
763 currentState = ECS_Disconnected;
766 if ( (true == skinChanged) || (currentState != s_oldState) ) {
767 wxWindowUpdateLocker freezer(m_wndToolbar);
769 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
771 switch (currentState) {
772 case ECS_Connecting:
773 toolbarTool->SetLabel(_("Cancel"));
774 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
775 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
776 break;
778 case ECS_Connected:
779 toolbarTool->SetLabel(_("Disconnect"));
780 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
781 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
782 break;
784 default:
785 toolbarTool->SetLabel(_("Connect"));
786 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
787 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
790 m_wndToolbar->InsertTool(0, toolbarTool);
791 m_wndToolbar->Realize();
792 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
794 s_oldState = currentState;
798 ////////////////////////////////////////////////////////////
799 // Update the globe-icon in the lower-right corner.
800 // (only if connection state has changed)
802 static ED2KState s_ED2KOldState = ED2KUndef;
803 static EKadState s_EKadOldState = EKadUndef;
804 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
805 s_ED2KOldState = ed2kState;
806 s_EKadOldState = kadState;
807 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
808 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
810 wxBitmap statusIcon = connBitmap->GetBitmap();
811 // Sanity check - otherwise there's a crash here if aMule runs out of resources
812 if (statusIcon.GetRefData() == NULL) {
813 return;
816 wxMemoryDC bitmapDC(statusIcon);
818 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
819 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
821 connBitmap->SetBitmap(statusIcon);
826 void CamuleDlg::ShowUserCount(const wxString& info)
828 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
830 // Update Kad tab
831 m_serverwnd->UpdateKadInfo();
833 label->SetLabel(info);
834 label->GetParent()->Layout();
838 void CamuleDlg::ShowTransferRate()
840 float kBpsUp = theStats::GetUploadRate() / 1024.0;
841 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
842 wxString buffer;
843 if( thePrefs::ShowOverhead() )
845 buffer = CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp % (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown % (theStats::GetDownOverheadRate() / 1024.0);
846 } else {
847 buffer = CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
849 buffer.Truncate(50); // Max size 50
851 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
852 label->SetLabel(buffer);
853 label->GetParent()->Layout();
855 // Show upload/download speed in title
856 if (thePrefs::GetShowRatesOnTitle()) {
857 wxString UpDownSpeed = CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
858 if (thePrefs::GetShowRatesOnTitle() == 1) {
859 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
860 } else {
861 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
865 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
866 if (m_wndTaskbarNotifier) {
867 // set trayicon-icon
868 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
869 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
871 wxString buffer2;
872 if ( theApp->IsConnected() ) {
873 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
874 } else {
875 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
877 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
880 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
881 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
884 void CamuleDlg::DlgShutDown()
886 // Are we already shutting down or still on init?
887 if ( m_is_safe_state == false ) {
888 return;
891 // we are going DOWN
892 m_is_safe_state = false;
894 // Stop the GUI Timer
895 delete gui_timer;
896 m_transferwnd->downloadlistctrl->DeleteAllItems();
898 // We want to delete the systray too!
899 RemoveSystray();
902 void CamuleDlg::OnClose(wxCloseEvent& evt)
904 if (thePrefs::HideOnClose() && evt.CanVeto()) {
905 Show(false);
906 evt.Veto();
907 return;
910 // This will be here till the core close is != app close
911 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
912 if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
913 wxString(_("Exit confirmation")), wxYES_NO, this)) {
914 evt.Veto();
915 return;
919 SaveGUIPrefs();
921 Enable(false);
922 Show(false);
924 theApp->ShutDown(evt);
928 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
930 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
932 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
933 wxString strlink = ctl->GetLineText(i);
934 strlink.Trim(true);
935 strlink.Trim(false);
936 if ( !strlink.IsEmpty() ) {
937 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
941 ctl->SetValue(wxEmptyString);
945 // Formerly known as LoadRazorPrefs()
946 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
948 // Create a config base for loading razor preferences
949 wxConfigBase *config = wxConfigBase::Get();
950 // If config haven't been created exit without loading
951 if (config == NULL) {
952 return false;
955 // The section where to save in in file
956 wxString section = wxT("/Razor_Preferences/");
958 // Get window size and position
959 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
960 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
961 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
962 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
964 int maximized = config->Read(section + wxT("Maximized"), 01);
966 // Kry - Random usable pos for m_srv_split_pos
967 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
968 if (!override_size) {
969 if (x2 > 0 && y2 > 0) {
970 SetSize(x2, y2);
971 } else {
972 #ifndef __WXGTK__
973 // Probably first run.
974 Maximize();
975 #endif
979 if (!override_pos) {
980 // If x1 and y1 != -1 Redefine location
981 if(x1 != -1 && y1 != -1) {
982 wxRect display = wxGetClientDisplayRect();
983 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
984 Move(x1, y1);
985 } else {
986 // It's offscreen... so let's not.
991 if (!override_size && !override_pos && maximized) {
992 Maximize();
995 return true;
999 bool CamuleDlg::SaveGUIPrefs()
1001 /* Razor 1a - Modif by MikaelB
1002 Save client size and position */
1004 // Create a config base for saving razor preferences
1005 wxConfigBase *config = wxConfigBase::Get();
1006 // If config haven't been created exit without saving
1007 if (config == NULL) {
1008 return false;
1010 // The section where to save in in file
1011 wxString section = wxT("/Razor_Preferences/");
1013 if (!IsIconized()) {
1014 // Main window location and size
1015 int x1, y1, x2, y2;
1016 GetPosition(&x1, &y1);
1017 GetSize(&x2, &y2);
1019 // Saving window size and position
1020 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1021 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1023 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1024 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1026 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1029 // Saving sash position of splitter in server window
1030 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1032 config->Flush(true);
1034 /* End modif */
1036 return true;
1040 void CamuleDlg::DoIconize(bool iconize)
1042 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1043 if (iconize) {
1044 // Skip() will do it.
1045 //Iconize(true);
1046 if (SafeState()) {
1047 Show(false);
1049 } else {
1050 Show(true);
1051 Raise();
1053 } else {
1054 // Will be done by Skip();
1055 //Iconize(iconize);
1059 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1061 // Evil Hack: check if the mouse is inside the window
1062 #ifndef __WINDOWS__
1063 if (GetScreenRect().Contains(wxGetMousePosition()))
1064 #endif
1066 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1067 // Veto.
1068 } else {
1069 if (m_wndTaskbarNotifier) {
1070 #if wxCHECK_VERSION(2, 9, 0)
1071 DoIconize(evt.IsIconized());
1072 #else
1073 DoIconize(evt.Iconized());
1074 #endif
1076 evt.Skip();
1081 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1083 // Former TimerProc section
1085 static uint32 msPrev1, msPrev5;
1087 uint32 msCur = theStats::GetUptimeMillis();
1089 // can this actually happen under wxwin ?
1090 if (!SafeState()) {
1091 return;
1094 #ifndef CLIENT_GUI
1095 static uint32 msPrevGraph, msPrevStats;
1096 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1097 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1098 // trying to get the graph shifts evenly spaced after a change in the update period
1099 msPrevGraph = msCur;
1101 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1103 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1104 m_kademliawnd->UpdateGraph(update);
1107 int sStatsUpdate = thePrefs::GetStatsInterval();
1108 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1109 if (m_statisticswnd->IsShownOnScreen()) {
1110 msPrevStats = msCur;
1111 m_statisticswnd->ShowStatistics();
1114 #endif
1116 if (msCur-msPrev5 > 5000) { // every 5 seconds
1117 msPrev5 = msCur;
1118 ShowTransferRate();
1119 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1120 m_transferwnd->UpdateCatTabTitles();
1122 if (thePrefs::AutoSortDownload()) {
1123 m_transferwnd->downloadlistctrl->SortList();
1124 m_transferwnd->clientlistctrl->SortList();
1125 m_sharedfileswnd->peerslistctrl->SortList();
1127 m_kademliawnd->UpdateNodeCount(CStatistics::GetKadNodes());
1130 if (msCur-msPrev1 > 1000) { // every second
1131 msPrev1 = msCur;
1132 if (m_CurrentBlinkBitmap == 12) {
1133 m_CurrentBlinkBitmap = 7;
1134 SetMessagesTool();
1135 } else {
1136 if (m_BlinkMessages) {
1137 m_CurrentBlinkBitmap = 12;
1138 SetMessagesTool();
1146 void CamuleDlg::SetMessagesTool()
1148 wxWindowUpdateLocker freezer(m_wndToolbar);
1149 #ifdef __WXCOCOA__
1150 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1151 #else
1152 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1153 #endif
1156 void CamuleDlg::LaunchUrl( const wxString& url )
1158 wxString cmd;
1160 cmd = thePrefs::GetBrowser();
1161 wxString tmp = url;
1162 // Pipes cause problems, so escape them
1163 tmp.Replace( wxT("|"), wxT("%7C") );
1165 if ( !cmd.IsEmpty() ) {
1166 if (!cmd.Replace(wxT("%s"), tmp)) {
1167 // No %s found, just append the url
1168 cmd += wxT(" ") + tmp;
1171 CTerminationProcess *p = new CTerminationProcess(cmd);
1172 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1173 AddLogLineN(_("Launch Command: ") + cmd);
1174 return;
1175 } else {
1176 delete p;
1178 } else {
1179 wxLaunchDefaultBrowser(tmp);
1180 return;
1182 // Unable to execute browser. But this error message doesn't make sense,
1183 // cosidering that you _can't_ set the browser executable path... =/
1184 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1188 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1190 wxString URL;
1191 switch (wsProvider) {
1192 case WS_FILEHASH:
1193 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1194 break;
1195 default:
1196 wxFAIL;
1198 URL.Replace(wxT("FILENAME"), filename);
1200 return URL;
1204 bool CamuleDlg::Check_and_Init_Skin()
1206 bool ret = true;
1207 wxString skinFileName(thePrefs::GetSkin());
1209 if (skinFileName.IsEmpty() || skinFileName.IsSameAs(_("- default -"))) {
1210 return false;
1213 wxString userDir(JoinPaths(thePrefs::GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1215 wxStandardPathsBase &spb(wxStandardPaths::Get());
1216 #ifdef __WINDOWS__
1217 wxString dataDir(spb.GetPluginsDir());
1218 #elif defined(__WXMAC__)
1219 wxString dataDir(spb.GetDataDir());
1220 #else
1221 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1222 #endif
1223 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1226 skinFileName.Replace(wxT("User:"), userDir );
1227 skinFileName.Replace(wxT("System:"), systemDir );
1229 m_skinFileName.Assign(skinFileName);
1230 if (!m_skinFileName.FileExists()) {
1231 AddLogLineC(CFormat(
1232 _("Skin directory '%s' does not exist")) %
1233 skinFileName );
1234 ret = false;
1235 } else if (!m_skinFileName.IsFileReadable()) {
1236 AddLogLineC(CFormat(
1237 _("WARNING: Unable to open skin file '%s' for read")) %
1238 skinFileName);
1239 ret = false;
1242 wxFFileInputStream in(m_skinFileName.GetFullPath());
1243 wxZipInputStream zip(in);
1244 wxZipEntry *entry;
1246 while ((entry = zip.GetNextEntry()) != NULL) {
1247 wxZipEntry*& current = cat[entry->GetInternalName()];
1248 delete current;
1249 current = entry;
1252 return ret;
1256 void CamuleDlg::Add_Skin_Icon(
1257 const wxString &iconName,
1258 const wxBitmap &stdIcon,
1259 bool useSkins)
1261 wxImage new_image;
1262 if (useSkins) {
1263 wxFFileInputStream in(m_skinFileName.GetFullPath());
1264 wxZipInputStream zip(in);
1266 ZipCatalog::iterator it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1267 if ( it != cat.end() ) {
1268 zip.OpenEntry(*it->second);
1269 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1270 AddLogLineN(wxT("Warning: Error loading icon for ") +
1271 iconName);
1272 useSkins = false;
1274 }else {
1275 AddLogLineN(wxT("Warning: Can't load icon for ") +
1276 iconName);
1277 useSkins = false;
1282 wxBitmap bmp(useSkins ? new_image : stdIcon);
1283 if (iconName.StartsWith(wxT("Client_"))) {
1284 m_imagelist.Add(bmp);
1285 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1286 m_tblist.Add(bmp);
1291 void CamuleDlg::Apply_Clients_Skin()
1293 bool useSkins = Check_and_Init_Skin();
1295 // Clear the client image list
1296 m_imagelist.RemoveAll();
1298 // Add the images to the image list
1299 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1300 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1301 clientImages(i), useSkins);
1306 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1308 bool useSkins = Check_and_Init_Skin();
1311 // Clear the toolbar image list
1312 m_tblist.RemoveAll();
1314 // Add the images to the image list
1315 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1316 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1317 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1318 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1319 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1320 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1321 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1322 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1323 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1324 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1325 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1326 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1327 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1329 // Build aMule toolbar
1330 wndToolbar->SetMargins(0, 0);
1332 // Placeholder. Gets updated by ShowConnectionState
1333 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1335 wndToolbar->AddSeparator();
1336 wndToolbar->AddTool(ID_BUTTONNETWORKS, _("Networks"), m_tblist.GetBitmap(3), wxNullBitmap, wxITEM_CHECK, _("Networks Window"));
1337 wndToolbar->AddTool(ID_BUTTONSEARCH, _("Searches"), m_tblist.GetBitmap(5), wxNullBitmap, wxITEM_CHECK, _("Searches Window"));
1338 wndToolbar->AddTool(ID_BUTTONDOWNLOADS, _("Downloads"), m_tblist.GetBitmap(4), wxNullBitmap, wxITEM_CHECK, _("Downloads Window"));
1339 wndToolbar->AddTool(ID_BUTTONSHARED, _("Shared files"), m_tblist.GetBitmap(6), wxNullBitmap, wxITEM_CHECK, _("Shared Files Window"));
1340 wndToolbar->AddTool(ID_BUTTONMESSAGES, _("Messages"), m_tblist.GetBitmap(7), wxNullBitmap, wxITEM_CHECK, _("Messages Window"));
1341 wndToolbar->AddTool(ID_BUTTONSTATISTICS, _("Statistics"), m_tblist.GetBitmap(8), wxNullBitmap, wxITEM_CHECK, _("Statistics Graph Window"));
1342 wndToolbar->AddSeparator();
1343 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES, _("Preferences"), m_tblist.GetBitmap(9), wxNullBitmap, wxITEM_NORMAL, _("Preferences Settings Window"));
1344 #ifndef CLIENT_GUI
1345 wndToolbar->AddTool(ID_BUTTONIMPORT, _("Import"), m_tblist.GetBitmap(10), wxNullBitmap, wxITEM_NORMAL, _("The partfile importer tool"));
1346 #endif
1347 wndToolbar->AddTool(ID_ABOUT, _("About"), m_tblist.GetBitmap(11), wxNullBitmap, wxITEM_NORMAL, _("About/Help"));
1349 wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true);
1351 // Needed for non-GTK platforms, where the
1352 // items don't get added immediatly.
1353 wndToolbar->Realize();
1355 // Updates the "Connect" button, and so on.
1356 ShowConnectionState(true);
1360 void CamuleDlg::Create_Toolbar(bool orientation)
1362 Freeze();
1363 // Create ToolBar from the one designed by wxDesigner (BigBob)
1364 wxToolBar *current = GetToolBar();
1366 wxASSERT(current == m_wndToolbar);
1368 if (current) {
1369 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1370 if (oldorientation != orientation) {
1371 current->Destroy();
1372 SetToolBar(NULL); // Remove old one if present
1373 m_wndToolbar = NULL;
1374 } else {
1375 current->ClearTools();
1379 if (!m_wndToolbar) {
1380 m_wndToolbar = CreateToolBar(
1381 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1382 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1383 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1386 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1389 Apply_Toolbar_Skin(m_wndToolbar);
1391 Thaw();
1395 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1397 wxFrame::OnSize(evt);
1398 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1399 // Transfer window's splitter set again if it's hidden.
1400 if (!m_transferwnd->clientlistctrl->GetShowing()) {
1401 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1402 wxSplitterWindow* splitter =
1403 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1404 height += splitter->GetWindow1()->GetSize().GetHeight();
1405 splitter->SetSashPosition( height );
1411 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1413 if (event.GetKeyCode() == WXK_F1) {
1414 // Ctrl/Alt/Shift must not be pressed, to avoid
1415 // conflicts with other (global) shortcuts.
1416 if (!event.HasModifiers() && !event.ShiftDown()) {
1417 LaunchUrl(wxT("http://wiki.amule.org"));
1418 return;
1422 event.Skip();
1426 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1428 Close(true);
1431 void CamuleDlg::DoNetworkRearrange()
1433 #if !defined(__WXOSX_COCOA__)
1434 // in Mac OS with wxWidgets >= 3.0 and COCOA the following seems to cause problems
1435 // (window is not refreshed after changes in network settings)
1436 wxWindowUpdateLocker freezer(this);
1437 #endif
1439 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1441 // set the log windows
1442 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1444 while (logs_notebook->GetPageCount() > 1) {
1445 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1448 if (thePrefs::GetNetworkED2K()) {
1449 #ifndef CLIENT_GUI
1450 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1451 #endif
1452 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1455 if (thePrefs::GetNetworkKademlia()) {
1456 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1459 // Set the main window.
1460 // If we have both networks active, activate a notebook to select between them.
1461 // If only one is active, show the window directly without a surrounding one tab notebook.
1463 // States:
1464 // 1: ED2K only
1465 // 2: Kad only
1466 // 3: both (in Notebook)
1468 static uint8 currentState = 3; // on startup we have both enabled
1469 uint8 newState;
1470 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1471 newState = 3;
1472 toolbarTool->SetLabel(_("Networks"));
1474 else if (thePrefs::GetNetworkED2K()) {
1475 newState = 1;
1476 toolbarTool->SetLabel(_("eD2k network"));
1478 else { // Kad only or no network
1479 newState = 2; // no network makes no sense anyway, so just show Kad there
1480 toolbarTool->SetLabel(thePrefs::GetNetworkKademlia() ? _("Kad network") : _("No network"));
1483 if (newState != currentState) {
1484 wxNotebook* networks_notebook = CastChild(ID_NETNOTEBOOK, wxNotebook);
1485 // First hide all windows
1486 networks_notebook->Show(false);
1487 m_networkpages[0].page->Show(false);
1488 m_networkpages[1].page->Show(false);
1489 m_networknotebooksizer->Clear();
1491 wxWindow* replacement = NULL;
1493 // Move both pages into the notebook if they aren't already there.
1494 if (currentState == 1) { // ED2K
1495 m_networkpages[0].page->Reparent(networks_notebook);
1496 networks_notebook->InsertPage(0, m_networkpages[0].page, m_networkpages[0].name);
1497 } else if (currentState == 2) { // Kad
1498 m_networkpages[1].page->Reparent(networks_notebook);
1499 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1502 // Now both pages are in the notebook. If we want to show one of them outside, move it back out again.
1503 // Windows that are part of a notebook can't be reparented.
1504 if (newState == 3) {
1505 // Since we messed with the notebook, we now have to show both pages, one after the other.
1506 // Otherwise GTK gets confused and shows the first tab only.
1507 // (So much for "platform independent".)
1508 networks_notebook->SetSelection(1);
1509 m_networkpages[1].page->Show();
1510 networks_notebook->SetSelection(0);
1511 m_networkpages[0].page->Show();
1512 replacement = networks_notebook;
1513 } else if (newState == 1) {
1514 replacement = m_networkpages[0].page;
1515 networks_notebook->RemovePage(0);
1516 } else {
1517 replacement = m_networkpages[1].page;
1518 networks_notebook->RemovePage(1);
1521 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1522 replacement->Show();
1523 m_networknotebooksizer->Add(replacement, 1, wxGROW | wxALIGN_CENTER_VERTICAL | wxTOP, 5);
1524 m_networknotebooksizer->Layout();
1525 currentState = newState;
1528 // Tool bar
1530 m_wndToolbar->InsertTool(2, toolbarTool);
1531 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1532 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
1534 m_wndToolbar->Realize();
1536 ShowConnectionState(); // status in the bottom right
1537 m_searchwnd->FixSearchTypes();
1540 // File_checked_for_headers