예제 #1
0
// Determines the mime type of uri.
// Returns mime type or empty string if it can't be determined.
std::string GetMimeType(const URI& uri)
{
	std::string mimeType;
	// We don't need to free buffer.
	char* const buffer = gnome_vfs_get_mime_type(uri.ToString().c_str());
	if (buffer != 0)
		mimeType = buffer;
	return mimeType;
}
예제 #2
0
파일: girl-station.c 프로젝트: hmt/girl
void girl_launch_helper(char *url, GirlStreamType type)
{
	GError *err = NULL;
	const char *mime_info;

	/* GnomeVFSMimeApplication *app; */
	char *app, *command, *msg;

	g_return_if_fail(url != NULL);
	MSG("%s", url);

	mime_info = gnome_vfs_get_mime_type(url);

	/* app = gnome_vfs_mime_get_default_application (mime_info); */

	app = g_strdup(GIRL_HELPER);

	if (app != NULL) {
		command = g_strconcat(app, " ", url, NULL);
		g_print("Helper command is %s\n", command);
		/* gnome_vfs_mime_application_free (app); */
	} else {
		if (type == GIRL_STREAM_SHOUTCAST) {
			command = g_strconcat(app, " ", url, NULL);
			g_print("Helper command is %s\n", command);
		} else {
			msg =
			    g_strdup_printf(_
					    ("An error happened trying to play "
					     "%s\nEither the file doesn't exist, or you "
					     "don't have a player for it."),
					    url);
			show_error(msg);
			g_free(msg);
		}
		return;
	}

	if (!g_spawn_command_line_async(command, &err)) {
		msg = g_strdup_printf(_("Failed to open URL: '%s'\n"
					"Details: %s"), url, err->message);
		show_error(msg);
		g_error_free(err);
		g_free(msg);
	} else {
		g_print("Launching %s\n", command);
	}
}
예제 #3
0
int
main (int argc, char **argv)
{
	GnomeVFSURI *uri;
	gboolean magic_only;
	gboolean suffix_only;
	gboolean dump_table;
	gboolean speed_test;
	const char *result;
	const char *table_path;
	char *uri_string;
	char *curdir;
	char *path;
	struct stat tmp;
	GTimer *timer;
	int i;

	table_path = NULL;
	magic_only = FALSE;
	dump_table = FALSE;
	speed_test = FALSE;
	suffix_only = FALSE;
	
	if (!gnome_vfs_init ()) {
		fprintf (stderr, "Cannot initialize gnome-vfs.\n");
		return 1;
	}

	if (argc == 1 || strcmp (argv[1], "--help") == 0) {
		fprintf (stderr, "Usage: %s [--magicOnly | --suffixOnly] [--dumpTable] "
			" [--loadTable <table path>] fileToCheck1 [fileToCheck2 ...] \n", *argv);
		return 1;
	}


	++argv;
	for (; *argv; argv++) {
		if (strcmp (*argv, "--magicOnly") == 0) {
			magic_only = TRUE;
		} else if (strcmp (*argv, "--suffixOnly") == 0) {
			suffix_only = TRUE;
		} else if (strcmp (*argv, "--dumpTable") == 0) {
			dump_table = TRUE;
		} else if (strcmp (*argv, "--speedTest") == 0) {
			speed_test = TRUE;
		} else if (strcmp (*argv, "--loadTable") == 0) {
			++argv;
			if (!*argv) {
				fprintf (stderr, "Table path expected.\n");
				return 1;
			}
			table_path = *argv;
			if (stat(table_path, &tmp) != 0) {
				fprintf (stderr, "Table path %s not found.\n", table_path);
				return 1;
			}
		} else {
			break;
		}
	}


	if (speed_test) {
		timer = g_timer_new ();
		g_timer_start (timer);
		for (i = 0; i < 100; i++) {
			gnome_vfs_mime_info_reload ();
		}
		fprintf (stderr, "Mime reload took %g(ms)\n",
			 g_timer_elapsed (timer, NULL) * 10.0);
	}

	for (; *argv != NULL; argv++) {
	        uri_string = g_strdup (*argv);
		if (is_uri (uri_string)) {
			uri = gnome_vfs_uri_new (*argv);
		} else {
			uri = NULL;
		}
		if (uri == NULL) {
			if (g_path_is_absolute (uri_string)) {
				path = uri_string;
			} else {
				curdir = g_get_current_dir ();
				path = g_build_filename (curdir,uri_string, NULL);
				g_free (uri_string);
				g_free (curdir);
			}
			uri_string = gnome_vfs_get_uri_from_local_path (path);
			g_free (path);
			uri = gnome_vfs_uri_new (uri_string);
		}
		if (uri == NULL) {
			printf ("%s is neither a full URI nor an absolute filename\n", *argv);
			continue;
		}

		if (magic_only) {
			result = gnome_vfs_get_mime_type_from_file_data (uri);
		} else if (suffix_only) {
			result = gnome_vfs_get_mime_type_from_uri (uri);
		} else {
			result = gnome_vfs_get_mime_type (uri_string);
		}
	
		printf ("looks like %s is %s\n", *argv, result);
		gnome_vfs_uri_unref (uri);
	}
	
	return 0;
}