[Goodies-commits] r5653 - xfbib/branches/gobject/src
Jesper Karlsson
zarper at xfce.org
Fri Oct 17 01:03:00 CEST 2008
Author: zarper
Date: 2008-10-16 23:03:00 +0000 (Thu, 16 Oct 2008)
New Revision: 5653
Modified:
xfbib/branches/gobject/src/xfbib-bibtex-string.c
xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
xfbib/branches/gobject/src/xfbib-input-dialog.c
xfbib/branches/gobject/src/xfbib-input-dialog.h
xfbib/branches/gobject/src/xfbib-multiple-input.c
xfbib/branches/gobject/src/xfbib-multiple-input.h
Log:
Added ability to add a String in the multiple-input list.
Modified: xfbib/branches/gobject/src/xfbib-bibtex-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-string.c 2008-10-16 22:50:24 UTC (rev 5652)
+++ xfbib/branches/gobject/src/xfbib-bibtex-string.c 2008-10-16 23:03:00 UTC (rev 5653)
@@ -89,6 +89,12 @@
xfbib_strbuf_append(string->variable, variable);
}
+void
+xfbib_bibtex_string_set_value(XfbibBibtexString *string, XfbibBibtexValue *value)
+{
+ string->value = value;
+}
+
gboolean
xfbib_bibtex_string_parse(XfbibBibtexString *string, const gchar *str)
{
Modified: xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c 2008-10-16 22:50:24 UTC (rev 5652)
+++ xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c 2008-10-16 23:03:00 UTC (rev 5653)
@@ -121,7 +121,7 @@
char *tmp;
strbuf = xfbib_strbuf_new();
- lastname = xfbib_multiple_input_get_nth_row(XFBIB_MULTIPLE_INPUT (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_FIELD_AUTHOR]),0);
+ lastname = xfbib_multiple_input_get_nth_row_ith_column(XFBIB_MULTIPLE_INPUT (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_FIELD_AUTHOR]),0,0);
if(lastname != NULL) {
tmp = strrchr(lastname, ' ') + 1;
xfbib_strbuf_append(strbuf, tmp);
@@ -391,12 +391,11 @@
}
*/
if (g_list_length(xfbib_bibtex_value_get(value)) == 1) {
- /* Single value */
+ /* 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));
}
@@ -424,24 +423,32 @@
GList *field_list = NULL;
XfbibBibtexValue *value;
int n;
+ const gchar *str;
entry = xfbib_bibtex_entry_new();
xfbib_bibtex_entry_set_key(entry, gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->key_entry)));
xfbib_bibtex_entry_set_bibtype(entry, gtk_combo_box_get_active_text(GTK_COMBO_BOX(entry_edit_dialog->type_combo_box)));
for (n = 0; n < XFBIB_FIELD_N_FIELDS; n++) {
if (n == XFBIB_FIELD_AUTHOR || n == XFBIB_FIELD_EDITOR) {
- if(xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n])) == "") {
+ str = xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n]));
+ if(str == NULL) {
+ field = xfbib_bibtex_field_new();
+ xfbib_bibtex_field_set_variable(field, xfbib_input_constants[n].label);
+ value = xfbib_bibtex_value_new();
+ /* TODO: Don't add field if GList = NULL */
+ xfbib_bibtex_value_set(value, xfbib_multiple_input_get(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n])));
+ } else if(strcmp(str, "") == 0) {
continue;
+ } else {
+ field = xfbib_bibtex_field_new();
+ xfbib_bibtex_field_set_variable(field, xfbib_input_constants[n].label);
+ value = xfbib_bibtex_value_new();
+ xfbib_bibtex_value_set_str(value, str);
}
- /* TODO: check if they are integers or strings(variables), don't assume text */
- field = xfbib_bibtex_field_new();
- xfbib_bibtex_field_set_variable(field, xfbib_input_constants[n].label);
- value = xfbib_bibtex_value_new();
- xfbib_bibtex_value_set_str(value, xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n])));
+ field_list = g_list_append(field_list, field);
xfbib_bibtex_field_set_value(field, value);
- field_list = g_list_append(field_list, field);
} else {
- if(gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n])) == "") {
+ if(strcmp(gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n])), "") == 0) {
continue;
}
/* TODO: check if they are integers or strings(variables), don't assume text */
Modified: xfbib/branches/gobject/src/xfbib-input-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-input-dialog.c 2008-10-16 22:50:24 UTC (rev 5652)
+++ xfbib/branches/gobject/src/xfbib-input-dialog.c 2008-10-16 23:03:00 UTC (rev 5653)
@@ -28,8 +28,10 @@
struct _XfbibInputDialog
{
XfceTitledDialog parent;
- GtkWidget *label;
- GtkWidget *entry;
+ GtkWidget *string_key_label;
+ GtkWidget *text_label;
+ GtkWidget *string_key_entry;
+ GtkWidget *text_entry;
};
typedef struct _XfbibInputDialogClass
@@ -79,21 +81,28 @@
static void
xfbib_input_dialog_init(XfbibInputDialog *instance)
{
- GtkWidget *hbox;
+ GtkWidget *table;
- hbox = gtk_hbox_new(FALSE, 10);
+ table = gtk_table_new(2,2,FALSE);
- /* TODO: Change label text */
- instance->label = gtk_label_new("Input:");
+ gtk_table_set_row_spacings(GTK_TABLE(table), 6);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 12);
+ gtk_container_set_border_width(GTK_CONTAINER (table), 6);
- instance->entry = gtk_entry_new();
- gtk_entry_set_width_chars(GTK_ENTRY (instance->entry), 30);
+ instance->string_key_label = gtk_label_new("String key:");
+ instance->text_label = gtk_label_new("Text:");
- gtk_box_pack_start (GTK_BOX (hbox), instance->label, FALSE, FALSE, 10);
- gtk_box_pack_end (GTK_BOX (hbox), instance->entry, FALSE, TRUE, 10);
+ instance->string_key_entry = gtk_combo_box_entry_new();
+ instance->text_entry = gtk_entry_new();
- gtk_box_pack_end (GTK_BOX (GTK_DIALOG (instance)->vbox), hbox, FALSE, TRUE, 10);
+ gtk_table_attach(GTK_TABLE(table), instance->string_key_label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), instance->text_label, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), instance->string_key_entry, 0, 1, 0, 1);
+ gtk_table_attach_defaults(GTK_TABLE(table), instance->text_entry, 1, 2, 0, 1);
+
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (instance)->vbox), table, FALSE, TRUE, 6);
+
/* Add OK and cancel button */
gtk_dialog_add_button (GTK_DIALOG (instance), GTK_STOCK_OK, GTK_RESPONSE_OK);
gtk_dialog_add_button (GTK_DIALOG (instance), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
@@ -121,14 +130,19 @@
"title", title,
NULL);
- lbl = g_strdup_printf("%s:", label);
- gtk_label_set_text(GTK_LABEL(input_dialog->label), lbl);
- free(lbl);
+ //lbl = g_strdup_printf("%s:", label);
+ //gtk_label_set_text(GTK_LABEL(input_dialog->label), lbl);
+ //free(lbl);
return GTK_WIDGET(input_dialog);
}
-const gchar *xfbib_input_dialog_get_input(XfbibInputDialog *instance)
+const gchar *xfbib_input_dialog_get_string_key(XfbibInputDialog *instance)
{
- return gtk_entry_get_text(GTK_ENTRY(instance->entry));
+ return gtk_combo_box_get_active_text(GTK_COMBO_BOX_ENTRY(instance->string_key_entry));
}
+const gchar *xfbib_input_dialog_get_text(XfbibInputDialog *instance)
+{
+ return gtk_entry_get_text(GTK_ENTRY(instance->text_entry));
+}
+
Modified: xfbib/branches/gobject/src/xfbib-input-dialog.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-input-dialog.h 2008-10-16 22:50:24 UTC (rev 5652)
+++ xfbib/branches/gobject/src/xfbib-input-dialog.h 2008-10-16 23:03:00 UTC (rev 5653)
@@ -36,7 +36,8 @@
GType xfbib_input_dialog_get_type() G_GNUC_CONST;
GtkWidget *xfbib_input_dialog_new(gchar *, const gchar *);
-const gchar *xfbib_input_dialog_get_input(XfbibInputDialog *);
+const gchar *xfbib_input_dialog_get_string_key(XfbibInputDialog *);
+const gchar *xfbib_input_dialog_get_text(XfbibInputDialog *);
G_END_DECLS
#endif //__XFBIB_INPUT_DIALOG_H
Modified: xfbib/branches/gobject/src/xfbib-multiple-input.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-multiple-input.c 2008-10-16 22:50:24 UTC (rev 5652)
+++ xfbib/branches/gobject/src/xfbib-multiple-input.c 2008-10-16 23:03:00 UTC (rev 5653)
@@ -25,6 +25,8 @@
#include "xfbib-multiple-input.h"
#include "xfbib-input-dialog.h"
#include "xfbib-strbuf.h"
+#include "xfbib-bibtex-string.h"
+#include "xfbib-bibtex-value.h"
struct _XfbibMultipleInput
{
@@ -70,20 +72,25 @@
GtkListStore *list;
GtkTreeIter iter;
GtkTreeViewColumn *column;
- const gchar *input;
+ const gchar *string_key, *text;
gchar *str;
column = gtk_tree_view_get_column(GTK_TREE_VIEW(tree_view), 0);
str = g_strdup_printf("Add %s", g_ascii_strdown(gtk_tree_view_column_get_title(column), -1));
dialog = xfbib_input_dialog_new(str, gtk_tree_view_column_get_title(column));
- free(str);
+ g_free(str);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
- input = xfbib_input_dialog_get_input(XFBIB_INPUT_DIALOG(dialog));
- if (strcasecmp (input, "") != 0) {
+ string_key = xfbib_input_dialog_get_string_key(XFBIB_INPUT_DIALOG(dialog));
+ text = xfbib_input_dialog_get_text(XFBIB_INPUT_DIALOG(dialog));
+ if ((strcasecmp (string_key, "") != 0) || (strcasecmp (text, "") != 0)) {
list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)));
gtk_list_store_append(list, &iter);
- gtk_list_store_set(list, &iter, 0, input, -1);
+ if (strcasecmp (string_key, "") != 0) {
+ gtk_list_store_set(list, &iter, 0, string_key, 1, text, -1);
+ } else {
+ gtk_list_store_set(list, &iter, 0, text, -1);
+ }
/* TODO: Update colors */
}
}
@@ -228,7 +235,7 @@
}
const gchar *
-xfbib_multiple_input_get_nth_row(XfbibMultipleInput *multiple_input, gint row)
+xfbib_multiple_input_get_nth_row_ith_column(XfbibMultipleInput *multiple_input, gint row, gint column)
{
GtkTreeModel *model;
GtkTreeIter iter;
@@ -241,7 +248,7 @@
n++;
}
if(n == row) {
- gtk_tree_model_get(model, &iter, 0, &tmp, -1);
+ gtk_tree_model_get(model, &iter, column, &tmp, -1);
return tmp;
}
}
@@ -252,17 +259,52 @@
xfbib_multiple_input_get_str(XfbibMultipleInput *multiple_input)
{
XfbibStrbuf *strbuf;
- gchar *str;
- int n = 0;
+ const gchar *str;
+ int n;
+ for(n = 0; (str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 1)) != NULL; n++) {
+ if(strcmp(str, "") != 0) {
+ /* Atleast one string found, needs to be handled by xfbib_multiple_input_get */
+ return NULL;
+ }
+ }
strbuf = xfbib_strbuf_new();
- while((str = xfbib_multiple_input_get_nth_row(multiple_input, n)) != NULL) {
+ for(n = 0; (str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 0)) != NULL; n++) {
if(n != 0) {
xfbib_strbuf_append(strbuf, " and ");
}
xfbib_strbuf_append(strbuf, str);
- n++;
}
return xfbib_strbuf_get_str(strbuf);
}
+GList *
+xfbib_multiple_input_get(XfbibMultipleInput *multiple_input)
+{
+ GList *list = NULL;
+ XfbibStrbuf *strbuf;
+ XfbibBibtexString *string;
+ XfbibBibtexValue *value;
+ const gchar *str, *text;
+ gint n;
+
+ for(n = 0; (str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 0)) != NULL; n++) {
+ text = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 1);
+ if(strcmp(text, "") != 0) {
+ string = xfbib_bibtex_string_new();
+ value = xfbib_bibtex_value_new();
+
+ xfbib_bibtex_string_set_variable(string, str);
+ xfbib_bibtex_value_set_str(value, text);
+ xfbib_bibtex_string_set_value(string, value);
+
+ list = g_list_append(list, G_OBJECT(string));
+ } else {
+ strbuf = xfbib_strbuf_new();
+ xfbib_strbuf_append(strbuf, str);
+ list = g_list_append(list, G_OBJECT(strbuf));
+ }
+ }
+ return list;
+}
+
Modified: xfbib/branches/gobject/src/xfbib-multiple-input.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-multiple-input.h 2008-10-16 22:50:24 UTC (rev 5652)
+++ xfbib/branches/gobject/src/xfbib-multiple-input.h 2008-10-16 23:03:00 UTC (rev 5653)
@@ -37,8 +37,9 @@
GtkWidget *xfbib_multiple_input_new(gchar *, gchar *);
void xfbib_multiple_input_set_text(XfbibMultipleInput *, const gchar *);
-const gchar *xfbib_multiple_input_get_nth_row(XfbibMultipleInput *, gint);
+const gchar *xfbib_multiple_input_get_nth_row_ith_column(XfbibMultipleInput *, gint, gint);
const gchar *xfbib_multiple_input_get_str(XfbibMultipleInput *);
+GList *xfbib_multiple_input_get(XfbibMultipleInput *);
G_END_DECLS
More information about the Goodies-commits
mailing list