[mythtv] patch: setting scope, fixschema
Andy Davidoff
dert at pobox.com
Mon Feb 24 05:13:31 EST 2003
Settings have scope set via MythContext::SetModule(QString) which
lets us shadow global settings on a per-module (as well as per-host)
basis. All settings are of global scope by default, and settings
updated or added via SetSetting() will default to local scope.
The database/fixschema tool updates the schema with this feature.
It should be run immediately after libmyth is rebuilt.
Much of the (Get|Set)Settings() logic was simplified into SQL in
this patch. This reduces the number of SELECTs per GetSetting().
This patch includes the prior SetSetting() patch necessarily;
fixschema depends upon this for properly convergent behavior.
#if Andy Davidoff /* Feb 24, 02:44 */
> This patch makes MythContext::SetSetting() save settings into the
> database. It defaults to updating settings for localhost context,
> but you can give it an optional 'true' argument to affect the global
> value for the given key.
#endif /* dert at pobox.com */
-------------- next part --------------
Index: mythtv.pro
===================================================================
RCS file: /var/lib/cvs/MC/mythtv.pro,v
retrieving revision 1.9
diff -d -u -w -r1.9 mythtv.pro
--- mythtv.pro 27 Sep 2002 20:05:38 -0000 1.9
+++ mythtv.pro 24 Feb 2003 09:56:45 -0000
@@ -5,4 +5,4 @@
TEMPLATE = subdirs
# Directories
-SUBDIRS += libs filters programs themes setup
+SUBDIRS += libs filters programs themes setup database
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.45
diff -d -u -w -r1.45 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp 22 Feb 2003 13:01:20 -0000 1.45
+++ libs/libmyth/mythcontext.cpp 24 Feb 2003 09:56:47 -0000
@@ -57,6 +57,8 @@
expectingReply = false;
lcd_device = new LCD();
+
+ SetModule("TV");
}
MythContext::~MythContext()
@@ -238,36 +240,26 @@
KickDatabase(m_db);
QString query = QString("SELECT data FROM settings WHERE value = '%1' "
- "AND hostname = '%2';")
- .arg(key).arg(m_localhostname);
+ "AND (hostname = '%2' OR hostname = '') AND "
+ "(FIND_IN_SET('%3', scope) OR "
+ "FIND_IN_SET('Any', scope)) ORDER BY hostname "
+ "DESC, FIND_IN_SET('%4', scope) DESC LIMIT 1;")
+ .arg(key).arg(m_localhostname)
+ .arg(moduleName).arg(moduleName);
QSqlQuery result = m_db->exec(query);
- if (result.isActive() && result.numRowsAffected() > 0)
- {
- result.next();
- value = result.value(0).toString();
- found = true;
- }
- else
- {
- query = QString("SELECT data FROM settings WHERE value = '%1' AND "
- "hostname IS NULL;").arg(key);
-
- result = m_db->exec(query);
-
- if (result.isActive() && result.numRowsAffected() > 0)
+ if (result.next())
{
- result.next();
value = result.value(0).toString();
found = true;
}
}
- }
pthread_mutex_unlock(&dbLock);
if (found)
return value;
+
return m_settings->GetSetting(key, defaultval);
}
@@ -282,32 +274,21 @@
KickDatabase(m_db);
QString query = QString("SELECT data FROM settings WHERE value = '%1' "
- "AND hostname = '%2';")
- .arg(key).arg(m_localhostname);
+ "AND (hostname = '%2' OR hostname = '') AND "
+ "(FIND_IN_SET('%3', scope) OR "
+ "FIND_IN_SET('Any', scope)) ORDER BY hostname "
+ "DESC, FIND_IN_SET('%4', scope) DESC LIMIT 1;")
+ .arg(key).arg(m_localhostname)
+ .arg(moduleName).arg(moduleName);
QSqlQuery result = m_db->exec(query);
- if (result.isActive() && result.numRowsAffected() > 0)
- {
- result.next();
- value = result.value(0).toString().toInt();
- found = true;
- }
- else
- {
- query = QString("SELECT data FROM settings WHERE value = '%1' AND "
- "hostname IS NULL;").arg(key);
-
- result = m_db->exec(query);
-
- if (result.isActive() && result.numRowsAffected() > 0)
+ if (result.next())
{
- result.next();
value = result.value(0).toString().toInt();
found = true;
}
}
- }
pthread_mutex_unlock(&dbLock);
@@ -497,7 +478,57 @@
void MythContext::SetSetting(const QString &key, const QString &newValue)
{
+ SetSetting(key, newValue, false);
+}
+
+void MythContext::SetSetting(const QString &key, const QString &newValue, bool global)
+{
+ QString where;
+ QString query;
+
m_settings->SetSetting(key, newValue);
+
+ where = QString("WHERE value = '%1' AND FIND_IN_SET('%2', scope)")
+ .arg(key).arg(moduleName);
+
+ if (global)
+ {
+ where += " AND (hostname = '' OR hostname IS NULL)";
+ }
+ else
+ {
+ where += " AND hostname = '" + m_localhostname + "'";
+ }
+
+ pthread_mutex_lock(&dbLock);
+ if (m_db->isOpen())
+ {
+ KickDatabase(m_db);
+
+ query = QString("SELECT data FROM settings " + where +
+ " ORDER BY FIND_IN_SET('%1', scope) DESC "
+ "LIMIT 1;").arg(moduleName);
+ QSqlQuery result = QSqlQuery(query, m_db);
+
+ if (0 < result.size())
+ {
+ if (newValue != result.value(0).asString())
+ query = QString("UPDATE settings SET data = '%1', "
+ "SET scope = CONCAT(scope, ',%2') %3;")
+ .arg(newValue).arg(moduleName).arg(where);
+ QSqlQuery(query, m_db);
+ }
+ else
+ {
+ query = QString("INSERT INTO settings (value, data, hostname, scope) "
+ "VALUES ('%1', '%2', '%3', '%4');")
+ .arg(key).arg(newValue)
+ .arg(global ? "" : m_localhostname)
+ .arg(moduleName);
+ QSqlQuery(query, m_db);
+ }
+ }
+ pthread_mutex_unlock(&dbLock);
}
void MythContext::SendReceiveStringList(QStringList &strlist)
@@ -511,6 +542,11 @@
expectingReply = false;
pthread_mutex_unlock(&serverSockLock);
+}
+
+void MythContext::SetModule(QString name)
+{
+ moduleName = name;
}
void MythContext::readSocket(void)
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmyth/mythcontext.h,v
retrieving revision 1.35
diff -d -u -w -r1.35 mythcontext.h
--- libs/libmyth/mythcontext.h 16 Feb 2003 19:25:37 -0000 1.35
+++ libs/libmyth/mythcontext.h 24 Feb 2003 09:56:47 -0000
@@ -78,11 +78,14 @@
int GetNumSetting(const QString &key, int defaultval = 0);
void SetSetting(const QString &key, const QString &newValue);
+ void SetSetting(const QString &key, const QString &newValue, bool global);
int GetBigFontSize() { return GetNumSetting("QtFontBig", 25); }
int GetMediumFontSize() { return GetNumSetting("QtFontMedium", 16); }
int GetSmallFontSize() { return GetNumSetting("QtFontSmall", 12); }
+ void SetModule(QString module);
+
void ThemeWidget(QWidget *widget);
QPixmap *LoadScalePixmap(QString filename);
@@ -124,6 +127,7 @@
QSocket *serverSock;
QString m_localhostname;
+ QString moduleName;
pthread_mutex_t serverSockLock;
bool expectingReply;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: settingscope.tar.gz
Type: application/x-tar-gz
Size: 1355 bytes
Desc: not available
Url : /pipermail/attachments/20030224/65f6bc71/settingscope.tar.bin
More information about the mythtv-dev
mailing list