Upstream tarball 10101
[amule.git] / src / GuiEvents.cpp
blob540c360c2325ebb6896817671b7e43bf27efc0f4
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 "ClientListCtrl.h"
22 # include "SharedFilesCtrl.h"
23 # include "DownloadListCtrl.h"
24 # include "muuli_wdr.h"
25 # include "PartFileConvertDlg.h"
26 #endif
28 #ifndef CLIENT_GUI
29 # include "PartFileConvert.h"
30 #endif
33 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY)
36 namespace MuleNotify
39 void HandleNotification(const CMuleNotiferBase& ntf)
41 if (wxThread::IsMain()) {
42 #if defined(AMULE_DAEMON)
43 ntf.Notify();
44 #else
45 if (theApp->amuledlg) {
46 ntf.Notify();
48 #endif
49 } else {
50 CMuleGUIEvent evt(ntf.Clone());
51 wxPostEvent(wxTheApp, evt);
55 void Search_Add_Download(CSearchFile* file, uint8 category)
57 theApp->downloadqueue->AddSearchToDownload(file, category);
61 void ShowUserCount(wxString NOT_ON_DAEMON(str))
63 #ifndef AMULE_DAEMON
64 theApp->amuledlg->ShowUserCount(str);
65 #endif
69 void Search_Update_Progress(uint32 NOT_ON_DAEMON(val))
71 #ifndef AMULE_DAEMON
72 if (theApp->amuledlg->m_searchwnd) {
73 if (val == 0xffff) {
74 // Global search ended
75 theApp->amuledlg->m_searchwnd->ResetControls();
76 } else if (val == 0xfffe) {
77 // Kad search ended
78 theApp->amuledlg->m_searchwnd->KadSearchEnd(0);
79 } else {
80 theApp->amuledlg->m_searchwnd->UpdateProgress(val);
83 #endif
87 void DownloadCtrlUpdateItem(const void* item)
89 #ifndef CLIENT_GUI
90 theApp->ECServerHandler->m_ec_notifier->DownloadFile_SetDirty((CPartFile *)item);
91 #endif
92 #ifndef AMULE_DAEMON
93 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
94 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
96 #endif
100 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
102 #ifndef AMULE_DAEMON
103 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
104 #endif
107 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
109 #ifndef AMULE_DAEMON
110 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
111 #endif
114 void ConvertUpdateProgress(float NOT_ON_DAEMON(percent), wxString NOT_ON_DAEMON(text), wxString NOT_ON_DAEMON(header))
116 #ifndef AMULE_DAEMON
117 CPartFileConvertDlg::UpdateProgress(percent, text, header);
118 #endif
121 void ConvertUpdateJobInfo(ConvertInfo NOT_ON_DAEMON(info))
123 #ifndef AMULE_DAEMON
124 CPartFileConvertDlg::UpdateJobInfo(info);
125 #endif
128 void ConvertRemoveJobInfo(unsigned NOT_ON_DAEMON(id))
130 #ifndef AMULE_DAEMON
131 CPartFileConvertDlg::RemoveJobInfo(id);
132 #endif
135 void ConvertClearInfos()
137 #ifndef AMULE_DAEMON
138 CPartFileConvertDlg::ClearInfo();
139 #endif
142 void ConvertRemoveJob(unsigned NOT_ON_REMOTEGUI(id))
144 #ifndef CLIENT_GUI
145 CPartFileConvert::RemoveJob(id);
146 #endif
149 void ConvertRetryJob(unsigned NOT_ON_REMOTEGUI(id))
151 #ifndef CLIENT_GUI
152 CPartFileConvert::RetryJob(id);
153 #endif
156 void ConvertReaddAllJobs()
158 #ifndef CLIENT_GUI
159 CPartFileConvert::ReaddAllJobs();
160 #endif
163 void ShowGUI()
165 #ifndef AMULE_DAEMON
166 theApp->amuledlg->Iconize(false);
167 #endif
170 #ifdef CLIENT_GUI
172 void PartFile_Swap_A4AF(CPartFile* file)
174 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
177 void PartFile_Swap_A4AF_Auto(CPartFile* file)
179 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
182 void PartFile_Swap_A4AF_Others(CPartFile* file)
184 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
187 void PartFile_Pause(CPartFile* file)
189 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
192 void PartFile_Resume(CPartFile* file)
194 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
197 void PartFile_Stop(CPartFile* file)
199 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
202 void PartFile_PrioAuto(CPartFile* file, bool val)
204 theApp->downloadqueue->AutoPrio(file, val);
207 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
209 theApp->downloadqueue->Prio(file, newDownPriority);
212 void PartFile_Delete(CPartFile* file)
214 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
217 void PartFile_SetCat(CPartFile* file, uint32 val)
219 theApp->downloadqueue->Category(file, val);
222 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
224 theApp->sharedfiles->SetFilePrio(file, val);
227 void KnownFile_Up_Prio_Auto(CKnownFile* file)
229 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
232 void Download_Set_Cat_Prio(uint8, uint8)
236 void Download_Set_Cat_Status(uint8, int)
240 #else
242 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
244 #ifndef AMULE_DAEMON
245 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
246 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
248 #endif
251 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
253 #ifndef AMULE_DAEMON
254 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
255 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
257 #endif
260 void SharedFilesRemoveAllFiles()
262 #ifndef AMULE_DAEMON
263 if (theApp->amuledlg->m_sharedfileswnd) {
264 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
266 #endif
270 void SharedFilesShowFileList()
272 #ifndef AMULE_DAEMON
273 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
274 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
276 #endif
280 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
282 #ifndef AMULE_DAEMON
283 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
284 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
286 #endif
290 void DownloadCtrlAddFile(CPartFile* file)
292 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
293 #ifndef AMULE_DAEMON
294 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
295 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
297 #endif
300 void DownloadCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), DownloadItemType NOT_ON_DAEMON(type))
302 #ifndef AMULE_DAEMON
303 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
304 if (owner->ShowSources()) {
305 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddSource(owner, source, type);
308 #endif
311 void DownloadCtrlRemoveFile(CPartFile* file)
313 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
314 #ifndef AMULE_DAEMON
315 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
316 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
318 #endif
321 void DownloadCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
323 #ifndef AMULE_DAEMON
324 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
325 if ((owner == NULL) || owner->ShowSources()) {
326 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveSource(source, owner);
329 #endif
332 void DownloadCtrlHideSource(CPartFile* NOT_ON_DAEMON(file))
334 #ifndef AMULE_DAEMON
335 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
336 theApp->amuledlg->m_transferwnd->downloadlistctrl->ShowSources(file, false);
338 #endif
341 void DownloadCtrlSort()
343 #ifndef AMULE_DAEMON
344 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
345 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
347 #endif
351 void ClientCtrlAddClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
353 #ifndef AMULE_DAEMON
354 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
355 theApp->amuledlg->m_transferwnd->clientlistctrl->InsertClient(client, type);
357 #endif
360 void ClientCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
362 #ifndef AMULE_DAEMON
363 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
364 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateClient(client, type);
366 #endif
369 void ClientCtrlRemoveClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
371 #ifndef AMULE_DAEMON
372 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
373 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveClient(client, type);
375 #endif
379 void ServerAdd(CServer* NOT_ON_DAEMON(server))
381 #ifndef AMULE_DAEMON
382 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
383 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
385 #endif
388 void ServerRemove(CServer* NOT_ON_DAEMON(server))
390 #ifndef AMULE_DAEMON
391 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
392 theApp->amuledlg->m_serverwnd->serverlistctrl->RemoveServer(server);
394 #endif
397 void ServerRemoveDead()
399 if (theApp->serverlist) {
400 theApp->serverlist->RemoveDeadServers();
404 void ServerRemoveAll()
406 #ifndef AMULE_DAEMON
407 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
408 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
410 #endif
413 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
415 #ifndef AMULE_DAEMON
416 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
417 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
419 #endif
422 void ServerRefresh(CServer* NOT_ON_DAEMON(server))
424 #ifndef AMULE_DAEMON
425 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
426 theApp->amuledlg->m_serverwnd->serverlistctrl->RefreshServer(server);
428 #endif
431 void ServerFreeze()
433 #ifndef AMULE_DAEMON
434 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
435 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
437 #endif
440 void ServerThaw()
442 #ifndef AMULE_DAEMON
443 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
444 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
446 #endif
449 void ServerUpdateED2KInfo()
451 #ifndef AMULE_DAEMON
452 if (theApp->amuledlg->m_serverwnd) {
453 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
455 #endif
458 void ServerUpdateKadKInfo()
460 #ifndef AMULE_DAEMON
461 if (theApp->amuledlg->m_serverwnd) {
462 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
464 #endif
468 void SearchCancel()
470 #ifndef AMULE_DAEMON
471 if (theApp->amuledlg->m_searchwnd) {
472 theApp->amuledlg->m_searchwnd->ResetControls();
474 #endif
477 void SearchLocalEnd()
479 #ifndef AMULE_DAEMON
480 if (theApp->amuledlg->m_searchwnd) {
481 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
483 #endif
486 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
488 #ifndef AMULE_DAEMON
489 if (theApp->amuledlg->m_searchwnd) {
490 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
492 #endif
493 theApp->searchlist->SetKadSearchFinished();
496 void Search_Update_Sources(CSearchFile* result)
498 result->SetDownloadStatus();
499 #ifndef AMULE_DAEMON
500 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
501 theApp->amuledlg->m_searchwnd->UpdateResult(result);
503 #endif
506 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
508 #ifndef AMULE_DAEMON
509 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
510 theApp->amuledlg->m_searchwnd->AddResult(result);
512 #endif
516 void ChatRefreshFriend(CFriend * NOT_ON_DAEMON(Friend), bool NOT_ON_DAEMON(connected))
518 #ifndef AMULE_DAEMON
519 if (theApp->amuledlg->m_chatwnd) {
520 theApp->amuledlg->m_chatwnd->RefreshFriend(Friend, connected);
522 #endif
525 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
527 #ifndef AMULE_DAEMON
528 if (theApp->amuledlg->m_chatwnd) {
529 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
531 #endif
534 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
536 #ifndef AMULE_DAEMON
537 if (theApp->amuledlg->m_chatwnd) {
538 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
540 #endif
544 void ChatSendCaptcha(wxString NOT_ON_DAEMON(captcha), uint64 NOT_ON_DAEMON(to_id))
546 #ifndef AMULE_DAEMON
547 if (theApp->amuledlg->m_chatwnd) {
548 theApp->amuledlg->m_chatwnd->SendMessage(captcha, wxEmptyString, to_id);
550 #endif
554 void ShowConnState(long WXUNUSED(state))
556 #ifndef AMULE_DAEMON
557 theApp->amuledlg->ShowConnectionState();
558 #endif
561 void ShowQueueCount(uint32 NOT_ON_DAEMON(count))
563 #ifndef AMULE_DAEMON
564 if (theApp->amuledlg->m_transferwnd) {
565 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
567 #endif
570 void ShowUpdateCatTabTitles()
572 #ifndef AMULE_DAEMON
573 if (theApp->amuledlg->m_transferwnd) {
574 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
576 #endif
579 void CategoryAdded()
581 #ifndef AMULE_DAEMON
582 if (theApp->amuledlg->m_transferwnd) {
583 theApp->amuledlg->m_transferwnd->
584 AddCategory(theApp->glob_prefs->GetCategory(
585 theApp->glob_prefs->GetCatCount()-1));
587 #endif
590 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
592 #ifndef AMULE_DAEMON
593 if (theApp->amuledlg->m_transferwnd) {
594 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
595 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
596 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
598 #endif
601 void CategoryDelete(uint32 cat)
603 #ifdef AMULE_DAEMON
604 if (cat > 0) {
605 theApp->downloadqueue->ResetCatParts(cat);
606 theApp->glob_prefs->RemoveCat(cat);
607 if ( theApp->glob_prefs->GetCatCount() == 1 ) {
608 thePrefs::SetAllcatType(0);
610 theApp->glob_prefs->SaveCats();
612 #else
613 if (theApp->amuledlg->m_transferwnd) {
614 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
616 #endif
620 void PartFile_Swap_A4AF(CPartFile* file)
622 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
623 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
624 for ( ; it != file->GetA4AFList().end(); ) {
625 CUpDownClient *cur_source = *it++;
627 cur_source->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 CUpDownClient* cur_source = *it++;
644 cur_source->SwapToAnotherFile(false, false, false, NULL);
649 void PartFile_Pause(CPartFile* file)
651 file->PauseFile();
654 void PartFile_Resume(CPartFile* file)
656 file->ResumeFile();
657 file->SavePartFile();
660 void PartFile_Stop(CPartFile* file)
662 file->StopFile();
665 void PartFile_PrioAuto(CPartFile* file, bool val)
667 file->SetAutoDownPriority(val);
670 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
672 file->SetDownPriority(newDownPriority, bSave);
675 void PartFile_Delete(CPartFile* file)
677 file->Delete();
680 void PartFile_SetCat(CPartFile* file, uint32 val)
682 file->SetCategory(val);
686 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
688 file->SetAutoUpPriority(false);
689 file->SetUpPriority(val);
692 void KnownFile_Up_Prio_Auto(CKnownFile* file)
694 file->SetAutoUpPriority(true);
695 file->UpdateAutoUpPriority();
698 void KnownFile_Comment_Set(CKnownFile* file, wxString comment)
700 file->SetFileComment(comment);
704 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
706 theApp->downloadqueue->SetCatPrio(cat, newprio);
709 void Download_Set_Cat_Status(uint8 cat, int newstatus)
711 theApp->downloadqueue->SetCatStatus(cat, newstatus);
714 #endif // #ifdef CLIENT_GUI
716 // File_checked_for_headers