Upstream tarball 10020
[amule.git] / src / amuleDlg.cpp
blobd77684739ca210b5dd391c0d5cc128c170da56a2
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(theApp->ConfigDir);
245 #else
246 m_GeoIPavailable = false;
247 #endif
248 m_searchwnd = new CSearchDlg(p_cnt);
249 m_transferwnd = new CTransferWnd(p_cnt);
250 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
251 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
252 m_chatwnd = new CChatWnd(p_cnt);
253 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
255 m_serverwnd->Show(false);
256 m_searchwnd->Show(false);
257 m_transferwnd->Show(false);
258 m_sharedfileswnd->Show(false);
259 m_statisticswnd->Show(false);
260 m_chatwnd->Show(false);
262 // Create the GUI timer
263 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
264 if (!gui_timer) {
265 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 theApp->amuledlg = NULL;
536 #ifdef ENABLE_IP2COUNTRY
537 delete m_IP2Country;
538 #endif
540 AddLogLineN(_("aMule dialog destroyed"));
544 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
547 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
548 #ifndef CLIENT_GUI
549 || (Kademlia::CKademlia::IsRunning())
550 #endif
552 if (thePrefs::GetNetworkED2K()) {
553 if (disconnect) {
554 //disconnect if currently connected
555 if (theApp->serverconnect->IsConnecting()) {
556 theApp->serverconnect->StopConnectionTry();
557 } else {
558 theApp->serverconnect->Disconnect();
560 } else {
561 //connect if not currently connected
562 AddLogLineM(true, _("Connecting"));
563 theApp->serverconnect->ConnectToAnyServer();
565 } else {
566 wxASSERT(!theApp->IsConnectedED2K());
569 // Connect Kad also
570 if (thePrefs::GetNetworkKademlia()) {
571 if( disconnect ) {
572 theApp->StopKad();
573 } else {
574 theApp->StartKad();
576 } else {
577 #ifndef CLIENT_GUI
578 wxASSERT(!Kademlia::CKademlia::IsRunning());
579 #endif
582 ShowConnectionState();
586 void CamuleDlg::ResetLog(int id)
588 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
589 wxCHECK_RET(ct, wxT("Resetting unknown log"));
591 ct->Clear();
593 if (id == ID_LOGVIEW) {
594 // Also clear the log line
595 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
596 text->SetLabel(wxEmptyString);
597 text->GetParent()->Layout();
602 void CamuleDlg::AddLogLine(const wxString& line)
604 bool addtostatusbar = line[0] == '!';
605 wxString bufferline = line.Mid(1);
607 // Add the message to the log-view
608 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
609 if ( ct ) {
610 // Bold critical log-lines
611 // to enable this on Windows control has to be changed to wxTE_RICH2 in muuli
612 #ifdef __WXMSW__
613 ct->AppendText(line); // keep the leading "!" if it can't be bolded
614 #else
615 wxTextAttr style = ct->GetDefaultStyle();
616 wxFont font = style.GetFont();
617 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
618 style.SetFont(font);
619 ct->SetDefaultStyle(style);
620 ct->AppendText(bufferline);
621 #endif
622 ct->ShowPosition( ct->GetLastPosition() - 1 );
626 // Set the status-bar if the event warrents it
627 if ( addtostatusbar ) {
628 // Escape "&"s, which would otherwise not show up
629 bufferline.Replace( wxT("&"), wxT("&&") );
630 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
631 // Only show the first line if multiple lines
632 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
633 text->SetToolTip( bufferline );
634 text->GetParent()->Layout();
640 void CamuleDlg::AddServerMessageLine(wxString& message)
642 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
643 if(cv) {
644 if (message.Length() > 500) {
645 cv->AppendText(message.Left(500) + wxT("\n"));
646 } else {
647 cv->AppendText(message + wxT("\n"));
649 cv->ShowPosition(cv->GetLastPosition()-1);
654 void CamuleDlg::ShowConnectionState(bool skinChanged)
656 static wxImageList status_arrows(16,16,true,0);
657 if (!status_arrows.GetImageCount()) {
658 // Generate the image list (This is only done once)
659 for (int t = 0; t < 7; ++t) {
660 status_arrows.Add(connImages(t));
664 m_serverwnd->UpdateED2KInfo();
665 m_serverwnd->UpdateKadInfo();
668 ////////////////////////////////////////////////////////////
669 // Determine the status of the networks
671 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
672 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
674 ED2KState ed2kState = ED2KOff;
675 EKadState kadState = EKadOff;
677 ////////////////////////////////////////////////////////////
678 // Update the label on the status-bar and determine
679 // the states of the two networks.
681 wxString msgED2K;
682 if (theApp->IsConnectedED2K()) {
683 CServer* server = theApp->serverconnect->GetCurrentServer();
684 if (server) {
685 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
688 if (theApp->serverconnect->IsLowID()) {
689 ed2kState = ED2KLowID;
690 } else {
691 ed2kState = ED2KHighID;
693 } else if (theApp->serverconnect->IsConnecting()) {
694 msgED2K = _("eD2k: Connecting");
696 ed2kState = ED2KConnecting;
697 } else if (thePrefs::GetNetworkED2K()) {
698 msgED2K = _("eD2k: Disconnected");
701 wxString msgKad;
702 if (theApp->IsConnectedKad()) {
703 if (theApp->IsFirewalledKad()) {
704 msgKad = _("Kad: Firewalled");
706 kadState = EKadFW;
707 } else {
708 msgKad = _("Kad: Connected");
710 kadState = EKadOK;
712 } else if (theApp->IsKadRunning()) {
713 msgKad = _("Kad: Connecting");
715 kadState = EKadConnecting;
716 } else if (thePrefs::GetNetworkKademlia()) {
717 msgKad = _("Kad: Off");
720 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
721 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
723 wxString labelMsg;
724 if (msgED2K.Length() && msgKad.Length()) {
725 labelMsg = msgED2K + wxT(" | ") + msgKad;
726 } else {
727 labelMsg = msgED2K + msgKad;
730 connLabel->SetLabel(labelMsg);
731 connLabel->GetParent()->Layout();
734 ////////////////////////////////////////////////////////////
735 // Update the connect/disconnect/cancel button.
737 enum EConnState {
738 ECS_Unknown,
739 ECS_Connected,
740 ECS_Connecting,
741 ECS_Disconnected
744 static EConnState s_oldState = ECS_Unknown;
745 EConnState currentState = ECS_Disconnected;
747 if (theApp->serverconnect->IsConnecting() ||
748 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
749 currentState = ECS_Connecting;
750 } else if (theApp->IsConnected()) {
751 currentState = ECS_Connected;
752 } else {
753 currentState = ECS_Disconnected;
756 if ( (true == skinChanged) || (currentState != s_oldState) ) {
757 wxWindowUpdateLocker freezer(m_wndToolbar);
759 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
761 switch (currentState) {
762 case ECS_Connecting:
763 toolbarTool->SetLabel(_("Cancel"));
764 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
765 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
766 break;
768 case ECS_Connected:
769 toolbarTool->SetLabel(_("Disconnect"));
770 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
771 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
772 break;
774 default:
775 toolbarTool->SetLabel(_("Connect"));
776 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
777 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
780 m_wndToolbar->InsertTool(0, toolbarTool);
781 m_wndToolbar->Realize();
783 s_oldState = currentState;
787 ////////////////////////////////////////////////////////////
788 // Update the globe-icon in the lower-right corner.
789 // (only if connection state has changed)
791 static ED2KState s_ED2KOldState = ED2KUndef;
792 static EKadState s_EKadOldState = EKadUndef;
793 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
794 s_ED2KOldState = ed2kState;
795 s_EKadOldState = kadState;
796 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
797 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
799 wxBitmap statusIcon = connBitmap->GetBitmap();
800 // Sanity check - otherwise there's a crash here if aMule runs out of resources
801 if (statusIcon.GetRefData() == NULL) {
802 return;
805 wxMemoryDC bitmapDC(statusIcon);
807 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
808 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
810 connBitmap->SetBitmap(statusIcon);
815 void CamuleDlg::ShowUserCount(const wxString& info)
817 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
819 // Update Kad tab
820 m_serverwnd->UpdateKadInfo();
822 label->SetLabel(info);
823 label->GetParent()->Layout();
827 void CamuleDlg::ShowTransferRate()
829 float kBpsUp = theStats::GetUploadRate() / 1024.0;
830 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
831 wxString buffer;
832 if( thePrefs::ShowOverhead() )
834 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
835 } else {
836 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
838 buffer.Truncate(50); // Max size 50
840 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
841 label->SetLabel(buffer);
842 label->GetParent()->Layout();
844 // Show upload/download speed in title
845 if (thePrefs::GetShowRatesOnTitle()) {
846 wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
847 if (thePrefs::GetShowRatesOnTitle() == 1) {
848 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
849 } else {
850 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
854 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
855 if (m_wndTaskbarNotifier) {
856 // set trayicon-icon
857 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
858 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
860 wxString buffer2;
861 if ( theApp->IsConnected() ) {
862 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
863 } else {
864 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
866 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
869 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
870 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
873 void CamuleDlg::DlgShutDown()
875 // Are we already shutting down or still on init?
876 if ( m_is_safe_state == false ) {
877 return;
880 // we are going DOWN
881 m_is_safe_state = false;
883 // Stop the GUI Timer
884 delete gui_timer;
885 m_transferwnd->downloadlistctrl->DeleteAllItems();
887 // We want to delete the systray too!
888 RemoveSystray();
891 void CamuleDlg::OnClose(wxCloseEvent& evt)
893 // This will be here till the core close is != app close
894 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
895 if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
896 wxString(_("Exit confirmation")), wxYES_NO, this)) {
897 evt.Veto();
898 return;
902 SaveGUIPrefs();
904 Enable(false);
905 Show(false);
907 theApp->ShutDown(evt);
911 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
913 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
915 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
916 wxString strlink = ctl->GetLineText(i);
917 strlink.Trim(true);
918 strlink.Trim(false);
919 if ( !strlink.IsEmpty() ) {
920 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
924 ctl->SetValue(wxEmptyString);
928 // Formerly known as LoadRazorPrefs()
929 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
931 // Create a config base for loading razor preferences
932 wxConfigBase *config = wxConfigBase::Get();
933 // If config haven't been created exit without loading
934 if (config == NULL) {
935 return false;
938 // The section where to save in in file
939 wxString section = wxT("/Razor_Preferences/");
941 // Get window size and position
942 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
943 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
944 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
945 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
947 int maximized = config->Read(section + wxT("Maximized"), 01);
949 // Kry - Random usable pos for m_srv_split_pos
950 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
951 if (!override_size) {
952 if (x2 > 0 && y2 > 0) {
953 SetSize(x2, y2);
954 } else {
955 #ifndef __WXGTK__
956 // Probably first run.
957 Maximize();
958 #endif
962 if (!override_pos) {
963 // If x1 and y1 != -1 Redefine location
964 if(x1 != -1 && y1 != -1) {
965 wxRect display = wxGetClientDisplayRect();
966 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
967 Move(x1, y1);
968 } else {
969 // It's offscreen... so let's not.
974 if (!override_size && !override_pos && maximized) {
975 Maximize();
978 return true;
982 bool CamuleDlg::SaveGUIPrefs()
984 /* Razor 1a - Modif by MikaelB
985 Save client size and position */
987 // Create a config base for saving razor preferences
988 wxConfigBase *config = wxConfigBase::Get();
989 // If config haven't been created exit without saving
990 if (config == NULL) {
991 return false;
993 // The section where to save in in file
994 wxString section = wxT("/Razor_Preferences/");
996 if (!IsIconized()) {
997 // Main window location and size
998 int x1, y1, x2, y2;
999 GetPosition(&x1, &y1);
1000 GetSize(&x2, &y2);
1002 // Saving window size and position
1003 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1004 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1006 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1007 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1009 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1012 // Saving sash position of splitter in server window
1013 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1015 config->Flush(true);
1017 /* End modif */
1019 return true;
1023 void CamuleDlg::DoIconize(bool iconize)
1025 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1026 if (iconize) {
1027 // Skip() will do it.
1028 //Iconize(true);
1029 if (SafeState()) {
1030 Show(false);
1032 } else {
1033 Show(true);
1034 Raise();
1036 } else {
1037 // Will be done by Skip();
1038 //Iconize(iconize);
1042 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1044 // Evil Hack: check if the mouse is inside the window
1045 #ifndef __WXMSW__
1046 if (GetScreenRect().Contains(wxGetMousePosition()))
1047 #endif
1049 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1050 // Veto.
1051 } else {
1052 if (m_wndTaskbarNotifier) {
1053 #if wxCHECK_VERSION(2, 9, 0)
1054 DoIconize(evt.IsIconized());
1055 #else
1056 DoIconize(evt.Iconized());
1057 #endif
1059 evt.Skip();
1064 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1066 // Former TimerProc section
1068 static uint32 msPrev1, msPrev5, msPrevStats;
1070 uint32 msCur = theStats::GetUptimeMillis();
1072 // can this actually happen under wxwin ?
1073 if (!SafeState()) {
1074 return;
1077 #ifndef CLIENT_GUI
1078 static uint32 msPrevGraph;
1079 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1080 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1081 // trying to get the graph shifts evenly spaced after a change in the update period
1082 msPrevGraph = msCur;
1084 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1086 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1087 m_kademliawnd->UpdateGraph(update);
1089 #else
1090 //#warning TODO: CORE/GUI -- EC needed
1091 #endif
1093 int sStatsUpdate = thePrefs::GetStatsInterval();
1094 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1095 if (m_statisticswnd->IsShownOnScreen()) {
1096 msPrevStats = msCur;
1097 m_statisticswnd->ShowStatistics();
1101 if (msCur-msPrev5 > 5000) { // every 5 seconds
1102 msPrev5 = msCur;
1103 ShowTransferRate();
1104 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1105 m_transferwnd->UpdateCatTabTitles();
1107 if (thePrefs::AutoSortDownload()) {
1108 m_transferwnd->downloadlistctrl->SortList();
1112 if (msCur-msPrev1 > 1000) { // every second
1113 msPrev1 = msCur;
1114 if (m_CurrentBlinkBitmap == 12) {
1115 m_CurrentBlinkBitmap = 7;
1116 SetMessagesTool();
1117 } else {
1118 if (m_BlinkMessages) {
1119 m_CurrentBlinkBitmap = 12;
1120 SetMessagesTool();
1128 void CamuleDlg::SetMessagesTool()
1130 wxWindowUpdateLocker freezer(m_wndToolbar);
1131 #ifdef __WXCOCOA__
1132 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1133 #else
1134 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1135 #endif
1138 void CamuleDlg::LaunchUrl( const wxString& url )
1140 wxString cmd;
1142 cmd = thePrefs::GetBrowser();
1143 wxString tmp = url;
1144 // Pipes cause problems, so escape them
1145 tmp.Replace( wxT("|"), wxT("%7C") );
1147 if ( !cmd.IsEmpty() ) {
1148 if (!cmd.Replace(wxT("%s"), tmp)) {
1149 // No %s found, just append the url
1150 cmd += wxT(" ") + tmp;
1153 CTerminationProcess *p = new CTerminationProcess(cmd);
1154 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1155 AddLogLineN(_("Launch Command: ") + cmd);
1156 return;
1157 } else {
1158 delete p;
1160 } else {
1161 wxLaunchDefaultBrowser(tmp);
1162 return;
1164 // Unable to execute browser. But this error message doesn't make sense,
1165 // cosidering that you _can't_ set the browser executable path... =/
1166 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1170 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1172 wxString URL;
1173 switch (wsProvider) {
1174 case WS_FILEHASH:
1175 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1176 break;
1177 default:
1178 wxFAIL;
1180 URL.Replace(wxT("FILENAME"), filename);
1182 return URL;
1186 bool CamuleDlg::Check_and_Init_Skin()
1188 bool ret = true;
1189 wxString skinFileName(thePrefs::GetSkin());
1191 if (skinFileName.IsEmpty()) {
1192 return false;
1195 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1197 wxStandardPathsBase &spb(wxStandardPaths::Get());
1198 #ifdef __WXMSW__
1199 wxString dataDir(spb.GetPluginsDir());
1200 #elif defined(__WXMAC__)
1201 wxString dataDir(spb.GetDataDir());
1202 #else
1203 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1204 #endif
1205 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1208 skinFileName.Replace(wxT("User:"), userDir );
1209 skinFileName.Replace(wxT("System:"), systemDir );
1211 m_skinFileName.Assign(skinFileName);
1212 if (!m_skinFileName.FileExists()) {
1213 AddLogLineM(true, CFormat(
1214 _("Skin directory '%s' does not exist")) %
1215 skinFileName );
1216 ret = false;
1217 } else if (!m_skinFileName.IsFileReadable()) {
1218 AddLogLineM(true, CFormat(
1219 _("WARNING: Unable to open skin file '%s' for read")) %
1220 skinFileName);
1221 ret = false;
1224 wxFFileInputStream in(m_skinFileName.GetFullPath());
1225 wxZipInputStream zip(in);
1227 while ((entry = zip.GetNextEntry()) != NULL) {
1228 wxZipEntry*& current = cat[entry->GetInternalName()];
1229 delete current;
1230 current = entry;
1233 return ret;
1237 void CamuleDlg::Add_Skin_Icon(
1238 const wxString &iconName,
1239 const wxBitmap &stdIcon,
1240 bool useSkins)
1242 wxImage new_image;
1243 if (useSkins) {
1244 wxFFileInputStream in(m_skinFileName.GetFullPath());
1245 wxZipInputStream zip(in);
1247 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1248 if ( it != cat.end() ) {
1249 zip.OpenEntry(*it->second);
1250 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1251 AddLogLineM(false,
1252 wxT("Warning: Error loading icon for ") +
1253 iconName);
1254 useSkins = false;
1256 }else {
1257 AddLogLineM(false,
1258 wxT("Warning: Can't load icon for ") +
1259 iconName);
1260 useSkins = false;
1265 wxBitmap bmp(useSkins ? new_image : stdIcon);
1266 if (iconName.StartsWith(wxT("Client_"))) {
1267 m_imagelist.Add(bmp);
1268 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1269 m_tblist.Add(bmp);
1274 void CamuleDlg::Apply_Clients_Skin()
1276 bool useSkins = Check_and_Init_Skin();
1278 // Clear the client image list
1279 m_imagelist.RemoveAll();
1281 // Add the images to the image list
1282 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1283 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1284 clientImages(i), useSkins);
1289 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1291 bool useSkins = Check_and_Init_Skin();
1294 // Clear the toolbar image list
1295 m_tblist.RemoveAll();
1297 // Add the images to the image list
1298 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1299 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1300 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1301 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1302 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1303 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1304 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1305 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1306 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1307 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1312 // Build aMule toolbar
1313 wndToolbar->SetMargins(0, 0);
1315 // Placeholder. Gets updated by ShowConnectionState
1316 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1318 wndToolbar->AddSeparator();
1319 wndToolbar->AddTool(ID_BUTTONNETWORKS,
1320 _("Networks"), m_tblist.GetBitmap(3),
1321 wxNullBitmap, wxITEM_CHECK,
1322 _("Networks window"));
1323 wndToolbar->AddTool(ID_BUTTONSEARCH,
1324 _("Searches"), m_tblist.GetBitmap(5),
1325 wxNullBitmap, wxITEM_CHECK,
1326 _("Searches window"));
1327 wndToolbar->AddTool(ID_BUTTONTRANSFER,
1328 _("Transfers"), m_tblist.GetBitmap(4),
1329 wxNullBitmap, wxITEM_CHECK,
1330 _("Files transfers window"));
1331 wndToolbar->AddTool(ID_BUTTONSHARED,
1332 _("Shared files"), m_tblist.GetBitmap(6),
1333 wxNullBitmap, wxITEM_CHECK,
1334 _("Shared files window"));
1335 wndToolbar->AddTool(ID_BUTTONMESSAGES,
1336 _("Messages"), m_tblist.GetBitmap(7),
1337 wxNullBitmap, wxITEM_CHECK,
1338 _("Messages window"));
1339 wndToolbar->AddTool(ID_BUTTONSTATISTICS,
1340 _("Statistics"), m_tblist.GetBitmap(8),
1341 wxNullBitmap, wxITEM_CHECK,
1342 _("Statistics graph window"));
1343 wndToolbar->AddSeparator();
1344 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES,
1345 _("Preferences"), m_tblist.GetBitmap(9),
1346 wxNullBitmap, wxITEM_NORMAL,
1347 _("Preferences settings window"));
1348 wndToolbar->AddTool(ID_BUTTONIMPORT,
1349 _("Import"), m_tblist.GetBitmap(10),
1350 wxNullBitmap, wxITEM_NORMAL,
1351 _("The partfile importer tool"));
1352 wndToolbar->AddTool(ID_ABOUT,
1353 _("About"), m_tblist.GetBitmap(11),
1354 wxNullBitmap, wxITEM_NORMAL,
1355 _("About/Help"));
1357 wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true);
1359 // Needed for non-GTK platforms, where the
1360 // items don't get added immediatly.
1361 wndToolbar->Realize();
1363 // Updates the "Connect" button, and so on.
1364 ShowConnectionState(true);
1368 void CamuleDlg::Create_Toolbar(bool orientation)
1370 Freeze();
1371 // Create ToolBar from the one designed by wxDesigner (BigBob)
1372 wxToolBar *current = GetToolBar();
1374 wxASSERT(current == m_wndToolbar);
1376 if (current) {
1377 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1378 if (oldorientation != orientation) {
1379 current->Destroy();
1380 SetToolBar(NULL); // Remove old one if present
1381 m_wndToolbar = NULL;
1382 } else {
1383 current->ClearTools();
1387 if (!m_wndToolbar) {
1388 m_wndToolbar = CreateToolBar(
1389 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1390 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1391 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1394 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1397 Apply_Toolbar_Skin(m_wndToolbar);
1399 Thaw();
1403 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1405 wxFrame::OnSize(evt);
1406 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1407 // Transfer window's splitter set again if it's hidden.
1408 if (m_transferwnd->clientlistctrl->GetListView() == vtNone) {
1409 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1410 wxSplitterWindow* splitter =
1411 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1412 height += splitter->GetWindow1()->GetSize().GetHeight();
1413 splitter->SetSashPosition( height );
1420 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1422 if (event.GetKeyCode() == WXK_F1) {
1423 // Ctrl/Alt/Shift must not be pressed, to avoid
1424 // conflicts with other (global) shortcuts.
1425 if (!event.HasModifiers() && !event.ShiftDown()) {
1426 LaunchUrl(wxT("http://wiki.amule.org"));
1427 return;
1431 event.Skip();
1435 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1437 Close();
1440 void CamuleDlg::DoNetworkRearrange()
1443 wxWindowUpdateLocker freezer(this);
1445 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1447 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1448 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1450 while (logs_notebook->GetPageCount() > 1) {
1451 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1454 while (networks_notebook->GetPageCount() > 0) {
1455 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1458 if (thePrefs::GetNetworkED2K()) {
1459 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1460 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1463 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1465 if (thePrefs::GetNetworkKademlia()) {
1466 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1469 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1471 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1473 wxWindow* replacement = NULL;
1475 m_networknotebooksizer->Clear();
1477 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1478 toolbarTool->SetLabel(_("Networks"));
1480 m_networkpages[0].page->Reparent(networks_notebook);
1481 m_networkpages[1].page->Reparent(networks_notebook);
1483 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1484 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1486 replacement = networks_notebook;
1488 } else if (thePrefs::GetNetworkED2K()) {
1489 toolbarTool->SetLabel(_("eD2k network"));
1490 replacement = m_networkpages[0].page;
1491 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1492 } else if (thePrefs::GetNetworkKademlia()) {
1493 toolbarTool->SetLabel(_("Kad network"));
1494 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1495 replacement = m_networkpages[1].page;
1496 } else {
1497 // No networks.
1498 toolbarTool->SetLabel(_("No network"));
1501 if (replacement) {
1502 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1503 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1504 m_networknotebooksizer->Layout();
1507 m_wndToolbar->InsertTool(2, toolbarTool);
1509 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1510 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1512 m_wndToolbar->Realize();
1514 m_searchwnd->FixSearchTypes();
1517 // File_checked_for_headers