Skip to content

Commit

Permalink
cleanup titles rework
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Nov 26, 2023
1 parent 3c70434 commit e2ab88f
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 207 deletions.
2 changes: 1 addition & 1 deletion lib/components/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Button extends StatelessWidget {
@override
Widget build(BuildContext context) {
PushButton button = PushButton(
buttonSize: ButtonSize.large,
controlSize: ControlSize.large,
padding: EdgeInsets.only(
top: verticalPadding,
bottom: verticalPadding + 2,
Expand Down
20 changes: 11 additions & 9 deletions lib/components/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class TraxDialog {
builder: (context) => MacosAlertDialog(
appIcon: const AppIcon(),
message: Text(message),
primaryButton: SizedBox(
width: 100,
primaryButton: PushButton(
controlSize: ControlSize.large,
child: Button(
t.ok,
onPressed: () => Navigator.of(context).pop(),
Expand All @@ -43,6 +43,7 @@ class TraxDialog {
required DialogCallback onConfirmed,
DialogCallback? onCancel,
bool isDestructive = false,
bool horizontalActions = true,
Color? barrierColor,
}) {
AppLocalizations t = AppLocalizations.of(context)!;
Expand All @@ -63,15 +64,16 @@ class TraxDialog {
textAlign: TextAlign.center,
style: MacosTheme.of(context).typography.callout,
),
horizontalActions: horizontalActions,
primaryButton: PushButton(
isSecondary: isDestructive,
buttonSize: ButtonSize.large,
secondary: isDestructive,
controlSize: ControlSize.large,
onPressed: () => onConfirmed(context),
child: Text(confirmLabel ?? t.yes),
),
secondaryButton: PushButton(
isSecondary: !isDestructive,
buttonSize: ButtonSize.large,
secondary: !isDestructive,
controlSize: ControlSize.large,
onPressed: () => onCancel != null
? onCancel(context)
: Navigator.of(context).pop(),
Expand Down Expand Up @@ -109,8 +111,8 @@ class TraxDialog {
children: [
Expanded(
child: PushButton(
buttonSize: ButtonSize.small,
isSecondary: true,
controlSize: ControlSize.small,
secondary: true,
onPressed: () => onCancel != null
? onCancel(context)
: Navigator.of(context).pop(),
Expand All @@ -121,7 +123,7 @@ class TraxDialog {
Expanded(
child: PushButton(
color: Colors.green,
buttonSize: ButtonSize.small,
controlSize: ControlSize.small,
onPressed: () =>
onConfirmed(context, controller.value.text),
child: Text(t.ok),
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@
"transcodeInfoVariousSampleRates": "various sample rates",
"transcodeInfoVariousBitsPerSample": "various bits per sample",

"cleanupTitleWithCopyToComment": "Common suffix found in selected tracks titles. Do you want to move it to the comments?",
"cleanupTitleWithoutCopyToComment": "Common suffix found in selected tracks titles. Do you want to remove it?",
"cleanupTitleCommentsEmpty": "Title notes like \"(Remastered 2023)\" will be moved to comments. Continue?",
"cleanupTitleCommentsNotEmpty": "Title notes like \"(Remastered 2023)\" will overwrite current comments. Continue?",

"appName": "Trax"

Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@
"transcodeInfoVariousSampleRates": "fréquences variables",
"transcodeInfoVariousBitsPerSample": "tailles variables",

"cleanupTitleWithCopyToComment": "Suffixe commun trouvé dans les titres des pistes sélectionnées. Voulez-vous le déplacer vers les commentaires ?",
"cleanupTitleWithoutCopyToComment": "Suffixe commun trouvé dans les titres des pistes sélectionnées. Voulez-vous le supprimer ?",
"cleanupTitleCommentsEmpty": "Les notes de titre comme \"(Remastered 2023)\" vont être déplacées vers les commentaires. Continuer ?",
"cleanupTitleCommentsNotEmpty": "Les notes de titre comme \"(Remastered 2023)\" vont écrasés les commentaires existants. Continuer ?",

"appName": "Trax"

Expand Down
74 changes: 33 additions & 41 deletions lib/processors/tagger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,34 @@ class Tagger {
// needed
AppLocalizations t = AppLocalizations.of(context)!;

// find a common suffix
String? suffix = _findCommonSuffix(tracks);
if (suffix == null) {
TraxDialog.inform(context: context, message: t.cleanupTitleError);
return;
}

// check if comments are empty
bool allCommentsEmpty = _allCommentsEmpty(tracks);
TraxDialog.confirm(
context: context,
text: allCommentsEmpty
? t.cleanupTitleWithCopyToComment
: t.cleanupTitleWithoutCopyToComment,
? t.cleanupTitleCommentsEmpty
: t.cleanupTitleCommentsNotEmpty,
isDestructive: !allCommentsEmpty,
onConfirmed: (context) {
Navigator.of(context).pop();
_cleanupTitles(
tracks,
suffix,
allCommentsEmpty,
true,
);
},
);
}

void _cleanupTitles(TrackList tracks, String suffix, bool moveToComments) {
void _cleanupTitles(TrackList tracks, bool moveToComments) {
// we need a taglib
TagLib tagLib = TagLib();

// get a clean suffix for comments
String cleanSuffix = _cleanSuffix(suffix);

// now for each track
for (Track track in tracks) {
// get suffix
String? suffix = _findSuffix(track);
if (suffix == null) continue;

// reload from disk and make sure it is up to date
Tags tags = tagLib.getAudioTags(track.filename);
if (tags.title != track.tags?.title) continue;
Expand All @@ -59,7 +53,7 @@ class Tagger {
.substring(0, tags.title.length - suffix.length)
.trimRight();
if (moveToComments) {
tags.comment = cleanSuffix;
tags.comment = _cleanSuffix(suffix);
}

// save on file and in db
Expand All @@ -72,34 +66,32 @@ class Tagger {
database.notify();
}

String? _findCommonSuffix(TrackList tracks) {
//
int length = 1;
String? suffix;
String? title = tracks.first.tags?.title;
if (title == null) return null;
while (true) {
String testSuffix = title.substring(title.length - length);
bool allEndsWith = _allEndsWith(tracks, testSuffix);
if (allEndsWith == false) {
break;
} else {
suffix = testSuffix;
length++;
}
String? _findSuffix(Track track) {
// title
String title = track.tags?.title ?? '';
if (title.isEmpty) return null;
if (title.endsWith(')')) {
int index = title.lastIndexOf('(');
if (index < 0) return null;
return title.substring(index, title.length);
} else if (title.endsWith(']')) {
int index = title.lastIndexOf('[');
if (index < 0) return null;
return title.substring(index, title.length);
} else {
return null;
}
return suffix;
}

bool _allEndsWith(TrackList tracks, String suffix) {
for (Track track in tracks) {
if (track.tags?.title == null ||
track.tags!.title.endsWith(suffix) == false) {
return false;
}
}
return true;
}
// bool _allEndsWith(TrackList tracks, String suffix) {
// for (Track track in tracks) {
// if (track.tags?.title == null ||
// track.tags!.title.endsWith(suffix) == false) {
// return false;
// }
// }
// return true;
// }

bool _allCommentsEmpty(TrackList tracks) {
for (Track track in tracks) {
Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ SPEC CHECKSUMS:
macos_ui: 6229a8922cd97bafb7d9636c8eb8dfb0744183ca
macos_window_utils: 933f91f64805e2eb91a5bd057cf97cd097276663
pasteboard: 9b69dba6fedbb04866be632205d532fe2f6b1d99
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
shared_preferences_foundation: e2dae3258e06f44cc55f49d42024fd8dd03c590c
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
sqflite: a5789cceda41d54d23f31d6de539d65bb14100ea
taglib-framework: 66b9b6eed87597adb846fcd87669f6122a3a8d0f
taglib_ffi: a0f65635de6b53d49fa0d59d5ec3d532747e9f62
Expand Down
2 changes: 1 addition & 1 deletion macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading

0 comments on commit e2ab88f

Please sign in to comment.