-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathamuleDlg.cpp
1501 lines (1232 loc) · 43.4 KB
/
amuleDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// This file is part of the aMule Project.
//
// Copyright (c) 2003-2011 aMule Team ( [email protected] / http://www.amule.org )
// Copyright (c) 2002-2011 Merkur ( [email protected] / http://www.emule-project.net )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
#include <wx/app.h>
#include <wx/archive.h>
#include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
#include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7)
#include <wx/html/htmlwin.h>
#include <wx/mimetype.h> // Do_not_auto_remove (win32)
#include <wx/stattext.h>
#include <wx/stdpaths.h>
#include <wx/textfile.h> // Do_not_auto_remove (win32)
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
#include <wx/sysopt.h>
#include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker
#include <wx/utils.h> // Needed for wxFindWindowAtPoint
#include <common/EventIDs.h>
#include "config.h" // Needed for SVNDATE, PACKAGE, VERSION
#include "amuleDlg.h" // Interface declarations.
#include <common/Format.h> // Needed for CFormat
#include "amule.h" // Needed for theApp
#include "ChatWnd.h" // Needed for CChatWnd
#include "SourceListCtrl.h" // Needed for CSourceListCtrl
#include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
#include "DownloadQueue.h" // Needed for CDownloadQueue
#include "KadDlg.h" // Needed for CKadDlg
#include "Logger.h"
#include "MuleTrayIcon.h"
#include "muuli_wdr.h" // Needed for ID_BUTTON*
#include "Preferences.h" // Needed for CPreferences
#include "PrefsUnifiedDlg.h"
#include "SearchDlg.h" // Needed for CSearchDlg
#include "Server.h" // Needed for CServer
#include "ServerConnect.h" // Needed for CServerConnect
#include "ServerWnd.h" // Needed for CServerWnd
#include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
#include "SharedFilePeersListCtrl.h" // Needed for CSharedFilePeersListCtrl
#include "Statistics.h" // Needed for theStats
#include "StatisticsDlg.h" // Needed for CStatisticsDlg
#include "TerminationProcess.h" // Needed for CTerminationProcess
#include "TransferWnd.h" // Needed for CTransferWnd
#ifndef CLIENT_GUI
#include "PartFileConvertDlg.h"
#endif
#include "IPFilter.h"
#ifndef __WINDOWS__
#include "aMule.xpm"
#endif
#include "kademlia/kademlia/Kademlia.h"
#include "MuleVersion.h" // Needed for GetMuleVersion()
#ifdef ENABLE_IP2COUNTRY
#include "IP2Country.h" // Needed for IP2Country
#endif
#ifdef ENABLE_IP2COUNTRY // That's no bug. MSVC has ENABLE_IP2COUNTRY always on,
// but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again.
void CamuleDlg::IP2CountryDownloadFinished(uint32 result)
{
m_IP2Country->DownloadFinished(result);
}
void CamuleDlg::EnableIP2Country()
{
if (thePrefs::IsGeoIPEnabled()) {
m_IP2Country->Enable();
}
}
#else
void CamuleDlg::IP2CountryDownloadFinished(uint32){}
void CamuleDlg::EnableIP2Country(){}
#endif
BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)
EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)
EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)
EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)
EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)
EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)
EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)
EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)
EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)
EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)
EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)
EVT_CLOSE(CamuleDlg::OnClose)
EVT_ICONIZE(CamuleDlg::OnMinimize)
EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)
EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)
EVT_SIZE(CamuleDlg::OnMainGUISizeChange)
EVT_KEY_UP(CamuleDlg::OnKeyPressed)
EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)
END_EVENT_TABLE()
#ifndef wxCLOSE_BOX
#define wxCLOSE_BOX 0
#endif
CamuleDlg::CamuleDlg(
wxWindow* pParent,
const wxString &title,
wxPoint where,
wxSize dlg_size)
:
wxFrame(
pParent, -1, title, where, dlg_size,
wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT|
wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX,
wxT("aMule")),
m_activewnd(NULL),
m_transferwnd(NULL),
m_serverwnd(NULL),
m_sharedfileswnd(NULL),
m_searchwnd(NULL),
m_chatwnd(NULL),
m_statisticswnd(NULL),
m_kademliawnd(NULL),
m_prefsDialog(NULL),
m_srv_split_pos(0),
m_imagelist(16,16),
m_tblist(32,32),
m_prefsVisible(false),
m_wndToolbar(NULL),
m_wndTaskbarNotifier(NULL),
m_nActiveDialog(DT_NETWORKS_WND),
m_is_safe_state(false),
m_BlinkMessages(false),
m_CurrentBlinkBitmap(24),
m_last_iconizing(0),
m_skinFileName(),
m_clientSkinNames(CLIENT_SKIN_SIZE)
{
// Initialize skin names
m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer");
m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting");
m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue");
m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull");
m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown");
m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol");
m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent");
m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy");
m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey");
m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow");
m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload");
m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend");
m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule");
m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey");
m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid");
m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule");
m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant");
m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza");
m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule");
m_clientSkinNames[Client_Unknown] = wxT("Unknown");
m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile");
m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile");
m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile");
m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile");
m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile");
m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly");
m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted");
// wxWidgets send idle events to ALL WINDOWS by default... *SIGH*
wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
wxInitAllImageHandlers();
Apply_Clients_Skin();
#ifdef __WINDOWS__
wxSystemOptions::SetOption(wxT("msw.remap"), 0);
#endif
#if !defined(__WXMAC__)
// this crashes on Mac with wx 2.9
SetIcon(wxICON(aMule));
#endif
srand(time(NULL));
// Create new sizer and stuff a wxPanel in there.
wxFlexGridSizer *s_main = new wxFlexGridSizer(1);
s_main->AddGrowableCol(0);
s_main->AddGrowableRow(0);
wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize);
s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0);
muleDlg(p_cnt, false, true);
SetSizer(s_main, true);
m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos);
AddLogLineN(wxEmptyString);
AddLogLineN(wxT(" - ") +
CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion());
AddLogLineN(wxT(" ") +
CFormat(_("Running on %s")) % wxGetOsDescription());
AddLogLineN(wxT(" - ") +
wxString(_("Visit http://www.amule.org to check if a new version is available.")));
AddLogLineN(wxEmptyString);
#ifdef ENABLE_IP2COUNTRY
m_GeoIPavailable = true;
m_IP2Country = new CIP2Country(thePrefs::GetConfigDir());
#else
m_GeoIPavailable = false;
#endif
m_searchwnd = new CSearchDlg(p_cnt);
m_transferwnd = new CTransferWnd(p_cnt);
m_sharedfileswnd = new CSharedFilesWnd(p_cnt);
m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics);
m_chatwnd = new CChatWnd(p_cnt);
m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg);
m_serverwnd->Show(false);
m_searchwnd->Show(false);
m_transferwnd->Show(false);
m_sharedfileswnd->Show(false);
m_statisticswnd->Show(false);
m_chatwnd->Show(false);
// Create the GUI timer
gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT);
if (!gui_timer) {
AddLogLineN(_("FATAL ERROR: Failed to create Timer"));
exit(1);
}
// Set transfers as active window
Create_Toolbar(thePrefs::VerticalToolbar());
SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true );
bool override_where = (where != wxDefaultPosition);
bool override_size = (
(dlg_size.x != DEFAULT_SIZE_X) ||
(dlg_size.y != DEFAULT_SIZE_Y) );
if (!LoadGUIPrefs(override_where, override_size)) {
// Prefs not loaded for some reason, exit
AddLogLineC(wxT("Error! Unable to load Preferences") );
return;
}
// Prepare the dialog, sets the splitter-position (AFTER window size is set)
m_transferwnd->Prepare();
m_is_safe_state = true;
// Init statistics stuff, better do it asap
m_statisticswnd->Init();
m_kademliawnd->Init();
m_searchwnd->UpdateCatChoice();
if (thePrefs::UseTrayIcon()) {
CreateSystray();
}
Show(true);
// Must we start minimized?
if (thePrefs::GetStartMinimized()) {
Iconize(true);
}
// Set shortcut keys
wxAcceleratorEntry entries[] = {
wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT)
};
SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries));
ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook);
wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook);
wxASSERT(logs_notebook->GetPageCount() == 4);
wxASSERT(networks_notebook->GetPageCount() == 2);
for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) {
m_logpages[i].page = logs_notebook->GetPage(i);
m_logpages[i].name = logs_notebook->GetPageText(i);
}
for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) {
m_networkpages[i].page = networks_notebook->GetPage(i);
m_networkpages[i].name = networks_notebook->GetPageText(i);
}
DoNetworkRearrange();
}
// Madcat - Sets Fast ED2K Links Handler on/off.
void CamuleDlg::ShowED2KLinksHandler( bool show )
{
// Errorchecking in case the pointer becomes invalid ...
if (s_fed2klh == NULL) {
wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."));
return;
}
s_dlgcnt->Show( s_fed2klh, show );
s_dlgcnt->Layout();
}
// Toogles ed2k link handler.
void CamuleDlg::ToogleED2KLinksHandler()
{
// Errorchecking in case the pointer becomes invalid ...
if (s_fed2klh == NULL) {
wxLogWarning(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."));
return;
}
ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh));
}
void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg)
{
m_nActiveDialog = type;
if ( type == DT_TRANSFER_WND ) {
if (thePrefs::ShowCatTabInfos()) {
m_transferwnd->UpdateCatTabTitles();
}
}
if ( m_activewnd ) {
m_activewnd->Show(false);
contentSizer->Detach(m_activewnd);
}
contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND);
dlg->Show(true);
m_activewnd=dlg;
s_dlgcnt->Layout();
// Since we might be suspending redrawing while hiding the dialog
// we have to refresh it once it is visible again
dlg->Refresh( true );
dlg->SetFocus();
if ( type == DT_SHARED_WND ) {
// set up splitter now that window sizes are defined
m_sharedfileswnd->Prepare();
}
}
void CamuleDlg::UpdateTrayIcon(int percent)
{
// set trayicon-icon
if(!theApp->IsConnected()) {
m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent);
} else {
if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) {
m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent);
} else {
m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent);
}
}
}
void CamuleDlg::CreateSystray()
{
wxCHECK_RET(m_wndTaskbarNotifier == NULL,
wxT("Systray already created"));
m_wndTaskbarNotifier = new CMuleTrayIcon();
// This will effectively show the Tray Icon.
UpdateTrayIcon(0);
}
void CamuleDlg::RemoveSystray()
{
delete m_wndTaskbarNotifier;
m_wndTaskbarNotifier = NULL;
}
void CamuleDlg::OnToolBarButton(wxCommandEvent& ev)
{
static int lastbutton = ID_BUTTONDOWNLOADS;
// Kry - just if the GUI is ready for it
if ( m_is_safe_state ) {
// Rehide the handler if needed
if ( lastbutton == ID_BUTTONSEARCH && !thePrefs::GetFED2KLH() ) {
if (ev.GetId() != ID_BUTTONSEARCH) {
ShowED2KLinksHandler( false );
} else {
// Toogle ED2K handler.
ToogleED2KLinksHandler();
}
}
if ( lastbutton != ev.GetId() ) {
switch ( ev.GetId() ) {
case ID_BUTTONNETWORKS:
SetActiveDialog(DT_NETWORKS_WND, m_serverwnd);
// Set serverlist splitter position
CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )->SetSashPosition(m_srv_split_pos, true);
break;
case ID_BUTTONSEARCH:
// The search dialog should always display the handler
if ( !thePrefs::GetFED2KLH() )
ShowED2KLinksHandler( true );
SetActiveDialog(DT_SEARCH_WND, m_searchwnd);
break;
case ID_BUTTONDOWNLOADS:
SetActiveDialog(DT_TRANSFER_WND, m_transferwnd);
// Prepare the dialog, sets the splitter-position
m_transferwnd->Prepare();
break;
case ID_BUTTONSHARED:
SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd);
break;
case ID_BUTTONMESSAGES:
m_BlinkMessages = false;
SetActiveDialog(DT_CHAT_WND, m_chatwnd);
break;
case ID_BUTTONSTATISTICS:
SetActiveDialog(DT_STATS_WND, m_statisticswnd);
break;
// This shouldn't happen, but just in case
default:
AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") );
break;
}
}
m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() );
lastbutton = ev.GetId();
}
}
void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev))
{
wxString msg = wxT(" ");
#ifdef CLIENT_GUI
msg << _("aMule remote control ") << wxT(VERSION);
#else
msg << wxT("aMule ") << wxT(VERSION);
#endif
msg << wxT(" ");
#ifdef SVNDATE
msg << _("Snapshot:") << wxT("\n ") << wxT(SVNDATE);
#endif
msg << wxT("\n\n") << _("'All-Platform' p2p client based on eMule \n\n") <<
_("Website: http://www.amule.org \n") <<
_("Forum: http://forum.amule.org \n") <<
_("FAQ: http://wiki.amule.org \n\n") <<
_("Contact: [email protected] (administrative issues) \n") <<
_("Copyright (c) 2003-2019 aMule Team \n\n") <<
_("Part of aMule is based on \n") <<
_("Kademlia: Peer-to-peer routing based on the XOR metric.\n") <<
_(" Copyright (c) 2002-2011 Petar Maymounkov ( [email protected] )\n") <<
_("http://kademlia.scs.cs.nyu.edu\n");
if (m_is_safe_state) {
wxMessageBox(msg, _("Message"), wxOK | wxICON_INFORMATION, this);
}
}
void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev))
{
if (m_is_safe_state) {
if (m_prefsDialog == NULL) {
m_prefsDialog = new PrefsUnifiedDlg(this);
}
m_prefsDialog->TransferToWindow();
m_prefsDialog->Show(true);
m_prefsDialog->Raise();
}
}
void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev))
{
#ifndef CLIENT_GUI
if (m_is_safe_state) {
CPartFileConvertDlg::ShowGUI(NULL);
}
#endif
}
CamuleDlg::~CamuleDlg()
{
theApp->amuledlg = NULL;
#ifdef ENABLE_IP2COUNTRY
delete m_IP2Country;
#endif
AddLogLineN(_("aMule dialog destroyed"));
}
void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt))
{
bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting())
#ifdef CLIENT_GUI
|| theApp->IsConnectedKad() // there's no Kad running state atm
#else
|| (Kademlia::CKademlia::IsRunning())
#endif
;
if (thePrefs::GetNetworkED2K()) {
if (disconnect) {
//disconnect if currently connected
if (theApp->serverconnect->IsConnecting()) {
theApp->serverconnect->StopConnectionTry();
} else {
theApp->serverconnect->Disconnect();
}
} else {
//connect if not currently connected
AddLogLineC(_("Connecting"));
theApp->serverconnect->ConnectToAnyServer();
}
} else {
wxASSERT(!theApp->IsConnectedED2K());
}
// Connect Kad also
if (thePrefs::GetNetworkKademlia()) {
if( disconnect ) {
theApp->StopKad();
} else {
theApp->StartKad();
}
} else {
#ifndef CLIENT_GUI
wxASSERT(!Kademlia::CKademlia::IsRunning());
#endif
}
ShowConnectionState();
}
void CamuleDlg::ResetLog(int id)
{
wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl);
wxCHECK_RET(ct, wxT("Resetting unknown log"));
ct->Clear();
if (id == ID_LOGVIEW) {
// Also clear the log line
wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText);
text->SetLabel(wxEmptyString);
text->GetParent()->Layout();
}
}
void CamuleDlg::AddLogLine(const wxString& line)
{
bool addtostatusbar = line[0] == '!';
wxString bufferline = line.Mid(1);
// Add the message to the log-view
wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl );
if ( ct ) {
// Bold critical log-lines
// Works in Windows too thanks to wxTE_RICH2 style in muuli
wxTextAttr style = ct->GetDefaultStyle();
wxFont font = style.GetFont();
font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
style.SetFont(font);
style.SetFontSize(8);
ct->SetDefaultStyle(style);
ct->AppendText(bufferline);
ct->ShowPosition( ct->GetLastPosition() - 1 );
}
// Set the status-bar if the event warrents it
if ( addtostatusbar ) {
// Escape "&"s, which would otherwise not show up
bufferline.Replace( wxT("&"), wxT("&&") );
wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText );
// Only show the first line if multiple lines
text->SetLabel( bufferline.BeforeFirst( wxT('\n') ) );
text->SetToolTip( bufferline );
text->GetParent()->Layout();
}
}
void CamuleDlg::AddServerMessageLine(wxString& message)
{
wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl );
if(cv) {
if (message.Length() > 500) {
cv->AppendText(message.Left(500) + wxT("\n"));
} else {
cv->AppendText(message + wxT("\n"));
}
cv->ShowPosition(cv->GetLastPosition()-1);
}
}
void CamuleDlg::ShowConnectionState(bool skinChanged)
{
static wxImageList status_arrows(16,16,true,0);
if (!status_arrows.GetImageCount()) {
// Generate the image list (This is only done once)
for (int t = 0; t < 7; ++t) {
status_arrows.Add(connImages(t));
}
}
m_serverwnd->UpdateED2KInfo();
m_serverwnd->UpdateKadInfo();
////////////////////////////////////////////////////////////
// Determine the status of the networks
//
enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 };
enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 };
ED2KState ed2kState = ED2KOff;
EKadState kadState = EKadOff;
////////////////////////////////////////////////////////////
// Update the label on the status-bar and determine
// the states of the two networks.
//
wxString msgED2K;
if (theApp->IsConnectedED2K()) {
CServer* server = theApp->serverconnect->GetCurrentServer();
if (server) {
msgED2K = CFormat(wxT("eD2k: %s")) % server->GetListName();
}
if (theApp->serverconnect->IsLowID()) {
ed2kState = ED2KLowID;
} else {
ed2kState = ED2KHighID;
}
} else if (theApp->serverconnect->IsConnecting()) {
msgED2K = _("eD2k: Connecting");
ed2kState = ED2KConnecting;
} else if (thePrefs::GetNetworkED2K()) {
msgED2K = _("eD2k: Disconnected");
}
wxString msgKad;
if (theApp->IsConnectedKad()) {
if (theApp->IsFirewalledKad()) {
msgKad = _("Kad: Firewalled");
kadState = EKadFW;
} else {
msgKad = _("Kad: Connected");
kadState = EKadOK;
}
} else if (theApp->IsKadRunning()) {
msgKad = _("Kad: Connecting");
kadState = EKadConnecting;
} else if (thePrefs::GetNetworkKademlia()) {
msgKad = _("Kad: Off");
}
wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText );
{ wxCHECK_RET(connLabel, wxT("'connLabel' widget not found")); }
wxString labelMsg;
if (msgED2K.Length() && msgKad.Length()) {
labelMsg = msgED2K + wxT(" | ") + msgKad;
} else {
labelMsg = msgED2K + msgKad;
}
connLabel->SetLabel(labelMsg);
connLabel->GetParent()->Layout();
////////////////////////////////////////////////////////////
// Update the connect/disconnect/cancel button.
//
enum EConnState {
ECS_Unknown,
ECS_Connected,
ECS_Connecting,
ECS_Disconnected
};
static EConnState s_oldState = ECS_Unknown;
EConnState currentState = ECS_Disconnected;
if (theApp->serverconnect->IsConnecting() ||
(theApp->IsKadRunning() && !theApp->IsConnectedKad())) {
currentState = ECS_Connecting;
} else if (theApp->IsConnected()) {
currentState = ECS_Connected;
} else {
currentState = ECS_Disconnected;
}
if ( (true == skinChanged) || (currentState != s_oldState) ) {
wxWindowUpdateLocker freezer(m_wndToolbar);
wxToolBarToolBase* toolbarTool = m_wndToolbar->FindById(ID_BUTTONCONNECT);
switch (currentState) {
case ECS_Connecting:
toolbarTool->SetLabel(_("Cancel"));
toolbarTool->SetShortHelp(_("Stop the current connection attempts"));
toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2));
break;
case ECS_Connected:
toolbarTool->SetLabel(_("Disconnect"));
toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks"));
toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1));
break;
default:
toolbarTool->SetLabel(_("Connect"));
toolbarTool->SetShortHelp(_("Connect to the currently enabled networks"));
toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0));
}
m_wndToolbar->EnableTool(ID_BUTTONCONNECT, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady());
s_oldState = currentState;
}
////////////////////////////////////////////////////////////
// Update the globe-icon in the lower-right corner.
// (only if connection state has changed)
//
static ED2KState s_ED2KOldState = ED2KUndef;
static EKadState s_EKadOldState = EKadUndef;
if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) {
s_ED2KOldState = ed2kState;
s_EKadOldState = kadState;
wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap );
wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"));
wxBitmap statusIcon = connBitmap->GetBitmap();
// Sanity check - otherwise there's a crash here if aMule runs out of resources
if (statusIcon.GetRefData() == NULL) {
return;
}
wxMemoryDC bitmapDC(statusIcon);
status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
connBitmap->SetBitmap(statusIcon);
}
}
void CamuleDlg::ShowUserCount(const wxString& info)
{
wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText );
// Update Kad tab
m_serverwnd->UpdateKadInfo();
label->SetLabel(info);
label->GetParent()->Layout();
}
void CamuleDlg::ShowTransferRate()
{
float kBpsUp = theStats::GetUploadRate() / 1024.0;
float kBpsDown = theStats::GetDownloadRate() / 1024.0;
float MBpsUp = kBpsUp / 1024.0;
float MBpsDown = kBpsDown / 1024.0;
bool showMBpsUp = (MBpsUp >= 1);
bool showMBpsDown = (MBpsDown >= 1);
wxString buffer;
if( thePrefs::ShowOverhead() )
{
buffer = CFormat(_("Up: %.1f%s (%.1f) | Down: %.1f%s (%.1f)"))
% (showMBpsUp ? MBpsUp : kBpsUp) % (showMBpsUp ? _(" MB/s") : ((kBpsUp > 0) ? _(" kB/s") : wxT(""))) % (theStats::GetUpOverheadRate() / 1024.0)
% (showMBpsDown ? MBpsDown : kBpsDown) % (showMBpsDown ? _(" MB/s") : ((kBpsDown > 0) ? _(" kB/s") : wxT(""))) % (theStats::GetDownOverheadRate() / 1024.0);
} else {
buffer = CFormat(_("Up: %.1f%s | Down: %.1f%s"))
% (showMBpsUp ? MBpsUp : kBpsUp) % (showMBpsUp ? _(" MB/s") : ((kBpsUp > 0) ? _(" kB/s") : wxT("")))
% (showMBpsDown ? MBpsDown : kBpsDown) % (showMBpsDown ? _(" MB/s") : ((kBpsDown > 0) ? _(" kB/s") : wxT("")));
}
buffer.Truncate(50); // Max size 50
wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText );
label->SetLabel(buffer);
label->GetParent()->Layout();
// Show upload/download speed in title
if (thePrefs::GetShowRatesOnTitle()) {
wxString UpDownSpeed = CFormat(wxT("Up: %.1f%s | Down: %.1f%s"))
% (showMBpsUp ? MBpsUp : kBpsUp) % (showMBpsUp ? _(" MB/s") : ((kBpsUp > 0) ? _(" kB/s") : wxT("")))
% (showMBpsDown ? MBpsDown : kBpsDown) % (showMBpsDown ? _(" MB/s") : ((kBpsDown > 0) ? _(" kB/s") : wxT("")));
if (thePrefs::GetShowRatesOnTitle() == 1) {
SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed);
} else {
SetTitle(UpDownSpeed + wxT(" -- ") + theApp->m_FrameTitle);
}
}
wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon());
if (m_wndTaskbarNotifier) {
// set trayicon-icon
int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate());
UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown);
wxString buffer2;
if ( theApp->IsConnected() ) {
buffer2 = CFormat(_("aMule (%s | Connected)")) % buffer;
} else {
buffer2 = CFormat(_("aMule (%s | Disconnected)")) % buffer;
}
m_wndTaskbarNotifier->SetTrayToolTip(buffer2);
}
wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap );
bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0)));
}
void CamuleDlg::DlgShutDown()
{
// Are we already shutting down or still on init?
if ( m_is_safe_state == false ) {
return;
}
// we are going DOWN
m_is_safe_state = false;
// Stop the GUI Timer
delete gui_timer;
m_transferwnd->downloadlistctrl->DeleteAllItems();
// We want to delete the systray too!
RemoveSystray();
}
void CamuleDlg::OnClose(wxCloseEvent& evt)
{
if (thePrefs::HideOnClose() && evt.CanVeto()) {
Show(false);
evt.Veto();
return;
}
// This will be here till the core close is != app close
if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) {
if (wxNO == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")) % theApp->GetMuleAppName()),
wxString(_("Exit confirmation")), wxYES_NO, this)) {
evt.Veto();
return;
}
}
SaveGUIPrefs();
Enable(false);
Show(false);
theApp->ShutDown(evt);
}
void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt))
{
wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl );
for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) {
wxString strlink = ctl->GetLineText(i);
strlink.Trim(true);
strlink.Trim(false);
if ( !strlink.IsEmpty() ) {
theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() );
}
}
ctl->SetValue(wxEmptyString);
}
// Formerly known as LoadRazorPrefs()
bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size)
{
// Create a config base for loading razor preferences
wxConfigBase *config = wxConfigBase::Get();
// If config haven't been created exit without loading
if (config == NULL) {
return false;
}
// The section where to save in in file
wxString section = wxT("/Razor_Preferences/");
// Get window size and position
int x1 = config->Read(section + wxT("MAIN_X_POS"), -1);
int y1 = config->Read(section + wxT("MAIN_Y_POS"), -1);
int x2 = config->Read(section + wxT("MAIN_X_SIZE"), -1);
int y2 = config->Read(section + wxT("MAIN_Y_SIZE"), -1);
int maximized = config->Read(section + wxT("Maximized"), 01);
// Kry - Random usable pos for m_srv_split_pos
m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS"), 463l);
if (!override_size) {
if (x2 > 0 && y2 > 0) {
SetSize(x2, y2);
} else {
#ifndef __WXGTK__
// Probably first run.
Maximize();
#endif
}
}
if (!override_pos) {
// If x1 and y1 != -1 Redefine location
if(x1 != -1 && y1 != -1) {
wxRect display = wxGetClientDisplayRect();
if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) {
Move(x1, y1);
} else {
// It's offscreen... so let's not.
}
}
}
if (!override_size && !override_pos && maximized) {
Maximize();
}
return true;
}