mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Socket API: add an option to replace existing files with virtual files
Issue #6726
This commit is contained in:
parent
afc953b649
commit
46aa8fd1f8
@ -702,6 +702,41 @@ void SocketApi::command_DOWNLOAD_VIRTUAL_FILE(const QString &filesArg, SocketLis
|
||||
}
|
||||
}
|
||||
|
||||
/* Go over all the files ans replace them by a virtual file */
|
||||
void SocketApi::command_REPLACE_VIRTUAL_FILE(const QString &filesArg, SocketListener *)
|
||||
{
|
||||
QStringList files = filesArg.split(QLatin1Char('\x1e')); // Record Separator
|
||||
auto suffix = QStringLiteral(APPLICATION_DOTVIRTUALFILE_SUFFIX);
|
||||
|
||||
for (const auto &file : files) {
|
||||
auto folder = FolderMan::instance()->folderForPath(file);
|
||||
if (!folder)
|
||||
continue;
|
||||
if (file.endsWith(suffix))
|
||||
continue;
|
||||
QString relativePath = QDir::cleanPath(file).mid(folder->cleanPath().length() + 1);
|
||||
QFileInfo fi(file);
|
||||
if (fi.isDir()) {
|
||||
folder->journalDb()->getFilesBelowPath(relativePath.toUtf8(), [&](const SyncJournalFileRecord &rec) {
|
||||
if (rec._type != ItemTypeFile || rec._path.endsWith(APPLICATION_DOTVIRTUALFILE_SUFFIX))
|
||||
return;
|
||||
QString file = folder->path() + '/' + QString::fromUtf8(rec._path);
|
||||
if (!FileSystem::rename(file, file + suffix)) {
|
||||
qCWarning(lcSocketApi) << "Unable to rename " << file;
|
||||
}
|
||||
});
|
||||
continue;
|
||||
}
|
||||
SyncJournalFileRecord record;
|
||||
if (!folder->journalDb()->getFileRecord(relativePath, &record) || !record.isValid())
|
||||
continue;
|
||||
if (!FileSystem::rename(file, file + suffix)) {
|
||||
qCWarning(lcSocketApi) << "Unable to rename " << file;
|
||||
}
|
||||
FolderMan::instance()->scheduleFolder(folder);
|
||||
}
|
||||
}
|
||||
|
||||
void SocketApi::copyUrlToClipboard(const QString &link)
|
||||
{
|
||||
QApplication::clipboard()->setText(link);
|
||||
@ -979,12 +1014,23 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
|
||||
if (syncFolder) {
|
||||
auto virtualFileSuffix = QStringLiteral(APPLICATION_DOTVIRTUALFILE_SUFFIX);
|
||||
bool hasVirtualFile = false;
|
||||
bool hasNormalFiles = false;
|
||||
bool hasDir = false;
|
||||
for (const auto &file : files) {
|
||||
if (file.endsWith(virtualFileSuffix) || (syncFolder->useVirtualFiles() && QFileInfo(file).isDir()))
|
||||
if (QFileInfo(file).isDir()) {
|
||||
hasDir = true;
|
||||
} else if (file.endsWith(virtualFileSuffix)) {
|
||||
hasVirtualFile = true;
|
||||
} else if (!hasNormalFiles) {
|
||||
bool isOnTheServer = FileData::get(file).journalRecord().isValid();
|
||||
hasNormalFiles = isOnTheServer;
|
||||
}
|
||||
}
|
||||
if (hasVirtualFile)
|
||||
if (hasVirtualFile || (hasDir && syncFolder->useVirtualFiles()))
|
||||
listener->sendMessage(QLatin1String("MENU_ITEM:DOWNLOAD_VIRTUAL_FILE::") + tr("Download file(s)", "", files.size()));
|
||||
|
||||
if ((hasNormalFiles || hasDir) && syncFolder->useVirtualFiles())
|
||||
listener->sendMessage(QLatin1String("MENU_ITEM:REPLACE_VIRTUAL_FILE::") + tr("Replace file(s) by virtual file", "", files.size()));
|
||||
}
|
||||
|
||||
listener->sendMessage(QString("GET_MENU_ITEMS:END"));
|
||||
|
||||
@ -110,6 +110,7 @@ private:
|
||||
Q_INVOKABLE void command_EMAIL_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
|
||||
Q_INVOKABLE void command_OPEN_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
|
||||
Q_INVOKABLE void command_DOWNLOAD_VIRTUAL_FILE(const QString &filesArg, SocketListener *listener);
|
||||
Q_INVOKABLE void command_REPLACE_VIRTUAL_FILE(const QString &filesArg, SocketListener *listener);
|
||||
Q_INVOKABLE void command_RESOLVE_CONFLICT(const QString &localFile, SocketListener *listener);
|
||||
Q_INVOKABLE void command_DELETE_ITEM(const QString &localFile, SocketListener *listener);
|
||||
Q_INVOKABLE void command_MOVE_ITEM(const QString &localFile, SocketListener *listener);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user