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"
39 # include "amuleDlg.h"
40 # include "ServerWnd.h"
41 # include "SearchDlg.h"
42 # include "TransferWnd.h"
43 # include "SharedFilesWnd.h"
44 # include "ServerListCtrl.h"
45 # include "SourceListCtrl.h"
46 # include "SharedFilesCtrl.h"
47 # include "DownloadListCtrl.h"
48 # include "muuli_wdr.h"
49 # include "SharedFilePeersListCtrl.h"
51 # include "PartFileConvertDlg.h"
52 # include "PartFileConvert.h"
57 # include "UploadQueue.h"
60 #include <common/MacrosProgramSpecific.h>
62 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY
)
68 void HandleNotification(const CMuleNotiferBase
& ntf
)
70 if (wxThread::IsMain()) {
74 if (theApp
->amuledlg
) {
79 CMuleGUIEvent
evt(ntf
.Clone());
80 wxPostEvent(wxTheApp
, evt
);
85 void HandleNotificationAlways(const CMuleNotiferBase
& ntf
)
87 CMuleGUIEvent
evt(ntf
.Clone());
88 wxPostEvent(wxTheApp
, evt
);
92 void Search_Add_Download(CSearchFile
* file
, uint8 category
)
94 theApp
->downloadqueue
->AddSearchToDownload(file
, category
);
98 void ShowUserCount(wxString
NOT_ON_DAEMON(str
))
101 theApp
->amuledlg
->ShowUserCount(str
);
106 void Search_Update_Progress(uint32
NOT_ON_DAEMON(val
))
109 if (theApp
->amuledlg
->m_searchwnd
) {
111 // Global search ended
112 theApp
->amuledlg
->m_searchwnd
->ResetControls();
113 } else if (val
== 0xfffe) {
115 theApp
->amuledlg
->m_searchwnd
->KadSearchEnd(0);
117 theApp
->amuledlg
->m_searchwnd
->UpdateProgress(val
);
124 void DownloadCtrlUpdateItem(const void* item
)
127 theApp
->ECServerHandler
->m_ec_notifier
->DownloadFile_SetDirty((CPartFile
*)item
);
130 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
131 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(item
);
137 void DownloadCtrlDoItemSelectionChanged()
140 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
141 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->DoItemSelectionChanged();
147 void NodesURLChanged(wxString
NOT_ON_DAEMON(url
))
150 CastByID(IDC_NODESLISTURL
, NULL
, wxTextCtrl
)->SetValue(url
);
154 void ServersURLChanged(wxString
NOT_ON_DAEMON(url
))
157 CastByID(IDC_SERVERLISTURL
, NULL
, wxTextCtrl
)->SetValue(url
);
164 theApp
->amuledlg
->Iconize(false);
168 void SourceCtrlUpdateSource(uint32
NOT_ON_DAEMON(source
), SourceItemType
NOT_ON_DAEMON(type
))
171 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->clientlistctrl
) {
172 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->UpdateItem(source
, type
);
177 void SourceCtrlAddSource(CPartFile
* NOT_ON_DAEMON(owner
), CClientRef
NOT_ON_DAEMON(source
), SourceItemType
NOT_ON_DAEMON(type
))
180 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->clientlistctrl
) {
181 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->AddSource(owner
, source
, type
);
186 void SourceCtrlRemoveSource(uint32
NOT_ON_DAEMON(source
), const CPartFile
* NOT_ON_DAEMON(owner
))
189 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->clientlistctrl
) {
190 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->RemoveSource(source
, owner
);
195 void SharedCtrlAddClient(CKnownFile
* NOT_ON_DAEMON(owner
), CClientRef
NOT_ON_DAEMON(source
), SourceItemType
NOT_ON_DAEMON(type
))
198 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
) {
199 theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
->AddSource(owner
, source
, type
);
204 void SharedCtrlRefreshClient(uint32
NOT_ON_DAEMON(client
), SourceItemType
NOT_ON_DAEMON(type
))
207 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
) {
208 theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
->UpdateItem(client
, type
);
213 void SharedCtrlRemoveClient(uint32
NOT_ON_DAEMON(source
), const CKnownFile
* NOT_ON_DAEMON(owner
))
216 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
) {
217 theApp
->amuledlg
->m_sharedfileswnd
->peerslistctrl
->RemoveSource(source
, owner
);
222 void ServerRefresh(CServer
* NOT_ON_DAEMON(server
))
225 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
226 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(server
);
231 void ChatUpdateFriend(CFriend
* NOT_ON_DAEMON(toupdate
))
234 if (theApp
->amuledlg
->m_chatwnd
) {
235 theApp
->amuledlg
->m_chatwnd
->UpdateFriend(toupdate
);
240 void ChatRemoveFriend(CFriend
* toremove
)
243 if (theApp
->amuledlg
->m_chatwnd
) {
244 theApp
->amuledlg
->m_chatwnd
->RemoveFriend(toremove
);
252 void PartFile_Swap_A4AF(CPartFile
* file
)
254 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_SWAP_A4AF_THIS
);
257 void PartFile_Swap_A4AF_Auto(CPartFile
* file
)
259 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO
);
262 void PartFile_Swap_A4AF_Others(CPartFile
* file
)
264 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_SWAP_A4AF_OTHERS
);
267 void PartFile_Pause(CPartFile
* file
)
269 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_PAUSE
);
272 void PartFile_Resume(CPartFile
* file
)
274 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_RESUME
);
277 void PartFile_Stop(CPartFile
* file
)
279 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_STOP
);
282 void PartFile_PrioAuto(CPartFile
* file
, bool val
)
284 theApp
->downloadqueue
->AutoPrio(file
, val
);
287 void PartFile_PrioSet(CPartFile
* file
, uint8 newDownPriority
, bool)
289 theApp
->downloadqueue
->Prio(file
, newDownPriority
);
292 void PartFile_Delete(CPartFile
* file
)
294 theApp
->downloadqueue
->SendFileCommand(file
, EC_OP_PARTFILE_DELETE
);
297 void PartFile_SetCat(CPartFile
* file
, uint32 val
)
299 theApp
->downloadqueue
->Category(file
, val
);
302 void KnownFile_Up_Prio_Set(CKnownFile
* file
, uint8 val
)
304 theApp
->sharedfiles
->SetFilePrio(file
, val
);
307 void KnownFile_Up_Prio_Auto(CKnownFile
* file
)
309 theApp
->sharedfiles
->SetFilePrio(file
, PR_AUTO
);
312 void KnownFile_Comment_Set(CKnownFile
* file
, wxString comment
, int8 rating
)
314 theApp
->sharedfiles
->SetFileCommentRating(file
, comment
, rating
);
317 void Download_Set_Cat_Prio(uint8
, uint8
)
321 void Download_Set_Cat_Status(uint8
, int)
325 void Upload_Resort_Queue()
331 void SharedFilesShowFile(CKnownFile
* NOT_ON_DAEMON(file
))
334 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
335 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
340 void SharedFilesRemoveFile(CKnownFile
* NOT_ON_DAEMON(file
))
343 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
344 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
);
349 void SharedFilesRemoveAllFiles()
352 if (theApp
->amuledlg
->m_sharedfileswnd
) {
353 theApp
->amuledlg
->m_sharedfileswnd
->RemoveAllSharedFiles();
359 void SharedFilesShowFileList()
362 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
363 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFileList();
369 void SharedFilesUpdateItem(CKnownFile
* NOT_ON_DAEMON(file
))
372 if (theApp
->amuledlg
->m_sharedfileswnd
&& theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
) {
373 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
379 void DownloadCtrlAddFile(CPartFile
* file
)
381 theApp
->ECServerHandler
->m_ec_notifier
->DownloadFile_AddFile(file
);
383 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
384 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
389 void DownloadCtrlRemoveFile(CPartFile
* file
)
391 theApp
->ECServerHandler
->m_ec_notifier
->DownloadFile_RemoveFile(file
);
393 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
394 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile(file
);
399 void DownloadCtrlSort()
402 if (theApp
->amuledlg
->m_transferwnd
&& theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
) {
403 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->SortList();
408 void ServerAdd(CServer
* NOT_ON_DAEMON(server
))
411 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
412 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->AddServer(server
);
417 void ServerRemove(CServer
* NOT_ON_DAEMON(server
))
420 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
421 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(server
);
426 void ServerRemoveDead()
428 if (theApp
->serverlist
) {
429 theApp
->serverlist
->RemoveDeadServers();
433 void ServerRemoveAll()
436 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
437 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->DeleteAllItems();
442 void ServerHighlight(CServer
* NOT_ON_DAEMON(server
), bool NOT_ON_DAEMON(highlight
))
445 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
446 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->HighlightServer(server
, highlight
);
454 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
455 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->Freeze();
463 if (theApp
->amuledlg
->m_serverwnd
&& theApp
->amuledlg
->m_serverwnd
->serverlistctrl
) {
464 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->Thaw();
469 void ServerUpdateED2KInfo()
472 if (theApp
->amuledlg
->m_serverwnd
) {
473 theApp
->amuledlg
->m_serverwnd
->UpdateED2KInfo();
478 void ServerUpdateKadKInfo()
481 if (theApp
->amuledlg
->m_serverwnd
) {
482 theApp
->amuledlg
->m_serverwnd
->UpdateKadInfo();
491 if (theApp
->amuledlg
->m_searchwnd
) {
492 theApp
->amuledlg
->m_searchwnd
->ResetControls();
497 void SearchLocalEnd()
500 if (theApp
->amuledlg
->m_searchwnd
) {
501 theApp
->amuledlg
->m_searchwnd
->LocalSearchEnd();
506 void KadSearchEnd(uint32
NOT_ON_DAEMON(id
))
509 if (theApp
->amuledlg
->m_searchwnd
) {
510 theApp
->amuledlg
->m_searchwnd
->KadSearchEnd(id
);
513 theApp
->searchlist
->SetKadSearchFinished();
516 void Search_Update_Sources(CSearchFile
* result
)
518 result
->SetDownloadStatus();
520 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
521 theApp
->amuledlg
->m_searchwnd
->UpdateResult(result
);
526 void Search_Add_Result(CSearchFile
* NOT_ON_DAEMON(result
))
529 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
530 theApp
->amuledlg
->m_searchwnd
->AddResult(result
);
536 void ChatConnResult(bool NOT_ON_DAEMON(success
), uint64
NOT_ON_DAEMON(id
), wxString
NOT_ON_DAEMON(message
))
539 if (theApp
->amuledlg
->m_chatwnd
) {
540 theApp
->amuledlg
->m_chatwnd
->ConnectionResult(success
, message
, id
);
545 void ChatProcessMsg(uint64
NOT_ON_DAEMON(sender
), wxString
NOT_ON_DAEMON(message
))
548 if (theApp
->amuledlg
->m_chatwnd
) {
549 theApp
->amuledlg
->m_chatwnd
->ProcessMessage(sender
, message
);
555 void ChatSendCaptcha(wxString
NOT_ON_DAEMON(captcha
), uint64
NOT_ON_DAEMON(to_id
))
558 if (theApp
->amuledlg
->m_chatwnd
) {
559 theApp
->amuledlg
->m_chatwnd
->SendMessage(captcha
, wxEmptyString
, to_id
);
565 void ShowConnState(long NOT_ON_DAEMON(forceUpdate
))
568 theApp
->amuledlg
->ShowConnectionState(forceUpdate
!= 0);
572 void ShowUpdateCatTabTitles()
575 if (theApp
->amuledlg
->m_transferwnd
) {
576 theApp
->amuledlg
->m_transferwnd
->UpdateCatTabTitles();
584 if (theApp
->amuledlg
->m_transferwnd
) {
585 theApp
->amuledlg
->m_transferwnd
->
586 AddCategory(theApp
->glob_prefs
->GetCategory(
587 theApp
->glob_prefs
->GetCatCount()-1));
592 void CategoryUpdate(uint32
NOT_ON_DAEMON(cat
))
595 if (theApp
->amuledlg
->m_transferwnd
) {
596 theApp
->amuledlg
->m_transferwnd
->UpdateCategory(cat
);
597 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->Refresh();
598 theApp
->amuledlg
->m_searchwnd
->UpdateCatChoice();
603 void CategoryDelete(uint32 cat
)
607 theApp
->downloadqueue
->ResetCatParts(cat
);
608 theApp
->glob_prefs
->RemoveCat(cat
);
609 if ( theApp
->glob_prefs
->GetCatCount() == 1 ) {
610 thePrefs::SetAllcatFilter( acfAll
);
612 theApp
->glob_prefs
->SaveCats();
615 if (theApp
->amuledlg
->m_transferwnd
) {
616 theApp
->amuledlg
->m_transferwnd
->RemoveCategory(cat
);
622 void PartFile_Swap_A4AF(CPartFile
* file
)
624 if ((file
->GetStatus(false) == PS_READY
|| file
->GetStatus(false) == PS_EMPTY
)) {
625 CPartFile::SourceSet::const_iterator it
= file
->GetA4AFList().begin();
626 for ( ; it
!= file
->GetA4AFList().end(); ) {
627 it
++->SwapToAnotherFile(true, false, false, file
);
632 void PartFile_Swap_A4AF_Auto(CPartFile
* file
)
634 file
->SetA4AFAuto(!file
->IsA4AFAuto());
637 void PartFile_Swap_A4AF_Others(CPartFile
* file
)
639 if ((file
->GetStatus(false) == PS_READY
) || (file
->GetStatus(false) == PS_EMPTY
)) {
640 CPartFile::SourceSet::const_iterator it
= file
->GetSourceList().begin();
641 for( ; it
!= file
->GetSourceList().end(); ) {
642 it
++->SwapToAnotherFile(false, false, false, NULL
);
647 void PartFile_Pause(CPartFile
* file
)
652 void PartFile_Resume(CPartFile
* file
)
655 file
->SavePartFile();
658 void PartFile_Stop(CPartFile
* file
)
663 void PartFile_PrioAuto(CPartFile
* file
, bool val
)
665 file
->SetAutoDownPriority(val
);
668 void PartFile_PrioSet(CPartFile
* file
, uint8 newDownPriority
, bool bSave
)
670 file
->SetDownPriority(newDownPriority
, bSave
);
673 void PartFile_Delete(CPartFile
* file
)
678 void PartFile_SetCat(CPartFile
* file
, uint32 val
)
680 file
->SetCategory(val
);
684 void KnownFile_Up_Prio_Set(CKnownFile
* file
, uint8 val
)
686 file
->SetAutoUpPriority(false);
687 file
->SetUpPriority(val
);
690 void KnownFile_Up_Prio_Auto(CKnownFile
* file
)
692 file
->SetAutoUpPriority(true);
693 file
->UpdateAutoUpPriority();
696 void KnownFile_Comment_Set(CKnownFile
* file
, wxString comment
, int8 rating
)
698 file
->SetFileCommentRating(comment
, rating
);
699 SharedFilesUpdateItem(file
);
703 void Download_Set_Cat_Prio(uint8 cat
, uint8 newprio
)
705 theApp
->downloadqueue
->SetCatPrio(cat
, newprio
);
708 void Download_Set_Cat_Status(uint8 cat
, int newstatus
)
710 theApp
->downloadqueue
->SetCatStatus(cat
, newstatus
);
713 void Upload_Resort_Queue()
715 theApp
->uploadqueue
->ResortQueue();
718 void IPFilter_Reload()
720 theApp
->ipfilter
->Reload();
723 void IPFilter_Update(wxString url
)
725 theApp
->ipfilter
->Update(url
);
728 void Client_Delete(CClientRef client
)
730 client
.Safe_Delete();
734 void ConvertUpdateProgress(float percent
, wxString text
, wxString header
)
736 CPartFileConvertDlg::UpdateProgress(percent
, text
, header
);
739 void ConvertUpdateJobInfo(ConvertInfo info
)
741 CPartFileConvertDlg::UpdateJobInfo(info
);
744 void ConvertRemoveJobInfo(unsigned id
)
746 CPartFileConvertDlg::RemoveJobInfo(id
);
749 void ConvertClearInfos()
751 CPartFileConvertDlg::ClearInfo();
754 void ConvertRemoveJob(unsigned id
)
756 CPartFileConvert::RemoveJob(id
);
759 void ConvertRetryJob(unsigned id
)
761 CPartFileConvert::RetryJob(id
);
764 void ConvertReaddAllJobs()
766 CPartFileConvert::ReaddAllJobs();
768 #endif // #ifndef AMULE_DAEMON
770 #endif // #ifndef CLIENT_GUI
772 // File_checked_for_headers