[fractal/split-async-state-ui-appop-mgmt: 10/13] Move stuff in notify from AppOp to UI




commit 6950ebe325c524bbe6a862c917698ce3c09cae93
Author: Alejandro Domínguez <adomu net-c com>
Date:   Sat Dec 5 12:26:59 2020 +0100

    Move stuff in notify from AppOp to UI

 fractal-gtk/src/appop/notify.rs | 40 ++++------------------------------------
 fractal-gtk/src/appop/sync.rs   |  5 +++--
 fractal-gtk/src/meson.build     |  1 +
 fractal-gtk/src/ui/mod.rs       |  1 +
 fractal-gtk/src/ui/notify.rs    | 37 +++++++++++++++++++++++++++++++++++++
 5 files changed, 46 insertions(+), 38 deletions(-)
---
diff --git a/fractal-gtk/src/appop/notify.rs b/fractal-gtk/src/appop/notify.rs
index cbfa7a9d..7d386a9e 100644
--- a/fractal-gtk/src/appop/notify.rs
+++ b/fractal-gtk/src/appop/notify.rs
@@ -1,44 +1,15 @@
 use crate::app::RUNTIME;
+use crate::appop::AppOp;
 use crate::backend::user;
+use crate::util::i18n::i18n;
 use gio::ApplicationExt;
 use gio::FileExt;
 use gio::Notification;
-use gtk::prelude::*;
 use log::info;
 use matrix_sdk::identifiers::{EventId, RoomId};
 use std::path::Path;
 
-use crate::util::i18n::i18n;
-
-use crate::appop::AppOp;
-
-use crate::widgets::ErrorDialog;
-
 impl AppOp {
-    pub fn inapp_notify(&self, msg: &str) {
-        let inapp: gtk::Revealer = self
-            .ui
-            .builder
-            .get_object("inapp_revealer")
-            .expect("Can't find inapp_revealer in ui file.");
-        let label: gtk::Label = self
-            .ui
-            .builder
-            .get_object("inapp_label")
-            .expect("Can't find inapp_label in ui file.");
-        label.set_text(msg);
-        inapp.set_reveal_child(true);
-    }
-
-    pub fn hide_inapp_notify(&self) {
-        let inapp: gtk::Revealer = self
-            .ui
-            .builder
-            .get_object("inapp_revealer")
-            .expect("Can't find inapp_revealer in ui file.");
-        inapp.set_reveal_child(false);
-    }
-
     pub fn notify(&self, app: gtk::Application, room_id: RoomId, id: EventId) -> Option<()> {
         let session_client = self.login_data.as_ref()?.session_client.clone();
         let msg = self.get_message_by_id(&room_id, &id)?;
@@ -77,14 +48,11 @@ impl AppOp {
     }
 
     pub fn show_error(&self, msg: String) {
-        ErrorDialog::new(false, &msg);
+        self.ui.show_error(msg);
     }
 
     pub fn show_error_with_info(&self, msg: String, info: Option<String>) {
-        let dialog = ErrorDialog::new(false, &msg);
-        if let Some(text) = info {
-            dialog.set_property_secondary_text(Some(text.as_ref()));
-        }
+        self.ui.show_error_with_info(msg, info);
     }
 }
 
diff --git a/fractal-gtk/src/appop/sync.rs b/fractal-gtk/src/appop/sync.rs
index 865a5f95..82ef00d5 100644
--- a/fractal-gtk/src/appop/sync.rs
+++ b/fractal-gtk/src/appop/sync.rs
@@ -22,9 +22,10 @@ use std::collections::BTreeMap;
 impl AppOp {
     pub fn initial_sync(&self, show: bool) {
         if show {
-            self.inapp_notify(&i18n("Syncing, this could take a while"));
+            self.ui
+                .inapp_notify(&i18n("Syncing, this could take a while"));
         } else {
-            self.hide_inapp_notify();
+            self.ui.hide_inapp_notify();
         }
     }
 
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index dcfa246c..ef80081b 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -105,6 +105,7 @@ app_sources = files(
   'ui/invite.rs',
   'ui/member.rs',
   'ui/mod.rs',
+  'ui/notify.rs',
   'ui/start_chat.rs',
   'util/i18n.rs',
   'util/mod.rs',
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index 3a7e2b4c..9bd8e712 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -14,6 +14,7 @@ pub mod connect;
 pub mod directory;
 pub mod invite;
 pub mod member;
+pub mod notify;
 pub mod start_chat;
 
 pub struct UI {
diff --git a/fractal-gtk/src/ui/notify.rs b/fractal-gtk/src/ui/notify.rs
new file mode 100644
index 00000000..3a7ef7e9
--- /dev/null
+++ b/fractal-gtk/src/ui/notify.rs
@@ -0,0 +1,37 @@
+use super::UI;
+use crate::widgets::ErrorDialog;
+use gtk::prelude::*;
+
+impl UI {
+    pub fn inapp_notify(&self, msg: &str) {
+        let inapp: gtk::Revealer = self
+            .builder
+            .get_object("inapp_revealer")
+            .expect("Can't find inapp_revealer in ui file.");
+        let label: gtk::Label = self
+            .builder
+            .get_object("inapp_label")
+            .expect("Can't find inapp_label in ui file.");
+        label.set_text(msg);
+        inapp.set_reveal_child(true);
+    }
+
+    pub fn hide_inapp_notify(&self) {
+        let inapp: gtk::Revealer = self
+            .builder
+            .get_object("inapp_revealer")
+            .expect("Can't find inapp_revealer in ui file.");
+        inapp.set_reveal_child(false);
+    }
+
+    pub fn show_error(&self, msg: String) {
+        ErrorDialog::new(false, &msg);
+    }
+
+    pub fn show_error_with_info(&self, msg: String, info: Option<String>) {
+        let dialog = ErrorDialog::new(false, &msg);
+        if let Some(text) = info {
+            dialog.set_property_secondary_text(Some(text.as_ref()));
+        }
+    }
+}


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