Fix restored columns getting an almost-zero width
[amule.git] / src / amuleDlg.cpp
blobeca4232574a97c1c20f4093ea8fe532f3911ebc1
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 "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 #include "PartFileConvertDlg.h"
75 #include "IPFilter.h"
77 #ifndef __WXMSW__
78 #include "aMule.xpm"
79 #endif
81 #include "kademlia/kademlia/Kademlia.h"
83 #ifdef ENABLE_IP2COUNTRY
84 #include "IP2Country.h" // Needed for IP2Country
85 #endif
87 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
88 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
89 void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
91 m_IP2Country->DownloadFinished(result);
94 void CamuleDlg::EnableIP2Country()
96 if (thePrefs::IsGeoIPEnabled()) {
97 m_IP2Country->Enable();
101 #else
103 void CamuleDlg::IP2CountryDownloadFinished(uint32){}
104 void CamuleDlg::EnableIP2Country(){}
106 #endif
108 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
110 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
111 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
112 EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)
113 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
114 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
115 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
116 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
118 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
119 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
121 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
123 EVT_CLOSE(CamuleDlg::OnClose)
124 EVT_ICONIZE(CamuleDlg::OnMinimize)
126 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
128 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
130 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
132 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
134 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
136 END_EVENT_TABLE()
138 #ifndef wxCLOSE_BOX
139 #define wxCLOSE_BOX 0
140 #endif
142 CamuleDlg::CamuleDlg(
143 wxWindow* pParent,
144 const wxString &title,
145 wxPoint where,
146 wxSize dlg_size)
148 wxFrame(
149 pParent, -1, title, where, dlg_size,
150 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
151 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
152 wxT("aMule")),
153 m_activewnd(NULL),
154 m_transferwnd(NULL),
155 m_serverwnd(NULL),
156 m_sharedfileswnd(NULL),
157 m_searchwnd(NULL),
158 m_chatwnd(NULL),
159 m_statisticswnd(NULL),
160 m_kademliawnd(NULL),
161 m_prefsDialog(NULL),
162 m_srv_split_pos(0),
163 m_imagelist(16,16),
164 m_tblist(32,32),
165 m_prefsVisible(false),
166 m_wndToolbar(NULL),
167 m_wndTaskbarNotifier(NULL),
168 m_nActiveDialog(DT_NETWORKS_WND),
169 m_is_safe_state(false),
170 m_BlinkMessages(false),
171 m_CurrentBlinkBitmap(24),
172 m_last_iconizing(0),
173 m_skinFileName(),
174 m_clientSkinNames(CLIENT_SKIN_SIZE)
176 // Initialize skin names
177 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
178 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
179 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
180 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
181 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
182 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
183 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
184 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
185 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
186 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
187 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
188 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
189 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
190 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
191 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
192 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
193 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
194 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
195 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
196 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
197 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
198 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
199 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
200 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
201 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
202 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
203 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
205 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
206 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
207 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
208 wxInitAllImageHandlers();
209 Apply_Clients_Skin();
211 #ifdef __WXMSW__
212 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
213 #endif
215 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
216 // this crashes on Mac with wx 2.9
217 SetIcon(wxICON(aMule));
218 #endif
220 srand(time(NULL));
222 // Create new sizer and stuff a wxPanel in there.
223 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
224 s_main->AddGrowableCol(0);
225 s_main->AddGrowableRow(0);
227 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
228 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
229 muleDlg(p_cnt, false, true);
230 SetSizer(s_main, true);
232 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
233 AddLogLineN(wxEmptyString);
234 AddLogLineN(wxT(" - ") +
235 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
236 AddLogLineN(wxT(" ") +
237 CFormat(_("Running on %s")) % wxGetOsDescription());
238 AddLogLineN(wxT(" - ") +
239 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
240 AddLogLineN(wxEmptyString);
242 #ifdef ENABLE_IP2COUNTRY
243 m_GeoIPavailable = true;
244 m_IP2Country = new CIP2Country(theApp->ConfigDir);
245 #else
246 m_GeoIPavailable = false;
247 #endif
248 m_searchwnd = new CSearchDlg(p_cnt);
249 m_transferwnd = new CTransferWnd(p_cnt);
250 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
251 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
252 m_chatwnd = new CChatWnd(p_cnt);
253 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
255 m_serverwnd->Show(false);
256 m_searchwnd->Show(false);
257 m_transferwnd->Show(false);
258 m_sharedfileswnd->Show(false);
259 m_statisticswnd->Show(false);
260 m_chatwnd->Show(false);
262 // Create the GUI timer
263 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
264 if (!gui_timer) {
265 AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
266 exit(1);
269 // Set transfers as active window
270 Create_Toolbar(thePrefs::VerticalToolbar());
271 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
272 m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true );
274 bool override_where = (where != wxDefaultPosition);
275 bool override_size = (
276 (dlg_size.x != DEFAULT_SIZE_X) ||
277 (dlg_size.y != DEFAULT_SIZE_Y) );
278 if (!LoadGUIPrefs(override_where, override_size)) {
279 // Prefs not loaded for some reason, exit
280 AddLogLineC(wxT("Error! Unable to load Preferences") );
281 return;
284 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
285 m_transferwnd->Prepare();
287 m_is_safe_state = true;
289 // Init statistics stuff, better do it asap
290 m_statisticswnd->Init();
291 m_kademliawnd->Init();
292 m_searchwnd->UpdateCatChoice();
293 if (thePrefs::UseTrayIcon()) {
294 CreateSystray();
297 Show(true);
298 // Must we start minimized?
299 if (thePrefs::GetStartMinimized()) {
300 DoIconize(true);
303 // Set shortcut keys
304 wxAcceleratorEntry entries[] = {
305 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
308 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
309 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
311 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
312 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
314 wxASSERT(logs_notebook->GetPageCount() == 4);
315 wxASSERT(networks_notebook->GetPageCount() == 2);
317 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
318 m_logpages[i].page = logs_notebook->GetPage(i);
319 m_logpages[i].name = logs_notebook->GetPageText(i);
322 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
323 m_networkpages[i].page = networks_notebook->GetPage(i);
324 m_networkpages[i].name = networks_notebook->GetPageText(i);
327 DoNetworkRearrange();
331 // Madcat - Sets Fast ED2K Links Handler on/off.
332 void CamuleDlg::ShowED2KLinksHandler( bool show )
334 // Errorchecking in case the pointer becomes invalid ...
335 if (s_fed2klh == NULL) {
336 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
337 return;
340 s_dlgcnt->Show( s_fed2klh, show );
341 s_dlgcnt->Layout();
344 // Toogles ed2k link handler.
345 void CamuleDlg::ToogleED2KLinksHandler()
347 // Errorchecking in case the pointer becomes invalid ...
348 if (s_fed2klh == NULL) {
349 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
350 return;
352 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
355 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
357 m_nActiveDialog = type;
359 if ( type == DT_TRANSFER_WND ) {
360 if (thePrefs::ShowCatTabInfos()) {
361 m_transferwnd->UpdateCatTabTitles();
365 if ( m_activewnd ) {
366 m_activewnd->Show(false);
367 contentSizer->Detach(m_activewnd);
370 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
371 dlg->Show(true);
372 m_activewnd=dlg;
373 s_dlgcnt->Layout();
375 // Since we might be suspending redrawing while hiding the dialog
376 // we have to refresh it once it is visible again
377 dlg->Refresh( true );
378 dlg->SetFocus();
380 if ( type == DT_SHARED_WND ) {
381 // set up splitter now that window sizes are defined
382 m_sharedfileswnd->Prepare();
387 void CamuleDlg::UpdateTrayIcon(int percent)
389 // set trayicon-icon
390 if(!theApp->IsConnected()) {
391 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
392 } else {
393 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
394 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
395 } else {
396 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
402 void CamuleDlg::CreateSystray()
404 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
405 wxT("Systray already created"));
407 m_wndTaskbarNotifier = new CMuleTrayIcon();
408 // This will effectively show the Tray Icon.
409 UpdateTrayIcon(0);
413 void CamuleDlg::RemoveSystray()
415 delete m_wndTaskbarNotifier;
416 m_wndTaskbarNotifier = NULL;
420 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
422 static int lastbutton = ID_BUTTONDOWNLOADS;
424 // Kry - just if the GUI is ready for it
425 if ( m_is_safe_state ) {
427 // Rehide the handler if needed
428 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
429 if (ev.GetId() != ID_BUTTONSEARCH) {
430 ShowED2KLinksHandler( false );
431 } else {
432 // Toogle ED2K handler.
433 ToogleED2KLinksHandler();
437 if ( lastbutton != ev.GetId() ) {
438 switch ( ev.GetId() ) {
439 case ID_BUTTONNETWORKS:
440 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
441 // Set serverlist splitter position
442 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
443 break;
445 case ID_BUTTONSEARCH:
446 // The search dialog should always display the handler
447 if ( !thePrefs::GetFED2KLH() )
448 ShowED2KLinksHandler( true );
450 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
451 break;
453 case ID_BUTTONDOWNLOADS:
454 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
455 // Prepare the dialog, sets the splitter-position
456 m_transferwnd->Prepare();
457 break;
459 case ID_BUTTONSHARED:
460 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
461 break;
463 case ID_BUTTONMESSAGES:
464 m_BlinkMessages = false;
465 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
466 break;
468 case ID_BUTTONSTATISTICS:
469 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
470 break;
472 // This shouldn't happen, but just in case
473 default:
474 AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
475 break;
479 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
480 lastbutton = ev.GetId();
485 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
487 wxString msg = wxT(" ");
488 #ifdef CLIENT_GUI
489 msg << _("aMule remote control ") << wxT(VERSION);
490 #else
491 msg << wxT("aMule ") << wxT(VERSION);
492 #endif
493 msg << wxT(" ");
494 #ifdef SVNDATE
495 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
496 #endif
497 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
498 _("Website: http://www.amule.org \n") <<
499 _("Forum: http://forum.amule.org \n") <<
500 _("FAQ: http://wiki.amule.org \n\n") <<
501 _("Contact: admin@amule.org (administrative issues) \n") <<
502 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
503 _("Part of aMule is based on \n") <<
504 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
505 _(" Copyright (c) 2002-2008 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
506 _("http://kademlia.scs.cs.nyu.edu\n");
508 if (m_is_safe_state) {
509 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
514 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
516 if (m_is_safe_state) {
517 if (m_prefsDialog == NULL) {
518 m_prefsDialog = new PrefsUnifiedDlg(this);
521 m_prefsDialog->TransferToWindow();
522 m_prefsDialog->Show(true);
523 m_prefsDialog->Raise();
528 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
530 if (m_is_safe_state) {
531 CPartFileConvertDlg::ShowGUI(NULL);
536 CamuleDlg::~CamuleDlg()
538 theApp->amuledlg = NULL;
540 #ifdef ENABLE_IP2COUNTRY
541 delete m_IP2Country;
542 #endif
544 AddLogLineN(_("aMule dialog destroyed"));
548 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
551 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
552 #ifdef CLIENT_GUI
553 || theApp->IsConnectedKad() // there's no Kad running state atm
554 #else
555 || (Kademlia::CKademlia::IsRunning())
556 #endif
558 if (thePrefs::GetNetworkED2K()) {
559 if (disconnect) {
560 //disconnect if currently connected
561 if (theApp->serverconnect->IsConnecting()) {
562 theApp->serverconnect->StopConnectionTry();
563 } else {
564 theApp->serverconnect->Disconnect();
566 } else {
567 //connect if not currently connected
568 AddLogLineC(_("Connecting"));
569 theApp->serverconnect->ConnectToAnyServer();
571 } else {
572 wxASSERT(!theApp->IsConnectedED2K());
575 // Connect Kad also
576 if (thePrefs::GetNetworkKademlia()) {
577 if( disconnect ) {
578 theApp->StopKad();
579 } else {
580 theApp->StartKad();
582 } else {
583 #ifndef CLIENT_GUI
584 wxASSERT(!Kademlia::CKademlia::IsRunning());
585 #endif
588 ShowConnectionState();
592 void CamuleDlg::ResetLog(int id)
594 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
595 wxCHECK_RET(ct, wxT("Resetting unknown log"));
597 ct->Clear();
599 if (id == ID_LOGVIEW) {
600 // Also clear the log line
601 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
602 text->SetLabel(wxEmptyString);
603 text->GetParent()->Layout();
608 void CamuleDlg::AddLogLine(const wxString& line)
610 bool addtostatusbar = line[0] == '!';
611 wxString bufferline = line.Mid(1);
613 // Add the message to the log-view
614 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
615 if ( ct ) {
616 // Bold critical log-lines
617 // to enable this on Windows control has to be changed to wxTE_RICH2 in muuli
618 #ifdef __WXMSW__
619 ct->AppendText(line); // keep the leading "!" if it can't be bolded
620 #else
621 wxTextAttr style = ct->GetDefaultStyle();
622 wxFont font = style.GetFont();
623 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
624 style.SetFont(font);
625 ct->SetDefaultStyle(style);
626 ct->AppendText(bufferline);
627 #endif
628 ct->ShowPosition( ct->GetLastPosition() - 1 );
632 // Set the status-bar if the event warrents it
633 if ( addtostatusbar ) {
634 // Escape "&"s, which would otherwise not show up
635 bufferline.Replace( wxT("&"), wxT("&&") );
636 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
637 // Only show the first line if multiple lines
638 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
639 text->SetToolTip( bufferline );
640 text->GetParent()->Layout();
646 void CamuleDlg::AddServerMessageLine(wxString& message)
648 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
649 if(cv) {
650 if (message.Length() > 500) {
651 cv->AppendText(message.Left(500) + wxT("\n"));
652 } else {
653 cv->AppendText(message + wxT("\n"));
655 cv->ShowPosition(cv->GetLastPosition()-1);
660 void CamuleDlg::ShowConnectionState(bool skinChanged)
662 static wxImageList status_arrows(16,16,true,0);
663 if (!status_arrows.GetImageCount()) {
664 // Generate the image list (This is only done once)
665 for (int t = 0; t < 7; ++t) {
666 status_arrows.Add(connImages(t));
670 m_serverwnd->UpdateED2KInfo();
671 m_serverwnd->UpdateKadInfo();
674 ////////////////////////////////////////////////////////////
675 // Determine the status of the networks
677 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
678 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
680 ED2KState ed2kState = ED2KOff;
681 EKadState kadState = EKadOff;
683 ////////////////////////////////////////////////////////////
684 // Update the label on the status-bar and determine
685 // the states of the two networks.
687 wxString msgED2K;
688 if (theApp->IsConnectedED2K()) {
689 CServer* server = theApp->serverconnect->GetCurrentServer();
690 if (server) {
691 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
694 if (theApp->serverconnect->IsLowID()) {
695 ed2kState = ED2KLowID;
696 } else {
697 ed2kState = ED2KHighID;
699 } else if (theApp->serverconnect->IsConnecting()) {
700 msgED2K = _("eD2k: Connecting");
702 ed2kState = ED2KConnecting;
703 } else if (thePrefs::GetNetworkED2K()) {
704 msgED2K = _("eD2k: Disconnected");
707 wxString msgKad;
708 if (theApp->IsConnectedKad()) {
709 if (theApp->IsFirewalledKad()) {
710 msgKad = _("Kad: Firewalled");
712 kadState = EKadFW;
713 } else {
714 msgKad = _("Kad: Connected");
716 kadState = EKadOK;
718 } else if (theApp->IsKadRunning()) {
719 msgKad = _("Kad: Connecting");
721 kadState = EKadConnecting;
722 } else if (thePrefs::GetNetworkKademlia()) {
723 msgKad = _("Kad: Off");
726 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
727 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
729 wxString labelMsg;
730 if (msgED2K.Length() && msgKad.Length()) {
731 labelMsg = msgED2K + wxT(" | ") + msgKad;
732 } else {
733 labelMsg = msgED2K + msgKad;
736 connLabel->SetLabel(labelMsg);
737 connLabel->GetParent()->Layout();
740 ////////////////////////////////////////////////////////////
741 // Update the connect/disconnect/cancel button.
743 enum EConnState {
744 ECS_Unknown,
745 ECS_Connected,
746 ECS_Connecting,
747 ECS_Disconnected
750 static EConnState s_oldState = ECS_Unknown;
751 EConnState currentState = ECS_Disconnected;
753 if (theApp->serverconnect->IsConnecting() ||
754 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
755 currentState = ECS_Connecting;
756 } else if (theApp->IsConnected()) {
757 currentState = ECS_Connected;
758 } else {
759 currentState = ECS_Disconnected;
762 if ( (true == skinChanged) || (currentState != s_oldState) ) {
763 wxWindowUpdateLocker freezer(m_wndToolbar);
765 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
767 switch (currentState) {
768 case ECS_Connecting:
769 toolbarTool->SetLabel(_("Cancel"));
770 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
771 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
772 break;
774 case ECS_Connected:
775 toolbarTool->SetLabel(_("Disconnect"));
776 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
777 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
778 break;
780 default:
781 toolbarTool->SetLabel(_("Connect"));
782 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
783 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
786 m_wndToolbar->InsertTool(0, toolbarTool);
787 m_wndToolbar->Realize();
788 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
790 s_oldState = currentState;
794 ////////////////////////////////////////////////////////////
795 // Update the globe-icon in the lower-right corner.
796 // (only if connection state has changed)
798 static ED2KState s_ED2KOldState = ED2KUndef;
799 static EKadState s_EKadOldState = EKadUndef;
800 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
801 s_ED2KOldState = ed2kState;
802 s_EKadOldState = kadState;
803 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
804 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
806 wxBitmap statusIcon = connBitmap->GetBitmap();
807 // Sanity check - otherwise there's a crash here if aMule runs out of resources
808 if (statusIcon.GetRefData() == NULL) {
809 return;
812 wxMemoryDC bitmapDC(statusIcon);
814 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
815 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
817 connBitmap->SetBitmap(statusIcon);
822 void CamuleDlg::ShowUserCount(const wxString& info)
824 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
826 // Update Kad tab
827 m_serverwnd->UpdateKadInfo();
829 label->SetLabel(info);
830 label->GetParent()->Layout();
834 void CamuleDlg::ShowTransferRate()
836 float kBpsUp = theStats::GetUploadRate() / 1024.0;
837 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
838 wxString buffer;
839 if( thePrefs::ShowOverhead() )
841 buffer = CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp % (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown % (theStats::GetDownOverheadRate() / 1024.0);
842 } else {
843 buffer = CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
845 buffer.Truncate(50); // Max size 50
847 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
848 label->SetLabel(buffer);
849 label->GetParent()->Layout();
851 // Show upload/download speed in title
852 if (thePrefs::GetShowRatesOnTitle()) {
853 wxString UpDownSpeed = CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
854 if (thePrefs::GetShowRatesOnTitle() == 1) {
855 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
856 } else {
857 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
861 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
862 if (m_wndTaskbarNotifier) {
863 // set trayicon-icon
864 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
865 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
867 wxString buffer2;
868 if ( theApp->IsConnected() ) {
869 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
870 } else {
871 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
873 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
876 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
877 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
880 void CamuleDlg::DlgShutDown()
882 // Are we already shutting down or still on init?
883 if ( m_is_safe_state == false ) {
884 return;
887 // we are going DOWN
888 m_is_safe_state = false;
890 // Stop the GUI Timer
891 delete gui_timer;
892 m_transferwnd->downloadlistctrl->DeleteAllItems();
894 // We want to delete the systray too!
895 RemoveSystray();
898 void CamuleDlg::OnClose(wxCloseEvent& evt)
900 // This will be here till the core close is != app close
901 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
902 if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
903 wxString(_("Exit confirmation")), wxYES_NO, this)) {
904 evt.Veto();
905 return;
909 SaveGUIPrefs();
911 Enable(false);
912 Show(false);
914 theApp->ShutDown(evt);
918 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
920 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
922 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
923 wxString strlink = ctl->GetLineText(i);
924 strlink.Trim(true);
925 strlink.Trim(false);
926 if ( !strlink.IsEmpty() ) {
927 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
931 ctl->SetValue(wxEmptyString);
935 // Formerly known as LoadRazorPrefs()
936 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
938 // Create a config base for loading razor preferences
939 wxConfigBase *config = wxConfigBase::Get();
940 // If config haven't been created exit without loading
941 if (config == NULL) {
942 return false;
945 // The section where to save in in file
946 wxString section = wxT("/Razor_Preferences/");
948 // Get window size and position
949 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
950 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
951 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
952 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
954 int maximized = config->Read(section + wxT("Maximized"), 01);
956 // Kry - Random usable pos for m_srv_split_pos
957 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
958 if (!override_size) {
959 if (x2 > 0 && y2 > 0) {
960 SetSize(x2, y2);
961 } else {
962 #ifndef __WXGTK__
963 // Probably first run.
964 Maximize();
965 #endif
969 if (!override_pos) {
970 // If x1 and y1 != -1 Redefine location
971 if(x1 != -1 && y1 != -1) {
972 wxRect display = wxGetClientDisplayRect();
973 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
974 Move(x1, y1);
975 } else {
976 // It's offscreen... so let's not.
981 if (!override_size && !override_pos && maximized) {
982 Maximize();
985 return true;
989 bool CamuleDlg::SaveGUIPrefs()
991 /* Razor 1a - Modif by MikaelB
992 Save client size and position */
994 // Create a config base for saving razor preferences
995 wxConfigBase *config = wxConfigBase::Get();
996 // If config haven't been created exit without saving
997 if (config == NULL) {
998 return false;
1000 // The section where to save in in file
1001 wxString section = wxT("/Razor_Preferences/");
1003 if (!IsIconized()) {
1004 // Main window location and size
1005 int x1, y1, x2, y2;
1006 GetPosition(&x1, &y1);
1007 GetSize(&x2, &y2);
1009 // Saving window size and position
1010 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1011 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1013 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1014 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1016 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1019 // Saving sash position of splitter in server window
1020 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1022 config->Flush(true);
1024 /* End modif */
1026 return true;
1030 void CamuleDlg::DoIconize(bool iconize)
1032 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1033 if (iconize) {
1034 // Skip() will do it.
1035 //Iconize(true);
1036 if (SafeState()) {
1037 Show(false);
1039 } else {
1040 Show(true);
1041 Raise();
1043 } else {
1044 // Will be done by Skip();
1045 //Iconize(iconize);
1049 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1051 // Evil Hack: check if the mouse is inside the window
1052 #ifndef __WXMSW__
1053 if (GetScreenRect().Contains(wxGetMousePosition()))
1054 #endif
1056 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1057 // Veto.
1058 } else {
1059 if (m_wndTaskbarNotifier) {
1060 #if wxCHECK_VERSION(2, 9, 0)
1061 DoIconize(evt.IsIconized());
1062 #else
1063 DoIconize(evt.Iconized());
1064 #endif
1066 evt.Skip();
1071 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1073 // Former TimerProc section
1075 static uint32 msPrev1, msPrev5, msPrevStats;
1077 uint32 msCur = theStats::GetUptimeMillis();
1079 // can this actually happen under wxwin ?
1080 if (!SafeState()) {
1081 return;
1084 #ifndef CLIENT_GUI
1085 static uint32 msPrevGraph;
1086 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1087 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1088 // trying to get the graph shifts evenly spaced after a change in the update period
1089 msPrevGraph = msCur;
1091 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1093 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1094 m_kademliawnd->UpdateGraph(update);
1096 #else
1097 //#warning TODO: CORE/GUI -- EC needed
1098 #endif
1100 int sStatsUpdate = thePrefs::GetStatsInterval();
1101 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1102 if (m_statisticswnd->IsShownOnScreen()) {
1103 msPrevStats = msCur;
1104 m_statisticswnd->ShowStatistics();
1108 if (msCur-msPrev5 > 5000) { // every 5 seconds
1109 msPrev5 = msCur;
1110 ShowTransferRate();
1111 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1112 m_transferwnd->UpdateCatTabTitles();
1114 if (thePrefs::AutoSortDownload()) {
1115 m_transferwnd->downloadlistctrl->SortList();
1119 if (msCur-msPrev1 > 1000) { // every second
1120 msPrev1 = msCur;
1121 if (m_CurrentBlinkBitmap == 12) {
1122 m_CurrentBlinkBitmap = 7;
1123 SetMessagesTool();
1124 } else {
1125 if (m_BlinkMessages) {
1126 m_CurrentBlinkBitmap = 12;
1127 SetMessagesTool();
1135 void CamuleDlg::SetMessagesTool()
1137 wxWindowUpdateLocker freezer(m_wndToolbar);
1138 #ifdef __WXCOCOA__
1139 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1140 #else
1141 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1142 #endif
1145 void CamuleDlg::LaunchUrl( const wxString& url )
1147 wxString cmd;
1149 cmd = thePrefs::GetBrowser();
1150 wxString tmp = url;
1151 // Pipes cause problems, so escape them
1152 tmp.Replace( wxT("|"), wxT("%7C") );
1154 if ( !cmd.IsEmpty() ) {
1155 if (!cmd.Replace(wxT("%s"), tmp)) {
1156 // No %s found, just append the url
1157 cmd += wxT(" ") + tmp;
1160 CTerminationProcess *p = new CTerminationProcess(cmd);
1161 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1162 AddLogLineN(_("Launch Command: ") + cmd);
1163 return;
1164 } else {
1165 delete p;
1167 } else {
1168 wxLaunchDefaultBrowser(tmp);
1169 return;
1171 // Unable to execute browser. But this error message doesn't make sense,
1172 // cosidering that you _can't_ set the browser executable path... =/
1173 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1177 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1179 wxString URL;
1180 switch (wsProvider) {
1181 case WS_FILEHASH:
1182 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1183 break;
1184 default:
1185 wxFAIL;
1187 URL.Replace(wxT("FILENAME"), filename);
1189 return URL;
1193 bool CamuleDlg::Check_and_Init_Skin()
1195 bool ret = true;
1196 wxString skinFileName(thePrefs::GetSkin());
1198 if (skinFileName.IsEmpty()) {
1199 return false;
1202 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1204 wxStandardPathsBase &spb(wxStandardPaths::Get());
1205 #ifdef __WXMSW__
1206 wxString dataDir(spb.GetPluginsDir());
1207 #elif defined(__WXMAC__)
1208 wxString dataDir(spb.GetDataDir());
1209 #else
1210 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1211 #endif
1212 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1215 skinFileName.Replace(wxT("User:"), userDir );
1216 skinFileName.Replace(wxT("System:"), systemDir );
1218 m_skinFileName.Assign(skinFileName);
1219 if (!m_skinFileName.FileExists()) {
1220 AddLogLineC(CFormat(
1221 _("Skin directory '%s' does not exist")) %
1222 skinFileName );
1223 ret = false;
1224 } else if (!m_skinFileName.IsFileReadable()) {
1225 AddLogLineC(CFormat(
1226 _("WARNING: Unable to open skin file '%s' for read")) %
1227 skinFileName);
1228 ret = false;
1231 wxFFileInputStream in(m_skinFileName.GetFullPath());
1232 wxZipInputStream zip(in);
1234 while ((entry = zip.GetNextEntry()) != NULL) {
1235 wxZipEntry*& current = cat[entry->GetInternalName()];
1236 delete current;
1237 current = entry;
1240 return ret;
1244 void CamuleDlg::Add_Skin_Icon(
1245 const wxString &iconName,
1246 const wxBitmap &stdIcon,
1247 bool useSkins)
1249 wxImage new_image;
1250 if (useSkins) {
1251 wxFFileInputStream in(m_skinFileName.GetFullPath());
1252 wxZipInputStream zip(in);
1254 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1255 if ( it != cat.end() ) {
1256 zip.OpenEntry(*it->second);
1257 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1258 AddLogLineN(wxT("Warning: Error loading icon for ") +
1259 iconName);
1260 useSkins = false;
1262 }else {
1263 AddLogLineN(wxT("Warning: Can't load icon for ") +
1264 iconName);
1265 useSkins = false;
1270 wxBitmap bmp(useSkins ? new_image : stdIcon);
1271 if (iconName.StartsWith(wxT("Client_"))) {
1272 m_imagelist.Add(bmp);
1273 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1274 m_tblist.Add(bmp);
1279 void CamuleDlg::Apply_Clients_Skin()
1281 bool useSkins = Check_and_Init_Skin();
1283 // Clear the client image list
1284 m_imagelist.RemoveAll();
1286 // Add the images to the image list
1287 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1288 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1289 clientImages(i), useSkins);
1294 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1296 bool useSkins = Check_and_Init_Skin();
1299 // Clear the toolbar image list
1300 m_tblist.RemoveAll();
1302 // Add the images to the image list
1303 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1304 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1305 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1306 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1307 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1311 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1312 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1313 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1314 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1315 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1317 // Build aMule toolbar
1318 wndToolbar->SetMargins(0, 0);
1320 // Placeholder. Gets updated by ShowConnectionState
1321 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1323 wndToolbar->AddSeparator();
1324 wndToolbar->AddTool(ID_BUTTONNETWORKS, _("Networks"), m_tblist.GetBitmap(3), wxNullBitmap, wxITEM_CHECK, _("Networks Window"));
1325 wndToolbar->AddTool(ID_BUTTONSEARCH, _("Searches"), m_tblist.GetBitmap(5), wxNullBitmap, wxITEM_CHECK, _("Searches Window"));
1326 wndToolbar->AddTool(ID_BUTTONDOWNLOADS, _("Downloads"), m_tblist.GetBitmap(4), wxNullBitmap, wxITEM_CHECK, _("Downloads Window"));
1327 wndToolbar->AddTool(ID_BUTTONSHARED, _("Shared files"), m_tblist.GetBitmap(6), wxNullBitmap, wxITEM_CHECK, _("Shared Files Window"));
1328 wndToolbar->AddTool(ID_BUTTONMESSAGES, _("Messages"), m_tblist.GetBitmap(7), wxNullBitmap, wxITEM_CHECK, _("Messages Window"));
1329 wndToolbar->AddTool(ID_BUTTONSTATISTICS, _("Statistics"), m_tblist.GetBitmap(8), wxNullBitmap, wxITEM_CHECK, _("Statistics Graph Window"));
1330 wndToolbar->AddSeparator();
1331 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES, _("Preferences"), m_tblist.GetBitmap(9), wxNullBitmap, wxITEM_NORMAL, _("Preferences Settings Window"));
1332 wndToolbar->AddTool(ID_BUTTONIMPORT, _("Import"), m_tblist.GetBitmap(10), wxNullBitmap, wxITEM_NORMAL, _("The partfile importer tool"));
1333 wndToolbar->AddTool(ID_ABOUT, _("About"), m_tblist.GetBitmap(11), wxNullBitmap, wxITEM_NORMAL, _("About/Help"));
1335 wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true);
1337 // Needed for non-GTK platforms, where the
1338 // items don't get added immediatly.
1339 wndToolbar->Realize();
1341 // Updates the "Connect" button, and so on.
1342 ShowConnectionState(true);
1346 void CamuleDlg::Create_Toolbar(bool orientation)
1348 Freeze();
1349 // Create ToolBar from the one designed by wxDesigner (BigBob)
1350 wxToolBar *current = GetToolBar();
1352 wxASSERT(current == m_wndToolbar);
1354 if (current) {
1355 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1356 if (oldorientation != orientation) {
1357 current->Destroy();
1358 SetToolBar(NULL); // Remove old one if present
1359 m_wndToolbar = NULL;
1360 } else {
1361 current->ClearTools();
1365 if (!m_wndToolbar) {
1366 m_wndToolbar = CreateToolBar(
1367 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1368 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1369 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1372 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1375 Apply_Toolbar_Skin(m_wndToolbar);
1377 Thaw();
1381 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1383 wxFrame::OnSize(evt);
1384 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1385 // Transfer window's splitter set again if it's hidden.
1386 if (!m_transferwnd->clientlistctrl->GetShowing()) {
1387 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1388 wxSplitterWindow* splitter =
1389 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1390 height += splitter->GetWindow1()->GetSize().GetHeight();
1391 splitter->SetSashPosition( height );
1398 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1400 if (event.GetKeyCode() == WXK_F1) {
1401 // Ctrl/Alt/Shift must not be pressed, to avoid
1402 // conflicts with other (global) shortcuts.
1403 if (!event.HasModifiers() && !event.ShiftDown()) {
1404 LaunchUrl(wxT("http://wiki.amule.org"));
1405 return;
1409 event.Skip();
1413 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1415 Close();
1418 void CamuleDlg::DoNetworkRearrange()
1421 wxWindowUpdateLocker freezer(this);
1423 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1425 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1426 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1428 while (logs_notebook->GetPageCount() > 1) {
1429 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1432 while (networks_notebook->GetPageCount() > 0) {
1433 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1436 if (thePrefs::GetNetworkED2K()) {
1437 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1438 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1441 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1443 if (thePrefs::GetNetworkKademlia()) {
1444 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1447 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1449 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1451 wxWindow* replacement = NULL;
1453 m_networknotebooksizer->Clear();
1455 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1456 toolbarTool->SetLabel(_("Networks"));
1458 m_networkpages[0].page->Reparent(networks_notebook);
1459 m_networkpages[1].page->Reparent(networks_notebook);
1461 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1462 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1464 replacement = networks_notebook;
1466 } else if (thePrefs::GetNetworkED2K()) {
1467 toolbarTool->SetLabel(_("eD2k network"));
1468 replacement = m_networkpages[0].page;
1469 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1470 } else if (thePrefs::GetNetworkKademlia()) {
1471 toolbarTool->SetLabel(_("Kad network"));
1472 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1473 replacement = m_networkpages[1].page;
1474 } else {
1475 // No networks.
1476 toolbarTool->SetLabel(_("No network"));
1479 if (replacement) {
1480 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1481 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1482 m_networknotebooksizer->Layout();
1485 m_wndToolbar->InsertTool(2, toolbarTool);
1487 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1488 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
1490 m_wndToolbar->Realize();
1492 m_searchwnd->FixSearchTypes();
1495 // File_checked_for_headers