Beispiel #1
0
static void getDefaultApp(UT_String &imageApp, bool &bLeaveImageAsPNG)
{
#ifdef WIN32
	bLeaveImageAsPNG = false;
	imageApp.clear();

	char buffer[MAX_PATH];
	// for WinNT mspaint is most likely in the system directory (eg C:\WINNT\SYSTEM32\MSPAINT.EXE)
	if (GetSystemDirectory(buffer, MAX_PATH))
	{
		imageApp = buffer;
		imageApp += "\\MSPAINT.EXE";
		UT_DEBUGMSG(("ABIPAINT: Checking if %s exists\n", imageApp.c_str()));
		if (!UT_isRegularFile(imageApp.c_str()))
			imageApp.clear();
	}
	// if not there, try in Win95b directory (eg %PROGRAMFILES%\ACCESSORIES\MSPAINT.EXE)
	if (imageApp.empty())
	{
		HKEY hKey;
		unsigned long lType;	
		DWORD dwSize;
		unsigned char* szValue = NULL;
		if( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS )
		{
			if( ::RegQueryValueEx( hKey, "ProgramFilesDir", NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS )
			{
				szValue = new unsigned char[dwSize + 1];
				::RegQueryValueEx( hKey, "ProgramFilesDir", NULL, &lType, szValue, &dwSize);
				imageApp = (char*) szValue;
				delete[] szValue;
				imageApp += "\\ACCESSORIES\\MSPAINT.EXE";
				UT_DEBUGMSG(("ABIPAINT: Checking if %s exists\n", imageApp.c_str()));
				if (!UT_isRegularFile(imageApp.c_str()))
					imageApp.clear();
			}
			::RegCloseKey(hKey);
		}
	}
	// if we still haven't found the file, then simply try mspaint.exe
	if (imageApp.empty())
	{
		imageApp = "mspaint.exe";
		UT_DEBUGMSG(("ABIPAINT: Falling back to %s (will probably fail)\n", imageApp.c_str()));
	}
#else
	// for other platforms default to the GIMP, assume in path
	bLeaveImageAsPNG = true;
	imageApp = "gimp";
#endif
}
Beispiel #2
0
const char * AP_UnixPrefs::_getPrefsPathname(void) const
{
	/* return a pointer to a static buffer */
	static UT_String buf;

	if(!buf.empty())
	  return buf.c_str();

	const char * szDirectory = XAP_App::getApp()->getUserPrivateDirectory();
	const char * szFile = "AbiWord.Profile";

	buf = szDirectory;
	if (!buf.size() || szDirectory[buf.size()-1] != '/')
	  buf += "/";
	buf += szFile;

	return buf.c_str();
}
/*!
 * simplesplit splits the referring string along the character 'separator', 
 * removing the separator character, and placing the resulting strings in a 
 * UT_Vector. If 'max' is specified, this is done max times - the max + 1
 * string in the vector will contain the remainder of the original string 
 * (str).
 */
UT_GenericVector<UT_String*> * simpleSplit (const UT_String & str, char separator,
						 size_t max)
{
	UT_GenericVector<UT_String*> * utvResult = new UT_GenericVector<UT_String*>();
	UT_String* utsEntry;
	UT_uint32 start = 0;

	for(size_t j = 0; (max == 0 || j < max) && start < str.size(); j++)
	{
		utsEntry = new UT_String;

		for (; (str[start] != separator || j == max - 1) && start < str.size(); start++)
			*utsEntry += str[start];

		start++;						// skipping over the separator character
										// itself
		if (utsEntry->empty())
			delete utsEntry;
		else
			utvResult->addItem(utsEntry);
	}

	return utvResult;
}
#include "tf_test.h"
#include "ut_string_class.h"

#define TFSUITE "core.af.util.stringclass"

TFTEST_MAIN("UT_String")
{
	UT_String s("foobar");

	TFPASS(s.size() == 6);
	TFPASS(s.length() == 6);

	TFFAIL(s.empty());

	TFPASS(s == "foobar");
	TFPASS(s == UT_String("foobar"));

	s += "baz";
	TFPASS(s.size() == 9);
	TFPASS(s == "foobarbaz");

	s += UT_String("42");
	TFPASS(s.size() == 11);
	TFPASS(s == "foobarbaz42");

	s += '!';
	TFPASS(s.size() == 12);
	TFPASS(s == "foobarbaz42!");

	TFPASS(s[3] == 'b');
Beispiel #5
0
/**
 * Adds an data item (<d> tag) in the AbiWord document for the specified image.
 * 
 * Code mainly from Dom Lachowicz and/or Robert Staudinger.
 * 
 * @param rDataId Receives the id that has been given to the added data item.
 * @param ppAtts The attributes of a <draw:image> element.
 */
bool ODi_Abi_Data::addObjectDataItem(UT_String& rDataId, const gchar** ppAtts, int& pto_Type) {
    
    const gchar* pHRef = UT_getAttribute ("xlink:href", ppAtts);
    UT_return_val_if_fail(pHRef,false);

    // If we have a string smaller then this we are in trouble. File corrupted?
    UT_return_val_if_fail((strlen(pHRef) >= 10 /*10 == strlen("Pictures/a")*/), false);

    UT_Error error = UT_OK;
    UT_ByteBuf *object_buf;
    GsfInfile* pObjects_dir;
    UT_uint32 objectID;

    // The subdirectory that holds the picture. e.g: "ObjectReplacements" or "Pictures"
    UT_String dirName;
    
    // The file name of the picture. e.g.: "Object 1" or "10000201000000D100000108FF0E3707.png" 
    UT_String fileName;
    
    const std::string id = m_href_to_id[pHRef];
    if (!id.empty()) {
        // This object was already added.
        // Use the existing data item id.
        rDataId = id;
        return true;
    }
    
    
    // Get a new, unique, ID.
    objectID = m_pAbiDocument->getUID(UT_UniqueId::Math);
    UT_String_sprintf(rDataId, "MathLatex%d", objectID);
    
    // Add this id to the list
    UT_DebugOnly<href_id_map_t::iterator> iter = m_href_to_id
		.insert(m_href_to_id.begin(),
			href_id_map_t::value_type(pHRef, 
						  rDataId.c_str()));
    UT_ASSERT((href_id_map_t::iterator)iter != m_href_to_id.end());

    _splitDirectoryAndFileName(pHRef, dirName, fileName);

    if (fileName.empty ())
      fileName = "content.xml";

    pObjects_dir =
        GSF_INFILE(gsf_infile_child_by_name(m_pGsfInfile, dirName.c_str()));

    UT_return_val_if_fail(pObjects_dir, false);

    // Loads object_buf
    object_buf = new UT_ByteBuf ();
    error = _loadStream(pObjects_dir, fileName.c_str(), *object_buf);
    g_object_unref (G_OBJECT (pObjects_dir));

    if (error != UT_OK) {
	delete object_buf;
        return false;
    }

    // check to ensure that we're seeing math. this can probably be made smarter.
    static const char math_header[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE math:math";

    if ((object_buf->getLength () > strlen (math_header)) &&
	(strncmp ((const char*)object_buf->getPointer (0), math_header, strlen (math_header)) != 0)) {
	delete object_buf;
        return false;
    }

    //
    // Create the data item.
    //

    if (!m_pAbiDocument->createDataItem(rDataId.c_str(), false, object_buf, 
                                        "application/mathml+xml", NULL)) {            
        UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
        return false;
    }  

    pto_Type = PTO_Math;
    return true;
}