This is called via global.resourceWatcher when a resource has been updated by an external program. The file name is the resource file which starts with the lid.
| 3118 | // has been updated by an external program. The file name is the |
| 3119 | // resource file which starts with the lid. |
| 3120 | void NixNote::resourceExternallyUpdated(QString resourceFile) { |
| 3121 | // We do a remove of the watcher at the beginning and a |
| 3122 | // re-add at the end, because some applications don't actually |
| 3123 | // update an existing file, but delete & re-add it. The delete |
| 3124 | // causes NN to stop watching and any later saves are lost. |
| 3125 | // This re-add at the end hopefully fixes it. |
| 3126 | global.resourceWatcher->removePath(resourceFile); |
| 3127 | QString shortName = resourceFile; |
| 3128 | QString dba = global.fileManager.getDbaDirPath(); |
| 3129 | shortName.replace(dba, ""); |
| 3130 | int pos = shortName.indexOf("."); |
| 3131 | if (pos != -1) |
| 3132 | shortName = shortName.mid(0,pos); |
| 3133 | qint32 lid = shortName.toInt(); |
| 3134 | QFile file(resourceFile); |
| 3135 | file.open(QIODevice::ReadOnly); |
| 3136 | QByteArray ba = file.readAll(); |
| 3137 | file.close(); |
| 3138 | QByteArray newHash = QCryptographicHash::hash(ba, QCryptographicHash::Md5); |
| 3139 | ResourceTable resTable(global.db); |
| 3140 | QByteArray oldHash = resTable.getDataHash(lid); |
| 3141 | if (oldHash != newHash) { |
| 3142 | qint32 noteLid = resTable.getNoteLid(lid); |
| 3143 | resTable.updateResourceHash(lid, newHash); |
| 3144 | NoteTable noteTable(global.db); |
| 3145 | noteTable.updateEnmediaHash(noteLid, oldHash, newHash, true); |
| 3146 | tabWindow->updateResourceHash(noteLid, oldHash, newHash); |
| 3147 | } |
| 3148 | AttachmentIconBuilder icon; |
| 3149 | icon.buildIcon(lid,resourceFile); |
| 3150 | global.resourceWatcher->addPath(resourceFile); |
| 3151 | } |
| 3152 | |
| 3153 | |
| 3154 | //********************************************************************* |
nothing calls this directly
no test coverage detected