Ticket #7616: 7616-fixes-v1.patch

File 7616-fixes-v1.patch, 6.4 KB (added by danielk, 11 years ago)

untested patch

  • libs/libmythdb/mythdb.cpp

     
    1212
    1313unsigned int db_messages = VB_IMPORTANT | VB_GENERAL;
    1414
     15// For thread safety reasons this is not a QString
     16const char *kSentinelValue = "<settings_sentinel_value>";
     17
    1518MythDB *MythDB::getMythDB(void)
    1619{
    1720    if (mythdb)
     
    302305
    303306    d->settingsCacheLock.lock();
    304307
    305     value = d->settingsCache.value(key, "_cold_");
     308    value = d->settingsCache.value(key, kSentinelValue);
    306309
    307310    d->settingsCacheLock.unlock();
    308311
    309     if (value != "_cold_" && d->useSettingsCache)
     312    if (d->useSettingsCache && value != kSentinelValue)
    310313        return value;
    311314
    312315    bool found = false;
     
    353356    }
    354357
    355358    if (!found)
    356         return d->m_settings->GetSetting(key, defaultval);
     359        value = d->m_settings->GetSetting(key, defaultval);
    357360
    358     // Do not store default values since they may not have been specified.
    359     if (!value.isNull() && d->useSettingsCache)
     361    if (d->useSettingsCache && value != kSentinelValue)
    360362    {
    361363        d->settingsCacheLock.lock();
    362364        d->settingsCache[key] = value;
     
    382384    return retval.toDouble();
    383385}
    384386
     387QString MythDB::GetSetting(const QString &key)
     388{
     389    QString sentinel = QString(kSentinelValue);
     390    QString retval = GetSetting(key, sentinel);
     391    return (retval == sentinel) ? "" : retval;
     392}
     393
     394int MythDB::GetNumSetting(const QString &key)
     395{
     396    QString sentinel = QString(kSentinelValue);
     397    QString retval = GetSetting(key, sentinel);
     398    return (retval == sentinel) ? 0 : retval.toInt();
     399}
     400
     401double MythDB::GetFloatSetting(const QString &key)
     402{
     403    QString sentinel = QString(kSentinelValue);
     404    QString retval = GetSetting(key, sentinel);
     405    return (retval == sentinel) ? 0.0 : retval.toDouble();
     406}
     407
    385408QString MythDB::GetSettingOnHost(const QString &key, const QString &host,
    386409                                      const QString &defaultval)
    387410{
     
    425448            query.bindValue(":VALUE", key);
    426449            query.bindValue(":HOSTNAME", host);
    427450
    428             if (query.exec() && query.isActive() && query.size() > 0)
     451            if (query.exec() && query.next())
    429452            {
    430                 if (query.next())
    431                 {
    432                     value = query.value(0).toString();
    433                     found = true;
    434                 }
     453                value = query.value(0).toString();
    435454            }
    436455        }
    437456        else
     
    443462        }
    444463    }
    445464
    446     if (found && d->useSettingsCache)
     465    if (d->useSettingsCache && value != kSentinelValue)
    447466    {
    448467        d->settingsCacheLock.lock();
    449468        d->settingsCache[host + ' ' + key] = value;
     
    471490    return retval.toDouble();
    472491}
    473492
     493QString MythDB::GetSettingOnHost(const QString &key, const QString &host)
     494{
     495    QString sentinel = QString(kSentinelValue);
     496    QString retval = GetSettingOnHost(key, host, sentinel);
     497    return (retval == sentinel) ? "" : retval;
     498}
     499
     500int MythDB::GetNumSettingOnHost(const QString &key, const QString &host)
     501{
     502    QString sentinel = QString(kSentinelValue);
     503    QString retval = GetSettingOnHost(key, host, sentinel);
     504    return (retval == sentinel) ? 0 : retval.toInt();
     505}
     506
     507double MythDB::GetFloatSettingOnHost(const QString &key, const QString &host)
     508{
     509    QString sentinel = QString(kSentinelValue);
     510    QString retval = GetSettingOnHost(key, host, sentinel);
     511    return (retval == sentinel) ? 0.0 : retval.toDouble();
     512}
     513
    474514void MythDB::SetSetting(const QString &key, const QString &newValue)
    475515{
    476516    d->m_settings->SetSetting(key, newValue);
  • libs/libmythdb/mythversion.h

     
    88/// Update this whenever the plug-in API changes.
    99/// Including changes in the libmythdb, libmyth and libmythui class methods
    1010/// used by plug-ins.
    11 #define MYTH_BINARY_VERSION "0.22.20091023-1"
     11#define MYTH_BINARY_VERSION "0.22.20091119-1"
    1212
    1313/** \brief Increment this whenever the MythTV network protocol changes.
    1414 *
  • libs/libmythdb/mythdb.h

     
    4141    bool SaveSettingOnHost(const QString &key, const QString &newValue,
    4242                           const QString &host);
    4343
    44     QString GetSetting(const QString &key, const QString &defaultval = "");
    45     int GetNumSetting(const QString &key, int defaultval = 0);
    46     double GetFloatSetting(const QString &key, double defaultval = 0.0);
     44    QString GetSetting(     const QString &key, const QString &defaultval);
     45    int     GetNumSetting(  const QString &key, int            defaultval);
     46    double  GetFloatSetting(const QString &key, double         defaultval);
     47
     48    QString GetSetting(     const QString &key);
     49    int     GetNumSetting(  const QString &key);
     50    double  GetFloatSetting(const QString &key);
     51
     52    QString GetSettingOnHost(
     53        const QString &key, const QString &host, const QString &defaultval);
     54    int     GetNumSettingOnHost(
     55        const QString &key, const QString &host, int            defaultval);
     56    double  GetFloatSettingOnHost(
     57        const QString &key, const QString &host, double         defaultval);
     58
     59    QString GetSettingOnHost(     const QString &key, const QString &host);
     60    int     GetNumSettingOnHost(  const QString &key, const QString &host);
     61    double  GetFloatSettingOnHost(const QString &key, const QString &host);
     62
    4763    void GetResolutionSetting(const QString &type, int &width, int &height,
    4864                              double& forced_aspect, double &refreshrate,
    4965                              int index=-1);
    5066    void GetResolutionSetting(const QString &type, int &width, int &height,
    5167                              int index=-1);
    5268
    53     QString GetSettingOnHost(const QString &key, const QString &host,
    54                              const QString &defaultval = "");
    55     int GetNumSettingOnHost(const QString &key, const QString &host,
    56                             int defaultval = 0);
    57     double GetFloatSettingOnHost(const QString &key, const QString &host,
    58                                  double defaultval = 0.0);
    59 
    6069    void SetSetting(const QString &key, const QString &newValue);
    6170
    6271    static MythDB *getMythDB();