mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Folder: Simplify relative path computation
It was done manually in several places after folderForPath() calls.
This commit is contained in:
parent
8b6ae04155
commit
8358dabbfd
@ -633,13 +633,13 @@ void Application::openPlaceholder(const QString &filename)
|
||||
qWarning(lcApplication) << "Can only handle file ending in .owncloud. Unable to open" << filename;
|
||||
return;
|
||||
}
|
||||
auto folder = FolderMan::instance()->folderForPath(filename);
|
||||
QString relativePath;
|
||||
auto folder = FolderMan::instance()->folderForPath(filename, &relativePath);
|
||||
if (!folder) {
|
||||
qWarning(lcApplication) << "Can't find sync folder for" << filename;
|
||||
// TODO: show a QMessageBox for errors
|
||||
return;
|
||||
}
|
||||
QString relativePath = QDir::cleanPath(filename).mid(folder->cleanPath().length() + 1);
|
||||
folder->downloadPlaceholder(relativePath);
|
||||
QString normalName = filename.left(filename.size() - placeholderExt.size());
|
||||
auto con = QSharedPointer<QMetaObject::Connection>::create();
|
||||
|
||||
@ -934,7 +934,7 @@ Folder *FolderMan::addFolderInternal(FolderDefinition folderDefinition,
|
||||
return folder;
|
||||
}
|
||||
|
||||
Folder *FolderMan::folderForPath(const QString &path)
|
||||
Folder *FolderMan::folderForPath(const QString &path, QString *relativePath)
|
||||
{
|
||||
QString absolutePath = QDir::cleanPath(path) + QLatin1Char('/');
|
||||
|
||||
@ -942,10 +942,16 @@ Folder *FolderMan::folderForPath(const QString &path)
|
||||
const QString folderPath = folder->cleanPath() + QLatin1Char('/');
|
||||
|
||||
if (absolutePath.startsWith(folderPath, (Utility::isWindows() || Utility::isMac()) ? Qt::CaseInsensitive : Qt::CaseSensitive)) {
|
||||
if (relativePath) {
|
||||
*relativePath = absolutePath.mid(folderPath.length());
|
||||
relativePath->chop(1); // we added a '/' above
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
|
||||
if (relativePath)
|
||||
relativePath->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -77,8 +77,13 @@ public:
|
||||
/** Removes a folder */
|
||||
void removeFolder(Folder *);
|
||||
|
||||
/** Returns the folder which the file or directory stored in path is in */
|
||||
Folder *folderForPath(const QString &path);
|
||||
/**
|
||||
* Returns the folder which the file or directory stored in path is in
|
||||
*
|
||||
* Optionally, the path relative to the found folder is returned in
|
||||
* relativePath.
|
||||
*/
|
||||
Folder *folderForPath(const QString &path, QString *relativePath = nullptr);
|
||||
|
||||
/**
|
||||
* returns a list of local files that exist on the local harddisk for an
|
||||
|
||||
@ -1031,7 +1031,8 @@ void ownCloudGui::raiseDialog(QWidget *raiseWidget)
|
||||
|
||||
void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &localPath)
|
||||
{
|
||||
const auto folder = FolderMan::instance()->folderForPath(localPath);
|
||||
QString file;
|
||||
const auto folder = FolderMan::instance()->folderForPath(localPath, &file);
|
||||
if (!folder) {
|
||||
qCWarning(lcApplication) << "Could not open share dialog for" << localPath << "no responsible folder found";
|
||||
return;
|
||||
@ -1042,7 +1043,6 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
|
||||
|
||||
const auto accountState = folder->accountState();
|
||||
|
||||
const QString file = localPath.mid(folder->cleanPath().length() + 1);
|
||||
SyncJournalFileRecord fileRecord;
|
||||
|
||||
bool resharingAllowed = true; // lets assume the good
|
||||
|
||||
@ -361,7 +361,8 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString &argument, SocketList
|
||||
{
|
||||
QString statusString;
|
||||
|
||||
Folder *syncFolder = FolderMan::instance()->folderForPath(argument);
|
||||
QString relativePath;
|
||||
Folder *syncFolder = FolderMan::instance()->folderForPath(argument, &relativePath);
|
||||
if (!syncFolder) {
|
||||
// this can happen in offline mode e.g.: nothing to worry about
|
||||
statusString = QLatin1String("NOP");
|
||||
@ -376,7 +377,6 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString &argument, SocketList
|
||||
QString directory = systemPath.left(systemPath.lastIndexOf('/'));
|
||||
listener->registerMonitoredDirectory(qHash(directory));
|
||||
|
||||
QString relativePath = systemPath.mid(syncFolder->cleanPath().length() + 1);
|
||||
SyncFileStatus fileStatus = syncFolder->syncEngine().syncFileStatusTracker().fileStatus(relativePath);
|
||||
statusString = fileStatus.toSocketAPIString();
|
||||
}
|
||||
@ -389,7 +389,8 @@ void SocketApi::command_SHARE(const QString &localFile, SocketListener *listener
|
||||
{
|
||||
auto theme = Theme::instance();
|
||||
|
||||
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
||||
QString file;
|
||||
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile, &file);
|
||||
if (!shareFolder) {
|
||||
const QString message = QLatin1String("SHARE:NOP:") + QDir::toNativeSeparators(localFile);
|
||||
// files that are not within a sync folder are not synced.
|
||||
@ -403,7 +404,6 @@ void SocketApi::command_SHARE(const QString &localFile, SocketListener *listener
|
||||
listener->sendMessage(message);
|
||||
} else {
|
||||
const QString localFileClean = QDir::cleanPath(localFile);
|
||||
const QString file = localFileClean.mid(shareFolder->cleanPath().length() + 1);
|
||||
SyncFileStatus fileStatus = shareFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
|
||||
|
||||
// Verify the file is on the server (to our knowledge of course)
|
||||
@ -436,13 +436,13 @@ void SocketApi::command_VERSION(const QString &, SocketListener *listener)
|
||||
|
||||
void SocketApi::command_SHARE_STATUS(const QString &localFile, SocketListener *listener)
|
||||
{
|
||||
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
||||
QString file;
|
||||
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile, &file);
|
||||
|
||||
if (!shareFolder) {
|
||||
const QString message = QLatin1String("SHARE_STATUS:NOP:") + QDir::toNativeSeparators(localFile);
|
||||
listener->sendMessage(message);
|
||||
} else {
|
||||
const QString file = QDir::cleanPath(localFile).mid(shareFolder->cleanPath().length() + 1);
|
||||
SyncFileStatus fileStatus = shareFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
|
||||
|
||||
// Verify the file is on the server (to our knowledge of course)
|
||||
@ -492,15 +492,13 @@ void SocketApi::command_SHARE_MENU_TITLE(const QString &, SocketListener *listen
|
||||
// Fetches the private link url asynchronously and then calls the target slot
|
||||
static void fetchPrivateLinkUrlHelper(const QString &localFile, SocketApi *target, void (SocketApi::*targetFun)(const QString &url) const)
|
||||
{
|
||||
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
||||
QString file;
|
||||
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile, &file);
|
||||
if (!shareFolder) {
|
||||
qCWarning(lcSocketApi) << "Unknown path" << localFile;
|
||||
return;
|
||||
}
|
||||
|
||||
const QString localFileClean = QDir::cleanPath(localFile);
|
||||
const QString file = localFileClean.mid(shareFolder->cleanPath().length() + 1);
|
||||
|
||||
AccountPtr account = shareFolder->accountState()->account();
|
||||
|
||||
SyncJournalFileRecord rec;
|
||||
@ -535,9 +533,9 @@ void SocketApi::command_DOWNLOAD_PLACEHOLDER(const QString &filesArg, SocketList
|
||||
for (const auto &file : files) {
|
||||
if (!file.endsWith(placeholderSuffix))
|
||||
continue;
|
||||
auto folder = FolderMan::instance()->folderForPath(file);
|
||||
QString relativePath;
|
||||
auto folder = FolderMan::instance()->folderForPath(file, &relativePath);
|
||||
if (folder) {
|
||||
QString relativePath = QDir::cleanPath(file).mid(folder->cleanPath().length() + 1);
|
||||
folder->downloadPlaceholder(relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user