[epiphany/gnome-3-24-loki: 3/6] Add fallback for missing GtkFileChooserNative
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-3-24-loki: 3/6] Add fallback for missing GtkFileChooserNative
- Date: Thu, 21 Sep 2017 23:10:11 +0000 (UTC)
commit 1f1fcbdc40f5c4cb829a18d61980ecfcf2695c12
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Thu Sep 21 17:44:54 2017 -0500
Add fallback for missing GtkFileChooserNative
lib/widgets/ephy-file-chooser.c | 33 ++++++++++++++++++
src/popup-commands.c | 8 ++++
src/window-commands.c | 71 +++++++++++++++++++++++++++++++++++++--
3 files changed, 109 insertions(+), 3 deletions(-)
---
diff --git a/lib/widgets/ephy-file-chooser.c b/lib/widgets/ephy-file-chooser.c
index aeec06d..462f5f2 100644
--- a/lib/widgets/ephy-file-chooser.c
+++ b/lib/widgets/ephy-file-chooser.c
@@ -102,12 +102,21 @@ ephy_create_file_chooser (const char *title,
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
g_return_val_if_fail (default_filter >= 0 && default_filter <= EPHY_FILE_FILTER_LAST, NULL);
+#if GTK_CHECK_VERSION(3, 20, 0)
dialog = GTK_FILE_CHOOSER (gtk_file_chooser_native_new (title,
GTK_WINDOW (parent),
action,
NULL,
_("_Cancel")));
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
+#else
+ dialog = GTK_FILE_CHOOSER (gtk_file_chooser_dialog_new (title,
+ GTK_WINDOW (parent),
+ action,
+ NULL,
+ NULL));
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+#endif
downloads_dir = ephy_file_get_downloads_dir ();
gtk_file_chooser_add_shortcut_folder (dialog, downloads_dir, NULL);
@@ -116,9 +125,33 @@ ephy_create_file_chooser (const char *title,
if (action == GTK_FILE_CHOOSER_ACTION_OPEN ||
action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) {
+#if GTK_CHECK_VERSION(3, 20, 0)
gtk_file_chooser_native_set_accept_label (GTK_FILE_CHOOSER_NATIVE (dialog), _("_Open"));
+#else
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+#pragma GCC diagnostic pop
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_ACCEPT);
+#endif
} else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
+#if GTK_CHECK_VERSION(3, 20, 0)
gtk_file_chooser_native_set_accept_label (GTK_FILE_CHOOSER_NATIVE (dialog), _("_Save"));
+#else
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+#pragma GCC diagnostic pop
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_ACCEPT);
+#endif
}
if (default_filter != EPHY_FILE_FILTER_NONE) {
diff --git a/src/popup-commands.c b/src/popup-commands.c
index ad8304a..2d2124f 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -168,7 +168,11 @@ filename_suggested_cb (EphyDownload *download,
gtk_file_chooser_set_current_name (dialog, sanitized_filename);
g_free (sanitized_filename);
+#if GTK_CHECK_VERSION(3, 20, 0)
if (gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+#else
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+#endif
char *uri;
WebKitDownload *webkit_download;
@@ -188,7 +192,11 @@ filename_suggested_cb (EphyDownload *download,
g_object_unref);
}
+#if GTK_CHECK_VERSION(3, 20, 0)
g_object_unref (dialog);
+#else
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+#endif
g_free (data->title);
g_object_unref (data->window);
g_free (data);
diff --git a/src/window-commands.c b/src/window-commands.c
index bf074da..45bc798 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -285,23 +285,46 @@ dialog_bookmarks_import_cb (GtkDialog *dialog,
if (active == 0) {
GtkFileFilter *filter;
+#if GTK_CHECK_VERSION(3, 20, 0)
file_chooser_dialog = GTK_FILE_CHOOSER (gtk_file_chooser_native_new (_("Choose File"),
GTK_WINDOW (dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("I_mport"),
_("_Cancel")));
+#else
+ file_chooser_dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
+ "action", GTK_FILE_CHOOSER_ACTION_OPEN,
+ "filter", filter,
+ "modal", TRUE,
+ "transient-for", dialog,
+ "title", _("Choose File"),
+ NULL);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (file_chooser_dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+#endif
gtk_file_chooser_set_show_hidden (file_chooser_dialog, TRUE);
filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, "*.gvdb");
gtk_file_chooser_set_filter (file_chooser_dialog, filter);
+#if GTK_CHECK_VERSION(3, 20, 0)
chooser_response = gtk_native_dialog_run (GTK_NATIVE_DIALOG (file_chooser_dialog));
+#else
+ chooser_response = gtk_dialog_run (GTK_DIALOG (file_chooser_dialog));
+#endif
if (chooser_response == GTK_RESPONSE_ACCEPT) {
GError *error = NULL;
char *filename;
+#if GTK_CHECK_VERSION(3, 20, 0)
gtk_native_dialog_hide (GTK_NATIVE_DIALOG (file_chooser_dialog));
+#else
+ gtk_widget_hide (GTK_WIDGET (file_chooser_dialog));
+#endif
filename = gtk_file_chooser_get_filename (file_chooser_dialog);
imported = ephy_bookmarks_import (manager, filename, &error);
@@ -318,7 +341,11 @@ dialog_bookmarks_import_cb (GtkDialog *dialog,
gtk_widget_destroy (import_info_dialog);
}
+#if GTK_CHECK_VERSION(3, 20, 0)
g_object_unref (file_chooser_dialog);
+#else
+ gtk_widget_destroy (GTK_WIDGET (file_chooser_dialog));
+#endif
} else if (active == 1) {
GError *error = NULL;
GSList *profiles;
@@ -441,11 +468,21 @@ window_cmd_export_bookmarks (GSimpleAction *action,
gboolean exported;
GtkFileFilter *filter;
+#if GTK_CHECK_VERSION(3, 20, 0)
dialog = GTK_FILE_CHOOSER (gtk_file_chooser_native_new (_("Choose File"),
GTK_WINDOW (user_data),
GTK_FILE_CHOOSER_ACTION_SAVE,
_("_Save"),
_("_Cancel")));
+#else
+ dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
+ "action", GTK_FILE_CHOOSER_ACTION_SAVE,
+ "filter", filter,
+ "modal", TRUE,
+ "transient-for", user_data,
+ "title", _("Choose File"),
+ NULL);
+#endif
gtk_file_chooser_set_show_hidden (dialog, TRUE);
/* Translators: Only translate the part before ".gvdb" (e.g. "bookmarks") */
@@ -455,12 +492,20 @@ window_cmd_export_bookmarks (GSimpleAction *action,
gtk_file_filter_add_pattern (filter, "*.gvdb");
gtk_file_chooser_set_filter (dialog, filter);
+#if GTK_CHECK_VERSION(3, 20, 0)
chooser_response = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
+#else
+ chooser_response = gtk_dialog_run (GTK_DIALOG (dialog));
+#endif
if (chooser_response == GTK_RESPONSE_ACCEPT) {
GError *error = NULL;
char *filename;
+#if GTK_CHECK_VERSION(3, 20, 0)
gtk_native_dialog_hide (GTK_NATIVE_DIALOG (dialog));
+#else
+ gtk_widget_hide (GTK_WIDGET (dialog));
+#endif
filename = gtk_file_chooser_get_filename (dialog);
exported = ephy_bookmarks_export (manager, filename, &error);
@@ -477,7 +522,11 @@ window_cmd_export_bookmarks (GSimpleAction *action,
gtk_widget_destroy (export_info_dialog);
}
+#if GTK_CHECK_VERSION(3, 20, 0)
g_object_unref (dialog);
+#else
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+#endif
}
void
@@ -857,12 +906,12 @@ window_cmd_new_tab (GSimpleAction *action,
}
static void
-open_response_cb (GtkNativeDialog *dialog, int response, EphyWindow *window)
+open_response_cb (GtkFileChooser *dialog, int response, EphyWindow *window)
{
if (response == GTK_RESPONSE_ACCEPT) {
char *uri, *converted;
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+ uri = gtk_file_chooser_get_uri (dialog);
if (uri != NULL) {
converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
@@ -875,7 +924,11 @@ open_response_cb (GtkNativeDialog *dialog, int response, EphyWindow *window)
}
}
+#if GTK_CHECK_VERSION(3, 20, 0)
g_object_unref (dialog);
+#else
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+#endif
}
void
@@ -894,7 +947,11 @@ window_cmd_open (GSimpleAction *action,
g_signal_connect (dialog, "response",
G_CALLBACK (open_response_cb), window);
+#if GTK_CHECK_VERSION(3, 20, 0)
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
+#else
+ gtk_widget_show (GTK_WIDGET (dialog));
+#endif
}
typedef struct {
@@ -1445,7 +1502,7 @@ get_suggested_filename (EphyEmbed *embed)
}
static void
-save_response_cb (GtkNativeDialog *dialog, int response, EphyEmbed *embed)
+save_response_cb (GtkFileChooser *dialog, int response, EphyEmbed *embed)
{
if (response == GTK_RESPONSE_ACCEPT) {
char *uri, *converted;
@@ -1464,7 +1521,11 @@ save_response_cb (GtkNativeDialog *dialog, int response, EphyEmbed *embed)
}
}
+#if GTK_CHECK_VERSION(3, 20, 0)
g_object_unref (dialog);
+#else
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+#endif
}
void
@@ -1495,7 +1556,11 @@ window_cmd_save_as (GSimpleAction *action,
g_signal_connect (dialog, "response",
G_CALLBACK (save_response_cb), embed);
+#if GTK_CHECK_VERSION(3, 20, 0)
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
+#else
+ gtk_widget_show (GTK_WIDGET (dialog));
+#endif
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]