示例#1
0
gboolean
caja_drag_can_accept_items (CajaFile *drop_target_item,
                            const GList *items)
{
    int max;

    if (drop_target_item == NULL)
        return FALSE;

    g_assert (CAJA_IS_FILE (drop_target_item));

    /* Iterate through selection checking if item will get accepted by the
     * drop target. If more than 100 items selected, return an over-optimisic
     * result
     */
    for (max = 100; items != NULL && max >= 0; items = items->next, max--)
    {
        if (!caja_drag_can_accept_item (drop_target_item,
                                        ((CajaDragSelectionItem *)items->data)->uri))
        {
            return FALSE;
        }
    }

    return TRUE;
}
示例#2
0
void
caja_drag_file_receive_dropped_keyword (CajaFile *file,
                                        const char *keyword)
{
    GList *keywords, *word;

    g_return_if_fail (CAJA_IS_FILE (file));
    g_return_if_fail (keyword != NULL);

    /* special case the erase emblem */
    if (strcmp (keyword, CAJA_FILE_DND_ERASE_KEYWORD) == 0)
    {
        keywords = NULL;
    }
    else
    {
        keywords = caja_file_get_keywords (file);
        word = g_list_find_custom (keywords, keyword, (GCompareFunc) strcmp);
        if (word == NULL)
        {
            keywords = g_list_prepend (keywords, g_strdup (keyword));
        }
        else
        {
            keywords = g_list_remove_link (keywords, word);
            g_free (word->data);
            g_list_free_1 (word);
        }
    }

    caja_file_set_keywords (file, keywords);
    g_list_free_full (keywords, g_free);
}
示例#3
0
static void
fm_icon_container_stop_monitor_top_left (CajaIconContainer *container,
        CajaIconData      *data,
        gconstpointer          client)
{
    CajaFile *file;

    file = (CajaFile *) data;

    g_assert (CAJA_IS_FILE (file));

    caja_file_monitor_remove (file, client);
}
示例#4
0
void
fm_rename_file (CajaFile *file,
                const char *new_name,
                CajaFileOperationCallback callback,
                gpointer callback_data)
{
    char *old_name, *wait_message;
    FMRenameData *data;
    char *uri;
    GError *error;

    g_return_if_fail (CAJA_IS_FILE (file));
    g_return_if_fail (new_name != NULL);

    /* Stop any earlier rename that's already in progress. */
    error = g_error_new (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled");
    finish_rename (file, TRUE, error);
    g_error_free (error);

    data = g_new0 (FMRenameData, 1);
    data->name = g_strdup (new_name);
    data->callback = callback;
    data->callback_data = callback_data;

    /* Attach the new name to the file. */
    g_object_set_data_full (G_OBJECT (file),
                            NEW_NAME_TAG,
                            data, (GDestroyNotify)fm_rename_data_free);

    /* Start the timed wait to cancel the rename. */
    old_name = caja_file_get_display_name (file);
    wait_message = g_strdup_printf (_("Renaming \"%s\" to \"%s\"."),
                                    old_name,
                                    new_name);
    g_free (old_name);
    eel_timed_wait_start (cancel_rename_callback, file, wait_message,
                          NULL); /* FIXME bugzilla.gnome.org 42395: Parent this? */
    g_free (wait_message);

    uri = caja_file_get_uri (file);
    caja_debug_log (FALSE, CAJA_DEBUG_LOG_DOMAIN_USER,
                    "rename file old=\"%s\", new=\"%s\"",
                    uri, new_name);
    g_free (uri);

    /* Start the rename. */
    caja_file_rename (file, new_name,
                      rename_callback, NULL);
}
示例#5
0
static void
fm_icon_container_prioritize_thumbnailing (CajaIconContainer *container,
        CajaIconData      *data)
{
    CajaFile *file;
    char *uri;

    file = (CajaFile *) data;

    g_assert (CAJA_IS_FILE (file));

    if (caja_file_is_thumbnailing (file))
    {
        uri = caja_file_get_uri (file);
        caja_thumbnail_prioritize (uri);
        g_free (uri);
    }
}
示例#6
0
static void
fm_icon_container_start_monitor_top_left (CajaIconContainer *container,
        CajaIconData      *data,
        gconstpointer          client,
        gboolean               large_text)
{
    CajaFile *file;
    CajaFileAttributes attributes;

    file = (CajaFile *) data;

    g_assert (CAJA_IS_FILE (file));

    attributes = CAJA_FILE_ATTRIBUTE_TOP_LEFT_TEXT;
    if (large_text)
    {
        attributes |= CAJA_FILE_ATTRIBUTE_LARGE_TOP_LEFT_TEXT;
    }
    caja_file_monitor_add (file, client, attributes);
}
示例#7
0
static char *
fm_icon_container_get_icon_description (CajaIconContainer *container,
                                        CajaIconData      *data)
{
    CajaFile *file;
    char *mime_type;
    const char *description;

    file = CAJA_FILE (data);
    g_assert (CAJA_IS_FILE (file));

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

    mime_type = caja_file_get_mime_type (file);
    description = g_content_type_get_description (mime_type);
    g_free (mime_type);
    return g_strdup (description);
}
示例#8
0
static void
rename_callback (CajaFile *file, GFile *result_location,
                 GError *error, gpointer callback_data)
{
    FMRenameData *data;

    g_assert (CAJA_IS_FILE (file));
    g_assert (callback_data == NULL);

    data = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
    g_assert (data != NULL);

    if (error &&
            !(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED))
    {
        /* If rename failed, notify the user. */
        fm_report_error_renaming_file (file, data->name, error, NULL);
    }

    finish_rename (file, TRUE, error);
}
示例#9
0
static void
load_note_text_from_metadata (CajaFile *file,
                              CajaNotesViewer *notes)
{
    char *saved_text;

    g_assert (CAJA_IS_FILE (file));
    g_assert (notes->details->file == file);

    saved_text = caja_file_get_metadata (file, CAJA_METADATA_KEY_ANNOTATION, "");

    /* This fn is called for any change signal on the file, so make sure that the
     * metadata has actually changed.
     */
    if (g_strcmp0 (saved_text, notes->details->previous_saved_text) != 0)
    {
        set_saved_text (notes, saved_text);
        cancel_pending_save (notes);

        /* Block the handler, so we don't respond to our own change.
         */
        g_signal_handlers_block_matched (notes->details->text_buffer,
                                         G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
                                         0, 0, NULL,
                                         G_CALLBACK (on_changed),
                                         notes);
        gtk_text_buffer_set_text (notes->details->text_buffer, saved_text, -1);
        g_signal_handlers_unblock_matched (notes->details->text_buffer,
                                           G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
                                           0, 0, NULL,
                                           G_CALLBACK (on_changed),
                                           notes);
    }
    else
    {
        g_free (saved_text);
    }
}
示例#10
0
static CajaIconInfo *
fm_icon_container_get_icon_images (CajaIconContainer *container,
                                   CajaIconData      *data,
                                   int                    size,
                                   GList                **emblem_pixbufs,
                                   char                 **embedded_text,
                                   gboolean               for_drag_accept,
                                   gboolean               need_large_embeddded_text,
                                   gboolean              *embedded_text_needs_loading,
                                   gboolean              *has_window_open)
{
    FMIconView *icon_view;
    char **emblems_to_ignore;
    CajaFile *file;
    gboolean use_embedding;
    CajaFileIconFlags flags;
    guint emblem_size;

    file = (CajaFile *) data;

    g_assert (CAJA_IS_FILE (file));
    icon_view = get_icon_view (container);
    g_return_val_if_fail (icon_view != NULL, NULL);

    use_embedding = FALSE;
    if (embedded_text)
    {
        *embedded_text = caja_file_peek_top_left_text (file, need_large_embeddded_text, embedded_text_needs_loading);
        use_embedding = *embedded_text != NULL;
    }

    if (emblem_pixbufs != NULL)
    {
        emblem_size = caja_icon_get_emblem_size_for_icon_size (size);
        /* don't return images larger than the actual icon size */
        emblem_size = MIN (emblem_size, size);

        if (emblem_size > 0)
        {
            emblems_to_ignore = fm_directory_view_get_emblem_names_to_exclude
                                (FM_DIRECTORY_VIEW (icon_view));
            *emblem_pixbufs = caja_file_get_emblem_pixbufs (file,
                              emblem_size,
                              FALSE,
                              emblems_to_ignore);
            g_strfreev (emblems_to_ignore);
        }
    }

    *has_window_open = caja_file_has_open_window (file);

    flags = CAJA_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
    if (!fm_icon_view_is_compact (icon_view) ||
            caja_icon_container_get_zoom_level (container) > CAJA_ZOOM_LEVEL_STANDARD)
    {
        flags |= CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS;
        if (fm_icon_view_is_compact (icon_view))
        {
            flags |= CAJA_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE;
        }
    }

    if (use_embedding)
    {
        flags |= CAJA_FILE_ICON_FLAGS_EMBEDDING_TEXT;
    }
    if (for_drag_accept)
    {
        flags |= CAJA_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
    }

    return caja_file_get_icon (file, size, flags);
}
示例#11
0
/* This callback returns the text, both the editable part, and the
 * part below that is not editable.
 */
static void
fm_icon_container_get_icon_text (CajaIconContainer *container,
                                 CajaIconData      *data,
                                 char                 **editable_text,
                                 char                 **additional_text,
                                 gboolean               include_invisible)
{
    char *actual_uri;
    gchar *description;
    GQuark *attributes;
    char *text_array[4];
    int i, j, num_attributes;
    FMIconView *icon_view;
    CajaFile *file;
    gboolean use_additional;

    file = CAJA_FILE (data);

    g_assert (CAJA_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 (caja_icon_container_get_zoom_level (container) == CAJA_ZOOM_LEVEL_SMALLEST &&
            !include_invisible)
    {
        *editable_text = NULL;
    }
    else
    {
        /* Strip the suffix for caja object xml files. */
        *editable_text = caja_file_get_display_name (file);
    }

    if (!use_additional)
    {
        return;
    }

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

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

    /* Handle link files specially. */
    if (caja_file_is_caja_link (file))
    {
        /* FIXME bugzilla.gnome.org 42531: Does sync. I/O and works only locally. */
        *additional_text = NULL;
        if (caja_file_is_local (file))
        {
            actual_uri = caja_file_get_uri (file);
            description = caja_link_local_get_additional_text (actual_uri);
            if (description)
                *additional_text = g_strdup_printf (" \n%s\n ", description);
            g_free (description);
            g_free (actual_uri);
        }
        /* Don't show the normal extra information for desktop files, it doesn't
         * make sense. */
        return;
    }

    /* Find out what attributes go below each icon. */
    attributes = fm_icon_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++] =
            caja_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]);
        }
    }
}