[Goodies-commits] r5631 - xfbib/branches/gobject/src

David Gustafsson tssj at xfce.org
Wed Oct 15 09:48:17 CEST 2008


Author: tssj
Date: 2008-10-15 07:48:17 +0000 (Wed, 15 Oct 2008)
New Revision: 5631

Modified:
   xfbib/branches/gobject/src/xfbib-bibtex-entry.c
   xfbib/branches/gobject/src/xfbib-bibtex-entry.h
   xfbib/branches/gobject/src/xfbib-bibtex-field.c
   xfbib/branches/gobject/src/xfbib-bibtex-field.h
   xfbib/branches/gobject/src/xfbib-bibtex-value.c
   xfbib/branches/gobject/src/xfbib-bibtex-value.h
   xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
   xfbib/branches/gobject/src/xfbib-list-store.c
Log:
Updated the api of the parser.


Modified: xfbib/branches/gobject/src/xfbib-bibtex-entry.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-entry.c	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-bibtex-entry.c	2008-10-15 07:48:17 UTC (rev 5631)
@@ -146,6 +146,55 @@
 	return TRUE;
 }
 
+const GList *
+xfbib_bibtex_entry_get_fields(XfbibBibtexEntry *entry)
+{
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), NULL);
+	return entry->fields;
+}
+
+void
+xfbib_bibtex_entry_set_fields(XfbibBibtexEntry *entry, GList *list)
+{
+	g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
+	g_list_foreach (entry->fields, (GFunc) g_object_unref, NULL);
+	g_list_free (entry->fields);
+
+	entry->fields = list;
+}
+
+const gchar *
+xfbib_bibtex_entry_get_key(XfbibBibtexEntry *entry)
+{
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), NULL);
+	return xfbib_strbuf_get_str(entry->key);
+}
+
+void 
+xfbib_bibtex_entry_set_key(XfbibBibtexEntry *entry, const gchar *key)
+{
+	g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
+	xfbib_strbuf_wipe(entry->key);
+	xfbib_strbuf_append(entry->key, key);
+}
+
+const gchar *
+xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *entry)
+{
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), NULL);
+	return xfbib_strbuf_get_str(entry->bibtype);
+}
+
+
+void 
+xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *entry, const gchar *bibtype)
+{
+	g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
+	xfbib_strbuf_wipe(entry->bibtype);
+	xfbib_strbuf_append(entry->bibtype, bibtype);
+}
+
+#if 0
 XfbibBibtexField *
 xfbib_bibtex_entry_get_field_by_column(XfbibBibtexEntry *entry, gint column)
 {
@@ -192,4 +241,4 @@
 {
 	entry->fields = fields;
 }
-
+#endif

Modified: xfbib/branches/gobject/src/xfbib-bibtex-entry.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-entry.h	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-bibtex-entry.h	2008-10-15 07:48:17 UTC (rev 5631)
@@ -39,12 +39,20 @@
 
 XfbibBibtexEntry *xfbib_bibtex_entry_new();
 gboolean xfbib_bibtex_entry_parse(XfbibBibtexEntry *, const gchar *);
+const GList *xfbib_bibtex_entry_get_fields(XfbibBibtexEntry *);
+void xfbib_bibtex_entry_set_fields(XfbibBibtexEntry *, GList *);
+const gchar *xfbib_bibtex_entry_get_key(XfbibBibtexEntry *);
+void xfbib_bibtex_entry_set_key(XfbibBibtexEntry *, const gchar *);
+const gchar *xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *);
+void xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *, const gchar *);
+#if 0
 XfbibBibtexField *xfbib_bibtex_entry_get_field_by_column(XfbibBibtexEntry *, gint);
 XfbibStrbuf *xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *);
 XfbibStrbuf *xfbib_bibtex_entry_get_key(XfbibBibtexEntry *);
 void xfbib_bibtex_entry_set_key(XfbibBibtexEntry *, const gchar *);
 void xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *, const gchar *);
 void xfbib_bibtex_entry_set_fields(XfbibBibtexEntry *, GList *);
+#endif
 G_END_DECLS
 
 #endif //__XFBIB_BIBTEX_ENTRY_H

Modified: xfbib/branches/gobject/src/xfbib-bibtex-field.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-field.c	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-bibtex-field.c	2008-10-15 07:48:17 UTC (rev 5631)
@@ -26,38 +26,6 @@
 #include "xfbib-strbuf.h"
 #include "xfbib-bibtex-value.h"
 
-static struct {
-	gchar *label;
-	gchar *tooltip;
-}xfbib_bibtex_field_constants[] = {
-	{"Address", "Address of publisher"},
-	{"Annote", "Annotation for annotated bibliography styles"},
-	{"Author", "Name(s) of the author(s), separated by 'and' if more than one"},
-	{"Booktitle", "Title of the book, if only part of it is being cited"},
-	{"Chapter", "Chapter number"},
-	{"Crossref", "Citation key of the cross-referenced entry"},
-	{"Edition", "Edition of the book (such as \"first\" or \"second\")"},
-	{"Editor", "Name(s) of the editor(s), separated by 'and' if more than one"},
-	{"E-print", "Specification of electronic publication"},
-	{"HowPublished", "Publishing method if the method is nonstandard"},
-	{"Institution", "Institution that was involved in the publishing"},
-	{"Journal", "Journal or magazine in which the work was published"},
-	{"Key", "Hidden field used for specifying or overriding the alphabetical order of entries"},
-	{"Month", "Month of publication or creation if unpublished"},
-	{"Note", "Miscellaneous extra information"},
-	{"Number", "Number of journal, magazine, or tech-report"},
-	{"Organization", "Sponsor of the conference"},
-	{"Pages", "Page numbers separated by commas or double-hyphens"},
-	{"Publisher", "Name of publisher"},
-	{"School", "School where thesis was written"},
-	{"Series", "Series of books in which the book was published"},
-	{"Title", "Title of the work"},
-	{"Type", "Type of technical report"},
-	{"URL", "Internet address"},
-	{"Volume", "Number of the volume"},
-	{"Year", "Year of publication or creation if unpublished"}
-};
-
 struct _XfbibBibtexField
 {
 	GObject parent;
@@ -109,6 +77,7 @@
 xfbib_bibtex_field_parse(XfbibBibtexField *field, const gchar *str)
 {
 	gchar **split = NULL;
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_FIELD(field), FALSE);
 
 	split = g_strsplit(str, "=", 2);
 
@@ -134,6 +103,39 @@
 	return TRUE;
 }
 
+const gchar *
+xfbib_bibtex_field_get_variable(XfbibBibtexField *field)
+{
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_FIELD(field), NULL);	
+	return xfbib_strbuf_get_str(field->variable);
+}
+
+void 
+xfbib_bibtex_field_set_variable(XfbibBibtexField *field, const gchar *str)
+{
+	g_return_if_fail(XFBIB_IS_BIBTEX_FIELD(field));
+	
+	xfbib_strbuf_wipe(field->variable);
+	xfbib_strbuf_append(field->variable, str);
+}
+
+const XfbibBibtexValue *
+xfbib_bibtex_field_get_value(XfbibBibtexField *field)
+{
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_FIELD(field), NULL);
+	return field->value;
+}
+
+void 
+xfbib_bibtex_field_set_value(XfbibBibtexField *field, XfbibBibtexValue *value)
+{
+	g_return_if_fail(XFBIB_IS_BIBTEX_FIELD(field));
+	g_object_unref(field->value);
+	field->value = value;
+}
+
+
+#if 0
 gboolean
 xfbib_bibtex_field_is_column(XfbibBibtexField *field, gint column)
 {
@@ -164,4 +166,4 @@
 	}
 	field->value = value;
 }
-
+#endif

Modified: xfbib/branches/gobject/src/xfbib-bibtex-field.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-field.h	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-bibtex-field.h	2008-10-15 07:48:17 UTC (rev 5631)
@@ -62,16 +62,54 @@
 	XFBIB_FIELD_N_FIELDS,
 };
 
+static struct {
+	gchar *label;
+	gchar *tooltip;
+}xfbib_bibtex_field_constants[] = {
+	{"Address", "Address of publisher"},
+	{"Annote", "Annotation for annotated bibliography styles"},
+	{"Author", "Name(s) of the author(s), separated by 'and' if more than one"},
+	{"Booktitle", "Title of the book, if only part of it is being cited"},
+	{"Chapter", "Chapter number"},
+	{"Crossref", "Citation key of the cross-referenced entry"},
+	{"Edition", "Edition of the book (such as \"first\" or \"second\")"},
+	{"Editor", "Name(s) of the editor(s), separated by 'and' if more than one"},
+	{"E-print", "Specification of electronic publication"},
+	{"HowPublished", "Publishing method if the method is nonstandard"},
+	{"Institution", "Institution that was involved in the publishing"},
+	{"Journal", "Journal or magazine in which the work was published"},
+	{"Key", "Hidden field used for specifying or overriding the alphabetical order of entries"},
+	{"Month", "Month of publication or creation if unpublished"},
+	{"Note", "Miscellaneous extra information"},
+	{"Number", "Number of journal, magazine, or tech-report"},
+	{"Organization", "Sponsor of the conference"},
+	{"Pages", "Page numbers separated by commas or double-hyphens"},
+	{"Publisher", "Name of publisher"},
+	{"School", "School where thesis was written"},
+	{"Series", "Series of books in which the book was published"},
+	{"Title", "Title of the work"},
+	{"Type", "Type of technical report"},
+	{"URL", "Internet address"},
+	{"Volume", "Number of the volume"},
+	{"Year", "Year of publication or creation if unpublished"}
+};
+
 typedef struct _XfbibBibtexField         XfbibBibtexField;
 
 GType xfbib_field_get_type() G_GNUC_CONST;
 
 XfbibBibtexField *xfbib_bibtex_field_new();
 gboolean xfbib_bibtex_field_parse(XfbibBibtexField *, const gchar *);
-gboolean xfbib_bibtex_field_is_column(XfbibBibtexField *, gint);
+const gchar *xfbib_bibtex_field_get_variable(XfbibBibtexField *);
+void xfbib_bibtex_field_set_variable(XfbibBibtexField *, const gchar *);
+const XfbibBibtexValue *xfbib_bibtex_field_get_value(XfbibBibtexField *);
+void xfbib_bibtex_field_set_value(XfbibBibtexField *, XfbibBibtexValue *);
+#if 0
 const gchar *xfbib_bibtex_field_get_value_str(XfbibBibtexField *);
 void xfbib_bibtex_field_set_variable(XfbibBibtexField *, const gchar *);
 void xfbib_bibtex_field_set_value(XfbibBibtexField *, XfbibBibtexValue *);
+gboolean xfbib_bibtex_field_is_column(XfbibBibtexField *, gint);
+#endif
 G_END_DECLS
 
 #endif //__XFBIB_BIBTEX_FIELD_H

Modified: xfbib/branches/gobject/src/xfbib-bibtex-value.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-value.c	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-bibtex-value.c	2008-10-15 07:48:17 UTC (rev 5631)
@@ -44,6 +44,13 @@
 static void
 xfbib_bibtex_value_finalize(GObject *obj)
 {
+	XfbibBibtexValue *value;
+	g_return_if_fail(XFBIB_IS_BIBTEX_VALUE(value));
+	
+	value = XFBIB_BIBTEX_VALUE(obj);
+	g_list_foreach (value->list, (GFunc) g_object_unref, NULL);
+	g_list_free (value->list);
+	value->list = NULL;
 	G_OBJECT_CLASS(xfbib_bibtex_value_parent_class)->finalize(obj);
 }
 
@@ -152,57 +159,63 @@
 	return TRUE;
 }
 
+const GList *xfbib_bibtex_value_get(XfbibBibtexValue *value)
+{
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_VALUE(value), NULL);
+	
+	return value->list;
+}
+
+
+void xfbib_bibtex_value_set(XfbibBibtexValue *value, GList *list)
+{
+	g_return_if_fail(XFBIB_IS_BIBTEX_VALUE(value));
+
+	/* Remove all values */
+	g_list_foreach (value->list, (GFunc) g_object_unref, NULL);
+	g_list_free (value->list);
+	
+	value->list = list;
+}
+
 const gchar *
 xfbib_bibtex_value_get_str(XfbibBibtexValue *value)
 {
 	GObject *obj;
+	g_return_val_if_fail(XFBIB_IS_BIBTEX_VALUE(value), NULL);
+	
 	if (g_list_length(value->list) == 1) {
 		obj = g_list_nth_data(value->list, 0);
 		if (XFBIB_IS_BIBTEX_STRING(obj)) {
-			/* Variable */
-			return "TODO: Variable";
+			/* variable */
+			return "todo: variable";
 		} else if (XFBIB_IS_STRBUF(obj)) {
-			/* Regular string */
+			/* regular string */
 			return xfbib_strbuf_get_str(XFBIB_STRBUF(obj));
 		} else if (XFBIB_IS_INTEGER(obj)) {
-			/* Integer value */
-			return "TODO: Integer";
-		}
-	} else {
-		return "Compund string";
+			/* integer value */
+			return "todo: integer";
+		}	
 	}
+	return NULL;
 }
 
+/*
+ * Remove all values in the list and set the first value to str
+ */
 void
 xfbib_bibtex_value_set_str(XfbibBibtexValue *value, const gchar *str)
 {
 	XfbibStrbuf *strbuf;
-	GList *list;
-
+	g_return_if_fail(XFBIB_IS_BIBTEX_VALUE(value));
+	
+	/* Remove all values */
+	g_list_foreach (value->list, (GFunc) g_object_unref, NULL);
+	g_list_free (value->list);
+	value->list = NULL;
+	
 	strbuf = xfbib_strbuf_new();
 	xfbib_strbuf_append(strbuf, str);
-	list = g_list_append(list, G_OBJECT(strbuf));
-	if(value->list != NULL) {
-		/* TODO: Free the list */
-	}
-	value->list = list;
+	value->list = g_list_append(value->list, G_OBJECT(strbuf));	
 }
 
-void
-xfbib_bibtex_value_set_int(XfbibBibtexValue *value)
-{
-	/* TODO */
-}
-
-void
-xfbib_bibtex_value_set_string(XfbibBibtexValue *value)
-{
-	/* TODO */
-}
-
-void
-xfbib_bibtex_value_set_comstr(XfbibBibtexValue *value)
-{
-	/* TODO */
-}
-

Modified: xfbib/branches/gobject/src/xfbib-bibtex-value.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-value.h	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-bibtex-value.h	2008-10-15 07:48:17 UTC (rev 5631)
@@ -18,6 +18,8 @@
 
 XfbibBibtexValue *xfbib_bibtex_value_new();
 gboolean xfbib_bibtex_value_parse(XfbibBibtexValue *, const gchar *);
+const GList *xfbib_bibtex_value_get(XfbibBibtexValue *);
+void xfbib_bibtex_value_set(XfbibBibtexValue *, GList *);
 const gchar *xfbib_bibtex_value_get_str(XfbibBibtexValue *);
 void xfbib_bibtex_value_set_str(XfbibBibtexValue *, const gchar *);
 

Modified: xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c	2008-10-15 07:48:17 UTC (rev 5631)
@@ -341,8 +341,10 @@
 xfbib_entry_edit_dialog_new(XfbibBibtexEntry *entry)
 {
 	XfbibBibtexField *field;
+	XfbibBibtexValue *value;
 	const gchar *bibtype;
-	int n;
+	GList *list;
+	int n, i;
 
 	XfbibEntryEditDialog *entry_edit_dialog;
 	entry_edit_dialog = g_object_new(XFBIB_TYPE_ENTRY_EDIT_DIALOG,
@@ -364,14 +366,48 @@
 		gtk_entry_set_text(GTK_ENTRY (entry_edit_dialog->key_entry), xfbib_strbuf_get_str(xfbib_bibtex_entry_get_key(entry)));
 
 		for (n = 0; n < XFBIB_FIELD_N_FIELDS; n++) {
+
+			list = xfbib_bibtex_entry_get_fields(entry);
+
+			for (i = 0; i < g_list_length(list); i++) {
+				field = g_list_nth_data(list, i);
+				if (strcasecmp(xfbib_bibtex_field_get_variable(field),
+							xfbib_bibtex_field_constants[n].label) == 0) {
+					break;
+				}
+			}
+			
+			if (i >= g_list_length(list)) {
+				/* Did not find a matching field */
+				continue;
+			}
+			/*
 			field = xfbib_bibtex_entry_get_field_by_column(entry, n);
+			
+			
 			if (field == NULL) {
 				continue;
 			}
-			if (n == XFBIB_FIELD_AUTHOR || n == XFBIB_FIELD_EDITOR) {
-				xfbib_multiple_input_set_text (XFBIB_MULTIPLE_INPUT (entry_edit_dialog->inputs[n]), xfbib_bibtex_field_get_value_str(field));
+			*/
+			if (g_list_length(xfbib_bibtex_value_get(value)) == 1) {
+					/* Single value */
+				if (n == XFBIB_FIELD_AUTHOR || n == XFBIB_FIELD_EDITOR) {
+					xfbib_multiple_input_set_text (XFBIB_MULTIPLE_INPUT (entry_edit_dialog->inputs[n]),
+							xfbib_bibtex_value_get_str(value));
+				} else {
+
+					gtk_entry_set_text(GTK_ENTRY (entry_edit_dialog->inputs[n]),
+							xfbib_bibtex_value_get_str(value));
+				}
 			} else {
-				gtk_entry_set_text(GTK_ENTRY (entry_edit_dialog->inputs[n]), xfbib_bibtex_field_get_value_str(field));
+				/* TODO: Compund string: Set sensitivity to false
+				 * and make the compund button workable
+				 */
+				if (n == XFBIB_FIELD_AUTHOR || n == XFBIB_FIELD_EDITOR) {
+					gtk_widget_set_sensitive(entry_edit_dialog->inputs[n], FALSE);
+				} else {
+					gtk_widget_set_sensitive(entry_edit_dialog->inputs[n], FALSE);
+				}
 			}
 		}
 	}

Modified: xfbib/branches/gobject/src/xfbib-list-store.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-list-store.c	2008-10-15 07:30:38 UTC (rev 5630)
+++ xfbib/branches/gobject/src/xfbib-list-store.c	2008-10-15 07:48:17 UTC (rev 5631)
@@ -253,6 +253,9 @@
 {
 	XfbibListStore *list_store;
 	XfbibBibtexField *field;
+	GList *list;
+	gchar *tmp;
+	gint i;
 
 	g_return_if_fail(XFBIB_IS_LIST_STORE(tree_model));
 
@@ -268,10 +271,30 @@
 			g_return_if_fail(column < XFBIB_FIELD_N_FIELDS
 					 && XFBIB_IS_BIBTEX_ENTRY(iter->user_data));
 
+
+			list = xfbib_bibtex_entry_get_fields(XFBIB_BIBTEX_ENTRY(iter->user_data));
+
+			for (i = 0; i < g_list_length(list); i++) {
+				field = g_list_nth_data(list, i);
+				if (strcasecmp(xfbib_bibtex_field_get_variable(field),
+							xfbib_bibtex_field_constants[column].label) == 0) {
+					break;
+				}
+			}
+			
+			if (i >= g_list_length(list)) {
+				/* Did not find a matching field */
+				return;
+			}
+
+#if 0
 			field = xfbib_bibtex_entry_get_field_by_column(XFBIB_BIBTEX_ENTRY(iter->user_data), column);
+
 			if (field == NULL)
 				return;
-			g_value_set_string(value, xfbib_bibtex_field_get_value_str(field));
+#endif			
+			tmp = xfbib_bibtex_value_get_str(xfbib_bibtex_field_get_value(field));
+			g_value_set_string(value, (tmp == NULL) ? "" : tmp);
 			break;
 		default:
 			return;




More information about the Goodies-commits mailing list