Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Add state bool for user changed icons. Only update backend icons if n…
Browse files Browse the repository at this point in the history
…ot user changed.
  • Loading branch information
mikrohard authored and opdenkamp committed Mar 16, 2012
1 parent c4a845e commit 5547b90
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
18 changes: 11 additions & 7 deletions xbmc/pvr/PVRDatabase.cpp
Expand Up @@ -73,6 +73,7 @@ bool CPVRDatabase::CreateTables()
"iUniqueId integer, "
"bIsRadio bool, "
"bIsHidden bool, "
"bIsUserSetIcon bool, "
"sIconPath varchar(255), "
"sChannelName varchar(64), "
"bIsVirtual bool, "
Expand Down Expand Up @@ -255,6 +256,8 @@ bool CPVRDatabase::UpdateOldVersion(int iVersion)
database.Close();
}
}
if (iVersion < 20)
m_pDS->exec("ALTER TABLE channels ADD bIsUserSetIcon bool;");
}
}
catch (...)
Expand Down Expand Up @@ -315,11 +318,11 @@ int CPVRDatabase::Persist(const CPVRChannel &channel, bool bQueueWrite /* = fals
{
/* new channel */
strQuery = FormatSQL("INSERT INTO channels ("
"iUniqueId, bIsRadio, bIsHidden, "
"iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, "
"sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, "
"iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idEpg) "
"VALUES (%i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i);",
channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0),
"VALUES (%i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i);",
channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0),
channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(),
channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(),
channel.EpgID());
Expand All @@ -328,11 +331,11 @@ int CPVRDatabase::Persist(const CPVRChannel &channel, bool bQueueWrite /* = fals
{
/* update channel */
strQuery = FormatSQL("REPLACE INTO channels ("
"iUniqueId, bIsRadio, bIsHidden, "
"iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, "
"sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, "
"iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idChannel, idEpg) "
"VALUES (%i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i, %i);",
channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0),
"VALUES (%i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i, %i);",
channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0),
channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(),
channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID(),
channel.EpgID());
Expand Down Expand Up @@ -365,7 +368,7 @@ int CPVRDatabase::Get(CPVRChannelGroupInternal &results)
{
int iReturn = 0;

CStdString strQuery = FormatSQL("SELECT channels.idChannel, channels.iUniqueId, channels.bIsRadio, channels.bIsHidden, "
CStdString strQuery = FormatSQL("SELECT channels.idChannel, channels.iUniqueId, channels.bIsRadio, channels.bIsHidden, channels.bIsUserSetIcon, "
"channels.sIconPath, channels.sChannelName, channels.bIsVirtual, channels.bEPGEnabled, channels.sEPGScraper, channels.iLastWatched, channels.iClientId, "
"channels.iClientChannelNumber, channels.sInputFormat, channels.sInputFormat, channels.sStreamURL, channels.iEncryptionSystem, map_channelgroups_channels.iChannelNumber, channels.idEpg "
"FROM map_channelgroups_channels "
Expand All @@ -383,6 +386,7 @@ int CPVRDatabase::Get(CPVRChannelGroupInternal &results)
channel->m_iUniqueId = m_pDS->fv("iUniqueId").get_asInt();
channel->m_bIsRadio = m_pDS->fv("bIsRadio").get_asBool();
channel->m_bIsHidden = m_pDS->fv("bIsHidden").get_asBool();
channel->m_bIsUserSetIcon = m_pDS->fv("bIsUserSetIcon").get_asBool();
channel->m_strIconPath = m_pDS->fv("sIconPath").get_asString();
channel->m_strChannelName = m_pDS->fv("sChannelName").get_asString();
channel->m_bIsVirtual = m_pDS->fv("bIsVirtual").get_asBool();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/PVRDatabase.h
Expand Up @@ -57,7 +57,7 @@ namespace PVR
* @brief Get the minimal database version that is required to operate correctly.
* @return The minimal database version.
*/
virtual int GetMinVersion() const { return 19; };
virtual int GetMinVersion() const { return 20; };

/*!
* @brief Get the default sqlite database filename.
Expand Down
19 changes: 16 additions & 3 deletions xbmc/pvr/channels/PVRChannel.cpp
Expand Up @@ -61,6 +61,7 @@ CPVRChannel::CPVRChannel(bool bRadio /* = false */)
m_iChannelId = -1;
m_bIsRadio = bRadio;
m_bIsHidden = false;
m_bIsUserSetIcon = false;
m_strIconPath = StringUtils::EmptyString;
m_strChannelName = StringUtils::EmptyString;
m_bIsVirtual = false;
Expand Down Expand Up @@ -88,6 +89,7 @@ CPVRChannel::CPVRChannel(const PVR_CHANNEL &channel, unsigned int iClientId)
m_iChannelId = -1;
m_bIsRadio = channel.bIsRadio;
m_bIsHidden = channel.bIsHidden;
m_bIsUserSetIcon = false;
m_strIconPath = channel.strIconPath;
m_strChannelName = channel.strChannelName;
m_iUniqueId = channel.iUniqueId;
Expand Down Expand Up @@ -123,6 +125,7 @@ CPVRChannel &CPVRChannel::operator=(const CPVRChannel &channel)
m_iChannelId = channel.m_iChannelId;
m_bIsRadio = channel.m_bIsRadio;
m_bIsHidden = channel.m_bIsHidden;
m_bIsUserSetIcon = channel.m_bIsUserSetIcon;
m_strIconPath = channel.m_strIconPath;
m_strChannelName = channel.m_strChannelName;
m_bIsVirtual = channel.m_bIsVirtual;
Expand Down Expand Up @@ -192,7 +195,7 @@ bool CPVRChannel::UpdateFromClient(const CPVRChannel &channel)
CSingleLock lock(m_critSection);
if (m_strChannelName.IsEmpty())
SetChannelName(channel.ClientChannelName());
if (m_strIconPath.IsEmpty()||!m_strIconPath.Equals(channel.IconPath()))
if (m_strIconPath.IsEmpty()||(!m_strIconPath.Equals(channel.IconPath()) && !IsUserSetIcon()))
SetIconPath(channel.IconPath());

return m_bChanged;
Expand Down Expand Up @@ -281,13 +284,13 @@ bool CPVRChannel::IsRecording(void) const
return g_PVRTimers->IsRecordingOnChannel(*this);
}

bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bSaveInDb /* = false */)
bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bSaveInDb /* = false */, bool bIsUserSetIcon /* = false */)
{
bool bReturn(true); // different from the behaviour of the rest of this class
CSingleLock lock(m_critSection);

/* check if the path is valid */
if (!CFile::Exists(strIconPath))
if (!CFile::Exists(strIconPath) && !strIconPath.IsEmpty())
return false;

if (m_strIconPath != strIconPath)
Expand All @@ -297,6 +300,16 @@ bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bSaveInDb /* =
SetChanged();
m_bChanged = true;

/* did the user change the icon? */
if (bIsUserSetIcon) {
if (!m_strIconPath.IsEmpty()) {
m_bIsUserSetIcon = true;
}
else {
m_bIsUserSetIcon = false;
}
}

/* persist the changes */
if (bSaveInDb)
Persist();
Expand Down
10 changes: 9 additions & 1 deletion xbmc/pvr/channels/PVRChannel.h
Expand Up @@ -58,6 +58,7 @@ namespace PVR
int m_iChannelId; /*!< the identifier given to this channel by the TV database */
bool m_bIsRadio; /*!< true if this channel is a radio channel, false if not */
bool m_bIsHidden; /*!< true if this channel is hidden, false if not */
bool m_bIsUserSetIcon; /*!< true if user set the icon via GUI, false if not */
CStdString m_strIconPath; /*!< the path to the icon for this channel */
CStdString m_strChannelName; /*!< the name for this channel used by XBMC */
bool m_bIsVirtual; /*!< true if this channel is marked as virtual, false if not */
Expand Down Expand Up @@ -180,13 +181,20 @@ namespace PVR
*/
const CStdString &IconPath(void) const { return m_strIconPath; }

/*!
* @brief True if this user changed icon via GUI. False if not.
* @return True if this user changed icon via GUI. False if not.
*/
bool IsUserSetIcon(void) const { return m_bIsUserSetIcon; }

/*!
* @brief Set the path to the icon for this channel.
* @param strIconPath The new path.
* @param bSaveInDb Save in the database or not.
* @param bIsUserSetIcon true if user changed the icon via GUI, false otherwise.
* @return True if the something changed, false otherwise.
*/
bool SetIconPath(const CStdString &strIconPath, bool bSaveInDb = false);
bool SetIconPath(const CStdString &strIconPath, bool bSaveInDb = false, bool bIsUserSetIcon = false);

/*!
* @brief The name for this channel used by XBMC.
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/windows/GUIWindowPVRChannels.cpp
Expand Up @@ -448,7 +448,7 @@ bool CGUIWindowPVRChannels::OnContextButtonSetThumb(CFileItem *item, CONTEXT_BUT
if (strThumb == "thumb://None")
strThumb = "";

channel->SetIconPath(strThumb, true);
channel->SetIconPath(strThumb, true, true);
UpdateData();
}

Expand Down

0 comments on commit 5547b90

Please sign in to comment.