[fractal/bilelmoussaoui/bump-gtk-rs: 4/16] replace all the new_from with just from_




commit 09096a0373ab5cf8b23d11f44c2301f2014ba746
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Wed Jul 15 18:39:41 2020 +0200

    replace all the new_from with just from_
    
    part of the new gtk-rs changes

 Cargo.lock                                  |  1 +
 fractal-gtk/src/actions/message.rs          |  4 +---
 fractal-gtk/src/appop/account.rs            |  5 ++---
 fractal-gtk/src/appop/attach.rs             |  6 +++---
 fractal-gtk/src/appop/message.rs            |  2 +-
 fractal-gtk/src/static_resources.rs.in      |  2 +-
 fractal-gtk/src/widgets/address.rs          | 10 ++++------
 fractal-gtk/src/widgets/avatar.rs           |  8 ++++----
 fractal-gtk/src/widgets/image.rs            |  4 ++--
 fractal-gtk/src/widgets/inline_player.rs    |  8 ++++----
 fractal-gtk/src/widgets/login.rs            |  2 +-
 fractal-gtk/src/widgets/media_viewer.rs     |  8 +++-----
 fractal-gtk/src/widgets/message.rs          | 23 +++++------------------
 fractal-gtk/src/widgets/room.rs             |  4 ++--
 fractal-gtk/src/widgets/room_settings.rs    |  2 +-
 fractal-gtk/src/widgets/roomlist.rs         |  2 +-
 fractal-gtk/src/widgets/roomrow.rs          |  2 +-
 fractal-gtk/src/widgets/sourceview_entry.rs |  9 ++++-----
 18 files changed, 41 insertions(+), 61 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index d0f1733e..93657fea 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -952,6 +952,7 @@ name = "gstreamer"
 version = "0.16.2"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 checksum = "ce4ce1ba28d3293b8cb8c3d33f50e6da2e5cfeefa59a0d10d922ab8015791609"
+
 dependencies = [
  "bitflags",
  "cfg-if",
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index 5abf33e8..d08d2f2d 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -200,13 +200,11 @@ pub fn new(
                         Continue(true)
                     }
                     Ok(Ok(fname)) => {
-                        if let Ok(pixbuf) = gdk_pixbuf::Pixbuf::new_from_file(fname) {
+                        if let Ok(pixbuf) = gdk_pixbuf::Pixbuf::from_file(fname) {
                             let atom = gdk::Atom::intern("CLIPBOARD");
                             let clipboard = gtk::Clipboard::get(&atom);
-
                             clipboard.set_image(&pixbuf);
                         }
-
                         Continue(false)
                     }
                     Ok(Err(err)) => {
diff --git a/fractal-gtk/src/appop/account.rs b/fractal-gtk/src/appop/account.rs
index 136c0c3c..d515aacf 100644
--- a/fractal-gtk/src/appop/account.rs
+++ b/fractal-gtk/src/appop/account.rs
@@ -336,7 +336,7 @@ impl AppOp {
 
         name_btn.hide();
         name.set_editable(true);
-        let image = gtk::Image::new_from_icon_name(Some("emblem-ok-symbolic"), gtk::IconSize::Menu);
+        let image = gtk::Image::from_icon_name(Some("emblem-ok-symbolic"), gtk::IconSize::Menu);
         name_btn.set_image(Some(&image));
         name_btn.set_sensitive(true);
 
@@ -577,8 +577,7 @@ impl AppOp {
             .expect("Can't find account_settings_name_button in ui file.");
         if let Some(name) = name.clone() {
             button.hide();
-            let image =
-                gtk::Image::new_from_icon_name(Some("emblem-ok-symbolic"), gtk::IconSize::Menu);
+            let image = gtk::Image::from_icon_name(Some("emblem-ok-symbolic"), gtk::IconSize::Menu);
             button.set_image(Some(&image));
             button.set_sensitive(true);
             entry.set_editable(true);
diff --git a/fractal-gtk/src/appop/attach.rs b/fractal-gtk/src/appop/attach.rs
index 3b5bff4c..c5dc844c 100644
--- a/fractal-gtk/src/appop/attach.rs
+++ b/fractal-gtk/src/appop/attach.rs
@@ -33,7 +33,7 @@ impl AppOp {
                 .get_object("main_window")
                 .expect("Can't find main_window in ui file.");
             let img = gtk::Image::new();
-            let dialog = gtk::Dialog::new_with_buttons(
+            let dialog = gtk::Dialog::with_buttons(
                 Some(i18n("Image from Clipboard").as_str()),
                 Some(&window),
                 gtk::DialogFlags::MODAL
@@ -49,8 +49,8 @@ impl AppOp {
 
             if let Some(hbar) = dialog.get_header_bar() {
                 let headerbar = hbar.downcast::<gtk::HeaderBar>().unwrap();
-                let closebtn = gtk::Button::new_with_label(i18n("Cancel").as_str());
-                let okbtn = gtk::Button::new_with_label(i18n("Send").as_str());
+                let closebtn = gtk::Button::with_label(i18n("Cancel").as_str());
+                let okbtn = gtk::Button::with_label(i18n("Send").as_str());
                 okbtn.get_style_context().add_class("suggested-action");
 
                 headerbar.set_show_close_button(false);
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index fd724dd6..32de2443 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -581,7 +581,7 @@ fn get_image_media_info(file: &Path, mimetype: &str) -> Option<JsonValue> {
     let size = fs::metadata(file).ok()?.len();
 
     // make thumbnail max 800x600
-    let thumb = Pixbuf::new_from_file_at_scale(&file, 800, 600, true).ok()?;
+    let thumb = Pixbuf::from_file_at_scale(&file, 800, 600, true).ok()?;
     let mut rng = rand::thread_rng();
     let x: u64 = rng.gen_range(1, 9_223_372_036_854_775_807);
     let thumb_path = format!(
diff --git a/fractal-gtk/src/static_resources.rs.in b/fractal-gtk/src/static_resources.rs.in
index 28207a6f..a578fedb 100644
--- a/fractal-gtk/src/static_resources.rs.in
+++ b/fractal-gtk/src/static_resources.rs.in
@@ -11,7 +11,7 @@ pub fn init() -> Result<(), Error> {
 
     // Create Resource, it will live as long the value lives.
     let gbytes = Bytes::from(res_bytes.as_ref());
-    let resource = Resource::new_from_data(&gbytes)?;
+    let resource = Resource::from_data(&gbytes)?;
 
     // Register the resource so It wont be dropped and will continue to live in memory.
     resources_register(&resource);
diff --git a/fractal-gtk/src/widgets/address.rs b/fractal-gtk/src/widgets/address.rs
index d8da0020..6d51d38a 100644
--- a/fractal-gtk/src/widgets/address.rs
+++ b/fractal-gtk/src/widgets/address.rs
@@ -61,7 +61,7 @@ impl<'a> Address<'a> {
 
             self.action = Some(AddressAction::Delete);
             let label =
-                gtk::Image::new_from_icon_name(Some("user-trash-symbolic"), gtk::IconSize::Menu);
+                gtk::Image::from_icon_name(Some("user-trash-symbolic"), gtk::IconSize::Menu);
             self.button.set_image(Some(&label));
             self.button.show();
         } else {
@@ -72,8 +72,7 @@ impl<'a> Address<'a> {
 
             self.entry.set_placeholder_text(Some(text));
             self.action = Some(AddressAction::Add);
-            let label =
-                gtk::Image::new_from_icon_name(Some("list-add-symbolic"), gtk::IconSize::Menu);
+            let label = gtk::Image::from_icon_name(Some("list-add-symbolic"), gtk::IconSize::Menu);
             self.button.set_image(Some(&label));
             self.button
                 .get_style_context()
@@ -102,7 +101,7 @@ impl<'a> Address<'a> {
 
             self.action = Some(AddressAction::Delete);
             let label =
-                gtk::Image::new_from_icon_name(Some("user-trash-symbolic"), gtk::IconSize::Menu);
+                gtk::Image::from_icon_name(Some("user-trash-symbolic"), gtk::IconSize::Menu);
             self.button.set_image(Some(&label));
             self.button
                 .get_style_context()
@@ -110,8 +109,7 @@ impl<'a> Address<'a> {
             self.button.show();
         } else {
             self.action = Some(AddressAction::Add);
-            let label =
-                gtk::Image::new_from_icon_name(Some("list-add-symbolic"), gtk::IconSize::Menu);
+            let label = gtk::Image::from_icon_name(Some("list-add-symbolic"), gtk::IconSize::Menu);
             self.button.set_image(Some(&label));
             self.button
                 .get_style_context()
diff --git a/fractal-gtk/src/widgets/avatar.rs b/fractal-gtk/src/widgets/avatar.rs
index 198dca34..3bb03f1e 100644
--- a/fractal-gtk/src/widgets/avatar.rs
+++ b/fractal-gtk/src/widgets/avatar.rs
@@ -191,15 +191,15 @@ impl AvatarExt for gtk::Overlay {
     }
 }
 
-fn load_pixbuf(path: &Path, size: i32) -> Option<Pixbuf> {
-    if let Ok(pixbuf) = Pixbuf::new_from_file(&path) {
+fn load_pixbuf(path: &str, size: i32) -> Option<Pixbuf> {
+    if let Ok(pixbuf) = Pixbuf::from_file(&path) {
         // FIXME: We end up loading the file twice but we need to load the file first to find out its 
dimensions to be
         // able to decide wether to scale by width or height and gdk doesn't provide simple API to scale a 
loaded
         // pixbuf while preserving aspect ratio.
         if pixbuf.get_width() > pixbuf.get_height() {
-            Pixbuf::new_from_file_at_scale(&path, -1, size, true).ok()
+            Pixbuf::from_file_at_scale(&path, -1, size, true).ok()
         } else {
-            Pixbuf::new_from_file_at_scale(&path, size, -1, true).ok()
+            Pixbuf::from_file_at_scale(&path, size, -1, true).ok()
         }
     } else {
         None
diff --git a/fractal-gtk/src/widgets/image.rs b/fractal-gtk/src/widgets/image.rs
index 1f056bb7..591b11f8 100644
--- a/fractal-gtk/src/widgets/image.rs
+++ b/fractal-gtk/src/widgets/image.rs
@@ -313,7 +313,7 @@ pub fn load_pixbuf(
         return;
     }
 
-    match Pixbuf::new_from_file(fname) {
+    match Pixbuf::from_file(fname) {
         Ok(px) => {
             *pix.lock().unwrap() = Some(px);
             *scaled.lock().unwrap() = None;
@@ -342,7 +342,7 @@ pub fn load_animation(
     widget: DrawingArea,
     fname: &Path,
 ) {
-    let res = PixbufAnimation::new_from_file(fname);
+    let res = PixbufAnimation::from_file(fname);
     if res.is_err() {
         return;
     }
diff --git a/fractal-gtk/src/widgets/inline_player.rs b/fractal-gtk/src/widgets/inline_player.rs
index 5fce6ed9..1e183fb1 100644
--- a/fractal-gtk/src/widgets/inline_player.rs
+++ b/fractal-gtk/src/widgets/inline_player.rs
@@ -248,7 +248,7 @@ impl Default for VideoPlayerWidget {
         let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None);
         let sink = gst::ElementFactory::make("gtksink", None)
             .expect("Missing dependency: element gtksink is needed (usually, in gstreamer-plugins-good or in 
gst-plugin-gtk).");
-        let renderer = gst_player::PlayerVideoOverlayVideoRenderer::new_with_sink(&sink).upcast();
+        let renderer = gst_player::PlayerVideoOverlayVideoRenderer::with_sink(&sink).upcast();
         let player = gst_player::Player::new(
             Some(&renderer),
             // Use the gtk main thread
@@ -570,14 +570,14 @@ impl<T: MediaPlayer + 'static> PlayerExt for T {
         let player = player_widget.get_player();
         if player.get_mute() {
             player.set_mute(false);
-            let image = gtk::Image::new_from_icon_name(
+            let image = gtk::Image::from_icon_name(
                 Some("audio-volume-high-symbolic"),
                 gtk::IconSize::Button,
             );
             button.set_image(Some(&image));
         } else {
             player.set_mute(true);
-            let image = gtk::Image::new_from_icon_name(
+            let image = gtk::Image::from_icon_name(
                 Some("audio-volume-muted-symbolic"),
                 gtk::IconSize::Button,
             );
@@ -632,7 +632,7 @@ impl<T: MediaPlayer + 'static> ControlsConnection for T {
 }
 
 fn create_controls(player: &gst_player::Player) -> PlayerControls {
-    let builder = gtk::Builder::new_from_resource("/org/gnome/Fractal/ui/audio_player.ui");
+    let builder = gtk::Builder::from_resource("/org/gnome/Fractal/ui/audio_player.ui");
     let container = builder.get_object("container").unwrap();
 
     let buttons_container = builder.get_object("buttons").unwrap();
diff --git a/fractal-gtk/src/widgets/login.rs b/fractal-gtk/src/widgets/login.rs
index e7eea190..46857eac 100644
--- a/fractal-gtk/src/widgets/login.rs
+++ b/fractal-gtk/src/widgets/login.rs
@@ -157,7 +157,7 @@ impl LoginWidget {
 
 impl Default for LoginWidget {
     fn default() -> Self {
-        let builder = gtk::Builder::new_from_resource("/org/gnome/Fractal/ui/login_flow.ui");
+        let builder = gtk::Builder::from_resource("/org/gnome/Fractal/ui/login_flow.ui");
 
         let container: gtk::Stack = builder.get_object("login_flow_stack").unwrap();
         let headers: gtk::Stack = builder.get_object("login_flow_headers").unwrap();
diff --git a/fractal-gtk/src/widgets/media_viewer.rs b/fractal-gtk/src/widgets/media_viewer.rs
index 4d55f010..34c51a87 100644
--- a/fractal-gtk/src/widgets/media_viewer.rs
+++ b/fractal-gtk/src/widgets/media_viewer.rs
@@ -380,15 +380,13 @@ impl Data {
         let control_box = PlayerExt::get_controls_container(&player).unwrap();
         full_control_box.pack_start(&control_box, false, true, 0);
 
-        let mute_button = gtk::Button::new_from_icon_name(
-            Some("audio-volume-high-symbolic"),
-            gtk::IconSize::Button,
-        );
+        let mute_button =
+            gtk::Button::from_icon_name(Some("audio-volume-high-symbolic"), gtk::IconSize::Button);
         /* The followign callback requires `Send` but is handled by the gtk main loop */
         let button = Fragile::new(mute_button.clone());
         PlayerExt::get_player(&player).connect_state_changed(move |player, state| match state {
             gst_player::PlayerState::Playing if player.get_mute() => {
-                let image = gtk::Image::new_from_icon_name(
+                let image = gtk::Image::from_icon_name(
                     Some("audio-volume-muted-symbolic"),
                     gtk::IconSize::Button,
                 );
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index 4f050eab..a1ef7526 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -246,10 +246,8 @@ impl MessageBox {
         body_bx.pack_start(&body, true, true, 0);
 
         if let Some(replace_date) = msg.replace_date {
-            let edit_mark = gtk::Image::new_from_icon_name(
-                Some("document-edit-symbolic"),
-                gtk::IconSize::Button,
-            );
+            let edit_mark =
+                gtk::Image::from_icon_name(Some("document-edit-symbolic"), gtk::IconSize::Button);
             edit_mark.get_style_context().add_class("edit-mark");
             edit_mark.set_valign(gtk::Align::End);
 
@@ -477,7 +475,7 @@ impl MessageBox {
         }
 
         let download_btn =
-            gtk::Button::new_from_icon_name(Some("document-save-symbolic"), gtk::IconSize::Button);
+            gtk::Button::from_icon_name(Some("document-save-symbolic"), gtk::IconSize::Button);
         download_btn.set_tooltip_text(Some(i18n("Save").as_str()));
 
         let evid = msg
@@ -518,12 +516,6 @@ impl MessageBox {
                 start_playing,
             );
 
-            let overlay = Overlay::new();
-            let video_widget = player.get_video_widget();
-            video_widget.set_size_request(-1, 390);
-            VideoPlayerWidget::auto_adjust_video_dimensions(&player);
-            overlay.add(&video_widget);
-
             let play_button = gtk::Button::new();
             let play_icon = gtk::Image::new_from_icon_name(
                 Some("media-playback-start-symbolic"),
@@ -567,12 +559,7 @@ impl MessageBox {
             let redactable = msg.redactable;
             let menu = MessageMenu::new(evid, &RowType::Video, &redactable, None, None);
             menu_button.set_popover(Some(&menu.get_popover()));
-
-            bx.pack_start(&overlay, true, true, 0);
-            self.connect_media_viewer(msg);
-            self.video_player = Some(player);
         }
-
         bx
     }
 
@@ -592,7 +579,7 @@ impl MessageBox {
         name_lbl.get_style_context().add_class("msg-highlighted");
 
         let download_btn =
-            gtk::Button::new_from_icon_name(Some("document-save-symbolic"), gtk::IconSize::Button);
+            gtk::Button::from_icon_name(Some("document-save-symbolic"), gtk::IconSize::Button);
         download_btn.set_tooltip_text(Some(i18n("Save").as_str()));
 
         let evid = msg
@@ -606,7 +593,7 @@ impl MessageBox {
         download_btn.set_action_name(Some("message.save_as"));
 
         let open_btn =
-            gtk::Button::new_from_icon_name(Some("document-open-symbolic"), gtk::IconSize::Button);
+            gtk::Button::from_icon_name(Some("document-open-symbolic"), gtk::IconSize::Button);
         open_btn.set_tooltip_text(Some(i18n("Open").as_str()));
 
         let data = glib::Variant::from(&evid);
diff --git a/fractal-gtk/src/widgets/room.rs b/fractal-gtk/src/widgets/room.rs
index 1fc34070..7248af73 100644
--- a/fractal-gtk/src/widgets/room.rs
+++ b/fractal-gtk/src/widgets/room.rs
@@ -115,13 +115,13 @@ impl<'a> RoomBox<'a> {
             membership_grid.set_column_spacing(6);
 
             let members_icon =
-                gtk::Image::new_from_icon_name(Some("system-users-symbolic"), gtk::IconSize::Menu);
+                gtk::Image::from_icon_name(Some("system-users-symbolic"), gtk::IconSize::Menu);
             members_icon.get_style_context().add_class("dim-label");
 
             let members_count = gtk::Label::new(Some(&format!("{}", room.n_members)[..]));
             members_count.get_style_context().add_class("dim-label");
 
-            let join_button = gtk::Button::new_with_label(i18n("Join").as_str());
+            let join_button = gtk::Button::with_label(i18n("Join").as_str());
             let room_id = room.id.clone();
             join_button.connect_clicked(move |_| {
                 let server_url = login_data.server_url.clone();
diff --git a/fractal-gtk/src/widgets/room_settings.rs b/fractal-gtk/src/widgets/room_settings.rs
index d1d4ae3a..0b70d48a 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/widgets/room_settings.rs
@@ -304,7 +304,7 @@ impl RoomSettings {
     }
 
     pub fn reset_action_button(&self, button: gtk::Button) {
-        let image = gtk::Image::new_from_icon_name(Some("emblem-ok-symbolic"), gtk::IconSize::Menu);
+        let image = gtk::Image::from_icon_name(Some("emblem-ok-symbolic"), gtk::IconSize::Menu);
         button.set_image(Some(&image));
         button.set_sensitive(true);
     }
diff --git a/fractal-gtk/src/widgets/roomlist.rs b/fractal-gtk/src/widgets/roomlist.rs
index 0ed74bfd..c5ba4e31 100644
--- a/fractal-gtk/src/widgets/roomlist.rs
+++ b/fractal-gtk/src/widgets/roomlist.rs
@@ -86,7 +86,7 @@ impl RoomListGroup {
         title.set_halign(gtk::Align::Start);
         title.set_valign(gtk::Align::Start);
         let arrow =
-            gtk::Image::new_from_icon_name(Some("pan-down-symbolic"), gtk::IconSize::SmallToolbar);
+            gtk::Image::from_icon_name(Some("pan-down-symbolic"), gtk::IconSize::SmallToolbar);
         let expanded = Arc::new(AtomicBool::new(true));
         let title_eb = gtk::EventBox::new();
 
diff --git a/fractal-gtk/src/widgets/roomrow.rs b/fractal-gtk/src/widgets/roomrow.rs
index dcd0315e..70bbf4be 100644
--- a/fractal-gtk/src/widgets/roomrow.rs
+++ b/fractal-gtk/src/widgets/roomrow.rs
@@ -29,7 +29,7 @@ impl RoomRow {
 
         let icon = widgets::Avatar::avatar_new(Some(ICON_SIZE));
         let direct =
-            gtk::Image::new_from_icon_name(Some("avatar-default-symbolic"), gtk::IconSize::Menu);
+            gtk::Image::from_icon_name(Some("avatar-default-symbolic"), gtk::IconSize::Menu);
         direct.get_style_context().add_class("direct-chat");
 
         let text = gtk::Label::new(Some(name.as_str()));
diff --git a/fractal-gtk/src/widgets/sourceview_entry.rs b/fractal-gtk/src/widgets/sourceview_entry.rs
index be8148a6..f7eb9526 100644
--- a/fractal-gtk/src/widgets/sourceview_entry.rs
+++ b/fractal-gtk/src/widgets/sourceview_entry.rs
@@ -34,7 +34,7 @@ impl Default for SVEntry {
 
         let size = gtk::IconSize::Button;
         let attach = gtk::Button::new();
-        let attach_img = gtk::Image::new_from_icon_name(Some("mail-attachment-symbolic"), size);
+        let attach_img = gtk::Image::from_icon_name(Some("mail-attachment-symbolic"), size);
         attach.set_image(Some(&attach_img));
         attach.set_valign(gtk::Align::End);
         attach.set_receives_default(true);
@@ -47,8 +47,7 @@ impl Default for SVEntry {
         */
 
         let markdown = gtk::MenuButton::new();
-        let markdown_img =
-            gtk::Image::new_from_icon_name(Some("format-justify-left-symbolic"), size);
+        let markdown_img = gtk::Image::from_icon_name(Some("format-justify-left-symbolic"), size);
         markdown.set_image(Some(&markdown_img));
         markdown.set_valign(gtk::Align::End);
         markdown.set_receives_default(true);
@@ -68,7 +67,7 @@ impl Default for SVEntry {
 
         let tag_table: Option<&gtk::TextTagTable> = None;
         let buffer = sourceview4::Buffer::new(tag_table);
-        let view = sourceview4::View::new_with_buffer(&buffer);
+        let view = sourceview4::View::with_buffer(&buffer);
         view.set_wrap_mode(gtk::WrapMode::WordChar);
         view.set_indent_on_tab(false);
 
@@ -85,7 +84,7 @@ impl Default for SVEntry {
         entry_box.add(&scroll);
 
         let send = gtk::Button::new();
-        let send_img = gtk::Image::new_from_icon_name(Some("send-symbolic"), size);
+        let send_img = gtk::Image::from_icon_name(Some("send-symbolic"), size);
         send.set_image(Some(&send_img));
         send.set_valign(gtk::Align::End);
         send.set_receives_default(true);


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