From 3d473ace6c86b8548c073fb4cea6884b513203ea Mon Sep 17 00:00:00 2001 From: Martin van Zijl Date: Tue, 15 Oct 2019 20:29:35 +1300 Subject: [PATCH 1/2] Allow deleting files in File Browser on Linux. This sends them to the recycle bin in the user's home directory. --- toonz/sources/common/tsystem/tsystempd.cpp | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/toonz/sources/common/tsystem/tsystempd.cpp b/toonz/sources/common/tsystem/tsystempd.cpp index ef3f3bdc..867ebacf 100644 --- a/toonz/sources/common/tsystem/tsystempd.cpp +++ b/toonz/sources/common/tsystem/tsystempd.cpp @@ -59,7 +59,10 @@ #include #include #include - +#include +#include +#include +#include #endif #if defined(MACOSX) @@ -452,7 +455,40 @@ void TSystem::moveFileToRecycleBin(const TFilePath &fp) { } catch (...) { } } +#elif defined(LINUX) + // + // From https://stackoverflow.com/questions/17964439/move-files-to-trash-recycle-bin-in-qt + // + QString fileToRecycle = fp.getQString(); + QFileInfo FileName(fileToRecycle); + QDateTime currentTime(QDateTime::currentDateTime()); // get system time + + QString trashFilePath = QDir::homePath() + "/.local/share/Trash/files/"; // this folder contains deleted files + QString trashInfoPath = QDir::homePath() + "/.local/share/Trash/info/"; // this folder contains information about the deleted files + + // check paths exist + if( !QDir(trashFilePath).exists() || !QDir(trashFilePath).exists(trashInfoPath) ) { + outputDebug("Could not find the right paths to send the file to the recycle bin."); + return; + } + + // create file for the "Trash/info" folder + QFile infoFile(trashInfoPath + FileName.completeBaseName() + "." + FileName.completeSuffix() + ".trashinfo"); // filename+extension+.trashinfo + + infoFile.open(QIODevice::ReadWrite); + + QTextStream stream(&infoFile); + + stream << "[Trash Info]" << endl; + stream << "Path=" + QString(QUrl::toPercentEncoding(FileName.absoluteFilePath(), "~_-./")) << endl; // convert path to percentage encoded string + stream << "DeletionDate=" + currentTime.toString("yyyy-MM-dd") + "T" + currentTime.toString("hh:mm:ss") << endl; // get date and time in format YYYY-MM-DDThh:mm:ss + + infoFile.close(); + + // move the original file to the "Trash/files" folder + QDir file; + file.rename(FileName.absoluteFilePath(), trashFilePath+FileName.completeBaseName() + "." + FileName.completeSuffix()); // rename(original path, trash path) #else assert(!"Not implemented yet"); #endif From 63e956981a71a751fd0b2b4a5e5d22c87c64caac Mon Sep 17 00:00:00 2001 From: Martin van Zijl Date: Thu, 2 Apr 2020 14:27:09 +1300 Subject: [PATCH 2/2] Disable deleting on external drives in Linux. Still need to implement this to correct standard. --- toonz/sources/common/tsystem/tsystempd.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/toonz/sources/common/tsystem/tsystempd.cpp b/toonz/sources/common/tsystem/tsystempd.cpp index 867ebacf..37e986c9 100644 --- a/toonz/sources/common/tsystem/tsystempd.cpp +++ b/toonz/sources/common/tsystem/tsystempd.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #endif @@ -464,11 +465,26 @@ void TSystem::moveFileToRecycleBin(const TFilePath &fp) { QDateTime currentTime(QDateTime::currentDateTime()); // get system time + // check if the file is on the local drive + const QStorageInfo fileStorageInfo(fileToRecycle); + const QStorageInfo homeStorageInfo(QDir::homePath()); + const bool isOnHomeDrive = fileStorageInfo == homeStorageInfo; + QString trashFilePath = QDir::homePath() + "/.local/share/Trash/files/"; // this folder contains deleted files QString trashInfoPath = QDir::homePath() + "/.local/share/Trash/info/"; // this folder contains information about the deleted files + // different paths are used for external drives + if (!isOnHomeDrive) { + //trashFilePath = fileStorageInfo.rootPath() + "/.Trash-1000/files/"; + //trashInfoPath = fileStorageInfo.rootPath() + "/.Trash-1000/info/"; + + // TODO: Implement this... The standard is /.Trash-/... + outputDebug("Deleting files on external drives in Linux is not implemented yet."); + return; + } + // check paths exist - if( !QDir(trashFilePath).exists() || !QDir(trashFilePath).exists(trashInfoPath) ) { + if( !QDir(trashFilePath).exists() || !QDir(trashInfoPath).exists() ) { outputDebug("Could not find the right paths to send the file to the recycle bin."); return; }