Exemple #1
0
void
gth_location_chooser_set_current (GthLocationChooser *self,
				  GFile              *file)
{


	if (self->priv->file_source != NULL)
		g_object_unref (self->priv->file_source);
	self->priv->file_source = gth_main_get_file_source (file);

	if (self->priv->file_source == NULL)
		return;

	if ((self->priv->location != NULL) && g_file_equal (file, self->priv->location))
		return;

	if (self->priv->location != NULL)
		g_object_unref (self->priv->location);
	self->priv->location = g_file_dup (file);

	if (gtk_widget_get_realized (GTK_WIDGET (self)))
		current_location_changed (self);

	g_signal_emit (G_OBJECT (self), gth_location_chooser_signals[CHANGED], 0);
}
Exemple #2
0
GObject *
gth_search_real_duplicate (GthDuplicable *duplicable)
{
	GthSearch *search = GTH_SEARCH (duplicable);
	GthSearch *new_search;
	GList     *file_list;
	GList     *new_file_list = NULL;
	GList     *scan;

	new_search = gth_search_new ();
	
	gth_search_set_folder (new_search, gth_search_get_folder (search));
	gth_search_set_recursive (new_search, gth_search_is_recursive (search));
	
	if (search->priv->test != NULL)
		new_search->priv->test = (GthTestChain*) gth_duplicable_duplicate (GTH_DUPLICABLE (search->priv->test));

	file_list = gth_catalog_get_file_list (GTH_CATALOG (search));
	for (scan = file_list; scan; scan = scan->next) {
		GFile *file = scan->data;		
		new_file_list = g_list_prepend (new_file_list, g_file_dup (file));
	}
	gth_catalog_set_file_list (GTH_CATALOG (new_search), new_file_list);
	
	_g_object_list_unref (new_file_list);
	
	return (GObject *) new_search;
}
Exemple #3
0
static void
gth_file_source_queue_for_each_child (GthFileSource        *file_source,
				      GFile                *parent,
				      gboolean              recursive,
				      const char           *attributes,
				      StartDirCallback      dir_func,
				      ForEachChildCallback  child_func,
				      ReadyCallback         ready_func,
				      gpointer              data)
{
	FileSourceAsyncOp *async_op;

	async_op = g_new0 (FileSourceAsyncOp, 1);
	async_op->file_source = file_source;
	async_op->op = FILE_SOURCE_OP_FOR_EACH_CHILD;
	async_op->data.fec.parent = g_file_dup (parent);
	async_op->data.fec.recursive = recursive;
	async_op->data.fec.attributes = attributes;
	async_op->data.fec.dir_func = dir_func;
	async_op->data.fec.child_func = child_func;
	async_op->data.fec.ready_func = ready_func;
	async_op->data.fec.data = data;

	file_source->priv->queue = g_list_append (file_source->priv->queue, async_op);
}
Exemple #4
0
static void
copy_files_to_folder (GthBrowser *browser,
		      GList      *files,
		      gboolean    move,
		      char       *destination_uri,
		      gboolean    view_destination)
{
	GthFileData      *destination_data;
	GthFileSource    *file_source;
	CopyToFolderData *data;
	GthTask          *task;

	destination_data = gth_file_data_new_for_uri (destination_uri, NULL);
	file_source = gth_main_get_file_source (destination_data->file);

	data = g_new0 (CopyToFolderData, 1);
	data->browser = g_object_ref (browser);
	data->move = move;
	data->destination = g_file_dup (destination_data->file);
	data->view_destination = view_destination;

	task = gth_copy_task_new (file_source, destination_data, move, files, -1);
	g_signal_connect (task,
			  "completed",
			  G_CALLBACK (copy_complete_cb),
			  data);
	gth_browser_exec_task (browser, task, GTH_TASK_FLAGS_DEFAULT);

	g_object_unref (file_source);
}
static void
list_ready_cb (GList    *files,
	       GError   *error,
	       gpointer  user_data)
{
	DialogData *data = user_data;

	data->loading_list = FALSE;

	if (data->cancelling) {
		gth_file_list_cancel (GTH_FILE_LIST (data->file_list), cancel_done, data);
	}
	else if (error != NULL) {
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not load the folder"), error);
	}
	else {
		_g_object_unref (data->last_source);
		data->last_source = g_file_dup (data->source);

		data->files = _g_object_list_ref (files);
		gth_file_list_set_files (GTH_FILE_LIST (data->file_list), data->files);
	}

	update_sensitivity (data);
}
static void
copy_from_menu_item_activate_cb (GtkMenuItem *menu_item,
         			 gpointer     user_data)
{
	GthContactSheetThemeDialog *self = user_data;
	char                       *display_name;
	GFile                      *file;
	GthContactSheetTheme       *theme;

	if ((self->priv->theme != NULL) && (self->priv->theme->file != NULL))
		file = g_file_dup (self->priv->theme->file);
	else
		file = NULL;
	display_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry"))));

	theme = g_object_get_data (G_OBJECT (menu_item), "theme");
	if (theme != NULL)
		update_controls_from_theme (self, theme);
	gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), display_name);

	_g_object_unref (self->priv->theme->file);
	self->priv->theme->file = _g_object_ref (file);

	g_free (display_name);
	_g_object_unref (file);
}
Exemple #7
0
VimEditor*
vim_editor_new (AnjutaPlugin *plugin, GFile* file)
{
    VimEditor *editor;
    VimWidget *widget;
    GError *err = NULL;

    if (!file)
        file = g_file_new_for_path (UNTITLED_FILE);

    DEBUG_PRINT ("VimPlugin: Creating new editor ...");

    widget = VIM_WIDGET (g_object_new(VIM_TYPE_WIDGET,
                                      NULL));

    if (!widget->priv->plugin) widget->priv->plugin = (VimPlugin*)plugin;

    /* Make sure that editors aren't repeated */
    if (editor = vim_widget_get_document_file (widget, file, NULL))
    {
        g_object_unref (widget);
        return g_object_ref (editor);
    }

    editor = VIM_EDITOR (g_object_new(VIM_TYPE_EDITOR, NULL));
    editor->priv->file = g_file_dup(file);
    vim_widget_add_document (widget, editor, NULL);
    g_object_unref (widget);

    /* Add to the documents */
    return g_object_ref_sink (editor);
}
Exemple #8
0
void
catalogs__gth_browser_file_renamed_cb (GthBrowser *browser,
				       GFile      *file,
				       GFile      *new_file)
{
	GthFileStore *file_store;
	BrowserData  *data;
	GFile        *location;
	GList        *scan;
	RenameData   *rename_data;

	if (! GTH_IS_FILE_SOURCE_CATALOGS (gth_browser_get_location_source (browser)))
		return;

	file_store = gth_browser_get_file_store (browser);
	if (! gth_file_store_find (file_store, file, NULL))
		return;

	location = gth_browser_get_location (browser);
	if (location == NULL)
		return;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);

	rename_data = NULL;
	for (scan = data->rename_data_list; scan; scan = scan->next) {
		RenameData *rename_data_scan = scan->data;
		if (g_file_equal (rename_data_scan->location, location)) {
			rename_data = rename_data_scan;
			break;
		}
	}

	if (rename_data == NULL) {
		rename_data = rename_data_new (location);
		data->rename_data_list = g_list_prepend (data->rename_data_list, rename_data);
	}

	rename_data->files = g_list_prepend (rename_data->files, g_file_dup (file));
	rename_data->new_files = g_list_prepend (rename_data->new_files, g_file_dup (new_file));

	if (data->update_renamed_files_id != 0)
		g_source_remove (data->update_renamed_files_id);
	data->update_renamed_files_id = g_timeout_add (UPDATE_RENAMED_FILES_DELAY,
						       process_rename_data_list,
						       data);
}
Exemple #9
0
void
gb_beautifier_process_launch_async (GbBeautifierWorkbenchAddin  *self,
                                    IdeSourceView               *source_view,
                                    GtkTextIter                 *begin,
                                    GtkTextIter                 *end,
                                    GbBeautifierConfigEntry     *entry,
                                    GAsyncReadyCallback          callback,
                                    GCancellable                *cancellable,
                                    gpointer                     user_data)
{
  GtkTextBuffer *buffer;
  ProcessState *state;
  g_autoptr(GTask) task = NULL;
  const gchar *lang_id;

  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
  g_assert (IDE_IS_SOURCE_VIEW (source_view));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
  g_assert (entry != NULL);
  g_assert (callback != NULL);

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view));
  lang_id = gb_beautifier_helper_get_lang_id (self, source_view);

  if (begin == NULL)
    gtk_text_buffer_get_start_iter (buffer, begin);

  if (end == NULL)
    gtk_text_buffer_get_end_iter (buffer, begin);

  g_assert (gtk_text_iter_get_buffer (begin) == buffer);
  g_assert (gtk_text_iter_get_buffer (end) == buffer);

  state = g_slice_new0 (ProcessState);
  state->self = self;
  state->source_view = source_view;

  gtk_text_iter_order (begin, end);
  state->text = gtk_text_buffer_get_text (buffer, begin, end, FALSE);
  state->begin_mark = gtk_text_buffer_create_mark (buffer, NULL, begin, TRUE);
  state->end_mark = gtk_text_buffer_create_mark (buffer, NULL, end, FALSE);
  state->command = entry->command;
  state->lang_id = g_strdup (lang_id);

  if (G_IS_FILE (entry->config_file))
    state->config_file = g_file_dup (entry->config_file);

  if (entry->command_args != NULL)
    state->command_args = command_args_copy (entry->command_args);
  task = g_task_new (self, cancellable, callback, user_data);
  g_task_set_source_tag (task, gb_beautifier_process_launch_async);
  g_task_set_task_data (task, state, process_state_free);

  gb_beautifier_helper_create_tmp_file_async (self,
                                              state->text,
                                              create_tmp_file_cb,
                                              cancellable,
                                              g_steal_pointer (&task));
}
/*
 *	computes the relative complement of A in B.
 *	we view FileOpsClipboardInfo's file_list as a set.
 *	return B-A = {x in B| x not in A}.
 *	@A : the current clipboard_info
 *	@B : the previous clipboard_info
 *	@return B-A: the set of files we need to un-fade on the desktop.
 */
static GList*
__set_diff_clipboard_info (FileOpsClipboardInfo* A, FileOpsClipboardInfo* B)
{
    //previous clipboard_info operation must be 'cut'.
    g_assert (B->cut == TRUE);

    GList* file_list = NULL;

#if 0
    g_debug ("__set_diff: A op : %s", A->cut?"cut":"paste");
    for (int i=0; i<A->num; i++)
    {
	g_debug ("A: %d : %s", i, g_file_get_uri (A->file_list[i]));
    }
#endif
    //send all files in B
    if (A->cut != B->cut)
    {
	for (int i = 0; i < B->num; i++)
	{
	    GFile* dup_file = g_file_dup (B->file_list[i]);
	    file_list = g_list_append (file_list, dup_file);
	}
    }
    else
    {
	for (int i = 0; i < B->num; i++)
	{
	    gboolean is_in_A = FALSE;
	    for (int j = 0; j < A->num; j++)
	    {
	    	if (g_file_equal (B->file_list[i], A->file_list[j]))
	    	{
		    is_in_A = TRUE;
		    break;
		}
	    }
	    if (!is_in_A)
	    {
		GFile* dup_file = g_file_dup (B->file_list[i]);
            	file_list = g_list_append (file_list, dup_file);
	    }
	}
    }
    return file_list;
}
Exemple #11
0
/**
 * gtr_po_get_location:
 * @po: a #GtrPo
 *
 * Gets the GFile of the po file.
 *
 * Returns: (transfer full): the GFile associated with the @po. The returned
 *          location must be freed with g_object_unref.
 **/
GFile *
gtr_po_get_location (GtrPo * po)
{
  GtrPoPrivate *priv = gtr_po_get_instance_private (po);
  g_return_val_if_fail (GTR_IS_PO (po), NULL);

  return g_file_dup (priv->location);
}
static GPtrArray *
copy_files (GPtrArray *in)
{
  GPtrArray *out = g_ptr_array_new_full (in->len, g_object_unref);
  for (guint i = 0; i < in->len; i++)
    g_ptr_array_add (out, g_file_dup (g_ptr_array_index (in, i)));
  return g_steal_pointer (&out);
}
Exemple #13
0
void
dlg_catalog_properties (GthBrowser  *browser,
			GthFileData *file_data)
{
	DialogData *data;

	g_return_if_fail (file_data != NULL);

	data = g_new0 (DialogData, 1);
	data->browser = browser;
	data->file_data = gth_file_data_dup (file_data);
	data->original_file = g_file_dup (data->file_data->file);
	data->builder = _gtk_builder_new_from_file ("catalog-properties.ui", "catalogs");

	/* Set widgets data. */

	data->dialog = g_object_new (GTK_TYPE_DIALOG,
				     "title", _("Properties"),
				     "transient-for", GTK_WINDOW (browser),
				     "modal", TRUE,
				     "destroy-with-parent", FALSE,
				     "use-header-bar", _gtk_settings_get_dialogs_use_header (),
				     NULL);
	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))),
			   _gtk_builder_get_widget (data->builder, "dialog_content"));
	gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
				_GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
				_GTK_LABEL_SAVE, GTK_RESPONSE_OK,
				NULL);
	_gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION);

	data->time_selector = gth_time_selector_new ();
	gth_time_selector_show_time (GTH_TIME_SELECTOR (data->time_selector), FALSE, FALSE);
	gtk_widget_show (data->time_selector);
	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("date_container_box")), data->time_selector, TRUE, TRUE, 0);

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  data);
	g_signal_connect (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK),
			  "clicked",
			  G_CALLBACK (save_button_clicked_cb),
			  data);
	g_signal_connect_swapped (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_CANCEL),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  data->dialog);

	/* run dialog. */

	gtk_widget_grab_focus (GET_WIDGET ("name_entry"));
	gth_catalog_load_from_file_async (file_data->file, NULL, catalog_ready_cb, data);
}
Exemple #14
0
static void
gth_file_source_queue_rename (GthFileSource *file_source,
			      GFile         *file,
			      GFile         *new_file,
			      ReadyCallback  callback,
			      gpointer       data)
{
	FileSourceAsyncOp *async_op;

	async_op = g_new0 (FileSourceAsyncOp, 1);
	async_op->file_source = file_source;
	async_op->op = FILE_SOURCE_OP_RENAME;
	async_op->data.rename.file = g_file_dup (file);
	async_op->data.rename.new_file = g_file_dup (new_file);
	async_op->data.rename.callback = callback;
	async_op->data.rename.data = data;

	file_source->priv->queue = g_list_append (file_source->priv->queue, async_op);
}
Exemple #15
0
static RenameData *
rename_data_new (GFile *location)
{
	RenameData *rename_data;

	rename_data = g_new0 (RenameData, 1);
	rename_data->location = g_file_dup (location);

	return rename_data;
}
Exemple #16
0
MkpProject *
mkp_project_new (GFile *file, GError  **error)
{
	MkpProject *project;

	project = MKP_PROJECT (g_object_new (MKP_TYPE_PROJECT, NULL));
	project->parent.file = (file != NULL) ? g_file_dup (file) : NULL;
	project->parent.type = ANJUTA_PROJECT_ROOT;

	return project;
}
Exemple #17
0
GthTask *
gth_organize_task_new (GthBrowser     *browser,
		       GFile          *folder,
		       GthGroupPolicy  group_policy)
{
	GthOrganizeTask *self;

	self = (GthOrganizeTask *) g_object_new (GTH_TYPE_ORGANIZE_TASK, NULL);
	self->priv->browser = browser;
	self->priv->folder = g_file_dup (folder);
	self->priv->group_policy = group_policy;

	return (GthTask*) self;
}
Exemple #18
0
AnjutaProjectNode*
dir_root_node_new (GFile *file)
{
	AnjutaDirRootNode *root = NULL;

	root = g_object_new (ANJUTA_TYPE_DIR_ROOT_NODE, NULL);
	root->base.type = ANJUTA_PROJECT_ROOT;
	root->base.custom_properties = NULL;
	root->base.native_properties = NULL;
	root->base.file = g_file_dup (file);
	root->base.name = NULL;

	return ANJUTA_PROJECT_NODE (root);
}
void
dlg_catalog_properties (GthBrowser  *browser,
			GthFileData *file_data)
{
	DialogData *data;

	g_return_if_fail (file_data != NULL);

	data = g_new0 (DialogData, 1);
	data->browser = browser;
	data->file_data = gth_file_data_dup (file_data);
	data->original_file = g_file_dup (data->file_data->file);
	data->builder = _gtk_builder_new_from_file ("catalog-properties.ui", "catalogs");
	data->dialog = GET_WIDGET ("properties_dialog");

	/* Set widgets data. */

	data->time_selector = gth_time_selector_new ();
	gth_time_selector_show_time (GTH_TIME_SELECTOR (data->time_selector), FALSE, FALSE);
	gtk_widget_show (data->time_selector);
	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("date_container_box")), data->time_selector, TRUE, TRUE, 0);

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  data);
	g_signal_connect (G_OBJECT (GET_WIDGET ("save_button")),
			  "clicked",
			  G_CALLBACK (save_button_clicked_cb),
			  data);
	g_signal_connect_swapped (G_OBJECT (GET_WIDGET ("cancel_button")),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  data->dialog);
	g_signal_connect (G_OBJECT (GET_WIDGET ("help_button")),
			  "clicked",
			  G_CALLBACK (help_button_clicked_cb),
			  data);

	/* run dialog. */

	gtk_widget_grab_focus (GET_WIDGET ("name_entry"));
	gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);

	gth_catalog_load_from_file_async (file_data->file, NULL, catalog_ready_cb, data);
}
Exemple #20
0
AnjutaProjectNode*
dir_source_node_new (GFile *file)
{
	AnjutaDirSourceNode *source = NULL;

	source = g_object_new (ANJUTA_TYPE_DIR_SOURCE_NODE, NULL);
	source->base.type = ANJUTA_PROJECT_SOURCE;
	source->base.native_properties = NULL;
	source->base.custom_properties = NULL;
	source->base.name = NULL;
	source->base.file = g_file_dup (file);
	source->base.state = ANJUTA_PROJECT_CAN_REMOVE |
						ANJUTA_PROJECT_REMOVE_FILE;

	return ANJUTA_PROJECT_NODE (source);
}
Exemple #21
0
/**
 * gtr_po_set_location:
 * @po: a #GtrPo
 * @location: The GFile to set to the #GtrPo
 *
 * Sets the GFile location within the #GtrPo object.
 **/
void
gtr_po_set_location (GtrPo * po, GFile * location)
{
  GtrPoPrivate *priv = gtr_po_get_instance_private (po);
  g_return_if_fail (GTR_IS_PO (po));

  if (priv->location)
    {
      if (g_file_equal (priv->location, location))
        return;
      g_object_unref (priv->location);
    }

  priv->location = g_file_dup (location);

  g_object_notify (G_OBJECT (po), "location");
}
Exemple #22
0
static void
gth_file_source_queue_list (GthFileSource *file_source,
			    GFile         *folder,
			    const char    *attributes,
			    ListReady      func,
			    gpointer       data)
{
	FileSourceAsyncOp *async_op;

	async_op = g_new0 (FileSourceAsyncOp, 1);
	async_op->file_source = file_source;
	async_op->op = FILE_SOURCE_OP_LIST;
	async_op->data.list.folder = g_file_dup (folder);
	async_op->data.list.attributes = attributes;
	async_op->data.list.func = func;
	async_op->data.list.data = data;

	file_source->priv->queue = g_list_append (file_source->priv->queue, async_op);
}
Exemple #23
0
static GList *
base_get_current_list (GthFileSource  *file_source,
		       GFile          *file)
{
	GList *list = NULL;
	GFile *parent;

	if (file == NULL)
		return NULL;

	parent = g_file_dup (file);
	while (parent != NULL) {
		GFile *tmp;

		list = g_list_prepend (list, g_object_ref (parent));
		tmp = g_file_get_parent (parent);
		g_object_unref (parent);
		parent = tmp;
	}

	return g_list_reverse (list);
}
Exemple #24
0
gboolean gtodo_client_load(GTodoClient *cl, GFile *xml_file, GError **error)
{
	void  *(* function)(gpointer cl, gpointer data) ;
	gpointer data;	
	
	if (cl->gtodo_doc)
		xmlFreeDoc(cl->gtodo_doc);
	cl->gtodo_doc = NULL;
	cl->root = NULL;
	function = cl->function;
	data = cl->data;
	gtodo_client_destroy_changed_callback	(cl, function, data);
	if (cl->xml_file)
		g_object_unref (cl->xml_file);

	cl->xml_file = g_file_dup (xml_file);
	if(!gtodo_client_check_file(cl, error)) return FALSE;
	
	gtodo_client_set_changed_callback (cl, function, data);
	if (cl->function)
		cl->function(cl, cl->data);

	return TRUE;
}
Exemple #25
0
static GsfInput *
gsf_input_gio_dup (GsfInput *src_input, GError **err)
{
    GsfInputGio *src = (GsfInputGio *)src_input;
    GFile *clone;

    g_return_val_if_fail (src_input != NULL, NULL);
    g_return_val_if_fail (src->file != NULL, NULL);

    clone = g_file_dup (src->file);
    if (clone != NULL) {
        GsfInput *dst = gsf_input_gio_new (clone, err);

        /*
         * gsf_input_gio_new() adds a ref, or fails to create a new
         * file.  in any case, we need to unref the clone
         */
        g_object_unref (clone);

        return dst;
    }

    return NULL;
}
Exemple #26
0
static GFile *
base_to_gio_file (GthFileSource *file_source,
		  GFile         *file)
{
	return g_file_dup (file);
}
Exemple #27
0
static void
new_library_button_clicked_cb (GtkWidget  *widget,
		       	       DialogData *data)
{
	char          *name;
	GthFileData   *selected_parent;
	GFile         *parent;
	GthFileSource *file_source;
	GFile         *gio_parent;
	GError        *error = NULL;
	GFile         *gio_file;

	name = _gtk_request_dialog_run (GTK_WINDOW (data->dialog),
					GTK_DIALOG_MODAL,
					_("Enter the library name: "),
					"",
					1024,
					GTK_STOCK_CANCEL,
					_("C_reate"));
	if (name == NULL)
		return;

	selected_parent = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (data->source_tree));
	if (selected_parent != NULL) {
		GthFileSource *file_source;
		GFileInfo     *info;

		file_source = gth_main_get_file_source (selected_parent->file);
		info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES);
		if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
			parent = g_file_get_parent (selected_parent->file);
		else
			parent = g_file_dup (selected_parent->file);

		g_object_unref (info);
		g_object_unref (file_source);
	}
	else
		parent = g_file_new_for_uri ("catalog:///");

	file_source = gth_main_get_file_source (parent);
	gio_parent = gth_file_source_to_gio_file (file_source, parent);
	gio_file = _g_directory_create_unique (gio_parent, name, "", &error);
	if (gio_file != NULL) {
		GFile *file;
		GList *list;

		file = gth_catalog_file_from_gio_file (gio_file, NULL);
		list = g_list_prepend (NULL, file);
		gth_monitor_folder_changed (gth_main_get_default_monitor (),
					    parent,
					    list,
					    GTH_MONITOR_EVENT_CREATED);

		g_list_free (list);
		g_object_unref (file);
	}
	else
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not create the library"), &error);

	g_object_unref (gio_file);
	g_object_unref (gio_parent);
	g_object_unref (file_source);

	/*

	selected_catalog = gth_folder_tree_get_selected (GTH_FOLDER_TREE (data->source_tree));
	parent = get_catalog_parent (selected_catalog->file);
	new_library = g_file_get_child_for_display_name (parent, name, &error);

	if ((new_library != NULL) && (strchr (display_name, '/') != NULL)) {
		error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, _("The name \"%s\" is not valid because it contains the character \"/\". " "Please use a different name."), display_name);
		g_object_unref (new_library);
		new_library = NULL;
	}

	if (error == NULL) {
		GFile *gio_file;

		gio_file = gth_file_source_to_gio_file (data->file_source, new_library);
		g_file_make_directory (new_library, NULL, &error);

		g_object_unref (gio_file);
	}

	if (error != NULL)
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not create a new library"), &error);

	if (new_library != NULL)
		g_object_unref (new_library);
	g_object_unref (parent);
	g_object_unref (selected_catalog);
	g_free (name);

	*/
}
Exemple #28
0
void
gth_browser_activate_action_tool_desktop_background (GtkAction  *action,
					             GthBrowser *browser)
{
	WallpaperData *wdata;
	gboolean       saving_wallpaper = FALSE;
	GList         *items;
	GList         *file_list;
	GthFileData   *file_data;
	const char    *mime_type;

	wdata = wallpaper_data_new (browser);

	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
	file_data = (file_list != NULL) ? file_list->data : NULL;
	mime_type = (file_data != NULL) ? gth_file_data_get_mime_type (file_data) : NULL;

	if (gth_main_extension_is_active ("image_viewer")
	    && (gth_browser_get_file_modified (browser) || ! _gdk_pixbuf_mime_type_is_readable (mime_type)))
	{
		GtkWidget *viewer_page;

		viewer_page = gth_browser_get_viewer_page (browser);
		if (viewer_page != NULL) {
			GthImage *image;
			GthTask  *task;

			image = gth_image_new_for_surface (gth_image_viewer_page_get_image (GTH_IMAGE_VIEWER_PAGE (viewer_page)));
			file_data = gth_file_data_new (wdata->new_style.file, NULL);
			task = gth_save_image_task_new (image,
							"image/jpeg",
							file_data,
							GTH_OVERWRITE_RESPONSE_YES);
			g_signal_connect (task,
					  "completed",
					  G_CALLBACK (save_wallpaper_task_completed_cb),
					  wdata);
			gth_browser_exec_task (GTH_BROWSER (browser), task, FALSE);

			saving_wallpaper = TRUE;

			_g_object_unref (task);
			g_object_unref (image);
		}
	}

	if (saving_wallpaper)
		return;

	if (file_data == NULL)
		return;

	if (g_file_is_native (file_data->file)) {
		_g_object_unref (wdata->new_style.file);
		wdata->new_style.file = g_file_dup (file_data->file);
		wallpaper_data_set (wdata);
	}
	else
		g_file_copy_async (file_data->file,
				   wdata->new_style.file,
				   G_FILE_COPY_OVERWRITE,
				   G_PRIORITY_DEFAULT,
				   NULL,
				   NULL,
				   NULL,
				   copy_wallpaper_ready_cb,
				   wdata);

	_g_object_list_unref (file_list);
	_gtk_tree_path_list_free (items);
}
Exemple #29
0
static void
catalog_new_dialog_response_cb (GtkWidget *dialog,
				int        response_id,
				gpointer   user_data)
{
	GthBrowser    *browser = user_data;
	char          *name;
	GthFileData   *selected_parent;
	GFile         *parent;
	GthFileSource *file_source;
	GFile         *gio_parent;
	char          *display_name;
	GError        *error = NULL;
	GFile         *gio_file;

	if (response_id != GTK_RESPONSE_OK) {
		gtk_widget_destroy (dialog);
		return;
	}

	name = gth_request_dialog_get_normalized_text (GTH_REQUEST_DIALOG (dialog));
	if (_g_utf8_all_spaces (name)) {
		g_free (name);
		gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, _("No name specified"));
		return;
	}

	if (g_regex_match_simple ("/", name, 0, 0)) {
		char *message;

		message = g_strdup_printf (_("Invalid name. The following characters are not allowed: %s"), "/");
		gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, message);

		g_free (message);
		g_free (name);

		return;
	}

	selected_parent = gth_browser_get_folder_popup_file_data (browser);
	if (selected_parent != NULL) {
		GthFileSource *file_source;
		GFileInfo     *info;

		file_source = gth_main_get_file_source (selected_parent->file);
		info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES);
		if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
			parent = g_file_get_parent (selected_parent->file);
		else
			parent = g_file_dup (selected_parent->file);

		g_object_unref (info);
		g_object_unref (file_source);
	}
	else
		parent = g_file_new_for_uri ("catalog:///");

	file_source = gth_main_get_file_source (parent);
	gio_parent = gth_file_source_to_gio_file (file_source, parent);
	display_name = g_strconcat (name, ".catalog", NULL);
	gio_file = g_file_get_child_for_display_name (gio_parent, display_name, &error);
	if (gio_file != NULL) {
		GFileOutputStream *stream;

		stream = g_file_create (gio_file, G_FILE_CREATE_NONE, NULL, &error);
		if (stream != NULL) {
			GFile *file;
			GList *list;

			file = gth_catalog_file_from_gio_file (gio_file, NULL);
			list = g_list_prepend (NULL, file);
			gth_monitor_folder_changed (gth_main_get_default_monitor (),
						    parent,
						    list,
						    GTH_MONITOR_EVENT_CREATED);

			g_list_free (list);
			g_object_unref (file);
			g_object_unref (stream);
		}

		g_object_unref (gio_file);
	}

	if (error != NULL) {
		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
			gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, _("Name already used"));
		else
			gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, error->message);
		g_clear_error (&error);
	}
	else
		gtk_widget_destroy (dialog);

	g_free (display_name);
	g_object_unref (gio_parent);
	g_object_unref (file_source);
	g_free (name);
}
Exemple #30
0
void
watcher_event(GFileMonitor *monitor, GFile *file, GFile *other_file,
    GFileMonitorEvent event_type, gpointer user_data)
{
  GFile *parent, *top, *tmp;
  gboolean depth = 1;
  watcher_t *watcher;
  watcher_event_t *event;

  if (!user_data)
    return;

  watcher = (watcher_t *) user_data;

  parent = g_file_new_for_path(watcher->path);

  event = (watcher_event_t *) g_new0(watcher_event_t, 1);
  event->watcher = watcher;
  event->file = g_file_get_path(file);
  event->rfile = g_file_get_relative_path(parent, file);
  if (!event->rfile)
    event->rfile = g_strdup("");

  if (watcher->recursive)
    {
      for (top = g_file_dup(file), depth = 1;
          !g_file_equal(top, parent) && !g_file_has_parent(top, parent); top =
              tmp, depth++)
        {
          tmp = g_file_get_parent(top);

          g_object_unref(top);
        }

      g_object_unref(top);

      LOG_DEBUG("%s: file depth to watcher path is '%d'", watcher->name, depth);
    }

  g_object_unref(parent);

  LOG_DEBUG("%s: %s (event_type=%d, file=%s)",
      watcher->name, N_("watcher event received"), event_type, event->file);

  switch (event_type)
  {
  case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
    {
      event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_CHANGING);

      break;
    }

  case G_FILE_MONITOR_EVENT_CHANGED:
    {
      event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_CHANGED);

      break;
    }

  case G_FILE_MONITOR_EVENT_CREATED:
    {
      event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_CREATED);

      break;
    }

  case G_FILE_MONITOR_EVENT_DELETED:
    {
      event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_DELETED);

      break;
    }

  case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
    {
      event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_ATTRIBUTECHANGED);

      break;
    }

  default:
    {
      LOG_DEBUG("%s: %s (event_type=%d)",
          watcher->name, N_("unknown event"), event_type);

      g_free(event->file);
      g_free(event->rfile);
      g_free(event);

      return;

      break;
    }
  }

  if ((event_type == G_FILE_MONITOR_EVENT_DELETED) && watcher->recursive
      && (g_strcmp0(event->file, watcher->path) != 0))
    {
      watcher_remove_monitor_for_recursive_path(watcher, event->file);
    }

  if (!watcher_event_test(watcher, event))
    {
      LOG_DEBUG("%s: %s (event=%s, file=%s)",
          watcher->name, N_("event ignored"), event->event, event->file);

      g_free(event->event);
      g_free(event->file);
      g_free(event->rfile);
      g_free(event);

      return;
    }

  if (event_type == G_FILE_MONITOR_EVENT_CREATED && watcher->recursive
      && g_file_test(event->file, G_FILE_TEST_IS_DIR)
  && (g_strcmp0(event->file, watcher->path) != 0))
    {
      watcher_add_monitor_for_recursive_path(watcher, event->file, depth);
    }

  watcher_event_fired(watcher, event);

  g_free(event->event);
  g_free(event->file);
  g_free(event->rfile);
  g_free(event);
}