Upstream tarball 20080803
[amule.git] / src / amuleDlg.cpp
blob4ac12d5b990695a3434248657ceacbcd9eaad5cb
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <wx/app.h>
28 #include <wx/archive.h>
29 #include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
30 #include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
31 #include <wx/html/htmlwin.h>
32 #include <wx/mimetype.h> // Do_not_auto_remove (win32)
33 #include <wx/stattext.h>
34 #include <wx/stdpaths.h>
35 #include <wx/textfile.h> // Do_not_auto_remove (win32)
36 #include <wx/tokenzr.h>
37 #include <wx/wfstream.h>
38 #include <wx/zipstrm.h>
39 #include <wx/sysopt.h>
40 #include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker
42 #include <common/EventIDs.h>
44 #ifdef HAVE_CONFIG_H
45 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
46 #else
47 #include <common/ClientVersion.h>
48 #endif // HAVE_CONFIG_H
50 #include "amuleDlg.h" // Interface declarations.
52 #include <common/Format.h> // Needed for CFormat
53 #include "amule.h" // Needed for theApp
54 #include "ChatWnd.h" // Needed for CChatWnd
55 #include "ClientListCtrl.h" // Needed for CClientListCtrl
56 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
57 #include "DownloadQueue.h" // Needed for CDownloadQueue
58 #include "KadDlg.h" // Needed for CKadDlg
59 #include "Logger.h"
60 #include "MuleTrayIcon.h"
61 #include "muuli_wdr.h" // Needed for ID_BUTTON*
62 #include "Preferences.h" // Needed for CPreferences
63 #include "PrefsUnifiedDlg.h"
64 #include "SearchDlg.h" // Needed for CSearchDlg
65 #include "Server.h" // Needed for CServer
66 #include "ServerConnect.h" // Needed for CServerConnect
67 #include "ServerWnd.h" // Needed for CServerWnd
68 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
69 #include "Statistics.h" // Needed for theStats
70 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
71 #include "TerminationProcess.h" // Needed for CTerminationProcess
72 #include "TransferWnd.h" // Needed for CTransferWnd
73 #ifndef CLIENT_GUI
74 #include "PartFileConvert.h"
75 #endif
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 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
89 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
90 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
91 EVT_TOOL(ID_BUTTONTRANSFER, CamuleDlg::OnToolBarButton)
92 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
93 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
94 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
95 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
97 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
98 #ifndef CLIENT_GUI
99 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
100 #endif
102 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
104 EVT_CLOSE(CamuleDlg::OnClose)
105 EVT_ICONIZE(CamuleDlg::OnMinimize)
107 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
109 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
111 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
113 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
115 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
117 END_EVENT_TABLE()
119 #ifndef wxCLOSE_BOX
120 #define wxCLOSE_BOX 0
121 #endif
123 CamuleDlg::CamuleDlg(
124 wxWindow* pParent,
125 const wxString &title,
126 wxPoint where,
127 wxSize dlg_size)
129 wxFrame(
130 pParent, -1, title, where, dlg_size,
131 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
132 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
133 wxT("aMule")),
134 m_activewnd(NULL),
135 m_transferwnd(NULL),
136 m_serverwnd(NULL),
137 m_sharedfileswnd(NULL),
138 m_searchwnd(NULL),
139 m_chatwnd(NULL),
140 m_statisticswnd(NULL),
141 m_kademliawnd(NULL),
142 m_prefsDialog(NULL),
143 m_srv_split_pos(0),
144 m_imagelist(16,16),
145 m_tblist(32,32),
146 m_prefsVisible(false),
147 m_wndToolbar(NULL),
148 m_wndTaskbarNotifier(NULL),
149 m_nActiveDialog(DT_NETWORKS_WND),
150 m_is_safe_state(false),
151 m_BlinkMessages(false),
152 m_CurrentBlinkBitmap(24),
153 m_last_iconizing(0),
154 m_skinFileName(),
155 m_clientSkinNames(CLIENT_SKIN_SIZE)
157 // Initialize skin names
158 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
159 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
160 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
161 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
162 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
163 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
164 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
165 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
166 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
167 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
168 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
169 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
170 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
171 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
172 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
173 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
174 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
175 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
176 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
177 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
178 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
179 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
180 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
181 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
182 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
183 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
184 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
186 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
187 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
188 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
189 wxInitAllImageHandlers();
190 Apply_Clients_Skin();
192 #ifdef __WXMSW__
193 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
194 #endif
196 SetIcon(wxICON(aMule));
198 srand(time(NULL));
200 // Create new sizer and stuff a wxPanel in there.
201 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
202 s_main->AddGrowableCol(0);
203 s_main->AddGrowableRow(0);
205 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
206 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
207 muleDlg(p_cnt, false, true);
208 SetSizer(s_main, true);
210 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
211 AddLogLineM(false, wxEmptyString);
212 AddLogLineM(false, wxT(" - ") +
213 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
214 AddLogLineM(false, wxT(" ") +
215 CFormat(_("Running on %s")) % wxGetOsDescription());
216 AddLogLineM(false, wxT(" - ") +
217 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
218 AddLogLineM(false, wxEmptyString);
220 #ifdef ENABLE_IP2COUNTRY
221 m_IP2Country = new CIP2Country();
222 #endif
223 m_searchwnd = new CSearchDlg(p_cnt);
224 m_transferwnd = new CTransferWnd(p_cnt);
225 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
226 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
227 m_chatwnd = new CChatWnd(p_cnt);
228 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
230 m_serverwnd->Show(false);
231 m_searchwnd->Show(false);
232 m_transferwnd->Show(false);
233 m_sharedfileswnd->Show(false);
234 m_statisticswnd->Show(false);
235 m_chatwnd->Show(false);
237 // Create the GUI timer
238 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
239 if (!gui_timer) {
240 AddLogLine(false, _("FATAL ERROR: Failed to create Timer"));
241 exit(1);
244 // Set transfers as active window
245 Create_Toolbar(thePrefs::VerticalToolbar());
246 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
247 // Prepare the dialog, sets the splitter-position
248 m_transferwnd->Prepare();
249 m_wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true );
251 bool override_where = (where != wxDefaultPosition);
252 bool override_size = (
253 (dlg_size.x != DEFAULT_SIZE_X) ||
254 (dlg_size.y != DEFAULT_SIZE_Y) );
255 if (!LoadGUIPrefs(override_where, override_size)) {
256 // Prefs not loaded for some reason, exit
257 AddLogLineM( true, wxT("Error! Unable to load Preferences") );
258 return;
261 m_is_safe_state = true;
263 // Init statistics stuff, better do it asap
264 m_statisticswnd->Init();
265 m_kademliawnd->Init();
266 m_searchwnd->UpdateCatChoice();
267 if (thePrefs::UseTrayIcon()) {
268 CreateSystray();
271 Show(true);
272 // Must we start minimized?
273 if (thePrefs::GetStartMinimized()) {
274 DoIconize(true);
277 // Set shortcut keys
278 wxAcceleratorEntry entries[] = {
279 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
282 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
283 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
285 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
286 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
288 wxASSERT(logs_notebook->GetPageCount() == 4);
289 wxASSERT(networks_notebook->GetPageCount() == 2);
291 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
292 m_logpages[i].page = logs_notebook->GetPage(i);
293 m_logpages[i].name = logs_notebook->GetPageText(i);
296 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
297 m_networkpages[i].page = networks_notebook->GetPage(i);
298 m_networkpages[i].name = networks_notebook->GetPageText(i);
301 DoNetworkRearrange();
305 // Madcat - Sets Fast ED2K Links Handler on/off.
306 void CamuleDlg::ShowED2KLinksHandler( bool show )
308 // Errorchecking in case the pointer becomes invalid ...
309 if (s_fed2klh == NULL) {
310 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
311 return;
314 s_dlgcnt->Show( s_fed2klh, show );
315 s_dlgcnt->Layout();
318 // Toogles ed2k link handler.
319 void CamuleDlg::ToogleED2KLinksHandler()
321 // Errorchecking in case the pointer becomes invalid ...
322 if (s_fed2klh == NULL) {
323 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
324 return;
326 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
329 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
331 m_nActiveDialog = type;
333 if ( type == DT_TRANSFER_WND ) {
334 if (thePrefs::ShowCatTabInfos()) {
335 m_transferwnd->UpdateCatTabTitles();
339 if ( m_activewnd ) {
340 m_activewnd->Show(false);
341 contentSizer->Detach(m_activewnd);
344 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
345 dlg->Show(true);
346 m_activewnd=dlg;
347 s_dlgcnt->Layout();
349 // Since we might be suspending redrawing while hiding the dialog
350 // we have to refresh it once it is visible again
351 dlg->Refresh( true );
352 dlg->SetFocus();
356 void CamuleDlg::UpdateTrayIcon(int percent)
358 // set trayicon-icon
359 if(!theApp->IsConnected()) {
360 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
361 } else {
362 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
363 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
364 } else {
365 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
371 void CamuleDlg::CreateSystray()
373 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
374 wxT("Systray already created"));
376 m_wndTaskbarNotifier = new CMuleTrayIcon();
377 // This will effectively show the Tray Icon.
378 UpdateTrayIcon(0);
382 void CamuleDlg::RemoveSystray()
384 delete m_wndTaskbarNotifier;
385 m_wndTaskbarNotifier = NULL;
389 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
391 static int lastbutton = ID_BUTTONTRANSFER;
393 // Kry - just if the GUI is ready for it
394 if ( m_is_safe_state ) {
396 // Rehide the handler if needed
397 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
398 if (ev.GetId() != ID_BUTTONSEARCH) {
399 ShowED2KLinksHandler( false );
400 } else {
401 // Toogle ED2K handler.
402 ToogleED2KLinksHandler();
406 if ( lastbutton != ev.GetId() ) {
407 switch ( ev.GetId() ) {
408 case ID_BUTTONNETWORKS:
409 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
410 // Set serverlist splitter position
411 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
412 break;
414 case ID_BUTTONSEARCH:
415 // The search dialog should always display the handler
416 if ( !thePrefs::GetFED2KLH() )
417 ShowED2KLinksHandler( true );
419 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
420 break;
422 case ID_BUTTONTRANSFER:
423 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
424 // Prepare the dialog, sets the splitter-position
425 m_transferwnd->Prepare();
426 break;
428 case ID_BUTTONSHARED:
429 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
430 break;
432 case ID_BUTTONMESSAGES:
433 m_BlinkMessages = false;
434 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
435 break;
437 case ID_BUTTONSTATISTICS:
438 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
439 break;
441 // This shouldn't happen, but just in case
442 default:
443 AddLogLineM( true, wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
444 break;
448 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
449 lastbutton = ev.GetId();
454 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
456 wxString msg = wxT(" ");
457 #ifdef CLIENT_GUI
458 msg << _("aMule remote control ") << wxT(VERSION);
459 #else
460 msg << wxT("aMule ") << wxT(VERSION);
461 #endif
462 msg << wxT(" ");
463 #ifdef SVNDATE
464 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
465 #endif
466 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
467 _("Website: http://www.amule.org \n") <<
468 _("Forum: http://forum.amule.org \n") <<
469 _("FAQ: http://wiki.amule.org \n\n") <<
470 _("Contact: admin@amule.org (administrative issues) \n") <<
471 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
472 _("Part of aMule is based on \n") <<
473 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
474 _(" Copyright (C) 2002 Petar Maymounkov <petar@post.harvard.edu>\n") <<
475 _("http://kademlia.scs.cs.nyu.edu\n");
477 if (m_is_safe_state) {
478 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
483 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
485 if (m_is_safe_state) {
486 if (m_prefsDialog == NULL) {
487 m_prefsDialog = new PrefsUnifiedDlg(this);
490 m_prefsDialog->TransferToWindow();
491 m_prefsDialog->Show(true);
492 m_prefsDialog->Raise();
497 #ifndef CLIENT_GUI
498 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
500 if ( m_is_safe_state ) {
501 CPartFileConvert::ShowGUI(NULL);
504 #endif
506 CamuleDlg::~CamuleDlg()
508 printf("Shutting down aMule...\n");
510 SaveGUIPrefs();
512 theApp->amuledlg = NULL;
514 #ifdef ENABLE_IP2COUNTRY
515 delete m_IP2Country;
516 #endif
518 printf("aMule dialog destroyed\n");
522 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
525 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
526 #ifndef CLIENT_GUI
527 || (Kademlia::CKademlia::IsRunning())
528 #endif
530 if (thePrefs::GetNetworkED2K()) {
531 if (disconnect) {
532 //disconnect if currently connected
533 if (theApp->serverconnect->IsConnecting()) {
534 theApp->serverconnect->StopConnectionTry();
535 } else {
536 theApp->serverconnect->Disconnect();
538 } else {
539 //connect if not currently connected
540 AddLogLine(true, _("Connecting"));
541 theApp->serverconnect->ConnectToAnyServer();
543 } else {
544 wxASSERT(!theApp->IsConnectedED2K());
547 // Connect Kad also
548 if (thePrefs::GetNetworkKademlia()) {
549 if( disconnect ) {
550 theApp->StopKad();
551 } else {
552 theApp->StartKad();
554 } else {
555 #ifndef CLIENT_GUI
556 wxASSERT(!Kademlia::CKademlia::IsRunning());
557 #endif
560 ShowConnectionState();
564 void CamuleDlg::ResetLog(int id)
566 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
567 wxCHECK_RET(ct, wxT("Resetting unknown log"));
569 ct->Clear();
571 if (id == ID_LOGVIEW) {
572 // Also clear the log line
573 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
574 text->SetLabel(wxEmptyString);
575 text->GetParent()->Layout();
580 void CamuleDlg::AddLogLine(bool addtostatusbar, const wxString& line)
582 // Remove newspace at end, it causes problems with the layout...
583 wxString bufferline = line.Strip(wxString::trailing);
585 // Create the timestamp
586 wxString stamp = wxDateTime::Now().FormatISODate() + wxT(" ") + wxDateTime::Now().FormatISOTime() + wxT(": ");
588 // Add the message to the log-view
589 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
590 if ( ct ) {
591 if ( bufferline.IsEmpty() ) {
592 // If it's empty we just write a blank line with no timestamp.
593 ct->AppendText( wxT("\n") );
594 } else {
595 // Bold critical log-lines
596 // Windows doesn't support this feature, and it causes GDI resource leaks
597 #ifndef __WXMSW__
598 wxTextAttr style = ct->GetDefaultStyle();
599 wxFont font = style.GetFont();
600 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
601 style.SetFont(font);
602 ct->SetDefaultStyle(style);
603 #endif
605 // Split multi-line messages into individual lines
606 wxStringTokenizer tokens( bufferline, wxT("\n") );
607 while ( tokens.HasMoreTokens() ) {
608 ct->AppendText( stamp + tokens.GetNextToken() + wxT("\n") );
612 ct->ShowPosition( ct->GetLastPosition() - 1 );
616 // Set the status-bar if the event warrents it
617 if ( addtostatusbar ) {
618 // Escape "&"s, which would otherwise not show up
619 bufferline.Replace( wxT("&"), wxT("&&") );
620 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
621 // Only show the first line if multiple lines
622 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
623 text->SetToolTip( bufferline );
624 text->GetParent()->Layout();
630 void CamuleDlg::AddServerMessageLine(wxString& message)
632 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
633 if(cv) {
634 if (message.Length() > 500) {
635 cv->AppendText(message.Left(500) + wxT("\n"));
636 } else {
637 cv->AppendText(message + wxT("\n"));
639 cv->ShowPosition(cv->GetLastPosition()-1);
644 void CamuleDlg::ShowConnectionState(bool skinChanged)
646 static wxImageList status_arrows(16,16,true,0);
647 if (!status_arrows.GetImageCount()) {
648 // Generate the image list (This is only done once)
649 for (int t = 0; t < 7; ++t) {
650 status_arrows.Add(connImages(t));
654 m_serverwnd->UpdateED2KInfo();
655 m_serverwnd->UpdateKadInfo();
658 ////////////////////////////////////////////////////////////
659 // Determine the status of the networks
661 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
662 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
664 ED2KState ed2kState = ED2KOff;
665 EKadState kadState = EKadOff;
667 ////////////////////////////////////////////////////////////
668 // Update the label on the status-bar and determine
669 // the states of the two networks.
671 wxString msgED2K;
672 if (theApp->IsConnectedED2K()) {
673 CServer* server = theApp->serverconnect->GetCurrentServer();
674 if (server) {
675 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
678 if (theApp->serverconnect->IsLowID()) {
679 ed2kState = ED2KLowID;
680 } else {
681 ed2kState = ED2KHighID;
683 } else if (theApp->serverconnect->IsConnecting()) {
684 msgED2K = _("eD2k: Connecting");
686 ed2kState = ED2KConnecting;
687 } else if (thePrefs::GetNetworkED2K()) {
688 msgED2K = _("eD2k: Disconnected");
691 wxString msgKad;
692 if (theApp->IsConnectedKad()) {
693 if (theApp->IsFirewalledKad()) {
694 msgKad = _("Kad: Firewalled");
696 kadState = EKadFW;
697 } else {
698 msgKad = _("Kad: Connected");
700 kadState = EKadOK;
702 } else if (theApp->IsKadRunning()) {
703 msgKad = _("Kad: Connecting");
705 kadState = EKadConnecting;
706 } else if (thePrefs::GetNetworkKademlia()) {
707 msgKad = _("Kad: Off");
710 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
711 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
713 wxString labelMsg;
714 if (msgED2K.Length() && msgKad.Length()) {
715 labelMsg = msgED2K + wxT(" | ") + msgKad;
716 } else {
717 labelMsg = msgED2K + msgKad;
720 connLabel->SetLabel(labelMsg);
721 connLabel->GetParent()->Layout();
724 ////////////////////////////////////////////////////////////
725 // Update the connect/disconnect/cancel button.
727 enum EConnState {
728 ECS_Unknown,
729 ECS_Connected,
730 ECS_Connecting,
731 ECS_Disconnected
734 static EConnState s_oldState = ECS_Unknown;
735 EConnState currentState = ECS_Disconnected;
737 if (theApp->serverconnect->IsConnecting() ||
738 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
739 currentState = ECS_Connecting;
740 } else if (theApp->IsConnected()) {
741 currentState = ECS_Connected;
742 } else {
743 currentState = ECS_Disconnected;
746 if ( (true == skinChanged) || (currentState != s_oldState) ) {
747 wxWindowUpdateLocker freezer(m_wndToolbar);
749 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
751 switch (currentState) {
752 case ECS_Connecting:
753 toolbarTool->SetLabel(_("Cancel"));
754 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
755 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
756 break;
758 case ECS_Connected:
759 toolbarTool->SetLabel(_("Disconnect"));
760 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
761 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
762 break;
764 default:
765 toolbarTool->SetLabel(_("Connect"));
766 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
767 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
770 m_wndToolbar->InsertTool(0, toolbarTool);
771 m_wndToolbar->Realize();
773 s_oldState = currentState;
777 ////////////////////////////////////////////////////////////
778 // Update the globe-icon in the lower-right corner.
779 // (only if connection state has changed)
781 static ED2KState s_ED2KOldState = ED2KUndef;
782 static EKadState s_EKadOldState = EKadUndef;
783 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
784 s_ED2KOldState = ed2kState;
785 s_EKadOldState = kadState;
786 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
787 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
789 wxBitmap statusIcon = connBitmap->GetBitmap();
790 // Sanity check - otherwise there's a crash here if aMule runs out of ressources
791 if (statusIcon.GetBitmapData() == NULL) {
792 return;
795 wxMemoryDC bitmapDC(statusIcon);
797 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
798 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
800 connBitmap->SetBitmap(statusIcon);
805 void CamuleDlg::ShowUserCount(const wxString& info)
807 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
809 // Update Kad tab
810 m_serverwnd->UpdateKadInfo();
812 label->SetLabel(info);
813 label->GetParent()->Layout();
817 void CamuleDlg::ShowTransferRate()
819 float kBpsUp = theStats::GetUploadRate() / 1024.0;
820 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
821 wxString buffer;
822 if( thePrefs::ShowOverhead() )
824 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
825 } else {
826 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
828 buffer.Truncate(50); // Max size 50
830 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
831 label->SetLabel(buffer);
832 label->GetParent()->Layout();
834 // Show upload/download speed in title
835 if (thePrefs::GetShowRatesOnTitle()) {
836 wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
837 if (thePrefs::GetShowRatesOnTitle() == 1) {
838 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
839 } else {
840 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
844 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
845 if (m_wndTaskbarNotifier) {
846 // set trayicon-icon
847 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
848 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
850 wxString buffer2;
851 if ( theApp->IsConnected() ) {
852 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
853 } else {
854 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
856 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
859 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
860 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
863 void CamuleDlg::DlgShutDown()
865 // Are we already shutting down or still on init?
866 if ( m_is_safe_state == false ) {
867 return;
870 // we are going DOWN
871 m_is_safe_state = false;
873 // Stop the GUI Timer
874 delete gui_timer;
875 m_transferwnd->downloadlistctrl->DeleteAllItems();
877 // We want to delete the systray too!
878 RemoveSystray();
881 void CamuleDlg::OnClose(wxCloseEvent& evt)
883 // This will be here till the core close is != app close
884 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
885 if (wxNO == wxMessageBox(wxString(_("Do you really want to exit aMule?")),
886 wxString(_("Exit confirmation")), wxYES_NO, this)) {
887 evt.Veto();
888 return;
892 Enable(false);
893 Show(false);
895 theApp->ShutDown(evt);
899 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
901 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
903 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
904 wxString strlink = ctl->GetLineText(i);
905 strlink.Trim(true);
906 strlink.Trim(false);
907 if ( !strlink.IsEmpty() ) {
908 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
912 ctl->SetValue(wxEmptyString);
916 // Formerly known as LoadRazorPrefs()
917 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
919 // Create a config base for loading razor preferences
920 wxConfigBase *config = wxConfigBase::Get();
921 // If config haven't been created exit without loading
922 if (config == NULL) {
923 return false;
926 // The section where to save in in file
927 wxString section = wxT("/Razor_Preferences/");
929 // Get window size and position
930 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
931 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
932 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
933 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
935 int maximized = config->Read(section + wxT("Maximized"), 01);
937 // Kry - Random usable pos for m_srv_split_pos
938 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
939 if (!override_size) {
940 if (x2 > 0 && y2 > 0) {
941 SetSize(x2, y2);
942 } else {
943 #ifndef __WXGTK__
944 // Probably first run.
945 Maximize();
946 #endif
950 if (!override_pos) {
951 // If x1 and y1 != -1 Redefine location
952 if(x1 != -1 && y1 != -1) {
953 wxRect display = wxGetClientDisplayRect();
954 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
955 Move(x1, y1);
956 } else {
957 // It's offscreen... so let's not.
962 if (!override_size && !override_pos && maximized) {
963 Maximize();
966 return true;
970 bool CamuleDlg::SaveGUIPrefs()
972 /* Razor 1a - Modif by MikaelB
973 Save client size and position */
975 // Create a config base for saving razor preferences
976 wxConfigBase *config = wxConfigBase::Get();
977 // If config haven't been created exit without saving
978 if (config == NULL) {
979 return false;
981 // The section where to save in in file
982 wxString section = wxT("/Razor_Preferences/");
984 // Main window location and size
985 int x1, y1, x2, y2;
986 GetPosition(&x1, &y1);
987 GetSize(&x2, &y2);
989 // Saving window size and position
990 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
991 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
993 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
994 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
996 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
998 // Saving sash position of splitter in server window
999 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1001 config->Flush(true);
1003 /* End modif */
1005 return true;
1009 void CamuleDlg::DoIconize(bool iconize)
1011 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1012 if (iconize) {
1013 // Skip() will do it.
1014 //Iconize(true);
1015 if (SafeState()) {
1016 Show(false);
1018 } else {
1019 Show(true);
1020 Raise();
1022 } else {
1023 // Will be done by Skip();
1024 //Iconize(iconize);
1028 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1030 // Evil Hack: check if the mouse is inside the window
1031 #ifndef __WINDOWS__
1032 if (GetScreenRect().Contains(wxGetMousePosition()))
1033 #endif
1035 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1036 // Veto.
1037 } else {
1038 if (m_wndTaskbarNotifier) {
1039 DoIconize(evt.Iconized());
1041 evt.Skip();
1046 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1048 // Former TimerProc section
1050 static uint32 msPrev1, msPrev5, msPrevStats;
1052 uint32 msCur = theStats::GetUptimeMillis();
1054 // can this actually happen under wxwin ?
1055 if (!SafeState()) {
1056 return;
1059 #ifndef CLIENT_GUI
1060 static uint32 msPrevGraph;
1061 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1062 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1063 // trying to get the graph shifts evenly spaced after a change in the update period
1064 msPrevGraph = msCur;
1066 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1068 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1069 m_kademliawnd->UpdateGraph(update);
1071 #else
1072 //#warning TODO: CORE/GUI -- EC needed
1073 #endif
1075 int sStatsUpdate = thePrefs::GetStatsInterval();
1076 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1077 if (m_statisticswnd->IsShownOnScreen()) {
1078 msPrevStats = msCur;
1079 m_statisticswnd->ShowStatistics();
1083 if (msCur-msPrev5 > 5000) { // every 5 seconds
1084 msPrev5 = msCur;
1085 ShowTransferRate();
1086 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1087 m_transferwnd->UpdateCatTabTitles();
1089 if (thePrefs::AutoSortDownload()) {
1090 m_transferwnd->downloadlistctrl->SortList();
1094 if (msCur-msPrev1 > 1000) { // every second
1095 msPrev1 = msCur;
1096 if (m_CurrentBlinkBitmap == 12) {
1097 m_CurrentBlinkBitmap = 7;
1098 SetMessagesTool();
1099 } else {
1100 if (m_BlinkMessages) {
1101 m_CurrentBlinkBitmap = 12;
1102 SetMessagesTool();
1110 void CamuleDlg::SetMessagesTool()
1112 int pos = m_wndToolbar->GetToolPos(ID_BUTTONMESSAGES);
1113 wxASSERT(pos == 6); // so we don't miss a change on wx2.4
1115 wxWindowUpdateLocker freezer(m_wndToolbar);
1116 #ifdef __WXCOCOA__
1117 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1118 #else
1119 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1120 #endif
1123 void CamuleDlg::LaunchUrl( const wxString& url )
1125 wxString cmd;
1127 cmd = thePrefs::GetBrowser();
1128 wxString tmp = url;
1129 // Pipes cause problems, so escape them
1130 tmp.Replace( wxT("|"), wxT("%7C") );
1132 if ( !cmd.IsEmpty() ) {
1133 if (!cmd.Replace(wxT("%s"), tmp)) {
1134 // No %s found, just append the url
1135 cmd += wxT(" ") + tmp;
1138 CTerminationProcess *p = new CTerminationProcess(cmd);
1139 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1140 printf( "Launch Command: %s\n", (const char *)unicode2char(cmd));
1141 return;
1142 } else {
1143 delete p;
1145 } else {
1146 wxLaunchDefaultBrowser(tmp);
1147 return;
1149 // Unable to execute browser. But this error message doesn't make sense,
1150 // cosidering that you _can't_ set the browser executable path... =/
1151 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1155 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1157 wxString URL;
1158 switch (wsProvider) {
1159 case WS_FILEHASH:
1160 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1161 break;
1162 default:
1163 wxASSERT(0);
1165 URL.Replace(wxT("FILENAME"), filename);
1167 return URL;
1171 bool CamuleDlg::Check_and_Init_Skin()
1173 bool ret = true;
1174 wxString skinFileName(thePrefs::GetSkin());
1176 if (skinFileName.IsEmpty()) {
1177 return false;
1180 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1182 wxStandardPathsBase &spb(wxStandardPaths::Get());
1183 #ifdef __WXMSW__
1184 wxString dataDir(spb.GetPluginsDir());
1185 #elif defined(__WXMAC__)
1186 wxString dataDir(spb.GetDataDir());
1187 #else
1188 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1189 #endif
1190 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1193 skinFileName.Replace(wxT("User:"), userDir );
1194 skinFileName.Replace(wxT("System:"), systemDir );
1196 m_skinFileName.Assign(skinFileName);
1197 if (!m_skinFileName.FileExists()) {
1198 AddLogLineM(true, CFormat(
1199 _("Skin directory '%s' does not exist")) %
1200 skinFileName );
1201 ret = false;
1202 } else if (!m_skinFileName.IsFileReadable()) {
1203 AddLogLineM(true, CFormat(
1204 _("WARNING: Unable to open skin file '%s' for read")) %
1205 skinFileName);
1206 ret = false;
1209 wxFFileInputStream in(m_skinFileName.GetFullPath());
1210 wxZipInputStream zip(in);
1212 while ((entry = zip.GetNextEntry()) != NULL) {
1213 wxZipEntry*& current = cat[entry->GetInternalName()];
1214 delete current;
1215 current = entry;
1218 return ret;
1222 void CamuleDlg::Add_Skin_Icon(
1223 const wxString &iconName,
1224 const wxBitmap &stdIcon,
1225 bool useSkins)
1227 wxImage new_image;
1228 if (useSkins) {
1229 wxFFileInputStream in(m_skinFileName.GetFullPath());
1230 wxZipInputStream zip(in);
1232 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1233 if ( it != cat.end() ) {
1234 zip.OpenEntry(*it->second);
1235 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1236 AddLogLineM(false,
1237 wxT("Warning: Error loading icon for ") +
1238 iconName);
1239 useSkins = false;
1241 }else {
1242 AddLogLineM(false,
1243 wxT("Warning: Can't load icon for ") +
1244 iconName);
1245 useSkins = false;
1250 wxBitmap bmp(useSkins ? new_image : stdIcon);
1251 if (iconName.StartsWith(wxT("Client_"))) {
1252 m_imagelist.Add(bmp);
1253 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1254 m_tblist.Add(bmp);
1259 void CamuleDlg::Apply_Clients_Skin()
1261 bool useSkins = Check_and_Init_Skin();
1263 // Clear the client image list
1264 m_imagelist.RemoveAll();
1266 // Add the images to the image list
1267 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1268 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1269 clientImages(i), useSkins);
1274 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1276 bool useSkins = Check_and_Init_Skin();
1279 // Clear the toolbar image list
1280 m_tblist.RemoveAll();
1282 // Add the images to the image list
1283 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1284 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1285 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1286 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1287 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1288 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1289 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1290 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1291 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1292 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1293 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1294 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1295 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1297 // Build aMule toolbar
1298 wndToolbar->SetMargins(0, 0);
1300 // Placeholder. Gets updated by ShowConnectionState
1301 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1303 wndToolbar->AddSeparator();
1304 wndToolbar->AddTool(ID_BUTTONNETWORKS,
1305 _("Networks"), m_tblist.GetBitmap(3),
1306 wxNullBitmap, wxITEM_CHECK,
1307 _("Networks window"));
1308 wndToolbar->AddTool(ID_BUTTONSEARCH,
1309 _("Searches"), m_tblist.GetBitmap(5),
1310 wxNullBitmap, wxITEM_CHECK,
1311 _("Searches window"));
1312 wndToolbar->AddTool(ID_BUTTONTRANSFER,
1313 _("Transfers"), m_tblist.GetBitmap(4),
1314 wxNullBitmap, wxITEM_CHECK,
1315 _("Files transfers window"));
1316 wndToolbar->AddTool(ID_BUTTONSHARED,
1317 _("Shared files"), m_tblist.GetBitmap(6),
1318 wxNullBitmap, wxITEM_CHECK,
1319 _("Shared files window"));
1320 wndToolbar->AddTool(ID_BUTTONMESSAGES,
1321 _("Messages"), m_tblist.GetBitmap(7),
1322 wxNullBitmap, wxITEM_CHECK,
1323 _("Messages window"));
1324 wndToolbar->AddTool(ID_BUTTONSTATISTICS,
1325 _("Statistics"), m_tblist.GetBitmap(8),
1326 wxNullBitmap, wxITEM_CHECK,
1327 _("Statistics graph window"));
1328 wndToolbar->AddSeparator();
1329 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES,
1330 _("Preferences"), m_tblist.GetBitmap(9),
1331 wxNullBitmap, wxITEM_NORMAL,
1332 _("Preferences settings window"));
1333 wndToolbar->AddTool(ID_BUTTONIMPORT,
1334 _("Import"), m_tblist.GetBitmap(10),
1335 wxNullBitmap, wxITEM_NORMAL,
1336 _("The partfile importer tool"));
1337 wndToolbar->AddTool(ID_ABOUT,
1338 _("About"), m_tblist.GetBitmap(11),
1339 wxNullBitmap, wxITEM_NORMAL,
1340 _("About/Help"));
1342 wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true);
1344 // Needed for non-GTK platforms, where the
1345 // items don't get added immediatly.
1346 wndToolbar->Realize();
1348 // Updates the "Connect" button, and so on.
1349 ShowConnectionState(true);
1353 void CamuleDlg::Create_Toolbar(bool orientation)
1355 Freeze();
1356 // Create ToolBar from the one designed by wxDesigner (BigBob)
1357 wxToolBar *current = GetToolBar();
1359 wxASSERT(current == m_wndToolbar);
1361 if (current) {
1362 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1363 if (oldorientation != orientation) {
1364 current->Destroy();
1365 SetToolBar(NULL); // Remove old one if present
1366 m_wndToolbar = NULL;
1367 } else {
1368 current->ClearTools();
1372 if (!m_wndToolbar) {
1373 m_wndToolbar = CreateToolBar(
1374 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1375 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1376 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1379 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1382 Apply_Toolbar_Skin(m_wndToolbar);
1383 #ifdef CLIENT_GUI
1384 m_wndToolbar->DeleteTool(ID_BUTTONIMPORT);
1385 #endif
1387 Thaw();
1391 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1393 wxFrame::OnSize(evt);
1394 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1395 // Transfer window's splitter set again if it's hidden.
1396 if (m_transferwnd->clientlistctrl->GetListView() == vtNone) {
1397 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1398 wxSplitterWindow* splitter =
1399 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1400 height += splitter->GetWindow1()->GetSize().GetHeight();
1401 splitter->SetSashPosition( height );
1408 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1410 if (event.GetKeyCode() == WXK_F1) {
1411 // Ctrl/Alt/Shift must not be pressed, to avoid
1412 // conflicts with other (global) shortcuts.
1413 if (!event.HasModifiers() && !event.ShiftDown()) {
1414 LaunchUrl(wxT("http://wiki.amule.org"));
1415 return;
1419 event.Skip();
1423 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1425 Close();
1428 void CamuleDlg::DoNetworkRearrange()
1431 wxWindowUpdateLocker freezer(this);
1433 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1435 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1436 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1438 while (logs_notebook->GetPageCount() > 1) {
1439 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1442 while (networks_notebook->GetPageCount() > 0) {
1443 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1446 if (thePrefs::GetNetworkED2K()) {
1447 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1448 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1451 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1453 if (thePrefs::GetNetworkKademlia()) {
1454 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1457 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1459 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1461 wxWindow* replacement = NULL;
1463 m_networknotebooksizer->Clear();
1465 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1466 toolbarTool->SetLabel(_("Networks"));
1468 m_networkpages[0].page->Reparent(networks_notebook);
1469 m_networkpages[1].page->Reparent(networks_notebook);
1471 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1472 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1474 replacement = networks_notebook;
1476 } else if (thePrefs::GetNetworkED2K()) {
1477 toolbarTool->SetLabel(_("eD2k network"));
1478 replacement = m_networkpages[0].page;
1479 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1480 } else if (thePrefs::GetNetworkKademlia()) {
1481 toolbarTool->SetLabel(_("Kad network"));
1482 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1483 replacement = m_networkpages[1].page;
1484 } else {
1485 // No networks.
1486 toolbarTool->SetLabel(_("No network"));
1489 if (replacement) {
1490 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1491 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1492 m_networknotebooksizer->Layout();
1495 m_wndToolbar->InsertTool(2, toolbarTool);
1497 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1498 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1500 m_wndToolbar->Realize();
1502 m_searchwnd->FixSearchTypes();
1505 // File_checked_for_headers