Upstream tarball 9882
[amule.git] / src / amuleDlg.cpp
blobce61e924fe5fdfbf7c9e408c3cb79b62155daa27
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
42 #include <wx/utils.h> // Needed for wxBusyCursor
44 #include <common/EventIDs.h>
46 #ifdef HAVE_CONFIG_H
47 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
48 #else
49 #include <common/ClientVersion.h>
50 #endif // HAVE_CONFIG_H
52 #include "amuleDlg.h" // Interface declarations.
54 #include <common/Format.h> // Needed for CFormat
55 #include "amule.h" // Needed for theApp
56 #include "ChatWnd.h" // Needed for CChatWnd
57 #include "ClientListCtrl.h" // Needed for CClientListCtrl
58 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
59 #include "DownloadQueue.h" // Needed for CDownloadQueue
60 #include "KadDlg.h" // Needed for CKadDlg
61 #include "Logger.h"
62 #include "MuleTrayIcon.h"
63 #include "muuli_wdr.h" // Needed for ID_BUTTON*
64 #include "Preferences.h" // Needed for CPreferences
65 #include "PrefsUnifiedDlg.h"
66 #include "SearchDlg.h" // Needed for CSearchDlg
67 #include "Server.h" // Needed for CServer
68 #include "ServerConnect.h" // Needed for CServerConnect
69 #include "ServerWnd.h" // Needed for CServerWnd
70 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
71 #include "Statistics.h" // Needed for theStats
72 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
73 #include "TerminationProcess.h" // Needed for CTerminationProcess
74 #include "TransferWnd.h" // Needed for CTransferWnd
75 #include "PartFileConvertDlg.h"
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_BUTTONTRANSFER, 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 AddLogLineM(false, wxEmptyString);
234 AddLogLineM(false, wxT(" - ") +
235 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
236 AddLogLineM(false, wxT(" ") +
237 CFormat(_("Running on %s")) % wxGetOsDescription());
238 AddLogLineM(false, wxT(" - ") +
239 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
240 AddLogLineM(false, wxEmptyString);
242 #ifdef ENABLE_IP2COUNTRY
243 m_GeoIPavailable = true;
244 m_IP2Country = new CIP2Country();
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 AddLogLineM(false, _("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_BUTTONTRANSFER, 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 AddLogLineM( true, 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();
382 void CamuleDlg::UpdateTrayIcon(int percent)
384 // set trayicon-icon
385 if(!theApp->IsConnected()) {
386 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
387 } else {
388 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
389 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
390 } else {
391 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
397 void CamuleDlg::CreateSystray()
399 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
400 wxT("Systray already created"));
402 m_wndTaskbarNotifier = new CMuleTrayIcon();
403 // This will effectively show the Tray Icon.
404 UpdateTrayIcon(0);
408 void CamuleDlg::RemoveSystray()
410 delete m_wndTaskbarNotifier;
411 m_wndTaskbarNotifier = NULL;
415 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
417 static int lastbutton = ID_BUTTONTRANSFER;
419 // Kry - just if the GUI is ready for it
420 if ( m_is_safe_state ) {
422 // Rehide the handler if needed
423 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
424 if (ev.GetId() != ID_BUTTONSEARCH) {
425 ShowED2KLinksHandler( false );
426 } else {
427 // Toogle ED2K handler.
428 ToogleED2KLinksHandler();
432 if ( lastbutton != ev.GetId() ) {
433 switch ( ev.GetId() ) {
434 case ID_BUTTONNETWORKS:
435 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
436 // Set serverlist splitter position
437 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
438 break;
440 case ID_BUTTONSEARCH:
441 // The search dialog should always display the handler
442 if ( !thePrefs::GetFED2KLH() )
443 ShowED2KLinksHandler( true );
445 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
446 break;
448 case ID_BUTTONTRANSFER:
449 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
450 // Prepare the dialog, sets the splitter-position
451 m_transferwnd->Prepare();
452 break;
454 case ID_BUTTONSHARED:
455 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
456 break;
458 case ID_BUTTONMESSAGES:
459 m_BlinkMessages = false;
460 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
461 break;
463 case ID_BUTTONSTATISTICS:
464 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
465 break;
467 // This shouldn't happen, but just in case
468 default:
469 AddLogLineM( true, wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
470 break;
474 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
475 lastbutton = ev.GetId();
480 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
482 wxString msg = wxT(" ");
483 #ifdef CLIENT_GUI
484 msg << _("aMule remote control ") << wxT(VERSION);
485 #else
486 msg << wxT("aMule ") << wxT(VERSION);
487 #endif
488 msg << wxT(" ");
489 #ifdef SVNDATE
490 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
491 #endif
492 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
493 _("Website: http://www.amule.org \n") <<
494 _("Forum: http://forum.amule.org \n") <<
495 _("FAQ: http://wiki.amule.org \n\n") <<
496 _("Contact: admin@amule.org (administrative issues) \n") <<
497 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
498 _("Part of aMule is based on \n") <<
499 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
500 _(" Copyright (c) 2002-2008 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
501 _("http://kademlia.scs.cs.nyu.edu\n");
503 if (m_is_safe_state) {
504 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
509 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
511 if (m_is_safe_state) {
512 wxBusyCursor busyCursor;
513 if (m_prefsDialog == NULL) {
514 m_prefsDialog = new PrefsUnifiedDlg(this);
517 m_prefsDialog->TransferToWindow();
518 m_prefsDialog->Show(true);
519 m_prefsDialog->Raise();
524 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
526 if (m_is_safe_state) {
527 CPartFileConvertDlg::ShowGUI(NULL);
532 CamuleDlg::~CamuleDlg()
534 AddLogLineN(_("Shutting down aMule..."));
536 SaveGUIPrefs();
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 #ifndef CLIENT_GUI
553 || (Kademlia::CKademlia::IsRunning())
554 #endif
556 if (thePrefs::GetNetworkED2K()) {
557 if (disconnect) {
558 //disconnect if currently connected
559 if (theApp->serverconnect->IsConnecting()) {
560 theApp->serverconnect->StopConnectionTry();
561 } else {
562 theApp->serverconnect->Disconnect();
564 } else {
565 //connect if not currently connected
566 AddLogLineM(true, _("Connecting"));
567 theApp->serverconnect->ConnectToAnyServer();
569 } else {
570 wxASSERT(!theApp->IsConnectedED2K());
573 // Connect Kad also
574 if (thePrefs::GetNetworkKademlia()) {
575 if( disconnect ) {
576 theApp->StopKad();
577 } else {
578 theApp->StartKad();
580 } else {
581 #ifndef CLIENT_GUI
582 wxASSERT(!Kademlia::CKademlia::IsRunning());
583 #endif
586 ShowConnectionState();
590 void CamuleDlg::ResetLog(int id)
592 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
593 wxCHECK_RET(ct, wxT("Resetting unknown log"));
595 ct->Clear();
597 if (id == ID_LOGVIEW) {
598 // Also clear the log line
599 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
600 text->SetLabel(wxEmptyString);
601 text->GetParent()->Layout();
606 void CamuleDlg::AddLogLine(const wxString& line)
608 bool addtostatusbar = line[0] == '!';
609 wxString bufferline = line.Mid(1);
611 // Add the message to the log-view
612 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
613 if ( ct ) {
614 // Bold critical log-lines
615 // to enable this on Windows control has to be changed to wxTE_RICH2 in muuli
616 #ifdef __WXMSW__
617 ct->AppendText(line); // keep the leading "!" if it can't be bolded
618 #else
619 wxTextAttr style = ct->GetDefaultStyle();
620 wxFont font = style.GetFont();
621 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
622 style.SetFont(font);
623 ct->SetDefaultStyle(style);
624 ct->AppendText(bufferline);
625 #endif
626 ct->ShowPosition( ct->GetLastPosition() - 1 );
630 // Set the status-bar if the event warrents it
631 if ( addtostatusbar ) {
632 // Escape "&"s, which would otherwise not show up
633 bufferline.Replace( wxT("&"), wxT("&&") );
634 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
635 // Only show the first line if multiple lines
636 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
637 text->SetToolTip( bufferline );
638 text->GetParent()->Layout();
644 void CamuleDlg::AddServerMessageLine(wxString& message)
646 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
647 if(cv) {
648 if (message.Length() > 500) {
649 cv->AppendText(message.Left(500) + wxT("\n"));
650 } else {
651 cv->AppendText(message + wxT("\n"));
653 cv->ShowPosition(cv->GetLastPosition()-1);
658 void CamuleDlg::ShowConnectionState(bool skinChanged)
660 static wxImageList status_arrows(16,16,true,0);
661 if (!status_arrows.GetImageCount()) {
662 // Generate the image list (This is only done once)
663 for (int t = 0; t < 7; ++t) {
664 status_arrows.Add(connImages(t));
668 m_serverwnd->UpdateED2KInfo();
669 m_serverwnd->UpdateKadInfo();
672 ////////////////////////////////////////////////////////////
673 // Determine the status of the networks
675 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
676 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
678 ED2KState ed2kState = ED2KOff;
679 EKadState kadState = EKadOff;
681 ////////////////////////////////////////////////////////////
682 // Update the label on the status-bar and determine
683 // the states of the two networks.
685 wxString msgED2K;
686 if (theApp->IsConnectedED2K()) {
687 CServer* server = theApp->serverconnect->GetCurrentServer();
688 if (server) {
689 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
692 if (theApp->serverconnect->IsLowID()) {
693 ed2kState = ED2KLowID;
694 } else {
695 ed2kState = ED2KHighID;
697 } else if (theApp->serverconnect->IsConnecting()) {
698 msgED2K = _("eD2k: Connecting");
700 ed2kState = ED2KConnecting;
701 } else if (thePrefs::GetNetworkED2K()) {
702 msgED2K = _("eD2k: Disconnected");
705 wxString msgKad;
706 if (theApp->IsConnectedKad()) {
707 if (theApp->IsFirewalledKad()) {
708 msgKad = _("Kad: Firewalled");
710 kadState = EKadFW;
711 } else {
712 msgKad = _("Kad: Connected");
714 kadState = EKadOK;
716 } else if (theApp->IsKadRunning()) {
717 msgKad = _("Kad: Connecting");
719 kadState = EKadConnecting;
720 } else if (thePrefs::GetNetworkKademlia()) {
721 msgKad = _("Kad: Off");
724 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
725 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
727 wxString labelMsg;
728 if (msgED2K.Length() && msgKad.Length()) {
729 labelMsg = msgED2K + wxT(" | ") + msgKad;
730 } else {
731 labelMsg = msgED2K + msgKad;
734 connLabel->SetLabel(labelMsg);
735 connLabel->GetParent()->Layout();
738 ////////////////////////////////////////////////////////////
739 // Update the connect/disconnect/cancel button.
741 enum EConnState {
742 ECS_Unknown,
743 ECS_Connected,
744 ECS_Connecting,
745 ECS_Disconnected
748 static EConnState s_oldState = ECS_Unknown;
749 EConnState currentState = ECS_Disconnected;
751 if (theApp->serverconnect->IsConnecting() ||
752 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
753 currentState = ECS_Connecting;
754 } else if (theApp->IsConnected()) {
755 currentState = ECS_Connected;
756 } else {
757 currentState = ECS_Disconnected;
760 if ( (true == skinChanged) || (currentState != s_oldState) ) {
761 wxWindowUpdateLocker freezer(m_wndToolbar);
763 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
765 switch (currentState) {
766 case ECS_Connecting:
767 toolbarTool->SetLabel(_("Cancel"));
768 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
769 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
770 break;
772 case ECS_Connected:
773 toolbarTool->SetLabel(_("Disconnect"));
774 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
775 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
776 break;
778 default:
779 toolbarTool->SetLabel(_("Connect"));
780 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
781 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
784 m_wndToolbar->InsertTool(0, toolbarTool);
785 m_wndToolbar->Realize();
787 s_oldState = currentState;
791 ////////////////////////////////////////////////////////////
792 // Update the globe-icon in the lower-right corner.
793 // (only if connection state has changed)
795 static ED2KState s_ED2KOldState = ED2KUndef;
796 static EKadState s_EKadOldState = EKadUndef;
797 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
798 s_ED2KOldState = ed2kState;
799 s_EKadOldState = kadState;
800 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
801 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
803 wxBitmap statusIcon = connBitmap->GetBitmap();
804 // Sanity check - otherwise there's a crash here if aMule runs out of resources
805 if (statusIcon.GetRefData() == NULL) {
806 return;
809 wxMemoryDC bitmapDC(statusIcon);
811 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
812 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
814 connBitmap->SetBitmap(statusIcon);
819 void CamuleDlg::ShowUserCount(const wxString& info)
821 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
823 // Update Kad tab
824 m_serverwnd->UpdateKadInfo();
826 label->SetLabel(info);
827 label->GetParent()->Layout();
831 void CamuleDlg::ShowTransferRate()
833 float kBpsUp = theStats::GetUploadRate() / 1024.0;
834 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
835 wxString buffer;
836 if( thePrefs::ShowOverhead() )
838 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
839 } else {
840 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
842 buffer.Truncate(50); // Max size 50
844 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
845 label->SetLabel(buffer);
846 label->GetParent()->Layout();
848 // Show upload/download speed in title
849 if (thePrefs::GetShowRatesOnTitle()) {
850 wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
851 if (thePrefs::GetShowRatesOnTitle() == 1) {
852 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
853 } else {
854 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
858 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
859 if (m_wndTaskbarNotifier) {
860 // set trayicon-icon
861 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
862 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
864 wxString buffer2;
865 if ( theApp->IsConnected() ) {
866 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
867 } else {
868 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
870 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
873 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
874 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
877 void CamuleDlg::DlgShutDown()
879 // Are we already shutting down or still on init?
880 if ( m_is_safe_state == false ) {
881 return;
884 // we are going DOWN
885 m_is_safe_state = false;
887 // Stop the GUI Timer
888 delete gui_timer;
889 m_transferwnd->downloadlistctrl->DeleteAllItems();
891 // We want to delete the systray too!
892 RemoveSystray();
895 void CamuleDlg::OnClose(wxCloseEvent& evt)
897 // This will be here till the core close is != app close
898 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
899 if (wxNO == wxMessageBox(wxString(_("Do you really want to exit aMule?")),
900 wxString(_("Exit confirmation")), wxYES_NO, this)) {
901 evt.Veto();
902 return;
906 Enable(false);
907 Show(false);
909 theApp->ShutDown(evt);
913 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
915 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
917 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
918 wxString strlink = ctl->GetLineText(i);
919 strlink.Trim(true);
920 strlink.Trim(false);
921 if ( !strlink.IsEmpty() ) {
922 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
926 ctl->SetValue(wxEmptyString);
930 // Formerly known as LoadRazorPrefs()
931 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
933 // Create a config base for loading razor preferences
934 wxConfigBase *config = wxConfigBase::Get();
935 // If config haven't been created exit without loading
936 if (config == NULL) {
937 return false;
940 // The section where to save in in file
941 wxString section = wxT("/Razor_Preferences/");
943 // Get window size and position
944 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
945 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
946 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
947 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
949 int maximized = config->Read(section + wxT("Maximized"), 01);
951 // Kry - Random usable pos for m_srv_split_pos
952 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
953 if (!override_size) {
954 if (x2 > 0 && y2 > 0) {
955 SetSize(x2, y2);
956 } else {
957 #ifndef __WXGTK__
958 // Probably first run.
959 Maximize();
960 #endif
964 if (!override_pos) {
965 // If x1 and y1 != -1 Redefine location
966 if(x1 != -1 && y1 != -1) {
967 wxRect display = wxGetClientDisplayRect();
968 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
969 Move(x1, y1);
970 } else {
971 // It's offscreen... so let's not.
976 if (!override_size && !override_pos && maximized) {
977 Maximize();
980 return true;
984 bool CamuleDlg::SaveGUIPrefs()
986 /* Razor 1a - Modif by MikaelB
987 Save client size and position */
989 // Create a config base for saving razor preferences
990 wxConfigBase *config = wxConfigBase::Get();
991 // If config haven't been created exit without saving
992 if (config == NULL) {
993 return false;
995 // The section where to save in in file
996 wxString section = wxT("/Razor_Preferences/");
998 if (!IsIconized()) {
999 // Main window location and size
1000 int x1, y1, x2, y2;
1001 GetPosition(&x1, &y1);
1002 GetSize(&x2, &y2);
1004 // Saving window size and position
1005 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1006 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1008 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1009 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1011 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1014 // Saving sash position of splitter in server window
1015 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1017 config->Flush(true);
1019 /* End modif */
1021 return true;
1025 void CamuleDlg::DoIconize(bool iconize)
1027 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1028 if (iconize) {
1029 // Skip() will do it.
1030 //Iconize(true);
1031 if (SafeState()) {
1032 Show(false);
1034 } else {
1035 Show(true);
1036 Raise();
1038 } else {
1039 // Will be done by Skip();
1040 //Iconize(iconize);
1044 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1046 // Evil Hack: check if the mouse is inside the window
1047 #ifndef __WXMSW__
1048 if (GetScreenRect().Contains(wxGetMousePosition()))
1049 #endif
1051 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1052 // Veto.
1053 } else {
1054 if (m_wndTaskbarNotifier) {
1055 #if wxCHECK_VERSION(2, 9, 0)
1056 DoIconize(evt.IsIconized());
1057 #else
1058 DoIconize(evt.Iconized());
1059 #endif
1061 evt.Skip();
1066 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1068 // Former TimerProc section
1070 static uint32 msPrev1, msPrev5, msPrevStats;
1072 uint32 msCur = theStats::GetUptimeMillis();
1074 // can this actually happen under wxwin ?
1075 if (!SafeState()) {
1076 return;
1079 #ifndef CLIENT_GUI
1080 static uint32 msPrevGraph;
1081 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1082 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1083 // trying to get the graph shifts evenly spaced after a change in the update period
1084 msPrevGraph = msCur;
1086 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1088 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1089 m_kademliawnd->UpdateGraph(update);
1091 #else
1092 //#warning TODO: CORE/GUI -- EC needed
1093 #endif
1095 int sStatsUpdate = thePrefs::GetStatsInterval();
1096 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1097 if (m_statisticswnd->IsShownOnScreen()) {
1098 msPrevStats = msCur;
1099 m_statisticswnd->ShowStatistics();
1103 if (msCur-msPrev5 > 5000) { // every 5 seconds
1104 msPrev5 = msCur;
1105 ShowTransferRate();
1106 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1107 m_transferwnd->UpdateCatTabTitles();
1109 if (thePrefs::AutoSortDownload()) {
1110 m_transferwnd->downloadlistctrl->SortList();
1114 if (msCur-msPrev1 > 1000) { // every second
1115 msPrev1 = msCur;
1116 if (m_CurrentBlinkBitmap == 12) {
1117 m_CurrentBlinkBitmap = 7;
1118 SetMessagesTool();
1119 } else {
1120 if (m_BlinkMessages) {
1121 m_CurrentBlinkBitmap = 12;
1122 SetMessagesTool();
1130 void CamuleDlg::SetMessagesTool()
1132 wxWindowUpdateLocker freezer(m_wndToolbar);
1133 #ifdef __WXCOCOA__
1134 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1135 #else
1136 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1137 #endif
1140 void CamuleDlg::LaunchUrl( const wxString& url )
1142 wxString cmd;
1144 cmd = thePrefs::GetBrowser();
1145 wxString tmp = url;
1146 // Pipes cause problems, so escape them
1147 tmp.Replace( wxT("|"), wxT("%7C") );
1149 if ( !cmd.IsEmpty() ) {
1150 if (!cmd.Replace(wxT("%s"), tmp)) {
1151 // No %s found, just append the url
1152 cmd += wxT(" ") + tmp;
1155 CTerminationProcess *p = new CTerminationProcess(cmd);
1156 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1157 AddLogLineN(_("Launch Command: ") + cmd);
1158 return;
1159 } else {
1160 delete p;
1162 } else {
1163 wxLaunchDefaultBrowser(tmp);
1164 return;
1166 // Unable to execute browser. But this error message doesn't make sense,
1167 // cosidering that you _can't_ set the browser executable path... =/
1168 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1172 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1174 wxString URL;
1175 switch (wsProvider) {
1176 case WS_FILEHASH:
1177 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1178 break;
1179 default:
1180 wxFAIL;
1182 URL.Replace(wxT("FILENAME"), filename);
1184 return URL;
1188 bool CamuleDlg::Check_and_Init_Skin()
1190 bool ret = true;
1191 wxString skinFileName(thePrefs::GetSkin());
1193 if (skinFileName.IsEmpty()) {
1194 return false;
1197 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1199 wxStandardPathsBase &spb(wxStandardPaths::Get());
1200 #ifdef __WXMSW__
1201 wxString dataDir(spb.GetPluginsDir());
1202 #elif defined(__WXMAC__)
1203 wxString dataDir(spb.GetDataDir());
1204 #else
1205 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1206 #endif
1207 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1210 skinFileName.Replace(wxT("User:"), userDir );
1211 skinFileName.Replace(wxT("System:"), systemDir );
1213 m_skinFileName.Assign(skinFileName);
1214 if (!m_skinFileName.FileExists()) {
1215 AddLogLineM(true, CFormat(
1216 _("Skin directory '%s' does not exist")) %
1217 skinFileName );
1218 ret = false;
1219 } else if (!m_skinFileName.IsFileReadable()) {
1220 AddLogLineM(true, CFormat(
1221 _("WARNING: Unable to open skin file '%s' for read")) %
1222 skinFileName);
1223 ret = false;
1226 wxFFileInputStream in(m_skinFileName.GetFullPath());
1227 wxZipInputStream zip(in);
1229 while ((entry = zip.GetNextEntry()) != NULL) {
1230 wxZipEntry*& current = cat[entry->GetInternalName()];
1231 delete current;
1232 current = entry;
1235 return ret;
1239 void CamuleDlg::Add_Skin_Icon(
1240 const wxString &iconName,
1241 const wxBitmap &stdIcon,
1242 bool useSkins)
1244 wxImage new_image;
1245 if (useSkins) {
1246 wxFFileInputStream in(m_skinFileName.GetFullPath());
1247 wxZipInputStream zip(in);
1249 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1250 if ( it != cat.end() ) {
1251 zip.OpenEntry(*it->second);
1252 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1253 AddLogLineM(false,
1254 wxT("Warning: Error loading icon for ") +
1255 iconName);
1256 useSkins = false;
1258 }else {
1259 AddLogLineM(false,
1260 wxT("Warning: Can't load icon for ") +
1261 iconName);
1262 useSkins = false;
1267 wxBitmap bmp(useSkins ? new_image : stdIcon);
1268 if (iconName.StartsWith(wxT("Client_"))) {
1269 m_imagelist.Add(bmp);
1270 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1271 m_tblist.Add(bmp);
1276 void CamuleDlg::Apply_Clients_Skin()
1278 bool useSkins = Check_and_Init_Skin();
1280 // Clear the client image list
1281 m_imagelist.RemoveAll();
1283 // Add the images to the image list
1284 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1285 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1286 clientImages(i), useSkins);
1291 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1293 bool useSkins = Check_and_Init_Skin();
1296 // Clear the toolbar image list
1297 m_tblist.RemoveAll();
1299 // Add the images to the image list
1300 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1301 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1302 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1303 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1304 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1305 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1306 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1307 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1311 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1312 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1314 // Build aMule toolbar
1315 wndToolbar->SetMargins(0, 0);
1317 // Placeholder. Gets updated by ShowConnectionState
1318 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1320 wndToolbar->AddSeparator();
1321 wndToolbar->AddTool(ID_BUTTONNETWORKS,
1322 _("Networks"), m_tblist.GetBitmap(3),
1323 wxNullBitmap, wxITEM_CHECK,
1324 _("Networks window"));
1325 wndToolbar->AddTool(ID_BUTTONSEARCH,
1326 _("Searches"), m_tblist.GetBitmap(5),
1327 wxNullBitmap, wxITEM_CHECK,
1328 _("Searches window"));
1329 wndToolbar->AddTool(ID_BUTTONTRANSFER,
1330 _("Transfers"), m_tblist.GetBitmap(4),
1331 wxNullBitmap, wxITEM_CHECK,
1332 _("Files transfers window"));
1333 wndToolbar->AddTool(ID_BUTTONSHARED,
1334 _("Shared files"), m_tblist.GetBitmap(6),
1335 wxNullBitmap, wxITEM_CHECK,
1336 _("Shared files window"));
1337 wndToolbar->AddTool(ID_BUTTONMESSAGES,
1338 _("Messages"), m_tblist.GetBitmap(7),
1339 wxNullBitmap, wxITEM_CHECK,
1340 _("Messages window"));
1341 wndToolbar->AddTool(ID_BUTTONSTATISTICS,
1342 _("Statistics"), m_tblist.GetBitmap(8),
1343 wxNullBitmap, wxITEM_CHECK,
1344 _("Statistics graph window"));
1345 wndToolbar->AddSeparator();
1346 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES,
1347 _("Preferences"), m_tblist.GetBitmap(9),
1348 wxNullBitmap, wxITEM_NORMAL,
1349 _("Preferences settings window"));
1350 wndToolbar->AddTool(ID_BUTTONIMPORT,
1351 _("Import"), m_tblist.GetBitmap(10),
1352 wxNullBitmap, wxITEM_NORMAL,
1353 _("The partfile importer tool"));
1354 wndToolbar->AddTool(ID_ABOUT,
1355 _("About"), m_tblist.GetBitmap(11),
1356 wxNullBitmap, wxITEM_NORMAL,
1357 _("About/Help"));
1359 wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true);
1361 // Needed for non-GTK platforms, where the
1362 // items don't get added immediatly.
1363 wndToolbar->Realize();
1365 // Updates the "Connect" button, and so on.
1366 ShowConnectionState(true);
1370 void CamuleDlg::Create_Toolbar(bool orientation)
1372 Freeze();
1373 // Create ToolBar from the one designed by wxDesigner (BigBob)
1374 wxToolBar *current = GetToolBar();
1376 wxASSERT(current == m_wndToolbar);
1378 if (current) {
1379 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1380 if (oldorientation != orientation) {
1381 current->Destroy();
1382 SetToolBar(NULL); // Remove old one if present
1383 m_wndToolbar = NULL;
1384 } else {
1385 current->ClearTools();
1389 if (!m_wndToolbar) {
1390 m_wndToolbar = CreateToolBar(
1391 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1392 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1393 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1396 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1399 Apply_Toolbar_Skin(m_wndToolbar);
1401 Thaw();
1405 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1407 wxFrame::OnSize(evt);
1408 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1409 // Transfer window's splitter set again if it's hidden.
1410 if (m_transferwnd->clientlistctrl->GetListView() == vtNone) {
1411 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1412 wxSplitterWindow* splitter =
1413 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1414 height += splitter->GetWindow1()->GetSize().GetHeight();
1415 splitter->SetSashPosition( height );
1422 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1424 if (event.GetKeyCode() == WXK_F1) {
1425 // Ctrl/Alt/Shift must not be pressed, to avoid
1426 // conflicts with other (global) shortcuts.
1427 if (!event.HasModifiers() && !event.ShiftDown()) {
1428 LaunchUrl(wxT("http://wiki.amule.org"));
1429 return;
1433 event.Skip();
1437 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1439 Close();
1442 void CamuleDlg::DoNetworkRearrange()
1445 wxWindowUpdateLocker freezer(this);
1447 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1449 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1450 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1452 while (logs_notebook->GetPageCount() > 1) {
1453 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1456 while (networks_notebook->GetPageCount() > 0) {
1457 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1460 if (thePrefs::GetNetworkED2K()) {
1461 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1462 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1465 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1467 if (thePrefs::GetNetworkKademlia()) {
1468 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1471 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1473 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1475 wxWindow* replacement = NULL;
1477 m_networknotebooksizer->Clear();
1479 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1480 toolbarTool->SetLabel(_("Networks"));
1482 m_networkpages[0].page->Reparent(networks_notebook);
1483 m_networkpages[1].page->Reparent(networks_notebook);
1485 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1486 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1488 replacement = networks_notebook;
1490 } else if (thePrefs::GetNetworkED2K()) {
1491 toolbarTool->SetLabel(_("eD2k network"));
1492 replacement = m_networkpages[0].page;
1493 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1494 } else if (thePrefs::GetNetworkKademlia()) {
1495 toolbarTool->SetLabel(_("Kad network"));
1496 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1497 replacement = m_networkpages[1].page;
1498 } else {
1499 // No networks.
1500 toolbarTool->SetLabel(_("No network"));
1503 if (replacement) {
1504 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1505 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1506 m_networknotebooksizer->Layout();
1509 m_wndToolbar->InsertTool(2, toolbarTool);
1511 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1512 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1514 m_wndToolbar->Realize();
1516 m_searchwnd->FixSearchTypes();
1519 // File_checked_for_headers