Don't try loading the "- default -" skin from the skins directory.
[amule.git] / src / amuleDlg.cpp
blob99e6669b22fa844f56403d21a3fb0c6b48e0c507
2 //
3 // This file is part of the aMule Project.
4 //
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 //
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include <wx/app.h>
29 #include <wx/archive.h>
30 #include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
31 #include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
32 #include <wx/html/htmlwin.h>
33 #include <wx/mimetype.h> // Do_not_auto_remove (win32)
34 #include <wx/stattext.h>
35 #include <wx/stdpaths.h>
36 #include <wx/textfile.h> // Do_not_auto_remove (win32)
37 #include <wx/tokenzr.h>
38 #include <wx/wfstream.h>
39 #include <wx/zipstrm.h>
40 #include <wx/sysopt.h>
41 #include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker
43 #include <common/EventIDs.h>
45 #ifdef HAVE_CONFIG_H
46 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
47 #else
48 #include <common/ClientVersion.h>
49 #endif // HAVE_CONFIG_H
51 #include "amuleDlg.h" // Interface declarations.
53 #include <common/Format.h> // Needed for CFormat
54 #include "amule.h" // Needed for theApp
55 #include "ChatWnd.h" // Needed for CChatWnd
56 #include "SourceListCtrl.h" // Needed for CSourceListCtrl
57 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
58 #include "DownloadQueue.h" // Needed for CDownloadQueue
59 #include "KadDlg.h" // Needed for CKadDlg
60 #include "Logger.h"
61 #include "MuleTrayIcon.h"
62 #include "muuli_wdr.h" // Needed for ID_BUTTON*
63 #include "Preferences.h" // Needed for CPreferences
64 #include "PrefsUnifiedDlg.h"
65 #include "SearchDlg.h" // Needed for CSearchDlg
66 #include "Server.h" // Needed for CServer
67 #include "ServerConnect.h" // Needed for CServerConnect
68 #include "ServerWnd.h" // Needed for CServerWnd
69 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
70 #include "SharedFilePeersListCtrl.h" // Needed for CSharedFilePeersListCtrl
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 "PartFileConvertDlg.h"
77 #endif
78 #include "IPFilter.h"
80 #ifndef __WXMSW__
81 #include "aMule.xpm"
82 #endif
84 #include "kademlia/kademlia/Kademlia.h"
86 #ifdef ENABLE_IP2COUNTRY
87 #include "IP2Country.h" // Needed for IP2Country
88 #endif
90 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
91 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
92 void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
94 m_IP2Country->DownloadFinished(result);
97 void CamuleDlg::EnableIP2Country()
99 if (thePrefs::IsGeoIPEnabled()) {
100 m_IP2Country->Enable();
104 #else
106 void CamuleDlg::IP2CountryDownloadFinished(uint32){}
107 void CamuleDlg::EnableIP2Country(){}
109 #endif
111 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
113 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
114 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
115 EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)
116 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
117 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
118 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
119 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
121 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
122 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
124 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
126 EVT_CLOSE(CamuleDlg::OnClose)
127 EVT_ICONIZE(CamuleDlg::OnMinimize)
129 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
131 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
133 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
135 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
137 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
139 END_EVENT_TABLE()
141 #ifndef wxCLOSE_BOX
142 #define wxCLOSE_BOX 0
143 #endif
145 CamuleDlg::CamuleDlg(
146 wxWindow* pParent,
147 const wxString &title,
148 wxPoint where,
149 wxSize dlg_size)
151 wxFrame(
152 pParent, -1, title, where, dlg_size,
153 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
154 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
155 wxT("aMule")),
156 m_activewnd(NULL),
157 m_transferwnd(NULL),
158 m_serverwnd(NULL),
159 m_sharedfileswnd(NULL),
160 m_searchwnd(NULL),
161 m_chatwnd(NULL),
162 m_statisticswnd(NULL),
163 m_kademliawnd(NULL),
164 m_prefsDialog(NULL),
165 m_srv_split_pos(0),
166 m_imagelist(16,16),
167 m_tblist(32,32),
168 m_prefsVisible(false),
169 m_wndToolbar(NULL),
170 m_wndTaskbarNotifier(NULL),
171 m_nActiveDialog(DT_NETWORKS_WND),
172 m_is_safe_state(false),
173 m_BlinkMessages(false),
174 m_CurrentBlinkBitmap(24),
175 m_last_iconizing(0),
176 m_skinFileName(),
177 m_clientSkinNames(CLIENT_SKIN_SIZE)
179 // Initialize skin names
180 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
181 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
182 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
183 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
184 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
185 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
186 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
187 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
188 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
189 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
190 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
191 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
192 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
193 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
194 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
195 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
196 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
197 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
198 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
199 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
200 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
201 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
202 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
203 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
204 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
205 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
206 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
208 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
209 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
210 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
211 wxInitAllImageHandlers();
212 Apply_Clients_Skin();
214 #ifdef __WXMSW__
215 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
216 #endif
218 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
219 // this crashes on Mac with wx 2.9
220 SetIcon(wxICON(aMule));
221 #endif
223 srand(time(NULL));
225 // Create new sizer and stuff a wxPanel in there.
226 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
227 s_main->AddGrowableCol(0);
228 s_main->AddGrowableRow(0);
230 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
231 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
232 muleDlg(p_cnt, false, true);
233 SetSizer(s_main, true);
235 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
236 AddLogLineN(wxEmptyString);
237 AddLogLineN(wxT(" - ") +
238 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
239 AddLogLineN(wxT(" ") +
240 CFormat(_("Running on %s")) % wxGetOsDescription());
241 AddLogLineN(wxT(" - ") +
242 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
243 AddLogLineN(wxEmptyString);
245 #ifdef ENABLE_IP2COUNTRY
246 m_GeoIPavailable = true;
247 m_IP2Country = new CIP2Country(theApp->ConfigDir);
248 #else
249 m_GeoIPavailable = false;
250 #endif
251 m_searchwnd = new CSearchDlg(p_cnt);
252 m_transferwnd = new CTransferWnd(p_cnt);
253 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
254 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
255 m_chatwnd = new CChatWnd(p_cnt);
256 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
258 m_serverwnd->Show(false);
259 m_searchwnd->Show(false);
260 m_transferwnd->Show(false);
261 m_sharedfileswnd->Show(false);
262 m_statisticswnd->Show(false);
263 m_chatwnd->Show(false);
265 // Create the GUI timer
266 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
267 if (!gui_timer) {
268 AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
269 exit(1);
272 // Set transfers as active window
273 Create_Toolbar(thePrefs::VerticalToolbar());
274 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
275 m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true );
277 bool override_where = (where != wxDefaultPosition);
278 bool override_size = (
279 (dlg_size.x != DEFAULT_SIZE_X) ||
280 (dlg_size.y != DEFAULT_SIZE_Y) );
281 if (!LoadGUIPrefs(override_where, override_size)) {
282 // Prefs not loaded for some reason, exit
283 AddLogLineC(wxT("Error! Unable to load Preferences") );
284 return;
287 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
288 m_transferwnd->Prepare();
290 m_is_safe_state = true;
292 // Init statistics stuff, better do it asap
293 m_statisticswnd->Init();
294 m_kademliawnd->Init();
295 m_searchwnd->UpdateCatChoice();
296 if (thePrefs::UseTrayIcon()) {
297 CreateSystray();
300 Show(true);
301 // Must we start minimized?
302 if (thePrefs::GetStartMinimized()) {
303 DoIconize(true);
306 // Set shortcut keys
307 wxAcceleratorEntry entries[] = {
308 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
311 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
312 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
314 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
315 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
317 wxASSERT(logs_notebook->GetPageCount() == 4);
318 wxASSERT(networks_notebook->GetPageCount() == 2);
320 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
321 m_logpages[i].page = logs_notebook->GetPage(i);
322 m_logpages[i].name = logs_notebook->GetPageText(i);
325 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
326 m_networkpages[i].page = networks_notebook->GetPage(i);
327 m_networkpages[i].name = networks_notebook->GetPageText(i);
330 DoNetworkRearrange();
334 // Madcat - Sets Fast ED2K Links Handler on/off.
335 void CamuleDlg::ShowED2KLinksHandler( bool show )
337 // Errorchecking in case the pointer becomes invalid ...
338 if (s_fed2klh == NULL) {
339 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
340 return;
343 s_dlgcnt->Show( s_fed2klh, show );
344 s_dlgcnt->Layout();
347 // Toogles ed2k link handler.
348 void CamuleDlg::ToogleED2KLinksHandler()
350 // Errorchecking in case the pointer becomes invalid ...
351 if (s_fed2klh == NULL) {
352 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
353 return;
355 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
358 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
360 m_nActiveDialog = type;
362 if ( type == DT_TRANSFER_WND ) {
363 if (thePrefs::ShowCatTabInfos()) {
364 m_transferwnd->UpdateCatTabTitles();
368 if ( m_activewnd ) {
369 m_activewnd->Show(false);
370 contentSizer->Detach(m_activewnd);
373 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
374 dlg->Show(true);
375 m_activewnd=dlg;
376 s_dlgcnt->Layout();
378 // Since we might be suspending redrawing while hiding the dialog
379 // we have to refresh it once it is visible again
380 dlg->Refresh( true );
381 dlg->SetFocus();
383 if ( type == DT_SHARED_WND ) {
384 // set up splitter now that window sizes are defined
385 m_sharedfileswnd->Prepare();
390 void CamuleDlg::UpdateTrayIcon(int percent)
392 // set trayicon-icon
393 if(!theApp->IsConnected()) {
394 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
395 } else {
396 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
397 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
398 } else {
399 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
405 void CamuleDlg::CreateSystray()
407 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
408 wxT("Systray already created"));
410 m_wndTaskbarNotifier = new CMuleTrayIcon();
411 // This will effectively show the Tray Icon.
412 UpdateTrayIcon(0);
416 void CamuleDlg::RemoveSystray()
418 delete m_wndTaskbarNotifier;
419 m_wndTaskbarNotifier = NULL;
423 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
425 static int lastbutton = ID_BUTTONDOWNLOADS;
427 // Kry - just if the GUI is ready for it
428 if ( m_is_safe_state ) {
430 // Rehide the handler if needed
431 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
432 if (ev.GetId() != ID_BUTTONSEARCH) {
433 ShowED2KLinksHandler( false );
434 } else {
435 // Toogle ED2K handler.
436 ToogleED2KLinksHandler();
440 if ( lastbutton != ev.GetId() ) {
441 switch ( ev.GetId() ) {
442 case ID_BUTTONNETWORKS:
443 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
444 // Set serverlist splitter position
445 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
446 break;
448 case ID_BUTTONSEARCH:
449 // The search dialog should always display the handler
450 if ( !thePrefs::GetFED2KLH() )
451 ShowED2KLinksHandler( true );
453 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
454 break;
456 case ID_BUTTONDOWNLOADS:
457 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
458 // Prepare the dialog, sets the splitter-position
459 m_transferwnd->Prepare();
460 break;
462 case ID_BUTTONSHARED:
463 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
464 break;
466 case ID_BUTTONMESSAGES:
467 m_BlinkMessages = false;
468 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
469 break;
471 case ID_BUTTONSTATISTICS:
472 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
473 break;
475 // This shouldn't happen, but just in case
476 default:
477 AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
478 break;
482 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
483 lastbutton = ev.GetId();
488 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
490 wxString msg = wxT(" ");
491 #ifdef CLIENT_GUI
492 msg << _("aMule remote control ") << wxT(VERSION);
493 #else
494 msg << wxT("aMule ") << wxT(VERSION);
495 #endif
496 msg << wxT(" ");
497 #ifdef SVNDATE
498 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
499 #endif
500 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
501 _("Website: http://www.amule.org \n") <<
502 _("Forum: http://forum.amule.org \n") <<
503 _("FAQ: http://wiki.amule.org \n\n") <<
504 _("Contact: admin@amule.org (administrative issues) \n") <<
505 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
506 _("Part of aMule is based on \n") <<
507 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
508 _(" Copyright (c) 2002-2008 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
509 _("http://kademlia.scs.cs.nyu.edu\n");
511 if (m_is_safe_state) {
512 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
517 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
519 if (m_is_safe_state) {
520 if (m_prefsDialog == NULL) {
521 m_prefsDialog = new PrefsUnifiedDlg(this);
524 m_prefsDialog->TransferToWindow();
525 m_prefsDialog->Show(true);
526 m_prefsDialog->Raise();
531 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
533 #ifndef CLIENT_GUI
534 if (m_is_safe_state) {
535 CPartFileConvertDlg::ShowGUI(NULL);
537 #endif
541 CamuleDlg::~CamuleDlg()
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 #ifdef CLIENT_GUI
558 || theApp->IsConnectedKad() // there's no Kad running state atm
559 #else
560 || (Kademlia::CKademlia::IsRunning())
561 #endif
563 if (thePrefs::GetNetworkED2K()) {
564 if (disconnect) {
565 //disconnect if currently connected
566 if (theApp->serverconnect->IsConnecting()) {
567 theApp->serverconnect->StopConnectionTry();
568 } else {
569 theApp->serverconnect->Disconnect();
571 } else {
572 //connect if not currently connected
573 AddLogLineC(_("Connecting"));
574 theApp->serverconnect->ConnectToAnyServer();
576 } else {
577 wxASSERT(!theApp->IsConnectedED2K());
580 // Connect Kad also
581 if (thePrefs::GetNetworkKademlia()) {
582 if( disconnect ) {
583 theApp->StopKad();
584 } else {
585 theApp->StartKad();
587 } else {
588 #ifndef CLIENT_GUI
589 wxASSERT(!Kademlia::CKademlia::IsRunning());
590 #endif
593 ShowConnectionState();
597 void CamuleDlg::ResetLog(int id)
599 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
600 wxCHECK_RET(ct, wxT("Resetting unknown log"));
602 ct->Clear();
604 if (id == ID_LOGVIEW) {
605 // Also clear the log line
606 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
607 text->SetLabel(wxEmptyString);
608 text->GetParent()->Layout();
613 void CamuleDlg::AddLogLine(const wxString& line)
615 bool addtostatusbar = line[0] == '!';
616 wxString bufferline = line.Mid(1);
618 // Add the message to the log-view
619 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
620 if ( ct ) {
621 // Bold critical log-lines
622 // Works in Windows too thanks to wxTE_RICH2 style in muuli
623 wxTextAttr style = ct->GetDefaultStyle();
624 wxFont font = style.GetFont();
625 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
626 style.SetFont(font);
627 #if wxCHECK_VERSION(2, 9, 0)
628 style.SetFontSize(8);
629 #endif
630 ct->SetDefaultStyle(style);
631 ct->AppendText(bufferline);
632 ct->ShowPosition( ct->GetLastPosition() - 1 );
636 // Set the status-bar if the event warrents it
637 if ( addtostatusbar ) {
638 // Escape "&"s, which would otherwise not show up
639 bufferline.Replace( wxT("&"), wxT("&&") );
640 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
641 // Only show the first line if multiple lines
642 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
643 text->SetToolTip( bufferline );
644 text->GetParent()->Layout();
650 void CamuleDlg::AddServerMessageLine(wxString& message)
652 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
653 if(cv) {
654 if (message.Length() > 500) {
655 cv->AppendText(message.Left(500) + wxT("\n"));
656 } else {
657 cv->AppendText(message + wxT("\n"));
659 cv->ShowPosition(cv->GetLastPosition()-1);
664 void CamuleDlg::ShowConnectionState(bool skinChanged)
666 static wxImageList status_arrows(16,16,true,0);
667 if (!status_arrows.GetImageCount()) {
668 // Generate the image list (This is only done once)
669 for (int t = 0; t < 7; ++t) {
670 status_arrows.Add(connImages(t));
674 m_serverwnd->UpdateED2KInfo();
675 m_serverwnd->UpdateKadInfo();
678 ////////////////////////////////////////////////////////////
679 // Determine the status of the networks
681 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
682 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
684 ED2KState ed2kState = ED2KOff;
685 EKadState kadState = EKadOff;
687 ////////////////////////////////////////////////////////////
688 // Update the label on the status-bar and determine
689 // the states of the two networks.
691 wxString msgED2K;
692 if (theApp->IsConnectedED2K()) {
693 CServer* server = theApp->serverconnect->GetCurrentServer();
694 if (server) {
695 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
698 if (theApp->serverconnect->IsLowID()) {
699 ed2kState = ED2KLowID;
700 } else {
701 ed2kState = ED2KHighID;
703 } else if (theApp->serverconnect->IsConnecting()) {
704 msgED2K = _("eD2k: Connecting");
706 ed2kState = ED2KConnecting;
707 } else if (thePrefs::GetNetworkED2K()) {
708 msgED2K = _("eD2k: Disconnected");
711 wxString msgKad;
712 if (theApp->IsConnectedKad()) {
713 if (theApp->IsFirewalledKad()) {
714 msgKad = _("Kad: Firewalled");
716 kadState = EKadFW;
717 } else {
718 msgKad = _("Kad: Connected");
720 kadState = EKadOK;
722 } else if (theApp->IsKadRunning()) {
723 msgKad = _("Kad: Connecting");
725 kadState = EKadConnecting;
726 } else if (thePrefs::GetNetworkKademlia()) {
727 msgKad = _("Kad: Off");
730 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
731 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
733 wxString labelMsg;
734 if (msgED2K.Length() && msgKad.Length()) {
735 labelMsg = msgED2K + wxT(" | ") + msgKad;
736 } else {
737 labelMsg = msgED2K + msgKad;
740 connLabel->SetLabel(labelMsg);
741 connLabel->GetParent()->Layout();
744 ////////////////////////////////////////////////////////////
745 // Update the connect/disconnect/cancel button.
747 enum EConnState {
748 ECS_Unknown,
749 ECS_Connected,
750 ECS_Connecting,
751 ECS_Disconnected
754 static EConnState s_oldState = ECS_Unknown;
755 EConnState currentState = ECS_Disconnected;
757 if (theApp->serverconnect->IsConnecting() ||
758 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
759 currentState = ECS_Connecting;
760 } else if (theApp->IsConnected()) {
761 currentState = ECS_Connected;
762 } else {
763 currentState = ECS_Disconnected;
766 if ( (true == skinChanged) || (currentState != s_oldState) ) {
767 wxWindowUpdateLocker freezer(m_wndToolbar);
769 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
771 switch (currentState) {
772 case ECS_Connecting:
773 toolbarTool->SetLabel(_("Cancel"));
774 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
775 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
776 break;
778 case ECS_Connected:
779 toolbarTool->SetLabel(_("Disconnect"));
780 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
781 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
782 break;
784 default:
785 toolbarTool->SetLabel(_("Connect"));
786 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
787 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
790 m_wndToolbar->InsertTool(0, toolbarTool);
791 m_wndToolbar->Realize();
792 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
794 s_oldState = currentState;
798 ////////////////////////////////////////////////////////////
799 // Update the globe-icon in the lower-right corner.
800 // (only if connection state has changed)
802 static ED2KState s_ED2KOldState = ED2KUndef;
803 static EKadState s_EKadOldState = EKadUndef;
804 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
805 s_ED2KOldState = ed2kState;
806 s_EKadOldState = kadState;
807 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
808 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
810 wxBitmap statusIcon = connBitmap->GetBitmap();
811 // Sanity check - otherwise there's a crash here if aMule runs out of resources
812 if (statusIcon.GetRefData() == NULL) {
813 return;
816 wxMemoryDC bitmapDC(statusIcon);
818 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
819 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
821 connBitmap->SetBitmap(statusIcon);
826 void CamuleDlg::ShowUserCount(const wxString& info)
828 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
830 // Update Kad tab
831 m_serverwnd->UpdateKadInfo();
833 label->SetLabel(info);
834 label->GetParent()->Layout();
838 void CamuleDlg::ShowTransferRate()
840 float kBpsUp = theStats::GetUploadRate() / 1024.0;
841 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
842 wxString buffer;
843 if( thePrefs::ShowOverhead() )
845 buffer = CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp % (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown % (theStats::GetDownOverheadRate() / 1024.0);
846 } else {
847 buffer = CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
849 buffer.Truncate(50); // Max size 50
851 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
852 label->SetLabel(buffer);
853 label->GetParent()->Layout();
855 // Show upload/download speed in title
856 if (thePrefs::GetShowRatesOnTitle()) {
857 wxString UpDownSpeed = CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown;
858 if (thePrefs::GetShowRatesOnTitle() == 1) {
859 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
860 } else {
861 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
865 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
866 if (m_wndTaskbarNotifier) {
867 // set trayicon-icon
868 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
869 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
871 wxString buffer2;
872 if ( theApp->IsConnected() ) {
873 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
874 } else {
875 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
877 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
880 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
881 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
884 void CamuleDlg::DlgShutDown()
886 // Are we already shutting down or still on init?
887 if ( m_is_safe_state == false ) {
888 return;
891 // we are going DOWN
892 m_is_safe_state = false;
894 // Stop the GUI Timer
895 delete gui_timer;
896 m_transferwnd->downloadlistctrl->DeleteAllItems();
898 // We want to delete the systray too!
899 RemoveSystray();
902 void CamuleDlg::OnClose(wxCloseEvent& evt)
904 // This will be here till the core close is != app close
905 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
906 if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
907 wxString(_("Exit confirmation")), wxYES_NO, this)) {
908 evt.Veto();
909 return;
913 SaveGUIPrefs();
915 Enable(false);
916 Show(false);
918 theApp->ShutDown(evt);
922 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
924 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
926 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
927 wxString strlink = ctl->GetLineText(i);
928 strlink.Trim(true);
929 strlink.Trim(false);
930 if ( !strlink.IsEmpty() ) {
931 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
935 ctl->SetValue(wxEmptyString);
939 // Formerly known as LoadRazorPrefs()
940 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
942 // Create a config base for loading razor preferences
943 wxConfigBase *config = wxConfigBase::Get();
944 // If config haven't been created exit without loading
945 if (config == NULL) {
946 return false;
949 // The section where to save in in file
950 wxString section = wxT("/Razor_Preferences/");
952 // Get window size and position
953 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
954 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
955 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
956 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
958 int maximized = config->Read(section + wxT("Maximized"), 01);
960 // Kry - Random usable pos for m_srv_split_pos
961 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
962 if (!override_size) {
963 if (x2 > 0 && y2 > 0) {
964 SetSize(x2, y2);
965 } else {
966 #ifndef __WXGTK__
967 // Probably first run.
968 Maximize();
969 #endif
973 if (!override_pos) {
974 // If x1 and y1 != -1 Redefine location
975 if(x1 != -1 && y1 != -1) {
976 wxRect display = wxGetClientDisplayRect();
977 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
978 Move(x1, y1);
979 } else {
980 // It's offscreen... so let's not.
985 if (!override_size && !override_pos && maximized) {
986 Maximize();
989 return true;
993 bool CamuleDlg::SaveGUIPrefs()
995 /* Razor 1a - Modif by MikaelB
996 Save client size and position */
998 // Create a config base for saving razor preferences
999 wxConfigBase *config = wxConfigBase::Get();
1000 // If config haven't been created exit without saving
1001 if (config == NULL) {
1002 return false;
1004 // The section where to save in in file
1005 wxString section = wxT("/Razor_Preferences/");
1007 if (!IsIconized()) {
1008 // Main window location and size
1009 int x1, y1, x2, y2;
1010 GetPosition(&x1, &y1);
1011 GetSize(&x2, &y2);
1013 // Saving window size and position
1014 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
1015 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
1017 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
1018 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
1020 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1023 // Saving sash position of splitter in server window
1024 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1026 config->Flush(true);
1028 /* End modif */
1030 return true;
1034 void CamuleDlg::DoIconize(bool iconize)
1036 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1037 if (iconize) {
1038 // Skip() will do it.
1039 //Iconize(true);
1040 if (SafeState()) {
1041 Show(false);
1043 } else {
1044 Show(true);
1045 Raise();
1047 } else {
1048 // Will be done by Skip();
1049 //Iconize(iconize);
1053 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1055 // Evil Hack: check if the mouse is inside the window
1056 #ifndef __WXMSW__
1057 if (GetScreenRect().Contains(wxGetMousePosition()))
1058 #endif
1060 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1061 // Veto.
1062 } else {
1063 if (m_wndTaskbarNotifier) {
1064 #if wxCHECK_VERSION(2, 9, 0)
1065 DoIconize(evt.IsIconized());
1066 #else
1067 DoIconize(evt.Iconized());
1068 #endif
1070 evt.Skip();
1075 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1077 // Former TimerProc section
1079 static uint32 msPrev1, msPrev5;
1081 uint32 msCur = theStats::GetUptimeMillis();
1083 // can this actually happen under wxwin ?
1084 if (!SafeState()) {
1085 return;
1088 #ifndef CLIENT_GUI
1089 static uint32 msPrevGraph, msPrevStats;
1090 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1091 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1092 // trying to get the graph shifts evenly spaced after a change in the update period
1093 msPrevGraph = msCur;
1095 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1097 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1098 m_kademliawnd->UpdateGraph(update);
1101 int sStatsUpdate = thePrefs::GetStatsInterval();
1102 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1103 if (m_statisticswnd->IsShownOnScreen()) {
1104 msPrevStats = msCur;
1105 m_statisticswnd->ShowStatistics();
1108 #endif
1110 if (msCur-msPrev5 > 5000) { // every 5 seconds
1111 msPrev5 = msCur;
1112 ShowTransferRate();
1113 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1114 m_transferwnd->UpdateCatTabTitles();
1116 if (thePrefs::AutoSortDownload()) {
1117 m_transferwnd->downloadlistctrl->SortList();
1118 m_transferwnd->clientlistctrl->SortList();
1119 m_sharedfileswnd->peerslistctrl->SortList();
1123 if (msCur-msPrev1 > 1000) { // every second
1124 msPrev1 = msCur;
1125 if (m_CurrentBlinkBitmap == 12) {
1126 m_CurrentBlinkBitmap = 7;
1127 SetMessagesTool();
1128 } else {
1129 if (m_BlinkMessages) {
1130 m_CurrentBlinkBitmap = 12;
1131 SetMessagesTool();
1139 void CamuleDlg::SetMessagesTool()
1141 wxWindowUpdateLocker freezer(m_wndToolbar);
1142 #ifdef __WXCOCOA__
1143 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1144 #else
1145 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1146 #endif
1149 void CamuleDlg::LaunchUrl( const wxString& url )
1151 wxString cmd;
1153 cmd = thePrefs::GetBrowser();
1154 wxString tmp = url;
1155 // Pipes cause problems, so escape them
1156 tmp.Replace( wxT("|"), wxT("%7C") );
1158 if ( !cmd.IsEmpty() ) {
1159 if (!cmd.Replace(wxT("%s"), tmp)) {
1160 // No %s found, just append the url
1161 cmd += wxT(" ") + tmp;
1164 CTerminationProcess *p = new CTerminationProcess(cmd);
1165 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1166 AddLogLineN(_("Launch Command: ") + cmd);
1167 return;
1168 } else {
1169 delete p;
1171 } else {
1172 wxLaunchDefaultBrowser(tmp);
1173 return;
1175 // Unable to execute browser. But this error message doesn't make sense,
1176 // cosidering that you _can't_ set the browser executable path... =/
1177 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1181 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1183 wxString URL;
1184 switch (wsProvider) {
1185 case WS_FILEHASH:
1186 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1187 break;
1188 default:
1189 wxFAIL;
1191 URL.Replace(wxT("FILENAME"), filename);
1193 return URL;
1197 bool CamuleDlg::Check_and_Init_Skin()
1199 bool ret = true;
1200 wxString skinFileName(thePrefs::GetSkin());
1202 if (skinFileName.IsEmpty() || skinFileName.IsSameAs(_("- default -"))) {
1203 return false;
1206 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1208 wxStandardPathsBase &spb(wxStandardPaths::Get());
1209 #ifdef __WXMSW__
1210 wxString dataDir(spb.GetPluginsDir());
1211 #elif defined(__WXMAC__)
1212 wxString dataDir(spb.GetDataDir());
1213 #else
1214 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1215 #endif
1216 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1219 skinFileName.Replace(wxT("User:"), userDir );
1220 skinFileName.Replace(wxT("System:"), systemDir );
1222 m_skinFileName.Assign(skinFileName);
1223 if (!m_skinFileName.FileExists()) {
1224 AddLogLineC(CFormat(
1225 _("Skin directory '%s' does not exist")) %
1226 skinFileName );
1227 ret = false;
1228 } else if (!m_skinFileName.IsFileReadable()) {
1229 AddLogLineC(CFormat(
1230 _("WARNING: Unable to open skin file '%s' for read")) %
1231 skinFileName);
1232 ret = false;
1235 wxFFileInputStream in(m_skinFileName.GetFullPath());
1236 wxZipInputStream zip(in);
1238 while ((entry = zip.GetNextEntry()) != NULL) {
1239 wxZipEntry*& current = cat[entry->GetInternalName()];
1240 delete current;
1241 current = entry;
1244 return ret;
1248 void CamuleDlg::Add_Skin_Icon(
1249 const wxString &iconName,
1250 const wxBitmap &stdIcon,
1251 bool useSkins)
1253 wxImage new_image;
1254 if (useSkins) {
1255 wxFFileInputStream in(m_skinFileName.GetFullPath());
1256 wxZipInputStream zip(in);
1258 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1259 if ( it != cat.end() ) {
1260 zip.OpenEntry(*it->second);
1261 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1262 AddLogLineN(wxT("Warning: Error loading icon for ") +
1263 iconName);
1264 useSkins = false;
1266 }else {
1267 AddLogLineN(wxT("Warning: Can't load icon for ") +
1268 iconName);
1269 useSkins = false;
1274 wxBitmap bmp(useSkins ? new_image : stdIcon);
1275 if (iconName.StartsWith(wxT("Client_"))) {
1276 m_imagelist.Add(bmp);
1277 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1278 m_tblist.Add(bmp);
1283 void CamuleDlg::Apply_Clients_Skin()
1285 bool useSkins = Check_and_Init_Skin();
1287 // Clear the client image list
1288 m_imagelist.RemoveAll();
1290 // Add the images to the image list
1291 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1292 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1293 clientImages(i), useSkins);
1298 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1300 bool useSkins = Check_and_Init_Skin();
1303 // Clear the toolbar image list
1304 m_tblist.RemoveAll();
1306 // Add the images to the image list
1307 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1308 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1309 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1310 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1311 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1312 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1313 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1314 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1315 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1316 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1317 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1318 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1319 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1321 // Build aMule toolbar
1322 wndToolbar->SetMargins(0, 0);
1324 // Placeholder. Gets updated by ShowConnectionState
1325 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1327 wndToolbar->AddSeparator();
1328 wndToolbar->AddTool(ID_BUTTONNETWORKS, _("Networks"), m_tblist.GetBitmap(3), wxNullBitmap, wxITEM_CHECK, _("Networks Window"));
1329 wndToolbar->AddTool(ID_BUTTONSEARCH, _("Searches"), m_tblist.GetBitmap(5), wxNullBitmap, wxITEM_CHECK, _("Searches Window"));
1330 wndToolbar->AddTool(ID_BUTTONDOWNLOADS, _("Downloads"), m_tblist.GetBitmap(4), wxNullBitmap, wxITEM_CHECK, _("Downloads Window"));
1331 wndToolbar->AddTool(ID_BUTTONSHARED, _("Shared files"), m_tblist.GetBitmap(6), wxNullBitmap, wxITEM_CHECK, _("Shared Files Window"));
1332 wndToolbar->AddTool(ID_BUTTONMESSAGES, _("Messages"), m_tblist.GetBitmap(7), wxNullBitmap, wxITEM_CHECK, _("Messages Window"));
1333 wndToolbar->AddTool(ID_BUTTONSTATISTICS, _("Statistics"), m_tblist.GetBitmap(8), wxNullBitmap, wxITEM_CHECK, _("Statistics Graph Window"));
1334 wndToolbar->AddSeparator();
1335 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES, _("Preferences"), m_tblist.GetBitmap(9), wxNullBitmap, wxITEM_NORMAL, _("Preferences Settings Window"));
1336 #ifndef CLIENT_GUI
1337 wndToolbar->AddTool(ID_BUTTONIMPORT, _("Import"), m_tblist.GetBitmap(10), wxNullBitmap, wxITEM_NORMAL, _("The partfile importer tool"));
1338 #endif
1339 wndToolbar->AddTool(ID_ABOUT, _("About"), m_tblist.GetBitmap(11), wxNullBitmap, wxITEM_NORMAL, _("About/Help"));
1341 wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true);
1343 // Needed for non-GTK platforms, where the
1344 // items don't get added immediatly.
1345 wndToolbar->Realize();
1347 // Updates the "Connect" button, and so on.
1348 ShowConnectionState(true);
1352 void CamuleDlg::Create_Toolbar(bool orientation)
1354 Freeze();
1355 // Create ToolBar from the one designed by wxDesigner (BigBob)
1356 wxToolBar *current = GetToolBar();
1358 wxASSERT(current == m_wndToolbar);
1360 if (current) {
1361 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1362 if (oldorientation != orientation) {
1363 current->Destroy();
1364 SetToolBar(NULL); // Remove old one if present
1365 m_wndToolbar = NULL;
1366 } else {
1367 current->ClearTools();
1371 if (!m_wndToolbar) {
1372 m_wndToolbar = CreateToolBar(
1373 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1374 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1375 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1378 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1381 Apply_Toolbar_Skin(m_wndToolbar);
1383 Thaw();
1387 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1389 wxFrame::OnSize(evt);
1390 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1391 // Transfer window's splitter set again if it's hidden.
1392 if (!m_transferwnd->clientlistctrl->GetShowing()) {
1393 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1394 wxSplitterWindow* splitter =
1395 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1396 height += splitter->GetWindow1()->GetSize().GetHeight();
1397 splitter->SetSashPosition( height );
1404 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1406 if (event.GetKeyCode() == WXK_F1) {
1407 // Ctrl/Alt/Shift must not be pressed, to avoid
1408 // conflicts with other (global) shortcuts.
1409 if (!event.HasModifiers() && !event.ShiftDown()) {
1410 LaunchUrl(wxT("http://wiki.amule.org"));
1411 return;
1415 event.Skip();
1419 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1421 Close();
1424 void CamuleDlg::DoNetworkRearrange()
1427 wxWindowUpdateLocker freezer(this);
1429 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1431 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1432 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1434 while (logs_notebook->GetPageCount() > 1) {
1435 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1438 while (networks_notebook->GetPageCount() > 0) {
1439 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1442 if (thePrefs::GetNetworkED2K()) {
1443 #ifndef CLIENT_GUI
1444 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1445 #endif
1446 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1449 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1451 if (thePrefs::GetNetworkKademlia()) {
1452 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1455 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1457 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1459 wxWindow* replacement = NULL;
1461 m_networknotebooksizer->Clear();
1463 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1464 toolbarTool->SetLabel(_("Networks"));
1466 m_networkpages[0].page->Reparent(networks_notebook);
1467 m_networkpages[1].page->Reparent(networks_notebook);
1469 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1470 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1472 replacement = networks_notebook;
1474 } else if (thePrefs::GetNetworkED2K()) {
1475 toolbarTool->SetLabel(_("eD2k network"));
1476 replacement = m_networkpages[0].page;
1477 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1478 } else if (thePrefs::GetNetworkKademlia()) {
1479 toolbarTool->SetLabel(_("Kad network"));
1480 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1481 replacement = m_networkpages[1].page;
1482 } else {
1483 // No networks.
1484 toolbarTool->SetLabel(_("No network"));
1487 if (replacement) {
1488 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1489 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1490 m_networknotebooksizer->Layout();
1493 m_wndToolbar->InsertTool(2, toolbarTool);
1495 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1496 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
1498 m_wndToolbar->Realize();
1500 m_searchwnd->FixSearchTypes();
1503 // File_checked_for_headers