Permalink
Browse files

epg: notify observers when added and deleting a table, and make the e…

…pg container observer epg tables. fixes epg timeline not being updated when tags change
  • Loading branch information...
opdenkamp committed Jul 11, 2012
1 parent f05a59b commit 49c2278638327d31e5eb4496d8b23e9217245872
Showing with 39 additions and 21 deletions.
  1. +19 −15 xbmc/epg/Epg.cpp
  2. +15 −1 xbmc/epg/EpgContainer.cpp
  3. +5 −5 xbmc/epg/EpgContainer.h
View
@@ -413,8 +413,6 @@ bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
bool bReturn(false);
CEpgDatabase *database = g_EpgContainer.GetDatabase();
- CSingleLock lock(m_critSection);
-
if (epg.m_tags.size() > 0)
{
if (bStoreInDb)
@@ -426,18 +424,22 @@ bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
}
database->BeginTransaction();
}
- CLog::Log(LOGDEBUG, "%s - %u entries in memory before merging", __FUNCTION__, m_tags.size());
- /* copy over tags */
- for (map<CDateTime, CEpgInfoTag *>::const_iterator it = epg.m_tags.begin(); it != epg.m_tags.end(); it++)
- UpdateEntry(*it->second, bStoreInDb, false);
-
- CLog::Log(LOGDEBUG, "%s - %u entries in memory after merging and before fixing", __FUNCTION__, m_tags.size());
- FixOverlappingEvents(bStoreInDb);
- CLog::Log(LOGDEBUG, "%s - %u entries in memory after fixing", __FUNCTION__, m_tags.size());
- /* update the last scan time of this table */
- m_lastScanTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime();
-
- //m_bTagsChanged = true;
+
+ {
+ CSingleLock lock(m_critSection);
+ CLog::Log(LOGDEBUG, "%s - %u entries in memory before merging", __FUNCTION__, m_tags.size());
+ /* copy over tags */
+ for (map<CDateTime, CEpgInfoTag *>::const_iterator it = epg.m_tags.begin(); it != epg.m_tags.end(); it++)
+ UpdateEntry(*it->second, bStoreInDb, false);
+
+ CLog::Log(LOGDEBUG, "%s - %u entries in memory after merging and before fixing", __FUNCTION__, m_tags.size());
+ FixOverlappingEvents(bStoreInDb);
+ CLog::Log(LOGDEBUG, "%s - %u entries in memory after fixing", __FUNCTION__, m_tags.size());
+ /* update the last scan time of this table */
+ m_lastScanTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime();
+
+ SetChanged();
+ }
/* persist changes */
if (bStoreInDb)
{
@@ -453,9 +455,11 @@ bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
if (bStoreInDb)
bReturn = Persist(true);
else
- bReturn = true;
+ bReturn = true;
}
+ NotifyObservers("epg");
+
return bReturn;
}
View
@@ -97,7 +97,10 @@ void CEpgContainer::Clear(bool bClearDb /* = false */)
CSingleLock lock(m_critSection);
/* clear all epg tables and remove pointers to epg tables on channels */
for (map<unsigned int, CEpg *>::iterator it = m_epgs.begin(); it != m_epgs.end(); it++)
+ {
+ it->second->UnregisterObserver(this);
delete it->second;
+ }
m_epgs.clear();
m_iNextEpgUpdate = 0;
m_bIsInitialising = true;
@@ -143,8 +146,13 @@ bool CEpgContainer::Stop(void)
void CEpgContainer::Notify(const Observable &obs, const CStdString& msg)
{
/* settings were updated */
- if (msg == "settings")
+ if (msg.Equals("settings"))
LoadSettings();
+ else if (msg.Equals("epg"))
+ {
+ SetChanged();
+ NotifyObservers(msg);
+ }
}
void CEpgContainer::LoadFromDB(void)
@@ -287,6 +295,8 @@ bool CEpgContainer::UpdateEntry(const CEpg &entry, bool bUpdateDatabase /* = fal
{
bReturn = epg->UpdateMetadata(entry, bUpdateDatabase);
m_epgs.insert(make_pair((unsigned int)epg->EpgID(), epg));
+ SetChanged();
+ epg->RegisterObserver(this);
}
}
else
@@ -301,12 +311,15 @@ bool CEpgContainer::UpdateEntry(const CEpg &entry, bool bUpdateDatabase /* = fal
{
DeleteEpg(*epg);
bReturn = false;
+ SetChanged();
}
}
m_bPreventUpdates = false;
CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
+ NotifyObservers("epg");
+
return bReturn;
}
@@ -372,6 +385,7 @@ bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = fal
if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.IsOpen())
m_database.Delete(*it->second);
+ it->second->UnregisterObserver(this);
delete it->second;
m_epgs.erase(it);
View
@@ -45,6 +45,11 @@ namespace EPG
friend class CEpgDatabase;
public:
+ /*!
+ * @brief Create a new EPG table container.
+ */
+ CEpgContainer(void);
+
/*!
* @brief Destroy this instance.
*/
@@ -256,11 +261,6 @@ namespace EPG
*/
virtual void Process(void);
- /*!
- * @brief Create a new EPG table container.
- */
- CEpgContainer(void);
-
/*!
* @brief Load all tables from the database
*/

0 comments on commit 49c2278

Please sign in to comment.