Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of new folders from the Settings Dialog. #2897

Merged

Conversation

allexzander
Copy link
Contributor

Signed-off-by: allexzander blackslayer4@gmail.com

Also fixed incorrect path for SubFolderInfo that was resulting in an inability to open encrypted subfolder and create a new folder inside it via the Settings Dialog's context menu.


if (!QDir(_destination).mkdir(ui->newFolderNameEdit->text())) {
QMessageBox messageBox;
messageBox.critical(0, tr("Error"), tr("Could not create a folder! Check your write permissions."));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr and not 0

That said you could have used this, since we want this message box to stack up on on top of the current dialog. Also you're calling a static method, you don't need an instance of QMessageBox for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin

nullptr and not 0

Indeed. Copy-pasted :)

if (!QDir(_destination).mkdir(ui->newFolderNameEdit->text())) {
QMessageBox messageBox;
messageBox.critical(0, tr("Error"), tr("Could not create a folder! Check your write permissions."));
messageBox.setFixedSize(500,200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is unneeded since you used the static method anyway it's not doing anything (well forcing just a fixed size on a message box which was never displayed).

@@ -333,6 +334,43 @@ void AccountSettings::slotEditCurrentIgnoredFiles()
openIgnoredFilesDialog(f->path());
}

void AccountSettings::slotOpenMkFolderDialog()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd spell "Make" fully not "Mk".

I think I'd even favor "Create" to "Make" (your call).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin I'll go with "Make" as "OpenCreate" really sounds for me like -Open and Create, instead of Open Create Folder Dialog" :)

return;
}

QString fileName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use an Immediately Invoked Lambda (IIL) here to have the filename as const. I'd even do the chop() call below in said lambda

Copy link
Contributor Author

@allexzander allexzander Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin Although, I don't consider "having something as const" as a good reason for using lambda, I'm going to add this nitpick.


QString fileName;

if (classification == FolderStatusModel::RootFolder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I guess we could have added support for FolderPathRole also on the RootFolder? This way we wouldn't need that if in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin Hmmmmmm, I don't know. This will introduce significantly more work and more QA + more chances for an error. Do we really need this sacrifice for the sake of not having if/else? I mean, if there were no other way, or if we've happened to become in need of using the same condition somewhere else, then I'd certainly vote for such refactoring, but, now, I see more evil than good if I do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, let's not do this. It came mostly out of my sheer surprise that this role wasn't supported on said roots... feels like it was overlooked back then.

delete ui;
}

void FolderCreationDialog::setDestination(const QString& destination)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before and not after &


void FolderCreationDialog::showEvent(QShowEvent *event)
{
const auto newFolderFullPath = _destination + "/" + SuggestedFolderNamePrefix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to have that inside setDestination instead?

I mean we could always construct cases where the dialog is displayed first and setDestination called a bit later asynchronously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin My intent was to make sure the dialog is always initialized when it is shown. But, I haven't made this intent clear. I will change the constructor and remove the setter now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note I didn't mind the setter. But OK let's go with a ctor parameter instead. You won't need show event anymore though, this can all be done in the ctor then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin Alrighty then. Removed.

QDialog::accept();
}

void FolderCreationDialog::on_newFolderNameEdit_textEdited(const QString &)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a matter of personal taste... but I think also a question of benefiting from compile time checks. I'd not rely on such connect via convention but have my slot named on my own convention and use and explicit connect in the ctor.

This way if it should break because something changed in the ui file (for instance) the compiler would catch it.

@@ -0,0 +1,80 @@
#include "foldercreationdialog.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright header missing

@@ -0,0 +1,34 @@
#ifndef FOLDERCREATIONDIALOG_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright header missing

@allexzander allexzander requested a review from er-vin February 2, 2021 14:35
{
const auto selected = _ui->_folderList->selectionModel()->currentIndex();
const QString fileName = [this] () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, probably my fault for being unclear. :-/

What I meant if that the IIL would be nicely used for the part starting now from QString result. Using it all the way to selected, classification and friend goes overboard and hinder readability in my opinion. This is pattern which works only for short things where typically the ternary operator wouldn't be enough but not for full blown initialization of many intermediate variables.

FolderCreationDialog folderCreationDialog;
folderCreationDialog.setDestination(fileName);
folderCreationDialog.exec();
FolderCreationDialog(fileName).exec();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note it is still on the stack, without parent and using exec. It should really go the other way around and be on the heap with a parent and using show + delete on close attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin Changed

@@ -10,30 +24,29 @@ namespace {
const QString SuggestedFolderNamePrefix = QObject::tr("New folder");
};

FolderCreationDialog::FolderCreationDialog(QWidget *parent) :
FolderCreationDialog::FolderCreationDialog(const QString &destination, QWidget *parent) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow didn't notice it earlier but we seem to use mostly that convention in our code base (although it's not my favorite):

Foo::Foo(QWidget *parent)
    : Base(parent)
    , _member1(...)
    , _member2(...)
{


void FolderCreationDialog::showEvent(QShowEvent *event)
{
const auto newFolderFullPath = _destination + "/" + SuggestedFolderNamePrefix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note I didn't mind the setter. But OK let's go with a ctor parameter instead. You won't need show event anymore though, this can all be done in the ctor then.

@allexzander allexzander force-pushed the allow-creation-of-new-folders-from-the-settings-dialog branch from ccc9272 to 0dd9be6 Compare February 2, 2021 17:48
@allexzander allexzander requested a review from er-vin February 2, 2021 17:49
return;
}

const QString fileName = [this, &selected, &classification] () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't necessarily go change it, it is more a "by the way for next time" comment. So you know you can omit the parenthesis for lambdas not taking any parameter. It's a tiny bit less syntactic noise which is always welcome.

result = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString();
}

if (!result.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that if is redundant. Indeed if result.endsWith('/') is true then !result.isEmpty() is necessarily true. Also if you're concerned about performances all the implementations of endsWith have a fast path for the empty case so it's checked in some way.


if (!fileName.isEmpty()) {
const auto folderCreationDialog = new FolderCreationDialog(fileName, this);
folderCreationDialog->open();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd open last.

Not that it'd matter in practice it's more of a readability thing IMHO.

#include <QMessageBox>

namespace {
const QString SuggestedFolderNamePrefix = QObject::tr("New folder");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs to be moved as a local variable in the ctor.

QDialog::accept();
}

void FolderCreationDialog::slotNewFolderNameEditTextEdited(const QString &)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have that parameter at all since we don't use it?

@allexzander allexzander force-pushed the allow-creation-of-new-folders-from-the-settings-dialog branch from ca478bf to 1c0c1be Compare February 3, 2021 11:51
@allexzander allexzander requested a review from er-vin February 3, 2021 11:53

connect(ui->newFolderNameEdit, &QLineEdit::textChanged, this, &FolderCreationDialog::slotNewFolderNameEditTextEdited);

const QString SuggestedFolderNamePrefix = QObject::tr("New folder");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please start the name with a lowercase s like any other variable.

@allexzander allexzander force-pushed the allow-creation-of-new-folders-from-the-settings-dialog branch 3 times, most recently from 261c9bb to eef9f68 Compare February 3, 2021 18:28
@allexzander allexzander requested a review from er-vin February 3, 2021 19:53
if (classification == FolderStatusModel::RootFolder) {
const auto alias = _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString();
const auto folderMan = FolderMan::instance();
if (const QPointer<Folder> folder = folderMan->folder(alias)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this is back or I missed the fact that the comment wasn't addressed but you don't need a QPointer here, a raw pointer is enough. There's no chance that object will be destroyed between the folder and path calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin I guess you missed it. Alright. This was copy-pasted from another method :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin Was blindly copy-pasted from void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I guess it made sense there at some point in time if one of slots connected to the actions were receiving that pointer, but not anymore since none of them use it (the folder is refetched in the slots anyway).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin Ok. Removed it. And, accidentally, cleared the history. But you can locate this change I am sure. This was the only one.

@er-vin
Copy link
Member

er-vin commented Feb 4, 2021

You can start cleaning up the history BTW. I'm confident it'll be good to go on the next iteration. ;-)

@allexzander
Copy link
Contributor Author

You can start cleaning up the history BTW. I'm confident it'll be good to go on the next iteration. ;-)

@er-vin I guess I can do it before the merge. Let's not be in hurry.

Signed-off-by: allexzander <blackslayer4@gmail.com>
@allexzander allexzander force-pushed the allow-creation-of-new-folders-from-the-settings-dialog branch from eae63dd to 81a090b Compare February 4, 2021 08:06
@nextcloud-desktop-bot
Copy link

AppImage file: Nextcloud-PR-2897-81a090b362f10df8d208924c97148b0bcff135ad-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

@allexzander allexzander merged commit 2c8fa40 into master Feb 4, 2021
@allexzander allexzander deleted the allow-creation-of-new-folders-from-the-settings-dialog branch February 4, 2021 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants