MythTV  master
dbsettings.cpp
Go to the documentation of this file.
1 // Qt headers
2 #include <QFile>
3 #include <QDir>
4 #include <QObject>
5 
6 // MythTV headers
9 
10 #include "dbsettings.h"
11 #include "mythcontext.h"
12 
13 DatabaseSettings::DatabaseSettings(QString DBhostOverride) :
14  m_dbHostOverride(std::move(DBhostOverride))
15 {
16  setLabel(DatabaseSettings::tr("Database Configuration"));
17 
19  if (query.isConnected())
20  {
22  DatabaseSettings::tr("All database settings take effect when "
23  "you restart this program."));
24  }
25  else
26  {
28  DatabaseSettings::tr("MythTV could not connect to the database. "
29  "Please verify your database settings "
30  "below."));
31  }
32 
34  m_dbHostName->setLabel(DatabaseSettings::tr("Hostname"));
36  DatabaseSettings::tr("The host name or IP address of "
37  "the machine hosting the database. "
38  "This information is required."));
40 
41  // Ping database host is no longer used
42 
44  m_dbPort->setLabel(DatabaseSettings::tr("Port"));
46  DatabaseSettings::tr("The port number the database is running "
47  "on. Leave blank if using the default "
48  "port (3306)."));
50 
52  m_dbName->setLabel(QCoreApplication::translate("(Common)",
53  "Database name"));
55  DatabaseSettings::tr("The name of the database. "
56  "This information is required."));
58 
60  m_dbUserName->setLabel(QCoreApplication::translate("(Common)", "User"));
62  DatabaseSettings::tr("The user name to use while "
63  "connecting to the database. "
64  "This information is required."));
66 
68  m_dbPassword->setLabel(DatabaseSettings::tr("Password"));
70  DatabaseSettings::tr("The password to use while "
71  "connecting to the database. "
72  "This information is required."));
74 
77  DatabaseSettings::tr("Use custom identifier for frontend "
78  "preferences"));
80  DatabaseSettings::tr("If this frontend's host name "
81  "changes often, check this box "
82  "and provide a network-unique "
83  "name to identify it. "
84  "If unchecked, the frontend "
85  "machine's local host name will "
86  "be used to save preferences in "
87  "the database."));
89 
91  m_localHostName->setLabel(DatabaseSettings::tr("Custom identifier"));
93  DatabaseSettings::tr("An identifier to use while "
94  "saving the settings for this "
95  "frontend."));
97 
100  DatabaseSettings::tr("Enable database server wakeup"));
102  DatabaseSettings::tr("If enabled, the frontend will use "
103  "database wakeup parameters to "
104  "reconnect to the database server."));
106 
107  m_wolReconnect = new TransMythUISpinBoxSetting(0, 60, 1, 1);
108  m_wolReconnect->setLabel(DatabaseSettings::tr("Reconnect time"));
110  DatabaseSettings::tr("The time in seconds to wait for "
111  "the server to wake up."));
113 
114  m_wolRetry = new TransMythUISpinBoxSetting(1, 10, 1, 1);
115  m_wolRetry->setLabel(DatabaseSettings::tr("Retry attempts"));
117  DatabaseSettings::tr("The number of retries to wake the "
118  "server before the frontend gives "
119  "up."));
121 
123  m_wolCommand->setLabel(DatabaseSettings::tr("Wake command or MAC"));
125  DatabaseSettings::tr("The command executed on this "
126  "frontend or server MAC to wake up the database "
127  "server (eg. sudo /etc/init.d/mysql "
128  "restart or 32:D2:86:00:17:A8)."));
130 }
131 
133 {
134  DatabaseParams params = GetMythDB()->GetDatabaseParams();
135 
136  if (params.m_dbHostName.isEmpty() ||
137  params.m_dbUserName.isEmpty() ||
138  params.m_dbPassword.isEmpty() ||
139  params.m_dbName.isEmpty())
140  {
141  setHelpText(getHelpText() + "\n" +
142  DatabaseSettings::tr("Required fields are"
143  " marked with an asterisk (*)."));
144  }
145 
146  if (params.m_dbHostName.isEmpty())
147  {
150  }
151  else
152  {
154  }
155 
156  if (params.m_dbPort)
157  m_dbPort->setValue(QString::number(params.m_dbPort));
158 
160  if (params.m_dbUserName.isEmpty())
163  if (params.m_dbPassword.isEmpty())
165  m_dbName->setValue(params.m_dbName);
166  if (params.m_dbName.isEmpty())
167  m_dbName->setLabel("* " + m_dbName->getLabel());
168 
171 
173  m_wolReconnect->setValue(params.m_wolReconnect.count());
174  m_wolRetry->setValue(params.m_wolRetry);
176  //set all the children's m_haveChanged to false
178 }
180 {
181  DatabaseParams params = GetMythDB()->GetDatabaseParams();
182 
183  params.m_dbHostName = m_dbHostName->getValue();
184  // Ping database host is no longer used
185  params.m_dbHostPing = false;
186  params.m_dbPort = m_dbPort->getValue().toInt();
187  params.m_dbUserName = m_dbUserName->getValue();
188  params.m_dbPassword = m_dbPassword->getValue();
189  params.m_dbName = m_dbName->getValue();
190  params.m_dbType = "QMYSQL";
191 
194 
195  params.m_wolEnabled = m_wolEnabled->boolValue();
196  params.m_wolReconnect = std::chrono::seconds(m_wolReconnect->intValue());
197  params.m_wolRetry = m_wolRetry->intValue();
198  params.m_wolCommand = m_wolCommand->getValue();
199 
200  gContext->SaveDatabaseParams(params);
201  //set all the children's m_haveChanged to false
203 }
204 
206 {
207  emit isClosing();
208 }
DatabaseSettings::DatabaseSettings
DatabaseSettings(QString DBhostOverride=QString())
Definition: dbsettings.cpp:13
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
DatabaseSettings::m_dbHostName
TransTextEditSetting * m_dbHostName
Definition: dbsettings.h:28
DatabaseParams::m_dbHostName
QString m_dbHostName
database server
Definition: mythdbparams.h:22
TransMythUICheckBoxSetting
Definition: standardsettings.h:411
StandardSetting::getLabel
QString getLabel(void) const
Definition: standardsettings.h:35
StandardSetting::setValue
virtual void setValue(const QString &newValue)
Definition: standardsettings.cpp:169
TransTextEditSetting
Definition: standardsettings.h:161
DatabaseParams
Structure containing the basic Database parameters.
Definition: mythdbparams.h:10
dbsettings.h
TransMythUISpinBoxSetting
Definition: standardsettings.h:353
mythdbcon.h
MythContext::SaveDatabaseParams
bool SaveDatabaseParams(const DatabaseParams &params, bool force=false)
Definition: mythcontext.cpp:1732
StandardSetting::addTargetedChild
void addTargetedChild(const QString &value, StandardSetting *setting)
Definition: standardsettings.cpp:116
DatabaseSettings::isClosing
void isClosing(void)
DatabaseParams::m_dbType
QString m_dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:28
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:50
DatabaseSettings::m_dbName
TransTextEditSetting * m_dbName
Definition: dbsettings.h:31
DatabaseSettings::m_wolReconnect
TransMythUISpinBoxSetting * m_wolReconnect
Definition: dbsettings.h:37
DatabaseSettings::m_localHostName
TransTextEditSetting * m_localHostName
Definition: dbsettings.h:35
DatabaseParams::m_wolReconnect
std::chrono::seconds m_wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:35
DatabaseSettings::m_dbHostOverride
QString m_dbHostOverride
Definition: dbsettings.h:40
StandardSetting::addChild
virtual void addChild(StandardSetting *child)
Definition: standardsettings.cpp:70
DatabaseParams::m_dbPort
int m_dbPort
database port
Definition: mythdbparams.h:24
DatabaseSettings::m_dbPort
TransTextEditSetting * m_dbPort
Definition: dbsettings.h:30
DatabaseParams::m_dbHostPing
bool m_dbHostPing
No longer used.
Definition: mythdbparams.h:23
DatabaseSettings::m_wolRetry
TransMythUISpinBoxSetting * m_wolRetry
Definition: dbsettings.h:38
DatabaseSettings::m_dbPassword
TransTextEditSetting * m_dbPassword
Definition: dbsettings.h:33
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
MythUISpinBoxSetting::intValue
int intValue()
Definition: standardsettings.cpp:685
StandardSetting::Load
virtual void Load(void)
Definition: standardsettings.cpp:213
StandardSetting::setHelpText
virtual void setHelpText(const QString &str)
Definition: standardsettings.h:37
StandardSetting::Save
virtual void Save(void)
Definition: standardsettings.cpp:232
StandardSetting::getValue
virtual QString getValue(void) const
Definition: standardsettings.h:52
DatabaseParams::m_dbPassword
QString m_dbPassword
DB password.
Definition: mythdbparams.h:26
DatabaseParams::m_wolRetry
int m_wolRetry
times to retry to reconnect
Definition: mythdbparams.h:36
DatabaseParams::m_dbName
QString m_dbName
database name
Definition: mythdbparams.h:27
MSqlQuery::isConnected
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:137
DatabaseSettings::m_wolCommand
TransTextEditSetting * m_wolCommand
Definition: dbsettings.h:39
StandardSetting::setLabel
virtual void setLabel(QString str)
Definition: standardsettings.h:34
DatabaseSettings::Save
void Save(void) override
Definition: dbsettings.cpp:179
DatabaseParams::m_wolCommand
QString m_wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:37
DatabaseParams::m_dbUserName
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:25
DatabaseSettings::Load
void Load(void) override
Definition: dbsettings.cpp:132
StandardSetting::getHelpText
QString getHelpText(void) const
Definition: standardsettings.h:38
mythcontext.h
DatabaseSettings::m_wolEnabled
TransMythUICheckBoxSetting * m_wolEnabled
Definition: dbsettings.h:36
DatabaseSettings::m_localEnabled
TransMythUICheckBoxSetting * m_localEnabled
Definition: dbsettings.h:34
DatabaseParams::m_localEnabled
bool m_localEnabled
true if localHostName is not default
Definition: mythdbparams.h:30
DatabaseSettings::~DatabaseSettings
~DatabaseSettings() override
Definition: dbsettings.cpp:205
DatabaseParams::m_wolEnabled
bool m_wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:34
MythUICheckBoxSetting::setValue
void setValue(const QString &newValue) override
Definition: standardsettings.cpp:732
DatabaseParams::m_localHostName
QString m_localHostName
name used for loading/saving settings
Definition: mythdbparams.h:31
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:64
DatabaseSettings::m_dbUserName
TransTextEditSetting * m_dbUserName
Definition: dbsettings.h:32
mythdbparams.h
MythUICheckBoxSetting::boolValue
bool boolValue()
Definition: standardsettings.h:403