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

Jesper Karlsson zarper at xfce.org
Sat Sep 20 22:50:34 CEST 2008


Author: zarper
Date: 2008-09-20 20:50:34 +0000 (Sat, 20 Sep 2008)
New Revision: 5427

Added:
   xfbib/branches/gobject/src/xfbib-file-io.c
   xfbib/branches/gobject/src/xfbib-file-io.h
Modified:
   xfbib/branches/gobject/src/Makefile.am
   xfbib/branches/gobject/src/xfbib-list-store.c
   xfbib/branches/gobject/src/xfbib-menu-bar.c
   xfbib/branches/gobject/src/xfbib-toolbar.c
   xfbib/branches/gobject/src/xfbib-toolbar.h
   xfbib/branches/gobject/src/xfbib-window.c
   xfbib/branches/gobject/src/xfbib-window.h
Log:
Prepared for file opening functionality


Modified: xfbib/branches/gobject/src/Makefile.am
===================================================================
--- xfbib/branches/gobject/src/Makefile.am	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/Makefile.am	2008-09-20 20:50:34 UTC (rev 5427)
@@ -12,6 +12,8 @@
 	xfbib-entry-edit-dialog.h \
 	xfbib-field.c \
 	xfbib-field.h \
+	xfbib-file-io.c \
+	xfbib-file-io.h \
 	xfbib-input-dialog.c \
 	xfbib-input-dialog.h \
 	xfbib-integer.c \

Added: xfbib/branches/gobject/src/xfbib-file-io.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.c	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-file-io.c	2008-09-20 20:50:34 UTC (rev 5427)
@@ -0,0 +1,105 @@
+/* 
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gtk/gtk.h>
+#include <libxfcegui4/libxfcegui4.h>
+
+#include "xfbib-file-io.h"
+#include "xfbib-strbuf.h"
+#include "xfbib-elements.h"
+#include "xfbib-window.h"
+
+struct _XfbibFileIo
+{
+	GObject parent;
+	XfbibStrbuf *filename;
+};
+ 
+typedef struct _XfbibFileIoClass
+{
+	GObjectClass parent;
+} XfbibFileIoClass;
+ 
+static void xfbib_file_io_class_init(XfbibFileIoClass *klass);
+
+static void xfbib_file_io_init(XfbibFileIo *instance);
+static void xfbib_file_io_finalize(GObject *obj);
+
+G_DEFINE_TYPE(XfbibFileIo, xfbib_file_io, G_TYPE_OBJECT)
+
+static void
+xfbib_file_io_class_init(XfbibFileIoClass *klass)
+{
+	GObjectClass *object_class = (GObjectClass *)klass;
+	object_class->finalize = xfbib_file_io_finalize;
+}
+ 
+static void
+xfbib_file_io_init(XfbibFileIo *instance)
+{
+	instance->filename = xfbib_strbuf_new();
+}
+ 
+static void
+xfbib_file_io_finalize(GObject *obj)
+{
+	G_OBJECT_CLASS(xfbib_file_io_parent_class)->finalize(obj);
+}
+ 
+XfbibFileIo *
+xfbib_file_io_new()
+{
+	XfbibFileIo *file_io;
+	file_io = g_object_new(XFBIB_TYPE_FILE_IO, NULL);
+	return file_io;
+}
+
+gboolean
+xfbib_file_io_open(XfbibFileIo *file_io, XfbibWindow *window)
+{
+	GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open BibTeX file"),
+                                                    GTK_WINDOW(window),
+                                                    GTK_FILE_CHOOSER_ACTION_OPEN,
+                                                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                                    GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+                                                    NULL);
+
+	if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
+	{
+		/* TODO: Check if the file is accessible or not */
+		xfbib_strbuf_wipe(file_io->filename);
+		xfbib_strbuf_append(file_io->filename, gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
+		
+		const gchar *file;
+		file = fopen(xfbib_strbuf_get_str(file_io->filename), "r");
+
+		XfbibElements *elements;
+		xfbib_elements_parse(elements, file);
+
+		/* Add all the entries to the tree view*/
+
+		fclose(file);
+	}
+	gtk_widget_destroy(dialog);
+	
+	return TRUE;
+}

Added: xfbib/branches/gobject/src/xfbib-file-io.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.h	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-file-io.h	2008-09-20 20:50:34 UTC (rev 5427)
@@ -0,0 +1,45 @@
+/* 
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFBIB_FILE_IO_H
+#define __XFBIB_FILE_IO_H
+
+#include <glib-object.h>
+#include "xfbib-window.h"
+
+#define XFBIB_TYPE_FILE_IO             (xfbib_file_io_get_type())
+#define XFBIB_FILE_IO(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_FILE_IO, XfbibFileIo))
+#define XFBIB_IS_FILE_IO(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFBIB_TYPE_FILE_IO))
+#define XFBIB_FILE_IO_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), XFBIB_TYPE_FILE_IO, XfbibFileIoClass))
+#define XFBIB_IS_FILE_IO_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), XFBIB_TYPE_FILE_IO))
+#define XFBIB_FILE_IO_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), XFBIB_TYPE_FILE_IO, XfbibFileIoClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfbibFileIo         XfbibFileIo;
+
+GType xfbib_file_io_get_type() G_GNUC_CONST;
+
+XfbibFileIo *xfbib_file_io_new();
+gboolean xfbib_file_io_open(XfbibFileIo *, XfbibWindow *);
+
+G_END_DECLS
+
+#endif //__XFBIB_FILE_IO_H
+

Modified: xfbib/branches/gobject/src/xfbib-list-store.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-list-store.c	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/xfbib-list-store.c	2008-09-20 20:50:34 UTC (rev 5427)
@@ -343,8 +343,6 @@
 	return FALSE;
 }
 
-
-
 XfbibListStore *
 xfbib_list_store_new(XfbibElements *elements)
 {

Modified: xfbib/branches/gobject/src/xfbib-menu-bar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-menu-bar.c	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/xfbib-menu-bar.c	2008-09-20 20:50:34 UTC (rev 5427)
@@ -23,10 +23,13 @@
 
 #include <gtk/gtk.h>
 #include <libxfcegui4/libxfcegui4.h>
+#include <stdio.h>
 
 #include "xfbib-entry-edit-dialog.h"
 #include "xfbib-menu-bar.h"
 #include "xfbib-field.h"
+#include "xfbib-elements.h"
+#include "xfbib-file-io.h"
 
 struct _XfbibMenuBar
 {
@@ -64,6 +67,17 @@
 cb_file_open_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
 	g_printf("File/Open\n");
+
+	XfbibFileIo *file_io;
+	file_io = xfbib_file_io_new();
+	
+	if (xfbib_file_io_open(file_io, window))
+	{
+		//TODO: What happens to the previous FileIo object?
+		//TODO: Should these two lines be located here or in xfbib-file-io.c ?
+		xfbib_window_set_file_io(window, file_io);
+		//xfbib_window_set_title(window, filename;
+	}
 }
 
 static void
@@ -198,8 +212,8 @@
 	/* Open */
 	item = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN, accel);
 	gtk_menu_shell_append(GTK_MENU_SHELL(instance->file), item);
-	g_signal_connect_swapped (G_OBJECT (item), "activate",
-			G_CALLBACK (cb_file_open_activate), "open");
+	g_signal_connect (G_OBJECT (item), "activate",
+			G_CALLBACK (cb_file_open_activate), NULL);
 	
 	/* Save */
 	item = gtk_image_menu_item_new_from_stock(GTK_STOCK_SAVE, accel);

Modified: xfbib/branches/gobject/src/xfbib-toolbar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-toolbar.c	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/xfbib-toolbar.c	2008-09-20 20:50:34 UTC (rev 5427)
@@ -23,6 +23,8 @@
 #include <gtk/gtk.h>
 
 #include "xfbib-toolbar.h"
+#include "xfbib-file-io.h"
+#include "xfbib-window.h"
 
 struct _XfbibToolbar
 {
@@ -31,6 +33,8 @@
 	GtkToolItem *save;
 };
 
+static XfbibWindow *window;
+
 typedef struct _XfbibToolbarClass
 {
 	GtkToolbarClass parent;
@@ -43,6 +47,23 @@
 
 static GObjectClass *xfbib_toolbar_parent_class = NULL;
 
+static void
+cb_open_clicked (GtkButton *buttonitem, gpointer user_data)
+{
+	g_printf("Toolbar_Open\n");
+
+	XfbibFileIo *file_io;
+	file_io = xfbib_file_io_new();
+	
+	if (xfbib_file_io_open(file_io, window))
+	{
+		//TODO: What happens to the previous FileIo object?
+		//TODO: Should these two lines be located here or in xfbib-file-io.c ?
+		xfbib_window_set_file_io(window, file_io);
+		//xfbib_window_set_title(window, filename;
+	}
+}
+
 GType
 xfbib_toolbar_get_type (void)
 {
@@ -82,6 +103,7 @@
 
 	instance->open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
 	gtk_toolbar_insert (GTK_TOOLBAR (instance), instance->open, -1);
+	g_signal_connect (G_OBJECT (instance->open), "clicked", G_CALLBACK (cb_open_clicked), NULL);
 
 	instance->save = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
 	gtk_toolbar_insert (GTK_TOOLBAR (instance), instance->save, -1);
@@ -94,11 +116,11 @@
 }
 
 GtkWidget *
-xfbib_toolbar_new()
+xfbib_toolbar_new(XfbibWindow *w)
 {
 	XfbibToolbar *toolbar;
 	toolbar = g_object_new(XFBIB_TYPE_TOOLBAR, NULL);
-	
+	window = w;
 	return GTK_WIDGET(toolbar);
 }
 

Modified: xfbib/branches/gobject/src/xfbib-toolbar.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-toolbar.h	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/xfbib-toolbar.h	2008-09-20 20:50:34 UTC (rev 5427)
@@ -21,6 +21,7 @@
 #define __XFBIB_TOOLBAR_H
 
 #include <gtk/gtk.h>
+#include "xfbib-window.h"
 
 #define XFBIB_TYPE_TOOLBAR             (xfbib_toolbar_get_type())
 #define XFBIB_TOOLBAR(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_TOOLBAR, XfbibToolbar))
@@ -35,7 +36,7 @@
 
 GType xfbib_toolbar_get_type() G_GNUC_CONST;
 
-GtkWidget *xfbib_toolbar_new();
+GtkWidget *xfbib_toolbar_new(XfbibWindow *);
 
 G_END_DECLS
 

Modified: xfbib/branches/gobject/src/xfbib-window.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-window.c	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/xfbib-window.c	2008-09-20 20:50:34 UTC (rev 5427)
@@ -27,6 +27,8 @@
 #include "xfbib-toolbar.h"
 #include "xfbib-tree-view.h"
 #include "xfbib-statusbar.h"
+#include "xfbib-strbuf.h"
+#include "xfbib-file-io.h"
 
 struct _XfbibWindow
 {
@@ -36,6 +38,7 @@
 	GtkWidget *toolbar;
 	GtkWidget *tree_view;
 	GtkWidget *status_bar;
+	GtkWidget *file_io;
 	XfbibElements *elements;
 };
 	
@@ -94,7 +97,7 @@
 	instance->menu_bar = xfbib_menu_bar_new(instance);
 	gtk_box_pack_start(GTK_BOX(instance->vbox), instance->menu_bar, FALSE, FALSE, 0);
 
-	instance->toolbar = xfbib_toolbar_new();
+	instance->toolbar = xfbib_toolbar_new(instance);
 	gtk_box_pack_start(GTK_BOX(instance->vbox), instance->toolbar, FALSE, FALSE, 0);
 	
 	instance->tree_view = xfbib_tree_view_new(instance->elements);
@@ -103,6 +106,8 @@
 	instance->status_bar = xfbib_statusbar_new();
 	gtk_box_pack_end(GTK_BOX(instance->vbox), instance->status_bar, FALSE, FALSE, 0);
 
+	instance->file_io = NULL;
+
 	gtk_window_set_icon_name(GTK_WINDOW(instance), "xfbib");
 }
 
@@ -120,7 +125,15 @@
 	return GTK_WIDGET(window);
 }
 
-Xfbib_window_get_elements(XfbibWindow *window)
+void
+xfbib_window_set_title(XfbibWindow *window, XfbibStrbuf *title)
 {
-	return window->elements;
+	gtk_window_set_title(GTK_WINDOW(window), xfbib_strbuf_get_str(title));
 }
+
+void
+xfbib_window_set_file_io(XfbibWindow *window, XfbibFileIo *file_io)
+{
+	window->file_io = file_io;
+}
+

Modified: xfbib/branches/gobject/src/xfbib-window.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-window.h	2008-09-20 12:54:10 UTC (rev 5426)
+++ xfbib/branches/gobject/src/xfbib-window.h	2008-09-20 20:50:34 UTC (rev 5427)
@@ -21,6 +21,7 @@
 #define __XFBIB_WINDOW_H
 
 #include <gtk/gtk.h>
+#include "xfbib-strbuf.h"
 
 #define XFBIB_TYPE_WINDOW             (xfbib_window_get_type())
 #define XFBIB_WINDOW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_WINDOW, XfbibWindow))
@@ -36,6 +37,7 @@
 GType xfbib_window_get_type() G_GNUC_CONST;
 
 GtkWidget *xfbib_window_new();
+void xfbib_window_set_title(XfbibWindow *, XfbibStrbuf *);
 
 G_END_DECLS
 




More information about the Goodies-commits mailing list