00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <qstring.h>
00010 #include <qdir.h>
00011 #include "libmyth/mythdbcon.h"
00012 #include "libmyth/mythcontext.h"
00013 #include "libmyth/util.h"
00014
00016
00017 static bool checkPath(QString path, QString *probs)
00018 {
00019 QDir dir(path);
00020 if (!dir.exists())
00021 {
00022 probs->append(QObject::tr("Path"));
00023 probs->append(QString(" %1 ").arg(path));
00024 probs->append(QObject::tr("doesn't exist"));
00025 probs->append(".\n");
00026 return true;
00027 }
00028
00029 QFile test(path.append("/.test"));
00030 if (test.open(IO_WriteOnly))
00031 test.remove();
00032 else
00033 {
00034 probs->append(QObject::tr("Cannot create a file"));
00035 probs->append(QString(" %1 - ").arg(path));
00036 probs->append(QObject::tr("directory is not writable?"));
00037 probs->append("\n");
00038 return true;
00039 }
00040
00041 return false;
00042 }
00043
00046
00047 bool checkStoragePaths(QString *probs)
00048 {
00049 bool problemFound = false;
00050
00051 QString recordFilePrefix = gContext->GetSetting("RecordFilePrefix", "EMPTY");
00052
00053 MSqlQuery query(MSqlQuery::InitCon());
00054
00055 query.prepare("SELECT count(groupname) FROM storagegroup;");
00056 if (!query.exec() || !query.isActive() || query.size() < 1)
00057 {
00058 MythContext::DBError("checkStoragePaths", query);
00059 return false;
00060 }
00061
00062 query.next();
00063 if (query.value(0).toInt() == 0)
00064 {
00065 QString trMesg;
00066
00067 trMesg = QObject::tr("No Storage Group directories are defined. You "
00068 "must add at least one directory to the Default "
00069 "Storage Group where new recordings will be "
00070 "stored.");
00071 probs->append(trMesg + "\n");
00072 VERBOSE(VB_IMPORTANT, trMesg);
00073 return true;
00074 }
00075
00076 query.prepare("SELECT groupname, dirname "
00077 "FROM storagegroup "
00078 "WHERE hostname = :HOSTNAME;");
00079 query.bindValue(":HOSTNAME", gContext->GetHostName());
00080 if (!query.exec() || !query.isActive() || query.size() < 1)
00081 {
00082 MythContext::DBError("checkStoragePaths", query);
00083 return false;
00084 }
00085
00086 QDir checkDir("");
00087 while (query.next())
00088 {
00089 QString sgDir = query.value(0).toString();
00090 QStringList tokens = QStringList::split(",", query.value(1).toString());
00091 unsigned int curToken = 0;
00092 while (curToken < tokens.size())
00093 {
00094 checkDir.setPath(tokens[curToken]);
00095 if (checkPath(tokens[curToken], probs))
00096 {
00097 problemFound = true;
00098 }
00099 curToken++;
00100 }
00101 }
00102
00103 return problemFound;
00104 }
00105
00106
00107
00108
00109
00110
00111 bool checkChannelPresets(QString *probs)
00112 {
00113 bool problemFound = false;
00114
00115 MSqlQuery query(MSqlQuery::InitCon());
00116
00117 query.prepare("SELECT cardid, startchan, sourceid, inputname"
00118 " FROM cardinput;");
00119
00120 if (!query.exec() || !query.isActive())
00121 {
00122 MythContext::DBError("checkChannelPresets", query);
00123 return false;
00124 }
00125
00126 while (query.next())
00127 {
00128 int cardid = query.value(0).toInt();
00129 QString startchan = query.value(1).toString();
00130 int sourceid = query.value(2).toInt();
00131
00132 if (query.value(1).toString() == "")
00133 startchan = "3";
00134
00135 MSqlQuery channelExists(MSqlQuery::InitCon());
00136 QString channelQuery;
00137 channelQuery = QString("SELECT chanid FROM channel"
00138 " WHERE channum='%1' AND sourceid=%2;")
00139 .arg(startchan).arg(sourceid);
00140 channelExists.prepare(channelQuery);
00141
00142 if (!channelExists.exec() || !channelExists.isActive())
00143 {
00144 MythContext::DBError("checkChannelPresets", channelExists);
00145 return problemFound;
00146 }
00147
00148 if (channelExists.size() == 0)
00149 {
00150 probs->append(QObject::tr("Card"));
00151 probs->append(QString(" %1 (").arg(cardid));
00152 probs->append(QObject::tr("type"));
00153 probs->append(QString(" %1) ").arg(query.value(3).toString()));
00154 probs->append(QObject::tr("is set to start on channel"));
00155 probs->append(QString(" %1, ").arg(startchan));
00156 probs->append(QObject::tr("which does not exist"));
00157 probs->append(".\n");
00158 problemFound = true;
00159 }
00160 }
00161
00162 return problemFound;
00163 }
00164
00167
00168 bool CheckSetup(QString *problems)
00169 {
00170 return checkStoragePaths(problems)
00171 || checkChannelPresets(problems);
00172 }
00173
00174