Commit 00ae6fb4 authored by Morten Welinder's avatar Morten Welinder

Introspection: add basic io

parent 574643c2
2018-04-13 Morten Welinder <terra@gnome.org>
* src/workbook-view.c (workboook_view_save_to_uri): Renamed from
wb_view_save_to_uri for introspection.
(workbook_view_save_to_output): Renamed from
wb_view_save_to_output for introspection.
* src/style-color.c (gnm_style_color_get_type): Duplicate of
gnm_color_get_type, more or less.
......
......@@ -95,7 +95,8 @@ go_gnm_component_get_data (GOComponent *component, gpointer *data, int *length,
GOFileSaver *gfs = workbook_get_file_saver (gognm->wb);
if (gfs == NULL)
gfs = go_file_saver_get_default ();
wbv_save_to_output (gognm->wv, gfs, output, io_context);
workbook_view_save_to_output (gognm->wv, gfs, output,
io_context);
*data = (gpointer) gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (output));
*length = gsf_output_size (output);
*clearfunc = g_object_unref;
......
......@@ -1729,7 +1729,7 @@ sheet_apply_style (Sheet *sheet,
* sheet_apply_style_gi: (rename-to sheet_apply_style)
* @sheet: the sheet in which can be found
* @range: the range to which should be applied
* @mstyle: A #GnmStyle partial style
* @style: A #GnmStyle partial style
*
* A mid level routine that applies the supplied partial style @style to the
* target @range and performs the necessary respanning and redrawing.
......
......@@ -340,7 +340,7 @@ GOUndo * sheet_range_set_expr_undo (GnmSheetRange *sr,
GnmExprTop const *texpr);
GOUndo * sheet_range_set_markup_undo (GnmSheetRange *sr,
PangoAttrList *markup);
void sheet_apply_style (Sheet *sheet, GnmRange const *range, GnmStyle *mstyle);
void sheet_apply_style (Sheet *sheet, GnmRange const *range, GnmStyle *style);
GOUndo * sheet_apply_style_undo (GnmSheetRange *sr,
GnmStyle *style);
void sheet_apply_border (Sheet *sheet, GnmRange const *range, GnmBorder **borders);
......
......@@ -792,8 +792,9 @@ static void
highlight_diff_end (gpointer user)
{
DiffState *state = user;
wbv_save_to_output (state->highlight.wbv, state->highlight_fs,
state->output, state->ioc);
workbook_view_save_to_output (state->highlight.wbv,
state->highlight_fs,
state->output, state->ioc);
}
static void
......
......@@ -1313,7 +1313,7 @@ gnm_solver_saveas (GnmSolver *solver, WorkbookControl *wbc,
output = gsf_output_stdio_new_FILE (*filename, file, TRUE);
io_context = go_io_context_new (GO_CMD_CONTEXT (wbc));
wbv_save_to_output (wbv, fs, output, io_context);
workbook_view_save_to_output (wbv, fs, output, io_context);
ok = !go_io_error_occurred (io_context);
g_object_unref (io_context);
g_object_unref (output);
......
......@@ -363,7 +363,7 @@ gnm_validation_equal (GnmValidation const *a, GnmValidation const *b,
GnmValidation *
gnm_validation_ref (GnmValidation const *v)
{
g_return_if_fail (v != NULL);
g_return_val_if_fail (v != NULL, NULL);
((GnmValidation *)v)->ref_count++;
return ((GnmValidation *)v);
}
......
......@@ -142,7 +142,7 @@ static GNM_ACTION_DEF (cb_file_sendto) {
g_free (basename);
uri = go_filename_to_uri (full_name);
wb_view_save_to_uri (wbv, fs, uri, io_context);
workbook_view_save_to_uri (wbv, fs, uri, io_context);
if (go_io_error_occurred (io_context) ||
go_io_warning_occurred (io_context))
......
......@@ -1082,7 +1082,7 @@ workbook_view_new (Workbook *wb)
}
/**
* wbv_save_to_output:
* workbook_view_save_to_output:
* @wbv: #WorkbookView
* @fs: #GOFileSaver
* @output: #GsfOutput
......@@ -1091,8 +1091,8 @@ workbook_view_new (Workbook *wb)
* NOTE : Temporary api until we get the new output framework.
**/
void
wbv_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
GsfOutput *output, GOIOContext *io_context)
workbook_view_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
GsfOutput *output, GOIOContext *io_context)
{
GError const *err;
char const *msg;
......@@ -1116,9 +1116,17 @@ wbv_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), msg);
}
/**
* workbook_view_save_to_uri:
* @wbv: #WorkbookView
* @fs: #GOFileSaver
* @uri: destination URI
* @io_context: #GOIOContext
*
**/
void
wb_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
char const *uri, GOIOContext *io_context)
workbook_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
char const *uri, GOIOContext *io_context)
{
char *msg = NULL;
GError *err = NULL;
......@@ -1135,7 +1143,7 @@ wb_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), msg);
g_free (msg);
} else {
wbv_save_to_output (wbv, fs, output, io_context);
workbook_view_save_to_output (wbv, fs, output, io_context);
g_object_unref (output);
}
}
......@@ -1196,7 +1204,7 @@ wb_view_save_as (WorkbookView *wbv, GOFileSaver *fs, char const *uri,
io_context = go_io_context_new (cc);
go_cmd_context_set_sensitive (cc, FALSE);
wb_view_save_to_uri (wbv, fs, uri, io_context);
workbook_view_save_to_uri (wbv, fs, uri, io_context);
go_cmd_context_set_sensitive (cc, TRUE);
has_error = go_io_error_occurred (io_context);
......@@ -1265,7 +1273,7 @@ wb_view_save (WorkbookView *wbv, GOCmdContext *context)
_("Default file saver is not available."));
else {
char const *uri = go_doc_get_uri (GO_DOC (wb));
wb_view_save_to_uri (wbv, fs, uri, io_context);
workbook_view_save_to_uri (wbv, fs, uri, io_context);
}
has_error = go_io_error_occurred (io_context);
......@@ -1406,7 +1414,7 @@ workbook_view_new_from_input (GsfInput *input,
* workbook_view_new_from_uri:
* @uri: URI for file
* @file_opener: (allow-none): #GOFileOpener
* @io_context: (allow-none): Context to display errors.
* @io_context: Context to display errors.
* @encoding: (allow-none): Encoding for @file_opener that understands it
*
* Reads @uri file using given file opener @file_opener, or probes for a valid
......
......@@ -90,10 +90,12 @@ void wb_view_auto_expr_recalc (WorkbookView *wbv);
gboolean wb_view_save_as (WorkbookView *wbv, GOFileSaver *fs,
char const *uri, GOCmdContext *cc);
gboolean wb_view_save (WorkbookView *wbv, GOCmdContext *cc);
void wbv_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
GsfOutput *output, GOIOContext *io_context);
void wb_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
char const *uri, GOIOContext *io_context);
void workbook_view_save_to_output (WorkbookView *wbv,
GOFileSaver const *fs,
GsfOutput *output,
GOIOContext *io_context);
void workbook_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
char const *uri, GOIOContext *io_context);
WorkbookView *workbook_view_new_from_input (GsfInput *input,
const char *uri,
......
......@@ -272,6 +272,7 @@ sub corpus {
sub test_command {
my ($cmd,$test) = @_;
print STDERR "# $cmd\n" if $verbose;
my $output = `$cmd 2>&1`;
my $err = $?;
die "Failed command: $cmd\n" if $err;
......
......@@ -181,7 +181,8 @@ SUPPS = common.supp gui.supp t8003-valgrind-pdf.supp
INTROSPECTION_TSTS = \
t3000-introspection-basic.pl \
t3001-introspection-simple.pl
t3001-introspection-simple.pl \
t3002-introspection-io.pl
INTROSPECTION_SUPPS = \
$(INTROSPECTION_TSTS:.pl=.py)
......
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------
use strict;
use lib ($0 =~ m|^(.*/)| ? $1 : ".");
use GnumericTest;
&setup_python_environment ();
my $python_script = $0;
$python_script =~ s/\.pl$/.py/;
for my $file ('format-tests.gnumeric') {
my $src = "$samples/$file";
my $dst = $file;
$dst =~ s{\.([^./]+)$}{-copy.$1};
unlink $dst;
&GnumericTest::junkfile ($dst);
&test_command ($PYTHON . ' ' .
&GnumericTest::quotearg ($python_script, $src, $dst),
sub { 1 });
&test_command (&GnumericTest::quotearg ($ssdiff, '--xml', $src, $dst),
sub { 1 });
&GnumericTest::removejunk ($dst);
}
#!/usr/bin/python
# -----------------------------------------------------------------------------
import gi
gi.require_version('Gnm', '1.12')
gi.require_version('GOffice', '0.10')
from gi.repository import Gnm
from gi.repository import GOffice
Gnm.init()
import sys
src_uri = GOffice.filename_to_uri (sys.argv[1])
print(src_uri)
dst_uri = GOffice.filename_to_uri (sys.argv[2])
print(dst_uri)
ioc = GOffice.IOContext.new (Gnm.CmdContextStderr.new ())
wbv = Gnm.WorkbookView.new_from_uri (src_uri, None, ioc, None)
fs = GOffice.FileSaver.for_file_name (dst_uri)
wbv.save_to_uri (fs, dst_uri, ioc)
ioc = None
wbv = None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment