00001 #include <QFile>
00002 #include <QDir>
00003
00004 #include "dbsettings.h"
00005 #include "mythcontext.h"
00006 #include "mythdbcon.h"
00007 #include "mythdbparams.h"
00008
00009 class MythDbSettings1: public VerticalConfigurationGroup {
00010 public:
00011 MythDbSettings1(const QString &DBhostOverride = QString::null);
00012
00013 void Load(void);
00014 void Save(void);
00015 void Save(QString ) { Save(); }
00016
00017 protected:
00018 TransLabelSetting *info;
00019 TransLineEditSetting *dbHostName;
00020 TransCheckBoxSetting *dbHostPing;
00021 TransLineEditSetting *dbPort;
00022 TransLineEditSetting *dbName;
00023 TransLineEditSetting *dbUserName;
00024 TransLineEditSetting *dbPassword;
00025
00026
00027 QString m_DBhostOverride;
00028 };
00029
00030 class MythDbSettings2: public VerticalConfigurationGroup {
00031 public:
00032 MythDbSettings2();
00033
00034 void Load(void);
00035 void Save(void);
00036 void Save(QString ) { Save(); }
00037
00038 protected:
00039 TransCheckBoxSetting *localEnabled;
00040 TransLineEditSetting *localHostName;
00041 TransCheckBoxSetting *wolEnabled;
00042 TransSpinBoxSetting *wolReconnect;
00043 TransSpinBoxSetting *wolRetry;
00044 TransLineEditSetting *wolCommand;
00045 };
00046
00047
00048
00049 class LocalHostNameSettings : public TriggeredConfigurationGroup
00050 {
00051 public:
00052 LocalHostNameSettings(Setting *checkbox, ConfigurationGroup *group) :
00053 TriggeredConfigurationGroup(false, false, false, false)
00054 {
00055 setLabel(QObject::tr("Use custom identifier for frontend preferences"));
00056 addChild(checkbox);
00057 setTrigger(checkbox);
00058
00059 addTarget("1", group);
00060 addTarget("0", new VerticalConfigurationGroup(true));
00061 }
00062 };
00063
00064 class WOLsqlSettings : public TriggeredConfigurationGroup
00065 {
00066 public:
00067 WOLsqlSettings(Setting *checkbox, ConfigurationGroup *group) :
00068 TriggeredConfigurationGroup(false, false, false, false)
00069 {
00070 setLabel(QObject::tr("Backend Server Wakeup settings"));
00071
00072 addChild(checkbox);
00073 setTrigger(checkbox);
00074
00075 addTarget("1", group);
00076 addTarget("0", new VerticalConfigurationGroup(true));
00077 }
00078 };
00079
00080 MythDbSettings1::MythDbSettings1(const QString &DbHostOverride) :
00081 VerticalConfigurationGroup(false, true, false, false)
00082 {
00083 m_DBhostOverride = DbHostOverride;
00084
00085 setLabel(QObject::tr("Database Configuration") + " 1/2");
00086
00087 info = new TransLabelSetting();
00088
00089 MSqlQuery query(MSqlQuery::InitCon());
00090 if (query.isConnected())
00091 info->setValue(QObject::tr("All database settings take effect when "
00092 "you restart this program."));
00093 else
00094 info->setValue(QObject::tr("MythTV could not connect to the database. "
00095 "Please verify your database settings "
00096 "below."));
00097 addChild(info);
00098
00099 VerticalConfigurationGroup* dbServer = new VerticalConfigurationGroup();
00100 dbServer->setLabel(QObject::tr("Database Server Settings"));
00101 dbHostName = new TransLineEditSetting(true);
00102 dbHostName->setLabel(QObject::tr("Hostname"));
00103 dbHostName->setHelpText(QObject::tr("The host name or IP address of "
00104 "the machine hosting the database. "
00105 "This information is required."));
00106 dbServer->addChild(dbHostName);
00107
00108 HorizontalConfigurationGroup* g =
00109 new HorizontalConfigurationGroup(false, false);
00110
00111 dbHostPing = new TransCheckBoxSetting();
00112 dbHostPing->setLabel(QObject::tr("Ping test server?"));
00113 dbHostPing->setHelpText(QObject::tr("Test basic host connectivity using "
00114 "the ping command. Turn off if your "
00115 "host or network don't support ping "
00116 "(ICMP ECHO) packets"));
00117 g->addChild(dbHostPing);
00118
00119
00120 TransLabelSetting *l = new TransLabelSetting();
00121 l->setValue(" ");
00122 g->addChild(l);
00123
00124 dbServer->addChild(g);
00125
00126 dbPort = new TransLineEditSetting(true);
00127 dbPort->setLabel(QObject::tr("Port"));
00128 dbPort->setHelpText(QObject::tr("The port number the database is running "
00129 "on. Leave blank if using the default "
00130 "port (3306)."));
00131 g->addChild(dbPort);
00132
00133 dbName = new TransLineEditSetting(true);
00134 dbName->setLabel(QObject::tr("Database name"));
00135 dbName->setHelpText(QObject::tr("The name of the database. "
00136 "This information is required."));
00137 dbServer->addChild(dbName);
00138
00139 dbUserName = new TransLineEditSetting(true);
00140 dbUserName->setLabel(QObject::tr("User"));
00141 dbUserName->setHelpText(QObject::tr("The user name to use while "
00142 "connecting to the database. "
00143 "This information is required."));
00144 dbServer->addChild(dbUserName);
00145
00146 dbPassword = new TransLineEditSetting(true);
00147 dbPassword->setLabel(QObject::tr("Password"));
00148 dbPassword->setHelpText(QObject::tr("The password to use while "
00149 "connecting to the database. "
00150 "This information is required."));
00151 dbServer->addChild(dbPassword);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 addChild(dbServer);
00163
00164 }
00165
00166 MythDbSettings2::MythDbSettings2(void) :
00167 VerticalConfigurationGroup(false, true, false, false)
00168 {
00169 setLabel(QObject::tr("Database Configuration") + " 2/2");
00170
00171 localEnabled = new TransCheckBoxSetting();
00172 localEnabled->setLabel(QObject::tr("Use custom identifier for frontend "
00173 "preferences"));
00174 localEnabled->setHelpText(QObject::tr("If this frontend's host name "
00175 "changes often, check this box "
00176 "and provide a network-unique "
00177 "name to identify it. "
00178 "If unchecked, the frontend "
00179 "machine's local host name will "
00180 "be used to save preferences in "
00181 "the database."));
00182
00183 localHostName = new TransLineEditSetting(true);
00184 localHostName->setLabel(QObject::tr("Custom identifier"));
00185 localHostName->setHelpText(QObject::tr("An identifier to use while "
00186 "saving the settings for this "
00187 "frontend."));
00188
00189 VerticalConfigurationGroup *group1 =
00190 new VerticalConfigurationGroup(false);
00191 group1->addChild(localHostName);
00192
00193 LocalHostNameSettings *sub3 =
00194 new LocalHostNameSettings(localEnabled, group1);
00195 addChild(sub3);
00196
00197 wolEnabled = new TransCheckBoxSetting();
00198 wolEnabled->setLabel(QObject::tr("Enable database server wakeup"));
00199 wolEnabled->setHelpText(QObject::tr("If enabled, the frontend will use "
00200 "database wakeup parameters to "
00201 "reconnect to the database server."));
00202
00203 wolReconnect = new TransSpinBoxSetting(0, 60, 1, true);
00204 wolReconnect->setLabel(QObject::tr("Reconnect time"));
00205 wolReconnect->setHelpText(QObject::tr("The time in seconds to wait for "
00206 "the server to wake up."));
00207
00208 wolRetry = new TransSpinBoxSetting(1, 10, 1, true);
00209 wolRetry->setLabel(QObject::tr("Retry attempts"));
00210 wolRetry->setHelpText(QObject::tr("The number of retries to wake the "
00211 "server before the frontend gives "
00212 "up."));
00213
00214 wolCommand = new TransLineEditSetting(true);
00215 wolCommand->setLabel(QObject::tr("Wake command"));
00216 wolCommand->setHelpText(QObject::tr("The command executed on this "
00217 "frontend to wake up the database "
00218 "server (eg. sudo /etc/init.d/mysql "
00219 "restart)."));
00220
00221 HorizontalConfigurationGroup *group2 =
00222 new HorizontalConfigurationGroup(false, false);
00223 group2->addChild(wolReconnect);
00224 group2->addChild(wolRetry);
00225
00226 VerticalConfigurationGroup *group3 =
00227 new VerticalConfigurationGroup(false);
00228 group3->addChild(group2);
00229 group3->addChild(wolCommand);
00230
00231 WOLsqlSettings *sub4 =
00232 new WOLsqlSettings(wolEnabled, group3);
00233 addChild(sub4);
00234 }
00235
00236 void MythDbSettings1::Load(void)
00237 {
00238 DatabaseParams params = gContext->GetDatabaseParams();
00239
00240 if (params.dbHostName.isEmpty() ||
00241 params.dbUserName.isEmpty() ||
00242 params.dbPassword.isEmpty() ||
00243 params.dbName.isEmpty())
00244 info->setValue(info->getValue() + "\n" +
00245 QObject::tr("Required fields are"
00246 " marked with an asterisk (*)."));
00247
00248 if (params.dbHostName.isEmpty())
00249 {
00250 dbHostName->setLabel("* " + dbHostName->getLabel());
00251 dbHostName->setValue(m_DBhostOverride);
00252 }
00253 else
00254 dbHostName->setValue(params.dbHostName);
00255
00256 dbHostPing->setValue(params.dbHostPing);
00257
00258 if (params.dbPort)
00259 dbPort->setValue(QString::number(params.dbPort));
00260
00261 dbUserName->setValue(params.dbUserName);
00262 if (params.dbUserName.isEmpty())
00263 dbUserName->setLabel("* " + dbUserName->getLabel());
00264 dbPassword->setValue(params.dbPassword);
00265 if (params.dbPassword.isEmpty())
00266 dbPassword->setLabel("* " + dbPassword->getLabel());
00267 dbName->setValue(params.dbName);
00268 if (params.dbName.isEmpty())
00269 dbName->setLabel("* " + dbName->getLabel());
00270
00271
00272
00273
00274
00275 }
00276
00277 void MythDbSettings2::Load(void)
00278 {
00279 DatabaseParams params = gContext->GetDatabaseParams();
00280
00281 localEnabled->setValue(params.localEnabled);
00282 localHostName->setValue(params.localHostName);
00283
00284 wolEnabled->setValue(params.wolEnabled);
00285 wolReconnect->setValue(params.wolReconnect);
00286 wolRetry->setValue(params.wolRetry);
00287 wolCommand->setValue(params.wolCommand);
00288 }
00289
00290 void MythDbSettings1::Save(void)
00291 {
00292 DatabaseParams params = gContext->GetDatabaseParams();
00293
00294 params.dbHostName = dbHostName->getValue();
00295 params.dbHostPing = dbHostPing->boolValue();
00296 params.dbPort = dbPort->getValue().toInt();
00297 params.dbUserName = dbUserName->getValue();
00298 params.dbPassword = dbPassword->getValue();
00299 params.dbName = dbName->getValue();
00300
00301 params.dbType = "QMYSQL";
00302
00303 gContext->SaveDatabaseParams(params);
00304 }
00305
00306 void MythDbSettings2::Save(void)
00307 {
00308 DatabaseParams params = gContext->GetDatabaseParams();
00309
00310 params.localEnabled = localEnabled->boolValue();
00311 params.localHostName = localHostName->getValue();
00312
00313 params.wolEnabled = wolEnabled->boolValue();
00314 params.wolReconnect = wolReconnect->intValue();
00315 params.wolRetry = wolRetry->intValue();
00316 params.wolCommand = wolCommand->getValue();
00317
00318 gContext->SaveDatabaseParams(params);
00319 }
00320
00321 DatabaseSettings::DatabaseSettings(const QString &DBhostOverride)
00322 {
00323 addChild(new MythDbSettings1(DBhostOverride));
00324 addChild(new MythDbSettings2());
00325 }
00326
00327 void DatabaseSettings::addDatabaseSettings(ConfigurationWizard *wizard)
00328 {
00329 wizard->addChild(new MythDbSettings1());
00330 wizard->addChild(new MythDbSettings2());
00331 }