Blob Blame History Raw
From 6bb533cf0a1bd0eb8b60f26ad022753608e519e8 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 13 May 2015 10:56:09 -0400
Subject: [PATCH 04/19] stop using gsm_util_get_current_desktop

It no longer exists.
---
 capplet/gsp-app.c | 111 +++++++++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 51 deletions(-)

diff --git a/capplet/gsp-app.c b/capplet/gsp-app.c
index c92b8dad..123ab217 100644
--- a/capplet/gsp-app.c
+++ b/capplet/gsp-app.c
@@ -3,60 +3,61 @@
  * Copyright (C) 1999 Free Software Foundation, Inc.
  * Copyright (C) 2007, 2009 Vincent Untz.
  * Copyright (C) 2008 Lucas Rocha.
  * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
  */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 #include <string.h>
 #include <sys/stat.h>
 
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
+#include <gio/gdesktopappinfo.h>
 
 #include "gsm-app-dialog.h"
 #include "gsm-properties-dialog.h"
 #include "gsm-util.h"
 #include "gsp-app-manager.h"
 #include "gsp-keyfile.h"
 
 #include "gsp-app.h"
 
 #define GSP_APP_SAVE_DELAY 2
 
 #define GSP_ASP_SAVE_MASK_HIDDEN     0x0001
 #define GSP_ASP_SAVE_MASK_ENABLED    0x0002
 #define GSP_ASP_SAVE_MASK_NAME       0x0004
 #define GSP_ASP_SAVE_MASK_EXEC       0x0008
 #define GSP_ASP_SAVE_MASK_COMMENT    0x0010
 #define GSP_ASP_SAVE_MASK_NO_DISPLAY 0x0020
 #define GSP_ASP_SAVE_MASK_ALL        0xffff
 
 struct _GspAppPrivate {
         char         *basename;
         char         *path;
 
         gboolean      hidden;
         gboolean      no_display;
         gboolean      enabled;
         gboolean      shown;
 
         char         *name;
         char         *exec;
@@ -281,148 +282,145 @@ _gsp_app_update_description (GspApp *app)
         } else {
                 secondary = _("No description");
         }
 
         g_free (app->priv->description);
         app->priv->description = g_markup_printf_escaped ("<b>%s</b>\n%s",
                                                           primary,
                                                           secondary);
 }
 
 /*
  * Saving
  */
 
 static void
 _gsp_ensure_user_autostart_dir (void)
 {
         char *dir;
 
         dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL);
         g_mkdir_with_parents (dir, S_IRWXU);
 
         g_free (dir);
 }
 
 static gboolean
 _gsp_app_user_equal_system (GspApp  *app,
                             char   **system_path)
 {
         GspAppManager *manager;
-        const char    *system_dir;
-        char          *path;
-        char          *str;
-        GKeyFile      *keyfile;
+        gboolean       return_value = FALSE;
+        const char    *system_dir = NULL;
+        char          *path = NULL;
+        char          *str = NULL;
+        GKeyFile      *keyfile = NULL;
+        GDesktopAppInfo *app_info = NULL;
 
         manager = gsp_app_manager_get ();
         system_dir = gsp_app_manager_get_dir (manager,
                                               app->priv->xdg_system_position);
         g_object_unref (manager);
         if (!system_dir) {
-                return FALSE;
+                goto out;
         }
 
         path = g_build_filename (system_dir, app->priv->basename, NULL);
 
         keyfile = g_key_file_new ();
         if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL)) {
-                g_free (path);
-                g_key_file_free (keyfile);
-                return FALSE;
+                goto out;
         }
 
-        if (gsp_key_file_get_boolean (keyfile,
-                                      G_KEY_FILE_DESKTOP_KEY_HIDDEN,
-                                      FALSE) != app->priv->hidden ||
-            gsp_key_file_get_boolean (keyfile,
-                                      GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_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;
+        app_info = g_desktop_app_info_new_from_keyfile (keyfile);
+
+        if (!app_info) {
+                goto out;
         }
 
-        if (gsp_key_file_get_boolean (keyfile,
-                                      G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
-                                      FALSE) != app->priv->no_display) {
-                g_free (path);
-                g_key_file_free (keyfile);
-                return FALSE;
+        if (g_desktop_app_info_get_is_hidden (app_info)) {
+                goto out;
+        }
+
+        if (g_desktop_app_info_has_key (app_info,
+                                        GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED) &&
+            !g_desktop_app_info_get_boolean (app_info,
+                                             GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED)) {
+                goto out;
+        }
+
+        if (!g_desktop_app_info_get_show_in (app_info, NULL)) {
+                goto out;
+        }
+
+        if (g_desktop_app_info_get_nodisplay (app_info)) {
+                goto out;
         }
 
         str = gsp_key_file_get_locale_string (keyfile,
                                               G_KEY_FILE_DESKTOP_KEY_NAME);
         if (!_gsp_str_equal (str, app->priv->name)) {
-                g_free (str);
-                g_free (path);
-                g_key_file_free (keyfile);
-                return FALSE;
+                goto out;
         }
-        g_free (str);
+        g_clear_pointer (&str, g_free);
 
         str = gsp_key_file_get_locale_string (keyfile,
                                               G_KEY_FILE_DESKTOP_KEY_COMMENT);
         if (!_gsp_str_equal (str, app->priv->comment)) {
-                g_free (str);
-                g_free (path);
-                g_key_file_free (keyfile);
-                return FALSE;
+                goto out;
         }
-        g_free (str);
+        g_clear_pointer (&str, g_free);
 
         str = gsp_key_file_get_string (keyfile,
                                        G_KEY_FILE_DESKTOP_KEY_EXEC);
         if (!_gsp_str_equal (str, app->priv->exec)) {
-                g_free (str);
-                g_free (path);
-                g_key_file_free (keyfile);
-                return FALSE;
+                goto out;
         }
-        g_free (str);
+        g_clear_pointer (&str, g_free);
 
         str = gsp_key_file_get_locale_string (keyfile,
                                               G_KEY_FILE_DESKTOP_KEY_ICON);
         if (!_gsp_str_equal (str, app->priv->icon)) {
-                g_free (str);
-                g_free (path);
-                g_key_file_free (keyfile);
-                return FALSE;
+                goto out;
         }
-        g_free (str);
-
-        g_key_file_free (keyfile);
+        g_clear_pointer (&str, g_free);
 
         *system_path = path;
-
-        return TRUE;
+        path = NULL;
+        return_value = TRUE;
+out:
+        g_clear_pointer (&path, g_free);
+        g_clear_pointer (&str, g_free);
+        g_clear_object (&app_info);
+        g_clear_pointer (&keyfile, g_key_file_free);
+
+        return return_value;
 }
 
 static inline void
 _gsp_app_save_done_success (GspApp *app)
 {
         app->priv->save_mask = 0;
 
         if (app->priv->old_system_path) {
                 g_free (app->priv->old_system_path);
                 app->priv->old_system_path = NULL;
         }
 }
 
 static gboolean
 _gsp_app_save (gpointer data)
 {
         GspApp   *app;
         char     *use_path;
         GKeyFile *keyfile;
         GError   *error;
 
         app = GSP_APP (data);
 
         /* first check if removing the data from the user dir and using the
          * data from the system dir is enough -- this helps us keep clean the
          * user config dir by removing unneeded files */
         if (_gsp_app_user_equal_system (app, &use_path)) {
                 if (g_file_test (app->priv->path, G_FILE_TEST_EXISTS)) {
                         g_remove (app->priv->path);
                 }
@@ -748,153 +746,164 @@ gsp_app_delete (GspApp *app)
                 app->priv->hidden = TRUE;
                 app->priv->save_mask |= GSP_ASP_SAVE_MASK_HIDDEN;
 
                 _gsp_app_queue_save (app);
                 _gsp_app_emit_changed (app);
         }
 }
 
 /*
  * New autostart app
  */
 
 void
 gsp_app_reload_at (GspApp       *app,
                    const char   *path,
                    unsigned int  xdg_position)
 {
         g_return_if_fail (GSP_IS_APP (app));
 
         app->priv->xdg_position = G_MAXUINT;
         gsp_app_new (path, xdg_position);
 }
 
 GspApp *
 gsp_app_new (const char   *path,
              unsigned int  xdg_position)
 {
         GspAppManager *manager;
         GspApp        *app;
         GKeyFile      *keyfile;
+        GDesktopAppInfo *app_info;
         char          *basename;
         gboolean       new;
 
         basename = g_path_get_basename (path);
 
         manager = gsp_app_manager_get ();
         app = gsp_app_manager_find_app_with_basename (manager, basename);
         g_object_unref (manager);
 
         new = (app == NULL);
 
         if (!new) {
                 if (app->priv->xdg_position == xdg_position) {
                         if (app->priv->skip_next_monitor_event) {
                                 app->priv->skip_next_monitor_event = FALSE;
                                 return NULL;
                         }
                         /* else: the file got changed but not by us, we'll
                          * update our data from disk */
                 }
 
                 if (app->priv->xdg_position < xdg_position ||
                     app->priv->save_timeout != 0) {
                         /* we don't really care about this file, since we
                          * already have something with a higher priority, or
                          * we're going to write something in the user config
                          * anyway.
                          * Note: xdg_position >= 1 so it's a system dir */
                         app->priv->xdg_system_position = MIN (xdg_position,
                                                               app->priv->xdg_system_position);
                         return NULL;
                 }
         }
 
         keyfile = g_key_file_new ();
         if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL)) {
                 g_key_file_free (keyfile);
                 g_free (basename);
                 return NULL;
         }
 
+        app_info = g_desktop_app_info_new_from_keyfile (keyfile);
+
+        if (!app_info) {
+                g_object_unref (app_info);
+                g_key_file_free (keyfile);
+                g_free (basename);
+                return NULL;
+        }
+
         if (new) {
                 app = g_object_new (GSP_TYPE_APP, NULL);
                 app->priv->basename = basename;
         } else {
                 g_free (basename);
                 _gsp_app_free_reusable_data (app);
         }
 
+
         app->priv->path = g_strdup (path);
 
         app->priv->hidden = gsp_key_file_get_boolean (keyfile,
                                                       G_KEY_FILE_DESKTOP_KEY_HIDDEN,
                                                       FALSE);
         app->priv->no_display = gsp_key_file_get_boolean (keyfile,
                                                           G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
                                                           FALSE);
         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->shown = g_desktop_app_info_get_show_in (app_info, NULL);
 
         app->priv->name = gsp_key_file_get_locale_string (keyfile,
                                                           G_KEY_FILE_DESKTOP_KEY_NAME);
         app->priv->exec = gsp_key_file_get_string (keyfile,
                                                    G_KEY_FILE_DESKTOP_KEY_EXEC);
         app->priv->comment = gsp_key_file_get_locale_string (keyfile,
                                                              G_KEY_FILE_DESKTOP_KEY_COMMENT);
 
         if (gsm_util_text_is_blank (app->priv->name)) {
                 g_free (app->priv->name);
                 app->priv->name = g_strdup (app->priv->exec);
         }
 
         app->priv->icon = gsp_key_file_get_locale_string (keyfile,
                                                           G_KEY_FILE_DESKTOP_KEY_ICON);
 
         if (app->priv->icon) {
                 /* look at icon and see if it's a themed icon or not */
                 if (g_path_is_absolute (app->priv->icon)) {
                         GFile *iconfile;
 
                         iconfile = g_file_new_for_path (app->priv->icon);
                         app->priv->gicon = g_file_icon_new (iconfile);
                         g_object_unref (iconfile);
                 } else {
                         app->priv->gicon = g_themed_icon_new (app->priv->icon);
                 }
         } else {
                 app->priv->gicon = NULL;
         }
 
+        g_object_unref (app_info);
         g_key_file_free (keyfile);
 
         _gsp_app_update_description (app);
 
         if (xdg_position > 0) {
                 g_assert (xdg_position <= app->priv->xdg_system_position);
                 app->priv->xdg_system_position = xdg_position;
         }
         /* else we keep the old value (which is G_MAXUINT if it wasn't set) */
         app->priv->xdg_position = xdg_position;
 
         g_assert (!new || app->priv->save_timeout == 0);
         app->priv->save_timeout = 0;
         app->priv->old_system_path = NULL;
         app->priv->skip_next_monitor_event = FALSE;
 
         if (!new) {
                 _gsp_app_emit_changed (app);
         }
 
         return app;
 }
 
 static char *
 _gsp_find_free_basename (const char *suggested_basename)
 {
         GspAppManager *manager;
         char          *base_path;
         char          *filename;
         char          *basename;
-- 
2.17.0