Commit 1c910b5a authored by Daniel García Moreno's avatar Daniel García Moreno

Room config dialog with leave button working

parent 1d8a7faa
Fixs:
* Fix room list after join
* Add mentions tab with a search of the username
* Ignore launched threads when changing room...
* Sort rooms by last message or fav?
Functionality:
* Register
* Leave room
* Room creation
* Set topic
* Set room avatar
* Set room name
* Register
* Room creation
* Change user display name
* Change user avatar
* Show media messages (images / videos)
......
......@@ -76,8 +76,7 @@
<child>
<object class="GtkTreeViewColumn">
<child>
<object class="GtkCellRendererText">
</object>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
......@@ -193,7 +192,7 @@
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="room_config_button">
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
......@@ -742,6 +741,203 @@ Join a room to start to chat</property>
</object>
</child>
</object>
<object class="GtkDialog" id="room_config_dialog">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="deletable">False</property>
<property name="gravity">center</property>
<property name="transient_for">main_window</property>
<property name="attached_to">main_window</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="room_dialog_set">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="room_dialog_close">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">5</property>
<property name="column_spacing">10</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Avatar</property>
<property name="justify">right</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="halign">end</property>
<property name="label" translatable="yes">Name</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Topic</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImage" id="room_avatar_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFileChooserButton" id="room_avatar_filechooser">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="room_name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="secondary_icon_tooltip_text" translatable="yes">room name</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="room_topic_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="secondary_icon_tooltip_text" translatable="yes">room topic</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="room_leave_button">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Leave this room</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">1</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkPopover" id="user_menu">
<property name="can_focus">False</property>
<property name="relative_to">user_button</property>
......
......@@ -394,7 +394,11 @@ impl AppOp {
let name_label = self.gtk_builder
.get_object::<gtk::Label>("room_name")
.expect("Can't find room_name in ui file.");
let edit = self.gtk_builder
.get_object::<gtk::Entry>("room_name_entry")
.expect("Can't find room_name_entry in ui file.");
name_label.set_text(&name);
edit.set_text(&name);
// getting room details
self.backend.send(BKCommand::SetRoom(self.active_room.clone())).unwrap();
......@@ -407,14 +411,24 @@ impl AppOp {
let name_label = self.gtk_builder
.get_object::<gtk::Label>("room_name")
.expect("Can't find room_name in ui file.");
let edit = self.gtk_builder
.get_object::<gtk::Entry>("room_name_entry")
.expect("Can't find room_name_entry in ui file.");
name_label.set_text(&value);
edit.set_text(&value);
}
"m.room.topic" => {
let topic_label = self.gtk_builder
.get_object::<gtk::Label>("room_topic")
.expect("Can't find room_topic in ui file.");
let edit = self.gtk_builder
.get_object::<gtk::Entry>("room_topic_entry")
.expect("Can't find room_topic_entry in ui file.");
topic_label.set_tooltip_text(&value[..]);
topic_label.set_text(&value);
edit.set_text(&value);
}
_ => println!("no key {}", key),
};
......@@ -424,13 +438,18 @@ impl AppOp {
let image = self.gtk_builder
.get_object::<gtk::Image>("room_image")
.expect("Can't find room_image in ui file.");
let config = self.gtk_builder
.get_object::<gtk::Image>("room_avatar_image")
.expect("Can't find room_avatar_image in ui file.");
if !avatar.is_empty() {
if let Ok(pixbuf) = Pixbuf::new_from_file_at_size(&avatar, 40, 40) {
image.set_from_pixbuf(&pixbuf);
config.set_from_pixbuf(&pixbuf);
}
} else {
image.set_from_icon_name("image-missing", 5);
config.set_from_icon_name("image-missing", 5);
}
}
......@@ -666,6 +685,39 @@ impl AppOp {
self.room_panel(RoomPanel::Room);
}
}
pub fn show_room_dialog(&self) {
let dialog = self.gtk_builder
.get_object::<gtk::Dialog>("room_config_dialog")
.expect("Can't find room_config_dialog in ui file.");
dialog.show();
}
pub fn leave_active_room(&mut self) {
let r = self.active_room.clone();
self.backend.send(BKCommand::LeaveRoom(r.clone())).unwrap();
self.rooms.remove(&r);
self.active_room = String::new();
self.room_panel(RoomPanel::NoRoom);
let store: gtk::TreeStore = self.gtk_builder
.get_object("rooms_tree_store")
.expect("Couldn't find rooms_tree_store in ui file.");
if let Some(iter) = store.get_iter_first() {
loop {
let v1 = store.get_value(&iter, 1);
let id: &str = v1.get().unwrap();
if id == r {
store.remove(&iter);
}
if !store.iter_next(&iter) {
break;
}
}
}
}
}
/// State for the main thread.
......@@ -773,6 +825,8 @@ impl App {
Ok(BKResponse::JoinRoom) => {
theop.lock().unwrap().reload_rooms();
}
Ok(BKResponse::LeaveRoom) => {
}
Ok(BKResponse::MarkedAsRead(r, _)) => {
theop.lock().unwrap().update_room_notifications(&r, |_| 0);
}
......@@ -831,6 +885,54 @@ impl App {
self.connect_send();
self.connect_directory();
self.connect_room_config();
}
fn connect_room_config(&self) {
// room config button
let mut btn = self.gtk_builder
.get_object::<gtk::Button>("room_config_button")
.expect("Can't find room_config_button in ui file.");
let mut op = self.op.clone();
btn.connect_clicked(move |_| {
op.lock().unwrap().show_room_dialog();
});
// room leave button
let dialog = self.gtk_builder
.get_object::<gtk::Dialog>("room_config_dialog")
.expect("Can't find room_config_dialog in ui file.");
btn = self.gtk_builder
.get_object::<gtk::Button>("room_leave_button")
.expect("Can't find room_leave_button in ui file.");
op = self.op.clone();
let d = dialog.clone();
btn.connect_clicked(move |_| {
op.lock().unwrap().leave_active_room();
d.hide();
});
btn = self.gtk_builder
.get_object::<gtk::Button>("room_dialog_close")
.expect("Can't find room_dialog_close in ui file.");
let d = dialog.clone();
btn.connect_clicked(move |_| {
d.hide();
});
// TODO: connect OK
let name = self.gtk_builder
.get_object::<gtk::Entry>("room_name_entry")
.expect("Can't find room_name_entry in ui file.");
let topic = self.gtk_builder
.get_object::<gtk::Entry>("room_topic_entry")
.expect("Can't find room_topic_entry in ui file.");
let avatar = self.gtk_builder
.get_object::<gtk::Image>("room_avatar_image")
.expect("Can't find room_avatar_image in ui file.");
let avatar_fs = self.gtk_builder
.get_object::<gtk::FileChooserButton>("room_avatar_filechooser")
.expect("Can't find room_avatar_filechooser in ui file.");
}
fn connect_directory(&self) {
......@@ -1002,6 +1104,7 @@ impl App {
glib::set_application_name("guillotine");
glib::set_prgname(Some("guillotine"));
gtk::main();
libnotify::uninit();
......
......@@ -61,6 +61,7 @@ pub enum BKCommand {
DirectorySearch(String, String, bool),
JoinRoom(String),
MarkAsRead(String, String),
LeaveRoom(String),
}
#[derive(Debug)]
......@@ -80,6 +81,7 @@ pub enum BKResponse {
DirectoryProtocols(Vec<Protocol>),
DirectorySearch(Vec<Room>),
JoinRoom,
LeaveRoom,
MarkedAsRead(String, String),
//errors
......@@ -98,6 +100,7 @@ pub enum BKResponse {
DirectoryError(Error),
JoinRoomError(Error),
MarkAsReadError(Error),
LeaveRoomError(Error),
}
......@@ -195,6 +198,10 @@ impl Backend {
let r = self.join_room(roomid);
bkerror!(r, tx, BKResponse::JoinRoomError);
}
Ok(BKCommand::LeaveRoom(roomid)) => {
let r = self.leave_room(roomid);
bkerror!(r, tx, BKResponse::LeaveRoomError);
}
Ok(BKCommand::MarkAsRead(roomid, evid)) => {
let r = self.mark_as_read(roomid, evid);
bkerror!(r, tx, BKResponse::MarkAsReadError);
......@@ -728,6 +735,23 @@ impl Backend {
Ok(())
}
pub fn leave_room(&self, roomid: String) -> Result<(), Error> {
let baseu = self.get_base_url()?;
let tk = self.data.lock().unwrap().access_token.clone();
let mut url = baseu.join("/_matrix/client/r0/rooms/")?.join(&(roomid.clone() + "/leave"))?;
url = url.join(&format!("?access_token={}", tk))?;
let tx = self.tx.clone();
post!(&url,
move |_: JsonValue| {
tx.send(BKResponse::LeaveRoom).unwrap();
},
|err| { tx.send(BKResponse::LeaveRoomError(err)).unwrap(); }
);
Ok(())
}
pub fn mark_as_read(&self, roomid: String, eventid: String) -> Result<(), Error> {
let baseu = self.get_base_url()?;
let tk = self.data.lock().unwrap().access_token.clone();
......
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