Commit 1947c6d4 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Now we take a Workbook argument to bind the dialog boxes properly to the


1999-02-06  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/gnumeric-util.c (gnumeric_notice): Now we take a Workbook
	argument to bind the dialog boxes properly to the main window.  We
	use gnome_messagebox now to report errors.  We now take a type
	parameter for the message box type.

	* plugins/ff-csv/csv-io.c: Use gnumeric_error

	* src/workbook.c (wb_input_finished): Call sheet_set_current_value
	instead of the cancel pending input routine.

	* Moved src/csv-io.[ch] to the plugins/ff-csv directory and
	converted them to
parent 1ef4f731
1999-02-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-util.c (gnumeric_notice): Now we take a Workbook
argument to bind the dialog boxes properly to the main window. We
use gnome_messagebox now to report errors. We now take a type
parameter for the message box type.
* plugins/ff-csv/csv-io.c: Use gnumeric_error
* src/workbook.c (wb_input_finished): Call sheet_set_current_value
instead of the cancel pending input routine.
* Moved src/csv-io.[ch] to the plugins/ff-csv directory and
converted them to
1999-02-06 Vincent Renardias <vincent@ldsol.com>
* src/csv-io.h src/csv-io.c: Added code to load
......
1999-02-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-util.c (gnumeric_notice): Now we take a Workbook
argument to bind the dialog boxes properly to the main window. We
use gnome_messagebox now to report errors. We now take a type
parameter for the message box type.
* plugins/ff-csv/csv-io.c: Use gnumeric_error
* src/workbook.c (wb_input_finished): Call sheet_set_current_value
instead of the cancel pending input routine.
* Moved src/csv-io.[ch] to the plugins/ff-csv directory and
converted them to
1999-02-06 Vincent Renardias <vincent@ldsol.com>
* src/csv-io.h src/csv-io.c: Added code to load
......
1999-02-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-util.c (gnumeric_notice): Now we take a Workbook
argument to bind the dialog boxes properly to the main window. We
use gnome_messagebox now to report errors. We now take a type
parameter for the message box type.
* plugins/ff-csv/csv-io.c: Use gnumeric_error
* src/workbook.c (wb_input_finished): Call sheet_set_current_value
instead of the cancel pending input routine.
* Moved src/csv-io.[ch] to the plugins/ff-csv directory and
converted them to
1999-02-06 Vincent Renardias <vincent@ldsol.com>
* src/csv-io.h src/csv-io.c: Added code to load
......
1999-02-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-util.c (gnumeric_notice): Now we take a Workbook
argument to bind the dialog boxes properly to the main window. We
use gnome_messagebox now to report errors. We now take a type
parameter for the message box type.
* plugins/ff-csv/csv-io.c: Use gnumeric_error
* src/workbook.c (wb_input_finished): Call sheet_set_current_value
instead of the cancel pending input routine.
* Moved src/csv-io.[ch] to the plugins/ff-csv directory and
converted them to
1999-02-06 Vincent Renardias <vincent@ldsol.com>
* src/csv-io.h src/csv-io.c: Added code to load
......
......@@ -123,6 +123,7 @@ plugins/perl/Makefile
plugins/perl/ext/Makefile.PL
plugins/stat/Makefile
plugins/guile/Makefile
plugins/ff-csv/Makefile
intl/Makefile
po/Makefile.in
macros/Makefile
......
......@@ -17,4 +17,4 @@ else
GUILE_DIR =
endif
SUBDIRS = sample stat excel $(PYTHON) $(PERL) $(GUILE_DIR)
SUBDIRS = sample stat excel ff-csv $(PYTHON) $(PERL) $(GUILE_DIR)
#
# Sample Makefile for a Gnumeric plugin.
#
# Where can we find the Gnumeric include files.
#
GNUMERIC_SRC_DIR = $(top_srcdir)/src
#
# Where to install the plugin
#
plugindir = $(libdir)/gnumeric/plugins
CFLAGS += -g -Wall \
-Wshadow -Wpointer-arith \
-Wmissing-prototypes -Wmissing-declarations
plugin_LTLIBRARIES = libcsv.la
libcsv_la_SOURCES = csv-io.h csv-io.c
INCLUDES = \
-I$(GNUMERIC_SRC_DIR) \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-I$(includedir) \
$(GNOME_INCLUDEDIR)
......@@ -21,117 +21,136 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "gnumeric.h"
#include "sheet-object.h"
#include <errno.h>
#include "../../src/gnumeric.h"
#include "../../src/gnumeric-util.h"
#include "../../src/plugin.h"
#include "csv-io.h"
#include "file.h"
static char insert_csv_cell(Sheet* sheet, char *string, int start, int end, int col, int row)
static char
insert_csv_cell (Sheet* sheet, char *string, int start, int end, int col, int row)
{
char *p;
int i;
int ii=0;
int ii = 0;
Cell *cell;
if(sheet == NULL)
return 0;
if (start>1 && end >1){
p=(char*) malloc(end-start +1);
g_assert(p>0);
for(i=start;i<=end;i++){
p[ii++]=string[i];
if (start > 1 && end > 1){
p = g_malloc (end - start + 1);
g_assert (p > 0);
for (i = start; i <= end; i++){
p [ii++] = string [i];
}
p[ii]='\0';
p [ii] = '\0';
} else {
p=(char*) malloc(2);
p[0]=string[0];
p[1]='\0';
p = (char*) g_malloc (2);
p [0] = string [0];
p [1] = '\0';
}
/*fprintf(stderr,"'%s' at col:%d, row:%d.\n", p, col, row);*/
if ((cell = sheet_cell_get(sheet,row,col)) == NULL){
if ((cell = sheet_cell_new(sheet,row,col)) == 0){
if ((cell = sheet_cell_get (sheet, row, col)) == NULL){
if ((cell = sheet_cell_new (sheet, row, col)) == 0){
return 0;
}
}
cell_set_text_simple(cell, p);
free(p);
cell_set_text_simple (cell, p);
free (p);
return 0;
}
static int
csvParseFile (const char *filename,Sheet *sheet)
csv_parse_file (const char *filename,Sheet *sheet)
{
int fd;
struct stat buf;
int flen; /* file length */
char *file; /* data pointer */
int i,index=0,lindex=-1;
int i, idx, lindex;
int crow=0,ccol=0,mrow=0,mcol=0; /* current/max col/row */
int data=0;
int non_printable=0;
if ( (fd=open(filename, O_RDONLY)) < 0 ){
perror(filename);
idx = 0;
lindex = -1;
if ((fd = open (filename, O_RDONLY)) < 0){
char *msg;
int err = errno;
msg = g_strdup_printf (_("While opening %s\n%s"),
filename, g_strerror (err));
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR, msg);
g_free (msg);
return 0;
}
if (fstat (fd, &buf) == -1){
perror("stat failed");
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
"Can not stat the file");
close(fd);
return 0;
}
if (buf.st_size < 1 || buf.st_size > 1000000){ /* FIXME: ARBITRARY VALUE */
/* FIXME: ARBITRARY VALUE */
if (buf.st_size < 1 || buf.st_size > 1000000){
close(fd);
return 0;
} else {
flen = buf.st_size;
}
if ((file=mmap(NULL, flen, PROT_READ, MAP_PRIVATE, fd, 0))==(char*)-1){
perror("mmap failed");
close(fd);
if ((file = mmap (NULL, flen, PROT_READ, MAP_PRIVATE, fd, 0)) == (char*)-1){
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR, "Can not mmap the file");
close (fd);
return 0;
}
while(index <= flen){
switch(file[index]){
while (idx <= flen){
switch (file [idx]){
case '\r':
if (file[index+1] == '\n')
index++;
if (file [idx+1] == '\n')
idx++;
break;
case '\n':
if(data){ /* Non empty line */
insert_csv_cell(sheet,file,lindex,index-1,crow,ccol);
if (data){ /* Non empty line */
insert_csv_cell (sheet, file, lindex, idx-1, crow, ccol);
}
data=0;
lindex=index+1;
ccol=0;
data = 0;
lindex = idx+1;
ccol = 0;
crow++;
index++;
idx++;
break;
case ',':
if(data){ /* Non empty cell */
insert_csv_cell(sheet,file,lindex,index-1,crow,ccol);
insert_csv_cell (sheet, file, lindex, idx-1, crow, ccol);
}
data=0;
lindex=index+1;
data = 0;
lindex = idx+1;
ccol++;
index++;
idx++;
break;
default:
if (file[index] < 21 || file[index] > 126){
if (file [idx] < 21 || file [idx] > 126){
non_printable++;
if (non_printable > 10){ /* FIXME: ARBITRARY VALUE */
close(fd);
close (fd);
return 0;
}
}
index++;
data=1;
idx++;
data = 1;
break;
}
}
......@@ -140,27 +159,29 @@ csvParseFile (const char *filename,Sheet *sheet)
sheet->max_col_used=ccol;
sheet->max_row_used=crow;
}
munmap(file, flen);
close(fd);
munmap (file, flen);
close (fd);
return 1;
}
Workbook * gnumericReadCSVWorkbook (const char* filename)
Workbook *
csv_read_workbook (const char* filename)
{
Workbook *book;
Sheet *sheet;
int *mcol;
int *mrow;
book=workbook_new(); /* FIXME: Can this return NULL? */
book = workbook_new (); /* FIXME: Can this return NULL? */
sheet = sheet_new (book, _("NoName"));
workbook_attach_sheet(book,sheet);
workbook_attach_sheet (book, sheet);
/*if (sheet != NULL){
book->sheet = sheet;
}*/
if((csvParseFile(filename,sheet)) == 0){
if ((csv_parse_file (filename, sheet)) == 0){
return NULL;
}
......@@ -171,7 +192,7 @@ Workbook * gnumericReadCSVWorkbook (const char* filename)
static gboolean
csv_probe (const char *filename)
{
if(csvParseFile(filename,0) == 1){
if(csv_parse_file (filename,0) == 1){
return TRUE;
} else {
return FALSE;
......@@ -183,7 +204,30 @@ csv_init (void)
{
char *desc = _("CSV (comma separated values)");
file_format_register_open (101, desc, csv_probe, gnumericReadCSVWorkbook);
file_format_register_open (101, desc, csv_probe, csv_read_workbook);
/* file_format_register_save (".csv", desc, gnumericWriteCSVWorkbook);*/
}
static int
csv_cleanup_plugin (PluginData *pd)
{
file_format_unregister_save (csv_read_workbook);
}
static int
csv_can_unload (PluginData *pd)
{
return TRUE;
}
int
init_plugin (PluginData *pd)
{
csv_init ();
pd->can_unload = csv_can_unload;
pd->cleanup_plugin = csv_cleanup_plugin;
pd->title = g_strdup (_("CSV (comma separated value file import/export plugin"));
return 0;
}
......@@ -48,7 +48,8 @@ cleanup_plugin (PluginData *pd)
}
}
int init_plugin (PluginData * pd)
int
init_plugin (PluginData *pd)
{
install_symbols (plugin_functions);
pd->can_unload = can_unload;
......
......@@ -102,9 +102,7 @@ GNUMERIC_BASE_SOURCES = \
widget-editable-label.h \
workbook.c \
xml-io.c \
xml-io.h \
csv-io.c \
csv-io.h
xml-io.h
GNUMERIC_CORBA_GENERATED = \
Gnumeric-common.c \
......
......@@ -80,12 +80,14 @@ dialog_zoom (Workbook *wb, Sheet *sheet)
g_free (custom);
if (zoom < 0.25){
gnumeric_notice (_("Zoom factor should be at least 50%"));
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Zoom factor should be at least 50%"));
return;
}
if (zoom > 9000){
gnumeric_notice (_("Zoom factor should be at most 900%"));
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Zoom factor should be at most 900%"));
return;
}
......
......@@ -80,12 +80,14 @@ dialog_zoom (Workbook *wb, Sheet *sheet)
g_free (custom);
if (zoom < 0.25){
gnumeric_notice (_("Zoom factor should be at least 50%"));
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Zoom factor should be at least 50%"));
return;
}
if (zoom > 9000){
gnumeric_notice (_("Zoom factor should be at most 900%"));
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Zoom factor should be at most 900%"));
return;
}
......
......@@ -13,17 +13,17 @@
#include "style.h"
void
gnumeric_notice (char *str)
gnumeric_notice (Workbook *wb, char *type, char *str)
{
GtkWidget *dialog;
GtkWidget *label;
label = gtk_label_new (str);
dialog = gnome_dialog_new (_("Notice"), GNOME_STOCK_BUTTON_OK, NULL);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
dialog = gnome_message_box_new (str, type, GNOME_STOCK_BUTTON_OK, NULL);
if (wb)
gnome_dialog_set_parent (GNOME_DIALOG (dialog),
GTK_WINDOW (wb->toplevel));
gnome_dialog_run (GNOME_DIALOG (dialog));
gtk_object_destroy (GTK_OBJECT (dialog));
}
int
......
#ifndef GNUMERIC_GNUMERIC_UTIL_H
#define GNUMERIC_GNUMERIC_UTIL_H
void gnumeric_notice (char *str);
void gnumeric_notice (Workbook *wb, char *type, char *str);
/* A simple routine for making a popup menu */
int run_popup_menu (GdkEvent *event, int button, char **strings);
......
......@@ -13,17 +13,17 @@
#include "style.h"
void
gnumeric_notice (char *str)
gnumeric_notice (Workbook *wb, char *type, char *str)
{
GtkWidget *dialog;
GtkWidget *label;
label = gtk_label_new (str);
dialog = gnome_dialog_new (_("Notice"), GNOME_STOCK_BUTTON_OK, NULL);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
dialog = gnome_message_box_new (str, type, GNOME_STOCK_BUTTON_OK, NULL);
if (wb)
gnome_dialog_set_parent (GNOME_DIALOG (dialog),
GTK_WINDOW (wb->toplevel));
gnome_dialog_run (GNOME_DIALOG (dialog));
gtk_object_destroy (GTK_OBJECT (dialog));
}
int
......
#ifndef GNUMERIC_GNUMERIC_UTIL_H
#define GNUMERIC_GNUMERIC_UTIL_H
void gnumeric_notice (char *str);
void gnumeric_notice (Workbook *wb, char *type, char *str);
/* A simple routine for making a popup menu */
int run_popup_menu (GdkEvent *event, int button, char **strings);
......
/*
* Gnumeric, the GNOME spreadsheet.
*
* Main file, startup code.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "xml-io.h"
#include "csv-io.h"
#include "plugin.h"
#include "format.h"
#include "cursors.h"
......@@ -56,7 +63,6 @@ gnumeric_main (void *closure, int argc, char *argv [])
/* The statically linked in file formats */
xml_init ();
excel_init ();
csv_init ();
if (dump_file_name){
dump_functions (dump_file_name);
......
/*
* Gnumeric, the GNOME spreadsheet.
*
* Main file, startup code.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "xml-io.h"
#include "csv-io.h"
#include "plugin.h"
#include "format.h"
#include "cursors.h"
......@@ -56,7 +63,6 @@ gnumeric_main (void *closure, int argc, char *argv [])
/* The statically linked in file formats */
xml_init ();
excel_init ();
csv_init ();
if (dump_file_name){
dump_functions (dump_file_name);
......
......@@ -62,7 +62,7 @@ add_cb (GtkWidget *button, PluginManager *pm)
if (!modfile)
return;
pd = plugin_load (modfile);
pd = plugin_load (pm->workbook, modfile);
populate_clist (pm);
}
......@@ -73,7 +73,7 @@ remove_cb (GtkWidget *button, PluginManager *pm)
gint row = GPOINTER_TO_INT (g_list_nth_data (selection, 0));
PluginData *pd = gtk_clist_get_row_data (GTK_CLIST (pm->clist), row);
plugin_unload (pd);
plugin_unload (pm->workbook, pd);
populate_clist (pm);
}
......
......@@ -18,7 +18,7 @@
GList *plugin_list = NULL;
PluginData *
plugin_load (gchar *modfile)
plugin_load (Workbook *wb, gchar *modfile)
{
PluginData *data;
......@@ -34,19 +34,21 @@ plugin_load (gchar *modfile)
if (!data->handle) {
char *str;
str = g_strconcat(_("unable to open module file: "), g_module_error(), NULL);
gnumeric_notice(str);
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR, str);
g_free(str);
g_free(data);
return NULL;
}
if (!g_module_symbol (data->handle, "init_plugin", (gpointer *) &data->init_plugin)){
gnumeric_notice (_("Plugin must contain init_plugin function."));
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Plugin must contain init_plugin function."));
goto error;
}
if (data->init_plugin (data) < 0){
gnumeric_notice (_("init_plugin returned error"));
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
_("init_plugin returned error"));
goto error;
}
......@@ -60,12 +62,13 @@ plugin_load (gchar *modfile)
}
void
plugin_unload (PluginData *pd)
plugin_unload (Workbook *wb, PluginData *pd)
{
g_return_if_fail (pd != NULL);
if (pd->can_unload && !pd->can_unload(pd)) {
gnumeric_notice(_("Plugin is still in use.\n"));
gnumeric_notice (wb, GNOME_MESSAGE_BOX_INFO,
_("Plugin is still in use.\n"));
return;
}
......@@ -92,7 +95,7 @@ plugin_load_plugins_in_dir (char *directory)
char *plugin_name;
plugin_name = g_strconcat (directory, e->d_name, NULL);
plugin_load (plugin_name);
plugin_load (NULL, plugin_name);
g_free (plugin_name);
}
}
......
......@@ -20,8 +20,8 @@ typedef struct PluginData PluginData;
extern GList *plugin_list;
void plugins_init (void);
PluginData *plugin_load (gchar *filename);
void plugin_unload (PluginData *pd);
PluginData *plugin_load (Workbook *wb, gchar *filename);
void plugin_unload (Workbook *wb, PluginData *pd);
GtkWidget *plugin_manager_new (Workbook *wb);
#endif /* GNUMERIC_PLUGIN_H */
......@@ -2367,7 +2367,7 @@ sheet_verify_selection_simple (Sheet *sheet, char *command_name)
msg = g_strconcat (
"The command `", command_name,
"' can not be performed with multiple selections", NULL);
gnumeric_notice (msg);
gnumeric_notice (sheet->workbook, GNOME_MESSAGE_BOX_ERROR, msg);
g_free (msg);