00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <QDir>
00010
00011 #include "mythdb.h"
00012 #include "mythcorecontext.h"
00013 #include "mythmiscutil.h"
00014 #include "checksetup.h"
00015
00017
00018 static bool checkPath(QString path, QStringList &probs)
00019 {
00020 QDir dir(path);
00021 if (!dir.exists())
00022 {
00023 probs.push_back(QObject::tr("Path \"%1\" doesn't exist.").arg(path));
00024 return true;
00025 }
00026
00027 QFile test(path.append("/.test"));
00028 if (test.open(QIODevice::WriteOnly))
00029 test.remove();
00030 else
00031 {
00032 probs.push_back(QObject::tr("Unable to create file \"%1\" - directory "
00033 "is not writable?").arg(path));
00034 return true;
00035 }
00036
00037 return false;
00038 }
00039
00042
00043 bool checkStoragePaths(QStringList &probs)
00044 {
00045 bool problemFound = false;
00046
00047 QString recordFilePrefix =
00048 gCoreContext->GetSetting("RecordFilePrefix", "EMPTY");
00049
00050 MSqlQuery query(MSqlQuery::InitCon());
00051
00052 query.prepare("SELECT count(groupname) FROM storagegroup;");
00053 if (!query.exec() || !query.next())
00054 {
00055 MythDB::DBError("checkStoragePaths", query);
00056 return false;
00057 }
00058
00059 if (query.value(0).toInt() == 0)
00060 {
00061 QString trMesg =
00062 QObject::tr("No Storage Group directories are defined. You "
00063 "must add at least one directory to the Default "
00064 "Storage Group where new recordings will be "
00065 "stored.");
00066 probs.push_back(trMesg);
00067 LOG(VB_GENERAL, LOG_ERR, trMesg);
00068 return true;
00069 }
00070
00071 query.prepare("SELECT groupname, dirname "
00072 "FROM storagegroup "
00073 "WHERE hostname = :HOSTNAME;");
00074 query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
00075 if (!query.exec() || !query.isActive())
00076 {
00077 MythDB::DBError("checkStoragePaths", query);
00078 return false;
00079 }
00080 else if (query.size() < 1)
00081 {
00082 if (gCoreContext->IsMasterHost())
00083 {
00084
00085 QString trMesg =
00086 QObject::tr("No Storage Group directories are defined. "
00087 "You must add at least one directory to the "
00088 "Default Storage Group where new recordings "
00089 "will be stored.");
00090 probs.push_back(trMesg);
00091 LOG(VB_GENERAL, LOG_ERR, trMesg);
00092 return true;
00093 }
00094 else
00095 return false;
00096 }
00097
00098 QDir checkDir("");
00099 QString dirname;
00100 while (query.next())
00101 {
00102
00103
00104
00105 dirname = QString::fromUtf8(query.value(1)
00106 .toByteArray().constData());
00107 QStringList tokens = dirname.split(",");
00108 int curToken = 0;
00109 while (curToken < tokens.size())
00110 {
00111 checkDir.setPath(tokens[curToken]);
00112 if (checkPath(tokens[curToken], probs))
00113 {
00114 problemFound = true;
00115 }
00116 curToken++;
00117 }
00118 }
00119
00120 return problemFound;
00121 }
00122
00123 bool checkImageStoragePaths(QStringList &probs)
00124 {
00125 bool problemFound = false;
00126
00127 MSqlQuery query(MSqlQuery::InitCon());
00128
00129 query.prepare("SELECT groupname "
00130 "FROM storagegroup "
00131 "WHERE hostname = :HOSTNAME;");
00132 query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
00133 if (!query.exec() || !query.isActive())
00134 {
00135 MythDB::DBError("checkImageStoragePaths", query);
00136 return false;
00137 }
00138 else if (query.size() < 1)
00139 {
00140 return false;
00141 }
00142
00143 QStringList groups;
00144 while (query.next())
00145 {
00146 groups += query.value(0).toString();
00147 }
00148
00149 if (groups.contains("Videos"))
00150 {
00151 if (groups.contains("Fanart") &&
00152 groups.contains("Coverart") &&
00153 groups.contains("Screenshots") &&
00154 groups.contains("Banners"))
00155 problemFound = false;
00156 else
00157 {
00158 QString trMesg =
00159 QObject::tr("You have a Video Storage "
00160 "Group, but have not set up "
00161 "all Image Groups. If you continue, "
00162 "video image downloads will be saved in "
00163 "your Videos Storage Group. Do you want "
00164 "to store them in their own groups?");
00165 probs.push_back(trMesg);
00166 LOG(VB_GENERAL, LOG_ERR, trMesg);
00167 problemFound = true;
00168 }
00169 }
00170
00171 return problemFound;
00172 }
00173
00174
00175
00176
00177
00178 bool checkChannelPresets(QStringList &probs)
00179 {
00180 bool problemFound = false;
00181
00182 MSqlQuery query(MSqlQuery::InitCon());
00183
00184 query.prepare("SELECT cardid, startchan, sourceid, inputname"
00185 " FROM cardinput;");
00186
00187 if (!query.exec() || !query.isActive())
00188 {
00189 MythDB::DBError("checkChannelPresets", query);
00190 return false;
00191 }
00192
00193 while (query.next())
00194 {
00195 int cardid = query.value(0).toInt();
00196 QString startchan = query.value(1).toString();
00197 int sourceid = query.value(2).toInt();
00198
00199 if (query.value(1).toString().isEmpty())
00200 startchan = "3";
00201
00202 MSqlQuery channelExists(MSqlQuery::InitCon());
00203 QString channelQuery;
00204 channelQuery = QString("SELECT chanid FROM channel"
00205 " WHERE channum='%1' AND sourceid=%2;")
00206 .arg(startchan).arg(sourceid);
00207 channelExists.prepare(channelQuery);
00208
00209 if (!channelExists.exec() || !channelExists.isActive())
00210 {
00211 MythDB::DBError("checkChannelPresets", channelExists);
00212 return problemFound;
00213 }
00214
00215 if (channelExists.size() == 0)
00216 {
00217 probs.push_back(QObject::tr("Card %1 (type %2) is set to start on "
00218 "channel %3, which does not exist.")
00219 .arg(cardid).arg(query.value(3).toString()).arg(startchan));
00220 problemFound = true;
00221 }
00222 }
00223
00224 return problemFound;
00225 }
00226
00229
00230 bool CheckSetup(QStringList &problems)
00231 {
00232 return checkStoragePaths(problems)
00233 || checkChannelPresets(problems)
00234 || checkImageStoragePaths(problems);
00235 }
00236
00237 bool needsMFDBReminder()
00238 {
00239 bool needsReminder = false;
00240 MSqlQuery query(MSqlQuery::InitCon());
00241
00242 query.prepare("SELECT sourceid "
00243 "FROM videosource "
00244 "WHERE xmltvgrabber = 'schedulesdirect1' "
00245 "OR xmltvgrabber = 'datadirect' "
00246 "OR xmltvgrabber LIKE 'tv_grab_%';");
00247 if (!query.exec() || !query.isActive())
00248 {
00249 MythDB::DBError("needsMFDBReminder", query);
00250 }
00251 else if (query.size() >= 1)
00252 {
00253 needsReminder = true;
00254 }
00255
00256 return needsReminder;
00257 }
00258
00259