2008-01-20 19:40:12 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2008 Olivier Teulière
|
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-09-07 15:17:39 +02:00
|
|
|
#include <string>
|
2010-10-17 23:23:39 +02:00
|
|
|
#include <exception>
|
2008-09-03 19:28:27 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QTranslator>
|
2011-01-30 00:47:20 +01:00
|
|
|
#include "logging.h"
|
2010-10-17 23:23:39 +02:00
|
|
|
#include "base_exception.h"
|
|
|
|
#include "stacktrace.h"
|
2008-01-20 19:40:12 +01:00
|
|
|
#include "main_window.h"
|
2008-09-05 23:31:30 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
2010-01-29 22:11:44 +01:00
|
|
|
#ifdef __APPLE__
|
2010-02-07 18:34:59 +01:00
|
|
|
# include <CoreFoundation/CoreFoundation.h>
|
2010-01-29 22:11:44 +01:00
|
|
|
#endif
|
2008-01-20 19:40:12 +01:00
|
|
|
|
2010-10-17 23:23:39 +02:00
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
# include <signal.h>
|
|
|
|
# include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2012-04-12 09:26:02 +02:00
|
|
|
#ifdef HAVE_EXECINFO_H
|
2010-10-17 23:23:39 +02:00
|
|
|
static void bt_sighandler(int);
|
2012-04-12 09:26:02 +02:00
|
|
|
#endif
|
2010-10-17 23:23:39 +02:00
|
|
|
|
|
|
|
// Custom QApplication to catch and log exceptions properly
|
|
|
|
// See http://forum.qtfr.org/viewtopic.php?id=7615
|
|
|
|
class MyApplication : public QApplication
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyApplication(int argc, char **argv)
|
|
|
|
: QApplication(argc, argv)
|
|
|
|
{}
|
2008-09-07 15:17:39 +02:00
|
|
|
|
2010-10-17 23:23:39 +02:00
|
|
|
virtual bool notify(QObject *receiver, QEvent *event)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return QApplication::notify(receiver, event);
|
|
|
|
}
|
|
|
|
catch (const BaseException &e)
|
|
|
|
{
|
2011-01-30 00:47:20 +01:00
|
|
|
LOG_ROOT_ERROR("Exception caught: " << e.what() << "\n" << e.getStackTrace());
|
2010-10-17 23:23:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2008-09-07 15:17:39 +02:00
|
|
|
|
2008-01-20 19:40:12 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2010-10-17 23:23:39 +02:00
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
// Install a custom signal handler to print a backtrace when crashing
|
|
|
|
// See http://www.linuxjournal.com/article/6391 for inspiration
|
|
|
|
signal(SIGSEGV, &bt_sighandler);
|
|
|
|
#endif
|
|
|
|
|
2010-02-07 18:34:59 +01:00
|
|
|
// On Mac, running Eliot from the dock does not automatically set the LANG
|
|
|
|
// variable, so we do it ourselves.
|
|
|
|
// Note: The following block of code is copied from VLC, and slightly
|
|
|
|
// modified by me (original author: Pierre d'Herbemont)
|
|
|
|
#if defined(ENABLE_NLS) && defined(__APPLE__)
|
|
|
|
/* Check if $LANG is set. */
|
|
|
|
if (NULL == getenv("LANG"))
|
|
|
|
{
|
2011-01-30 00:47:20 +01:00
|
|
|
// Retrieve the preferred language as chosen in System Preferences.app
|
2010-02-07 18:34:59 +01:00
|
|
|
// (note that CFLocaleCopyCurrent() is not used because it returns the
|
|
|
|
// preferred locale not language)
|
|
|
|
CFArrayRef all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
|
|
|
|
CFArrayRef preferred_locales = CFBundleCopyLocalizationsForPreferences(all_locales, NULL);
|
|
|
|
|
|
|
|
if (preferred_locales)
|
|
|
|
{
|
|
|
|
if (CFArrayGetCount(preferred_locales))
|
|
|
|
{
|
|
|
|
char psz_locale[50];
|
|
|
|
CFStringRef user_language_string_ref = (CFStringRef) CFArrayGetValueAtIndex(preferred_locales, 0);
|
|
|
|
CFStringGetCString(user_language_string_ref, psz_locale, sizeof(psz_locale), kCFStringEncodingUTF8);
|
|
|
|
setenv("LANG", psz_locale, 1);
|
|
|
|
}
|
|
|
|
CFRelease(preferred_locales);
|
|
|
|
}
|
|
|
|
CFRelease(all_locales);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-09-03 19:28:27 +02:00
|
|
|
#ifdef HAVE_SETLOCALE
|
2008-01-20 19:40:12 +01:00
|
|
|
// Set locale via LC_ALL
|
|
|
|
setlocale(LC_ALL, "");
|
2010-02-07 18:34:59 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// FIXME: Ugly hack: we hardcode the encoding to UTF-8, because I don't
|
2010-02-12 19:16:57 +01:00
|
|
|
// know how to retrieve it properly when LANG is not set
|
2010-02-07 18:34:59 +01:00
|
|
|
setlocale(LC_CTYPE, "UTF-8");
|
|
|
|
#endif
|
2008-01-20 19:40:12 +01:00
|
|
|
#endif
|
|
|
|
|
2010-10-17 23:23:39 +02:00
|
|
|
MyApplication app(argc, argv);
|
2008-09-03 19:28:27 +02:00
|
|
|
app.setWindowIcon(QIcon(":/images/eliot.xpm"));
|
2012-02-02 09:02:20 +01:00
|
|
|
// Used for QSettings
|
|
|
|
app.setApplicationName(PACKAGE_NAME);
|
|
|
|
app.setOrganizationName("eliot");
|
2008-09-03 19:28:27 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
2008-01-20 19:40:12 +01:00
|
|
|
// Set the message domain
|
2008-09-05 23:31:30 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
// Get the absolute path, as returned by GetFullPathName()
|
2008-09-07 15:17:39 +02:00
|
|
|
char baseDir[MAX_PATH];
|
|
|
|
GetFullPathName(argv[0], MAX_PATH, baseDir, NULL);
|
|
|
|
char *pos = strrchr(baseDir, L'\\');
|
2008-09-05 23:31:30 +02:00
|
|
|
if (pos)
|
|
|
|
*pos = '\0';
|
2008-09-07 15:17:39 +02:00
|
|
|
const string localeDir = baseDir + string("\\locale");
|
2010-01-29 22:11:44 +01:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
const char *bundlePath = CFStringGetCStringPtr(CFURLCopyFileSystemPath(
|
|
|
|
CFBundleCopyBundleURL(CFBundleGetMainBundle()), kCFURLPOSIXPathStyle), CFStringGetSystemEncoding());
|
|
|
|
const string localeDir = string(bundlePath) + "/Contents/Resources/locale";
|
2008-09-05 23:31:30 +02:00
|
|
|
#else
|
2008-09-07 15:17:39 +02:00
|
|
|
static const string localeDir = LOCALEDIR;
|
2008-09-05 23:31:30 +02:00
|
|
|
#endif
|
2008-09-07 15:17:39 +02:00
|
|
|
bindtextdomain(PACKAGE, localeDir.c_str());
|
2010-02-12 19:16:57 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// Force messages to UTF-8
|
|
|
|
bind_textdomain_codeset(PACKAGE, "UTF-8");
|
|
|
|
#endif
|
2008-01-20 19:40:12 +01:00
|
|
|
textdomain(PACKAGE);
|
2008-09-03 19:28:27 +02:00
|
|
|
|
|
|
|
// Translations for Qt's own strings
|
|
|
|
QTranslator translator;
|
|
|
|
// Set the path for the translation file
|
2008-09-05 23:31:30 +02:00
|
|
|
#ifdef WIN32
|
2008-09-07 15:17:39 +02:00
|
|
|
QString path = QString(localeDir.c_str()) + "\\qt4";
|
2008-09-03 19:28:27 +02:00
|
|
|
#else
|
2008-09-05 23:31:30 +02:00
|
|
|
QString path = QString(QT4LOCALEDIR);
|
2008-09-03 19:28:27 +02:00
|
|
|
#endif
|
|
|
|
QString lang = QLocale::system().name();
|
2008-09-05 23:31:30 +02:00
|
|
|
translator.load(path + "/qt_" + lang);
|
2008-09-03 19:28:27 +02:00
|
|
|
app.installTranslator(&translator);
|
2008-01-20 19:40:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
MainWindow qmain;
|
|
|
|
qmain.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|
2010-10-17 23:23:39 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
static void bt_sighandler(int signum)
|
|
|
|
{
|
2011-01-30 00:47:20 +01:00
|
|
|
LOG_ROOT_FATAL("Segmentation fault!");
|
|
|
|
LOG_ROOT_FATAL("Backtrace:\n" << StackTrace::GetStack());
|
2010-10-17 23:23:39 +02:00
|
|
|
|
|
|
|
// Restore the default handler to generate a nice core dump
|
|
|
|
signal(signum, SIG_DFL);
|
|
|
|
raise(signum);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|