Exemple #1
0
/* Initialize application data. */
static void
initialize_data (void)
{
	char *current_dir;
	char *path, *filename;
	int   i = 0;

	convert_to_new_comment_system ();
	create_default_categories_if_needed ();

	eel_gconf_monitor_add ("/apps/gthumb");

	gth_monitor = gth_monitor_new ();

	/* Icon theme */

	icon_theme = gtk_icon_theme_get_default ();
	g_signal_connect (icon_theme,
			  "changed",
			  G_CALLBACK (theme_changed_cb),
			  NULL);

	/* Default windows icon */

	init_icon_pixbufs ();
	g_set_application_name (_("gThumb"));
	gtk_window_set_default_icon_name ("gthumb");

	/**/

	init_session ("gthumb");
	if (session_is_restored ())
		return;

	/* Parse command line arguments. */

	if (remaining_args == NULL) { /* No arguments specified. */
		reset_command_line_catalog ();
		return;
	}

	current_dir = g_get_current_dir ();
	while ((filename = remaining_args[i++]) != NULL) {
		char     *tmp1 = NULL;
		gboolean  is_dir;

		if (uri_has_scheme (filename) || g_path_is_absolute (filename))
			tmp1 = gnome_vfs_make_uri_from_shell_arg (filename);
		else
			tmp1 = g_strconcat (current_dir, "/", filename, NULL);

		path = remove_special_dirs_from_path (tmp1);
		g_free (tmp1);

		if (path_is_dir (path))
			is_dir = TRUE;
		else if (path_is_file (path))
			is_dir = FALSE;
		else {
			g_free (path);
			continue;
		}

		if (is_dir) {
			dir_urls = g_list_prepend (dir_urls, add_scheme_if_absent (path));
			g_free (path);
		} 
		else
			file_urls = g_list_prepend (file_urls, path);
	}

	n_file_urls = g_list_length (file_urls);
	n_dir_urls = g_list_length (dir_urls);

	if (n_file_urls == 1)
		view_single_image = TRUE;

	if (n_file_urls > 1) {
		/* Create a catalog with the command line list. */
		Catalog *catalog;
		char    *catalog_path;
		GList   *scan;

		catalog = catalog_new ();
		catalog_path = get_command_line_catalog_path ();
		catalog_set_path (catalog, catalog_path);
		g_free (catalog_path);

		for (scan = file_urls; scan; scan = scan->next)
			catalog_add_item (catalog, scan->data);

		catalog->sort_method = GTH_SORT_METHOD_MANUAL;

		catalog_write_to_disk (catalog, NULL);
		catalog_free (catalog);

		view_comline_catalog = TRUE;
	}
	else
		reset_command_line_catalog ();

	g_free (current_dir);
}
int
main (int argc, char **argv)
{
    GnomeVFSResult result;
    char *text_uri;
    GnomeVFSURI *src, *dest;
    GnomeVFSFileInfo *info;

    if (argc != 3) {
        printf ("Usage: %s <src> <dest>\n", argv[0]);
        return 1;
    }

    if (!gnome_vfs_init ()) {
        fprintf (stderr, "Cannot initialize gnome-vfs.\n");
        return 1;
    }

    command_line_authentication_init ();

    text_uri = gnome_vfs_make_uri_from_shell_arg (argv[1]);

    src = gnome_vfs_uri_new (text_uri);
    g_free (text_uri);

    text_uri = gnome_vfs_make_uri_from_shell_arg (argv[2]);

    dest = gnome_vfs_uri_new (text_uri);
    g_free (text_uri);

    if (src == NULL || dest == NULL) {
        result = GNOME_VFS_ERROR_INVALID_URI;
        goto out;
    }

    info   = gnome_vfs_file_info_new ();
    result = gnome_vfs_get_file_info_uri (dest, info,
                                          GNOME_VFS_FILE_INFO_DEFAULT);

    if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_NOT_FOUND) {
        gnome_vfs_file_info_unref (info);
        goto out;
    }

    /* If the target is a directory do not overwrite it but copy the
       source into the directory! (This is like cp does it) */
    if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
            info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
        char *name;
        GnomeVFSURI *new_dest;

        name     = gnome_vfs_uri_extract_short_path_name (src);
        new_dest = gnome_vfs_uri_append_string (dest, name);
        gnome_vfs_uri_unref (dest);
        g_free (name);
        dest = new_dest;

    }

    gnome_vfs_file_info_unref (info);

    result = gnome_vfs_xfer_uri (src, dest,
                                 GNOME_VFS_XFER_RECURSIVE,
                                 GNOME_VFS_XFER_ERROR_MODE_ABORT,
                                 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
                                 NULL, NULL);

out:
    if (src) {
        gnome_vfs_uri_unref (src);
    }

    if (dest) {
        gnome_vfs_uri_unref (dest);
    }

    if (result != GNOME_VFS_OK) {
        fprintf (stderr, "Failed to copy %s to %s\nReason: %s\n",
                 argv[1], argv[2], gnome_vfs_result_to_string (result));
        return 1;
    }

    return 0;
}