[gnome-disk-utility] Remove deprecated GTK functions



commit c08ae342af217a5606b12d995843e543c1e4f18b
Author: Kai Lüke <kailueke riseup net>
Date:   Tue Apr 4 19:36:23 2017 +0200

    Remove deprecated GTK functions
    
    Uses of various deprecated functions have been replaced to
    build with -Werror. This also obsoletes the custom
    generic_menu_position_func as gtk_menu_popup_at_widget should
    be enough for the drop down menu in the volume toolbar.
    The call of gtk_style_context_set_background has been removed
    because it did not have an effect since some GTK releases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780864

 src/disks/gduapplication.c            |   11 ++--
 src/disks/gducreatediskimagedialog.c  |   15 +++---
 src/disks/gducreatefilesystemwidget.c |    6 ++-
 src/disks/gduvolumegrid.c             |    4 --
 src/disks/gduwindow.c                 |   92 +++-----------------------------
 5 files changed, 26 insertions(+), 102 deletions(-)
---
diff --git a/src/disks/gduapplication.c b/src/disks/gduapplication.c
index 4901ec4..7b67740 100644
--- a/src/disks/gduapplication.c
+++ b/src/disks/gduapplication.c
@@ -334,12 +334,11 @@ help_activated (GSimpleAction *action,
                 GVariant      *parameter,
                 gpointer       user_data)
 {
-  //GduApplication *app = GDU_APPLICATION (user_data);
-  //gtk_widget_destroy (GTK_WIDGET (app->window));
-  gtk_show_uri (NULL, /* GdkScreen */
-                "help:gnome-help/disk",
-                GDK_CURRENT_TIME,
-                NULL); /* GError */
+  GduApplication *app = GDU_APPLICATION (user_data);
+  gtk_show_uri_on_window (GTK_WINDOW (app->window),
+                          "help:gnome-help/disk",
+                          GDK_CURRENT_TIME,
+                          NULL); /* GError */
 }
 
 static GActionEntry app_entries[] =
diff --git a/src/disks/gducreatediskimagedialog.c b/src/disks/gducreatediskimagedialog.c
index 119309b..2eac084 100644
--- a/src/disks/gducreatediskimagedialog.c
+++ b/src/disks/gducreatediskimagedialog.c
@@ -466,7 +466,7 @@ on_success (gpointer user_data)
    */
   if (data->num_error_bytes > 0)
     {
-      GtkWidget *dialog, *button;
+      GtkWidget *dialog;
       GError *error = NULL;
       gchar *s = NULL;
       gint response;
@@ -475,7 +475,7 @@ on_success (gpointer user_data)
       dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (data->window),
                                                    GTK_DIALOG_MODAL,
                                                    GTK_MESSAGE_WARNING,
-                                                   GTK_BUTTONS_CLOSE,
+                                                   GTK_BUTTONS_NONE,
                                                    "<big><b>%s</b></big>",
                                                    /* Translators: Primary message in dialog shown if some 
data was unreadable while creating a disk image */
                                                    _("Unrecoverable read errors while creating disk image"));
@@ -491,12 +491,11 @@ on_success (gpointer user_data)
                                                   percentage,
                                                   s,
                                                   gtk_label_get_text (GTK_LABEL (data->source_label)));
-      button = gtk_dialog_add_button (GTK_DIALOG (dialog),
-                                      /* Translators: Label of secondary button in dialog if some data was 
unreadable while creating a disk image */
-                                      _("_Delete Disk Image File"),
-                                      GTK_RESPONSE_NO);
-      gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
-                                          button, TRUE);
+      gtk_dialog_add_button (GTK_DIALOG (dialog),
+                             /* Translators: Label of secondary button in dialog if some data was unreadable 
while creating a disk image */
+                             _("_Delete Disk Image File"),
+                             GTK_RESPONSE_NO);
+      gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Close"), GTK_RESPONSE_CLOSE);
       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
       response = gtk_dialog_run (GTK_DIALOG (dialog));
       gtk_widget_destroy (dialog);
diff --git a/src/disks/gducreatefilesystemwidget.c b/src/disks/gducreatefilesystemwidget.c
index 3793587..5c00384 100644
--- a/src/disks/gducreatefilesystemwidget.c
+++ b/src/disks/gducreatefilesystemwidget.c
@@ -556,7 +556,11 @@ gdu_create_filesystem_widget_constructed (GObject *object)
                       TRUE, TRUE, 0);
 
   /* reparent and nuke the dummy window */
-  gtk_widget_reparent (widget->grid, GTK_WIDGET (widget));
+  g_object_ref (widget->grid);
+  gtk_container_remove (GTK_CONTAINER (dummy_window), widget->grid);
+  gtk_container_add (GTK_CONTAINER (widget), widget->grid);
+  g_object_unref (widget->grid);
+
   gtk_widget_destroy (dummy_window);
 
   populate (widget);
diff --git a/src/disks/gduvolumegrid.c b/src/disks/gduvolumegrid.c
index c49ba72..641fc85 100644
--- a/src/disks/gduvolumegrid.c
+++ b/src/disks/gduvolumegrid.c
@@ -432,7 +432,6 @@ gdu_volume_grid_realize (GtkWidget *widget)
   GdkWindowAttr attributes;
   gint attributes_mask;
   GtkAllocation allocation;
-  GtkStyleContext *context;
 
   gtk_widget_set_realized (widget, TRUE);
   gtk_widget_get_allocation (widget, &allocation);
@@ -464,9 +463,6 @@ gdu_volume_grid_realize (GtkWidget *widget)
                            attributes_mask);
   gtk_widget_set_window (widget, window);
   gdk_window_set_user_data (window, grid);
-
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_set_background (context, window);
 }
 
 static guint
diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c
index 0508829..74f4cdf 100644
--- a/src/disks/gduwindow.c
+++ b/src/disks/gduwindow.c
@@ -266,12 +266,6 @@ typedef struct
   ShowFlagsVolumeMenu        volume_menu;
 } ShowFlags;
 
-static void generic_menu_position_func (GtkMenu       *menu,
-                                        gint          *x,
-                                        gint          *y,
-                                        gboolean      *push_in,
-                                        gpointer       user_data);
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void update_all (GduWindow *window);
@@ -1056,7 +1050,10 @@ gdu_window_constructed (GObject *object)
 
   gtk_widget_show_all (window->header);
 
-  gtk_widget_reparent (window->main_box, GTK_WIDGET (window));
+  g_object_ref (window->main_box);
+  gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (window->main_box)), window->main_box);
+  gtk_container_add (GTK_CONTAINER (window), window->main_box);
+  g_object_unref (window->main_box);
   gtk_window_set_title (GTK_WINDOW (window), _("Disks"));
   gtk_window_set_default_size (GTK_WINDOW (window), 800, 700);
   gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
@@ -3424,88 +3421,17 @@ on_unmount_tool_button_clicked (GtkToolButton *button, gpointer user_data)
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-generic_menu_position_func (GtkMenu       *menu,
-                            gint          *x,
-                            gint          *y,
-                            gboolean      *push_in,
-                            gpointer       user_data)
-{
-  GtkWidget *align_widget = GTK_WIDGET (user_data);
-  GtkRequisition menu_req;
-  GtkTextDirection direction;
-  GdkRectangle monitor;
-  gint monitor_num;
-  GdkScreen *screen;
-  GdkWindow *gdk_window;
-  GtkAllocation allocation, arrow_allocation;
-  GtkAlign align;
-  GtkWidget *toplevel;
-
-  align = gtk_widget_get_halign (GTK_WIDGET (menu));
-  direction = gtk_widget_get_direction (align_widget);
-  gdk_window = gtk_widget_get_window (align_widget);
-
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
-                                 &menu_req,
-                                 NULL);
-
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
-  gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
-
-  screen = gtk_widget_get_screen (GTK_WIDGET (menu));
-  monitor_num = gdk_screen_get_monitor_at_window (screen, gdk_window);
-  if (monitor_num < 0)
-    monitor_num = 0;
-  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
-
-  gtk_widget_get_allocation (align_widget, &allocation);
-  gtk_widget_get_allocation (align_widget, &arrow_allocation);
-
-  gdk_window_get_origin (gdk_window, x, y);
-  *x += allocation.x;
-  *y += allocation.y;
-
-  /* treat the default align value like START */
-  if (align == GTK_ALIGN_FILL)
-    align = GTK_ALIGN_START;
-
-  if (align == GTK_ALIGN_CENTER)
-    *x -= (menu_req.width - allocation.width) / 2;
-  else if ((align == GTK_ALIGN_START && direction == GTK_TEXT_DIR_LTR) ||
-           (align == GTK_ALIGN_END && direction == GTK_TEXT_DIR_RTL))
-    *x += MAX (allocation.width - menu_req.width, 0);
-  else if (menu_req.width > allocation.width)
-    *x -= menu_req.width - allocation.width;
-
-  if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height)
-    *y += arrow_allocation.height;
-  else if ((*y - menu_req.height) >= monitor.y)
-    *y -= menu_req.height;
-  else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
-    *y += arrow_allocation.height;
-  else
-    *y -= menu_req.height;
-
-  *push_in = FALSE;
-}
-
-static void
 on_generic_tool_button_clicked (GtkToolButton *button, gpointer user_data)
 {
   GduWindow *window = GDU_WINDOW (user_data);
-  GdkEventButton *event = NULL;
 
   update_all (window);
 
-  gtk_menu_popup_for_device (GTK_MENU (window->generic_menu),
-                             event != NULL ? event->device : NULL,
-                             NULL, /* parent_menu_shell */
-                             NULL, /* parent_menu_item */
-                             generic_menu_position_func,
-                             window->toolbutton_generic_menu,
-                             NULL, /* user_data GDestroyNotify */
-                             event != NULL ? event->button : 0,
-                             event != NULL ? event->time : gtk_get_current_event_time ());
+  gtk_menu_popup_at_widget (GTK_MENU (window->generic_menu),
+                            window->toolbutton_generic_menu,
+                            GDK_GRAVITY_SOUTH_WEST,
+                            GDK_GRAVITY_NORTH_WEST,
+                            NULL);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */


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