Create a new resource and add it to the database
| 104 | |
| 105 | // Create a new resource and add it to the database |
| 106 | qint32 AddNote::createResource(Resource &r, int sequence, QByteArray data, QString mime, bool attachment, QString filename, qint32 noteLid) { |
| 107 | qint32 lid = noteLid; |
| 108 | ConfigStore cs(global.db); |
| 109 | qint32 rlid = cs.incrementLidCounter(); |
| 110 | |
| 111 | QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); |
| 112 | |
| 113 | QString guid = QString::number(rlid); |
| 114 | NoteTable noteTable(global.db); |
| 115 | r.guid = guid; |
| 116 | r.noteGuid = noteTable.getGuid(lid); |
| 117 | QString noteguid = r.noteGuid; |
| 118 | if (noteguid == "") |
| 119 | return 0; |
| 120 | r.mime = mime; |
| 121 | r.active = true; |
| 122 | r.updateSequenceNum = sequence; |
| 123 | r.width = 0; |
| 124 | r.height = 0; |
| 125 | r.duration = 0; |
| 126 | ResourceAttributes a; |
| 127 | if (r.attributes.isSet()) |
| 128 | a = r.attributes; |
| 129 | a.attachment = attachment; |
| 130 | if (filename != "") { |
| 131 | a.fileName = filename; |
| 132 | } |
| 133 | |
| 134 | Data d; |
| 135 | d.body = data; |
| 136 | d.bodyHash = hash; |
| 137 | d.size = data.size(); |
| 138 | |
| 139 | r.data = d; |
| 140 | r.attributes = a; |
| 141 | ResourceTable resourceTable(global.db); |
| 142 | resourceTable.add(rlid, r, true, lid); |
| 143 | |
| 144 | return rlid; |
| 145 | } |
no test coverage detected