Commit 71d046b1 authored by Sophie Herold's avatar Sophie Herold
Browse files

Update to new gtk-rs release

Issue #7
parent 2082234a
......@@ -37,11 +37,11 @@ serde_derive = "1.0"
serde_json = "1.0"
# GNOME
gdk = "0.12"
gio = { version = "0.8", features = ["v2_52"] }
glib = "0.9"
gtk = { version = "0.8", features = ["v3_24"] }
pango = "0.8"
gdk-pixbuf = "0.8"
gdk = "0.13"
gdk-pixbuf = "0.9"
gio = { version = "0.9", features = ["v2_52"] }
glib = "0.10"
gtk = { version = "0.9", features = ["v3_24"] }
pango = "0.9"
[dev-dependencies]
......@@ -72,7 +72,7 @@ def struct_code(name, path):
impl {name} {{
pub fn new() -> Self {{
Self {{
builder: gtk::Builder::new_from_string(include_str!(concat!(
builder: gtk::Builder::from_string(include_str!(concat!(
data_dir!(),
"/{path}"
))),
......
......@@ -127,7 +127,7 @@ impl BackupConfig {
exclude.insert(Pattern::PathPrefix(".cache".into()));
Self {
id: glib::uuid_string_random().unwrap().to_string(),
id: glib::uuid_string_random().to_string(),
repo,
encrypted: false,
include,
......
......@@ -20,7 +20,7 @@ where
F: Fn(&borg::ListArchive) -> T,
{
let row = &main_ui().archive_list().get_selected_rows()[0];
let archive_id = row.get_widget_name().unwrap().to_string();
let archive_id = row.get_widget_name().to_string();
f(ARCHIVES.load().get(&archive_id).as_ref().unwrap())
}
......
......@@ -5,10 +5,7 @@ pub struct About {
impl About {
pub fn new() -> Self {
Self {
builder: gtk::Builder::new_from_string(include_str!(concat!(
data_dir!(),
"/ui/about.ui"
))),
builder: gtk::Builder::from_string(include_str!(concat!(data_dir!(), "/ui/about.ui"))),
}
}
......@@ -29,7 +26,7 @@ pub struct EncryptionPassword {
impl EncryptionPassword {
pub fn new() -> Self {
Self {
builder: gtk::Builder::new_from_string(include_str!(concat!(
builder: gtk::Builder::from_string(include_str!(concat!(
data_dir!(),
"/ui/encryption_password.ui"
))),
......@@ -77,10 +74,7 @@ pub struct Main {
impl Main {
pub fn new() -> Self {
Self {
builder: gtk::Builder::new_from_string(include_str!(concat!(
data_dir!(),
"/ui/main.ui"
))),
builder: gtk::Builder::from_string(include_str!(concat!(data_dir!(), "/ui/main.ui"))),
}
}
......@@ -301,7 +295,7 @@ pub struct NewBackup {
impl NewBackup {
pub fn new() -> Self {
Self {
builder: gtk::Builder::new_from_string(include_str!(concat!(
builder: gtk::Builder::from_string(include_str!(concat!(
data_dir!(),
"/ui/new_backup.ui"
))),
......@@ -433,7 +427,7 @@ pub struct Storage {
impl Storage {
pub fn new() -> Self {
Self {
builder: gtk::Builder::new_from_string(include_str!(concat!(
builder: gtk::Builder::from_string(include_str!(concat!(
data_dir!(),
"/ui/storage.ui"
))),
......
......@@ -58,18 +58,14 @@ pub fn init() {
});
main_ui().include().connect_row_activated(|_, row| {
if let Some(ref name) = row.get_widget_name() {
if name == "-add" {
add_include();
}
if row.get_widget_name() == "-add" {
add_include();
}
});
main_ui().backup_exclude().connect_row_activated(|_, row| {
if let Some(ref name) = row.get_widget_name() {
if name == "-add" {
add_exclude();
}
if row.get_widget_name() == "-add" {
add_exclude();
}
});
......@@ -194,7 +190,7 @@ pub fn add_list_row(list: &gtk::ListBox, file: &std::path::Path, position: i32)
horizontal_box.add(&label);
let button = gtk::Button::new();
button.add(&gtk::Image::new_from_icon_name(
button.add(&gtk::Image::from_icon_name(
Some("window-close-symbolic"),
gtk::IconSize::Button,
));
......@@ -252,7 +248,7 @@ pub fn refresh() {
let (_, horizontal_box) = ui::utils::add_list_box_row(&repo_ui, None, 1);
if let Ok(icon) = gio::Icon::new_for_string(&utils::repo_icon(&backup.repo)) {
let img = gtk::Image::new_from_gicon(&icon, gtk::IconSize::Dialog);
let img = gtk::Image::from_gicon(&icon, gtk::IconSize::Dialog);
horizontal_box.add(&img);
}
......
......@@ -39,19 +39,14 @@ impl Ask {
.connect_clicked(move |_| dialog.response(gtk::ResponseType::Ok));
let response = ui.dialog().run();
let password = ui
.password()
.get_text()
.map(|x| x.as_bytes().to_vec())
.map(Zeroizing::new);
let password = Zeroizing::new(ui.password().get_text().as_bytes().to_vec());
ui.dialog().close();
ui.dialog().hide();
match password {
Some(password) if gtk::ResponseType::Ok == response => {
Some((password, ui.password_store().get_active()))
}
_ => None,
if gtk::ResponseType::Ok == response {
Some((password, ui.password_store().get_active()))
} else {
None
}
}
}
......@@ -75,16 +75,15 @@ pub fn new_backup() {
}
fn add_repo_list_activated(row: &gtk::ListBoxRow, ui: Rc<builder::NewBackup>) {
if let Some(name) = row.get_widget_name() {
if name == "-add-local" {
add_local(ui);
} else if name == "-add-remote" {
ui.stack().set_visible_child(&ui.add_remote_page());
ui.add_button().show();
ui.add_button().grab_default();
} else {
add_repo_config_local(std::path::Path::new(&name), ui);
}
let name = row.get_widget_name();
if name == "-add-local" {
add_local(ui);
} else if name == "-add-remote" {
ui.stack().set_visible_child(&ui.add_remote_page());
ui.add_button().show();
ui.add_button().grab_default();
} else {
add_repo_config_local(std::path::Path::new(&name), ui);
}
}
......@@ -111,34 +110,33 @@ fn add_button_clicked(ui: Rc<builder::NewBackup>) {
main_pending::show(&gettext("Initializing new backup respository …"));
ui.new_backup().hide();
let uri = ui.add_remote_uri().get_text().unwrap();
let uri = ui.add_remote_uri().get_text();
add_repo_config_remote(uri.to_string(), ui);
}
fn init_repo_list_activated(row: &gtk::ListBoxRow, ui: &builder::NewBackup) {
if let Some(name) = row.get_widget_name() {
ui.init_dir().set_text(&format!(
"backup-{}-{}",
glib::get_host_name()
.map(|x| x.to_string())
.unwrap_or_default(),
glib::get_user_name()
.and_then(|x| x.into_string().ok())
.unwrap_or_default()
));
if name == "-init-remote" {
ui.init_location().set_visible_child(&ui.init_remote());
} else {
ui.init_location().set_visible_child(&ui.init_local());
trace!("Setting {} as init_path", &name);
ui.init_path()
.set_current_folder(std::path::PathBuf::from(&name));
}
ui.password_quality().set_value(0.0);
ui.stack().set_visible_child(&ui.init_page());
ui.init_button().show();
ui.init_button().grab_default();
ui.init_dir().set_text(&format!(
"backup-{}-{}",
glib::get_host_name()
.map(|x| x.to_string())
.unwrap_or_default(),
glib::get_user_name()
.and_then(|x| x.into_string().ok())
.unwrap_or_default()
));
let name = row.get_widget_name();
if name == "-init-remote" {
ui.init_location().set_visible_child(&ui.init_remote());
} else {
ui.init_location().set_visible_child(&ui.init_local());
trace!("Setting {} as init_path", &name);
ui.init_path()
.set_current_folder(std::path::PathBuf::from(&name));
}
ui.password_quality().set_value(0.0);
ui.stack().set_visible_child(&ui.init_page());
ui.init_button().show();
ui.init_button().grab_default();
}
fn init_button_clicked(ui: Rc<builder::NewBackup>) {
......@@ -162,12 +160,12 @@ fn init_button_clicked(ui: Rc<builder::NewBackup>) {
return;
}
path.push(ui.init_dir().get_text().unwrap().as_str());
path.push(ui.init_dir().get_text().as_str());
trace!("Init repo at {:?}", &path);
BackupConfig::new_from_path(&path)
} else {
let url = ui.init_url().get_text().unwrap().to_string();
let url = ui.init_url().get_text().to_string();
if url.is_empty() {
ui::utils::dialog_error(gettext("You have to enter a repository location."));
return;
......@@ -179,7 +177,7 @@ fn init_button_clicked(ui: Rc<builder::NewBackup>) {
let mut borg = borg::Borg::new(config.clone());
if encrypted {
let password = Zeroizing::new(ui.password().get_text().unwrap().as_bytes().to_vec());
let password = Zeroizing::new(ui.password().get_text().as_bytes().to_vec());
if ui.password_store().get_active() {
ui::utils::dialog_catch_err(
......@@ -211,7 +209,7 @@ fn init_button_clicked(ui: Rc<builder::NewBackup>) {
}
fn init_repo_password_changed(ui: &builder::NewBackup) {
let password = ui.password().get_text().unwrap_or_else(|| "".into());
let password = ui.password().get_text();
let score = if let Ok(pw_check) = zxcvbn::zxcvbn(&password, &[]) {
if pw_check.score() > 3 {
let n = pw_check.guesses_log10();
......@@ -270,7 +268,7 @@ fn add_mount(list: &gtk::ListBox, mount: &gio::Mount, repo: Option<&std::path::P
ui::utils::add_list_box_row(list, name.as_ref().map(std::borrow::Borrow::borrow), 0);
if let Some(icon) = drive.as_ref().and_then(gio::Drive::get_icon) {
let img = gtk::Image::new_from_gicon(&icon, gtk::IconSize::Dialog);
let img = gtk::Image::from_gicon(&icon, gtk::IconSize::Dialog);
horizontal_box.add(&img);
}
......
......@@ -52,12 +52,11 @@ pub fn main() {
});
main_ui().main_backups().connect_row_activated(|_, row| {
if let Some(ref name) = row.get_widget_name() {
if name == "-add" {
new_backup::new_backup()
} else {
detail::view_backup_conf(name)
}
let name = row.get_widget_name();
if name == "-add" {
new_backup::new_backup()
} else {
detail::view_backup_conf(&name)
}
});
}
......
......@@ -71,7 +71,7 @@ pub trait CronoAdditions {
impl CronoAdditions for NaiveDateTime {
fn to_glib(&self) -> glib::DateTime {
glib::DateTime::new_from_unix_local(self.timestamp())
glib::DateTime::from_unix_local(self.timestamp())
}
fn to_locale(&self) -> String {
......@@ -84,7 +84,7 @@ impl CronoAdditions for NaiveDateTime {
impl CronoAdditions for DateTime<Local> {
fn to_glib(&self) -> glib::DateTime {
glib::DateTime::new_from_unix_local(self.timestamp())
glib::DateTime::from_unix_local(self.timestamp())
}
fn to_locale(&self) -> String {
......
......@@ -304,11 +304,9 @@ pub fn dialog_yes_no<S: AsRef<str>>(message: S) -> bool {
pub fn clear(listbox: &gtk::ListBox) {
for c in listbox.get_children() {
if let Some(ref name) = c.get_widget_name() {
if name.starts_with('-') {
continue;
}
};
if c.get_widget_name().starts_with('-') {
continue;
}
listbox.remove(&c);
}
}
......@@ -372,7 +370,7 @@ pub fn file_icon(path: &std::path::PathBuf, icon_size: gtk::IconSize) -> Option<
let info = file.query_info("*", gio::FileQueryInfoFlags::NONE, none);
if let Ok(info) = info {
let icon = info.get_icon();
icon.map(|icon| gtk::Image::new_from_gicon(&icon, icon_size))
icon.map(|icon| gtk::Image::from_gicon(&icon, icon_size))
} else {
None
}
......
......@@ -83,7 +83,7 @@ fn status() -> borg::Communication {
}
fn config() -> shared::BackupConfig {
let uuid = glib::uuid_string_random().unwrap().to_string();
let uuid = glib::uuid_string_random().to_string();
shared::BackupConfig {
id: uuid.clone(),
repo: shared::BackupRepo::Local {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment