Fix header inclusions
[amule.git] / src / GuiEvents.cpp
blobf6cf194db5598bd4ee8e7efbb4cd7439d640ef42
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
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
8 // respective authors.
9 //
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"
26 #include "amule.h"
27 #include "PartFile.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"
34 #include "IPFilter.h"
35 #include "Friend.h"
37 #ifndef AMULE_DAEMON
38 # include "ChatWnd.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"
50 # ifndef CLIENT_GUI
51 # include "PartFileConvertDlg.h"
52 # include "PartFileConvert.h"
53 # endif
54 #endif
56 #ifndef CLIENT_GUI
57 # include "UploadQueue.h"
58 #endif
60 #include <common/MacrosProgramSpecific.h>
62 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY)
65 namespace MuleNotify
68 void HandleNotification(const CMuleNotiferBase& ntf)
70 if (wxThread::IsMain()) {
71 #ifdef AMULE_DAEMON
72 ntf.Notify();
73 #else
74 if (theApp->amuledlg) {
75 ntf.Notify();
77 #endif
78 } else {
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))
100 #ifndef AMULE_DAEMON
101 theApp->amuledlg->ShowUserCount(str);
102 #endif
106 void Search_Update_Progress(uint32 NOT_ON_DAEMON(val))
108 #ifndef AMULE_DAEMON
109 if (theApp->amuledlg->m_searchwnd) {
110 if (val == 0xffff) {
111 // Global search ended
112 theApp->amuledlg->m_searchwnd->ResetControls();
113 } else if (val == 0xfffe) {
114 // Kad search ended
115 theApp->amuledlg->m_searchwnd->KadSearchEnd(0);
116 } else {
117 theApp->amuledlg->m_searchwnd->UpdateProgress(val);
120 #endif
124 void DownloadCtrlUpdateItem(const void* item)
126 #ifndef CLIENT_GUI
127 theApp->ECServerHandler->m_ec_notifier->DownloadFile_SetDirty((CPartFile *)item);
128 #endif
129 #ifndef AMULE_DAEMON
130 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
131 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
133 #endif
137 void DownloadCtrlDoItemSelectionChanged()
139 #ifndef AMULE_DAEMON
140 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
141 theApp->amuledlg->m_transferwnd->downloadlistctrl->DoItemSelectionChanged();
143 #endif
147 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
149 #ifndef AMULE_DAEMON
150 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
151 #endif
154 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
156 #ifndef AMULE_DAEMON
157 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
158 #endif
161 void ShowGUI()
163 #ifndef AMULE_DAEMON
164 theApp->amuledlg->Iconize(false);
165 #endif
168 void SourceCtrlUpdateSource(uint32 NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
170 #ifndef AMULE_DAEMON
171 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
172 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateItem(source, type);
174 #endif
177 void SourceCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CClientRef NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
179 #ifndef AMULE_DAEMON
180 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
181 theApp->amuledlg->m_transferwnd->clientlistctrl->AddSource(owner, source, type);
183 #endif
186 void SourceCtrlRemoveSource(uint32 NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
188 #ifndef AMULE_DAEMON
189 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
190 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveSource(source, owner);
192 #endif
195 void SharedCtrlAddClient(CKnownFile* NOT_ON_DAEMON(owner), CClientRef NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
197 #ifndef AMULE_DAEMON
198 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
199 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->AddSource(owner, source, type);
201 #endif
204 void SharedCtrlRefreshClient(uint32 NOT_ON_DAEMON(client), SourceItemType NOT_ON_DAEMON(type))
206 #ifndef AMULE_DAEMON
207 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
208 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->UpdateItem(client, type);
210 #endif
213 void SharedCtrlRemoveClient(uint32 NOT_ON_DAEMON(source), const CKnownFile* NOT_ON_DAEMON(owner))
215 #ifndef AMULE_DAEMON
216 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
217 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->RemoveSource(source, owner);
219 #endif
222 void ServerRefresh(CServer* NOT_ON_DAEMON(server))
224 #ifndef AMULE_DAEMON
225 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
226 theApp->amuledlg->m_serverwnd->serverlistctrl->RefreshServer(server);
228 #endif
231 void ChatUpdateFriend(CFriend * NOT_ON_DAEMON(toupdate))
233 #ifndef AMULE_DAEMON
234 if (theApp->amuledlg->m_chatwnd) {
235 theApp->amuledlg->m_chatwnd->UpdateFriend(toupdate);
237 #endif
240 void ChatRemoveFriend(CFriend * toremove)
242 #ifndef AMULE_DAEMON
243 if (theApp->amuledlg->m_chatwnd) {
244 theApp->amuledlg->m_chatwnd->RemoveFriend(toremove);
246 #endif
247 delete toremove;
250 #ifdef CLIENT_GUI
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()
329 #else
331 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
333 #ifndef AMULE_DAEMON
334 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
335 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
337 #endif
340 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
342 #ifndef AMULE_DAEMON
343 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
344 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
346 #endif
349 void SharedFilesRemoveAllFiles()
351 #ifndef AMULE_DAEMON
352 if (theApp->amuledlg->m_sharedfileswnd) {
353 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
355 #endif
359 void SharedFilesShowFileList()
361 #ifndef AMULE_DAEMON
362 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
363 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
365 #endif
369 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
371 #ifndef AMULE_DAEMON
372 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
373 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
375 #endif
379 void DownloadCtrlAddFile(CPartFile* file)
381 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
382 #ifndef AMULE_DAEMON
383 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
384 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
386 #endif
389 void DownloadCtrlRemoveFile(CPartFile* file)
391 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
392 #ifndef AMULE_DAEMON
393 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
394 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
396 #endif
399 void DownloadCtrlSort()
401 #ifndef AMULE_DAEMON
402 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
403 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
405 #endif
408 void ServerAdd(CServer* NOT_ON_DAEMON(server))
410 #ifndef AMULE_DAEMON
411 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
412 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
414 #endif
417 void ServerRemove(CServer* NOT_ON_DAEMON(server))
419 #ifndef AMULE_DAEMON
420 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
421 theApp->amuledlg->m_serverwnd->serverlistctrl->RemoveServer(server);
423 #endif
426 void ServerRemoveDead()
428 if (theApp->serverlist) {
429 theApp->serverlist->RemoveDeadServers();
433 void ServerRemoveAll()
435 #ifndef AMULE_DAEMON
436 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
437 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
439 #endif
442 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
444 #ifndef AMULE_DAEMON
445 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
446 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
448 #endif
451 void ServerFreeze()
453 #ifndef AMULE_DAEMON
454 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
455 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
457 #endif
460 void ServerThaw()
462 #ifndef AMULE_DAEMON
463 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
464 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
466 #endif
469 void ServerUpdateED2KInfo()
471 #ifndef AMULE_DAEMON
472 if (theApp->amuledlg->m_serverwnd) {
473 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
475 #endif
478 void ServerUpdateKadKInfo()
480 #ifndef AMULE_DAEMON
481 if (theApp->amuledlg->m_serverwnd) {
482 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
484 #endif
488 void SearchCancel()
490 #ifndef AMULE_DAEMON
491 if (theApp->amuledlg->m_searchwnd) {
492 theApp->amuledlg->m_searchwnd->ResetControls();
494 #endif
497 void SearchLocalEnd()
499 #ifndef AMULE_DAEMON
500 if (theApp->amuledlg->m_searchwnd) {
501 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
503 #endif
506 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
508 #ifndef AMULE_DAEMON
509 if (theApp->amuledlg->m_searchwnd) {
510 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
512 #endif
513 theApp->searchlist->SetKadSearchFinished();
516 void Search_Update_Sources(CSearchFile* result)
518 result->SetDownloadStatus();
519 #ifndef AMULE_DAEMON
520 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
521 theApp->amuledlg->m_searchwnd->UpdateResult(result);
523 #endif
526 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
528 #ifndef AMULE_DAEMON
529 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
530 theApp->amuledlg->m_searchwnd->AddResult(result);
532 #endif
536 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
538 #ifndef AMULE_DAEMON
539 if (theApp->amuledlg->m_chatwnd) {
540 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
542 #endif
545 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
547 #ifndef AMULE_DAEMON
548 if (theApp->amuledlg->m_chatwnd) {
549 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
551 #endif
555 void ChatSendCaptcha(wxString NOT_ON_DAEMON(captcha), uint64 NOT_ON_DAEMON(to_id))
557 #ifndef AMULE_DAEMON
558 if (theApp->amuledlg->m_chatwnd) {
559 theApp->amuledlg->m_chatwnd->SendMessage(captcha, wxEmptyString, to_id);
561 #endif
565 void ShowConnState(long NOT_ON_DAEMON(forceUpdate))
567 #ifndef AMULE_DAEMON
568 theApp->amuledlg->ShowConnectionState(forceUpdate != 0);
569 #endif
572 void ShowUpdateCatTabTitles()
574 #ifndef AMULE_DAEMON
575 if (theApp->amuledlg->m_transferwnd) {
576 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
578 #endif
581 void CategoryAdded()
583 #ifndef AMULE_DAEMON
584 if (theApp->amuledlg->m_transferwnd) {
585 theApp->amuledlg->m_transferwnd->
586 AddCategory(theApp->glob_prefs->GetCategory(
587 theApp->glob_prefs->GetCatCount()-1));
589 #endif
592 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
594 #ifndef AMULE_DAEMON
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();
600 #endif
603 void CategoryDelete(uint32 cat)
605 #ifdef AMULE_DAEMON
606 if (cat > 0) {
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();
614 #else
615 if (theApp->amuledlg->m_transferwnd) {
616 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
618 #endif
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)
649 file->PauseFile();
652 void PartFile_Resume(CPartFile* file)
654 file->ResumeFile();
655 file->SavePartFile();
658 void PartFile_Stop(CPartFile* file)
660 file->StopFile();
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)
675 file->Delete();
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();
733 #ifndef AMULE_DAEMON
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