Commit 7b4fe55a authored by Julian Sparber's avatar Julian Sparber

show user info in popover

parent 9a0d36b7
Pipeline #5504 passed with stage
in 8 minutes and 28 seconds
......@@ -227,6 +227,92 @@
<property name="margin_bottom">6</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<property name="width_request">200</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<child>
<object class="GtkStack" id="user_info">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkSpinner" id="user_info_spinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
<property name="hexpand">True</property>
<property name="margin_top">10</property>
</object>
<packing>
<property name="name">spinner</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="user_info_avatar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="valign">center</property>
<child>
<object class="GtkLabel" id="user_info_username">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label"></property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="user_info_uid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label"></property>
<style>
<class name="member-uid"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="name">info</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="account_settings_menu">
<property name="visible">False</property>
......@@ -238,12 +324,12 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
......@@ -251,7 +337,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
......
......@@ -86,6 +86,7 @@ pub struct AppOp {
pub username: Option<String>,
pub uid: Option<String>,
pub avatar: Option<String>,
pub server_url: String,
pub autoscroll: bool,
......@@ -173,6 +174,7 @@ impl AppOp {
rooms: HashMap::new(),
username: None,
uid: None,
avatar: None,
server_url: String::from("https://matrix.org"),
syncing: false,
tmp_msgs: vec![],
......@@ -206,7 +208,8 @@ impl AppOp {
self.set_state(AppState::Chat);
self.set_uid(Some(uid.clone()));
self.set_username(Some(uid));
/* Do we need to set the username to uid
self.set_username(Some(uid));*/
self.get_username();
// initial sync, we're shoing some feedback to the user
......@@ -456,25 +459,52 @@ impl AppOp {
self.backend.send(BKCommand::GetAvatar).unwrap();
}
pub fn set_username(&mut self, username: Option<String>) {
self.username = username;
}
pub fn show_user_info (&self) {
let stack = self.gtk_builder
.get_object::<gtk::Stack>("user_info")
.expect("Can't find user_info_avatar in ui file.");
pub fn set_uid(&mut self, uid: Option<String>) {
self.uid = uid;
}
/* Show user infos inside the popover but wait for all data to arrive */
if self.avatar.is_some() && self.username.is_some() && self.uid.is_some() {
let avatar = self.gtk_builder
.get_object::<gtk::Container>("user_info_avatar")
.expect("Can't find user_info_avatar in ui file.");
let name = self.gtk_builder
.get_object::<gtk::Label>("user_info_username")
.expect("Can't find user_info_avatar in ui file.");
let uid = self.gtk_builder
.get_object::<gtk::Label>("user_info_uid")
.expect("Can't find user_info_avatar in ui file.");
uid.set_text(&self.uid.clone().unwrap_or_default());
name.set_text(&self.username.clone().unwrap_or_default());
/* remove all old avatar from the popover */
for w in avatar.get_children().iter() {
avatar.remove(w);
}
let w = widgets::Avatar::circle_avatar(self.avatar.clone().unwrap_or_default(), Some(40));
avatar.add(&w);
stack.set_visible_child_name("info");
}
else {
stack.set_visible_child_name("spinner");
}
pub fn set_avatar(&self, fname: Option<String>) {
/* update user menu button avatar */
let button = self.gtk_builder
.get_object::<gtk::MenuButton>("user_menu_button")
.expect("Can't find user_menu_button in ui file.");
let eb = gtk::EventBox::new();
match fname {
Some(s) => {
let w = widgets::Avatar::circle_avatar(s, Some(20));
eb.add(&w);
}
match self.avatar.clone() {
Some(s) => {
let w = widgets::Avatar::circle_avatar(s.clone(), Some(20));
eb.add(&w);
}
None => {
let w = gtk::Spinner::new();
w.show();
......@@ -487,6 +517,21 @@ impl AppOp {
button.set_image(&eb);
}
pub fn set_username(&mut self, username: Option<String>) {
self.username = username;
self.show_user_info();
}
pub fn set_uid(&mut self, uid: Option<String>) {
self.uid = uid;
self.show_user_info();
}
pub fn set_avatar(&mut self, fname: Option<String>) {
self.avatar = fname;
self.show_user_info();
}
pub fn disconnect(&self) {
self.backend.send(BKCommand::ShutDown).unwrap();
}
......
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