Upstream tarball 9613
[amule.git] / src / GuiEvents.cpp
blob705347cddae6c33abf788fb37fb66c58616246e9
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 #endif
25 #ifdef AMULE_DAEMON
26 # define NOT_ON_DAEMON(x) WXUNUSED(x)
27 #else
28 # define NOT_ON_DAEMON(x) x
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) || defined(REMOTE_GUI)
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
111 #ifdef CLIENT_GUI
113 void PartFile_Swap_A4AF(CPartFile* file)
115 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
118 void PartFile_Swap_A4AF_Auto(CPartFile* file)
120 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
123 void PartFile_Swap_A4AF_Others(CPartFile* file)
125 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
128 void PartFile_Pause(CPartFile* file)
130 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
133 void PartFile_Resume(CPartFile* file)
135 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
138 void PartFile_Stop(CPartFile* file)
140 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
143 void PartFile_PrioAuto(CPartFile* file, bool val)
145 theApp->downloadqueue->AutoPrio(file, val);
148 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
150 theApp->downloadqueue->Prio(file, newDownPriority);
153 void PartFile_Delete(CPartFile* file)
155 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
158 void PartFile_SetCat(CPartFile* file, uint32 val)
160 theApp->downloadqueue->Category(file, val);
163 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
165 theApp->sharedfiles->SetFilePrio(file, val);
168 void KnownFile_Up_Prio_Auto(CKnownFile* file)
170 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
173 void Download_Set_Cat_Prio(uint8, uint8)
177 void Download_Set_Cat_Status(uint8, int)
181 #else
183 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
185 #ifndef AMULE_DAEMON
186 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
187 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
189 #endif
192 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
194 #ifndef AMULE_DAEMON
195 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
196 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
198 #endif
201 void SharedFilesRemoveAllFiles()
203 #ifndef AMULE_DAEMON
204 if (theApp->amuledlg->m_sharedfileswnd) {
205 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
207 #endif
211 void SharedFilesShowFileList()
213 #ifndef AMULE_DAEMON
214 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
215 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
217 #endif
221 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
223 #ifndef AMULE_DAEMON
224 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
225 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
227 #endif
231 void DownloadCtrlAddFile(CPartFile* file)
233 #ifndef CLIENT_GUI
234 theApp->ECServerHandler->m_ec_notifier->DownloadFile_AddFile(file);
235 #endif
236 #ifndef AMULE_DAEMON
237 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
238 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
240 #endif
243 void DownloadCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), DownloadItemType NOT_ON_DAEMON(type))
245 #ifndef AMULE_DAEMON
246 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
247 if (owner->ShowSources()) {
248 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddSource(owner, source, type);
251 #endif
254 void DownloadCtrlRemoveFile(CPartFile* file)
256 #ifndef CLIENT_GUI
257 theApp->ECServerHandler->m_ec_notifier->DownloadFile_RemoveFile(file);
258 #endif
259 #ifndef AMULE_DAEMON
260 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
261 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
263 #endif
266 void DownloadCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
268 #ifndef AMULE_DAEMON
269 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
270 if ((owner == NULL) || owner->ShowSources()) {
271 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveSource(source, owner);
274 #endif
277 void DownloadCtrlHideSource(CPartFile* NOT_ON_DAEMON(file))
279 #ifndef AMULE_DAEMON
280 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
281 theApp->amuledlg->m_transferwnd->downloadlistctrl->ShowSources(file, false);
283 #endif
286 void DownloadCtrlSort()
288 #ifndef AMULE_DAEMON
289 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
290 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
292 #endif
296 void ClientCtrlAddClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
298 #ifndef AMULE_DAEMON
299 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
300 theApp->amuledlg->m_transferwnd->clientlistctrl->InsertClient(client, type);
302 #endif
305 void ClientCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
307 #ifndef AMULE_DAEMON
308 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
309 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateClient(client, type);
311 #endif
314 void ClientCtrlRemoveClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
316 #ifndef AMULE_DAEMON
317 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
318 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveClient(client, type);
320 #endif
324 void ServerAdd(CServer* NOT_ON_DAEMON(server))
326 #ifndef AMULE_DAEMON
327 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
328 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
330 #endif
333 void ServerRemove(CServer* NOT_ON_DAEMON(server))
335 #ifndef AMULE_DAEMON
336 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
337 theApp->amuledlg->m_serverwnd->serverlistctrl->RemoveServer(server);
339 #endif
342 void ServerRemoveDead()
344 if (theApp->serverlist) {
345 theApp->serverlist->RemoveDeadServers();
349 void ServerRemoveAll()
351 #ifndef AMULE_DAEMON
352 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
353 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
355 #endif
358 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
360 #ifndef AMULE_DAEMON
361 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
362 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
364 #endif
367 void ServerRefresh(CServer* NOT_ON_DAEMON(server))
369 #ifndef AMULE_DAEMON
370 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
371 theApp->amuledlg->m_serverwnd->serverlistctrl->RefreshServer(server);
373 #endif
376 void ServerFreeze()
378 #ifndef AMULE_DAEMON
379 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
380 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
382 #endif
385 void ServerThaw()
387 #ifndef AMULE_DAEMON
388 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
389 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
391 #endif
394 void ServerUpdateED2KInfo()
396 #ifndef AMULE_DAEMON
397 if (theApp->amuledlg->m_serverwnd) {
398 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
400 #endif
403 void ServerUpdateKadKInfo()
405 #ifndef AMULE_DAEMON
406 if (theApp->amuledlg->m_serverwnd) {
407 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
409 #endif
413 void SearchCancel()
415 #ifndef AMULE_DAEMON
416 if (theApp->amuledlg->m_searchwnd) {
417 theApp->amuledlg->m_searchwnd->ResetControls();
419 #endif
422 void SearchLocalEnd()
424 #ifndef AMULE_DAEMON
425 if (theApp->amuledlg->m_searchwnd) {
426 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
428 #endif
431 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
433 #ifndef AMULE_DAEMON
434 if (theApp->amuledlg->m_searchwnd) {
435 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
437 #endif
440 void Search_Update_Sources(CSearchFile* NOT_ON_DAEMON(result))
442 #ifndef AMULE_DAEMON
443 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
444 theApp->amuledlg->m_searchwnd->UpdateResult(result);
446 #endif
449 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
451 #ifndef AMULE_DAEMON
452 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
453 theApp->amuledlg->m_searchwnd->AddResult(result);
455 #endif
459 void ChatRefreshFriend(uint32 NOT_ON_DAEMON(lastUsedIP), uint32 NOT_ON_DAEMON(lastUsedPort), wxString NOT_ON_DAEMON(name))
461 #ifndef AMULE_DAEMON
462 if (theApp->amuledlg->m_chatwnd) {
463 theApp->amuledlg->m_chatwnd->RefreshFriend(CMD4Hash(), name, lastUsedIP, lastUsedPort);
465 #endif
468 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
470 #ifndef AMULE_DAEMON
471 if (theApp->amuledlg->m_chatwnd) {
472 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
474 #endif
477 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
479 #ifndef AMULE_DAEMON
480 if (theApp->amuledlg->m_chatwnd) {
481 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
483 #endif
487 void ChatSendCaptcha(wxString NOT_ON_DAEMON(captcha), uint64 NOT_ON_DAEMON(to_id))
489 #ifndef AMULE_DAEMON
490 if (theApp->amuledlg->m_chatwnd) {
491 theApp->amuledlg->m_chatwnd->SendMessage(captcha, wxEmptyString, to_id);
493 #endif
497 void ShowConnState(long WXUNUSED(state))
499 #ifndef AMULE_DAEMON
500 theApp->amuledlg->ShowConnectionState();
501 #endif
504 void ShowQueueCount(uint32 NOT_ON_DAEMON(count))
506 #ifndef AMULE_DAEMON
507 if (theApp->amuledlg->m_transferwnd) {
508 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
510 #endif
513 void ShowUpdateCatTabTitles()
515 #ifndef AMULE_DAEMON
516 if (theApp->amuledlg->m_transferwnd) {
517 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
519 #endif
522 void ShowGUI()
524 #ifndef AMULE_DAEMON
525 theApp->amuledlg->Iconize(false);
526 #endif
530 void CategoryAdded()
532 #ifndef AMULE_DAEMON
533 if (theApp->amuledlg->m_transferwnd) {
534 theApp->amuledlg->m_transferwnd->
535 AddCategory(theApp->glob_prefs->GetCategory(
536 theApp->glob_prefs->GetCatCount()-1));
538 #endif
541 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
543 #ifndef AMULE_DAEMON
544 if (theApp->amuledlg->m_transferwnd) {
545 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
546 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
547 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
549 #endif
552 void CategoryDelete(uint32 NOT_ON_DAEMON(cat))
554 #ifndef AMULE_DAEMON
555 if (theApp->amuledlg->m_transferwnd) {
556 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
558 #endif
562 void PartFile_Swap_A4AF(CPartFile* file)
564 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
565 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
566 for ( ; it != file->GetA4AFList().end(); ) {
567 CUpDownClient *cur_source = *it++;
569 cur_source->SwapToAnotherFile(true, false, false, file);
574 void PartFile_Swap_A4AF_Auto(CPartFile* file)
576 file->SetA4AFAuto(!file->IsA4AFAuto());
579 void PartFile_Swap_A4AF_Others(CPartFile* file)
581 if ((file->GetStatus(false) == PS_READY) || (file->GetStatus(false) == PS_EMPTY)) {
582 CPartFile::SourceSet::const_iterator it = file->GetSourceList().begin();
583 for( ; it != file->GetSourceList().end(); ) {
584 CUpDownClient* cur_source = *it++;
586 cur_source->SwapToAnotherFile(false, false, false, NULL);
591 void PartFile_Pause(CPartFile* file)
593 file->PauseFile();
596 void PartFile_Resume(CPartFile* file)
598 file->ResumeFile();
599 file->SavePartFile();
602 void PartFile_Stop(CPartFile* file)
604 file->StopFile();
607 void PartFile_PrioAuto(CPartFile* file, bool val)
609 file->SetAutoDownPriority(val);
612 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
614 file->SetDownPriority(newDownPriority, bSave);
617 void PartFile_Delete(CPartFile* file)
619 file->Delete();
622 void PartFile_SetCat(CPartFile* file, uint32 val)
624 file->SetCategory(val);
628 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
630 file->SetAutoUpPriority(false);
631 file->SetUpPriority(val);
634 void KnownFile_Up_Prio_Auto(CKnownFile* file)
636 file->SetAutoUpPriority(true);
637 file->UpdateAutoUpPriority();
640 void KnownFile_Comment_Set(CKnownFile* file, wxString comment)
642 file->SetFileComment(comment);
646 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
648 theApp->downloadqueue->SetCatPrio(cat, newprio);
651 void Download_Set_Cat_Status(uint8 cat, int newstatus)
653 theApp->downloadqueue->SetCatStatus(cat, newstatus);
656 #endif // #ifdef CLIENT_GUI
658 // File_checked_for_headers