2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "GuiEvents.h"
28 #include "DownloadQueue.h"
29 #include "ServerList.h"
30 #include "Preferences.h"
31 #include "ExternalConn.h"
32 #include "SearchFile.h"
33 #include "SearchList.h"
40 # include "amuleDlg.h"
41 # include "ServerWnd.h"
42 # include "SearchDlg.h"
43 # include "TransferWnd.h"
44 # include "SharedFilesWnd.h"
45 # include "ServerListCtrl.h"
46 # include "SourceListCtrl.h"
47 # include "SharedFilesCtrl.h"
48 # include "DownloadListCtrl.h"
49 # include "muuli_wdr.h"
50 # include "SharedFilePeersListCtrl.h"
52 # include "PartFileConvertDlg.h"
53 # include "PartFileConvert.h"
58 # include "UploadQueue.h"
59 # include "EMSocket.h"
60 # include "ListenSocket.h"
61 # include "MuleUDPSocket.h"
64 #include <common/MacrosProgramSpecific.h>
66 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY
)
72 void HandleNotification(const CMuleNotiferBase
& ntf
)
74 if (wxThread::IsMain()) {
78 if (theApp
->amuledlg
) {
83 CMuleGUIEvent
evt(ntf
.Clone());
84 wxPostEvent(wxTheApp
, evt
);
89 void HandleNotificationAlways(const CMuleNotiferBase
& ntf
)
91 CMuleGUIEvent
evt(ntf
.Clone());
92 wxPostEvent(wxTheApp
, evt
);
96 void Search_Add_Download(CSearchFile
* file
, uint8 category
)
98 theApp
->downloadqueue
->AddSearchToDownload(file
, category
);
102 void ShowUserCount(wxString
NOT_ON_DAEMON(str
))
105 theApp
->amuledlg
->ShowUserCount(str
);
110 void Search_Update_Progress(uint32
NOT_ON_DAEMON(val
))
113 if (theApp
->amuledlg
->m_searchwnd
) {
115 // Global search ended
116 theApp
->amuledlg
->m_searchwnd
->ResetControls();
117 } else if (val
== 0xfffe) {
119 theApp
->amuledlg
->m_searchwnd
->KadSearchEnd(0);
121 theApp
->amuledlg
->m_searchwnd
->UpdateProgress(val
);
128 void DownloadCtrlUpdateItem(const void* item
)
131 theApp
->ECServerHandler
->m_ec_notifier
->DownloadFile_SetDirty(static_cast<const CPartFile
*>(item
));
134 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
135 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(item
);
141 void DownloadCtrlDoItemSelectionChanged()
144 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
145 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->DoItemSelectionChanged();
151 void NodesURLChanged(wxString
NOT_ON_DAEMON(url
))
154 CastByID(IDC_NODESLISTURL
, NULL
, wxTextCtrl
)->SetValue(url
);
158 void ServersURLChanged(wxString
NOT_ON_DAEMON(url
))
161 CastByID(IDC_SERVERLISTURL
, NULL
, wxTextCtrl
)->SetValue(url
);
168 theApp
->amuledlg
->Iconize(false);
172 void SourceCtrlUpdateSource(uint32
NOT_ON_DAEMON(source
), SourceItemType
NOT_ON_DAEMON(type
))
175 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->clientlistctrl
) {
176 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->UpdateItem(source
, type
);
181 void SourceCtrlAddSource(CPartFile
* NOT_ON_DAEMON(owner
), CClientRef
NOT_ON_DAEMON(source
), SourceItemType
NOT_ON_DAEMON(type
))
184 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->clientlistctrl
) {
185 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->AddSource(owner
, source
, type
);
190 void SourceCtrlRemoveSource(uint32
NOT_ON_DAEMON(source
), const CPartFile
* NOT_ON_DAEMON(owner
))
193 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->clientlistctrl
) {
194 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->RemoveSource(source
, owner
);
199 void SharedCtrlAddClient(CKnownFile
* NOT_ON_DAEMON(owner
), CClientRef
NOT_ON_DAEMON(source
), SourceItemType
NOT_ON_DAEMON(type
))
202 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
) {
203 theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
->AddSource(owner
, source
, type
);
208 void SharedCtrlRefreshClient(uint32
NOT_ON_DAEMON(client
), SourceItemType
NOT_ON_DAEMON(type
))
211 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
) {
212 theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
->UpdateItem(client
, type
);
217 void SharedCtrlRemoveClient(uint32
NOT_ON_DAEMON(source
), const CKnownFile
* NOT_ON_DAEMON(owner
))
220 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
) {
221 theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
->RemoveSource(source
, owner
);
226 void ServerRefresh(CServer
* NOT_ON_DAEMON(server
))
229 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
230 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(server
);
235 void ChatUpdateFriend(CFriend
* NOT_ON_DAEMON(toupdate
))
238 if (theApp
->amuledlg
->m_chatwnd
) {
239 theApp
->amuledlg
->m_chatwnd
->UpdateFriend(toupdate
);
244 void ChatRemoveFriend(CFriend
* toremove
)
247 if (theApp
->amuledlg
->m_chatwnd
) {
248 theApp
->amuledlg
->m_chatwnd
->RemoveFriend(toremove
);
256 void PartFile_Swap_A4AF(CPartFile
* file
)
258 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_SWAP_A4AF_THIS
);
261 void PartFile_Swap_A4AF_Auto(CPartFile
* file
)
263 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO
);
266 void PartFile_Swap_A4AF_Others(CPartFile
* file
)
268 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_SWAP_A4AF_OTHERS
);
271 void PartFile_Pause(CPartFile
* file
)
273 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_PAUSE
);
276 void PartFile_Resume(CPartFile
* file
)
278 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_RESUME
);
281 void PartFile_Stop(CPartFile
* file
)
283 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_STOP
);
286 void PartFile_PrioAuto(CPartFile
* file
, bool val
)
288 theApp
->downloadqueue
->AutoPrio(file
, val
);
291 void PartFile_PrioSet(CPartFile
* file
, uint8 newDownPriority
, bool)
293 theApp
->downloadqueue
->Prio(file
, newDownPriority
);
296 void PartFile_Delete(CPartFile
* file
)
298 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_DELETE
);
301 void PartFile_SetCat(CPartFile
* file
, uint32 val
)
303 theApp
->downloadqueue
->Category(file
, val
);
306 void KnownFile_Up_Prio_Set(CKnownFile
* file
, uint8 val
)
308 theApp
->sharedfiles
->SetFilePrio(file
, val
);
311 void KnownFile_Up_Prio_Auto(CKnownFile
* file
)
313 theApp
->sharedfiles
->SetFilePrio(file
, PR_AUTO
);
316 void KnownFile_Comment_Set(CKnownFile
* file
, wxString comment
, int8 rating
)
318 theApp
->sharedfiles
->SetFileCommentRating(file
, comment
, rating
);
321 void Download_Set_Cat_Prio(uint8
, uint8
)
325 void Download_Set_Cat_Status(uint8
, int)
329 void Upload_Resort_Queue()
335 void SharedFilesShowFile(CKnownFile
* NOT_ON_DAEMON(file
))
338 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
339 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
344 void SharedFilesRemoveFile(CKnownFile
* NOT_ON_DAEMON(file
))
347 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
348 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
);
353 void SharedFilesRemoveAllFiles()
356 if (theApp
->amuledlg
->m_sharedfileswnd
) {
357 theApp
->amuledlg
->m_sharedfileswnd
->RemoveAllSharedFiles();
363 void SharedFilesShowFileList()
366 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
367 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFileList();
373 void SharedFilesUpdateItem(CKnownFile
* NOT_ON_DAEMON(file
))
376 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
377 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
383 void DownloadCtrlAddFile(CPartFile
* file
)
385 theApp
->ECServerHandler
->m_ec_notifier
->DownloadFile_AddFile(file
);
387 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
388 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
393 void DownloadCtrlRemoveFile(CPartFile
* file
)
395 theApp
->ECServerHandler
->m_ec_notifier
->DownloadFile_RemoveFile(file
);
397 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
398 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile(file
);
403 void DownloadCtrlSort()
406 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
407 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->SortList();
412 void ServerAdd(CServer
* NOT_ON_DAEMON(server
))
415 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
416 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->AddServer(server
);
421 void ServerRemove(CServer
* NOT_ON_DAEMON(server
))
424 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
425 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(server
);
430 void ServerRemoveDead()
432 if (theApp
->serverlist
) {
433 theApp
->serverlist
->RemoveDeadServers();
437 void ServerRemoveAll()
440 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
441 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->DeleteAllItems();
446 void ServerHighlight(CServer
* NOT_ON_DAEMON(server
), bool NOT_ON_DAEMON(highlight
))
449 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
450 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->HighlightServer(server
, highlight
);
458 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
459 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->Freeze();
467 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
468 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->Thaw();
473 void ServerUpdateED2KInfo()
476 if (theApp
->amuledlg
->m_serverwnd
) {
477 theApp
->amuledlg
->m_serverwnd
->UpdateED2KInfo();
482 void ServerUpdateKadKInfo()
485 if (theApp
->amuledlg
->m_serverwnd
) {
486 theApp
->amuledlg
->m_serverwnd
->UpdateKadInfo();
495 if (theApp
->amuledlg
->m_searchwnd
) {
496 theApp
->amuledlg
->m_searchwnd
->ResetControls();
501 void SearchLocalEnd()
504 if (theApp
->amuledlg
->m_searchwnd
) {
505 theApp
->amuledlg
->m_searchwnd
->LocalSearchEnd();
510 void KadSearchEnd(uint32
NOT_ON_DAEMON(id
))
513 if (theApp
->amuledlg
->m_searchwnd
) {
514 theApp
->amuledlg
->m_searchwnd
->KadSearchEnd(id
);
517 theApp
->searchlist
->SetKadSearchFinished();
520 void Search_Update_Sources(CSearchFile
* result
)
522 result
->SetDownloadStatus();
524 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
525 theApp
->amuledlg
->m_searchwnd
->UpdateResult(result
);
530 void Search_Add_Result(CSearchFile
* NOT_ON_DAEMON(result
))
533 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
534 theApp
->amuledlg
->m_searchwnd
->AddResult(result
);
540 void ChatConnResult(bool NOT_ON_DAEMON(success
), uint64
NOT_ON_DAEMON(id
), wxString
NOT_ON_DAEMON(message
))
543 if (theApp
->amuledlg
->m_chatwnd
) {
544 theApp
->amuledlg
->m_chatwnd
->ConnectionResult(success
, message
, id
);
549 void ChatProcessMsg(uint64
NOT_ON_DAEMON(sender
), wxString
NOT_ON_DAEMON(message
))
552 if (theApp
->amuledlg
->m_chatwnd
) {
553 theApp
->amuledlg
->m_chatwnd
->ProcessMessage(sender
, message
);
559 void ChatSendCaptcha(wxString
NOT_ON_DAEMON(captcha
), uint64
NOT_ON_DAEMON(to_id
))
562 if (theApp
->amuledlg
->m_chatwnd
) {
563 theApp
->amuledlg
->m_chatwnd
->SendMessage(captcha
, wxEmptyString
, to_id
);
569 void ShowConnState(long NOT_ON_DAEMON(forceUpdate
))
572 theApp
->amuledlg
->ShowConnectionState(forceUpdate
!= 0);
576 void ShowUpdateCatTabTitles()
579 if (theApp
->amuledlg
->m_transferwnd
) {
580 theApp
->amuledlg
->m_transferwnd
->UpdateCatTabTitles();
588 if (theApp
->amuledlg
->m_transferwnd
) {
589 theApp
->amuledlg
->m_transferwnd
->
590 AddCategory(theApp
->glob_prefs
->GetCategory(
591 theApp
->glob_prefs
->GetCatCount()-1));
596 void CategoryUpdate(uint32
NOT_ON_DAEMON(cat
))
599 if (theApp
->amuledlg
->m_transferwnd
) {
600 theApp
->amuledlg
->m_transferwnd
->UpdateCategory(cat
);
601 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->Refresh();
602 theApp
->amuledlg
->m_searchwnd
->UpdateCatChoice();
607 void CategoryDelete(uint32 cat
)
611 theApp
->downloadqueue
->ResetCatParts(cat
);
612 theApp
->glob_prefs
->RemoveCat(cat
);
613 if ( theApp
->glob_prefs
->GetCatCount() == 1 ) {
614 thePrefs::SetAllcatFilter( acfAll
);
616 theApp
->glob_prefs
->SaveCats();
619 if (theApp
->amuledlg
->m_transferwnd
) {
620 theApp
->amuledlg
->m_transferwnd
->RemoveCategory(cat
);
626 void PartFile_Swap_A4AF(CPartFile
* file
)
628 if ((file
->GetStatus(false) == PS_READY
|| file
->GetStatus(false) == PS_EMPTY
)) {
629 CPartFile::SourceSet::const_iterator it
= file
->GetA4AFList().begin();
630 for ( ; it
!= file
->GetA4AFList().end(); ) {
631 it
++->SwapToAnotherFile(true, false, false, file
);
636 void PartFile_Swap_A4AF_Auto(CPartFile
* file
)
638 file
->SetA4AFAuto(!file
->IsA4AFAuto());
641 void PartFile_Swap_A4AF_Others(CPartFile
* file
)
643 if ((file
->GetStatus(false) == PS_READY
) || (file
->GetStatus(false) == PS_EMPTY
)) {
644 CPartFile::SourceSet::const_iterator it
= file
->GetSourceList().begin();
645 for( ; it
!= file
->GetSourceList().end(); ) {
646 it
++->SwapToAnotherFile(false, false, false, NULL
);
651 void PartFile_Pause(CPartFile
* file
)
654 file
->SavePartFile();
657 void PartFile_Resume(CPartFile
* file
)
660 file
->SavePartFile();
663 void PartFile_Stop(CPartFile
* file
)
666 file
->SavePartFile();
669 void PartFile_PrioAuto(CPartFile
* file
, bool val
)
671 file
->SetAutoDownPriority(val
);
674 void PartFile_PrioSet(CPartFile
* file
, uint8 newDownPriority
, bool bSave
)
676 file
->SetDownPriority(newDownPriority
, bSave
);
679 void PartFile_Delete(CPartFile
* file
)
684 void PartFile_SetCat(CPartFile
* file
, uint32 val
)
686 file
->SetCategory(val
);
690 void KnownFile_Up_Prio_Set(CKnownFile
* file
, uint8 val
)
692 file
->SetAutoUpPriority(false);
693 file
->SetUpPriority(val
);
696 void KnownFile_Up_Prio_Auto(CKnownFile
* file
)
698 file
->SetAutoUpPriority(true);
699 file
->UpdateAutoUpPriority();
702 void KnownFile_Comment_Set(CKnownFile
* file
, wxString comment
, int8 rating
)
704 file
->SetFileCommentRating(comment
, rating
);
705 SharedFilesUpdateItem(file
);
709 void Download_Set_Cat_Prio(uint8 cat
, uint8 newprio
)
711 theApp
->downloadqueue
->SetCatPrio(cat
, newprio
);
714 void Download_Set_Cat_Status(uint8 cat
, int newstatus
)
716 theApp
->downloadqueue
->SetCatStatus(cat
, newstatus
);
719 void Upload_Resort_Queue()
721 theApp
->uploadqueue
->ResortQueue();
724 void IPFilter_Reload()
726 theApp
->ipfilter
->Reload();
729 void IPFilter_Update(wxString url
)
731 theApp
->ipfilter
->Update(url
);
734 void Client_Delete(CClientRef client
)
736 client
.Safe_Delete();
740 void ConvertUpdateProgress(float percent
, wxString text
, wxString header
)
742 CPartFileConvertDlg::UpdateProgress(percent
, text
, header
);
745 void ConvertUpdateJobInfo(ConvertInfo info
)
747 CPartFileConvertDlg::UpdateJobInfo(info
);
750 void ConvertRemoveJobInfo(unsigned id
)
752 CPartFileConvertDlg::RemoveJobInfo(id
);
755 void ConvertClearInfos()
757 CPartFileConvertDlg::ClearInfo();
760 void ConvertRemoveJob(unsigned id
)
762 CPartFileConvert::RemoveJob(id
);
765 void ConvertRetryJob(unsigned id
)
767 CPartFileConvert::RetryJob(id
);
770 void ConvertReaddAllJobs()
772 CPartFileConvert::ReaddAllJobs();
774 #endif // #ifndef AMULE_DAEMON
776 #endif // #ifndef CLIENT_GUI
778 void FixAmuleGuiLinkage()
780 // HACK: LibSocketWX is needed in libec, but discarded from libmuleappcommon before,
781 // unless we use something from it in a non-lib module.
782 // I could have done LOTS of full-non-lib builds in the time required to track
784 // Function is never called of course.
785 amuleIPV4Address dummy
;
788 void UDPSocketSend(CMuleUDPSocket
* NOT_ON_REMOTEGUI(socket
))
791 AddDebugLogLineF(logAsio
, wxT("UDPSocketSend"));
796 void UDPSocketReceive(CMuleUDPSocket
* NOT_ON_REMOTEGUI(socket
))
799 AddDebugLogLineF(logAsio
, wxT("UDPSocketReceive"));
800 socket
->OnReceive(0);
806 // File_checked_for_headers