示例#1
0
/* Session */
gboolean
ev_application_load_session (EvApplication *application)
{
	GKeyFile *state_file;
	gchar    *uri;

#ifdef WITH_SMCLIENT
	if (egg_sm_client_is_resumed (application->smclient)) {
		state_file = egg_sm_client_get_state_file (application->smclient);
		if (!state_file)
			return FALSE;
	} else
#endif /* WITH_SMCLIENT */
		return FALSE;

	uri = g_key_file_get_string (state_file, "Atril", "uri", NULL);
	if (!uri)
		return FALSE;

	ev_application_open_uri_at_dest (application, uri,
					 gdk_screen_get_default (),
					 NULL, 0, NULL,
					 GDK_CURRENT_TIME);
	g_free (uri);
	g_key_file_free (state_file);

	return TRUE;
}
static PyObject *
_wrap_egg_sm_client_is_resumed(PyGObject *self)
{
    int ret;

    
    ret = egg_sm_client_is_resumed(EGG_SM_CLIENT(self->obj));
    
    return PyBool_FromLong(ret);

}
示例#3
0
int
main (int argc, char *argv[])
{
    gboolean kill_shell;
    gboolean no_default_window;
    gboolean browser_window;
    gboolean no_desktop;
    gboolean version;
    gboolean autostart_mode;
    const char *autostart_id;
    gchar *geometry;
    gchar **remaining;
    gboolean perform_self_check;
    CajaApplication *application;
    GOptionContext *context;
    GFile *file = NULL;
    GFileInfo *fileinfo = NULL;
    GAppInfo *appinfo = NULL;
    char *uri = NULL;
    char **uris = NULL;
    GPtrArray *uris_array;
    GError *error;
    int i;

    const GOptionEntry options[] =
    {
#ifndef CAJA_OMIT_SELF_CHECK
        {
            "check", 'c', 0, G_OPTION_ARG_NONE, &perform_self_check,
            N_("Perform a quick set of self-check tests."), NULL
        },
#endif
        {
            "version", '\0', 0, G_OPTION_ARG_NONE, &version,
            N_("Show the version of the program."), NULL
        },
        {
            "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry,
            N_("Create the initial window with the given geometry."), N_("GEOMETRY")
        },
        {
            "no-default-window", 'n', 0, G_OPTION_ARG_NONE, &no_default_window,
            N_("Only create windows for explicitly specified URIs."), NULL
        },
        {
            "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop,
            N_("Do not manage the desktop (ignore the preference set in the preferences dialog)."), NULL
        },
        {
            "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window,
            N_("open a browser window."), NULL
        },
        {
            "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell,
            N_("Quit Caja."), NULL
        },
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL,  N_("[URI...]") },

        { NULL }
    };

#if defined (HAVE_MALLOPT) && defined(M_MMAP_THRESHOLD)
    /* Caja uses lots and lots of small and medium size allocations,
     * and then a few large ones for the desktop background. By default
     * glibc uses a dynamic treshold for how large allocations should
     * be mmaped. Unfortunately this triggers quickly for caja when
     * it does the desktop background allocations, raising the limit
     * such that a lot of temporary large allocations end up on the
     * heap and are thus not returned to the OS. To fix this we set
     * a hardcoded limit. I don't know what a good value is, but 128K
     * was the old glibc static limit, lets use that.
     */
    mallopt (M_MMAP_THRESHOLD, 128 *1024);
#endif

    g_thread_init (NULL);

    /* This will be done by gtk+ later, but for now, force it to MATE */
    g_desktop_app_info_set_desktop_env ("MATE");

    if (g_getenv ("CAJA_DEBUG") != NULL)
    {
        eel_make_warnings_and_criticals_stop_in_debugger ();
    }

    /* Initialize gettext support */
    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    autostart_mode = FALSE;

    autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
    if (autostart_id != NULL && *autostart_id != '\0')
    {
        autostart_mode = TRUE;
    }

    /* Get parameters. */
    remaining = NULL;
    geometry = NULL;
    version = FALSE;
    kill_shell = FALSE;
    no_default_window = FALSE;
    no_desktop = FALSE;
    perform_self_check = FALSE;
    browser_window = FALSE;

    g_set_prgname ("caja");

    if (g_file_test (DATADIR "/applications/caja.desktop", G_FILE_TEST_EXISTS))
    {
        egg_set_desktop_file (DATADIR "/applications/caja.desktop");
    }

    context = g_option_context_new (_("\n\nBrowse the file system with the file manager"));
    g_option_context_add_main_entries (context, options, NULL);

    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_add_group (context, egg_sm_client_get_option_group ());

    error = NULL;
    if (!g_option_context_parse (context, &argc, &argv, &error))
    {
        g_printerr ("Could not parse arguments: %s\n", error->message);
        g_error_free (error);
        return 1;
    }

    g_option_context_free (context);

    if (version)
    {
        g_print ("MATE caja " PACKAGE_VERSION "\n");
        return 0;
    }

#ifdef HAVE_EXEMPI
    xmp_init();
#endif

    setup_debug_log ();

    /* If in autostart mode (aka started by mate-session), we need to ensure
         * caja starts with the correct options.
         */
    if (autostart_mode)
    {
        no_default_window = TRUE;
        no_desktop = FALSE;
    }

    if (perform_self_check && remaining != NULL)
    {
        /* translators: %s is an option (e.g. --check) */
        fprintf (stderr, _("caja: %s cannot be used with URIs.\n"),
                 "--check");
        return EXIT_FAILURE;
    }
    if (perform_self_check && kill_shell)
    {
        fprintf (stderr, _("caja: --check cannot be used with other options.\n"));
        return EXIT_FAILURE;
    }
    if (kill_shell && remaining != NULL)
    {
        fprintf (stderr, _("caja: %s cannot be used with URIs.\n"),
                 "--quit");
        return EXIT_FAILURE;
    }
    if (geometry != NULL && remaining != NULL && remaining[0] != NULL && remaining[1] != NULL)
    {
        fprintf (stderr, _("caja: --geometry cannot be used with more than one URI.\n"));
        return EXIT_FAILURE;
    }

    /* Initialize the services that we use. */
    LIBXML_TEST_VERSION

    /* Initialize preferences. This is needed so that proper
     * defaults are available before any preference peeking
     * happens.
     */
    caja_global_preferences_init ();

    /* exit_with_last_window being FALSE, caja can run without window. */
    exit_with_last_window = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_EXIT_WITH_LAST_WINDOW);

    application = NULL;

    /* Do either the self-check or the real work. */
    if (perform_self_check)
    {
		#ifndef CAJA_OMIT_SELF_CHECK
			/* Run the checks (each twice) for caja and libcaja-private. */

			caja_run_self_checks ();
			caja_run_lib_self_checks ();
			eel_exit_if_self_checks_failed ();

			caja_run_self_checks ();
			caja_run_lib_self_checks ();
			eel_exit_if_self_checks_failed ();
		#endif
    }
    else
    {
        /* Convert args to URIs */
        if (remaining != NULL)
        {
            uris_array = g_ptr_array_new ();
            for (i = 0; remaining[i] != NULL; i++)
            {
                file = g_file_new_for_commandline_arg (remaining[i]);
                if (file != NULL)
                {
                    uri = g_file_get_uri (file);
                    if (uri)
                    {
                        fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
                        if (fileinfo && g_file_info_get_file_type(fileinfo) == G_FILE_TYPE_DIRECTORY)
                        {
                            g_ptr_array_add (uris_array, uri);
                        }
                        else
                        {
                            if (fileinfo)
                                g_object_unref (fileinfo);
                            fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
                            if (fileinfo)
                            {
                                appinfo = g_app_info_get_default_for_type (g_file_info_get_content_type (fileinfo), TRUE);
                                if (appinfo)
                                {
                                    if (g_strcmp0 (g_app_info_get_executable (appinfo), "caja") != 0)
                                    {
                                        g_app_info_launch_default_for_uri (uri, NULL, NULL);
                                    }
                                    else
                                    {
                                        fprintf (stderr, _("caja: set erroneously as default application for '%s' content type.\n"),
                                                 g_file_info_get_content_type (fileinfo));
                                    }
                                    g_object_unref (appinfo);
                                }
                                g_free (uri);
                            }
                            else
                            {
                                g_ptr_array_add (uris_array, uri);
                            }
                        }
                        if (fileinfo)
                            g_object_unref (fileinfo);
                    }
                    if (file)
                        g_object_unref (file);
                }
            }
            if (uris_array->len == 0)
            {
                /* Caja is being used only to open files (not directories), so closing */
                g_strfreev (remaining);
                return EXIT_SUCCESS;
            }
            g_ptr_array_add (uris_array, NULL);
            uris = (char**) g_ptr_array_free (uris_array, FALSE);
            g_strfreev (remaining);
        }


        /* Run the caja application. */
        application = caja_application_new ();

        if (egg_sm_client_is_resumed (application->smclient))
        {
            no_default_window = TRUE;
        }

        caja_application_startup
        (application,
         kill_shell, no_default_window, no_desktop,
         browser_window,
         geometry,
         uris);
        g_strfreev (uris);

        if (unique_app_is_running (application->unique_app) ||
                kill_shell)
        {
            exit_with_last_window = TRUE;
        }

        if (is_event_loop_needed ())
        {
            gtk_main ();
        }
    }

    caja_icon_info_clear_caches ();

    if (application != NULL)
    {
        g_object_unref (application);
    }

    eel_debug_shut_down ();

    caja_application_save_accel_map (NULL);

    return EXIT_SUCCESS;
}
示例#4
0
static int
fr_application_command_line (GApplication            *application,
                             GApplicationCommandLine *command_line)
{
	char           **argv;
	int              argc;
	GOptionContext  *context;
	GError          *error = NULL;
	GFile           *extraction_destination = NULL;
	GFile           *add_to_archive = NULL;
	GFile           *default_directory = NULL;

	argv = g_application_command_line_get_arguments (command_line, &argc);

	/* parse command line options */

	context = fr_application_create_option_context ();
	if (! g_option_context_parse (context, &argc, &argv, &error)) {
		g_critical ("Failed to parse arguments: %s", error->message);
		g_error_free (error);
		g_option_context_free (context);

		return fr_application_command_line_finished (application, EXIT_FAILURE);
	}
	g_option_context_free (context);

	/* restore the session */

#ifdef USE_SMCLIENT
	{
		EggSMClient *client;

		client = egg_sm_client_get ();
		g_signal_connect (client,
				  "save_state",
				  G_CALLBACK (client_save_state),
				  NULL);
		g_signal_connect (client,
				  "quit",
				  G_CALLBACK (client_quit_cb),
				  NULL);
		if (egg_sm_client_is_resumed (client)) {
			fr_restore_session (client);
			return fr_application_command_line_finished (application, EXIT_SUCCESS);
		}
	}
#endif

	if (remaining_args == NULL) { /* No archive specified. */
		if (! arg_service)
			gtk_widget_show (fr_window_new ());
		return fr_application_command_line_finished (application, EXIT_SUCCESS);
	}

	if (arg_extract_to != NULL)
		extraction_destination = g_file_new_for_commandline_arg (arg_extract_to);

	if (arg_add_to != NULL)
		add_to_archive = g_file_new_for_commandline_arg (arg_add_to);

	if (arg_default_dir != NULL)
		default_directory = g_file_new_for_commandline_arg (arg_default_dir);

	if ((arg_add_to != NULL) || (arg_add == 1)) { /* Add files to an archive */
		GtkWidget   *window;
		GList       *file_list;
		const char  *filename;
		int          i = 0;

		window = fr_window_new ();

		if (default_directory != NULL)
			fr_window_set_default_dir (FR_WINDOW (window), default_directory, TRUE);

		file_list = NULL;
		while ((filename = remaining_args[i++]) != NULL)
			file_list = g_list_prepend (file_list, g_file_new_for_commandline_arg (filename));
		file_list = g_list_reverse (file_list);

		fr_window_new_batch (FR_WINDOW (window), _("Compress"));
		fr_window_set_batch__add (FR_WINDOW (window), add_to_archive, file_list);

		if (! arg_notify)
			fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		else
			fr_window_set_notify (FR_WINDOW (window), TRUE);
		fr_window_start_batch (FR_WINDOW (window));

		_g_object_list_unref (file_list);
	}
	else if ((arg_extract_to != NULL) || (arg_extract == 1) || (arg_extract_here == 1)) {

		/* Extract all archives. */

		GtkWidget  *window;
		const char *archive;
		int         i = 0;

		window = fr_window_new ();

		if (default_directory != NULL)
			fr_window_set_default_dir (FR_WINDOW (window), default_directory, TRUE);

		fr_window_new_batch (FR_WINDOW (window), _("Extract archive"));
		while ((archive = remaining_args[i++]) != NULL) {
			GFile *file;

			file = g_file_new_for_commandline_arg (archive);
			if (arg_extract_here == 1)
				fr_window_set_batch__extract_here (FR_WINDOW (window), file);
			else
				fr_window_set_batch__extract (FR_WINDOW (window), file, extraction_destination);

			g_object_unref (file);
		}
		if (! arg_notify)
			fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		else
			fr_window_set_notify (FR_WINDOW (window), TRUE);

		fr_window_start_batch (FR_WINDOW (window));
	}
	else { /* Open each archive in a window */
		const char *filename = NULL;

		int i = 0;
		while ((filename = remaining_args[i++]) != NULL) {
			GtkWidget *window;
			GFile     *file;

			window = fr_window_new ();
			gtk_widget_show (window);

			file = g_file_new_for_commandline_arg (filename);
			fr_window_archive_open (FR_WINDOW (window), file, GTK_WINDOW (window));

			g_object_unref (file);
		}
	}

	_g_object_unref (default_directory);
	_g_object_unref (add_to_archive);
	_g_object_unref (extraction_destination);

	return fr_application_command_line_finished (application, EXIT_SUCCESS);
}