add error handling dialog

This commit is contained in:
ochibani 2024-06-28 04:50:54 +02:00
parent 8e039c3df5
commit 965b303832
No known key found for this signature in database
GPG Key ID: 2C6B61CE0C704ED4
3 changed files with 62 additions and 34 deletions

View File

@ -7,6 +7,56 @@
<property name="logo-icon-name">blue-recorder</property>
<property name="modal">True</property>
</object>
<object class="GtkMessageDialog" id="error_dialog">
<property name="can-focus">True</property>
<property name="destroy-with-parent">True</property>
<property name="modal">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="orientation">vertical</property>
<child type="top">
<object class="GtkImage" id="error_image">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="pixel-size">32</property>
<property name="icon-name">dialog-error-symbolic</property>
</object>
</child>
<child type="center">
<object class="GtkLabel" id="error_text">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">label</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
</object>
</child>
<child type="start">
<object class="GtkExpander" id="error_expander">
<property name="label-widget">expander_label</property>
<child>
<object class="GtkTextView" id="error_details">
<property name="receives-default">False</property>
<property name="can-focus">False</property>
<property name="editable">False</property>
</object>
</child>
</object>
</child>
<child type="bottom">
<object class="GtkButton" id="error_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="label" translatable="yes">label</property>
<property name="hexpand">True</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkAdjustment" id="adjustment_delay">
<property name="upper">10</property>
<property name="step-increment">1</property>
@ -30,6 +80,11 @@
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkLabel" id="expander_label">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">label</property>
</object>
<object class="GtkWindow" id="area_chooser_window">
<property name="name">area_chooser_window</property>
<property name="can-focus">True</property>

View File

@ -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();

View File

@ -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();
}