Esempio n. 1
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);
}
Esempio n. 2
0
static void
update_xdg_dir_cache (void)
{
    GFile *file;
    char *config_file, *uri;
    int i;

    free_xdg_dir_cache ();
    g_reload_user_special_dirs_cache ();
    schedule_user_dirs_changed ();
    desktop_dir_changed ();

    cached_xdg_dirs = parse_xdg_dirs (NULL);

    for (i = 0 ; cached_xdg_dirs[i].type != NULL; i++)
    {
        cached_xdg_dirs[i].file = NULL;
        if (strcmp (cached_xdg_dirs[i].path, g_get_home_dir ()) != 0)
        {
            uri = g_filename_to_uri (cached_xdg_dirs[i].path, NULL, NULL);
            cached_xdg_dirs[i].file = caja_file_get_by_uri (uri);
            caja_file_monitor_add (cached_xdg_dirs[i].file,
                                   &cached_xdg_dirs[i],
                                   CAJA_FILE_ATTRIBUTE_INFO);
            g_signal_connect (cached_xdg_dirs[i].file,
                              "changed", G_CALLBACK (xdg_dir_changed), &cached_xdg_dirs[i]);
            g_free (uri);
        }
    }

    if (cached_xdg_dirs_monitor == NULL)
    {
        config_file = g_build_filename (g_get_user_config_dir (),
                                        "user-dirs.dirs", NULL);
        file = g_file_new_for_path (config_file);
        cached_xdg_dirs_monitor = g_file_monitor_file (file, 0, NULL, NULL);
        g_signal_connect (cached_xdg_dirs_monitor, "changed",
                          G_CALLBACK (xdg_dir_cache_changed_cb), NULL);
        g_object_unref (file);
        g_free (config_file);

        eel_debug_call_at_shutdown (destroy_xdg_dir_cache);
    }
}
Esempio n. 3
0
/* This is a one-shot idle callback called from the main loop to call
   notify_file_changed() for a thumbnail. It frees the uri afterwards.
   We do this in an idle callback as I don't think caja_file_changed() is
   thread-safe. */
static gboolean
thumbnail_thread_notify_file_changed (gpointer image_uri)
{
    CajaFile *file;

    file = caja_file_get_by_uri ((char *) image_uri);
#ifdef DEBUG_THUMBNAILS
    g_message ("(Thumbnail Thread) Notifying file changed file:%p uri: %s\n", file, (char*) image_uri);
#endif

    if (file != NULL)
    {
        caja_file_set_is_thumbnailing (file, FALSE);
        caja_file_invalidate_attributes (file,
                                         CAJA_FILE_ATTRIBUTE_THUMBNAIL |
                                         CAJA_FILE_ATTRIBUTE_INFO);
        caja_file_unref (file);
    }
    g_free (image_uri);

    return FALSE;
}
Esempio n. 4
0
static void
notes_load_metainfo (CajaNotesViewer *notes)
{
    CajaFileAttributes attributes;

    done_with_file (notes);
    notes->details->file = caja_file_get_by_uri (notes->details->uri);

    /* 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, "", -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);

    if (notes->details->file == NULL)
    {
        return;
    }

    attributes = CAJA_FILE_ATTRIBUTE_INFO;
    caja_file_monitor_add (notes->details->file, notes, attributes);

    if (caja_file_check_if_ready (notes->details->file, attributes))
    {
        load_note_text_from_metadata (notes->details->file, notes);
    }

    g_signal_connect (notes->details->file, "changed",
                      G_CALLBACK (load_note_text_from_metadata), notes);
}
void
caja_launch_application_by_uri (GAppInfo *application,
                                GList *uris,
                                GtkWindow *parent_window)
{
    char            *uri, *uri_scheme;
    GList           *locations, *l;
    GFile *location;
    CajaFile    *file;
    gboolean        result;
    GError *error;
    GdkAppLaunchContext *launch_context;
    CajaIconInfo *icon;
    int count, total;

    g_assert (uris != NULL);

    /* count the number of uris with local paths */
    count = 0;
    total = g_list_length (uris);
    locations = NULL;
    for (l = uris; l != NULL; l = l->next)
    {
        uri = l->data;

        location = g_file_new_for_uri (uri);
        if (g_file_is_native (location))
        {
            count++;
        }
        locations = g_list_prepend (locations, location);
    }
    locations = g_list_reverse (locations);

    launch_context = gdk_app_launch_context_new ();
    if (parent_window)
        gdk_app_launch_context_set_screen (launch_context,
                                           gtk_window_get_screen (parent_window));

    file = caja_file_get_by_uri (uris->data);
    icon = caja_file_get_icon (file, 48, 0);
    caja_file_unref (file);
    if (icon)
    {
        gdk_app_launch_context_set_icon_name (launch_context,
                                              caja_icon_info_get_used_name (icon));
        g_object_unref (icon);
    }

    error = NULL;

    if (count == total)
    {
        /* All files are local, so we can use g_app_info_launch () with
         * the file list we constructed before.
         */
        result = g_app_info_launch (application,
                                    locations,
                                    G_APP_LAUNCH_CONTEXT (launch_context),
                                    &error);
    }
    else
    {
        /* Some files are non local, better use g_app_info_launch_uris ().
         */
        result = g_app_info_launch_uris (application,
                                         uris,
                                         G_APP_LAUNCH_CONTEXT (launch_context),
                                         &error);
    }

    g_object_unref (launch_context);

    if (!result)
    {
        if (error->domain == G_IO_ERROR &&
                error->code == G_IO_ERROR_NOT_SUPPORTED)
        {
            uri_scheme = g_uri_parse_scheme (uris->data);
            application_cannot_open_location (application,
                                              file,
                                              uri_scheme,
                                              parent_window);
            g_free (uri_scheme);
        }
        else
        {
#ifdef NEW_MIME_COMPLETE
            caja_program_chooser_show_invalid_message
            (MATE_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window);
#else
            g_warning ("Cannot open app: %s\n", error->message);
#endif
        }
        g_error_free (error);
    }
    else
    {
        for (l = uris; l != NULL; l = l->next)
        {
            file = caja_file_get_by_uri (l->data);
            caja_recent_add_file (file, application);
            caja_file_unref (file);
        }
    }

    g_list_free_full (locations, g_object_unref);
}
Esempio n. 6
0
void
caja_launch_application_by_uri (GAppInfo *application,
                                GList *uris,
                                GtkWindow *parent_window)
{
    char            *uri, *uri_scheme;
    GList           *locations, *l;
    GFile *location;
    CajaFile    *file;
    gboolean        result;
    GError *error;
    GdkDisplay *display;
    GdkAppLaunchContext *launch_context;
    CajaIconInfo *icon;
    int count, total;

    g_assert (uris != NULL);

    /* count the number of uris with local paths */
    count = 0;
    total = g_list_length (uris);
    locations = NULL;
    for (l = uris; l != NULL; l = l->next)
    {
        uri = l->data;

        location = g_file_new_for_uri (uri);
        if (g_file_is_native (location))
        {
            count++;
        }
        locations = g_list_prepend (locations, location);
    }
    locations = g_list_reverse (locations);

    if (parent_window != NULL) {
            display = gtk_widget_get_display (GTK_WIDGET (parent_window));
    } else {
            display = gdk_display_get_default ();
    }

    launch_context = gdk_display_get_app_launch_context (display);

    if (parent_window != NULL) {
        gdk_app_launch_context_set_screen (launch_context,
                                           gtk_window_get_screen (parent_window));
    }

    file = caja_file_get_by_uri (uris->data);
    icon = caja_file_get_icon (file, 48, 0);
    caja_file_unref (file);
    if (icon)
    {
        gdk_app_launch_context_set_icon_name (launch_context,
                                              caja_icon_info_get_used_name (icon));
        g_object_unref (icon);
    }

    error = NULL;

    result = g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (application),
                                                        uris,
                                                        G_APP_LAUNCH_CONTEXT (launch_context),
                                                        G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
                                                        NULL, NULL,
                                                        gather_pid_callback, application,
                                                        &error);

    g_object_unref (launch_context);

    if (!result)
    {
        if (error->domain == G_IO_ERROR &&
                error->code == G_IO_ERROR_NOT_SUPPORTED)
        {
            uri_scheme = g_uri_parse_scheme (uris->data);
            application_cannot_open_location (application,
                                              file,
                                              uri_scheme,
                                              parent_window);
            g_free (uri_scheme);
        }
        else
        {
#ifdef NEW_MIME_COMPLETE
            caja_program_chooser_show_invalid_message
            (MATE_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window);
#else
            g_warning ("Cannot open app: %s\n", error->message);
#endif
        }
        g_error_free (error);
    }
    else
    {
        for (l = uris; l != NULL; l = l->next)
        {
            file = caja_file_get_by_uri (l->data);
            caja_recent_add_file (file, application);
            caja_file_unref (file);
        }
    }

    g_list_free_full (locations, g_object_unref);
}