Example #1
0
void IE_Exp_AbiWord_1::_setupFile()
{
	// allow people to override this on the command line or otherwise
	const std::string & prop = (getProperty ("compress"));
	if (!prop.empty())
		m_bIsCompressed = UT_parseBool(prop.c_str (), m_bIsCompressed);
	
	if (m_bIsCompressed)
	{
		GsfOutput * gzip = gsf_output_gzip_new(getFp (), NULL);
		m_output = gzip;
	}
	else
	{
		m_output = 0;
	}
}
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;
}