viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. #include "feedpoller.h"
  2. #include <QtXml>
  3. #include "feedmodel.h"
  4.  
  5. using namespace Larss;
  6.  
  7. FeedPoller::FeedPoller(QObject *parent, RssParser *parser, FeedModel *model) :
  8. QThread(parent)
  9. {
  10. this->parser = parser;
  11. this->model = model;
  12.  
  13. workQueue = new QList<QModelIndex> ();
  14. nowLoading = 0;
  15.  
  16. rssContent = new QHash<quint32, QString>();
  17. poll_active = true;
  18.  
  19. // Create the QNetworkAccessManager and connect the loaded signal
  20. // with our handler.
  21. manager = new QNetworkAccessManager ();
  22. manager->connect(manager, SIGNAL(finished(QNetworkReply*)),
  23. this, SLOT(networkManagerReplyFinished(QNetworkReply*)));
  24. }
  25.  
  26. void
  27. FeedPoller::run()
  28. {
  29.  
  30. // Create the timer that will call the function every second.
  31. QTimer *timer = new QTimer ();
  32. timer->setInterval(1000);
  33. timer->connect(timer, SIGNAL(timeout()),
  34. this, SLOT(poll()));
  35. timer->start();
  36.  
  37. QThread::exec();
  38. }
  39.  
  40. bool
  41. FeedPoller::poll()
  42. {
  43. // Poll indefinitely until we are requested to exit.
  44. if (nowLoading == 0)
  45. {
  46. if (workQueue->isEmpty())
  47. return false;
  48. else
  49. {
  50. QModelIndex next_item = workQueue->takeFirst();
  51. nowLoading = next_item.internalId();
  52. manager->get(QNetworkRequest(QUrl(model->getUrl(next_item))));
  53. return true;
  54. }
  55. }
  56. }
  57.  
  58. void
  59. FeedPoller::stopPolling ()
  60. {
  61. poll_active = false;
  62. QThread::exit();
  63. }
  64.  
  65. void
  66. FeedPoller::queueWork(const QModelIndex &index)
  67. {
  68. if (index.internalId() < FEEDMODEL_MAX_CATEGORIES)
  69. return;
  70. workQueue->append(index);
  71. }
  72.  
  73. void
  74. FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
  75. {
  76. // Assume that the string is UTF-8 encoded. This is likely to be
  77. // true, but I should check it in some way.
  78. rssContent->insert (nowLoading, QString::fromUtf8(reply->readAll()));
  79.  
  80. // Now update the database with the new data obtained.
  81. QDomDocument doc;
  82. if (doc.setContent(rssContent->value(nowLoading)))
  83. {
  84. // Try to catch other news_feed with the same link, so preload all of them.
  85. QSqlQuery query(parser->db);
  86. query.prepare ("SELECT link from news WHERE feed=:feed");
  87. query.bindValue("feed", nowLoading - FEEDMODEL_MAX_CATEGORIES);
  88. if (!query.exec ())
  89. return;
  90.  
  91. QStringList links;
  92. if (query.first())
  93. {
  94. links.append(query.value(0).toString());
  95. while (query.next())
  96. links.append(query.value(0).toString());
  97. }
  98.  
  99. QDomElement doc_el = doc.documentElement();
  100. QDomNodeList items = doc_el.elementsByTagName("item");
  101.  
  102. for (quint32 i = 0; i < items.length(); i++)
  103. {
  104. // Get the i-th news
  105. QDomNode item = items.item(i);
  106. QDomElement element = item.toElement();
  107.  
  108. // Get the data in it
  109. QString link = element.elementsByTagName("link").item(0).firstChild().nodeValue();
  110. QString title = element.elementsByTagName("title").item(0).firstChild().nodeValue();
  111. QString description = element.elementsByTagName("description").item(0).firstChild().nodeValue();
  112. QString content = element.elementsByTagName("content:encoded").item(0).firstChild().nodeValue();
  113.  
  114. // We should enable this for RSS 2.0
  115. // QString guid = element.elementsByTagName("guid").item(0).firstChild().nodeValue();
  116. // QString pubDate = element.elementsByTagName("pubDate").item(0).firstChild().nodeValue();
  117.  
  118. if (!links.contains(link))
  119. {
  120. // That means that no results were found, so let's insert this one.
  121. QSqlRecord record = parser->record();
  122. record.setValue("time", 0);
  123. record.setValue("read", 0);
  124. record.setValue("title", title);
  125. record.setValue("link", link);
  126. record.setValue("description", description);
  127. record.setValue("content", content);
  128. record.setValue("feed", nowLoading - FEEDMODEL_MAX_CATEGORIES);
  129.  
  130. if (!parser->insertRecord(-1, record))
  131. qDebug () << "Error inserting record";
  132. }
  133. }
  134.  
  135. if (!parser->submitAll())
  136. qDebug() << "Error submitting new data";
  137. }
  138. else
  139. qDebug () << "Error parsing the document";
  140.  
  141. nowLoading = 0;
  142. return;
  143.  
  144. // Check if there is work in the queue
  145. if (!workQueue->isEmpty())
  146. {
  147. QModelIndex next_item = workQueue->takeFirst();
  148. nowLoading = next_item.internalId();
  149. manager->get(QNetworkRequest(QUrl(model->getUrl(next_item))));
  150. }
  151. }