VNoteFile: update config file after save() to update the modified time

This commit is contained in:
Le Tan 2018-07-19 20:52:45 +08:00
parent 6f1a0c6980
commit 42fbdace55
3 changed files with 25 additions and 3 deletions

View File

@ -262,9 +262,15 @@ void VFileList::fillItem(QListWidgetItem *p_item, const VNoteFile *p_file)
{
qulonglong ptr = (qulonglong)p_file;
p_item->setData(Qt::UserRole, ptr);
p_item->setToolTip(p_file->getName());
p_item->setText(p_file->getName());
QString createdTime = VUtils::displayDateTime(p_file->getCreatedTimeUtc().toLocalTime());
QString modifiedTime = VUtils::displayDateTime(p_file->getModifiedTimeUtc().toLocalTime());
QString tooltip = tr("%1\n\nCreated Time: %2\nModified Time: %3")
.arg(p_file->getName())
.arg(createdTime)
.arg(modifiedTime);
p_item->setToolTip(tooltip);
V_ASSERT(sizeof(p_file) <= sizeof(ptr));
}

View File

@ -164,9 +164,9 @@ QJsonObject VNoteFile::toConfigJson() const
// Attachments.
QJsonArray attachmentJson;
for (int i = 0; i < m_attachments.size(); ++i) {
const VAttachment &item = m_attachments[i];
const VAttachment &att = m_attachments[i];
QJsonObject attachmentItem;
attachmentItem[DirConfig::c_name] = item.m_name;
attachmentItem[DirConfig::c_name] = att.m_name;
attachmentJson.append(attachmentItem);
}
@ -652,3 +652,17 @@ bool VNoteFile::addTag(const QString &p_tag)
return true;
}
bool VNoteFile::save()
{
bool ret = VFile::save();
if (ret) {
if (!getDirectory()->updateFileConfig(this)) {
qWarning() << "fail to update config of file" << m_name
<< "in directory" << fetchBasePath();
ret = false;
}
}
return ret;
}

View File

@ -47,6 +47,8 @@ public:
QString getImageFolderInLink() const Q_DECL_OVERRIDE;
bool save() Q_DECL_OVERRIDE;
// Set the name of this file.
void setName(const QString &p_name);