Upstream tarball 20080414
[amule.git] / src / GuiEvents.cpp
blob4e7ef12e07d52183e4a726b9b3eb845f1c132237
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"
10 #ifndef AMULE_DAEMON
11 # include "ChatWnd.h"
12 # include "amuleDlg.h"
13 # include "ServerWnd.h"
14 # include "SearchDlg.h"
15 # include "TransferWnd.h"
16 # include "SharedFilesWnd.h"
17 # include "ServerListCtrl.h"
18 # include "ClientListCtrl.h"
19 # include "SharedFilesCtrl.h"
20 # include "DownloadListCtrl.h"
21 # include "muuli_wdr.h"
22 #endif
24 #ifdef AMULE_DAEMON
25 # define NOT_ON_DAEMON(x) WXUNUSED(x)
26 #else
27 # define NOT_ON_DAEMON(x) x
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) || defined(REMOTE_GUI)
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* NOT_ON_DAEMON(item))
84 #ifndef AMULE_DAEMON
85 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
86 theApp->amuledlg->m_transferwnd->downloadlistctrl->UpdateItem(item);
88 #endif
92 void NodesURLChanged(wxString NOT_ON_DAEMON(url))
94 #ifndef AMULE_DAEMON
95 CastByID(IDC_NODESLISTURL, NULL, wxTextCtrl)->SetValue(url);
96 #endif
99 void ServersURLChanged(wxString NOT_ON_DAEMON(url))
101 #ifndef AMULE_DAEMON
102 CastByID(IDC_SERVERLISTURL, NULL, wxTextCtrl)->SetValue(url);
103 #endif
107 #ifdef CLIENT_GUI
109 void PartFile_Swap_A4AF(CPartFile* file)
111 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS);
114 void PartFile_Swap_A4AF_Auto(CPartFile* file)
116 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_THIS_AUTO);
119 void PartFile_Swap_A4AF_Others(CPartFile* file)
121 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_SWAP_A4AF_OTHERS);
124 void PartFile_Pause(CPartFile* file)
126 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_PAUSE);
129 void PartFile_Resume(CPartFile* file)
131 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_RESUME);
134 void PartFile_Stop(CPartFile* file)
136 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_STOP);
139 void PartFile_PrioAuto(CPartFile* file, bool val)
141 theApp->downloadqueue->AutoPrio(file, val);
144 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool)
146 theApp->downloadqueue->Prio(file, newDownPriority);
149 void PartFile_Delete(CPartFile* file)
151 theApp->downloadqueue->SendFileCommand(file, EC_OP_PARTFILE_DELETE);
154 void PartFile_SetCat(CPartFile* file, uint32 val)
156 theApp->downloadqueue->Category(file, val);
159 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
161 theApp->sharedfiles->SetFilePrio(file, val);
164 void KnownFile_Up_Prio_Auto(CKnownFile* file)
166 theApp->sharedfiles->SetFilePrio(file, PR_AUTO);
169 void Download_Set_Cat_Prio(uint8, uint8)
173 void Download_Set_Cat_Status(uint8, int)
177 #else
179 void SharedFilesShowFile(CKnownFile* NOT_ON_DAEMON(file))
181 #ifndef AMULE_DAEMON
182 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
183 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFile(file);
185 #endif
188 void SharedFilesRemoveFile(CKnownFile* NOT_ON_DAEMON(file))
190 #ifndef AMULE_DAEMON
191 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
192 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->RemoveFile(file);
194 #endif
197 void SharedFilesRemoveAllFiles()
199 #ifndef AMULE_DAEMON
200 if (theApp->amuledlg->m_sharedfileswnd) {
201 theApp->amuledlg->m_sharedfileswnd->RemoveAllSharedFiles();
203 #endif
207 void SharedFilesShowFileList()
209 #ifndef AMULE_DAEMON
210 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
211 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->ShowFileList();
213 #endif
217 void SharedFilesUpdateItem(CKnownFile* NOT_ON_DAEMON(file))
219 #ifndef AMULE_DAEMON
220 if (theApp->amuledlg->m_sharedfileswnd && theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl) {
221 theApp->amuledlg->m_sharedfileswnd->sharedfilesctrl->UpdateItem(file);
223 #endif
227 void DownloadCtrlAddFile(CPartFile* NOT_ON_DAEMON(file))
229 #ifndef AMULE_DAEMON
230 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl ) {
231 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddFile(file);
233 #endif
236 void DownloadCtrlAddSource(CPartFile* NOT_ON_DAEMON(owner), CUpDownClient* NOT_ON_DAEMON(source), DownloadItemType NOT_ON_DAEMON(type))
238 #ifndef AMULE_DAEMON
239 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
240 if (owner->ShowSources()) {
241 theApp->amuledlg->m_transferwnd->downloadlistctrl->AddSource(owner, source, type);
244 #endif
247 void DownloadCtrlRemoveFile(CPartFile* NOT_ON_DAEMON(file))
249 #ifndef AMULE_DAEMON
250 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
251 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveFile(file);
253 #endif
256 void DownloadCtrlRemoveSource(const CUpDownClient* NOT_ON_DAEMON(source), const CPartFile* NOT_ON_DAEMON(owner))
258 #ifndef AMULE_DAEMON
259 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
260 if ((owner == NULL) || owner->ShowSources()) {
261 theApp->amuledlg->m_transferwnd->downloadlistctrl->RemoveSource(source, owner);
264 #endif
267 void DownloadCtrlHideSource(CPartFile* NOT_ON_DAEMON(file))
269 #ifndef AMULE_DAEMON
270 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
271 theApp->amuledlg->m_transferwnd->downloadlistctrl->ShowSources(file, false);
273 #endif
276 void DownloadCtrlSort()
278 #ifndef AMULE_DAEMON
279 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->downloadlistctrl) {
280 theApp->amuledlg->m_transferwnd->downloadlistctrl->SortList();
282 #endif
286 void ClientCtrlAddClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
288 #ifndef AMULE_DAEMON
289 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
290 theApp->amuledlg->m_transferwnd->clientlistctrl->InsertClient(client, type);
292 #endif
295 void ClientCtrlRefreshClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
297 #ifndef AMULE_DAEMON
298 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
299 theApp->amuledlg->m_transferwnd->clientlistctrl->UpdateClient(client, type);
301 #endif
304 void ClientCtrlRemoveClient(CUpDownClient* NOT_ON_DAEMON(client), ViewType NOT_ON_DAEMON(type))
306 #ifndef AMULE_DAEMON
307 if (theApp->amuledlg->m_transferwnd && theApp->amuledlg->m_transferwnd->clientlistctrl) {
308 theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveClient(client, type);
310 #endif
314 void ServerAdd(CServer* NOT_ON_DAEMON(server))
316 #ifndef AMULE_DAEMON
317 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
318 theApp->amuledlg->m_serverwnd->serverlistctrl->AddServer(server);
320 #endif
323 void ServerRemove(CServer* NOT_ON_DAEMON(server))
325 #ifndef AMULE_DAEMON
326 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
327 theApp->amuledlg->m_serverwnd->serverlistctrl->RemoveServer(server);
329 #endif
332 void ServerRemoveDead()
334 if (theApp->serverlist) {
335 theApp->serverlist->RemoveDeadServers();
339 void ServerRemoveAll()
341 #ifndef AMULE_DAEMON
342 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
343 theApp->amuledlg->m_serverwnd->serverlistctrl->DeleteAllItems();
345 #endif
348 void ServerHighlight(CServer* NOT_ON_DAEMON(server), bool NOT_ON_DAEMON(highlight))
350 #ifndef AMULE_DAEMON
351 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
352 theApp->amuledlg->m_serverwnd->serverlistctrl->HighlightServer(server, highlight);
354 #endif
357 void ServerRefresh(CServer* NOT_ON_DAEMON(server))
359 #ifndef AMULE_DAEMON
360 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
361 theApp->amuledlg->m_serverwnd->serverlistctrl->RefreshServer(server);
363 #endif
366 void ServerFreeze()
368 #ifndef AMULE_DAEMON
369 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
370 theApp->amuledlg->m_serverwnd->serverlistctrl->Freeze();
372 #endif
375 void ServerThaw()
377 #ifndef AMULE_DAEMON
378 if (theApp->amuledlg->m_serverwnd && theApp->amuledlg->m_serverwnd->serverlistctrl) {
379 theApp->amuledlg->m_serverwnd->serverlistctrl->Thaw();
381 #endif
384 void ServerUpdateED2KInfo()
386 #ifndef AMULE_DAEMON
387 if (theApp->amuledlg->m_serverwnd) {
388 theApp->amuledlg->m_serverwnd->UpdateED2KInfo();
390 #endif
393 void ServerUpdateKadKInfo()
395 #ifndef AMULE_DAEMON
396 if (theApp->amuledlg->m_serverwnd) {
397 theApp->amuledlg->m_serverwnd->UpdateKadInfo();
399 #endif
403 void SearchCancel()
405 #ifndef AMULE_DAEMON
406 if (theApp->amuledlg->m_searchwnd) {
407 theApp->amuledlg->m_searchwnd->ResetControls();
409 #endif
412 void SearchLocalEnd()
414 #ifndef AMULE_DAEMON
415 if (theApp->amuledlg->m_searchwnd) {
416 theApp->amuledlg->m_searchwnd->LocalSearchEnd();
418 #endif
421 void KadSearchEnd(uint32 NOT_ON_DAEMON(id))
423 #ifndef AMULE_DAEMON
424 if (theApp->amuledlg->m_searchwnd) {
425 theApp->amuledlg->m_searchwnd->KadSearchEnd(id);
427 #endif
430 void Search_Update_Sources(CSearchFile* NOT_ON_DAEMON(result))
432 #ifndef AMULE_DAEMON
433 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
434 theApp->amuledlg->m_searchwnd->UpdateResult(result);
436 #endif
439 void Search_Add_Result(CSearchFile* NOT_ON_DAEMON(result))
441 #ifndef AMULE_DAEMON
442 if (theApp->amuledlg && theApp->amuledlg->m_searchwnd) {
443 theApp->amuledlg->m_searchwnd->AddResult(result);
445 #endif
449 void ChatRefreshFriend(uint32 NOT_ON_DAEMON(lastUsedIP), uint32 NOT_ON_DAEMON(lastUsedPort), wxString NOT_ON_DAEMON(name))
451 #ifndef AMULE_DAEMON
452 if (theApp->amuledlg->m_chatwnd) {
453 theApp->amuledlg->m_chatwnd->RefreshFriend(CMD4Hash(), name, lastUsedIP, lastUsedPort);
455 #endif
458 void ChatConnResult(bool NOT_ON_DAEMON(success), uint64 NOT_ON_DAEMON(id), wxString NOT_ON_DAEMON(message))
460 #ifndef AMULE_DAEMON
461 if (theApp->amuledlg->m_chatwnd) {
462 theApp->amuledlg->m_chatwnd->ConnectionResult(success, message, id);
464 #endif
467 void ChatProcessMsg(uint64 NOT_ON_DAEMON(sender), wxString NOT_ON_DAEMON(message))
469 #ifndef AMULE_DAEMON
470 if (theApp->amuledlg->m_chatwnd) {
471 theApp->amuledlg->m_chatwnd->ProcessMessage(sender, message);
473 #endif
477 void ShowConnState(long NOT_ON_DAEMON(state))
479 #ifndef AMULE_DAEMON
480 #ifdef CLIENT_GUI
481 theApp->m_ConnState = state;
482 #endif
484 theApp->amuledlg->ShowConnectionState();
485 #endif
488 void ShowQueueCount(uint32 NOT_ON_DAEMON(count))
490 #ifndef AMULE_DAEMON
491 if (theApp->amuledlg->m_transferwnd) {
492 theApp->amuledlg->m_transferwnd->ShowQueueCount(count);
494 #endif
497 void ShowUpdateCatTabTitles()
499 #ifndef AMULE_DAEMON
500 if (theApp->amuledlg->m_transferwnd) {
501 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
503 #endif
506 void ShowGUI()
508 #ifndef AMULE_DAEMON
509 theApp->amuledlg->Iconize(false);
510 #endif
514 void CategoryAdded()
516 #ifndef AMULE_DAEMON
517 if (theApp->amuledlg->m_transferwnd) {
518 theApp->amuledlg->m_transferwnd->
519 AddCategory(theApp->glob_prefs->GetCategory(
520 theApp->glob_prefs->GetCatCount()-1));
522 #endif
525 void CategoryUpdate(uint32 NOT_ON_DAEMON(cat))
527 #ifndef AMULE_DAEMON
528 if (theApp->amuledlg->m_transferwnd) {
529 theApp->amuledlg->m_transferwnd->UpdateCategory(cat);
530 theApp->amuledlg->m_transferwnd->downloadlistctrl->Refresh();
531 theApp->amuledlg->m_searchwnd->UpdateCatChoice();
533 #endif
536 void CategoryDelete(uint32 NOT_ON_DAEMON(cat))
538 #ifndef AMULE_DAEMON
539 if (theApp->amuledlg->m_transferwnd) {
540 theApp->amuledlg->m_transferwnd->RemoveCategory(cat);
542 #endif
546 void PartFile_Swap_A4AF(CPartFile* file)
548 if ((file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)) {
549 CPartFile::SourceSet::const_iterator it = file->GetA4AFList().begin();
550 for ( ; it != file->GetA4AFList().end(); ) {
551 CUpDownClient *cur_source = *it++;
553 cur_source->SwapToAnotherFile(true, false, false, file);
558 void PartFile_Swap_A4AF_Auto(CPartFile* file)
560 file->SetA4AFAuto(!file->IsA4AFAuto());
563 void PartFile_Swap_A4AF_Others(CPartFile* file)
565 if ((file->GetStatus(false) == PS_READY) || (file->GetStatus(false) == PS_EMPTY)) {
566 CPartFile::SourceSet::const_iterator it = file->GetSourceList().begin();
567 for( ; it != file->GetSourceList().end(); ) {
568 CUpDownClient* cur_source = *it++;
570 cur_source->SwapToAnotherFile(false, false, false, NULL);
575 void PartFile_Pause(CPartFile* file)
577 file->PauseFile();
580 void PartFile_Resume(CPartFile* file)
582 file->ResumeFile();
583 file->SavePartFile();
586 void PartFile_Stop(CPartFile* file)
588 file->StopFile();
591 void PartFile_PrioAuto(CPartFile* file, bool val)
593 file->SetAutoDownPriority(val);
596 void PartFile_PrioSet(CPartFile* file, uint8 newDownPriority, bool bSave)
598 file->SetDownPriority(newDownPriority, bSave);
601 void PartFile_Delete(CPartFile* file)
603 file->Delete();
606 void PartFile_SetCat(CPartFile* file, uint32 val)
608 file->SetCategory(val);
612 void KnownFile_Up_Prio_Set(CKnownFile* file, uint8 val)
614 file->SetAutoUpPriority(false);
615 file->SetUpPriority(val);
618 void KnownFile_Up_Prio_Auto(CKnownFile* file)
620 file->SetAutoUpPriority(true);
621 file->UpdateAutoUpPriority();
624 void KnownFile_Comment_Set(CKnownFile* file, wxString comment)
626 file->SetFileComment(comment);
630 void Download_Set_Cat_Prio(uint8 cat, uint8 newprio)
632 theApp->downloadqueue->SetCatPrio(cat, newprio);
635 void Download_Set_Cat_Status(uint8 cat, int newstatus)
637 theApp->downloadqueue->SetCatStatus(cat, newstatus);
640 #endif // #ifdef CLIENT_GUI
642 // File_checked_for_headers