static gboolean
setup_directory_structure (const gchar  *theme_name,
			   GError      **error)
{
  gchar *dir, *theme_name_dir;
  GnomeVFSURI *uri;
  gboolean retval = TRUE;

  theme_name_dir = str_remove_slash (theme_name);

  dir = g_build_filename (g_get_home_dir (), ".themes", NULL);
  uri = gnome_vfs_uri_new (dir);
  if (!gnome_vfs_uri_exists (uri))
    gnome_vfs_make_directory_for_uri (uri, 0775);
  gnome_vfs_uri_unref (uri);
  g_free (dir);

  dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, NULL);
  uri = gnome_vfs_uri_new (dir);
  if (!gnome_vfs_uri_exists (uri))
    gnome_vfs_make_directory_for_uri (uri, 0775);
  gnome_vfs_uri_unref (uri);
  g_free (dir);

  dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, "index.theme", NULL);
  g_free (theme_name_dir);
  uri = gnome_vfs_uri_new (dir);
  g_free (dir);

  if (gnome_vfs_uri_exists (uri)) {
    GtkDialog *dialog;
    GtkWidget *button;
    gint response;

    dialog = (GtkDialog *) gtk_message_dialog_new (NULL,
						   GTK_DIALOG_MODAL,
						   GTK_MESSAGE_QUESTION,
	 					   GTK_BUTTONS_CANCEL,
						   _("The theme already exists. Would you like to replace it?"));
    button = gtk_dialog_add_button (dialog, _("_Overwrite"), GTK_RESPONSE_ACCEPT);
    gtk_button_set_image (GTK_BUTTON (button),
			  gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON));
    response = gtk_dialog_run (dialog);
    gtk_widget_destroy (GTK_WIDGET (dialog));
    retval = (response != GTK_RESPONSE_CANCEL);
  }

  gnome_vfs_uri_unref (uri);

  return retval;
}
static gboolean _downloadmanager_begin_download(download_t* pDownload)
{
	GList *pSrcList = NULL, *pDestList = NULL;

	g_assert(pDownload != NULL);
	//g_print("downloader: beginning download of %s\n", pDownload->pszRemoteFilePath);

	g_assert(pDownload->pszLocalFilePath == NULL);
	gint nHandle = g_file_open_tmp(TEMP_FILE_TEMPLATE, &(pDownload->pszLocalFilePath), NULL);
    if(nHandle == -1) {
		g_warning("downloader: failed to create a temporary file\n");
		return FALSE;
	}
	g_assert(pDownload->pszLocalFilePath != NULL);
	close(nHandle);	// we don't use the file here.  gnome-vfs overwrites it.

	//g_print("downloader: using temp file '%s'\n", pDownload->pszLocalFilePath);

	GnomeVFSURI* pSrcURI = gnome_vfs_uri_new(pDownload->pszRemoteFilePath);
	pSrcList = g_list_prepend(pSrcList, pSrcURI);

	GnomeVFSURI* pDestURI = gnome_vfs_uri_new(pDownload->pszLocalFilePath);
	pDestList = g_list_prepend(pDestList, pDestURI);

	GnomeVFSResult res = gnome_vfs_async_xfer(&(pDownload->pGnomeVFSHandle),
                                             pSrcList, pDestList,
											 GNOME_VFS_XFER_DEFAULT,
											 GNOME_VFS_XFER_ERROR_MODE_ABORT,
											 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,		// overwrite the tmp file we just made.
                                             GNOME_VFS_PRIORITY_MIN,
											 (GnomeVFSAsyncXferProgressCallback)_downloadmanager_gnome_vfs_progress_callback,
											 (gpointer)pDownload,	// callback userdata
                                             NULL,
											 NULL);

	gnome_vfs_uri_unref(pSrcURI);
	gnome_vfs_uri_unref(pDestURI);
	g_list_free(pSrcList);
	g_list_free(pDestList);

	if(res != GNOME_VFS_OK) {
		// return the download_t to a 'pending' state
		g_free(pDownload->pszLocalFilePath); pDownload->pszLocalFilePath = NULL;
		g_assert(pDownload->pGnomeVFSHandle == NULL);
		return FALSE;
	}
	g_assert(pDownload->pGnomeVFSHandle != NULL);
	return TRUE;
}
Пример #3
0
static GnomeVFSURI *
translate_uri (GnomeVFSURI *uri)
{
	GnomeVFSURI *translated_uri;
	char *uri_text;
	char *translated_uri_text;
	char *no_method;

	uri_text = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
	no_method = strchr (uri_text, ':');
	
	if (test_method_name != NULL) {
	  translated_uri_text = g_strconcat ((char *)test_method_name, 
					     no_method, NULL);
	} else {
	  translated_uri_text = NULL;
	}

	if (translated_uri_text != NULL) {
	  translated_uri = gnome_vfs_uri_new (translated_uri_text);
	} else {
	  translated_uri = NULL;
	}

	g_free (translated_uri_text);
	g_free (uri_text);

	return translated_uri;
}
Пример #4
0
/**
 * gnome_vfs_async_create:
 * @handle_return: pointer to a pointer to a #GnomeVFSHandle object.
 * @text_uri: string representing the uri to create.
 * @open_mode: mode to leave the file opened in after creation (or %GNOME_VFS_OPEN_MODE_NONE
 * to leave the file closed after creation).
 * @exclusive: whether the file should be created in "exclusive" mode:
 * i.e. if this flag is nonzero, operation will fail if a file with the
 * same name already exists.
 * @perm: bitmap representing the permissions for the newly created file
 * (Unix style).
 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
 * in allocating threads from the thread pool.
 * @callback: function to be called when the operation is complete.
 * @callback_data: data to pass to @callback.
 * 
 * Create a file at @uri according to mode @open_mode, with permissions @perm (in
 * the standard UNIX packed bit permissions format). When the create has been completed
 * @callback will be called with the result code and @callback_data.
 */
void
gnome_vfs_async_create (GnomeVFSAsyncHandle **handle_return,
			const gchar *text_uri,
			GnomeVFSOpenMode open_mode,
			gboolean exclusive,
			guint perm,
			int priority,
			GnomeVFSAsyncOpenCallback callback,
			gpointer callback_data)
{
	GnomeVFSURI *uri;

	g_return_if_fail (handle_return != NULL);
	g_return_if_fail (text_uri != NULL);
	g_return_if_fail (callback != NULL);
	g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
	g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);

	uri = gnome_vfs_uri_new (text_uri);
	*handle_return = async_create (uri, open_mode, exclusive, perm,
				       priority, callback, callback_data);
	if (uri != NULL) {
		gnome_vfs_uri_unref (uri);
	}
}
Пример #5
0
/**
 * gnome_vfs_async_load_directory:
 * @handle_return: when the function returns, will point to a handle for
 * the async operation.
 * @text_uri: string representing the uri of the directory to be loaded.
 * @options: packed boolean type providing control over various details
 * of the get_file_info operation.
 * @items_per_notification: number of files to process in a row before calling @callback
 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign to this job
 * in allocating threads from the thread pool.
 * @callback: function to be called when the operation is complete.
 * @callback_data: data to pass to @callback.
 * 
 * Read the contents of the directory at @text_uri, passing back #GnomeVFSFileInfo 
 * structs about each file in the directory to @callback. @items_per_notification
 * files will be processed between each call to @callback.
 */
void
gnome_vfs_async_load_directory (GnomeVFSAsyncHandle **handle_return,
				const gchar *text_uri,
				GnomeVFSFileInfoOptions options,
				guint items_per_notification,
				int priority,
				GnomeVFSAsyncDirectoryLoadCallback callback,
				gpointer callback_data)
{
	GnomeVFSURI *uri;

	g_return_if_fail (handle_return != NULL);
	g_return_if_fail (text_uri != NULL);
	g_return_if_fail (callback != NULL);
	g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
	g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);

	uri = gnome_vfs_uri_new (text_uri);
	*handle_return = async_load_directory (uri, options,
				               items_per_notification,
				               priority,
					       callback, callback_data);
	if (uri != NULL) {
		gnome_vfs_uri_unref (uri);
	}
}
static void
directory_load_callback (GnomeVFSAsyncHandle *handle,
			 GnomeVFSResult result,
			 GList *list,
			 guint entries_read,
			 gpointer callback_data)
{
	CallbackData *data;
	GnomeVFSFileInfo *info;
	GnomeVFSURI *parent_uri;
	GnomeVFSURI *uri;
	GList *node;
	guint i;

	data = (CallbackData *)callback_data;


	if (!measure_speed) {
		printf ("Directory load callback: %s, %d entries, callback_data `%s'\n",
			gnome_vfs_result_to_string (result),
			entries_read,
			(gchar *) data->parent_uri);
	}

	parent_uri = gnome_vfs_uri_new (data->parent_uri);
	for (i = 0, node = list; i < entries_read && node != NULL; i++, node = node->next) {
		info = node->data;
		if (!measure_speed) {
			printf ("  File `%s'%s (%s, %s), "
				"size %"GNOME_VFS_SIZE_FORMAT_STR", mode %04o\n",
				info->name,
				(info->flags & GNOME_VFS_FILE_FLAGS_SYMLINK) ? " [link]" : "",
				type_to_string (info->type),
				gnome_vfs_file_info_get_mime_type (info),
				info->size, info->permissions);
			fflush (stdout);
		}
		if (read_files) {
			if ((info->type & GNOME_VFS_FILE_TYPE_REGULAR) != 0) {
				uri = gnome_vfs_uri_append_file_name (parent_uri, info->name);
				test_read_file_async (uri);
				gnome_vfs_uri_unref (uri);
			}
			if (!measure_speed) {
				printf ("reading a bit of %s\n", info->name);
			}
		}
	}

	
	data->num_entries_read += entries_read;

	gnome_vfs_uri_unref (parent_uri);
	if (result != GNOME_VFS_OK) {
		if (--async_task_counter == 0) {
			g_main_loop_quit (main_loop);
		}
	}
}
Пример #7
0
// Pulling nearly all of gnomevfs just to copy a file. *sigh*.
static GnomeVFSResult copy_file(const char * source_uri, const char * dest_uri)
{
	GnomeVFSURI* src = gnome_vfs_uri_new(source_uri);
	GnomeVFSURI* dst = gnome_vfs_uri_new(dest_uri);
	GnomeVFSResult res;

	res = gnome_vfs_xfer_uri(src, dst,
			GNOME_VFS_XFER_TARGET_DEFAULT_PERMS,
			GNOME_VFS_XFER_ERROR_MODE_ABORT,
			GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
			NULL, NULL);

	gnome_vfs_uri_unref(src);
	gnome_vfs_uri_unref(dst);

	return res;
}
Пример #8
0
GnomeVFSURI *la_track_get_vfs_uri(LaTrack * self)
{
    if (!self->vfs_uri) {
	self->vfs_uri = gnome_vfs_uri_new(self->uri);
    }
    gnome_vfs_uri_ref(self->vfs_uri);
    return self->vfs_uri;
}
Пример #9
0
static void
gst_gnome_vfs_src_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstGnomeVFSSrc *src;

  src = GST_GNOME_VFS_SRC (object);

  switch (prop_id) {
    case ARG_LOCATION:{
      const gchar *new_location;

      /* the element must be stopped or paused in order to do this */
      if (GST_STATE (src) == GST_STATE_PLAYING ||
          GST_STATE (src) == GST_STATE_PAUSED)
        break;

      if (src->uri) {
        gnome_vfs_uri_unref (src->uri);
        src->uri = NULL;
      }
      if (src->uri_name) {
        g_free (src->uri_name);
        src->uri_name = NULL;
      }

      new_location = g_value_get_string (value);
      if (new_location) {
        src->uri_name = gst_gnome_vfs_location_to_uri_string (new_location);
        src->uri = gnome_vfs_uri_new (src->uri_name);
      }
      break;
    }
    case ARG_HANDLE:
      if (GST_STATE (src) == GST_STATE_NULL ||
          GST_STATE (src) == GST_STATE_READY) {
        if (src->uri) {
          gnome_vfs_uri_unref (src->uri);
          src->uri = NULL;
        }
        if (src->uri_name) {
          g_free (src->uri_name);
          src->uri_name = NULL;
        }
        src->handle = g_value_get_boxed (value);
      }
      break;
    case ARG_IRADIO_MODE:
      src->iradio_mode = g_value_get_boolean (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
NS_IMETHODIMP
nsGnomeVFSProtocolHandler::NewURI(const nsACString &aSpec,
                                  const char *aOriginCharset,
                                  nsIURI *aBaseURI,
                                  nsIURI **aResult)
{
  const nsCString flatSpec(aSpec);
  LOG(("gnomevfs: NewURI [spec=%s]\n", flatSpec.get()));

  if (!aBaseURI)
  {
    //
    // XXX This check is used to limit the gnome-vfs protocols we support.  For
    //     security reasons, it is best that we limit the protocols we support to
    //     those with known characteristics.  We might want to lessen this
    //     restriction if it proves to be too heavy handed.  A black list of
    //     protocols we don't want to support might be better.  For example, we
    //     probably don't want to try to load "start-here:" inside the browser.
    //     There are others that fall into this category, which are best handled
    //     externally by Nautilus (or another app like it).
    //
    if (!IsSupportedProtocol(flatSpec))
      return NS_ERROR_UNKNOWN_PROTOCOL;

    // Verify that GnomeVFS supports this URI scheme.
    GnomeVFSURI *uri = gnome_vfs_uri_new(flatSpec.get());
    if (!uri)
      return NS_ERROR_UNKNOWN_PROTOCOL;
  }

  //
  // XXX Can we really assume that all gnome-vfs URIs can be parsed using
  //     nsStandardURL?  We probably really need to implement nsIURI/nsIURL
  //     in terms of the gnome_vfs_uri_XXX methods, but at least this works
  //     correctly for smb:// URLs ;-)
  //
  //     Also, it might not be possible to fully implement nsIURI/nsIURL in
  //     terms of GnomeVFSURI since some Necko methods have no GnomeVFS
  //     equivalent.
  //
  nsresult rv;
  nsCOMPtr<nsIStandardURL> url =
      do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    return rv;

  rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec,
                 aOriginCharset, aBaseURI);
  if (NS_SUCCEEDED(rv))
    rv = CallQueryInterface(url, aResult);

  return rv;
}
Пример #11
0
int
main (int argc, char **argv)
{
	GnomeVFSResult    result;
	GnomeVFSHandle   *handle;
	gchar             buffer[1024];
	GnomeVFSFileSize  bytes_read;
	GnomeVFSURI 	 *uri;
	gchar            *text_uri;

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

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

	uri = gnome_vfs_uri_new (argv[1]);
	if (uri == NULL) {
		fprintf (stderr, "URI not valid.\n");
		return 1;
	}

	text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);

	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
	show_result (result, "open", text_uri);

	while( result==GNOME_VFS_OK && !feof(stdin)) {
		GnomeVFSFileSize temp;

		bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin);
		if(!bytes_read) break;
		buffer[bytes_read] = 0;
		result = gnome_vfs_write (handle, buffer, bytes_read,
				 	&temp);
		show_result (result, "write", text_uri);
	
	}

	result = gnome_vfs_close (handle);
	show_result (result, "close", text_uri);

	g_free (text_uri);

	return 0;
}
static GObject *
panel_ditem_editor_constructor (GType                  type,
				guint                  n_construct_properties,
				GObjectConstructParam *construct_properties)
{
	GObject          *obj;
	PanelDItemEditor *dialog;
	GnomeVFSURI      *vfs_uri;
	gboolean          loaded;

	obj = G_OBJECT_CLASS (panel_ditem_editor_parent_class)->constructor (type,
									     n_construct_properties,
									     construct_properties);

	dialog = PANEL_DITEM_EDITOR (obj);

	if (dialog->priv->key_file) {
		panel_ditem_editor_key_file_loaded (dialog);
		dialog->priv->new_file = FALSE;
		dialog->priv->free_key_file = FALSE;
		loaded = TRUE;
	} else {
		dialog->priv->key_file = panel_util_key_file_new_desktop ();
		dialog->priv->free_key_file = TRUE;
		loaded = FALSE;
	}

	if (!loaded && dialog->priv->uri) {
		vfs_uri = gnome_vfs_uri_new (dialog->priv->uri);
		if (gnome_vfs_uri_exists (vfs_uri)) {
			//FIXME what if there's an error?
			panel_ditem_editor_load_uri (dialog, NULL);
			dialog->priv->new_file = FALSE;
		} else {
			dialog->priv->new_file = TRUE;
		}
		gnome_vfs_uri_unref (vfs_uri);
	} else {
		dialog->priv->new_file = !loaded;
	}

	dialog->priv->dirty = FALSE;

	panel_ditem_editor_setup_ui (dialog);

	return obj;
}
Пример #13
0
char *
mn_vfs_uri_extract_short_name (const char *text_uri)
{
  GnomeVFSURI *uri;
  char *name;

  g_return_val_if_fail(text_uri != NULL, NULL);

  uri = gnome_vfs_uri_new(text_uri);
  if (! uri)
    return NULL;

  name = gnome_vfs_uri_extract_short_name(uri);
  gnome_vfs_uri_unref(uri);

  return name;
}
Пример #14
0
/**
 * file_exists_and_readable:
 * @filename: a #const gchar * with a file path
 *
 * tests if the file exists, and  if it is readable, the last
 * check is not reliable, it does not check all the groups you are
 * in, so change this function before you rely on that check!
 *
 * this function is Gnome-VFS aware, so it will work on URI's
 *
 * Return value: gboolean, TRUE if readable, else FALSE
 **/
gboolean file_exists_and_readable(const gchar * filename) {
	gchar *ondiskencoding;
	/* not sure the purpose of returning true here by default so I changed it to false. */
	/* gboolean retval=TRUE; */
	gboolean retval = FALSE;

#ifdef WIN32
	 if (strchr(filename,'/')==filename) filename++;
#endif /* WIN32 */

#ifdef DEVELOPMENT
	g_assert(filename);
#endif
	if (!filename || strlen(filename) < 2) {
		DEBUG_MSG("file_exists_and_readable, strlen(filename) < 2 or no filename!!!!\n");
		return FALSE;
	}
	DEBUG_MSG("file_exists_and_readable, filename(%p)=\"%s\", strlen(filename)=%d\n", filename, filename, strlen(filename));
	ondiskencoding = get_filename_on_disk_encoding(filename);
	DEBUG_MSG("file_exists_and_readable, ondiskencoding='%s'\n",ondiskencoding);
#ifdef HAVE_GNOME_VFS
	{
		GnomeVFSURI* uri;
		uri = gnome_vfs_uri_new(ondiskencoding);
		retval = gnome_vfs_uri_exists(uri);
		DEBUG_MSG("gnome_vfs_uri has path %s\n",gnome_vfs_uri_get_path(uri));
		gnome_vfs_uri_unref(uri);
		DEBUG_MSG("file_exists_and_readable, return %d for %s\n",retval,filename);
	}
#else /* HAVE_GNOME_VFS */
	{
#ifdef WIN32		
		struct _stat naamstat;
		errno = 0;
		retval = ((_stat(ondiskencoding, &naamstat) == 0) && (errno == 0));
#else /* NOT WIN32 */
		struct stat naamstat;
		errno = 0;
		retval = ((stat(ondiskencoding, &naamstat) == 0) && (errno == 0));
#endif
		DEBUG_MSG("file_exists_and_readable, retval=%d (ernno=%d) for\n %s\n",retval,errno,ondiskencoding);
	}
#endif /* HAVE_GNOME_VFS */
	g_free(ondiskencoding);
	return retval;
}
gboolean launcher_application_validate(struct launcher *launcher,
                                       const char *text_uri)
{
        GnomeVFSURI *uri;

        g_return_val_if_fail(launcher, FALSE);
        g_return_val_if_fail(launcher==&launcher_application, FALSE);
        g_return_val_if_fail(text_uri!=NULL, FALSE);

        uri=gnome_vfs_uri_new(text_uri);
        if(uri) {
                gboolean retval=gnome_vfs_uri_exists(uri);
                gnome_vfs_uri_unref(uri);
                return retval;
        } else {
                return FALSE;
        }
}
int
main(int argc, char **argv)
{
	GdkPixbuf *pixbuf;
	GnomeThemeMetaInfo *theme;
	GnomeVFSURI *uri;

	g_thread_init (NULL);
	theme_thumbnail_factory_init (argc, argv);

	if (argc != 3) {
		g_printerr ("usage: gnome-theme-thumbnailer theme output-image\n");
		return 1;
	}

	if (!gnome_vfs_init ()) {
		g_printerr ("could not initialise gnome-vfs\n");
		return 1;
	}

	uri = gnome_vfs_uri_new (argv[1]);
	theme = gnome_theme_read_meta_theme (uri);
	gnome_vfs_uri_unref (uri);

	if (theme) {
	    pixbuf = generate_meta_theme_thumbnail (theme);
	    gnome_theme_meta_info_free (theme);

	    if (pixbuf) {
		    save_pixbuf (pixbuf, argv[2]);
		    gdk_pixbuf_unref (pixbuf);
	    } else {
		    g_printerr ("could not generate thumbnail\n");
		    return 1;
	    }
	}
	else {
	    g_printerr ("usage: gnome-theme-thumbnailer theme output-image\n");
	    return 1;
	}

	return 0;
}
Пример #17
0
static gchar *
get_protocols (void)
{
  static const gchar *protocols[] =
  {
    "http:",
    "https:",
    "ftp:",
    "sftp:",
    "ssh:",
    "smb:",
    "dav:",
    "davs:"
  };

  GString *string = g_string_new (NULL);
  gint     i;

  for (i = 0; i < G_N_ELEMENTS (protocols); i++)
    {
      gchar       *uri;
      GnomeVFSURI *vfs_uri;

      uri = g_strdup_printf ("%s//foo/bar.xcf", protocols[i]);

      vfs_uri = gnome_vfs_uri_new (uri);

      if (vfs_uri)
        {
          if (string->len > 0)
            g_string_append_c (string, ',');

          g_string_append (string, protocols[i]);

          gnome_vfs_uri_unref (vfs_uri);
        }

      g_free (uri);
    }

  return g_string_free (string, FALSE);
}
Пример #18
0
/**
 * gnome_vfs_async_create_as_channel:
 * @handle_return: pointer to a pointer to a #GnomeVFSHandle object.
 * @text_uri: string of the uri to open as a #GIOChannel, creating it as necessary.
 * @open_mode: open mode i.e. for reading, writing, random, etc.
 * @exclusive: replace the file if it already exists.
 * @perm: standard POSIX-style permissions bitmask, permissions of created file.
 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
 * in allocating threads from the thread pool.
 * @callback: function to be called when the operation is complete.
 * @callback_data: data to pass to @callback.
 *
 * Open @text_uri as a #GIOChannel, creating it as necessary. Once the channel has 
 * been established @callback will be called with @callback_data, the result of the 
 * operation, and if the result was %GNOME_VFS_OK, a reference to a #GIOChannel pointing
 * at @text_uri in @open_mode.
 *
 * This function has been deprecated due to behaving weirdly which suggests 
 * that it hasn't been used. See bugs #157266, #157265, #157261, #138398 in
 * the GNOME Bugzilla. If the *_as_channel functions are needed they should be
 * fixed and undeprecated.
 */
void
gnome_vfs_async_create_as_channel (GnomeVFSAsyncHandle **handle_return,
				   const gchar *text_uri,
				   GnomeVFSOpenMode open_mode,
				   gboolean exclusive,
				   guint perm,
				   int priority,
				   GnomeVFSAsyncOpenAsChannelCallback callback,
				   gpointer callback_data)
{
	GnomeVFSURI *uri;
	g_return_if_fail (text_uri != NULL);
	
	uri = gnome_vfs_uri_new (text_uri);
	gnome_vfs_async_create_uri_as_channel (handle_return, uri, open_mode, 
					       exclusive, perm, priority, 
					       callback, callback_data);
	if (uri != NULL) {
		gnome_vfs_uri_unref (uri);
	}
}
Пример #19
0
/**
    \return    A new document just for you!
    \brief     This function takes in a filename of a SVG document and
               turns it into a SPDocument.
    \param     mod   Module to use
    \param     uri   The path to the file (UTF-8)

    This function is really simple, it just calls sp_document_new...
*/
SPDocument *
Svg::open (Inkscape::Extension::Input */*mod*/, const gchar *uri)
{
#ifdef WITH_GNOME_VFS
    if (!gnome_vfs_initialized() || gnome_vfs_uri_is_local(gnome_vfs_uri_new(uri))) {
        // Use built-in loader instead of VFS for this
        return sp_document_new(uri, TRUE);
    }
    gchar * buffer = _load_uri(uri);
    if (buffer == NULL) {
        g_warning("Error:  Could not open file '%s' with VFS\n", uri);
        return NULL;
    }
    SPDocument * doc = sp_document_new_from_mem(buffer, strlen(buffer), 1);

    g_free(buffer);
    return doc;
#else
    return sp_document_new (uri, TRUE);
#endif
}
Пример #20
0
void
peacock_file_set_uri (PeacockFile *file, const gchar *uri)
{
	const gchar *old_uri;

	g_return_if_fail (file != NULL);
	g_return_if_fail (PEACOCK_IS_FILE (file));

	/* Save old uri to be passed to signal. */
	old_uri = (file->priv->uri ? peacock_file_get_uri (file) : NULL);

	/* Free old URI */
	if (file->priv->uri)
		gnome_vfs_uri_unref (file->priv->uri);

	file->priv->uri = gnome_vfs_uri_new (uri);

	/* Emit uri_changed signal. */
	g_signal_emit (G_OBJECT (file), peacock_file_signals[URI_CHANGED],
		       0, old_uri);
}
Пример #21
0
/**
 * gnome_vfs_async_open_as_channel:
 * @handle_return: pointer to a pointer to a #GnomeVFSHandle object.
 * @text_uri: string of the uri to open as a #GIOChannel.
 * @open_mode: open mode i.e. for reading, writing, random, etc.
 * @advised_block_size: the preferred block size for #GIOChannel to read.
 * @priority: a value from %GNOME_VFS_PRIORITY_MIN to %GNOME_VFS_PRIORITY_MAX (normally
 * should be %GNOME_VFS_PRIORITY_DEFAULT) indicating the priority to assign this job
 * in allocating threads from the thread pool.
 * @callback: function to be called when the operation is complete.
 * @callback_data: data to pass to @callback.
 *
 * Open @text_uri as a #GIOChannel. Once the channel has been established
 * @callback will be called with @callback_data, the result of the operation,
 * and if the result was %GNOME_VFS_OK, a reference to a #GIOChannel pointing
 * at @text_uri in @open_mode.
 *
 * This function has been deprecated due to behaving weirdly which suggests 
 * that it hasn't been used. See bugs #157266, #157265, #157261, #138398 in
 * the GNOME Bugzilla. If the *_as_channel functions are needed they should be
 * fixed and undeprecated.
 */
void
gnome_vfs_async_open_as_channel (GnomeVFSAsyncHandle **handle_return,
				 const gchar *text_uri,
				 GnomeVFSOpenMode open_mode,
				 guint advised_block_size,
				 int priority,
				 GnomeVFSAsyncOpenAsChannelCallback callback,
				 gpointer callback_data)
{
	GnomeVFSURI *uri;

	g_return_if_fail (handle_return != NULL);
	g_return_if_fail (text_uri != NULL);
	g_return_if_fail (callback != NULL);
	g_return_if_fail (priority >= GNOME_VFS_PRIORITY_MIN);
	g_return_if_fail (priority <= GNOME_VFS_PRIORITY_MAX);

	uri = gnome_vfs_uri_new (text_uri);
	*handle_return = async_open_as_channel (uri, open_mode, advised_block_size,
						priority, callback, callback_data);
	if (uri != NULL) {
		gnome_vfs_uri_unref (uri);
	}
}
Пример #22
0
/*--------------------------------------------------------------------------*/
static void
prepare_downloading_page( GnomeDruidPage *page, GnomeDruid *druid,
			  gpointer data )
{
	const gchar *site_name;
	GList *p;
	Site *site;

	gb_debug (DEBUG_UPDATE, "START");

	gnome_druid_set_buttons_sensitive( druid, FALSE, FALSE, TRUE, FALSE );
	site_name = gtk_entry_get_text( GTK_ENTRY(site_entry) );
	for ( p = site_list; p != NULL; p=p->next ) {
		site = (Site *)p->data;
		if ( strcmp( site_name, site->name ) == 0 ) {
			site_uri = site->uri;
			break;
		}
	}

	get_remote_file_list( gnome_vfs_uri_new( site_uri ) );

	gb_debug (DEBUG_UPDATE, "END");
}
static gboolean
write_theme_to_disk (GnomeThemeMetaInfo  *theme_info,
		     const gchar         *theme_name,
		     const gchar         *theme_description,
		     gboolean		  save_background,
		     GError             **error)
{
  gchar *dir, *theme_name_dir;
  GnomeVFSURI *uri;
  GnomeVFSURI *target_uri;
  GnomeVFSHandle *handle = NULL;
  GnomeVFSFileSize bytes_written;
  gchar *str, *current_background;
  GConfClient *client;
  const gchar *theme_header =
      "[Desktop Entry]\n"
      "Name=%s\n"
      "Type=X-GNOME-Metatheme\n"
      "Comment=%s\n"
      "\n"
      "[X-GNOME-Metatheme]\n"
      "GtkTheme=%s\n"
      "MetacityTheme=%s\n"
      "IconTheme=%s\n";

  theme_name_dir = str_remove_slash (theme_name);
  dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, "index.theme~", NULL);
  g_free (theme_name_dir);

  uri = gnome_vfs_uri_new (dir);
  dir [strlen (dir) - 1] = '\000';
  target_uri = gnome_vfs_uri_new (dir);
  g_free (dir);
  gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_WRITE, FALSE, 0644);

  gnome_vfs_truncate_handle (handle, 0);

  /* start making the theme file */
  str = g_strdup_printf (theme_header, theme_name, theme_description,
			 theme_info->gtk_theme_name,
			 theme_info->metacity_theme_name,
			 theme_info->icon_theme_name);
  gnome_vfs_write (handle, str, strlen (str), &bytes_written);
  g_free (str);

  if (theme_info->gtk_color_scheme) {
    gchar *a, *tmp;
    tmp = g_strdup (theme_info->gtk_color_scheme);
    for (a = tmp; *a != '\0'; a++)
      if (*a == '\n')
        *a = ',';
    str = g_strdup_printf ("GtkColorScheme=%s\n", tmp);
    gnome_vfs_write (handle, str, strlen (str), &bytes_written);
    g_free (str);
    g_free (tmp);
  }

  if (theme_info->cursor_theme_name) {
#ifdef HAVE_XCURSOR
    str = g_strdup_printf ("CursorTheme=%s\n"
                           "CursorSize=%i\n",
                           theme_info->cursor_theme_name,
                           theme_info->cursor_size);
#else
    str = g_strdup_printf ("CursorFont=%s\n", theme_info->cursor_theme_name);
#endif
    gnome_vfs_write (handle, str, strlen (str), &bytes_written);
    g_free (str);
  }

  if (save_background) {
    client = gconf_client_get_default ();
    current_background = gconf_client_get_string (client, BACKGROUND_KEY, NULL);

    if (current_background != NULL) {
      str = g_strdup_printf ("BackgroundImage=%s\n", current_background);

      gnome_vfs_write (handle, str, strlen (str), &bytes_written);

      g_free (current_background);
      g_free (str);
    }
    g_object_unref (client);
  }

  gnome_vfs_close (handle);

  gnome_vfs_move_uri (uri, target_uri, TRUE);
  gnome_vfs_uri_unref (uri);
  gnome_vfs_uri_unref (target_uri);

  return TRUE;
}
Пример #24
0
static void
gst_gnome_vfs_sink_set_property (GObject * object, guint prop_id,
                                 const GValue * value, GParamSpec * pspec)
{
    GstGnomeVFSSink *sink;
    GstState cur_state;

    sink = GST_GNOME_VFS_SINK (object);

    gst_element_get_state (GST_ELEMENT (sink), &cur_state, NULL, 0);

    if (cur_state == GST_STATE_PLAYING || cur_state == GST_STATE_PAUSED) {
        GST_WARNING_OBJECT (sink, "cannot set property when PAUSED or PLAYING");
        return;
    }

    GST_OBJECT_LOCK (sink);

    switch (prop_id) {
    case ARG_LOCATION: {
        const gchar *new_location;

        if (sink->uri) {
            gnome_vfs_uri_unref (sink->uri);
            sink->uri = NULL;
        }
        if (sink->uri_name) {
            g_free (sink->uri_name);
            sink->uri_name = NULL;
        }

        new_location = g_value_get_string (value);
        if (new_location) {
            sink->uri_name = gst_gnome_vfs_location_to_uri_string (new_location);
            sink->uri = gnome_vfs_uri_new (sink->uri_name);
        }
        break;
    }
    case ARG_URI: {
        if (sink->uri) {
            gnome_vfs_uri_unref (sink->uri);
            sink->uri = NULL;
        }
        if (sink->uri_name) {
            g_free (sink->uri_name);
            sink->uri_name = NULL;
        }
        if (g_value_get_boxed (value)) {
            sink->uri = (GnomeVFSURI *) g_value_dup_boxed (value);
            sink->uri_name = gnome_vfs_uri_to_string (sink->uri, 0);
        }
        break;
    }
    case ARG_HANDLE: {
        if (sink->uri) {
            gnome_vfs_uri_unref (sink->uri);
            sink->uri = NULL;
        }
        if (sink->uri_name) {
            g_free (sink->uri_name);
            sink->uri_name = NULL;
        }
        sink->handle = g_value_get_boxed (value);
        break;
    }
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }

    GST_OBJECT_UNLOCK (sink);
}
GnomeVFSResult
gnome_vfs_find_directory_cancellable (GnomeVFSURI *near_uri,
				      GnomeVFSFindDirectoryKind kind,
				      GnomeVFSURI **result_uri,
				      gboolean create_if_needed,
				      gboolean find_if_needed,
				      guint permissions,
				      GnomeVFSContext *context)
{
	GnomeVFSResult result;
	GnomeVFSURI *resolved_uri;

	g_return_val_if_fail (result_uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);

	*result_uri = NULL;

	if (gnome_vfs_context_check_cancellation (context))
		return GNOME_VFS_ERROR_CANCELLED;

	if (near_uri != NULL) {
		gnome_vfs_uri_ref (near_uri);
	} else {
		char *text_uri;

		text_uri = gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
		g_assert (text_uri != NULL);
		/* assume file: method and the home directory */
		near_uri = gnome_vfs_uri_new (text_uri);
		g_free (text_uri);
	}

	g_assert (near_uri != NULL);

	if (!VFS_METHOD_HAS_FUNC (near_uri->method, find_directory)) {
		/* skip file systems not supporting find_directory.
		 *
		 * TODO if we decide to introduce cross-method links (e.g. http allows
		 * arbitrary URIs), this could be slightly wrong, because the target
		 * method may support find_directory, so we'd also have to make sure
		 * that a method doesn't support cross-method links.
		 **/
		return GNOME_VFS_ERROR_NOT_SUPPORTED;
	}

	/* Need to expand the final symlink, since if the directory is a symlink
	 * we want to look at the device the symlink points to, not the one the
	 * symlink is stored on
	 */
	result = _gnome_vfs_uri_resolve_all_symlinks_uri (near_uri, &resolved_uri);
	if (result == GNOME_VFS_OK) {
		gnome_vfs_uri_unref (near_uri);
		near_uri = resolved_uri;
	} else
		return result;

	g_assert (near_uri != NULL);

	if (!VFS_METHOD_HAS_FUNC(near_uri->method, find_directory)) {
		gnome_vfs_uri_unref (near_uri);
		return GNOME_VFS_ERROR_NOT_SUPPORTED;
	}

	result = near_uri->method->find_directory (near_uri->method, near_uri, kind,
		result_uri, create_if_needed, find_if_needed, permissions, context);

	gnome_vfs_uri_unref (near_uri);
	return result;
}
Пример #26
0
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;
}
Пример #27
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;
}
Пример #28
0
static void action_callback(CongServiceDocTool *tool, CongPrimaryWindow *primary_window, gpointer user_data)
{
    GenerateWebsiteWorkspace *workspace = g_new0(GenerateWebsiteWorkspace,1);
    GError *error = NULL;

    workspace->primary_window = primary_window;
    workspace->doc = cong_primary_window_get_document(primary_window);

    /* FIXME: Do dialog here: */
    workspace->src_dir = g_strdup("/home/david/coding/website-experiment/src"); /* for now */
    workspace->build_dir = g_strdup("/home/david/coding/website-experiment/build");
    workspace->xsl_dir = g_strdup("/usr/share/xml/website-2.4.1/xsl");

    /*  	workspace->xsl_file = "/usr/share/xml/website-2.4.1/xsl/chunk-website.xsl"; */
    /*   	workspace->xsl_file = "/usr/share/xml/website-2.4.1/xsl/chunk-tabular.xsl"; */
    /*  	workspace->xsl_file = "/usr/share/xml/website-2.4.1/xsl/tabular.xsl"; */
    /*  	workspace->xsl_file = "/usr/share/xml/website-2.4.1/xsl/website.xsl"; */
    workspace->xsl_file = "/home/david/coding/website-experiment/src/custom-stylesheet.xsl";

    workspace->src_uri = gnome_vfs_uri_new(workspace->src_dir);
    workspace->build_uri = gnome_vfs_uri_new(workspace->build_dir);
    workspace->xsl_uri  = gnome_vfs_uri_new(workspace->xsl_dir);

    /* Traverse the DOM tree for layout.xml, building up useful information: */
    traverse_dom_tree(workspace, (xmlNodePtr)cong_document_get_xml(workspace->doc));

    /* Init the dependency node graph: */
    workspace->graph = cong_dependency_graph_new();

    /* Add the autolayout dependency */

    /* FIXME */

    /* Build up the set of nodes, with dependencies: */
    build_node_graph(workspace);

    /* Query to save any unsaved dependencies: */
    /* FIXME */
#if 0
    cong_dependency_graph_query_unsaved(workspace->graph,
                                        _("Generating website"),
                                        cong_primary_window_get_toplevel(primary_window));
#endif

    /* Build the nodes: */
    if (cong_dependency_graph_process(workspace->graph, &error)) {
        GtkDialog *dialog = cong_dialog_information_alert_new(cong_primary_window_get_toplevel(primary_window),
                            _("Finished generating website."));
        gtk_dialog_run(dialog);
        gtk_widget_destroy(GTK_WIDGET(dialog));
    } else {
        GtkDialog* dialog = cong_error_dialog_new_with_convenience(cong_primary_window_get_toplevel(primary_window),
                            _("Conglomerate did not finish generating the website"),
                            _("One of the stages reported an error."),
                            _("Click on the \"Details\" button for more information"),
                            _("_Details"),
                            on_error_details,
                            workspace);
        cong_error_dialog_run(dialog);
        gtk_widget_destroy(GTK_WIDGET(dialog));
    }

    /* FIXME: memory leaks here! */
    g_free(workspace);
}
Пример #29
0
	explicit URI(const std::string& textURI) : m_handle(gnome_vfs_uri_new(textURI.c_str())) {}