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

feat: replace spaces by another delimiter in renamer #1827

Merged
merged 8 commits into from
Dec 7, 2024

Conversation

taniashafiei
Copy link
Contributor

add feature from request #1082

@bugwelle
Copy link
Collaborator

bugwelle commented Dec 3, 2024

Hi!

First of all: THANK YOU for opening a PR! That is very much welcome and I'm glad other people are interested in developing MediaElch!

Due to the size of this PR, I will likely not get to review this this week. See #1710 for reasons (time constraints).

The renamer is old and not well written. The fact that you had to adapt so many places is a sign for that. :)

Do you want me to change minor stuff like renaming defaultValue to defaultDelimiter myself or should I add code comments, so that you can pick it up? Whatever suites you best.

Regards,
Andre

@@ -71,6 +71,15 @@ QString Renamer::replaceCondition(QString& text, const QString& condition, bool
return text;
}

bool Renamer::replaceDelimiter(QString& text, QString oldDelimiter, QString newDelimiter, bool execCondition)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The third argument seems strange. I think it would be better to remove it and move the boolean into a condition surrounding the call to replaceDelimiter:

if (execCondition) {
  Renamer::replaceDelimiter(...)
}

Reason being: It is not clear to the caller what the third argument does.

Also: `sanitizeFolderName` already calls `sanitizeFileName` in your PR. Why call `sanitizeFileName` after `replaceDelimiter` in `*Renamer.cpp`? :)

Copy link
Contributor Author

@taniashafiei taniashafiei Dec 6, 2024

Choose a reason for hiding this comment

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

Hello, I made some modifications based on the feedback you gave me. If there are other things that need to be changed, please let me know, and I will try to do it as soon as possible ! You can add code comments if that works best for you. ^^.

Copy link
Collaborator

@bugwelle bugwelle left a comment

Choose a reason for hiding this comment

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

Hi,

thanks! I've pushed a commit that reviews/changes this PR a bit. I'll leave comments as well, but note that those are fixed in my commit and are only meant for reference. :)

Regards,
Andre

@@ -228,11 +228,12 @@ void sanitizeFileName(QString& fileName)
fileName.replace(QRegularExpression(R"(\s\s+)"), " ");

fileName = fileName.trimmed();
Renamer::replaceDelimiter(fileName, " ", defaultDelimiter);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The function is just a text.replace() call. The helper file shouldn't depend on the Renamer one. It would be best to replace this call by the function's contents. :)

}

void sanitizeFolderName(QString& fileName)
void sanitizeFolderName(QString& fileName, QString defaultDelimiter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer const QString&, as we don't need the string to be mutable. :)

<item row="1" column="1">
<widget class="PlaceholderLineEdit" name="fileNaming">
<property name="currentText">
<string notr="true">&lt;title&gt;.&lt;extension&gt;</string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This somehow got lost?

@@ -847,6 +876,13 @@ void Settings::renamings(RenameType renameType, bool& files, bool& folders, bool
seasonDirectories =
settings()->value(QString("RenamePattern/%1/UseSeasonDirectories").arg(renameTypeStr), true).toBool();
}
void Settings::renamings(RenameType renameType, bool& files, bool& folders, bool& seasonDirectories, bool& replaceDelimiter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no need to add another method. Adapting the existing one is fine. :)
The code isn't great to begin with, so adding another argument is ok here.

{
Settings::setRenamings(renameType, files, folders, seasonDirectories);
const QString renameTypeStr = renamerTypeToString(renameType);
settings()->setValue(QString("RenamePattern/%1/ReplaceDelimiter").arg(renameTypeStr), replaceDelimiter);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer Delimiter, because that's what it is intended to be: a delimiter between words. That we only replace spaces is a restriction or implementation detail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, this comment was meant for the string value, not the boolean value. :)

@bugwelle bugwelle merged commit e5ff8de into Komet:master Dec 7, 2024
@taniashafiei
Copy link
Contributor Author

taniashafiei commented Dec 8, 2024

Thank you for your feedback, the correcting and merging the pr ! I will take note of those for future contributions.

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.

2 participants