]> git.sur5r.net Git - glabels/commitdiff
Multiple fixes to merge type and properties dialog.
authorJim Evins <evins@snaught.com>
Thu, 5 Dec 2002 22:38:38 +0000 (22:38 +0000)
committerJim Evins <evins@snaught.com>
Thu, 5 Dec 2002 22:38:38 +0000 (22:38 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@200 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/label.c
glabels2/src/merge-init.c
glabels2/src/merge-properties-dialog.c
glabels2/src/merge.c

index cd776ecdac43d0d71f989cc609f2c1a7c363a547..5bd3a48b2e1d15dda063bd48fd55e6cc540f175a 100644 (file)
@@ -506,7 +506,9 @@ gl_label_set_merge (glLabel *label,
 
        g_return_if_fail (label && GL_IS_LABEL (label));
 
-       g_object_unref (G_OBJECT(label->private->merge));
+       if ( label->private->merge != NULL ) {
+               g_object_unref (G_OBJECT(label->private->merge));
+       }
        label->private->merge = gl_merge_dup (merge);
 
        label->private->modified_flag = TRUE;
index 251769c3cbabbefe0c8015035dc6ac77bf0e63a6..a5e585af18c4230762debd5994598336dedfc1ec 100644 (file)
@@ -59,14 +59,14 @@ gl_merge_init (void)
                                   "Text/Colon",
                                   _("Text file with colon delimeters"),
                                   GL_MERGE_SRC_IS_FILE,
-                                  "delim", ',',
+                                  "delim", ':',
                                   NULL);
 
        gl_merge_register_backend (GL_TYPE_MERGE_TEXT,
                                   "Text/Tab",
-                                  _("Text file with tab delimeters (CSV)"),
+                                  _("Text file with tab delimeters"),
                                   GL_MERGE_SRC_IS_FILE,
-                                  "delim", ',',
+                                  "delim", '\t',
                                   NULL);
 
 }
index ede3779e87204881d61c9a7a39524894d21578c6..ba31921cc48cee888a3027958f2f5d477c8f79ce 100644 (file)
@@ -40,6 +40,7 @@ typedef struct {
        glMerge *merge;
 
        GtkWidget *type_entry;
+       GtkWidget *src_entry_holder;
        GtkWidget *src_entry;
        GtkWidget *sample;
 
@@ -78,6 +79,8 @@ gl_merge_properties_dialog (glView *view)
        PropertyDialogPassback *data;
        GtkWidget *dialog;
 
+       gl_debug (DEBUG_MERGE, "START");
+
        data = g_new0 (PropertyDialogPassback, 1);
 
        dialog = gl_hig_dialog_new_with_buttons (
@@ -99,6 +102,7 @@ gl_merge_properties_dialog (glView *view)
 
        gtk_widget_show_all (GTK_WIDGET (dialog));
 
+       gl_debug (DEBUG_MERGE, "END");
 }
 
 /*--------------------------------------------------------------------------*/
@@ -115,6 +119,8 @@ create_merge_dialog_widgets (glHigDialog * dialog,
        gchar             *src;
        GtkSizeGroup      *label_size_group;
 
+       gl_debug (DEBUG_MERGE, "START");
+
        data->merge = gl_label_get_merge (data->label);
        description = gl_merge_get_description (data->merge);
        src_type    = gl_merge_get_src_type (data->merge);
@@ -136,6 +142,14 @@ create_merge_dialog_widgets (glHigDialog * dialog,
 
        wcombo = gtk_combo_new ();
        texts = gl_merge_get_descriptions ();
+       gl_debug (DEBUG_MERGE, "DESCRIPTIONS:");
+       {
+               GList *p;
+
+               for (p=texts; p!=NULL; p=p->next) {
+                       gl_debug (DEBUG_MERGE, "    \"%s\"", p->data);
+               }
+       }
        gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), texts);
        gl_merge_free_descriptions (&texts);
        data->type_entry = GTK_COMBO (wcombo)->entry;
@@ -154,6 +168,7 @@ create_merge_dialog_widgets (glHigDialog * dialog,
        gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
        gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wlabel);
 
+       gl_debug (DEBUG_MERGE, "Src_type = %d", src_type);
        switch (src_type) {
        case GL_MERGE_SRC_IS_FILE:
                data->src_entry =
@@ -167,7 +182,9 @@ create_merge_dialog_widgets (glHigDialog * dialog,
                data->src_entry = gtk_label_new (_("N/A"));
                break;
        }
-       gl_hig_hbox_add_widget_justify (GL_HIG_HBOX(whbox), data->src_entry);
+       data->src_entry_holder = gtk_hbox_new (FALSE, 0);
+       gtk_container_add( GTK_CONTAINER(data->src_entry_holder), data->src_entry);
+       gl_hig_hbox_add_widget_justify (GL_HIG_HBOX(whbox), data->src_entry_holder);
 
        /* ---- Sample Fields section ---- */
        wframe = gl_hig_category_new (_("Sample fields"));
@@ -196,6 +213,8 @@ create_merge_dialog_widgets (glHigDialog * dialog,
        g_free (description);
 
         gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+       gl_debug (DEBUG_MERGE, "END");
 }
 
 /*--------------------------------------------------------------------------*/
@@ -211,13 +230,17 @@ type_changed_cb (GtkWidget * widget,
        glMergeSrcType     src_type;
        GtkWidget         *wentry;
 
+       gl_debug (DEBUG_MERGE, "START");
+
        description = gtk_editable_get_chars (GTK_EDITABLE (data->type_entry),
                                              0, -1);
        name = gl_merge_description_to_name (description);
 
        src = gl_merge_get_src (data->merge); /* keep current source if possible */
 
-       g_object_unref (G_OBJECT(data->merge));
+       if (data->merge != NULL) {
+               g_object_unref (G_OBJECT(data->merge));
+       }
        data->merge = gl_merge_new (name);
 
        gtk_widget_destroy (data->src_entry);
@@ -227,7 +250,9 @@ type_changed_cb (GtkWidget * widget,
                data->src_entry =
                        gnome_file_entry_new (NULL, _("Select merge-database source"));
                wentry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY(data->src_entry));
-               gtk_entry_set_text (GTK_ENTRY(wentry), src);
+               if (src != NULL) {
+                       gtk_entry_set_text (GTK_ENTRY(wentry), src);
+               }
                g_signal_connect (G_OBJECT (wentry), "changed",
                                  G_CALLBACK (src_changed_cb), data);
                break;
@@ -235,10 +260,14 @@ type_changed_cb (GtkWidget * widget,
                data->src_entry = gtk_label_new (_("N/A"));
                break;
        }
+       gtk_container_add( GTK_CONTAINER(data->src_entry_holder), data->src_entry);
+       gtk_widget_show (data->src_entry);
 
        g_free (description);
        g_free (name);
        g_free (src);
+
+       gl_debug (DEBUG_MERGE, "END");
 }
 
 /*--------------------------------------------------------------------------*/
@@ -251,6 +280,8 @@ src_changed_cb (GtkWidget * widget,
        gchar     *src;
        GtkWidget *wentry;
 
+       gl_debug (DEBUG_MERGE, "START");
+
        wentry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY(data->src_entry));
        src = gtk_editable_get_chars (GTK_EDITABLE (wentry), 0, -1);
 
@@ -258,6 +289,8 @@ src_changed_cb (GtkWidget * widget,
        gl_merge_ui_field_ws_set_type_src (GL_MERGE_UI_FIELD_WS
                                           (data->sample), type, src);
 #endif
+
+       gl_debug (DEBUG_MERGE, "END");
 }
 
 /*--------------------------------------------------------------------------*/
@@ -268,6 +301,8 @@ response_cb (glHigDialog * dialog,
             gint response,
             PropertyDialogPassback * data)
 {
+       gl_debug (DEBUG_MERGE, "START");
+
        switch (response) {
 
        case GTK_RESPONSE_OK:
@@ -277,7 +312,11 @@ response_cb (glHigDialog * dialog,
        }
 
 
-       g_object_unref (G_OBJECT(data->merge));
+       if (data->merge != NULL) {
+               g_object_unref (G_OBJECT(data->merge));
+       }
        g_free (data);
        gtk_widget_destroy (GTK_WIDGET(dialog));
+
+       gl_debug (DEBUG_MERGE, "END");
 }
index 5d6a7feed707c2f231239bc04238bea3c4f2126d..70ded1dea8a8a9a314530c433c694ea54a433e01 100644 (file)
@@ -22,6 +22,7 @@
 #include <config.h>
 
 #include <gnome.h>
+#include <gobject/gvaluecollector.h>
 #include <string.h>
 
 #include "merge.h"
@@ -50,8 +51,8 @@ typedef struct {
        gchar             *description;
        glMergeSrcType     src_type;
 
-       const gchar       *first_arg_name;
-       va_list            args;
+       guint              n_params;
+       GParameter        *params;
 
 } Backend;
 
@@ -86,22 +87,59 @@ gl_merge_register_backend (GType              type,
                           const gchar       *first_arg_name,
                           ...)
 {
-       Backend *backend;
-       va_list  args;
-       gchar   *a_nam;
-       gpointer a_val;
+       Backend      *backend;
+       va_list       args;
+       const gchar  *pname;
+       GObjectClass *class;
+       GParamSpec   *pspec;
+       GParameter   *params;
+       guint         n_params = 0, n_alloced_params = 16;
 
        backend = g_new0 (Backend, 1);
 
-       backend->type = type;
-       backend->name = g_strdup (name);
+       backend->type        = type;
+       backend->name        = g_strdup (name);
        backend->description = g_strdup (description);
+       backend->src_type    = src_type;
 
-       backend->first_arg_name = first_arg_name;
+       params = g_new (GParameter, n_alloced_params);
        va_start (args, first_arg_name);
-       G_VA_COPY (backend->args, args);
+       for ( pname=first_arg_name; pname != NULL; pname=va_arg (args,gchar *) ) {
+               gchar *error = NULL;
+
+               class = g_type_class_ref (type);
+               if (class == NULL) {
+                       g_warning ("%s: unknown object type %d",
+                                  G_STRLOC, type);
+                       break;
+               }
+               pspec = g_object_class_find_property (class, pname);
+               if (pspec == NULL) {
+                       g_warning ("%s: object class `%s' has no property named `%s'",
+                                  G_STRLOC, g_type_name (type), pname);
+                       break;
+               }
+               if (n_params >= n_alloced_params) {
+                       n_alloced_params += 16;
+                       params = g_renew (GParameter, params, n_alloced_params);
+               }
+               params[n_params].name = pname;
+               params[n_params].value.g_type = 0;
+               g_value_init (&params[n_params].value, pspec->value_type);
+               G_VALUE_COLLECT (&params[n_params].value, args, 0, &error);
+               if (error) {
+                       g_warning ("%s: %s", G_STRLOC, error);
+                       g_free (error);
+                       break;
+               }
+
+               n_params++;
+       }
        va_end (args);
 
+       backend->n_params = n_params;
+       backend->params   = params;
+
        backends = g_list_append (backends, backend);
 
 }
@@ -257,12 +295,12 @@ gl_merge_new (gchar *name)
 
                if (g_strcasecmp(name, backend->name) == 0) {
 
-                       merge = GL_MERGE (g_object_new_valist (backend->type,
-                                                              backend->first_arg_name,
-                                                              backend->args));
+                       merge = GL_MERGE (g_object_newv (backend->type,
+                                                        backend->n_params,
+                                                        backend->params));
 
-                       merge->private->name        = name;
-                       merge->private->description = backend->description;
+                       merge->private->name        = g_strdup (name);
+                       merge->private->description = g_strdup (backend->description);
                        merge->private->src_type    = backend->src_type;
 
                        break;
@@ -299,6 +337,7 @@ gl_merge_dup (glMerge *src_merge)
        dst_merge->private->name        = g_strdup (src_merge->private->name);
        dst_merge->private->description = g_strdup (src_merge->private->description);
        dst_merge->private->src         = g_strdup (src_merge->private->src);
+       dst_merge->private->src_type    = src_merge->private->src_type;
 
        if ( GL_MERGE_GET_CLASS(src_merge)->copy != NULL ) {