diff --git a/mythtv/libs/libmyth/mythcontext.cpp b/mythtv/libs/libmyth/mythcontext.cpp
index b3dbf24..75b8271 100644
a
|
b
|
bool MythContext::Init(const bool gui, |
1178 | 1178 | return false; |
1179 | 1179 | } |
1180 | 1180 | |
| 1181 | gCoreContext->ActivateSettingsCache(true); |
| 1182 | |
1181 | 1183 | if (!d->Init(gui, promptForBackend, disableAutoDiscovery, ignoreDB)) |
1182 | 1184 | { |
1183 | 1185 | return false; |
1184 | 1186 | } |
1185 | 1187 | |
1186 | | gCoreContext->ActivateSettingsCache(true); |
1187 | | |
1188 | 1188 | return true; |
1189 | 1189 | } |
1190 | 1190 | |
diff --git a/mythtv/libs/libmyth/settings.h b/mythtv/libs/libmyth/settings.h
index 04bf691..d76a535 100644
a
|
b
|
class MPUBLIC TransListBoxSetting : |
673 | 673 | |
674 | 674 | /////////////////////////////////////////////////////////////////////////////// |
675 | 675 | |
676 | | class MPUBLIC HostSlider : public SliderSetting, public HostDBStorage |
| 676 | class MPUBLIC HostSlider : public SliderSetting, public HostSettingStorage |
677 | 677 | { |
678 | 678 | Q_OBJECT |
679 | 679 | public: |
680 | 680 | HostSlider(const QString &name, int min, int max, int step) : |
681 | 681 | SliderSetting(this, min, max, step), |
682 | | HostDBStorage(this, name) { } |
| 682 | HostSettingStorage(this, name) { } |
683 | 683 | }; |
684 | 684 | |
685 | | class MPUBLIC HostSpinBox: public SpinBoxSetting, public HostDBStorage |
| 685 | class MPUBLIC HostSpinBox: public SpinBoxSetting, public HostSettingStorage |
686 | 686 | { |
687 | 687 | Q_OBJECT |
688 | 688 | public: |
689 | 689 | HostSpinBox(const QString &name, int min, int max, int step, |
690 | 690 | bool allow_single_step = false) : |
691 | 691 | SpinBoxSetting(this, min, max, step, allow_single_step), |
692 | | HostDBStorage(this, name) { } |
| 692 | HostSettingStorage(this, name) { } |
693 | 693 | }; |
694 | 694 | |
695 | | class MPUBLIC HostCheckBox : public CheckBoxSetting, public HostDBStorage |
| 695 | class MPUBLIC HostCheckBox : public CheckBoxSetting, public HostSettingStorage |
696 | 696 | { |
697 | 697 | Q_OBJECT |
698 | 698 | public: |
699 | 699 | HostCheckBox(const QString &name) : |
700 | | CheckBoxSetting(this), HostDBStorage(this, name) { } |
| 700 | CheckBoxSetting(this), HostSettingStorage(this, name) { } |
701 | 701 | virtual ~HostCheckBox() { ; } |
702 | 702 | }; |
703 | 703 | |
704 | | class MPUBLIC HostComboBox : public ComboBoxSetting, public HostDBStorage |
| 704 | class MPUBLIC HostComboBox : public ComboBoxSetting, public HostSettingStorage |
705 | 705 | { |
706 | 706 | Q_OBJECT |
707 | 707 | public: |
708 | 708 | HostComboBox(const QString &name, bool rw = false) : |
709 | | ComboBoxSetting(this, rw), HostDBStorage(this, name) { } |
| 709 | ComboBoxSetting(this, rw), HostSettingStorage(this, name) { } |
710 | 710 | virtual ~HostComboBox() { ; } |
711 | 711 | }; |
712 | 712 | |
… |
… |
class MPUBLIC HostRefreshRateComboBox : public HostComboBox |
725 | 725 | static const vector<double> GetRefreshRates(const QString &resolution); |
726 | 726 | }; |
727 | 727 | |
728 | | class MPUBLIC HostTimeBox : public ComboBoxSetting, public HostDBStorage |
| 728 | class MPUBLIC HostTimeBox : public ComboBoxSetting, public HostSettingStorage |
729 | 729 | { |
730 | 730 | Q_OBJECT |
731 | 731 | public: |
732 | 732 | HostTimeBox(const QString &name, const QString &defaultTime = "00:00", |
733 | 733 | const int interval = 1) : |
734 | 734 | ComboBoxSetting(this, false, 30 / interval), |
735 | | HostDBStorage(this, name) |
| 735 | HostSettingStorage(this, name) |
736 | 736 | { |
737 | 737 | int hour; |
738 | 738 | int minute; |
… |
… |
class MPUBLIC HostTimeBox : public ComboBoxSetting, public HostDBStorage |
750 | 750 | } |
751 | 751 | }; |
752 | 752 | |
753 | | class MPUBLIC HostLineEdit: public LineEditSetting, public HostDBStorage |
| 753 | class MPUBLIC HostLineEdit: public LineEditSetting, public HostSettingStorage |
754 | 754 | { |
755 | 755 | Q_OBJECT |
756 | 756 | public: |
757 | 757 | HostLineEdit(const QString &name, bool rw = true) : |
758 | | LineEditSetting(this, rw), HostDBStorage(this, name) { } |
| 758 | LineEditSetting(this, rw), HostSettingStorage(this, name) { } |
759 | 759 | }; |
760 | 760 | |
761 | 761 | /////////////////////////////////////////////////////////////////////////////// |
diff --git a/mythtv/libs/libmythbase/mythdb.cpp b/mythtv/libs/libmythbase/mythdb.cpp
index e60fce0..a857321 100644
a
|
b
|
QString MythDB::GetSetting(const QString &_key, const QString &defaultval) |
376 | 376 | d->settingsCacheLock.unlock(); |
377 | 377 | return value; |
378 | 378 | } |
| 379 | d->settingsCacheLock.unlock(); |
| 380 | return defaultval; |
379 | 381 | } |
380 | 382 | SettingsMap::const_iterator it = d->overriddenSettings.find(key); |
381 | 383 | if (it != d->overriddenSettings.end()) |
… |
… |
QString MythDB::GetSettingOnHost(const QString &_key, const QString &_host, |
609 | 611 | d->settingsCacheLock.unlock(); |
610 | 612 | return value; |
611 | 613 | } |
| 614 | d->settingsCacheLock.unlock(); |
| 615 | return defaultval; |
612 | 616 | } |
613 | 617 | SettingsMap::const_iterator it = d->overriddenSettings.find(myKey); |
614 | 618 | if (it != d->overriddenSettings.end()) |
… |
… |
void MythDB::ClearSettingsCache(const QString &_key) |
855 | 859 | d->settingsCache[it.key()] = *it; |
856 | 860 | d->settingsCache[mk2] = *it; |
857 | 861 | } |
| 862 | |
| 863 | if (!d->useSettingsCache || d->ignoreDatabase || !HaveValidDatabase()) |
| 864 | { |
| 865 | d->settingsCacheLock.unlock(); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | MSqlQuery query(MSqlQuery::InitCon()); |
| 870 | if (!query.isConnected()) |
| 871 | { |
| 872 | d->settingsCacheLock.unlock(); |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | query.prepare( |
| 877 | "SELECT value, data " |
| 878 | "FROM settings " |
| 879 | "WHERE hostname = :HOSTNAME"); |
| 880 | query.bindValue(":HOSTNAME", d->m_localhostname); |
| 881 | |
| 882 | QString value; |
| 883 | QString data; |
| 884 | if (query.exec()) |
| 885 | while (query.next()) |
| 886 | { |
| 887 | value = query.value(0).toString(); |
| 888 | data = query.value(1).toString(); |
| 889 | |
| 890 | QString &cacheValue = d->settingsCache[value.toLower()]; |
| 891 | if( cacheValue.isEmpty() ) |
| 892 | { |
| 893 | cacheValue = data; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | if (!query.isConnected()) |
| 898 | { |
| 899 | d->settingsCacheLock.unlock(); |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | query.prepare( |
| 904 | "SELECT value, data " |
| 905 | "FROM settings " |
| 906 | "WHERE hostname IS NULL"); |
| 907 | |
| 908 | if (query.exec()) |
| 909 | while (query.next()) |
| 910 | { |
| 911 | value = query.value(0).toString(); |
| 912 | data = query.value(1).toString(); |
| 913 | |
| 914 | QString &cacheValue = d->settingsCache[value.toLower()]; |
| 915 | if( cacheValue.isEmpty() ) |
| 916 | { |
| 917 | cacheValue = data; |
| 918 | } |
| 919 | } |
858 | 920 | } |
859 | 921 | else |
860 | 922 | { |
diff --git a/mythtv/libs/libmythbase/mythstorage.cpp b/mythtv/libs/libmythbase/mythstorage.cpp
index d53e8f7..048d36f 100644
a
|
b
|
QString GlobalDBStorage::GetSetClause(MSqlBindings &bindings) const |
196 | 196 | |
197 | 197 | return clause; |
198 | 198 | } |
| 199 | |
| 200 | void HostSettingStorage::Load(void) |
| 201 | { |
| 202 | QString result = GetMythDB()->GetSetting(key, QString()); |
| 203 | if (!result.isNull()) |
| 204 | { |
| 205 | initval = result; |
| 206 | user->SetDBValue(result); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | void HostSettingStorage::Save(QString _table) |
| 211 | { |
| 212 | // not implementable, and not needed for settings |
| 213 | } |
| 214 | |
| 215 | void HostSettingStorage::Save(void) |
| 216 | { |
| 217 | if (!IsSaveRequired()) |
| 218 | return; |
| 219 | |
| 220 | GetMythDB()->SaveSetting(key, user->GetDBValue()); |
| 221 | } |
| 222 | |
| 223 | bool HostSettingStorage::IsSaveRequired(void) const |
| 224 | { |
| 225 | return user->GetDBValue() != initval; |
| 226 | } |
| 227 | |
| 228 | void HostSettingStorage::SetSaveRequired(void) |
| 229 | { |
| 230 | initval.clear(); |
| 231 | } |
diff --git a/mythtv/libs/libmythbase/mythstorage.h b/mythtv/libs/libmythbase/mythstorage.h
index 120ebc5..db0aa70 100644
a
|
b
|
class MBASE_PUBLIC GlobalDBStorage : public SimpleDBStorage |
129 | 129 | QString settingname; |
130 | 130 | }; |
131 | 131 | |
| 132 | class MBASE_PUBLIC HostSettingStorage : public Storage |
| 133 | { |
| 134 | public: |
| 135 | HostSettingStorage(StorageUser *_user, |
| 136 | QString _key) : user(_user), key(_key) |
| 137 | {} |
| 138 | virtual ~HostSettingStorage() { } |
| 139 | |
| 140 | virtual void Load(void); |
| 141 | virtual void Save(void); |
| 142 | virtual void Save(QString destination); |
| 143 | virtual bool IsSaveRequired(void) const; |
| 144 | virtual void SetSaveRequired(void); |
| 145 | |
| 146 | protected: |
| 147 | StorageUser *user; |
| 148 | QString key; |
| 149 | QString initval; |
| 150 | }; |
132 | 151 | /////////////////////////////////////////////////////////////////////////////// |
133 | 152 | |
134 | 153 | #endif // MYTHSTORAGE_H |