Ejemplo n.º 1
0
gint
main (int     argc,
      gchar  *argv[])
{
  gchar *chosen_test_path;
  gchar *file_uri;
  GError *error = NULL;

  grl_init (&argc, &argv);
  GRL_LOG_DOMAIN_INIT (example_log_domain, "example");

  if (argc != 2) {
    g_printf ("Usage: %s <path to browse>\n", argv[0]);
    return 1;
  }

  chosen_test_path = argv[1];
  GFile *file = g_file_new_for_path (chosen_test_path);
  if (!file) {
    g_printf ("Invalid file/directory %s\n", argv[1]);
    return 1;
  }

  GFileInfo *info = g_file_query_info (file,
               G_FILE_ATTRIBUTE_STANDARD_TYPE,
               0,
               NULL,
               &error);
  if (!info) {
    g_printf ("Invalid file/directory information\n");
    return 1;
  }

  if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) {
    return 1;
  }

  gchar *dirname = g_path_get_dirname(chosen_test_path);
  config_plugins (dirname);
  g_free (dirname);

  file_uri = g_filename_to_uri (chosen_test_path, NULL, &error);

  g_object_unref (file);
  g_object_unref (info);
  load_plugins (file_uri);
  g_free (file_uri);

  return 0;
}
Ejemplo n.º 2
0
/**
 * Emit the 'entry' signal for @path after converting it to an URI.
 **/
static void
got_absolute_path (PlaylistParser *parser,
                   const char     *path)
{
        char *uri;

        uri = g_filename_to_uri (path, NULL, NULL);
        if (!uri)
                return;
        
        g_signal_emit (parser, signals[SIGNAL_ENTRY], 0, uri);

        g_free (uri);
}
static char *
impl_build_dest_uri (RBRemovableMediaSource *source,
		     RhythmDBEntry *entry,
		     const char *mimetype,
		     const char *extension)
{
	char* file = g_strdup_printf ("%s/%s-%s.%s", g_get_tmp_dir (),
				      rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ARTIST),
				      rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE),
				      extension);
	char* uri = g_filename_to_uri (file, NULL, NULL);
	g_free (file);
	return uri;
}
Ejemplo n.º 4
0
void FrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
{
    WebKitWebView* webView = getViewFromFrame(m_frame);
    GError* webError = g_error_new_literal(g_quark_from_string(error.domain().utf8().data()),
                                           error.errorCode(),
                                           error.localizedDescription().utf8().data());
    gboolean isHandled = false;
    g_signal_emit_by_name(webView, "load-error", m_frame, error.failingURL().utf8().data(), webError, &isHandled);

    if (isHandled) {
        g_error_free(webError);
        return;
    }

    if (!shouldFallBack(error)) {
        g_error_free(webError);
        // FIXME: load-done is deprecated. Please remove when signal's been removed.
        g_signal_emit_by_name(m_frame, "load-done", false);
        return;
    }

    String content;
    gchar* fileContent = 0;
    gchar* errorURI = g_filename_to_uri(DATA_DIR"/webkit-1.0/resources/error.html", NULL, NULL);
    GFile* errorFile = g_file_new_for_uri(errorURI);
    g_free(errorURI);

    if (!errorFile)
        content = String::format("<html><body>%s</body></html>", webError->message);
    else {
        gboolean loaded = g_file_load_contents(errorFile, 0, &fileContent, 0, 0, 0);
        if (!loaded)
            content = String::format("<html><body>%s</body></html>", webError->message);
        else
            content = String::format(fileContent, error.failingURL().utf8().data(), webError->message);
    }

    webkit_web_frame_load_alternate_string(m_frame, content.utf8().data(), 0, error.failingURL().utf8().data());

    g_free(fileContent);

    if (errorFile)
        g_object_unref(errorFile);

    g_error_free(webError);

    // FIXME: load-done is deprecated. Please remove when signal's been removed.
    g_signal_emit_by_name(m_frame, "load-done", false);
}
Ejemplo n.º 5
0
void wxFileHistory::AddFileToHistory(const wxString& file)
{
    wxFileHistoryBase::AddFileToHistory(file);

#ifdef __WXGTK210__
    const wxString fullPath = wxFileName(file).GetFullPath();
    if ( !gtk_check_version(2,10,0) )
    {
        wxGtkString uri(g_filename_to_uri(fullPath.fn_str(), NULL, NULL));

        if ( uri )
            gtk_recent_manager_add_item(gtk_recent_manager_get_default(), uri);
    }
#endif
}
Ejemplo n.º 6
0
static void
load_uri (const gchar * uri)
{
  gchar *addr = NULL;

  if (!uri || !uri[0])
    return;

  if (g_file_test (uri, G_FILE_TEST_EXISTS))
    {
      if (g_path_is_absolute (uri))
        addr = g_filename_to_uri (uri, NULL, NULL);
      else
        {
          gchar *afn = g_new0 (gchar, PATH_MAX);
          realpath (uri, afn);
          addr = g_filename_to_uri (afn, NULL, NULL);
          g_free (afn);
        }
    }
  else
    {
      if (g_uri_parse_scheme (uri) == NULL)
        addr = g_strdup_printf ("http://%s", uri);
      else
        addr = g_strdup (uri);
    }

  if (addr)
    {
      webkit_web_view_load_uri (view, addr);
      g_free (addr);
    }
  else
    g_printerr ("yad_html_load_uri: cannot load uri '%s'\n", uri);
}
Ejemplo n.º 7
0
gboolean
xmr_player_open(XmrPlayer	*player,
			const gchar *uri)
{
	XmrPlayerPrivate *priv;
	gchar *r_uri = NULL;
	libvlc_media_t *media = NULL;

	g_return_val_if_fail( player != NULL && uri != NULL, FALSE);
	priv = player->priv;

	{
		static const gchar * const prefix[] =
		{
			"http://", "file://" // we don't deal with others
		};
		gboolean prefix_ok = FALSE;
		gint i;

		for (i = 0; i < 2; ++i)
		{
			if (g_str_has_prefix(uri, prefix[i]))
			{
				prefix_ok = TRUE;
				break ;
			}
		}

		if (!prefix_ok) {
			r_uri = g_filename_to_uri(uri, NULL, NULL);
		} else {
			r_uri = g_strdup(uri);
		}
	}

	media = libvlc_media_new_location(priv->instance, r_uri);
	g_free(r_uri);

	if(media == NULL)
		return FALSE;
	
	libvlc_media_player_set_media(priv->player, media);
	xmr_player_set_repeat(player);

	libvlc_media_release(media);
	
	return TRUE;
}
Ejemplo n.º 8
0
static char *
pack_files (GList *file_list)
{
	char *file_roller_cmd;
	const char *filename;
	GList *l;
	GString *cmd, *tmp;
	char *pack_type, *tmp_work_dir, *packed_file;

	file_roller_cmd = g_find_program_in_path ("file-roller");
	filename = pack_filename_from_names (file_list);

	g_assert (filename != NULL && *filename != '\0');

	tmp_work_dir = g_build_filename (g_get_tmp_dir (),
					 "nautilus-sendto-XXXXXX",
					 NULL);
	tmp_work_dir = g_mkdtemp (tmp_work_dir);

	pack_type = g_strdup (".zip");

	cmd = g_string_new ("");
	g_string_printf (cmd, "%s --add-to=\"%s/%s%s\"",
			 file_roller_cmd, tmp_work_dir,
			 filename,
			 pack_type);

	/* file-roller doesn't understand URIs */
	for (l = file_list ; l; l=l->next){
		char *file;

		file = g_filename_from_uri (l->data, NULL, NULL);
		g_string_append_printf (cmd," \"%s\"", file);
		g_free (file);
	}

	g_spawn_command_line_sync (cmd->str, NULL, NULL, NULL, NULL);
	g_string_free (cmd, TRUE);
	tmp = g_string_new("");
	g_string_printf (tmp,"%s/%s%s", tmp_work_dir,
			 filename,
			 pack_type);
	g_free (tmp_work_dir);
	packed_file = g_filename_to_uri (tmp->str, NULL, NULL);
	g_string_free(tmp, TRUE);

	return packed_file;
}
Ejemplo n.º 9
0
/* {{{ proto string Glib::filenameToUri(string filename)
	   Converts an escaped ASCII-encoded URI to a local filename in the encoding used for filenames.
      */
PHP_METHOD(Glib, filenameToUri)
{
	char *filename, *uri;
	int length;
	GError *error = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &length) == FAILURE) {
		return;
	}

	uri = g_filename_to_uri((const gchar*)filename, NULL, &error);
	if (php_glib_handle_gerror(&error TSRMLS_CC)) {
		return;
	}
	RETURN_STRING(uri, 1);
}
Ejemplo n.º 10
0
static void
panel_addto_setup_launcher_drag (GtkTreeView *tree_view,
				 const char  *path)
{
        static GtkTargetEntry target[] = {
		{ "text/uri-list", 0, 0 }
	};
	char *uri;
	char *uri_list;

	uri = g_filename_to_uri (path, NULL, NULL);
	uri_list = g_strconcat (uri, "\r\n", NULL);
	panel_addto_setup_drag (tree_view, target, uri_list);
	g_free (uri_list);
	g_free (uri);
}
Ejemplo n.º 11
0
static void
help_contents_action (GtkAction *action,
                      gpointer   user_data)
{
	GPInstructServerWindow *window = GPINSTRUCT_SERVER_WINDOW (user_data);

	GAppInfo *app_info;
	gchar *uri;

	app_info = g_app_info_get_default_for_uri_scheme ("help");

#ifdef G_OS_WIN32
        gchar *prefix = g_win32_get_package_installation_directory_of_module (NULL);
	gchar *index_filename = g_build_filename (prefix, "share", "help", "C", PACKAGE, "index.html", NULL);
#else
	gchar *index_filename = g_build_filename (PACKAGE_PREFIX, "share", "help", "C", PACKAGE, "index.html", NULL);
#endif

	if (app_info)
	{
		uri = g_strdup ("help:" PACKAGE);
	}
	else if (g_file_test (index_filename, G_FILE_TEST_IS_REGULAR))
	{
		uri = g_filename_to_uri (index_filename, NULL, NULL);
	}
	else
	{
		uri = g_strdup (PACKAGE_URL);
	}

	gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (window)),
	              uri,
	              GDK_CURRENT_TIME,
	              NULL);

	g_free (uri);
	g_free (index_filename);

	if (app_info)
		g_object_unref (app_info);

#ifdef G_OS_WIN32
	g_free (prefix);
#endif
}
Ejemplo n.º 12
0
/* Check if we have an up-to-date thumbnail for this image.
 * If so, return it. Otherwise, returns NULL.
 */
static GdkPixbuf*
get_thumbnail_for(const char *pathname)
{
	GdkPixbuf *thumb = NULL;
	char *thumb_path, *uri;
	const char *ssize, *smtime;
	struct stat info;
	time_t ttime, now;

	char* path = pathdup(pathname);
	uri = g_filename_to_uri(path, NULL, NULL);
	if(!uri) uri = g_strconcat("file://", path, NULL);
	char* md5 = md5_hash(uri);
	g_free(uri);
	
	thumb_path = g_strdup_printf("%s/.thumbnails/normal/%s.png", g_get_home_dir(), md5);
	g_free(md5);

	thumb = gdk_pixbuf_new_from_file(thumb_path, NULL);
	if (!thumb) goto err;

	// Note that these don't need freeing... 
	ssize = gdk_pixbuf_get_option(thumb, "tEXt::Thumb::Size");
	if (!ssize) goto err;

	smtime = gdk_pixbuf_get_option(thumb, "tEXt::Thumb::MTime");
	if (!smtime) goto err;
	
	if (stat(path, &info) != 0) goto err;

	ttime=(time_t) atol(smtime);
	time(&now);
	if (info.st_mtime != ttime && now>ttime+PIXMAP_THUMB_TOO_OLD_TIME)
		goto err;

	if (info.st_size < atol(ssize)) goto err;

	goto out;
err:
	if (thumb) gdk_pixbuf_unref(thumb);
	thumb = NULL;
out:
	g_free(path);
	g_free(thumb_path);
	return thumb;
}
Ejemplo n.º 13
0
gchar
*canonical_location (char *location)
{
    /* Allocates uri but doesn't free it */
    gchar *uri;
    char *tmp;
    struct stat st;

    if (!stat(location, &st)) {
        tmp = realpath(location, NULL);
        uri = g_filename_to_uri(tmp, NULL, NULL);
        free(tmp);
    } else {
        uri = g_strdup(location);
    }
    return(uri);
}
Ejemplo n.º 14
0
/* Get raw, unscaled thumbnail, also get NULL when there's none. */
GdkPixbuf*
_gwy_app_recent_file_try_thumbnail(const gchar *filename_sys)
{
    GdkPixbuf *pixbuf;
    gchar *uri, *thumb;

    if (!(uri = g_filename_to_uri(filename_sys, NULL, NULL)))
        return NULL;

    thumb = gwy_recent_file_thumbnail_name(uri);
    g_free(uri);

    pixbuf = gdk_pixbuf_new_from_file(thumb, NULL);
    g_free(thumb);

    return pixbuf;
}
Ejemplo n.º 15
0
char *fm_path_to_uri (FmPath *path)
{
    char *uri = NULL;
    char *str = fm_path_to_str (path);
    
    if (G_LIKELY (str))
    {
        if (str[0] == '/') // absolute path
            uri = g_filename_to_uri (str, NULL, NULL);
        else
        {
            uri = g_uri_escape_string (str, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
        }
        g_free (str);
    }
    return uri;
}
Ejemplo n.º 16
0
GdkPixbuf *
file_utils_load_thumbnail (const gchar *filename)
{
    GimpThumbnail *thumbnail = NULL;
    GdkPixbuf     *pixbuf    = NULL;
    gchar         *uri;

    g_return_val_if_fail (filename != NULL, NULL);

    uri = g_filename_to_uri (filename, NULL, NULL);

    if (uri)
    {
        thumbnail = gimp_thumbnail_new ();
        gimp_thumbnail_set_uri (thumbnail, uri);

        pixbuf = gimp_thumbnail_load_thumb (thumbnail,
                                            GIMP_THUMBNAIL_SIZE_NORMAL,
                                            NULL);
    }

    g_free (uri);

    if (pixbuf)
    {
        gint width  = gdk_pixbuf_get_width (pixbuf);
        gint height = gdk_pixbuf_get_height (pixbuf);

        if (gdk_pixbuf_get_n_channels (pixbuf) != 3)
        {
            GdkPixbuf *tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
                                             width, height);

            gdk_pixbuf_composite_color (pixbuf, tmp,
                                        0, 0, width, height, 0, 0, 1.0, 1.0,
                                        GDK_INTERP_NEAREST, 255,
                                        0, 0, GIMP_CHECK_SIZE_SM,
                                        0x66666666, 0x99999999);

            g_object_unref (pixbuf);
            pixbuf = tmp;
        }
    }

    return pixbuf;
}
Ejemplo n.º 17
0
static gboolean dnd_source_set_uri_list(GdkWindow *requestor, GdkAtom property)
{
    const gchar* url = NULL;
    jstring jurl = NULL;

    jobjectArray files_array = NULL;
    gsize files_cnt = 0;

    if (jurl = (jstring) dnd_source_get_data("text/uri-list")) {
        url = mainEnv->GetStringUTFChars(jurl, NULL);
    }

    if (files_array = (jobjectArray) dnd_source_get_data("application/x-java-file-list")) {
        files_cnt = mainEnv->GetArrayLength(files_array);
    }
    if (!url && !files_cnt) {
        return FALSE;
    }

    GString* res = g_string_new (NULL); //http://www.ietf.org/rfc/rfc2483.txt 

    if (files_cnt > 0) {
        for (gsize i = 0; i < files_cnt; ++i) {
            jstring string = (jstring) mainEnv->GetObjectArrayElement(files_array, i);
            const gchar* file = mainEnv->GetStringUTFChars(string, NULL);
            gchar* uri = g_filename_to_uri(file, NULL, NULL);

            g_string_append(res, uri);
            g_string_append(res, URI_LIST_LINE_BREAK);

            g_free(uri);
            mainEnv->ReleaseStringUTFChars(string, file);
        }
    }
    if (url) {
        g_string_append(res, url);
        g_string_append(res, URI_LIST_LINE_BREAK);
        mainEnv->ReleaseStringUTFChars(jurl, url);
    }

    gdk_property_change(requestor, property, GDK_SELECTION_TYPE_STRING,
            8, GDK_PROP_MODE_REPLACE, (guchar *) res->str, res->len);

    g_string_free(res, TRUE);
    return TRUE;
}
Ejemplo n.º 18
0
static void
search_callback (gchar  **results, 
		 GError  *error, 
		 gpointer user_data)
{
  GtkSearchEngineTracker *tracker;
  gchar **results_p;
  GList *hit_uris;
  
  tracker = GTK_SEARCH_ENGINE_TRACKER (user_data);
  hit_uris = NULL;
  
  tracker->priv->query_pending = FALSE;

  if (error) 
    {
      _gtk_search_engine_error ( GTK_SEARCH_ENGINE (tracker), error->message);
      g_error_free (error);
      return;
    }

  if (!results)
    return;
	
  for (results_p = results; *results_p; results_p++) 
    {
      gchar *uri;

      if (tracker->priv->version == TRACKER_0_6)
        uri = g_filename_to_uri (*results_p, NULL, NULL);
      else
        uri = *results_p;

      if (uri)
	hit_uris = g_list_prepend (hit_uris, uri);
    }

  _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (tracker), hit_uris);
  _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker));

  g_strfreev  (results);
  if (tracker->priv->version == TRACKER_0_6)
    g_list_foreach (hit_uris, (GFunc)g_free, NULL);
  g_list_free (hit_uris);
}
Ejemplo n.º 19
0
static gboolean
download_requested_cb(WebKitWebView* web_view,
                      WebKitDownload* download,
                      gboolean* beenThere)
{
    *beenThere = TRUE;
    if (temporaryFilename) {
        gchar *uri = g_filename_to_uri(temporaryFilename, NULL, NULL);
        if (uri)
            webkit_download_set_destination_uri(download, uri);
        g_free(uri);
    }

    g_signal_connect(download, "notify::status",
                     G_CALLBACK(notify_status_cb), NULL);

    return TRUE;
}
Ejemplo n.º 20
0
gboolean
uri_backend_load_image (const gchar  *uri,
                        const gchar  *tmpname,
                        GimpRunMode   run_mode,
                        GError      **error)
{
  gchar    *dest_uri;
  gboolean  success;

  dest_uri = g_filename_to_uri (tmpname, NULL, NULL);
  success = copy_uri (uri, dest_uri,
                      _("Downloading %s of image data"),
                      _("Downloaded %s of image data"),
                      error);
  g_free (dest_uri);

  return success;
}
Ejemplo n.º 21
0
static void _on_about_to_finish(GstElement *playbin, gpointer userData)
{
	NPlaybackEngineGStreamer *obj = reinterpret_cast<NPlaybackEngineGStreamer *>(userData);

	gchar *uri_before;
	g_object_get(playbin, "uri", &uri_before, NULL);

	obj->_crossfadingPrepare();
	obj->_emitAboutToFinish();

	gchar *uri_after = g_filename_to_uri(QFileInfo(obj->currentMedia()).absoluteFilePath().toUtf8().constData(), NULL, NULL);

	if (g_strcmp0(uri_before, uri_after) == 0) // uri hasn't changed
		obj->_crossfadingCancel();

	g_free(uri_before);
	g_free(uri_after);
}
Ejemplo n.º 22
0
static void 
search_view_row_activated_cb(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, LmplayerObject *lmplayer)
{
	GtkTreeModel *model;
	GtkTreeIter iter;

	model = gtk_tree_view_get_model(treeview);
	if(gtk_tree_model_get_iter(model, &iter, path))
	{
		gchar *filename;
		gtk_tree_model_get(model, &iter, 1, &filename, -1);
		gchar *uri = g_filename_to_uri(filename, NULL, NULL);
		g_free(filename);
		lmplayer_playlist_add_mrl(lmplayer->playing_playlist, uri, NULL);
		g_print("select uri %s\n", uri);
		g_free(uri);
	}
}
Ejemplo n.º 23
0
gboolean
uri_backend_save_image (const gchar  *uri,
                        const gchar  *tmpname,
                        GimpRunMode   run_mode,
                        GError      **error)
{
  gchar    *src_uri;
  gboolean  success;

  src_uri = g_filename_to_uri (tmpname, NULL, NULL);
  success = copy_uri (src_uri, uri,
                      _("Uploading %s of image data"),
                      _("Uploaded %s of image data"),
                      error);
  g_free (src_uri);

  return success;
}
Ejemplo n.º 24
0
void
pragha_backend_play (PraghaBackend *backend)
{
	PraghaMusicSource file_source = FILE_NONE;
	gchar *file = NULL, *uri = NULL;

	PraghaBackendPrivate *priv = backend->priv;

	g_object_get(priv->mobj,
	             "file", &file,
	             "source", &file_source,
	             NULL);

	if (string_is_empty(file))
		goto exit;

	CDEBUG(DBG_BACKEND, "Playing: %s", file);

	switch (file_source) {
		case FILE_USER_L:
		case FILE_USER_3:
		case FILE_USER_2:
		case FILE_USER_1:
		case FILE_USER_0:
			g_signal_emit (backend, signals[SIGNAL_PREPARE_SOURCE], 0);
			break;
		case FILE_LOCAL:
			uri = g_filename_to_uri (file, NULL, NULL);
			g_object_set (priv->pipeline, "uri", uri, NULL);
			g_free (uri);
			break;
		case FILE_HTTP:
			g_object_set (priv->pipeline, "uri", file, NULL);
			break;
		case FILE_NONE:
		default:
			break;
	}

	pragha_backend_set_target_state (backend, GST_STATE_PLAYING);

exit:
	g_free(file);
}
Ejemplo n.º 25
0
static void
update_xdg_dir_cache (void)
{
    GFile *file;
    char *config_file, *uri;
    int i;

    free_xdg_dir_cache ();
    g_reload_user_special_dirs_cache ();
    schedule_user_dirs_changed ();
    desktop_dir_changed ();

    cached_xdg_dirs = parse_xdg_dirs (NULL);

    for (i = 0 ; cached_xdg_dirs[i].type != NULL; i++)
    {
        cached_xdg_dirs[i].file = NULL;
        if (strcmp (cached_xdg_dirs[i].path, g_get_home_dir ()) != 0)
        {
            uri = g_filename_to_uri (cached_xdg_dirs[i].path, NULL, NULL);
            cached_xdg_dirs[i].file = caja_file_get_by_uri (uri);
            caja_file_monitor_add (cached_xdg_dirs[i].file,
                                   &cached_xdg_dirs[i],
                                   CAJA_FILE_ATTRIBUTE_INFO);
            g_signal_connect (cached_xdg_dirs[i].file,
                              "changed", G_CALLBACK (xdg_dir_changed), &cached_xdg_dirs[i]);
            g_free (uri);
        }
    }

    if (cached_xdg_dirs_monitor == NULL)
    {
        config_file = g_build_filename (g_get_user_config_dir (),
                                        "user-dirs.dirs", NULL);
        file = g_file_new_for_path (config_file);
        cached_xdg_dirs_monitor = g_file_monitor_file (file, 0, NULL, NULL);
        g_signal_connect (cached_xdg_dirs_monitor, "changed",
                          G_CALLBACK (xdg_dir_cache_changed_cb), NULL);
        g_object_unref (file);
        g_free (config_file);

        eel_debug_call_at_shutdown (destroy_xdg_dir_cache);
    }
}
Ejemplo n.º 26
0
static gchar* make_silence(void) {
        const gchar silentwave[] = {0x52, 0x49, 0x46, 0x46, 0x24, 0x00, 0x00, 0x00, 0x57,
                0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00,
                0x01, 0x00, 0x02, 0x00, 0x80, 0xBB, 0x00, 0x00, 0x00, 0xEE, 0x02,
                0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00,
                0x00, 0x00};
        GError *error = NULL;
        gchar *tmpfilename;
        GIOChannel *outfile;
        gsize bytes_written;

        g_clear_error (&error);
        gint fd = g_file_open_tmp (NULL, &tmpfilename, &error);

        if (-1 == fd) {
                g_print ("Unable to create tmp file: %s\n", error->message);
                g_error_free (error);
                return dummyuri();
        }

        outfile = g_io_channel_unix_new (fd);

        /* make it a binary channel */
        if (G_IO_STATUS_NORMAL != g_io_channel_set_encoding (outfile, NULL, NULL)) {
                g_print ("Unable to create tmpfile in binary mode\n");
                return dummyuri();
        }

        g_print ("File is %lu\n", sizeof(*silentwave));

        g_clear_error (&error);
        if (G_IO_STATUS_NORMAL != g_io_channel_write_chars (outfile, &silentwave[0], sizeof(silentwave), &bytes_written, &error)) {
                g_print ("Unable to write to tmpfile: %s\n", error->message);
                g_error_free (error);
                return dummyuri();
        }

        g_io_channel_shutdown (outfile, TRUE, NULL);
        g_io_channel_unref (outfile);

        close(fd);

        return g_filename_to_uri (tmpfilename, NULL, NULL);
}
Ejemplo n.º 27
0
int main (int argc, char *argv[])
{
	guchar raw_hash[DMAP_HASH_SIZE] = { 0 };
	guchar hash[DMAP_HASH_SIZE * 2 + 1] = { 0 };
	gchar *absolute_path = NULL;

	if (argc != 2) {
		fprintf (stderr, "usage: %s path\n", argv[0]);
		exit (EXIT_FAILURE);
	}

	if (! g_path_is_absolute (argv[1])) {
		gchar *dir = g_get_current_dir ();
		if (NULL == dir) {
			g_error ("Could not determine current directory\n");
		}

		absolute_path = g_build_filename (dir, argv[1], NULL);
	} else {
		absolute_path = g_strdup (argv[1]);
	}

	if (NULL == absolute_path) {
		g_error ("Could not build absolute path\n");
	}

	gchar *uri = g_filename_to_uri (absolute_path, NULL, NULL);
	if (NULL == uri) {
		g_error ("Could not convert %s to a URI", argv[1]);
	}

	gchar *escaped_filename = strrchr (uri, '/') + 1;
	
	if (! dmapd_util_hash_file (uri, raw_hash)) {
		exit (EXIT_FAILURE);
        }

	dmap_hash_progressive_to_string (raw_hash, hash);

	printf ("%s\n", hash);

	g_free (uri);
	g_free (absolute_path);
}
/**
 * rb_sanitize_uri_for_filesystem:
 * @uri: a URI to sanitize
 *
 * Return value: a copy of the URI with characters not allowed by the target filesystem
 *   replaced
 */
char *
rb_sanitize_uri_for_filesystem (const char *uri)
{
	char *filesystem = rb_uri_get_filesystem_type (uri);
	char *sane_uri = NULL;

	if (!filesystem)
		return g_strdup (uri);

	if (!strcmp (filesystem, "fat") ||
	    !strcmp (filesystem, "vfat") ||
	    !strcmp (filesystem, "msdos")) {
	    	char *hostname = NULL;
		GError *error = NULL;
	    	char *full_path = g_filename_from_uri (uri, &hostname, &error);

		if (error) {
			g_error_free (error);
			g_free (filesystem);
			g_free (full_path);
			return g_strdup (uri);
		}

		g_strdelimit (full_path, "\"", '\'');
		g_strdelimit (full_path, ":|<>*?\\", '_');

		/* create a new uri from this */
		sane_uri = g_filename_to_uri (full_path, hostname, &error);

		g_free (hostname);
		g_free (full_path);

		if (error) {
			g_error_free (error);
			g_free (filesystem);
			return g_strdup (uri);
		}
	}

	/* add workarounds for other filesystems limitations here */

	g_free (filesystem);
	return sane_uri ? sane_uri : g_strdup (uri);
}
Ejemplo n.º 29
0
int
main (int argc, char *argv[])
{
  GError *error = NULL;
  GOptionContext *context;
  GstSwitchUI *switchui;
  GMainLoop *main_loop;

  //if (!g_thread_supported ()) g_thread_init(NULL);

  context = g_option_context_new ("- FIXME");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gst_init_get_option_group ());
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
    g_print ("option parsing failed: %s\n", error->message);
    exit (1);
  }
  g_option_context_free (context);

  switchui = gst_switchui_new ();

  if (argc > 1) {
    gchar *uri;
    if (gst_uri_is_valid (argv[1])) {
      uri = g_strdup (argv[1]);
    } else {
      uri = g_filename_to_uri (argv[1], NULL, NULL);
    }
    gst_switchui_create_pipeline_playbin (switchui, uri);
    g_free (uri);
  } else {
    gst_switchui_create_pipeline (switchui);
  }

  gst_switchui_start (switchui);

  main_loop = g_main_loop_new (NULL, TRUE);
  switchui->main_loop = main_loop;

  g_main_loop_run (main_loop);

  exit (0);
}
Ejemplo n.º 30
0
char *
panel_launcher_get_uri (const char *location)
{
	char *path;
	char *uri;

	if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
		return g_strdup (location);

	if (!g_path_is_absolute (location))
		path = panel_make_full_path (NULL, location);
	else
		path = g_strdup (location);

	uri = g_filename_to_uri (path, NULL, NULL);
	g_free (path);

	return uri;
}