Skip to content
Open
88 changes: 49 additions & 39 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
const auto index = folderList->indexAt(pos);
if (model->classify(index) == FolderStatusModel::RootFolder &&
(FolderStatusDelegate::errorsListRect(folderList->visualRect(index)).contains(pos) ||
FolderStatusDelegate::optionsButtonRect(folderList->visualRect(index),folderList->layoutDirection()).contains(pos))) {
FolderStatusDelegate::moreRectPos(folderList->visualRect(index)).contains(pos))) {
shape = Qt::PointingHandCursor;
}
folderList->setCursor(shape);
Expand Down Expand Up @@ -608,8 +608,9 @@
{
Q_UNUSED(pos);

QMenu menu;
auto ac = menu.addAction(tr("Open folder"));
auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
auto ac = menu->addAction(tr("Open folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentLocalSubFolder);

const auto fileName = _model->data(index, FolderStatusDelegate::FolderPathRole).toString();
Expand All @@ -628,24 +629,21 @@
const auto isExternal = info->_isExternal;

if (!isEncrypted && !isParentEncrypted && !isExternal && isTopFolder) {
ac = menu.addAction(tr("Encrypt"));
ac = menu->addAction(tr("Encrypt"));
connect(ac, &QAction::triggered, [this, info] { slotMarkSubfolderEncrypted(info); });
} else {
// Ignore decrypting for now since it only works with an empty folder
// connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderDecrypted(info); });
}
}

ac = menu.addAction(tr("Edit Ignored Files"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentLocalIgnoredFiles);

ac = menu.addAction(tr("Create new folder"));
ac = menu->addAction(tr("Create new folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenMakeFolderDialog);
ac->setEnabled(QFile::exists(fileName));

const auto folder = info->_folder;
if (folder && folder->virtualFilesEnabled()) {
auto availabilityMenu = menu.addMenu(tr("Availability"));
auto availabilityMenu = menu->addMenu(tr("Availability"));

// Has '/' suffix convention for paths here but VFS and
// sync engine expects no such suffix
Expand All @@ -668,7 +666,26 @@
connect(ac, &QAction::triggered, this, [this, folder, path] { slotSetSubFolderAvailability(folder, path, PinState::OnlineOnly); });
}

menu.exec(QCursor::pos());
const auto highlightColor = palette().highlight().color();
menu->setStyleSheet(QString(R"(
QMenu {
background-color: palette(window);
color: palette(window-text);
border: 1px solid black;
border-radius: 4px;
padding: 6px;
}
QMenu::item {
background-color: transparent;
padding: 8px;
}
QMenu::item:selected,
QMenu::item:hover {
background-color: %1;
}
)").arg(highlightColor.name(QColor::HexRgb)));

menu->popup(QCursor::pos());
}

void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
Expand Down Expand Up @@ -699,16 +716,13 @@
return;
}

const auto menu = new QMenu(treeView);
auto menu = new QMenu(treeView);

Check failure on line 719 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=nextmcloud_desktop&issues=AZ5jchFwxMYQet-qyaye&open=AZ5jchFwxMYQet-qyaye&pullRequest=425

menu->setAttribute(Qt::WA_DeleteOnClose);

auto ac = menu->addAction(tr("Open folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentFolder);

ac = menu->addAction(tr("Edit Ignored Files"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentIgnoredFiles);

ac = menu->addAction(tr("Create new folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenMakeFolderDialog);
ac->setEnabled(QFile::exists(folder->path()));
Expand Down Expand Up @@ -749,6 +763,8 @@
ac->setDisabled(Theme::instance()->enforceVirtualFilesSyncFolder());
}

const auto highlightColor = palette().highlight().color();

if (const auto mode = bestAvailableVfsMode();
!Theme::instance()->disableVirtualFilesSyncFolder() &&
Theme::instance()->showVirtualFilesOption() &&
Expand All @@ -764,40 +780,34 @@
}
}

menu->setStyleSheet(QString(R"(
QMenu {
background-color: palette(window);
color: palette(window-text);
border: 1px solid black;
border-radius: 4px;
padding: 6px;
}
QMenu::item {
background-color: transparent;
padding: 8px;
}
QMenu::item:selected,
QMenu::item:hover {
background-color: %1;
}
)").arg(highlightColor.name(QColor::HexRgb)));

menu->popup(treeView->mapToGlobal(pos));
menu->popup(treeView->viewport()->mapToGlobal(pos));
}

void AccountSettings::slotFolderListClicked(const QModelIndex &indx)
{
if (indx.data(FolderStatusDelegate::AddButton).toBool()) {
// "Add Folder Sync Connection"
const auto treeView = _ui->_folderList;
const auto pos = treeView->mapFromGlobal(QCursor::pos());
QStyleOptionViewItem opt;
opt.initFrom(treeView);
const auto btnRect = treeView->visualRect(indx);
const auto btnSize = treeView->itemDelegateForIndex(indx)->sizeHint(opt, indx);
const auto actual = QStyle::visualRect(opt.direction, btnRect, QRect(btnRect.topLeft(), btnSize));
if (!actual.contains(pos)) {
return;
}

if (indx.flags() & Qt::ItemIsEnabled) {
slotAddFolder();
} else {
QToolTip::showText(
QCursor::pos(),
_model->data(indx, Qt::ToolTipRole).toString(),
this);
}
return;
}
if (_model->classify(indx) == FolderStatusModel::RootFolder) {
// tries to find if we clicked on the '...' button.
const auto treeView = _ui->_folderList;
const auto pos = treeView->mapFromGlobal(QCursor::pos());
if (FolderStatusDelegate::optionsButtonRect(treeView->visualRect(indx), layoutDirection()).contains(pos)) {
if (FolderStatusDelegate::moreRectPos(treeView->visualRect(indx)).contains(pos)) {
slotCustomContextMenuRequested(pos);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountsetupcommandlinemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ void AccountSetupCommandLineManager::setupAccountFromCommandLine()
_serverUrl.clear();
_remoteDirPath.clear();
_localDirPath.clear();
_isVfsEnabled = true;
_isVfsEnabled = false;
}
}
Loading