From 965b303832c51e8aba3397bf2367406b028acc36 Mon Sep 17 00:00:00 2001
From: ochibani <11yzyv86j@relay.firefox.com>
Date: Fri, 28 Jun 2024 04:50:54 +0200
Subject: [PATCH] add error handling dialog
---
interfaces/main.ui | 55 ++++++++++++++++++++++++++++++++++++++++++++++
src/main.rs | 9 ++++++--
src/utils.rs | 32 ---------------------------
3 files changed, 62 insertions(+), 34 deletions(-)
diff --git a/interfaces/main.ui b/interfaces/main.ui
index d206996..2561eb9 100644
--- a/interfaces/main.ui
+++ b/interfaces/main.ui
@@ -7,6 +7,56 @@
blue-recorder
True
+
10
1
@@ -30,6 +80,11 @@
1
10
+
+ True
+ True
+ label
+
area_chooser_window
True
diff --git a/src/main.rs b/src/main.rs
index 9feca13..d0be7d4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,8 +13,8 @@ use gtk::glib;
use gtk::prelude::*;
use gtk::{
AboutDialog, Application, Builder, Button, CheckButton, ComboBoxText, CssProvider, Entry,
- FileChooserAction, FileChooserNative, Image, Label, SpinButton,
- ToggleButton, Window,
+ FileChooserAction, FileChooserNative, Image, Label, MessageDialog, SpinButton,
+ ToggleButton, TextView, Window,
};
use utils::{get_bundle, is_wayland};
use std::cell::RefCell;
@@ -69,6 +69,11 @@ pub fn build_ui(application: &Application) {
let delay_window_button: ToggleButton = builder.object("delay_window_stopbutton").unwrap();
let delay_window_label: Label = builder.object("delay_window_label").unwrap();
let delay_window_title: Label = builder.object("delay_window_title").unwrap();
+ let error_dialog: MessageDialog = builder.object("error_dialog").unwrap();
+ let error_dialog_button: Button = builder.object("error_button").unwrap();
+ let error_dialog_label: Label = builder.object("error_text").unwrap();
+ let error_expander_label: Label = builder.object("expander_label").unwrap();
+ let error_message: TextView = builder.object("error_details").unwrap();
let filename_entry: Entry = builder.object("filename").unwrap();
let folder_chooser_button: Button = builder.object("folder_chooser").unwrap();
let folder_chooser_image: Image = builder.object("folder_chooser_image").unwrap();
diff --git a/src/utils.rs b/src/utils.rs
index ab289a1..a5aa689 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,7 +1,5 @@
use fluent_bundle::bundle::FluentBundle;
use fluent_bundle::{FluentArgs, FluentResource};
-use gtk::prelude::{ButtonExt, GtkWindowExt, WidgetExt};
-use gtk::{Box, Button, ButtonsType, DialogFlags, MessageDialog, MessageType, Orientation, Window};
use std::path::Path;
pub fn is_wayland() -> bool {
@@ -14,21 +12,6 @@ pub fn is_snap() -> bool {
!std::env::var("SNAP").unwrap_or_default().is_empty()
}
-pub enum BlueRecorderError {
- Start,
- Stop,
- Play,
-}
-
-pub fn error_message(error_type: BlueRecorderError) -> String {
- let error_message = match error_type {
- BlueRecorderError::Start => get_bundle("start-error", None),
- BlueRecorderError::Stop => get_bundle("stop-error", None),
- BlueRecorderError::Play => get_bundle("play-error", None),
- };
- error_message
-}
-
// Translate
pub fn get_bundle(message_id: &str, arg: Option<&FluentArgs>) -> String {
let mut ftl_path = {
@@ -63,18 +46,3 @@ pub fn get_bundle(message_id: &str, arg: Option<&FluentArgs>) -> String {
bundle.format_pattern(bundle.get_message(message_id)
.unwrap().value().unwrap(), arg, &mut vec![]).to_string()
}
-
-pub fn show_error_dialog(message: String, window: Window) {
- let error_dialog = MessageDialog::new(
- Some(&window),
- DialogFlags::all(),
- MessageType::Error,
- ButtonsType::Close,
- &message,
- );
- let dialog_box = Box::new(Orientation::Horizontal, 10);
- let details_button = Button::new();
- details_button.set_label(&get_bundle("details-button", None));
- error_dialog.set_child(Some(&details_button));
- error_dialog.show();
-}