Skip to content

Commit

Permalink
Don't keep this dialog in memory. With that we can cancel jobs on OnW…
Browse files Browse the repository at this point in the history
…indowUnload().
  • Loading branch information
ace20022 authored and popcornmix committed Mar 1, 2015
1 parent fa1230b commit da4fffd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
53 changes: 32 additions & 21 deletions xbmc/video/dialogs/GUIDialogVideoBookmarks.cpp
Expand Up @@ -68,7 +68,8 @@ CGUIDialogVideoBookmarks::CGUIDialogVideoBookmarks()
: CGUIDialog(WINDOW_DIALOG_VIDEO_BOOKMARKS, "VideoOSDBookmarks.xml")
{
m_vecItems = new CFileItemList;
m_loadType = KEEP_IN_MEMORY;
m_loadType = LOAD_EVERY_TIME;
m_jobsStarted = 0;
}

CGUIDialogVideoBookmarks::~CGUIDialogVideoBookmarks()
Expand Down Expand Up @@ -143,7 +144,7 @@ bool CGUIDialogVideoBookmarks::OnMessage(CGUIMessage& message)
case 0:
OnRefreshList();
break;
case 2:
case 1:
UpdateItem(message.GetParam2());
break;
default:
Expand Down Expand Up @@ -213,29 +214,22 @@ void CGUIDialogVideoBookmarks::Delete(int item)
Update();
}

void CGUIDialogVideoBookmarks::UpdateItem(unsigned int id)
void CGUIDialogVideoBookmarks::UpdateItem(unsigned int itemIdx)
{
CSingleLock lock(m_refreshSection);
std::map<unsigned int, unsigned int>::iterator iter = m_mapJobsChapter.find(id);
if (iter != m_mapJobsChapter.end())

if ((int) itemIdx < m_vecItems->Size())
{
unsigned int itemId = (*iter).second;
if (itemId + m_bookmarks.size() < m_vecItems->Size())
std::string time = StringUtils::Format("chapter://%s/%i", m_filePath.c_str(), itemIdx);
std::string cachefile = CTextureCache::Get().GetCachedPath(CTextureCache::Get().GetCacheFile(time) + ".jpg");
if (XFILE::CFile::Exists(cachefile))
{
std::string time = StringUtils::Format("chapter://%s/%i", m_filePath.c_str(), itemId);
std::string cachefile = CTextureCache::Get().GetCachedPath(CTextureCache::Get().GetCacheFile(time) + ".jpg");
if (XFILE::CFile::Exists(cachefile))
{
//m_vecItems->UpdateItem ->get[itemId]->SetArt("thumb", cachefile);
CFileItemPtr item = (*m_vecItems)[itemId];
item->SetArt("thumb", cachefile);
//m_viewControl.SetItems(*m_vecItems);
}
(*m_vecItems)[itemIdx]->SetArt("thumb", cachefile);
}
}
}

void CGUIDialogVideoBookmarks::OnRefreshList(bool createThumbJob)
void CGUIDialogVideoBookmarks::OnRefreshList()
{
m_bookmarks.clear();
CBookmark resumemark;
Expand Down Expand Up @@ -289,11 +283,12 @@ void CGUIDialogVideoBookmarks::OnRefreshList(bool createThumbJob)
std::string cachefile = CTextureCache::Get().GetCachedPath(CTextureCache::Get().GetCacheFile(time)+".jpg");
if (XFILE::CFile::Exists(cachefile))
item->SetArt("thumb", cachefile);
else if (createThumbJob)
else if (i > m_jobsStarted)
{
CFileItem item(m_filePath, false);
unsigned int jobId = CJobManager::GetInstance().AddJob(new CThumbExtractor(item, m_filePath, true, time, pos*1000, false), this, CJob::PRIORITY_NORMAL);
m_mapJobsChapter[jobId] = i;
m_mapJobsChapter[jobId] = m_vecItems->Size();
m_jobsStarted++;
}
m_vecItems->Add(item);
}
Expand Down Expand Up @@ -454,10 +449,20 @@ void CGUIDialogVideoBookmarks::OnWindowLoaded()
m_viewControl.Reset();
m_viewControl.SetParentWindow(GetID());
m_viewControl.AddView(GetControl(CONTROL_THUMBS));
m_jobsStarted = 0;
m_mapJobsChapter.clear();
m_vecItems->Clear();
}

void CGUIDialogVideoBookmarks::OnWindowUnload()
{
//stop running thumb extraction jobs
for (MAPJOBSCHAPS::iterator it = m_mapJobsChapter.begin(); it != m_mapJobsChapter.end(); ++it)
{
CJobManager::GetInstance().CancelJob(it->first);
}
m_mapJobsChapter.clear();
m_vecItems->Clear();
CGUIDialog::OnWindowUnload();
m_viewControl.Reset();
}
Expand Down Expand Up @@ -546,7 +551,13 @@ void CGUIDialogVideoBookmarks::OnJobComplete(unsigned int jobID,
{
if (success && IsActive())
{
CGUIMessage m(GUI_MSG_REFRESH_LIST, GetID(), 0, 2, jobID);
CApplicationMessenger::Get().SendGUIMessage(m);
MAPJOBSCHAPS::iterator iter = m_mapJobsChapter.find(jobID);
if (iter != m_mapJobsChapter.end())
{
unsigned int itemIdx = (*iter).second;
CGUIMessage m(GUI_MSG_REFRESH_LIST, GetID(), 0, 1, itemIdx);
CApplicationMessenger::Get().SendGUIMessage(m);
m_mapJobsChapter.erase(iter);
}
}
}
9 changes: 6 additions & 3 deletions xbmc/video/dialogs/GUIDialogVideoBookmarks.h
Expand Up @@ -29,6 +29,8 @@ class CFileItemList;

class CGUIDialogVideoBookmarks : public CGUIDialog, public IJobCallback
{
typedef std::map<unsigned int, unsigned int> MAPJOBSCHAPS;

public:
CGUIDialogVideoBookmarks(void);
virtual ~CGUIDialogVideoBookmarks(void);
Expand Down Expand Up @@ -66,7 +68,7 @@ class CGUIDialogVideoBookmarks : public CGUIDialog, public IJobCallback
static bool AddBookmark(CVideoInfoTag *tag=NULL);
void Delete(int item);
void Clear();
void OnRefreshList(bool createThumbJob = true);
void OnRefreshList();
void OnPopupMenu(int item);
CGUIControl *GetFirstFocusableControl(int id);

Expand All @@ -77,9 +79,10 @@ class CGUIDialogVideoBookmarks : public CGUIDialog, public IJobCallback
VECBOOKMARKS m_bookmarks;

private:
void UpdateItem(unsigned int id);
void UpdateItem(unsigned int itemIdx);

int m_jobsStarted;
std::string m_filePath;
CCriticalSection m_refreshSection;
std::map<unsigned int, unsigned int> m_mapJobsChapter;
MAPJOBSCHAPS m_mapJobsChapter;
};

0 comments on commit da4fffd

Please sign in to comment.