3 // This file is part of the aMule Project.
5 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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.
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
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>
46 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
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
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
76 #include "PartFileConvertDlg.h"
84 #include "kademlia/kademlia/Kademlia.h"
86 #ifdef ENABLE_IP2COUNTRY
87 #include "IP2Country.h" // Needed for IP2Country
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();
106 void CamuleDlg::IP2CountryDownloadFinished(uint32
){}
107 void CamuleDlg::EnableIP2Country(){}
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
)
142 #define wxCLOSE_BOX 0
145 CamuleDlg::CamuleDlg(
147 const wxString
&title
,
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
,
159 m_sharedfileswnd(NULL
),
162 m_statisticswnd(NULL
),
168 m_prefsVisible(false),
170 m_wndTaskbarNotifier(NULL
),
171 m_nActiveDialog(DT_NETWORKS_WND
),
172 m_is_safe_state(false),
173 m_BlinkMessages(false),
174 m_CurrentBlinkBitmap(24),
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();
215 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
218 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
219 // this crashes on Mac with wx 2.9
220 SetIcon(wxICON(aMule
));
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
);
249 m_GeoIPavailable
= false;
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
);
268 AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
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") );
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();
297 if (thePrefs::UseTrayIcon()) {
302 // Must we start minimized?
303 if (thePrefs::GetStartMinimized()) {
308 wxAcceleratorEntry entries
[] = {
309 wxAcceleratorEntry(wxACCEL_CTRL
, wxT('Q'), wxID_EXIT
)
312 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries
), entries
));
313 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
315 wxNotebook
* logs_notebook
= CastChild( ID_SRVLOG_NOTEBOOK
, wxNotebook
);
316 wxNotebook
* networks_notebook
= CastChild( ID_NETNOTEBOOK
, wxNotebook
);
318 wxASSERT(logs_notebook
->GetPageCount() == 4);
319 wxASSERT(networks_notebook
->GetPageCount() == 2);
321 for (uint32 i
= 0; i
< logs_notebook
->GetPageCount(); ++i
) {
322 m_logpages
[i
].page
= logs_notebook
->GetPage(i
);
323 m_logpages
[i
].name
= logs_notebook
->GetPageText(i
);
326 for (uint32 i
= 0; i
< networks_notebook
->GetPageCount(); ++i
) {
327 m_networkpages
[i
].page
= networks_notebook
->GetPage(i
);
328 m_networkpages
[i
].name
= networks_notebook
->GetPageText(i
);
331 DoNetworkRearrange();
335 // Madcat - Sets Fast ED2K Links Handler on/off.
336 void CamuleDlg::ShowED2KLinksHandler( bool show
)
338 // Errorchecking in case the pointer becomes invalid ...
339 if (s_fed2klh
== NULL
) {
340 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
344 s_dlgcnt
->Show( s_fed2klh
, show
);
348 // Toogles ed2k link handler.
349 void CamuleDlg::ToogleED2KLinksHandler()
351 // Errorchecking in case the pointer becomes invalid ...
352 if (s_fed2klh
== NULL
) {
353 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
356 ShowED2KLinksHandler(!s_dlgcnt
->IsShown(s_fed2klh
));
359 void CamuleDlg::SetActiveDialog(DialogType type
, wxWindow
* dlg
)
361 m_nActiveDialog
= type
;
363 if ( type
== DT_TRANSFER_WND
) {
364 if (thePrefs::ShowCatTabInfos()) {
365 m_transferwnd
->UpdateCatTabTitles();
370 m_activewnd
->Show(false);
371 contentSizer
->Detach(m_activewnd
);
374 contentSizer
->Add(dlg
, 1, wxALIGN_LEFT
|wxEXPAND
);
379 // Since we might be suspending redrawing while hiding the dialog
380 // we have to refresh it once it is visible again
381 dlg
->Refresh( true );
384 if ( type
== DT_SHARED_WND
) {
385 // set up splitter now that window sizes are defined
386 m_sharedfileswnd
->Prepare();
391 void CamuleDlg::UpdateTrayIcon(int percent
)
394 if(!theApp
->IsConnected()) {
395 m_wndTaskbarNotifier
->SetTrayIcon(TRAY_ICON_DISCONNECTED
, percent
);
397 if(theApp
->IsConnectedED2K() && theApp
->serverconnect
->IsLowID()) {
398 m_wndTaskbarNotifier
->SetTrayIcon(TRAY_ICON_LOWID
, percent
);
400 m_wndTaskbarNotifier
->SetTrayIcon(TRAY_ICON_HIGHID
, percent
);
406 void CamuleDlg::CreateSystray()
408 wxCHECK_RET(m_wndTaskbarNotifier
== NULL
,
409 wxT("Systray already created"));
411 m_wndTaskbarNotifier
= new CMuleTrayIcon();
412 // This will effectively show the Tray Icon.
417 void CamuleDlg::RemoveSystray()
419 delete m_wndTaskbarNotifier
;
420 m_wndTaskbarNotifier
= NULL
;
424 void CamuleDlg::OnToolBarButton(wxCommandEvent
& ev
)
426 static int lastbutton
= ID_BUTTONDOWNLOADS
;
428 // Kry - just if the GUI is ready for it
429 if ( m_is_safe_state
) {
431 // Rehide the handler if needed
432 if ( lastbutton
== ID_BUTTONSEARCH
&& !thePrefs::GetFED2KLH() ) {
433 if (ev
.GetId() != ID_BUTTONSEARCH
) {
434 ShowED2KLinksHandler( false );
436 // Toogle ED2K handler.
437 ToogleED2KLinksHandler();
441 if ( lastbutton
!= ev
.GetId() ) {
442 switch ( ev
.GetId() ) {
443 case ID_BUTTONNETWORKS
:
444 SetActiveDialog(DT_NETWORKS_WND
, m_serverwnd
);
445 // Set serverlist splitter position
446 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow
)->SetSashPosition(m_srv_split_pos
, true);
449 case ID_BUTTONSEARCH
:
450 // The search dialog should always display the handler
451 if ( !thePrefs::GetFED2KLH() )
452 ShowED2KLinksHandler( true );
454 SetActiveDialog(DT_SEARCH_WND
, m_searchwnd
);
457 case ID_BUTTONDOWNLOADS
:
458 SetActiveDialog(DT_TRANSFER_WND
, m_transferwnd
);
459 // Prepare the dialog, sets the splitter-position
460 m_transferwnd
->Prepare();
463 case ID_BUTTONSHARED
:
464 SetActiveDialog(DT_SHARED_WND
, m_sharedfileswnd
);
467 case ID_BUTTONMESSAGES
:
468 m_BlinkMessages
= false;
469 SetActiveDialog(DT_CHAT_WND
, m_chatwnd
);
472 case ID_BUTTONSTATISTICS
:
473 SetActiveDialog(DT_STATS_WND
, m_statisticswnd
);
476 // This shouldn't happen, but just in case
478 AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
483 m_wndToolbar
->ToggleTool(lastbutton
, lastbutton
== ev
.GetId() );
484 lastbutton
= ev
.GetId();
489 void CamuleDlg::OnAboutButton(wxCommandEvent
& WXUNUSED(ev
))
491 wxString msg
= wxT(" ");
493 msg
<< _("aMule remote control ") << wxT(VERSION
);
495 msg
<< wxT("aMule ") << wxT(VERSION
);
499 msg
<< _("Snapshot:") << wxT("\n ") << wxT(SVNDATE
);
501 msg
<< wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
502 _("Website: http://www.amule.org \n") <<
503 _("Forum: http://forum.amule.org \n") <<
504 _("FAQ: http://wiki.amule.org \n\n") <<
505 _("Contact: admin@amule.org (administrative issues) \n") <<
506 _("Copyright (c) 2003-2011 aMule Team \n\n") <<
507 _("Part of aMule is based on \n") <<
508 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
509 _(" Copyright (c) 2002-2011 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
510 _("http://kademlia.scs.cs.nyu.edu\n");
512 if (m_is_safe_state
) {
513 wxMessageBox(msg
, _("Message"), wxOK
| wxICON_INFORMATION
, this);
518 void CamuleDlg::OnPrefButton(wxCommandEvent
& WXUNUSED(ev
))
520 if (m_is_safe_state
) {
521 if (m_prefsDialog
== NULL
) {
522 m_prefsDialog
= new PrefsUnifiedDlg(this);
525 m_prefsDialog
->TransferToWindow();
526 m_prefsDialog
->Show(true);
527 m_prefsDialog
->Raise();
532 void CamuleDlg::OnImportButton(wxCommandEvent
& WXUNUSED(ev
))
535 if (m_is_safe_state
) {
536 CPartFileConvertDlg::ShowGUI(NULL
);
542 CamuleDlg::~CamuleDlg()
544 theApp
->amuledlg
= NULL
;
546 #ifdef ENABLE_IP2COUNTRY
550 AddLogLineN(_("aMule dialog destroyed"));
554 void CamuleDlg::OnBnConnect(wxCommandEvent
& WXUNUSED(evt
))
557 bool disconnect
= (theApp
->IsConnectedED2K() || theApp
->serverconnect
->IsConnecting())
559 || theApp
->IsConnectedKad() // there's no Kad running state atm
561 || (Kademlia::CKademlia::IsRunning())
564 if (thePrefs::GetNetworkED2K()) {
566 //disconnect if currently connected
567 if (theApp
->serverconnect
->IsConnecting()) {
568 theApp
->serverconnect
->StopConnectionTry();
570 theApp
->serverconnect
->Disconnect();
573 //connect if not currently connected
574 AddLogLineC(_("Connecting"));
575 theApp
->serverconnect
->ConnectToAnyServer();
578 wxASSERT(!theApp
->IsConnectedED2K());
582 if (thePrefs::GetNetworkKademlia()) {
590 wxASSERT(!Kademlia::CKademlia::IsRunning());
594 ShowConnectionState();
598 void CamuleDlg::ResetLog(int id
)
600 wxTextCtrl
* ct
= CastByID(id
, m_serverwnd
, wxTextCtrl
);
601 wxCHECK_RET(ct
, wxT("Resetting unknown log"));
605 if (id
== ID_LOGVIEW
) {
606 // Also clear the log line
607 wxStaticText
* text
= CastChild(wxT("infoLabel"), wxStaticText
);
608 text
->SetLabel(wxEmptyString
);
609 text
->GetParent()->Layout();
614 void CamuleDlg::AddLogLine(const wxString
& line
)
616 bool addtostatusbar
= line
[0] == '!';
617 wxString bufferline
= line
.Mid(1);
619 // Add the message to the log-view
620 wxTextCtrl
* ct
= CastByID( ID_LOGVIEW
, m_serverwnd
, wxTextCtrl
);
622 // Bold critical log-lines
623 // Works in Windows too thanks to wxTE_RICH2 style in muuli
624 wxTextAttr style
= ct
->GetDefaultStyle();
625 wxFont font
= style
.GetFont();
626 font
.SetWeight(addtostatusbar
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
628 #if wxCHECK_VERSION(2, 9, 0)
629 style
.SetFontSize(8);
631 ct
->SetDefaultStyle(style
);
632 ct
->AppendText(bufferline
);
633 ct
->ShowPosition( ct
->GetLastPosition() - 1 );
637 // Set the status-bar if the event warrents it
638 if ( addtostatusbar
) {
639 // Escape "&"s, which would otherwise not show up
640 bufferline
.Replace( wxT("&"), wxT("&&") );
641 wxStaticText
* text
= CastChild( wxT("infoLabel"), wxStaticText
);
642 // Only show the first line if multiple lines
643 text
->SetLabel( bufferline
.BeforeFirst( wxT('\n') ) );
644 text
->SetToolTip( bufferline
);
645 text
->GetParent()->Layout();
651 void CamuleDlg::AddServerMessageLine(wxString
& message
)
653 wxTextCtrl
* cv
= CastByID( ID_SERVERINFO
, m_serverwnd
, wxTextCtrl
);
655 if (message
.Length() > 500) {
656 cv
->AppendText(message
.Left(500) + wxT("\n"));
658 cv
->AppendText(message
+ wxT("\n"));
660 cv
->ShowPosition(cv
->GetLastPosition()-1);
665 void CamuleDlg::ShowConnectionState(bool skinChanged
)
667 static wxImageList
status_arrows(16,16,true,0);
668 if (!status_arrows
.GetImageCount()) {
669 // Generate the image list (This is only done once)
670 for (int t
= 0; t
< 7; ++t
) {
671 status_arrows
.Add(connImages(t
));
675 m_serverwnd
->UpdateED2KInfo();
676 m_serverwnd
->UpdateKadInfo();
679 ////////////////////////////////////////////////////////////
680 // Determine the status of the networks
682 enum ED2KState
{ ED2KOff
= 0, ED2KLowID
= 1, ED2KConnecting
= 2, ED2KHighID
= 3, ED2KUndef
= -1 };
683 enum EKadState
{ EKadOff
= 4, EKadFW
= 5, EKadConnecting
= 5, EKadOK
= 6, EKadUndef
= -1 };
685 ED2KState ed2kState
= ED2KOff
;
686 EKadState kadState
= EKadOff
;
688 ////////////////////////////////////////////////////////////
689 // Update the label on the status-bar and determine
690 // the states of the two networks.
693 if (theApp
->IsConnectedED2K()) {
694 CServer
* server
= theApp
->serverconnect
->GetCurrentServer();
696 msgED2K
= CFormat(wxT("eD2k: %s")) % server
->GetListName();
699 if (theApp
->serverconnect
->IsLowID()) {
700 ed2kState
= ED2KLowID
;
702 ed2kState
= ED2KHighID
;
704 } else if (theApp
->serverconnect
->IsConnecting()) {
705 msgED2K
= _("eD2k: Connecting");
707 ed2kState
= ED2KConnecting
;
708 } else if (thePrefs::GetNetworkED2K()) {
709 msgED2K
= _("eD2k: Disconnected");
713 if (theApp
->IsConnectedKad()) {
714 if (theApp
->IsFirewalledKad()) {
715 msgKad
= _("Kad: Firewalled");
719 msgKad
= _("Kad: Connected");
723 } else if (theApp
->IsKadRunning()) {
724 msgKad
= _("Kad: Connecting");
726 kadState
= EKadConnecting
;
727 } else if (thePrefs::GetNetworkKademlia()) {
728 msgKad
= _("Kad: Off");
731 wxStaticText
* connLabel
= CastChild( wxT("connLabel"), wxStaticText
);
732 { wxCHECK_RET(connLabel
, wxT("'connLabel' widget not found")); }
735 if (msgED2K
.Length() && msgKad
.Length()) {
736 labelMsg
= msgED2K
+ wxT(" | ") + msgKad
;
738 labelMsg
= msgED2K
+ msgKad
;
741 connLabel
->SetLabel(labelMsg
);
742 connLabel
->GetParent()->Layout();
745 ////////////////////////////////////////////////////////////
746 // Update the connect/disconnect/cancel button.
755 static EConnState s_oldState
= ECS_Unknown
;
756 EConnState currentState
= ECS_Disconnected
;
758 if (theApp
->serverconnect
->IsConnecting() ||
759 (theApp
->IsKadRunning() && !theApp
->IsConnectedKad())) {
760 currentState
= ECS_Connecting
;
761 } else if (theApp
->IsConnected()) {
762 currentState
= ECS_Connected
;
764 currentState
= ECS_Disconnected
;
767 if ( (true == skinChanged
) || (currentState
!= s_oldState
) ) {
768 wxWindowUpdateLocker
freezer(m_wndToolbar
);
770 wxToolBarToolBase
* toolbarTool
= m_wndToolbar
->RemoveTool(ID_BUTTONCONNECT
);
772 switch (currentState
) {
774 toolbarTool
->SetLabel(_("Cancel"));
775 toolbarTool
->SetShortHelp(_("Stop the current connection attempts"));
776 toolbarTool
->SetNormalBitmap(m_tblist
.GetBitmap(2));
780 toolbarTool
->SetLabel(_("Disconnect"));
781 toolbarTool
->SetShortHelp(_("Disconnect from the currently connected networks"));
782 toolbarTool
->SetNormalBitmap(m_tblist
.GetBitmap(1));
786 toolbarTool
->SetLabel(_("Connect"));
787 toolbarTool
->SetShortHelp(_("Connect to the currently enabled networks"));
788 toolbarTool
->SetNormalBitmap(m_tblist
.GetBitmap(0));
791 m_wndToolbar
->InsertTool(0, toolbarTool
);
792 m_wndToolbar
->Realize();
793 m_wndToolbar
->EnableTool(ID_BUTTONCONNECT
, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp
->ipfilter
->IsReady());
795 s_oldState
= currentState
;
799 ////////////////////////////////////////////////////////////
800 // Update the globe-icon in the lower-right corner.
801 // (only if connection state has changed)
803 static ED2KState s_ED2KOldState
= ED2KUndef
;
804 static EKadState s_EKadOldState
= EKadUndef
;
805 if (ed2kState
!= s_ED2KOldState
|| kadState
!= s_EKadOldState
) {
806 s_ED2KOldState
= ed2kState
;
807 s_EKadOldState
= kadState
;
808 wxStaticBitmap
* connBitmap
= CastChild( wxT("connImage"), wxStaticBitmap
);
809 wxCHECK_RET(connBitmap
, wxT("'connImage' widget not found"));
811 wxBitmap statusIcon
= connBitmap
->GetBitmap();
812 // Sanity check - otherwise there's a crash here if aMule runs out of resources
813 if (statusIcon
.GetRefData() == NULL
) {
817 wxMemoryDC
bitmapDC(statusIcon
);
819 status_arrows
.Draw(kadState
, bitmapDC
, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT
);
820 status_arrows
.Draw(ed2kState
, bitmapDC
, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT
);
822 connBitmap
->SetBitmap(statusIcon
);
827 void CamuleDlg::ShowUserCount(const wxString
& info
)
829 wxStaticText
* label
= CastChild( wxT("userLabel"), wxStaticText
);
832 m_serverwnd
->UpdateKadInfo();
834 label
->SetLabel(info
);
835 label
->GetParent()->Layout();
839 void CamuleDlg::ShowTransferRate()
841 float kBpsUp
= theStats::GetUploadRate() / 1024.0;
842 float kBpsDown
= theStats::GetDownloadRate() / 1024.0;
844 if( thePrefs::ShowOverhead() )
846 buffer
= CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp
% (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown
% (theStats::GetDownOverheadRate() / 1024.0);
848 buffer
= CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp
% kBpsDown
;
850 buffer
.Truncate(50); // Max size 50
852 wxStaticText
* label
= CastChild( wxT("speedLabel"), wxStaticText
);
853 label
->SetLabel(buffer
);
854 label
->GetParent()->Layout();
856 // Show upload/download speed in title
857 if (thePrefs::GetShowRatesOnTitle()) {
858 wxString UpDownSpeed
= CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp
% kBpsDown
;
859 if (thePrefs::GetShowRatesOnTitle() == 1) {
860 SetTitle(theApp
->m_FrameTitle
+ wxT(" -- ") + UpDownSpeed
);
862 SetTitle(UpDownSpeed
+ wxT(" -- ") + theApp
->m_FrameTitle
);
866 wxASSERT((m_wndTaskbarNotifier
!= NULL
) == thePrefs::UseTrayIcon());
867 if (m_wndTaskbarNotifier
) {
869 int percentDown
= (int)ceil((kBpsDown
*100) / thePrefs::GetMaxGraphDownloadRate());
870 UpdateTrayIcon( ( percentDown
> 100 ) ? 100 : percentDown
);
873 if ( theApp
->IsConnected() ) {
874 buffer2
= CFormat(_("aMule (%s | Connected)")) % buffer
;
876 buffer2
= CFormat(_("aMule (%s | Disconnected)")) % buffer
;
878 m_wndTaskbarNotifier
->SetTrayToolTip(buffer2
);
881 wxStaticBitmap
* bmp
= CastChild( wxT("transferImg"), wxStaticBitmap
);
882 bmp
->SetBitmap(dlStatusImages((kBpsUp
>0.01 ? 2 : 0) + (kBpsDown
>0.01 ? 1 : 0)));
885 void CamuleDlg::DlgShutDown()
887 // Are we already shutting down or still on init?
888 if ( m_is_safe_state
== false ) {
893 m_is_safe_state
= false;
895 // Stop the GUI Timer
897 m_transferwnd
->downloadlistctrl
->DeleteAllItems();
899 // We want to delete the systray too!
903 void CamuleDlg::OnClose(wxCloseEvent
& evt
)
905 if (thePrefs::HideOnClose() && evt
.CanVeto()) {
911 // This will be here till the core close is != app close
912 if (evt
.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
913 if (wxNO
== wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp
->GetMuleAppName()),
914 wxString(_("Exit confirmation")), wxYES_NO
, this)) {
925 theApp
->ShutDown(evt
);
929 void CamuleDlg::OnBnClickedFast(wxCommandEvent
& WXUNUSED(evt
))
931 wxTextCtrl
* ctl
= CastChild( wxT("FastEd2kLinks"), wxTextCtrl
);
933 for ( int i
= 0; i
< ctl
->GetNumberOfLines(); i
++ ) {
934 wxString strlink
= ctl
->GetLineText(i
);
937 if ( !strlink
.IsEmpty() ) {
938 theApp
->downloadqueue
->AddLink( strlink
, m_transferwnd
->downloadlistctrl
->GetCategory() );
942 ctl
->SetValue(wxEmptyString
);
946 // Formerly known as LoadRazorPrefs()
947 bool CamuleDlg::LoadGUIPrefs(bool override_pos
, bool override_size
)
949 // Create a config base for loading razor preferences
950 wxConfigBase
*config
= wxConfigBase::Get();
951 // If config haven't been created exit without loading
952 if (config
== NULL
) {
956 // The section where to save in in file
957 wxString section
= wxT("/Razor_Preferences/");
959 // Get window size and position
960 int x1
= config
->Read(section
+ wxT("MAIN_X_POS"), -1);
961 int y1
= config
->Read(section
+ wxT("MAIN_Y_POS"), -1);
962 int x2
= config
->Read(section
+ wxT("MAIN_X_SIZE"), -1);
963 int y2
= config
->Read(section
+ wxT("MAIN_Y_SIZE"), -1);
965 int maximized
= config
->Read(section
+ wxT("Maximized"), 01);
967 // Kry - Random usable pos for m_srv_split_pos
968 m_srv_split_pos
= config
->Read(section
+ wxT("SRV_SPLITTER_POS"), 463l);
969 if (!override_size
) {
970 if (x2
> 0 && y2
> 0) {
974 // Probably first run.
981 // If x1 and y1 != -1 Redefine location
982 if(x1
!= -1 && y1
!= -1) {
983 wxRect display
= wxGetClientDisplayRect();
984 if (x1
<= display
.GetRightTop().x
&& y1
<= display
.GetRightBottom().y
) {
987 // It's offscreen... so let's not.
992 if (!override_size
&& !override_pos
&& maximized
) {
1000 bool CamuleDlg::SaveGUIPrefs()
1002 /* Razor 1a - Modif by MikaelB
1003 Save client size and position */
1005 // Create a config base for saving razor preferences
1006 wxConfigBase
*config
= wxConfigBase::Get();
1007 // If config haven't been created exit without saving
1008 if (config
== NULL
) {
1011 // The section where to save in in file
1012 wxString section
= wxT("/Razor_Preferences/");
1014 if (!IsIconized()) {
1015 // Main window location and size
1017 GetPosition(&x1
, &y1
);
1020 // Saving window size and position
1021 config
->Write(section
+wxT("MAIN_X_POS"), (long) x1
);
1022 config
->Write(section
+wxT("MAIN_Y_POS"), (long) y1
);
1024 config
->Write(section
+wxT("MAIN_X_SIZE"), (long) x2
);
1025 config
->Write(section
+wxT("MAIN_Y_SIZE"), (long) y2
);
1027 config
->Write(section
+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1030 // Saving sash position of splitter in server window
1031 config
->Write(section
+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos
);
1033 config
->Flush(true);
1041 void CamuleDlg::DoIconize(bool iconize
)
1043 if (m_wndTaskbarNotifier
&& thePrefs::DoMinToTray()) {
1045 // Skip() will do it.
1055 // Will be done by Skip();
1060 void CamuleDlg::OnMinimize(wxIconizeEvent
& evt
)
1062 // Evil Hack: check if the mouse is inside the window
1064 if (GetScreenRect().Contains(wxGetMousePosition()))
1067 if (m_prefsDialog
&& m_prefsDialog
->IsShown()) {
1070 if (m_wndTaskbarNotifier
) {
1071 #if wxCHECK_VERSION(2, 9, 0)
1072 DoIconize(evt
.IsIconized());
1074 DoIconize(evt
.Iconized());
1082 void CamuleDlg::OnGUITimer(wxTimerEvent
& WXUNUSED(evt
))
1084 // Former TimerProc section
1086 static uint32 msPrev1
, msPrev5
;
1088 uint32 msCur
= theStats::GetUptimeMillis();
1090 // can this actually happen under wxwin ?
1096 static uint32 msPrevGraph
, msPrevStats
;
1097 int msGraphUpdate
= thePrefs::GetTrafficOMeterInterval() * 1000;
1098 if ((msGraphUpdate
> 0) && ((msCur
/ msGraphUpdate
) > (msPrevGraph
/ msGraphUpdate
))) {
1099 // trying to get the graph shifts evenly spaced after a change in the update period
1100 msPrevGraph
= msCur
;
1102 GraphUpdateInfo update
= theApp
->m_statistics
->GetPointsForUpdate();
1104 m_statisticswnd
->UpdateStatGraphs(theStats::GetPeakConnections(), update
);
1105 m_kademliawnd
->UpdateGraph(update
);
1108 int sStatsUpdate
= thePrefs::GetStatsInterval();
1109 if ((sStatsUpdate
> 0) && ((int)(msCur
- msPrevStats
) > sStatsUpdate
*1000)) {
1110 if (m_statisticswnd
->IsShownOnScreen()) {
1111 msPrevStats
= msCur
;
1112 m_statisticswnd
->ShowStatistics();
1117 if (msCur
-msPrev5
> 5000) { // every 5 seconds
1120 if (thePrefs::ShowCatTabInfos() && theApp
->amuledlg
->m_activewnd
== theApp
->amuledlg
->m_transferwnd
) {
1121 m_transferwnd
->UpdateCatTabTitles();
1123 if (thePrefs::AutoSortDownload()) {
1124 m_transferwnd
->downloadlistctrl
->SortList();
1125 m_transferwnd
->clientlistctrl
->SortList();
1126 m_sharedfileswnd
->peerslistctrl
->SortList();
1130 if (msCur
-msPrev1
> 1000) { // every second
1132 if (m_CurrentBlinkBitmap
== 12) {
1133 m_CurrentBlinkBitmap
= 7;
1136 if (m_BlinkMessages
) {
1137 m_CurrentBlinkBitmap
= 12;
1146 void CamuleDlg::SetMessagesTool()
1148 wxWindowUpdateLocker
freezer(m_wndToolbar
);
1150 m_wndToolbar
->FindById(ID_BUTTONMESSAGES
)->SetNormalBitmap(m_tblist
.GetBitmap(m_CurrentBlinkBitmap
));
1152 m_wndToolbar
->SetToolNormalBitmap(ID_BUTTONMESSAGES
, m_tblist
.GetBitmap(m_CurrentBlinkBitmap
));
1156 void CamuleDlg::LaunchUrl( const wxString
& url
)
1160 cmd
= thePrefs::GetBrowser();
1162 // Pipes cause problems, so escape them
1163 tmp
.Replace( wxT("|"), wxT("%7C") );
1165 if ( !cmd
.IsEmpty() ) {
1166 if (!cmd
.Replace(wxT("%s"), tmp
)) {
1167 // No %s found, just append the url
1168 cmd
+= wxT(" ") + tmp
;
1171 CTerminationProcess
*p
= new CTerminationProcess(cmd
);
1172 if (wxExecute(cmd
, wxEXEC_ASYNC
, p
)) {
1173 AddLogLineN(_("Launch Command: ") + cmd
);
1179 wxLaunchDefaultBrowser(tmp
);
1182 // Unable to execute browser. But this error message doesn't make sense,
1183 // cosidering that you _can't_ set the browser executable path... =/
1184 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1188 wxString
CamuleDlg::GenWebSearchUrl(const wxString
&filename
, WebSearch wsProvider
)
1191 switch (wsProvider
) {
1193 URL
= wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1198 URL
.Replace(wxT("FILENAME"), filename
);
1204 bool CamuleDlg::Check_and_Init_Skin()
1207 wxString
skinFileName(thePrefs::GetSkin());
1209 if (skinFileName
.IsEmpty() || skinFileName
.IsSameAs(_("- default -"))) {
1213 wxString
userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1215 wxStandardPathsBase
&spb(wxStandardPaths::Get());
1217 wxString
dataDir(spb
.GetPluginsDir());
1218 #elif defined(__WXMAC__)
1219 wxString
dataDir(spb
.GetDataDir());
1221 wxString
dataDir(spb
.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1223 wxString
systemDir(JoinPaths(dataDir
,wxT("skins")) + wxFileName::GetPathSeparator());
1226 skinFileName
.Replace(wxT("User:"), userDir
);
1227 skinFileName
.Replace(wxT("System:"), systemDir
);
1229 m_skinFileName
.Assign(skinFileName
);
1230 if (!m_skinFileName
.FileExists()) {
1231 AddLogLineC(CFormat(
1232 _("Skin directory '%s' does not exist")) %
1235 } else if (!m_skinFileName
.IsFileReadable()) {
1236 AddLogLineC(CFormat(
1237 _("WARNING: Unable to open skin file '%s' for read")) %
1242 wxFFileInputStream
in(m_skinFileName
.GetFullPath());
1243 wxZipInputStream
zip(in
);
1245 while ((entry
= zip
.GetNextEntry()) != NULL
) {
1246 wxZipEntry
*& current
= cat
[entry
->GetInternalName()];
1255 void CamuleDlg::Add_Skin_Icon(
1256 const wxString
&iconName
,
1257 const wxBitmap
&stdIcon
,
1262 wxFFileInputStream
in(m_skinFileName
.GetFullPath());
1263 wxZipInputStream
zip(in
);
1265 it
= cat
.find(wxZipEntry::GetInternalName(iconName
+ wxT(".png")));
1266 if ( it
!= cat
.end() ) {
1267 zip
.OpenEntry(*it
->second
);
1268 if ( !new_image
.LoadFile(zip
,wxBITMAP_TYPE_PNG
) ) {
1269 AddLogLineN(wxT("Warning: Error loading icon for ") +
1274 AddLogLineN(wxT("Warning: Can't load icon for ") +
1281 wxBitmap
bmp(useSkins
? new_image
: stdIcon
);
1282 if (iconName
.StartsWith(wxT("Client_"))) {
1283 m_imagelist
.Add(bmp
);
1284 } else if (iconName
.StartsWith(wxT("Toolbar_"))) {
1290 void CamuleDlg::Apply_Clients_Skin()
1292 bool useSkins
= Check_and_Init_Skin();
1294 // Clear the client image list
1295 m_imagelist
.RemoveAll();
1297 // Add the images to the image list
1298 for (int i
= 0; i
< CLIENT_SKIN_SIZE
; ++i
) {
1299 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames
[i
],
1300 clientImages(i
), useSkins
);
1305 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar
*wndToolbar
)
1307 bool useSkins
= Check_and_Init_Skin();
1310 // Clear the toolbar image list
1311 m_tblist
.RemoveAll();
1313 // Add the images to the image list
1314 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins
);
1315 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins
);
1316 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins
);
1317 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins
);
1318 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins
);
1319 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins
);
1320 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins
);
1321 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins
);
1322 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins
);
1323 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins
);
1324 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins
);
1325 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins
);
1326 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins
);
1328 // Build aMule toolbar
1329 wndToolbar
->SetMargins(0, 0);
1331 // Placeholder. Gets updated by ShowConnectionState
1332 wndToolbar
->AddTool(ID_BUTTONCONNECT
, wxT("..."), m_tblist
.GetBitmap(0));
1334 wndToolbar
->AddSeparator();
1335 wndToolbar
->AddTool(ID_BUTTONNETWORKS
, _("Networks"), m_tblist
.GetBitmap(3), wxNullBitmap
, wxITEM_CHECK
, _("Networks Window"));
1336 wndToolbar
->AddTool(ID_BUTTONSEARCH
, _("Searches"), m_tblist
.GetBitmap(5), wxNullBitmap
, wxITEM_CHECK
, _("Searches Window"));
1337 wndToolbar
->AddTool(ID_BUTTONDOWNLOADS
, _("Downloads"), m_tblist
.GetBitmap(4), wxNullBitmap
, wxITEM_CHECK
, _("Downloads Window"));
1338 wndToolbar
->AddTool(ID_BUTTONSHARED
, _("Shared files"), m_tblist
.GetBitmap(6), wxNullBitmap
, wxITEM_CHECK
, _("Shared Files Window"));
1339 wndToolbar
->AddTool(ID_BUTTONMESSAGES
, _("Messages"), m_tblist
.GetBitmap(7), wxNullBitmap
, wxITEM_CHECK
, _("Messages Window"));
1340 wndToolbar
->AddTool(ID_BUTTONSTATISTICS
, _("Statistics"), m_tblist
.GetBitmap(8), wxNullBitmap
, wxITEM_CHECK
, _("Statistics Graph Window"));
1341 wndToolbar
->AddSeparator();
1342 wndToolbar
->AddTool(ID_BUTTONNEWPREFERENCES
, _("Preferences"), m_tblist
.GetBitmap(9), wxNullBitmap
, wxITEM_NORMAL
, _("Preferences Settings Window"));
1344 wndToolbar
->AddTool(ID_BUTTONIMPORT
, _("Import"), m_tblist
.GetBitmap(10), wxNullBitmap
, wxITEM_NORMAL
, _("The partfile importer tool"));
1346 wndToolbar
->AddTool(ID_ABOUT
, _("About"), m_tblist
.GetBitmap(11), wxNullBitmap
, wxITEM_NORMAL
, _("About/Help"));
1348 wndToolbar
->ToggleTool(ID_BUTTONDOWNLOADS
, true);
1350 // Needed for non-GTK platforms, where the
1351 // items don't get added immediatly.
1352 wndToolbar
->Realize();
1354 // Updates the "Connect" button, and so on.
1355 ShowConnectionState(true);
1359 void CamuleDlg::Create_Toolbar(bool orientation
)
1362 // Create ToolBar from the one designed by wxDesigner (BigBob)
1363 wxToolBar
*current
= GetToolBar();
1365 wxASSERT(current
== m_wndToolbar
);
1368 bool oldorientation
= ((current
->GetWindowStyle() & wxTB_VERTICAL
) == wxTB_VERTICAL
);
1369 if (oldorientation
!= orientation
) {
1371 SetToolBar(NULL
); // Remove old one if present
1372 m_wndToolbar
= NULL
;
1374 current
->ClearTools();
1378 if (!m_wndToolbar
) {
1379 m_wndToolbar
= CreateToolBar(
1380 (orientation
? wxTB_VERTICAL
: wxTB_HORIZONTAL
) |
1381 wxNO_BORDER
| wxTB_TEXT
| wxTB_3DBUTTONS
|
1382 wxTB_FLAT
| wxCLIP_CHILDREN
| wxTB_NODIVIDER
);
1385 m_wndToolbar
->SetToolBitmapSize(wxSize(32, 32));
1388 Apply_Toolbar_Skin(m_wndToolbar
);
1394 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent
& evt
)
1396 wxFrame::OnSize(evt
);
1397 if (m_transferwnd
&& m_transferwnd
->clientlistctrl
) {
1398 // Transfer window's splitter set again if it's hidden.
1399 if (!m_transferwnd
->clientlistctrl
->GetShowing()) {
1400 int height
= m_transferwnd
->clientlistctrl
->GetSize().GetHeight();
1401 wxSplitterWindow
* splitter
=
1402 CastChild(wxT("splitterWnd"), wxSplitterWindow
);
1403 height
+= splitter
->GetWindow1()->GetSize().GetHeight();
1404 splitter
->SetSashPosition( height
);
1410 void CamuleDlg::OnKeyPressed(wxKeyEvent
& event
)
1412 if (event
.GetKeyCode() == WXK_F1
) {
1413 // Ctrl/Alt/Shift must not be pressed, to avoid
1414 // conflicts with other (global) shortcuts.
1415 if (!event
.HasModifiers() && !event
.ShiftDown()) {
1416 LaunchUrl(wxT("http://wiki.amule.org"));
1425 void CamuleDlg::OnExit(wxCommandEvent
& WXUNUSED(evt
))
1430 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()) {
1449 logs_notebook
->AddPage(m_logpages
[1].page
, m_logpages
[1].name
);
1451 logs_notebook
->AddPage(m_logpages
[2].page
, m_logpages
[2].name
);
1454 m_networkpages
[0].page
->Show(thePrefs::GetNetworkED2K());
1456 if (thePrefs::GetNetworkKademlia()) {
1457 logs_notebook
->AddPage(m_logpages
[3].page
, m_logpages
[3].name
);
1460 m_networkpages
[1].page
->Show(thePrefs::GetNetworkKademlia());
1462 networks_notebook
->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1464 wxWindow
* replacement
= NULL
;
1466 m_networknotebooksizer
->Clear();
1468 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1469 toolbarTool
->SetLabel(_("Networks"));
1471 m_networkpages
[0].page
->Reparent(networks_notebook
);
1472 m_networkpages
[1].page
->Reparent(networks_notebook
);
1474 networks_notebook
->AddPage(m_networkpages
[0].page
, m_networkpages
[0].name
);
1475 networks_notebook
->AddPage(m_networkpages
[1].page
, m_networkpages
[1].name
);
1477 replacement
= networks_notebook
;
1479 } else if (thePrefs::GetNetworkED2K()) {
1480 toolbarTool
->SetLabel(_("eD2k network"));
1481 replacement
= m_networkpages
[0].page
;
1482 m_networkpages
[1].page
->Reparent(m_networknotebooksizer
->GetContainingWindow());
1483 } else if (thePrefs::GetNetworkKademlia()) {
1484 toolbarTool
->SetLabel(_("Kad network"));
1485 m_networkpages
[0].page
->Reparent(m_networknotebooksizer
->GetContainingWindow());
1486 replacement
= m_networkpages
[1].page
;
1489 toolbarTool
->SetLabel(_("No network"));
1493 replacement
->Reparent(m_networknotebooksizer
->GetContainingWindow());
1494 m_networknotebooksizer
->Add( replacement
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
, 5 );
1495 m_networknotebooksizer
->Layout();
1498 m_wndToolbar
->InsertTool(2, toolbarTool
);
1500 m_wndToolbar
->EnableTool(ID_BUTTONNETWORKS
, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1501 m_wndToolbar
->EnableTool(ID_BUTTONCONNECT
, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp
->ipfilter
->IsReady());
1503 m_wndToolbar
->Realize();
1505 m_searchwnd
->FixSearchTypes();
1508 // File_checked_for_headers