Skip to content

Commit 4b4d23b

Browse files
re2zerodeepin-bot[bot]
authored andcommitted
fix: Update image info after rename
Update the file path in database and notify refresh after rename; flush all collection view if delete from it. Log: Update image info after rename. Bug: https://pms.uniontech.com/bug-view-308075.html https://pms.uniontech.com/bug-view-300873.html
1 parent 96d2bce commit 4b4d23b

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

src/qml/MainAlbumView.qml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,19 @@ FadeInoutAnimation {
217217
}
218218

219219
Connections {
220+
target: FileControl
220221
// 关联外部通过 DBus 等方式触发调用相册
221222
function onOpenImageFile(fileName) {
222223
var paths = []
223224
paths.push(fileName)
224225
openAndImportImages(paths)
225226
}
226227

227-
target: FileControl
228+
// 应用内重命名后,更新数据库后,需要更新缩略图显示; 应用外无法实现
229+
function onImageRenamed(oldPath, newPath) {
230+
// console.log("MainAlbumView onImageRenamed oldPath:", oldPath, "newPath:", newPath)
231+
albumControl.updateInfoPath(oldPath, newPath)
232+
}
228233
}
229234

230235
Connections {

src/qml/MenuItemStates.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ Item {
121121
if (selectedUrls.length > 0) {
122122
albumControl.removeFromAlbum(GStatus.currentCustomAlbumUId, selectedUrls)
123123
GStatus.sigFlushCustomAlbumView(GStatus.currentCustomAlbumUId)
124+
if (GStatus.currentViewType === Album.Types.ViewCollecttion) {
125+
// 合集视图下,刷新所有合集列表内容
126+
GStatus.sigFlushAllCollectionView()
127+
}
124128
}
125129
}
126130

src/src/albumControl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,21 @@ bool AlbumControl::insertImportIntoAlbum(int UID, const QStringList &paths)
18441844
return DBManager::instance()->insertIntoAlbum(UID, localPaths, atype);
18451845
}
18461846

1847+
void AlbumControl::updateInfoPath(const QString &oldPath, const QString &newPath)
1848+
{
1849+
auto oldLocalPath = url2localPath(oldPath);
1850+
auto newLocalPath = url2localPath(newPath);
1851+
bool ok = DBManager::instance()->updateImgPath(oldLocalPath, newLocalPath);
1852+
1853+
if (ok) {
1854+
// 通知前端刷新相关界面,包括自定义相册/我的收藏/合集-所有项目/已导入
1855+
sigRefreshCustomAlbum(-1);
1856+
sigRefreshAllCollection();
1857+
sigRefreshImportAlbum();
1858+
sigRefreshSearchView();
1859+
}
1860+
}
1861+
18471862
bool AlbumControl::renameAlbum(int UID, const QString &newName)
18481863
{
18491864
DBManager::instance()->renameAlbum(UID, newName);

src/src/albumControl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ class AlbumControl : public QObject
184184
//添加某相册中的图片 0:我的收藏 1:截图录屏 2:相机 3:画板 4-~:其他自定义 paths:需要删除的图片地址
185185
Q_INVOKABLE bool insertImportIntoAlbum(int UID, const QStringList &paths);
186186

187+
Q_INVOKABLE void updateInfoPath(const QString &oldPath, const QString &newPath);
188+
187189
//修改相册名称
188190
Q_INVOKABLE bool renameAlbum(int UID, const QString &newName);
189191

src/src/dbmanager/dbmanager.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,55 @@ const DBImgInfoList DBManager::getInfosForKeyword(int UID, const QString &keywor
10541054
return infos;
10551055
}
10561056

1057+
bool DBManager::updateImgPath(const QString &oldPath, const QString &newPath)
1058+
{
1059+
QString oldHash = LibUnionImage_NameSpace::hashByString(oldPath);
1060+
QString newHash = LibUnionImage_NameSpace::hashByString(newPath);
1061+
1062+
QMutexLocker mutex(&m_dbMutex);
1063+
1064+
// 更新 AlbumTable3 表的 PathHash
1065+
if (!m_query->exec("BEGIN IMMEDIATE TRANSACTION")) {
1066+
qDebug() << m_query->lastError();
1067+
return false;
1068+
}
1069+
QString updateAlbumQs = "UPDATE AlbumTable3 SET PathHash=:newHash WHERE PathHash=:oldHash";
1070+
if (!m_query->prepare(updateAlbumQs)) {
1071+
// 处理错误
1072+
}
1073+
m_query->bindValue(":newHash", newHash);
1074+
m_query->bindValue(":oldHash", oldHash);
1075+
if (!m_query->exec()) {
1076+
return false;
1077+
}
1078+
if (!m_query->exec("COMMIT")) {
1079+
qDebug() << m_query->lastError();
1080+
return false;
1081+
}
1082+
1083+
// 更新 ImageTable3 表的 PathHash 和 filePath
1084+
if (!m_query->exec("BEGIN IMMEDIATE TRANSACTION")) {
1085+
qDebug() << m_query->lastError();
1086+
return false;
1087+
}
1088+
QString updateImageQs = "UPDATE ImageTable3 SET PathHash=:newHash, filePath=:newPath WHERE PathHash=:oldHash";
1089+
if (!m_query->prepare(updateImageQs)) {
1090+
// 处理错误
1091+
}
1092+
m_query->bindValue(":newHash", newHash);
1093+
m_query->bindValue(":newPath", newPath);
1094+
m_query->bindValue(":oldHash", oldHash);
1095+
if (!m_query->exec()) {
1096+
// 处理错误
1097+
return false;
1098+
}
1099+
if (!m_query->exec("COMMIT")) {
1100+
// qDebug() << m_query->lastError();
1101+
return false;
1102+
}
1103+
return true;
1104+
}
1105+
10571106
const QMultiMap<QString, QString> DBManager::getAllPathAlbumNames() const
10581107
{
10591108
QMutexLocker mutex(&m_dbMutex);

src/src/dbmanager/dbmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class DBManager : public QObject
8888
const DBImgInfoList getInfosForKeyword(const QString &keywords) const;
8989
const DBImgInfoList getTrashInfosForKeyword(const QString &keywords) const;
9090
const DBImgInfoList getInfosForKeyword(int UID, const QString &keywords) const;
91+
bool updateImgPath(const QString &oldPath, const QString &newPath);
9192

9293
//CustomAutoImportPathTable
9394
//检查当前的自定义自动导入路径是否已经被监控,检查内容包括是否是子文件夹和是否是默认导入路径

0 commit comments

Comments
 (0)