Blame synfig-studio/src/gui/main.cpp

Carlos Lopez a09598
/* === S Y N F I G ========================================================= */
Carlos Lopez a09598
/*!	\file gtkmm/main.cpp
Carlos Lopez a09598
**	\brief Synfig Studio Entrypoint
Carlos Lopez a09598
**
Carlos Lopez a09598
**	$Id$
Carlos Lopez a09598
**
Carlos Lopez a09598
**	\legal
Carlos Lopez a09598
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Carlos Lopez a09598
**	Copyright (c) 2007, 2008 Chris Moore
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is free software; you can redistribute it and/or
Carlos Lopez a09598
**	modify it under the terms of the GNU General Public License as
Carlos Lopez a09598
**	published by the Free Software Foundation; either version 2 of
Carlos Lopez a09598
**	the License, or (at your option) any later version.
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is distributed in the hope that it will be useful,
Carlos Lopez a09598
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez a09598
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez a09598
**	General Public License for more details.
Carlos Lopez a09598
**	\endlegal
Carlos Lopez a09598
*/
Carlos Lopez a09598
/* ========================================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === H E A D E R S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
#ifdef USING_PCH
Carlos Lopez a09598
#	include "pch.h"
Carlos Lopez a09598
#else
Carlos Lopez a09598
#ifdef HAVE_CONFIG_H
Carlos Lopez a09598
#	include <config.h></config.h>
Carlos Lopez a09598
#endif
Carlos Lopez a09598
bw 94d8a6
#include <synfig general.h=""></synfig>
bw 94d8a6
Carlos Lopez a09598
#include "app.h"
Carlos Lopez a09598
#include <iostream></iostream>
Carlos Lopez a09598
#include "ipc.h"
Carlos Lopez a09598
#include <stdexcept></stdexcept>
Carlos Lopez a09598
abdbf2
#include <gui localization.h=""></gui>
c55bbc
#include <glibmm convert.h=""></glibmm>
Carlos Lopez a09598
10a93e
#ifdef _WIN32
da71a8
#include "main_win32.h"
c90f29
#endif
c90f29
Carlos Lopez a09598
#endif
Carlos Lopez a09598
Carlos Lopez a09598
/* === U S I N G =========================================================== */
Carlos Lopez a09598
Carlos Lopez a09598
using namespace std;
Carlos Lopez a09598
using namespace etl;
Carlos Lopez a09598
using namespace synfig;
Carlos Lopez a09598
using namespace studio;
Carlos Lopez a09598
Carlos Lopez a09598
/* === M A C R O S ========================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === G L O B A L S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === P R O C E D U R E S ================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === M E T H O D S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === E N T R Y P O I N T ================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
int main(int argc, char **argv)
Carlos Lopez a09598
{
de63b6
10a93e
#ifdef _WIN32
da71a8
	if (consoleOptionEnabled(argc, argv))
da71a8
	{
da71a8
		redirectIOToConsole();
da71a8
	}
de63b6
	else
de63b6
	{
de63b6
		// QuickHack: to avoid strange bug with stderr
de63b6
		freopen("NUL", "w", stdout);
de63b6
		freopen("NUL", "w", stderr);
de63b6
		freopen("NUL", "r", stdin);
de63b6
		ios::sync_with_stdio();
de63b6
	}
da71a8
#endif
Carlos Lopez a09598
091b41
	String binary_path = synfig::get_binary_path(String(argv[0]));
e88995
	
e88995
#ifdef ENABLE_NLS
873d31
	String locale_dir;
091b41
	locale_dir = etl::dirname(etl::dirname(binary_path))+ETL_DIRECTORY_SEPARATOR+"share"+ETL_DIRECTORY_SEPARATOR+"locale";
Carlos Lopez a09598
	setlocale(LC_ALL, "");
c55bbc
	bindtextdomain(GETTEXT_PACKAGE,  Glib::locale_from_utf8(locale_dir).c_str() );
0bdb5b
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
0bdb5b
	textdomain(GETTEXT_PACKAGE);
Carlos Lopez a09598
#endif
Carlos Lopez a09598
	{
Carlos Lopez a09598
		SmartFILE file(IPC::make_connection());
Carlos Lopez a09598
		if(file)
Carlos Lopez a09598
		{
Carlos Lopez a09598
			cout << endl;
Carlos Lopez a09598
			cout << "   " << _("synfig studio is already running") << endl << endl;
Rodolfo Ribeiro Gomes 0f2e3e
			cout << "   " << _("the existing process will be used") << endl << endl;
Carlos Lopez a09598
Carlos Lopez a09598
			// Hey, another copy of us is open!
Carlos Lopez a09598
			// don't bother opening us, just go ahead and
Carlos Lopez a09598
			// tell the other copy to load it all up
Carlos Lopez a09598
			if (argc>1)
Carlos Lopez a09598
				fprintf(file.get(),"F\n");
Carlos Lopez a09598
Carlos Lopez a09598
			while(--argc)
Carlos Lopez a09598
				if((argv)[argc] && (argv)[argc][0]!='-')
Carlos Lopez a09598
					fprintf(file.get(),"O %s\n",etl::absolute_path((argv)[argc]).c_str());
Carlos Lopez a09598
Carlos Lopez a09598
			fprintf(file.get(),"F\n");
Carlos Lopez a09598
Carlos Lopez a09598
			return 0;
Carlos Lopez a09598
		}
Carlos Lopez a09598
	}
Carlos Lopez a09598
Carlos Lopez a09598
	cout << endl;
Carlos Lopez a09598
	cout << "   " << _("synfig studio -- starting up application...") << endl << endl;
Carlos Lopez a09598
Carlos Lopez a09598
	try
Carlos Lopez a09598
	{
ac3d4b
		studio::App app(etl::dirname(binary_path), &argc, &argv);
Carlos Lopez a09598
Carlos Lopez a09598
		app.run();
Carlos Lopez a09598
	}
Carlos Lopez a09598
	catch(int ret)
Carlos Lopez a09598
	{
Carlos Lopez a09598
		std::cerr<<"Application shutdown with errors ("<
Carlos Lopez a09598
		return ret;
Carlos Lopez a09598
	}
4a958f
	catch(string& str)
Carlos Lopez a09598
	{
Carlos Lopez ac6eb5
		std::cerr<<"Uncaught Exception:string: "<
Carlos Lopez a09598
		throw;
Carlos Lopez a09598
	}
4a958f
	catch(std::exception& x)
Carlos Lopez a09598
	{
Carlos Lopez a09598
		std::cerr<<"Standard Exception: "<
Carlos Lopez a09598
		throw;
Carlos Lopez a09598
	}
Carlos Lopez a09598
	catch(Glib::Exception& x)
Carlos Lopez a09598
	{
Carlos Lopez a09598
		std::cerr<<"GLib Exception: "<
Carlos Lopez a09598
		throw;
Carlos Lopez a09598
	}
Carlos Lopez a09598
	catch(...)
Carlos Lopez a09598
	{
Carlos Lopez a09598
		std::cerr<<"Uncaught Exception"<
Carlos Lopez a09598
		throw;
Carlos Lopez a09598
	}
Carlos Lopez a09598
Carlos Lopez a09598
	std::cerr<<"Application appears to have terminated successfully"<
Carlos Lopez a09598
Carlos Lopez a09598
	return 0;
Carlos Lopez a09598
}