2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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
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.
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
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
41 #include <wx/utils.h> // Needed for wxFindWindowAtPoint
43 #include <common/EventIDs.h>
45 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
46 #include "amuleDlg.h" // Interface declarations.
48 #include <common/Format.h> // Needed for CFormat
49 #include "amule.h" // Needed for theApp
50 #include "ChatWnd.h" // Needed for CChatWnd
51 #include "SourceListCtrl.h" // Needed for CSourceListCtrl
52 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
53 #include "DownloadQueue.h" // Needed for CDownloadQueue
54 #include "KadDlg.h" // Needed for CKadDlg
56 #include "MuleTrayIcon.h"
57 #include "muuli_wdr.h" // Needed for ID_BUTTON*
58 #include "Preferences.h" // Needed for CPreferences
59 #include "PrefsUnifiedDlg.h"
60 #include "SearchDlg.h" // Needed for CSearchDlg
61 #include "Server.h" // Needed for CServer
62 #include "ServerConnect.h" // Needed for CServerConnect
63 #include "ServerWnd.h" // Needed for CServerWnd
64 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
65 #include "SharedFilePeersListCtrl.h" // Needed for CSharedFilePeersListCtrl
66 #include "Statistics.h" // Needed for theStats
67 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
68 #include "TerminationProcess.h" // Needed for CTerminationProcess
69 #include "TransferWnd.h" // Needed for CTransferWnd
71 #include "PartFileConvertDlg.h"
79 #include "kademlia/kademlia/Kademlia.h"
80 #include "MuleVersion.h" // Needed for GetMuleVersion()
82 #ifdef ENABLE_IP2COUNTRY
83 #include "IP2Country.h" // Needed for IP2Country
86 #ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
87 // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
88 void CamuleDlg::IP2CountryDownloadFinished(uint32 result
)
90 m_IP2Country
->DownloadFinished(result
);
93 void CamuleDlg::EnableIP2Country()
95 if (thePrefs::IsGeoIPEnabled()) {
96 m_IP2Country
->Enable();
102 void CamuleDlg::IP2CountryDownloadFinished(uint32
){}
103 void CamuleDlg::EnableIP2Country(){}
107 BEGIN_EVENT_TABLE(CamuleDlg
, wxFrame
)
109 EVT_TOOL(ID_BUTTONNETWORKS
, CamuleDlg::OnToolBarButton
)
110 EVT_TOOL(ID_BUTTONSEARCH
, CamuleDlg::OnToolBarButton
)
111 EVT_TOOL(ID_BUTTONDOWNLOADS
, CamuleDlg::OnToolBarButton
)
112 EVT_TOOL(ID_BUTTONSHARED
, CamuleDlg::OnToolBarButton
)
113 EVT_TOOL(ID_BUTTONMESSAGES
, CamuleDlg::OnToolBarButton
)
114 EVT_TOOL(ID_BUTTONSTATISTICS
, CamuleDlg::OnToolBarButton
)
115 EVT_TOOL(ID_ABOUT
, CamuleDlg::OnAboutButton
)
117 EVT_TOOL(ID_BUTTONNEWPREFERENCES
, CamuleDlg::OnPrefButton
)
118 EVT_TOOL(ID_BUTTONIMPORT
, CamuleDlg::OnImportButton
)
120 EVT_TOOL(ID_BUTTONCONNECT
, CamuleDlg::OnBnConnect
)
122 EVT_CLOSE(CamuleDlg::OnClose
)
123 EVT_ICONIZE(CamuleDlg::OnMinimize
)
125 EVT_BUTTON(ID_BUTTON_FAST
, CamuleDlg::OnBnClickedFast
)
127 EVT_TIMER(ID_GUI_TIMER_EVENT
, CamuleDlg::OnGUITimer
)
129 EVT_SIZE(CamuleDlg::OnMainGUISizeChange
)
131 EVT_KEY_UP(CamuleDlg::OnKeyPressed
)
133 EVT_MENU(wxID_EXIT
, CamuleDlg::OnExit
)
138 #define wxCLOSE_BOX 0
141 CamuleDlg::CamuleDlg(
143 const wxString
&title
,
148 pParent
, -1, title
, where
, dlg_size
,
149 wxCAPTION
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxDIALOG_NO_PARENT
|
150 wxRESIZE_BORDER
|wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxCLOSE_BOX
,
155 m_sharedfileswnd(NULL
),
158 m_statisticswnd(NULL
),
164 m_prefsVisible(false),
166 m_wndTaskbarNotifier(NULL
),
167 m_nActiveDialog(DT_NETWORKS_WND
),
168 m_is_safe_state(false),
169 m_BlinkMessages(false),
170 m_CurrentBlinkBitmap(24),
173 m_clientSkinNames(CLIENT_SKIN_SIZE
)
175 // Initialize skin names
176 m_clientSkinNames
[Client_Green_Smiley
] = wxT("Transfer");
177 m_clientSkinNames
[Client_Red_Smiley
] = wxT("Connecting");
178 m_clientSkinNames
[Client_Yellow_Smiley
] = wxT("OnQueue");
179 m_clientSkinNames
[Client_Grey_Smiley
] = wxT("A4AFNoNeededPartsQueueFull");
180 m_clientSkinNames
[Client_White_Smiley
] = wxT("StatusUnknown");
181 m_clientSkinNames
[Client_ExtendedProtocol_Smiley
] = wxT("ExtendedProtocol");
182 m_clientSkinNames
[Client_SecIdent_Smiley
] = wxT("SecIdent");
183 m_clientSkinNames
[Client_BadGuy_Smiley
] = wxT("BadGuy");
184 m_clientSkinNames
[Client_CreditsGrey_Smiley
] = wxT("CreditsGrey");
185 m_clientSkinNames
[Client_CreditsYellow_Smiley
] = wxT("CreditsYellow");
186 m_clientSkinNames
[Client_Upload_Smiley
] = wxT("Upload");
187 m_clientSkinNames
[Client_Friend_Smiley
] = wxT("Friend");
188 m_clientSkinNames
[Client_eMule_Smiley
] = wxT("eMule");
189 m_clientSkinNames
[Client_mlDonkey_Smiley
] = wxT("mlDonkey");
190 m_clientSkinNames
[Client_eDonkeyHybrid_Smiley
] = wxT("eDonkeyHybrid");
191 m_clientSkinNames
[Client_aMule_Smiley
] = wxT("aMule");
192 m_clientSkinNames
[Client_lphant_Smiley
] = wxT("lphant");
193 m_clientSkinNames
[Client_Shareaza_Smiley
] = wxT("Shareaza");
194 m_clientSkinNames
[Client_xMule_Smiley
] = wxT("xMule");
195 m_clientSkinNames
[Client_Unknown
] = wxT("Unknown");
196 m_clientSkinNames
[Client_InvalidRating_Smiley
] = wxT("InvalidRatingOnFile");
197 m_clientSkinNames
[Client_PoorRating_Smiley
] = wxT("PoorRatingOnFile");
198 m_clientSkinNames
[Client_GoodRating_Smiley
] = wxT("GoodRatingOnFile");
199 m_clientSkinNames
[Client_FairRating_Smiley
] = wxT("FairRatingOnFile");
200 m_clientSkinNames
[Client_ExcellentRating_Smiley
] = wxT("ExcellentRatingOnFile");
201 m_clientSkinNames
[Client_CommentOnly_Smiley
] = wxT("CommentOnly");
202 m_clientSkinNames
[Client_Encryption_Smiley
] = wxT("Encrypted");
204 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
205 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED
);
206 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED
);
207 wxInitAllImageHandlers();
208 Apply_Clients_Skin();
211 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
214 #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__))
215 // this crashes on Mac with wx 2.9
216 SetIcon(wxICON(aMule
));
221 // Create new sizer and stuff a wxPanel in there.
222 wxFlexGridSizer
*s_main
= new wxFlexGridSizer(1);
223 s_main
->AddGrowableCol(0);
224 s_main
->AddGrowableRow(0);
226 wxPanel
* p_cnt
= new wxPanel(this, -1, wxDefaultPosition
, wxDefaultSize
);
227 s_main
->Add(p_cnt
, 0, wxGROW
|wxEXPAND
, 0);
228 muleDlg(p_cnt
, false, true);
229 SetSizer(s_main
, true);
231 m_serverwnd
= new CServerWnd(p_cnt
, m_srv_split_pos
);
232 AddLogLineN(wxEmptyString
);
233 AddLogLineN(wxT(" - ") +
234 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
235 AddLogLineN(wxT(" ") +
236 CFormat(_("Running on %s")) % wxGetOsDescription());
237 AddLogLineN(wxT(" - ") +
238 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
239 AddLogLineN(wxEmptyString
);
241 #ifdef ENABLE_IP2COUNTRY
242 m_GeoIPavailable
= true;
243 m_IP2Country
= new CIP2Country(thePrefs::GetConfigDir());
245 m_GeoIPavailable
= false;
247 m_searchwnd
= new CSearchDlg(p_cnt
);
248 m_transferwnd
= new CTransferWnd(p_cnt
);
249 m_sharedfileswnd
= new CSharedFilesWnd(p_cnt
);
250 m_statisticswnd
= new CStatisticsDlg(p_cnt
, theApp
->m_statistics
);
251 m_chatwnd
= new CChatWnd(p_cnt
);
252 m_kademliawnd
= CastChild(wxT("kadWnd"), CKadDlg
);
254 m_serverwnd
->Show(false);
255 m_searchwnd
->Show(false);
256 m_transferwnd
->Show(false);
257 m_sharedfileswnd
->Show(false);
258 m_statisticswnd
->Show(false);
259 m_chatwnd
->Show(false);
261 // Create the GUI timer
262 gui_timer
=new wxTimer(this,ID_GUI_TIMER_EVENT
);
264 AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
268 // Set transfers as active window
269 Create_Toolbar(thePrefs::VerticalToolbar());
270 SetActiveDialog(DT_TRANSFER_WND
, m_transferwnd
);
271 m_wndToolbar
->ToggleTool(ID_BUTTONDOWNLOADS
, true );
273 bool override_where
= (where
!= wxDefaultPosition
);
274 bool override_size
= (
275 (dlg_size
.x
!= DEFAULT_SIZE_X
) ||
276 (dlg_size
.y
!= DEFAULT_SIZE_Y
) );
277 if (!LoadGUIPrefs(override_where
, override_size
)) {
278 // Prefs not loaded for some reason, exit
279 AddLogLineC(wxT("Error! Unable to load Preferences") );
283 // Prepare the dialog, sets the splitter-position (AFTER window size is set)
284 m_transferwnd
->Prepare();
286 m_is_safe_state
= true;
288 // Init statistics stuff, better do it asap
289 m_statisticswnd
->Init();
290 m_kademliawnd
->Init();
291 m_searchwnd
->UpdateCatChoice();
293 if (thePrefs::UseTrayIcon()) {
298 // Must we start minimized?
299 if (thePrefs::GetStartMinimized()) {
304 wxAcceleratorEntry entries
[] = {
305 wxAcceleratorEntry(wxACCEL_CTRL
, wxT('Q'), wxID_EXIT
)
308 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries
), entries
));
309 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
311 wxNotebook
* logs_notebook
= CastChild( ID_SRVLOG_NOTEBOOK
, wxNotebook
);
312 wxNotebook
* networks_notebook
= CastChild( ID_NETNOTEBOOK
, wxNotebook
);
314 wxASSERT(logs_notebook
->GetPageCount() == 4);
315 wxASSERT(networks_notebook
->GetPageCount() == 2);
317 for (uint32 i
= 0; i
< logs_notebook
->GetPageCount(); ++i
) {
318 m_logpages
[i
].page
= logs_notebook
->GetPage(i
);
319 m_logpages
[i
].name
= logs_notebook
->GetPageText(i
);
322 for (uint32 i
= 0; i
< networks_notebook
->GetPageCount(); ++i
) {
323 m_networkpages
[i
].page
= networks_notebook
->GetPage(i
);
324 m_networkpages
[i
].name
= networks_notebook
->GetPageText(i
);
327 DoNetworkRearrange();
331 // Madcat - Sets Fast ED2K Links Handler on/off.
332 void CamuleDlg::ShowED2KLinksHandler( bool show
)
334 // Errorchecking in case the pointer becomes invalid ...
335 if (s_fed2klh
== NULL
) {
336 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
340 s_dlgcnt
->Show( s_fed2klh
, show
);
344 // Toogles ed2k link handler.
345 void CamuleDlg::ToogleED2KLinksHandler()
347 // Errorchecking in case the pointer becomes invalid ...
348 if (s_fed2klh
== NULL
) {
349 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
352 ShowED2KLinksHandler(!s_dlgcnt
->IsShown(s_fed2klh
));
355 void CamuleDlg::SetActiveDialog(DialogType type
, wxWindow
* dlg
)
357 m_nActiveDialog
= type
;
359 if ( type
== DT_TRANSFER_WND
) {
360 if (thePrefs::ShowCatTabInfos()) {
361 m_transferwnd
->UpdateCatTabTitles();
366 m_activewnd
->Show(false);
367 contentSizer
->Detach(m_activewnd
);
370 contentSizer
->Add(dlg
, 1, wxALIGN_LEFT
|wxEXPAND
);
375 // Since we might be suspending redrawing while hiding the dialog
376 // we have to refresh it once it is visible again
377 dlg
->Refresh( true );
380 if ( type
== DT_SHARED_WND
) {
381 // set up splitter now that window sizes are defined
382 m_sharedfileswnd
->Prepare();
387 void CamuleDlg::UpdateTrayIcon(int percent
)
390 if(!theApp
->IsConnected()) {
391 m_wndTaskbarNotifier
->SetTrayIcon(TRAY_ICON_DISCONNECTED
, percent
);
393 if(theApp
->IsConnectedED2K() && theApp
->serverconnect
->IsLowID()) {
394 m_wndTaskbarNotifier
->SetTrayIcon(TRAY_ICON_LOWID
, percent
);
396 m_wndTaskbarNotifier
->SetTrayIcon(TRAY_ICON_HIGHID
, percent
);
402 void CamuleDlg::CreateSystray()
404 wxCHECK_RET(m_wndTaskbarNotifier
== NULL
,
405 wxT("Systray already created"));
407 m_wndTaskbarNotifier
= new CMuleTrayIcon();
408 // This will effectively show the Tray Icon.
413 void CamuleDlg::RemoveSystray()
415 delete m_wndTaskbarNotifier
;
416 m_wndTaskbarNotifier
= NULL
;
420 void CamuleDlg::OnToolBarButton(wxCommandEvent
& ev
)
422 static int lastbutton
= ID_BUTTONDOWNLOADS
;
424 // Kry - just if the GUI is ready for it
425 if ( m_is_safe_state
) {
427 // Rehide the handler if needed
428 if ( lastbutton
== ID_BUTTONSEARCH
&& !thePrefs::GetFED2KLH() ) {
429 if (ev
.GetId() != ID_BUTTONSEARCH
) {
430 ShowED2KLinksHandler( false );
432 // Toogle ED2K handler.
433 ToogleED2KLinksHandler();
437 if ( lastbutton
!= ev
.GetId() ) {
438 switch ( ev
.GetId() ) {
439 case ID_BUTTONNETWORKS
:
440 SetActiveDialog(DT_NETWORKS_WND
, m_serverwnd
);
441 // Set serverlist splitter position
442 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow
)->SetSashPosition(m_srv_split_pos
, true);
445 case ID_BUTTONSEARCH
:
446 // The search dialog should always display the handler
447 if ( !thePrefs::GetFED2KLH() )
448 ShowED2KLinksHandler( true );
450 SetActiveDialog(DT_SEARCH_WND
, m_searchwnd
);
453 case ID_BUTTONDOWNLOADS
:
454 SetActiveDialog(DT_TRANSFER_WND
, m_transferwnd
);
455 // Prepare the dialog, sets the splitter-position
456 m_transferwnd
->Prepare();
459 case ID_BUTTONSHARED
:
460 SetActiveDialog(DT_SHARED_WND
, m_sharedfileswnd
);
463 case ID_BUTTONMESSAGES
:
464 m_BlinkMessages
= false;
465 SetActiveDialog(DT_CHAT_WND
, m_chatwnd
);
468 case ID_BUTTONSTATISTICS
:
469 SetActiveDialog(DT_STATS_WND
, m_statisticswnd
);
472 // This shouldn't happen, but just in case
474 AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
479 m_wndToolbar
->ToggleTool(lastbutton
, lastbutton
== ev
.GetId() );
480 lastbutton
= ev
.GetId();
485 void CamuleDlg::OnAboutButton(wxCommandEvent
& WXUNUSED(ev
))
487 wxString msg
= wxT(" ");
489 msg
<< _("aMule remote control ") << wxT(VERSION
);
491 msg
<< wxT("aMule ") << wxT(VERSION
);
495 msg
<< _("Snapshot:") << wxT("\n ") << wxT(SVNDATE
);
497 msg
<< wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
498 _("Website: http://www.amule.org \n") <<
499 _("Forum: http://forum.amule.org \n") <<
500 _("FAQ: http://wiki.amule.org \n\n") <<
501 _("Contact: admin@amule.org (administrative issues) \n") <<
502 _("Copyright (c) 2003-2019 aMule Team \n\n") <<
503 _("Part of aMule is based on \n") <<
504 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
505 _(" Copyright (c) 2002-2011 Petar Maymounkov ( petar@post.harvard.edu )\n") <<
506 _("http://kademlia.scs.cs.nyu.edu\n");
508 if (m_is_safe_state
) {
509 wxMessageBox(msg
, _("Message"), wxOK
| wxICON_INFORMATION
, this);
514 void CamuleDlg::OnPrefButton(wxCommandEvent
& WXUNUSED(ev
))
516 if (m_is_safe_state
) {
517 if (m_prefsDialog
== NULL
) {
518 m_prefsDialog
= new PrefsUnifiedDlg(this);
521 m_prefsDialog
->TransferToWindow();
522 m_prefsDialog
->Show(true);
523 m_prefsDialog
->Raise();
528 void CamuleDlg::OnImportButton(wxCommandEvent
& WXUNUSED(ev
))
531 if (m_is_safe_state
) {
532 CPartFileConvertDlg::ShowGUI(NULL
);
538 CamuleDlg::~CamuleDlg()
540 theApp
->amuledlg
= NULL
;
542 #ifdef ENABLE_IP2COUNTRY
546 AddLogLineN(_("aMule dialog destroyed"));
550 void CamuleDlg::OnBnConnect(wxCommandEvent
& WXUNUSED(evt
))
553 bool disconnect
= (theApp
->IsConnectedED2K() || theApp
->serverconnect
->IsConnecting())
555 || theApp
->IsConnectedKad() // there's no Kad running state atm
557 || (Kademlia::CKademlia::IsRunning())
560 if (thePrefs::GetNetworkED2K()) {
562 //disconnect if currently connected
563 if (theApp
->serverconnect
->IsConnecting()) {
564 theApp
->serverconnect
->StopConnectionTry();
566 theApp
->serverconnect
->Disconnect();
569 //connect if not currently connected
570 AddLogLineC(_("Connecting"));
571 theApp
->serverconnect
->ConnectToAnyServer();
574 wxASSERT(!theApp
->IsConnectedED2K());
578 if (thePrefs::GetNetworkKademlia()) {
586 wxASSERT(!Kademlia::CKademlia::IsRunning());
590 ShowConnectionState();
594 void CamuleDlg::ResetLog(int id
)
596 wxTextCtrl
* ct
= CastByID(id
, m_serverwnd
, wxTextCtrl
);
597 wxCHECK_RET(ct
, wxT("Resetting unknown log"));
601 if (id
== ID_LOGVIEW
) {
602 // Also clear the log line
603 wxStaticText
* text
= CastChild(wxT("infoLabel"), wxStaticText
);
604 text
->SetLabel(wxEmptyString
);
605 text
->GetParent()->Layout();
610 void CamuleDlg::AddLogLine(const wxString
& line
)
612 bool addtostatusbar
= line
[0] == '!';
613 wxString bufferline
= line
.Mid(1);
615 // Add the message to the log-view
616 wxTextCtrl
* ct
= CastByID( ID_LOGVIEW
, m_serverwnd
, wxTextCtrl
);
618 // Bold critical log-lines
619 // Works in Windows too thanks to wxTE_RICH2 style in muuli
620 wxTextAttr style
= ct
->GetDefaultStyle();
621 wxFont font
= style
.GetFont();
622 font
.SetWeight(addtostatusbar
? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
624 #if wxCHECK_VERSION(2, 9, 0)
625 style
.SetFontSize(8);
627 ct
->SetDefaultStyle(style
);
628 ct
->AppendText(bufferline
);
629 ct
->ShowPosition( ct
->GetLastPosition() - 1 );
633 // Set the status-bar if the event warrents it
634 if ( addtostatusbar
) {
635 // Escape "&"s, which would otherwise not show up
636 bufferline
.Replace( wxT("&"), wxT("&&") );
637 wxStaticText
* text
= CastChild( wxT("infoLabel"), wxStaticText
);
638 // Only show the first line if multiple lines
639 text
->SetLabel( bufferline
.BeforeFirst( wxT('\n') ) );
640 text
->SetToolTip( bufferline
);
641 text
->GetParent()->Layout();
647 void CamuleDlg::AddServerMessageLine(wxString
& message
)
649 wxTextCtrl
* cv
= CastByID( ID_SERVERINFO
, m_serverwnd
, wxTextCtrl
);
651 if (message
.Length() > 500) {
652 cv
->AppendText(message
.Left(500) + wxT("\n"));
654 cv
->AppendText(message
+ wxT("\n"));
656 cv
->ShowPosition(cv
->GetLastPosition()-1);
661 void CamuleDlg::ShowConnectionState(bool skinChanged
)
663 static wxImageList
status_arrows(16,16,true,0);
664 if (!status_arrows
.GetImageCount()) {
665 // Generate the image list (This is only done once)
666 for (int t
= 0; t
< 7; ++t
) {
667 status_arrows
.Add(connImages(t
));
671 m_serverwnd
->UpdateED2KInfo();
672 m_serverwnd
->UpdateKadInfo();
675 ////////////////////////////////////////////////////////////
676 // Determine the status of the networks
678 enum ED2KState
{ ED2KOff
= 0, ED2KLowID
= 1, ED2KConnecting
= 2, ED2KHighID
= 3, ED2KUndef
= -1 };
679 enum EKadState
{ EKadOff
= 4, EKadFW
= 5, EKadConnecting
= 5, EKadOK
= 6, EKadUndef
= -1 };
681 ED2KState ed2kState
= ED2KOff
;
682 EKadState kadState
= EKadOff
;
684 ////////////////////////////////////////////////////////////
685 // Update the label on the status-bar and determine
686 // the states of the two networks.
689 if (theApp
->IsConnectedED2K()) {
690 CServer
* server
= theApp
->serverconnect
->GetCurrentServer();
692 msgED2K
= CFormat(wxT("eD2k: %s")) % server
->GetListName();
695 if (theApp
->serverconnect
->IsLowID()) {
696 ed2kState
= ED2KLowID
;
698 ed2kState
= ED2KHighID
;
700 } else if (theApp
->serverconnect
->IsConnecting()) {
701 msgED2K
= _("eD2k: Connecting");
703 ed2kState
= ED2KConnecting
;
704 } else if (thePrefs::GetNetworkED2K()) {
705 msgED2K
= _("eD2k: Disconnected");
709 if (theApp
->IsConnectedKad()) {
710 if (theApp
->IsFirewalledKad()) {
711 msgKad
= _("Kad: Firewalled");
715 msgKad
= _("Kad: Connected");
719 } else if (theApp
->IsKadRunning()) {
720 msgKad
= _("Kad: Connecting");
722 kadState
= EKadConnecting
;
723 } else if (thePrefs::GetNetworkKademlia()) {
724 msgKad
= _("Kad: Off");
727 wxStaticText
* connLabel
= CastChild( wxT("connLabel"), wxStaticText
);
728 { wxCHECK_RET(connLabel
, wxT("'connLabel' widget not found")); }
731 if (msgED2K
.Length() && msgKad
.Length()) {
732 labelMsg
= msgED2K
+ wxT(" | ") + msgKad
;
734 labelMsg
= msgED2K
+ msgKad
;
737 connLabel
->SetLabel(labelMsg
);
738 connLabel
->GetParent()->Layout();
741 ////////////////////////////////////////////////////////////
742 // Update the connect/disconnect/cancel button.
751 static EConnState s_oldState
= ECS_Unknown
;
752 EConnState currentState
= ECS_Disconnected
;
754 if (theApp
->serverconnect
->IsConnecting() ||
755 (theApp
->IsKadRunning() && !theApp
->IsConnectedKad())) {
756 currentState
= ECS_Connecting
;
757 } else if (theApp
->IsConnected()) {
758 currentState
= ECS_Connected
;
760 currentState
= ECS_Disconnected
;
763 if ( (true == skinChanged
) || (currentState
!= s_oldState
) ) {
764 wxWindowUpdateLocker
freezer(m_wndToolbar
);
766 wxToolBarToolBase
* toolbarTool
= m_wndToolbar
->RemoveTool(ID_BUTTONCONNECT
);
768 switch (currentState
) {
770 toolbarTool
->SetLabel(_("Cancel"));
771 toolbarTool
->SetShortHelp(_("Stop the current connection attempts"));
772 toolbarTool
->SetNormalBitmap(m_tblist
.GetBitmap(2));
776 toolbarTool
->SetLabel(_("Disconnect"));
777 toolbarTool
->SetShortHelp(_("Disconnect from the currently connected networks"));
778 toolbarTool
->SetNormalBitmap(m_tblist
.GetBitmap(1));
782 toolbarTool
->SetLabel(_("Connect"));
783 toolbarTool
->SetShortHelp(_("Connect to the currently enabled networks"));
784 toolbarTool
->SetNormalBitmap(m_tblist
.GetBitmap(0));
787 m_wndToolbar
->InsertTool(0, toolbarTool
);
788 m_wndToolbar
->Realize();
789 m_wndToolbar
->EnableTool(ID_BUTTONCONNECT
, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp
->ipfilter
->IsReady());
791 s_oldState
= currentState
;
795 ////////////////////////////////////////////////////////////
796 // Update the globe-icon in the lower-right corner.
797 // (only if connection state has changed)
799 static ED2KState s_ED2KOldState
= ED2KUndef
;
800 static EKadState s_EKadOldState
= EKadUndef
;
801 if (ed2kState
!= s_ED2KOldState
|| kadState
!= s_EKadOldState
) {
802 s_ED2KOldState
= ed2kState
;
803 s_EKadOldState
= kadState
;
804 wxStaticBitmap
* connBitmap
= CastChild( wxT("connImage"), wxStaticBitmap
);
805 wxCHECK_RET(connBitmap
, wxT("'connImage' widget not found"));
807 wxBitmap statusIcon
= connBitmap
->GetBitmap();
808 // Sanity check - otherwise there's a crash here if aMule runs out of resources
809 if (statusIcon
.GetRefData() == NULL
) {
813 wxMemoryDC
bitmapDC(statusIcon
);
815 status_arrows
.Draw(kadState
, bitmapDC
, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT
);
816 status_arrows
.Draw(ed2kState
, bitmapDC
, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT
);
818 connBitmap
->SetBitmap(statusIcon
);
823 void CamuleDlg::ShowUserCount(const wxString
& info
)
825 wxStaticText
* label
= CastChild( wxT("userLabel"), wxStaticText
);
828 m_serverwnd
->UpdateKadInfo();
830 label
->SetLabel(info
);
831 label
->GetParent()->Layout();
835 void CamuleDlg::ShowTransferRate()
837 float kBpsUp
= theStats::GetUploadRate() / 1024.0;
838 float kBpsDown
= theStats::GetDownloadRate() / 1024.0;
839 float MBpsUp
= kBpsUp
/ 1024.0;
840 float MBpsDown
= kBpsDown
/ 1024.0;
841 bool showMBpsUp
= (MBpsUp
>= 1);
842 bool showMBpsDown
= (MBpsDown
>= 1);
844 if( thePrefs::ShowOverhead() )
846 buffer
= CFormat(_("Up: %.1f%s (%.1f) | Down: %.1f%s (%.1f)"))
847 % (showMBpsUp
? MBpsUp
: kBpsUp
) % (showMBpsUp
? _(" MB/s") : ((kBpsUp
> 0) ? _(" kB/s") : wxT(""))) % (theStats::GetUpOverheadRate() / 1024.0)
848 % (showMBpsDown
? MBpsDown
: kBpsDown
) % (showMBpsDown
? _(" MB/s") : ((kBpsDown
> 0) ? _(" kB/s") : wxT(""))) % (theStats::GetDownOverheadRate() / 1024.0);
850 buffer
= CFormat(_("Up: %.1f%s | Down: %.1f%s"))
851 % (showMBpsUp
? MBpsUp
: kBpsUp
) % (showMBpsUp
? _(" MB/s") : ((kBpsUp
> 0) ? _(" kB/s") : wxT("")))
852 % (showMBpsDown
? MBpsDown
: kBpsDown
) % (showMBpsDown
? _(" MB/s") : ((kBpsDown
> 0) ? _(" kB/s") : wxT("")));
854 buffer
.Truncate(50); // Max size 50
856 wxStaticText
* label
= CastChild( wxT("speedLabel"), wxStaticText
);
857 label
->SetLabel(buffer
);
858 label
->GetParent()->Layout();
860 // Show upload/download speed in title
861 if (thePrefs::GetShowRatesOnTitle()) {
862 wxString UpDownSpeed
= CFormat(wxT("Up: %.1f%s | Down: %.1f%s"))
863 % (showMBpsUp
? MBpsUp
: kBpsUp
) % (showMBpsUp
? _(" MB/s") : ((kBpsUp
> 0) ? _(" kB/s") : wxT("")))
864 % (showMBpsDown
? MBpsDown
: kBpsDown
) % (showMBpsDown
? _(" MB/s") : ((kBpsDown
> 0) ? _(" kB/s") : wxT("")));
865 if (thePrefs::GetShowRatesOnTitle() == 1) {
866 SetTitle(theApp
->m_FrameTitle
+ wxT(" -- ") + UpDownSpeed
);
868 SetTitle(UpDownSpeed
+ wxT(" -- ") + theApp
->m_FrameTitle
);
872 wxASSERT((m_wndTaskbarNotifier
!= NULL
) == thePrefs::UseTrayIcon());
873 if (m_wndTaskbarNotifier
) {
875 int percentDown
= (int)ceil((kBpsDown
*100) / thePrefs::GetMaxGraphDownloadRate());
876 UpdateTrayIcon( ( percentDown
> 100 ) ? 100 : percentDown
);
879 if ( theApp
->IsConnected() ) {
880 buffer2
= CFormat(_("aMule (%s | Connected)")) % buffer
;
882 buffer2
= CFormat(_("aMule (%s | Disconnected)")) % buffer
;
884 m_wndTaskbarNotifier
->SetTrayToolTip(buffer2
);
887 wxStaticBitmap
* bmp
= CastChild( wxT("transferImg"), wxStaticBitmap
);
888 bmp
->SetBitmap(dlStatusImages((kBpsUp
>0.01 ? 2 : 0) + (kBpsDown
>0.01 ? 1 : 0)));
891 void CamuleDlg::DlgShutDown()
893 // Are we already shutting down or still on init?
894 if ( m_is_safe_state
== false ) {
899 m_is_safe_state
= false;
901 // Stop the GUI Timer
903 m_transferwnd
->downloadlistctrl
->DeleteAllItems();
905 // We want to delete the systray too!
909 void CamuleDlg::OnClose(wxCloseEvent
& evt
)
911 if (thePrefs::HideOnClose() && evt
.CanVeto()) {
917 // This will be here till the core close is != app close
918 if (evt
.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
919 if (wxNO
== wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp
->GetMuleAppName()),
920 wxString(_("Exit confirmation")), wxYES_NO
, this)) {
931 theApp
->ShutDown(evt
);
935 void CamuleDlg::OnBnClickedFast(wxCommandEvent
& WXUNUSED(evt
))
937 wxTextCtrl
* ctl
= CastChild( wxT("FastEd2kLinks"), wxTextCtrl
);
939 for ( int i
= 0; i
< ctl
->GetNumberOfLines(); i
++ ) {
940 wxString strlink
= ctl
->GetLineText(i
);
943 if ( !strlink
.IsEmpty() ) {
944 theApp
->downloadqueue
->AddLink( strlink
, m_transferwnd
->downloadlistctrl
->GetCategory() );
948 ctl
->SetValue(wxEmptyString
);
952 // Formerly known as LoadRazorPrefs()
953 bool CamuleDlg::LoadGUIPrefs(bool override_pos
, bool override_size
)
955 // Create a config base for loading razor preferences
956 wxConfigBase
*config
= wxConfigBase::Get();
957 // If config haven't been created exit without loading
958 if (config
== NULL
) {
962 // The section where to save in in file
963 wxString section
= wxT("/Razor_Preferences/");
965 // Get window size and position
966 int x1
= config
->Read(section
+ wxT("MAIN_X_POS"), -1);
967 int y1
= config
->Read(section
+ wxT("MAIN_Y_POS"), -1);
968 int x2
= config
->Read(section
+ wxT("MAIN_X_SIZE"), -1);
969 int y2
= config
->Read(section
+ wxT("MAIN_Y_SIZE"), -1);
971 int maximized
= config
->Read(section
+ wxT("Maximized"), 01);
973 // Kry - Random usable pos for m_srv_split_pos
974 m_srv_split_pos
= config
->Read(section
+ wxT("SRV_SPLITTER_POS"), 463l);
975 if (!override_size
) {
976 if (x2
> 0 && y2
> 0) {
980 // Probably first run.
987 // If x1 and y1 != -1 Redefine location
988 if(x1
!= -1 && y1
!= -1) {
989 wxRect display
= wxGetClientDisplayRect();
990 if (x1
<= display
.GetRightTop().x
&& y1
<= display
.GetRightBottom().y
) {
993 // It's offscreen... so let's not.
998 if (!override_size
&& !override_pos
&& maximized
) {
1006 bool CamuleDlg::SaveGUIPrefs()
1008 /* Razor 1a - Modif by MikaelB
1009 Save client size and position */
1011 // Create a config base for saving razor preferences
1012 wxConfigBase
*config
= wxConfigBase::Get();
1013 // If config haven't been created exit without saving
1014 if (config
== NULL
) {
1017 // The section where to save in in file
1018 wxString section
= wxT("/Razor_Preferences/");
1020 if (!IsIconized()) {
1021 // Main window location and size
1023 GetPosition(&x1
, &y1
);
1026 // Saving window size and position
1027 config
->Write(section
+wxT("MAIN_X_POS"), (long) x1
);
1028 config
->Write(section
+wxT("MAIN_Y_POS"), (long) y1
);
1030 config
->Write(section
+wxT("MAIN_X_SIZE"), (long) x2
);
1031 config
->Write(section
+wxT("MAIN_Y_SIZE"), (long) y2
);
1033 config
->Write(section
+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
1036 // Saving sash position of splitter in server window
1037 config
->Write(section
+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos
);
1039 config
->Flush(true);
1047 void CamuleDlg::OnMinimize(wxIconizeEvent
& evt
)
1049 // Evil Hack: check if the mouse is inside the window
1051 if (wxFindWindowAtPoint(wxGetMousePosition()))
1054 if (m_prefsDialog
&& m_prefsDialog
->IsShown()) {
1057 if (m_wndTaskbarNotifier
&& thePrefs::DoMinToTray()) {
1058 #if wxCHECK_VERSION(2, 9, 0)
1059 Show(!evt
.IsIconized());
1061 Show(!evt
.Iconized());
1071 void CamuleDlg::OnGUITimer(wxTimerEvent
& WXUNUSED(evt
))
1073 // Former TimerProc section
1075 static uint32 msPrev1
, msPrev5
;
1077 uint32 msCur
= theStats::GetUptimeMillis();
1079 // can this actually happen under wxwin ?
1085 static uint32 msPrevGraph
, msPrevStats
;
1086 int msGraphUpdate
= thePrefs::GetTrafficOMeterInterval() * 1000;
1087 if ((msGraphUpdate
> 0) && ((msCur
/ msGraphUpdate
) > (msPrevGraph
/ msGraphUpdate
))) {
1088 // trying to get the graph shifts evenly spaced after a change in the update period
1089 msPrevGraph
= msCur
;
1091 GraphUpdateInfo update
= theApp
->m_statistics
->GetPointsForUpdate();
1093 m_statisticswnd
->UpdateStatGraphs(theStats::GetPeakConnections(), update
);
1094 m_kademliawnd
->UpdateGraph(update
);
1097 int sStatsUpdate
= thePrefs::GetStatsInterval();
1098 if ((sStatsUpdate
> 0) && ((int)(msCur
- msPrevStats
) > sStatsUpdate
*1000)) {
1099 if (m_statisticswnd
->IsShownOnScreen()) {
1100 msPrevStats
= msCur
;
1101 m_statisticswnd
->ShowStatistics();
1106 if (msCur
-msPrev5
> 5000) { // every 5 seconds
1109 if (thePrefs::ShowCatTabInfos() && theApp
->amuledlg
->m_activewnd
== theApp
->amuledlg
->m_transferwnd
) {
1110 m_transferwnd
->UpdateCatTabTitles();
1112 if (thePrefs::AutoSortDownload()) {
1113 m_transferwnd
->downloadlistctrl
->SortList();
1114 m_transferwnd
->clientlistctrl
->SortList();
1115 m_sharedfileswnd
->peerslistctrl
->SortList();
1117 m_kademliawnd
->UpdateNodeCount(CStatistics::GetKadNodes());
1120 if (msCur
-msPrev1
> 1000) { // every second
1122 if (m_CurrentBlinkBitmap
== 12) {
1123 m_CurrentBlinkBitmap
= 7;
1126 if (m_BlinkMessages
) {
1127 m_CurrentBlinkBitmap
= 12;
1136 void CamuleDlg::SetMessagesTool()
1138 wxWindowUpdateLocker
freezer(m_wndToolbar
);
1140 m_wndToolbar
->FindById(ID_BUTTONMESSAGES
)->SetNormalBitmap(m_tblist
.GetBitmap(m_CurrentBlinkBitmap
));
1142 m_wndToolbar
->SetToolNormalBitmap(ID_BUTTONMESSAGES
, m_tblist
.GetBitmap(m_CurrentBlinkBitmap
));
1146 void CamuleDlg::LaunchUrl( const wxString
& url
)
1150 cmd
= thePrefs::GetBrowser();
1152 // Pipes cause problems, so escape them
1153 tmp
.Replace( wxT("|"), wxT("%7C") );
1155 if ( !cmd
.IsEmpty() ) {
1156 if (!cmd
.Replace(wxT("%s"), tmp
)) {
1157 // No %s found, just append the url
1158 cmd
+= wxT(" ") + tmp
;
1161 CTerminationProcess
*p
= new CTerminationProcess(cmd
);
1162 if (wxExecute(cmd
, wxEXEC_ASYNC
, p
)) {
1163 AddLogLineN(_("Launch Command: ") + cmd
);
1169 wxLaunchDefaultBrowser(tmp
);
1172 // Unable to execute browser. But this error message doesn't make sense,
1173 // cosidering that you _can't_ set the browser executable path... =/
1174 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1178 bool CamuleDlg::Check_and_Init_Skin()
1181 wxString
skinFileName(thePrefs::GetSkin());
1183 if (skinFileName
.IsEmpty() || skinFileName
.IsSameAs(_("- default -"))) {
1187 wxString
userDir(JoinPaths(thePrefs::GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1189 wxStandardPathsBase
&spb(wxStandardPaths::Get());
1191 wxString
dataDir(spb
.GetPluginsDir());
1192 #elif defined(__WXMAC__)
1193 wxString
dataDir(spb
.GetDataDir());
1195 wxString
dataDir(spb
.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1197 wxString
systemDir(JoinPaths(dataDir
,wxT("skins")) + wxFileName::GetPathSeparator());
1200 skinFileName
.Replace(wxT("User:"), userDir
);
1201 skinFileName
.Replace(wxT("System:"), systemDir
);
1203 m_skinFileName
.Assign(skinFileName
);
1204 if (!m_skinFileName
.FileExists()) {
1205 AddLogLineC(CFormat(
1206 _("Skin directory '%s' does not exist")) %
1209 } else if (!m_skinFileName
.IsFileReadable()) {
1210 AddLogLineC(CFormat(
1211 _("WARNING: Unable to open skin file '%s' for read")) %
1216 wxFFileInputStream
in(m_skinFileName
.GetFullPath());
1217 wxZipInputStream
zip(in
);
1220 while ((entry
= zip
.GetNextEntry()) != NULL
) {
1221 wxZipEntry
*& current
= cat
[entry
->GetInternalName()];
1230 void CamuleDlg::Add_Skin_Icon(
1231 const wxString
&iconName
,
1232 const wxBitmap
&stdIcon
,
1237 wxFFileInputStream
in(m_skinFileName
.GetFullPath());
1238 wxZipInputStream
zip(in
);
1240 ZipCatalog::iterator it
= cat
.find(wxZipEntry::GetInternalName(iconName
+ wxT(".png")));
1241 if ( it
!= cat
.end() ) {
1242 zip
.OpenEntry(*it
->second
);
1243 if ( !new_image
.LoadFile(zip
,wxBITMAP_TYPE_PNG
) ) {
1244 AddLogLineN(wxT("Warning: Error loading icon for ") +
1249 AddLogLineN(wxT("Warning: Can't load icon for ") +
1256 wxBitmap
bmp(useSkins
? new_image
: stdIcon
);
1257 if (iconName
.StartsWith(wxT("Client_"))) {
1258 m_imagelist
.Add(bmp
);
1259 } else if (iconName
.StartsWith(wxT("Toolbar_"))) {
1265 void CamuleDlg::Apply_Clients_Skin()
1267 bool useSkins
= Check_and_Init_Skin();
1269 // Clear the client image list
1270 m_imagelist
.RemoveAll();
1272 // Add the images to the image list
1273 for (int i
= 0; i
< CLIENT_SKIN_SIZE
; ++i
) {
1274 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames
[i
],
1275 clientImages(i
), useSkins
);
1280 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar
*wndToolbar
)
1282 bool useSkins
= Check_and_Init_Skin();
1285 // Clear the toolbar image list
1286 m_tblist
.RemoveAll();
1288 // Add the images to the image list
1289 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins
);
1290 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins
);
1291 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins
);
1292 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins
);
1293 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins
);
1294 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins
);
1295 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins
);
1296 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins
);
1297 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins
);
1298 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins
);
1299 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins
);
1300 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins
);
1301 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins
);
1303 // Build aMule toolbar
1304 wndToolbar
->SetMargins(0, 0);
1306 // Placeholder. Gets updated by ShowConnectionState
1307 wndToolbar
->AddTool(ID_BUTTONCONNECT
, wxT("..."), m_tblist
.GetBitmap(0));
1309 wndToolbar
->AddSeparator();
1310 wndToolbar
->AddTool(ID_BUTTONNETWORKS
, _("Networks"), m_tblist
.GetBitmap(3), wxNullBitmap
, wxITEM_CHECK
, _("Networks Window"));
1311 wndToolbar
->AddTool(ID_BUTTONSEARCH
, _("Searches"), m_tblist
.GetBitmap(5), wxNullBitmap
, wxITEM_CHECK
, _("Searches Window"));
1312 wndToolbar
->AddTool(ID_BUTTONDOWNLOADS
, _("Downloads"), m_tblist
.GetBitmap(4), wxNullBitmap
, wxITEM_CHECK
, _("Downloads Window"));
1313 wndToolbar
->AddTool(ID_BUTTONSHARED
, _("Shared files"), m_tblist
.GetBitmap(6), wxNullBitmap
, wxITEM_CHECK
, _("Shared Files Window"));
1314 wndToolbar
->AddTool(ID_BUTTONMESSAGES
, _("Messages"), m_tblist
.GetBitmap(7), wxNullBitmap
, wxITEM_CHECK
, _("Messages Window"));
1315 wndToolbar
->AddTool(ID_BUTTONSTATISTICS
, _("Statistics"), m_tblist
.GetBitmap(8), wxNullBitmap
, wxITEM_CHECK
, _("Statistics Graph Window"));
1316 wndToolbar
->AddSeparator();
1317 wndToolbar
->AddTool(ID_BUTTONNEWPREFERENCES
, _("Preferences"), m_tblist
.GetBitmap(9), wxNullBitmap
, wxITEM_NORMAL
, _("Preferences Settings Window"));
1319 wndToolbar
->AddTool(ID_BUTTONIMPORT
, _("Import"), m_tblist
.GetBitmap(10), wxNullBitmap
, wxITEM_NORMAL
, _("The partfile importer tool"));
1321 wndToolbar
->AddTool(ID_ABOUT
, _("About"), m_tblist
.GetBitmap(11), wxNullBitmap
, wxITEM_NORMAL
, _("About/Help"));
1323 wndToolbar
->ToggleTool(ID_BUTTONDOWNLOADS
, true);
1325 // Needed for non-GTK platforms, where the
1326 // items don't get added immediatly.
1327 wndToolbar
->Realize();
1329 // Updates the "Connect" button, and so on.
1330 ShowConnectionState(true);
1334 void CamuleDlg::Create_Toolbar(bool orientation
)
1337 // Create ToolBar from the one designed by wxDesigner (BigBob)
1338 wxToolBar
*current
= GetToolBar();
1340 wxASSERT(current
== m_wndToolbar
);
1343 bool oldorientation
= ((current
->GetWindowStyle() & wxTB_VERTICAL
) == wxTB_VERTICAL
);
1344 if (oldorientation
!= orientation
) {
1346 SetToolBar(NULL
); // Remove old one if present
1347 m_wndToolbar
= NULL
;
1349 current
->ClearTools();
1353 if (!m_wndToolbar
) {
1354 #if wxCHECK_VERSION(3, 1, 2)
1355 m_wndToolbar
= CreateToolBar(
1356 (orientation
? wxTB_VERTICAL
: wxTB_HORIZONTAL
) |
1357 wxNO_BORDER
| wxTB_TEXT
| wxTB_FLAT
|
1358 wxCLIP_CHILDREN
| wxTB_NODIVIDER
);
1360 m_wndToolbar
= CreateToolBar(
1361 (orientation
? wxTB_VERTICAL
: wxTB_HORIZONTAL
) |
1362 wxNO_BORDER
| wxTB_TEXT
| wxTB_3DBUTTONS
|
1363 wxTB_FLAT
| wxCLIP_CHILDREN
| wxTB_NODIVIDER
);
1366 m_wndToolbar
->SetToolBitmapSize(wxSize(32, 32));
1369 Apply_Toolbar_Skin(m_wndToolbar
);
1375 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent
& evt
)
1377 wxFrame::OnSize(evt
);
1378 if (m_transferwnd
&& m_transferwnd
->clientlistctrl
) {
1379 // Transfer window's splitter set again if it's hidden.
1380 if (!m_transferwnd
->clientlistctrl
->GetShowing()) {
1381 int height
= m_transferwnd
->clientlistctrl
->GetSize().GetHeight();
1382 wxSplitterWindow
* splitter
=
1383 CastChild(wxT("splitterWnd"), wxSplitterWindow
);
1384 height
+= splitter
->GetWindow1()->GetSize().GetHeight();
1385 splitter
->SetSashPosition( height
);
1391 void CamuleDlg::OnKeyPressed(wxKeyEvent
& event
)
1393 if (event
.GetKeyCode() == WXK_F1
) {
1394 // Ctrl/Alt/Shift must not be pressed, to avoid
1395 // conflicts with other (global) shortcuts.
1396 if (!event
.HasModifiers() && !event
.ShiftDown()) {
1397 LaunchUrl(wxT("http://wiki.amule.org"));
1406 void CamuleDlg::OnExit(wxCommandEvent
& WXUNUSED(evt
))
1411 void CamuleDlg::DoNetworkRearrange()
1413 #if !defined(__WXOSX_COCOA__)
1414 // in Mac OS with wxWidgets >= 3.0 and COCOA the following seems to cause problems
1415 // (window is not refreshed after changes in network settings)
1416 wxWindowUpdateLocker
freezer(this);
1419 wxToolBarToolBase
* toolbarTool
= m_wndToolbar
->RemoveTool(ID_BUTTONNETWORKS
);
1421 // set the log windows
1422 wxNotebook
* logs_notebook
= CastChild( ID_SRVLOG_NOTEBOOK
, wxNotebook
);
1424 while (logs_notebook
->GetPageCount() > 1) {
1425 logs_notebook
->RemovePage(logs_notebook
->GetPageCount() - 1);
1428 if (thePrefs::GetNetworkED2K()) {
1430 logs_notebook
->AddPage(m_logpages
[1].page
, m_logpages
[1].name
);
1432 logs_notebook
->AddPage(m_logpages
[2].page
, m_logpages
[2].name
);
1435 if (thePrefs::GetNetworkKademlia()) {
1436 logs_notebook
->AddPage(m_logpages
[3].page
, m_logpages
[3].name
);
1439 // Set the main window.
1440 // If we have both networks active, activate a notebook to select between them.
1441 // If only one is active, show the window directly without a surrounding one tab notebook.
1446 // 3: both (in Notebook)
1448 static uint8 currentState
= 3; // on startup we have both enabled
1450 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1452 toolbarTool
->SetLabel(_("Networks"));
1454 else if (thePrefs::GetNetworkED2K()) {
1456 toolbarTool
->SetLabel(_("eD2k network"));
1458 else { // Kad only or no network
1459 newState
= 2; // no network makes no sense anyway, so just show Kad there
1460 toolbarTool
->SetLabel(thePrefs::GetNetworkKademlia() ? _("Kad network") : _("No network"));
1463 if (newState
!= currentState
) {
1464 wxNotebook
* networks_notebook
= CastChild(ID_NETNOTEBOOK
, wxNotebook
);
1465 // First hide all windows
1466 networks_notebook
->Show(false);
1467 m_networkpages
[0].page
->Show(false);
1468 m_networkpages
[1].page
->Show(false);
1469 m_networknotebooksizer
->Clear();
1471 wxWindow
* replacement
= NULL
;
1473 // Move both pages into the notebook if they aren't already there.
1474 if (currentState
== 1) { // ED2K
1475 m_networkpages
[0].page
->Reparent(networks_notebook
);
1476 networks_notebook
->InsertPage(0, m_networkpages
[0].page
, m_networkpages
[0].name
);
1477 } else if (currentState
== 2) { // Kad
1478 m_networkpages
[1].page
->Reparent(networks_notebook
);
1479 networks_notebook
->AddPage(m_networkpages
[1].page
, m_networkpages
[1].name
);
1482 // Now both pages are in the notebook. If we want to show one of them outside, move it back out again.
1483 // Windows that are part of a notebook can't be reparented.
1484 if (newState
== 3) {
1485 // Since we messed with the notebook, we now have to show both pages, one after the other.
1486 // Otherwise GTK gets confused and shows the first tab only.
1487 // (So much for "platform independent".)
1488 networks_notebook
->SetSelection(1);
1489 m_networkpages
[1].page
->Show();
1490 networks_notebook
->SetSelection(0);
1491 m_networkpages
[0].page
->Show();
1492 replacement
= networks_notebook
;
1493 } else if (newState
== 1) {
1494 replacement
= m_networkpages
[0].page
;
1495 networks_notebook
->RemovePage(0);
1497 replacement
= m_networkpages
[1].page
;
1498 networks_notebook
->RemovePage(1);
1501 replacement
->Reparent(m_networknotebooksizer
->GetContainingWindow());
1502 replacement
->Show();
1503 m_networknotebooksizer
->Add(replacement
, 1, wxGROW
| wxALIGN_CENTER_VERTICAL
| wxTOP
, 5);
1504 m_networknotebooksizer
->Layout();
1505 currentState
= newState
;
1510 m_wndToolbar
->InsertTool(2, toolbarTool
);
1511 m_wndToolbar
->EnableTool(ID_BUTTONNETWORKS
, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1512 m_wndToolbar
->EnableTool(ID_BUTTONCONNECT
, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp
->ipfilter
->IsReady());
1514 m_wndToolbar
->Realize();
1516 ShowConnectionState(); // status in the bottom right
1517 m_searchwnd
->FixSearchTypes();
1520 // File_checked_for_headers