Upstream tarball 9931
[amule.git] / src / GuiEvents.cpp
blob8630ebd579dc4fa1a3f03a985c53d00d6bf10c20
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"
11 #ifndef AMULE_DAEMON
12 # include "ChatWnd.h"
13 # include "amuleDlg.h"
14 # include "ServerWnd.h"
15 # include "SearchDlg.h"
16 # include "TransferWnd.h"
17 # include "SharedFilesWnd.h"
18 # include "ServerListCtrl.h"
19 # include "ClientListCtrl.h"
20 # include "SharedFilesCtrl.h"
21 # include "DownloadListCtrl.h"
22 # include "muuli_wdr.h"
23 # include "PartFileConvertDlg.h"
24 #endif
26 #ifndef CLIENT_GUI
27 # include "PartFileConvert.h"
28 #endif
31 DEFINE_LOCAL_EVENT_TYPE(MULE_EVT_NOTIFY)
34 namespace MuleNotify
37 void HandleNotification(const CMuleNotiferBase& ntf)
39 if (wxThread::IsMain()) {
40 #if defined(AMULE_DAEMON)
41 ntf.Notify();
42 #else
43 if (theApp->amuledlg) {
44 ntf.Notify();
46 #endif
47 } else {
48 CMuleGUIEvent evt(ntf.Clone());
49 wxPostEvent(wxTheApp, evt);
53 void Search_Add_Download(CSearchFile* file, uint8 category)
55 theApp->downloadqueue->AddSearchToDownload(file, category);
59 void ShowUserCount(wxString NOT_ON_DAEMON(str))
61 #ifndef AMULE_DAEMON
62 theApp->amuledlg->ShowUserCount(str);
63 #endif
67 void Search_Update_Progress(uint32 NOT_ON_DAEMON(val))
69 #ifndef AMULE_DAEMON
70 if (theApp->amuledlg->m_searchwnd) {
71 if (val == 0xffff) {
72 // Global search ended
73 theApp->amuledlg->m_searchwnd->ResetControls();
74 } else {
75 theApp->amuledlg->m_searchwnd->UpdateProgress(val);
78 #endif
82 void DownloadCtrlUpdateItem(const void* item)
84 #ifndef CLIENT_GUI
85 theApp->ECServerHandler->m_ec_notifier->DownloadFile_SetDirty((CPartFile *)item);
86 #endif
87 #ifndef AMULE_DAEMON
88 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
89 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
91 #endif
95 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
97 #ifndef AMULE_DAEMON
98 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
99 #endif
102 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
104 #ifndef AMULE_DAEMON
105 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
106 #endif
109 void ConvertUpdateProgress(float NOT_ON_DAEMON(percent), wxString NOT_ON_DAEMON(text), wxString NOT_ON_DAEMON(header))
111 #ifndef AMULE_DAEMON
112 CPartFileConvertDlg::UpdateProgress(percent, text, header);
113 #endif
116 void ConvertUpdateJobInfo(ConvertInfo NOT_ON_DAEMON(info))
118 #ifndef AMULE_DAEMON
119 CPartFileConvertDlg::UpdateJobInfo(info);
120 #endif
123 void ConvertRemoveJobInfo(unsigned NOT_ON_DAEMON(id))
125 #ifndef AMULE_DAEMON
126 CPartFileConvertDlg::RemoveJobInfo(id);
127 #endif
130 void ConvertClearInfos()
132 #ifndef AMULE_DAEMON
133 CPartFileConvertDlg::ClearInfo();
134 #endif
137 void ConvertRemoveJob(unsigned NOT_ON_REMOTEGUI(id))
139 #ifndef CLIENT_GUI
140 CPartFileConvert::RemoveJob(id);
141 #endif
144 void ConvertRetryJob(unsigned NOT_ON_REMOTEGUI(id))
146 #ifndef CLIENT_GUI
147 CPartFileConvert::RetryJob(id);
148 #endif
151 void ConvertReaddAllJobs()
153 #ifndef CLIENT_GUI
154 CPartFileConvert::ReaddAllJobs();
155 #endif
158 void ShowGUI()
160 #ifndef AMULE_DAEMON
161 theApp->amuledlg->Iconize(false);
162 #endif
165 #ifdef CLIENT_GUI
167 void PartFile_Swap_A4AF(CPartFile* file)
169 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
172 void PartFile_Swap_A4AF_Auto(CPartFile* file)
174 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
177 void PartFile_Swap_A4AF_Others(CPartFile* file)
179 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
182 void PartFile_Pause(CPartFile* file)
184 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
187 void PartFile_Resume(CPartFile* file)
189 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
192 void PartFile_Stop(CPartFile* file)
194 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
197 void PartFile_PrioAuto(CPartFile* file, bool val)
199 theApp->downloadqueue->AutoPrio(file, val);
202 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
204 theApp->downloadqueue->Prio(file, newDownPriority);
207 void PartFile_Delete(CPartFile* file)
209 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
212 void PartFile_SetCat(CPartFile* file, uint32 val)
214 theApp->downloadqueue->Category(file, val);
217 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
219 theApp->sharedfiles->SetFilePrio(file, val);
222 void KnownFile_Up_Prio_Auto(CKnownFile* file)
224 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
227 void Download_Set_Cat_Prio(uint8, uint8)
231 void Download_Set_Cat_Status(uint8, int)
235 #else
237 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
239 #ifndef AMULE_DAEMON
240 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
241 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
243 #endif
246 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
248 #ifndef AMULE_DAEMON
249 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
250 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
252 #endif
255 void SharedFilesRemoveAllFiles()
257 #ifndef AMULE_DAEMON
258 if (theApp->amuledlg->m_sharedfileswnd) {
259 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
261 #endif
265 void SharedFilesShowFileList()
267 #ifndef AMULE_DAEMON
268 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
269 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
271 #endif
275 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
277 #ifndef AMULE_DAEMON
278 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
279 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
281 #endif
285 void DownloadCtrlAddFile(CPartFile* file)
287 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
288 #ifndef AMULE_DAEMON
289 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
290 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
292 #endif
295 void DownloadCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), DownloadItemType NOT_ON_DAEMON(type))
297 #ifndef AMULE_DAEMON
298 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
299 if (owner->ShowSources()) {
300 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddSource(owner, source, type);
303 #endif
306 void DownloadCtrlRemoveFile(CPartFile* file)
308 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
309 #ifndef AMULE_DAEMON
310 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
311 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
313 #endif
316 void DownloadCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
318 #ifndef AMULE_DAEMON
319 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
320 if ((owner == NULL) || owner->ShowSources()) {
321 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveSource(source, owner);
324 #endif
327 void DownloadCtrlHideSource(CPartFile* NOT_ON_DAEMON(file))
329 #ifndef AMULE_DAEMON
330 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
331 theApp->amuledlg->m_transferwnd->downloadlistctrl->ShowSources(file, false);
333 #endif
336 void DownloadCtrlSort()
338 #ifndef AMULE_DAEMON
339 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
340 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
342 #endif
346 void ClientCtrlAddClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
348 #ifndef AMULE_DAEMON
349 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
350 theApp->amuledlg->m_transferwnd->clientlistctrl->InsertClient(client, type);
352 #endif
355 void ClientCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
357 #ifndef AMULE_DAEMON
358 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
359 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateClient(client, type);
361 #endif
364 void ClientCtrlRemoveClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
366 #ifndef AMULE_DAEMON
367 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
368 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveClient(client, type);
370 #endif
374 void ServerAdd(CServer* NOT_ON_DAEMON(server))
376 #ifndef AMULE_DAEMON
377 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
378 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
380 #endif
383 void ServerRemove(CServer* NOT_ON_DAEMON(server))
385 #ifndef AMULE_DAEMON
386 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
387 theApp->amuledlg->m_serverwnd->serverlistctrl->RemoveServer(server);
389 #endif
392 void ServerRemoveDead()
394 if (theApp->serverlist) {
395 theApp->serverlist->RemoveDeadServers();
399 void ServerRemoveAll()
401 #ifndef AMULE_DAEMON
402 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
403 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
405 #endif
408 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
410 #ifndef AMULE_DAEMON
411 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
412 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
414 #endif
417 void ServerRefresh(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->RefreshServer(server);
423 #endif
426 void ServerFreeze()
428 #ifndef AMULE_DAEMON
429 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
430 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
432 #endif
435 void ServerThaw()
437 #ifndef AMULE_DAEMON
438 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
439 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
441 #endif
444 void ServerUpdateED2KInfo()
446 #ifndef AMULE_DAEMON
447 if (theApp->amuledlg->m_serverwnd) {
448 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
450 #endif
453 void ServerUpdateKadKInfo()
455 #ifndef AMULE_DAEMON
456 if (theApp->amuledlg->m_serverwnd) {
457 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
459 #endif
463 void SearchCancel()
465 #ifndef AMULE_DAEMON
466 if (theApp->amuledlg->m_searchwnd) {
467 theApp->amuledlg->m_searchwnd->ResetControls();
469 #endif
472 void SearchLocalEnd()
474 #ifndef AMULE_DAEMON
475 if (theApp->amuledlg->m_searchwnd) {
476 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
478 #endif
481 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
483 #ifndef AMULE_DAEMON
484 if (theApp->amuledlg->m_searchwnd) {
485 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
487 #endif
490 void Search_Update_Sources(CSearchFile* NOT_ON_DAEMON(result))
492 #ifndef AMULE_DAEMON
493 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
494 theApp->amuledlg->m_searchwnd->UpdateResult(result);
496 #endif
499 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
501 #ifndef AMULE_DAEMON
502 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
503 theApp->amuledlg->m_searchwnd->AddResult(result);
505 #endif
509 void ChatRefreshFriend(CFriend * NOT_ON_DAEMON(Friend), bool NOT_ON_DAEMON(connected))
511 #ifndef AMULE_DAEMON
512 if (theApp->amuledlg->m_chatwnd) {
513 theApp->amuledlg->m_chatwnd->RefreshFriend(Friend, connected);
515 #endif
518 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
520 #ifndef AMULE_DAEMON
521 if (theApp->amuledlg->m_chatwnd) {
522 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
524 #endif
527 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
529 #ifndef AMULE_DAEMON
530 if (theApp->amuledlg->m_chatwnd) {
531 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
533 #endif
537 void ChatSendCaptcha(wxString NOT_ON_DAEMON(captcha), uint64 NOT_ON_DAEMON(to_id))
539 #ifndef AMULE_DAEMON
540 if (theApp->amuledlg->m_chatwnd) {
541 theApp->amuledlg->m_chatwnd->SendMessage(captcha, wxEmptyString, to_id);
543 #endif
547 void ShowConnState(long WXUNUSED(state))
549 #ifndef AMULE_DAEMON
550 theApp->amuledlg->ShowConnectionState();
551 #endif
554 void ShowQueueCount(uint32 NOT_ON_DAEMON(count))
556 #ifndef AMULE_DAEMON
557 if (theApp->amuledlg->m_transferwnd) {
558 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
560 #endif
563 void ShowUpdateCatTabTitles()
565 #ifndef AMULE_DAEMON
566 if (theApp->amuledlg->m_transferwnd) {
567 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
569 #endif
572 void CategoryAdded()
574 #ifndef AMULE_DAEMON
575 if (theApp->amuledlg->m_transferwnd) {
576 theApp->amuledlg->m_transferwnd->
577 AddCategory(theApp->glob_prefs->GetCategory(
578 theApp->glob_prefs->GetCatCount()-1));
580 #endif
583 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
585 #ifndef AMULE_DAEMON
586 if (theApp->amuledlg->m_transferwnd) {
587 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
588 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
589 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
591 #endif
594 void CategoryDelete(uint32 cat)
596 #ifdef AMULE_DAEMON
597 theApp->glob_prefs->RemoveCat(cat);
598 #else
599 if (theApp->amuledlg->m_transferwnd) {
600 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
602 #endif
606 void PartFile_Swap_A4AF(CPartFile* file)
608 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
609 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
610 for ( ; it != file->GetA4AFList().end(); ) {
611 CUpDownClient *cur_source = *it++;
613 cur_source->SwapToAnotherFile(true, false, false, file);
618 void PartFile_Swap_A4AF_Auto(CPartFile* file)
620 file->SetA4AFAuto(!file->IsA4AFAuto());
623 void PartFile_Swap_A4AF_Others(CPartFile* file)
625 if ((file->GetStatus(false) == PS_READY) || (file->GetStatus(false) == PS_EMPTY)) {
626 CPartFile::SourceSet::const_iterator it = file->GetSourceList().begin();
627 for( ; it != file->GetSourceList().end(); ) {
628 CUpDownClient* cur_source = *it++;
630 cur_source->SwapToAnotherFile(false, false, false, NULL);
635 void PartFile_Pause(CPartFile* file)
637 file->PauseFile();
640 void PartFile_Resume(CPartFile* file)
642 file->ResumeFile();
643 file->SavePartFile();
646 void PartFile_Stop(CPartFile* file)
648 file->StopFile();
651 void PartFile_PrioAuto(CPartFile* file, bool val)
653 file->SetAutoDownPriority(val);
656 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
658 file->SetDownPriority(newDownPriority, bSave);
661 void PartFile_Delete(CPartFile* file)
663 file->Delete();
666 void PartFile_SetCat(CPartFile* file, uint32 val)
668 file->SetCategory(val);
672 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
674 file->SetAutoUpPriority(false);
675 file->SetUpPriority(val);
678 void KnownFile_Up_Prio_Auto(CKnownFile* file)
680 file->SetAutoUpPriority(true);
681 file->UpdateAutoUpPriority();
684 void KnownFile_Comment_Set(CKnownFile* file, wxString comment)
686 file->SetFileComment(comment);
690 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
692 theApp->downloadqueue->SetCatPrio(cat, newprio);
695 void Download_Set_Cat_Status(uint8 cat, int newstatus)
697 theApp->downloadqueue->SetCatStatus(cat, newstatus);
700 #endif // #ifdef CLIENT_GUI
702 // File_checked_for_headers