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