Пример #1
0
static char *
convert_file_list_to_string (CajaClipboardInfo *info,
                             gboolean format_for_text,
                             gsize *len)
{
    GString *uris;
    char *uri, *tmp;
    GFile *f;
    guint i;
    GList *l;

    if (format_for_text)
    {
        uris = g_string_new (NULL);
    }
    else
    {
        uris = g_string_new (info->cut ? "cut" : "copy");
    }

    for (i = 0, l = info->files; l != NULL; l = l->next, i++)
    {
        uri = caja_file_get_uri (l->data);

        if (format_for_text)
        {
            f = g_file_new_for_uri (uri);
            tmp = g_file_get_parse_name (f);
            g_object_unref (f);

            if (tmp != NULL)
            {
                g_string_append (uris, tmp);
                g_free (tmp);
            }
            else
            {
                g_string_append (uris, uri);
            }

            /* skip newline for last element */
            if (i + 1 < g_list_length (info->files))
            {
                g_string_append_c (uris, '\n');
            }
        }
        else
        {
            g_string_append_c (uris, '\n');
            g_string_append (uris, uri);
        }

        g_free (uri);
    }

    *len = uris->len;
    return g_string_free (uris, FALSE);
}
Пример #2
0
static void
fm_ditem_page_exec_drag_data_received (GtkWidget *widget, GdkDragContext *context,
                                       int x, int y,
                                       GtkSelectionData *selection_data,
                                       guint info, guint time,
                                       GtkEntry *entry)
{
    char **uris;
    gboolean exactly_one;
    CajaFile *file;
    GKeyFile *key_file;
    char *uri, *type, *exec;

    uris = g_strsplit (gtk_selection_data_get_data (selection_data), "\r\n", 0);
    exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');

    if (!exactly_one)
    {
        g_strfreev (uris);
        return;
    }

    file = caja_file_get_by_uri (uris[0]);
    g_strfreev (uris);

    g_return_if_fail (file != NULL);

    uri = caja_file_get_uri (file);
    if (caja_file_is_mime_type (file, "application/x-desktop"))
    {
        key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
        if (key_file != NULL)
        {
            type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
            if (type != NULL && strcmp (type, "Application") == 0)
            {
                exec = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL);
                if (exec != NULL)
                {
                    g_free (uri);
                    uri = exec;
                }
            }
            g_free (type);
            g_key_file_free (key_file);
        }
    }
    gtk_entry_set_text (entry,
                        uri?uri:"");
    gtk_widget_grab_focus (GTK_WIDGET (entry));

    g_free (uri);

    caja_file_unref (file);
}
Пример #3
0
void
caja_get_clipboard_callback (GtkClipboard     *clipboard,
                             GtkSelectionData *selection_data,
                             guint             info,
                             gpointer          user_data)
{
    char **uris;
    GList *l;
    int i;
    CajaClipboardInfo *clipboard_info;
    GdkAtom target;

    clipboard_info =
        caja_clipboard_monitor_get_clipboard_info (caja_clipboard_monitor_get ());

    target = gtk_selection_data_get_target (selection_data);

    if (gtk_targets_include_uri (&target, 1))
    {
        uris = g_malloc ((g_list_length (clipboard_info->files) + 1) * sizeof (char *));
        i = 0;

        for (l = clipboard_info->files; l != NULL; l = l->next)
        {
            uris[i] = caja_file_get_uri (l->data);
            i++;
        }

        uris[i] = NULL;

        gtk_selection_data_set_uris (selection_data, uris);

        g_strfreev (uris);
    }
    else if (gtk_targets_include_text (&target, 1))
    {
        char *str;
        gsize len;

        str = convert_file_list_to_string (clipboard_info, TRUE, &len);
        gtk_selection_data_set_text (selection_data, str, len);
        g_free (str);
    }
    else if (target == copied_files_atom)
    {
        char *str;
        gsize len;

        str = convert_file_list_to_string (clipboard_info, FALSE, &len);
        gtk_selection_data_set (selection_data, copied_files_atom, 8, str, len);
        g_free (str);
    }
}
Пример #4
0
static void
each_path_get_data_binder (CajaDragEachSelectedItemDataGet data_get,
                           gpointer context,
                           gpointer data)
{
    DragDataGetInfo *info;
    GList *l;
    CajaFile *file;
    GtkTreeRowReference *row;
    GtkTreePath *path;
    char *uri;
    GdkRectangle cell_area;
    GtkTreeViewColumn *column;

    info = context;

    g_return_if_fail (info->model->details->drag_view);

    column = gtk_tree_view_get_column (info->model->details->drag_view, 0);

    for (l = info->path_list; l != NULL; l = l->next)
    {
        row = l->data;

        path = gtk_tree_row_reference_get_path (row);
        file = fm_list_model_file_for_path (info->model, path);
        if (file)
        {
            gtk_tree_view_get_cell_area
            (info->model->details->drag_view,
             path,
             column,
             &cell_area);

            uri = caja_file_get_uri (file);

            (*data_get) (uri,
                         0,
                         cell_area.y - info->model->details->drag_begin_y,
                         cell_area.width, cell_area.height,
                         data);

            g_free (uri);

            caja_file_unref (file);
        }

        gtk_tree_path_free (path);
    }
}
Пример #5
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);
}
Пример #6
0
static void
files_changed (CajaDirectory *directory,
	       GList *changed_files)
{
#if 0
	GList *list;

	for (list = changed_files; list != NULL; list = list->next) {
		CajaFile *file = list->data;

		g_print (" - %s\n", caja_file_get_uri (file));
	}
#endif
	g_print ("files changed: %d\n",
		 g_list_length (changed_files));
}
Пример #7
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);
    }
}
Пример #8
0
gboolean
caja_can_thumbnail (CajaFile *file)
{
    MateDesktopThumbnailFactory *factory;
    gboolean res;
    char *uri;
    time_t mtime;
    char *mime_type;

    uri = caja_file_get_uri (file);
    mime_type = caja_file_get_mime_type (file);
    mtime = caja_file_get_mtime (file);

    factory = get_thumbnail_factory ();
    res = mate_desktop_thumbnail_factory_can_thumbnail (factory,
            uri,
            mime_type,
            mtime);
    g_free (mime_type);
    g_free (uri);

    return res;
}
Пример #9
0
void
caja_create_thumbnail (CajaFile *file)
{
    time_t file_mtime = 0;
    CajaThumbnailInfo *info;
    CajaThumbnailInfo *existing_info;
    GList *existing, *node;

    caja_file_set_is_thumbnailing (file, TRUE);

    info = g_new0 (CajaThumbnailInfo, 1);
    info->image_uri = caja_file_get_uri (file);
    info->mime_type = caja_file_get_mime_type (file);

    /* Hopefully the CajaFile will already have the image file mtime,
       so we can just use that. Otherwise we have to get it ourselves. */
    if (file->details->got_file_info &&
            file->details->file_info_is_up_to_date &&
            file->details->mtime != 0)
    {
        file_mtime = file->details->mtime;
    }
    else
    {
        get_file_mtime (info->image_uri, &file_mtime);
    }

    info->original_file_mtime = file_mtime;


#ifdef DEBUG_THUMBNAILS
    g_message ("(Main Thread) Locking mutex\n");
#endif
    g_mutex_lock (&thumbnails_mutex);

    /*********************************
     * MUTEX LOCKED
     *********************************/

    if (thumbnails_to_make_hash == NULL)
    {
        thumbnails_to_make_hash = g_hash_table_new (g_str_hash,
                                  g_str_equal);
    }

    /* Check if it is already in the list of thumbnails to make. */
    existing = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
    if (existing == NULL)
    {
        /* Add the thumbnail to the list. */
#ifdef DEBUG_THUMBNAILS
        g_message ("(Main Thread) Adding thumbnail: %s\n",
                   info->image_uri);
#endif
        g_queue_push_tail ((GQueue *)&thumbnails_to_make, info);
        node = g_queue_peek_tail_link ((GQueue *)&thumbnails_to_make);
        g_hash_table_insert (thumbnails_to_make_hash,
                             info->image_uri,
                             node);
        /* If the thumbnail thread isn't running, and we haven't
           scheduled an idle function to start it up, do that now.
           We don't want to start it until all the other work is done,
           so the GUI will be updated as quickly as possible.*/
        if (thumbnail_thread_is_running == FALSE &&
                thumbnail_thread_starter_id == 0)
        {
            thumbnail_thread_starter_id = g_idle_add_full (G_PRIORITY_LOW, thumbnail_thread_starter_cb, NULL, NULL);
        }
    }
    else
    {
#ifdef DEBUG_THUMBNAILS
        g_message ("(Main Thread) Updating non-current mtime: %s\n",
                   info->image_uri);
#endif
        /* The file in the queue might need a new original mtime */
        existing_info = existing->data;
        existing_info->original_file_mtime = info->original_file_mtime;
        free_thumbnail_info (info);
    }

    /*********************************
     * MUTEX UNLOCKED
     *********************************/

#ifdef DEBUG_THUMBNAILS
    g_message ("(Main Thread) Unlocking mutex\n");
#endif
    g_mutex_unlock (&thumbnails_mutex);
}
Пример #10
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]);
        }
    }
}