/
ApplicationMessenger.cpp
1212 lines (1038 loc) · 31.8 KB
/
ApplicationMessenger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "system.h"
#include "ApplicationMessenger.h"
#include "Application.h"
#include "PlayListPlayer.h"
#include "Util.h"
#ifdef HAS_PYTHON
#include "interfaces/python/XBPython.h"
#endif
#include "pictures/GUIWindowSlideShow.h"
#include "interfaces/Builtins.h"
#include "network/Network.h"
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "guilib/GUIWindowManager.h"
#include "settings/Settings.h"
#include "settings/GUISettings.h"
#include "FileItem.h"
#include "guilib/GUIDialog.h"
#include "GUIInfoManager.h"
#include "utils/Splash.h"
#include "cores/VideoRenderers/RenderManager.h"
#include "powermanagement/PowerManager.h"
#ifdef _WIN32
#include "WIN32Util.h"
#define CHalManager CWIN32Util
#elif defined(TARGET_DARWIN)
#include "CocoaInterface.h"
#endif
#include "storage/MediaManager.h"
#include "guilib/LocalizeStrings.h"
#include "threads/SingleLock.h"
#ifdef HAS_PYTHON
#include "interfaces/python/xbmcmodule/GUIPythonWindowDialog.h"
#include "interfaces/python/xbmcmodule/GUIPythonWindowXMLDialog.h"
#endif
#ifdef HAS_HTTPAPI
#include "interfaces/http-api/XBMChttp.h"
#endif
#include "playlists/PlayList.h"
#include "FileItem.h"
#include "ThumbLoader.h"
using namespace std;
CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay) : CThread("CDelayedMessage")
{
m_msg.dwMessage = msg.dwMessage;
m_msg.dwParam1 = msg.dwParam1;
m_msg.dwParam2 = msg.dwParam2;
m_msg.waitEvent = msg.waitEvent;
m_msg.lpVoid = msg.lpVoid;
m_msg.strParam = msg.strParam;
m_msg.params = msg.params;
m_delay = delay;
}
void CDelayedMessage::Process()
{
Sleep(m_delay);
if (!m_bStop)
CApplicationMessenger::Get().SendMessage(m_msg, false);
}
CApplicationMessenger& CApplicationMessenger::Get()
{
static CApplicationMessenger s_messenger;
return s_messenger;
}
CApplicationMessenger::CApplicationMessenger()
{
}
CApplicationMessenger::~CApplicationMessenger()
{
Cleanup();
}
void CApplicationMessenger::Cleanup()
{
CSingleLock lock (m_critSection);
while (m_vecMessages.size() > 0)
{
ThreadMessage* pMsg = m_vecMessages.front();
if (pMsg->waitEvent)
pMsg->waitEvent->Set();
delete pMsg;
m_vecMessages.pop();
}
while (m_vecWindowMessages.size() > 0)
{
ThreadMessage* pMsg = m_vecWindowMessages.front();
if (pMsg->waitEvent)
pMsg->waitEvent->Set();
delete pMsg;
m_vecWindowMessages.pop();
}
}
void CApplicationMessenger::SendMessage(ThreadMessage& message, bool wait)
{
message.waitEvent.reset();
boost::shared_ptr<CEvent> waitEvent;
if (wait)
{ // check that we're not being called from our application thread, else we'll be waiting
// forever!
if (!g_application.IsCurrentThread())
{
message.waitEvent.reset(new CEvent(true));
waitEvent = message.waitEvent;
}
else
{
//OutputDebugString("Attempting to wait on a SendMessage() from our application thread will cause lockup!\n");
//OutputDebugString("Sending immediately\n");
ProcessMessage(&message);
return;
}
}
CSingleLock lock (m_critSection);
if (g_application.m_bStop)
{
if (message.waitEvent)
message.waitEvent.reset();
return;
}
ThreadMessage* msg = new ThreadMessage();
msg->dwMessage = message.dwMessage;
msg->dwParam1 = message.dwParam1;
msg->dwParam2 = message.dwParam2;
msg->waitEvent = message.waitEvent;
msg->lpVoid = message.lpVoid;
msg->strParam = message.strParam;
msg->params = message.params;
if (msg->dwMessage == TMSG_DIALOG_DOMODAL)
m_vecWindowMessages.push(msg);
else
m_vecMessages.push(msg);
lock.Leave(); // this releases the lock on the vec of messages and
// allows the ProcessMessage to execute and therefore
// delete the message itself. Therefore any accesss
// of the message itself after this point consittutes
// a race condition (yarc - "yet another race condition")
//
if (waitEvent) // ... it just so happens we have a spare reference to the
// waitEvent ... just for such contingencies :)
{
// ensure the thread doesn't hold the graphics lock
CSingleExit exit(g_graphicsContext);
waitEvent->Wait();
}
}
void CApplicationMessenger::ProcessMessages()
{
// process threadmessages
CSingleLock lock (m_critSection);
while (m_vecMessages.size() > 0)
{
ThreadMessage* pMsg = m_vecMessages.front();
//first remove the message from the queue, else the message could be processed more then once
m_vecMessages.pop();
//Leave here as the message might make another
//thread call processmessages or sendmessage
boost::shared_ptr<CEvent> waitEvent = pMsg->waitEvent;
lock.Leave(); // <- see the large comment in SendMessage ^
ProcessMessage(pMsg);
if (waitEvent)
waitEvent->Set();
delete pMsg;
lock.Enter();
}
}
void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)
{
switch (pMsg->dwMessage)
{
case TMSG_SHUTDOWN:
{
switch (g_guiSettings.GetInt("powermanagement.shutdownstate"))
{
case POWERSTATE_SHUTDOWN:
Powerdown();
break;
case POWERSTATE_SUSPEND:
Suspend();
break;
case POWERSTATE_HIBERNATE:
Hibernate();
break;
case POWERSTATE_QUIT:
Quit();
break;
case POWERSTATE_MINIMIZE:
Minimize();
break;
case TMSG_RENDERER_FLUSH:
g_renderManager.Flush();
break;
}
}
break;
case TMSG_POWERDOWN:
{
g_application.Stop(EXITCODE_POWERDOWN);
g_powerManager.Powerdown();
}
break;
case TMSG_QUIT:
{
g_application.Stop(EXITCODE_QUIT);
}
break;
case TMSG_HIBERNATE:
{
g_powerManager.Hibernate();
}
break;
case TMSG_SUSPEND:
{
g_powerManager.Suspend();
}
break;
case TMSG_RESTART:
case TMSG_RESET:
{
g_application.Stop(EXITCODE_REBOOT);
g_powerManager.Reboot();
}
break;
case TMSG_RESTARTAPP:
{
#ifdef _WIN32
g_application.Stop(EXITCODE_RESTARTAPP);
#endif
// TODO
}
break;
case TMSG_MEDIA_PLAY:
{
// first check if we were called from the PlayFile() function
if (pMsg->lpVoid && pMsg->dwParam2 == 0)
{
CFileItem *item = (CFileItem *)pMsg->lpVoid;
g_application.PlayFile(*item, pMsg->dwParam1 != 0);
delete item;
return;
}
// restore to previous window if needed
if (g_windowManager.GetActiveWindow() == WINDOW_SLIDESHOW ||
g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_VIDEO ||
g_windowManager.GetActiveWindow() == WINDOW_VISUALISATION)
g_windowManager.PreviousWindow();
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
//g_application.StopPlaying();
// play file
if(pMsg->lpVoid)
{
CFileItemList *list = (CFileItemList *)pMsg->lpVoid;
if (list->Size() > 0)
{
int playlist = PLAYLIST_MUSIC;
for (int i = 0; i < list->Size(); i++)
{
if ((*list)[i]->IsVideo())
{
playlist = PLAYLIST_VIDEO;
break;
}
}
g_playlistPlayer.ClearPlaylist(playlist);
g_playlistPlayer.SetCurrentPlaylist(playlist);
//For single item lists try PlayMedia. This covers some more cases where a playlist is not appropriate
//It will fall through to PlayFile
if (list->Size() == 1 && !(*list)[0]->IsPlayList())
g_application.PlayMedia(*((*list)[0]), playlist);
else
{
// Handle "shuffled" option if present
if (list->HasProperty("shuffled") && list->GetProperty("shuffled").isBoolean())
g_playlistPlayer.SetShuffle(playlist, list->GetProperty("shuffled").asBoolean(), false);
// Handle "repeat" option if present
if (list->HasProperty("repeat") && list->GetProperty("repeat").isInteger())
g_playlistPlayer.SetRepeat(playlist, (PLAYLIST::REPEAT_STATE)list->GetProperty("repeat").asInteger(), false);
g_playlistPlayer.Add(playlist, (*list));
g_playlistPlayer.Play(pMsg->dwParam1);
}
}
delete list;
}
else if (pMsg->dwParam1 == PLAYLIST_MUSIC || pMsg->dwParam1 == PLAYLIST_VIDEO)
{
if (g_playlistPlayer.GetCurrentPlaylist() != (int)pMsg->dwParam1)
g_playlistPlayer.SetCurrentPlaylist(pMsg->dwParam1);
PlayListPlayerPlay(pMsg->dwParam2);
}
}
break;
case TMSG_MEDIA_RESTART:
g_application.Restart(true);
break;
case TMSG_PICTURE_SHOW:
{
CGUIWindowSlideShow *pSlideShow = (CGUIWindowSlideShow *)g_windowManager.GetWindow(WINDOW_SLIDESHOW);
if (!pSlideShow) return ;
// stop playing file
if (g_application.IsPlayingVideo()) g_application.StopPlaying();
if (g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_VIDEO)
g_windowManager.PreviousWindow();
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
g_graphicsContext.Lock();
if (g_windowManager.GetActiveWindow() != WINDOW_SLIDESHOW)
g_windowManager.ActivateWindow(WINDOW_SLIDESHOW);
if (URIUtils::IsZIP(pMsg->strParam) || URIUtils::IsRAR(pMsg->strParam)) // actually a cbz/cbr
{
CFileItemList items;
CStdString strPath;
if (URIUtils::IsZIP(pMsg->strParam))
URIUtils::CreateArchivePath(strPath, "zip", pMsg->strParam.c_str(), "");
else
URIUtils::CreateArchivePath(strPath, "rar", pMsg->strParam.c_str(), "");
CUtil::GetRecursiveListing(strPath, items, g_settings.m_pictureExtensions);
if (items.Size() > 0)
{
pSlideShow->Reset();
for (int i=0;i<items.Size();++i)
{
pSlideShow->Add(items[i].get());
}
pSlideShow->Select(items[0]->GetPath());
}
}
else
{
CFileItem item(pMsg->strParam, false);
pSlideShow->Reset();
pSlideShow->Add(&item);
pSlideShow->Select(pMsg->strParam);
}
g_graphicsContext.Unlock();
}
break;
case TMSG_SLIDESHOW_SCREENSAVER:
case TMSG_PICTURE_SLIDESHOW:
{
CGUIWindowSlideShow *pSlideShow = (CGUIWindowSlideShow *)g_windowManager.GetWindow(WINDOW_SLIDESHOW);
if (!pSlideShow) return ;
if (g_application.IsPlayingVideo())
g_application.StopPlaying();
g_graphicsContext.Lock();
pSlideShow->Reset();
CFileItemList items;
CStdString strPath = pMsg->strParam;
CStdString extensions = g_settings.m_pictureExtensions;
if (pMsg->dwParam1)
extensions += "|.tbn";
CUtil::GetRecursiveListing(strPath, items, extensions);
if (items.Size() > 0)
{
for (int i=0;i<items.Size();++i)
pSlideShow->Add(items[i].get());
pSlideShow->StartSlideShow(pMsg->dwMessage == TMSG_SLIDESHOW_SCREENSAVER); //Start the slideshow!
}
if (pMsg->dwMessage == TMSG_SLIDESHOW_SCREENSAVER)
pSlideShow->Shuffle();
if (g_windowManager.GetActiveWindow() != WINDOW_SLIDESHOW)
{
if(items.Size() == 0)
{
g_guiSettings.SetString("screensaver.mode", "screensaver.xbmc.builtin.dim");
g_application.ActivateScreenSaver();
}
else
g_windowManager.ActivateWindow(WINDOW_SLIDESHOW);
}
g_graphicsContext.Unlock();
}
break;
case TMSG_SETLANGUAGE:
g_guiSettings.SetLanguage(pMsg->strParam);
break;
case TMSG_MEDIA_STOP:
{
// restore to previous window if needed
if (g_windowManager.GetActiveWindow() == WINDOW_SLIDESHOW ||
g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_VIDEO ||
g_windowManager.GetActiveWindow() == WINDOW_VISUALISATION)
g_windowManager.PreviousWindow();
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
// stop playing file
if (g_application.IsPlaying()) g_application.StopPlaying();
}
break;
case TMSG_MEDIA_PAUSE:
if (g_application.m_pPlayer)
{
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
g_application.m_pPlayer->Pause();
}
break;
case TMSG_MEDIA_UNPAUSE:
if (g_application.IsPaused())
{
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
g_application.m_pPlayer->Pause();
}
break;
case TMSG_SWITCHTOFULLSCREEN:
if( g_windowManager.GetActiveWindow() != WINDOW_FULLSCREEN_VIDEO )
g_application.SwitchToFullScreen();
break;
case TMSG_TOGGLEFULLSCREEN:
g_graphicsContext.Lock();
g_graphicsContext.ToggleFullScreenRoot();
g_graphicsContext.Unlock();
break;
case TMSG_MINIMIZE:
g_application.Minimize();
break;
case TMSG_EXECUTE_OS:
#if defined( _LINUX) && !defined(TARGET_DARWIN)
CUtil::RunCommandLine(pMsg->strParam.c_str(), (pMsg->dwParam1 == 1));
#elif defined(_WIN32)
CWIN32Util::XBMCShellExecute(pMsg->strParam.c_str(), (pMsg->dwParam1 == 1));
#endif
break;
case TMSG_HTTPAPI:
{
#ifdef HAS_HTTPAPI
if (!m_pXbmcHttp)
{
m_pXbmcHttp = new CXbmcHttp();
}
switch (m_pXbmcHttp->xbmcCommand(pMsg->strParam))
{
case 1:
Restart();
break;
case 2:
Shutdown();
break;
case 3:
Quit();
break;
case 4:
Reset();
break;
case 5:
RestartApp();
break;
}
#endif
}
break;
case TMSG_EXECUTE_SCRIPT:
#ifdef HAS_PYTHON
g_pythonParser.evalFile(pMsg->strParam.c_str(),ADDON::AddonPtr());
#endif
break;
case TMSG_EXECUTE_BUILT_IN:
CBuiltins::Execute(pMsg->strParam.c_str());
break;
case TMSG_PLAYLISTPLAYER_PLAY:
if (pMsg->dwParam1 != (DWORD) -1)
g_playlistPlayer.Play(pMsg->dwParam1);
else
g_playlistPlayer.Play();
break;
case TMSG_PLAYLISTPLAYER_PLAY_SONG_ID:
if (pMsg->dwParam1 != (DWORD) -1)
{
bool *result = (bool*)pMsg->lpVoid;
*result = g_playlistPlayer.PlaySongId(pMsg->dwParam1);
}
else
g_playlistPlayer.Play();
break;
case TMSG_PLAYLISTPLAYER_NEXT:
g_playlistPlayer.PlayNext();
break;
case TMSG_PLAYLISTPLAYER_PREV:
g_playlistPlayer.PlayPrevious();
break;
case TMSG_PLAYLISTPLAYER_ADD:
if(pMsg->lpVoid)
{
CFileItemList *list = (CFileItemList *)pMsg->lpVoid;
g_playlistPlayer.Add(pMsg->dwParam1, (*list));
delete list;
}
break;
case TMSG_PLAYLISTPLAYER_INSERT:
if (pMsg->lpVoid)
{
CFileItemList *list = (CFileItemList *)pMsg->lpVoid;
g_playlistPlayer.Insert(pMsg->dwParam1, (*list), pMsg->dwParam2);
delete list;
}
break;
case TMSG_PLAYLISTPLAYER_REMOVE:
if (pMsg->dwParam1 != (DWORD) -1)
g_playlistPlayer.Remove(pMsg->dwParam1,pMsg->dwParam2);
break;
case TMSG_PLAYLISTPLAYER_CLEAR:
g_playlistPlayer.ClearPlaylist(pMsg->dwParam1);
break;
case TMSG_PLAYLISTPLAYER_SHUFFLE:
g_playlistPlayer.SetShuffle(pMsg->dwParam1, pMsg->dwParam2 > 0);
break;
case TMSG_PLAYLISTPLAYER_REPEAT:
g_playlistPlayer.SetRepeat(pMsg->dwParam1, (PLAYLIST::REPEAT_STATE)pMsg->dwParam2);
break;
case TMSG_PLAYLISTPLAYER_GET_ITEMS:
if (pMsg->lpVoid)
{
PLAYLIST::CPlayList playlist = g_playlistPlayer.GetPlaylist(pMsg->dwParam1);
CFileItemList *list = (CFileItemList *)pMsg->lpVoid;
for (int i = 0; i < playlist.size(); i++)
list->Add(CFileItemPtr(new CFileItem(*playlist[i])));
}
break;
case TMSG_PLAYLISTPLAYER_SWAP:
if (pMsg->lpVoid)
{
vector<int> *indexes = (vector<int> *)pMsg->lpVoid;
if (indexes->size() == 2)
g_playlistPlayer.Swap(pMsg->dwParam1, indexes->at(0), indexes->at(1));
delete indexes;
}
break;
// Window messages below here...
case TMSG_DIALOG_DOMODAL: //doModel of window
{
CGUIDialog* pDialog = (CGUIDialog*)g_windowManager.GetWindow(pMsg->dwParam1);
if (!pDialog) return ;
pDialog->DoModal();
}
break;
case TMSG_NETWORKMESSAGE:
{
g_application.getNetwork().NetworkMessage((CNetwork::EMESSAGE)pMsg->dwParam1, (int)pMsg->dwParam2);
}
break;
case TMSG_GUI_DO_MODAL:
{
CGUIDialog *pDialog = (CGUIDialog *)pMsg->lpVoid;
if (pDialog)
pDialog->DoModal((int)pMsg->dwParam1, pMsg->strParam);
}
break;
case TMSG_GUI_SHOW:
{
CGUIDialog *pDialog = (CGUIDialog *)pMsg->lpVoid;
if (pDialog)
pDialog->Show();
}
break;
case TMSG_GUI_WINDOW_CLOSE:
{
CGUIWindow *window = (CGUIWindow *)pMsg->lpVoid;
if (window)
window->Close(pMsg->dwParam2 & 0x1 ? true : false, pMsg->dwParam1, pMsg->dwParam2 & 0x2 ? true : false);
}
break;
case TMSG_GUI_ACTIVATE_WINDOW:
{
g_windowManager.ActivateWindow(pMsg->dwParam1, pMsg->params, pMsg->dwParam2 > 0);
}
break;
case TMSG_GUI_PYTHON_DIALOG:
{
if (pMsg->lpVoid)
{ // TODO: This is ugly - really these python dialogs should just be normal XBMC dialogs
if (pMsg->dwParam1)
((CGUIPythonWindowXMLDialog *)pMsg->lpVoid)->Show_Internal(pMsg->dwParam2 > 0);
else
((CGUIPythonWindowDialog *)pMsg->lpVoid)->Show_Internal(pMsg->dwParam2 > 0);
}
}
break;
case TMSG_GUI_ACTION:
{
if (pMsg->lpVoid)
{
CAction *action = (CAction *)pMsg->lpVoid;
if (pMsg->dwParam1 == WINDOW_INVALID)
g_application.OnAction(*action);
else
{
CGUIWindow *pWindow = g_windowManager.GetWindow(pMsg->dwParam1);
if (pWindow)
pWindow->OnAction(*action);
else
CLog::Log(LOGWARNING, "Failed to get window with ID %i to send an action to", pMsg->dwParam1);
}
delete action;
}
}
break;
case TMSG_GUI_MESSAGE:
{
if (pMsg->lpVoid)
{
CGUIMessage *message = (CGUIMessage *)pMsg->lpVoid;
g_windowManager.SendMessage(*message, pMsg->dwParam1);
delete message;
}
}
break;
case TMSG_GUI_INFOLABEL:
{
if (pMsg->lpVoid)
{
vector<CStdString> *infoLabels = (vector<CStdString> *)pMsg->lpVoid;
for (unsigned int i = 0; i < pMsg->params.size(); i++)
infoLabels->push_back(g_infoManager.GetLabel(g_infoManager.TranslateString(pMsg->params[i])));
}
}
break;
case TMSG_GUI_INFOBOOL:
{
if (pMsg->lpVoid)
{
vector<bool> *infoLabels = (vector<bool> *)pMsg->lpVoid;
for (unsigned int i = 0; i < pMsg->params.size(); i++)
infoLabels->push_back(g_infoManager.EvaluateBool(pMsg->params[i]));
}
}
break;
case TMSG_CALLBACK:
{
ThreadMessageCallback *callback = (ThreadMessageCallback*)pMsg->lpVoid;
callback->callback(callback->userptr);
}
break;
case TMSG_VOLUME_SHOW:
{
CAction action((int)pMsg->dwParam1);
g_application.ShowVolumeBar(&action);
}
break;
case TMSG_SPLASH_MESSAGE:
{
if (g_application.GetSplash())
g_application.GetSplash()->Show(pMsg->strParam);
}
break;
}
}
void CApplicationMessenger::ProcessWindowMessages()
{
CSingleLock lock (m_critSection);
//message type is window, process window messages
while (m_vecWindowMessages.size() > 0)
{
ThreadMessage* pMsg = m_vecWindowMessages.front();
//first remove the message from the queue, else the message could be processed more then once
m_vecWindowMessages.pop();
// leave here in case we make more thread messages from this one
boost::shared_ptr<CEvent> waitEvent = pMsg->waitEvent;
lock.Leave(); // <- see the large comment in SendMessage ^
ProcessMessage(pMsg);
if (waitEvent)
waitEvent->Set();
delete pMsg;
lock.Enter();
}
}
int CApplicationMessenger::SetResponse(CStdString response)
{
CSingleLock lock (m_critBuffer);
bufferResponse=response;
lock.Leave();
return 0;
}
CStdString CApplicationMessenger::GetResponse()
{
CStdString tmp;
CSingleLock lock (m_critBuffer);
tmp=bufferResponse;
lock.Leave();
return tmp;
}
void CApplicationMessenger::HttpApi(string cmd, bool wait)
{
SetResponse("");
ThreadMessage tMsg = {TMSG_HTTPAPI};
tMsg.strParam = cmd;
SendMessage(tMsg, wait);
}
void CApplicationMessenger::ExecBuiltIn(const CStdString &command, bool wait)
{
ThreadMessage tMsg = {TMSG_EXECUTE_BUILT_IN};
tMsg.strParam = command;
SendMessage(tMsg, wait);
}
void CApplicationMessenger::MediaPlay(string filename)
{
CFileItem item(filename, false);
if (item.IsAudio())
CMusicThumbLoader::FillThumb(item);
else
CVideoThumbLoader::FillThumb(item);
item.FillInDefaultIcon();
MediaPlay(item);
}
void CApplicationMessenger::MediaPlay(const CFileItem &item)
{
CFileItemList list;
list.Add(CFileItemPtr(new CFileItem(item)));
MediaPlay(list);
}
void CApplicationMessenger::MediaPlay(const CFileItemList &list, int song)
{
ThreadMessage tMsg = {TMSG_MEDIA_PLAY};
CFileItemList* listcopy = new CFileItemList();
listcopy->Copy(list);
tMsg.lpVoid = (void*)listcopy;
tMsg.dwParam1 = song;
tMsg.dwParam2 = 1;
SendMessage(tMsg, true);
}
void CApplicationMessenger::MediaPlay(int playlistid, int song /* = -1 */)
{
ThreadMessage tMsg = {TMSG_MEDIA_PLAY};
tMsg.lpVoid = NULL;
tMsg.dwParam1 = playlistid;
tMsg.dwParam2 = song;
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayFile(const CFileItem &item, bool bRestart /*= false*/)
{
ThreadMessage tMsg = {TMSG_MEDIA_PLAY};
CFileItem *pItem = new CFileItem(item);
tMsg.lpVoid = (void *)pItem;
tMsg.dwParam1 = bRestart ? 1 : 0;
tMsg.dwParam2 = 0;
SendMessage(tMsg, false);
}
void CApplicationMessenger::MediaStop()
{
ThreadMessage tMsg = {TMSG_MEDIA_STOP};
SendMessage(tMsg, true);
}
void CApplicationMessenger::MediaPause()
{
ThreadMessage tMsg = {TMSG_MEDIA_PAUSE};
SendMessage(tMsg, true);
}
void CApplicationMessenger::MediaRestart(bool bWait)
{
ThreadMessage tMsg = {TMSG_MEDIA_RESTART};
SendMessage(tMsg, bWait);
}
void CApplicationMessenger::PlayListPlayerPlay()
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PLAY, (DWORD) -1};
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerPlay(int iSong)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PLAY, iSong};
SendMessage(tMsg, true);
}
bool CApplicationMessenger::PlayListPlayerPlaySongId(int songId)
{
bool returnState;
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PLAY_SONG_ID, songId};
tMsg.lpVoid = (void *)&returnState;
SendMessage(tMsg, true);
return returnState;
}
void CApplicationMessenger::PlayListPlayerNext()
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_NEXT};
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerPrevious()
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_PREV};
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerAdd(int playlist, const CFileItem &item)
{
CFileItemList list;
list.Add(CFileItemPtr(new CFileItem(item)));
PlayListPlayerAdd(playlist, list);
}
void CApplicationMessenger::PlayListPlayerAdd(int playlist, const CFileItemList &list)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_ADD};
CFileItemList* listcopy = new CFileItemList();
listcopy->Copy(list);
tMsg.lpVoid = (void*)listcopy;
tMsg.dwParam1 = playlist;
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerInsert(int playlist, const CFileItem &item, int index)
{
CFileItemList list;
list.Add(CFileItemPtr(new CFileItem(item)));
PlayListPlayerInsert(playlist, list, index);
}
void CApplicationMessenger::PlayListPlayerInsert(int playlist, const CFileItemList &list, int index)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_INSERT};
CFileItemList* listcopy = new CFileItemList();
listcopy->Copy(list);
tMsg.lpVoid = (void *)listcopy;
tMsg.dwParam1 = playlist;
tMsg.dwParam2 = index;
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerRemove(int playlist, int position)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_REMOVE, playlist, position};
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerClear(int playlist)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_CLEAR};
tMsg.dwParam1 = playlist;
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerShuffle(int playlist, bool shuffle)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_SHUFFLE};
tMsg.dwParam1 = playlist;
tMsg.dwParam2 = shuffle ? 1 : 0;
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerGetItems(int playlist, CFileItemList &list)
{
ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_GET_ITEMS};
tMsg.dwParam1 = playlist;
tMsg.lpVoid = (void *)&list;
SendMessage(tMsg, true);
}
void CApplicationMessenger::PlayListPlayerSwap(int playlist, int indexItem1, int indexItem2)
{