diff -Naur abi/src/af/xap/cocoa/xap_CocoaApp.h abi.mod/src/af/xap/cocoa/xap_CocoaApp.h --- abi/src/af/xap/cocoa/xap_CocoaApp.h Tue Feb 10 15:19:43 2004 +++ abi.mod/src/af/xap/cocoa/xap_CocoaApp.h Tue Oct 5 01:41:49 2004 @@ -63,6 +63,8 @@ virtual void pasteFromClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard, bool bHonorFormatting = true) = 0; virtual bool canPasteFromClipboard() = 0; virtual const char * getUserPrivateDirectory(); + virtual bool findAbiSuiteLibFile(UT_String & path, const char * filename, const char * subdir = 0) const; + virtual bool findAbiSuiteAppFile(UT_String & path, const char * filename, const char * subdir = 0) const; // doesn't check user-dir virtual void setSelectionStatus(AV_View * pView) = 0; virtual void clearSelection() = 0; diff -Naur abi/src/af/xap/cocoa/xap_CocoaApp.mm abi.mod/src/af/xap/cocoa/xap_CocoaApp.mm --- abi/src/af/xap/cocoa/xap_CocoaApp.mm Sun Mar 7 20:43:23 2004 +++ abi.mod/src/af/xap/cocoa/xap_CocoaApp.mm Tue Oct 5 01:41:49 2004 @@ -31,6 +31,7 @@ #include #include "ut_debugmsg.h" +#include "ut_path.h" #include "ut_string.h" #include "ut_uuid.h" @@ -207,6 +208,61 @@ return upd_cache; } +bool XAP_CocoaApp::findAbiSuiteLibFile(UT_String & path, const char * filename, const char * subdir) const +{ + if (!filename) + return false; + if (XAP_App::findAbiSuiteLibFile(path,filename,subdir)) + return true; + + bool bFound = false; + + // get Bundle resource directory and use that. + NSString * resDir = [[NSBundle mainBundle] resourcePath]; + if (resDir) + { + path = [resDir UTF8String]; + if (subdir) + { + path += "/"; + path += subdir; + } + path += "/"; + path += filename; +xxx_UT_DEBUGMSG(("XAP_CocoaApp::findAbiSuiteLibFile(\"%s\",\"%s\",\"%s\")\n",path.c_str(),filename,subdir)); + bFound = UT_isRegularFile (path.c_str ()); + } + return bFound; +} + +bool XAP_CocoaApp::findAbiSuiteAppFile(UT_String & path, const char * filename, const char * subdir) const +{ + if (!filename) + return false; + if (XAP_App::findAbiSuiteLibFile(path,filename,subdir)) + return true; + + bool bFound = false; + + // get Bundle resource directory and use that. + NSString * resDir = [[NSBundle mainBundle] resourcePath]; + if (resDir) + { + path = [resDir UTF8String]; + path += "/AbiWord"; + if (subdir) + { + path += "/"; + path += subdir; + } + path += "/"; + path += filename; +xxx_UT_DEBUGMSG(("XAP_CocoaApp::findAbiSuiteAppFile(\"%s\",\"%s\",\"%s\")\n",path.c_str(),filename,subdir)); + bFound = UT_isRegularFile (path.c_str ()); + } + return bFound; +} + bool XAP_CocoaApp::_loadFonts() { return true; @@ -214,6 +270,8 @@ void XAP_CocoaApp::_setAbiSuiteLibDir() { + XAP_App::_setAbiSuiteLibDir("/Library/Application Support/AbiSuite"); +#if 0 // TODO Change that to use Bundle path instead. Probably by using FJF code. char buf[PATH_MAX]; // char buf2[PATH_MAX]; // not used? @@ -268,6 +326,7 @@ UT_DEBUGMSG(("Couldn't get resource bundle directory.")); XAP_App::_setAbiSuiteLibDir(getAbiSuiteHome()); return; +#endif } ////////////////////////////////////////////////////////////////// diff -Naur abi/src/af/xap/xp/xap_App.cpp abi.mod/src/af/xap/xp/xap_App.cpp --- abi/src/af/xap/xp/xap_App.cpp Sat Oct 2 21:48:47 2004 +++ abi.mod/src/af/xap/xp/xap_App.cpp Tue Oct 5 01:41:49 2004 @@ -25,6 +25,7 @@ #include "ut_types.h" #include "ut_assert.h" +#include "ut_path.h" #include "ut_string.h" #include "ut_debugmsg.h" #include "ut_Language.h" @@ -781,6 +782,72 @@ const char * XAP_App::getAbiSuiteLibDir() const { return m_szAbiSuiteLibDir; +} + +bool XAP_App::findAbiSuiteLibFile(UT_String & path, const char * filename, const char * subdir) const +{ + if (!filename) return false; + +#if defined(WIN32) + const char * sep = "\\"; +#else + const char * sep = "/"; +#endif + bool bFound = false; + + const char * dir = 0; + if (dir = getUserPrivateDirectory()) + { + path = dir; + if (subdir) + { + path += sep; + path += subdir; + } + path += sep; + path += filename; + bFound = UT_isRegularFile (path.c_str ()); + } + if (!bFound && (dir = getAbiSuiteLibDir())) + { + path = dir; + if (subdir) + { + path += sep; + path += subdir; + } + path += sep; + path += filename; + bFound = UT_isRegularFile (path.c_str ()); + } + return bFound; +} + +bool XAP_App::findAbiSuiteAppFile(UT_String & path, const char * filename, const char * subdir) const +{ + if (!filename) return false; + +#if defined(WIN32) + const char * sep = "\\"; +#else + const char * sep = "/"; +#endif + bool bFound = false; + + const char * dir = 0; + if (dir = getAbiSuiteAppDir()) + { + path = dir; + if (subdir) + { + path += sep; + path += subdir; + } + path += sep; + path += filename; + bFound = UT_isRegularFile (path.c_str ()); + } + return bFound; } bool XAP_App::addWordToDict(const UT_UCSChar * pWord, UT_uint32 len) diff -Naur abi/src/af/xap/xp/xap_App.h abi.mod/src/af/xap/xp/xap_App.h --- abi/src/af/xap/xp/xap_App.h Fri Oct 1 20:32:26 2004 +++ abi.mod/src/af/xap/xp/xap_App.h Tue Oct 5 01:41:49 2004 @@ -152,6 +152,8 @@ virtual const char * getUserPrivateDirectory() = 0; virtual const char * getAbiSuiteLibDir() const; virtual const char * getAbiSuiteAppDir() const = 0; + virtual bool findAbiSuiteLibFile(UT_String & path, const char * filename, const char * subdir = 0) const; + virtual bool findAbiSuiteAppFile(UT_String & path, const char * filename, const char * subdir = 0) const; // doesn't check user-dir virtual void copyToClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard = true) = 0; virtual void pasteFromClipboard(PD_DocumentRange * pDocRange, bool bUseClipboard, bool bHonorFormatting = true) = 0; virtual bool canPasteFromClipboard() = 0; diff -Naur abi/src/other/spell/xp/ispell_checker.cpp abi.mod/src/other/spell/xp/ispell_checker.cpp --- abi/src/other/spell/xp/ispell_checker.cpp Tue Mar 23 00:12:16 2004 +++ abi.mod/src/other/spell/xp/ispell_checker.cpp Tue Oct 5 01:41:50 2004 @@ -17,12 +17,6 @@ // for a silly messagebox #include -#if defined(WIN32) -#define DICTIONARY_LIST_FILENAME "\\dictionary\\ispell_dictionary_list.xml" -#else -#define DICTIONARY_LIST_FILENAME "/dictionary/ispell_dictionary_list.xml" -#endif - /***************************************************************************/ class ABI_EXPORT DictionaryListener : public UT_XML::Listener @@ -212,15 +206,15 @@ if (mRefCnt == 0) { // load the dictionary list - UT_String dictionary_list ( XAP_App::getApp()->getAbiSuiteLibDir() ); - dictionary_list += DICTIONARY_LIST_FILENAME; - - DictionaryListener listener(m_mapping); - UT_XML parser; - parser.setListener (&listener); - parser.parse (dictionary_list.c_str()); + UT_String dictionary_list; + if (XAP_App::getApp()->findAbiSuiteLibFile(dictionary_list,"ispell_dictionary_list.xml","dictionary")) + { + DictionaryListener listener(m_mapping); + UT_XML parser; + parser.setListener (&listener); + parser.parse (dictionary_list.c_str()); + } } - mRefCnt++; } @@ -397,48 +391,6 @@ return sgvec; } -static char * -s_buildHashName ( const char * base, const char * dict ) -{ - UT_String hName ( base ); -#if defined(WIN32) - hName += "\\dictionary\\"; -#else - hName += "/dictionary/"; -#endif - hName += dict; - return UT_strdup (hName.c_str()); -} - - -char * -ISpellChecker::loadGlobalDictionary ( const char *szHash ) -{ - char *hashname = NULL; - hashname = s_buildHashName ( XAP_App::getApp()->getAbiSuiteLibDir(), szHash ); - if (linit(const_cast(hashname)) < 0) - { - FREEP( hashname ); - return(NULL); - } - - return(hashname); -} - - -char * -ISpellChecker::loadLocalDictionary ( const char *szHash ) -{ - char *hashname = NULL; - hashname = s_buildHashName ( XAP_App::getApp()->getUserPrivateDirectory(), szHash ); - if (linit(const_cast(hashname)) < 0) - { - FREEP( hashname ); - return(NULL); - } - return(hashname); -} - /*! * Load ispell dictionary hash file for given language. @@ -449,8 +401,7 @@ bool ISpellChecker::loadDictionaryForLanguage ( const char * szLang ) { - char *hashname = NULL; - + UT_String hashname; UT_String encoding; UT_String szFile; @@ -478,17 +429,15 @@ alloc_ispell_struct(); - if (!(hashname = loadGlobalDictionary(szFile.c_str()))) + if (XAP_App::getApp()->findAbiSuiteLibFile(hashname,szFile.c_str(),"dictionary")) { - if (!(hashname = loadLocalDictionary(szFile.c_str()))) + if (!(linit(const_cast(hashname.c_str())) < 0)) { - return false; + setDictionaryEncoding (hashname.c_str(), encoding.c_str() ); + return true; } } - - // one of the two above calls succeeded - setDictionaryEncoding ( hashname, encoding.c_str() ); - return true; + return false; } void @@ -559,9 +508,11 @@ bool ISpellChecker::doesDictionaryExist (const char * szLang) { - char *hashname = NULL; + UT_String hashname; UT_String szFile; + FILE * in = 0; + for (UT_uint32 i = 0; i < m_mapping.size(); i++) { DictionaryMapping * mapping = static_cast(const_cast(m_mapping.getNthItem ( i ))); @@ -575,17 +526,12 @@ if (szFile.size () == 0 ) return false; - hashname = s_buildHashName ( XAP_App::getApp()->getAbiSuiteLibDir(), szFile.c_str()); - FILE* in = fopen(hashname, "r"); - FREEP(hashname); - - if (!in) - return false; - else + if (XAP_App::getApp()->findAbiSuiteLibFile(hashname,szFile.c_str(),"dictionary")) { - fclose(in); - return true; + in = fopen(hashname.c_str(), "r"); + if (in) fclose (in); } + return (in != 0); } bool diff -Naur abi/src/other/spell/xp/ispell_checker.h abi.mod/src/other/spell/xp/ispell_checker.h --- abi/src/other/spell/xp/ispell_checker.h Tue Mar 23 00:12:17 2004 +++ abi.mod/src/other/spell/xp/ispell_checker.h Tue Oct 5 01:41:50 2004 @@ -30,9 +30,6 @@ virtual bool _requestDictionary (const char * szLang); - char * loadGlobalDictionary ( const char *szHash ); - char * loadLocalDictionary ( const char *szHash ); - bool loadDictionaryForLanguage ( const char * szLang ); void setDictionaryEncoding ( const char * hashname, const char * enc ); diff -Naur abi/src/text/ptbl/xp/pd_Document.cpp abi.mod/src/text/ptbl/xp/pd_Document.cpp --- abi/src/text/ptbl/xp/pd_Document.cpp Sun Oct 3 19:52:18 2004 +++ abi.mod/src/text/ptbl/xp/pd_Document.cpp Tue Oct 5 01:41:50 2004 @@ -227,9 +227,23 @@ template_list[0] = user_template_base; // always try to load user's normal.awt first template_list[1] = UT_String_sprintf ("%s-%s_%s", user_template_base.c_str(), lang.utf8_str(), terr.utf8_str()); template_list[2] = UT_String_sprintf ("%s-%s", user_template_base.c_str(), lang.utf8_str()); - template_list[3] = UT_String_sprintf ("%s-%s_%s", global_template_base.c_str(), lang.utf8_str(), terr.utf8_str()); - template_list[4] = UT_String_sprintf ("%s-%s", global_template_base.c_str(), lang.utf8_str()); - template_list[5] = global_template_base; // always try to load global normal.awt last + + if (!XAP_App::getApp()->findAbiSuiteLibFile(template_list[5],base.c_str(),"templates")) + template_list[5] = global_template_base; // always try to load global normal.awt last + + UT_String xbase = base; + + xbase += "-"; + xbase += lang.utf8_str(); + + if (!XAP_App::getApp()->findAbiSuiteLibFile(template_list[4],xbase.c_str(),"templates")) + template_list[4] = UT_String_sprintf ("%s-%s", global_template_base.c_str(), lang.utf8_str()); + + xbase += "_"; + xbase += terr.utf8_str(); + + if (!XAP_App::getApp()->findAbiSuiteLibFile(template_list[3],xbase.c_str(),"templates")) + template_list[3] = UT_String_sprintf ("%s-%s_%s", global_template_base.c_str(), lang.utf8_str(), terr.utf8_str()); } UT_Error PD_Document::importFile(const char * szFilename, int ieft, diff -Naur abi/src/wp/ap/cocoa/ap_CocoaApp.mm abi.mod/src/wp/ap/cocoa/ap_CocoaApp.mm --- abi/src/wp/ap/cocoa/ap_CocoaApp.mm Sun Oct 3 02:02:32 2004 +++ abi.mod/src/wp/ap/cocoa/ap_CocoaApp.mm Tue Oct 5 01:41:50 2004 @@ -444,6 +444,9 @@ */ const char * AP_CocoaApp::getAbiSuiteAppDir(void) const { + static const char * SystemAppDir = "/Library/Application Support/AbiSuite/AbiWord"; + return SystemAppDir; +#if 0 // we return a static string, use it quickly. static XML_Char buf[1024]; @@ -451,6 +454,7 @@ sprintf(buf,"%s/%s",getAbiSuiteLibDir(),ABIWORD_APP_LIBDIR); return buf; +#endif } /*! diff -Naur abi/src/wp/ap/xp/ap_Prefs.cpp abi.mod/src/wp/ap/xp/ap_Prefs.cpp --- abi/src/wp/ap/xp/ap_Prefs.cpp Sat Nov 29 21:13:17 2003 +++ abi.mod/src/wp/ap/xp/ap_Prefs.cpp Tue Oct 5 01:41:51 2004 @@ -143,13 +143,12 @@ void AP_Prefs::overlaySystemPrefs(void) { // read system prefs file and overlay builtin values. - - const char * szSystemDefaultPrefsDir = m_pApp->getAbiSuiteAppDir(); - char buf[1024]; - sprintf(buf,"%s/%s",szSystemDefaultPrefsDir,"system.profile"); - const char** items = localeinfo_combinations(buf,"","-",0); + const char** items = localeinfo_combinations("system.profile","","-",0); + UT_String path; while(*items) { - loadSystemDefaultPrefsFile(*items++); + const char * item = *items++; + if (m_pApp->findAbiSuiteAppFile(path,item)) + loadSystemDefaultPrefsFile(path.c_str()); }; }