forked from bartsidee/boxee
/
ItemLoader.cpp
729 lines (621 loc) · 21.2 KB
/
ItemLoader.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
#include "ItemLoader.h"
#include "FileSystem/Directory.h"
#include "GUIWindowManager.h"
#include "BoxeeFeedItemsLoader.h"
#include "BoxeeServerItemsLoader.h"
#include "PictureThumbLoader.h"
#include "FileSystem/DirectoryCache.h"
#include "ThumbLoader.h"
#include "utils/SingleLock.h"
#include "Util.h"
#include "cores/dvdplayer/DVDFileInfo.h"
#include "Application.h"
#include "MetadataResolverVideo.h"
#include "FileSystem/File.h"
#include "FileSystem/FileCurl.h"
#include "VideoDatabase.h"
#include "lib/libBoxee/boxee.h"
#include "utils/TimeUtils.h"
#include "BoxeeUtils.h"
#define NUM_ITEM_LOADER_THREADS 5
#define NUM_DIRECTORY_LOADER_THREADS 5
#ifdef HAS_EMBEDDED
#define NUM_VIDEO_ITEM_LOADER_THREAD 2
#endif
using namespace DIRECTORY;
using namespace XFILE;
CGetDirectoryJob::CGetDirectoryJob(const CStdString& strPath, int iWindowId, int iControlId, IItemLoaderCallback* pCallback) : BXBGJob("CGetDirectoryJob")
{
m_pCallback = pCallback;
m_strPath = strPath;
m_iWindowId = iWindowId;
m_iControlId = iControlId;
m_iSortMethod = SORT_METHOD_NONE;
m_iSortOrder = SORT_ORDER_NONE;
m_iSelectedItem = -1;
}
CGetDirectoryJob::CGetDirectoryJob(const CStdString& strPath, int iWindowId, int iControlId, IItemLoaderCallback* pCallback,
SORT_METHOD iSortMethod, SORT_ORDER iSortOrder, int iSelectedItem) : BXBGJob("CGetDirectoryJob")
{
m_pCallback = pCallback;
m_strPath = strPath;
m_iWindowId = iWindowId;
m_iControlId = iControlId;
m_iSortMethod = iSortMethod;
m_iSortOrder = iSortOrder;
m_iSelectedItem = iSelectedItem;
}
CGetDirectoryJob::~CGetDirectoryJob()
{
}
void CGetDirectoryJob::DoWork()
{
CFileItemList items;
CLog::Log(LOGDEBUG,"CGetDirectoryJob::DoWork, NEWUI, loading directory, path = %s", m_strPath.c_str());
bool bResult;
items.SetProperty("dontUseGuestCredentials",true);
if (m_pItem)
{
bResult = DIRECTORY::CDirectory::GetDirectory(m_pItem.get(), items);
}
else
{
bResult = DIRECTORY::CDirectory::GetDirectory(m_strPath, items, "", true, true);
}
CLog::Log(LOGDEBUG,"CGetDirectoryJob::DoWork, NEWUI, done loading directory, bResult = %d", bResult);
if (bResult || items.GetPropertyBOOL("getcredentials"))
{
items.SetProperty("windowId", m_iWindowId);
items.SetProperty("controlId", m_iControlId);
items.SetProperty("selectedItem", m_iSelectedItem);
items.SetProperty("requestId", GetId());
items.m_strPath = m_strPath;
// If the original item has background image copy it to the items
if (m_pItem && m_pItem->HasProperty("BrowseBackgroundImage") && !items.HasProperty("BrowseBackgroundImage"))
items.SetProperty("BrowseBackgroundImage", m_pItem->GetProperty("BrowseBackgroundImage").c_str());
if (items.HasProperty("BrowseBackgroundImage"))
{
CStdString strImagePath = items.GetProperty("BrowseBackgroundImage");
if (!CUtil::IsHD(strImagePath))
{
CStdString cacheImagePath = CFileItem::GetCachedThumb(strImagePath,g_settings.GetVideoFanartFolder());
items.SetProperty("BrowseBackgroundImage", cacheImagePath);
CFileCurl http;
if (!http.Download(strImagePath,cacheImagePath))
items.ClearProperty("BrowseBackgroundImage"); // failed. no image
}
}
items.Sort(m_iSortMethod,m_iSortOrder);
m_pCallback->ItemsLoaded(items);
}
else
{
if (items.HasProperty("NotErrorDontShowErrorDialog"))
{
CLog::Log(LOGDEBUG,"CGetDirectoryJob::DoWork, NEWUI, No Error, path = %s", m_strPath.c_str());
m_pCallback->LoadFailed(m_iWindowId, m_iControlId, false);
}
else
{
CLog::Log(LOGDEBUG,"CGetDirectoryJob::DoWork, NEWUI, could not load directory, path = %s", m_strPath.c_str());
m_pCallback->LoadFailed(m_iWindowId, m_iControlId);
}
}
}
bool CGetDirectoryJob::Equals(const BXBGJob& other) const
{
try
{
const CGetDirectoryJob& dcast_other = dynamic_cast<const CGetDirectoryJob&>(other);
if (m_strPath == dcast_other.m_strPath && m_iWindowId == dcast_other.m_iWindowId &&
m_iControlId == dcast_other.m_iControlId && m_iSortMethod == dcast_other.m_iSortMethod &&
m_iSortOrder == dcast_other.m_iSortOrder)
{
return true;
}
else
{
return false;
}
}
catch (const std::bad_cast& e)
{
CLog::Log(LOGERROR,"Bad Casting Exception: %s",e.what());
}
return false;
}
CLoadFileItemJob::CLoadFileItemJob(CFileItemPtr pItem, IBackgroundLoaderObserver* pCallback) : BXBGJob("CLoadFileItemJob")
{
m_pCallback = pCallback;
m_pItem = pItem;
}
CLoadFileItemJob::~CLoadFileItemJob()
{
}
void CLoadFileItemJob::DoWork()
{
if (!CBackgroundLoaderFactory::RunBackgroundLoader(m_pItem, true))
{
// In case load has failed mark the item accordingly
m_pItem->SetProperty("LoadFailed",true);
}
m_pCallback->OnItemLoaded(m_pItem.get());
}
CLoadMetadataJob::CLoadMetadataJob(CFileItemPtr pItem, IBackgroundLoaderObserver* pCallback) : BXBGJob("CLoadMetadataJob")
{
m_pCallback = pCallback;
m_pItem = pItem;
}
CLoadMetadataJob::~CLoadMetadataJob()
{
}
void CLoadMetadataJob::DoWork()
{
if ((m_pItem->IsHD() || m_pItem->IsSmb()) && !m_pItem->m_bIsFolder && !m_pItem->m_bIsShareOrDrive &&
!m_pItem->m_strPath.IsEmpty() && !m_pItem->GetPropertyBOOL("MetaDataExtracted") &&
g_application.IsPathAvailable(m_pItem->m_strPath), false)
{
CDVDFileInfo::GetFileMetaData(m_pItem->m_strPath, m_pItem.get());
m_pItem->SetProperty("MetaDataExtracted",true);
}
m_pCallback->OnItemLoaded(m_pItem.get());
}
CLoadBackgroundImageJob::CLoadBackgroundImageJob(int windowId, const CStdString& strImagePath): BXBGJob("CLoadBackgroundImageJob")
{
m_windowId = windowId;
m_strImagePath = strImagePath;
}
CLoadBackgroundImageJob::~CLoadBackgroundImageJob()
{
}
void CLoadBackgroundImageJob::DoWork()
{
if (!CUtil::IsHD(m_strImagePath))
{
CStdString cacheImagePath = CFileItem::GetCachedThumb(m_strImagePath, g_settings.GetVideoFanartFolder());
CFileCurl http;
if (!http.Download(m_strImagePath, cacheImagePath))
{
return;
}
else
{
m_strImagePath = cacheImagePath;
}
}
CGUIMessage msg(GUI_MSG_BG_PICTURE, m_windowId, 0);
msg.SetStringParam(m_strImagePath);
g_windowManager.SendThreadMessage(msg, m_windowId);
}
bool CBackgroundLoaderFactory::RunBackgroundLoader(CFileItemPtr pItem, bool bCanBlock)
{
bool result = false;
bool bIsPlayableFolder = false;
if(pItem->m_bIsFolder)
{
bIsPlayableFolder = BOXEE::Boxee::GetInstance().GetMetadataEngine().IsPlayableFolder(pItem->m_strPath);
}
if (pItem->GetPropertyBOOL("ishistory"))
{
CPictureThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->GetPropertyBOOL("IsFeedItem"))
{
CBoxeeFeedItemsLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->GetPropertyBOOL("IsBoxeeServerItem"))
{
CBoxeeServerItemsLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->IsRSS())
{
CPictureThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->GetPropertyBOOL("IsFriend"))
{
CPictureThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->IsAudio() || pItem->GetPropertyBOOL("IsAlbum") || (pItem->GetPropertyBOOL("IsGroup") && pItem->GetProperty("grouptype") == "music"))
{
CLog::Log(LOGDEBUG,"CBackgroundLoaderFactory::RunBackgroundLoader, run music thumb loader on item label = %s, path = %s (musicthumb)",
pItem->GetLabel().c_str(), pItem->m_strPath.c_str());
CMusicThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->GetPropertyBOOL("IsArtist"))
{
CLog::Log(LOGDEBUG,"CBackgroundLoaderFactory::RunBackgroundLoader, run picture thumb loader on artist item %s (musicthumb)", pItem->m_strPath.c_str());
CPictureThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (bIsPlayableFolder || pItem->IsVideo() || (pItem->GetPropertyBOOL("IsGroup") && pItem->GetProperty("grouptype") == "video") || pItem->GetPropertyBOOL("isvideo") || pItem->GetProperty("isvideo") == "true")
{
CVideoThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else if (pItem->IsPicture())
{
CPictureThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
else {
CPictureThumbLoader loader;
result = loader.LoadItem(pItem.get(), bCanBlock);
}
// confusing name - it means - mark the watched property of an item (either watched or unwatched)
BoxeeUtils::MarkWatched(pItem.get());
if (result)
pItem->SetProperty("isloaded",true);
return result;
}
CItemLoader::CItemLoader()
{
m_bStopped = false;
m_processor.SetName("Item Loader");
m_directoryProcessor.SetName("Directory Loader");
#ifdef HAS_EMBEDDED
m_videoProcessor.SetName("Video Item Loader");
#endif
}
CItemLoader::~CItemLoader()
{
Stop();
}
bool CItemLoader::Init()
{
CLog::Log(LOGDEBUG,"CItemLoader::Init, NEWUI, item loader initialized");
bool bResult = true;
bResult &= m_processor.Start(NUM_ITEM_LOADER_THREADS);
bResult &= m_directoryProcessor.Start(NUM_DIRECTORY_LOADER_THREADS);
#ifdef HAS_EMBEDDED
bResult &= m_videoProcessor.Start(NUM_VIDEO_ITEM_LOADER_THREAD);
#endif
return bResult;
}
void CItemLoader::SignalStop()
{
m_bStopped = true;
#ifdef HAS_EMBEDDED
m_videoProcessor.SignalStop();
#endif
m_directoryProcessor.SignalStop();
m_processor.SignalStop();
}
void CItemLoader::Stop()
{
m_bStopped = true;
#ifdef HAS_EMBEDDED
m_videoProcessor.Stop();
#endif
m_directoryProcessor.Stop();
m_processor.Stop();
}
int CItemLoader::GetQueueSize()
{
return m_processor.GetQueueSize();
}
void CItemLoader::AddControl(int dwWindowId, int dwControlId, CFileItemList items, SORT_METHOD iSortMethod, SORT_ORDER iSortOrder, int iSelectedItem)
{
if (items.Size() == 0)
{
return;
}
CLog::Log(LOGDEBUG,"CItemLoader::AddControl, 1 GUI_MSG_LOADING, window = %d, control = %d (basecontainer)", dwWindowId, dwControlId);
CGUIMessage msg(GUI_MSG_LOADING, dwWindowId, dwControlId);
g_windowManager.SendMessage(msg, dwWindowId);
items.SetProperty("windowId", (int)dwWindowId);
items.SetProperty("controlId", (int)dwControlId);
items.SetProperty("selectedItem", (int)iSelectedItem);
ItemsLoaded(items);
}
//void CItemLoader::AddControl(int dwWindowId, int dwControlId, CFileItem* pItem, SORT_METHOD iSortMethod, SORT_ORDER iSortOrder, int iSelectedItem)
//{
// CLog::Log(LOGDEBUG,"CItemLoader::AddControl, window = %d, control = %d, path = %s (browse)", dwWindowId, dwControlId, pItem->m_strPath.c_str());
//
// if (!pItem)
// return;
//
// if (pItem->m_strPath == "")
// {
// delete pItem;
// return;
// }
//
// CLog::Log(LOGDEBUG,"CItemLoader::AddControl, 2 GUI_MSG_LOADING, window = %d, control = %d (basecontainer)", dwWindowId, dwControlId);
// CGUIMessage msg(GUI_MSG_LOADING, dwWindowId, dwControlId);
// g_windowManager.SendMessage(msg);
//
// CFileItemList items;
//
// // Retreive the items corresponding the path
// CFileItemPtr itemPtr(pItem);
// CGetDirectoryJob* pJob = new CGetDirectoryJob(itemPtr, dwWindowId, dwControlId, this, iSortMethod, iSortOrder, iSelectedItem);
//
// // python requires some stuff to run from the main thread. therefore we do not queue the job on pythons (plugins/scripts) but rather execute it
// if (CUtil::IsPlugin(itemPtr->m_strPath) || CUtil::IsScript(itemPtr->m_strPath))
// {
// pJob->DoWork();
// delete pJob;
// }
// else
// {
// if (!m_directoryProcessor.QueueJob(pJob))
// {
// CLog::Log(LOGERROR,"CItemLoader::AddControl, unable to queue directory job, path = %s (browse)", pItem->m_strPath.c_str());
// delete pJob;
// LoadFailed(dwWindowId, dwControlId);
// }
// }
// CLog::Log(LOGDEBUG,"CItemLoader::AddControl, added directory job, path = %s (browse)", pItem->m_strPath.c_str());
//}
int CItemLoader::AddControl(int dwWindowId, int dwControlId, const CStdString& strPath, SORT_METHOD iSortMethod, SORT_ORDER iSortOrder, int iSelectedItem)
{
int jobId = 0;
CLog::Log(LOGDEBUG,"CItemLoader::AddControl, window = %d, control = %d, path = %s (browse)", dwWindowId, dwControlId, strPath.c_str());
if (strPath != "")
{
CLog::Log(LOGDEBUG,"CItemLoader::AddControl, 3 GUI_MSG_LOADING, window = %d, control = %d (basecontainer)", dwWindowId, dwControlId);
CGUIMessage msg(GUI_MSG_LOADING, dwWindowId, dwControlId);
g_windowManager.SendMessage(msg, dwWindowId);
CFileItemList items;
// Retreive the items corresponding the path
CGetDirectoryJob* pJob = new CGetDirectoryJob(strPath, dwWindowId, dwControlId, this, iSortMethod, iSortOrder, iSelectedItem);
jobId = pJob->GetId();
// python requires some stuff to run from the main thread. therefore we do not queue the job on pythons (plugins/scripts) but rather execute it
if (CUtil::IsPlugin(strPath) || CUtil::IsScript(strPath))
{
CLog::Log(LOGDEBUG,"CItemLoader::AddControl, path = %s is either plugin ,script or database - Executing. (browse)", strPath.c_str());
pJob->DoWork();
delete pJob;
}
else
{
if (!m_directoryProcessor.QueueJob(pJob))
{
CLog::Log(LOGERROR,"CItemLoader::AddControl, unable to queue directory job, path = %s (browse)", strPath.c_str());
delete pJob;
LoadFailed(dwWindowId, dwControlId);
}
else
{
CLog::Log(LOGDEBUG,"CItemLoader::AddControl, added directory job, path = %s (browse)", strPath.c_str());
}
}
}
return jobId;
}
void CItemLoader::LoadBackgroundImage(int dwWindowId, const CStdString& strImagePath)
{
BOXEE::BXBGJob* pJob = new CLoadBackgroundImageJob(dwWindowId, strImagePath);
if (!m_processor.QueueFront(pJob))
{
CLog::Log(LOGERROR,"CItemLoader::LoadBackgroundImage, Could not queue job ");
delete pJob;
}
}
//void CItemLoader::LoadImage(int dwWindowId, int dwControlId, const CStdString& strPath)
//{
// CFileItemPtr pItem ( new CFileItem );
// pItem->m_strPath = strPath;
// pItem->SetThumbnailImage(strPath);
// pItem->SetProperty("IsPicture",true);
// pItem->SetProperty("ControlID",(int)dwControlId);
//
// BOXEE::BXBGJob* pJob = new CLoadFileItemJob(pItem, this);
//
// if (!m_processor.QueueFront(pJob)) {
// CLog::Log(LOGERROR,"CItemLoader::LoadImage, NEWUI, Could not queue job ");
// delete pJob;
// }
//}
void CItemLoader::LoadFailed(int windowId, int controlId, bool bErrorOccured)
{
CGUIMessage msg(GUI_MSG_LOAD_FAILED, windowId, controlId, bErrorOccured ? 1 : 0);
g_windowManager.SendThreadMessage(msg, windowId);
}
void CItemLoader::ItemsLoaded(CFileItemList& items)
{
// Get the path for which items were loaded
CStdString strPath = items.m_strPath;
// Assign unique id to each of the items
for (int j=0; j < items.Size() && !m_bStopped; j++)
{
CStdString strId;
unsigned int now = CTimeUtils::GetTimeMS();
strId.Format("%lu-%d",now, j);
items[j]->SetProperty("itemid", strId);
items[j]->SetProperty("directoryPath", strPath);
}
int windowId = items.GetPropertyInt("windowId");
int controlId = items.GetPropertyInt("controlId");
int iSelectedItem = items.GetPropertyInt("selectedItem");
// we may have items, but the request timed out, so its not the complete list of items..
if (items.GetPropertyBOOL("isRequestTimedOut"))
{
CGUIMessage msgErr(GUI_MSG_LOADING_TIMEDOUT, items.GetPropertyInt("windowId"), 0, items.GetPropertyInt("requestId"));
msgErr.SetStringParam(items.m_strPath);
g_windowManager.SendThreadMessage(msgErr, items.GetPropertyInt("windowId"));
}
// We create a new list and send it to the browse screen
// the browse screen is responsible for deleting the items
CFileItemList* pNewList = new CFileItemList();
pNewList->Copy(items);
std::vector<BOXEE::BXBGJob*> vecLoadJobs;
vecLoadJobs.reserve(items.Size()+1);
#ifdef HAS_EMBEDDED
std::vector<BOXEE::BXBGJob*> vecVideoLoadJobs;
vecVideoLoadJobs.reserve(items.Size()+1);
#endif
// Go over all retrieved items and activate relevant background loading
for (int j=pNewList->Size()-1; j >= 0 && !m_bStopped; j--)
{
CFileItemPtr pItem = pNewList->Get(j);
if (!pItem->GetPropertyBOOL("isloaded"))
{
// Window and control id will be used by other loaders to match the item to its container
pItem->SetProperty("windowId", (int)windowId);
pItem->SetProperty("controlId", (int)controlId);
if (pItem->GetPropertyBOOL("doload"))
{
// Create new item and send it to the background loader
CFileItemPtr pNewItem ( new CFileItem(*pItem) );
BOXEE::BXBGJob* pJob = new CLoadFileItemJob(pNewItem, this);
#ifdef HAS_EMBEDDED
if (!pItem->HasThumbnail() && !pItem->GetPropertyBOOL("IsBoxeeServerItem"))
{
vecVideoLoadJobs.push_back(pJob);
}
else
#endif
{
vecLoadJobs.push_back(pJob);
}
//pItem->SetThumbnailImage("defaultloading.gif");
}
else
{
pItem->SetProperty("needsloading", true);
}
}
}
if (items.HasProperty("BrowseBackgroundImage"))
{
CGUIMessage msg(GUI_MSG_BG_PICTURE, windowId, controlId);
msg.SetStringParam(items.GetProperty("BrowseBackgroundImage"));
g_windowManager.SendThreadMessage(msg, windowId);
}
CLog::Log(LOGDEBUG,"CGetDirectoryJob::ItemsLoaded, sending GUI_MSG_LABEL_BIND windowId [%d] controlId[%d] size[%d]", windowId, controlId, pNewList->Size());
CGUIMessage msg(GUI_MSG_LABEL_BIND, windowId, controlId, iSelectedItem, 0, pNewList);
g_windowManager.SendThreadMessage(msg, windowId);
#ifdef HAS_EMBEDDED
if (vecVideoLoadJobs.size())
{
std::reverse(vecVideoLoadJobs.begin(), vecVideoLoadJobs.end());
m_videoProcessor.QueueJobs(vecVideoLoadJobs);
}
#endif
// Queue all jobs into the processor in reverse order
if (vecLoadJobs.size())
{
std::reverse(vecLoadJobs.begin(), vecLoadJobs.end());
m_processor.QueueJobs(vecLoadJobs);
}
}
void CItemLoader::LoadItem(CFileItem* pItem , bool bAsyncOnly)
{
CFileItemPtr pNewItem ( new CFileItem(*pItem) );
if (!bAsyncOnly)
{
CBackgroundLoaderFactory::RunBackgroundLoader(pNewItem, false);
if (pNewItem->GetPropertyBOOL("isloaded"))
{
*pItem = *pNewItem;
return;
}
}
BOXEE::BXBGJob* pJob = new CLoadFileItemJob(pNewItem, this);
//pItem->SetThumbnailImage(PLACEHOLDER_IMAGE);
#ifdef HAS_EMBEDDED
if (!pNewItem->HasThumbnail() && !pNewItem->GetPropertyBOOL("IsBoxeeServerItem"))
{
m_videoProcessor.QueueFront(pJob);
}
else
#endif
{
m_processor.QueueFront(pJob);
}
}
// Implementation of the IBackgroundLoaderObserver interface
void CItemLoader::OnItemLoaded(CFileItem* pItem)
{
int windowId = pItem->GetPropertyInt("windowId");
int controlId = pItem->GetPropertyInt("controlId");
pItem->FillInDefaultIcon();
pItem->SetProperty("isloaded", true);
// Update the cache
g_directoryCache.UpdateItem(*pItem);
CGUIMessage winmsg(GUI_MSG_ITEM_LOADED, windowId, controlId, 0, 0);
winmsg.SetPointer(new CFileItem(*pItem));
g_windowManager.SendThreadMessage(winmsg, windowId);
//send to all observers
CStdString itemId = pItem->GetProperty("itemid");
std::map< CStdString , std::set<int> >::iterator it1 = m_itemLoadedObservers.find(itemId);
if (it1 != m_itemLoadedObservers.end())
{
for (std::set<int>::iterator it2 = it1->second.begin(); it2 != it1->second.end() ; it2++)
{
windowId = (int)(*it2);
CGUIMessage winmsg(GUI_MSG_ITEM_LOADED, windowId, 0);
winmsg.SetPointer(new CFileItem(*pItem));
g_windowManager.SendThreadMessage(winmsg, windowId);
}
}
#ifdef HAS_EMBEDDED
uint64_t size = 0;
struct __stat64 stat;
CStdString thumb = pItem->GetThumbnailImage();
if (CFile::Stat(thumb,&stat) == 0)
{
size = stat.st_size;
g_application.GetThumbnailsManager().TouchThumbnailFile(thumb, size);
}
#endif
}
void CItemLoader::LoadFileMetadata(int dwWindowId, int dwControlId, CFileItem* pItem)
{
pItem->SetProperty("windowId", (int)dwWindowId);
pItem->SetProperty("controlId", (int)dwControlId);
// Create new item and send it to the background loader
CFileItemPtr pNewItem ( new CFileItem(*pItem) );
BOXEE::BXBGJob* pJob = new CLoadMetadataJob(pNewItem, this);
if (!m_processor.QueueFront(pJob)) {
CLog::Log(LOGERROR,"CItemLoader::ItemsLoaded, NEWUI, Could not queue job ");
delete pJob;
}
}
void CItemLoader::Pause(bool bVideoProcessorOnly)
{
#ifdef HAS_EMBEDDED
if(bVideoProcessorOnly)
return m_videoProcessor.Pause();
m_videoProcessor.Pause();
m_processor.Pause();
#endif
}
void CItemLoader::Resume(bool bVideoProcessorOnly)
{
#ifdef HAS_EMBEDDED
if(bVideoProcessorOnly)
return m_videoProcessor.Resume();
m_videoProcessor.Resume();
m_processor.Resume();
#endif
}
void CItemLoader::AddItemLoadedObserver(const CStdString& strItemId , int windowId)
{
/*std::map< CStdString , std::set<int> >::iterator it;
it = m_itemLoadedObservers.find(strItemId);
if (it != m_itemLoadedObservers.end())
{
it->second.insert(windowId);
}
else*/
{
m_itemLoadedObservers[strItemId].insert(windowId);
}
}
void CItemLoader::RemoveItemLoadedObserver(const CStdString& strItemId , int windowId)
{
std::map< CStdString , std::set<int> >::iterator it;
it = m_itemLoadedObservers.find(strItemId);
if (it != m_itemLoadedObservers.end())
{
it->second.erase(windowId);
}
}