gtk-demo: Port to async dialog API
authorMatthias Clasen <mclasen@redhat.com>
Fri, 28 Oct 2022 15:38:57 +0000 (11:38 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 29 Oct 2022 17:31:41 +0000 (13:31 -0400)
17 files changed:
demos/gtk-demo/application.c
demos/gtk-demo/clipboard.c
demos/gtk-demo/clipboard.ui
demos/gtk-demo/font_features.c
demos/gtk-demo/font_features.ui
demos/gtk-demo/fontrendering.c
demos/gtk-demo/fontrendering.ui
demos/gtk-demo/images.c
demos/gtk-demo/infobar.c
demos/gtk-demo/links.c
demos/gtk-demo/listview_applauncher.c
demos/gtk-demo/listview_words.c
demos/gtk-demo/paint.c
demos/gtk-demo/paintable_svg.c
demos/gtk-demo/pickers.c
demos/gtk-demo/printing.c
demos/gtk-demo/video_player.c

index a3e29bfb1c14999b1173250c0cb4009575d753bc..ffb7ed6d295033a2c4a5481e8a6b5359607eebac 100644 (file)
@@ -33,22 +33,12 @@ static void create_window (GApplication *app, const char *contents);
 static void
 show_action_dialog (GSimpleAction *action)
 {
-  const char *name;
-  GtkWidget *dialog;
-
-  name = g_action_get_name (G_ACTION (action));
-
-  dialog = gtk_message_dialog_new (NULL,
-                                   GTK_DIALOG_DESTROY_WITH_PARENT,
-                                   GTK_MESSAGE_INFO,
-                                   GTK_BUTTONS_CLOSE,
-                                   "You activated action: \"%s\"",
-                                    name);
+  GtkAlertDialog *dialog;
 
-  g_signal_connect (dialog, "response",
-                    G_CALLBACK (gtk_window_destroy), NULL);
-
-  gtk_widget_show (dialog);
+  dialog = gtk_alert_dialog_new ("You activated action: \"%s\n",
+                                 g_action_get_name (G_ACTION (action)));
+  gtk_alert_dialog_show (dialog, NULL);
+  g_object_unref (dialog);
 }
 
 static void
@@ -90,20 +80,19 @@ activate_new (GSimpleAction *action,
 }
 
 static void
-open_response_cb (GtkNativeDialog *dialog,
-                  int              response_id,
-                  gpointer         user_data)
+open_response_cb (GObject *source,
+                  GAsyncResult *result,
+                  gpointer user_data)
 {
-  GtkFileChooserNative *native = user_data;
-  GApplication *app = g_object_get_data (G_OBJECT (native), "app");
-  GtkWidget *message_dialog;
+  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
+  GApplication *app = G_APPLICATION (user_data);
   GFile *file;
-  char *contents;
   GError *error = NULL;
 
-  if (response_id == GTK_RESPONSE_ACCEPT)
+  file = gtk_file_dialog_save_finish (dialog, result, &error);
+  if (file)
     {
-      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
+      char *contents;
 
       if (g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
         {
@@ -112,21 +101,16 @@ open_response_cb (GtkNativeDialog *dialog,
         }
       else
         {
-          message_dialog = gtk_message_dialog_new (NULL,
-                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                   GTK_MESSAGE_ERROR,
-                                                   GTK_BUTTONS_CLOSE,
-                                                   "Error loading file: \"%s\"",
-                                                   error->message);
-          g_signal_connect (message_dialog, "response",
-                            G_CALLBACK (gtk_window_destroy), NULL);
-          gtk_widget_show (message_dialog);
+          GtkAlertDialog *alert;
+
+          alert = gtk_alert_dialog_new ("Error loading file: \"%s\"", error->message);
+          gtk_alert_dialog_show (alert, NULL);
+          g_object_unref (alert);
           g_error_free (error);
         }
     }
 
-  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
-  g_object_unref (native);
+  g_object_unref (app);
 }
 
 
@@ -136,21 +120,11 @@ activate_open (GSimpleAction *action,
                gpointer       user_data)
 {
   GApplication *app = user_data;
-  GtkFileChooserNative *native;
-
-  native = gtk_file_chooser_native_new ("Open File",
-                                        NULL,
-                                        GTK_FILE_CHOOSER_ACTION_OPEN,
-                                        "_Open",
-                                        "_Cancel");
-
-  g_object_set_data_full (G_OBJECT (native), "app", g_object_ref (app), g_object_unref);
-  g_signal_connect (native,
-                    "response",
-                    G_CALLBACK (open_response_cb),
-                    native);
+  GtkFileDialog *dialog;
 
-  gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
+  dialog = gtk_file_dialog_new ();
+  gtk_file_dialog_open (dialog, NULL, NULL, NULL, open_response_cb, g_object_ref (app));
+  g_object_unref (dialog);
 }
 
 static void
index 1520349498a45da366e5cdc8173a97328a41be71..f397285fae08eb316d49972cba46a3b5b4a716cb 100644 (file)
@@ -50,10 +50,10 @@ copy_button_clicked (GtkStack *source_stack,
     }
   else if (strcmp (visible_child_name, "Color") == 0)
     {
-      GdkRGBA color;
+      const GdkRGBA *color;
 
-      gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (visible_child), &color);
-      gdk_clipboard_set (clipboard, GDK_TYPE_RGBA, &color);
+      color = gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (visible_child));
+      gdk_clipboard_set (clipboard, GDK_TYPE_RGBA, color);
     }
   else if (strcmp (visible_child_name, "File") == 0)
     {
@@ -215,37 +215,36 @@ file_button_set_file (GtkButton *button,
 }
 
 static void
-file_chooser_response (GtkNativeDialog *dialog,
-                       int              response,
-                       GtkButton       *button)
+file_chooser_response (GObject *source,
+                       GAsyncResult *result,
+                       gpointer user_data)
 {
-  gtk_native_dialog_hide (dialog);
+  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
+  GtkButton *button = GTK_BUTTON (user_data);
+  GFile *file;
 
-  if (response == GTK_RESPONSE_ACCEPT)
+  file = gtk_file_dialog_open_finish (dialog, result, NULL);
+  if (file)
     {
-      GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
       file_button_set_file (button, file);
       g_object_unref (file);
 
       update_copy_button_sensitivity (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_STACK));
     }
-
-  gtk_native_dialog_destroy (dialog);
 }
 
 static void
 open_file_cb (GtkWidget *button)
 {
-  GtkFileChooserNative *chooser;
+  GtkFileDialog *dialog;
 
-  chooser = gtk_file_chooser_native_new ("Choose a file",
-                                         GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)),
-                                         GTK_FILE_CHOOSER_ACTION_OPEN,
-                                         "_Open",
-                                         "_Cancel");
+  dialog = gtk_file_dialog_new ();
 
-  g_signal_connect (chooser, "response", G_CALLBACK (file_chooser_response), button);
-  gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
+  gtk_file_dialog_open (dialog,
+                        GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)),
+                        NULL,
+                        NULL,
+                        file_chooser_response, button);
 }
 
 static void
index ef83cd4ba7346d7c86ab925a80ecd5af3277c817..6cc7ed4324e3bdad59e366deb55bb69f2fc8b015 100644 (file)
                   <object class="GtkStackPage">
                     <property name="name">Color</property>
                     <property name="child">
-                      <object class="GtkColorButton" id="source_color">
+                      <object class="GtkColorDialogButton" id="source_color">
+                        <property name="dialog">
+                          <object class="GtkColorDialog">
+                          </object>
+                        </property>
                         <property name="valign">center</property>
                         <property name="rgba">purple</property>
                       </object>
index 804c6261fab0687ded4051def35abe7eb63fea64..ed71354f1d4ea550e07427e82531bee3b8ea0dd4 100644 (file)
@@ -256,10 +256,10 @@ swap_colors (void)
   GdkRGBA fg;
   GdkRGBA bg;
 
-  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->foreground), &fg);
-  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->background), &bg);
-  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->foreground), &bg);
-  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->background), &fg);
+  fg = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground));
+  bg = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background));
+  gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground), &bg);
+  gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background), &fg);
 }
 
 static void
@@ -268,8 +268,8 @@ font_features_reset_basic (void)
   gtk_adjustment_set_value (demo->size_adjustment, 20);
   gtk_adjustment_set_value (demo->letterspacing_adjustment, 0);
   gtk_adjustment_set_value (demo->line_height_adjustment, 1);
-  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->foreground), &(GdkRGBA){0.,0.,0.,1.});
-  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->background), &(GdkRGBA){1.,1.,1.,1.});
+  gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground), &(GdkRGBA){0.,0.,0.,1.});
+  gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background), &(GdkRGBA){1.,1.,1.,1.});
 }
 
 static void
@@ -277,7 +277,7 @@ update_basic (void)
 {
   PangoFontDescription *desc;
 
-  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (demo->font));
+  desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (demo->font));
 
   gtk_adjustment_set_value (demo->size_adjustment,
                             pango_font_description_get_size (desc) / (double) PANGO_SCALE);
@@ -588,7 +588,7 @@ update_display (void)
       end = PANGO_ATTR_INDEX_TO_TEXT_END;
     }
 
-  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (demo->font));
+  desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (demo->font));
 
   value = gtk_adjustment_get_value (demo->size_adjustment);
   pango_font_description_set_size (desc, value * PANGO_SCALE);
@@ -679,7 +679,7 @@ update_display (void)
       GdkRGBA rgba;
       char *fg, *bg, *css;
 
-      gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->foreground), &rgba);
+      rgba = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground));
       attr = pango_attr_foreground_new (65535 * rgba.red,
                                         65535 * rgba.green,
                                         65535 * rgba.blue);
@@ -692,7 +692,7 @@ update_display (void)
       pango_attr_list_insert (attrs, attr);
 
       fg = gdk_rgba_to_string (&rgba);
-      gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->background), &rgba);
+      rgba = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background));
       bg = gdk_rgba_to_string (&rgba);
       css = g_strdup_printf (".font_features_background { caret-color: %s; background-color: %s; }", fg, bg);
       gtk_css_provider_load_from_data (demo->provider, css, strlen (css));
@@ -767,7 +767,6 @@ update_display (void)
   gtk_label_set_attributes (GTK_LABEL (demo->the_label), attrs);
 
   g_free (font_desc);
-  pango_font_description_free (desc);
   g_free (features);
   pango_attr_list_unref (attrs);
   g_free (text);
@@ -779,7 +778,7 @@ get_pango_font (void)
   PangoFontDescription *desc;
   PangoContext *context;
 
-  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (demo->font));
+  desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (demo->font));
   context = gtk_widget_get_pango_context (demo->font);
 
   return pango_context_load_font (context, desc);
@@ -831,17 +830,17 @@ update_script_combo (void)
   GHashTable *tags;
   GHashTableIter iter;
   TagPair *pair;
-  char *lang;
+  PangoLanguage *language;
+  const char *lang;
   hb_tag_t active;
 
-  lang = gtk_font_chooser_get_language (GTK_FONT_CHOOSER (demo->font));
+  language = gtk_font_dialog_button_get_language (GTK_FONT_DIALOG_BUTTON (demo->font));
+  lang = pango_language_to_string (language);
 
   G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   active = hb_ot_tag_from_language (hb_language_from_string (lang, -1));
   G_GNUC_END_IGNORE_DEPRECATIONS
 
-  g_free (lang);
-
   store = g_list_store_new (script_lang_get_type ());
 
   pango_font = get_pango_font ();
@@ -1005,7 +1004,7 @@ update_features (void)
     {
       hb_tag_t tables[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS };
       hb_face_t *hb_face;
-      char *feat;
+      const char *feat;
 
       hb_face = hb_font_get_face (hb_font);
 
@@ -1098,7 +1097,7 @@ update_features (void)
             }
         }
 
-      feat = gtk_font_chooser_get_font_features (GTK_FONT_CHOOSER (demo->font));
+      feat = gtk_font_dialog_button_get_font_features (GTK_FONT_DIALOG_BUTTON (demo->font));
       if (feat)
         {
           for (l = demo->feature_items; l; l = l->next)
@@ -1124,8 +1123,6 @@ update_features (void)
                     }
                 }
             }
-
-          g_free (feat);
         }
     }
 
@@ -1780,6 +1777,7 @@ do_font_features (GtkWidget *do_widget)
       demo->description = GTK_WIDGET (gtk_builder_get_object (builder, "description"));
       demo->font = GTK_WIDGET (gtk_builder_get_object (builder, "font"));
       demo->script_lang = GTK_WIDGET (gtk_builder_get_object (builder, "script_lang"));
+      g_assert (GTK_IS_DROP_DOWN (demo->script_lang));
       expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL, G_CALLBACK (script_lang_get_langname), NULL, NULL);
       gtk_drop_down_set_expression (GTK_DROP_DOWN (demo->script_lang), expression);
       gtk_expression_unref (expression);
index c351cbfaf6b326565761f04d44f999c7dbf68b3b..b498273cc8c9e533893b1631998867a9039f6def 100644 (file)
                     <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
-                      <object class="GtkFontButton" id="font">
+                      <object class="GtkFontDialogButton" id="font">
+                        <property name="dialog">
+                          <object class="GtkFontDialog">
+                          </object>
+                        </property>
                         <property name="receives-default">1</property>
-                        <property name="font">Sans 12</property>
-                        <property name="level">family|style</property>
-                        <signal name="font-set" handler="font_features_font_changed" swapped="no"/>
+                        <property name="level">face</property>
+                        <signal name="notify::font-desc" handler="font_features_font_changed" swapped="no"/>
                       </object>
                     </child>
                     <child>
                           </object>
                         </child>
                         <child>
-                          <object class="GtkColorButton" id="foreground">
+                          <object class="GtkColorDialogButton" id="foreground">
+                            <property name="dialog">
+                              <object class="GtkColorDialog">
+                              </object>
+                            </property>
                             <property name="valign">baseline</property>
                             <property name="rgba">black</property>
                             <signal name="notify::rgba" handler="color_set_cb"/>
                           </object>
                         </child>
                         <child>
-                          <object class="GtkColorButton" id="background">
+                          <object class="GtkColorDialogButton" id="background">
+                            <property name="dialog">
+                              <object class="GtkColorDialog">
+                              </object>
+                            </property>
                             <property name="valign">baseline</property>
                             <property name="rgba">white</property>
                             <signal name="notify::rgba" handler="color_set_cb"/>
index a187f41397bbd52cbdac9bb7983d5ae91ab31254..9ec15a57335e90cdf4044e3c30424a0e886b5247 100644 (file)
@@ -53,7 +53,7 @@ update_image (void)
     context = gtk_widget_create_pango_context (image);
 
   text = gtk_editable_get_text (GTK_EDITABLE (entry));
-  desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font_button));
+  desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (font_button));
 
   fopt = cairo_font_options_copy (pango_cairo_context_get_font_options (context));
 
@@ -287,8 +287,6 @@ retry:
   gtk_picture_set_pixbuf (GTK_PICTURE (image), pixbuf2);
 
   g_object_unref (pixbuf2);
-
-  pango_font_description_free (desc);
 }
 
 static gboolean fading = FALSE;
index 23b782cf4e7b5f846c6df89d17b6c96856388b25..8a9d8b06b834dcf2b110f212f9097a51527a2900 100644 (file)
               </object>
             </child>
             <child>
-              <object class="GtkFontButton" id="font_button">
+              <object class="GtkFontDialogButton" id="font_button">
+                <property name="dialog">
+                  <object class="GtkFontDialog">
+                  </object>
+                </property>
                 <layout>
                   <property name="column">2</property>
                   <property name="row">1</property>
index 39b01103b255cb61e6dfd904d9d35ace1181210e..184ef3d1623a623f77470a569c12f5895bd3527a 100644 (file)
@@ -83,24 +83,17 @@ progressive_timeout (gpointer data)
 
       if (bytes_read < 0)
         {
-          GtkWidget *dialog;
-
-          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                           GTK_DIALOG_DESTROY_WITH_PARENT,
-                                           GTK_MESSAGE_ERROR,
-                                           GTK_BUTTONS_CLOSE,
-                                           "Failure reading image file 'alphatest.png': %s",
-                                           error->message);
-          g_error_free (error);
+          GtkAlertDialog *dialog;
 
-          g_signal_connect (dialog, "response",
-                            G_CALLBACK (gtk_window_destroy), NULL);
+          dialog = gtk_alert_dialog_new ("Failure reading image file 'alphatest.png': %s",
+                                         error->message);
+          gtk_alert_dialog_show (dialog, NULL);
+          g_object_unref (dialog);
+          g_error_free (error);
 
           g_object_unref (image_stream);
           image_stream = NULL;
 
-          gtk_widget_show (dialog);
-
           load_timeout = 0;
 
           return FALSE; /* uninstall the timeout */
@@ -110,25 +103,17 @@ progressive_timeout (gpointer data)
                                     buf, bytes_read,
                                     &error))
         {
-          GtkWidget *dialog;
-
-          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                           GTK_DIALOG_DESTROY_WITH_PARENT,
-                                           GTK_MESSAGE_ERROR,
-                                           GTK_BUTTONS_CLOSE,
-                                           "Failed to load image: %s",
-                                           error->message);
+          GtkAlertDialog *dialog;
 
+          dialog = gtk_alert_dialog_new ("Failed to load image: %s",
+                                         error->message);
+          gtk_alert_dialog_show (dialog, NULL);
+          g_object_unref (dialog);
           g_error_free (error);
 
-          g_signal_connect (dialog, "response",
-                            G_CALLBACK (gtk_window_destroy), NULL);
-
           g_object_unref (image_stream);
           image_stream = NULL;
 
-          gtk_widget_show (dialog);
-
           load_timeout = 0;
 
           return FALSE; /* uninstall the timeout */
@@ -143,22 +128,14 @@ progressive_timeout (gpointer data)
           error = NULL;
           if (!g_input_stream_close (image_stream, NULL, &error))
             {
-              GtkWidget *dialog;
-
-              dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                               GTK_DIALOG_DESTROY_WITH_PARENT,
-                                               GTK_MESSAGE_ERROR,
-                                               GTK_BUTTONS_CLOSE,
-                                               "Failed to load image: %s",
-                                               error->message);
+              GtkAlertDialog *dialog;
 
+              dialog = gtk_alert_dialog_new ("Failed to load image: %s",
+                                             error->message);
+              gtk_alert_dialog_show (dialog, NULL);
+              g_object_unref (dialog);
               g_error_free (error);
 
-              g_signal_connect (dialog, "response",
-                                G_CALLBACK (gtk_window_destroy), NULL);
-
-              gtk_widget_show (dialog);
-
               g_object_unref (image_stream);
               image_stream = NULL;
               g_object_unref (pixbuf_loader);
@@ -177,25 +154,16 @@ progressive_timeout (gpointer data)
            * it was incomplete.
            */
           error = NULL;
-          if (!gdk_pixbuf_loader_close (pixbuf_loader,
-                                        &error))
+          if (!gdk_pixbuf_loader_close (pixbuf_loader, &error))
             {
-              GtkWidget *dialog;
-
-              dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                               GTK_DIALOG_DESTROY_WITH_PARENT,
-                                               GTK_MESSAGE_ERROR,
-                                               GTK_BUTTONS_CLOSE,
-                                               "Failed to load image: %s",
-                                               error->message);
+              GtkAlertDialog *dialog;
 
+              dialog = gtk_alert_dialog_new ("Failed to load image: %s",
+                                             error->message);
+              gtk_alert_dialog_show (dialog, NULL);
+              g_object_unref (dialog);
               g_error_free (error);
 
-              g_signal_connect (dialog, "response",
-                                G_CALLBACK (gtk_window_destroy), NULL);
-
-              gtk_widget_show (dialog);
-
               g_object_unref (pixbuf_loader);
               pixbuf_loader = NULL;
 
@@ -216,20 +184,14 @@ progressive_timeout (gpointer data)
 
       if (image_stream == NULL)
         {
-          GtkWidget *dialog;
+          GtkAlertDialog *dialog;
 
-          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                           GTK_DIALOG_DESTROY_WITH_PARENT,
-                                           GTK_MESSAGE_ERROR,
-                                           GTK_BUTTONS_CLOSE,
-                                           "%s", error->message);
+          dialog = gtk_alert_dialog_new ("%s",
+                                         error->message);
+          gtk_alert_dialog_show (dialog, NULL);
+          g_object_unref (dialog);
           g_error_free (error);
 
-          g_signal_connect (dialog, "response",
-                            G_CALLBACK (gtk_window_destroy), NULL);
-
-          gtk_widget_show (dialog);
-
           load_timeout = 0;
 
           return FALSE; /* uninstall the timeout */
index 15caf102861ae58748e7dc4c4ef831bc9efdcd97..d484e856cb8515ee0289f2f92e9e52cf76edeabb 100644 (file)
@@ -12,8 +12,8 @@ on_bar_response (GtkInfoBar *info_bar,
                  int         response_id,
                  gpointer    user_data)
 {
-  GtkWidget *dialog;
-  GtkWidget *window;
+  GtkAlertDialog *dialog;
+  char *detail;
 
   if (response_id == GTK_RESPONSE_CLOSE)
     {
@@ -21,19 +21,12 @@ on_bar_response (GtkInfoBar *info_bar,
       return;
     }
 
-  window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (info_bar)));
-  dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                   GTK_MESSAGE_INFO,
-                                   GTK_BUTTONS_OK,
-                                   "You clicked a button on an info bar");
-  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                            "Your response has id %d", response_id);
-
-  g_signal_connect_swapped (dialog, "response",
-                            G_CALLBACK (gtk_window_destroy), dialog);
-
-  gtk_widget_show (dialog);
+  dialog = gtk_alert_dialog_new ("You clicked a button on an info bar");
+  detail = g_strdup_printf ("Your response has been %d", response_id);
+  gtk_alert_dialog_set_detail (dialog, detail);
+  g_free (detail);
+  gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (info_bar))));
+  g_object_unref (dialog);
 }
 
 GtkWidget *
index 63ac1d0c7fbac2ec2e54b63eba1e4bf422096fec..7efcb125d6830c071c463b43bb6b6b12d96344cd 100644 (file)
@@ -7,38 +7,22 @@
 
 #include <gtk/gtk.h>
 
-static void
-response_cb (GtkWidget *dialog,
-             int        response_id,
-             gpointer   data)
-{
-  gtk_window_destroy (GTK_WINDOW (dialog));
-}
-
 static gboolean
-activate_link (GtkWidget   *label,
+activate_link (GtkWidget  *label,
                const char *uri,
-               gpointer     data)
+               gpointer    data)
 {
   if (g_strcmp0 (uri, "keynav") == 0)
     {
-      GtkWidget *dialog;
-      GtkWidget *parent;
-
-      parent = GTK_WIDGET (gtk_widget_get_root (label));
-      dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (parent),
-                 GTK_DIALOG_DESTROY_WITH_PARENT,
-                 GTK_MESSAGE_INFO,
-                 GTK_BUTTONS_OK,
-                 "Keyboard navigation");
-      gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
-                 "The term <i>keynav</i> is a shorthand for "
-                 "keyboard navigation and refers to the process of using "
-                 "a program (exclusively) via keyboard input.");
-      gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+      GtkAlertDialog *dialog;
 
-      gtk_window_present (GTK_WINDOW (dialog));
-      g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
+      dialog = gtk_alert_dialog_new ("Keyboard navigation");
+      gtk_alert_dialog_set_detail (dialog,
+                                   "The term ‘keynav’ is a shorthand for "
+                                   "keyboard navigation and refers to the process of using "
+                                   "a program (exclusively) via keyboard input.");
+      gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (label)));
+      g_object_unref (dialog);
 
       return TRUE;
     }
index 3194e05e2155350cdb4670c6ecccbc47efdc1c3a..72adbedd96d40f6958e93d4703701977fea628fa 100644 (file)
@@ -117,19 +117,16 @@ activate_cb (GtkListView  *list,
                           G_APP_LAUNCH_CONTEXT (context),
                           &error))
     {
-      GtkWidget *dialog;
+      GtkAlertDialog *dialog;
 
       /* And because error handling is important, even a simple demo has it:
        * We display an error dialog that something went wrong.
        */
-      dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (list))),
-                                       GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
-                                       GTK_MESSAGE_ERROR,
-                                       GTK_BUTTONS_CLOSE,
-                                       "Could not launch %s", g_app_info_get_display_name (app_info));
-      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+      dialog = gtk_alert_dialog_new ("Could not launch %s", g_app_info_get_display_name (app_info));
+      gtk_alert_dialog_set_detail (dialog, error->message);
+      gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (list))));
+      g_object_unref (dialog);
       g_clear_error (&error);
-      gtk_widget_show (dialog);
     }
 
   g_object_unref (context);
index 06c6394368972979ba84f77b3559a6ee9c206787..a884ff8ef603dd3faaf3ec0d8ec36d977a293c6b 100644 (file)
@@ -141,39 +141,35 @@ load_file (GtkStringList *list,
 }
 
 static void
-open_response_cb (GtkNativeDialog *dialog,
-                  int              response,
-                  GtkStringList   *stringlist)
+open_response_cb (GObject *source,
+                  GAsyncResult *result,
+                  void *user_data)
 {
-  gtk_native_dialog_hide (dialog);
+  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
+  GtkStringList *stringlist = GTK_STRING_LIST (user_data);
+  GFile *file;
 
-  if (response == GTK_RESPONSE_ACCEPT)
+  file = gtk_file_dialog_open_finish (dialog, result, NULL);
+  if (file)
     {
-      GFile *file;
-
-      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
       load_file (stringlist, file);
       g_object_unref (file);
     }
-
-  gtk_native_dialog_destroy (dialog);
 }
 
 static void
 file_open_cb (GtkWidget     *button,
               GtkStringList *stringlist)
 {
-  GtkFileChooserNative *dialog;
-
-  dialog = gtk_file_chooser_native_new ("Open file",
-                                        GTK_WINDOW (gtk_widget_get_root (button)),
-                                        GTK_FILE_CHOOSER_ACTION_OPEN,
-                                        "_Load",
-                                        "_Cancel");
-  gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
-
-  g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), stringlist);
-  gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
+  GtkFileDialog *dialog;
+
+  dialog = gtk_file_dialog_new ();
+  gtk_file_dialog_open (dialog,
+                        GTK_WINDOW (gtk_widget_get_root (button)),
+                        NULL,
+                        NULL,
+                        open_response_cb, stringlist);
+  g_object_unref (dialog);
 }
 
 GtkWidget *
index 147ddea7530f535027cd57c5ee1db9d90645c986..92774b0efbf47729983521d39cf9e5bd8c458e9d 100644 (file)
@@ -51,8 +51,8 @@ static const char *pad_colors[] = {
 static GType drawing_area_get_type (void);
 G_DEFINE_TYPE (DrawingArea, drawing_area, GTK_TYPE_WIDGET)
 
-static void drawing_area_set_color (DrawingArea *area,
-                                    GdkRGBA     *color);
+static void drawing_area_set_color (DrawingArea   *area,
+                                    const GdkRGBA *color);
 
 static void
 drawing_area_ensure_surface (DrawingArea *area,
@@ -350,8 +350,8 @@ drawing_area_new (void)
 }
 
 static void
-drawing_area_set_color (DrawingArea *area,
-                        GdkRGBA     *color)
+drawing_area_set_color (DrawingArea   *area,
+                        const GdkRGBA *color)
 {
   if (gdk_rgba_equal (&area->draw_color, color))
     return;
@@ -361,21 +361,22 @@ drawing_area_set_color (DrawingArea *area,
 }
 
 static void
-color_button_color_set (GtkColorButton *button,
-                        DrawingArea    *draw_area)
+color_button_color_set (GtkColorDialogButton *button,
+                        GParamSpec           *pspec,
+                        DrawingArea          *draw_area)
 {
-  GdkRGBA color;
+  const GdkRGBA *color;
 
-  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color);
-  drawing_area_set_color (draw_area, &color);
+  color = gtk_color_dialog_button_get_rgba (button);
+  drawing_area_set_color (draw_area, color);
 }
 
 static void
-drawing_area_color_set (DrawingArea    *area,
-                        GdkRGBA        *color,
-                        GtkColorButton *button)
+drawing_area_color_set (DrawingArea          *area,
+                        GdkRGBA              *color,
+                        GtkColorDialogButton *button)
 {
-  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), color);
+  gtk_color_dialog_button_set_rgba (button, color);
 }
 
 GtkWidget *
@@ -394,13 +395,13 @@ do_paint (GtkWidget *toplevel)
 
       headerbar = gtk_header_bar_new ();
 
-      colorbutton = gtk_color_button_new ();
-      g_signal_connect (colorbutton, "color-set",
+      colorbutton = gtk_color_dialog_button_new (gtk_color_dialog_new ());
+      g_signal_connect (colorbutton, "notify::rgba",
                         G_CALLBACK (color_button_color_set), draw_area);
       g_signal_connect (draw_area, "color-set",
                         G_CALLBACK (drawing_area_color_set), colorbutton);
-      gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (colorbutton),
-                                  &(GdkRGBA) { 0, 0, 0, 1 });
+      gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (colorbutton),
+                                        &(GdkRGBA) { 0, 0, 0, 1 });
 
       gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), colorbutton);
       gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
index a1c97721e19d11ad34f6efc225b50f728cc47149..5d73fd91bb892181892f226a825b05b16043de42 100644 (file)
 
 
 static void
-open_response_cb (GtkNativeDialog *dialog,
-                  int              response,
-                  GtkPicture      *picture)
+open_response_cb (GObject *source,
+                  GAsyncResult *result,
+                  void *data)
 {
-  gtk_native_dialog_hide (dialog);
+  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
+  GtkPicture *picture = data;
+  GFile *file;
 
-  if (response == GTK_RESPONSE_ACCEPT)
+  file = gtk_file_dialog_open_finish (dialog, result, NULL);
+  if (file)
     {
-      GFile *file;
       GdkPaintable *paintable;
 
-      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
       paintable = svg_paintable_new (file);
       gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
       g_object_unref (paintable);
       g_object_unref (file);
     }
-
-  gtk_native_dialog_destroy (dialog);
 }
 
 static void
@@ -39,20 +38,25 @@ show_file_open (GtkWidget  *button,
                 GtkPicture *picture)
 {
   GtkFileFilter *filter;
-  GtkFileChooserNative *dialog;
+  GtkFileDialog *dialog;
+  GListStore *filters;
 
-  dialog = gtk_file_chooser_native_new ("Open node file",
-                                        GTK_WINDOW (gtk_widget_get_root (button)),
-                                        GTK_FILE_CHOOSER_ACTION_OPEN,
-                                        "_Load",
-                                        "_Cancel");
+  dialog = gtk_file_dialog_new ();
+  gtk_file_dialog_set_title (dialog, "Open node file");
 
   filter = gtk_file_filter_new ();
   gtk_file_filter_add_mime_type (filter, "image/svg+xml");
-  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
-  gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
-  g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), picture);
-  gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
+  filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
+  g_list_store_append (filters, filter);
+  g_object_unref (filter);
+  gtk_file_dialog_set_filters (dialog, G_LIST_MODEL (filters));
+  g_object_unref (filters);
+
+  gtk_file_dialog_open (dialog,
+                        GTK_WINDOW (gtk_widget_get_root (button)),
+                        NULL,
+                        NULL,
+                        open_response_cb, picture);
 }
 
 static GtkWidget *window;
index da15b51b9d757696358f22fb67ba2beace162998..ec5ddd5f33d85bd5f761a74d6dd8f559f5484e44 100644 (file)
@@ -1,5 +1,5 @@
 /* Pickers
- * #Keywords: GtkColorChooser, GtkFontChooser, GtkApplicationChooser
+ * #Keywords: GtkColorDialog, GtkFontDialog, GtkFileDialog
  *
  * These widgets are mainly intended for use in preference dialogs.
  * They allow to select colors, fonts and applications.
index beef569f250cf56e603290b55627f50df7ee4e2a..94f00d1da941c5847da9688f78ccc35429782d93 100644 (file)
@@ -177,19 +177,12 @@ do_printing (GtkWidget *do_widget)
 
   if (error)
     {
-      GtkWidget *dialog;
+      GtkAlertDialog *dialog;
 
-      dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget),
-                                       GTK_DIALOG_DESTROY_WITH_PARENT,
-                                       GTK_MESSAGE_ERROR,
-                                       GTK_BUTTONS_CLOSE,
-                                       "%s", error->message);
+      dialog = gtk_alert_dialog_new ("%s", error->message);
+      gtk_alert_dialog_show (dialog, GTK_WINDOW (do_widget));
+      g_object_unref (dialog);
       g_error_free (error);
-
-      g_signal_connect (dialog, "response",
-                        G_CALLBACK (gtk_window_destroy), NULL);
-
-      gtk_widget_show (dialog);
     }
 
 
index 8b467a25d9a870979ba4753f3fbe2712b398daaf..f34c640419d492a4bf961b6038c2b3446858fb45 100644 (file)
 static GtkWidget *window = NULL;
 
 static void
-open_dialog_response_cb (GtkNativeDialog *dialog,
-                         int              response,
-                         GtkWidget       *video)
+open_dialog_response_cb (GObject *source,
+                         GAsyncResult *result,
+                         void *user_data)
 {
-  gtk_native_dialog_hide (dialog);
+  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
+  GtkWidget *video = user_data;
+  GFile *file;
 
-  if (response == GTK_RESPONSE_ACCEPT)
+  file = gtk_file_dialog_open_finish (dialog, result, NULL);
+  if (file)
     {
-      GFile *file;
-
-      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
       gtk_video_set_file (GTK_VIDEO (video), file);
       g_object_unref (file);
     }
-
-  gtk_native_dialog_destroy (dialog);
 }
 
 static void
 open_clicked_cb (GtkWidget *button,
                  GtkWidget *video)
 {
-  GtkFileChooserNative *dialog;
+  GtkFileDialog *dialog;
   GtkFileFilter *filter;
+  GListStore *filters;
 
-  dialog = gtk_file_chooser_native_new ("Select a video",
-                                        GTK_WINDOW (gtk_widget_get_root (button)),
-                                        GTK_FILE_CHOOSER_ACTION_OPEN,
-                                        "_Open",
-                                        "_Cancel");
+  dialog = gtk_file_dialog_new ();
+  gtk_file_dialog_set_title (dialog, "Select a video");
+
+  filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
 
   filter = gtk_file_filter_new ();
   gtk_file_filter_add_pattern (filter, "*");
   gtk_file_filter_set_name (filter, "All Files");
-  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+  g_list_store_append (filters, filter);
   g_object_unref (filter);
 
   filter = gtk_file_filter_new ();
   gtk_file_filter_add_mime_type (filter, "image/*");
   gtk_file_filter_set_name (filter, "Images");
-  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+  g_list_store_append (filters, filter);
   g_object_unref (filter);
 
   filter = gtk_file_filter_new ();
   gtk_file_filter_add_mime_type (filter, "video/*");
   gtk_file_filter_set_name (filter, "Video");
-  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-  
-  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+  g_list_store_append (filters, filter);
+
+  gtk_file_dialog_set_current_filter (dialog, filter);
   g_object_unref (filter);
 
-  gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
-  g_signal_connect (dialog, "response", G_CALLBACK (open_dialog_response_cb), video);
-  gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
+  gtk_file_dialog_set_filters (dialog, G_LIST_MODEL (filters));
+  g_object_unref (filters);
+
+  gtk_file_dialog_open (dialog,
+                        GTK_WINDOW (gtk_widget_get_root (button)),
+                        NULL,
+                        NULL,
+                        open_dialog_response_cb, video);
 }
 
 static void