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())
21  DatabaseSettings::tr("All database settings take effect when "
22  "you restart this program."));
23  else
25  DatabaseSettings::tr("MythTV could not connect to the database. "
26  "Please verify your database settings "
27  "below."));
28 
30  m_dbHostName->setLabel(DatabaseSettings::tr("Hostname"));
32  DatabaseSettings::tr("The host name or IP address of "
33  "the machine hosting the database. "
34  "This information is required."));
36 
38  m_dbHostPing->setLabel(DatabaseSettings::tr("Ping test server?"));
40  DatabaseSettings::tr("Test basic host connectivity using "
41  "the ping command. Turn off if your "
42  "host or network don't support ping "
43  "(ICMP ECHO) packets"));
45 
47  m_dbPort->setLabel(DatabaseSettings::tr("Port"));
49  DatabaseSettings::tr("The port number the database is running "
50  "on. Leave blank if using the default "
51  "port (3306)."));
53 
55  m_dbName->setLabel(QCoreApplication::translate("(Common)",
56  "Database name"));
58  DatabaseSettings::tr("The name of the database. "
59  "This information is required."));
61 
63  m_dbUserName->setLabel(QCoreApplication::translate("(Common)", "User"));
65  DatabaseSettings::tr("The user name to use while "
66  "connecting to the database. "
67  "This information is required."));
69 
71  m_dbPassword->setLabel(DatabaseSettings::tr("Password"));
73  DatabaseSettings::tr("The password to use while "
74  "connecting to the database. "
75  "This information is required."));
77 
80  DatabaseSettings::tr("Use custom identifier for frontend "
81  "preferences"));
83  DatabaseSettings::tr("If this frontend's host name "
84  "changes often, check this box "
85  "and provide a network-unique "
86  "name to identify it. "
87  "If unchecked, the frontend "
88  "machine's local host name will "
89  "be used to save preferences in "
90  "the database."));
92 
94  m_localHostName->setLabel(DatabaseSettings::tr("Custom identifier"));
96  DatabaseSettings::tr("An identifier to use while "
97  "saving the settings for this "
98  "frontend."));
100 
103  DatabaseSettings::tr("Enable database server wakeup"));
105  DatabaseSettings::tr("If enabled, the frontend will use "
106  "database wakeup parameters to "
107  "reconnect to the database server."));
109 
110  m_wolReconnect = new TransMythUISpinBoxSetting(0, 60, 1, 1);
111  m_wolReconnect->setLabel(DatabaseSettings::tr("Reconnect time"));
113  DatabaseSettings::tr("The time in seconds to wait for "
114  "the server to wake up."));
116 
117  m_wolRetry = new TransMythUISpinBoxSetting(1, 10, 1, 1);
118  m_wolRetry->setLabel(DatabaseSettings::tr("Retry attempts"));
120  DatabaseSettings::tr("The number of retries to wake the "
121  "server before the frontend gives "
122  "up."));
124 
126  m_wolCommand->setLabel(DatabaseSettings::tr("Wake command or MAC"));
128  DatabaseSettings::tr("The command executed on this "
129  "frontend or server MAC to wake up the database "
130  "server (eg. sudo /etc/init.d/mysql "
131  "restart or 32:D2:86:00:17:A8)."));
133 }
134 
136 {
138 
139  if (params.dbHostName.isEmpty() ||
140  params.dbUserName.isEmpty() ||
141  params.dbPassword.isEmpty() ||
142  params.dbName.isEmpty())
143  setHelpText(getHelpText() + "\n" +
144  DatabaseSettings::tr("Required fields are"
145  " marked with an asterisk (*)."));
146 
147  if (params.dbHostName.isEmpty())
148  {
151  }
152  else
154 
156 
157  if (params.dbPort)
158  m_dbPort->setValue(QString::number(params.dbPort));
159 
161  if (params.dbUserName.isEmpty())
164  if (params.dbPassword.isEmpty())
166  m_dbName->setValue(params.dbName);
167  if (params.dbName.isEmpty())
168  m_dbName->setLabel("* " + m_dbName->getLabel());
169 
172 
175  m_wolRetry->setValue(params.wolRetry);
177  //set all the children's m_haveChanged to false
179 }
181 {
183 
184  params.dbHostName = m_dbHostName->getValue();
185  params.dbHostPing = m_dbHostPing->boolValue();
186  params.dbPort = m_dbPort->getValue().toInt();
187  params.dbUserName = m_dbUserName->getValue();
188  params.dbPassword = m_dbPassword->getValue();
189  params.dbName = m_dbName->getValue();
190  params.dbType = "QMYSQL";
191 
194 
195  params.wolEnabled = m_wolEnabled->boolValue();
197  params.wolRetry = m_wolRetry->intValue();
198  params.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 }
TransMythUISpinBoxSetting * m_wolReconnect
Definition: dbsettings.h:35
bool wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:33
QString wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:36
QString dbName
database name
Definition: mythdbparams.h:26
TransTextEditSetting * m_dbHostName
Definition: dbsettings.h:26
TransTextEditSetting * m_dbUserName
Definition: dbsettings.h:30
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
bool isConnected(void)
Only updated once during object creation.
Definition: mythdbcon.h:135
QString getLabel(void) const
DatabaseParams GetDatabaseParams(void)
bool localEnabled
true if localHostName is not default
Definition: mythdbparams.h:29
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:63
TransTextEditSetting * m_dbPort
Definition: dbsettings.h:28
virtual QString getValue(void) const
QString dbPassword
DB password.
Definition: mythdbparams.h:25
DatabaseSettings(const QString &DBhostOverride=QString())
Definition: dbsettings.cpp:12
TransMythUISpinBoxSetting * m_wolRetry
Definition: dbsettings.h:36
TransTextEditSetting * m_dbPassword
Definition: dbsettings.h:31
QString dbUserName
DB user name.
Definition: mythdbparams.h:24
TransMythUICheckBoxSetting * m_dbHostPing
Definition: dbsettings.h:27
TransTextEditSetting * m_localHostName
Definition: dbsettings.h:33
virtual void setLabel(QString str)
QString dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:27
bool dbHostPing
Can we test connectivity using ping?
Definition: mythdbparams.h:22
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
int wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:34
virtual void addChild(StandardSetting *child)
virtual void Save(void)
bool SaveDatabaseParams(const DatabaseParams &params)
Structure containing the basic Database parameters.
Definition: mythdbparams.h:9
QString dbHostName
database server
Definition: mythdbparams.h:21
void Load(void) override
Definition: dbsettings.cpp:135
void setValue(const QString &) override
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:180
QString localHostName
name used for loading/saving settings
Definition: mythdbparams.h:30
int dbPort
database port
Definition: mythdbparams.h:23
void addTargetedChild(const QString &value, StandardSetting *setting)
int wolRetry
times to retry to reconnect
Definition: mythdbparams.h:35
virtual void setValue(const QString &newValue)
QString getHelpText(void) const