Пример #1
0
static int
nemo_icon_view_container_compare_icons_by_name (NemoIconContainer *container,
						    NemoIconData      *icon_a,
						    NemoIconData      *icon_b)
{
	return nemo_file_compare_for_sort
		(NEMO_FILE (icon_a),
		 NEMO_FILE (icon_b),
		 NEMO_FILE_SORT_BY_DISPLAY_NAME,
		 FALSE, FALSE);
}
Пример #2
0
GList *
nemo_directory_match_pattern (NemoDirectory *directory, const char *pattern)
{
	GList *files, *l, *ret;
	GPatternSpec *spec;


	ret = NULL;
	spec = g_pattern_spec_new (pattern);
	
	files = nemo_directory_get_file_list (directory);
	for (l = files; l; l = l->next) {
		NemoFile *file;
		char *name;
	       
	        file = NEMO_FILE (l->data);
		name = nemo_file_get_display_name (file);

		if (g_pattern_match_string (spec, name)) {
			ret = g_list_prepend(ret, nemo_file_ref (file));	
		}

		g_free (name);
	}

	g_pattern_spec_free (spec);
	nemo_file_list_free (files);

	return ret;
}
Пример #3
0
void
nemo_directory_moved (const char *old_uri,
			  const char *new_uri)
{
	GList *list, *node;
	GHashTable *hash;
	NemoFile *file;
	GFile *old_location;
	GFile *new_location;

	hash = g_hash_table_new (NULL, NULL);

	old_location = g_file_new_for_uri (old_uri);
	new_location = g_file_new_for_uri (new_uri);
	
	list = nemo_directory_moved_internal (old_location, new_location);
	for (node = list; node != NULL; node = node->next) {
		file = NEMO_FILE (node->data);
		hash_table_list_prepend (hash,
					 file->details->directory,
					 nemo_file_ref (file));
	}
	nemo_file_list_free (list);
	
	g_object_unref (old_location);
	g_object_unref (new_location);

	g_hash_table_foreach (hash, call_files_changed_unref_free_list, NULL);
	g_hash_table_destroy (hash);
}
Пример #4
0
NemoFile *
nemo_file_queue_head (NemoFileQueue *queue)
{
	if (queue->head == NULL) {
		return NULL;
	}

	return NEMO_FILE (queue->head->data);
}
Пример #5
0
static gchar *
get_insertion_string (TokenType token_type, GList *selection, NemoFile *parent)
{
    GList *l;

    GString *str = g_string_new("");
    gboolean first = TRUE;

    switch (token_type) {
        case TOKEN_PATH_LIST:
            for (l = selection; l != NULL; l = l->next) {
                if (!first)
                    str = g_string_append (str, " ");
                gchar *path = nemo_file_get_path (NEMO_FILE (l->data));
                str = g_string_append (str, path);
                g_free (path);
                first = FALSE;
            }
            break;
        case TOKEN_URI_LIST:
            for (l = selection; l != NULL; l = l->next) {
                if (!first)
                    str = g_string_append (str, " ");
                gchar *uri = nemo_file_get_uri (NEMO_FILE (l->data));
                str = g_string_append (str, uri);
                g_free (uri);
                first = FALSE;
            }
            break;
        case TOKEN_PARENT:
            ;
            gchar *path = nemo_file_get_path (parent);
            str = g_string_append (str, path);
            g_free (path);
            break;
    }

    gchar *ret = str->str;

    g_string_free (str, FALSE);

    return ret;
}
Пример #6
0
NemoFile *
nemo_directory_find_file_by_name (NemoDirectory *directory,
				      const char *name)
{
	GList *node;

	g_return_val_if_fail (NEMO_IS_DIRECTORY (directory), NULL);
	g_return_val_if_fail (name != NULL, NULL);

	node = g_hash_table_lookup (directory->details->file_hash,
				    name);
	return node == NULL ? NULL : NEMO_FILE (node->data);
}
static void
nemo_mime_application_chooser_apply_labels (NemoMimeApplicationChooser *chooser)
{
    gchar *label, *extension = NULL, *description = NULL;

    if (chooser->details->files != NULL) {
        /* here we assume all files are of the same content type */
        if (g_content_type_is_unknown (chooser->details->content_type)) {
            extension = get_extension_from_file (NEMO_FILE (chooser->details->files->data));

            /* the %s here is a file extension */
            description = g_strdup_printf (_("%s document"), extension);
        } else {
            description = g_content_type_get_description (chooser->details->content_type);
        }

        label = g_strdup_printf (_("Open all files of type \"%s\" with"),
                                 description);
    } else {
        GFile *file;
        gchar *basename, *emname;

        file = g_file_new_for_uri (chooser->details->uri);
        basename = g_file_get_basename (file);

        if (g_content_type_is_unknown (chooser->details->content_type)) {
            extension = get_extension (basename);

            /* the %s here is a file extension */
            description = g_strdup_printf (_("%s document"), extension);
        } else {
            description = g_content_type_get_description (chooser->details->content_type);
        }

        /* first %s is filename, second %s is mime-type description */
        emname = g_strdup_printf ("<i>%s</i>", basename);
        label = g_strdup_printf (_("Select an application in the list to open %s and other files of type \"%s\""),
                                 emname, description);

        g_free (emname);
        g_free (basename);
        g_object_unref (file);
    }

    gtk_label_set_markup (GTK_LABEL (chooser->details->label), label);

    g_free (label);
    g_free (extension);
    g_free (description);
}
Пример #8
0
static void
files_changed_callback (NemoDirectory *directory,
			GList *changed_files,
			gpointer callback_data)
{
	FMTreeModelRoot *root;
	GList *node;

	root = (FMTreeModelRoot *) (callback_data);

	for (node = changed_files; node != NULL; node = node->next) {
		process_file_change (root, NEMO_FILE (node->data));
	}
}
Пример #9
0
static gboolean
is_tentative (gpointer data, gpointer callback_data)
{
	NemoFile *file;

	g_assert (callback_data == NULL);

	file = NEMO_FILE (data);
	/* Avoid returning files with !is_added, because these
	 * will later be sent with the files_added signal, and a
	 * user doing get_file_list + files_added monitoring will
	 * then see the file twice */
	return !file->details->got_file_info || !file->details->is_added;
}
Пример #10
0
static char *
nemo_icon_view_container_get_icon_description (NemoIconContainer *container,
						   NemoIconData      *data)
{
	NemoFile *file;
	char *mime_type;
	const char *description;

	file = NEMO_FILE (data);
	g_assert (NEMO_IS_FILE (file));

	if (NEMO_IS_DESKTOP_ICON_FILE (file)) {
		return NULL;
	}

	mime_type = nemo_file_get_mime_type (file);
	description = g_content_type_get_description (mime_type);
	g_free (mime_type);
	return g_strdup (description);
}
Пример #11
0
static void
real_directory_notify_files_removed (NemoDirectory *real_directory)
{
	GList *files, *l;

	files = nemo_directory_get_file_list (real_directory);

	for (l = files; l; l = l->next) {
		NemoFile *file;
		char *uri;

		file = NEMO_FILE (l->data);
		uri = nemo_file_get_uri (file);
		nemo_file_unref (file);

		l->data = uri;
	}

	if (files) {
		nemo_directory_notify_files_removed_by_uri (files);
	}

	g_list_free_full (files, g_free);
}
Пример #12
0
/* This callback returns the text, both the editable part, and the
 * part below that is not editable.
 */
static void
nemo_icon_view_container_get_icon_text (NemoIconContainer *container,
					    NemoIconData      *data,
					    char                 **editable_text,
					    char                 **additional_text,
					    gboolean               include_invisible)
{
	GQuark *attributes;
	char *text_array[4];
	int i, j, num_attributes;
	NemoIconView *icon_view;
	NemoFile *file;
	gboolean use_additional;

	file = NEMO_FILE (data);

	g_assert (NEMO_IS_FILE (file));
	g_assert (editable_text != NULL);
	icon_view = get_icon_view (container);
	g_return_if_fail (icon_view != NULL);

	use_additional = (additional_text != NULL);

	/* In the smallest zoom mode, no text is drawn. */
	if (nemo_icon_container_get_zoom_level (container) == NEMO_ZOOM_LEVEL_SMALLEST &&
            !include_invisible) {
		*editable_text = NULL;
	} else {
		/* Strip the suffix for nemo object xml files. */
		*editable_text = nemo_file_get_display_name (file);
	}

	if (!use_additional) {
		return;
	}

	if (nemo_icon_view_is_compact (icon_view)) {
		*additional_text = NULL;
		return;
	}

	if (NEMO_IS_DESKTOP_ICON_FILE (file) ||
	    nemo_file_is_nemo_link (file)) {
		/* Don't show the normal extra information for desktop icons,
		 * or desktop files, it doesn't make sense. */
 		*additional_text = NULL;
		return;
	}

	/* Find out what attributes go below each icon. */
	attributes = nemo_icon_view_container_get_icon_text_attribute_names (container,
									   &num_attributes);

	/* Get the attributes. */
	j = 0;
	for (i = 0; i < num_attributes; ++i) {
		if (attributes[i] == attribute_none_q) {
			continue;
		}

		text_array[j++] =
			nemo_file_get_string_attribute_with_default_q (file, attributes[i]);
	}
	text_array[j] = NULL;

	/* Return them. */
	if (j == 0) {
		*additional_text = NULL;
	} else if (j == 1) {
		/* Only one item, avoid the strdup + free */
		*additional_text = text_array[0];
	} else {
		*additional_text = g_strjoinv ("\n", text_array);
		
		for (i = 0; i < j; i++) {
			g_free (text_array[i]);
		}
	}
}
Пример #13
0
static void
handle_local_move (NemoIconContainer *container,
		   double world_x, double world_y)
{
	GList *moved_icons, *p;
	NemoDragSelectionItem *item;
	NemoIcon *icon;
	NemoFile *file = NULL;
	char screen_string[32];
	GdkScreen *screen;
    gint monitor;
	time_t now;

	if (container->details->auto_layout) {
		return;
	}

	time (&now);

	/* Move and select the icons. */
	moved_icons = NULL;
	for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next) {
		item = p->data;
		
		icon = nemo_icon_container_get_icon_by_uri
			(container, item->uri);

		if (icon == NULL) {
			/* probably dragged from another screen.  Add it to
			 * this screen
			 */

			file = nemo_file_get_by_uri (item->uri);

			screen = gtk_widget_get_screen (GTK_WIDGET (container));
			g_snprintf (screen_string, sizeof (screen_string), "%d",
				    gdk_screen_get_number (screen));
			nemo_file_set_metadata (file,
					NEMO_METADATA_KEY_SCREEN,
					NULL, screen_string);
			nemo_file_set_time_metadata (file,
							 NEMO_METADATA_KEY_ICON_POSITION_TIMESTAMP, now);

			nemo_icon_container_add (container, NEMO_ICON_CONTAINER_ICON_DATA (file));
			
			icon = nemo_icon_container_get_icon_by_uri
				(container, item->uri);
		}

        if (file == NULL)
            file = NEMO_FILE (icon->data);

        nemo_file_set_is_desktop_orphan (file, FALSE);

        monitor = nemo_desktop_utils_get_monitor_for_widget (GTK_WIDGET (container));
        nemo_file_set_integer_metadata (file, NEMO_METADATA_KEY_MONITOR, 0, monitor);

		if (item->got_icon_position) {
			nemo_icon_container_move_icon
				(container, icon,
				 world_x + item->icon_x, world_y + item->icon_y,
				 icon->scale,
				 TRUE, TRUE, TRUE);
		}
		moved_icons = g_list_prepend (moved_icons, icon);
	}		
	nemo_icon_container_select_list_unselect_others
		(container, moved_icons);
	/* Might have been moved in a way that requires adjusting scroll region. */
	nemo_icon_container_update_scroll_region (container);
	g_list_free (moved_icons);
}
Пример #14
0
static gchar *
get_insertion_string (NemoAction *action, TokenType token_type, GList *selection, NemoFile *parent)
{
    GList *l;

    GString *str = g_string_new("");
    gboolean first = TRUE;

    switch (token_type) {
        case TOKEN_PATH_LIST:
            if (g_list_length (selection) > 0) {
                for (l = selection; l != NULL; l = l->next) {
                    if (!first)
                        str = insert_separator (action, str);
                    str = insert_quote (action, str);
                    gchar *path = get_path (action, NEMO_FILE (l->data));
                    if (path)
                        str = score_append (action, str, path);
                    g_free (path);
                    str = insert_quote (action, str);
                    first = FALSE;
                }
            } else {
                goto default_parent_path;
            }
            break;
        case TOKEN_URI_LIST:
            if (g_list_length (selection) > 0) {
                for (l = selection; l != NULL; l = l->next) {
                    if (!first)
                        str = insert_separator (action, str);
                    str = insert_quote (action, str);
                    gchar *uri = nemo_file_get_uri (NEMO_FILE (l->data));
                    str = score_append (action, str, uri);
                    g_free (uri);
                    str = insert_quote (action, str);
                    first = FALSE;
                }
            } else {
                goto default_parent_path;
            }
            break;
        case TOKEN_PARENT_PATH:
            ;
default_parent_path:
            ;
            gchar *path = get_path (action, parent);
            if (path == NULL) {
                gchar *name = nemo_file_get_display_name (parent);
                if (g_strcmp0 (name, "x-nemo-desktop") == 0)
                    path = nemo_get_desktop_directory ();
                else
                    path = g_strdup ("");
                g_free (name);
            }
            str = insert_quote (action, str);
            str = score_append (action, str, path);
            str = insert_quote (action, str);
            g_free (path);
            break;
        case TOKEN_FILE_DISPLAY_NAME:
            if (g_list_length (selection) > 0) {
                gchar *file_display_name = nemo_file_get_display_name (NEMO_FILE (selection->data));
                str = score_append (action, str, file_display_name);
                g_free (file_display_name);
            } else {
                goto default_parent_display_name;
            }
            break;
        case TOKEN_PARENT_DISPLAY_NAME:
            ;
default_parent_display_name:
            ;
            gchar *parent_display_name;
            gchar *real_display_name = nemo_file_get_display_name (parent);
            if (g_strcmp0 (real_display_name, "x-nemo-desktop") == 0)
                parent_display_name = g_strdup_printf (_("Desktop"));
            else
                parent_display_name = nemo_file_get_display_name (parent);
            g_free (real_display_name);
            str = insert_quote (action, str);
            str = score_append (action, str, parent_display_name);
            str = insert_quote (action, str);
            g_free (parent_display_name);
            break;
        case TOKEN_DEVICE:
            if (g_list_length (selection) > 0) {
                for (l = selection; l != NULL; l = l->next) {
                    if (!first)
                        str = insert_separator (action, str);
                    str = insert_quote (action, str);
                    gchar *dev = get_device_path (action, NEMO_FILE (l->data));
                    if (dev)
                        str = score_append (action, str, dev);
                    g_free (dev);
                    str = insert_quote (action, str);
                    first = FALSE;
                }
            } else {
                goto default_parent_path;
            }
            break;
        default:
            break; 
    }

    gchar *ret = str->str;

    g_string_free (str, FALSE);

    return ret;
}
Пример #15
0
gboolean
nemo_action_get_visibility (NemoAction *action, GList *selection, NemoFile *parent)
{

    gboolean selection_type_show = FALSE;
    gboolean extension_type_show = TRUE;
    gboolean condition_type_show = TRUE;

    recalc_dbus_conditions (action);

    if (!nemo_action_get_dbus_satisfied (action))
        goto out;

    gchar **conditions = nemo_action_get_conditions (action);

    guint condition_count = conditions != NULL ? g_strv_length (conditions) : 0;

    if (condition_count > 0) {
        int j;
        gchar *condition;
        for (j = 0; j < condition_count; j++) {
            condition = conditions[j];
            if (g_strcmp0 (condition, "desktop") == 0) {
                gchar *name = nemo_file_get_display_name (parent);
                if (g_strcmp0 (name, "x-nemo-desktop") != 0)
                    condition_type_show = FALSE;
                g_free (name);
            } else if (g_strcmp0 (condition, "removable") == 0) {
                gboolean is_removable = FALSE;
                if (g_list_length (selection) > 0) {
                    GMount *mount = nemo_file_get_mount (selection->data);
                    if (mount) {
                        GDrive *drive = g_mount_get_drive (mount);
                        if (drive) {
                            if (g_drive_is_media_removable (drive))
                                is_removable = TRUE;
                            g_object_unref (drive);
                        }
                    }
                }
                condition_type_show = is_removable;
            } else if (g_str_has_prefix (condition, "gsettings")) {
                condition_type_show = check_gsettings_condition (action, condition);
            }
            if (!condition_type_show)
                break;
        }
    }

    if (!condition_type_show)
        goto out;

    SelectionType selection_type = nemo_action_get_selection_type (action);
    GList *iter;

    guint selected_count = g_list_length (selection);

    switch (selection_type) {
        case SELECTION_SINGLE:
            selection_type_show = selected_count == 1;
            break;
        case SELECTION_MULTIPLE:
            selection_type_show = selected_count > 1;
            break;
        case SELECTION_NOT_NONE:
            selection_type_show = selected_count > 0;
            break;
        case SELECTION_NONE:
            selection_type_show = selected_count == 0;
            break;
        case SELECTION_ANY:
            selection_type_show = TRUE;
            break;
        default:
            selection_type_show = selected_count == selection_type;
            break;
    }

    gchar **extensions = nemo_action_get_extension_list (action);
    gchar **mimetypes = nemo_action_get_mimetypes_list (action);

    guint ext_count = extensions != NULL ? g_strv_length (extensions) : 0;
    guint mime_count = mimetypes != NULL ? g_strv_length (mimetypes) : 0;

    if (ext_count == 1 && g_strcmp0 (extensions[0], "any") == 0)
        goto out;

    gboolean found_match = TRUE;

    for (iter = selection; iter != NULL && found_match; iter = iter->next) {
        found_match = FALSE;
        gchar *raw_fn = nemo_file_get_name (NEMO_FILE (iter->data));
        gchar *filename = g_ascii_strdown (raw_fn, -1);
        g_free (raw_fn);
        int i;
        gboolean is_dir = get_is_dir_hack (iter->data);
        if (ext_count > 0) {
            for (i = 0; i < ext_count; i++) {
                if (g_strcmp0 (extensions[i], "dir") == 0) {
                    if (is_dir) {
                        found_match = TRUE;
                        break;
                    }
                } else if (g_strcmp0 (extensions[i], "none") == 0) {
                    if (g_strrstr (filename, ".") == NULL) {
                        found_match = TRUE;
                        break;
                    }
                } else if (g_strcmp0 (extensions[i], "nodirs") == 0) {
                    if (!is_dir) {
                        found_match = TRUE;
                        break;
                    }
                } else {
                    gchar *str = g_ascii_strdown (extensions[i], -1);
                    if (g_str_has_suffix (filename, str)) {
                        found_match = TRUE;
                    }

                    g_free (str);

                    if (found_match) {
                        break;
                    }
                }
            }
            g_free (filename);
        }

        if (mime_count > 0) {
            for (i = 0; i < mime_count; i++) {
                if (nemo_file_is_mime_type (NEMO_FILE (iter->data), mimetypes[i])) {
                    found_match = TRUE;
                    break;
                }
            }
        }

        if (nemo_file_is_mime_type (NEMO_FILE (iter->data), "application/x-nemo-link")) {
            found_match = FALSE;
        }
    }

    extension_type_show = found_match;

out:

    return selection_type_show && extension_type_show && condition_type_show;
}
Пример #16
0
void
nemo_directory_notify_files_moved (GList *file_pairs)
{
	GList *p, *affected_files, *node;
	GFilePair *pair;
	NemoFile *file;
	NemoDirectory *old_directory, *new_directory;
	GHashTable *parent_directories;
	GList *new_files_list, *unref_list;
	GHashTable *added_lists, *changed_lists;
	char *name;
	NemoFileAttributes cancel_attributes;
	GFile *to_location, *from_location;
	
	/* Make a list of added and changed files in each directory. */
	new_files_list = NULL;
	added_lists = g_hash_table_new (NULL, NULL);
	changed_lists = g_hash_table_new (NULL, NULL);
	unref_list = NULL;

	/* Make a list of parent directories that will need their counts updated. */
	parent_directories = g_hash_table_new (NULL, NULL);

	cancel_attributes = nemo_file_get_all_attributes ();

	for (p = file_pairs; p != NULL; p = p->next) {
		pair = p->data;
		from_location = pair->from;
		to_location = pair->to;

		/* Handle overwriting a file. */
		file = nemo_file_get_existing (to_location);
		if (file != NULL) {
			/* Mark it gone and prepare to send the changed signal. */
			nemo_file_mark_gone (file);
			new_directory = file->details->directory;
			hash_table_list_prepend (changed_lists,
						 new_directory,
						 file);
			collect_parent_directories (parent_directories,
						    new_directory);
		}

		/* Update any directory objects that are affected. */
		affected_files = nemo_directory_moved_internal (from_location,
								    to_location);
		for (node = affected_files; node != NULL; node = node->next) {
			file = NEMO_FILE (node->data);
			hash_table_list_prepend (changed_lists,
						 file->details->directory,
						 file);
		}
		unref_list = g_list_concat (unref_list, affected_files);

		/* Move an existing file. */
		file = nemo_file_get_existing (from_location);
		if (file == NULL) {
			/* Handle this as if it was a new file. */
			new_files_list = g_list_prepend (new_files_list,
							 to_location);
		} else {
			/* Handle notification in the old directory. */
			old_directory = file->details->directory;
			collect_parent_directories (parent_directories, old_directory);

			/* Cancel loading of attributes in the old directory */
			nemo_directory_cancel_loading_file_attributes
				(old_directory, file, cancel_attributes);

			/* Locate the new directory. */
			new_directory = get_parent_directory (to_location);
			collect_parent_directories (parent_directories, new_directory);
			/* We can unref now -- new_directory is in the
			 * parent directories list so it will be
			 * around until the end of this function
			 * anyway.
			 */
			nemo_directory_unref (new_directory);

			/* Update the file's name and directory. */
			name = g_file_get_basename (to_location);
			nemo_file_update_name_and_directory 
				(file, name, new_directory);
			g_free (name);

			/* Update file attributes */
			nemo_file_invalidate_attributes (file, NEMO_FILE_ATTRIBUTE_INFO);

			hash_table_list_prepend (changed_lists,
						 old_directory,
						 file);
			if (old_directory != new_directory) {
				hash_table_list_prepend	(added_lists,
							 new_directory,
							 file);
			}

			/* Unref each file once to balance out nemo_file_get_by_uri. */
			unref_list = g_list_prepend (unref_list, file);
		}
	}

	/* Now send out the changed and added signals for existing file objects. */
	g_hash_table_foreach (changed_lists, call_files_changed_free_list, NULL);
	g_hash_table_destroy (changed_lists);
	g_hash_table_foreach (added_lists, call_files_added_free_list, NULL);
	g_hash_table_destroy (added_lists);

	/* Let the file objects go. */
	nemo_file_list_free (unref_list);

	/* Invalidate count for each parent directory. */
	g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
	g_hash_table_destroy (parent_directories);

	/* Separate handling for brand new file objects. */
	nemo_directory_notify_files_added (new_files_list);
	g_list_free (new_files_list);
}