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 "feedmodel.h"
  2. #include <QAbstractItemModel>
  3. #include <QSqlDatabase>
  4. #include <QSqlQuery>
  5. #include <QSqlError>
  6. #include <QDebug>
  7. #include <QStringList>
  8.  
  9. using namespace Larss;
  10.  
  11. #define FEEDMODEL_MAX_CATEGORIES 1024
  12.  
  13. FeedModel::FeedModel(QObject *parent) : QAbstractItemModel (parent)
  14. {
  15. db = QSqlDatabase::addDatabase("QSQLITE");
  16. db.setDatabaseName("/home/leonardo/larss.db");
  17. db.open();
  18. }
  19.  
  20. FeedModel::~FeedModel()
  21. {
  22. db.close();
  23. }
  24.  
  25.  
  26. QModelIndex
  27. FeedModel::index(int row, int column, const QModelIndex &parent) const
  28. {
  29. qDebug () << "Called index for row "<< row << " and column " << column;
  30. if (parent.internalId() == 0)
  31. {
  32. qDebug () << "That is a category";
  33. QSqlQuery query (db);
  34. query.prepare("SELECT id from categories;");
  35. if (query.exec())
  36. {
  37. if (!query.first())
  38. return QModelIndex();
  39. for (int i = 1; i < row; i++)
  40. {
  41. if (!query.next ())
  42. return QModelIndex();
  43. }
  44.  
  45. qDebug () << "Creating index with id " << query.value(0).toInt();
  46. return createIndex(row, column, query.value(0).toInt());
  47. }
  48. else
  49. return QModelIndex();
  50. }
  51. else
  52. {
  53. QSqlQuery query(db);
  54. query.prepare ("SELECT id from feeds WHERE category=:category ORDER BY id;");
  55. query.bindValue("category", parent.internalId());
  56. if (query.exec())
  57. {
  58. if (!query.first())
  59. return QModelIndex();
  60. else
  61. {
  62. for(int i = 1; i < row; i++)
  63. {
  64. if (!query.next())
  65. return QModelIndex();
  66. }
  67. return createIndex(row, column, query.value(0).toInt() + FEEDMODEL_MAX_CATEGORIES);
  68. }
  69. }
  70. else
  71. return QModelIndex();
  72. }
  73.  
  74. }
  75.  
  76. int
  77. FeedModel::rowCount(const QModelIndex &parent) const
  78. {
  79. qDebug() << "Called rowCount for parent with index " << parent.internalId();
  80. if (!parent.isValid())
  81. {
  82. // Categories count
  83. QSqlQuery query(db);
  84. query.prepare ("SELECT id from categories;");
  85. if (query.exec())
  86. {
  87. int row_count = 1;
  88. if (!query.first())
  89. return 0;
  90. else
  91. while (query.next())
  92. row_count++;
  93. return row_count;
  94. }
  95. else
  96. return 0;
  97. }
  98. else
  99. {
  100. int category_id = parent.internalId();
  101. QSqlQuery query(db);
  102. query.prepare("SELECT id from feeds where category=:category;");
  103. query.bindValue("category", category_id);
  104. if (query.exec())
  105. {
  106. int row_count = 1;
  107. if (!query.first())
  108. return 0;
  109. else
  110. while (query.next())
  111. row_count++;
  112. qDebug () << "Returning " << row_count << " childs for " << " category " << parent.internalId();
  113. return row_count;
  114. }
  115. else
  116. return 0;
  117. }
  118. }
  119.  
  120. int
  121. FeedModel::columnCount(const QModelIndex &parent) const
  122. {
  123. return 1;
  124. }
  125.  
  126. QVariant
  127. FeedModel::data(const QModelIndex &index, int role) const
  128. {
  129. qDebug () << "Called data for index" << index.internalId();
  130. if (role == Qt::DisplayRole)
  131. {
  132. if (index.internalId() == 0)
  133. return QString ("Root");
  134. if (index.internalId() < FEEDMODEL_MAX_CATEGORIES)
  135. {
  136. QSqlQuery query(db);
  137. query.prepare ("SELECT name from categories WHERE id=:category;");
  138. query.bindValue("category", index.internalId());
  139. if (query.exec())
  140. {
  141. if (!query.first())
  142. return QVariant(QVariant::Invalid);
  143. else
  144. return query.value(0).toString();
  145. }
  146. else
  147. return QVariant(QVariant::Invalid);
  148. }
  149. else
  150. {
  151. QSqlQuery query(db);
  152. query.prepare ("SELECT name from feeds WHERE id=:feed;");
  153. query.bindValue("feed", index.internalId() - FEEDMODEL_MAX_CATEGORIES);
  154. if (query.exec())
  155. {
  156. if (query.first())
  157. return query.value(0).toString();
  158. else
  159. return QVariant(QVariant::Invalid);
  160. }
  161. else
  162. return QVariant(QVariant::Invalid);
  163. }
  164. }
  165. else
  166. return QVariant (QVariant::Invalid);
  167. }
  168.  
  169. QModelIndex
  170. FeedModel::parent(const QModelIndex &child) const
  171. {
  172. if (!child.isValid())
  173. return QModelIndex ();
  174.  
  175. quint32 row;
  176. quint32 id = child.internalId();
  177.  
  178. if (id == 0)
  179. return QModelIndex();
  180. else if (id < FEEDMODEL_MAX_CATEGORIES)
  181. {
  182. // Get the position of the category
  183. QSqlQuery query (db);
  184. query.prepare ("SELECT id from category;");
  185. if (query.exec ())
  186. {
  187. if (query.first ())
  188. row = 1;
  189. else
  190. return QModelIndex ();
  191. while (query.next ())
  192. {
  193. row++;
  194. if ((quint64) query.value(0).toInt() == id)
  195. break;
  196. }
  197.  
  198. return createIndex (row, 1, 0);
  199. }
  200. else
  201. return QModelIndex();
  202. }
  203. else
  204. {
  205. // We have a feed here, that actually has a real parent.
  206. // We need to get the ID of the category
  207. id -= FEEDMODEL_MAX_CATEGORIES;
  208. QSqlQuery query (db);
  209. query.prepare ("SELECT category from feeds WHERE id=:id;");
  210. query.bindValue("id", id);
  211. if (query.exec())
  212. {
  213. query.first ();
  214. qDebug () << "Parent of " << id << " is " << query.boundValue(0);
  215. return createIndex (row, 1, query.boundValue(0).toInt());
  216. }
  217. else
  218. return QModelIndex();
  219. }
  220. }
  221.