Fix a compiler warning
[amule.git] / src / amuleDlg.cpp
blobf341a199aeeca21b71f4bd22b0d2ed515cd4dc2f
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"
76 #ifndef __WXMSW__
77 #include "aMule.xpm"
78 #endif
80 #include "kademlia/kademlia/Kademlia.h"
82 #ifdef ENABLE_IP2COUNTRY
83 #include "IP2Country.h" // Needed for IP2Country
84 #endif
86 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
87 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
88 void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
90 m_IP2Country->DownloadFinished(result);
93 void CamuleDlg::EnableIP2Country()
95 if (thePrefs::IsGeoIPEnabled()) {
96 m_IP2Country->Enable();
100 #else
102 void CamuleDlg::IP2CountryDownloadFinished(uint32){}
103 void CamuleDlg::EnableIP2Country(){}
105 #endif
107 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
109 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
110 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
111 EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)
112 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
113 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
114 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
115 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
117 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
118 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
120 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
122 EVT_CLOSE(CamuleDlg::OnClose)
123 EVT_ICONIZE(CamuleDlg::OnMinimize)
125 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
127 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
129 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
131 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
133 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
135 END_EVENT_TABLE()
137 #ifndef wxCLOSE_BOX
138 #define wxCLOSE_BOX 0
139 #endif
141 CamuleDlg::CamuleDlg(
142 wxWindow* pParent,
143 const wxString &title,
144 wxPoint where,
145 wxSize dlg_size)
147 wxFrame(
148 pParent, -1, title, where, dlg_size,
149 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
150 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
151 wxT("aMule")),
152 m_activewnd(NULL),
153 m_transferwnd(NULL),
154 m_serverwnd(NULL),
155 m_sharedfileswnd(NULL),
156 m_searchwnd(NULL),
157 m_chatwnd(NULL),
158 m_statisticswnd(NULL),
159 m_kademliawnd(NULL),
160 m_prefsDialog(NULL),
161 m_srv_split_pos(0),
162 m_imagelist(16,16),
163 m_tblist(32,32),
164 m_prefsVisible(false),
165 m_wndToolbar(NULL),
166 m_wndTaskbarNotifier(NULL),
167 m_nActiveDialog(DT_NETWORKS_WND),
168 m_is_safe_state(false),
169 m_BlinkMessages(false),
170 m_CurrentBlinkBitmap(24),
171 m_last_iconizing(0),
172 m_skinFileName(),
173 m_clientSkinNames(CLIENT_SKIN_SIZE)
175 // Initialize skin names
176 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
177 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
178 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
179 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
180 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
181 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
182 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
183 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
184 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
185 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
186 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
187 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
188 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
189 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
190 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
191 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
192 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
193 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
194 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
195 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
196 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
197 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
198 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
199 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
200 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
201 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
202 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
204 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
205 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
206 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
207 wxInitAllImageHandlers();
208 Apply_Clients_Skin();
210 #ifdef __WXMSW__
211 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
212 #endif
214 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
215 // this crashes on Mac with wx 2.9
216 SetIcon(wxICON(aMule));
217 #endif
219 srand(time(NULL));
221 // Create new sizer and stuff a wxPanel in there.
222 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
223 s_main->AddGrowableCol(0);
224 s_main->AddGrowableRow(0);
226 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
227 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
228 muleDlg(p_cnt, false, true);
229 SetSizer(s_main, true);
231 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
232 AddLogLineM(false, wxEmptyString);
233 AddLogLineM(false, wxT(" - ") +
234 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
235 AddLogLineM(false, wxT(" ") +
236 CFormat(_("Running on %s")) % wxGetOsDescription());
237 AddLogLineM(false, wxT(" - ") +
238 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
239 AddLogLineM(false, wxEmptyString);
241 #ifdef ENABLE_IP2COUNTRY
242 m_GeoIPavailable = true;
243 m_IP2Country = new CIP2Country(theApp->ConfigDir);
244 #else
245 m_GeoIPavailable = false;
246 #endif
247 m_searchwnd = new CSearchDlg(p_cnt);
248 m_transferwnd = new CTransferWnd(p_cnt);
249 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
250 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
251 m_chatwnd = new CChatWnd(p_cnt);
252 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
254 m_serverwnd->Show(false);
255 m_searchwnd->Show(false);
256 m_transferwnd->Show(false);
257 m_sharedfileswnd->Show(false);
258 m_statisticswnd->Show(false);
259 m_chatwnd->Show(false);
261 // Create the GUI timer
262 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
263 if (!gui_timer) {
264 AddLogLineM(false, _("FATAL ERROR: Failed to create Timer"));
265 exit(1);
268 // Set transfers as active window
269 Create_Toolbar(thePrefs::VerticalToolbar());
270 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
271 m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true );
273 bool override_where = (where != wxDefaultPosition);
274 bool override_size = (
275 (dlg_size.x != DEFAULT_SIZE_X) ||
276 (dlg_size.y != DEFAULT_SIZE_Y) );
277 if (!LoadGUIPrefs(override_where, override_size)) {
278 // Prefs not loaded for some reason, exit
279 AddLogLineM( true, wxT("Error! Unable to load Preferences") );
280 return;
283 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
284 m_transferwnd->Prepare();
286 m_is_safe_state = true;
288 // Init statistics stuff, better do it asap
289 m_statisticswnd->Init();
290 m_kademliawnd->Init();
291 m_searchwnd->UpdateCatChoice();
292 if (thePrefs::UseTrayIcon()) {
293 CreateSystray();
296 Show(true);
297 // Must we start minimized?
298 if (thePrefs::GetStartMinimized()) {
299 DoIconize(true);
302 // Set shortcut keys
303 wxAcceleratorEntry entries[] = {
304 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
307 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
308 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
310 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
311 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
313 wxASSERT(logs_notebook->GetPageCount() == 4);
314 wxASSERT(networks_notebook->GetPageCount() == 2);
316 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
317 m_logpages[i].page = logs_notebook->GetPage(i);
318 m_logpages[i].name = logs_notebook->GetPageText(i);
321 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
322 m_networkpages[i].page = networks_notebook->GetPage(i);
323 m_networkpages[i].name = networks_notebook->GetPageText(i);
326 DoNetworkRearrange();
330 // Madcat - Sets Fast ED2K Links Handler on/off.
331 void CamuleDlg::ShowED2KLinksHandler( bool show )
333 // Errorchecking in case the pointer becomes invalid ...
334 if (s_fed2klh == NULL) {
335 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
336 return;
339 s_dlgcnt->Show( s_fed2klh, show );
340 s_dlgcnt->Layout();
343 // Toogles ed2k link handler.
344 void CamuleDlg::ToogleED2KLinksHandler()
346 // Errorchecking in case the pointer becomes invalid ...
347 if (s_fed2klh == NULL) {
348 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
349 return;
351 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
354 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
356 m_nActiveDialog = type;
358 if ( type == DT_TRANSFER_WND ) {
359 if (thePrefs::ShowCatTabInfos()) {
360 m_transferwnd->UpdateCatTabTitles();
364 if ( m_activewnd ) {
365 m_activewnd->Show(false);
366 contentSizer->Detach(m_activewnd);
369 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
370 dlg->Show(true);
371 m_activewnd=dlg;
372 s_dlgcnt->Layout();
374 // Since we might be suspending redrawing while hiding the dialog
375 // we have to refresh it once it is visible again
376 dlg->Refresh( true );
377 dlg->SetFocus();
379 if ( type == DT_SHARED_WND ) {
380 // set up splitter now that window sizes are defined
381 m_sharedfileswnd->Prepare();
386 void CamuleDlg::UpdateTrayIcon(int percent)
388 // set trayicon-icon
389 if(!theApp->IsConnected()) {
390 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
391 } else {
392 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
393 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
394 } else {
395 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
401 void CamuleDlg::CreateSystray()
403 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
404 wxT("Systray already created"));
406 m_wndTaskbarNotifier = new CMuleTrayIcon();
407 // This will effectively show the Tray Icon.
408 UpdateTrayIcon(0);
412 void CamuleDlg::RemoveSystray()
414 delete m_wndTaskbarNotifier;
415 m_wndTaskbarNotifier = NULL;
419 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
421 static int lastbutton = ID_BUTTONDOWNLOADS;
423 // Kry - just if the GUI is ready for it
424 if ( m_is_safe_state ) {
426 // Rehide the handler if needed
427 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
428 if (ev.GetId() != ID_BUTTONSEARCH) {
429 ShowED2KLinksHandler( false );
430 } else {
431 // Toogle ED2K handler.
432 ToogleED2KLinksHandler();
436 if ( lastbutton != ev.GetId() ) {
437 switch ( ev.GetId() ) {
438 case ID_BUTTONNETWORKS:
439 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
440 // Set serverlist splitter position
441 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
442 break;
444 case ID_BUTTONSEARCH:
445 // The search dialog should always display the handler
446 if ( !thePrefs::GetFED2KLH() )
447 ShowED2KLinksHandler( true );
449 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
450 break;
452 case ID_BUTTONDOWNLOADS:
453 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
454 // Prepare the dialog, sets the splitter-position
455 m_transferwnd->Prepare();
456 break;
458 case ID_BUTTONSHARED:
459 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
460 break;
462 case ID_BUTTONMESSAGES:
463 m_BlinkMessages = false;
464 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
465 break;
467 case ID_BUTTONSTATISTICS:
468 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
469 break;
471 // This shouldn't happen, but just in case
472 default:
473 AddLogLineM( true, wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
474 break;
478 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
479 lastbutton = ev.GetId();
484 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
486 wxString msg = wxT(" ");
487 #ifdef CLIENT_GUI
488 msg << _("aMule remote control ") << wxT(VERSION);
489 #else
490 msg << wxT("aMule ") << wxT(VERSION);
491 #endif
492 msg << wxT(" ");
493 #ifdef SVNDATE
494 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
495 #endif
496 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
497 _("Website: http://www.amule.org \n") <<
498 _("Forum: http://forum.amule.org \n") <<
499 _("FAQ: http://wiki.amule.org \n\n") <<
500 _("Contact: admin@amule.org (administrative issues) \n") <<
501 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
502 _("Part of aMule is based on \n") <<
503 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
504 _(" Copyright (c) 2002-2008 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
505 _("http://kademlia.scs.cs.nyu.edu\n");
507 if (m_is_safe_state) {
508 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
513 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
515 if (m_is_safe_state) {
516 if (m_prefsDialog == NULL) {
517 m_prefsDialog = new PrefsUnifiedDlg(this);
520 m_prefsDialog->TransferToWindow();
521 m_prefsDialog->Show(true);
522 m_prefsDialog->Raise();
527 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
529 if (m_is_safe_state) {
530 CPartFileConvertDlg::ShowGUI(NULL);
535 CamuleDlg::~CamuleDlg()
537 theApp->amuledlg = NULL;
539 #ifdef ENABLE_IP2COUNTRY
540 delete m_IP2Country;
541 #endif
543 AddLogLineN(_("aMule dialog destroyed"));
547 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
550 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
551 #ifndef CLIENT_GUI
552 || (Kademlia::CKademlia::IsRunning())
553 #endif
555 if (thePrefs::GetNetworkED2K()) {
556 if (disconnect) {
557 //disconnect if currently connected
558 if (theApp->serverconnect->IsConnecting()) {
559 theApp->serverconnect->StopConnectionTry();
560 } else {
561 theApp->serverconnect->Disconnect();
563 } else {
564 //connect if not currently connected
565 AddLogLineM(true, _("Connecting"));
566 theApp->serverconnect->ConnectToAnyServer();
568 } else {
569 wxASSERT(!theApp->IsConnectedED2K());
572 // Connect Kad also
573 if (thePrefs::GetNetworkKademlia()) {
574 if( disconnect ) {
575 theApp->StopKad();
576 } else {
577 theApp->StartKad();
579 } else {
580 #ifndef CLIENT_GUI
581 wxASSERT(!Kademlia::CKademlia::IsRunning());
582 #endif
585 ShowConnectionState();
589 void CamuleDlg::ResetLog(int id)
591 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
592 wxCHECK_RET(ct, wxT("Resetting unknown log"));
594 ct->Clear();
596 if (id == ID_LOGVIEW) {
597 // Also clear the log line
598 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
599 text->SetLabel(wxEmptyString);
600 text->GetParent()->Layout();
605 void CamuleDlg::AddLogLine(const wxString& line)
607 bool addtostatusbar = line[0] == '!';
608 wxString bufferline = line.Mid(1);
610 // Add the message to the log-view
611 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
612 if ( ct ) {
613 // Bold critical log-lines
614 // to enable this on Windows control has to be changed to wxTE_RICH2 in muuli
615 #ifdef __WXMSW__
616 ct->AppendText(line); // keep the leading "!" if it can't be bolded
617 #else
618 wxTextAttr style = ct->GetDefaultStyle();
619 wxFont font = style.GetFont();
620 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
621 style.SetFont(font);
622 ct->SetDefaultStyle(style);
623 ct->AppendText(bufferline);
624 #endif
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();
786 s_oldState = currentState;
790 ////////////////////////////////////////////////////////////
791 // Update the globe-icon in the lower-right corner.
792 // (only if connection state has changed)
794 static ED2KState s_ED2KOldState = ED2KUndef;
795 static EKadState s_EKadOldState = EKadUndef;
796 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
797 s_ED2KOldState = ed2kState;
798 s_EKadOldState = kadState;
799 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
800 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
802 wxBitmap statusIcon = connBitmap->GetBitmap();
803 // Sanity check - otherwise there's a crash here if aMule runs out of resources
804 if (statusIcon.GetRefData() == NULL) {
805 return;
808 wxMemoryDC bitmapDC(statusIcon);
810 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
811 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
813 connBitmap->SetBitmap(statusIcon);
818 void CamuleDlg::ShowUserCount(const wxString& info)
820 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
822 // Update Kad tab
823 m_serverwnd->UpdateKadInfo();
825 label->SetLabel(info);
826 label->GetParent()->Layout();
830 void CamuleDlg::ShowTransferRate()
832 float kBpsUp = theStats::GetUploadRate() / 1024.0;
833 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
834 wxString buffer;
835 if( thePrefs::ShowOverhead() )
837 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
838 } else {
839 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
841 buffer.Truncate(50); // Max size 50
843 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
844 label->SetLabel(buffer);
845 label->GetParent()->Layout();
847 // Show upload/download speed in title
848 if (thePrefs::GetShowRatesOnTitle()) {
849 wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
850 if (thePrefs::GetShowRatesOnTitle() == 1) {
851 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
852 } else {
853 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
857 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
858 if (m_wndTaskbarNotifier) {
859 // set trayicon-icon
860 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
861 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
863 wxString buffer2;
864 if ( theApp->IsConnected() ) {
865 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
866 } else {
867 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
869 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
872 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
873 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
876 void CamuleDlg::DlgShutDown()
878 // Are we already shutting down or still on init?
879 if ( m_is_safe_state == false ) {
880 return;
883 // we are going DOWN
884 m_is_safe_state = false;
886 // Stop the GUI Timer
887 delete gui_timer;
888 m_transferwnd->downloadlistctrl->DeleteAllItems();
890 // We want to delete the systray too!
891 RemoveSystray();
894 void CamuleDlg::OnClose(wxCloseEvent& evt)
896 // This will be here till the core close is != app close
897 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
898 if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
899 wxString(_("Exit confirmation")), wxYES_NO, this)) {
900 evt.Veto();
901 return;
905 SaveGUIPrefs();
907 Enable(false);
908 Show(false);
910 theApp->ShutDown(evt);
914 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
916 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
918 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
919 wxString strlink = ctl->GetLineText(i);
920 strlink.Trim(true);
921 strlink.Trim(false);
922 if ( !strlink.IsEmpty() ) {
923 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
927 ctl->SetValue(wxEmptyString);
931 // Formerly known as LoadRazorPrefs()
932 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
934 // Create a config base for loading razor preferences
935 wxConfigBase *config = wxConfigBase::Get();
936 // If config haven't been created exit without loading
937 if (config == NULL) {
938 return false;
941 // The section where to save in in file
942 wxString section = wxT("/Razor_Preferences/");
944 // Get window size and position
945 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
946 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
947 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
948 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
950 int maximized = config->Read(section + wxT("Maximized"), 01);
952 // Kry - Random usable pos for m_srv_split_pos
953 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
954 if (!override_size) {
955 if (x2 > 0 && y2 > 0) {
956 SetSize(x2, y2);
957 } else {
958 #ifndef __WXGTK__
959 // Probably first run.
960 Maximize();
961 #endif
965 if (!override_pos) {
966 // If x1 and y1 != -1 Redefine location
967 if(x1 != -1 && y1 != -1) {
968 wxRect display = wxGetClientDisplayRect();
969 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
970 Move(x1, y1);
971 } else {
972 // It's offscreen... so let's not.
977 if (!override_size && !override_pos && maximized) {
978 Maximize();
981 return true;
985 bool CamuleDlg::SaveGUIPrefs()
987 /* Razor 1a - Modif by MikaelB
988 Save client size and position */
990 // Create a config base for saving razor preferences
991 wxConfigBase *config = wxConfigBase::Get();
992 // If config haven't been created exit without saving
993 if (config == NULL) {
994 return false;
996 // The section where to save in in file
997 wxString section = wxT("/Razor_Preferences/");
999 if (!IsIconized()) {
1000 // Main window location and size
1001 int x1, y1, x2, y2;
1002 GetPosition(&x1, &y1);
1003 GetSize(&x2, &y2);
1005 // Saving window size and position
1006 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1007 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1009 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1010 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1012 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1015 // Saving sash position of splitter in server window
1016 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1018 config->Flush(true);
1020 /* End modif */
1022 return true;
1026 void CamuleDlg::DoIconize(bool iconize)
1028 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1029 if (iconize) {
1030 // Skip() will do it.
1031 //Iconize(true);
1032 if (SafeState()) {
1033 Show(false);
1035 } else {
1036 Show(true);
1037 Raise();
1039 } else {
1040 // Will be done by Skip();
1041 //Iconize(iconize);
1045 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1047 // Evil Hack: check if the mouse is inside the window
1048 #ifndef __WXMSW__
1049 if (GetScreenRect().Contains(wxGetMousePosition()))
1050 #endif
1052 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1053 // Veto.
1054 } else {
1055 if (m_wndTaskbarNotifier) {
1056 #if wxCHECK_VERSION(2, 9, 0)
1057 DoIconize(evt.IsIconized());
1058 #else
1059 DoIconize(evt.Iconized());
1060 #endif
1062 evt.Skip();
1067 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1069 // Former TimerProc section
1071 static uint32 msPrev1, msPrev5, msPrevStats;
1073 uint32 msCur = theStats::GetUptimeMillis();
1075 // can this actually happen under wxwin ?
1076 if (!SafeState()) {
1077 return;
1080 #ifndef CLIENT_GUI
1081 static uint32 msPrevGraph;
1082 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1083 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1084 // trying to get the graph shifts evenly spaced after a change in the update period
1085 msPrevGraph = msCur;
1087 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1089 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1090 m_kademliawnd->UpdateGraph(update);
1092 #else
1093 //#warning TODO: CORE/GUI -- EC needed
1094 #endif
1096 int sStatsUpdate = thePrefs::GetStatsInterval();
1097 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1098 if (m_statisticswnd->IsShownOnScreen()) {
1099 msPrevStats = msCur;
1100 m_statisticswnd->ShowStatistics();
1104 if (msCur-msPrev5 > 5000) { // every 5 seconds
1105 msPrev5 = msCur;
1106 ShowTransferRate();
1107 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1108 m_transferwnd->UpdateCatTabTitles();
1110 if (thePrefs::AutoSortDownload()) {
1111 m_transferwnd->downloadlistctrl->SortList();
1115 if (msCur-msPrev1 > 1000) { // every second
1116 msPrev1 = msCur;
1117 if (m_CurrentBlinkBitmap == 12) {
1118 m_CurrentBlinkBitmap = 7;
1119 SetMessagesTool();
1120 } else {
1121 if (m_BlinkMessages) {
1122 m_CurrentBlinkBitmap = 12;
1123 SetMessagesTool();
1131 void CamuleDlg::SetMessagesTool()
1133 wxWindowUpdateLocker freezer(m_wndToolbar);
1134 #ifdef __WXCOCOA__
1135 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1136 #else
1137 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1138 #endif
1141 void CamuleDlg::LaunchUrl( const wxString& url )
1143 wxString cmd;
1145 cmd = thePrefs::GetBrowser();
1146 wxString tmp = url;
1147 // Pipes cause problems, so escape them
1148 tmp.Replace( wxT("|"), wxT("%7C") );
1150 if ( !cmd.IsEmpty() ) {
1151 if (!cmd.Replace(wxT("%s"), tmp)) {
1152 // No %s found, just append the url
1153 cmd += wxT(" ") + tmp;
1156 CTerminationProcess *p = new CTerminationProcess(cmd);
1157 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1158 AddLogLineN(_("Launch Command: ") + cmd);
1159 return;
1160 } else {
1161 delete p;
1163 } else {
1164 wxLaunchDefaultBrowser(tmp);
1165 return;
1167 // Unable to execute browser. But this error message doesn't make sense,
1168 // cosidering that you _can't_ set the browser executable path... =/
1169 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1173 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1175 wxString URL;
1176 switch (wsProvider) {
1177 case WS_FILEHASH:
1178 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1179 break;
1180 default:
1181 wxFAIL;
1183 URL.Replace(wxT("FILENAME"), filename);
1185 return URL;
1189 bool CamuleDlg::Check_and_Init_Skin()
1191 bool ret = true;
1192 wxString skinFileName(thePrefs::GetSkin());
1194 if (skinFileName.IsEmpty()) {
1195 return false;
1198 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1200 wxStandardPathsBase &spb(wxStandardPaths::Get());
1201 #ifdef __WXMSW__
1202 wxString dataDir(spb.GetPluginsDir());
1203 #elif defined(__WXMAC__)
1204 wxString dataDir(spb.GetDataDir());
1205 #else
1206 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1207 #endif
1208 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1211 skinFileName.Replace(wxT("User:"), userDir );
1212 skinFileName.Replace(wxT("System:"), systemDir );
1214 m_skinFileName.Assign(skinFileName);
1215 if (!m_skinFileName.FileExists()) {
1216 AddLogLineM(true, CFormat(
1217 _("Skin directory '%s' does not exist")) %
1218 skinFileName );
1219 ret = false;
1220 } else if (!m_skinFileName.IsFileReadable()) {
1221 AddLogLineM(true, CFormat(
1222 _("WARNING: Unable to open skin file '%s' for read")) %
1223 skinFileName);
1224 ret = false;
1227 wxFFileInputStream in(m_skinFileName.GetFullPath());
1228 wxZipInputStream zip(in);
1230 while ((entry = zip.GetNextEntry()) != NULL) {
1231 wxZipEntry*& current = cat[entry->GetInternalName()];
1232 delete current;
1233 current = entry;
1236 return ret;
1240 void CamuleDlg::Add_Skin_Icon(
1241 const wxString &iconName,
1242 const wxBitmap &stdIcon,
1243 bool useSkins)
1245 wxImage new_image;
1246 if (useSkins) {
1247 wxFFileInputStream in(m_skinFileName.GetFullPath());
1248 wxZipInputStream zip(in);
1250 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1251 if ( it != cat.end() ) {
1252 zip.OpenEntry(*it->second);
1253 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1254 AddLogLineM(false,
1255 wxT("Warning: Error loading icon for ") +
1256 iconName);
1257 useSkins = false;
1259 }else {
1260 AddLogLineM(false,
1261 wxT("Warning: Can't load icon for ") +
1262 iconName);
1263 useSkins = false;
1268 wxBitmap bmp(useSkins ? new_image : stdIcon);
1269 if (iconName.StartsWith(wxT("Client_"))) {
1270 m_imagelist.Add(bmp);
1271 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1272 m_tblist.Add(bmp);
1277 void CamuleDlg::Apply_Clients_Skin()
1279 bool useSkins = Check_and_Init_Skin();
1281 // Clear the client image list
1282 m_imagelist.RemoveAll();
1284 // Add the images to the image list
1285 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1286 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1287 clientImages(i), useSkins);
1292 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1294 bool useSkins = Check_and_Init_Skin();
1297 // Clear the toolbar image list
1298 m_tblist.RemoveAll();
1300 // Add the images to the image list
1301 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1302 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1303 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1304 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1305 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1306 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1307 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1311 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1312 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1313 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1315 // Build aMule toolbar
1316 wndToolbar->SetMargins(0, 0);
1318 // Placeholder. Gets updated by ShowConnectionState
1319 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1321 wndToolbar->AddSeparator();
1322 wndToolbar->AddTool(ID_BUTTONNETWORKS, _("Networks"), m_tblist.GetBitmap(3), wxNullBitmap, wxITEM_CHECK, _("Networks Window"));
1323 wndToolbar->AddTool(ID_BUTTONSEARCH, _("Searches"), m_tblist.GetBitmap(5), wxNullBitmap, wxITEM_CHECK, _("Searches Window"));
1324 wndToolbar->AddTool(ID_BUTTONDOWNLOADS, _("Downloads"), m_tblist.GetBitmap(4), wxNullBitmap, wxITEM_CHECK, _("Downloads Window"));
1325 wndToolbar->AddTool(ID_BUTTONSHARED, _("Shared files"), m_tblist.GetBitmap(6), wxNullBitmap, wxITEM_CHECK, _("Shared Files Window"));
1326 wndToolbar->AddTool(ID_BUTTONMESSAGES, _("Messages"), m_tblist.GetBitmap(7), wxNullBitmap, wxITEM_CHECK, _("Messages Window"));
1327 wndToolbar->AddTool(ID_BUTTONSTATISTICS, _("Statistics"), m_tblist.GetBitmap(8), wxNullBitmap, wxITEM_CHECK, _("Statistics Graph Window"));
1328 wndToolbar->AddSeparator();
1329 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES, _("Preferences"), m_tblist.GetBitmap(9), wxNullBitmap, wxITEM_NORMAL, _("Preferences Settings Window"));
1330 wndToolbar->AddTool(ID_BUTTONIMPORT, _("Import"), m_tblist.GetBitmap(10), wxNullBitmap, wxITEM_NORMAL, _("The partfile importer tool"));
1331 wndToolbar->AddTool(ID_ABOUT, _("About"), m_tblist.GetBitmap(11), wxNullBitmap, wxITEM_NORMAL, _("About/Help"));
1333 wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true);
1335 // Needed for non-GTK platforms, where the
1336 // items don't get added immediatly.
1337 wndToolbar->Realize();
1339 // Updates the "Connect" button, and so on.
1340 ShowConnectionState(true);
1344 void CamuleDlg::Create_Toolbar(bool orientation)
1346 Freeze();
1347 // Create ToolBar from the one designed by wxDesigner (BigBob)
1348 wxToolBar *current = GetToolBar();
1350 wxASSERT(current == m_wndToolbar);
1352 if (current) {
1353 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1354 if (oldorientation != orientation) {
1355 current->Destroy();
1356 SetToolBar(NULL); // Remove old one if present
1357 m_wndToolbar = NULL;
1358 } else {
1359 current->ClearTools();
1363 if (!m_wndToolbar) {
1364 m_wndToolbar = CreateToolBar(
1365 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1366 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1367 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1370 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1373 Apply_Toolbar_Skin(m_wndToolbar);
1375 Thaw();
1379 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1381 wxFrame::OnSize(evt);
1382 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1383 // Transfer window's splitter set again if it's hidden.
1384 if (!m_transferwnd->clientlistctrl->GetShowing()) {
1385 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1386 wxSplitterWindow* splitter =
1387 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1388 height += splitter->GetWindow1()->GetSize().GetHeight();
1389 splitter->SetSashPosition( height );
1396 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1398 if (event.GetKeyCode() == WXK_F1) {
1399 // Ctrl/Alt/Shift must not be pressed, to avoid
1400 // conflicts with other (global) shortcuts.
1401 if (!event.HasModifiers() && !event.ShiftDown()) {
1402 LaunchUrl(wxT("http://wiki.amule.org"));
1403 return;
1407 event.Skip();
1411 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1413 Close();
1416 void CamuleDlg::DoNetworkRearrange()
1419 wxWindowUpdateLocker freezer(this);
1421 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1423 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1424 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1426 while (logs_notebook->GetPageCount() > 1) {
1427 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1430 while (networks_notebook->GetPageCount() > 0) {
1431 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1434 if (thePrefs::GetNetworkED2K()) {
1435 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1436 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1439 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1441 if (thePrefs::GetNetworkKademlia()) {
1442 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1445 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1447 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1449 wxWindow* replacement = NULL;
1451 m_networknotebooksizer->Clear();
1453 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1454 toolbarTool->SetLabel(_("Networks"));
1456 m_networkpages[0].page->Reparent(networks_notebook);
1457 m_networkpages[1].page->Reparent(networks_notebook);
1459 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1460 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1462 replacement = networks_notebook;
1464 } else if (thePrefs::GetNetworkED2K()) {
1465 toolbarTool->SetLabel(_("eD2k network"));
1466 replacement = m_networkpages[0].page;
1467 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1468 } else if (thePrefs::GetNetworkKademlia()) {
1469 toolbarTool->SetLabel(_("Kad network"));
1470 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1471 replacement = m_networkpages[1].page;
1472 } else {
1473 // No networks.
1474 toolbarTool->SetLabel(_("No network"));
1477 if (replacement) {
1478 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1479 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1480 m_networknotebooksizer->Layout();
1483 m_wndToolbar->InsertTool(2, toolbarTool);
1485 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1486 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1488 m_wndToolbar->Realize();
1490 m_searchwnd->FixSearchTypes();
1493 // File_checked_for_headers