~ubuntu-branches/ubuntu/raring/gnome-session/raring

« back to all changes in this revision

Viewing changes to gnome-session/gsm-shell-extensions.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-05-07 11:22:35 UTC
  • mfrom: (1.1.75) (2.2.14 sid)
  • Revision ID: package-import@ubuntu.com-20120507112235-z9pe25ur5d8zt4c6
Tags: 3.4.1-1ubuntu1
* Merge with Debian. Remaining changes:
 - debian/control.in:
   + gnome-session
     - Recommend nautilus and either unity, unity-2d or gnome-shell
     - Only suggest gnome-session-fallback (we don't want it to be installed
       by default)
     - Drop the Recommends on gnome-power-manager, the code gnome-session uses
       has moved to gnome-settings-daemon
   + gnome-session-fallback
     - Recommend cups-pk-helper for gnome-session-fallback so that
       System Settings>Printers works
 - debian/gnome-session-bin.postinst, debian/gnome-session-bin.prerm:
    Moved registering gnome-session binary as a session manager to 
    gnome-session-bin package
 - debian/postinst, postrm:
    set the default lightdm session as ubuntu if none already set
 - don't install defaults.list (installed by desktop-file-utils in ubuntu):
    debian/gnome-session-common.dirs and gnome-session-common.install
 - add debian/gnome-session-common.gsettings-override:
   set ubuntu as the default session if nothing is provided
 - debian/55gnome-session_gnomerc:
    Use POSIX string substitutions (shell internal) instead of external
    basename and cut for startup speed.
 - debian/patches/20_hide_nodisplay.patch:
    Don't show applications in the Sessions properties dialog that have
    NoDisplay=true.
 - debian/patches/21_up_start_on_demand.patch:
    Don't call dkp_client_new() until actually needed. This blocks
    for some time whilst DK-Power is started, if it wasn't running already
    (which is the case during auto-login). This can delay the whole
    session from starting.
 - debian/patches/22_support_autostart_delay.patch:
    Bugzilla patch to support adding a delay to autostart apps, using
    a "X-GNOME-Autostart-Delay" key in the desktop file
 - debian/patches/50_ubuntu_sessions.patch:
    + Add Ubuntu & Ubuntu 2D sessions
    + Add GNOME Classic (Without Effects session). Use notify-osd for
      notifications, but don't add it to RequiredComponents since notify-osd
      doesn't have an autostart .desktop file
    + gnome-shell.desktop adds --session=gnome now that the "ubuntu" session
      is the default. Use TryExec to test if gnome-shell is installed.
 - debian/patches/51_remove_session_saving_from_gui.patch:
    add GNOME_SESSION_SAVE environment variable for people wanting to
    use the save session still, knowing that it can break your system
    if used unwisely (LP: #771896)
 - debian/patches/52_xdg_current_desktop.patch:
    Set XDG_CURRENT_DESKTOP inside gnome-session based on a
    new key 'DesktopName' in gnome-session .desktop files.
 - debian/patches/80_new_upstream_session_dialog.patch:
    Bugzilla patch to change the session dialog. (Deactivated, see bug 807503)
 - debian/patches/95_dbus_request_shutdown.patch:
    Add "RequestShutdown" and "RequestReboot" DBus methods to allow other
    applications to shutdown or reboot the machine via the session manager.
 - debian/patches/96_no_catch_sigsegv.patch:
    Don't register a handler for SIGSEGV. We want Apport to catch these
    crashes so that users can submit useful crash reports.
 - debian/patches/101_screen_lock_on_suspend.patch:
    Use the same logic as gnome-power-manager for deciding the "screen
    lock on suspend" policy. This restores the Jaunty behaviour rather
    than just using the screensaver settings, which is surprising for
    users.
    This patch is deactivated for now, we'll see with the new screensaver and
    screen locking experience what to do (not rebased on gsettings as well)
  - debian/patches/103_kill_the_fail_whale.patch:
    seems that the fail whale try to come back and resist from his removal
    refreshed the patch to ensure it's killed and won't come back ever ever
    again.
  - 104_dont_show_fallback_warning.patch:
    Disable GNOME Fallback warning. It doesn't really explain anything
    and assumes that there aren't people that want to run Fallback.
  - debian/patches/105_hide_session_startup_help.patch:
    Hide Help button on Startup Applications dialog, as it is broken
    and the help documentation hasn't been written for 3.x yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
#include "gsm-shell-extensions.h"
31
31
 
32
 
 
33
 
struct _GsmShellExtension
34
 
{
35
 
  gchar *uuid;
36
 
 
37
 
  gchar *name;
38
 
  gchar *description;
39
 
  gboolean enabled;
40
 
};
41
 
 
42
 
static void
43
 
gsm_shell_extension_free (gpointer data)
44
 
{
45
 
  GsmShellExtension *extension = (GsmShellExtension *)data;
46
 
 
47
 
  g_free (extension->uuid);
48
 
  g_free (extension->name);
49
 
  g_free (extension->description);
50
 
}
51
 
 
52
 
gchar *
53
 
gsm_shell_extension_get_uuid (GsmShellExtension *extension)
54
 
{
55
 
  return extension->uuid;
56
 
}
57
 
 
58
 
gchar *
59
 
gsm_shell_extension_get_name (GsmShellExtension *extension)
60
 
{
61
 
  return extension->name;
62
 
}
63
 
 
64
 
gchar *
65
 
gsm_shell_extension_get_description (GsmShellExtension *extension)
66
 
{
67
 
  return extension->description;
68
 
}
69
 
 
70
 
gboolean
71
 
gsm_shell_extension_get_is_enabled (GsmShellExtension *extension)
72
 
{
73
 
  return extension->enabled;
74
 
}
75
 
 
76
32
#define SHELL_SCHEMA "org.gnome.shell"
77
33
#define ENABLED_EXTENSIONS_KEY "enabled-extensions"
78
34
 
81
37
struct _GsmShellExtensionsPrivate
82
38
{
83
39
  GSettings *settings;
84
 
 
85
 
  /* uuid => GsmShellExtension */
86
 
  GHashTable *uuid_to_extension;
 
40
  guint num_extensions;
87
41
};
88
42
 
89
43
G_DEFINE_TYPE (GsmShellExtensions, gsm_shell_extensions, G_TYPE_OBJECT);
107
61
      priv->settings = NULL;
108
62
    }
109
63
 
110
 
  if (priv->uuid_to_extension != NULL)
111
 
    {
112
 
      g_hash_table_unref (priv->uuid_to_extension);
113
 
      priv->uuid_to_extension = NULL;
114
 
    }
115
 
 
116
64
  G_OBJECT_CLASS (gsm_shell_extensions_parent_class)->finalize (object);
117
65
}
118
66
 
133
81
}
134
82
 
135
83
static void
136
 
gsm_shell_extensions_fetch_enabled (GsmShellExtensions *self)
137
 
{
138
 
  gchar **enabled_uuids;
139
 
  gchar **uuids;
140
 
 
141
 
  enabled_uuids = g_settings_get_strv (self->priv->settings, ENABLED_EXTENSIONS_KEY);
142
 
 
143
 
  uuids = enabled_uuids;
144
 
  while (*uuids != '\0')
145
 
    {
146
 
      GsmShellExtension *extension;
147
 
      extension = g_hash_table_lookup (self->priv->uuid_to_extension, *uuids);
148
 
      if (extension != NULL)
149
 
        extension->enabled = TRUE;
150
 
 
151
 
      uuids ++;
152
 
    }
153
 
 
154
 
  g_strfreev (enabled_uuids);
155
 
}
156
 
 
157
 
static void
158
84
gsm_shell_extensions_scan_dir (GsmShellExtensions *self,
159
85
                               GFile              *dir)
160
86
{
175
101
 
176
102
  while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
177
103
    {
178
 
      GsmShellExtension *extension = g_slice_new (GsmShellExtension);
179
104
      gchar *metadata_filename;
180
 
      gchar *metadata_uuid;
 
105
      const gchar *metadata_uuid;
 
106
      gchar *dir_uuid;
181
107
      JsonObject *metadata_root;
182
108
 
183
 
      extension->uuid = (char *) g_file_info_get_name (info);
 
109
      dir_uuid = (char *) g_file_info_get_name (info);
184
110
 
185
111
      metadata_filename = g_build_filename (g_file_get_path (dir),
186
 
                                            extension->uuid,
 
112
                                            dir_uuid,
187
113
                                            "metadata.json",
188
114
                                            NULL);
189
115
 
194
120
 
195
121
      metadata_root = json_node_get_object (json_parser_get_root (metadata_parser));
196
122
 
197
 
      metadata_uuid = g_strdup (json_object_get_string_member (metadata_root, "uuid"));
198
 
      if (!g_str_equal (metadata_uuid, extension->uuid))
 
123
      metadata_uuid = json_object_get_string_member (metadata_root, "uuid");
 
124
      if (!g_str_equal (metadata_uuid, dir_uuid))
199
125
        {
200
126
          g_warning ("Extension with dirname '%s' does not match metadata's UUID of '%s'. Skipping.",
201
 
                     extension->uuid,
202
 
                     metadata_uuid);
 
127
                     dir_uuid, metadata_uuid);
203
128
          continue;
204
129
        }
205
130
 
206
 
      extension->enabled = FALSE;
207
 
      extension->name = g_strdup (json_object_get_string_member (metadata_root, "name"));
208
 
      extension->description = g_strdup (json_object_get_string_member (metadata_root, "description"));
209
 
 
210
 
      g_hash_table_insert (self->priv->uuid_to_extension,
211
 
                           g_strdup (extension->uuid), extension);
 
131
      self->priv->num_extensions++;
212
132
    }
213
133
}
214
134
 
267
187
      schemas ++;
268
188
    }
269
189
 
270
 
  if (self->priv->settings)
271
 
    {
272
 
      self->priv->uuid_to_extension = g_hash_table_new_full (g_str_hash,
273
 
                                                             g_str_equal,
274
 
                                                             g_free,
275
 
                                                             gsm_shell_extension_free);
276
 
      gsm_shell_extensions_scan (self);
277
 
      gsm_shell_extensions_fetch_enabled (self);
278
 
    }
 
190
  if (self->priv->settings != NULL)
 
191
    gsm_shell_extensions_scan (self);
279
192
}
280
193
 
281
194
gboolean
282
 
gsm_shell_extensions_set_enabled (GsmShellExtensions *self,
283
 
                                  gchar              *uuid,
284
 
                                  gboolean            enabled)
285
 
{
286
 
  gsize i, length;
287
 
  gchar **uuids;
288
 
  const gchar **new_uuids;
289
 
  GsmShellExtension *extension;
290
 
 
291
 
  if (self->priv->settings == NULL)
292
 
    return FALSE;
293
 
 
294
 
  extension = g_hash_table_lookup (self->priv->uuid_to_extension,
295
 
                                   uuid);
296
 
 
297
 
  if (extension == NULL)
298
 
    return FALSE;
299
 
 
300
 
  if (extension->enabled == enabled)
301
 
    return TRUE;
302
 
 
303
 
  uuids = g_settings_get_strv (self->priv->settings, ENABLED_EXTENSIONS_KEY);
304
 
  length = g_strv_length (uuids);
305
 
 
306
 
  if (enabled)
307
 
    {
308
 
      new_uuids = g_new (const gchar *, length + 2); /* New key, NULL */
309
 
      for (i = 0; i < length; i ++)
310
 
        new_uuids[i] = g_strdup (uuids[i]);
311
 
 
312
 
      new_uuids[i++] = g_strdup (uuid);
313
 
      new_uuids[i] = NULL;
314
 
    }
315
 
  else
316
 
    {
317
 
      gsize j = 0;
318
 
      new_uuids = g_new (const gchar *, length);
319
 
      for (i = 0; i < length; i ++)
320
 
        {
321
 
          if (g_str_equal (uuids[i], uuid))
322
 
            continue;
323
 
 
324
 
          new_uuids[j] = g_strdup (uuids[i]);
325
 
          j ++;
326
 
        }
327
 
 
328
 
      new_uuids[j] = NULL;
329
 
    }
330
 
 
331
 
  g_strfreev (uuids);
332
 
 
333
 
  if (g_settings_set_strv (self->priv->settings,
334
 
                           ENABLED_EXTENSIONS_KEY,
335
 
                           new_uuids))
336
 
    {
337
 
      extension->enabled = enabled;
338
 
      return TRUE;
339
 
    }
340
 
 
341
 
  return FALSE;
342
 
}
343
 
 
344
 
void
345
 
gsm_shell_extensions_foreach (GsmShellExtensions    *self,
346
 
                              GsmShellExtensionFunc  func,
347
 
                              gpointer               user_data)
348
 
{
349
 
  GHashTableIter iter;
350
 
  GsmShellExtension *extension;
351
 
 
352
 
  if (self->priv->settings == NULL)
353
 
    return;
354
 
 
355
 
  g_hash_table_iter_init (&iter, self->priv->uuid_to_extension);
356
 
  while (g_hash_table_iter_next (&iter, NULL, (gpointer) &extension))
357
 
    (*func) (self, extension, user_data);
358
 
}
359
 
 
360
 
GsmShellExtension *
361
 
gsm_shell_extensions_get_for_uuid (GsmShellExtensions *self,
362
 
                                   gchar              *uuid)
363
 
{
364
 
  if (self->priv->settings == NULL)
365
 
    return NULL;
366
 
 
367
 
  return g_hash_table_lookup (self->priv->uuid_to_extension, uuid);
 
195
gsm_shell_extensions_disable_all (GsmShellExtensions *self)
 
196
{
 
197
  return g_settings_set_strv (self->priv->settings,
 
198
                              ENABLED_EXTENSIONS_KEY,
 
199
                              NULL);
368
200
}
369
201
 
370
202
guint
373
205
  if (self->priv->settings == NULL)
374
206
    return 0;
375
207
 
376
 
  return g_hash_table_size (self->priv->uuid_to_extension);
 
208
  return self->priv->num_extensions;
377
209
}