54 lines
3.0 KiB
Dart
54 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
import '../app/app_controller.dart';
|
|
import '../core/models.dart';
|
|
import '../core/output_paths.dart';
|
|
import '../l10n/tr.dart';
|
|
|
|
/// P0: MKV 를 만들기 전에 결과 MKV 가 이미 있는 것이 있으면 묻는다 (환경 설정 "만들 MKV 가 이미 있으면" 이 "묻기" 일 때).
|
|
/// 돌려주는 것: 'overwrite' · 'skip' · 'rename', 이미 있는 것이 없으면 설정 값 그대로, [취소] 면 null (만들지 않음).
|
|
/// 예전에는 묻지 않고 시작해, 도중에 취소하면 예전에 완성한 MKV 까지 사라졌다
|
|
Future<String?> askExistingOutputs(BuildContext context, AppController c, List<VideoItem> targets) async {
|
|
final mode = c.settings.mkvExisting;
|
|
if (mode != 'ask') return mode;
|
|
final have = await c.withExistingOutput(targets);
|
|
if (have.isEmpty || !context.mounted) return 'ask';
|
|
final names = [for (final v in have.take(5)) p.basename(outputMkvPath(v.path))];
|
|
return showDialog<String>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
scrollable: true,
|
|
actionsOverflowDirection: VerticalDirection.down, // [취소] 가 먼저
|
|
title: Text(trf('이미 만든 MKV 가 있습니다 ({0}개)', [have.length])),
|
|
content: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
for (final n in names) Text('· $n', style: const TextStyle(fontSize: 13)),
|
|
if (have.length > names.length) Text(trf('… 외 {0}개', [have.length - names.length]), style: const TextStyle(fontSize: 13)),
|
|
const SizedBox(height: 10),
|
|
Text(tr('덮어쓰기여도 다 만든 뒤에만 바꿉니다. 도중에 취소 · 실패하면 예전 MKV 는 그대로 남습니다. '
|
|
'늘 같게 하려면 환경 설정 > MKV 만들기 > 만들 MKV 가 이미 있으면')),
|
|
]),
|
|
actions: [
|
|
TextButton(onPressed: () => Navigator.pop(ctx), child: Text(tr('취소'))),
|
|
TextButton(onPressed: () => Navigator.pop(ctx, 'skip'), child: Text(tr('건너뛰기'))),
|
|
TextButton(onPressed: () => Navigator.pop(ctx, 'rename'), child: Text(tr('다른 이름'))),
|
|
FilledButton(onPressed: () => Navigator.pop(ctx, 'overwrite'), child: Text(tr('덮어쓰기'))),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 고른 동영상을 MKV 로 - 결과가 이미 있으면 먼저 묻는다 ([취소] 면 만들지 않음)
|
|
Future<void> buildVideosAsking(BuildContext context, AppController c, List<VideoItem> targets) async {
|
|
final mode = await askExistingOutputs(context, c, targets);
|
|
if (mode == null) return;
|
|
await c.buildVideos(targets, onExisting: mode);
|
|
}
|
|
|
|
/// 아직 만들지 않은 것 모두 MKV 로 - 결과가 이미 있으면 먼저 묻는다
|
|
Future<void> buildAllAsking(BuildContext context, AppController c) async {
|
|
final mode = await askExistingOutputs(context, c, [for (final v in c.videos) if (v.status != JobStatus.done) v]);
|
|
if (mode == null) return;
|
|
await c.buildAll(onExisting: mode);
|
|
}
|