2
* This file is part of the Main Menu.
4
* Copyright (c) 2006, 2007 Novell, Inc.
6
* The Main Menu is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the Free
8
* Software Foundation; either version 2 of the License, or (at your option)
11
* The Main Menu is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
* You should have received a copy of the GNU General Public License along with
17
* the Main Menu; if not, write to the Free Software Foundation, Inc., 51
18
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "system-tile.h"
25
#include <glib/gi18n-lib.h>
26
#include <gconf/gconf-client.h>
28
#include "bookmark-agent.h"
29
#include "slab-gnome-util.h"
30
#include "libslab-utils.h"
32
G_DEFINE_TYPE (SystemTile, system_tile, NAMEPLATE_TILE_TYPE)
34
static void system_tile_finalize (GObject *);
35
static void system_tile_style_set (GtkWidget *, GtkStyle *);
37
static void load_image (SystemTile *);
38
static GtkWidget *create_header (const gchar *);
40
static void open_trigger (Tile *, TileEvent *, TileAction *);
41
static void remove_trigger (Tile *, TileEvent *, TileAction *);
43
static void update_user_list_menu_item (SystemTile *);
44
static void agent_notify_cb (GObject *, GParamSpec *, gpointer);
47
GnomeDesktopItem *desktop_item;
50
BookmarkStoreStatus agent_status;
51
gulong notify_signal_id;
54
gboolean image_is_broken;
57
#define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SYSTEM_TILE_TYPE, SystemTilePrivate))
60
system_tile_new (const gchar *desktop_item_id, const gchar *title)
63
SystemTilePrivate *priv;
66
GtkWidget *header = NULL;
68
GtkMenu *context_menu;
73
GtkContainer *menu_ctnr;
75
GnomeDesktopItem *desktop_item = NULL;
76
gchar *image_id = NULL;
77
gchar *header_txt = NULL;
81
AtkObject *accessible = NULL;
84
desktop_item = libslab_gnome_desktop_item_new_from_unknown_id (desktop_item_id);
87
image_id = g_strdup (gnome_desktop_item_get_localestring (desktop_item, "Icon"));
88
uri = g_strdup (gnome_desktop_item_get_location (desktop_item));
91
header_txt = g_strdup (title);
93
header_txt = g_strdup (
94
gnome_desktop_item_get_localestring (desktop_item, "Name"));
100
header = create_header (header_txt);
102
context_menu = GTK_MENU (gtk_menu_new ());
104
this = g_object_new (
107
"context-menu", context_menu,
108
"nameplate-image", gtk_image_new (),
109
"nameplate-header", header,
110
"nameplate-subheader", NULL,
112
priv = PRIVATE (this);
114
priv->agent = bookmark_agent_get_instance (BOOKMARK_STORE_SYSTEM);
115
g_object_get (G_OBJECT (priv->agent), BOOKMARK_AGENT_STORE_STATUS_PROP, & priv->agent_status, NULL);
117
priv->notify_signal_id = g_signal_connect (
118
G_OBJECT (priv->agent), "notify", G_CALLBACK (agent_notify_cb), this);
120
actions = g_new0 (TileAction *, 2);
122
TILE (this)->actions = actions;
123
TILE (this)->n_actions = 2;
125
menu_ctnr = GTK_CONTAINER (TILE (this)->context_menu);
127
markup = g_markup_printf_escaped (_("<b>Open %s</b>"), header_txt);
128
action = tile_action_new (TILE (this), open_trigger, markup, TILE_ACTION_OPENS_NEW_WINDOW);
129
actions [SYSTEM_TILE_ACTION_OPEN] = action;
132
menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
134
gtk_container_add (menu_ctnr, menu_item);
136
TILE (this)->default_action = action;
138
gtk_container_add (menu_ctnr, gtk_separator_menu_item_new ());
140
markup = g_markup_printf_escaped (_("Remove from System Items"));
141
action = tile_action_new (TILE (this), remove_trigger, markup, 0);
142
actions [SYSTEM_TILE_ACTION_REMOVE] = action;
145
menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
147
gtk_container_add (menu_ctnr, menu_item);
149
gtk_widget_show_all (GTK_WIDGET (TILE (this)->context_menu));
151
update_user_list_menu_item (this);
153
priv->desktop_item = desktop_item;
154
priv->image_id = g_strdup (image_id);
158
/* Set up the mnemonic for the tile */
159
gtk_label_set_mnemonic_widget (GTK_LABEL (header), GTK_WIDGET (this));
161
/* Set up the accessible name for the tile */
162
accessible = gtk_widget_get_accessible (GTK_WIDGET (this));
164
atk_object_set_name (accessible, header_txt);
170
return GTK_WIDGET (this);
174
system_tile_class_init (SystemTileClass *this_class)
176
GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);
177
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class);
179
g_obj_class->finalize = system_tile_finalize;
181
widget_class->style_set = system_tile_style_set;
183
g_type_class_add_private (this_class, sizeof (SystemTilePrivate));
187
system_tile_init (SystemTile *this)
189
SystemTilePrivate *priv = PRIVATE (this);
191
priv->desktop_item = NULL;
192
priv->image_id = NULL;
193
priv->image_is_broken = TRUE;
196
priv->agent_status = BOOKMARK_STORE_ABSENT;
197
priv->notify_signal_id = 0;
201
system_tile_finalize (GObject *g_obj)
203
SystemTilePrivate *priv = PRIVATE (g_obj);
205
g_free (priv->image_id);
206
gnome_desktop_item_unref (priv->desktop_item);
208
if (priv->notify_signal_id)
209
g_signal_handler_disconnect (priv->agent, priv->notify_signal_id);
211
G_OBJECT_CLASS (system_tile_parent_class)->finalize (g_obj);
215
system_tile_style_set (GtkWidget *widget, GtkStyle *prev_style)
217
load_image (SYSTEM_TILE (widget));
221
load_image (SystemTile *this)
223
SystemTilePrivate *priv = PRIVATE (this);
225
GtkImage *image = GTK_IMAGE (NAMEPLATE_TILE (this)->image);
228
g_object_set (G_OBJECT (image), "icon-size", GTK_ICON_SIZE_MENU, NULL);
230
priv->image_is_broken = libslab_gtk_image_set_by_id (image, priv->image_id);
234
create_header (const gchar *name)
238
header = gtk_label_new (name);
239
gtk_label_set_use_underline (GTK_LABEL (header), TRUE);
240
gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5);
246
open_trigger (Tile *this, TileEvent *event, TileAction *action)
248
open_desktop_item_exec (PRIVATE (this)->desktop_item);
252
remove_trigger (Tile *this, TileEvent *event, TileAction *action)
254
bookmark_agent_remove_item (PRIVATE (this)->agent, this->uri);
258
update_user_list_menu_item (SystemTile *this)
260
SystemTilePrivate *priv = PRIVATE (this);
266
action = TILE (this)->actions [SYSTEM_TILE_ACTION_REMOVE];
271
item = GTK_WIDGET (tile_action_get_menu_item (action));
273
if (! GTK_IS_MENU_ITEM (item))
276
g_object_get (G_OBJECT (priv->agent), BOOKMARK_AGENT_STORE_STATUS_PROP, & priv->agent_status, NULL);
278
gtk_widget_set_sensitive (item, (priv->agent_status != BOOKMARK_STORE_DEFAULT_ONLY));
282
agent_notify_cb (GObject *g_obj, GParamSpec *pspec, gpointer user_data)
284
update_user_list_menu_item (SYSTEM_TILE (user_data));