mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2024-11-23 17:13:11 +03:00
display home icons in folder chooser
This commit is contained in:
parent
3c0ea6eb37
commit
78d3fb64e5
@ -1,8 +1,10 @@
|
|||||||
extern crate glib;
|
extern crate glib;
|
||||||
extern crate ini;
|
extern crate ini;
|
||||||
|
extern crate dirs;
|
||||||
|
|
||||||
use glib::get_user_data_dir;
|
use glib::get_user_data_dir;
|
||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
|
use dirs::home_dir;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
@ -91,3 +93,24 @@ pub fn set(selection: &str, key: &str, value: &str) -> bool {
|
|||||||
pub fn set_bool(selection: &str, key: &str, value: bool) -> bool {
|
pub fn set_bool(selection: &str, key: &str, value: bool) -> bool {
|
||||||
set(&selection, &key, if value { "1" } else { "0" })
|
set(&selection, &key, if value { "1" } else { "0" })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn folder_icon(folder_chooser_name: Option<&str>) -> &str {
|
||||||
|
let home_folder = dirs::home_dir().unwrap();
|
||||||
|
if folder_chooser_name == home_folder.as_path().file_name().unwrap().to_str(){
|
||||||
|
"user-home"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
match folder_chooser_name {
|
||||||
|
Some("/") => "drive-harddisk",
|
||||||
|
Some("Desktop") => "user-desktop",
|
||||||
|
Some("Documents") => "folder-documents",
|
||||||
|
Some("Downloads") => "folder-download",
|
||||||
|
Some("Music") => "folder-music",
|
||||||
|
Some("Pictures") => "folder-pictures",
|
||||||
|
Some("Public") => "folder-publicshare",
|
||||||
|
Some("Templates") => "folder-templates",
|
||||||
|
Some("Videos") => "folder-videos",
|
||||||
|
_ => "folder",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -73,6 +73,7 @@ pub fn build_ui(application: &Application) {
|
|||||||
let delay_spin: SpinButton = builder.object("delay").unwrap();
|
let delay_spin: SpinButton = builder.object("delay").unwrap();
|
||||||
let filename_entry: Entry = builder.object("filename").unwrap();
|
let filename_entry: Entry = builder.object("filename").unwrap();
|
||||||
let folder_chooser_button: Button = builder.object("folderchooser").unwrap();
|
let folder_chooser_button: Button = builder.object("folderchooser").unwrap();
|
||||||
|
let folder_chooser_image: Image = builder.object("folderchooserimage").unwrap();
|
||||||
let folder_chooser_label: Label = builder.object("folderchooserlabel").unwrap();
|
let folder_chooser_label: Label = builder.object("folderchooserlabel").unwrap();
|
||||||
let follow_mouse_switch: CheckButton = builder.object("followmouseswitch").unwrap();
|
let follow_mouse_switch: CheckButton = builder.object("followmouseswitch").unwrap();
|
||||||
let format_chooser_combobox: ComboBoxText = builder.object("comboboxtext1").unwrap();
|
let format_chooser_combobox: ComboBoxText = builder.object("comboboxtext1").unwrap();
|
||||||
@ -250,14 +251,17 @@ pub fn build_ui(application: &Application) {
|
|||||||
let mut folder_chooser = Some(gio::File::for_uri(&config_management::get("default", "folder"))).unwrap();
|
let mut folder_chooser = Some(gio::File::for_uri(&config_management::get("default", "folder"))).unwrap();
|
||||||
let mut folder_chooser_name = folder_chooser.basename().unwrap();
|
let mut folder_chooser_name = folder_chooser.basename().unwrap();
|
||||||
folder_chooser_label.set_label(&folder_chooser_name.to_string_lossy());
|
folder_chooser_label.set_label(&folder_chooser_name.to_string_lossy());
|
||||||
|
let mut folder_chooser_icon = config_management::folder_icon(folder_chooser_name.to_str());
|
||||||
|
folder_chooser_image.set_icon_name(Some(folder_chooser_icon));
|
||||||
// show file chooser dialog
|
// show file chooser dialog
|
||||||
folder_chooser_button.connect_clicked(glib::clone!(@strong folder_chooser_native => move |_| {
|
folder_chooser_button.connect_clicked(glib::clone!(@strong folder_chooser_native => move |_| {
|
||||||
folder_chooser_native.connect_response(glib::clone!(@strong folder_chooser_native, @strong folder_chooser_label => move |_, response| {
|
folder_chooser_native.connect_response(glib::clone!(@strong folder_chooser_native, @strong folder_chooser_label, @strong folder_chooser_image => move |_, response| {
|
||||||
if response == gtk::ResponseType::Accept {
|
if response == gtk::ResponseType::Accept {
|
||||||
let folder_chooser = folder_chooser_native.file().unwrap();
|
let folder_chooser = folder_chooser_native.file().unwrap();
|
||||||
let folder_chooser_name = folder_chooser.basename().unwrap();
|
let folder_chooser_name = folder_chooser.basename().unwrap();
|
||||||
folder_chooser_label.set_label(&folder_chooser_name.to_string_lossy());
|
folder_chooser_label.set_label(&folder_chooser_name.to_string_lossy());
|
||||||
// TODO: change folder icon
|
let mut folder_chooser_icon = config_management::folder_icon(folder_chooser_name.to_str());
|
||||||
|
folder_chooser_image.set_icon_name(Some(folder_chooser_icon));
|
||||||
};
|
};
|
||||||
folder_chooser_native.destroy();
|
folder_chooser_native.destroy();
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user