Skip to content

Commit

Permalink
Merge pull request xbmc#4 from xhaggi/select-proper-bookmark-item
Browse files Browse the repository at this point in the history
Select proper bookmark item
  • Loading branch information
Leatherface75 committed Mar 27, 2015
2 parents 2693ada + 7188e2d commit 244d687
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
4 changes: 3 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -1270,7 +1270,9 @@ msgctxt "#298"
msgid "Bookmarks"
msgstr ""

#empty string with id 299
msgctxt "#299"
msgid "Bookmark"
msgstr ""

msgctxt "#300"
msgid "MP1 capable receiver"
Expand Down
4 changes: 2 additions & 2 deletions addons/skin.confluence/720p/VideoOSDBookmarks.xml
Expand Up @@ -105,7 +105,7 @@
<selectedcolor>selected</selectedcolor>
<align>center</align>
<aligny>center</aligny>
<info>ListItem.Label</info>
<label>$INFO[ListItem.Label]$INFO[ListItem.Label2, (,)]</label>
</control>
</itemlayout>
<focusedlayout height="215" width="240">
Expand Down Expand Up @@ -133,7 +133,7 @@
<selectedcolor>selected</selectedcolor>
<align>center</align>
<aligny>center</aligny>
<info>ListItem.Label</info>
<label>$INFO[ListItem.Label]$INFO[ListItem.Label2, (,)]</label>
</control>
</focusedlayout>
</control>
Expand Down
89 changes: 63 additions & 26 deletions xbmc/video/dialogs/GUIDialogVideoBookmarks.cpp
Expand Up @@ -219,7 +219,15 @@ void CGUIDialogVideoBookmarks::Delete(int item)
void CGUIDialogVideoBookmarks::UpdateItem(unsigned int chapterIdx)
{
CSingleLock lock(m_refreshSection);
int itemPos = ((chapterIdx - 1) + m_chapterOffset);

int itemPos = 0;
for (auto& item : m_vecItems->GetList())
{
if (chapterIdx == item->GetProperty("chapter").asInteger())
break;
itemPos++;
}

if (itemPos < m_vecItems->Size())
{
std::string time = StringUtils::Format("chapter://%s/%i", m_filePath.c_str(), chapterIdx);
Expand All @@ -235,6 +243,7 @@ void CGUIDialogVideoBookmarks::OnRefreshList()
{
m_bookmarks.clear();
CBookmark resumemark;
std::vector<CFileItemPtr> items;

// open the d/b and retrieve the bookmarks for the current movie
m_filePath = g_application.CurrentFile();
Expand All @@ -252,7 +261,9 @@ void CGUIDialogVideoBookmarks::OnRefreshList()
videoDatabase.Close();
CSingleLock lock(m_refreshSection);
m_vecItems->Clear();
// cycle through each stored bookmark and add it to our list control


// cycle through each stored bookmark and add it to our list control
for (unsigned int i = 0; i < m_bookmarks.size(); ++i)
{
if (m_bookmarks[i].type == CBookmark::RESUME)
Expand All @@ -263,40 +274,65 @@ void CGUIDialogVideoBookmarks::OnRefreshList()
bookmarkTime = StringUtils::Format("%s %li %s %li", g_localizeStrings.Get(20373).c_str(), m_bookmarks[i].seasonNumber, g_localizeStrings.Get(20359).c_str(), m_bookmarks[i].episodeNumber);
else
bookmarkTime = StringUtils::SecondsToTimeString((long)m_bookmarks[i].timeInSeconds, TIME_FORMAT_HH_MM_SS);

CFileItemPtr item(new CFileItem(bookmarkTime));

CFileItemPtr item(new CFileItem(g_localizeStrings.Get(299)));
item->SetLabel2(bookmarkTime);
item->SetArt("thumb", m_bookmarks[i].thumbNailImage);
m_vecItems->Add(item);
item->SetProperty("resumepoint", m_bookmarks[i].timeInSeconds);
item->SetProperty("playerstate", m_bookmarks[i].playerState);
items.push_back(item);
}

// add chapters if around
m_chapterOffset = m_vecItems->Size();
for (int i=1;i<=g_application.m_pPlayer->GetChapterCount();++i)
for (int i = 1; i <= g_application.m_pPlayer->GetChapterCount(); ++i)
{
std::string chapterName;
g_application.m_pPlayer->GetChapterName(chapterName, i);
if (chapterName.empty())
chapterName = StringUtils::Format(g_localizeStrings.Get(25010).c_str(), i);

int64_t pos = g_application.m_pPlayer->GetChapterPos(i);
std::string time =
StringUtils::SecondsToTimeString((long) pos, TIME_FORMAT_HH_MM_SS);
std::string name = StringUtils::Format("%s (%s)",
chapterName.c_str(), time.c_str());
CFileItemPtr item(new CFileItem(name));
time = StringUtils::Format("chapter://%s/%i", m_filePath.c_str(), i);
std::string cachefile = CTextureCache::Get().GetCachedPath(CTextureCache::Get().GetCacheFile(time)+".jpg");
std::string time = StringUtils::SecondsToTimeString((long) pos, TIME_FORMAT_HH_MM_SS);

if (chapterName.empty() || StringUtils::StartsWithNoCase(chapterName, time))
chapterName = StringUtils::Format(g_localizeStrings.Get(25010).c_str(), i);

CFileItemPtr item(new CFileItem(chapterName));
item->SetLabel2(time);

std::string chapterPath = StringUtils::Format("chapter://%s/%i", m_filePath.c_str(), i);
std::string cachefile = CTextureCache::Get().GetCachedPath(CTextureCache::Get().GetCacheFile(chapterPath)+".jpg");
if (XFILE::CFile::Exists(cachefile))
item->SetArt("thumb", cachefile);
else if (i > m_jobsStarted && CSettings::Get().GetBool("myvideos.extractchapterthumbs"))
{
CFileItem item(m_filePath, false);
CJob* job = new CThumbExtractor(item, m_filePath, true, time, pos * 1000, false);
CJob* job = new CThumbExtractor(item, m_filePath, true, chapterPath, pos * 1000, false);
AddJob(job);
m_mapJobsChapter[job] = i;
m_jobsStarted++;
}

item->SetProperty("chapter", i);
item->SetProperty("resumepoint", static_cast<double>(pos));
items.push_back(item);
}

// sort items by resume point
std::sort(items.begin(), items.end(), [](const CFileItemPtr &item1, const CFileItemPtr &item2) {
return item1->GetProperty("resumepoint").asDouble() < item2->GetProperty("resumepoint").asDouble();
});

// add items to file list and mark the proper item as selected if the current playtime is above
int selectedItemIndex = 0;
int playTime = g_application.GetTime();
for (auto& item : items)
{
m_vecItems->Add(item);
if (playTime >= item->GetProperty("resumepoint").asDouble())
selectedItemIndex = m_vecItems->Size() - 1;
}

m_viewControl.SetItems(*m_vecItems);
m_viewControl.SetSelectedItem(selectedItemIndex);;
}

void CGUIDialogVideoBookmarks::Update()
Expand Down Expand Up @@ -345,17 +381,18 @@ void CGUIDialogVideoBookmarks::Clear()

void CGUIDialogVideoBookmarks::GotoBookmark(int item)
{
if (item < 0 || item >= (int)m_bookmarks.size()+g_application.m_pPlayer->GetChapterCount()) return;
if (g_application.m_pPlayer->HasPlayer())
if (item < 0 || item >= m_vecItems->Size() || !g_application.m_pPlayer->HasPlayer())
return;

CFileItemPtr fileItem = m_vecItems->Get(item);
int chapter = fileItem->GetProperty("chapter").asInteger();
if (!chapter)
{
if (item < (int) m_bookmarks.size())
{
g_application.m_pPlayer->SetPlayerState(m_bookmarks[item].playerState);
g_application.SeekTime((double)m_bookmarks[item].timeInSeconds);
}
else
g_application.m_pPlayer->SeekChapter(item-m_bookmarks.size()+1);
g_application.m_pPlayer->SetPlayerState(fileItem->GetProperty("playerstate").asString());
g_application.SeekTime(fileItem->GetProperty("resumepoint").asDouble());
}
else
g_application.m_pPlayer->SeekChapter(fileItem->GetProperty("chapter").asInteger());
}

void CGUIDialogVideoBookmarks::ClearBookmarks()
Expand Down
1 change: 0 additions & 1 deletion xbmc/video/dialogs/GUIDialogVideoBookmarks.h
Expand Up @@ -81,7 +81,6 @@ class CGUIDialogVideoBookmarks : public CGUIDialog, public CJobQueue
private:
void UpdateItem(unsigned int chapterIdx);

int m_chapterOffset;
int m_jobsStarted;
std::string m_filePath;
CCriticalSection m_refreshSection;
Expand Down

0 comments on commit 244d687

Please sign in to comment.