2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "BackgroundInfoLoader.h"
23 #include "settings/AdvancedSettings.h"
24 #include "threads/SingleLock.h"
25 #include "utils/log.h"
29 CBackgroundInfoLoader::CBackgroundInfoLoader() : m_thread (NULL)
33 m_pProgressCallback=NULL;
38 CBackgroundInfoLoader::~CBackgroundInfoLoader()
43 void CBackgroundInfoLoader::Run()
47 if (m_vecItems.size() > 0)
51 // Stage 1: All "fast" stuff we have already cached
52 for (vector<CFileItemPtr>::const_iterator iter = m_vecItems.begin(); iter != m_vecItems.end(); ++iter)
54 CFileItemPtr pItem = *iter;
56 // Ask the callback if we should abort
57 if ((m_pProgressCallback && m_pProgressCallback->Abort()) || m_bStop)
62 if (LoadItemCached(pItem.get()) && m_pObserver)
63 m_pObserver->OnItemLoaded(pItem.get());
67 CLog::Log(LOGERROR, "CBackgroundInfoLoader::LoadItemCached - Unhandled exception for item %s", pItem->GetPath().c_str());
71 // Stage 2: All "slow" stuff that we need to lookup
72 for (vector<CFileItemPtr>::const_iterator iter = m_vecItems.begin(); iter != m_vecItems.end(); ++iter)
74 CFileItemPtr pItem = *iter;
76 // Ask the callback if we should abort
77 if ((m_pProgressCallback && m_pProgressCallback->Abort()) || m_bStop)
82 if (LoadItemLookup(pItem.get()) && m_pObserver)
83 m_pObserver->OnItemLoaded(pItem.get());
87 CLog::Log(LOGERROR, "CBackgroundInfoLoader::LoadItemLookup - Unhandled exception for item %s", pItem->GetPath().c_str());
98 CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__);
102 void CBackgroundInfoLoader::Load(CFileItemList& items)
106 if (items.Size() == 0)
109 CSingleLock lock(m_lock);
111 for (int nItem=0; nItem < items.Size(); nItem++)
112 m_vecItems.push_back(items[nItem]);
114 m_pVecItems = &items;
118 m_thread = new CThread(this, "BackgroundLoader");
121 m_thread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL);
125 void CBackgroundInfoLoader::StopAsync()
131 void CBackgroundInfoLoader::StopThread()
137 m_thread->StopThread();
143 m_bIsLoading = false;
146 bool CBackgroundInfoLoader::IsLoading()
151 void CBackgroundInfoLoader::SetObserver(IBackgroundLoaderObserver* pObserver)
153 m_pObserver = pObserver;
156 void CBackgroundInfoLoader::SetProgressCallback(IProgressCallback* pCallback)
158 m_pProgressCallback = pCallback;