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;
37 CBackgroundInfoLoader::~CBackgroundInfoLoader()
42 void CBackgroundInfoLoader::Run()
46 if (m_vecItems.size() > 0)
50 // Stage 1: All "fast" stuff we have already cached
51 for (vector<CFileItemPtr>::const_iterator iter = m_vecItems.begin(); iter != m_vecItems.end(); ++iter)
53 CFileItemPtr pItem = *iter;
55 // Ask the callback if we should abort
56 if ((m_pProgressCallback && m_pProgressCallback->Abort()) || m_bStop)
61 if (LoadItemCached(pItem.get()) && m_pObserver)
62 m_pObserver->OnItemLoaded(pItem.get());
66 CLog::Log(LOGERROR, "CBackgroundInfoLoader::LoadItemCached - Unhandled exception for item %s", pItem->GetPath().c_str());
70 // Stage 2: All "slow" stuff that we need to lookup
71 for (vector<CFileItemPtr>::const_iterator iter = m_vecItems.begin(); iter != m_vecItems.end(); ++iter)
73 CFileItemPtr pItem = *iter;
75 // Ask the callback if we should abort
76 if ((m_pProgressCallback && m_pProgressCallback->Abort()) || m_bStop)
81 if (LoadItemLookup(pItem.get()) && m_pObserver)
82 m_pObserver->OnItemLoaded(pItem.get());
86 CLog::Log(LOGERROR, "CBackgroundInfoLoader::LoadItemLookup - Unhandled exception for item %s", pItem->GetPath().c_str());
95 CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__);
99 void CBackgroundInfoLoader::Load(CFileItemList& items)
103 if (items.Size() == 0)
106 CSingleLock lock(m_lock);
108 for (int nItem=0; nItem < items.Size(); nItem++)
109 m_vecItems.push_back(items[nItem]);
111 m_pVecItems = &items;
114 m_thread = new CThread(this, "BackgroundLoader");
117 m_thread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL);
121 void CBackgroundInfoLoader::StopAsync()
127 void CBackgroundInfoLoader::StopThread()
133 m_thread->StopThread();
141 bool CBackgroundInfoLoader::IsLoading()
143 return m_thread != NULL;
146 void CBackgroundInfoLoader::SetObserver(IBackgroundLoaderObserver* pObserver)
148 m_pObserver = pObserver;
151 void CBackgroundInfoLoader::SetProgressCallback(IProgressCallback* pCallback)
153 m_pProgressCallback = pCallback;