Fix setting server priority and static from the Remote GUI
[amule.git] / src / GuiEvents.cpp
blob3d014d49ab47de4dac1a04aefe5b00cd2daa7289
2 #include "GuiEvents.h"
3 #include "amule.h"
4 #include "PartFile.h"
5 #include "DownloadQueue.h"
6 #include "updownclient.h"
7 #include "ServerList.h"
8 #include "Preferences.h"
9 #include "ExternalConn.h"
10 #include "SearchFile.h"
11 #include "SearchList.h"
12 #include "IPFilter.h"
14 #ifndef AMULE_DAEMON
15 # include "ChatWnd.h"
16 # include "amuleDlg.h"
17 # include "ServerWnd.h"
18 # include "SearchDlg.h"
19 # include "TransferWnd.h"
20 # include "SharedFilesWnd.h"
21 # include "ServerListCtrl.h"
22 # include "SourceListCtrl.h"
23 # include "SharedFilesCtrl.h"
24 # include "DownloadListCtrl.h"
25 # include "muuli_wdr.h"
26 # include "SharedFilePeersListCtrl.h"
27 # include "PartFileConvertDlg.h"
28 #endif
30 #ifndef CLIENT_GUI
31 # include "PartFileConvert.h"
32 #endif
34 #include <common/MacrosProgramSpecific.h>
36 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY)
39 namespace MuleNotify
42 void HandleNotification(const CMuleNotiferBase& ntf)
44 if (wxThread::IsMain()) {
45 #ifdef AMULE_DAEMON
46 ntf.Notify();
47 #else
48 if (theApp->amuledlg) {
49 ntf.Notify();
51 #endif
52 } else {
53 CMuleGUIEvent evt(ntf.Clone());
54 wxPostEvent(wxTheApp, evt);
59 void HandleNotificationAlways(const CMuleNotiferBase& ntf)
61 CMuleGUIEvent evt(ntf.Clone());
62 wxPostEvent(wxTheApp, evt);
66 void Search_Add_Download(CSearchFile* file, uint8 category)
68 theApp->downloadqueue->AddSearchToDownload(file, category);
72 void ShowUserCount(wxString NOT_ON_DAEMON(str))
74 #ifndef AMULE_DAEMON
75 theApp->amuledlg->ShowUserCount(str);
76 #endif
80 void Search_Update_Progress(uint32 NOT_ON_DAEMON(val))
82 #ifndef AMULE_DAEMON
83 if (theApp->amuledlg->m_searchwnd) {
84 if (val == 0xffff) {
85 // Global search ended
86 theApp->amuledlg->m_searchwnd->ResetControls();
87 } else if (val == 0xfffe) {
88 // Kad search ended
89 theApp->amuledlg->m_searchwnd->KadSearchEnd(0);
90 } else {
91 theApp->amuledlg->m_searchwnd->UpdateProgress(val);
94 #endif
98 void DownloadCtrlUpdateItem(const void* item)
100 #ifndef CLIENT_GUI
101 theApp->ECServerHandler->m_ec_notifier->DownloadFile_SetDirty((CPartFile *)item);
102 #endif
103 #ifndef AMULE_DAEMON
104 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
105 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
107 #endif
111 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
113 #ifndef AMULE_DAEMON
114 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
115 #endif
118 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
120 #ifndef AMULE_DAEMON
121 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
122 #endif
125 void ConvertUpdateProgress(float NOT_ON_DAEMON(percent), wxString NOT_ON_DAEMON(text), wxString NOT_ON_DAEMON(header))
127 #ifndef AMULE_DAEMON
128 CPartFileConvertDlg::UpdateProgress(percent, text, header);
129 #endif
132 void ConvertUpdateJobInfo(ConvertInfo NOT_ON_DAEMON(info))
134 #ifndef AMULE_DAEMON
135 CPartFileConvertDlg::UpdateJobInfo(info);
136 #endif
139 void ConvertRemoveJobInfo(unsigned NOT_ON_DAEMON(id))
141 #ifndef AMULE_DAEMON
142 CPartFileConvertDlg::RemoveJobInfo(id);
143 #endif
146 void ConvertClearInfos()
148 #ifndef AMULE_DAEMON
149 CPartFileConvertDlg::ClearInfo();
150 #endif
153 void ConvertRemoveJob(unsigned NOT_ON_REMOTEGUI(id))
155 #ifndef CLIENT_GUI
156 CPartFileConvert::RemoveJob(id);
157 #endif
160 void ConvertRetryJob(unsigned NOT_ON_REMOTEGUI(id))
162 #ifndef CLIENT_GUI
163 CPartFileConvert::RetryJob(id);
164 #endif
167 void ConvertReaddAllJobs()
169 #ifndef CLIENT_GUI
170 CPartFileConvert::ReaddAllJobs();
171 #endif
174 void ShowGUI()
176 #ifndef AMULE_DAEMON
177 theApp->amuledlg->Iconize(false);
178 #endif
181 void SourceCtrlUpdateSource(CUpDownClient* NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
183 #ifndef AMULE_DAEMON
184 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
185 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateItem(source, type);
187 #endif
190 void SourceCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
192 #ifndef AMULE_DAEMON
193 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
194 theApp->amuledlg->m_transferwnd->clientlistctrl->AddSource(owner, source, type);
196 #endif
199 void SourceCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
201 #ifndef AMULE_DAEMON
202 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
203 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveSource(source, owner);
205 #endif
208 void SharedCtrlAddClient(CKnownFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
210 #ifndef AMULE_DAEMON
211 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
212 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->AddSource(owner, source, type);
214 #endif
217 void SharedCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), SourceItemType NOT_ON_DAEMON(type))
219 #ifndef AMULE_DAEMON
220 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
221 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->UpdateItem(client, type);
223 #endif
226 void SharedCtrlRemoveClient(const CKnownFile* NOT_ON_DAEMON(owner), const CUpDownClient* NOT_ON_DAEMON(source))
228 #ifndef AMULE_DAEMON
229 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
230 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->RemoveSource(source, owner);
232 #endif
235 void ServerRefresh(CServer* NOT_ON_DAEMON(server))
237 #ifndef AMULE_DAEMON
238 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
239 theApp->amuledlg->m_serverwnd->serverlistctrl->RefreshServer(server);
241 #endif
245 #ifdef CLIENT_GUI
247 void PartFile_Swap_A4AF(CPartFile* file)
249 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
252 void PartFile_Swap_A4AF_Auto(CPartFile* file)
254 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
257 void PartFile_Swap_A4AF_Others(CPartFile* file)
259 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
262 void PartFile_Pause(CPartFile* file)
264 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
267 void PartFile_Resume(CPartFile* file)
269 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
272 void PartFile_Stop(CPartFile* file)
274 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
277 void PartFile_PrioAuto(CPartFile* file, bool val)
279 theApp->downloadqueue->AutoPrio(file, val);
282 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
284 theApp->downloadqueue->Prio(file, newDownPriority);
287 void PartFile_Delete(CPartFile* file)
289 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
292 void PartFile_SetCat(CPartFile* file, uint32 val)
294 theApp->downloadqueue->Category(file, val);
297 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
299 theApp->sharedfiles->SetFilePrio(file, val);
302 void KnownFile_Up_Prio_Auto(CKnownFile* file)
304 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
307 void KnownFile_Comment_Set(CKnownFile* file, wxString comment, int8 rating)
309 theApp->sharedfiles->SetFileCommentRating(file, comment, rating);
312 void Download_Set_Cat_Prio(uint8, uint8)
316 void Download_Set_Cat_Status(uint8, int)
320 #else
322 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
324 #ifndef AMULE_DAEMON
325 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
326 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
328 #endif
331 void SharedFilesRemoveFile(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->RemoveFile(file);
337 #endif
340 void SharedFilesRemoveAllFiles()
342 #ifndef AMULE_DAEMON
343 if (theApp->amuledlg->m_sharedfileswnd) {
344 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
346 #endif
350 void SharedFilesShowFileList()
352 #ifndef AMULE_DAEMON
353 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
354 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
356 #endif
360 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
362 #ifndef AMULE_DAEMON
363 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
364 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
366 #endif
370 void DownloadCtrlAddFile(CPartFile* file)
372 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
373 #ifndef AMULE_DAEMON
374 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
375 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
377 #endif
380 void DownloadCtrlRemoveFile(CPartFile* file)
382 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
383 #ifndef AMULE_DAEMON
384 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
385 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
387 #endif
390 void DownloadCtrlSort()
392 #ifndef AMULE_DAEMON
393 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
394 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
396 #endif
399 void ServerAdd(CServer* NOT_ON_DAEMON(server))
401 #ifndef AMULE_DAEMON
402 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
403 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
405 #endif
408 void ServerRemove(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->RemoveServer(server);
414 #endif
417 void ServerRemoveDead()
419 if (theApp->serverlist) {
420 theApp->serverlist->RemoveDeadServers();
424 void ServerRemoveAll()
426 #ifndef AMULE_DAEMON
427 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
428 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
430 #endif
433 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
435 #ifndef AMULE_DAEMON
436 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
437 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
439 #endif
442 void ServerFreeze()
444 #ifndef AMULE_DAEMON
445 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
446 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
448 #endif
451 void ServerThaw()
453 #ifndef AMULE_DAEMON
454 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
455 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
457 #endif
460 void ServerUpdateED2KInfo()
462 #ifndef AMULE_DAEMON
463 if (theApp->amuledlg->m_serverwnd) {
464 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
466 #endif
469 void ServerUpdateKadKInfo()
471 #ifndef AMULE_DAEMON
472 if (theApp->amuledlg->m_serverwnd) {
473 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
475 #endif
479 void SearchCancel()
481 #ifndef AMULE_DAEMON
482 if (theApp->amuledlg->m_searchwnd) {
483 theApp->amuledlg->m_searchwnd->ResetControls();
485 #endif
488 void SearchLocalEnd()
490 #ifndef AMULE_DAEMON
491 if (theApp->amuledlg->m_searchwnd) {
492 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
494 #endif
497 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
499 #ifndef AMULE_DAEMON
500 if (theApp->amuledlg->m_searchwnd) {
501 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
503 #endif
504 theApp->searchlist->SetKadSearchFinished();
507 void Search_Update_Sources(CSearchFile* result)
509 result->SetDownloadStatus();
510 #ifndef AMULE_DAEMON
511 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
512 theApp->amuledlg->m_searchwnd->UpdateResult(result);
514 #endif
517 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
519 #ifndef AMULE_DAEMON
520 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
521 theApp->amuledlg->m_searchwnd->AddResult(result);
523 #endif
527 void ChatRefreshFriend(CFriend * NOT_ON_DAEMON(Friend), bool NOT_ON_DAEMON(connected))
529 #ifndef AMULE_DAEMON
530 if (theApp->amuledlg->m_chatwnd) {
531 theApp->amuledlg->m_chatwnd->RefreshFriend(Friend, connected);
533 #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 ShowQueueCount(uint32 NOT_ON_DAEMON(count))
574 #ifndef AMULE_DAEMON
575 if (theApp->amuledlg->m_transferwnd) {
576 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
578 #endif
581 void ShowUpdateCatTabTitles()
583 #ifndef AMULE_DAEMON
584 if (theApp->amuledlg->m_transferwnd) {
585 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
587 #endif
590 void CategoryAdded()
592 #ifndef AMULE_DAEMON
593 if (theApp->amuledlg->m_transferwnd) {
594 theApp->amuledlg->m_transferwnd->
595 AddCategory(theApp->glob_prefs->GetCategory(
596 theApp->glob_prefs->GetCatCount()-1));
598 #endif
601 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
603 #ifndef AMULE_DAEMON
604 if (theApp->amuledlg->m_transferwnd) {
605 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
606 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
607 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
609 #endif
612 void CategoryDelete(uint32 cat)
614 #ifdef AMULE_DAEMON
615 if (cat > 0) {
616 theApp->downloadqueue->ResetCatParts(cat);
617 theApp->glob_prefs->RemoveCat(cat);
618 if ( theApp->glob_prefs->GetCatCount() == 1 ) {
619 thePrefs::SetAllcatFilter( acfAll );
621 theApp->glob_prefs->SaveCats();
623 #else
624 if (theApp->amuledlg->m_transferwnd) {
625 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
627 #endif
631 void PartFile_Swap_A4AF(CPartFile* file)
633 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
634 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
635 for ( ; it != file->GetA4AFList().end(); ) {
636 CUpDownClient *cur_source = *it++;
638 cur_source->SwapToAnotherFile(true, false, false, file);
643 void PartFile_Swap_A4AF_Auto(CPartFile* file)
645 file->SetA4AFAuto(!file->IsA4AFAuto());
648 void PartFile_Swap_A4AF_Others(CPartFile* file)
650 if ((file->GetStatus(false) == PS_READY) || (file->GetStatus(false) == PS_EMPTY)) {
651 CPartFile::SourceSet::const_iterator it = file->GetSourceList().begin();
652 for( ; it != file->GetSourceList().end(); ) {
653 CUpDownClient* cur_source = *it++;
655 cur_source->SwapToAnotherFile(false, false, false, NULL);
660 void PartFile_Pause(CPartFile* file)
662 file->PauseFile();
665 void PartFile_Resume(CPartFile* file)
667 file->ResumeFile();
668 file->SavePartFile();
671 void PartFile_Stop(CPartFile* file)
673 file->StopFile();
676 void PartFile_PrioAuto(CPartFile* file, bool val)
678 file->SetAutoDownPriority(val);
681 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
683 file->SetDownPriority(newDownPriority, bSave);
686 void PartFile_Delete(CPartFile* file)
688 file->Delete();
691 void PartFile_SetCat(CPartFile* file, uint32 val)
693 file->SetCategory(val);
697 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
699 file->SetAutoUpPriority(false);
700 file->SetUpPriority(val);
703 void KnownFile_Up_Prio_Auto(CKnownFile* file)
705 file->SetAutoUpPriority(true);
706 file->UpdateAutoUpPriority();
709 void KnownFile_Comment_Set(CKnownFile* file, wxString comment, int8 rating)
711 file->SetFileCommentRating(comment, rating);
712 SharedFilesUpdateItem(file);
716 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
718 theApp->downloadqueue->SetCatPrio(cat, newprio);
721 void Download_Set_Cat_Status(uint8 cat, int newstatus)
723 theApp->downloadqueue->SetCatStatus(cat, newstatus);
726 void IPFilter_Reload()
728 theApp->ipfilter->Reload();
731 void IPFilter_Update(wxString url)
733 theApp->ipfilter->Update(url);
737 #endif // #ifdef CLIENT_GUI
739 // File_checked_for_headers