~ogra/+junk/go-home-applet

« back to all changes in this revision

Viewing changes to src/applet.c

  • Committer: Michael Terry
  • Date: 2008-08-29 14:04:56 UTC
  • Revision ID: michael.terry@ubuntu.com-20080829140456-u79ryc8bl3l9kak3
support gconf key for icon name

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <gtk/gtk.h>
30
30
#include <libwnck/libwnck.h>
31
31
#include <libgnomeui/libgnomeui.h>
 
32
#include <gconf/gconf-client.h>
32
33
#include <panel-applet.h>
33
34
#include <panel-applet-gconf.h>
34
35
 
35
36
#include "launcher-util.h"
36
37
 
 
38
#define GCONF_ICON_KEY "icon_name"
37
39
#define ICON_SIZE 24
38
 
#define ICON_NAME "distributor-logo"
 
40
#define DEFAULT_ICON_NAME "distributor-logo"
39
41
#define XDG_OPEN "xdg-open"
40
42
 
41
43
typedef struct 
125
127
}
126
128
 
127
129
 
 
130
static gchar *
 
131
get_applet_icon_name (PanelApplet *applet)
 
132
{
 
133
  gchar *icon_name;
 
134
 
 
135
  icon_name = panel_applet_gconf_get_string (applet, GCONF_ICON_KEY, NULL);
 
136
  if (icon_name == NULL || icon_name[0] == 0)
 
137
    icon_name = g_strdup (DEFAULT_ICON_NAME);
 
138
 
 
139
  return icon_name;
 
140
}
 
141
 
 
142
 
 
143
static void
 
144
set_icon (GoHomeApp *app)
 
145
{
 
146
  gchar *icon_name;
 
147
 
 
148
  icon_name = get_applet_icon_name (PANEL_APPLET (app->applet));
 
149
  gtk_image_set_from_icon_name (GTK_IMAGE (app->image), icon_name, ICON_SIZE);
 
150
  g_free (icon_name);
 
151
}
 
152
 
 
153
 
 
154
/* GConf callback */
 
155
static void
 
156
icon_changed_cb (GConfClient *client,
 
157
                 guint        connection_id,
 
158
                 GConfEntry  *entry,
 
159
                 gpointer     data)
 
160
{
 
161
  GoHomeApp *app;
 
162
 
 
163
  app = (GoHomeApp*)data;
 
164
 
 
165
  set_icon (app);
 
166
}
 
167
 
 
168
 
128
169
/* Taken from nautilus::panel-util.c, with some modifications */
129
170
static gchar *
130
171
get_icon_name (GIcon *icon)
277
318
                const gchar *iid, 
278
319
                gpointer     data)
279
320
{
280
 
  GtkIconTheme *theme = gtk_icon_theme_get_default ();
281
321
  WnckScreen *screen;
282
322
  GoHomeApp *app;
283
323
  GtkWidget *eb;
284
 
  GdkPixbuf *home;
 
324
  gchar *key;
285
325
 
286
326
  if (strcmp (iid, "OAFIID:GNOME_GoHome") != 0)
287
327
                return FALSE;
290
330
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
291
331
  textdomain (GETTEXT_PACKAGE);
292
332
 
293
 
  home  = gtk_icon_theme_load_icon (theme, ICON_NAME, ICON_SIZE, 0, NULL); 
294
 
 
295
333
  app = g_slice_new0 (GoHomeApp);
296
334
  screen = wnck_screen_get_default ();
297
335
 
300
338
  gtk_container_set_border_width (GTK_CONTAINER (applet), 0);
301
339
  gtk_widget_set_tooltip_text (GTK_WIDGET (applet), 
302
340
                               _("Click here to hide all windows and show the home screen"));
303
 
  
 
341
 
 
342
  panel_applet_add_preferences (applet, "/schemas/apps/go-home-applet/prefs", NULL);
 
343
 
 
344
  key = panel_applet_gconf_get_full_key (applet, GCONF_ICON_KEY);
 
345
  gconf_client_notify_add (gconf_client_get_default (), key, icon_changed_cb,
 
346
                           app, NULL, NULL);
 
347
  g_free (key);
 
348
 
304
349
  eb = gtk_event_box_new ();
305
350
  g_object_set (eb, 
306
351
                "above-child", TRUE, 
322
367
                                      G_CALLBACK(on_drag_data_recieved), app);
323
368
 
324
369
  /* The actual icon */
325
 
  app->image = gtk_image_new_from_pixbuf (home);
 
370
  app->image = gtk_image_new ();
 
371
  set_icon (app);
326
372
  gtk_container_add (GTK_CONTAINER (eb), app->image);
327
 
  g_object_unref (home);
328
373
 
329
374
        gtk_widget_show_all (GTK_WIDGET (applet));
330
375
                
339
384
  panel_applet_setup_menu (PANEL_APPLET (applet),
340
385
                                Context_menu_xml,
341
386
                                _menu_verbs,
342
 
                                NULL);
 
387
                                applet);
343
388
        
344
389
        return TRUE;
345
390
}
392
437
                      const gchar       *verb)
393
438
{
394
439
  GtkWidget *panel_about_dialog;
 
440
  gchar *icon_name;
 
441
  PanelApplet *applet = (PanelApplet*)user_data;
395
442
        
396
443
  panel_about_dialog = gtk_about_dialog_new ();
397
444
 
 
445
  icon_name = get_applet_icon_name (applet);
398
446
  g_object_set (panel_about_dialog,
399
447
                "name", _("Go Home"),
400
448
                "comments", _("Go Home"),
401
449
                "version", "0.1",
402
450
                "authors", close_window_authors,
403
 
                "logo-icon-name", ICON_NAME,
 
451
                "logo-icon-name", icon_name,
 
452
                "icon-name", icon_name,
404
453
                "copyright", "Copyright \xc2\xa9 2008 Canonical Ltd",
405
454
                NULL);
 
455
  g_free (icon_name);
406
456
 
407
457
  gtk_widget_show (panel_about_dialog);
408
458