gnome-terminal r2627 - trunk/src



Author: chpe
Date: Thu May 29 19:39:54 2008
New Revision: 2627
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2627&view=rev

Log:
Add convenience function to load a GtkBuilder file, and use it.


Modified:
   trunk/src/terminal-app.c
   trunk/src/terminal-util.c
   trunk/src/terminal-util.h

Modified: trunk/src/terminal-app.c
==============================================================================
--- trunk/src/terminal-app.c	(original)
+++ trunk/src/terminal-app.c	Thu May 29 19:39:54 2008
@@ -1309,8 +1309,6 @@
 terminal_app_manage_profiles (TerminalApp     *app,
                               GtkWindow       *transient_parent)
 {
-  char *ui_filename;
-  GtkBuilder *builder;
   GObject *dialog;
   GObject *tree_view_container, *new_button, *edit_button, *remove_button;
   GObject *default_hbox, *default_label;
@@ -1323,19 +1321,16 @@
       return;
     }
 
-  builder = gtk_builder_new ();
-
-  ui_filename = g_build_filename (TERM_PKGDATADIR, "profile-manager.ui", NULL);
-  gtk_builder_add_from_file (builder, ui_filename, NULL);
-  g_free (ui_filename);
-
-  dialog = gtk_builder_get_object (builder, "profile-manager");
-  tree_view_container = gtk_builder_get_object (builder, "profiles-treeview-container");
-  new_button = gtk_builder_get_object (builder, "new-profile-button");
-  edit_button = gtk_builder_get_object (builder, "edit-profile-button");
-  remove_button = gtk_builder_get_object (builder, "delete-profile-button");
-  default_hbox = gtk_builder_get_object (builder, "default-profile-hbox");
-  default_label = gtk_builder_get_object (builder, "default-profile-label");
+  if (!terminal_util_load_builder_file ("profile-manager.ui",
+                                        "profile-manager", &dialog,
+                                        "profiles-treeview-container", &tree_view_container,
+                                        "new-profile-button", &new_button,
+                                        "edit-profile-button", &edit_button,
+                                        "delete-profile-button", &remove_button,
+                                        "default-profile-hbox", &default_hbox,
+                                        "default-profile-label", &default_label,
+                                        NULL))
+    return;
 
   app->manage_profiles_dialog = GTK_WIDGET (dialog);
   app->manage_profiles_new_button = GTK_WIDGET (new_button);
@@ -1385,8 +1380,6 @@
                                 transient_parent);
 
   gtk_window_present (GTK_WINDOW (app->manage_profiles_dialog));
-
-  g_object_unref (builder);
 }
 
 static void

Modified: trunk/src/terminal-util.c
==============================================================================
--- trunk/src/terminal-util.c	(original)
+++ trunk/src/terminal-util.c	Thu May 29 19:39:54 2008
@@ -282,3 +282,45 @@
       g_object_unref (file);
     }
 }
+
+gboolean
+terminal_util_load_builder_file (const char *filename,
+                                 const char *object_name,
+                                 ...)
+{
+  char *path;
+  GtkBuilder *builder;
+  GError *error = NULL;
+  va_list args;
+
+  path = g_build_filename (TERM_PKGDATADIR, filename, NULL);
+  builder = gtk_builder_new ();
+  if (!gtk_builder_add_from_file (builder, path, &error)) {
+    g_warning ("Failed to load %s: %s\n", filename, error->message);
+    g_error_free (error);
+    g_free (path);
+    g_object_unref (builder);
+    return FALSE;
+  }
+  g_free (path);
+
+  va_start (args, object_name);
+
+  while (object_name) {
+    GObject **objectptr;
+
+    objectptr = va_arg (args, GObject**);
+    *objectptr = gtk_builder_get_object (builder, object_name);
+    if (!*objectptr) {
+      g_warning ("Failed to fetch object '%s'\n", object_name);
+      break;
+    }
+
+    object_name = va_arg (args, const char*);
+  }
+
+  va_end (args);
+
+  g_object_unref (builder);
+  return object_name == NULL;
+}

Modified: trunk/src/terminal-util.h
==============================================================================
--- trunk/src/terminal-util.h	(original)
+++ trunk/src/terminal-util.h	Thu May 29 19:39:54 2008
@@ -50,4 +50,8 @@
 
 void terminal_util_transform_uris_to_quoted_fuse_paths (char **uris);
 
+gboolean terminal_util_load_builder_file (const char *filename,
+                                          const char *object_name,
+                                          ...);
+
 #endif /* TERMINAL_UTIL_H */



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