| 69 | |
| 70 | |
| 71 | void CounterRunner::countNotebooks() { |
| 72 | if (global.countBehavior == Global::CountNone) |
| 73 | return; |
| 74 | |
| 75 | QLOG_TRACE_IN(); |
| 76 | if (!init) |
| 77 | initialize(); |
| 78 | |
| 79 | // First get every possible notebook |
| 80 | NotebookTable nTable(db); |
| 81 | QList<qint32> lids; |
| 82 | nTable.getAll(lids); |
| 83 | |
| 84 | // Next, get the totals of everything possible |
| 85 | QHash<qint32, qint32> allNotebooks; |
| 86 | for (int i=0; i<lids.size(); i++) { |
| 87 | allNotebooks.insert(lids.at(i), 0); |
| 88 | } |
| 89 | |
| 90 | NSqlQuery query(db); |
| 91 | query.exec(" select data, count(data) from datastore where key=5011 and lid not in (select lid from datastore where data=0 and key=5010) group by data;"); |
| 92 | while (query.next()) { |
| 93 | qint32 lid = query.value(0).toInt(); |
| 94 | qint32 total = query.value(1).toInt(); |
| 95 | allNotebooks[lid] = total; |
| 96 | } |
| 97 | |
| 98 | query.exec("select notebooklid, count(notebooklid) from notetable where lid in (select lid from filter) and lid not in (select lid from datastore where data=0 and key=5010) group by notebooklid;"); |
| 99 | |
| 100 | while(query.next()) { |
| 101 | qint32 lid = query.value(0).toInt(); |
| 102 | emit notebookTotals(lid, query.value(1).toInt(), allNotebooks[lid]); |
| 103 | lids.removeAll(lid); |
| 104 | } |
| 105 | |
| 106 | // The ones that are left have a zero count |
| 107 | for (int i=0; i<lids.size(); i++) |
| 108 | emit(notebookTotals(lids[i], 0, allNotebooks[lids[i]])); |
| 109 | |
| 110 | emit(notebookTotals(-1, -1, -1)); |
| 111 | QLOG_TRACE_OUT(); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | void CounterRunner::countTags() { |