[file-roller/wip/jtojnar/gtk4] Replaces custom _gtk_builder_new_from_resource function
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller/wip/jtojnar/gtk4] Replaces custom _gtk_builder_new_from_resource function
- Date: Tue, 21 Dec 2021 00:11:11 +0000 (UTC)
commit 2e019e280bbbc9504fd5e3c9863a1da965fa6612
Author: Jan Tojnar <jtojnar gmail com>
Date: Tue Dec 21 01:07:18 2021 +0100
Replaces custom _gtk_builder_new_from_resource function
The official gtk_builder_new_from_resource is identical except
that it fails loudly. Given that resources are baked into the app,
not being able to load ui file should be a hard error anyway.
Transformed using the following semantic patch:
https://gitlab.gnome.org/jtojnar/glib-refactoring/-/blob/5d70945511ce1f924f2f3eae59cb382bf39caeb7/patches/file-roller/replaced-custom-gtk_builder_from_resource-wannabe.cocci
meson.build | 1 +
src/dlg-add.c | 10 ++--------
src/dlg-ask-password.c | 6 +-----
src/dlg-delete.c | 6 +-----
src/dlg-extract.c | 4 +---
src/dlg-password.c | 6 +-----
src/dlg-prop.c | 6 +-----
src/dlg-update.c | 6 +-----
src/fr-application-menu.c | 2 +-
src/fr-file-selector-dialog.c | 2 +-
src/fr-new-archive-dialog.c | 4 +---
src/fr-window.c | 6 +++---
src/gtk-utils.c | 22 +---------------------
src/gtk-utils.h | 1 -
14 files changed, 16 insertions(+), 66 deletions(-)
---
diff --git a/meson.build b/meson.build
index c1b9ce4d..d9fba300 100644
--- a/meson.build
+++ b/meson.build
@@ -60,6 +60,7 @@ config_data.set_quoted('GETTEXT_PACKAGE', gettext_package)
config_data.set_quoted('LOCALEDIR', join_paths(prefix, get_option('localedir')))
config_data.set_quoted('PACKAGE_NAME', meson.project_name())
config_data.set_quoted('PACKAGE_VERSION', meson.project_version())
+config_data.set_quoted('FILE_ROLLER_RESOURCE_UI_PATH', '/org/gnome/FileRoller/ui/')
if get_option('run-in-place')
config_data.set_quoted('PRIVDATADIR', join_paths(meson.source_root(), 'data'))
config_data.set_quoted('PRIVEXECDIR', join_paths(meson.source_root(), 'src', 'commands'))
diff --git a/src/dlg-add.c b/src/dlg-add.c
index 2395b05f..688a2737 100644
--- a/src/dlg-add.c
+++ b/src/dlg-add.c
@@ -177,9 +177,7 @@ dlg_add (FrWindow *window)
g_object_get (data->dialog, "use-header-bar", &use_header, NULL);
- data->builder = _gtk_builder_new_from_resource ("add-dialog-options.ui");
- if (data->builder == NULL)
- return;
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "add-dialog-options.ui");
fr_file_selector_dialog_set_extra_widget (FR_FILE_SELECTOR_DIALOG (data->dialog), GET_WIDGET
("extra_widget"));
/* options menu button */
@@ -733,11 +731,7 @@ load_options_activate_cb (GSimpleAction *action,
aod_data = g_new0 (LoadOptionsDialogData, 1);
aod_data->data = data;
- aod_data->builder = _gtk_builder_new_from_resource ("add-options.ui");
- if (aod_data->builder == NULL) {
- g_free (aod_data);
- return;
- }
+ aod_data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "add-options.ui");
/* Get the widgets. */
diff --git a/src/dlg-ask-password.c b/src/dlg-ask-password.c
index b7dd5864..081d5ab3 100644
--- a/src/dlg-ask-password.c
+++ b/src/dlg-ask-password.c
@@ -103,11 +103,7 @@ dlg_ask_password__common (FrWindow *window,
char *message;
data = g_new0 (DialogData, 1);
- data->builder = _gtk_builder_new_from_resource ("ask-password.ui");
- if (data->builder == NULL) {
- g_free (data);
- return;
- }
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "ask-password.ui");
data->window = window;
data->pwd_type = pwd_type;
diff --git a/src/dlg-delete.c b/src/dlg-delete.c
index 5be71b25..d0a123a7 100644
--- a/src/dlg-delete.c
+++ b/src/dlg-delete.c
@@ -117,11 +117,7 @@ dlg_delete__common (FrWindow *window,
data->window = window;
data->selected_files = selected_files;
- data->builder = _gtk_builder_new_from_resource ("delete.ui");
- if (data->builder == NULL) {
- g_free (data);
- return;
- }
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "delete.ui");
/* Get the widgets. */
diff --git a/src/dlg-extract.c b/src/dlg-extract.c
index aa0dd6a0..1050a239 100644
--- a/src/dlg-extract.c
+++ b/src/dlg-extract.c
@@ -331,9 +331,7 @@ dlg_extract__common (FrWindow *window,
gtk_file_chooser_set_create_folders (GTK_FILE_CHOOSER (data->dialog), TRUE);
gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);
- data->builder = _gtk_builder_new_from_resource ("extract-dialog-options.ui");
- if (data->builder == NULL)
- return;
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH
"extract-dialog-options.ui");
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (data->dialog), GET_WIDGET ("extra_widget"));
/* Set widgets data. */
diff --git a/src/dlg-password.c b/src/dlg-password.c
index 43fb4851..c4808dda 100644
--- a/src/dlg-password.c
+++ b/src/dlg-password.c
@@ -81,11 +81,7 @@ dlg_password (GtkWidget *widget,
data = g_new0 (DialogData, 1);
data->window = window;
- data->builder = _gtk_builder_new_from_resource ("password.ui");
- if (data->builder == NULL) {
- g_free (data);
- return;
- }
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "password.ui");
/* Set widgets data. */
diff --git a/src/dlg-prop.c b/src/dlg-prop.c
index 60483fe3..5898c567 100644
--- a/src/dlg-prop.c
+++ b/src/dlg-prop.c
@@ -63,11 +63,7 @@ dlg_prop (FrWindow *window)
data = g_new (DialogData, 1);
- data->builder = _gtk_builder_new_from_resource ("properties.ui");
- if (data->builder == NULL) {
- g_free (data);
- return;
- }
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "properties.ui");
/* Get the widgets. */
table = _gtk_builder_get_widget (data->builder, "content");
diff --git a/src/dlg-update.c b/src/dlg-update.c
index eec2e1bf..c7cac194 100644
--- a/src/dlg-update.c
+++ b/src/dlg-update.c
@@ -300,11 +300,7 @@ dlg_update (FrWindow *window)
data = g_new0 (DialogData, 1);
- data->builder = _gtk_builder_new_from_resource ("update.ui");
- if (data->builder == NULL) {
- g_free (data);
- return NULL;
- }
+ data->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "update.ui");
data->file_list = NULL;
data->window = g_object_ref (window);
diff --git a/src/fr-application-menu.c b/src/fr-application-menu.c
index b2fe98dd..c2f9c053 100644
--- a/src/fr-application-menu.c
+++ b/src/fr-application-menu.c
@@ -239,7 +239,7 @@ initialize_app_menubar (GApplication *application)
G_N_ELEMENTS (app_menu_entries),
application);
- builder = _gtk_builder_new_from_resource ("app-menubar.ui");
+ builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "app-menubar.ui");
gtk_application_set_menubar (GTK_APPLICATION (application),
G_MENU_MODEL (gtk_builder_get_object (builder, "app-menubar")));
g_object_unref (builder);
diff --git a/src/fr-file-selector-dialog.c b/src/fr-file-selector-dialog.c
index 2e88f010..c75c3dcd 100644
--- a/src/fr-file-selector-dialog.c
+++ b/src/fr-file-selector-dialog.c
@@ -680,7 +680,7 @@ static void
fr_file_selector_dialog_init (FrFileSelectorDialog *self)
{
self->current_folder = NULL;
- self->builder = _gtk_builder_new_from_resource ("file-selector.ui");
+ self->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "file-selector.ui");
self->icon_cache = NULL;
self->settings = g_settings_new ("org.gnome.FileRoller.FileSelector");
self->show_hidden = g_settings_get_boolean (self->settings, PREF_FILE_SELECTOR_SHOW_HIDDEN);
diff --git a/src/fr-new-archive-dialog.c b/src/fr-new-archive-dialog.c
index 7b23d89c..412a5fd6 100644
--- a/src/fr-new-archive-dialog.c
+++ b/src/fr-new-archive-dialog.c
@@ -206,9 +206,7 @@ _fr_new_archive_dialog_construct (FrNewArchiveDialog *self,
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
gtk_container_set_border_width (GTK_CONTAINER (self), 5);
- self->builder = _gtk_builder_new_from_resource ("new-archive-dialog.ui");
- if (self->builder == NULL)
- return;
+ self->builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "new-archive-dialog.ui");
_g_object_unref (self->original_file);
self->original_file = _g_object_ref (original_file);
diff --git a/src/fr-window.c b/src/fr-window.c
index dcd1edb1..acead7f0 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -2552,7 +2552,7 @@ create_the_progress_dialog (FrWindow *window)
title = NULL;
}
- builder = _gtk_builder_new_from_resource ("progress-dialog.ui");
+ builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "progress-dialog.ui");
use_header_bar = _gtk_settings_get_dialogs_use_header ();
dialog = g_object_new (GTK_TYPE_DIALOG, "use-header-bar", use_header_bar, NULL);
gtk_box_pack_end (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
@@ -5802,7 +5802,7 @@ fr_window_construct (FrWindow *window)
GtkBuilder *builder;
GMenuModel *menu;
- builder = _gtk_builder_new_from_resource ("gears-menu.ui");
+ builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "gears-menu.ui");
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
button = _gtk_menu_button_new_for_header_bar ();
gtk_size_group_add_widget (header_bar_size_group, button);
@@ -5881,7 +5881,7 @@ fr_window_construct (FrWindow *window)
{
GtkBuilder *builder;
- builder = _gtk_builder_new_from_resource ("menus.ui");
+ builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "menus.ui");
window->priv->file_popup_menu = gtk_popover_new_from_model (window->priv->list_view,
G_MENU_MODEL (gtk_builder_get_object (builder, "file-popup")));
window->priv->folder_popup_menu = gtk_popover_new_from_model (window->priv->list_view,
G_MENU_MODEL (gtk_builder_get_object (builder, "folder-popup")));
diff --git a/src/gtk-utils.c b/src/gtk-utils.c
index b1ade2ec..e0927771 100644
--- a/src/gtk-utils.c
+++ b/src/gtk-utils.c
@@ -24,7 +24,6 @@
#include "gtk-utils.h"
#define LOAD_BUFFER_SIZE 65536
-#define FILE_ROLLER_RESOURCE_UI_PATH "/org/gnome/FileRoller/ui/"
static void
@@ -132,7 +131,7 @@ _gtk_request_dialog_run (GtkWindow *parent,
GtkWidget *request_box;
char *result;
- builder = _gtk_builder_new_from_resource ("request-dialog.ui");
+ builder = gtk_builder_new_from_resource (FILE_ROLLER_RESOURCE_UI_PATH "request-dialog.ui");
request_box = _gtk_builder_get_widget (builder, "request_box");
dialog = g_object_new (GTK_TYPE_DIALOG,
@@ -546,25 +545,6 @@ _gtk_builder_new_from_file (const char *ui_file)
}
-GtkBuilder *
-_gtk_builder_new_from_resource (const char *resource_path)
-{
- GtkBuilder *builder;
- char *full_path;
- GError *error = NULL;
-
- builder = gtk_builder_new ();
- full_path = g_strconcat (FILE_ROLLER_RESOURCE_UI_PATH, resource_path, NULL);
- if (! gtk_builder_add_from_resource (builder, full_path, &error)) {
- g_warning ("%s\n", error->message);
- g_clear_error (&error);
- }
- g_free (full_path);
-
- return builder;
-}
-
-
GtkWidget *
_gtk_builder_get_widget (GtkBuilder *builder,
const char *name)
diff --git a/src/gtk-utils.h b/src/gtk-utils.h
index 69c7df75..e3f923c5 100644
--- a/src/gtk-utils.h
+++ b/src/gtk-utils.h
@@ -87,7 +87,6 @@ GdkPixbuf * _g_mime_type_get_icon (const char *mime_type,
void _gtk_show_help_dialog (GtkWindow *parent,
const char *section);
GtkBuilder * _gtk_builder_new_from_file (const char *filename);
-GtkBuilder * _gtk_builder_new_from_resource (const char *resource_path);
GtkWidget * _gtk_builder_get_widget (GtkBuilder *builder,
const char *name);
int _gtk_widget_lookup_for_size (GtkWidget *widget,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]