Skip to content

Commit 1df1444

Browse files
authored
Merge pull request #7502 from nextcloud/backport/7238/stable-3.14
[stable-3.14] Always remove folder icon when removing folder.
2 parents ec81e02 + d79434e commit 1df1444

File tree

6 files changed

+64
-43
lines changed

6 files changed

+64
-43
lines changed

src/common/utility.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,19 @@ namespace Utility {
6666
OCSYNC_EXPORT void sleep(int sec);
6767
OCSYNC_EXPORT void usleep(int usec);
6868
OCSYNC_EXPORT QString formatFingerprint(const QByteArray &, bool colonSeparated = true);
69+
/**
70+
* @brief Creates the Desktop.ini file which contains the folder IconResource shown as a favorite link
71+
*
72+
* @param folder absolute file path to folder
73+
*/
6974
OCSYNC_EXPORT void setupFavLink(const QString &folder);
75+
/**
76+
* @brief Removes the Desktop.ini file which contains the folder IconResource shown as a favorite link
77+
*
78+
* @param folder absolute file path to folder
79+
*/
7080
OCSYNC_EXPORT void removeFavLink(const QString &folder);
81+
7182
OCSYNC_EXPORT bool writeRandomFile(const QString &fname, int size = -1);
7283
OCSYNC_EXPORT QString octetsToString(const qint64 octets);
7384
OCSYNC_EXPORT QByteArray userAgentString();

src/common/utility_win.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,25 @@ void Utility::setupFavLink(const QString &folder)
139139
SetFileAttributesW((wchar_t *)desktopIni.fileName().utf16(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
140140
}
141141

142-
// Windows Explorer: Place under "Favorites" (Links)
143-
QString linkName;
144-
QDir folderDir(QDir::fromNativeSeparators(folder));
145-
146142
/* Use new WINAPI functions */
147143
PWSTR path;
148-
149-
if (SHGetKnownFolderPath(FOLDERID_Links, 0, nullptr, &path) == S_OK) {
150-
QString links = QDir::fromNativeSeparators(QString::fromWCharArray(path));
151-
linkName = QDir(links).filePath(folderDir.dirName() + QLatin1String(".lnk"));
152-
CoTaskMemFree(path);
144+
if (!SHGetKnownFolderPath(FOLDERID_Links, 0, nullptr, &path) == S_OK) {
145+
qCWarning(lcUtility) << "SHGetKnownFolderPath for " << folder << "has failed.";
146+
return;
153147
}
148+
149+
// Windows Explorer: Place under "Favorites" (Links)
150+
const auto links = QDir::fromNativeSeparators(QString::fromWCharArray(path));
151+
CoTaskMemFree(path);
152+
153+
const QDir folderDir(QDir::fromNativeSeparators(folder));
154+
const QString filePath = folderDir.dirName() + QLatin1String(".lnk");
155+
const auto linkName = QDir(links).filePath(filePath);
156+
154157
qCInfo(lcUtility) << "Creating favorite link from" << folder << "to" << linkName;
155-
if (!QFile::link(folder, linkName))
158+
if (!QFile::link(folder, linkName)) {
156159
qCWarning(lcUtility) << "linking" << folder << "to" << linkName << "failed!";
160+
}
157161
}
158162

159163
void Utility::removeFavLink(const QString &folder)

src/gui/accountsettings.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ void AccountSettings::slotRemoveCurrentFolder()
874874
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
875875
connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, folder, row, this]{
876876
if (messageBox->clickedButton() == yesButton) {
877-
Utility::removeFavLink(folder->path());
878877
FolderMan::instance()->removeFolder(folder);
879878
_model->removeRow(row);
880879

src/gui/folderman.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,40 +1327,43 @@ QStringList FolderMan::findFileInLocalFolders(const QString &relPath, const Acco
13271327
return re;
13281328
}
13291329

1330-
void FolderMan::removeFolder(Folder *f)
1330+
void FolderMan::removeFolder(Folder *folderToRemove)
13311331
{
1332-
if (!f) {
1332+
if (!folderToRemove) {
13331333
qCCritical(lcFolderMan) << "Can not remove null folder";
13341334
return;
13351335
}
13361336

1337-
qCInfo(lcFolderMan) << "Removing " << f->alias();
1337+
qCInfo(lcFolderMan) << "Removing " << folderToRemove->alias();
13381338

1339-
const bool currentlyRunning = f->isSyncRunning();
1339+
const bool currentlyRunning = folderToRemove->isSyncRunning();
13401340
if (currentlyRunning) {
13411341
// abort the sync now
1342-
f->slotTerminateSync();
1342+
folderToRemove->slotTerminateSync();
13431343
}
13441344

1345-
if (_scheduledFolders.removeAll(f) > 0) {
1345+
if (_scheduledFolders.removeAll(folderToRemove) > 0) {
13461346
emit scheduleQueueChanged();
13471347
}
13481348

1349-
f->setSyncPaused(true);
1350-
f->wipeForRemoval();
1349+
folderToRemove->setSyncPaused(true);
1350+
folderToRemove->wipeForRemoval();
13511351

13521352
// remove the folder configuration
1353-
f->removeFromSettings();
1353+
folderToRemove->removeFromSettings();
1354+
1355+
// remove Desktop.ini
1356+
Utility::removeFavLink(folderToRemove->path());
13541357

1355-
unloadFolder(f);
1358+
unloadFolder(folderToRemove);
13561359
if (currentlyRunning) {
13571360
// We want to schedule the next folder once this is done
1358-
connect(f, &Folder::syncFinished,
1361+
connect(folderToRemove, &Folder::syncFinished,
13591362
this, &FolderMan::slotFolderSyncFinished);
13601363
// Let the folder delete itself when done.
1361-
connect(f, &Folder::syncFinished, f, &QObject::deleteLater);
1364+
connect(folderToRemove, &Folder::syncFinished, folderToRemove, &QObject::deleteLater);
13621365
} else {
1363-
delete f;
1366+
delete folderToRemove;
13641367
}
13651368

13661369
_navigationPaneHelper.scheduleUpdateCloudStorageRegistry();

src/gui/folderman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class FolderMan : public QObject
101101
Folder *addFolder(AccountState *accountState, const FolderDefinition &folderDefinition);
102102

103103
/** Removes a folder */
104-
void removeFolder(Folder *);
104+
void removeFolder(Folder *folderToRemove);
105105

106106
/** Returns the folder which the file or directory stored in path is in */
107107
Folder *folderForPath(const QString &path);

src/gui/navigationpanehelper.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,26 @@ NavigationPaneHelper::NavigationPaneHelper(FolderMan *folderMan)
4141

4242
void NavigationPaneHelper::setShowInExplorerNavigationPane(bool show)
4343
{
44-
if (_showInExplorerNavigationPane == show)
44+
if (_showInExplorerNavigationPane == show) {
4545
return;
46+
}
4647

4748
_showInExplorerNavigationPane = show;
4849
// Re-generate a new CLSID when enabling, possibly throwing away the old one.
4950
// updateCloudStorageRegistry will take care of removing any unknown CLSID our application owns from the registry.
50-
foreach (Folder *folder, _folderMan->map())
51+
for (const auto &folder : qAsConst(_folderMan->map())) {
5152
folder->setNavigationPaneClsid(show ? QUuid::createUuid() : QUuid());
53+
}
5254

5355
scheduleUpdateCloudStorageRegistry();
5456
}
5557

5658
void NavigationPaneHelper::scheduleUpdateCloudStorageRegistry()
5759
{
5860
// Schedule the update to happen a bit later to avoid doing the update multiple times in a row.
59-
if (!_updateCloudStorageRegistryTimer.isActive())
61+
if (!_updateCloudStorageRegistryTimer.isActive()) {
6062
_updateCloudStorageRegistryTimer.start(500);
63+
}
6164
}
6265

6366
void NavigationPaneHelper::updateCloudStorageRegistry()
@@ -66,11 +69,12 @@ void NavigationPaneHelper::updateCloudStorageRegistry()
6669
// that matches ours when we saved.
6770
QVector<QUuid> entriesToRemove;
6871
#ifdef Q_OS_WIN
69-
QString nameSpaceKey = QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)");
72+
const auto nameSpaceKey = QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)");
7073
if (Utility::registryKeyExists(HKEY_CURRENT_USER, nameSpaceKey)) {
7174
Utility::registryWalkSubKeys(HKEY_CURRENT_USER, nameSpaceKey,
7275
[&entriesToRemove](HKEY key, const QString &subKey) {
73-
QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName"));
76+
const auto appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName"));
77+
qCDebug(lcNavPane) << "Searching for user with subKey:" << subKey;
7478
if (appName.toString() == QLatin1String(APPLICATION_NAME)) {
7579
QUuid clsid{ subKey };
7680
Q_ASSERT(!clsid.isNull());
@@ -85,23 +89,23 @@ void NavigationPaneHelper::updateCloudStorageRegistry()
8589
// Then re-save every folder that has a valid navigationPaneClsid to the registry.
8690
// We currently don't distinguish between new and existing CLSIDs, if it's there we just
8791
// save over it. We at least need to update the tile in case we are suddently using multiple accounts.
88-
foreach (Folder *folder, _folderMan->map()) {
92+
for (const auto &folder : qAsConst(_folderMan->map())) {
8993
if (!folder->navigationPaneClsid().isNull()) {
9094
// If it already exists, unmark it for removal, this is a valid sync root.
9195
entriesToRemove.removeOne(folder->navigationPaneClsid());
9296

93-
QString clsidStr = folder->navigationPaneClsid().toString();
94-
QString clsidPath = QString() % R"(Software\Classes\CLSID\)" % clsidStr;
95-
QString clsidPathWow64 = QString() % R"(Software\Classes\Wow6432Node\CLSID\)" % clsidStr;
96-
QString namespacePath = QString() % R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\)" % clsidStr;
97+
const auto clsidStr = folder->navigationPaneClsid().toString();
98+
const QString clsidPath = QString() % R"(Software\Classes\CLSID\)" % clsidStr;
99+
const QString clsidPathWow64 = QString() % R"(Software\Classes\Wow6432Node\CLSID\)" % clsidStr;
100+
const QString namespacePath = QString() % R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\)" % clsidStr;
97101

98-
QString title = folder->shortGuiRemotePathOrAppName();
102+
auto title = folder->shortGuiRemotePathOrAppName();
99103
// Write the account name in the sidebar only when using more than one account.
100104
if (AccountManager::instance()->accounts().size() > 1) {
101105
title = title % " - " % folder->accountState()->account()->prettyName();
102106
}
103-
QString iconPath = QDir::toNativeSeparators(qApp->applicationFilePath());
104-
QString targetFolderPath = QDir::toNativeSeparators(folder->cleanPath());
107+
const auto iconPath = QDir::toNativeSeparators(qApp->applicationFilePath());
108+
const auto targetFolderPath = QDir::toNativeSeparators(folder->cleanPath());
105109

106110
qCInfo(lcNavPane) << "Explorer Cloud storage provider: saving path" << targetFolderPath << "to CLSID" << clsidStr;
107111
#ifdef Q_OS_WIN
@@ -157,11 +161,11 @@ void NavigationPaneHelper::updateCloudStorageRegistry()
157161
}
158162

159163
// Then remove anything that isn't in our folder list anymore.
160-
foreach (auto &clsid, entriesToRemove) {
161-
QString clsidStr = clsid.toString();
162-
QString clsidPath = QString() % R"(Software\Classes\CLSID\)" % clsidStr;
163-
QString clsidPathWow64 = QString() % R"(Software\Classes\Wow6432Node\CLSID\)" % clsidStr;
164-
QString namespacePath = QString() % R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\)" % clsidStr;
164+
for (const auto &clsid : qAsConst(entriesToRemove)) {
165+
const auto clsidStr = clsid.toString();
166+
const QString clsidPath = QString() % R"(Software\Classes\CLSID\)" % clsidStr;
167+
const QString clsidPathWow64 = QString() % R"(Software\Classes\Wow6432Node\CLSID\)" % clsidStr;
168+
const QString namespacePath = QString() % R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\)" % clsidStr;
165169

166170
qCInfo(lcNavPane) << "Explorer Cloud storage provider: now unused, removing own CLSID" << clsidStr;
167171
#ifdef Q_OS_WIN

0 commit comments

Comments
 (0)