예제 #1
0
파일: main.c 프로젝트: ChingezKhan/gthumb
GdkPixbuf *
get_icon_for_uri (GtkWidget  *widget,
		  const char *uri)
{
	const char *stock_id = NULL;
	int         menu_size;

	menu_size = get_folder_pixbuf_size_for_list (widget);

	if (strcmp (uri, g_get_home_dir ()) == 0)
		return get_fs_icon (ICON_NAME_HOME, menu_size);
	else if (strcmp (uri, get_home_uri ()) == 0)
		return get_fs_icon (ICON_NAME_HOME, menu_size);

	if ((strcmp (uri, "file://") == 0) || (strcmp (uri, "/") == 0))
		return get_fs_icon (ICON_NAME_HARDDISK, menu_size);

	if (folder_is_film (uri))
		stock_id = GTHUMB_STOCK_FILM;
	else if (uri_scheme_is_catalog (uri)) {
		if (file_extension_is (uri, CATALOG_EXT))
			stock_id = GTHUMB_STOCK_CATALOG;
		else
			stock_id = GTHUMB_STOCK_LIBRARY;
	}
	else if (uri_scheme_is_search (uri))
		stock_id = GTHUMB_STOCK_SEARCH;

	if (stock_id != NULL)
		return gtk_widget_render_icon (widget, stock_id, GTK_ICON_SIZE_MENU, NULL);
	else
		return get_fs_icon (ICON_NAME_DIRECTORY, menu_size);
}
/* when on Automatic the user provided extension needs to be supported,
   otherwise an existing unsupported archive can be deleted (if the user
   provided name matches with its name) before we find out that the
   archive is unsupported
*/
static gboolean
is_supported_extension (GtkWidget *file_sel,
			char      *filename,
			int       *file_type)
{
	int i;
	for (i = 0; file_type[i] != -1; i++)
		if (file_extension_is (filename, mime_type_desc[file_type[i]].default_ext))
			return TRUE;
	return FALSE;
}
static void
fr_command_jar_add (FrCommand     *comm,
		    const char    *from_file,
		    GList         *file_list,
		    const char    *base_dir,
		    gboolean       update,
		    gboolean       recursive)
{
	FrProcess *proc = comm->process;
	GList     *zip_list = NULL, *jardata_list = NULL, *jar_list = NULL;
	GList     *scan;
	char      *tmp_dir;

	for (scan = file_list; scan; scan = scan->next) {
		char *filename = scan->data;
		char *path = build_uri (base_dir, filename, NULL);
		char *package = NULL;

		if (file_extension_is (filename, ".java"))
			package = get_package_name_from_java_file (path);
		else if (file_extension_is (filename, ".class"))
			package = get_package_name_from_class_file (path);

		if ((package == NULL) || (strlen (package) == 0))
			zip_list = g_list_append (zip_list, g_strdup (filename));
		else {
			JarData *newdata = g_new0 (JarData, 1);

			newdata->package_minus_one_level = remove_level_from_path (package);
			newdata->link_name = g_strdup (file_name_from_path (package));
			newdata->rel_path = remove_level_from_path (filename);
			newdata->filename = g_strdup (file_name_from_path (filename));
			jardata_list = g_list_append (jardata_list, newdata);
		}

		g_free (package);
		g_free (path);
	}

	tmp_dir = get_temp_work_dir (NULL);
	for (scan = jardata_list; scan ; scan = scan->next) {
		JarData *jdata = scan->data;
		char    *pack_path;
		char    *old_link;
		char    *link_name;
		int      retval;

		pack_path = build_uri (tmp_dir, jdata->package_minus_one_level, NULL);
		if (! make_directory_tree_from_path (pack_path, 0755, NULL)) {
			g_free (pack_path);
			continue;
		}

		old_link = build_uri (base_dir, jdata->rel_path, NULL);
		link_name = g_build_filename (pack_path, jdata->link_name, NULL);

		retval = symlink (old_link, link_name);
		if ((retval != -1) || (errno == EEXIST))
			jar_list = g_list_append (jar_list,
						  g_build_filename (jdata->package_minus_one_level,
							            jdata->link_name,
						      	            jdata->filename,
						      	            NULL));

		g_free (link_name);
		g_free (old_link);
		g_free (pack_path);
	}

	if (zip_list != NULL)
		parent_class->add (comm, NULL, zip_list, base_dir, update, FALSE);

	if (jar_list != NULL)
		parent_class->add (comm, NULL, jar_list, tmp_dir, update, FALSE);

	fr_process_begin_command (proc, "rm");
	fr_process_set_working_dir (proc, "/");
	fr_process_add_arg (proc, "-r");
	fr_process_add_arg (proc, "-f");
	fr_process_add_arg (proc, tmp_dir);
	fr_process_end_command (proc);
	fr_process_set_sticky (proc, TRUE);

	for (scan = jardata_list; scan ; scan = scan->next) {
		JarData *jdata = scan->data;
		g_free (jdata->filename);
		g_free (jdata->package_minus_one_level);
		g_free (jdata->link_name);
		g_free (jdata->rel_path);
	}

	path_list_free (jardata_list);
	path_list_free (jar_list);
	path_list_free (zip_list);
	g_free (tmp_dir);
}
static char *
get_uncompressed_name (FrCommandTar *c_tar,
                       const char   *e_filename)
{
    FrCommand *comm = FR_COMMAND (c_tar);
    char      *new_name = g_strdup (e_filename);
    int        l = strlen (new_name);

    if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
        /* X.tgz     -->  X.tar
         * X.tar.gz  -->  X.tar */
        if (file_extension_is (e_filename, ".tgz")) {
            new_name[l - 2] = 'a';
            new_name[l - 1] = 'r';
        }
        else if (file_extension_is (e_filename, ".tar.gz"))
            new_name[l - 3] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
        /* X.tbz2    -->  X.tar
         * X.tar.bz2 -->  X.tar */
        if (file_extension_is (e_filename, ".tbz2")) {
            new_name[l - 3] = 'a';
            new_name[l - 2] = 'r';
            new_name[l - 1] = 0;
        }
        else if (file_extension_is (e_filename, ".tar.bz2"))
            new_name[l - 4] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
        /* X.taz   -->  X.tar
         * X.tar.Z -->  X.tar */
        if (file_extension_is (e_filename, ".taz"))
            new_name[l - 1] = 'r';
        else if (file_extension_is (e_filename, ".tar.Z"))
            new_name[l - 2] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
        /* X.tlrz     -->  X.tar
         * X.tar.lrz  -->  X.tar */
        if (file_extension_is (e_filename, ".tlrz")) {
            new_name[l - 3] = 'a';
            new_name[l - 2] = 'r';
            new_name[l - 1] = 0;
        }
        else if (file_extension_is (e_filename, ".tar.lrz"))
            new_name[l - 4] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
        /* X.tlz     -->  X.tar
         * X.tar.lz  -->  X.tar */
        if (file_extension_is (e_filename, ".tlz")) {
            new_name[l - 2] = 'a';
            new_name[l - 1] = 'r';
        }
        else if (file_extension_is (e_filename, ".tar.lz"))
            new_name[l - 3] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
        /* X.tar.lzma --> X.tar
         * (There doesn't seem to be a shorthand suffix) */
        if (file_extension_is (e_filename, ".tar.lzma"))
            new_name[l - 5] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
        /* X.tar.xz --> X.tar
         * (There doesn't seem to be a shorthand suffix) */
        if (file_extension_is (e_filename, ".tar.xz"))
            new_name[l - 3] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
        /* X.tzo     -->  X.tar
         * X.tar.lzo -->  X.tar */
        if (file_extension_is (e_filename, ".tzo")) {
            new_name[l - 2] = 'a';
            new_name[l - 1] = 'r';
        }
        else if (file_extension_is (e_filename, ".tar.lzo"))
            new_name[l - 4] = 0;
    }
    else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
        /* X.tar.7z -->  X.tar */
        if (file_extension_is (e_filename, ".tar.7z"))
            new_name[l - 3] = 0;
    }

    return new_name;
}