~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to gnome-panel/panel-properties-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 22:20:05 UTC
  • mto: (2.1.6 squeeze) (1.3.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 171.
  • Revision ID: james.westby@ubuntu.com-20100114222005-rll7tw9fojl3ac6z
Tags: upstream-2.29.5.1
ImportĀ upstreamĀ versionĀ 2.29.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include <string.h>
30
30
#include <glib/gi18n.h>
31
 
#include <libgnomeui/gnome-icon-entry.h>
32
31
 
33
32
#include <libpanel-util/panel-error.h>
34
33
#include <libpanel-util/panel-glib.h>
35
34
#include <libpanel-util/panel-gtk.h>
 
35
#include <libpanel-util/panel-icon-chooser.h>
36
36
#include <libpanel-util/panel-show.h>
37
37
 
38
38
#include "nothing.h"
40
40
#include "panel-gconf.h"
41
41
#include "panel-util.h"
42
42
#include "panel-globals.h"
 
43
#include "panel-icon-names.h"
43
44
 
44
45
typedef struct {
45
46
        PanelToplevel *toplevel;
55
56
        GtkWidget     *size_label;
56
57
        GtkWidget     *size_label_pixels;
57
58
        GtkWidget     *icon_align;
58
 
        GtkWidget     *icon_entry;
 
59
        GtkWidget     *icon_chooser;
59
60
        GtkWidget     *icon_label;
60
61
        GtkWidget     *expand_toggle;
61
62
        GtkWidget     *autohide_toggle;
79
80
        guint          toplevel_notify;
80
81
        guint          background_notify;
81
82
 
82
 
        /* The theme directory of the icon, see bug #119209 */
83
 
        char          *icon_theme_dir;
84
 
 
85
83
        /* FIXME: This is a workaround for GTK+ bug #327243 */
86
84
        int            selection_emitted;
87
85
} PanelPropertiesDialog;
107
105
                gtk_widget_destroy (dialog->properties_dialog);
108
106
        dialog->properties_dialog = NULL;
109
107
 
110
 
        g_free (dialog->icon_theme_dir);
111
 
        dialog->icon_theme_dir = NULL;
112
 
 
113
108
        g_free (dialog);
114
109
}
115
110
 
246
241
}
247
242
 
248
243
static void
249
 
panel_properties_dialog_icon_changed (PanelPropertiesDialog *dialog,
250
 
                                      GnomeIconEntry        *entry)
 
244
panel_properties_dialog_icon_changed (PanelIconChooser      *chooser,
 
245
                                      const char            *icon,
 
246
                                      PanelPropertiesDialog *dialog)
251
247
{
252
 
        const char *icon = NULL;
253
 
        char       *freeme = NULL;
254
 
 
255
 
        icon = gnome_icon_entry_get_filename (entry);
256
 
 
257
 
        /* Strip dir from the icon path if in the icon
258
 
         * theme directory.  See bug #119209
259
 
         */
260
 
        if (icon && g_path_is_absolute (icon)) {
261
 
                char *dir;
262
 
 
263
 
                dir = g_path_get_dirname (icon);
264
 
 
265
 
                if (dir && dialog->icon_theme_dir && strcmp (dir, dialog->icon_theme_dir) == 0)
266
 
                        icon = freeme = g_path_get_basename (icon);
267
 
 
268
 
                g_free (dir);
269
 
        }
270
 
 
271
248
        panel_profile_set_attached_custom_icon (dialog->toplevel, icon);
272
 
 
273
 
        g_free (freeme);
274
249
}
275
250
 
276
251
static void
277
 
panel_properties_dialog_setup_icon_entry (PanelPropertiesDialog *dialog,
278
 
                                          GtkBuilder            *gui)
 
252
panel_properties_dialog_setup_icon_chooser (PanelPropertiesDialog *dialog,
 
253
                                            GtkBuilder            *gui)
279
254
{
280
255
        char *custom_icon;
281
256
 
282
257
        dialog->icon_align = PANEL_GTK_BUILDER_GET (gui, "icon_align");
283
258
        g_return_if_fail (dialog->icon_align != NULL);
284
259
 
285
 
        dialog->icon_entry = gnome_icon_entry_new ("panel-drawer-icon",
286
 
                                                   _("Browse icons"));
287
 
        gtk_widget_show (dialog->icon_entry);
 
260
        dialog->icon_chooser = panel_icon_chooser_new (NULL);
 
261
        panel_icon_chooser_set_fallback_icon_name (PANEL_ICON_CHOOSER (dialog->icon_chooser),
 
262
                                                   PANEL_ICON_DRAWER);
 
263
        gtk_widget_show (dialog->icon_chooser);
288
264
        gtk_container_add (GTK_CONTAINER (dialog->icon_align),
289
 
                           dialog->icon_entry);
 
265
                           dialog->icon_chooser);
290
266
 
291
267
        dialog->icon_label = PANEL_GTK_BUILDER_GET (gui, "icon_label");
292
268
        g_return_if_fail (dialog->icon_label != NULL);
293
269
 
294
 
        dialog->icon_theme_dir = NULL;
295
270
        custom_icon = panel_profile_get_attached_custom_icon (dialog->toplevel);
296
 
        if (custom_icon != NULL &&
297
 
            ! g_path_is_absolute (custom_icon)) {
298
 
                /* if the icon is not absolute path name it comes from the
299
 
                   theme, and as such we wish to store the theme directory
300
 
                   where it comes from.  See bug #119209 */
301
 
                char *icon;
302
 
                
303
 
                icon = panel_find_icon (gtk_icon_theme_get_default (),
304
 
                                        custom_icon, 48);
305
 
                if (icon != NULL)
306
 
                        dialog->icon_theme_dir = g_path_get_dirname (icon);
307
 
 
308
 
                g_free (custom_icon);
309
 
                custom_icon = icon;
310
 
        }
311
 
        gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (dialog->icon_entry), custom_icon);
 
271
        panel_icon_chooser_set_icon (PANEL_ICON_CHOOSER (dialog->icon_chooser),
 
272
                                     custom_icon);
312
273
        g_free (custom_icon);
313
274
 
314
 
        if (dialog->icon_theme_dir == NULL) {
315
 
                /* use the default pixmap directory as the standard icon_theme_dir,
316
 
                 * since the standard directory is themed */
317
 
                g_object_get (G_OBJECT (dialog->icon_entry), "pixmap_subdir",
318
 
                              &(dialog->icon_theme_dir), NULL);
319
 
        }
320
 
 
321
 
        g_signal_connect_swapped (dialog->icon_entry, "changed",
322
 
                                  G_CALLBACK (panel_properties_dialog_icon_changed), dialog);
 
275
        g_signal_connect (dialog->icon_chooser, "changed",
 
276
                          G_CALLBACK (panel_properties_dialog_icon_changed), dialog);
323
277
 
324
278
        if (!panel_profile_is_writable_attached_custom_icon (dialog->toplevel)) {
325
 
                gtk_widget_set_sensitive (dialog->icon_entry, FALSE);
 
279
                gtk_widget_set_sensitive (dialog->icon_chooser, FALSE);
326
280
                gtk_widget_set_sensitive (dialog->icon_label, FALSE);
327
281
                gtk_widget_show (dialog->writability_warn_general);
328
282
        }
416
370
}
417
371
 
418
372
static void
419
 
panel_properties_dialog_chooser_preview_update (GtkFileChooser *file_chooser,
420
 
                                                gpointer data)
421
 
{
422
 
        GtkWidget *preview;
423
 
        char      *filename;
424
 
        GdkPixbuf *pixbuf;
425
 
        gboolean   have_preview;
426
 
 
427
 
        preview = GTK_WIDGET (data);
428
 
        filename = gtk_file_chooser_get_preview_filename (file_chooser);
429
 
 
430
 
        if (filename == NULL)
431
 
                return;
432
 
 
433
 
        pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
434
 
        have_preview = (pixbuf != NULL);
435
 
        g_free (filename);
436
 
 
437
 
        gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
438
 
        if (pixbuf)
439
 
                g_object_unref (pixbuf);
440
 
 
441
 
        gtk_file_chooser_set_preview_widget_active (file_chooser,
442
 
                                                    have_preview);
443
 
}
444
 
 
445
 
static void
446
373
panel_properties_dialog_setup_image_chooser (PanelPropertiesDialog *dialog,
447
374
                                             GtkBuilder            *gui)
448
375
{
449
 
        GtkFileFilter *filter;
450
 
        GtkWidget     *chooser_preview;
451
 
        char          *image;
 
376
        char *image;
452
377
 
453
378
        dialog->image_chooser = PANEL_GTK_BUILDER_GET (gui, "image_chooser");
454
 
 
455
 
        filter = gtk_file_filter_new ();
456
 
        gtk_file_filter_add_pixbuf_formats (filter);
457
 
        gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog->image_chooser),
458
 
                                     filter);
459
 
 
460
 
        chooser_preview = gtk_image_new ();
461
 
        gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog->image_chooser),
462
 
                                             chooser_preview);
463
 
        g_signal_connect (dialog->image_chooser, "update-preview",
464
 
                          G_CALLBACK (panel_properties_dialog_chooser_preview_update),
465
 
                          chooser_preview);
 
379
        panel_gtk_file_chooser_add_image_preview (GTK_FILE_CHOOSER (dialog->image_chooser));
466
380
 
467
381
        image = panel_profile_get_background_image (dialog->toplevel);
468
382
 
915
829
}
916
830
 
917
831
static void
918
 
panel_properties_dialog_remove_icon_entry (PanelPropertiesDialog *dialog)
 
832
panel_properties_dialog_remove_icon_chooser (PanelPropertiesDialog *dialog)
919
833
{
920
834
        GtkContainer *container = GTK_CONTAINER (dialog->general_table);
921
835
 
924
838
 
925
839
        dialog->icon_label = NULL;
926
840
        dialog->icon_align = NULL;
927
 
        dialog->icon_entry = NULL;
 
841
        dialog->icon_chooser = NULL;
928
842
 
929
843
        gtk_table_resize (GTK_TABLE (dialog->general_table), 3, 2);
930
844
}
946
860
                                             gboolean               attached)
947
861
{
948
862
        if (!attached)
949
 
                panel_properties_dialog_remove_icon_entry (dialog);
 
863
                panel_properties_dialog_remove_icon_chooser (dialog);
950
864
        else {
951
865
                gtk_window_set_title (GTK_WINDOW (dialog->properties_dialog),
952
866
                                      _("Drawer Properties"));
987
901
 
988
902
        panel_properties_dialog_setup_orientation_combo  (dialog, gui);
989
903
        panel_properties_dialog_setup_size_spin          (dialog, gui);
990
 
        panel_properties_dialog_setup_icon_entry         (dialog, gui);
 
904
        panel_properties_dialog_setup_icon_chooser       (dialog, gui);
991
905
        panel_properties_dialog_setup_expand_toggle      (dialog, gui);
992
906
        panel_properties_dialog_setup_autohide_toggle    (dialog, gui);
993
907
        panel_properties_dialog_setup_hidebuttons_toggle (dialog, gui);