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(800);
  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. QStringList links;
  91. query.first();
  92. do
  93. {
  94. links.append(query.value(0).toString());
  95. } while (query.next());
  96.  
  97. QDomElement doc_el = doc.documentElement();
  98. QDomNodeList items = doc_el.elementsByTagName("item");
  99.  
  100. for (quint32 i = 0; i < items.length(); i++)
  101. {
  102. // Get the i-th news
  103. QDomNode item = items.item(i);
  104. QDomElement element = item.toElement();
  105.  
  106. // Get the data in it
  107. QString link = element.elementsByTagName("link").item(0).firstChild().nodeValue();
  108. QString title = element.elementsByTagName("title").item(0).firstChild().nodeValue();
  109. QString description = element.elementsByTagName("description").item(0).firstChild().nodeValue();
  110.  
  111. // We should enable this for RSS 2.0
  112. // QString guid = element.elementsByTagName("guid").item(0).firstChild().nodeValue();
  113. // QString pubDate = element.elementsByTagName("pubDate").item(0).firstChild().nodeValue();
  114.  
  115. if (!links.contains(link))
  116. {
  117. // That means that no results were found, so let's insert this one.
  118. QSqlRecord record = parser->record();
  119. record.setValue("time", 0);
  120. record.setValue("read", 0);
  121. record.setValue("title", title);
  122. record.setValue("link", link);
  123. record.setValue("description", description);
  124. record.setValue("feed", nowLoading - FEEDMODEL_MAX_CATEGORIES);
  125.  
  126. if (!parser->insertRecord(-1, record))
  127. qDebug () << "Error inserting record";
  128. }
  129. }
  130. }
  131. else
  132. qDebug () << "Error parsing the document";
  133.  
  134. nowLoading = 0;
  135. return;
  136.  
  137. // Check if there is work in the queue
  138. if (!workQueue->isEmpty())
  139. {
  140. QModelIndex next_item = workQueue->takeFirst();
  141. nowLoading = next_item.internalId();
  142. manager->get(QNetworkRequest(QUrl(model->getUrl(next_item))));
  143. }
  144. }