Room select signal connected

See #34
This commit is contained in:
Daniel García Moreno 2017-12-22 20:29:47 +01:00
parent c21685422b
commit 8d42e3e928
4 changed files with 27 additions and 1 deletions

View file

@ -228,7 +228,9 @@ impl Backend {
}
// Internal commands
Ok(BKCommand::SpreadResponse(resp)) => {
tx.send(resp).unwrap();
}
Ok(BKCommand::NotifyClicked(message)) => {
tx.send(BKResponse::NotificationClicked(message)).unwrap();
}

View file

@ -47,6 +47,7 @@ pub enum BKCommand {
Search(String, Option<String>),
NotifyClicked(Message),
NewRoom(String, RoomType),
SpreadResponse(BKResponse),
}
#[derive(Debug)]
@ -81,6 +82,7 @@ pub enum BKResponse {
SearchEnd,
NotificationClicked(Message),
NewRoom(Room),
RoomSelected(Room),
//errors
UserNameError(Error),

View file

@ -492,6 +492,11 @@ impl AppOp {
self.roomlist.add_room(v.clone());
}
let bk = self.backend.clone();
self.roomlist.connect(move |room| {
bk.send(BKCommand::SpreadResponse(BKResponse::RoomSelected(room))).unwrap();
});
let mut godef = def;
if let Some(aroom) = self.active_room.clone() {
if let Some(r) = self.rooms.get(&aroom) {
@ -1983,6 +1988,9 @@ fn backend_loop(op: Arc<Mutex<AppOp>>, rx: Receiver<BKResponse>) {
println!("SYNC");
op.lock().unwrap().synced(Some(since));
}
Ok(BKResponse::RoomSelected(room)) => {
op.lock().unwrap().set_active_room(&room);
}
Ok(BKResponse::Rooms(rooms, default)) => {
op.lock().unwrap().set_rooms(rooms, default);
}

View file

@ -12,6 +12,8 @@ pub struct RoomList {
pub rooms: HashMap<String, RoomRow>,
pub baseu: Url,
list: gtk::ListBox,
roomvec: Vec<Room>,
// TODO:
// * Add a header to the list
// * Add a collapse/expand button with a revealer
@ -26,11 +28,13 @@ impl RoomList {
None => Url::parse("https://matrix.org").unwrap()
};
let rooms = HashMap::new();
let roomvec = vec![];
RoomList {
list,
baseu,
rooms,
roomvec,
}
}
@ -41,6 +45,8 @@ impl RoomList {
}
let rid = r.id.clone();
self.roomvec.push(r.clone());
let row = RoomRow::new(r, &self.baseu);
self.list.add(&row.widget());
@ -76,4 +82,12 @@ impl RoomList {
b
}
pub fn connect<F: Fn(Room) + 'static>(&self, cb: F) {
let rs = self.roomvec.clone();
self.list.connect_row_activated(move |_, row| {
let idx = row.get_index();
cb(rs[idx as usize].clone());
});
}
}