Upstream tarball 10013
[amule.git] / src / GuiEvents.cpp
blob04d592c691c60bf08148f8de82417534fef962b7
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"
12 #ifndef AMULE_DAEMON
13 # include "ChatWnd.h"
14 # include "amuleDlg.h"
15 # include "ServerWnd.h"
16 # include "SearchDlg.h"
17 # include "TransferWnd.h"
18 # include "SharedFilesWnd.h"
19 # include "ServerListCtrl.h"
20 # include "ClientListCtrl.h"
21 # include "SharedFilesCtrl.h"
22 # include "DownloadListCtrl.h"
23 # include "muuli_wdr.h"
24 # include "PartFileConvertDlg.h"
25 #endif
27 #ifndef CLIENT_GUI
28 # include "PartFileConvert.h"
29 #endif
32 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY)
35 namespace MuleNotify
38 void HandleNotification(const CMuleNotiferBase& ntf)
40 if (wxThread::IsMain()) {
41 #if defined(AMULE_DAEMON)
42 ntf.Notify();
43 #else
44 if (theApp->amuledlg) {
45 ntf.Notify();
47 #endif
48 } else {
49 CMuleGUIEvent evt(ntf.Clone());
50 wxPostEvent(wxTheApp, evt);
54 void Search_Add_Download(CSearchFile* file, uint8 category)
56 theApp->downloadqueue->AddSearchToDownload(file, category);
60 void ShowUserCount(wxString NOT_ON_DAEMON(str))
62 #ifndef AMULE_DAEMON
63 theApp->amuledlg->ShowUserCount(str);
64 #endif
68 void Search_Update_Progress(uint32 NOT_ON_DAEMON(val))
70 #ifndef AMULE_DAEMON
71 if (theApp->amuledlg->m_searchwnd) {
72 if (val == 0xffff) {
73 // Global search ended
74 theApp->amuledlg->m_searchwnd->ResetControls();
75 } else {
76 theApp->amuledlg->m_searchwnd->UpdateProgress(val);
79 #endif
83 void DownloadCtrlUpdateItem(const void* item)
85 #ifndef CLIENT_GUI
86 theApp->ECServerHandler->m_ec_notifier->DownloadFile_SetDirty((CPartFile *)item);
87 #endif
88 #ifndef AMULE_DAEMON
89 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
90 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
92 #endif
96 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
98 #ifndef AMULE_DAEMON
99 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
100 #endif
103 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
105 #ifndef AMULE_DAEMON
106 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
107 #endif
110 void ConvertUpdateProgress(float NOT_ON_DAEMON(percent), wxString NOT_ON_DAEMON(text), wxString NOT_ON_DAEMON(header))
112 #ifndef AMULE_DAEMON
113 CPartFileConvertDlg::UpdateProgress(percent, text, header);
114 #endif
117 void ConvertUpdateJobInfo(ConvertInfo NOT_ON_DAEMON(info))
119 #ifndef AMULE_DAEMON
120 CPartFileConvertDlg::UpdateJobInfo(info);
121 #endif
124 void ConvertRemoveJobInfo(unsigned NOT_ON_DAEMON(id))
126 #ifndef AMULE_DAEMON
127 CPartFileConvertDlg::RemoveJobInfo(id);
128 #endif
131 void ConvertClearInfos()
133 #ifndef AMULE_DAEMON
134 CPartFileConvertDlg::ClearInfo();
135 #endif
138 void ConvertRemoveJob(unsigned NOT_ON_REMOTEGUI(id))
140 #ifndef CLIENT_GUI
141 CPartFileConvert::RemoveJob(id);
142 #endif
145 void ConvertRetryJob(unsigned NOT_ON_REMOTEGUI(id))
147 #ifndef CLIENT_GUI
148 CPartFileConvert::RetryJob(id);
149 #endif
152 void ConvertReaddAllJobs()
154 #ifndef CLIENT_GUI
155 CPartFileConvert::ReaddAllJobs();
156 #endif
159 void ShowGUI()
161 #ifndef AMULE_DAEMON
162 theApp->amuledlg->Iconize(false);
163 #endif
166 #ifdef CLIENT_GUI
168 void PartFile_Swap_A4AF(CPartFile* file)
170 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
173 void PartFile_Swap_A4AF_Auto(CPartFile* file)
175 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
178 void PartFile_Swap_A4AF_Others(CPartFile* file)
180 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
183 void PartFile_Pause(CPartFile* file)
185 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
188 void PartFile_Resume(CPartFile* file)
190 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
193 void PartFile_Stop(CPartFile* file)
195 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
198 void PartFile_PrioAuto(CPartFile* file, bool val)
200 theApp->downloadqueue->AutoPrio(file, val);
203 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
205 theApp->downloadqueue->Prio(file, newDownPriority);
208 void PartFile_Delete(CPartFile* file)
210 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
213 void PartFile_SetCat(CPartFile* file, uint32 val)
215 theApp->downloadqueue->Category(file, val);
218 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
220 theApp->sharedfiles->SetFilePrio(file, val);
223 void KnownFile_Up_Prio_Auto(CKnownFile* file)
225 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
228 void Download_Set_Cat_Prio(uint8, uint8)
232 void Download_Set_Cat_Status(uint8, int)
236 #else
238 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
240 #ifndef AMULE_DAEMON
241 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
242 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
244 #endif
247 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
249 #ifndef AMULE_DAEMON
250 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
251 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
253 #endif
256 void SharedFilesRemoveAllFiles()
258 #ifndef AMULE_DAEMON
259 if (theApp->amuledlg->m_sharedfileswnd) {
260 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
262 #endif
266 void SharedFilesShowFileList()
268 #ifndef AMULE_DAEMON
269 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
270 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
272 #endif
276 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
278 #ifndef AMULE_DAEMON
279 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
280 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
282 #endif
286 void DownloadCtrlAddFile(CPartFile* file)
288 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
289 #ifndef AMULE_DAEMON
290 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
291 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
293 #endif
296 void DownloadCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), DownloadItemType NOT_ON_DAEMON(type))
298 #ifndef AMULE_DAEMON
299 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
300 if (owner->ShowSources()) {
301 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddSource(owner, source, type);
304 #endif
307 void DownloadCtrlRemoveFile(CPartFile* file)
309 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
310 #ifndef AMULE_DAEMON
311 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
312 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
314 #endif
317 void DownloadCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
319 #ifndef AMULE_DAEMON
320 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
321 if ((owner == NULL) || owner->ShowSources()) {
322 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveSource(source, owner);
325 #endif
328 void DownloadCtrlHideSource(CPartFile* NOT_ON_DAEMON(file))
330 #ifndef AMULE_DAEMON
331 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
332 theApp->amuledlg->m_transferwnd->downloadlistctrl->ShowSources(file, false);
334 #endif
337 void DownloadCtrlSort()
339 #ifndef AMULE_DAEMON
340 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
341 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
343 #endif
347 void ClientCtrlAddClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
349 #ifndef AMULE_DAEMON
350 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
351 theApp->amuledlg->m_transferwnd->clientlistctrl->InsertClient(client, type);
353 #endif
356 void ClientCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
358 #ifndef AMULE_DAEMON
359 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
360 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateClient(client, type);
362 #endif
365 void ClientCtrlRemoveClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
367 #ifndef AMULE_DAEMON
368 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
369 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveClient(client, type);
371 #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
491 void Search_Update_Sources(CSearchFile* result)
493 result->SetDownloadStatus();
494 #ifndef AMULE_DAEMON
495 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
496 theApp->amuledlg->m_searchwnd->UpdateResult(result);
498 #endif
501 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
503 #ifndef AMULE_DAEMON
504 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
505 theApp->amuledlg->m_searchwnd->AddResult(result);
507 #endif
511 void ChatRefreshFriend(CFriend * NOT_ON_DAEMON(Friend), bool NOT_ON_DAEMON(connected))
513 #ifndef AMULE_DAEMON
514 if (theApp->amuledlg->m_chatwnd) {
515 theApp->amuledlg->m_chatwnd->RefreshFriend(Friend, connected);
517 #endif
520 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
522 #ifndef AMULE_DAEMON
523 if (theApp->amuledlg->m_chatwnd) {
524 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
526 #endif
529 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
531 #ifndef AMULE_DAEMON
532 if (theApp->amuledlg->m_chatwnd) {
533 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
535 #endif
539 void ChatSendCaptcha(wxString NOT_ON_DAEMON(captcha), uint64 NOT_ON_DAEMON(to_id))
541 #ifndef AMULE_DAEMON
542 if (theApp->amuledlg->m_chatwnd) {
543 theApp->amuledlg->m_chatwnd->SendMessage(captcha, wxEmptyString, to_id);
545 #endif
549 void ShowConnState(long WXUNUSED(state))
551 #ifndef AMULE_DAEMON
552 theApp->amuledlg->ShowConnectionState();
553 #endif
556 void ShowQueueCount(uint32 NOT_ON_DAEMON(count))
558 #ifndef AMULE_DAEMON
559 if (theApp->amuledlg->m_transferwnd) {
560 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
562 #endif
565 void ShowUpdateCatTabTitles()
567 #ifndef AMULE_DAEMON
568 if (theApp->amuledlg->m_transferwnd) {
569 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
571 #endif
574 void CategoryAdded()
576 #ifndef AMULE_DAEMON
577 if (theApp->amuledlg->m_transferwnd) {
578 theApp->amuledlg->m_transferwnd->
579 AddCategory(theApp->glob_prefs->GetCategory(
580 theApp->glob_prefs->GetCatCount()-1));
582 #endif
585 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
587 #ifndef AMULE_DAEMON
588 if (theApp->amuledlg->m_transferwnd) {
589 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
590 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
591 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
593 #endif
596 void CategoryDelete(uint32 cat)
598 #ifdef AMULE_DAEMON
599 theApp->glob_prefs->RemoveCat(cat);
600 #else
601 if (theApp->amuledlg->m_transferwnd) {
602 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
604 #endif
608 void PartFile_Swap_A4AF(CPartFile* file)
610 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
611 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
612 for ( ; it != file->GetA4AFList().end(); ) {
613 CUpDownClient *cur_source = *it++;
615 cur_source->SwapToAnotherFile(true, false, false, file);
620 void PartFile_Swap_A4AF_Auto(CPartFile* file)
622 file->SetA4AFAuto(!file->IsA4AFAuto());
625 void PartFile_Swap_A4AF_Others(CPartFile* file)
627 if ((file->GetStatus(false) == PS_READY) || (file->GetStatus(false) == PS_EMPTY)) {
628 CPartFile::SourceSet::const_iterator it = file->GetSourceList().begin();
629 for( ; it != file->GetSourceList().end(); ) {
630 CUpDownClient* cur_source = *it++;
632 cur_source->SwapToAnotherFile(false, false, false, NULL);
637 void PartFile_Pause(CPartFile* file)
639 file->PauseFile();
642 void PartFile_Resume(CPartFile* file)
644 file->ResumeFile();
645 file->SavePartFile();
648 void PartFile_Stop(CPartFile* file)
650 file->StopFile();
653 void PartFile_PrioAuto(CPartFile* file, bool val)
655 file->SetAutoDownPriority(val);
658 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
660 file->SetDownPriority(newDownPriority, bSave);
663 void PartFile_Delete(CPartFile* file)
665 file->Delete();
668 void PartFile_SetCat(CPartFile* file, uint32 val)
670 file->SetCategory(val);
674 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
676 file->SetAutoUpPriority(false);
677 file->SetUpPriority(val);
680 void KnownFile_Up_Prio_Auto(CKnownFile* file)
682 file->SetAutoUpPriority(true);
683 file->UpdateAutoUpPriority();
686 void KnownFile_Comment_Set(CKnownFile* file, wxString comment)
688 file->SetFileComment(comment);
692 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
694 theApp->downloadqueue->SetCatPrio(cat, newprio);
697 void Download_Set_Cat_Status(uint8 cat, int newstatus)
699 theApp->downloadqueue->SetCatStatus(cat, newstatus);
702 #endif // #ifdef CLIENT_GUI
704 // File_checked_for_headers