[fractal] appop: Remove RoomPanel enum and room_panel() func



commit 0b8055dff8603722fb027a95c158bea2bd2c6fe6
Author: Christopher Davis <brainblasted disroot org>
Date:   Tue Jan 29 11:21:52 2019 -0500

    appop: Remove RoomPanel enum and room_panel() func
    
    The functionality from these symbols have been moved into
    set_state().

 fractal-gtk/src/app/backend_loop.rs |  9 +++--
 fractal-gtk/src/appop/mod.rs        |  1 -
 fractal-gtk/src/appop/room.rs       | 68 ++-----------------------------------
 fractal-gtk/src/appop/start_chat.rs |  4 +--
 fractal-gtk/src/appop/state.rs      | 55 +++++++++++++++++++++++++++---
 5 files changed, 59 insertions(+), 78 deletions(-)
---
diff --git a/fractal-gtk/src/app/backend_loop.rs b/fractal-gtk/src/app/backend_loop.rs
index 862518b3..999910e1 100644
--- a/fractal-gtk/src/app/backend_loop.rs
+++ b/fractal-gtk/src/app/backend_loop.rs
@@ -3,7 +3,6 @@ use crate::i18n::i18n;
 use log::{error, info};
 
 use crate::actions::AppState;
-use crate::appop::RoomPanel;
 
 use glib;
 use std::process::Command;
@@ -224,17 +223,17 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
                     error!("{:?}", err);
 
                     let error = i18n("Can’t create the room, try again");
-                    let panel = RoomPanel::NoRoom;
+                    let state = AppState::NoRoom;
                     APPOP!(remove_room, (internal_id));
                     APPOP!(show_error, (error));
-                    APPOP!(room_panel, (panel));
+                    APPOP!(set_state, (state));
                 }
                 Ok(BKResponse::JoinRoomError(err)) => {
                     error!("{:?}", err);
                     let error = format!("{}", i18n("Can’t join the room, try again."));
-                    let panel = RoomPanel::NoRoom;
+                    let state = AppState::NoRoom;
                     APPOP!(show_error, (error));
-                    APPOP!(room_panel, (panel));
+                    APPOP!(set_state, (state));
                 }
                 Ok(BKResponse::LoginError(_)) => {
                     let error = i18n("Can’t login, try again");
diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs
index d87f6d13..16a127c6 100644
--- a/fractal-gtk/src/appop/mod.rs
+++ b/fractal-gtk/src/appop/mod.rs
@@ -39,7 +39,6 @@ mod user;
 
 use self::member::SearchType;
 use self::message::TmpMsg;
-pub use self::room::RoomPanel;
 
 pub struct AppOp {
     pub ui: uibuilder::UI,
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index 42a94ade..60bf9cb4 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -27,12 +27,6 @@ use rand::{thread_rng, Rng};
 
 pub struct Force(pub bool);
 
-#[derive(Debug, Clone)]
-pub enum RoomPanel {
-    Room,
-    NoRoom,
-}
-
 impl AppOp {
     pub fn remove_room(&mut self, id: String) {
         self.rooms.remove(&id);
@@ -115,7 +109,7 @@ impl AppOp {
                 return;
             }
         }
-        self.room_panel(RoomPanel::Room);
+        self.set_state(AppState::Room);
 
         let msg_entry = self.ui.sventry.view.clone();
         if let Some(buffer) = msg_entry.get_buffer() {
@@ -192,7 +186,7 @@ impl AppOp {
         self.rooms.remove(&r);
         self.active_room = None;
         self.clear_tmp_msgs();
-        self.room_panel(RoomPanel::NoRoom);
+        self.set_state(AppState::NoRoom);
 
         self.roomlist.remove_room(r);
     }
@@ -247,63 +241,7 @@ impl AppOp {
         fakeroom.name = Some(n);
         self.new_room(fakeroom, None);
         self.set_active_room_by_id(internal_id);
-        self.room_panel(RoomPanel::Room);
-    }
-
-    pub fn room_panel(&self, t: RoomPanel) {
-        let s = self
-            .ui
-            .builder
-            .get_object::<gtk::Stack>("room_view_stack")
-            .expect("Can't find room_view_stack in ui file.");
-        let headerbar = self
-            .ui
-            .builder
-            .get_object::<gtk::HeaderBar>("room_header_bar")
-            .expect("Can't find room_header_bar in ui file.");
-
-        let v = match t {
-            RoomPanel::Room => "room_view",
-            RoomPanel::NoRoom => "noroom",
-        };
-
-        s.set_visible_child_name(v);
-
-        match v {
-            "noroom" => {
-                for ch in headerbar.get_children().iter() {
-                    ch.hide();
-
-                    // Select new active room in the sidebar
-                    self.roomlist.unselect();
-                }
-            }
-            "room_view" => {
-                for ch in headerbar.get_children().iter() {
-                    ch.show();
-                }
-
-                self.ui.sventry.view.grab_focus();
-
-                let active_room_id = self.active_room.clone().unwrap_or_default();
-                let msg = self
-                    .unsent_messages
-                    .get(&active_room_id)
-                    .cloned()
-                    .unwrap_or_default();
-                if let Some(buffer) = self.ui.sventry.view.get_buffer() {
-                    buffer.set_text(&msg.0);
-
-                    let iter = buffer.get_iter_at_offset(msg.1);
-                    buffer.place_cursor(&iter);
-                }
-            }
-            _ => {
-                for ch in headerbar.get_children().iter() {
-                    ch.show();
-                }
-            }
-        }
+        self.set_state(AppState::Room);
     }
 
     pub fn cache_rooms(&self) {
diff --git a/fractal-gtk/src/appop/start_chat.rs b/fractal-gtk/src/appop/start_chat.rs
index 0c0855bf..ea4fc01d 100644
--- a/fractal-gtk/src/appop/start_chat.rs
+++ b/fractal-gtk/src/appop/start_chat.rs
@@ -1,8 +1,8 @@
 use gtk;
 use gtk::prelude::*;
 
+use crate::actions::AppState;
 use crate::appop::AppOp;
-use crate::appop::RoomPanel;
 use crate::appop::SearchType;
 
 use crate::backend::BKCommand;
@@ -31,7 +31,7 @@ impl AppOp {
 
         self.new_room(fakeroom, None);
         self.set_active_room_by_id(internal_id);
-        self.room_panel(RoomPanel::Room);
+        self.set_state(AppState::Room);
     }
 
     pub fn show_direct_chat_dialog(&mut self) {
diff --git a/fractal-gtk/src/appop/state.rs b/fractal-gtk/src/appop/state.rs
index 7cd6b433..b72f2f6f 100644
--- a/fractal-gtk/src/appop/state.rs
+++ b/fractal-gtk/src/appop/state.rs
@@ -2,23 +2,38 @@ use gtk;
 use gtk::prelude::*;
 
 use crate::actions::AppState;
-use crate::appop::room::RoomPanel;
 use crate::appop::AppOp;
 
 impl AppOp {
     pub fn set_state(&mut self, state: AppState) {
         self.state = state;
+        let stack = self
+            .ui
+            .builder
+            .get_object::<gtk::Stack>("room_view_stack")
+            .expect("Can't find room_view_stack in ui file.");
+        let headerbar = self
+            .ui
+            .builder
+            .get_object::<gtk::HeaderBar>("room_header_bar")
+            .expect("Can't find room_header_bar in ui file.");
 
+        let mut view_child = None;
         let widget_name = match self.state {
             AppState::Login => {
                 self.clean_login();
                 "login"
             }
             AppState::NoRoom => {
-                self.set_state_no_room();
+                view_child = Some("noroom");
+                self.set_state_no_room(&headerbar);
+                "chat"
+            }
+            AppState::Room => {
+                view_child = Some("room_view");
+                self.set_state_room(&headerbar);
                 "chat"
             }
-            AppState::Room => "chat",
             AppState::Directory => "directory",
             AppState::Loading => "loading",
             AppState::AccountSettings => "account-settings",
@@ -26,6 +41,10 @@ impl AppOp {
             AppState::MediaViewer => "media-viewer",
         };
 
+        view_child.map(|name| {
+            stack.set_visible_child_name(name);
+        });
+
         self.ui
             .builder
             .get_object::<gtk::Stack>("main_content_stack")
@@ -69,9 +88,35 @@ impl AppOp {
         }
     }
 
+    fn set_state_room(&self, headerbar: &gtk::HeaderBar) {
+        for ch in headerbar.get_children().iter() {
+            ch.show();
+        }
+
+        self.ui.sventry.view.grab_focus();
+
+        let active_room_id = self.active_room.clone().unwrap_or_default();
+        let msg = self
+            .unsent_messages
+            .get(&active_room_id)
+            .cloned()
+            .unwrap_or_default();
+        if let Some(buffer) = self.ui.sventry.view.get_buffer() {
+            buffer.set_text(&msg.0);
+
+            let iter = buffer.get_iter_at_offset(msg.1);
+            buffer.place_cursor(&iter);
+        }
+    }
+
     // WORKAROUND this is needed because NoRoom isn't a real app state
-    fn set_state_no_room(&mut self) {
-        self.room_panel(RoomPanel::NoRoom);
+    fn set_state_no_room(&mut self, headerbar: &gtk::HeaderBar) {
+        for ch in headerbar.get_children().iter() {
+            ch.hide();
+
+            // Select new active room in the sidebar
+            self.roomlist.unselect();
+        }
         self.active_room = None;
         self.clear_tmp_msgs();
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]