From 9807fab32a93500f0d9c437a22ddb23f28d6af06 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Wed, 3 Feb 2021 07:38:02 +0300 Subject: [PATCH] setup UIs, get Data from config, make UI better, fix About Dialog --- src/config_management.rs | 23 ++++--- src/main.rs | 100 +++++++++++++++++++++++------ windows/ui.glade | 133 ++++++++++++++++++++------------------- 3 files changed, 164 insertions(+), 92 deletions(-) diff --git a/src/config_management.rs b/src/config_management.rs index 4ced15b..c5acf57 100644 --- a/src/config_management.rs +++ b/src/config_management.rs @@ -1,10 +1,10 @@ -extern crate ini; extern crate glib; +extern crate ini; use glib::get_user_data_dir; use ini::Ini; -use std::path::{Path, PathBuf}; use std::ops::Add; +use std::path::{Path, PathBuf}; pub fn initialize() -> PathBuf { let config_path: PathBuf = Path::new(&get_user_data_dir().unwrap()) @@ -33,16 +33,17 @@ fn default() { .add( glib::get_user_special_dir(glib::UserDirectory::Videos) .expect(std::env::var("HOME").expect("/").as_str()) - .to_str().unwrap(), + .to_str() + .unwrap(), ) .as_str(), ); set("default", "command", ""); set("default", "filename", ""); - set("default", "videocheck", "true"); - set("default", "audiocheck", "true"); - set("default", "mousecheck", "true"); - set("default", "followmousecheck", "false"); + set("default", "videocheck", "1"); + set("default", "audiocheck", "1"); + set("default", "mousecheck", "1"); + set("default", "followmousecheck", "0"); } pub fn get(selection: &str, key: &str) -> String { @@ -58,6 +59,10 @@ pub fn get(selection: &str, key: &str) -> String { ) } +pub fn get_bool(selection: &str, key: &str) -> bool { + get(&selection, &key).eq_ignore_ascii_case("1") +} + pub fn set(selection: &str, key: &str, value: &str) -> bool { let config_path: PathBuf = Path::new(&get_user_data_dir().unwrap()) .join("blue-recorder") @@ -66,3 +71,7 @@ pub fn set(selection: &str, key: &str, value: &str) -> bool { config_init.with_section(Some(selection)).set(key, value); config_init.write_to_file(&config_path).is_ok() } + +pub fn set_bool(selection: &str, key: &str, value: bool) -> bool { + set(&selection, &key, if value { "1" } else { "0" }) +} diff --git a/src/main.rs b/src/main.rs index e47de02..954c2b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,13 +2,15 @@ extern crate gio; extern crate gtk; mod config_management; +use gtk::ComboBoxText; use gio::prelude::*; use gtk::prelude::*; use gtk::{ - Adjustment, Builder, Button, CheckButton, ComboBox, Entry, FileChooser, Label, MenuItem, - SpinButton, Window, Dialog + Adjustment, Builder, Button, CheckButton, ComboBox, AboutDialog, Entry, FileChooser, Label, + MenuItem, SpinButton, Window, }; use std::path::Path; + fn main() { if gtk::init().is_err() { println!("Failed to initialize GTK."); @@ -17,26 +19,25 @@ fn main() { let builder: Builder = Builder::from_file(Path::new("windows/ui.glade")); config_management::initialize(); - config_management::set("default", "frame", "30"); // get Objects from UI - let main_window: Window = builder.get_object("window1").unwrap(); - let about_dialog: Dialog = builder.get_object("aboutdialog").unwrap(); - let area_chooser: Window = builder.get_object("window2").unwrap(); + let main_window: Window = builder.get_object("main_window").unwrap(); + let about_dialog: AboutDialog = builder.get_object("about_dialog").unwrap(); + let area_chooser: Window = builder.get_object("area_chooser_window").unwrap(); let folder_chooser: FileChooser = builder.get_object("filechooser").unwrap(); let filename_entry: Entry = builder.get_object("filename").unwrap(); let command_entry: Entry = builder.get_object("command").unwrap(); - let format_chooser: ComboBox = builder.get_object("comboboxtext1").unwrap(); + let format_chooser: ComboBoxText = builder.get_object("comboboxtext1").unwrap(); let audio_source: ComboBox = builder.get_object("audiosource").unwrap(); let record_button: Button = builder.get_object("recordbutton").unwrap(); let stop_button: Button = builder.get_object("stopbutton").unwrap(); - let window_grab_button: Button = builder.get_object("button4").unwrap(); - let area_grab_button: Button = builder.get_object("button5").unwrap(); - let frame_text: Label = builder.get_object("label2").unwrap(); - let delay_text: Label = builder.get_object("label3").unwrap(); - let command_text: Label = builder.get_object("label6").unwrap(); + let window_grab_button: Button = builder.get_object("window_grab_button").unwrap(); + let area_grab_button: Button = builder.get_object("area_grab_button").unwrap(); + let frames_label: Label = builder.get_object("frames_label").unwrap(); + let delay_label: Label = builder.get_object("delay_label").unwrap(); + let command_label: Label = builder.get_object("command_label").unwrap(); let frames_spin: SpinButton = builder.get_object("frames").unwrap(); let delay_spin: SpinButton = builder.get_object("delay").unwrap(); - let audio_source_label: Label = builder.get_object("audiosourcelabel").unwrap(); + let audio_source_label: Label = builder.get_object("audio_source_label").unwrap(); let delay_adjustment: Adjustment = builder.get_object("adjustment1").unwrap(); let frames_adjustment: Adjustment = builder.get_object("adjustment2").unwrap(); let delay_pref_adjustment: Adjustment = builder.get_object("adjustment3").unwrap(); @@ -45,18 +46,77 @@ fn main() { let audio_switch: CheckButton = builder.get_object("audioswitch").unwrap(); let mouse_switch: CheckButton = builder.get_object("mouseswitch").unwrap(); let follow_mouse_switch: CheckButton = builder.get_object("followmouseswitch").unwrap(); - let about_menu_item: MenuItem = builder.get_object("item2").unwrap(); - + let about_menu_item: MenuItem = builder.get_object("about_menu_item").unwrap(); // --- default properties + // Windows + main_window.set_title("Blue Recorder"); + + // Entries + filename_entry.set_placeholder_text(Some("Enter filename")); + command_entry.set_placeholder_text(Some("Enter your command here")); + filename_entry.set_text(&config_management::get("default", "filename")); + command_entry.set_text(&config_management::get("default", "command")); + + // format chooser + format_chooser.append(Some("mkv"), "MKV (Matroska multimedia container format)"); + format_chooser.append(Some("avi"), "AVI (Audio Video Interleaved)"); + format_chooser.append(Some("mp4"), "MP4 (MPEG-4 Part 14)"); + format_chooser.append(Some("wmv"), "WMV (Windows Media Video)"); + format_chooser.append(Some("gif"), "GIF (Graphics Interchange Format)"); + format_chooser.append(Some("nut"), "NUT (NUT Recording Format)"); + format_chooser.set_active(Some(0)); + + // Switchs + video_switch.set_label("Record Video"); + audio_switch.set_label("Record Audio"); + mouse_switch.set_label("Show Mouse"); + follow_mouse_switch.set_label("Follow Mouse"); + video_switch.set_active(config_management::get_bool("default", "videocheck")); + audio_switch.set_active(config_management::get_bool("default", "audiocheck")); + mouse_switch.set_active(config_management::get_bool("default", "mousecheck")); + follow_mouse_switch.set_active(config_management::get_bool("default", "followmousecheck")); + + + // About Dialog about_menu_item.set_label("about"); + about_dialog.set_transient_for(Some(&main_window)); + about_dialog.set_program_name("Blue Recorder"); + about_dialog.set_version(Some("3.2.3")); + about_dialog.set_copyright(Some("© 2021 Salem Yaslem")); + about_dialog.set_wrap_license(true); + about_dialog.set_license(Some("Blue Recorder is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nBlue Recorder 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.\n\nSee the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Blue Recorder. If not, see .")); + about_dialog.set_comments(Some("A simple screen recorder for Linux desktop. Supports Wayland & Xorg.")); + about_dialog.set_authors(&["Salem Yaslem ", "M.Hanny Sabbagh ", "Alessandro Toia ","Patreon Supporters: Ahmad Gharib, Medium,\nWilliam Grunow, Alex Benishek."]); + about_dialog.set_artists(&["Mustapha Assabar"]); + about_dialog.set_website(Some("https://github.com/xlmnxp/blue-recorder/")); + about_dialog.set_logo_icon_name(Some("blue-recorder")); + + // Buttons + window_grab_button.set_label("Select a Window"); + area_grab_button.set_label("Select an Area"); + // Labels + command_label.set_label("Run Command After Recording"); + frames_label.set_label("Frames"); + delay_label.set_label("Delay"); + audio_source_label.set_label("Audio Input Source"); + // Spin + frames_spin.set_value(config_management::get("default", "frame").to_string().parse::().unwrap()); + delay_spin.set_value(config_management::get("default", "delay").to_string().parse::().unwrap()); + + // Other + folder_chooser.set_uri(&config_management::get("default", "folder")); // --- connections - // show dialog window when about button clicked then hide it after close - about_menu_item.connect_activate(move |_| { - &about_dialog.run(); - &about_dialog.hide(); - }); + // show dialog window when about button clicked then hide it after close + { + let about_dialog: AboutDialog = about_dialog.to_owned(); + about_menu_item.connect_activate(move |_| { + about_dialog.run(); + about_dialog.hide(); + }); + } + // close the application when main window destroy main_window.connect_destroy(|_| { std::process::exit(0); diff --git a/windows/ui.glade b/windows/ui.glade index cf45167..4f9f2b0 100644 --- a/windows/ui.glade +++ b/windows/ui.glade @@ -2,7 +2,7 @@ - + False True dialog @@ -52,6 +52,62 @@ 1 10 + + False + True + True + center + blue-recorder + static + + + True + False + False + True + + + True + True + True + half + True + + + + True + False + 3 + True + + + True + False + dialog-ok + + + 0 + 0 + + + + + True + False + Apply + + + 1 + 0 + + + + + + + + + True False @@ -66,13 +122,13 @@ True False - + True False - + True False 0.99999999977648257 @@ -261,7 +317,7 @@ 5 True - + button True True @@ -279,7 +335,7 @@ - + button True True @@ -385,10 +441,11 @@ True False + 3 True True - + True False label @@ -414,7 +471,7 @@ - + True False label @@ -460,6 +517,8 @@ 10 5 5 + 2 + 5 True @@ -476,7 +535,7 @@ - + True False 5 @@ -489,7 +548,7 @@ - + True False 5 @@ -523,60 +582,4 @@ - - False - True - True - center - blue-recorder - static - - - True - False - False - True - - - True - True - True - half - True - - - - True - False - 3 - True - - - True - False - dialog-ok - - - 0 - 0 - - - - - True - False - Apply - - - 1 - 0 - - - - - - - - -