added support for translations and printing
This commit is contained in:
@@ -27,6 +27,7 @@ import 'package:weblibre/features/geckoview/domain/entities/states/find_result.d
|
||||
import 'package:weblibre/features/geckoview/domain/entities/states/history.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/states/readerable.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/states/security.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/states/translation.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
|
||||
|
||||
part 'tab.g.dart';
|
||||
@@ -75,6 +76,7 @@ class TabState extends WebPageInfo {
|
||||
final HistoryState historyState;
|
||||
final ReaderableState readerableState;
|
||||
final FindResultState findResultState;
|
||||
final TranslationState translationState;
|
||||
|
||||
TabState({
|
||||
required this.id,
|
||||
@@ -93,6 +95,7 @@ class TabState extends WebPageInfo {
|
||||
required this.historyState,
|
||||
required this.readerableState,
|
||||
required this.findResultState,
|
||||
required this.translationState,
|
||||
}) : super(title: title.trim());
|
||||
|
||||
factory TabState.$default(String tabId) => TabState(
|
||||
@@ -111,6 +114,7 @@ class TabState extends WebPageInfo {
|
||||
historyState: HistoryState.$default(),
|
||||
readerableState: ReaderableState.$default(),
|
||||
findResultState: FindResultState.$default(),
|
||||
translationState: TranslationState.$default(),
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -130,5 +134,6 @@ class TabState extends WebPageInfo {
|
||||
historyState,
|
||||
readerableState,
|
||||
findResultState,
|
||||
translationState,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ abstract class _$TabStateCWProxy {
|
||||
|
||||
TabState findResultState(FindResultState findResultState);
|
||||
|
||||
TabState translationState(TranslationState translationState);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TabState(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
@@ -60,6 +62,7 @@ abstract class _$TabStateCWProxy {
|
||||
HistoryState historyState,
|
||||
ReaderableState readerableState,
|
||||
FindResultState findResultState,
|
||||
TranslationState translationState,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,6 +123,10 @@ class _$TabStateCWProxyImpl implements _$TabStateCWProxy {
|
||||
TabState findResultState(FindResultState findResultState) =>
|
||||
call(findResultState: findResultState);
|
||||
|
||||
@override
|
||||
TabState translationState(TranslationState translationState) =>
|
||||
call(translationState: translationState);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TabState(...).copyWith.fieldName(value)`.
|
||||
@@ -144,6 +151,7 @@ class _$TabStateCWProxyImpl implements _$TabStateCWProxy {
|
||||
Object? historyState = const $CopyWithPlaceholder(),
|
||||
Object? readerableState = const $CopyWithPlaceholder(),
|
||||
Object? findResultState = const $CopyWithPlaceholder(),
|
||||
Object? translationState = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return TabState(
|
||||
id: _value.id,
|
||||
@@ -217,6 +225,12 @@ class _$TabStateCWProxyImpl implements _$TabStateCWProxy {
|
||||
? _value.findResultState
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: findResultState as FindResultState,
|
||||
translationState:
|
||||
translationState == const $CopyWithPlaceholder() ||
|
||||
translationState == null
|
||||
? _value.translationState
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: translationState as TranslationState,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
|
||||
class TranslationState with FastEquatable {
|
||||
final bool isTranslated;
|
||||
final bool isTranslateProcessing;
|
||||
final bool isOfferTranslate;
|
||||
final bool isExpectedTranslate;
|
||||
final String? detectedLanguageCode;
|
||||
final String? userPreferredLanguageCode;
|
||||
final String? requestedFromLanguage;
|
||||
final String? requestedToLanguage;
|
||||
final String? translationErrorName;
|
||||
final bool? displayError;
|
||||
|
||||
TranslationState({
|
||||
required this.isTranslated,
|
||||
required this.isTranslateProcessing,
|
||||
required this.isOfferTranslate,
|
||||
required this.isExpectedTranslate,
|
||||
this.detectedLanguageCode,
|
||||
this.userPreferredLanguageCode,
|
||||
this.requestedFromLanguage,
|
||||
this.requestedToLanguage,
|
||||
this.translationErrorName,
|
||||
this.displayError,
|
||||
});
|
||||
|
||||
factory TranslationState.$default() => TranslationState(
|
||||
isTranslated: false,
|
||||
isTranslateProcessing: false,
|
||||
isOfferTranslate: false,
|
||||
isExpectedTranslate: false,
|
||||
);
|
||||
|
||||
factory TranslationState.fromData(TabTranslationStateData data) =>
|
||||
TranslationState(
|
||||
isTranslated: data.isTranslated,
|
||||
isTranslateProcessing: data.isTranslateProcessing,
|
||||
isOfferTranslate: data.isOfferTranslate,
|
||||
isExpectedTranslate: data.isExpectedTranslate,
|
||||
detectedLanguageCode: data.detectedLanguageCode,
|
||||
userPreferredLanguageCode: data.userPreferredLanguageCode,
|
||||
requestedFromLanguage: data.requestedFromLanguage,
|
||||
requestedToLanguage: data.requestedToLanguage,
|
||||
translationErrorName: data.translationErrorName,
|
||||
displayError: data.displayError,
|
||||
);
|
||||
|
||||
bool get hasError =>
|
||||
translationErrorName != null && (displayError ?? true);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
isTranslated,
|
||||
isTranslateProcessing,
|
||||
isOfferTranslate,
|
||||
isExpectedTranslate,
|
||||
detectedLanguageCode,
|
||||
userPreferredLanguageCode,
|
||||
requestedFromLanguage,
|
||||
requestedToLanguage,
|
||||
translationErrorName,
|
||||
displayError,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user