Upstream tarball 9440
[amule.git] / src / amuleDlg.cpp
bloba6346a7c2faeb92eedf25dbd4795a2ddda893c83
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 #ifndef CLIENT_GUI
76 #include "PartFileConvert.h"
77 #endif
79 #ifndef __WXMSW__
80 #include "aMule.xpm"
81 #endif
83 #include "kademlia/kademlia/Kademlia.h"
85 #ifdef ENABLE_IP2COUNTRY
86 #include "IP2Country.h" // Needed for IP2Country
87 #endif
89 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
90 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
91 void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
93 m_IP2Country->DownloadFinished(result);
96 void CamuleDlg::EnableIP2Country()
98 if (thePrefs::IsGeoIPEnabled()) {
99 m_IP2Country->Enable();
103 #else
105 void CamuleDlg::IP2CountryDownloadFinished(uint32){}
106 void CamuleDlg::EnableIP2Country(){}
108 #endif
110 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
112 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
113 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
114 EVT_TOOL(ID_BUTTONTRANSFER, CamuleDlg::OnToolBarButton)
115 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
116 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
117 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
118 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
120 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
121 #ifndef CLIENT_GUI
122 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
123 #endif
125 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
127 EVT_CLOSE(CamuleDlg::OnClose)
128 EVT_ICONIZE(CamuleDlg::OnMinimize)
130 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
132 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
134 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
136 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
138 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
140 END_EVENT_TABLE()
142 #ifndef wxCLOSE_BOX
143 #define wxCLOSE_BOX 0
144 #endif
146 CamuleDlg::CamuleDlg(
147 wxWindow* pParent,
148 const wxString &title,
149 wxPoint where,
150 wxSize dlg_size)
152 wxFrame(
153 pParent, -1, title, where, dlg_size,
154 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
155 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
156 wxT("aMule")),
157 m_activewnd(NULL),
158 m_transferwnd(NULL),
159 m_serverwnd(NULL),
160 m_sharedfileswnd(NULL),
161 m_searchwnd(NULL),
162 m_chatwnd(NULL),
163 m_statisticswnd(NULL),
164 m_kademliawnd(NULL),
165 m_prefsDialog(NULL),
166 m_srv_split_pos(0),
167 m_imagelist(16,16),
168 m_tblist(32,32),
169 m_prefsVisible(false),
170 m_wndToolbar(NULL),
171 m_wndTaskbarNotifier(NULL),
172 m_TrayIcon(false),
173 m_nActiveDialog(DT_NETWORKS_WND),
174 m_is_safe_state(false),
175 m_BlinkMessages(false),
176 m_CurrentBlinkBitmap(24),
177 m_last_iconizing(0),
178 m_skinFileName(),
179 m_clientSkinNames(CLIENT_SKIN_SIZE)
181 // Initialize skin names
182 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
183 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
184 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
185 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
186 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
187 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
188 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
189 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
190 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
191 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
192 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
193 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
194 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
195 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
196 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
197 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
198 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
199 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
200 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
201 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
202 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
203 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
204 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
205 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
206 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
207 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
208 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
210 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
211 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
212 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
213 wxInitAllImageHandlers();
214 Apply_Clients_Skin();
216 #ifdef __WXMSW__
217 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
218 #endif
220 SetIcon(wxICON(aMule));
222 srand(time(NULL));
224 // Create new sizer and stuff a wxPanel in there.
225 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
226 s_main->AddGrowableCol(0);
227 s_main->AddGrowableRow(0);
229 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
230 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
231 muleDlg(p_cnt, false, true);
232 SetSizer(s_main, true);
234 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
235 AddLogLineM(false, wxEmptyString);
236 AddLogLineM(false, wxT(" - ") +
237 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
238 AddLogLineM(false, wxT(" ") +
239 CFormat(_("Running on %s")) % wxGetOsDescription());
240 AddLogLineM(false, wxT(" - ") +
241 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
242 AddLogLineM(false, wxEmptyString);
244 #ifdef ENABLE_IP2COUNTRY
245 m_GeoIPavailable = true;
246 m_IP2Country = new CIP2Country();
247 #else
248 m_GeoIPavailable = false;
249 #endif
250 m_searchwnd = new CSearchDlg(p_cnt);
251 m_transferwnd = new CTransferWnd(p_cnt);
252 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
253 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
254 m_chatwnd = new CChatWnd(p_cnt);
255 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
257 m_serverwnd->Show(false);
258 m_searchwnd->Show(false);
259 m_transferwnd->Show(false);
260 m_sharedfileswnd->Show(false);
261 m_statisticswnd->Show(false);
262 m_chatwnd->Show(false);
264 // Create the GUI timer
265 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
266 if (!gui_timer) {
267 AddLogLineM(false, _("FATAL ERROR: Failed to create Timer"));
268 exit(1);
271 // Set transfers as active window
272 Create_Toolbar(thePrefs::VerticalToolbar());
273 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
274 m_wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true );
276 bool override_where = (where != wxDefaultPosition);
277 bool override_size = (
278 (dlg_size.x != DEFAULT_SIZE_X) ||
279 (dlg_size.y != DEFAULT_SIZE_Y) );
280 if (!LoadGUIPrefs(override_where, override_size)) {
281 // Prefs not loaded for some reason, exit
282 AddLogLineM( true, wxT("Error! Unable to load Preferences") );
283 return;
286 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
287 m_transferwnd->Prepare();
289 m_is_safe_state = true;
291 // Init statistics stuff, better do it asap
292 m_statisticswnd->Init();
293 m_kademliawnd->Init();
294 m_searchwnd->UpdateCatChoice();
295 if (thePrefs::UseTrayIcon()) {
296 CreateSystray();
299 Show(true);
300 // Must we start minimized?
301 if (thePrefs::GetStartMinimized()) {
302 DoIconize(true);
305 // Set shortcut keys
306 wxAcceleratorEntry entries[] = {
307 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
310 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
311 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
313 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
314 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
316 wxASSERT(logs_notebook->GetPageCount() == 4);
317 wxASSERT(networks_notebook->GetPageCount() == 2);
319 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
320 m_logpages[i].page = logs_notebook->GetPage(i);
321 m_logpages[i].name = logs_notebook->GetPageText(i);
324 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
325 m_networkpages[i].page = networks_notebook->GetPage(i);
326 m_networkpages[i].name = networks_notebook->GetPageText(i);
329 DoNetworkRearrange();
333 // Madcat - Sets Fast ED2K Links Handler on/off.
334 void CamuleDlg::ShowED2KLinksHandler( bool show )
336 // Errorchecking in case the pointer becomes invalid ...
337 if (s_fed2klh == NULL) {
338 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
339 return;
342 s_dlgcnt->Show( s_fed2klh, show );
343 s_dlgcnt->Layout();
346 // Toogles ed2k link handler.
347 void CamuleDlg::ToogleED2KLinksHandler()
349 // Errorchecking in case the pointer becomes invalid ...
350 if (s_fed2klh == NULL) {
351 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
352 return;
354 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
357 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
359 m_nActiveDialog = type;
361 if ( type == DT_TRANSFER_WND ) {
362 if (thePrefs::ShowCatTabInfos()) {
363 m_transferwnd->UpdateCatTabTitles();
367 if ( m_activewnd ) {
368 m_activewnd->Show(false);
369 contentSizer->Detach(m_activewnd);
372 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
373 dlg->Show(true);
374 m_activewnd=dlg;
375 s_dlgcnt->Layout();
377 // Since we might be suspending redrawing while hiding the dialog
378 // we have to refresh it once it is visible again
379 dlg->Refresh( true );
380 dlg->SetFocus();
384 void CamuleDlg::UpdateTrayIcon(int percent)
386 // set trayicon-icon
387 if(!theApp->IsConnected()) {
388 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
389 } else {
390 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
391 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
392 } else {
393 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
399 void CamuleDlg::CreateSystray()
401 wxCHECK_RET(m_TrayIcon == false,
402 wxT("Systray already created"));
404 m_wndTaskbarNotifier = new CMuleTrayIcon();
405 m_TrayIcon = true;
406 // This will effectively show the Tray Icon.
407 UpdateTrayIcon(0);
411 void CamuleDlg::RemoveSystray()
413 delete m_wndTaskbarNotifier;
414 m_wndTaskbarNotifier = NULL;
415 m_TrayIcon = false;
419 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
421 static int lastbutton = ID_BUTTONTRANSFER;
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_BUTTONTRANSFER:
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 wxBusyCursor busyCursor;
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 #ifndef CLIENT_GUI
529 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
531 if ( m_is_safe_state ) {
532 CPartFileConvert::ShowGUI(NULL);
535 #endif
537 CamuleDlg::~CamuleDlg()
539 AddLogLineN(_("Shutting down aMule..."));
541 SaveGUIPrefs();
543 theApp->amuledlg = NULL;
545 #ifdef ENABLE_IP2COUNTRY
546 delete m_IP2Country;
547 #endif
549 AddLogLineN(_("aMule dialog destroyed"));
553 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
556 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
557 #ifndef CLIENT_GUI
558 || (Kademlia::CKademlia::IsRunning())
559 #endif
561 if (thePrefs::GetNetworkED2K()) {
562 if (disconnect) {
563 //disconnect if currently connected
564 if (theApp->serverconnect->IsConnecting()) {
565 theApp->serverconnect->StopConnectionTry();
566 } else {
567 theApp->serverconnect->Disconnect();
569 } else {
570 //connect if not currently connected
571 AddLogLineM(true, _("Connecting"));
572 theApp->serverconnect->ConnectToAnyServer();
574 } else {
575 wxASSERT(!theApp->IsConnectedED2K());
578 // Connect Kad also
579 if (thePrefs::GetNetworkKademlia()) {
580 if( disconnect ) {
581 theApp->StopKad();
582 } else {
583 theApp->StartKad();
585 } else {
586 #ifndef CLIENT_GUI
587 wxASSERT(!Kademlia::CKademlia::IsRunning());
588 #endif
591 ShowConnectionState();
595 void CamuleDlg::ResetLog(int id)
597 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
598 wxCHECK_RET(ct, wxT("Resetting unknown log"));
600 ct->Clear();
602 if (id == ID_LOGVIEW) {
603 // Also clear the log line
604 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
605 text->SetLabel(wxEmptyString);
606 text->GetParent()->Layout();
611 void CamuleDlg::AddLogLine(const wxString& line)
613 bool addtostatusbar = line[0] == '!';
614 wxString bufferline = line.Mid(1);
616 // Add the message to the log-view
617 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
618 if ( ct ) {
619 // Bold critical log-lines
620 // to enable this on Windows control has to be changed to wxTE_RICH2 in muuli
621 #ifdef __WXMSW__
622 ct->AppendText(line); // keep the leading "!" if it can't be bolded
623 #else
624 wxTextAttr style = ct->GetDefaultStyle();
625 wxFont font = style.GetFont();
626 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
627 style.SetFont(font);
628 ct->SetDefaultStyle(style);
629 ct->AppendText(bufferline);
630 #endif
631 ct->ShowPosition( ct->GetLastPosition() - 1 );
635 // Set the status-bar if the event warrents it
636 if ( addtostatusbar ) {
637 // Escape "&"s, which would otherwise not show up
638 bufferline.Replace( wxT("&"), wxT("&&") );
639 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
640 // Only show the first line if multiple lines
641 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
642 text->SetToolTip( bufferline );
643 text->GetParent()->Layout();
649 void CamuleDlg::AddServerMessageLine(wxString& message)
651 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
652 if(cv) {
653 if (message.Length() > 500) {
654 cv->AppendText(message.Left(500) + wxT("\n"));
655 } else {
656 cv->AppendText(message + wxT("\n"));
658 cv->ShowPosition(cv->GetLastPosition()-1);
663 void CamuleDlg::ShowConnectionState(bool skinChanged)
665 static wxImageList status_arrows(16,16,true,0);
666 if (!status_arrows.GetImageCount()) {
667 // Generate the image list (This is only done once)
668 for (int t = 0; t < 7; ++t) {
669 status_arrows.Add(connImages(t));
673 m_serverwnd->UpdateED2KInfo();
674 m_serverwnd->UpdateKadInfo();
677 ////////////////////////////////////////////////////////////
678 // Determine the status of the networks
680 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
681 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
683 ED2KState ed2kState = ED2KOff;
684 EKadState kadState = EKadOff;
686 ////////////////////////////////////////////////////////////
687 // Update the label on the status-bar and determine
688 // the states of the two networks.
690 wxString msgED2K;
691 if (theApp->IsConnectedED2K()) {
692 CServer* server = theApp->serverconnect->GetCurrentServer();
693 if (server) {
694 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
697 if (theApp->serverconnect->IsLowID()) {
698 ed2kState = ED2KLowID;
699 } else {
700 ed2kState = ED2KHighID;
702 } else if (theApp->serverconnect->IsConnecting()) {
703 msgED2K = _("eD2k: Connecting");
705 ed2kState = ED2KConnecting;
706 } else if (thePrefs::GetNetworkED2K()) {
707 msgED2K = _("eD2k: Disconnected");
710 wxString msgKad;
711 if (theApp->IsConnectedKad()) {
712 if (theApp->IsFirewalledKad()) {
713 msgKad = _("Kad: Firewalled");
715 kadState = EKadFW;
716 } else {
717 msgKad = _("Kad: Connected");
719 kadState = EKadOK;
721 } else if (theApp->IsKadRunning()) {
722 msgKad = _("Kad: Connecting");
724 kadState = EKadConnecting;
725 } else if (thePrefs::GetNetworkKademlia()) {
726 msgKad = _("Kad: Off");
729 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
730 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
732 wxString labelMsg;
733 if (msgED2K.Length() && msgKad.Length()) {
734 labelMsg = msgED2K + wxT(" | ") + msgKad;
735 } else {
736 labelMsg = msgED2K + msgKad;
739 connLabel->SetLabel(labelMsg);
740 connLabel->GetParent()->Layout();
743 ////////////////////////////////////////////////////////////
744 // Update the connect/disconnect/cancel button.
746 enum EConnState {
747 ECS_Unknown,
748 ECS_Connected,
749 ECS_Connecting,
750 ECS_Disconnected
753 static EConnState s_oldState = ECS_Unknown;
754 EConnState currentState = ECS_Disconnected;
756 if (theApp->serverconnect->IsConnecting() ||
757 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
758 currentState = ECS_Connecting;
759 } else if (theApp->IsConnected()) {
760 currentState = ECS_Connected;
761 } else {
762 currentState = ECS_Disconnected;
765 if ( (true == skinChanged) || (currentState != s_oldState) ) {
766 wxWindowUpdateLocker freezer(m_wndToolbar);
768 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
770 switch (currentState) {
771 case ECS_Connecting:
772 toolbarTool->SetLabel(_("Cancel"));
773 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
774 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
775 break;
777 case ECS_Connected:
778 toolbarTool->SetLabel(_("Disconnect"));
779 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
780 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
781 break;
783 default:
784 toolbarTool->SetLabel(_("Connect"));
785 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
786 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
789 m_wndToolbar->InsertTool(0, toolbarTool);
790 m_wndToolbar->Realize();
792 s_oldState = currentState;
796 ////////////////////////////////////////////////////////////
797 // Update the globe-icon in the lower-right corner.
798 // (only if connection state has changed)
800 static ED2KState s_ED2KOldState = ED2KUndef;
801 static EKadState s_EKadOldState = EKadUndef;
802 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
803 s_ED2KOldState = ed2kState;
804 s_EKadOldState = kadState;
805 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
806 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
808 wxBitmap statusIcon = connBitmap->GetBitmap();
809 // Sanity check - otherwise there's a crash here if aMule runs out of resources
810 if (statusIcon.GetRefData() == NULL) {
811 return;
814 wxMemoryDC bitmapDC(statusIcon);
816 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
817 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
819 connBitmap->SetBitmap(statusIcon);
824 void CamuleDlg::ShowUserCount(const wxString& info)
826 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
828 // Update Kad tab
829 m_serverwnd->UpdateKadInfo();
831 label->SetLabel(info);
832 label->GetParent()->Layout();
836 void CamuleDlg::ShowTransferRate()
838 float kBpsUp = theStats::GetUploadRate() / 1024.0;
839 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
840 wxString buffer;
841 if( thePrefs::ShowOverhead() )
843 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
844 } else {
845 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
847 buffer.Truncate(50); // Max size 50
849 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
850 label->SetLabel(buffer);
851 label->GetParent()->Layout();
853 // Show upload/download speed in title
854 if (thePrefs::GetShowRatesOnTitle()) {
855 wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
856 if (thePrefs::GetShowRatesOnTitle() == 1) {
857 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
858 } else {
859 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
863 wxASSERT(m_TrayIcon == thePrefs::UseTrayIcon());
864 if (m_TrayIcon) {
865 // set trayicon-icon
866 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
867 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
869 wxString buffer2;
870 if ( theApp->IsConnected() ) {
871 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
872 } else {
873 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
875 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
878 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
879 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
882 void CamuleDlg::DlgShutDown()
884 // Are we already shutting down or still on init?
885 if ( m_is_safe_state == false ) {
886 return;
889 // we are going DOWN
890 m_is_safe_state = false;
892 // Stop the GUI Timer
893 delete gui_timer;
894 m_transferwnd->downloadlistctrl->DeleteAllItems();
896 // We want to delete the systray too!
897 RemoveSystray();
900 void CamuleDlg::OnClose(wxCloseEvent& evt)
902 // This will be here till the core close is != app close
903 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
904 if (wxNO == wxMessageBox(wxString(_("Do you really want to exit aMule?")),
905 wxString(_("Exit confirmation")), wxYES_NO, this)) {
906 evt.Veto();
907 return;
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 // Main window location and size
1004 int x1, y1, x2, y2;
1005 GetPosition(&x1, &y1);
1006 GetSize(&x2, &y2);
1008 // Saving window size and position
1009 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1010 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1012 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1013 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1015 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1017 // Saving sash position of splitter in server window
1018 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1020 config->Flush(true);
1022 /* End modif */
1024 return true;
1028 void CamuleDlg::DoIconize(bool iconize)
1030 if (m_TrayIcon && thePrefs::DoMinToTray()) {
1031 if (iconize) {
1032 // Skip() will do it.
1033 //Iconize(true);
1034 if (SafeState()) {
1035 Show(false);
1037 } else {
1038 Show(true);
1039 Raise();
1041 } else {
1042 // Will be done by Skip();
1043 //Iconize(iconize);
1047 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1049 // Evil Hack: check if the mouse is inside the window
1050 #ifndef __WXMSW__
1051 if (GetScreenRect().Contains(wxGetMousePosition()))
1052 #endif
1054 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1055 // Veto.
1056 } else {
1057 if (m_TrayIcon) {
1058 DoIconize(evt.Iconized());
1060 evt.Skip();
1065 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1067 // Former TimerProc section
1069 static uint32 msPrev1, msPrev5, msPrevStats;
1071 uint32 msCur = theStats::GetUptimeMillis();
1073 // can this actually happen under wxwin ?
1074 if (!SafeState()) {
1075 return;
1078 #ifndef CLIENT_GUI
1079 static uint32 msPrevGraph;
1080 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1081 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1082 // trying to get the graph shifts evenly spaced after a change in the update period
1083 msPrevGraph = msCur;
1085 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1087 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1088 m_kademliawnd->UpdateGraph(update);
1090 #else
1091 //#warning TODO: CORE/GUI -- EC needed
1092 #endif
1094 int sStatsUpdate = thePrefs::GetStatsInterval();
1095 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1096 if (m_statisticswnd->IsShownOnScreen()) {
1097 msPrevStats = msCur;
1098 m_statisticswnd->ShowStatistics();
1102 if (msCur-msPrev5 > 5000) { // every 5 seconds
1103 msPrev5 = msCur;
1104 ShowTransferRate();
1105 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1106 m_transferwnd->UpdateCatTabTitles();
1108 if (thePrefs::AutoSortDownload()) {
1109 m_transferwnd->downloadlistctrl->SortList();
1113 if (msCur-msPrev1 > 1000) { // every second
1114 msPrev1 = msCur;
1115 if (m_CurrentBlinkBitmap == 12) {
1116 m_CurrentBlinkBitmap = 7;
1117 SetMessagesTool();
1118 } else {
1119 if (m_BlinkMessages) {
1120 m_CurrentBlinkBitmap = 12;
1121 SetMessagesTool();
1129 void CamuleDlg::SetMessagesTool()
1131 int pos = m_wndToolbar->GetToolPos(ID_BUTTONMESSAGES);
1132 wxASSERT(pos == 6); // so we don't miss a change on wx2.4
1134 wxWindowUpdateLocker freezer(m_wndToolbar);
1135 #ifdef __WXCOCOA__
1136 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1137 #else
1138 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1139 #endif
1142 void CamuleDlg::LaunchUrl( const wxString& url )
1144 wxString cmd;
1146 cmd = thePrefs::GetBrowser();
1147 wxString tmp = url;
1148 // Pipes cause problems, so escape them
1149 tmp.Replace( wxT("|"), wxT("%7C") );
1151 if ( !cmd.IsEmpty() ) {
1152 if (!cmd.Replace(wxT("%s"), tmp)) {
1153 // No %s found, just append the url
1154 cmd += wxT(" ") + tmp;
1157 CTerminationProcess *p = new CTerminationProcess(cmd);
1158 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1159 AddLogLineN(_("Launch Command: ") + cmd);
1160 return;
1161 } else {
1162 delete p;
1164 } else {
1165 wxLaunchDefaultBrowser(tmp);
1166 return;
1168 // Unable to execute browser. But this error message doesn't make sense,
1169 // cosidering that you _can't_ set the browser executable path... =/
1170 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1174 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1176 wxString URL;
1177 switch (wsProvider) {
1178 case WS_FILEHASH:
1179 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1180 break;
1181 default:
1182 wxFAIL;
1184 URL.Replace(wxT("FILENAME"), filename);
1186 return URL;
1190 bool CamuleDlg::Check_and_Init_Skin()
1192 bool ret = true;
1193 wxString skinFileName(thePrefs::GetSkin());
1195 if (skinFileName.IsEmpty()) {
1196 return false;
1199 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1201 wxStandardPathsBase &spb(wxStandardPaths::Get());
1202 #ifdef __WXMSW__
1203 wxString dataDir(spb.GetPluginsDir());
1204 #elif defined(__WXMAC__)
1205 wxString dataDir(spb.GetDataDir());
1206 #else
1207 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1208 #endif
1209 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1212 skinFileName.Replace(wxT("User:"), userDir );
1213 skinFileName.Replace(wxT("System:"), systemDir );
1215 m_skinFileName.Assign(skinFileName);
1216 if (!m_skinFileName.FileExists()) {
1217 AddLogLineM(true, CFormat(
1218 _("Skin directory '%s' does not exist")) %
1219 skinFileName );
1220 ret = false;
1221 } else if (!m_skinFileName.IsFileReadable()) {
1222 AddLogLineM(true, CFormat(
1223 _("WARNING: Unable to open skin file '%s' for read")) %
1224 skinFileName);
1225 ret = false;
1228 wxFFileInputStream in(m_skinFileName.GetFullPath());
1229 wxZipInputStream zip(in);
1231 while ((entry = zip.GetNextEntry()) != NULL) {
1232 wxZipEntry*& current = cat[entry->GetInternalName()];
1233 delete current;
1234 current = entry;
1237 return ret;
1241 void CamuleDlg::Add_Skin_Icon(
1242 const wxString &iconName,
1243 const wxBitmap &stdIcon,
1244 bool useSkins)
1246 wxImage new_image;
1247 if (useSkins) {
1248 wxFFileInputStream in(m_skinFileName.GetFullPath());
1249 wxZipInputStream zip(in);
1251 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1252 if ( it != cat.end() ) {
1253 zip.OpenEntry(*it->second);
1254 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1255 AddLogLineM(false,
1256 wxT("Warning: Error loading icon for ") +
1257 iconName);
1258 useSkins = false;
1260 }else {
1261 AddLogLineM(false,
1262 wxT("Warning: Can't load icon for ") +
1263 iconName);
1264 useSkins = false;
1269 wxBitmap bmp(useSkins ? new_image : stdIcon);
1270 if (iconName.StartsWith(wxT("Client_"))) {
1271 m_imagelist.Add(bmp);
1272 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1273 m_tblist.Add(bmp);
1278 void CamuleDlg::Apply_Clients_Skin()
1280 bool useSkins = Check_and_Init_Skin();
1282 // Clear the client image list
1283 m_imagelist.RemoveAll();
1285 // Add the images to the image list
1286 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1287 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1288 clientImages(i), useSkins);
1293 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1295 bool useSkins = Check_and_Init_Skin();
1298 // Clear the toolbar image list
1299 m_tblist.RemoveAll();
1301 // Add the images to the image list
1302 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1303 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1304 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1305 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1306 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1307 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1311 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1312 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1313 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1314 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1316 // Build aMule toolbar
1317 wndToolbar->SetMargins(0, 0);
1319 // Placeholder. Gets updated by ShowConnectionState
1320 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1322 wndToolbar->AddSeparator();
1323 wndToolbar->AddTool(ID_BUTTONNETWORKS,
1324 _("Networks"), m_tblist.GetBitmap(3),
1325 wxNullBitmap, wxITEM_CHECK,
1326 _("Networks window"));
1327 wndToolbar->AddTool(ID_BUTTONSEARCH,
1328 _("Searches"), m_tblist.GetBitmap(5),
1329 wxNullBitmap, wxITEM_CHECK,
1330 _("Searches window"));
1331 wndToolbar->AddTool(ID_BUTTONTRANSFER,
1332 _("Transfers"), m_tblist.GetBitmap(4),
1333 wxNullBitmap, wxITEM_CHECK,
1334 _("Files transfers window"));
1335 wndToolbar->AddTool(ID_BUTTONSHARED,
1336 _("Shared files"), m_tblist.GetBitmap(6),
1337 wxNullBitmap, wxITEM_CHECK,
1338 _("Shared files window"));
1339 wndToolbar->AddTool(ID_BUTTONMESSAGES,
1340 _("Messages"), m_tblist.GetBitmap(7),
1341 wxNullBitmap, wxITEM_CHECK,
1342 _("Messages window"));
1343 wndToolbar->AddTool(ID_BUTTONSTATISTICS,
1344 _("Statistics"), m_tblist.GetBitmap(8),
1345 wxNullBitmap, wxITEM_CHECK,
1346 _("Statistics graph window"));
1347 wndToolbar->AddSeparator();
1348 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES,
1349 _("Preferences"), m_tblist.GetBitmap(9),
1350 wxNullBitmap, wxITEM_NORMAL,
1351 _("Preferences settings window"));
1352 wndToolbar->AddTool(ID_BUTTONIMPORT,
1353 _("Import"), m_tblist.GetBitmap(10),
1354 wxNullBitmap, wxITEM_NORMAL,
1355 _("The partfile importer tool"));
1356 wndToolbar->AddTool(ID_ABOUT,
1357 _("About"), m_tblist.GetBitmap(11),
1358 wxNullBitmap, wxITEM_NORMAL,
1359 _("About/Help"));
1361 wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true);
1363 // Needed for non-GTK platforms, where the
1364 // items don't get added immediatly.
1365 wndToolbar->Realize();
1367 // Updates the "Connect" button, and so on.
1368 ShowConnectionState(true);
1372 void CamuleDlg::Create_Toolbar(bool orientation)
1374 Freeze();
1375 // Create ToolBar from the one designed by wxDesigner (BigBob)
1376 wxToolBar *current = GetToolBar();
1378 wxASSERT(current == m_wndToolbar);
1380 if (current) {
1381 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1382 if (oldorientation != orientation) {
1383 current->Destroy();
1384 SetToolBar(NULL); // Remove old one if present
1385 m_wndToolbar = NULL;
1386 } else {
1387 current->ClearTools();
1391 if (!m_wndToolbar) {
1392 m_wndToolbar = CreateToolBar(
1393 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1394 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1395 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1398 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1401 Apply_Toolbar_Skin(m_wndToolbar);
1402 #ifdef CLIENT_GUI
1403 m_wndToolbar->DeleteTool(ID_BUTTONIMPORT);
1404 #endif
1406 Thaw();
1410 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1412 wxFrame::OnSize(evt);
1413 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1414 // Transfer window's splitter set again if it's hidden.
1415 if (m_transferwnd->clientlistctrl->GetListView() == vtNone) {
1416 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1417 wxSplitterWindow* splitter =
1418 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1419 height += splitter->GetWindow1()->GetSize().GetHeight();
1420 splitter->SetSashPosition( height );
1427 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1429 if (event.GetKeyCode() == WXK_F1) {
1430 // Ctrl/Alt/Shift must not be pressed, to avoid
1431 // conflicts with other (global) shortcuts.
1432 if (!event.HasModifiers() && !event.ShiftDown()) {
1433 LaunchUrl(wxT("http://wiki.amule.org"));
1434 return;
1438 event.Skip();
1442 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1444 Close();
1447 void CamuleDlg::DoNetworkRearrange()
1450 wxWindowUpdateLocker freezer(this);
1452 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1454 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1455 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1457 while (logs_notebook->GetPageCount() > 1) {
1458 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1461 while (networks_notebook->GetPageCount() > 0) {
1462 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1465 if (thePrefs::GetNetworkED2K()) {
1466 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1467 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1470 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1472 if (thePrefs::GetNetworkKademlia()) {
1473 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1476 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1478 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1480 wxWindow* replacement = NULL;
1482 m_networknotebooksizer->Clear();
1484 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1485 toolbarTool->SetLabel(_("Networks"));
1487 m_networkpages[0].page->Reparent(networks_notebook);
1488 m_networkpages[1].page->Reparent(networks_notebook);
1490 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1491 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1493 replacement = networks_notebook;
1495 } else if (thePrefs::GetNetworkED2K()) {
1496 toolbarTool->SetLabel(_("eD2k network"));
1497 replacement = m_networkpages[0].page;
1498 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1499 } else if (thePrefs::GetNetworkKademlia()) {
1500 toolbarTool->SetLabel(_("Kad network"));
1501 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1502 replacement = m_networkpages[1].page;
1503 } else {
1504 // No networks.
1505 toolbarTool->SetLabel(_("No network"));
1508 if (replacement) {
1509 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1510 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1511 m_networknotebooksizer->Layout();
1514 m_wndToolbar->InsertTool(2, toolbarTool);
1516 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1517 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1519 m_wndToolbar->Realize();
1521 m_searchwnd->FixSearchTypes();
1524 // File_checked_for_headers