1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/* ====================================================================
* Copyright (c) 2003-2009 Martin Hauner
* http://subcommander.tigris.org
*
* Subcommander is licensed as described in the file doc/COPYING, which
* you should have received as part of this distribution.
* ====================================================================
*/
// sc
#include "Utility.h"
#include "config.h"
#include "CrashHandler.h"
#ifdef _WIN32
#include "win32st/Stacktrace.h"
#endif // _WIN32
// qt
#include <QtGui/QApplication>
#include <QtCore/QRegExp>
#include <QtCore/QTextCodec>
#include <QtCore/QStringList>
// gettext
#ifdef _WIN32
#include <libintl.h>
#endif // _WIN32
// sys
#include <cstdlib>
#include <locale.h>
static QString _appName;
static CrashHandler _crash;
void setAppName( const QString& name )
{
_appName = name;
}
QString getDataDir()
{
#ifdef _MACOSX
if( getAppName() == "subcommander" )
return qApp->applicationDirPath() + "/../Resources";
else
return qApp->applicationDirPath() + "/../Resources";
//return qApp->applicationDirPath() + "/../../../subcommander.app/Contents/Resources";
#elif defined(_WIN32)
return qApp->applicationDirPath();
#else
return qApp->applicationDirPath() + "/../share/subcommander";
#endif
}
QString getMergePath()
{
QString path = qApp->applicationDirPath();
#if defined(_MACOSX)
// seperate bundle path
path += "/../../../submerge.app/Contents/MacOS/submerge";
// embeded bundle path
//path += "/../submerge.app/Contents/MacOS/submerge";
#elif defined(_WIN32)
# if defined(_DEBUG)
path += "/submergeD";
# else
path += "/submerge";
# endif // _DEBUG
#else // ! _WIN32
path += "/submerge";
#endif // _WIN32
return path;
}
QString getAppName()
{
return _appName;
}
QString getLongAppName()
{
if( _appName == "subcommander" )
{
return "subcommander";
}
else if( _appName == "submerge" )
{
return "submerge";
}
else
{
return "unknown";
}
}
QString getIconDir()
{
return getDataDir() + "/icons/default/";
}
void setPluginPath()
{
QString appPath = QCoreApplication::applicationDirPath();
QCoreApplication::setLibraryPaths(
QStringList() << appPath + "/plugins"
);
}
void initStackProcess()
{
#ifdef _WIN32
Stacktrace::setupProcess();
Stacktrace::setExceptionHandler(&_crash);
#endif // _WIN32
}
void stopStackProcess()
{
#ifdef _WIN32
Stacktrace::shutdownProcess();
#endif // _WIN32
}
void initStackThread()
{
#ifdef _WIN32
Stacktrace::setupThread();
#endif // _WIN32
}
void stopStackThread()
{
#ifdef _WIN32
Stacktrace::shutdownThread();
#endif // _WIN32
}
void setDumpOnException( bool b )
{
#ifdef _WIN32
Stacktrace::setDump(b);
#endif // _WIN32
}
bool getDumpOnException()
{
#ifdef _WIN32
return Stacktrace::getDump();
#else
return false;
#endif // _WIN32
}
// some magic to make sc/svn i18n aware
void setLocale()
{
#ifndef _WIN32
QString loc = QTextCodec::locale();
loc += ".UTF-8";
// set LANG if not set (on MacOSX the setlocale below doesn't work if LANG
// is not set).
setenv( "LANG", loc, 0 );
#endif // _WIN32
// C programs default to the "C" locale. We are supposed to be i18n-aware,
// so it should inherit the default locale of our environment.
/*const char* l =*/ setlocale(LC_ALL, "");
}
// overwrite the subversion locale directory to our installation directory
// for Windows and MacOSX
void enableLocale( bool enable )
{
#ifdef ENABLE_NLS
QString localePath = QCoreApplication::applicationDirPath();
#if defined(_MACOSX)
localePath = getDataDir() + "/locale";
#elif defined(_WIN32)
localePath += "/share/locale";
#else
localePath += "/../share/locale";
#endif
// invalidate path... make sure we don not find the translations
if(!enable)
localePath += "/nol10n";
#if defined(_WIN32) || (defined(_MACOSX) && defined(MACOSX_BUNDLED_SVN_NLS))
#define SVN_PACKAGE_NAME "subversion"
/*const char* svn_btd =*/ bindtextdomain( SVN_PACKAGE_NAME, (const char*)localePath.toLocal8Bit() );
/*const char* svn_btdc =*/ bind_textdomain_codeset( SVN_PACKAGE_NAME, "UTF-8" );
#define NEON_PACKAGE_NAME "neon"
/*const char* svn_btd =*/ bindtextdomain( NEON_PACKAGE_NAME, (const char*)localePath.toLocal8Bit() );
/*const char* svn_btdc =*/ bind_textdomain_codeset( NEON_PACKAGE_NAME, "UTF-8" );
#endif
#define SC_PACKAGE_NAME "Subcommander"
/*const char* sc_btd =*/ bindtextdomain( SC_PACKAGE_NAME, (const char*)localePath.toLocal8Bit() );
/*const char* sc_btdc =*/ bind_textdomain_codeset( SC_PACKAGE_NAME, "UTF-8" );
#endif // ENABLE_NLS
}
QString getDateFormat()
{
// Sun Aug 27 16:32:54 2006
return _q("ddd MMM dd hh:mm:ss yyyy");
}
static const char* neon_version = "";
static const char* serf_version = "";
void setNeonVersion( const char* v )
{
neon_version = v;
}
QString getNeonVersion()
{
return QString(neon_version).left(12);
}
void setSerfVersion( const char* v )
{
serf_version = v;
}
QString getSerfVersion()
{
return QString(serf_version);
}
|