Esempio n. 1
0
int
main (int argc,
      char **argv)
{
  GtkWidget *w;

  g_type_init ();
  gtk_init (&argc, &argv);

  toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_container_add (GTK_CONTAINER (toplevel), box);

  combobox = gtk_app_chooser_button_new ("image/jpeg");
  gtk_box_pack_start (GTK_BOX (box), combobox, TRUE, TRUE, 0);

  g_signal_connect (combobox, "changed",
                    G_CALLBACK (combo_changed_cb), NULL);

  w = gtk_label_new (NULL);
  gtk_label_set_markup (GTK_LABEL (w), "<b>Selected app info</b>");
  gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);

  w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);

  sel_image = gtk_image_new ();
  gtk_box_pack_start (GTK_BOX (w), sel_image, TRUE, TRUE, 0);
  sel_name = gtk_label_new (NULL);
  gtk_box_pack_start (GTK_BOX (w), sel_name, TRUE, TRUE, 0);

  gtk_app_chooser_button_set_heading (GTK_APP_CHOOSER_BUTTON (combobox), "Choose one, <i>not</i> two");
  gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (combobox));
  gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
                                             CUSTOM_ITEM,
                                             "Hey, I'm special!",
                                             g_themed_icon_new ("face-smile"));

  /* this one will trigger a warning, and will not be added */
  gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
                                             CUSTOM_ITEM,
                                             "Hey, I'm fake!",
                                             g_themed_icon_new ("face-evil"));

  gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (combobox),
                                               TRUE);

  /* connect to the detailed signal */
  g_signal_connect (combobox, "custom-item-activated::" CUSTOM_ITEM,
                    G_CALLBACK (special_item_activated_cb), NULL);

  /* connect to the generic signal too */
  g_signal_connect (combobox, "custom-item-activated",
                    G_CALLBACK (action_cb), NULL);

  /* test refresh on a combo */
  gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));

  gtk_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
                                                 CUSTOM_ITEM);

  gtk_widget_show_all (toplevel);

  g_signal_connect (toplevel, "delete-event",
                    G_CALLBACK (gtk_main_quit), NULL);

  gtk_main ();

  return EXIT_SUCCESS;
}
static void
prepare_combo_box (GtkWidget *combo_box,
		   AutorunDialogData *data)
{
        GtkAppChooserButton *app_chooser = GTK_APP_CHOOSER_BUTTON (combo_box);
        GIcon *icon;
        gboolean pref_ask;
        gboolean pref_start_app;
        gboolean pref_ignore;
        gboolean pref_open_folder;
        GAppInfo *info;
        gchar *content_type;

        content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser));

        /* fetch preferences for this content type */
        csd_autorun_get_preferences (content_type,
                                     &pref_start_app, &pref_ignore, &pref_open_folder);
        pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

        info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));

        /* append the separator only if we have >= 1 apps in the chooser */
        if (info != NULL) {
                gtk_app_chooser_button_append_separator (app_chooser);
                g_object_unref (info);
        }

        icon = g_themed_icon_new (GTK_STOCK_DIALOG_QUESTION);
        gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK,
                                                   _("Ask what to do"),
                                                   icon);
        g_object_unref (icon);

        icon = g_themed_icon_new (GTK_STOCK_CLOSE);
        gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING,
                                                   _("Do Nothing"),
                                                   icon);
        g_object_unref (icon);

        icon = g_themed_icon_new ("folder-open");
        gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER,
                                                   _("Open Folder"),
                                                   icon);
        g_object_unref (icon);

        gtk_app_chooser_button_set_show_dialog_item (app_chooser, TRUE);

        if (pref_ask) {
                gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_ASK);
        } else if (pref_ignore) {
                gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING);
        } else if (pref_open_folder) {
                gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER);
        }

        g_signal_connect (app_chooser, "changed",
                          G_CALLBACK (combo_box_changed_cb), data);
        g_signal_connect (app_chooser, "custom-item-activated",
                          G_CALLBACK (custom_item_activated_cb), data);

        g_free (content_type);
}