Example #1
0
gboolean filebrowser_backend_process_drag_drop(FilebrowserBackend *filebackend, gchar *stringdata)
{
  FilebrowserBackendDetails *directory;
  directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);
  GFile *destdir = g_file_new_for_commandline_arg (directory->current_folder);
  g_object_ref(destdir);

  if (destdir) {
    if (strchr(stringdata, '\n') == NULL) {  /* no newlines, probably a single file */
      GSList *list = NULL;
      GFile *uri;
      uri = g_file_new_for_commandline_arg(stringdata);
      list = g_slist_append(list, uri);
      filebrowser_backend_copy_uris_async(filebackend, destdir, list);
      g_slist_free(list);
      g_object_unref(uri);
    } else {
      /* there are newlines, probably this is a list of uri's */
      filebrowser_backend_copy_files_async(filebackend,destdir, stringdata);
    }
    g_object_unref(destdir);
    return TRUE;
  } else {
    return FALSE;
  }
}
/**
 * rb_async_copy_start:
 * @copy: a #RBAsyncCopy
 * @src: source URI
 * @dest: destination URI
 * @callback: completion callback
 * @user_data: data for completion callback
 * @destroy_data: destroy function for user_data
 *
 * Starts copying @src to @dest, calling @callback on completion or error.
 */
void
rb_async_copy_start (RBAsyncCopy *copy,
		     const char *src,
		     const char *dest,
		     RBAsyncCopyCallback callback,
		     gpointer user_data,
		     GDestroyNotify destroy_data)
{
	g_assert (copy->priv->src == NULL);

	copy->priv->cancel = g_cancellable_new ();

	copy->priv->callback = callback;
	copy->priv->callback_data = user_data;
	copy->priv->destroy_data = destroy_data;

	copy->priv->src = g_file_new_for_commandline_arg (src);
	copy->priv->dest = g_file_new_for_commandline_arg (dest);

	g_file_copy_async (copy->priv->src,
			   copy->priv->dest,
			   G_FILE_COPY_NONE,
			   G_PRIORITY_DEFAULT,
			   copy->priv->cancel,
			   progress_cb,
			   copy,
			   copy_cb,
			   copy);
}
Example #3
0
void filebrowser_backend_create_dir(FilebrowserBackend *filebackend, gchar *filename, gchar *name, gboolean isdir){
  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);
  GFile *config;
  GError *error=NULL;
  gchar *filename_int;
  if (isdir){
      gchar *parent=filename_parent_uri(filename);
      filename_int= g_strdup_printf("%s/%s",parent,name);
      g_free(parent);
      config= g_file_new_for_commandline_arg(filename_int);
  } else {
      gchar *parent;
      if (filename) {
        parent=filename_parent_uri(filename);
      } else {
        parent=g_strdup(directory->current_folder);
      }
      filename_int= g_build_path (G_DIR_SEPARATOR_S, parent, name, NULL);
      g_free(parent);
      config=g_file_new_for_commandline_arg(filename_int);
  }
  gphpedit_debug_message(DEBUG_FILEBROWSER, "New directory:%s",filename_int);

  g_free(filename_int);
  if (!g_file_make_directory (config, directory->cancellable, &error)){
     g_print(_("Error creating folder. GIO error:%s\n"), error->message);
     g_error_free (error);
  }
  g_object_unref(config);
	filebrowser_backend_refresh_folder (filebackend);
}
Example #4
0
int 
main (int argc, char* argv[])
{
	GtkWidget *window;
	GList *sources;
	GFile *dest;
	GFile *source;
	int i;
	GList *infos;
        NautilusProgressInfoManager *manager;
	NautilusProgressInfo *progress_info;
	
	test_init (&argc, &argv);

	if (argc < 3) {
		g_print ("Usage test-copy <sources...> <dest dir>\n");
		return 1;
	}

	sources = NULL;
	for (i = 1; i < argc - 1; i++) {
		source = g_file_new_for_commandline_arg (argv[i]);
		sources = g_list_prepend (sources, source);
	}
	sources = g_list_reverse (sources);
	
	dest = g_file_new_for_commandline_arg (argv[i]);
	
	window = test_window_new ("copy test", 5);
	
	gtk_widget_show (window);

        manager = nautilus_progress_info_manager_new ();

	nautilus_file_operations_copy (sources,
				       NULL /* GArray *relative_item_points */,
				       dest,
				       GTK_WINDOW (window),
				       copy_done, NULL);
        
	infos = nautilus_progress_info_manager_get_all_infos (manager);

	if (infos == NULL) {
		g_object_unref (manager);
		return 0;
	}

	progress_info = NAUTILUS_PROGRESS_INFO (infos->data);

	g_signal_connect (progress_info, "changed", (GCallback)changed_cb, NULL);
	g_signal_connect (progress_info, "progress-changed", (GCallback)progress_changed_cb, NULL);
	g_signal_connect (progress_info, "finished", (GCallback)finished_cb, NULL);
	
	gtk_main ();

        g_object_unref (manager);
	
	return 0;
}
Example #5
0
static void fm_path_entry_changed(GtkEditable *editable, gpointer user_data)
{
    FmPathEntry *entry = FM_PATH_ENTRY(editable);
    FmPathEntryPrivate *priv  = FM_PATH_ENTRY_GET_PRIVATE(entry);
    GtkWidget* widget = GTK_WIDGET(entry);
    const gchar *path_str, *sep;

    /* find parent dir of current path */
    path_str = gtk_entry_get_text( GTK_ENTRY(entry) );
    sep = g_utf8_strrchr(path_str, -1, G_DIR_SEPARATOR);
    if(sep) /* we found a parent dir */
    {
        int parent_len = (sep - path_str) + 1; /* includes the dir separator / */
        if(!priv->parent_dir
           || priv->parent_len != parent_len
           || strncmp(priv->parent_dir, path_str, parent_len ))
        {
            /* parent dir has been changed, reload dir list */
            ListSubDirNames* data = g_slice_new0(ListSubDirNames);
            g_free(priv->parent_dir);
            priv->parent_dir = g_strndup(path_str, parent_len);
            priv->parent_len = parent_len;
            /* g_debug("parent dir is changed to %s", priv->parent_dir); */

            /* FIXME: convert utf-8 encoded path to on-disk encoding. */
            data->entry = entry;
            if(priv->parent_dir[0] == '~') /* special case for home dir */
            {
                char* expand = g_strconcat(g_get_home_dir(), priv->parent_dir + 1, NULL);
                data->dir = g_file_new_for_commandline_arg(expand);
                g_free(expand);
            }
            else
                data->dir = g_file_new_for_commandline_arg(priv->parent_dir);

            /* clear current model */
            gtk_list_store_clear(GTK_LIST_STORE(priv->model));

            /* cancel running dir-listing jobs */
            if(priv->cancellable)
            {
                g_cancellable_cancel(priv->cancellable);
                g_object_unref(priv->cancellable);
            }

            /* launch a new job to do dir listing */
            data->cancellable = g_cancellable_new();
            priv->cancellable = (GCancellable*)g_object_ref(data->cancellable);
            g_io_scheduler_push_job(list_sub_dirs,
                                    data, (GDestroyNotify)list_sub_dir_names_free,
                                    G_PRIORITY_LOW, data->cancellable);
        }
        /* calculate the length of remaining part after / */
        priv->typed_basename_len = strlen(sep + 1);
    }
    else /* clear all autocompletion thing. */
        clear_completion(priv);
}
Example #6
0
/**
 * dax_dom_document_new_from_file:
 *
 * Creates a new #DaxDomDocument. FIXME
 *
 * Return value: the newly created #DaxDomDocument instance
 */
DaxDomDocument *
dax_dom_document_new_from_file (const gchar  *filename,
                                GError      **error)
{
    DaxDomDocument *document;
    GFile *file, *directory;
    ParserContext ctx;
    gchar *base_uri;

    ctx.reader = xmlNewTextReaderFilename(filename);
    if (ctx.reader == NULL)
        return NULL;

    document = dax_document_new();
    ctx.current_node = DAX_DOM_NODE (document);

    /* Set up the base uri */
    file = g_file_new_for_commandline_arg (filename);
    directory = g_file_get_parent (file);
    base_uri = g_file_get_uri (directory);
    dax_dom_document_set_base_iri (document, base_uri);
    g_free (base_uri);
    g_object_unref (file);
    g_object_unref (directory);

    dax_dom_document_parse_and_setup (document, &ctx);

    return document;
}
static GtkWidget *
cc_sharing_panel_new_media_sharing_row (const char     *uri_or_path,
                                        CcSharingPanel *self)
{
  GtkWidget *row, *box, *w;
  GUserDirectory dir = G_USER_N_DIRECTORIES;
  GIcon *icon;
  guint i;
  char *basename, *path;
  GFile *file;

  file = g_file_new_for_commandline_arg (uri_or_path);
  path = g_file_get_path (file);
  g_object_unref (file);

  row = gtk_list_box_row_new ();
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  gtk_container_set_border_width (GTK_CONTAINER (box), 12);
  gtk_container_add (GTK_CONTAINER (row), box);

  /* Find the icon and create it */
  for (i = 0; i < G_USER_N_DIRECTORIES; i++)
    {
      if (g_strcmp0 (path, g_get_user_special_dir (i)) == 0)
        {
          dir = i;
          break;
        }
    }

  icon = special_directory_get_gicon (dir);
  w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
  gtk_widget_set_margin_end (w, 12);
  gtk_container_add (GTK_CONTAINER (box), w);
  g_object_unref (icon);

  /* Label */
  basename = g_filename_display_basename (path);
  w = gtk_label_new (basename);
  g_free (basename);
  gtk_container_add (GTK_CONTAINER (box), w);

  /* Remove button */
  w = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
  gtk_widget_set_margin_top (w, 3);
  gtk_widget_set_margin_bottom (w, 3);
  gtk_widget_set_margin_end (w, 12);
  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
  gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (w), "clicked",
                    G_CALLBACK (cc_sharing_panel_remove_folder), self);
  g_object_set_data (G_OBJECT (w), "row", row);

  g_object_set_data_full (G_OBJECT (row), "path", g_strdup (path), g_free);

  gtk_widget_show_all (row);

  return row;
}
Example #8
0
static void
ag_app_import_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
    gint            response;
    GtkWidget       *fs;
    GtkFileFilter   *filter;
    GSList          *filenames   = NULL;
    const gchar     *target_type = g_variant_get_string(parameter, NULL);
    AgAppImportType type         = AG_APP_IMPORT_NONE;
    AgApp           *app         = AG_APP(user_data);

    if (strncmp("agc", target_type, 3) == 0) {
        type = AG_APP_IMPORT_AGC;
        filter = filter_chart;
    } else if (strncmp("hor", target_type, 3) == 0) {
        type = AG_APP_IMPORT_HOR;
        filter = filter_hor;
    } else {
        g_error("Unknown import type!");
    }

    fs = gtk_file_chooser_dialog_new(
            _("Select charts"),
            gtk_application_get_active_window(GTK_APPLICATION(app)),
            GTK_FILE_CHOOSER_ACTION_OPEN,
            _("_Cancel"), GTK_RESPONSE_CANCEL,
            _("_Import"), GTK_RESPONSE_ACCEPT,
            NULL
        );
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_all);
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter);
    gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter);
    gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT);
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(fs), TRUE);
    gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), FALSE);

    response = gtk_dialog_run(GTK_DIALOG(fs));

    if (response == GTK_RESPONSE_ACCEPT) {
        filenames = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(fs));
    }

    if (filenames != NULL) {
        GSList *l;

        for (l = filenames; l; l = g_slist_next(l)) {
            GFile *file;
            char  *data = l->data;

            if (data == NULL) {
                continue;
            }

            file = g_file_new_for_commandline_arg(data);
            ag_app_import_file(AG_APP(user_data), file, type);
        }
    }

    gtk_widget_destroy(fs);
}
Example #9
0
void
foreach_gxps_page (const gchar *xps_filename, GXPSPageFunc page_func, gpointer data)
{
	GError *error = NULL;
	GFile *gfile = g_file_new_for_commandline_arg (xps_filename);

	GXPSFile *file = gxps_file_new (gfile, &error);
	if (file == NULL)
		rerror ("Unable to open %s: %s", xps_filename, error->message);

	GXPSDocument *doc = gxps_file_get_document (file, 0, &error);
	if (doc == NULL)
		rerror ("Unable to open %s: %s", xps_filename, error->message);

	gint page_count = gxps_document_get_n_pages (doc);
	xps_range_set_min (range, 1);
	xps_range_set_max (range, page_count);
	if (xps_range_is_empty (range)) xps_range_append (range, 1, page_count, 1);

	gint pi;
	XpsRangeIter iter;
	xps_range_iter_init (&iter, range);
	while (xps_range_iter_next (&iter, &pi)) {
		GXPSPage *page = gxps_document_get_page (doc, pi-1, &error);
		gdouble width, height;
		gxps_page_get_size (page, &width, &height);
		page_func (page, width, height, data);
		g_object_unref (page);
	}
}
Example #10
0
static int
app_launch (gchar **args)
{
  GVariantBuilder files;
  gint i;

  if (!app_check_name (args, "launch"))
    return 1;

  if (args[1] == NULL)
    return app_activate (args[0]);

  g_variant_builder_init (&files, G_VARIANT_TYPE_STRING_ARRAY);

  for (i = 1; args[i]; i++)
    {
      GFile *file;

      /* "This operation never fails" */
      file = g_file_new_for_commandline_arg (args[i]);
      g_variant_builder_add_value (&files, g_variant_new_take_string (g_file_get_uri (file)));
      g_object_unref (file);
    }

  return app_call (args[0], "Open", g_variant_new ("([email protected]{sv})", &files, app_get_platform_data ()));
}
Example #11
0
gchar *
clean_uri (gchar * input_arg)
{
  GFile *gfile;
  gchar *fileuri;

  if (gst_uri_is_valid (input_arg))
    fileuri = g_strdup (input_arg);
  else {
    gfile = g_file_new_for_commandline_arg (input_arg);
    if (g_file_has_uri_scheme (gfile, "archive") != FALSE) {
      g_print ("ERROR: %s isn't a file\n", input_arg);
    }

    fileuri = g_file_get_path (gfile);

    if (g_str_has_suffix (fileuri, ".iso")) {
      fileuri = g_strdup_printf ("dvd://%s", fileuri);
    } else {
      fileuri = g_strdup_printf ("file://%s", fileuri);
    }
  }

  return fileuri;
}
Example #12
0
static char *
copy_db (void)
{
  GFile *src, *dest;
  char *url, *path;
  GError *error = NULL;
  gboolean ret;

  db_dir_path = g_dir_make_tmp("test-gom-find-XXXXXXX", &error);
  g_assert(db_dir_path);
  g_assert_no_error(error);

  src = g_file_new_for_commandline_arg (DB);
  path = g_build_filename(db_dir_path, "gom-db-test.db", NULL);
  dest = g_file_new_for_path (path);
  g_free (path);

  ret = g_file_copy (src, dest, G_FILE_COPY_TARGET_DEFAULT_PERMS, NULL, NULL, NULL, &error);
  g_assert_no_error(error);
  g_assert (ret);
  g_object_unref (src);

  url = g_file_get_uri(dest);
  g_object_unref (dest);

  return url;
}
Example #13
0
GSList*
eog_util_string_array_to_list (const gchar **files, gboolean create_uri)
{
	gint i;
	GSList *list = NULL;

	if (files == NULL) return list;

	for (i = 0; files[i]; i++) {
		char *str;

		if (create_uri) {
			GFile *file;

			file = g_file_new_for_commandline_arg (files[i]);
			str = g_file_get_uri (file);

			g_object_unref (file);
		} else {
			str = g_strdup (files[i]);
		}

		if (str) {
			list = g_slist_prepend (list, g_strdup (str));
			g_free (str);
		}
	}

	return g_slist_reverse (list);
}
Example #14
0
static void
destroy_and_quit(VteTerminal *terminal, GtkWidget *window)
{
	const char *output_file = g_object_get_data (G_OBJECT (terminal), "output_file");

	if (output_file) {
		GFile *file;
		GOutputStream *stream;
		GError *error = NULL;

		file = g_file_new_for_commandline_arg (output_file);
		stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));

		if (stream) {
			vte_terminal_write_contents (terminal, stream,
						     VTE_TERMINAL_WRITE_DEFAULT,
						     NULL, &error);
			g_object_unref (stream);
		}

		if (error) {
			g_printerr ("%s\n", error->message);
			g_error_free (error);
		}

		g_object_unref (file);
	}

	gtk_widget_destroy (window);
	gtk_main_quit ();
}
Example #15
0
static void
create_file_with_data (MMSms *sms,
                       const gchar *input_path_str)
{
    GError *error = NULL;
    gchar *path;
    GFile *file;
    const guint8 *data;
    gsize data_size;

    file = g_file_new_for_commandline_arg (input_path_str);
    path = g_file_get_path (file);

    data = mm_sms_get_data (sms, &data_size);
    if (!data) {
        g_printerr ("error: couldn't create file: SMS has no data\n");
        exit (EXIT_FAILURE);
    }

    if (!g_file_set_contents (path,
                              (const gchar *)data,
                              data_size,
                              &error)) {
        g_printerr ("error: cannot write to file '%s': '%s'\n",
                    input_path_str, error->message);
        exit (EXIT_FAILURE);
    }

    g_free (path);
    g_object_unref (file);
}
Example #16
0
VinagreConnection *
vinagre_connection_new_from_file (const gchar *uri, gchar **error_msg, gboolean use_bookmarks)
{
  VinagreConnection *conn;
  gchar             *data;
  GFile             *file_a;
  GError            *error;
  GHashTable        *extensions;
  GHashTableIter     iter;
  gpointer           ext;

  *error_msg = NULL;
  data = NULL;
  conn = NULL;
  error = NULL;

  file_a = g_file_new_for_commandline_arg (uri);
  if (!g_file_load_contents (file_a,
			     NULL,
			     &data,
			     NULL,
			     NULL,
			     &error))
    {
      if (error)
	{
	  *error_msg = g_strdup (error->message);
	  g_error_free (error);
	}
      else
	*error_msg = g_strdup (_("Could not open the file."));

      goto the_end;
    }

  extensions = vinagre_plugins_engine_get_plugins_by_protocol (vinagre_plugins_engine_get_default ());
  g_hash_table_iter_init (&iter, extensions);
  while (g_hash_table_iter_next (&iter, NULL, &ext))
    {
      VinagreProtocol *protocol = VINAGRE_PROTOCOL (ext);

      if (vinagre_protocol_recognize_file (protocol, file_a))
        {
          conn = vinagre_protocol_new_connection_from_file (protocol,
							    data,
							    use_bookmarks,
							    error_msg);
          break;
        }
    }

the_end:
  g_free (data);
  g_object_unref (file_a);

  if (!conn && !*error_msg)
    *error_msg = g_strdup (_("The file was not recognized by any of the plugins."));

  return conn;
}
static void
iterate_contacts (TpChannel	 *channel,
		  GArray	 *handles,
		  char		**argv)
{
	GError *error = NULL;

	int i;
	for (i = 0; i < handles->len; i++)
	{
		int handle = g_array_index (handles, int, i);
		/* FIXME: we should check that our client has the
		 * FT capability */

		/* begin ex.filetransfer.sending.gfileinfo */
		GFile *file = g_file_new_for_commandline_arg (argv[3]);
		GFileInfo *info = g_file_query_info (file,
				"standard::*",
				G_FILE_QUERY_INFO_NONE,
				NULL, &error);
		handle_error (error);

		GHashTable *props = tp_asv_new (
			TP_PROP_CHANNEL_CHANNEL_TYPE,
			G_TYPE_STRING,
			TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,

			TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
			G_TYPE_UINT,
			TP_HANDLE_TYPE_CONTACT,

			TP_PROP_CHANNEL_TARGET_HANDLE,
			G_TYPE_UINT,
			handle,

			TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME,
			G_TYPE_STRING,
			g_file_info_get_display_name (info),

			TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE,
			G_TYPE_STRING,
			g_file_info_get_content_type (info),

			TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE,
			G_TYPE_UINT64,
			g_file_info_get_size (info),

			NULL);

		tp_cli_connection_interface_requests_call_create_channel (
				conn, -1, props,
				create_ft_channel_cb,
				NULL, NULL, NULL);

		g_hash_table_destroy (props);
		g_object_unref (info);
		g_object_unref (file);
		/* end ex.filetransfer.sending.gfileinfo */
	}
}
Example #18
0
int
main (int argc, char *argv[])
{
  GError *error;
  GOptionContext *context;
  GFile *file;
  int retval = 0;
  gchar *param;
  gchar *summary;

  setlocale (LC_ALL, "");

  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  error = NULL;
  param = g_strdup_printf ("[%s...]", _("FILE"));
  summary = _("Delete the given files.");

  context = g_option_context_new (param);
  g_option_context_set_summary (context, summary);
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);
  g_option_context_free (context);
  g_free (param);

  if (error != NULL)
    {
      g_printerr (_("Error parsing commandline options: %s\n"), error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      g_error_free (error);
      return 1;
    }

  if (argc > 1)
    {
      int i;

      for (i = 1; i < argc; i++) {
	file = g_file_new_for_commandline_arg (argv[i]);
	error = NULL;
	if (!g_file_delete (file, NULL, &error))
	  {
	    if (!force ||
		!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
	      {
	        g_printerr ("Error deleting file: %s\n", error->message);
	        retval = 1;
	      }
	    g_error_free (error);
	  }
	g_object_unref (file);
      }
    }

  return retval;
}
Example #19
0
GSList*
vnr_tools_get_list_from_array (gchar **files)
{
    GSList *uri_list = NULL;
    gint i;

    if (files == NULL) return NULL;

    for (i = 0; files[i]; i++) {
        char *uri_string;

        GFile *file;

        file = g_file_new_for_commandline_arg (files[i]);

        uri_string = g_file_get_path (file);

        g_object_unref (file);

        if (uri_string) {
            uri_list = g_slist_prepend (uri_list, g_strdup (uri_string));
            g_free (uri_string);
        }
    }

    return g_slist_reverse (uri_list);
}
Example #20
0
int main (int argc, char **argv)
{
	GFile *file;
	char *url;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	gst_init (&argc, &argv);
	gtk_init (&argc, &argv);

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

	file = g_file_new_for_commandline_arg (argv[1]);
	url = g_file_get_uri (file);
	g_object_unref (file);

	create_props (url);
	g_free (url);

	gtk_main ();

	destroy_props ();

	return 0;
}
Example #21
0
String Util::canonical_external_path( const char * path , bool abort_on_error )
{
	String result;

	if ( path )
	{
		GFile * file = g_file_new_for_commandline_arg( path );

		gchar * p = g_file_get_path( file );

		g_object_unref( file );

		if ( p )
		{
			result = p;
			g_free( p );
		}
	}

	if ( abort_on_error && result.empty() )
	{
		g_error( "INVALID PATH '%s'" , path ? path : "<null>" );
	}

	return result;
}
Example #22
0
gboolean
timeout_func (gpointer user_data)
{
	char ** argv = (char **)user_data;

	g_usleep(500000);

	g_debug("Initing");

	gchar * command = g_strdup_printf("%s --dbus-name=org.dbusmenu.test --dbus-object=/org/test", argv[1]);
	g_debug("Executing: %s", command);

	gchar * output;
	g_spawn_command_line_sync(command, &output, NULL, NULL, NULL);

	GFile * ofile = g_file_new_for_commandline_arg(argv[2]);
	if (ofile != NULL) {
		g_file_replace_contents(ofile, output, g_utf8_strlen(output, -1), NULL, FALSE, 0, NULL, NULL, NULL);
	}

	g_spawn_command_line_sync("gdbus call --session --dest org.dbusmenu.test --object-path /org/test --method com.canonical.dbusmenu.Event 0 clicked \"<0>\" 0", NULL, NULL, NULL, NULL);

	g_main_loop_quit(mainloop);
	return TRUE;
}
Example #23
0
static gboolean
load_uri_args (const char **args, GFunc handler, gpointer user_data)
{
	gboolean handled;
	guint i;

	handled = FALSE;
	for (i = 0; args && args[i]; i++) {
		GFile *file;
		char *uri;

		rb_debug ("examining argument %s", args[i]);

		file = g_file_new_for_commandline_arg (args[i]);
		uri = g_file_get_uri (file);

		/*
		 * rb_uri_exists won't work if the location isn't mounted.
		 * however, things that are interesting to mount are generally
		 * non-local, so we'll process them anyway.
		 */
		if (rb_uri_is_local (uri) == FALSE || rb_uri_exists (uri)) {
			handler (uri, user_data);
		}
		g_free (uri);
		g_object_unref (file);

		handled = TRUE;
	}
	return handled;
}
Example #24
0
int
main (int argc, char *argv[])
{
    GFile *base, *crash;
    int result;

    RSVG_G_TYPE_INIT;
    g_test_init (&argc, &argv, NULL);

    if (argc < 2) {
        base = g_file_new_for_path (test_utils_get_test_data_path ());
        crash = g_file_get_child (base, "render-crash");
        test_utils_add_test_for_all_files ("/render-crash", crash, crash, test_render_crash, NULL);
        g_object_unref (base);
        g_object_unref (crash);
    } else {
        guint i;

        for (i = 1; i < argc; i++) {
            GFile *file = g_file_new_for_commandline_arg (argv[i]);

            test_utils_add_test_for_all_files ("/render-crash", NULL, file, test_render_crash, NULL);

            g_object_unref (file);
        }
    }

    result = g_test_run ();

    rsvg_cleanup ();

    return result;
}
Example #25
0
static cairo_font_face_t *
font_face_create(gchar *fontfile){
    FT_Error error;
    FT_Library library;
    FT_Face face;
    GFile *file;
    gchar *font_file;

    error = FT_Init_FreeType (&library);
    if (error) {
        g_printerr("Could not initialise freetype\n");
        exit(1);
    }

    file = g_file_new_for_commandline_arg (fontfile);
    font_file = g_file_get_uri (file);
    g_object_unref (file);

    if (!font_file) {
        g_printerr("Could not parse argument into a URI\n");
        exit(1);
    }
    error = FT_New_Face_From_URI (library, font_file, 0, &face);
    if (error) {
        g_printerr("Could not load face '%s'\n", font_file);
        exit(1);
    }
    return cairo_ft_font_face_create_for_ft_face (face, 0);
}
Example #26
0
int
main(int argc, char *argv[])
{
	GError *error = NULL;

	gtk_init(&argc, &argv);

	create_window();
	gtk_widget_show_all(window);

	if(argc < 2)
		g_error("Must provide a plugin\n");

	GFile *plugin_file;
	if( g_str_has_suffix(argv[1], ".la") )
		plugin_file = libname_from_la_file(argv[1]);
	else
		plugin_file = g_file_new_for_commandline_arg(argv[1]);

	chimara_glk_set_resource_load_callback(CHIMARA_GLK(glk), (ChimaraResourceLoadFunc)resource_load, NULL, NULL);

    if( !chimara_glk_run_file(CHIMARA_GLK(glk), plugin_file,
        argc - 1, argv + 1, &error) )
   		g_error("Error starting Glk library: %s\n", error->message);
    g_object_unref(plugin_file);

	gtk_main();

	chimara_glk_stop(CHIMARA_GLK(glk));
	chimara_glk_wait(CHIMARA_GLK(glk));
	g_object_unref(glk);

	return 0;
}
Example #27
0
static const char *
get_output_dir (void)
{
  static const char *output_dir = NULL;
  GError *error = NULL;

  if (output_dir)
    return output_dir;

  if (arg_output_dir)
    {
      GFile *file = g_file_new_for_commandline_arg (arg_output_dir);
      output_dir = g_file_get_path (file);
      g_object_unref (file);
    }
  else
    {
      output_dir = g_get_tmp_dir ();
    }

  if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
    {
      GFile *file;

      file = g_file_new_for_path (output_dir);
      g_assert (g_file_make_directory_with_parents (file, NULL, &error));
      g_assert_no_error (error);
      g_object_unref (file);
    }

  return output_dir;
}
Example #28
0
void install_monitor()
{
    if (_inotify_fd == -1) {
        _inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
        _monitor_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_object_unref);
        g_timeout_add(50, (GSourceFunc)_inotify_poll, NULL);

        _desktop_file = g_file_new_for_commandline_arg(DESKTOP_DIR());
        _trash_can = g_file_new_for_uri("trash:///");
        GFileMonitor* m = g_file_monitor(_trash_can, G_FILE_MONITOR_NONE, NULL, NULL);
        g_signal_connect(m, "changed", G_CALLBACK(trash_changed), NULL);

        _add_monitor_directory(_desktop_file);

        GDir *dir =  g_dir_open(DESKTOP_DIR(), 0, NULL);

        if (dir != NULL) {
            const char* filename = NULL;
            while ((filename = g_dir_read_name(dir)) != NULL) {
                GFile* f = g_file_get_child(_desktop_file, filename);
                _add_monitor_directory(f);
                g_object_unref(f);
            }
            g_dir_close(dir);
        }
    }
}
gboolean
xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable, GError **error)
{
  gboolean ret = FALSE;
  g_autoptr(GOptionContext) context = NULL;
  g_autoptr(GFile) base = NULL;
  g_autoptr(GFile) files = NULL;
  g_autoptr(GFile) metadata = NULL;
  g_autoptr(GFile) export = NULL;
  g_autoptr(GFile) repofile = NULL;
  g_autoptr(GFile) arg = NULL;
  g_autoptr(GFile) root = NULL;
  g_autoptr(OstreeRepo) repo = NULL;
  const char *location;
  const char *directory;
  const char *branch;
  g_autofree char *arch = NULL;
  g_autofree char *full_branch = NULL;
  g_autofree char *app_id = NULL;
  g_autofree char *parent = NULL;
  g_autofree char *commit_checksum = NULL;
  g_autofree char *metadata_contents = NULL;
  g_autofree char *format_size = NULL;
  g_autoptr(OstreeMutableTree) mtree = NULL;
  g_autoptr(GKeyFile) metakey = NULL;
  gsize metadata_size;
  g_autofree char *subject = NULL;
  g_autofree char *body = NULL;
  OstreeRepoTransactionStats stats;
  OstreeRepoCommitModifier *modifier = NULL;

  context = g_option_context_new ("LOCATION DIRECTORY [BRANCH] - Create a repository from a build directory");

  if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
    goto out;

  if (argc < 3)
    {
      usage_error (context, "LOCATION and DIRECTORY must be specified", error);
      goto out;
    }

  location = argv[1];
  directory = argv[2];

  if (argc >= 4)
    branch = argv[3];
  else
    branch = "master";

  if (!xdg_app_is_valid_branch (branch))
    {
      xdg_app_fail (error, "'%s' is not a valid branch name", branch);
      goto out;
    }

  base = g_file_new_for_commandline_arg (directory);
  files = g_file_get_child (base, "files");
  metadata = g_file_get_child (base, "metadata");
  export = g_file_get_child (base, "export");
static GList *
get_tracker_locations (void)
{
  gchar **locations;
  GList *list;
  gint idx;
  Place *location;
  const gchar *path;

  locations = g_settings_get_strv (tracker_preferences, TRACKER_KEY_RECURSIVE_DIRECTORIES);
  list = NULL;

  for (idx = 0; locations[idx] != NULL; idx++)
    {
      path = path_from_tracker_dir (locations[idx]);

      location = g_slice_new0 (Place);
      location->location = g_file_new_for_commandline_arg (path);
      location->display_name = g_file_get_basename (location->location);
      location->place_type = PLACE_OTHER;

      list = g_list_prepend (list, location);
    }

  g_strfreev (locations);

  return g_list_reverse (list);
}