[gnome-session] capplet: Respect OnlyShowIn and NotShowIn keys



commit 70b1ccfa82f79767baaa29bf1834d7d24594ed8f
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Aug 12 10:30:48 2011 +0200

    capplet: Respect OnlyShowIn and NotShowIn keys
    
    This only takes into account XDG_CURRENT_DESKTOP.
    
    Loosely based on patch by Michael Terry <michael terry canonical com>.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654040

 capplet/gsm-properties-dialog.c |    4 ++-
 capplet/gsp-app.c               |   16 +++++++++++-
 capplet/gsp-app.h               |    2 +
 capplet/gsp-keyfile.c           |   52 +++++++++++++++++++++++++++++++++++++++
 capplet/gsp-keyfile.h           |    2 +
 5 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/capplet/gsm-properties-dialog.c b/capplet/gsm-properties-dialog.c
index 675c75e..4270551 100644
--- a/capplet/gsm-properties-dialog.c
+++ b/capplet/gsm-properties-dialog.c
@@ -113,12 +113,14 @@ _fill_iter_from_app (GtkListStore *list_store,
 {
         gboolean    hidden;
         gboolean    enabled;
+        gboolean    shown;
         GIcon      *icon;
         const char *description;
         const char *app_name;
 
         hidden      = gsp_app_get_hidden (app);
         enabled     = gsp_app_get_enabled (app);
+        shown       = gsp_app_get_shown (app);
         icon        = gsp_app_get_icon (app);
         description = gsp_app_get_description (app);
         app_name    = gsp_app_get_name (app);
@@ -149,7 +151,7 @@ _fill_iter_from_app (GtkListStore *list_store,
         }
 
         gtk_list_store_set (list_store, iter,
-                            STORE_COL_VISIBLE, !hidden,
+                            STORE_COL_VISIBLE, !hidden && shown,
                             STORE_COL_ENABLED, enabled,
                             STORE_COL_GICON, icon,
                             STORE_COL_DESCRIPTION, description,
diff --git a/capplet/gsp-app.c b/capplet/gsp-app.c
index 206ff90..eeda466 100644
--- a/capplet/gsp-app.c
+++ b/capplet/gsp-app.c
@@ -54,6 +54,7 @@ struct _GspAppPrivate {
 
         gboolean      hidden;
         gboolean      enabled;
+        gboolean      shown;
 
         char         *name;
         char         *exec;
@@ -332,7 +333,9 @@ _gsp_app_user_equal_system (GspApp  *app,
                                       FALSE) != app->priv->hidden ||
             gsp_key_file_get_boolean (keyfile,
                                       GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,
-                                      TRUE) != app->priv->enabled) {
+                                      TRUE) != app->priv->enabled ||
+            gsp_key_file_get_shown (keyfile,
+                                    gsm_util_get_current_desktop ()) != app->priv->shown) {
                 g_free (path);
                 g_key_file_free (keyfile);
                 return FALSE;
@@ -569,6 +572,14 @@ gsp_app_set_enabled (GspApp   *app,
         _gsp_app_emit_changed (app);
 }
 
+gboolean
+gsp_app_get_shown (GspApp *app)
+{
+        g_return_val_if_fail (GSP_IS_APP (app), FALSE);
+
+        return app->priv->shown;
+}
+
 const char *
 gsp_app_get_name (GspApp *app)
 {
@@ -797,6 +808,8 @@ gsp_app_new (const char   *path,
         app->priv->enabled = gsp_key_file_get_boolean (keyfile,
                                                        GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,
                                                        TRUE);
+        app->priv->shown = gsp_key_file_get_shown (keyfile,
+                                                   gsm_util_get_current_desktop ());
 
         app->priv->name = gsp_key_file_get_locale_string (keyfile,
                                                           G_KEY_FILE_DESKTOP_KEY_NAME);
@@ -940,6 +953,7 @@ gsp_app_create (const char *name,
 
         app->priv->hidden = FALSE;
         app->priv->enabled = TRUE;
+        app->priv->shown = TRUE;
 
         if (!gsm_util_text_is_blank (name)) {
                 app->priv->name = g_strdup (name);
diff --git a/capplet/gsp-app.h b/capplet/gsp-app.h
index 7dce444..6a2e3be 100644
--- a/capplet/gsp-app.h
+++ b/capplet/gsp-app.h
@@ -79,6 +79,8 @@ gboolean         gsp_app_get_enabled       (GspApp       *app);
 void             gsp_app_set_enabled       (GspApp       *app,
                                             gboolean      enabled);
 
+gboolean         gsp_app_get_shown         (GspApp       *app);
+
 const char      *gsp_app_get_name          (GspApp       *app);
 const char      *gsp_app_get_exec          (GspApp       *app);
 const char      *gsp_app_get_comment       (GspApp       *app);
diff --git a/capplet/gsp-keyfile.c b/capplet/gsp-keyfile.c
index fb28230..9a1804a 100644
--- a/capplet/gsp-keyfile.c
+++ b/capplet/gsp-keyfile.c
@@ -94,6 +94,58 @@ gsp_key_file_get_boolean (GKeyFile    *keyfile,
         return retval;
 }
 
+gboolean
+gsp_key_file_get_shown (GKeyFile   *keyfile,
+                        const char *current_desktop)
+{
+        char     **only_show_in, **not_show_in;
+        gboolean   found;
+        int        i;
+
+        if (!current_desktop)
+                return TRUE;
+
+        only_show_in = g_key_file_get_string_list (keyfile, G_KEY_FILE_DESKTOP_GROUP,
+                                                   G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN,
+                                                   NULL, NULL);
+
+        if (only_show_in) {
+                found = FALSE;
+                for (i = 0; only_show_in[i] != NULL; i++) {
+                        if (g_strcmp0 (current_desktop, only_show_in[i]) == 0) {
+                                found = TRUE;
+                                break;
+                        }
+                }
+
+                g_strfreev (only_show_in);
+
+                if (!found)
+                        return FALSE;
+        }
+
+        not_show_in = g_key_file_get_string_list (keyfile, G_KEY_FILE_DESKTOP_GROUP,
+                                                  G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN,
+                                                  NULL, NULL);
+
+        if (not_show_in) {
+                found = FALSE;
+                for (i = 0; not_show_in[i] != NULL; i++) {
+                        if (g_strcmp0 (current_desktop, not_show_in[i]) == 0) {
+                                found = TRUE;
+                                break;
+                        }
+                }
+
+                g_strfreev (not_show_in);
+
+                if (found)
+                        return FALSE;
+        }
+
+        return TRUE;
+}
+
 void
 gsp_key_file_set_locale_string (GKeyFile    *keyfile,
                                 const gchar *key,
diff --git a/capplet/gsp-keyfile.h b/capplet/gsp-keyfile.h
index 51a56e0..d94f667 100644
--- a/capplet/gsp-keyfile.h
+++ b/capplet/gsp-keyfile.h
@@ -42,6 +42,8 @@ gboolean  gsp_key_file_to_file         (GKeyFile       *keyfile,
 gboolean gsp_key_file_get_boolean      (GKeyFile       *keyfile,
                                         const gchar    *key,
                                         gboolean        default_value);
+gboolean gsp_key_file_get_shown        (GKeyFile       *keyfile,
+                                        const char     *current_desktop);
 #define gsp_key_file_get_string(key_file, key) \
          g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL)
 #define gsp_key_file_get_locale_string(key_file, key) \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]