[fractal/ui-refactor: 3/7] Relocate UI rust code files




commit 36cf563eead4881edeb39c6db2a7f79d6638ede0
Author: Alejandro Domínguez <adomu net-c com>
Date:   Tue Nov 17 18:53:29 2020 +0100

    Relocate UI rust code files

 fractal-gtk/src/actions/message.rs                 |  2 +-
 fractal-gtk/src/app/mod.rs                         | 10 ++---
 fractal-gtk/src/appop/connect/account.rs           |  2 +-
 fractal-gtk/src/appop/connect/autocomplete.rs      |  2 +-
 fractal-gtk/src/appop/connect/direct.rs            |  2 +-
 fractal-gtk/src/appop/connect/directory.rs         |  2 +-
 fractal-gtk/src/appop/connect/headerbar.rs         |  2 +-
 fractal-gtk/src/appop/connect/invite.rs            |  2 +-
 fractal-gtk/src/appop/connect/join_room.rs         |  2 +-
 fractal-gtk/src/appop/connect/language.rs          |  2 +-
 fractal-gtk/src/appop/connect/leave_room.rs        |  2 +-
 fractal-gtk/src/appop/connect/markdown.rs          |  2 +-
 fractal-gtk/src/appop/connect/new_room.rs          |  2 +-
 fractal-gtk/src/appop/connect/roomlist_search.rs   |  2 +-
 fractal-gtk/src/appop/connect/send.rs              |  2 +-
 fractal-gtk/src/appop/connect/swipeable_widgets.rs |  2 +-
 fractal-gtk/src/appop/message.rs                   |  4 +-
 fractal-gtk/src/appop/mod.rs                       |  6 +--
 fractal-gtk/src/main.rs                            |  3 +-
 fractal-gtk/src/meson.build                        |  5 +--
 fractal-gtk/src/{uibuilder.rs => ui/mod.rs}        | 46 +++++++++++++++++++++-
 fractal-gtk/src/uitypes.rs                         | 46 ----------------------
 fractal-gtk/src/widgets/media_viewer.rs            |  2 +-
 fractal-gtk/src/widgets/message.rs                 |  4 +-
 fractal-gtk/src/widgets/message_menu.rs            |  2 +-
 fractal-gtk/src/widgets/mod.rs                     |  2 +
 fractal-gtk/src/widgets/room_history.rs            |  6 +--
 27 files changed, 82 insertions(+), 84 deletions(-)
---
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index cc63cf04..2ec85142 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -12,7 +12,7 @@ use crate::app::{AppRuntime, RUNTIME};
 use crate::appop::AppOp;
 use crate::backend::HandleError;
 use crate::model::message::Message;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 use crate::util::i18n::i18n;
 use gio::ActionGroupExt;
 use gio::ActionMapExt;
diff --git a/fractal-gtk/src/app/mod.rs b/fractal-gtk/src/app/mod.rs
index f2fbec83..4f3bb651 100644
--- a/fractal-gtk/src/app/mod.rs
+++ b/fractal-gtk/src/app/mod.rs
@@ -12,7 +12,7 @@ use crate::appop::AppOp;
 
 use crate::actions;
 use crate::config;
-use crate::uibuilder;
+use crate::ui;
 use crate::widgets;
 
 mod windowstate;
@@ -42,7 +42,7 @@ macro_rules! APPOP {
 pub struct AppRuntime(glib::Sender<Box<dyn FnOnce(&mut AppOp)>>);
 
 impl AppRuntime {
-    fn init(ui: uibuilder::UI) -> Self {
+    fn init(ui: ui::UI) -> Self {
         let (app_tx, app_rx) = glib::MainContext::channel(Default::default());
         let app_runtime = Self(app_tx);
         let mut state = AppOp::new(ui, app_runtime.clone());
@@ -65,7 +65,7 @@ impl AppRuntime {
     }
 }
 
-fn new(gtk_app: gtk::Application) -> (AppRuntime, uibuilder::UI) {
+fn new(gtk_app: gtk::Application) -> (AppRuntime, ui::UI) {
     // Set up the textdomain for gettext
     setlocale(LocaleCategory::LcAll, "");
     bindtextdomain("fractal", config::LOCALEDIR);
@@ -83,7 +83,7 @@ fn new(gtk_app: gtk::Application) -> (AppRuntime, uibuilder::UI) {
         gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
     );
 
-    let ui = uibuilder::UI::new(gtk_app.clone());
+    let ui = ui::UI::new(gtk_app.clone());
     let app_runtime = AppRuntime::init(ui.clone());
 
     let settings: gio::Settings = gio::Settings::new("org.gnome.Fractal");
@@ -208,7 +208,7 @@ pub fn on_startup(gtk_app: &gtk::Application) {
     });
 }
 
-fn on_activate(ui: &uibuilder::UI) {
+fn on_activate(ui: &ui::UI) {
     ui.main_window.show();
     ui.main_window.present();
 }
diff --git a/fractal-gtk/src/appop/connect/account.rs b/fractal-gtk/src/appop/connect/account.rs
index 12a6ad6c..19ec608f 100644
--- a/fractal-gtk/src/appop/connect/account.rs
+++ b/fractal-gtk/src/appop/connect/account.rs
@@ -1,5 +1,5 @@
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 use gio::ActionMapExt;
 use glib::clone;
 use gtk::prelude::*;
diff --git a/fractal-gtk/src/appop/connect/autocomplete.rs b/fractal-gtk/src/appop/connect/autocomplete.rs
index 01af58d6..59384fac 100644
--- a/fractal-gtk/src/appop/connect/autocomplete.rs
+++ b/fractal-gtk/src/appop/connect/autocomplete.rs
@@ -3,7 +3,7 @@ use gtk::prelude::*;
 use crate::widgets;
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let popover = ui
diff --git a/fractal-gtk/src/appop/connect/direct.rs b/fractal-gtk/src/appop/connect/direct.rs
index 512ab99b..76957f1b 100644
--- a/fractal-gtk/src/appop/connect/direct.rs
+++ b/fractal-gtk/src/appop/connect/direct.rs
@@ -5,7 +5,7 @@ use glib::source::Continue;
 use std::sync::{Arc, Mutex};
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let cancel = ui
diff --git a/fractal-gtk/src/appop/connect/directory.rs b/fractal-gtk/src/appop/connect/directory.rs
index 77918f3e..3b3c7967 100644
--- a/fractal-gtk/src/appop/connect/directory.rs
+++ b/fractal-gtk/src/appop/connect/directory.rs
@@ -7,7 +7,7 @@ use libhandy::prelude::*;
 
 use crate::app::AppRuntime;
 use crate::appop::RoomSearchPagination;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let q = ui
diff --git a/fractal-gtk/src/appop/connect/headerbar.rs b/fractal-gtk/src/appop/connect/headerbar.rs
index 643f6f40..c578fead 100644
--- a/fractal-gtk/src/appop/connect/headerbar.rs
+++ b/fractal-gtk/src/appop/connect/headerbar.rs
@@ -1,4 +1,4 @@
-use crate::uibuilder::UI;
+use crate::ui::UI;
 use glib::clone;
 use gtk::prelude::*;
 use libhandy::HeaderBarExt;
diff --git a/fractal-gtk/src/appop/connect/invite.rs b/fractal-gtk/src/appop/connect/invite.rs
index dd4417ed..b4bb6a86 100644
--- a/fractal-gtk/src/appop/connect/invite.rs
+++ b/fractal-gtk/src/appop/connect/invite.rs
@@ -5,7 +5,7 @@ use glib::source::Continue;
 use std::sync::{Arc, Mutex};
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect_dialog(ui: &UI, app_runtime: AppRuntime) {
     let dialog = ui
diff --git a/fractal-gtk/src/appop/connect/join_room.rs b/fractal-gtk/src/appop/connect/join_room.rs
index b7b4ebf7..4bb3f8e6 100644
--- a/fractal-gtk/src/appop/connect/join_room.rs
+++ b/fractal-gtk/src/appop/connect/join_room.rs
@@ -2,7 +2,7 @@ use glib::clone;
 use gtk::prelude::*;
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let dialog = ui
diff --git a/fractal-gtk/src/appop/connect/language.rs b/fractal-gtk/src/appop/connect/language.rs
index c50626a8..6abd6638 100644
--- a/fractal-gtk/src/appop/connect/language.rs
+++ b/fractal-gtk/src/appop/connect/language.rs
@@ -1,6 +1,6 @@
 use crate::app::{AppRuntime, RUNTIME};
 use crate::backend::{room, HandleError};
-use crate::uibuilder::UI;
+use crate::ui::UI;
 use glib::object::Cast;
 use gtk::prelude::*;
 
diff --git a/fractal-gtk/src/appop/connect/leave_room.rs b/fractal-gtk/src/appop/connect/leave_room.rs
index 749ece4b..7df97c93 100644
--- a/fractal-gtk/src/appop/connect/leave_room.rs
+++ b/fractal-gtk/src/appop/connect/leave_room.rs
@@ -2,7 +2,7 @@ use glib::clone;
 use gtk::prelude::*;
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let dialog = ui
diff --git a/fractal-gtk/src/appop/connect/markdown.rs b/fractal-gtk/src/appop/connect/markdown.rs
index 9e6a3225..9fd80301 100644
--- a/fractal-gtk/src/appop/connect/markdown.rs
+++ b/fractal-gtk/src/appop/connect/markdown.rs
@@ -5,7 +5,7 @@ use sourceview4::prelude::*;
 use crate::util;
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let md_popover_btn = &ui.sventry.markdown;
diff --git a/fractal-gtk/src/appop/connect/new_room.rs b/fractal-gtk/src/appop/connect/new_room.rs
index 22d7fd82..b7dc8e78 100644
--- a/fractal-gtk/src/appop/connect/new_room.rs
+++ b/fractal-gtk/src/appop/connect/new_room.rs
@@ -2,7 +2,7 @@ use glib::clone;
 use gtk::prelude::*;
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let dialog = ui
diff --git a/fractal-gtk/src/appop/connect/roomlist_search.rs 
b/fractal-gtk/src/appop/connect/roomlist_search.rs
index 5a2024eb..ee00aa03 100644
--- a/fractal-gtk/src/appop/connect/roomlist_search.rs
+++ b/fractal-gtk/src/appop/connect/roomlist_search.rs
@@ -2,7 +2,7 @@ use glib::clone;
 use gtk::prelude::*;
 
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     let search_btn = ui
diff --git a/fractal-gtk/src/appop/connect/send.rs b/fractal-gtk/src/appop/connect/send.rs
index 183b8ee9..cfbe41a7 100644
--- a/fractal-gtk/src/appop/connect/send.rs
+++ b/fractal-gtk/src/appop/connect/send.rs
@@ -4,7 +4,7 @@ use sourceview4::BufferExt;
 
 use crate::actions::activate_action;
 use crate::app::AppRuntime;
-use crate::uibuilder::UI;
+use crate::ui::UI;
 
 const MAX_INPUT_HEIGHT: i32 = 100;
 
diff --git a/fractal-gtk/src/appop/connect/swipeable_widgets.rs 
b/fractal-gtk/src/appop/connect/swipeable_widgets.rs
index a38f98fa..74f879ff 100644
--- a/fractal-gtk/src/appop/connect/swipeable_widgets.rs
+++ b/fractal-gtk/src/appop/connect/swipeable_widgets.rs
@@ -1,4 +1,4 @@
-use crate::uibuilder::UI;
+use crate::ui::UI;
 use gio::prelude::*;
 use gtk::prelude::*;
 use libhandy::prelude::*;
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 460a8fc6..f6b20033 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -21,8 +21,8 @@ use crate::app::RUNTIME;
 use crate::appop::room::Force;
 use crate::appop::AppOp;
 
-use crate::uitypes::MessageContent;
-use crate::uitypes::RowType;
+use crate::ui::MessageContent;
+use crate::ui::RowType;
 use crate::widgets;
 
 use crate::model::message::Message;
diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs
index 2060ebe9..60382d2f 100644
--- a/fractal-gtk/src/appop/mod.rs
+++ b/fractal-gtk/src/appop/mod.rs
@@ -24,7 +24,7 @@ use crate::passwd::PasswordStorage;
 use crate::actions::AppState;
 use crate::app::AppRuntime;
 use crate::cache;
-use crate::uibuilder;
+use crate::ui;
 use crate::widgets;
 
 mod about;
@@ -86,7 +86,7 @@ pub struct LoginData {
 
 pub struct AppOp {
     pub app_runtime: AppRuntime,
-    pub ui: uibuilder::UI,
+    pub ui: ui::UI,
 
     pub syncing: bool, // TODO: Replace with a Mutex
     pub msg_queue: Vec<TmpMsg>,
@@ -126,7 +126,7 @@ pub struct AppOp {
 impl PasswordStorage for AppOp {}
 
 impl AppOp {
-    pub fn new(ui: uibuilder::UI, app_runtime: AppRuntime) -> AppOp {
+    pub fn new(ui: ui::UI, app_runtime: AppRuntime) -> AppOp {
         let leaflet = ui
             .builder
             .get_object::<libhandy::Leaflet>("chat_page")
diff --git a/fractal-gtk/src/main.rs b/fractal-gtk/src/main.rs
index efb0ec27..4da0513d 100644
--- a/fractal-gtk/src/main.rs
+++ b/fractal-gtk/src/main.rs
@@ -13,8 +13,7 @@ mod util;
 mod cache;
 mod model;
 mod passwd;
-mod uibuilder;
-mod uitypes;
+mod ui;
 #[macro_use]
 mod app;
 mod actions;
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index 1ad69ed6..f8a201c3 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -103,6 +103,7 @@ app_sources = files(
   'model/room.rs',
   'util/i18n.rs',
   'util/mod.rs',
+  'ui/mod.rs',
   'widgets/address.rs',
   'widgets/autocomplete.rs',
   'widgets/avatar.rs',
@@ -134,9 +135,7 @@ app_sources = files(
   'error.rs',
   'globals.rs',
   'main.rs',
-  'passwd.rs',
-  'uibuilder.rs',
-  'uitypes.rs'
+  'passwd.rs'
 )
 
 cargo_release = custom_target('cargo-build',
diff --git a/fractal-gtk/src/uibuilder.rs b/fractal-gtk/src/ui/mod.rs
similarity index 75%
rename from fractal-gtk/src/uibuilder.rs
rename to fractal-gtk/src/ui/mod.rs
index 1365e8ec..d80bad13 100644
--- a/fractal-gtk/src/uibuilder.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -1,6 +1,11 @@
+use crate::model::message::Message;
 use crate::util::i18n::i18n;
-use crate::widgets::SVEntry;
+use crate::widgets::{self, SVEntry};
+use chrono::prelude::{DateTime, Local};
 use gtk::{self, prelude::*};
+use matrix_sdk::identifiers::{EventId, UserId};
+use std::path::PathBuf;
+use url::Url;
 
 #[derive(Clone, Debug)]
 pub struct UI {
@@ -102,3 +107,42 @@ impl UI {
         }
     }
 }
+
+/* MessageContent contains all data needed to display one row
+ * therefore it should contain only one Message body with one format
+ * To-Do: this should be moved to a file collecting all structs used in the UI */
+#[derive(Debug, Clone)]
+pub struct MessageContent {
+    pub id: Option<EventId>,
+    pub sender: UserId,
+    pub sender_name: Option<String>,
+    pub mtype: RowType,
+    pub body: String,
+    pub date: DateTime<Local>,
+    pub replace_date: Option<DateTime<Local>>,
+    pub thumb: Option<Url>,
+    pub url: Option<Url>,
+    pub local_path: Option<PathBuf>,
+    pub formatted_body: Option<String>,
+    pub format: Option<String>,
+    /* in some places we still need the backend message type (e.g. media viewer) */
+    pub msg: Message,
+    pub highlights: Vec<String>,
+    pub redactable: bool,
+    pub last_viewed: bool,
+    pub widget: Option<widgets::MessageBox>,
+}
+
+/* To-Do: this should be moved to a file collecting all structs used in the UI */
+#[derive(Debug, Copy, Clone, PartialEq)]
+pub enum RowType {
+    Mention,
+    Emote,
+    Message,
+    Sticker,
+    Image,
+    Audio,
+    Video,
+    File,
+    Emoji,
+}
diff --git a/fractal-gtk/src/widgets/media_viewer.rs b/fractal-gtk/src/widgets/media_viewer.rs
index ee4c5fa8..3f74ccaa 100644
--- a/fractal-gtk/src/widgets/media_viewer.rs
+++ b/fractal-gtk/src/widgets/media_viewer.rs
@@ -21,7 +21,7 @@ use url::Url;
 
 use crate::model::{message::Message, room::Room};
 
-use crate::uitypes::RowType;
+use crate::ui::RowType;
 use crate::widgets::image;
 use crate::widgets::message_menu::MessageMenu;
 use crate::widgets::ErrorDialog;
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index ece498f7..1c4beb6f 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -17,8 +17,8 @@ use crate::cache::download_to_cache_username;
 use crate::cache::download_to_cache_username_emote;
 
 use crate::globals;
-use crate::uitypes::MessageContent as Message;
-use crate::uitypes::RowType;
+use crate::ui::MessageContent as Message;
+use crate::ui::RowType;
 use crate::widgets;
 use crate::widgets::message_menu::MessageMenu;
 use crate::widgets::AvatarExt;
diff --git a/fractal-gtk/src/widgets/message_menu.rs b/fractal-gtk/src/widgets/message_menu.rs
index 0aaa5ea4..32073137 100644
--- a/fractal-gtk/src/widgets/message_menu.rs
+++ b/fractal-gtk/src/widgets/message_menu.rs
@@ -2,7 +2,7 @@ use gdk::prelude::*;
 use gtk::prelude::*;
 use matrix_sdk::identifiers::EventId;
 
-use crate::uitypes::RowType;
+use crate::ui::RowType;
 
 #[derive(Clone)]
 struct Widgets {
diff --git a/fractal-gtk/src/widgets/mod.rs b/fractal-gtk/src/widgets/mod.rs
index dc012720..85572beb 100644
--- a/fractal-gtk/src/widgets/mod.rs
+++ b/fractal-gtk/src/widgets/mod.rs
@@ -1,3 +1,5 @@
+// TODO: Move everything to ui module
+
 mod address;
 mod autocomplete;
 pub mod avatar;
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index f53f1770..7964ba4d 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -9,9 +9,9 @@ use std::collections::VecDeque;
 use std::rc::Rc;
 
 use crate::appop::UserInfoCache;
-use crate::uibuilder::UI;
-use crate::uitypes::MessageContent;
-use crate::uitypes::RowType;
+use crate::ui::MessageContent;
+use crate::ui::RowType;
+use crate::ui::UI;
 use crate::util::i18n::i18n;
 
 use crate::globals;


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