static GtkWidget *
create_emblem_widget (CajaEmblemSidebar *emblem_sidebar,
                      const char *name)
{
    GtkWidget *ret;
    const char *display_name;
    char *keyword;
    GdkPixbuf *pixbuf;
    CajaIconInfo *info;

    info = caja_icon_info_lookup_from_name (name, CAJA_ICON_SIZE_STANDARD);

    pixbuf = caja_icon_info_get_pixbuf_at_size (info, CAJA_ICON_SIZE_STANDARD);

    display_name = caja_icon_info_get_display_name (info);

    keyword = caja_emblem_get_keyword_from_icon_name (name);
    if (display_name == NULL)
    {
        display_name = keyword;
    }

    ret = create_emblem_widget_with_pixbuf (emblem_sidebar, keyword,
                                            display_name, pixbuf);
    g_free (keyword);
    g_object_unref (info);
    return ret;
}
예제 #2
0
/* returns TRUE if a folder window should be opened */
static gboolean
do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAutorunOpenWindow open_window_func, gpointer user_data)
{
    AutorunDialogData *data;
    GtkWidget *dialog;
    GtkWidget *hbox;
    GtkWidget *vbox;
    GtkWidget *label;
    GtkWidget *combo_box;
    GtkWidget *always_check_button;
    GtkWidget *eject_button;
    GtkWidget *image;
    char *markup;
    char *content_description;
    char *mount_name;
    GIcon *icon;
    GdkPixbuf *pixbuf;
    CajaIconInfo *icon_info;
    int icon_size;
    gboolean user_forced_dialog;
    gboolean pref_ask;
    gboolean pref_start_app;
    gboolean pref_ignore;
    gboolean pref_open_folder;
    char *media_greeting;
    gboolean ret;

    ret = FALSE;
    mount_name = NULL;

    if (g_content_type_is_a (x_content_type, "x-content/win32-software"))
    {
        /* don't pop up the dialog anyway if the content type says
         * windows software.
         */
        goto out;
    }

    user_forced_dialog = is_shift_pressed ();

    caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder);
    pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

    if (user_forced_dialog)
    {
        goto show_dialog;
    }

    if (!pref_ask && !pref_ignore && !pref_open_folder)
    {
        GAppInfo *app_info;
        app_info = g_app_info_get_default_for_type (x_content_type, FALSE);
        if (app_info != NULL)
        {
            caja_autorun_launch_for_mount (mount, app_info);
        }
        goto out;
    }

    if (pref_open_folder)
    {
        ret = TRUE;
        goto out;
    }

    if (pref_ignore)
    {
        goto out;
    }

show_dialog:

    mount_name = g_mount_get_name (mount);

    dialog = gtk_dialog_new ();

    hbox = gtk_hbox_new (FALSE, 12);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);

    icon = g_mount_get_icon (mount);
    icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
    icon_info = caja_icon_info_lookup (icon, icon_size);
    pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
    g_object_unref (icon_info);
    g_object_unref (icon);
    image = gtk_image_new_from_pixbuf (pixbuf);
    gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
    gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
    /* also use the icon on the dialog */
    gtk_window_set_title (GTK_WINDOW (dialog), mount_name);
    gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);
    gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
    g_object_unref (pixbuf);

    vbox = gtk_vbox_new (FALSE, 12);
    gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);

    label = gtk_label_new (NULL);


    /* Customize greeting for well-known x-content types */
    if (strcmp (x_content_type, "x-content/audio-cdda") == 0)
    {
        media_greeting = _("You have just inserted an Audio CD.");
    }
    else if (strcmp (x_content_type, "x-content/audio-dvd") == 0)
    {
        media_greeting = _("You have just inserted an Audio DVD.");
    }
    else if (strcmp (x_content_type, "x-content/video-dvd") == 0)
    {
        media_greeting = _("You have just inserted a Video DVD.");
    }
    else if (strcmp (x_content_type, "x-content/video-vcd") == 0)
    {
        media_greeting = _("You have just inserted a Video CD.");
    }
    else if (strcmp (x_content_type, "x-content/video-svcd") == 0)
    {
        media_greeting = _("You have just inserted a Super Video CD.");
    }
    else if (strcmp (x_content_type, "x-content/blank-cd") == 0)
    {
        media_greeting = _("You have just inserted a blank CD.");
    }
    else if (strcmp (x_content_type, "x-content/blank-dvd") == 0)
    {
        media_greeting = _("You have just inserted a blank DVD.");
    }
    else if (strcmp (x_content_type, "x-content/blank-cd") == 0)
    {
        media_greeting = _("You have just inserted a blank Blu-Ray disc.");
    }
    else if (strcmp (x_content_type, "x-content/blank-cd") == 0)
    {
        media_greeting = _("You have just inserted a blank HD DVD.");
    }
    else if (strcmp (x_content_type, "x-content/image-photocd") == 0)
    {
        media_greeting = _("You have just inserted a Photo CD.");
    }
    else if (strcmp (x_content_type, "x-content/image-picturecd") == 0)
    {
        media_greeting = _("You have just inserted a Picture CD.");
    }
    else if (strcmp (x_content_type, "x-content/image-dcf") == 0)
    {
        media_greeting = _("You have just inserted a medium with digital photos.");
    }
    else if (strcmp (x_content_type, "x-content/audio-player") == 0)
    {
        media_greeting = _("You have just inserted a digital audio player.");
    }
    else if (g_content_type_is_a (x_content_type, "x-content/software"))
    {
        media_greeting = _("You have just inserted a medium with software intended to be automatically started.");
    }
    else
    {
        /* fallback to generic greeting */
        media_greeting = _("You have just inserted a medium.");
    }
    markup = g_strdup_printf ("<big><b>%s %s</b></big>", media_greeting, _("Choose what application to launch."));
    gtk_label_set_markup (GTK_LABEL (label), markup);
    g_free (markup);
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

    label = gtk_label_new (NULL);
    content_description = g_content_type_get_description (x_content_type);
    markup = g_strdup_printf (_("Select how to open \"%s\" and whether to perform this action in the future for other media of type \"%s\"."), mount_name, content_description);
    g_free (content_description);
    gtk_label_set_markup (GTK_LABEL (label), markup);
    g_free (markup);
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

    data = g_new0 (AutorunDialogData, 1);
    data->dialog = dialog;
    data->mount = g_object_ref (mount);
    data->remember = !pref_ask;
    data->selected_ignore = pref_ignore;
    data->x_content_type = g_strdup (x_content_type);
    data->selected_app = g_app_info_get_default_for_type (x_content_type, FALSE);
    data->open_window_func = open_window_func;
    data->user_data = user_data;

    combo_box = gtk_combo_box_new ();
    caja_autorun_prepare_combo_box (combo_box, x_content_type, FALSE, TRUE, FALSE, autorun_combo_changed, data);
    g_signal_connect (G_OBJECT (combo_box),
                      "key-press-event",
                      G_CALLBACK (combo_box_enter_ok),
                      dialog);

    gtk_box_pack_start (GTK_BOX (vbox), combo_box, TRUE, TRUE, 0);

    always_check_button = gtk_check_button_new_with_mnemonic (_("_Always perform this action"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (always_check_button), data->remember);
    g_signal_connect (G_OBJECT (always_check_button),
                      "toggled",
                      G_CALLBACK (autorun_always_toggled),
                      data);
    gtk_box_pack_start (GTK_BOX (vbox), always_check_button, TRUE, TRUE, 0);

    gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK, GTK_RESPONSE_OK,
                            NULL);
    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

    if (g_mount_can_eject (mount))
    {
        GtkWidget *eject_image;
        eject_button = gtk_button_new_with_mnemonic (_("_Eject"));
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "media-eject",
                                           caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON),
                                           0,
                                           NULL);
        eject_image = gtk_image_new_from_pixbuf (pixbuf);
        g_object_unref (pixbuf);
        gtk_button_set_image (GTK_BUTTON (eject_button), eject_image);
        data->should_eject = TRUE;
    }
    else
    {
        eject_button = gtk_button_new_with_mnemonic (_("_Unmount"));
        data->should_eject = FALSE;
    }
    gtk_dialog_add_action_widget (GTK_DIALOG (dialog), eject_button, AUTORUN_DIALOG_RESPONSE_EJECT);
    gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), eject_button, TRUE);

    /* show the dialog */
    gtk_widget_show_all (dialog);

    g_signal_connect (G_OBJECT (dialog),
                      "response",
                      G_CALLBACK (autorun_dialog_response),
                      data);

    g_signal_connect (G_OBJECT (data->mount),
                      "unmounted",
                      G_CALLBACK (autorun_dialog_mount_unmounted),
                      data);

out:
    g_free (mount_name);
    return ret;
}
예제 #3
0
void
caja_autorun_prepare_combo_box (GtkWidget *combo_box,
                                const char *x_content_type,
                                gboolean include_ask,
                                gboolean include_open_with_other_app,
                                gboolean update_settings,
                                CajaAutorunComboBoxChanged changed_cb,
                                gpointer user_data)
{
    GList *l;
    GList *app_info_list;
    GAppInfo *default_app_info;
    GtkListStore *list_store;
    GtkTreeIter iter;
    GdkPixbuf *pixbuf;
    int icon_size;
    int set_active;
    int n;
    int num_apps;
    gboolean pref_ask;
    gboolean pref_start_app;
    gboolean pref_ignore;
    gboolean pref_open_folder;
    CajaAutorunComboBoxData *data;
    GtkCellRenderer *renderer;
    gboolean new_data;

    caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder);
    pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

    icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);

    set_active = -1;
    data = NULL;
    new_data = TRUE;

    app_info_list = g_app_info_get_all_for_type (x_content_type);
    default_app_info = g_app_info_get_default_for_type (x_content_type, FALSE);
    num_apps = g_list_length (app_info_list);

    list_store = gtk_list_store_new (5,
                                     GDK_TYPE_PIXBUF,
                                     G_TYPE_STRING,
                                     G_TYPE_APP_INFO,
                                     G_TYPE_STRING,
                                     G_TYPE_INT);

    /* no apps installed */
    if (num_apps == 0)
    {
        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           GTK_STOCK_DIALOG_ERROR,
                                           icon_size,
                                           0,
                                           NULL);

        /* TODO: integrate with PackageKit-mate to find applications */

        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("No applications found"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
                            -1);
        g_object_unref (pixbuf);
    }
    else
    {
        if (include_ask)
        {
            gtk_list_store_append (list_store, &iter);
            pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                               GTK_STOCK_DIALOG_QUESTION,
                                               icon_size,
                                               0,
                                               NULL);
            gtk_list_store_set (list_store, &iter,
                                COLUMN_AUTORUN_PIXBUF, pixbuf,
                                COLUMN_AUTORUN_NAME, _("Ask what to do"),
                                COLUMN_AUTORUN_APP_INFO, NULL,
                                COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                                COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
                                -1);
            g_object_unref (pixbuf);
        }

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           GTK_STOCK_CLOSE,
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Do Nothing"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE,
                            -1);
        g_object_unref (pixbuf);

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "folder-open",
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Open Folder"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER,
                            -1);
        g_object_unref (pixbuf);

        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, NULL,
                            COLUMN_AUTORUN_NAME, NULL,
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
                            -1);

        for (l = app_info_list, n = include_ask ? 4 : 3; l != NULL; l = l->next, n++)
        {
            GIcon *icon;
            CajaIconInfo *icon_info;
            char *open_string;
            GAppInfo *app_info = l->data;

            /* we deliberately ignore should_show because some apps might want
             * to install special handlers that should be hidden in the regular
             * application launcher menus
             */

            icon = g_app_info_get_icon (app_info);
            icon_info = caja_icon_info_lookup (icon, icon_size);
            pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
            g_object_unref (icon_info);

            open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info));

            gtk_list_store_append (list_store, &iter);
            gtk_list_store_set (list_store, &iter,
                                COLUMN_AUTORUN_PIXBUF, pixbuf,
                                COLUMN_AUTORUN_NAME, open_string,
                                COLUMN_AUTORUN_APP_INFO, app_info,
                                COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                                COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP,
                                -1);
            if (pixbuf != NULL)
            {
                g_object_unref (pixbuf);
            }
            g_free (open_string);

            if (g_app_info_equal (app_info, default_app_info))
            {
                set_active = n;
            }
        }
    }

    if (include_open_with_other_app)
    {
        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, NULL,
                            COLUMN_AUTORUN_NAME, NULL,
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
                            -1);

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "application-x-executable",
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Open with other Application..."),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP,
                            -1);
        g_object_unref (pixbuf);
    }

    if (default_app_info != NULL)
    {
        g_object_unref (default_app_info);
    }
    g_list_foreach (app_info_list, (GFunc) g_object_unref, NULL);
    g_list_free(app_info_list);

    gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (list_store));
    g_object_unref (G_OBJECT (list_store));

    gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box));

    renderer = gtk_cell_renderer_pixbuf_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
                                    "pixbuf", COLUMN_AUTORUN_PIXBUF,
                                    NULL);
    renderer = gtk_cell_renderer_text_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
                                    "text", COLUMN_AUTORUN_NAME,
                                    NULL);
    gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box), combo_box_separator_func, NULL, NULL);

    if (num_apps == 0)
    {
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
        gtk_widget_set_sensitive (combo_box, FALSE);
    }
    else
    {
        gtk_widget_set_sensitive (combo_box, TRUE);
        if (pref_ask && include_ask)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
        }
        else if (pref_ignore)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0);
        }
        else if (pref_open_folder)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 2 : 1);
        }
        else if (set_active != -1)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), set_active);
        }
        else
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0);
        }

        /* See if we have an old data around */
        data = g_object_get_data (G_OBJECT (combo_box), "caja_autorun_combobox_data");
        if (data)
        {
            new_data = FALSE;
            g_free (data->x_content_type);
        }
        else
        {
            data = g_new0 (CajaAutorunComboBoxData, 1);
        }

        data->x_content_type = g_strdup (x_content_type);
        data->include_ask = include_ask;
        data->include_open_with_other_app = include_open_with_other_app;
        data->update_settings = update_settings;
        data->changed_cb = changed_cb;
        data->user_data = user_data;
        data->combo_box = combo_box;
        if (data->changed_signal_id == 0)
        {
            data->changed_signal_id = g_signal_connect (G_OBJECT (combo_box),
                                      "changed",
                                      G_CALLBACK (combo_box_changed),
                                      data);
        }
    }

    if (new_data)
    {
        g_object_set_data_full (G_OBJECT (combo_box),
                                "caja_autorun_combobox_data",
                                data,
                                (GDestroyNotify) caja_autorun_combobox_data_destroy);
    }
}
예제 #4
0
static void
fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
    FMListModel *model;
    FileEntry *file_entry;
    CajaFile *file;
    char *str;
    GdkPixbuf *icon, *rendered_icon;
    GIcon *gicon, *emblemed_icon, *emblem_icon;
    CajaIconInfo *icon_info;
    GEmblem *emblem;
    GList *emblem_icons, *l;
    int icon_size;
    CajaZoomLevel zoom_level;
    CajaFile *parent_file;
    char *emblems_to_ignore[3];
    int i;
    CajaFileIconFlags flags;

    model = (FMListModel *)tree_model;

    g_return_if_fail (model->details->stamp == iter->stamp);
    g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

    file_entry = g_sequence_get (iter->user_data);
    file = file_entry->file;

    switch (column)
    {
    case FM_LIST_MODEL_FILE_COLUMN:
        g_value_init (value, CAJA_TYPE_FILE);

        g_value_set_object (value, file);
        break;
    case FM_LIST_MODEL_SUBDIRECTORY_COLUMN:
        g_value_init (value, CAJA_TYPE_DIRECTORY);

        g_value_set_object (value, file_entry->subdirectory);
        break;
    case FM_LIST_MODEL_SMALLEST_ICON_COLUMN:
    case FM_LIST_MODEL_SMALLER_ICON_COLUMN:
    case FM_LIST_MODEL_SMALL_ICON_COLUMN:
    case FM_LIST_MODEL_STANDARD_ICON_COLUMN:
    case FM_LIST_MODEL_LARGE_ICON_COLUMN:
    case FM_LIST_MODEL_LARGER_ICON_COLUMN:
    case FM_LIST_MODEL_LARGEST_ICON_COLUMN:
        g_value_init (value, GDK_TYPE_PIXBUF);

        if (file != NULL)
        {
            zoom_level = fm_list_model_get_zoom_level_from_column_id (column);
            icon_size = caja_get_icon_size_for_zoom_level (zoom_level);

            flags = CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS |
                    CAJA_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
                    CAJA_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
            if (model->details->drag_view != NULL)
            {
                GtkTreePath *path_a, *path_b;

                gtk_tree_view_get_drag_dest_row (model->details->drag_view,
                                                 &path_a,
                                                 NULL);
                if (path_a != NULL)
                {
                    path_b = gtk_tree_model_get_path (tree_model, iter);

                    if (gtk_tree_path_compare (path_a, path_b) == 0)
                    {
                        flags |= CAJA_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
                    }

                    gtk_tree_path_free (path_a);
                    gtk_tree_path_free (path_b);
                }
            }

            gicon = caja_file_get_gicon (file, flags);

            /* render emblems with GEmblemedIcon */
            parent_file = caja_file_get_parent (file);
            i = 0;
            emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_TRASH;
            if (parent_file) {
            	if (!caja_file_can_write (parent_file)) {
                    emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_CANT_WRITE;
            	}
            	caja_file_unref (parent_file);
            }
            emblems_to_ignore[i++] = NULL;

            emblem = NULL;
            emblem_icons = caja_file_get_emblem_icons (file,
            					       emblems_to_ignore);

            if (emblem_icons != NULL) {
                emblem_icon = emblem_icons->data;
                emblem = g_emblem_new (emblem_icon);
                emblemed_icon = g_emblemed_icon_new (gicon, emblem);

                g_object_unref (emblem);

            	for (l = emblem_icons->next; l != NULL; l = l->next) {
            	    emblem_icon = l->data;
            	    emblem = g_emblem_new (emblem_icon);
            	    g_emblemed_icon_add_emblem
            	        (G_EMBLEMED_ICON (emblemed_icon), emblem);

                    g_object_unref (emblem);
            	}

                g_list_free_full (emblem_icons, g_object_unref);

            	g_object_unref (gicon);
            	gicon = emblemed_icon;
            }

            icon_info = caja_icon_info_lookup (gicon, icon_size);
            icon = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);

            g_object_unref (icon_info);
            g_object_unref (gicon);

            if (model->details->highlight_files != NULL &&
                    g_list_find_custom (model->details->highlight_files,
                                        file, (GCompareFunc) caja_file_compare_location))
            {
                rendered_icon = eel_gdk_pixbuf_render (icon, 1, 255, 255, 0, 0);

                if (rendered_icon != NULL)
                {
                    g_object_unref (icon);
                    icon = rendered_icon;
                }
            }

            g_value_set_object (value, icon);
            g_object_unref (icon);
        }
        break;
    case FM_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
        g_value_init (value, G_TYPE_BOOLEAN);

        g_value_set_boolean (value, file != NULL && caja_file_can_rename (file));
        break;
    default:
        if (column >= FM_LIST_MODEL_NUM_COLUMNS || column < FM_LIST_MODEL_NUM_COLUMNS + model->details->columns->len)
        {
            CajaColumn *caja_column;
            GQuark attribute;
            caja_column = model->details->columns->pdata[column - FM_LIST_MODEL_NUM_COLUMNS];

            g_value_init (value, G_TYPE_STRING);
            g_object_get (caja_column,
                          "attribute_q", &attribute,
                          NULL);
            if (file != NULL)
            {
                str = caja_file_get_string_attribute_with_default_q (file,
                        attribute);
                g_value_take_string (value, str);
            }
            else if (attribute == attribute_name_q)
            {
                if (file_entry->parent->loaded)
                {
                    g_value_set_string (value, _("(Empty)"));
                }
                else
                {
                    g_value_set_string (value, _("Loading..."));
                }
            }
        }
        else
        {
            g_assert_not_reached ();
        }
    }
}
예제 #5
0
void
caja_x_content_bar_set_x_content_type (CajaXContentBar *bar, const char *x_content_type)
{
    char *message;
    char *description;
    GAppInfo *default_app;

    g_free (bar->priv->x_content_type);
    bar->priv->x_content_type = g_strdup (x_content_type);

    description = g_content_type_get_description (x_content_type);

    /* Customize greeting for well-known x-content types */
    if (strcmp (x_content_type, "x-content/audio-cdda") == 0)
    {
        message = g_strdup (_("These files are on an Audio CD."));
    }
    else if (strcmp (x_content_type, "x-content/audio-dvd") == 0)
    {
        message = g_strdup (_("These files are on an Audio DVD."));
    }
    else if (strcmp (x_content_type, "x-content/video-dvd") == 0)
    {
        message = g_strdup (_("These files are on a Video DVD."));
    }
    else if (strcmp (x_content_type, "x-content/video-vcd") == 0)
    {
        message = g_strdup (_("These files are on a Video CD."));
    }
    else if (strcmp (x_content_type, "x-content/video-svcd") == 0)
    {
        message = g_strdup (_("These files are on a Super Video CD."));
    }
    else if (strcmp (x_content_type, "x-content/image-photocd") == 0)
    {
        message = g_strdup (_("These files are on a Photo CD."));
    }
    else if (strcmp (x_content_type, "x-content/image-picturecd") == 0)
    {
        message = g_strdup (_("These files are on a Picture CD."));
    }
    else if (strcmp (x_content_type, "x-content/image-dcf") == 0)
    {
        message = g_strdup (_("The media contains digital photos."));
    }
    else if (strcmp (x_content_type, "x-content/audio-player") == 0)
    {
        message = g_strdup (_("These files are on a digital audio player."));
    }
    else if (strcmp (x_content_type, "x-content/software") == 0)
    {
        message = g_strdup (_("The media contains software."));
    }
    else
    {
        /* fallback to generic greeting */
        message = g_strdup_printf (_("The media has been detected as \"%s\"."), description);
    }


    gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
    gtk_widget_show (bar->priv->label);

    /* TODO: We really need a GtkBrowserBackButton-ish widget here.. until then, we only
     *       show the default application. */

    default_app = g_app_info_get_default_for_type (x_content_type, FALSE);
    if (default_app != NULL)
    {
        char *button_text;
        const char *name;
        GIcon *icon;
        GtkWidget *image;

        icon = g_app_info_get_icon (default_app);
        if (icon != NULL)
        {
            GdkPixbuf *pixbuf;
            int icon_size;
            CajaIconInfo *icon_info;
            icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON);
            icon_info = caja_icon_info_lookup (icon, icon_size);
            pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
            image = gtk_image_new_from_pixbuf (pixbuf);
            g_object_unref (pixbuf);
            g_object_unref (icon_info);
        }
        else
        {
            image = NULL;
        }

        name = g_app_info_get_display_name (default_app);
        button_text = g_strdup_printf (_("Open %s"), name);

        gtk_button_set_image (GTK_BUTTON (bar->priv->button), image);
        gtk_button_set_label (GTK_BUTTON (bar->priv->button), button_text);
        gtk_widget_show (bar->priv->button);
        g_free (button_text);
        g_object_unref (default_app);
    }
    else
    {
        gtk_widget_hide (bar->priv->button);
    }

    g_free (message);
    g_free (description);
}
예제 #6
0
static void
present_autorun_for_software_dialog (GMount *mount)
{
    GIcon *icon;
    int icon_size;
    CajaIconInfo *icon_info;
    GdkPixbuf *pixbuf;
    GtkWidget *image;
    char *mount_name;
    GtkWidget *dialog;
    AutorunSoftwareDialogData *data;

    mount_name = g_mount_get_name (mount);

    dialog = gtk_message_dialog_new_with_markup (NULL, /* TODO: parent window? */
             0,
             GTK_MESSAGE_OTHER,
             GTK_BUTTONS_CANCEL,
             _("<big><b>This medium contains software intended to be automatically started. Would you like to run it?</b></big>"));
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
            _("The software will run directly from the medium \"%s\". "
              "You should never run software that you don't trust.\n"
              "\n"
              "If in doubt, press Cancel."),
            mount_name);

    /* TODO: in a star trek future add support for verifying
     * software on media (e.g. if it has a certificate, check it
     * etc.)
     */


    icon = g_mount_get_icon (mount);
    icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
    icon_info = caja_icon_info_lookup (icon, icon_size);
    pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
    image = gtk_image_new_from_pixbuf (pixbuf);
    gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
    gtk_widget_set_valign (image, GTK_ALIGN_START);
    gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);

    gtk_window_set_title (GTK_WINDOW (dialog), mount_name);
    gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);

    data = g_new0 (AutorunSoftwareDialogData, 1);
    data->dialog = dialog;
    data->mount = g_object_ref (mount);

    g_signal_connect (G_OBJECT (mount),
                      "unmounted",
                      G_CALLBACK (autorun_software_dialog_mount_unmounted),
                      data);

    gtk_dialog_add_button (GTK_DIALOG (dialog),
                           _("_Run"),
                           GTK_RESPONSE_OK);

    gtk_widget_show_all (dialog);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
        gtk_widget_destroy (dialog);
        autorun (mount);
    }

    g_object_unref (icon_info);
    g_object_unref (pixbuf);
    g_free (mount_name);
}