Upstream tarball 20080603
[amule.git] / src / amuleDlg.cpp
blob9e894f6caa16deb6f375819c1e3219800ff20ce7
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <wx/app.h>
28 #include <wx/archive.h>
29 #include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
30 #include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
31 #include <wx/html/htmlwin.h>
32 #include <wx/mimetype.h> // Do_not_auto_remove (win32)
33 #include <wx/stattext.h>
34 #include <wx/stdpaths.h>
35 #include <wx/textfile.h> // Do_not_auto_remove (win32)
36 #include <wx/tokenzr.h>
37 #include <wx/wfstream.h>
38 #include <wx/zipstrm.h>
39 #include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker
41 #include <common/EventIDs.h>
43 #ifdef HAVE_CONFIG_H
44 #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
45 #else
46 #include <common/ClientVersion.h>
47 #endif // HAVE_CONFIG_H
49 #include "amuleDlg.h" // Interface declarations.
51 #include <common/Format.h> // Needed for CFormat
52 #include "amule.h" // Needed for theApp
53 #include "ChatWnd.h" // Needed for CChatWnd
54 #include "ClientListCtrl.h" // Needed for CClientListCtrl
55 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
56 #include "DownloadQueue.h" // Needed for CDownloadQueue
57 #include "KadDlg.h" // Needed for CKadDlg
58 #include "Logger.h"
59 #include "MuleTrayIcon.h"
60 #include "muuli_wdr.h" // Needed for ID_BUTTON*
61 #include "Preferences.h" // Needed for CPreferences
62 #include "PrefsUnifiedDlg.h"
63 #include "SearchDlg.h" // Needed for CSearchDlg
64 #include "Server.h" // Needed for CServer
65 #include "ServerConnect.h" // Needed for CServerConnect
66 #include "ServerWnd.h" // Needed for CServerWnd
67 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
68 #include "Statistics.h" // Needed for theStats
69 #include "StatisticsDlg.h" // Needed for CStatisticsDlg
70 #include "TerminationProcess.h" // Needed for CTerminationProcess
71 #include "TransferWnd.h" // Needed for CTransferWnd
72 #ifndef CLIENT_GUI
73 #include "PartFileConvert.h"
74 #endif
76 #ifndef __WXMSW__
77 #include "aMule.xpm"
78 #endif
80 #include "kademlia/kademlia/Kademlia.h"
82 #ifdef ENABLE_IP2COUNTRY
83 #include "IP2Country.h" // Needed for IP2Country
84 #endif
86 BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
88 EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
89 EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
90 EVT_TOOL(ID_BUTTONTRANSFER, CamuleDlg::OnToolBarButton)
91 EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
92 EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
93 EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
94 EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
96 EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
97 #ifndef CLIENT_GUI
98 EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
99 #endif
101 EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
103 EVT_CLOSE(CamuleDlg::OnClose)
104 EVT_ICONIZE(CamuleDlg::OnMinimize)
106 EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
107 EVT_BUTTON(IDC_SHOWSTATUSTEXT, CamuleDlg::OnBnStatusText)
109 EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
111 EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
113 EVT_KEY_UP(CamuleDlg::OnKeyPressed)
115 EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
117 END_EVENT_TABLE()
119 #ifndef wxCLOSE_BOX
120 #define wxCLOSE_BOX 0
121 #endif
123 CamuleDlg::CamuleDlg(
124 wxWindow* pParent,
125 const wxString &title,
126 wxPoint where,
127 wxSize dlg_size)
129 wxFrame(
130 pParent, -1, title, where, dlg_size,
131 wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
132 wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
133 wxT("aMule")),
134 m_activewnd(NULL),
135 m_transferwnd(NULL),
136 m_serverwnd(NULL),
137 m_sharedfileswnd(NULL),
138 m_searchwnd(NULL),
139 m_chatwnd(NULL),
140 m_statisticswnd(NULL),
141 m_kademliawnd(NULL),
142 m_prefsDialog(NULL),
143 m_srv_split_pos(0),
144 m_imagelist(16,16),
145 m_tblist(32,32),
146 m_prefsVisible(false),
147 m_wndToolbar(NULL),
148 m_wndTaskbarNotifier(NULL),
149 m_nActiveDialog(DT_NETWORKS_WND),
150 m_is_safe_state(false),
151 m_BlinkMessages(false),
152 m_CurrentBlinkBitmap(24),
153 m_last_iconizing(0),
154 m_skinFileName(),
155 m_clientSkinNames(CLIENT_SKIN_SIZE)
157 // Initialize skin names
158 m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
159 m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
160 m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
161 m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
162 m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
163 m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
164 m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
165 m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
166 m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
167 m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
168 m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
169 m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
170 m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
171 m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
172 m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
173 m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
174 m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
175 m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
176 m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
177 m_clientSkinNames[Client_Unknown] = wxT("Unknown");
178 m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
179 m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
180 m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
181 m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
182 m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
183 m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
184 m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
186 // wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
187 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
188 wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
189 wxInitAllImageHandlers();
190 Apply_Clients_Skin();
192 bool override_where = where != wxDefaultPosition;
193 bool override_size =
194 dlg_size.x != DEFAULT_SIZE_X ||
195 dlg_size.y != DEFAULT_SIZE_Y;
196 if (!LoadGUIPrefs(override_where, override_size)) {
197 // Prefs not loaded for some reason, exit
198 AddLogLineM( true, wxT("Error! Unable to load Preferences") );
199 return;
202 SetIcon(wxICON(aMule));
204 srand(time(NULL));
206 // Create new sizer and stuff a wxPanel in there.
207 wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
208 s_main->AddGrowableCol(0);
209 s_main->AddGrowableRow(0);
211 wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
212 s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
213 muleDlg(p_cnt, false, true);
214 SetSizer(s_main, true);
216 m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
217 AddLogLineM(false, wxEmptyString);
218 AddLogLineM(false, wxT(" - ") +
219 CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
220 AddLogLineM(false, wxT(" ") +
221 CFormat(_("Running on %s")) % wxGetOsDescription());
222 AddLogLineM(false, wxT(" - ") +
223 wxString(_("Visit http://www.amule.org to check if a new version is available.")));
224 AddLogLineM(false, wxEmptyString);
226 #ifdef ENABLE_IP2COUNTRY
227 m_IP2Country = new CIP2Country();
228 #endif
229 m_searchwnd = new CSearchDlg(p_cnt);
230 m_transferwnd = new CTransferWnd(p_cnt);
231 m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
232 m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
233 m_chatwnd = new CChatWnd(p_cnt);
234 m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
236 m_serverwnd->Show(false);
237 m_searchwnd->Show(false);
238 m_transferwnd->Show(false);
239 m_sharedfileswnd->Show(false);
240 m_statisticswnd->Show(false);
241 m_chatwnd->Show(false);
243 // Create the GUI timer
244 gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
245 if (!gui_timer) {
246 AddLogLine(false, _("Fatal Error: Failed to create Timer"));
247 exit(1);
250 // Set transfers as active window
251 Create_Toolbar(thePrefs::VerticalToolbar());
252 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
253 m_wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true );
255 m_is_safe_state = true;
257 // Init statistics stuff, better do it asap
258 m_statisticswnd->Init();
259 m_kademliawnd->Init();
260 m_searchwnd->UpdateCatChoice();
261 if (thePrefs::UseTrayIcon()) {
262 CreateSystray();
265 Show(true);
266 // Must we start minimized?
267 if (thePrefs::GetStartMinimized()) {
268 DoIconize(true);
271 // Set shortcut keys
272 wxAcceleratorEntry entries[] = {
273 wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
276 SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
277 ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
279 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
280 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
282 wxASSERT(logs_notebook->GetPageCount() == 4);
283 wxASSERT(networks_notebook->GetPageCount() == 2);
285 for (int i = 0; i < logs_notebook->GetPageCount(); ++i) {
286 m_logpages[i].page = logs_notebook->GetPage(i);
287 m_logpages[i].name = logs_notebook->GetPageText(i);
290 for (int i = 0; i < networks_notebook->GetPageCount(); ++i) {
291 m_networkpages[i].page = networks_notebook->GetPage(i);
292 m_networkpages[i].name = networks_notebook->GetPageText(i);
295 DoNetworkRearrange();
299 // Madcat - Sets Fast ED2K Links Handler on/off.
300 void CamuleDlg::ShowED2KLinksHandler( bool show )
302 // Errorchecking in case the pointer becomes invalid ...
303 if (s_fed2klh == NULL) {
304 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
305 return;
308 s_dlgcnt->Show( s_fed2klh, show );
309 s_dlgcnt->Layout();
312 // Toogles ed2k link handler.
313 void CamuleDlg::ToogleED2KLinksHandler()
315 // Errorchecking in case the pointer becomes invalid ...
316 if (s_fed2klh == NULL) {
317 wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
318 return;
320 ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
323 void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
325 m_nActiveDialog = type;
327 if ( type == DT_TRANSFER_WND ) {
328 if (thePrefs::ShowCatTabInfos()) {
329 m_transferwnd->UpdateCatTabTitles();
333 if ( m_activewnd ) {
334 m_activewnd->Show(false);
335 contentSizer->Detach(m_activewnd);
338 contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
339 dlg->Show(true);
340 m_activewnd=dlg;
341 s_dlgcnt->Layout();
343 // Since we might be suspending redrawing while hiding the dialog
344 // we have to refresh it once it is visible again
345 dlg->Refresh( true );
346 dlg->SetFocus();
350 void CamuleDlg::UpdateTrayIcon(int percent)
352 // set trayicon-icon
353 if(!theApp->IsConnected()) {
354 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
355 } else {
356 if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
357 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
358 } else {
359 m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
365 void CamuleDlg::CreateSystray()
367 wxCHECK_RET(m_wndTaskbarNotifier == NULL,
368 wxT("Systray already created"));
370 m_wndTaskbarNotifier = new CMuleTrayIcon();
371 // This will effectively show the Tray Icon.
372 UpdateTrayIcon(0);
376 void CamuleDlg::RemoveSystray()
378 delete m_wndTaskbarNotifier;
379 m_wndTaskbarNotifier = NULL;
383 void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
385 static int lastbutton = ID_BUTTONTRANSFER;
387 // Kry - just if the GUI is ready for it
388 if ( m_is_safe_state ) {
390 // Rehide the handler if needed
391 if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
392 if (ev.GetId() != ID_BUTTONSEARCH) {
393 ShowED2KLinksHandler( false );
394 } else {
395 // Toogle ED2K handler.
396 ToogleED2KLinksHandler();
400 if ( lastbutton != ev.GetId() ) {
401 switch ( ev.GetId() ) {
402 case ID_BUTTONNETWORKS:
403 SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
404 // Set serverlist splitter position
405 CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
406 break;
408 case ID_BUTTONSEARCH:
409 // The search dialog should always display the handler
410 if ( !thePrefs::GetFED2KLH() )
411 ShowED2KLinksHandler( true );
413 SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
414 break;
416 case ID_BUTTONTRANSFER:
417 SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
418 // Prepare the dialog, sets the splitter-position
419 m_transferwnd->Prepare();
420 break;
422 case ID_BUTTONSHARED:
423 SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
424 break;
426 case ID_BUTTONMESSAGES:
427 m_BlinkMessages = false;
428 SetActiveDialog(DT_CHAT_WND, m_chatwnd);
429 break;
431 case ID_BUTTONSTATISTICS:
432 SetActiveDialog(DT_STATS_WND, m_statisticswnd);
433 break;
435 // This shouldn't happen, but just in case
436 default:
437 AddLogLineM( true, wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
438 break;
442 m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
443 lastbutton = ev.GetId();
448 void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
450 wxString msg = wxT(" ");
451 #ifdef CLIENT_GUI
452 msg << _("aMule remote control ") << wxT(VERSION);
453 #else
454 msg << wxT("aMule ") << wxT(VERSION);
455 #endif
456 msg << wxT(" ");
457 #ifdef SVNDATE
458 msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
459 #endif
460 msg << wxT("\n\n") << _(" 'All-Platform' p2p client based on eMule \n\n") <<
461 _(" Website: http://www.amule.org \n") <<
462 _(" Forum: http://forum.amule.org \n") <<
463 _(" FAQ: http://wiki.amule.org \n\n") <<
464 _(" Contact: admin@amule.org (administrative issues) \n") <<
465 _(" Copyright (C) 2003-2008 aMule Team \n\n") <<
466 _(" Part of aMule is based on \n") <<
467 _("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
468 _(" Copyright (C) 2002 Petar Maymounkov\n") <<
469 _(" http://kademlia.scs.cs.nyu.edu\n");
471 if (m_is_safe_state) {
472 wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
477 void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
479 if (m_is_safe_state) {
480 if (m_prefsDialog == NULL) {
481 m_prefsDialog = new PrefsUnifiedDlg(this);
484 m_prefsDialog->TransferToWindow();
485 m_prefsDialog->Show(true);
486 m_prefsDialog->Raise();
491 #ifndef CLIENT_GUI
492 void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
494 if ( m_is_safe_state ) {
495 CPartFileConvert::ShowGUI(NULL);
498 #endif
500 CamuleDlg::~CamuleDlg()
502 printf("Shutting down aMule...\n");
504 SaveGUIPrefs();
506 theApp->amuledlg = NULL;
508 #ifdef ENABLE_IP2COUNTRY
509 delete m_IP2Country;
510 #endif
512 printf("aMule dialog destroyed\n");
516 void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
519 bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
520 #ifndef CLIENT_GUI
521 || (Kademlia::CKademlia::IsRunning())
522 #endif
524 if (thePrefs::GetNetworkED2K()) {
525 if (disconnect) {
526 //disconnect if currently connected
527 if (theApp->serverconnect->IsConnecting()) {
528 theApp->serverconnect->StopConnectionTry();
529 } else {
530 theApp->serverconnect->Disconnect();
532 } else {
533 //connect if not currently connected
534 AddLogLine(true, _("Connecting"));
535 theApp->serverconnect->ConnectToAnyServer();
537 } else {
538 wxASSERT(!theApp->IsConnectedED2K());
541 // Connect Kad also
542 if (thePrefs::GetNetworkKademlia()) {
543 if( disconnect ) {
544 theApp->StopKad();
545 } else {
546 theApp->StartKad();
548 } else {
549 #ifndef CLIENT_GUI
550 wxASSERT(!Kademlia::CKademlia::IsRunning());
551 #endif
554 ShowConnectionState();
558 void CamuleDlg::OnBnStatusText(wxCommandEvent& WXUNUSED(evt))
560 wxString line = CastChild(wxT("infoLabel"), wxStaticText)->GetLabel();
562 if (!line.IsEmpty()) {
563 wxMessageBox(line, wxString(_("Status text")), wxOK|wxICON_INFORMATION, this);
568 void CamuleDlg::ResetLog(int id)
570 wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
571 wxCHECK_RET(ct, wxT("Resetting unknown log"));
573 ct->Clear();
575 if (id == ID_LOGVIEW) {
576 // Also clear the log line
577 wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
578 text->SetLabel(wxEmptyString);
579 text->GetParent()->Layout();
584 void CamuleDlg::AddLogLine(bool addtostatusbar, const wxString& line)
586 // Remove newspace at end, it causes problems with the layout...
587 wxString bufferline = line.Strip(wxString::trailing);
589 // Create the timestamp
590 wxString stamp = wxDateTime::Now().FormatISODate() + wxT(" ") + wxDateTime::Now().FormatISOTime() + wxT(": ");
592 // Add the message to the log-view
593 wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
594 if ( ct ) {
595 if ( bufferline.IsEmpty() ) {
596 // If it's empty we just write a blank line with no timestamp.
597 ct->AppendText( wxT("\n") );
598 } else {
599 // Bold critical log-lines
600 wxTextAttr style = ct->GetDefaultStyle();
601 wxFont font = style.GetFont();
602 font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
603 style.SetFont(font);
604 ct->SetDefaultStyle(style);
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->GetParent()->Layout();
630 void CamuleDlg::AddServerMessageLine(wxString& message)
632 wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
633 if(cv) {
634 if (message.Length() > 500) {
635 cv->AppendText(message.Left(500) + wxT("\n"));
636 } else {
637 cv->AppendText(message + wxT("\n"));
639 cv->ShowPosition(cv->GetLastPosition()-1);
644 void CamuleDlg::ShowConnectionState()
646 static wxImageList status_arrows(16,16,true,0);
647 if (!status_arrows.GetImageCount()) {
648 // Generate the image list (This is only done once)
649 for (int t = 0; t < 7; ++t) {
650 status_arrows.Add(connImages(t));
654 m_serverwnd->UpdateED2KInfo();
655 m_serverwnd->UpdateKadInfo();
658 ////////////////////////////////////////////////////////////
659 // Determine the status of the networks
661 enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3 };
662 enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6 };
664 ED2KState ed2kState = ED2KOff;
665 EKadState kadState = EKadOff;
667 ////////////////////////////////////////////////////////////
668 // Update the label on the status-bar and determine
669 // the states of the two networks.
671 wxString msgED2K;
672 if (theApp->IsConnectedED2K()) {
673 CServer* server = theApp->serverconnect->GetCurrentServer();
674 if (server) {
675 msgED2K = CFormat(wxT("ED2K: %s")) % server->GetListName();
678 if (theApp->serverconnect->IsLowID()) {
679 ed2kState = ED2KLowID;
680 } else {
681 ed2kState = ED2KHighID;
683 } else if (theApp->serverconnect->IsConnecting()) {
684 msgED2K = _("ED2K: Connecting");
686 ed2kState = ED2KConnecting;
687 } else if (thePrefs::GetNetworkED2K()) {
688 msgED2K = _("ED2K: Disconnected");
691 wxString msgKad;
692 if (theApp->IsConnectedKad()) {
693 if (theApp->IsFirewalledKad()) {
694 msgKad = _("Kad: Firewalled");
696 kadState = EKadFW;
697 } else {
698 msgKad = _("Kad: Connected");
700 kadState = EKadOK;
702 } else if (theApp->IsKadRunning()) {
703 msgKad = _("Kad: Connecting");
705 kadState = EKadConnecting;
706 } else if (thePrefs::GetNetworkKademlia()) {
707 msgKad = _("Kad: Off");
710 wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
711 wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"));
713 wxString labelMsg;
714 if (msgED2K.Length() && msgKad.Length()) {
715 labelMsg = msgED2K + wxT(" | ") + msgKad;
716 } else {
717 labelMsg = msgED2K + msgKad;
720 connLabel->SetLabel(labelMsg);
721 connLabel->GetParent()->Layout();
724 ////////////////////////////////////////////////////////////
725 // Update the connect/disconnect/cancel button.
727 enum EConnState {
728 ECS_Unknown,
729 ECS_Connected,
730 ECS_Connecting,
731 ECS_Disconnected
734 static EConnState s_oldState = ECS_Unknown;
735 EConnState currentState = ECS_Disconnected;
737 if (theApp->serverconnect->IsConnecting() ||
738 (theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
739 currentState = ECS_Connecting;
740 } else if (theApp->IsConnected()) {
741 currentState = ECS_Connected;
742 } else {
743 currentState = ECS_Disconnected;
746 if (currentState != s_oldState) {
747 wxWindowUpdateLocker freezer(m_wndToolbar);
749 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONCONNECT);
751 switch (currentState) {
752 case ECS_Connecting:
753 toolbarTool->SetLabel(_("Cancel"));
754 toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
755 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
756 break;
758 case ECS_Connected:
759 toolbarTool->SetLabel(_("Disconnect"));
760 toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
761 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
762 break;
764 default:
765 toolbarTool->SetLabel(_("Connect"));
766 toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
767 toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
770 m_wndToolbar->InsertTool(0, toolbarTool);
771 m_wndToolbar->Realize();
773 s_oldState = currentState;
777 ////////////////////////////////////////////////////////////
778 // Update the globe-icon in the lower-right corner.
780 wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
781 wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
783 wxBitmap statusIcon = connBitmap->GetBitmap();
784 wxMemoryDC bitmapDC(statusIcon);
786 status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
787 status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
789 connBitmap->SetBitmap(statusIcon);
793 void CamuleDlg::ShowUserCount(const wxString& info)
795 wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
797 // Update Kad tab
798 m_serverwnd->UpdateKadInfo();
800 label->SetLabel(info);
801 label->GetParent()->Layout();
805 void CamuleDlg::ShowTransferRate()
807 float kBpsUp = theStats::GetUploadRate() / 1024.0;
808 float kBpsDown = theStats::GetDownloadRate() / 1024.0;
809 wxString buffer;
810 if( thePrefs::ShowOverhead() )
812 buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0);
813 } else {
814 buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
816 buffer.Truncate(50); // Max size 50
818 wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
819 label->SetLabel(buffer);
820 label->GetParent()->Layout();
822 // Show upload/download speed in title
823 if (thePrefs::GetShowRatesOnTitle()) {
824 wxString UpDownSpeed = wxString::Format(wxT(" -- Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown);
825 SetTitle(theApp->m_FrameTitle + UpDownSpeed);
828 wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
829 if (m_wndTaskbarNotifier) {
830 // set trayicon-icon
831 int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
832 UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
834 wxString buffer2;
835 if ( theApp->IsConnected() ) {
836 buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
837 } else {
838 buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
840 m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
843 wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
844 bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
847 void CamuleDlg::DlgShutDown()
849 // Are we already shutting down or still on init?
850 if ( m_is_safe_state == false ) {
851 return;
854 // we are going DOWN
855 m_is_safe_state = false;
857 // Stop the GUI Timer
858 delete gui_timer;
859 m_transferwnd->downloadlistctrl->DeleteAllItems();
861 // We want to delete the systray too!
862 RemoveSystray();
865 void CamuleDlg::OnClose(wxCloseEvent& evt)
867 // This will be here till the core close is != app close
868 if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
869 if (wxNO == wxMessageBox(wxString(_("Do you really want to exit aMule?")),
870 wxString(_("Exit confirmation")), wxYES_NO, this)) {
871 evt.Veto();
872 return;
876 Enable(false);
877 Show(false);
879 theApp->ShutDown(evt);
883 void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
885 wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
887 for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
888 wxString strlink = ctl->GetLineText(i);
889 strlink.Trim(true);
890 strlink.Trim(false);
891 if ( !strlink.IsEmpty() ) {
892 theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
896 ctl->SetValue(wxEmptyString);
900 // Formerly known as LoadRazorPrefs()
901 bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
903 // Create a config base for loading razor preferences
904 wxConfigBase *config = wxConfigBase::Get();
905 // If config haven't been created exit without loading
906 if (config == NULL) {
907 return false;
910 // The section where to save in in file
911 wxString section = wxT("/Razor_Preferences/");
913 // Get window size and position
914 int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
915 int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
916 int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
917 int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
919 int maximized = config->Read(section + wxT("Maximized"), 01);
921 // Kry - Random usable pos for m_srv_split_pos
922 m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
923 if (!override_size) {
924 if (x2 > 0 && y2 > 0) {
925 SetSize(x2, y2);
926 } else {
927 #ifndef __WXGTK__
928 // Probably first run.
929 Maximize();
930 #endif
934 if (!override_pos) {
935 // If x1 and y1 != -1 Redefine location
936 if(x1 != -1 && y1 != -1) {
937 wxRect display = wxGetClientDisplayRect();
938 if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
939 Move(x1, y1);
940 } else {
941 // It's offscreen... so let's not.
946 if (!override_size && !override_pos && maximized) {
947 Maximize();
950 return true;
954 bool CamuleDlg::SaveGUIPrefs()
956 /* Razor 1a - Modif by MikaelB
957 Save client size and position */
959 // Create a config base for saving razor preferences
960 wxConfigBase *config = wxConfigBase::Get();
961 // If config haven't been created exit without saving
962 if (config == NULL) {
963 return false;
965 // The section where to save in in file
966 wxString section = wxT("/Razor_Preferences/");
968 // Main window location and size
969 int x1, y1, x2, y2;
970 GetPosition(&x1, &y1);
971 GetSize(&x2, &y2);
973 // Saving window size and position
974 config->Write(section+wxT("MAIN_X_POS"), (long) x1);
975 config->Write(section+wxT("MAIN_Y_POS"), (long) y1);
977 config->Write(section+wxT("MAIN_X_SIZE"), (long) x2);
978 config->Write(section+wxT("MAIN_Y_SIZE"), (long) y2);
980 config->Write(section+wxT("Maximized"), (long) (IsMaximized() ? 1 : 0));
982 // Saving sash position of splitter in server window
983 config->Write(section+wxT("SRV_SPLITTER_POS"), (long) m_srv_split_pos);
985 config->Flush(true);
987 /* End modif */
989 return true;
993 void CamuleDlg::DoIconize(bool iconize)
995 // Evil Hack: check if the mouse is inside the window
996 #ifndef __WINDOWS__
997 if (GetScreenRect().Contains(wxGetMousePosition()))
998 #endif
1000 if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) {
1001 if (iconize) {
1002 // Skip() will do it.
1003 //Iconize(true);
1004 if (SafeState()) {
1005 Show(false);
1007 } else {
1008 Show(true);
1009 Raise();
1011 } else {
1012 // Will be done by Skip();
1013 //Iconize(iconize);
1018 void CamuleDlg::OnMinimize(wxIconizeEvent& evt)
1020 if (m_prefsDialog && m_prefsDialog->IsShown()) {
1021 // Veto.
1022 } else {
1023 if (m_wndTaskbarNotifier) {
1024 DoIconize(evt.Iconized());
1026 evt.Skip();
1030 void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt))
1032 // Former TimerProc section
1034 static uint32 msPrev1, msPrev5, msPrevStats;
1036 uint32 msCur = theStats::GetUptimeMillis();
1038 // can this actually happen under wxwin ?
1039 if (!SafeState()) {
1040 return;
1043 #ifndef CLIENT_GUI
1044 static uint32 msPrevGraph;
1045 int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000;
1046 if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) {
1047 // trying to get the graph shifts evenly spaced after a change in the update period
1048 msPrevGraph = msCur;
1050 GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate();
1052 m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update);
1053 m_kademliawnd->UpdateGraph(update);
1055 #else
1056 //#warning TODO: CORE/GUI -- EC needed
1057 #endif
1059 int sStatsUpdate = thePrefs::GetStatsInterval();
1060 if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) {
1061 if (m_statisticswnd->IsShownOnScreen()) {
1062 msPrevStats = msCur;
1063 m_statisticswnd->ShowStatistics();
1067 if (msCur-msPrev5 > 5000) { // every 5 seconds
1068 msPrev5 = msCur;
1069 ShowTransferRate();
1070 if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) {
1071 m_transferwnd->UpdateCatTabTitles();
1073 if (thePrefs::AutoSortDownload()) {
1074 m_transferwnd->downloadlistctrl->SortList();
1078 if (msCur-msPrev1 > 1000) { // every second
1079 msPrev1 = msCur;
1080 if (m_CurrentBlinkBitmap == 12) {
1081 m_CurrentBlinkBitmap = 7;
1082 SetMessagesTool();
1083 } else {
1084 if (m_BlinkMessages) {
1085 m_CurrentBlinkBitmap = 12;
1086 SetMessagesTool();
1094 void CamuleDlg::SetMessagesTool()
1096 int pos = m_wndToolbar->GetToolPos(ID_BUTTONMESSAGES);
1097 wxASSERT(pos == 6); // so we don't miss a change on wx2.4
1099 wxWindowUpdateLocker freezer(m_wndToolbar);
1100 m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES, m_tblist.GetBitmap(m_CurrentBlinkBitmap));
1105 Try to launch the specified url:
1106 - Windows: Default or custom browser will be used.
1107 - Mac: Currently not implemented
1108 - Anything else: Try a number of hardcoded browsers. Should be made configurable...
1110 void CamuleDlg::LaunchUrl( const wxString& url )
1112 wxString cmd;
1114 cmd = thePrefs::GetBrowser();
1115 if ( !cmd.IsEmpty() ) {
1116 wxString tmp = url;
1117 // Pipes cause problems, so escape them
1118 tmp.Replace( wxT("|"), wxT("%7C") );
1120 if (!cmd.Replace(wxT("%s"), tmp)) {
1121 // No %s found, just append the url
1122 cmd += wxT(" ") + tmp;
1125 CTerminationProcess *p = new CTerminationProcess(cmd);
1126 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1127 printf( "Launch Command: %s\n", (const char *)unicode2char(cmd));
1128 return;
1129 } else {
1130 delete p;
1132 #ifdef __WXMSW__
1133 } else {
1134 wxFileType* ft =
1135 wxTheMimeTypesManager->GetFileTypeFromExtension(wxT("html"));
1136 if (!ft) {
1137 wxLogError(wxT("Impossible to determine the file type for extension html. Please edit your MIME types."));
1138 return;
1141 bool ok = ft->GetOpenCommand(
1142 &cmd, wxFileType::MessageParameters(url, wxT("")));
1143 delete ft;
1145 if (!ok) {
1146 wxMessageBox(
1147 _("Could not determine the command for running the browser."),
1148 wxT("Browsing problem"), wxOK|wxICON_EXCLAMATION, this);
1149 return;
1152 wxPuts(wxT("Launch Command: ") + cmd);
1153 CTerminationProcess *p = new CTerminationProcess(cmd);
1154 if (wxExecute(cmd, wxEXEC_ASYNC, p)) {
1155 return;
1156 } else {
1157 delete p;
1159 #endif // __WXMSW__
1161 // Unable to execute browser. But this error message doesn't make sense,
1162 // cosidering that you _can't_ set the browser executable path... =/
1163 wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences."));
1167 wxString CamuleDlg::GenWebSearchUrl(const wxString &filename, WebSearch wsProvider )
1169 wxString URL;
1170 switch (wsProvider) {
1171 case WS_FILEHASH:
1172 URL = wxT("http://www.filehash.com/search.html?pattern=FILENAME&submit=Find");
1173 break;
1174 default:
1175 wxASSERT(0);
1177 URL.Replace(wxT("FILENAME"), filename);
1179 return URL;
1183 bool CamuleDlg::Check_and_Init_Skin()
1185 bool ret = true;
1186 wxString skinFileName(thePrefs::GetSkin());
1188 wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator());
1190 wxStandardPathsBase &spb(wxStandardPaths::Get());
1191 #ifdef __WXMSW__
1192 wxString dataDir(spb.GetPluginsDir());
1193 #elif defined(__WXMAC__)
1194 wxString dataDir(spb.GetDataDir());
1195 #else
1196 wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
1197 #endif
1198 wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator());
1201 skinFileName.Replace(wxT("User:"), userDir );
1202 skinFileName.Replace(wxT("System:"), systemDir );
1204 m_skinFileName.Assign(skinFileName);
1205 if (!m_skinFileName.FileExists()) {
1206 AddLogLineM(true, CFormat(
1207 _("Skin directory '%s' does not exist")) %
1208 skinFileName );
1209 ret = false;
1210 } else if (!m_skinFileName.IsFileReadable()) {
1211 AddLogLineM(true, CFormat(
1212 _("Warning: Unable to open skin file '%s' for read")) %
1213 skinFileName);
1214 ret = false;
1217 wxFFileInputStream in(m_skinFileName.GetFullPath());
1218 wxZipInputStream zip(in);
1220 while ((entry = zip.GetNextEntry()) != NULL) {
1221 wxZipEntry*& current = cat[entry->GetInternalName()];
1222 delete current;
1223 current = entry;
1226 return ret;
1230 void CamuleDlg::Add_Skin_Icon(
1231 const wxString &iconName,
1232 const wxBitmap &stdIcon,
1233 bool useSkins)
1235 wxImage new_image;
1236 if (useSkins) {
1237 wxFFileInputStream in(m_skinFileName.GetFullPath());
1238 wxZipInputStream zip(in);
1240 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 AddLogLineM(false,
1245 wxT("Warning: Error loading icon for ") +
1246 iconName);
1247 useSkins = false;
1249 }else {
1250 AddLogLineM(false,
1251 wxT("Warning: Can't load icon for ") +
1252 iconName);
1253 useSkins = false;
1258 wxBitmap bmp(useSkins ? new_image : stdIcon);
1259 if (iconName.StartsWith(wxT("Client_"))) {
1260 m_imagelist.Add(bmp);
1261 } else if (iconName.StartsWith(wxT("Toolbar_"))) {
1262 m_tblist.Add(bmp);
1267 void CamuleDlg::Apply_Clients_Skin()
1269 bool useSkins = thePrefs::UseSkins() && Check_and_Init_Skin();
1271 // Clear the client image list
1272 m_imagelist.RemoveAll();
1274 // Add the images to the image list
1275 for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) {
1276 Add_Skin_Icon(wxT("Client_") + m_clientSkinNames[i],
1277 clientImages(i), useSkins);
1282 void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar)
1284 bool useSkins = thePrefs::UseSkins() && Check_and_Init_Skin();
1286 // Clear the toolbar image list
1287 m_tblist.RemoveAll();
1289 // Add the images to the image list
1290 Add_Skin_Icon(wxT("Toolbar_Connect"), connButImg(0), useSkins);
1291 Add_Skin_Icon(wxT("Toolbar_Disconnect"), connButImg(1), useSkins);
1292 Add_Skin_Icon(wxT("Toolbar_Connecting"), connButImg(2), useSkins);
1293 Add_Skin_Icon(wxT("Toolbar_Network"), amuleDlgImages(20), useSkins);
1294 Add_Skin_Icon(wxT("Toolbar_Transfers"), amuleDlgImages(21), useSkins);
1295 Add_Skin_Icon(wxT("Toolbar_Search"), amuleDlgImages(22), useSkins);
1296 Add_Skin_Icon(wxT("Toolbar_Shared"), amuleDlgImages(23), useSkins);
1297 Add_Skin_Icon(wxT("Toolbar_Messages"), amuleDlgImages(24), useSkins);
1298 Add_Skin_Icon(wxT("Toolbar_Stats"), amuleDlgImages(25), useSkins);
1299 Add_Skin_Icon(wxT("Toolbar_Prefs"), amuleDlgImages(26), useSkins);
1300 Add_Skin_Icon(wxT("Toolbar_Import"), amuleDlgImages(32), useSkins);
1301 Add_Skin_Icon(wxT("Toolbar_About"), amuleDlgImages(29), useSkins);
1302 Add_Skin_Icon(wxT("Toolbar_Blink"), amuleDlgImages(33), useSkins);
1304 // Build aMule toolbar
1305 wndToolbar->SetMargins(0, 0);
1307 // Placeholder. Gets updated by ShowConnectionState
1308 wndToolbar->AddTool(ID_BUTTONCONNECT, wxT("..."), m_tblist.GetBitmap(0));
1310 wndToolbar->AddSeparator();
1311 wndToolbar->AddTool(ID_BUTTONNETWORKS,
1312 _("Networks"), m_tblist.GetBitmap(3),
1313 wxNullBitmap, wxITEM_CHECK,
1314 _("Networks Window"));
1315 wndToolbar->AddTool(ID_BUTTONSEARCH,
1316 _("Searches"), m_tblist.GetBitmap(5),
1317 wxNullBitmap, wxITEM_CHECK,
1318 _("Searches Window"));
1319 wndToolbar->AddTool(ID_BUTTONTRANSFER,
1320 _("Transfers"), m_tblist.GetBitmap(4),
1321 wxNullBitmap, wxITEM_CHECK,
1322 _("Files Transfers Window"));
1323 wndToolbar->AddTool(ID_BUTTONSHARED,
1324 _("Shared Files"), m_tblist.GetBitmap(6),
1325 wxNullBitmap, wxITEM_CHECK,
1326 _("Shared Files Window"));
1327 wndToolbar->AddTool(ID_BUTTONMESSAGES,
1328 _("Messages"), m_tblist.GetBitmap(7),
1329 wxNullBitmap, wxITEM_CHECK,
1330 _("Messages Window"));
1331 wndToolbar->AddTool(ID_BUTTONSTATISTICS,
1332 _("Statistics"), m_tblist.GetBitmap(8),
1333 wxNullBitmap, wxITEM_CHECK,
1334 _("Statistics Graph Window"));
1335 wndToolbar->AddSeparator();
1336 wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES,
1337 _("Preferences"), m_tblist.GetBitmap(9),
1338 wxNullBitmap, wxITEM_NORMAL,
1339 _("Preferences Settings Window"));
1340 wndToolbar->AddTool(ID_BUTTONIMPORT,
1341 _("Import"), m_tblist.GetBitmap(10),
1342 wxNullBitmap, wxITEM_NORMAL,
1343 _("The partfile importer tool"));
1344 wndToolbar->AddTool(ID_ABOUT,
1345 _("About"), m_tblist.GetBitmap(11),
1346 wxNullBitmap, wxITEM_NORMAL,
1347 _("About/Help"));
1349 wndToolbar->ToggleTool(ID_BUTTONTRANSFER, true);
1351 // Needed for non-GTK platforms, where the
1352 // items don't get added immediatly.
1353 wndToolbar->Realize();
1355 // Updates the "Connect" button, and so on.
1356 ShowConnectionState();
1360 void CamuleDlg::Create_Toolbar(bool orientation)
1362 Freeze();
1363 // Create ToolBar from the one designed by wxDesigner (BigBob)
1364 wxToolBar *current = GetToolBar();
1366 wxASSERT(current == m_wndToolbar);
1368 if (current) {
1369 bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL);
1370 if (oldorientation != orientation) {
1371 current->Destroy();
1372 SetToolBar(NULL); // Remove old one if present
1373 m_wndToolbar = NULL;
1374 } else {
1375 current->ClearTools();
1379 if (!m_wndToolbar) {
1380 m_wndToolbar = CreateToolBar(
1381 (orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) |
1382 wxNO_BORDER | wxTB_TEXT | wxTB_3DBUTTONS |
1383 wxTB_FLAT | wxCLIP_CHILDREN | wxTB_NODIVIDER);
1386 m_wndToolbar->SetToolBitmapSize(wxSize(32, 32));
1389 Apply_Toolbar_Skin(m_wndToolbar);
1390 #ifdef CLIENT_GUI
1391 m_wndToolbar->DeleteTool(ID_BUTTONIMPORT);
1392 #endif
1394 Thaw();
1398 void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt)
1400 wxFrame::OnSize(evt);
1401 if (m_transferwnd && m_transferwnd->clientlistctrl) {
1402 // Transfer window's splitter set again if it's hidden.
1403 if (m_transferwnd->clientlistctrl->GetListView() == vtNone) {
1404 int height = m_transferwnd->clientlistctrl->GetSize().GetHeight();
1405 wxSplitterWindow* splitter =
1406 CastChild(wxT("splitterWnd"), wxSplitterWindow);
1407 height += splitter->GetWindow1()->GetSize().GetHeight();
1408 splitter->SetSashPosition( height );
1415 void CamuleDlg::OnKeyPressed(wxKeyEvent& event)
1417 if (event.GetKeyCode() == WXK_F1) {
1418 // Ctrl/Alt/Shift must not be pressed, to avoid
1419 // conflicts with other (global) shortcuts.
1420 if (!event.HasModifiers() && !event.ShiftDown()) {
1421 LaunchUrl(wxT("http://wiki.amule.org"));
1422 return;
1426 event.Skip();
1430 void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt))
1432 Close();
1435 void CamuleDlg::DoNetworkRearrange()
1438 wxWindowUpdateLocker freezer(this);
1440 wxToolBarToolBase* toolbarTool = m_wndToolbar->RemoveTool(ID_BUTTONNETWORKS);
1442 wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
1443 wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
1445 while (logs_notebook->GetPageCount() > 1) {
1446 logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1);
1449 while (networks_notebook->GetPageCount() > 0) {
1450 networks_notebook->RemovePage(networks_notebook->GetPageCount() - 1);
1453 if (thePrefs::GetNetworkED2K()) {
1454 logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name);
1455 logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name);
1458 m_networkpages[0].page->Show(thePrefs::GetNetworkED2K());
1460 if (thePrefs::GetNetworkKademlia()) {
1461 logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name);
1464 m_networkpages[1].page->Show(thePrefs::GetNetworkKademlia());
1466 networks_notebook->Show(thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia());
1468 wxWindow* replacement = NULL;
1470 m_networknotebooksizer->Clear();
1472 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
1473 toolbarTool->SetLabel(_("Networks"));
1475 m_networkpages[0].page->Reparent(networks_notebook);
1476 m_networkpages[1].page->Reparent(networks_notebook);
1478 networks_notebook->AddPage(m_networkpages[0].page, m_networkpages[0].name);
1479 networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name);
1481 replacement = networks_notebook;
1483 } else if (thePrefs::GetNetworkED2K()) {
1484 toolbarTool->SetLabel(_("ed2k network"));
1485 replacement = m_networkpages[0].page;
1486 m_networkpages[1].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1487 } else if (thePrefs::GetNetworkKademlia()) {
1488 toolbarTool->SetLabel(_("Kad network"));
1489 m_networkpages[0].page->Reparent(m_networknotebooksizer->GetContainingWindow());
1490 replacement = m_networkpages[1].page;
1491 } else {
1492 // No networks.
1493 toolbarTool->SetLabel(_("No network"));
1496 if (replacement) {
1497 replacement->Reparent(m_networknotebooksizer->GetContainingWindow());
1498 m_networknotebooksizer->Add( replacement, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
1499 m_networknotebooksizer->Layout();
1502 m_wndToolbar->InsertTool(2, toolbarTool);
1504 m_wndToolbar->EnableTool(ID_BUTTONNETWORKS, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1505 m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()));
1507 m_wndToolbar->Realize();
1509 m_searchwnd->FixSearchTypes();
1512 // File_checked_for_headers