mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2024-11-23 17:13:11 +03:00
setup UIs, get Data from config, make UI better, fix About Dialog
This commit is contained in:
parent
f1e9e7677f
commit
9807fab32a
@ -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" })
|
||||
}
|
||||
|
100
src/main.rs
100
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 <http://www.gnu.org/licenses/>."));
|
||||
about_dialog.set_comments(Some("A simple screen recorder for Linux desktop. Supports Wayland & Xorg."));
|
||||
about_dialog.set_authors(&["Salem Yaslem <s@sy.sa>", "M.Hanny Sabbagh <mhsabbagh@outlook.com>", "Alessandro Toia <gort818@gmail.com>","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::<f64>().unwrap());
|
||||
delay_spin.set_value(config_management::get("default", "delay").to_string().parse::<f64>().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);
|
||||
|
133
windows/ui.glade
133
windows/ui.glade
@ -2,7 +2,7 @@
|
||||
<!-- Generated with glade 3.22.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.16"/>
|
||||
<object class="GtkAboutDialog" id="aboutdialog">
|
||||
<object class="GtkAboutDialog" id="about_dialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
@ -52,6 +52,62 @@
|
||||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="area_chooser_window">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="window_position">center</property>
|
||||
<property name="icon_name">blue-recorder</property>
|
||||
<property name="gravity">static</property>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar" id="headerbar2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="has_subtitle">False</property>
|
||||
<property name="show_close_button">True</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="areasettings">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="relief">half</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="areasettings" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="column_spacing">3</property>
|
||||
<property name="row_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">dialog-ok</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Apply</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
@ -66,13 +122,13 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="item2">
|
||||
<object class="GtkMenuItem" id="about_menu_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<object class="GtkWindow" id="main_window">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="opacity">0.99999999977648257</property>
|
||||
@ -261,7 +317,7 @@
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button4">
|
||||
<object class="GtkButton" id="window_grab_button">
|
||||
<property name="label" translatable="yes">button</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
@ -279,7 +335,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button5">
|
||||
<object class="GtkButton" id="area_grab_button">
|
||||
<property name="label" translatable="yes">button</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
@ -385,10 +441,11 @@
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="row_spacing">3</property>
|
||||
<property name="row_homogeneous">True</property>
|
||||
<property name="column_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label2">
|
||||
<object class="GtkLabel" id="frames_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
@ -414,7 +471,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label3">
|
||||
<object class="GtkLabel" id="delay_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
@ -460,6 +517,8 @@
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="row_spacing">2</property>
|
||||
<property name="column_spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="command">
|
||||
<property name="visible">True</property>
|
||||
@ -476,7 +535,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label6">
|
||||
<object class="GtkLabel" id="command_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">5</property>
|
||||
@ -489,7 +548,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="audiosourcelabel">
|
||||
<object class="GtkLabel" id="audio_source_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">5</property>
|
||||
@ -523,60 +582,4 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window2">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="window_position">center</property>
|
||||
<property name="icon_name">blue-recorder</property>
|
||||
<property name="gravity">static</property>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar" id="headerbar2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="has_subtitle">False</property>
|
||||
<property name="show_close_button">True</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="areasettings">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="relief">half</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="areasettings" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="column_spacing">3</property>
|
||||
<property name="row_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">dialog-ok</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Apply</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
Loading…
Reference in New Issue
Block a user