Commit e019e48d authored by Julian Sparber's avatar Julian Sparber

accountsettings: move account settings to the main window

* Upload new avatar directly without confirm
* Add scrolled view

https://gitlab.gnome.org/World/fractal/issues/21
parent 6ee5c993
......@@ -387,7 +387,7 @@ dependencies = [
[[package]]
name = "fractal-gtk"
version = "0.1.30"
version = "3.29.0"
dependencies = [
"cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
......
This diff is collapsed.
......@@ -2,7 +2,6 @@ extern crate gtk;
use self::gtk::prelude::*;
use glib;
//use std::sync::{Arc, Mutex};
use app::App;
......@@ -10,21 +9,15 @@ impl App {
pub fn connect_account_settings(&self) {
let op = &self.op;
let builder = &self.ui.builder;
let cancel = self.ui.builder
.get_object::<gtk::Button>("cancel_account_settings")
.expect("Can't find cancel_account_settings in ui file.");
let confirm = self.ui.builder
.get_object::<gtk::Button>("apply_account_settings")
.expect("Can't find join_room_button in ui file.");
let back = self.ui.builder
.get_object::<gtk::Button>("account_settings_back_button")
.expect("Can't find account_settings_back_button in ui file.");
let cancel_password = self.ui.builder
.get_object::<gtk::Button>("password-dialog-cancel")
.expect("Can't find password-dialog-cancel in ui file.");
let confirm_password = self.ui.builder
.get_object::<gtk::Button>("password-dialog-apply")
.expect("Can't find password-dialog-apply in ui file.");
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
let password_dialog = self.ui.builder
.get_object::<gtk::Dialog>("password_dialog")
.expect("Can't find password_dialog in ui file.");
......@@ -56,17 +49,8 @@ impl App {
.get_object::<gtk::Button>("account_settings_delete_btn")
.expect("Can't find account_settings_delete_btn in ui file.");
dialog.connect_delete_event(clone!(op => move |_, _| {
op.lock().unwrap().close_account_settings_dialog();
glib::signal::Inhibit(true)
}));
/* Headerbar */
cancel.connect_clicked(clone!(op => move |_| {
op.lock().unwrap().close_account_settings_dialog();
}));
confirm.connect_clicked(clone!(op => move |_| {
op.lock().unwrap().apply_account_settings();
back.connect_clicked(clone!(op => move |_| {
op.lock().unwrap().close_account_settings_dialog();
}));
......@@ -81,7 +65,7 @@ impl App {
if gtk::ResponseType::from(result) == gtk::ResponseType::Accept {
if let Some(file) = file_chooser.get_filename() {
if let Some(path) = file.to_str() {
op.lock().unwrap().save_tmp_avatar_account_settings(String::from(path));
op.lock().unwrap().update_avatar_account_settings(String::from(path));
}
}
}
......
......@@ -99,6 +99,22 @@ impl App {
.get_object::<gtk::MenuButton>("room_menu_button")
.expect("Can't find back_button in ui file.").set_valign(gtk::Align::Fill);
/* Add account settings view to the main stack */
let stack = ui.builder
.get_object::<gtk::Stack>("main_content_stack")
.expect("Can't find main_content_stack in ui file.");
let stack_header = ui.builder
.get_object::<gtk::Stack>("headerbar_stack")
.expect("Can't find headerbar_stack in ui file.");
let child = ui.builder
.get_object::<gtk::Box>("account_settings_box")
.expect("Can't find account_settings_box in ui file.");
let child_header = ui.builder
.get_object::<gtk::Box>("account_settings_headerbar")
.expect("Can't find account_settings_headerbar in ui file.");
stack.add_named(&child, "account-settings");
stack_header.add_named(&child_header, "account-settings");
let op = Arc::new(Mutex::new(
AppOp::new(gtk_app.clone(), ui.clone(), apptx, itx)
));
......
......@@ -3,6 +3,7 @@ extern crate gtk;
use self::gtk::prelude::*;
use appop::AppOp;
use appop::AppState;
use backend::BKCommand;
use widgets;
......@@ -35,8 +36,8 @@ impl AppOp {
pub fn show_phone_dialog(&self, sid: String) {
let parent = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
.get_object::<gtk::Window>("main_window")
.expect("Can't find main_window in ui file.");
let entry = gtk::Entry::new();
let msg = String::from("Insert the code recived via SMS");
......@@ -85,8 +86,8 @@ impl AppOp {
pub fn show_email_dialog(&self, sid: String) {
let parent = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
.get_object::<gtk::Window>("main_window")
.expect("Can't find main_window in ui file.");
let msg = String::from("In order to add this email address, go to your inbox and follow the link you received. Once you've done that, click 'continue'");
let flags = gtk::DialogFlags::MODAL | gtk::DialogFlags::DESTROY_WITH_PARENT;
......@@ -111,9 +112,9 @@ impl AppOp {
}
pub fn show_error_dialog(&self, error: String) {
let parent = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
let parent = self.ui.builder
.get_object::<gtk::Window>("main_window")
.expect("Can't find main_window in ui file.");
let msg = error;
let flags = gtk::DialogFlags::MODAL | gtk::DialogFlags::DESTROY_WITH_PARENT;
......@@ -145,10 +146,7 @@ impl AppOp {
}
}
pub fn show_account_settings_dialog(&self) {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
pub fn show_account_settings_dialog(&mut self) {
let avatar = self.ui.builder
.get_object::<gtk::Container>("account_settings_avatar")
.expect("Can't find account_settings_avatar in ui file.");
......@@ -210,11 +208,11 @@ impl AppOp {
destruction_flag.set_active(false);
destruction_btn.set_sensitive(false);
destruction_entry.set_text("");
dialog.set_redraw_on_allocate(true);
advanced_box.set_redraw_on_allocate(true);
delete_box.set_redraw_on_allocate(true);
dialog.present();
self.set_state(AppState::AccountSettings);
}
pub fn update_address(&self, data: Option<Vec<UserInfo>>) {
......@@ -309,11 +307,12 @@ impl AppOp {
dialog.present();
}
pub fn save_tmp_avatar_account_settings(&mut self, file: String) {
self.tmp_avatar = Some(file);
pub fn update_avatar_account_settings(&mut self, file: String) {
let command = BKCommand::SetUserAvatar(file);
self.backend.send(command).unwrap();
}
pub fn apply_account_settings(&self) {
pub fn update_username_account_settings(&self) {
let name = self.ui.builder
.get_object::<gtk::Entry>("account_settings_name")
.expect("Can't find account_settings_name in ui file.");
......@@ -324,24 +323,15 @@ impl AppOp {
if old_username != username {
self.backend.send(BKCommand::SetUserName(username)).unwrap();
}
if let Some(ref user) = self.tmp_avatar {
let command = BKCommand::SetUserAvatar(user.to_string());
self.backend.send(command).unwrap();
}
}
pub fn close_account_settings_dialog(&mut self) {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
let advanced = self.ui.builder
.get_object::<gtk::Revealer>("account_settings_advanced")
.expect("Can't find account_settings_advanced in ui file.");
let delete = self.ui.builder
.get_object::<gtk::Revealer>("account_settings_delete")
.expect("Can't find account_settings_delete in ui file.");
let advanced_toggle = self.ui.builder
.get_object::<gtk::EventBox>("account_settings_advanced_toggle")
.expect("Can't find account_settings_advanced_toggle in ui file.");
......@@ -354,8 +344,8 @@ impl AppOp {
delete_toggle.get_style_context().unwrap().remove_class("advanced_revealer_divider");
advanced.set_reveal_child(false);
delete.set_reveal_child(false);
dialog.hide();
dialog.resize(700, 200);
self.set_state(AppState::Chat);
}
pub fn set_new_password(&mut self) {
......@@ -436,8 +426,8 @@ impl AppOp {
.get_object::<gtk::CheckButton>("account_settings_delete_check")
.expect("Can't find account_settings_delete_check in ui file.");
let parent = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
.get_object::<gtk::Window>("main_window")
.expect("Can't find main_window in ui file.");
let msg = String::from("Are you sure you wan't do delete your account?");
let flags = gtk::DialogFlags::MODAL | gtk::DialogFlags::DESTROY_WITH_PARENT;
......
......@@ -12,6 +12,7 @@ pub enum AppState {
Chat,
Directory,
Loading,
AccountSettings,
}
......@@ -27,6 +28,7 @@ impl AppOp {
AppState::Chat => "chat",
AppState::Directory => "directory",
AppState::Loading => "loading",
AppState::AccountSettings => "account-settings",
};
self.ui.builder
......@@ -39,6 +41,7 @@ impl AppOp {
AppState::Login => "login",
AppState::Directory => "back",
AppState::Loading => "login",
AppState::AccountSettings => "account-settings",
_ => "normal",
};
......
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