~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to libslab/application-tile.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of libtile.
3
 
 *
4
 
 * Copyright (c) 2006, 2007 Novell, Inc.
5
 
 *
6
 
 * Libtile is free software; you can redistribute it and/or modify it under the
7
 
 * terms of the GNU Lesser General Public License as published by the Free
8
 
 * Software Foundation; either version 2 of the License, or (at your option)
9
 
 * any later version.
10
 
 *
11
 
 * Libtile is distributed in the hope that it will be useful, but WITHOUT ANY
12
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public License
17
 
 * along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
 
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "application-tile.h"
22
 
#include "config.h"
23
 
 
24
 
#include <string.h>
25
 
#include <glib.h>
26
 
#include <glib/gi18n-lib.h>
27
 
#include <glib/gstdio.h>
28
 
#include <gconf/gconf-client.h>
29
 
#include <unistd.h>
30
 
 
31
 
#include "slab-gnome-util.h"
32
 
#include "libslab-utils.h"
33
 
#include "bookmark-agent.h"
34
 
#include "themed-icon.h"
35
 
 
36
 
G_DEFINE_TYPE (ApplicationTile, application_tile, NAMEPLATE_TILE_TYPE)
37
 
 
38
 
typedef enum {
39
 
        APP_IN_USER_STARTUP_DIR,
40
 
        APP_NOT_IN_STARTUP_DIR,
41
 
        APP_NOT_ELIGIBLE
42
 
} StartupStatus;
43
 
 
44
 
static void application_tile_get_property (GObject *, guint,       GValue *, GParamSpec *);
45
 
static void application_tile_set_property (GObject *, guint, const GValue *, GParamSpec *);
46
 
static void application_tile_finalize     (GObject *);
47
 
 
48
 
static void application_tile_setup (ApplicationTile *, const gchar *);
49
 
 
50
 
static GtkWidget *create_header    (const gchar *);
51
 
static GtkWidget *create_subheader (const gchar *);
52
 
 
53
 
static void header_size_allocate_cb (GtkWidget *, GtkAllocation *, gpointer);
54
 
 
55
 
static void start_trigger     (Tile *, TileEvent *, TileAction *);
56
 
static void help_trigger      (Tile *, TileEvent *, TileAction *);
57
 
static void user_apps_trigger (Tile *, TileEvent *, TileAction *);
58
 
static void startup_trigger   (Tile *, TileEvent *, TileAction *);
59
 
static void upgrade_trigger   (Tile *, TileEvent *, TileAction *);
60
 
static void uninstall_trigger (Tile *, TileEvent *, TileAction *);
61
 
 
62
 
static void add_to_user_list         (ApplicationTile *);
63
 
static void remove_from_user_list    (ApplicationTile *);
64
 
static void add_to_startup_list      (ApplicationTile *);
65
 
static void remove_from_startup_list (ApplicationTile *);
66
 
 
67
 
static gboolean verify_package_management_command (const gchar *);
68
 
static void run_package_management_command (ApplicationTile *, gchar *);
69
 
 
70
 
static void update_user_list_menu_item (ApplicationTile *);
71
 
static void agent_notify_cb (GObject *, GParamSpec *, gpointer);
72
 
 
73
 
static StartupStatus get_desktop_item_startup_status (GnomeDesktopItem *);
74
 
static void          update_startup_menu_item (ApplicationTile *);
75
 
 
76
 
typedef struct {
77
 
        GnomeDesktopItem *desktop_item;
78
 
 
79
 
        gchar       *image_id;
80
 
        gboolean     image_is_broken;
81
 
        GtkIconSize  image_size;
82
 
 
83
 
        gboolean show_generic_name;
84
 
        StartupStatus startup_status;
85
 
 
86
 
        BookmarkAgent       *agent;
87
 
        BookmarkStoreStatus  agent_status;
88
 
        gboolean             is_bookmarked;
89
 
        gulong               notify_signal_id;
90
 
} ApplicationTilePrivate;
91
 
 
92
 
#define APPLICATION_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APPLICATION_TILE_TYPE, ApplicationTilePrivate))
93
 
 
94
 
enum {
95
 
        PROP_0,
96
 
        PROP_APPLICATION_NAME,
97
 
        PROP_APPLICATION_DESCRIPTION,
98
 
        PROP_APPLICATION_GCONF_PREFIX
99
 
};
100
 
 
101
 
static void
102
 
application_tile_class_init (ApplicationTileClass *app_tile_class)
103
 
{
104
 
        GObjectClass *g_obj_class = G_OBJECT_CLASS (app_tile_class);
105
 
 
106
 
        g_obj_class->get_property = application_tile_get_property;
107
 
        g_obj_class->set_property = application_tile_set_property;
108
 
        g_obj_class->finalize     = application_tile_finalize;
109
 
 
110
 
        g_type_class_add_private (app_tile_class, sizeof (ApplicationTilePrivate));
111
 
 
112
 
        g_object_class_install_property (
113
 
                g_obj_class, PROP_APPLICATION_NAME,
114
 
                g_param_spec_string (
115
 
                        "application-name", "application-name",
116
 
                        "the name of the application", NULL,
117
 
                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
118
 
 
119
 
        g_object_class_install_property (
120
 
                g_obj_class, PROP_APPLICATION_DESCRIPTION,
121
 
                g_param_spec_string (
122
 
                        "application-description", "application-description",
123
 
                        "the name of the application", NULL,
124
 
                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
125
 
 
126
 
        g_object_class_install_property (
127
 
                g_obj_class, PROP_APPLICATION_GCONF_PREFIX,
128
 
                g_param_spec_string (
129
 
                        "gconf-prefix", "gconf-prefix",
130
 
                        "configuration prefix", NULL,
131
 
                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
132
 
}
133
 
 
134
 
GtkWidget *
135
 
application_tile_new (const gchar *desktop_item_id)
136
 
{
137
 
        return application_tile_new_full (desktop_item_id, GTK_ICON_SIZE_DND, TRUE, NULL);
138
 
}
139
 
 
140
 
GtkWidget *
141
 
application_tile_new_full (const gchar *desktop_item_id,
142
 
        GtkIconSize image_size, gboolean show_generic_name, const gchar *gconf_prefix)
143
 
{
144
 
        ApplicationTile        *this;
145
 
        ApplicationTilePrivate *priv;
146
 
 
147
 
        const gchar *uri = NULL;
148
 
 
149
 
        GnomeDesktopItem *desktop_item;
150
 
 
151
 
 
152
 
        desktop_item = load_desktop_item_from_unknown (desktop_item_id);
153
 
 
154
 
        if (
155
 
                desktop_item &&
156
 
                gnome_desktop_item_get_entry_type (desktop_item) == GNOME_DESKTOP_ITEM_TYPE_APPLICATION
157
 
        )
158
 
                uri = gnome_desktop_item_get_location (desktop_item);
159
 
 
160
 
        if (! uri) {
161
 
                if (desktop_item)
162
 
                        gnome_desktop_item_unref (desktop_item);
163
 
 
164
 
                return NULL;
165
 
        }
166
 
 
167
 
        this = g_object_new (APPLICATION_TILE_TYPE, "tile-uri", uri, NULL);
168
 
        priv = APPLICATION_TILE_GET_PRIVATE (this);
169
 
 
170
 
        priv->image_size   = image_size;
171
 
        priv->desktop_item = desktop_item;
172
 
        priv->show_generic_name = show_generic_name;
173
 
 
174
 
        application_tile_setup (this, gconf_prefix);
175
 
 
176
 
        return GTK_WIDGET (this);
177
 
}
178
 
 
179
 
static void
180
 
application_tile_init (ApplicationTile *tile)
181
 
{
182
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (tile);
183
 
 
184
 
        priv->desktop_item    = NULL;
185
 
        priv->image_id        = NULL;
186
 
        priv->image_is_broken = TRUE;
187
 
 
188
 
        priv->agent            = NULL;
189
 
        priv->agent_status     = BOOKMARK_STORE_ABSENT;
190
 
        priv->is_bookmarked    = FALSE;
191
 
        priv->notify_signal_id = 0;
192
 
 
193
 
        tile->name = tile->description = tile->gconf_prefix = NULL;
194
 
}
195
 
 
196
 
static void
197
 
application_tile_finalize (GObject *g_object)
198
 
{
199
 
        ApplicationTile *tile = APPLICATION_TILE (g_object);
200
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (g_object);
201
 
 
202
 
        if (tile->name) {
203
 
                g_free (tile->name);
204
 
                tile->name = NULL;
205
 
        }
206
 
        if (tile->description) {
207
 
                g_free (tile->description);
208
 
                tile->description = NULL;
209
 
        }
210
 
        if (tile->gconf_prefix) {
211
 
                g_free (tile->gconf_prefix);
212
 
                tile->gconf_prefix = NULL;
213
 
        }
214
 
 
215
 
        if (priv->desktop_item) {
216
 
                gnome_desktop_item_unref (priv->desktop_item);
217
 
                priv->desktop_item = NULL;
218
 
        }
219
 
        if (priv->image_id) {
220
 
                g_free (priv->image_id);
221
 
                priv->image_id = NULL;
222
 
        }
223
 
 
224
 
        if (priv->notify_signal_id)
225
 
                g_signal_handler_disconnect (priv->agent, priv->notify_signal_id);
226
 
 
227
 
        g_object_unref (G_OBJECT (priv->agent));
228
 
 
229
 
        G_OBJECT_CLASS (application_tile_parent_class)->finalize (g_object);
230
 
}
231
 
 
232
 
static void
233
 
application_tile_get_property (GObject *g_obj, guint prop_id, GValue *value, GParamSpec *param_spec)
234
 
{
235
 
        ApplicationTile *tile = APPLICATION_TILE (g_obj);
236
 
 
237
 
        switch (prop_id) {
238
 
        case PROP_APPLICATION_NAME:
239
 
                g_value_set_string (value, tile->name);
240
 
                break;
241
 
 
242
 
        case PROP_APPLICATION_DESCRIPTION:
243
 
                g_value_set_string (value, tile->description);
244
 
                break;
245
 
 
246
 
        case PROP_APPLICATION_GCONF_PREFIX:
247
 
                g_value_set_string (value, tile->gconf_prefix);
248
 
                break;
249
 
 
250
 
        default:
251
 
                break;
252
 
        }
253
 
}
254
 
 
255
 
static void
256
 
application_tile_set_property (GObject *g_obj, guint prop_id, const GValue *value, GParamSpec *param_spec)
257
 
{
258
 
        ApplicationTile *tile = APPLICATION_TILE (g_obj);
259
 
 
260
 
        switch (prop_id) {
261
 
        case PROP_APPLICATION_NAME:
262
 
                if (tile->name)
263
 
                        g_free (tile->name);
264
 
                tile->name = g_strdup (g_value_get_string (value));
265
 
                break;
266
 
 
267
 
        case PROP_APPLICATION_DESCRIPTION:
268
 
                if (tile->description)
269
 
                        g_free (tile->description);
270
 
                tile->description = g_strdup (g_value_get_string (value));
271
 
                break;
272
 
 
273
 
        case PROP_APPLICATION_GCONF_PREFIX:
274
 
                if (tile->gconf_prefix)
275
 
                        g_free (tile->gconf_prefix);
276
 
                tile->gconf_prefix = g_strdup (g_value_get_string (value));
277
 
                break;
278
 
 
279
 
        default:
280
 
                break;
281
 
        }
282
 
}
283
 
 
284
 
static void
285
 
application_tile_setup (ApplicationTile *this, const gchar *gconf_prefix)
286
 
{
287
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
288
 
 
289
 
        GtkWidget *image;
290
 
        GtkWidget *header;
291
 
        GtkWidget *subheader;
292
 
        GtkMenu   *context_menu;
293
 
        AtkObject *accessible;
294
 
 
295
 
        TileAction  **actions;
296
 
        TileAction   *action;
297
 
        GtkWidget    *menu_item;
298
 
        GtkContainer *menu_ctnr;
299
 
 
300
 
        const gchar *name;
301
 
        const gchar *desc;
302
 
 
303
 
        const gchar *comment;
304
 
 
305
 
        const gchar *key;
306
 
        gchar *markup;
307
 
        gchar *str;
308
 
 
309
 
        /*Fixme - need to address the entire gconf key location issue */
310
 
        /*Fixme - this is just a temporary stop gap                   */
311
 
        gboolean use_new_prefix;
312
 
 
313
 
 
314
 
        if (! priv->desktop_item) {
315
 
                priv->desktop_item = load_desktop_item_from_unknown (TILE (this)->uri);
316
 
 
317
 
                if (! priv->desktop_item)
318
 
                        return;
319
 
        }
320
 
 
321
 
        priv->image_id = g_strdup (gnome_desktop_item_get_localestring (priv->desktop_item, "Icon"));
322
 
        image = themed_icon_new (priv->image_id, priv->image_size);
323
 
 
324
 
        name = gnome_desktop_item_get_localestring (priv->desktop_item, "Name");
325
 
        desc = gnome_desktop_item_get_localestring (priv->desktop_item, "GenericName");
326
 
        comment = gnome_desktop_item_get_localestring (priv->desktop_item, "Comment");  
327
 
 
328
 
        accessible = gtk_widget_get_accessible (GTK_WIDGET (this));
329
 
        if (name)
330
 
          atk_object_set_name (accessible, name);
331
 
        if (desc)
332
 
          atk_object_set_description (accessible, desc);
333
 
 
334
 
        header    = create_header    (name);
335
 
 
336
 
        /*if no GenericName then just show and center the Name */
337
 
        if (desc && priv->show_generic_name
338
 
            && (!name || strcmp(name, desc) != 0))
339
 
                subheader = create_subheader (desc);
340
 
        else
341
 
                subheader = NULL;
342
 
 
343
 
        context_menu = GTK_MENU (gtk_menu_new ());
344
 
 
345
 
        g_object_set (
346
 
                G_OBJECT (this),
347
 
                "nameplate-image",         image,
348
 
                "nameplate-header",        header,
349
 
                "nameplate-subheader",     subheader,
350
 
                "context-menu",            context_menu,
351
 
                "application-name",        name,
352
 
                "application-description", desc,
353
 
                "gconf-prefix",            gconf_prefix,
354
 
                NULL);
355
 
        gtk_widget_set_tooltip_text (GTK_WIDGET (this), comment);
356
 
 
357
 
        priv->agent = bookmark_agent_get_instance (BOOKMARK_STORE_USER_APPS);
358
 
        g_object_get (G_OBJECT (priv->agent), BOOKMARK_AGENT_STORE_STATUS_PROP, & priv->agent_status, NULL);
359
 
 
360
 
        priv->notify_signal_id = g_signal_connect (
361
 
                G_OBJECT (priv->agent), "notify", G_CALLBACK (agent_notify_cb), this);
362
 
 
363
 
        priv->startup_status  = get_desktop_item_startup_status (priv->desktop_item);
364
 
 
365
 
        actions = g_new0 (TileAction *, 6);
366
 
 
367
 
        TILE (this)->actions   = actions;
368
 
        TILE (this)->n_actions = 6;
369
 
 
370
 
        menu_ctnr = GTK_CONTAINER (TILE (this)->context_menu);
371
 
 
372
 
/* make start action */
373
 
 
374
 
        str = g_strdup_printf (_("Start %s"), this->name);
375
 
        markup = g_markup_printf_escaped ("<b>%s</b>", str);
376
 
        action = tile_action_new (TILE (this), start_trigger, markup, TILE_ACTION_OPENS_NEW_WINDOW);
377
 
        actions [APPLICATION_TILE_ACTION_START] = action;
378
 
        g_free (markup);
379
 
        g_free (str);
380
 
 
381
 
        menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
382
 
 
383
 
        gtk_container_add (menu_ctnr, menu_item);
384
 
 
385
 
        TILE (this)->default_action = action;
386
 
 
387
 
/* insert separator */
388
 
 
389
 
        gtk_container_add (menu_ctnr, gtk_separator_menu_item_new ());
390
 
 
391
 
/* make help action */
392
 
 
393
 
        if (gnome_desktop_item_get_string (priv->desktop_item, "DocPath")) {
394
 
                action = tile_action_new (
395
 
                        TILE (this), help_trigger, _("Help"),
396
 
                        TILE_ACTION_OPENS_NEW_WINDOW | TILE_ACTION_OPENS_HELP);
397
 
 
398
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
399
 
                gtk_container_add (menu_ctnr, menu_item);
400
 
        }
401
 
        else {
402
 
                action = NULL;
403
 
        }
404
 
 
405
 
        actions [APPLICATION_TILE_ACTION_HELP] = action;
406
 
 
407
 
/* insert separator */
408
 
 
409
 
        if (action != NULL)
410
 
                gtk_container_add (menu_ctnr, gtk_separator_menu_item_new ());
411
 
 
412
 
/* make "add/remove to favorites" action */
413
 
 
414
 
        update_user_list_menu_item (this);
415
 
 
416
 
/* make "add/remove to startup" action */
417
 
 
418
 
        if (priv->startup_status != APP_NOT_ELIGIBLE) {
419
 
                action = tile_action_new (TILE (this), startup_trigger, NULL, 0);
420
 
                actions [APPLICATION_TILE_ACTION_UPDATE_STARTUP] = action;
421
 
 
422
 
                update_startup_menu_item (this);
423
 
 
424
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
425
 
 
426
 
                gtk_container_add (menu_ctnr, menu_item);
427
 
        }
428
 
 
429
 
/* make upgrade action */
430
 
 
431
 
        if (this->gconf_prefix && ! g_str_has_prefix (this->gconf_prefix, "/desktop/"))
432
 
                use_new_prefix = TRUE;
433
 
        else
434
 
                use_new_prefix = FALSE;
435
 
 
436
 
        if(!use_new_prefix)
437
 
                key = SLAB_UPGRADE_PACKAGE_KEY;
438
 
        else
439
 
                key = "/apps/main-menu/upgrade_package_command";
440
 
 
441
 
        if (verify_package_management_command (key)) {
442
 
                action = tile_action_new (TILE (this), upgrade_trigger, _("Upgrade"), TILE_ACTION_OPENS_NEW_WINDOW);
443
 
                actions [APPLICATION_TILE_ACTION_UPGRADE_PACKAGE] = action;
444
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
445
 
                gtk_container_add (menu_ctnr, menu_item);
446
 
        } else
447
 
                actions [APPLICATION_TILE_ACTION_UPGRADE_PACKAGE] = NULL;
448
 
 
449
 
/* make uninstall action */
450
 
 
451
 
        if(!use_new_prefix)
452
 
                key = SLAB_UNINSTALL_PACKAGE_KEY;
453
 
        else
454
 
                key = "/apps/main-menu/uninstall_package_command";
455
 
 
456
 
        if (verify_package_management_command (key)) {
457
 
                action = tile_action_new (TILE (this), uninstall_trigger, _("Uninstall"), TILE_ACTION_OPENS_NEW_WINDOW);
458
 
                actions [APPLICATION_TILE_ACTION_UNINSTALL_PACKAGE] = action;
459
 
                menu_item = GTK_WIDGET (tile_action_get_menu_item (action));
460
 
                gtk_container_add (menu_ctnr, menu_item);
461
 
        } else
462
 
                actions [APPLICATION_TILE_ACTION_UNINSTALL_PACKAGE] = NULL;
463
 
 
464
 
        gtk_widget_show_all (GTK_WIDGET (TILE (this)->context_menu));
465
 
}
466
 
 
467
 
static GtkWidget *
468
 
create_header (const gchar *name)
469
 
{
470
 
        GtkWidget *header;
471
 
 
472
 
 
473
 
        header = gtk_label_new (name);
474
 
        gtk_label_set_line_wrap (GTK_LABEL (header), TRUE);
475
 
        gtk_misc_set_alignment (GTK_MISC (header), 0.0, 0.5);
476
 
 
477
 
        g_signal_connect (
478
 
                G_OBJECT (header),
479
 
                "size-allocate",
480
 
                G_CALLBACK (header_size_allocate_cb),
481
 
                NULL);
482
 
 
483
 
        return header;
484
 
}
485
 
 
486
 
static GtkWidget *
487
 
create_subheader (const gchar *desc)
488
 
{
489
 
        GtkWidget *subheader;
490
 
 
491
 
 
492
 
        subheader = gtk_label_new (desc);
493
 
        gtk_label_set_ellipsize (GTK_LABEL (subheader), PANGO_ELLIPSIZE_END);
494
 
        gtk_misc_set_alignment (GTK_MISC (subheader), 0.0, 0.5);
495
 
        gtk_widget_modify_fg (
496
 
                subheader,
497
 
                GTK_STATE_NORMAL,
498
 
                & subheader->style->fg [GTK_STATE_INSENSITIVE]);
499
 
 
500
 
        return subheader;
501
 
}
502
 
 
503
 
static void
504
 
start_trigger (Tile *tile, TileEvent *event, TileAction *action)
505
 
{
506
 
        open_desktop_item_exec (APPLICATION_TILE_GET_PRIVATE (tile)->desktop_item);
507
 
}
508
 
 
509
 
static void
510
 
help_trigger (Tile *tile, TileEvent *event, TileAction *action)
511
 
{
512
 
        open_desktop_item_help (APPLICATION_TILE_GET_PRIVATE (tile)->desktop_item);
513
 
}
514
 
 
515
 
static void
516
 
user_apps_trigger (Tile *tile, TileEvent *event, TileAction *action)
517
 
{
518
 
        ApplicationTile *this = APPLICATION_TILE (tile);
519
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
520
 
 
521
 
        if (priv->is_bookmarked)
522
 
                remove_from_user_list (this);
523
 
        else
524
 
                add_to_user_list (this);
525
 
 
526
 
        update_user_list_menu_item (this);
527
 
}
528
 
 
529
 
static void
530
 
add_to_user_list (ApplicationTile *this)
531
 
{
532
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
533
 
 
534
 
        BookmarkItem *item;
535
 
 
536
 
 
537
 
        item = g_new0 (BookmarkItem, 1);
538
 
        item->uri       = TILE (this)->uri;
539
 
        item->mime_type = "application/x-desktop";
540
 
 
541
 
        bookmark_agent_add_item (priv->agent, item);
542
 
        g_free (item);
543
 
 
544
 
        priv->is_bookmarked = TRUE;
545
 
}
546
 
 
547
 
static void
548
 
remove_from_user_list (ApplicationTile *this)
549
 
{
550
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
551
 
 
552
 
        bookmark_agent_remove_item (priv->agent, TILE (this)->uri);
553
 
 
554
 
        priv->is_bookmarked = FALSE;
555
 
}
556
 
 
557
 
static void
558
 
upgrade_trigger (Tile *tile, TileEvent *event, TileAction *action)
559
 
{
560
 
        run_package_management_command (APPLICATION_TILE (tile), SLAB_UPGRADE_PACKAGE_KEY);
561
 
}
562
 
 
563
 
static void
564
 
uninstall_trigger (Tile *tile, TileEvent *event, TileAction *action)
565
 
{
566
 
        run_package_management_command (APPLICATION_TILE (tile), SLAB_UNINSTALL_PACKAGE_KEY);
567
 
}
568
 
 
569
 
static gboolean
570
 
verify_package_management_command (const gchar *gconf_key)
571
 
{
572
 
        gchar *cmd;
573
 
        gchar *path;
574
 
        gchar *args;
575
 
 
576
 
        gboolean retval;
577
 
 
578
 
        cmd = get_slab_gconf_string (gconf_key);
579
 
        if (!cmd)
580
 
                return FALSE;
581
 
 
582
 
        args = strchr (cmd, ' ');
583
 
 
584
 
        if (args)
585
 
                *args = '\0';
586
 
 
587
 
        path = g_find_program_in_path (cmd);
588
 
 
589
 
        retval = (path != NULL);
590
 
 
591
 
        g_free (cmd);
592
 
        g_free (path);
593
 
 
594
 
        return retval;
595
 
}
596
 
 
597
 
static void
598
 
run_package_management_command (ApplicationTile *tile, gchar *gconf_key)
599
 
{
600
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (tile);
601
 
 
602
 
        gchar *cmd_precis;
603
 
        gchar *package_name;
604
 
 
605
 
        GString *cmd;
606
 
        gint pivot;
607
 
        gchar **argv;
608
 
 
609
 
        GError *error = NULL;
610
 
 
611
 
        package_name = get_package_name_from_desktop_item (priv->desktop_item);
612
 
 
613
 
        if (!package_name)
614
 
                return;
615
 
 
616
 
        cmd_precis = get_slab_gconf_string (gconf_key);
617
 
 
618
 
        g_assert (cmd_precis);
619
 
 
620
 
        pivot = strstr (cmd_precis, "PACKAGE_NAME") - cmd_precis;
621
 
 
622
 
        cmd = g_string_new_len (cmd_precis, pivot);
623
 
        g_string_append (cmd, package_name);
624
 
        g_string_append (cmd, & cmd_precis [pivot + 12]);
625
 
 
626
 
        argv = g_strsplit (cmd->str, " ", -1);
627
 
 
628
 
        g_string_free (cmd, TRUE);
629
 
 
630
 
        g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
631
 
 
632
 
        if (error) {
633
 
                g_warning ("error: [%s]\n", error->message);
634
 
 
635
 
                g_error_free (error);
636
 
        }
637
 
 
638
 
        g_free (cmd_precis);
639
 
        g_free (package_name);
640
 
        g_strfreev (argv);
641
 
}
642
 
 
643
 
static void
644
 
startup_trigger (Tile *tile, TileEvent *event, TileAction *action)
645
 
{
646
 
        ApplicationTile *this = APPLICATION_TILE (tile);
647
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
648
 
 
649
 
        switch (priv->startup_status) {
650
 
                case APP_IN_USER_STARTUP_DIR:
651
 
                        remove_from_startup_list (this);
652
 
                        break;
653
 
 
654
 
                case APP_NOT_IN_STARTUP_DIR:
655
 
                        add_to_startup_list (this);
656
 
                        break;
657
 
 
658
 
                default:
659
 
                        break;
660
 
        }
661
 
 
662
 
        update_startup_menu_item (this);
663
 
}
664
 
 
665
 
static void
666
 
add_to_startup_list (ApplicationTile *this)
667
 
{
668
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
669
 
 
670
 
        gchar *desktop_item_filename;
671
 
        gchar *desktop_item_basename;
672
 
 
673
 
        gchar *startup_dir;
674
 
        gchar *dst_filename;
675
 
 
676
 
        const gchar *src_uri;
677
 
        gchar *dst_uri;
678
 
 
679
 
        desktop_item_filename =
680
 
                g_filename_from_uri (gnome_desktop_item_get_location (priv->desktop_item), NULL,
681
 
                NULL);
682
 
 
683
 
        g_return_if_fail (desktop_item_filename != NULL);
684
 
 
685
 
        desktop_item_basename = g_path_get_basename (desktop_item_filename);
686
 
 
687
 
        startup_dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL);
688
 
 
689
 
        if (! g_file_test (startup_dir, G_FILE_TEST_EXISTS))
690
 
                g_mkdir_with_parents (startup_dir, 0700);
691
 
 
692
 
        dst_filename = g_build_filename (startup_dir, desktop_item_basename, NULL);
693
 
 
694
 
        src_uri = gnome_desktop_item_get_location (priv->desktop_item);
695
 
        dst_uri = g_filename_to_uri (dst_filename, NULL, NULL);
696
 
 
697
 
        copy_file (src_uri, dst_uri);
698
 
        priv->startup_status = APP_IN_USER_STARTUP_DIR;
699
 
 
700
 
        g_free (desktop_item_filename);
701
 
        g_free (desktop_item_basename);
702
 
        g_free (startup_dir);
703
 
        g_free (dst_filename);
704
 
        g_free (dst_uri);
705
 
}
706
 
 
707
 
static void
708
 
remove_from_startup_list (ApplicationTile *this)
709
 
{
710
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
711
 
 
712
 
        gchar *ditem_filename;
713
 
        gchar *ditem_basename;
714
 
        gchar *src_filename;
715
 
 
716
 
        ditem_filename =
717
 
                g_filename_from_uri (gnome_desktop_item_get_location (priv->desktop_item), NULL,
718
 
                NULL);
719
 
 
720
 
        g_return_if_fail (ditem_filename != NULL);
721
 
 
722
 
        ditem_basename = g_path_get_basename (ditem_filename);
723
 
 
724
 
        src_filename = g_build_filename (g_get_user_config_dir (), "autostart", ditem_basename, NULL);
725
 
 
726
 
        priv->startup_status = APP_NOT_IN_STARTUP_DIR;
727
 
        if (g_file_test (src_filename, G_FILE_TEST_EXISTS))
728
 
        {
729
 
                if(g_file_test (src_filename, G_FILE_TEST_IS_DIR))
730
 
                        g_assert_not_reached ();
731
 
                g_unlink (src_filename);
732
 
        }
733
 
 
734
 
        g_free (ditem_filename);
735
 
        g_free (ditem_basename);
736
 
        g_free (src_filename);
737
 
}
738
 
 
739
 
GnomeDesktopItem *
740
 
application_tile_get_desktop_item (ApplicationTile *tile)
741
 
{
742
 
        return APPLICATION_TILE_GET_PRIVATE (tile)->desktop_item;
743
 
}
744
 
 
745
 
static void
746
 
update_user_list_menu_item (ApplicationTile *this)
747
 
{
748
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
749
 
 
750
 
        TileAction *action;
751
 
        GtkWidget  *item;
752
 
 
753
 
 
754
 
        if (priv->agent_status == BOOKMARK_STORE_ABSENT) {
755
 
                if (TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU])
756
 
                        g_object_unref (TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU]);
757
 
 
758
 
                TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU] = NULL;
759
 
        }
760
 
        else if (! TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU]) {
761
 
                TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU] =
762
 
                        tile_action_new (TILE (this), user_apps_trigger, NULL, 0);
763
 
 
764
 
                tile_action_set_menu_item_label (
765
 
                        TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU], "blah");
766
 
 
767
 
                item = GTK_WIDGET (tile_action_get_menu_item (
768
 
                        TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU]));
769
 
                gtk_menu_shell_insert (GTK_MENU_SHELL (TILE (this)->context_menu), item, 4);
770
 
 
771
 
                gtk_widget_show_all (item);
772
 
        }
773
 
        else
774
 
                /* do nothing */ ;
775
 
 
776
 
        action = TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_MAIN_MENU];
777
 
 
778
 
        if (! action)
779
 
                return;
780
 
 
781
 
        priv->is_bookmarked = bookmark_agent_has_item (priv->agent, TILE (this)->uri);
782
 
 
783
 
        if (priv->is_bookmarked)
784
 
                tile_action_set_menu_item_label (action, _("Remove from Favorites"));
785
 
        else
786
 
                tile_action_set_menu_item_label (action, _("Add to Favorites"));
787
 
 
788
 
        item = GTK_WIDGET (tile_action_get_menu_item (action));
789
 
 
790
 
        if (! GTK_IS_MENU_ITEM (item))
791
 
                return;
792
 
 
793
 
        g_object_get (G_OBJECT (priv->agent), BOOKMARK_AGENT_STORE_STATUS_PROP, & priv->agent_status, NULL);
794
 
 
795
 
        gtk_widget_set_sensitive (item, (priv->agent_status != BOOKMARK_STORE_DEFAULT_ONLY));
796
 
}
797
 
 
798
 
static StartupStatus
799
 
get_desktop_item_startup_status (GnomeDesktopItem *desktop_item)
800
 
{
801
 
        gchar *filename;
802
 
        gchar *basename;
803
 
 
804
 
        const gchar * const * global_dirs;
805
 
        gchar *global_target;
806
 
        gchar *user_target;
807
 
 
808
 
        StartupStatus retval;
809
 
        gint x;
810
 
        
811
 
        filename = g_filename_from_uri (gnome_desktop_item_get_location (desktop_item), NULL, NULL);
812
 
        if (!filename)
813
 
                return APP_NOT_ELIGIBLE;
814
 
        basename = g_path_get_basename (filename);
815
 
 
816
 
        retval = APP_NOT_IN_STARTUP_DIR;
817
 
        global_dirs = g_get_system_config_dirs();
818
 
        for(x=0; global_dirs[x]; x++)
819
 
        {
820
 
                global_target = g_build_filename (global_dirs[x], "autostart", basename, NULL);
821
 
                if (g_file_test (global_target, G_FILE_TEST_EXISTS))
822
 
                {
823
 
                        retval = APP_NOT_ELIGIBLE;
824
 
                        g_free (global_target);
825
 
                        break;
826
 
                }
827
 
                g_free (global_target);
828
 
        }
829
 
 
830
 
        /* gnome-session currently checks these dirs also. see startup-programs.c */
831
 
        if (retval != APP_NOT_ELIGIBLE)
832
 
        {
833
 
                global_dirs = g_get_system_data_dirs();
834
 
                for(x=0; global_dirs[x]; x++)
835
 
                {
836
 
                        global_target = g_build_filename (global_dirs[x], "gnome", "autostart", basename, NULL);
837
 
                        if (g_file_test (global_target, G_FILE_TEST_EXISTS))
838
 
                        {
839
 
                                retval = APP_NOT_ELIGIBLE;
840
 
                                g_free (global_target);
841
 
                                break;
842
 
                        }
843
 
                        g_free (global_target);
844
 
                }
845
 
        }
846
 
 
847
 
        if (retval != APP_NOT_ELIGIBLE)
848
 
        {
849
 
                user_target = g_build_filename (g_get_user_config_dir (), "autostart", basename, NULL);
850
 
                if (g_file_test (user_target, G_FILE_TEST_EXISTS))
851
 
                        retval = APP_IN_USER_STARTUP_DIR;
852
 
                g_free (user_target);
853
 
        }
854
 
 
855
 
        g_free (basename);
856
 
        g_free (filename);
857
 
 
858
 
        return retval;
859
 
}
860
 
 
861
 
static void
862
 
update_startup_menu_item (ApplicationTile *this)
863
 
{
864
 
        TileAction *action = TILE (this)->actions [APPLICATION_TILE_ACTION_UPDATE_STARTUP];
865
 
        ApplicationTilePrivate *priv = APPLICATION_TILE_GET_PRIVATE (this);
866
 
 
867
 
        if (!action)
868
 
                return;
869
 
 
870
 
        if (priv->startup_status == APP_IN_USER_STARTUP_DIR)
871
 
                tile_action_set_menu_item_label (action, _("Remove from Startup Programs"));
872
 
        else
873
 
                tile_action_set_menu_item_label (action, _("Add to Startup Programs"));
874
 
}
875
 
 
876
 
static void
877
 
header_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer user_data)
878
 
{
879
 
        gtk_widget_set_size_request (widget, alloc->width, -1);
880
 
}
881
 
 
882
 
static void
883
 
agent_notify_cb (GObject *g_obj, GParamSpec *pspec, gpointer user_data)
884
 
{
885
 
        update_user_list_menu_item (APPLICATION_TILE (user_data));
886
 
}