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