Upstream tarball 20080902
[amule.git] / src / amuleDlg.cpp
blob673deb936d293abe52e76c424f58d2764d14db99
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 "ClientListCtrl.h" // Needed for CClientListCtrl
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 "Statistics.h" // Needed for theStats
71 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
72 #include "TerminationProcess.h" // Needed for CTerminationProcess
73 #include "TransferWnd.h" // Needed for CTransferWnd
74 #ifndef CLIENT_GUI
75 #include "PartFileConvert.h"
76 #endif
78 #ifndef __WXMSW__
79 #include "aMule.xpm"
80 #endif
82 #include "kademlia/kademlia/Kademlia.h"
84 #ifdef ENABLE_IP2COUNTRY
85 #include "IP2Country.h" // Needed for IP2Country
86 #endif
88 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
90 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
91 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
92 EVT_TOOL(ID_BUTTONTRANSFER, CamuleDlg::OnToolBarButton)
93 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
94 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
95 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
96 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
98 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
99 #ifndef CLIENT_GUI
100 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
101 #endif
103 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
105 EVT_CLOSE(CamuleDlg::OnClose)
106 EVT_ICONIZE(CamuleDlg::OnMinimize)
108 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
110 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
112 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
114 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
116 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
118 END_EVENT_TABLE()
120 #ifndef wxCLOSE_BOX
121 #define wxCLOSE_BOX 0
122 #endif
124 CamuleDlg::CamuleDlg(
125 wxWindow* pParent,
126 const wxString &title,
127 wxPoint where,
128 wxSize dlg_size)
130 wxFrame(
131 pParent, -1, title, where, dlg_size,
132 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
133 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
134 wxT("aMule")),
135 m_activewnd(NULL),
136 m_transferwnd(NULL),
137 m_serverwnd(NULL),
138 m_sharedfileswnd(NULL),
139 m_searchwnd(NULL),
140 m_chatwnd(NULL),
141 m_statisticswnd(NULL),
142 m_kademliawnd(NULL),
143 m_prefsDialog(NULL),
144 m_srv_split_pos(0),
145 m_imagelist(16,16),
146 m_tblist(32,32),
147 m_prefsVisible(false),
148 m_wndToolbar(NULL),
149 m_wndTaskbarNotifier(NULL),
150 m_nActiveDialog(DT_NETWORKS_WND),
151 m_is_safe_state(false),
152 m_BlinkMessages(false),
153 m_CurrentBlinkBitmap(24),
154 m_last_iconizing(0),
155 m_skinFileName(),
156 m_clientSkinNames(CLIENT_SKIN_SIZE)
158 // Initialize skin names
159 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
160 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
161 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
162 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
163 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
164 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
165 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
166 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
167 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
168 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
169 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
170 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
171 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
172 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
173 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
174 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
175 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
176 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
177 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
178 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
179 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
180 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
181 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
182 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
183 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
184 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
185 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
187 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
188 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
189 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
190 wxInitAllImageHandlers();
191 Apply_Clients_Skin();
193 #ifdef __WXMSW__
194 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
195 #endif
197 SetIcon(wxICON(aMule));
199 srand(time(NULL));
201 // Create new sizer and stuff a wxPanel in there.
202 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
203 s_main->AddGrowableCol(0);
204 s_main->AddGrowableRow(0);
206 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
207 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
208 muleDlg(p_cnt, false, true);
209 SetSizer(s_main, true);
211 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
212 AddLogLineM(false, wxEmptyString);
213 AddLogLineM(false, wxT(" - ") +
214 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
215 AddLogLineM(false, wxT(" ") +
216 CFormat(_("Running on %s")) % wxGetOsDescription());
217 AddLogLineM(false, wxT(" - ") +
218 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
219 AddLogLineM(false, wxEmptyString);
221 #ifdef ENABLE_IP2COUNTRY
222 m_IP2Country = new CIP2Country();
223 #endif
224 m_searchwnd = new CSearchDlg(p_cnt);
225 m_transferwnd = new CTransferWnd(p_cnt);
226 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
227 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
228 m_chatwnd = new CChatWnd(p_cnt);
229 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
231 m_serverwnd->Show(false);
232 m_searchwnd->Show(false);
233 m_transferwnd->Show(false);
234 m_sharedfileswnd->Show(false);
235 m_statisticswnd->Show(false);
236 m_chatwnd->Show(false);
238 // Create the GUI timer
239 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
240 if (!gui_timer) {
241 AddLogLine(false, _("FATAL ERROR: Failed to create Timer"));
242 exit(1);
245 // Set transfers as active window
246 Create_Toolbar(thePrefs::VerticalToolbar());
247 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
248 // Prepare the dialog, sets the splitter-position
249 m_transferwnd->Prepare();
250 m_wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true );
252 bool override_where = (where != wxDefaultPosition);
253 bool override_size = (
254 (dlg_size.x != DEFAULT_SIZE_X) ||
255 (dlg_size.y != DEFAULT_SIZE_Y) );
256 if (!LoadGUIPrefs(override_where, override_size)) {
257 // Prefs not loaded for some reason, exit
258 AddLogLineM( true, wxT("Error! Unable to load Preferences") );
259 return;
262 m_is_safe_state = true;
264 // Init statistics stuff, better do it asap
265 m_statisticswnd->Init();
266 m_kademliawnd->Init();
267 m_searchwnd->UpdateCatChoice();
268 if (thePrefs::UseTrayIcon()) {
269 CreateSystray();
272 Show(true);
273 // Must we start minimized?
274 if (thePrefs::GetStartMinimized()) {
275 DoIconize(true);
278 // Set shortcut keys
279 wxAcceleratorEntry entries[] = {
280 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
283 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
284 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
286 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
287 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
289 wxASSERT(logs_notebook->GetPageCount() == 4);
290 wxASSERT(networks_notebook->GetPageCount() == 2);
292 for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
293 m_logpages[i].page = logs_notebook->GetPage(i);
294 m_logpages[i].name = logs_notebook->GetPageText(i);
297 for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
298 m_networkpages[i].page = networks_notebook->GetPage(i);
299 m_networkpages[i].name = networks_notebook->GetPageText(i);
302 DoNetworkRearrange();
306 // Madcat - Sets Fast ED2K Links Handler on/off.
307 void CamuleDlg::ShowED2KLinksHandler( bool show )
309 // Errorchecking in case the pointer becomes invalid ...
310 if (s_fed2klh == NULL) {
311 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
312 return;
315 s_dlgcnt->Show( s_fed2klh, show );
316 s_dlgcnt->Layout();
319 // Toogles ed2k link handler.
320 void CamuleDlg::ToogleED2KLinksHandler()
322 // Errorchecking in case the pointer becomes invalid ...
323 if (s_fed2klh == NULL) {
324 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
325 return;
327 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
330 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
332 m_nActiveDialog = type;
334 if ( type == DT_TRANSFER_WND ) {
335 if (thePrefs::ShowCatTabInfos()) {
336 m_transferwnd->UpdateCatTabTitles();
340 if ( m_activewnd ) {
341 m_activewnd->Show(false);
342 contentSizer->Detach(m_activewnd);
345 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
346 dlg->Show(true);
347 m_activewnd=dlg;
348 s_dlgcnt->Layout();
350 // Since we might be suspending redrawing while hiding the dialog
351 // we have to refresh it once it is visible again
352 dlg->Refresh( true );
353 dlg->SetFocus();
357 void CamuleDlg::UpdateTrayIcon(int percent)
359 // set trayicon-icon
360 if(!theApp->IsConnected()) {
361 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
362 } else {
363 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
364 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
365 } else {
366 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
372 void CamuleDlg::CreateSystray()
374 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
375 wxT("Systray already created"));
377 m_wndTaskbarNotifier = new CMuleTrayIcon();
378 // This will effectively show the Tray Icon.
379 UpdateTrayIcon(0);
383 void CamuleDlg::RemoveSystray()
385 delete m_wndTaskbarNotifier;
386 m_wndTaskbarNotifier = NULL;
390 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
392 static int lastbutton = ID_BUTTONTRANSFER;
394 // Kry - just if the GUI is ready for it
395 if ( m_is_safe_state ) {
397 // Rehide the handler if needed
398 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
399 if (ev.GetId() != ID_BUTTONSEARCH) {
400 ShowED2KLinksHandler( false );
401 } else {
402 // Toogle ED2K handler.
403 ToogleED2KLinksHandler();
407 if ( lastbutton != ev.GetId() ) {
408 switch ( ev.GetId() ) {
409 case ID_BUTTONNETWORKS:
410 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
411 // Set serverlist splitter position
412 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
413 break;
415 case ID_BUTTONSEARCH:
416 // The search dialog should always display the handler
417 if ( !thePrefs::GetFED2KLH() )
418 ShowED2KLinksHandler( true );
420 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
421 break;
423 case ID_BUTTONTRANSFER:
424 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
425 // Prepare the dialog, sets the splitter-position
426 m_transferwnd->Prepare();
427 break;
429 case ID_BUTTONSHARED:
430 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
431 break;
433 case ID_BUTTONMESSAGES:
434 m_BlinkMessages = false;
435 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
436 break;
438 case ID_BUTTONSTATISTICS:
439 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
440 break;
442 // This shouldn't happen, but just in case
443 default:
444 AddLogLineM( true, wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
445 break;
449 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
450 lastbutton = ev.GetId();
455 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
457 wxString msg = wxT(" ");
458 #ifdef CLIENT_GUI
459 msg << _("aMule remote control ") << wxT(VERSION);
460 #else
461 msg << wxT("aMule ") << wxT(VERSION);
462 #endif
463 msg << wxT(" ");
464 #ifdef SVNDATE
465 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
466 #endif
467 msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
468 _("Website: http://www.amule.org \n") <<
469 _("Forum: http://forum.amule.org \n") <<
470 _("FAQ: http://wiki.amule.org \n\n") <<
471 _("Contact: admin@amule.org (administrative issues) \n") <<
472 _("Copyright (c) 2003-2008 aMule Team \n\n") <<
473 _("Part of aMule is based on \n") <<
474 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
475 _(" Copyright (c) 2002-2008 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
476 _("http://kademlia.scs.cs.nyu.edu\n");
478 if (m_is_safe_state) {
479 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
484 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
486 if (m_is_safe_state) {
487 if (m_prefsDialog == NULL) {
488 m_prefsDialog = new PrefsUnifiedDlg(this);
491 m_prefsDialog->TransferToWindow();
492 m_prefsDialog->Show(true);
493 m_prefsDialog->Raise();
498 #ifndef CLIENT_GUI
499 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
501 if ( m_is_safe_state ) {
502 CPartFileConvert::ShowGUI(NULL);
505 #endif
507 CamuleDlg::~CamuleDlg()
509 printf("Shutting down aMule...\n");
511 SaveGUIPrefs();
513 theApp->amuledlg = NULL;
515 #ifdef ENABLE_IP2COUNTRY
516 delete m_IP2Country;
517 #endif
519 printf("aMule dialog destroyed\n");
523 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
526 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
527 #ifndef CLIENT_GUI
528 || (Kademlia::CKademlia::IsRunning())
529 #endif
531 if (thePrefs::GetNetworkED2K()) {
532 if (disconnect) {
533 //disconnect if currently connected
534 if (theApp->serverconnect->IsConnecting()) {
535 theApp->serverconnect->StopConnectionTry();
536 } else {
537 theApp->serverconnect->Disconnect();
539 } else {
540 //connect if not currently connected
541 AddLogLine(true, _("Connecting"));
542 theApp->serverconnect->ConnectToAnyServer();
544 } else {
545 wxASSERT(!theApp->IsConnectedED2K());
548 // Connect Kad also
549 if (thePrefs::GetNetworkKademlia()) {
550 if( disconnect ) {
551 theApp->StopKad();
552 } else {
553 theApp->StartKad();
555 } else {
556 #ifndef CLIENT_GUI
557 wxASSERT(!Kademlia::CKademlia::IsRunning());
558 #endif
561 ShowConnectionState();
565 void CamuleDlg::ResetLog(int id)
567 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
568 wxCHECK_RET(ct, wxT("Resetting unknown log"));
570 ct->Clear();
572 if (id == ID_LOGVIEW) {
573 // Also clear the log line
574 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
575 text->SetLabel(wxEmptyString);
576 text->GetParent()->Layout();
581 void CamuleDlg::AddLogLine(bool addtostatusbar, const wxString& line)
583 // Remove newspace at end, it causes problems with the layout...
584 wxString bufferline = line.Strip(wxString::trailing);
586 // Create the timestamp
587 wxString stamp = wxDateTime::Now().FormatISODate() + wxT(" ") + wxDateTime::Now().FormatISOTime() + wxT(": ");
589 // Add the message to the log-view
590 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
591 if ( ct ) {
592 if ( bufferline.IsEmpty() ) {
593 // If it's empty we just write a blank line with no timestamp.
594 ct->AppendText( wxT("\n") );
595 } else {
596 // Bold critical log-lines
597 // Windows doesn't support this feature, and it causes GDI resource leaks
598 #ifndef __WXMSW__
599 wxTextAttr style = ct->GetDefaultStyle();
600 wxFont font = style.GetFont();
601 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
602 style.SetFont(font);
603 ct->SetDefaultStyle(style);
604 #endif
606 // Split multi-line messages into individual lines
607 wxStringTokenizer tokens( bufferline, wxT("\n") );
608 while ( tokens.HasMoreTokens() ) {
609 ct->AppendText( stamp + tokens.GetNextToken() + wxT("\n") );
613 ct->ShowPosition( ct->GetLastPosition() - 1 );
617 // Set the status-bar if the event warrents it
618 if ( addtostatusbar ) {
619 // Escape "&"s, which would otherwise not show up
620 bufferline.Replace( wxT("&"), wxT("&&") );
621 wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
622 // Only show the first line if multiple lines
623 text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
624 text->SetToolTip( bufferline );
625 text->GetParent()->Layout();
631 void CamuleDlg::AddServerMessageLine(wxString& message)
633 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
634 if(cv) {
635 if (message.Length() > 500) {
636 cv->AppendText(message.Left(500) + wxT("\n"));
637 } else {
638 cv->AppendText(message + wxT("\n"));
640 cv->ShowPosition(cv->GetLastPosition()-1);
645 void CamuleDlg::ShowConnectionState(bool skinChanged)
647 static wxImageList status_arrows(16,16,true,0);
648 if (!status_arrows.GetImageCount()) {
649 // Generate the image list (This is only done once)
650 for (int t = 0; t < 7; ++t) {
651 status_arrows.Add(connImages(t));
655 m_serverwnd->UpdateED2KInfo();
656 m_serverwnd->UpdateKadInfo();
659 ////////////////////////////////////////////////////////////
660 // Determine the status of the networks
662 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
663 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
665 ED2KState ed2kState = ED2KOff;
666 EKadState kadState = EKadOff;
668 ////////////////////////////////////////////////////////////
669 // Update the label on the status-bar and determine
670 // the states of the two networks.
672 wxString msgED2K;
673 if (theApp->IsConnectedED2K()) {
674 CServer* server = theApp->serverconnect->GetCurrentServer();
675 if (server) {
676 msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
679 if (theApp->serverconnect->IsLowID()) {
680 ed2kState = ED2KLowID;
681 } else {
682 ed2kState = ED2KHighID;
684 } else if (theApp->serverconnect->IsConnecting()) {
685 msgED2K = _("eD2k: Connecting");
687 ed2kState = ED2KConnecting;
688 } else if (thePrefs::GetNetworkED2K()) {
689 msgED2K = _("eD2k: Disconnected");
692 wxString msgKad;
693 if (theApp->IsConnectedKad()) {
694 if (theApp->IsFirewalledKad()) {
695 msgKad = _("Kad: Firewalled");
697 kadState = EKadFW;
698 } else {
699 msgKad = _("Kad: Connected");
701 kadState = EKadOK;
703 } else if (theApp->IsKadRunning()) {
704 msgKad = _("Kad: Connecting");
706 kadState = EKadConnecting;
707 } else if (thePrefs::GetNetworkKademlia()) {
708 msgKad = _("Kad: Off");
711 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
712 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
714 wxString labelMsg;
715 if (msgED2K.Length() && msgKad.Length()) {
716 labelMsg = msgED2K + wxT(" | ") + msgKad;
717 } else {
718 labelMsg = msgED2K + msgKad;
721 connLabel->SetLabel(labelMsg);
722 connLabel->GetParent()->Layout();
725 ////////////////////////////////////////////////////////////
726 // Update the connect/disconnect/cancel button.
728 enum EConnState {
729 ECS_Unknown,
730 ECS_Connected,
731 ECS_Connecting,
732 ECS_Disconnected
735 static EConnState s_oldState = ECS_Unknown;
736 EConnState currentState = ECS_Disconnected;
738 if (theApp->serverconnect->IsConnecting() ||
739 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
740 currentState = ECS_Connecting;
741 } else if (theApp->IsConnected()) {
742 currentState = ECS_Connected;
743 } else {
744 currentState = ECS_Disconnected;
747 if ( (true == skinChanged) || (currentState != s_oldState) ) {
748 wxWindowUpdateLocker freezer(m_wndToolbar);
750 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
752 switch (currentState) {
753 case ECS_Connecting:
754 toolbarTool->SetLabel(_("Cancel"));
755 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
756 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
757 break;
759 case ECS_Connected:
760 toolbarTool->SetLabel(_("Disconnect"));
761 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
762 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
763 break;
765 default:
766 toolbarTool->SetLabel(_("Connect"));
767 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
768 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
771 m_wndToolbar->InsertTool(0, toolbarTool);
772 m_wndToolbar->Realize();
774 s_oldState = currentState;
778 ////////////////////////////////////////////////////////////
779 // Update the globe-icon in the lower-right corner.
780 // (only if connection state has changed)
782 static ED2KState s_ED2KOldState = ED2KUndef;
783 static EKadState s_EKadOldState = EKadUndef;
784 if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
785 s_ED2KOldState = ed2kState;
786 s_EKadOldState = kadState;
787 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
788 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
790 wxBitmap statusIcon = connBitmap->GetBitmap();
791 // Sanity check - otherwise there's a crash here if aMule runs out of resources
792 if (statusIcon.GetRefData() == NULL) {
793 return;
796 wxMemoryDC bitmapDC(statusIcon);
798 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
799 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
801 connBitmap->SetBitmap(statusIcon);
806 void CamuleDlg::ShowUserCount(const wxString& info)
808 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
810 // Update Kad tab
811 m_serverwnd->UpdateKadInfo();
813 label->SetLabel(info);
814 label->GetParent()->Layout();
818 void CamuleDlg::ShowTransferRate()
820 float kBpsUp = theStats::GetUploadRate() / 1024.0;
821 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
822 wxString buffer;
823 if( thePrefs::ShowOverhead() )
825 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
826 } else {
827 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
829 buffer.Truncate(50); // Max size 50
831 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
832 label->SetLabel(buffer);
833 label->GetParent()->Layout();
835 // Show upload/download speed in title
836 if (thePrefs::GetShowRatesOnTitle()) {
837 wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
838 if (thePrefs::GetShowRatesOnTitle() == 1) {
839 SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
840 } else {
841 SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
845 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
846 if (m_wndTaskbarNotifier) {
847 // set trayicon-icon
848 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
849 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
851 wxString buffer2;
852 if ( theApp->IsConnected() ) {
853 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
854 } else {
855 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
857 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
860 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
861 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
864 void CamuleDlg::DlgShutDown()
866 // Are we already shutting down or still on init?
867 if ( m_is_safe_state == false ) {
868 return;
871 // we are going DOWN
872 m_is_safe_state = false;
874 // Stop the GUI Timer
875 delete gui_timer;
876 m_transferwnd->downloadlistctrl->DeleteAllItems();
878 // We want to delete the systray too!
879 RemoveSystray();
882 void CamuleDlg::OnClose(wxCloseEvent& evt)
884 // This will be here till the core close is != app close
885 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
886 if (wxNO == wxMessageBox(wxString(_("Do you really want to exit aMule?")),
887 wxString(_("Exit confirmation")), wxYES_NO, this)) {
888 evt.Veto();
889 return;
893 Enable(false);
894 Show(false);
896 theApp->ShutDown(evt);
900 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
902 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
904 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
905 wxString strlink = ctl->GetLineText(i);
906 strlink.Trim(true);
907 strlink.Trim(false);
908 if ( !strlink.IsEmpty() ) {
909 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
913 ctl->SetValue(wxEmptyString);
917 // Formerly known as LoadRazorPrefs()
918 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
920 // Create a config base for loading razor preferences
921 wxConfigBase *config = wxConfigBase::Get();
922 // If config haven't been created exit without loading
923 if (config == NULL) {
924 return false;
927 // The section where to save in in file
928 wxString section = wxT("/Razor_Preferences/");
930 // Get window size and position
931 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
932 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
933 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
934 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
936 int maximized = config->Read(section + wxT("Maximized"), 01);
938 // Kry - Random usable pos for m_srv_split_pos
939 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
940 if (!override_size) {
941 if (x2 > 0 && y2 > 0) {
942 SetSize(x2, y2);
943 } else {
944 #ifndef __WXGTK__
945 // Probably first run.
946 Maximize();
947 #endif
951 if (!override_pos) {
952 // If x1 and y1 != -1 Redefine location
953 if(x1 != -1 && y1 != -1) {
954 wxRect display = wxGetClientDisplayRect();
955 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
956 Move(x1, y1);
957 } else {
958 // It's offscreen... so let's not.
963 if (!override_size && !override_pos && maximized) {
964 Maximize();
967 return true;
971 bool CamuleDlg::SaveGUIPrefs()
973 /* Razor 1a - Modif by MikaelB
974 Save client size and position */
976 // Create a config base for saving razor preferences
977 wxConfigBase *config = wxConfigBase::Get();
978 // If config haven't been created exit without saving
979 if (config == NULL) {
980 return false;
982 // The section where to save in in file
983 wxString section = wxT("/Razor_Preferences/");
985 // Main window location and size
986 int x1, y1, x2, y2;
987 GetPosition(&x1, &y1);
988 GetSize(&x2, &y2);
990 // Saving window size and position
991 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
992 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
994 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
995 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
997 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
999 // Saving sash position of splitter in server window
1000 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
1002 config->Flush(true);
1004 /* End modif */
1006 return true;
1010 void CamuleDlg::DoIconize(bool iconize)
1012 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1013 if (iconize) {
1014 // Skip() will do it.
1015 //Iconize(true);
1016 if (SafeState()) {
1017 Show(false);
1019 } else {
1020 Show(true);
1021 Raise();
1023 } else {
1024 // Will be done by Skip();
1025 //Iconize(iconize);
1029 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1031 // Evil Hack: check if the mouse is inside the window
1032 #ifndef __WINDOWS__
1033 if (GetScreenRect().Contains(wxGetMousePosition()))
1034 #endif
1036 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1037 // Veto.
1038 } else {
1039 if (m_wndTaskbarNotifier) {
1040 DoIconize(evt.Iconized());
1042 evt.Skip();
1047 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1049 // Former TimerProc section
1051 static uint32 msPrev1, msPrev5, msPrevStats;
1053 uint32 msCur = theStats::GetUptimeMillis();
1055 // can this actually happen under wxwin ?
1056 if (!SafeState()) {
1057 return;
1060 #ifndef CLIENT_GUI
1061 static uint32 msPrevGraph;
1062 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1063 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1064 // trying to get the graph shifts evenly spaced after a change in the update period
1065 msPrevGraph = msCur;
1067 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1069 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1070 m_kademliawnd->UpdateGraph(update);
1072 #else
1073 //#warning TODO: CORE/GUI -- EC needed
1074 #endif
1076 int sStatsUpdate = thePrefs::GetStatsInterval();
1077 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1078 if (m_statisticswnd->IsShownOnScreen()) {
1079 msPrevStats = msCur;
1080 m_statisticswnd->ShowStatistics();
1084 if (msCur-msPrev5 > 5000) { // every 5 seconds
1085 msPrev5 = msCur;
1086 ShowTransferRate();
1087 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1088 m_transferwnd->UpdateCatTabTitles();
1090 if (thePrefs::AutoSortDownload()) {
1091 m_transferwnd->downloadlistctrl->SortList();
1095 if (msCur-msPrev1 > 1000) { // every second
1096 msPrev1 = msCur;
1097 if (m_CurrentBlinkBitmap == 12) {
1098 m_CurrentBlinkBitmap = 7;
1099 SetMessagesTool();
1100 } else {
1101 if (m_BlinkMessages) {
1102 m_CurrentBlinkBitmap = 12;
1103 SetMessagesTool();
1111 void CamuleDlg::SetMessagesTool()
1113 int pos = m_wndToolbar->GetToolPos(ID_BUTTONMESSAGES);
1114 wxASSERT(pos == 6); // so we don't miss a change on wx2.4
1116 wxWindowUpdateLocker freezer(m_wndToolbar);
1117 #ifdef __WXCOCOA__
1118 m_wndToolbar->FindById(ID_BUTTONMESSAGES)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1119 #else
1120 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1121 #endif
1124 void CamuleDlg::LaunchUrl( const wxString& url )
1126 wxString cmd;
1128 cmd = thePrefs::GetBrowser();
1129 wxString tmp = url;
1130 // Pipes cause problems, so escape them
1131 tmp.Replace( wxT("|"), wxT("%7C") );
1133 if ( !cmd.IsEmpty() ) {
1134 if (!cmd.Replace(wxT("%s"), tmp)) {
1135 // No %s found, just append the url
1136 cmd += wxT(" ") + tmp;
1139 CTerminationProcess *p = new CTerminationProcess(cmd);
1140 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1141 printf( "Launch Command: %s\n", (const char *)unicode2char(cmd));
1142 return;
1143 } else {
1144 delete p;
1146 } else {
1147 wxLaunchDefaultBrowser(tmp);
1148 return;
1150 // Unable to execute browser. But this error message doesn't make sense,
1151 // cosidering that you _can't_ set the browser executable path... =/
1152 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1156 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1158 wxString URL;
1159 switch (wsProvider) {
1160 case WS_FILEHASH:
1161 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1162 break;
1163 default:
1164 wxASSERT(0);
1166 URL.Replace(wxT("FILENAME"), filename);
1168 return URL;
1172 bool CamuleDlg::Check_and_Init_Skin()
1174 bool ret = true;
1175 wxString skinFileName(thePrefs::GetSkin());
1177 if (skinFileName.IsEmpty()) {
1178 return false;
1181 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1183 wxStandardPathsBase &spb(wxStandardPaths::Get());
1184 #ifdef __WXMSW__
1185 wxString dataDir(spb.GetPluginsDir());
1186 #elif defined(__WXMAC__)
1187 wxString dataDir(spb.GetDataDir());
1188 #else
1189 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1190 #endif
1191 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1194 skinFileName.Replace(wxT("User:"), userDir );
1195 skinFileName.Replace(wxT("System:"), systemDir );
1197 m_skinFileName.Assign(skinFileName);
1198 if (!m_skinFileName.FileExists()) {
1199 AddLogLineM(true, CFormat(
1200 _("Skin directory '%s' does not exist")) %
1201 skinFileName );
1202 ret = false;
1203 } else if (!m_skinFileName.IsFileReadable()) {
1204 AddLogLineM(true, CFormat(
1205 _("WARNING: Unable to open skin file '%s' for read")) %
1206 skinFileName);
1207 ret = false;
1210 wxFFileInputStream in(m_skinFileName.GetFullPath());
1211 wxZipInputStream zip(in);
1213 while ((entry = zip.GetNextEntry()) != NULL) {
1214 wxZipEntry*& current = cat[entry->GetInternalName()];
1215 delete current;
1216 current = entry;
1219 return ret;
1223 void CamuleDlg::Add_Skin_Icon(
1224 const wxString &iconName,
1225 const wxBitmap &stdIcon,
1226 bool useSkins)
1228 wxImage new_image;
1229 if (useSkins) {
1230 wxFFileInputStream in(m_skinFileName.GetFullPath());
1231 wxZipInputStream zip(in);
1233 it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")));
1234 if ( it != cat.end() ) {
1235 zip.OpenEntry(*it->second);
1236 if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) {
1237 AddLogLineM(false,
1238 wxT("Warning: Error loading icon for ") +
1239 iconName);
1240 useSkins = false;
1242 }else {
1243 AddLogLineM(false,
1244 wxT("Warning: Can't load icon for ") +
1245 iconName);
1246 useSkins = false;
1251 wxBitmap bmp(useSkins ? new_image : stdIcon);
1252 if (iconName.StartsWith(wxT("Client_"))) {
1253 m_imagelist.Add(bmp);
1254 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1255 m_tblist.Add(bmp);
1260 void CamuleDlg::Apply_Clients_Skin()
1262 bool useSkins = Check_and_Init_Skin();
1264 // Clear the client image list
1265 m_imagelist.RemoveAll();
1267 // Add the images to the image list
1268 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1269 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1270 clientImages(i), useSkins);
1275 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1277 bool useSkins = Check_and_Init_Skin();
1280 // Clear the toolbar image list
1281 m_tblist.RemoveAll();
1283 // Add the images to the image list
1284 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1285 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1286 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1287 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1288 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1289 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1290 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1291 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1292 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1293 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1294 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1295 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1296 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1298 // Build aMule toolbar
1299 wndToolbar->SetMargins(0, 0);
1301 // Placeholder. Gets updated by ShowConnectionState
1302 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1304 wndToolbar->AddSeparator();
1305 wndToolbar->AddTool(ID_BUTTONNETWORKS,
1306 _("Networks"), m_tblist.GetBitmap(3),
1307 wxNullBitmap, wxITEM_CHECK,
1308 _("Networks window"));
1309 wndToolbar->AddTool(ID_BUTTONSEARCH,
1310 _("Searches"), m_tblist.GetBitmap(5),
1311 wxNullBitmap, wxITEM_CHECK,
1312 _("Searches window"));
1313 wndToolbar->AddTool(ID_BUTTONTRANSFER,
1314 _("Transfers"), m_tblist.GetBitmap(4),
1315 wxNullBitmap, wxITEM_CHECK,
1316 _("Files transfers window"));
1317 wndToolbar->AddTool(ID_BUTTONSHARED,
1318 _("Shared files"), m_tblist.GetBitmap(6),
1319 wxNullBitmap, wxITEM_CHECK,
1320 _("Shared files window"));
1321 wndToolbar->AddTool(ID_BUTTONMESSAGES,
1322 _("Messages"), m_tblist.GetBitmap(7),
1323 wxNullBitmap, wxITEM_CHECK,
1324 _("Messages window"));
1325 wndToolbar->AddTool(ID_BUTTONSTATISTICS,
1326 _("Statistics"), m_tblist.GetBitmap(8),
1327 wxNullBitmap, wxITEM_CHECK,
1328 _("Statistics graph window"));
1329 wndToolbar->AddSeparator();
1330 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES,
1331 _("Preferences"), m_tblist.GetBitmap(9),
1332 wxNullBitmap, wxITEM_NORMAL,
1333 _("Preferences settings window"));
1334 wndToolbar->AddTool(ID_BUTTONIMPORT,
1335 _("Import"), m_tblist.GetBitmap(10),
1336 wxNullBitmap, wxITEM_NORMAL,
1337 _("The partfile importer tool"));
1338 wndToolbar->AddTool(ID_ABOUT,
1339 _("About"), m_tblist.GetBitmap(11),
1340 wxNullBitmap, wxITEM_NORMAL,
1341 _("About/Help"));
1343 wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true);
1345 // Needed for non-GTK platforms, where the
1346 // items don't get added immediatly.
1347 wndToolbar->Realize();
1349 // Updates the "Connect" button, and so on.
1350 ShowConnectionState(true);
1354 void CamuleDlg::Create_Toolbar(bool orientation)
1356 Freeze();
1357 // Create ToolBar from the one designed by wxDesigner (BigBob)
1358 wxToolBar *current = GetToolBar();
1360 wxASSERT(current == m_wndToolbar);
1362 if (current) {
1363 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1364 if (oldorientation != orientation) {
1365 current->Destroy();
1366 SetToolBar(NULL); // Remove old one if present
1367 m_wndToolbar = NULL;
1368 } else {
1369 current->ClearTools();
1373 if (!m_wndToolbar) {
1374 m_wndToolbar = CreateToolBar(
1375 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1376 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1377 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1380 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1383 Apply_Toolbar_Skin(m_wndToolbar);
1384 #ifdef CLIENT_GUI
1385 m_wndToolbar->DeleteTool(ID_BUTTONIMPORT);
1386 #endif
1388 Thaw();
1392 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1394 wxFrame::OnSize(evt);
1395 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1396 // Transfer window's splitter set again if it's hidden.
1397 if (m_transferwnd->clientlistctrl->GetListView() == vtNone) {
1398 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1399 wxSplitterWindow* splitter =
1400 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1401 height += splitter->GetWindow1()->GetSize().GetHeight();
1402 splitter->SetSashPosition( height );
1409 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1411 if (event.GetKeyCode() == WXK_F1) {
1412 // Ctrl/Alt/Shift must not be pressed, to avoid
1413 // conflicts with other (global) shortcuts.
1414 if (!event.HasModifiers() && !event.ShiftDown()) {
1415 LaunchUrl(wxT("http://wiki.amule.org"));
1416 return;
1420 event.Skip();
1424 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1426 Close();
1429 void CamuleDlg::DoNetworkRearrange()
1432 wxWindowUpdateLocker freezer(this);
1434 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1436 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1437 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1439 while (logs_notebook->GetPageCount() > 1) {
1440 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1443 while (networks_notebook->GetPageCount() > 0) {
1444 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1447 if (thePrefs::GetNetworkED2K()) {
1448 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1449 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1452 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1454 if (thePrefs::GetNetworkKademlia()) {
1455 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1458 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1460 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1462 wxWindow* replacement = NULL;
1464 m_networknotebooksizer->Clear();
1466 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1467 toolbarTool->SetLabel(_("Networks"));
1469 m_networkpages[0].page->Reparent(networks_notebook);
1470 m_networkpages[1].page->Reparent(networks_notebook);
1472 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1473 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1475 replacement = networks_notebook;
1477 } else if (thePrefs::GetNetworkED2K()) {
1478 toolbarTool->SetLabel(_("eD2k network"));
1479 replacement = m_networkpages[0].page;
1480 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1481 } else if (thePrefs::GetNetworkKademlia()) {
1482 toolbarTool->SetLabel(_("Kad network"));
1483 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1484 replacement = m_networkpages[1].page;
1485 } else {
1486 // No networks.
1487 toolbarTool->SetLabel(_("No network"));
1490 if (replacement) {
1491 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1492 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1493 m_networknotebooksizer->Layout();
1496 m_wndToolbar->InsertTool(2, toolbarTool);
1498 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1499 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1501 m_wndToolbar->Realize();
1503 m_searchwnd->FixSearchTypes();
1506 // File_checked_for_headers