/**
 * Constructor
 */
ODe_Style_MasterPage::ODe_Style_MasterPage (const gchar* pName,
                                            const gchar* pPageLayoutName) {

    m_name = pName;
    m_pageLayoutName = pPageLayoutName;

    m_pFooterContentTemp = gsf_output_memory_new ();
    m_pFooterEvenContentTemp = gsf_output_memory_new ();
    m_pHeaderContentTemp = gsf_output_memory_new ();
    m_pHeaderEvenContentTemp = gsf_output_memory_new ();
}
Esempio n. 2
0
static void
gnm_stf_file_saver_save (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *context,
			 GoView const *view, GsfOutput *output)
{
	WorkbookView *wbv = GNM_WORKBOOK_VIEW (view);
	Workbook *wb = wb_view_get_workbook (wbv);
	GnmStfExport *stfe = gnm_stf_get_stfe (G_OBJECT (wb));
	GsfOutput *dummy_sink;

	/* TODO: move this GUI dependent code out of this
	 * filesaver into gui-file.c. After this, remove includes (see above). */
	if (GNM_IS_WBC_GTK (context->impl)) {
		gboolean cancelled =
			stf_export_dialog (WBC_GTK (context->impl), stfe, wb);
		if (cancelled) {
			go_io_error_unknown (context);
			return;
		}
	}

	if (!stfe->sheet_list)
		gnm_stf_export_options_sheet_list_add
			(stfe, wb_view_cur_sheet (wbv));

	g_object_set (G_OBJECT (stfe), "sink", output, NULL);
	if (gnm_stf_export (stfe) == FALSE)
		go_cmd_context_error_import (GO_CMD_CONTEXT (context),
			_("Error while trying to export file as text"));

	/* We're not allowed to set a NULL sink, so use a dummy.  */
	dummy_sink = gsf_output_memory_new ();
	g_object_set (G_OBJECT (stfe), "sink", dummy_sink, NULL);
	g_object_unref (dummy_sink);
}
Esempio n. 3
0
static GsfInput *
make_local_copy (GFile *file, GInputStream *stream)
{
    GsfOutput *out;
    GsfInput  *copy;
    GFileInfo *info;

    out = gsf_output_memory_new ();

    while (1) {
        guint8 buf[4096];
        gssize nread;

        nread = g_input_stream_read (stream, buf, sizeof(buf), NULL, NULL);

        if (nread > 0) {
            if (!gsf_output_write (out, nread, buf)) {
                copy = NULL;
                goto cleanup_and_exit;
            }
        }
        else if (nread == 0)
            break;
        else {
            copy = NULL;
            goto cleanup_and_exit;
        }
    }

    copy = gsf_input_memory_new_clone
           (gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
            gsf_output_size (out));

    if (copy != NULL) {
        info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL);
        if (info) {
            gsf_input_set_name (GSF_INPUT (copy), g_file_info_get_name (info));
            g_object_unref (info);
        }
    }

cleanup_and_exit:

    gsf_output_close (out);
    g_object_unref (out);

    g_input_stream_close (stream, NULL, NULL);
    g_object_unref (stream);

    set_name_from_file (copy, file);

    return copy;
}
Esempio n. 4
0
static GsfInput *
make_local_copy (FILE *stream, const char *filename, GError **err)
{
	GsfOutput *out;
	GsfInput *copy = NULL;

	out = gsf_output_memory_new ();

	while (1) {
		guint8 buf[4096];
		gssize nread;

		nread = fread (buf, 1, sizeof(buf), stream);

		if (nread > 0) {
			if (!gsf_output_write (out, nread, buf))
				goto error;
		} else if (nread == 0)
			break;
		else
			goto error;
	}

	copy = gsf_input_memory_new_clone
		(gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
		 gsf_output_size (out));

	gsf_output_close (out);
	g_object_unref (out);

	if (filename)
		gsf_input_set_name_from_filename (GSF_INPUT (copy), filename);

	return copy;

error:
	if (err) {
		char *utf8name = filename
			? g_filename_display_name (filename)
			: g_strdup ("?");
		g_set_error (err, gsf_input_error_id (), 0,
			     "%s: not a regular file",
			     utf8name);
		g_free (utf8name);
	}

	gsf_output_close (out);
	g_object_unref (out);

	return NULL;
}
UT_Error AbiCollabSessionManager::serializeDocument(const PD_Document* pDoc, std::string& document, bool encodeBase64)
{
	UT_return_val_if_fail(pDoc, false);

	// Don't put this auto-save in the most recent list.
	XAP_App::getApp()->getPrefs()->setIgnoreNextRecent();
	
	// maskExport();
	GsfOutputMemory* sink = GSF_OUTPUT_MEMORY(gsf_output_memory_new());
	GsfOutput* gzSink = gsf_output_gzip_new(GSF_OUTPUT(sink), NULL);
	bool bAuthor = pDoc->isExportAuthorAtts();
	const_cast<PD_Document *>(pDoc)->setExportAuthorAtts(true);
	UT_Error result = const_cast<PD_Document*>(pDoc)->saveAs(GSF_OUTPUT(gzSink), IE_Exp::fileTypeForSuffix(".abw"), true);
	const_cast<PD_Document *>(pDoc)->setExportAuthorAtts(bAuthor);
	gsf_output_close(GSF_OUTPUT(gzSink));
	// unmaskExport();
	
	if (result == UT_OK)
	{
		guint32 size = gsf_output_size (GSF_OUTPUT(sink));
		const guint8* zabwBuf = gsf_output_memory_get_bytes (sink);
		
		if (encodeBase64)
		{
			// this would be more efficient if we had a GsfOutputBase64.. ah well, this will do for now
			guint8* base64zabwBuf = gsf_base64_encode_simple(zabwBuf, size);
			document += (char*)base64zabwBuf;
			g_free(base64zabwBuf);
		}
		else
		{
			// just copy raw zipped data into string
			document.resize( size );
			memcpy( &document[0], zabwBuf, size );
		}
	} 
	else
    {
		UT_DEBUGMSG(("Failed to export! Handle this gracefully!\n"));
    }

	g_object_unref(G_OBJECT(gzSink));
	g_object_unref(G_OBJECT(sink));
	return result;
}
/**
 * Do all necessary work before starting to listen the AbiWord document.
 */
bool ODe_DocumentData::doPreListeningWork() {
    bool ok;
    
    ok = m_styles.fetchRegularStyleStyles();
    if (!ok) {
        return false;
    }


    /////
    // Creates a <style:page-layout> from the info that goes on the <pagesize>
    // tag of abw files.
    ODe_Style_PageLayout* pPageLayout;
    
    pPageLayout = new ODe_Style_PageLayout();
    pPageLayout->setName("Standard");
    
    m_stylesAutoStyles.addPageLayout(pPageLayout);

    pPageLayout->fetchAttributesFromAbiDoc(m_pAbiDoc);
    
    
    
    // Create the "Standard" master page style
    ODe_Style_MasterPage* pMPStyle;
    pMPStyle = new ODe_Style_MasterPage("Standard", "Standard");
    m_masterStyles.insert("Standard", pMPStyle);
    
    
    m_pOfficeTextTemp = gsf_output_memory_new();
    if (m_pOfficeTextTemp == NULL) {
        return false;
    }
    
    // If we've reached this point, everything is fine.
    return true;
}
Esempio n. 7
0
/*!
  copy the given subset of the given document to the
  system clipboard in a variety of formats.

  to minimize the effects of race-conditions, we create
  all of the buffers we need and then post them to the
  server (well sorta) all at one time.
  \param pDocRange a range of the document to be copied
*/
void AP_UnixApp::copyToClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard)
{

    UT_ByteBuf bufRTF;
    UT_ByteBuf bufHTML4;
    UT_ByteBuf bufXHTML;
    UT_ByteBuf bufTEXT;
    UT_ByteBuf bufODT;

    // create RTF buffer to put on the clipboard
		
    IE_Exp_RTF * pExpRtf = new IE_Exp_RTF(pDocRange->m_pDoc);
    if (pExpRtf)
    {
		pExpRtf->copyToBuffer(pDocRange,&bufRTF);
		DELETEP(pExpRtf);
    }

	// create XHTML buffer to put on the clipboard

	IE_Exp_HTML * pExpHtml = new IE_Exp_HTML(pDocRange->m_pDoc);
	if (pExpHtml)
		{
			pExpHtml->set_HTML4 (false);
			pExpHtml->copyToBuffer (pDocRange, &bufXHTML);
			DELETEP(pExpHtml);
		}

	// create HTML4 buffer to put on the clipboard
	
	pExpHtml = new IE_Exp_HTML(pDocRange->m_pDoc);
	if (pExpHtml)
		{
			pExpHtml->set_HTML4 (true);
			pExpHtml->copyToBuffer(pDocRange, &bufHTML4);
			DELETEP(pExpHtml);
		}

	// Look to see if the ODT plugin is loaded

	IEFileType ftODT = IE_Exp::fileTypeForMimetype("application/vnd.oasis.opendocument.text");
	bool bExpODT = false;
	if(ftODT != IEFT_Unknown)
	{
		// ODT plugin is present construct an exporter
		//
		IE_Exp * pODT = NULL;
		IEFileType genIEFT = IEFT_Unknown;
		GsfOutput * outBuf =  gsf_output_memory_new();
		UT_Error err = IE_Exp::constructExporter(pDocRange->m_pDoc,outBuf,
												 ftODT,&pODT,& genIEFT);
		if(pODT && (genIEFT == ftODT))
		{
			//												 
			// Copy to the buffer
			//
			err = pODT->copyToBuffer(pDocRange, &bufODT);
			bExpODT = (err == UT_OK);
            UT_DEBUGMSG(("Putting ODF on the clipboard...e:%d bExpODT:%d\n", err, bExpODT ));

#ifdef DUMP_CLIPBOARD_COPY
            std::ofstream oss("/tmp/abiword-clipboard-copy.odt");
            oss.write( (const char*)bufODT.getPointer (0), bufODT.getLength () );
            oss.close();
#endif
		}
	}

    // create UTF-8 text buffer to put on the clipboard
		
    IE_Exp_Text * pExpText = new IE_Exp_Text(pDocRange->m_pDoc, "UTF-8");
    if (pExpText)
    {
		pExpText->copyToBuffer(pDocRange,&bufTEXT);
		DELETEP(pExpText);
    }

    // NOTE: this clearData() will actually release our ownership of
    // NOTE: the CLIPBOARD property in addition to clearing any
    // NOTE: stored buffers.  I'm omitting it since we seem to get
    // NOTE: clr callback after we have done some other processing
    // NOTE: (like adding the new stuff).
    // m_pClipboard->clearData(true,false);
	
    // TODO: handle CLIPBOARD vs PRIMARY
    XAP_UnixClipboard::T_AllowGet target = ((bUseClipboard)
					    ? XAP_UnixClipboard::TAG_ClipboardOnly
					    : XAP_UnixClipboard::TAG_PrimaryOnly);

	if (bufRTF.getLength () > 0)
		m_pClipboard->addRichTextData (target, bufRTF.getPointer (0), bufRTF.getLength ());
	if (bufXHTML.getLength () > 0)
		m_pClipboard->addHtmlData (target, bufXHTML.getPointer (0), bufXHTML.getLength (), true);
	if (bufHTML4.getLength () > 0)
		m_pClipboard->addHtmlData (target, bufHTML4.getPointer (0), bufHTML4.getLength (), false);
	if (bExpODT && bufODT.getLength () > 0)
		m_pClipboard->addODTData (target, bufODT.getPointer (0), bufODT.getLength ());
	if (bufTEXT.getLength () > 0)
		m_pClipboard->addTextData (target, bufTEXT.getPointer (0), bufTEXT.getLength ());

	{
		// TODO: we have to make a good way to tell if the current selection is just an image
		FV_View * pView = NULL;
		if(getLastFocussedFrame())
			pView = static_cast<FV_View*>(getLastFocussedFrame()->getCurrentView());

		if (pView && !pView->isSelectionEmpty())
			{
				// don't own, don't g_free
				const UT_ByteBuf * png = 0;
	  
				pView->saveSelectedImage (&png);
				if (png && png->getLength() > 0)
					{
						m_pClipboard->addPNGData(target, static_cast<const UT_Byte*>(png->getPointer(0)), png->getLength());
					}
			}
    }

	m_pClipboard->finishedAddingData();

    return;
}
Esempio n. 8
0
static int
test_xml_indent (void)
{
	GsfOutput *mem = gsf_output_memory_new ();
	GsfXMLOut *xml = gsf_xml_out_new (mem);
	const char *data;
	gboolean pprint;
	int err;
	const char *expected =
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
		"<outer>\n"
		"  <data/>\n"
		"  <data attr=\"val\"/>\n"
		"  <data>text</data>\n"
		"  <data>\n"
		"    <inner>text</inner>\n"
		"  </data>\n"
		"  <data>text</data>\n"
		"  <data><inner>text</inner></data>\n"
		"</outer>\n";

	gsf_xml_out_start_element (xml, "outer");

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_add_cstr_unchecked (xml, "attr", "val");
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_start_element (xml, "inner");
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_end_element (xml);
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	pprint = gsf_xml_out_set_pretty_print (xml, FALSE);
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_set_pretty_print (xml, pprint);
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	pprint = gsf_xml_out_set_pretty_print (xml, FALSE);
	gsf_xml_out_start_element (xml, "inner");
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_end_element (xml);
	gsf_xml_out_set_pretty_print (xml, pprint);
	gsf_xml_out_end_element (xml);

	gsf_xml_out_end_element (xml);

	g_object_unref (xml);

	data = (const char *)gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (mem));
	g_printerr ("Got\n%s\n", data);

	err = !g_str_equal (data, expected);
	if (err)
		g_printerr ("Expected\n%s\n", expected);

	g_object_unref (mem);

	return err;
}
Esempio n. 9
0
static gboolean
feed(ChupaDecomposer *decomposer, ChupaFeeder *feeder,
     ChupaData *data, GError **error)
{
    GOFileSaver *saver;
    GOFileOpener *opener = NULL;
    GOIOContext *io_context;
    WorkbookView *view = NULL;
    Workbook *workbook;
    GODoc *document;
    GsfInput *source;
    GsfOutput *output;
    GInputStream *input;
    ChupaData *next_data;
    const gchar *filename;
    GPrintFunc old_print_error_func;
    ChupaMetadata *metadata;

    filename = chupa_data_get_filename(data);

    source = chupa_data_input_new(data);
    io_context = go_io_context_new(command_context);
    old_print_error_func = g_set_printerr_handler(printerr_to_log_delegator);
    view = wb_view_new_from_input(source, filename, opener, io_context, NULL);
    g_object_unref(source);
    g_set_printerr_handler(old_print_error_func);
    if (go_io_error_occurred(io_context)) {
        go_io_error_display(io_context);
    }
    if (!view) {
        g_set_error(error,
                    CHUPA_DECOMPOSER_ERROR,
                    CHUPA_DECOMPOSER_ERROR_FEED,
                    "[decomposer][excel][feed][error][%s]"
                    ": failed to create workbook",
                    filename);
        g_object_unref(io_context);
        return FALSE;
    }
    workbook = wb_view_get_workbook(view);
    document = wb_view_get_doc(view);

    saver = find_file_saver(filename, view, workbook, document, error);
    if (!saver) {
        g_object_unref(workbook);
        g_object_unref(io_context);
        return FALSE;
    }

    output = gsf_output_memory_new();
    if (!output) {
        g_set_error(error,
                    CHUPA_DECOMPOSER_ERROR,
                    CHUPA_DECOMPOSER_ERROR_FEED,
                    "[decomposer][excel][feed][%s][error]"
                    ": failed to create output",
                    filename);
        g_object_unref(workbook);
        g_object_unref(io_context);
        return FALSE;
    }

    wbv_save_to_output(view, saver, output, io_context);
    if (go_io_error_occurred(io_context)) {
        go_io_error_display(io_context);
        g_object_unref(workbook);
        g_object_unref(io_context);
        g_object_unref(output);
        return FALSE;
    }

    metadata = chupa_metadata_new();
    chupa_metadata_merge_original_metadata(metadata,
                                           chupa_data_get_metadata(data));
    collect_metadata(metadata, document);
    g_object_unref(workbook);
    g_object_unref(io_context);

    input = chupa_memory_input_stream_new(GSF_OUTPUT_MEMORY(output));
    g_object_unref(output);

    chupa_metadata_set_content_length(metadata, gsf_output_size(output));
    next_data = chupa_data_new(input, metadata);
    g_object_unref(metadata);
    g_object_unref(input);
    chupa_feeder_accepted(feeder, next_data);
    chupa_data_finished(next_data, NULL);
    g_object_unref(next_data);

    return TRUE;
}
Esempio n. 10
0
/**
 * stf_text_to_columns:
 * @wbc: The control making the request
 * @cc:
 *
 * Main routine, handles importing a file including all dialog mumbo-jumbo
 **/
void
stf_text_to_columns (WorkbookControl *wbc, GOCmdContext *cc)
{
	DialogStfResult_t *dialogresult = NULL;
	SheetView	*sv;
	Sheet		*src_sheet, *target_sheet;
	GnmRange const	*src;
	GnmRange	 target;
	GsfOutput	*buf;
	guint8 const	*data;
	size_t data_len;

	sv    = wb_control_cur_sheet_view (wbc);
	src_sheet = sv_sheet (sv);
	src = selection_first_range (sv, cc, _("Text to Columns"));
	if (src == NULL)
		return;
	if (range_width	(src) > 1) {
		go_cmd_context_error (cc, g_error_new (go_error_invalid (), 0,
			_("Only one column of input data can be parsed at a time")));
		return;
	}

	/* FIXME : how to do this cleanly ? */
	if (!GNM_IS_WBC_GTK (wbc))
		return;

#warning Add UI for this
	target_sheet = src_sheet;
	target = *src;
	range_translate (&target, target_sheet, 1, 0);

	buf = gsf_output_memory_new ();
	sheet_foreach_cell_in_range (src_sheet,
		CELL_ITER_ALL,
		src->start.col, src->start.row,
		src->end.col, src->end.row,
		(CellIterFunc) &cb_get_content, buf);

	gsf_output_close (buf);
	data = gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (buf));
	data_len = (size_t)gsf_output_size (buf);
	if (data_len == 0) {
		go_cmd_context_error_import (GO_CMD_CONTEXT (cc),
					     _("There is no data "
					       "to convert"));
	} else {
		dialogresult = stf_dialog (WBC_GTK (wbc),
					   NULL, FALSE, NULL, FALSE,
					   _("Text to Columns"),
					   data, data_len);
	}
	if (dialogresult != NULL) {
		GnmCellRegion *cr = stf_parse_region (dialogresult->parseoptions,
			dialogresult->text, NULL, target_sheet->workbook);
		if (cr != NULL) {
			stf_dialog_result_attach_formats_to_cr (dialogresult, cr);
			target.end.col = target.start.col + cr->cols - 1;
			target.end.row = target.start.row + cr->rows - 1;
		}
		if (cr == NULL ||
		    cmd_text_to_columns (wbc, src, src_sheet,
					 &target, target_sheet, cr))
			go_cmd_context_error_import (GO_CMD_CONTEXT (cc),
					     _("Error while trying to "
					       "parse data into sheet"));
		stf_dialog_result_free (dialogresult);
	}

	g_object_unref (buf);
}