Rewrittern RSS 2.0 parser + more outputs for database.
This commit is contained in:
parent
0a9844e3e3
commit
3739cdb1f4
@ -55,8 +55,9 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
||||
if (!db_path.exists()) {
|
||||
if (!db_path.mkpath(db_path.absolutePath())) {
|
||||
// Failure when create database file path.
|
||||
qFatal("Directory for database file '%s' was NOT created."
|
||||
qFatal("Directory '%s' for database file '%s' was NOT created."
|
||||
"This is HUGE problem.",
|
||||
qPrintable(db_path.absolutePath()),
|
||||
qPrintable(db_file.symLinkTarget()));
|
||||
}
|
||||
}
|
||||
@ -91,8 +92,9 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
||||
|
||||
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
// Database initialization file not opened. HUGE problem.
|
||||
qFatal("Database initialization file '%s' was not found. Database is uninitialized.",
|
||||
APP_DB_INIT_FILE);
|
||||
qFatal("Database initialization file '%s' from directory '%s' was not found. Database is uninitialized.",
|
||||
APP_DB_INIT_FILE,
|
||||
qPrintable(APP_MISC_PATH));
|
||||
}
|
||||
|
||||
QStringList statements = QString(file_init.readAll()).split(APP_DB_INIT_SPLIT,
|
||||
|
@ -26,41 +26,51 @@ QList<Message> ParsingFactory::parseAsRSS20(const QString &data) {
|
||||
|
||||
for (int i = 0; i < messages_in_xml.size(); i++) {
|
||||
QDomNode message_item = messages_in_xml.item(i);
|
||||
|
||||
QDomElement elem_link = message_item.namedItem("link").toElement();
|
||||
QDomElement elem_description = message_item.namedItem("description").toElement();
|
||||
QDomElement elem_description2 = message_item.namedItem("encoded").toElement();
|
||||
QDomElement elem_title = message_item.namedItem("title").toElement();
|
||||
QDomElement elem_updated = message_item.namedItem("pubDate").toElement();
|
||||
QDomElement elem_author = message_item.namedItem("author").toElement();
|
||||
QDomElement elem_author2 = message_item.namedItem("creator").toElement();
|
||||
|
||||
// RSS 1.0 requires to have title and link valid.
|
||||
if (elem_description.text().isEmpty() && elem_title.text().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Message new_message;
|
||||
new_message.m_title = TextFactory::stripTags(elem_title.text().simplified());
|
||||
|
||||
if (new_message.m_title.isEmpty()) {
|
||||
new_message.m_title = TextFactory::stripTags(elem_description.text().simplified());
|
||||
// Deal with titles & descriptions.
|
||||
QString elem_title = message_item.namedItem("title").toElement().text().simplified();
|
||||
QString elem_description = message_item.namedItem("description").toElement().text();
|
||||
|
||||
if (elem_description.isEmpty()) {
|
||||
elem_description = message_item.namedItem("encoded").toElement().text();
|
||||
}
|
||||
|
||||
new_message.m_contents = elem_description2.text();
|
||||
if (new_message.m_contents.isEmpty()) {
|
||||
new_message.m_contents = elem_description.text();
|
||||
// Now we obtained maximum of informations for title & description.
|
||||
if (elem_title.isEmpty()) {
|
||||
if (elem_description.isEmpty()) {
|
||||
// BOTH title and description are empty, skip this message.
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// Title is empty but description is not.
|
||||
new_message.m_title = TextFactory::stripTags(elem_description);
|
||||
new_message.m_contents = elem_description;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (elem_description.isEmpty()) {
|
||||
// Title is not empty but description is empty.
|
||||
new_message.m_title = TextFactory::stripTags(elem_title);
|
||||
new_message.m_contents = QObject::tr("This message has not contents.");
|
||||
}
|
||||
else {
|
||||
// Both description and title are not empty.
|
||||
new_message.m_title = TextFactory::stripTags(elem_title);
|
||||
new_message.m_contents = elem_description;
|
||||
}
|
||||
}
|
||||
|
||||
new_message.m_url = elem_link.text();
|
||||
new_message.m_author = elem_author.text();
|
||||
// Deal with link and author.
|
||||
new_message.m_url = message_item.namedItem("link").toElement().text();
|
||||
new_message.m_author = message_item.namedItem("author").toElement().text();
|
||||
|
||||
if (new_message.m_author.isEmpty()) {
|
||||
new_message.m_author = elem_author2.text();
|
||||
new_message.m_author = message_item.namedItem("creator").toElement().text();
|
||||
}
|
||||
|
||||
// Setup dates.
|
||||
new_message.m_created = TextFactory::parseDateTime(elem_updated.text());
|
||||
// Deal with creation date.
|
||||
new_message.m_created = TextFactory::parseDateTime(message_item.namedItem("pubDate").toElement().text());
|
||||
new_message.m_createdFromFeed = !new_message.m_created.isNull();
|
||||
|
||||
if (!new_message.m_createdFromFeed) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user