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
7 #include "dbsettings.h"
8 #include "mythcontext.h"
9 #include "mythdbcon.h"
10 #include "mythdbparams.h"
11 
12 DatabaseSettings::DatabaseSettings(const QString &DBhostOverride)
13 {
14  m_DBhostOverride = 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 
42  m_dbHostPing->setLabel(DatabaseSettings::tr("Ping test server?"));
44  DatabaseSettings::tr("Test basic host connectivity using "
45  "the ping command. Turn off if your "
46  "host or network don't support ping "
47  "(ICMP ECHO) packets"));
49 
51  m_dbPort->setLabel(DatabaseSettings::tr("Port"));
53  DatabaseSettings::tr("The port number the database is running "
54  "on. Leave blank if using the default "
55  "port (3306)."));
57 
59  m_dbName->setLabel(QCoreApplication::translate("(Common)",
60  "Database name"));
62  DatabaseSettings::tr("The name of the database. "
63  "This information is required."));
65 
67  m_dbUserName->setLabel(QCoreApplication::translate("(Common)", "User"));
69  DatabaseSettings::tr("The user name to use while "
70  "connecting to the database. "
71  "This information is required."));
73 
75  m_dbPassword->setLabel(DatabaseSettings::tr("Password"));
77  DatabaseSettings::tr("The password to use while "
78  "connecting to the database. "
79  "This information is required."));
81 
84  DatabaseSettings::tr("Use custom identifier for frontend "
85  "preferences"));
87  DatabaseSettings::tr("If this frontend's host name "
88  "changes often, check this box "
89  "and provide a network-unique "
90  "name to identify it. "
91  "If unchecked, the frontend "
92  "machine's local host name will "
93  "be used to save preferences in "
94  "the database."));
96 
98  m_localHostName->setLabel(DatabaseSettings::tr("Custom identifier"));
100  DatabaseSettings::tr("An identifier to use while "
101  "saving the settings for this "
102  "frontend."));
104 
107  DatabaseSettings::tr("Enable database server wakeup"));
109  DatabaseSettings::tr("If enabled, the frontend will use "
110  "database wakeup parameters to "
111  "reconnect to the database server."));
113 
114  m_wolReconnect = new TransMythUISpinBoxSetting(0, 60, 1, 1);
115  m_wolReconnect->setLabel(DatabaseSettings::tr("Reconnect time"));
117  DatabaseSettings::tr("The time in seconds to wait for "
118  "the server to wake up."));
120 
121  m_wolRetry = new TransMythUISpinBoxSetting(1, 10, 1, 1);
122  m_wolRetry->setLabel(DatabaseSettings::tr("Retry attempts"));
124  DatabaseSettings::tr("The number of retries to wake the "
125  "server before the frontend gives "
126  "up."));
128 
130  m_wolCommand->setLabel(DatabaseSettings::tr("Wake command or MAC"));
132  DatabaseSettings::tr("The command executed on this "
133  "frontend or server MAC to wake up the database "
134  "server (eg. sudo /etc/init.d/mysql "
135  "restart or 32:D2:86:00:17:A8)."));
137 }
138 
140 {
142 
143  if (params.m_dbHostName.isEmpty() ||
144  params.m_dbUserName.isEmpty() ||
145  params.m_dbPassword.isEmpty() ||
146  params.m_dbName.isEmpty())
147  {
148  setHelpText(getHelpText() + "\n" +
149  DatabaseSettings::tr("Required fields are"
150  " marked with an asterisk (*)."));
151  }
152 
153  if (params.m_dbHostName.isEmpty())
154  {
157  }
158  else
160 
162 
163  if (params.m_dbPort)
164  m_dbPort->setValue(QString::number(params.m_dbPort));
165 
167  if (params.m_dbUserName.isEmpty())
170  if (params.m_dbPassword.isEmpty())
172  m_dbName->setValue(params.m_dbName);
173  if (params.m_dbName.isEmpty())
174  m_dbName->setLabel("* " + m_dbName->getLabel());
175 
178 
181  m_wolRetry->setValue(params.m_wolRetry);
183  //set all the children's m_haveChanged to false
185 }
187 {
189 
190  params.m_dbHostName = m_dbHostName->getValue();
191  params.m_dbHostPing = m_dbHostPing->boolValue();
192  params.m_dbPort = m_dbPort->getValue().toInt();
193  params.m_dbUserName = m_dbUserName->getValue();
194  params.m_dbPassword = m_dbPassword->getValue();
195  params.m_dbName = m_dbName->getValue();
196  params.m_dbType = "QMYSQL";
197 
200 
201  params.m_wolEnabled = m_wolEnabled->boolValue();
203  params.m_wolRetry = m_wolRetry->intValue();
204  params.m_wolCommand = m_wolCommand->getValue();
205 
206  gContext->SaveDatabaseParams(params);
207  //set all the children's m_haveChanged to false
209 }
210 
212 {
213  emit isClosing();
214 }
TransMythUISpinBoxSetting * m_wolReconnect
Definition: dbsettings.h:35
QString m_dbHostName
database server
Definition: mythdbparams.h:21
QString m_localHostName
name used for loading/saving settings
Definition: mythdbparams.h:30
TransTextEditSetting * m_dbHostName
Definition: dbsettings.h:26
bool m_localEnabled
true if localHostName is not default
Definition: mythdbparams.h:29
TransTextEditSetting * m_dbUserName
Definition: dbsettings.h:30
~DatabaseSettings() override
Definition: dbsettings.cpp:211
int m_wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:34
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
virtual void Load(void)
virtual void setHelpText(const QString &str)
void isClosing(void)
TransTextEditSetting * m_dbName
Definition: dbsettings.h:29
QString getLabel(void) const
DatabaseParams GetDatabaseParams(void)
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:62
QString m_dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:27
TransTextEditSetting * m_dbPort
Definition: dbsettings.h:28
virtual QString getValue(void) const
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:135
DatabaseSettings(const QString &DBhostOverride=QString())
Definition: dbsettings.cpp:12
TransMythUISpinBoxSetting * m_wolRetry
Definition: dbsettings.h:36
TransTextEditSetting * m_dbPassword
Definition: dbsettings.h:31
int m_wolRetry
times to retry to reconnect
Definition: mythdbparams.h:35
bool m_dbHostPing
Can we test connectivity using ping?
Definition: mythdbparams.h:22
MSqlQuery query(MSqlQuery::InitCon())
TransMythUICheckBoxSetting * m_dbHostPing
Definition: dbsettings.h:27
TransTextEditSetting * m_localHostName
Definition: dbsettings.h:33
virtual void setLabel(QString str)
QString m_dbName
database name
Definition: mythdbparams.h:26
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:24
QString m_dbPassword
DB password.
Definition: mythdbparams.h:25
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
virtual void addChild(StandardSetting *child)
int m_dbPort
database port
Definition: mythdbparams.h:23
virtual void Save(void)
void setValue(const QString &newValue) override
bool SaveDatabaseParams(const DatabaseParams &params)
bool m_wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:33
Structure containing the basic Database parameters.
Definition: mythdbparams.h:9
void Load(void) override
Definition: dbsettings.cpp:139
QString m_wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:36
TransMythUICheckBoxSetting * m_wolEnabled
Definition: dbsettings.h:34
TransMythUICheckBoxSetting * m_localEnabled
Definition: dbsettings.h:32
QString m_DBhostOverride
Definition: dbsettings.h:38
TransTextEditSetting * m_wolCommand
Definition: dbsettings.h:37
void Save(void) override
Definition: dbsettings.cpp:186
void addTargetedChild(const QString &value, StandardSetting *setting)
virtual void setValue(const QString &newValue)
QString getHelpText(void) const