Esempio n. 1
0
int
main (int    argc,
      char **argv)
{
	GtkWidget      *window = NULL;
	GError         *error = NULL;
	GOptionContext *context;
	char           *dir, *description;
	int             result = EXIT_SUCCESS;
	
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	setlocale (LC_ALL, "");

	g_thread_init (NULL);

	gdk_threads_init ();
	gdk_threads_enter ();

	context = g_option_context_new (NULL);

	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));

	description = g_strdup_printf (_("Report errors (in English, with LC_ALL=C) to <%s>."), PACKAGE_BUGREPORT);
	g_option_context_set_summary (context, N_("Giggle is a graphical frontend for the git content tracker."));
	g_option_context_set_description (context, description);
	g_free (description);

	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		gchar *the_basename = g_filename_display_basename (argv[0]);

		g_printerr ("%s: %s\n", the_basename, error->message);
		g_printerr (_("Try `%s --help' for more information.\n"), the_basename);

		result = EXIT_FAILURE;
		g_free (the_basename);

		goto end;
	}
	/* Freing memory */
	g_option_context_free (context);

	gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), ICONDIR);

	if (g_file_test ("pixmaps", G_FILE_TEST_IS_DIR))
		gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), "pixmaps");

	if (version) {
		g_print ("%s %s, "
			 "Copyright (C) 2007-2008 Imendio AB, "
			 "Copyright (C) 2008 Mathias Hasselmann\n",
			 PACKAGE_NAME, PACKAGE_VERSION);

		goto end;
	}

	gtk_window_set_default_icon_name (PACKAGE);
	g_set_application_name ("Giggle");
	window = giggle_window_new ();

	/* Set dir to:
	    - the first remaining arg, or
	    - the value of GIT_DIR, or
	    - the current working dir */
	if (dirs && *dirs) {
		dir = g_strdup (*dirs);
		g_strfreev (dirs);
	} else {
		dir = g_strdup (g_getenv ("GIT_DIR"));
		if (dir == NULL) {
			dir = g_get_current_dir ();
		}
	}
	g_unsetenv ("GIT_DIR");

	if (clone_uri) {
		GtkWidget *clone_dialog;
		GtkResponseType response;
		gchar *clone_dir;

		clone_dir = g_strdup (dir);
		clone_dialog = giggle_clone_dialog_new (clone_uri, clone_dir);
		g_free (clone_dir);

		response = gtk_dialog_run (GTK_DIALOG (clone_dialog));
		if (response == GTK_RESPONSE_ACCEPT) {
			/* replace dir with the the newly cloned repo's one */
			g_free (dir);
			dir = g_strdup (giggle_clone_dialog_get_directory (GIGGLE_CLONE_DIALOG (clone_dialog)));
		}
		gtk_widget_destroy (clone_dialog);
	}

	if (giggle_git_test_dir (dir)) {
		giggle_window_set_directory (GIGGLE_WINDOW (window), dir);
	} else {
		gtk_widget_show (window);
	}
	g_free (dir);

	/* window will show itself when it reads its initial size configuration */
	if (diff_window)
		giggle_window_show_diff_window (GIGGLE_WINDOW (window));

	gtk_main ();

end:
	if (window)
		gtk_widget_destroy (window);

	gdk_threads_leave ();

	return result;
}
Esempio n. 2
0
int
main (int    argc,
      char **argv)
{
	GtkWidget      *window = NULL;
	GError         *error = NULL;
	GOptionContext *context;
	char           *dir, *description;
	int             result = EXIT_SUCCESS;
	
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	setlocale (LC_ALL, "");

	g_thread_init (NULL);

	gdk_threads_init ();
	gdk_threads_enter ();

 	context = g_option_context_new (N_("[DIRECTORY]"));

	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));

	description = g_strdup_printf (_("Report errors (in English, with LC_ALL=C) to <%s>."), PACKAGE_BUGREPORT);
	g_option_context_set_summary (context, N_("Giggle is a graphical frontend for the git content tracker."));
	g_option_context_set_description (context, description);
	g_free (description);

	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		char *basename = g_filename_display_basename (argv[0]);

		g_printerr ("%s: %s\n", basename, error->message);
		g_printerr (_("Try `%s --help' for more information.\n"), basename);

		result = EXIT_FAILURE;
		g_free (basename);

		goto end;
	}

	gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), ICONDIR);

	if (g_file_test ("pixmaps", G_FILE_TEST_IS_DIR))
		gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), "pixmaps");

	if (version) {
		g_print ("%s %s, "
			 "Copyright (C) 2007-2008 Imendio AB, "
			 "Copyright (C) 2008 Mathias Hasselmann\n",
			 PACKAGE_NAME, PACKAGE_VERSION);

		goto end;
	}

	gtk_window_set_default_icon_name (PACKAGE);
	g_set_application_name ("Giggle");
	window = giggle_window_new ();

	/* parse GIT_DIR into dir and unset it; if empty use the current_wd */
	dir = g_strdup (g_getenv ("GIT_DIR"));

	if (!dir || !*dir) {
		g_free (dir);

		if (argc > 1 && *argv[1]) {
			dir = g_strdup (argv[1]);
		} else {
			dir = g_get_current_dir ();
		}
	}

	g_unsetenv ("GIT_DIR");

	if (giggle_git_test_dir (dir)) {
		giggle_window_set_directory (GIGGLE_WINDOW (window), dir);
	} else {
		gtk_widget_show (window);
	}

	g_free (dir);

	/* window will show itself when it reads its initial size configuration */
	if (diff_window)
		giggle_window_show_diff_window (GIGGLE_WINDOW (window));

	gtk_main ();

end:
	if (window)
		gtk_widget_destroy (window);

	gdk_threads_leave ();

	return result;
}