mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Merge pull request #8585 from nextcloud/bugfix/syncfolderdisplay
feat: set LocalizedResourceName for sync folders.
This commit is contained in:
commit
6cbccf5fc6
@ -69,9 +69,9 @@ namespace Utility {
|
||||
* @brief Creates or overwrite the Desktop.ini file to use new folder IconResource shown as a favorite link
|
||||
*
|
||||
* @param folder absolute file path to folder
|
||||
* @param overwrite boolean to create or overwrite ini file
|
||||
* @param localizedResourceName new folder name to be used as display name (migration)
|
||||
*/
|
||||
OCSYNC_EXPORT void setupDesktopIni(const QString &folder, bool overwrite = false);
|
||||
OCSYNC_EXPORT void setupDesktopIni(const QString &folder, const QString localizedResourceName = {});
|
||||
/**
|
||||
* @brief Removes the Desktop.ini file which contains the folder IconResource shown as a favorite link
|
||||
*
|
||||
|
||||
@ -61,6 +61,12 @@ void Utility::migrateFavLink(const QString &folder)
|
||||
Q_UNUSED(folder)
|
||||
}
|
||||
|
||||
void Utility::setupDesktopIni(const QString &folder, const QString localizedResourceName)
|
||||
{
|
||||
Q_UNUSED(folder)
|
||||
Q_UNUSED(localizedResourceName)
|
||||
}
|
||||
|
||||
QString Utility::syncFolderDisplayName(const QString &folder, const QString &displayName)
|
||||
{
|
||||
Q_UNUSED(folder)
|
||||
|
||||
@ -70,6 +70,12 @@ void Utility::migrateFavLink(const QString &folder)
|
||||
Q_UNUSED(folder)
|
||||
}
|
||||
|
||||
void Utility::setupDesktopIni(const QString &folder, const QString localizedResourceName)
|
||||
{
|
||||
Q_UNUSED(folder)
|
||||
Q_UNUSED(localizedResourceName)
|
||||
}
|
||||
|
||||
QString Utility::syncFolderDisplayName(const QString &folder, const QString &displayName)
|
||||
{
|
||||
Q_UNUSED(folder)
|
||||
|
||||
@ -118,11 +118,12 @@ QString Utility::systemPathToLinks()
|
||||
return pathToLinks;
|
||||
}
|
||||
|
||||
void Utility::setupDesktopIni(const QString &folder, bool overwrite)
|
||||
void Utility::setupDesktopIni(const QString &folder, const QString localizedResourceName)
|
||||
{
|
||||
// First create a Desktop.ini so that the folder and favorite link show our application's icon.
|
||||
QFile desktopIni(folder + QLatin1String("/Desktop.ini"));
|
||||
if (!overwrite && desktopIni.exists()) {
|
||||
const auto migration = !localizedResourceName.isEmpty();
|
||||
if (!migration && desktopIni.exists()) {
|
||||
qCWarning(lcUtility) << desktopIni.fileName() << "already exists, not overwriting it to set the folder icon.";
|
||||
return;
|
||||
}
|
||||
@ -138,6 +139,10 @@ void Utility::setupDesktopIni(const QString &folder, bool overwrite)
|
||||
#endif
|
||||
desktopIni.write(",");
|
||||
desktopIni.write(iconIndex);
|
||||
if (migration) {
|
||||
desktopIni.write("\r\nLocalizedResourceName=");
|
||||
desktopIni.write(localizedResourceName.toUtf8());
|
||||
}
|
||||
desktopIni.write("\r\n");
|
||||
desktopIni.close();
|
||||
|
||||
@ -190,16 +195,11 @@ QString Utility::syncFolderDisplayName(const QString ¤tDisplayName, const
|
||||
|
||||
void Utility::migrateFavLink(const QString &folder)
|
||||
{
|
||||
//overwrite Desktop.ini, update icon
|
||||
setupDesktopIni(folder, true);
|
||||
|
||||
const QDir folderDir(QDir::fromNativeSeparators(folder));
|
||||
const auto oldDirName = folderDir.dirName();
|
||||
const auto nextcloud = QStringLiteral("Nextcloud");
|
||||
if (!oldDirName.startsWith(nextcloud)) {
|
||||
qCWarning(lcUtility) << "Link name does not need to change for" << folder;
|
||||
return;
|
||||
}
|
||||
const auto folderDisplayName = syncFolderDisplayName(oldDirName, QStringLiteral(APPLICATION_NAME));
|
||||
// overwrite Desktop.ini, update icon, update folder display name
|
||||
setupDesktopIni(folder, folderDisplayName);
|
||||
|
||||
const auto pathToLinks = systemPathToLinks();
|
||||
if (pathToLinks.isEmpty()) {
|
||||
@ -209,7 +209,7 @@ void Utility::migrateFavLink(const QString &folder)
|
||||
|
||||
const QDir dirPathToLinks(pathToLinks);
|
||||
const auto oldLnkFilename = dirPathToLinks.filePath(oldDirName + QLatin1String(".lnk"));
|
||||
const auto newLnkFilename = dirPathToLinks.filePath(syncFolderDisplayName(oldDirName, QStringLiteral(APPLICATION_NAME)) + QLatin1String(".lnk"));
|
||||
const auto newLnkFilename = dirPathToLinks.filePath(folderDisplayName + QLatin1String(".lnk"));
|
||||
|
||||
if (QFile::exists(newLnkFilename)) {
|
||||
qCWarning(lcUtility) << "New lnk file already exists" << newLnkFilename;
|
||||
@ -248,7 +248,8 @@ void Utility::removeFavLink(const QString &folder)
|
||||
const QDir links(QString::fromWCharArray(path));
|
||||
CoTaskMemFree(path);
|
||||
|
||||
const auto linkName = QDir(links).absoluteFilePath(folderDir.dirName() + QLatin1String(".lnk"));
|
||||
const auto folderDisplayName = syncFolderDisplayName(folderDir.dirName(), QStringLiteral(APPLICATION_NAME));
|
||||
const auto linkName = QDir(links).absoluteFilePath(folderDisplayName + QLatin1String(".lnk"));
|
||||
|
||||
qCDebug(lcUtility) << "Removing favorite link from" << folder << "to" << linkName;
|
||||
if (!QFile::remove(linkName)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user