bool insertInDB(const QString &name, const QString &thumbnail, const QString &description, const QString &url, const QString &author, const bool &download, const QDateTime &updated, ArticleType type) { if (findInDB(name, type)) return false; MSqlQuery query(MSqlQuery::InitCon()); query.prepare("INSERT INTO internetcontent (name,thumbnail,description," "commandline,author,download,updated,podcast, type) " "VALUES( :NAME, :THUMBNAIL, :DESCRIPTION, :URL, :AUTHOR, :DOWNLOAD, " ":UPDATED, :PODCAST, :TYPE);"); query.bindValue(":NAME", name); query.bindValue(":THUMBNAIL", thumbnail); query.bindValue(":DESCRIPTION", description); query.bindValue(":URL", url); query.bindValue(":AUTHOR", author); query.bindValue(":DOWNLOAD", download); query.bindValue(":UPDATED", updated); query.bindValue(":PODCAST", true); query.bindValue(":TYPE", type); if (!query.exec() || !query.isActive()) { MythDB::DBError("netcontent: inserting in DB", query); return false; } return (query.numRowsAffected() > 0); }
void MythNewsConfig::populateSites(void) { QMutexLocker locker(&m_lock); QString filename = QString("%1%2") .arg(GetShareDir()).arg("mythnews/news-sites.xml"); QFile xmlFile(filename); if (!xmlFile.exists() || !xmlFile.open(QIODevice::ReadOnly)) { LOG(VB_GENERAL, LOG_ERR, LOC + "Cannot open news-sites.xml"); return; } QString errorMsg; int errorLine = 0; int errorColumn = 0; QDomDocument domDoc; if (!domDoc.setContent(&xmlFile, false, &errorMsg, &errorLine, &errorColumn)) { LOG(VB_GENERAL, LOG_ERR, LOC + "Could not read content of news-sites.xml" + QString("\n\t\t\tError parsing %1").arg(filename) + QString("\n\t\t\tat line: %1 column: %2 msg: %3") .arg(errorLine).arg(errorColumn).arg(errorMsg)); return; } m_priv->categoryList.clear(); QDomNodeList catList = domDoc.elementsByTagName(QString::fromUtf8("category")); QDomNode catNode; QDomNode siteNode; for (int i = 0; i < catList.count(); i++) { catNode = catList.item(i); NewsCategory cat; cat.name = catNode.toElement().attribute("name"); QDomNodeList siteList = catNode.childNodes(); for (int j = 0; j < siteList.count(); j++) { siteNode = siteList.item(j); NewsSiteItem site = NewsSiteItem(); site.name = siteNode.namedItem(QString("title")).toElement().text(); site.category = cat.name; site.url = siteNode.namedItem(QString("url")).toElement().text(); site.ico = siteNode.namedItem(QString("ico")).toElement().text(); site.podcast = false; site.inDB = findInDB(site.name); cat.siteList.push_back(site); } m_priv->categoryList.push_back(cat); } xmlFile.close(); }