2010-09-13 19:24:53 +02:00
|
|
|
/*
|
2010-09-17 19:03:03 +02:00
|
|
|
* logdiag.c -- logdiag main source file.
|
2010-09-13 19:24:53 +02:00
|
|
|
*
|
|
|
|
* This file is a part of logdiag.
|
2017-02-03 23:06:48 +01:00
|
|
|
* Copyright Přemysl Janouch 2010, 2011
|
2010-09-13 19:24:53 +02:00
|
|
|
*
|
|
|
|
* See the file LICENSE for licensing information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2011-02-12 02:07:39 +01:00
|
|
|
#include <locale.h>
|
2010-09-13 19:24:53 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-09-17 19:03:03 +02:00
|
|
|
#include "ld-window-main.h"
|
2010-09-13 19:24:53 +02:00
|
|
|
|
|
|
|
|
2011-06-10 14:52:22 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_utf8_args:
|
|
|
|
* @argc: where the number of arguments will be stored.
|
|
|
|
* @argv: where the actual array of arguments will be stored.
|
|
|
|
* Use g_strfreev() to free the array.
|
|
|
|
*
|
|
|
|
* Retrieve program arguments in UTF-8 encoding on Windows.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the function has succeeded.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
get_utf8_args (int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
LPWSTR *argv_wide;
|
|
|
|
int i, argc_local, buff_size;
|
|
|
|
char **argv_local, *arg;
|
|
|
|
|
|
|
|
argv_wide = CommandLineToArgvW (GetCommandLineW (), &argc_local);
|
|
|
|
if (!argv_wide)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
argv_local = g_malloc ((argc_local + 1) * sizeof (char *));
|
|
|
|
for (i = 0; i < argc_local; i++)
|
|
|
|
{
|
|
|
|
buff_size = WideCharToMultiByte (CP_UTF8, 0, argv_wide[i], -1,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
if (!buff_size)
|
|
|
|
goto get_utf8_args_fail;
|
|
|
|
|
|
|
|
argv_local[i] = g_malloc (buff_size);
|
|
|
|
if (!WideCharToMultiByte (CP_UTF8, 0, argv_wide[i], -1,
|
|
|
|
argv_local[i], buff_size, NULL, NULL))
|
|
|
|
{
|
|
|
|
g_free (argv_local[i]);
|
|
|
|
goto get_utf8_args_fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argv_local[i] = NULL;
|
|
|
|
LocalFree (argv_wide);
|
|
|
|
|
|
|
|
if (argc)
|
|
|
|
*argc = argc_local;
|
|
|
|
if (argv)
|
|
|
|
*argv = argv_local;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
get_utf8_args_fail:
|
|
|
|
while (i--)
|
|
|
|
g_free (argv_local[i]);
|
|
|
|
g_free (argv_local);
|
|
|
|
|
|
|
|
LocalFree (argv_wide);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-09 18:03:28 +02:00
|
|
|
static gint ld_active_windows = 0;
|
|
|
|
|
|
|
|
static void
|
2015-01-19 02:23:20 +01:00
|
|
|
window_on_destroyed (GtkWidget *object, gpointer user_data)
|
2012-10-09 18:03:28 +02:00
|
|
|
{
|
|
|
|
if (--ld_active_windows <= 0)
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_create (const gchar *file)
|
|
|
|
{
|
|
|
|
GtkWidget *wm;
|
|
|
|
|
|
|
|
wm = ld_window_main_new (file);
|
|
|
|
g_signal_connect (wm, "destroy", G_CALLBACK (window_on_destroyed), NULL);
|
|
|
|
ld_active_windows++;
|
|
|
|
}
|
|
|
|
|
2010-12-16 05:18:41 +01:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
2012-10-09 18:03:28 +02:00
|
|
|
gchar **iter, **files = NULL;
|
2011-06-10 14:51:42 +02:00
|
|
|
GOptionEntry option_entries[] =
|
|
|
|
{
|
|
|
|
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
|
2012-10-09 18:03:28 +02:00
|
|
|
NULL, N_("[FILE...]")},
|
2011-06-10 14:51:42 +02:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2011-02-13 20:41:11 +01:00
|
|
|
GError *error;
|
2011-02-13 21:14:24 +01:00
|
|
|
#ifdef _WIN32
|
2011-06-10 14:52:22 +02:00
|
|
|
gboolean argv_overriden;
|
2011-02-13 21:14:24 +01:00
|
|
|
gchar *install_dir;
|
|
|
|
|
|
|
|
install_dir = g_win32_get_package_installation_directory_of_module (NULL);
|
|
|
|
if (install_dir)
|
|
|
|
{
|
|
|
|
g_chdir (install_dir);
|
|
|
|
g_free (install_dir);
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-13 19:24:53 +02:00
|
|
|
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
|
|
|
bindtextdomain (GETTEXT_DOMAIN, GETTEXT_DIRNAME);
|
2011-01-09 05:40:25 +01:00
|
|
|
bind_textdomain_codeset (GETTEXT_DOMAIN, "UTF-8");
|
2010-09-13 19:24:53 +02:00
|
|
|
textdomain (GETTEXT_DOMAIN);
|
|
|
|
|
2012-04-17 10:29:14 +02:00
|
|
|
#ifdef PROJECT_GSETTINGS_DIR
|
|
|
|
/* This is enabled when the build is set up for developing, so that the
|
|
|
|
* application can find its schema. It might also find use when
|
|
|
|
* installing the application into a location that's missing from
|
|
|
|
* g_get_system_data_dirs(), for example /usr/local or ~/.local.
|
|
|
|
*/
|
|
|
|
g_setenv ("GSETTINGS_SCHEMA_DIR", PROJECT_GSETTINGS_DIR, 0);
|
|
|
|
#endif /* PROJECT_GSETTINGS_DIR */
|
|
|
|
|
2011-06-10 14:52:22 +02:00
|
|
|
#ifdef _WIN32
|
2011-06-10 14:52:53 +02:00
|
|
|
/* Don't be unneccessarily limited by the system ANSI codepage. */
|
2011-06-10 14:52:22 +02:00
|
|
|
argv_overriden = get_utf8_args (&argc, &argv);
|
|
|
|
if (argv_overriden)
|
|
|
|
_putenv ("CHARSET=UTF-8");
|
|
|
|
#endif
|
|
|
|
|
2011-02-13 20:41:11 +01:00
|
|
|
error = NULL;
|
2011-06-10 14:51:42 +02:00
|
|
|
gtk_init_with_args (&argc, &argv, N_("- Schematic editor"),
|
|
|
|
option_entries, GETTEXT_DOMAIN, &error);
|
2011-02-13 20:41:11 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-10 14:52:22 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (argv_overriden)
|
|
|
|
{
|
|
|
|
_putenv ("CHARSET=");
|
|
|
|
g_strfreev (argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-16 16:46:48 +01:00
|
|
|
gtk_window_set_default_icon_name (PROJECT_NAME);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2011-06-10 14:51:42 +02:00
|
|
|
if (files)
|
2011-02-19 23:21:14 +01:00
|
|
|
{
|
2012-10-09 18:03:28 +02:00
|
|
|
for (iter = files; *iter; iter++)
|
|
|
|
window_create (*iter);
|
2011-06-10 14:51:42 +02:00
|
|
|
g_strfreev (files);
|
2011-02-19 23:21:14 +01:00
|
|
|
}
|
2011-06-10 14:51:42 +02:00
|
|
|
else
|
2012-10-09 18:03:28 +02:00
|
|
|
window_create (NULL);
|
2011-02-19 13:22:06 +01:00
|
|
|
|
|
|
|
gtk_main ();
|
2010-09-13 19:24:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|