Upstream tarball 10192
[amule.git] / src / GuiEvents.cpp
bloba83e29977172c0f94875486aede8a250cefd0359
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"
13 #ifndef AMULE_DAEMON
14 # include "ChatWnd.h"
15 # include "amuleDlg.h"
16 # include "ServerWnd.h"
17 # include "SearchDlg.h"
18 # include "TransferWnd.h"
19 # include "SharedFilesWnd.h"
20 # include "ServerListCtrl.h"
21 # include "SourceListCtrl.h"
22 # include "SharedFilesCtrl.h"
23 # include "DownloadListCtrl.h"
24 # include "muuli_wdr.h"
25 # include "SharedFilePeersListCtrl.h"
26 # include "PartFileConvertDlg.h"
27 #endif
29 #ifndef CLIENT_GUI
30 # include "PartFileConvert.h"
31 #endif
34 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY)
37 namespace MuleNotify
40 void HandleNotification(const CMuleNotiferBase& ntf)
42 if (wxThread::IsMain()) {
43 #if defined(AMULE_DAEMON)
44 ntf.Notify();
45 #else
46 if (theApp->amuledlg) {
47 ntf.Notify();
49 #endif
50 } else {
51 CMuleGUIEvent evt(ntf.Clone());
52 wxPostEvent(wxTheApp, evt);
56 void Search_Add_Download(CSearchFile* file, uint8 category)
58 theApp->downloadqueue->AddSearchToDownload(file, category);
62 void ShowUserCount(wxString NOT_ON_DAEMON(str))
64 #ifndef AMULE_DAEMON
65 theApp->amuledlg->ShowUserCount(str);
66 #endif
70 void Search_Update_Progress(uint32 NOT_ON_DAEMON(val))
72 #ifndef AMULE_DAEMON
73 if (theApp->amuledlg->m_searchwnd) {
74 if (val == 0xffff) {
75 // Global search ended
76 theApp->amuledlg->m_searchwnd->ResetControls();
77 } else if (val == 0xfffe) {
78 // Kad search ended
79 theApp->amuledlg->m_searchwnd->KadSearchEnd(0);
80 } else {
81 theApp->amuledlg->m_searchwnd->UpdateProgress(val);
84 #endif
88 void DownloadCtrlUpdateItem(const void* item)
90 #ifndef CLIENT_GUI
91 theApp->ECServerHandler->m_ec_notifier->DownloadFile_SetDirty((CPartFile *)item);
92 #endif
93 #ifndef AMULE_DAEMON
94 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
95 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
97 #endif
101 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
103 #ifndef AMULE_DAEMON
104 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
105 #endif
108 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
110 #ifndef AMULE_DAEMON
111 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
112 #endif
115 void ConvertUpdateProgress(float NOT_ON_DAEMON(percent), wxString NOT_ON_DAEMON(text), wxString NOT_ON_DAEMON(header))
117 #ifndef AMULE_DAEMON
118 CPartFileConvertDlg::UpdateProgress(percent, text, header);
119 #endif
122 void ConvertUpdateJobInfo(ConvertInfo NOT_ON_DAEMON(info))
124 #ifndef AMULE_DAEMON
125 CPartFileConvertDlg::UpdateJobInfo(info);
126 #endif
129 void ConvertRemoveJobInfo(unsigned NOT_ON_DAEMON(id))
131 #ifndef AMULE_DAEMON
132 CPartFileConvertDlg::RemoveJobInfo(id);
133 #endif
136 void ConvertClearInfos()
138 #ifndef AMULE_DAEMON
139 CPartFileConvertDlg::ClearInfo();
140 #endif
143 void ConvertRemoveJob(unsigned NOT_ON_REMOTEGUI(id))
145 #ifndef CLIENT_GUI
146 CPartFileConvert::RemoveJob(id);
147 #endif
150 void ConvertRetryJob(unsigned NOT_ON_REMOTEGUI(id))
152 #ifndef CLIENT_GUI
153 CPartFileConvert::RetryJob(id);
154 #endif
157 void ConvertReaddAllJobs()
159 #ifndef CLIENT_GUI
160 CPartFileConvert::ReaddAllJobs();
161 #endif
164 void ShowGUI()
166 #ifndef AMULE_DAEMON
167 theApp->amuledlg->Iconize(false);
168 #endif
171 void SourceCtrlUpdateSource(CUpDownClient* NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
173 #ifndef AMULE_DAEMON
174 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
175 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateItem(source, type);
177 #endif
180 void SourceCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
182 #ifndef AMULE_DAEMON
183 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
184 theApp->amuledlg->m_transferwnd->clientlistctrl->AddSource(owner, source, type);
186 #endif
189 void SourceCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
191 #ifndef AMULE_DAEMON
192 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
193 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveSource(source, owner);
195 #endif
198 void SharedCtrlAddClient(CKnownFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), SourceItemType NOT_ON_DAEMON(type))
200 #ifndef AMULE_DAEMON
201 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
202 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->AddSource(owner, source, type);
204 #endif
207 void SharedCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), SourceItemType NOT_ON_DAEMON(type))
209 #ifndef AMULE_DAEMON
210 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
211 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->UpdateItem(client, type);
213 #endif
216 void SharedCtrlRemoveClient(const CKnownFile* NOT_ON_DAEMON(owner), const CUpDownClient* NOT_ON_DAEMON(source))
218 #ifndef AMULE_DAEMON
219 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->peerslistctrl) {
220 theApp->amuledlg->m_sharedfileswnd->peerslistctrl->RemoveSource(source, owner);
222 #endif
226 #ifdef CLIENT_GUI
228 void PartFile_Swap_A4AF(CPartFile* file)
230 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
233 void PartFile_Swap_A4AF_Auto(CPartFile* file)
235 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
238 void PartFile_Swap_A4AF_Others(CPartFile* file)
240 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
243 void PartFile_Pause(CPartFile* file)
245 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
248 void PartFile_Resume(CPartFile* file)
250 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
253 void PartFile_Stop(CPartFile* file)
255 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
258 void PartFile_PrioAuto(CPartFile* file, bool val)
260 theApp->downloadqueue->AutoPrio(file, val);
263 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
265 theApp->downloadqueue->Prio(file, newDownPriority);
268 void PartFile_Delete(CPartFile* file)
270 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
273 void PartFile_SetCat(CPartFile* file, uint32 val)
275 theApp->downloadqueue->Category(file, val);
278 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
280 theApp->sharedfiles->SetFilePrio(file, val);
283 void KnownFile_Up_Prio_Auto(CKnownFile* file)
285 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
288 void Download_Set_Cat_Prio(uint8, uint8)
292 void Download_Set_Cat_Status(uint8, int)
296 #else
298 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
300 #ifndef AMULE_DAEMON
301 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
302 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
304 #endif
307 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
309 #ifndef AMULE_DAEMON
310 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
311 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
313 #endif
316 void SharedFilesRemoveAllFiles()
318 #ifndef AMULE_DAEMON
319 if (theApp->amuledlg->m_sharedfileswnd) {
320 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
322 #endif
326 void SharedFilesShowFileList()
328 #ifndef AMULE_DAEMON
329 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
330 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
332 #endif
336 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
338 #ifndef AMULE_DAEMON
339 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
340 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
342 #endif
346 void DownloadCtrlAddFile(CPartFile* file)
348 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
349 #ifndef AMULE_DAEMON
350 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
351 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
353 #endif
356 void DownloadCtrlRemoveFile(CPartFile* file)
358 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
359 #ifndef AMULE_DAEMON
360 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
361 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
363 #endif
366 void DownloadCtrlSort()
368 #ifndef AMULE_DAEMON
369 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
370 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
372 #endif
375 void ServerAdd(CServer* NOT_ON_DAEMON(server))
377 #ifndef AMULE_DAEMON
378 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
379 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
381 #endif
384 void ServerRemove(CServer* NOT_ON_DAEMON(server))
386 #ifndef AMULE_DAEMON
387 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
388 theApp->amuledlg->m_serverwnd->serverlistctrl->RemoveServer(server);
390 #endif
393 void ServerRemoveDead()
395 if (theApp->serverlist) {
396 theApp->serverlist->RemoveDeadServers();
400 void ServerRemoveAll()
402 #ifndef AMULE_DAEMON
403 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
404 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
406 #endif
409 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
411 #ifndef AMULE_DAEMON
412 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
413 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
415 #endif
418 void ServerRefresh(CServer* NOT_ON_DAEMON(server))
420 #ifndef AMULE_DAEMON
421 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
422 theApp->amuledlg->m_serverwnd->serverlistctrl->RefreshServer(server);
424 #endif
427 void ServerFreeze()
429 #ifndef AMULE_DAEMON
430 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
431 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
433 #endif
436 void ServerThaw()
438 #ifndef AMULE_DAEMON
439 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
440 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
442 #endif
445 void ServerUpdateED2KInfo()
447 #ifndef AMULE_DAEMON
448 if (theApp->amuledlg->m_serverwnd) {
449 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
451 #endif
454 void ServerUpdateKadKInfo()
456 #ifndef AMULE_DAEMON
457 if (theApp->amuledlg->m_serverwnd) {
458 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
460 #endif
464 void SearchCancel()
466 #ifndef AMULE_DAEMON
467 if (theApp->amuledlg->m_searchwnd) {
468 theApp->amuledlg->m_searchwnd->ResetControls();
470 #endif
473 void SearchLocalEnd()
475 #ifndef AMULE_DAEMON
476 if (theApp->amuledlg->m_searchwnd) {
477 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
479 #endif
482 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
484 #ifndef AMULE_DAEMON
485 if (theApp->amuledlg->m_searchwnd) {
486 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
488 #endif
489 theApp->searchlist->SetKadSearchFinished();
492 void Search_Update_Sources(CSearchFile* result)
494 result->SetDownloadStatus();
495 #ifndef AMULE_DAEMON
496 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
497 theApp->amuledlg->m_searchwnd->UpdateResult(result);
499 #endif
502 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
504 #ifndef AMULE_DAEMON
505 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
506 theApp->amuledlg->m_searchwnd->AddResult(result);
508 #endif
512 void ChatRefreshFriend(CFriend * NOT_ON_DAEMON(Friend), bool NOT_ON_DAEMON(connected))
514 #ifndef AMULE_DAEMON
515 if (theApp->amuledlg->m_chatwnd) {
516 theApp->amuledlg->m_chatwnd->RefreshFriend(Friend, connected);
518 #endif
521 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
523 #ifndef AMULE_DAEMON
524 if (theApp->amuledlg->m_chatwnd) {
525 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
527 #endif
530 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
532 #ifndef AMULE_DAEMON
533 if (theApp->amuledlg->m_chatwnd) {
534 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
536 #endif
540 void ChatSendCaptcha(wxString NOT_ON_DAEMON(captcha), uint64 NOT_ON_DAEMON(to_id))
542 #ifndef AMULE_DAEMON
543 if (theApp->amuledlg->m_chatwnd) {
544 theApp->amuledlg->m_chatwnd->SendMessage(captcha, wxEmptyString, to_id);
546 #endif
550 void ShowConnState(long WXUNUSED(state))
552 #ifndef AMULE_DAEMON
553 theApp->amuledlg->ShowConnectionState();
554 #endif
557 void ShowQueueCount(uint32 NOT_ON_DAEMON(count))
559 #ifndef AMULE_DAEMON
560 if (theApp->amuledlg->m_transferwnd) {
561 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
563 #endif
566 void ShowUpdateCatTabTitles()
568 #ifndef AMULE_DAEMON
569 if (theApp->amuledlg->m_transferwnd) {
570 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
572 #endif
575 void CategoryAdded()
577 #ifndef AMULE_DAEMON
578 if (theApp->amuledlg->m_transferwnd) {
579 theApp->amuledlg->m_transferwnd->
580 AddCategory(theApp->glob_prefs->GetCategory(
581 theApp->glob_prefs->GetCatCount()-1));
583 #endif
586 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
588 #ifndef AMULE_DAEMON
589 if (theApp->amuledlg->m_transferwnd) {
590 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
591 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
592 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
594 #endif
597 void CategoryDelete(uint32 cat)
599 #ifdef AMULE_DAEMON
600 if (cat > 0) {
601 theApp->downloadqueue->ResetCatParts(cat);
602 theApp->glob_prefs->RemoveCat(cat);
603 if ( theApp->glob_prefs->GetCatCount() == 1 ) {
604 thePrefs::SetAllcatType(0);
606 theApp->glob_prefs->SaveCats();
608 #else
609 if (theApp->amuledlg->m_transferwnd) {
610 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
612 #endif
616 void PartFile_Swap_A4AF(CPartFile* file)
618 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
619 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
620 for ( ; it != file->GetA4AFList().end(); ) {
621 CUpDownClient *cur_source = *it++;
623 cur_source->SwapToAnotherFile(true, false, false, file);
628 void PartFile_Swap_A4AF_Auto(CPartFile* file)
630 file->SetA4AFAuto(!file->IsA4AFAuto());
633 void PartFile_Swap_A4AF_Others(CPartFile* file)
635 if ((file->GetStatus(false) == PS_READY) || (file->GetStatus(false) == PS_EMPTY)) {
636 CPartFile::SourceSet::const_iterator it = file->GetSourceList().begin();
637 for( ; it != file->GetSourceList().end(); ) {
638 CUpDownClient* cur_source = *it++;
640 cur_source->SwapToAnotherFile(false, false, false, NULL);
645 void PartFile_Pause(CPartFile* file)
647 file->PauseFile();
650 void PartFile_Resume(CPartFile* file)
652 file->ResumeFile();
653 file->SavePartFile();
656 void PartFile_Stop(CPartFile* file)
658 file->StopFile();
661 void PartFile_PrioAuto(CPartFile* file, bool val)
663 file->SetAutoDownPriority(val);
666 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
668 file->SetDownPriority(newDownPriority, bSave);
671 void PartFile_Delete(CPartFile* file)
673 file->Delete();
676 void PartFile_SetCat(CPartFile* file, uint32 val)
678 file->SetCategory(val);
682 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
684 file->SetAutoUpPriority(false);
685 file->SetUpPriority(val);
688 void KnownFile_Up_Prio_Auto(CKnownFile* file)
690 file->SetAutoUpPriority(true);
691 file->UpdateAutoUpPriority();
694 void KnownFile_Comment_Set(CKnownFile* file, wxString comment)
696 file->SetFileComment(comment);
700 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
702 theApp->downloadqueue->SetCatPrio(cat, newprio);
705 void Download_Set_Cat_Status(uint8 cat, int newstatus)
707 theApp->downloadqueue->SetCatStatus(cat, newstatus);
710 #endif // #ifdef CLIENT_GUI
712 // File_checked_for_headers