]> www.fi.muni.cz Git - evince.git/blobdiff - cut-n-paste/smclient/eggdesktopfile.c
smclient: Update smclient from libegg
[evince.git] / cut-n-paste / smclient / eggdesktopfile.c
index e88930597bf873b50fbab09df36500d467bb4b7f..b50f225cf41b2b047ff7e8ea8b397658e835f312 100644 (file)
@@ -17,8 +17,8 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; see the file COPYING.LIB. If not,
- * write to the Free Software Foundation, Inc., 59 Temple Place -
- * Suite 330, Boston, MA 02111-1307, USA.
+ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -431,6 +431,16 @@ egg_desktop_file_get_numeric (EggDesktopFile  *desktop_file,
                                error);
 }
 
+int
+egg_desktop_file_get_integer (EggDesktopFile *desktop_file,
+                             const char     *key,
+                             GError        **error)
+{
+  return g_key_file_get_integer (desktop_file->key_file,
+                                EGG_DESKTOP_FILE_GROUP, key,
+                                error);
+}
+
 char **
 egg_desktop_file_get_string_list (EggDesktopFile  *desktop_file,
                                  const char      *key,
@@ -987,7 +997,7 @@ end_startup_notification (GdkDisplay *display,
                                             NULL);
 }
 
-#define EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH (30 /* seconds */ * 1000)
+#define EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH (30 /* seconds */)
 
 typedef struct {
   GdkDisplay *display;
@@ -1017,8 +1027,8 @@ set_startup_notification_timeout (GdkDisplay *display,
   sn_data->display = g_object_ref (display);
   sn_data->startup_id = g_strdup (startup_id);
 
-  g_timeout_add (EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH,
-                startup_notification_timeout, sn_data);
+  g_timeout_add_seconds (EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH,
+                        startup_notification_timeout, sn_data);
 }
 #endif /* GTK 2.12 */
 
@@ -1072,7 +1082,7 @@ egg_desktop_file_launchv (EggDesktopFile *desktop_file,
                          GError **error)
 {
   EggDesktopFileLaunchOption option;
-  GSList *translated_documents, *docs;
+  GSList *translated_documents = NULL, *docs = NULL;
   char *command, **argv;
   int argc, i, screen_num;
   gboolean success, current_success;
@@ -1274,8 +1284,8 @@ egg_desktop_file_launchv (EggDesktopFile *desktop_file,
  out:
   if (env)
     {
-      g_strfreev ((char **)env->pdata);
-      g_ptr_array_free (env, FALSE);
+      g_ptr_array_foreach (env, (GFunc)g_free, NULL);
+      g_ptr_array_free (env, TRUE);
     }
   free_document_list (translated_documents);
 
@@ -1386,6 +1396,8 @@ egg_desktop_file_launch (EggDesktopFile *desktop_file,
       free_document_list (documents);
       break;
 
+    case EGG_DESKTOP_FILE_TYPE_UNRECOGNIZED:
+    case EGG_DESKTOP_FILE_TYPE_DIRECTORY:
     default:
       g_set_error (error, EGG_DESKTOP_FILE_ERROR,
                   EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
@@ -1408,6 +1420,40 @@ egg_desktop_file_error_quark (void)
 G_LOCK_DEFINE_STATIC (egg_desktop_file);
 static EggDesktopFile *egg_desktop_file;
 
+static void
+egg_set_desktop_file_internal (const char *desktop_file_path,
+                               gboolean set_defaults)
+{
+  GError *error = NULL;
+
+  G_LOCK (egg_desktop_file);
+  if (egg_desktop_file)
+    egg_desktop_file_free (egg_desktop_file);
+
+  egg_desktop_file = egg_desktop_file_new (desktop_file_path, &error);
+  if (error)
+    {
+      g_warning ("Could not load desktop file '%s': %s",
+                desktop_file_path, error->message);
+      g_error_free (error);
+    }
+
+  if (set_defaults && egg_desktop_file != NULL) {
+    /* Set localized application name and default window icon */
+    if (egg_desktop_file->name)
+      g_set_application_name (egg_desktop_file->name);
+    if (egg_desktop_file->icon)
+      {
+        if (g_path_is_absolute (egg_desktop_file->icon))
+          gtk_window_set_default_icon_from_file (egg_desktop_file->icon, NULL);
+        else
+          gtk_window_set_default_icon_name (egg_desktop_file->icon);
+      }
+  }
+
+  G_UNLOCK (egg_desktop_file);
+}
+
 /**
  * egg_set_desktop_file:
  * @desktop_file_path: path to the application's desktop file
@@ -1419,39 +1465,38 @@ static EggDesktopFile *egg_desktop_file;
  * gtk_window_set_default_icon_from_file() with the application's
  * icon. Other code may use additional information from the desktop
  * file.
+ * See egg_set_desktop_file_without_defaults() for a variant of this
+ * function that does not set the application name and default window
+ * icon.
  *
  * Note that for thread safety reasons, this function can only
- * be called once.
+ * be called once, and is mutually exclusive with calling
+ * egg_set_desktop_file_without_defaults().
  **/
 void
 egg_set_desktop_file (const char *desktop_file_path)
 {
-  GError *error = NULL;
-
-  G_LOCK (egg_desktop_file);
-  if (egg_desktop_file)
-    egg_desktop_file_free (egg_desktop_file);
-
-  egg_desktop_file = egg_desktop_file_new (desktop_file_path, &error);
-  if (error)
-    {
-      g_warning ("Could not load desktop file '%s': %s",
-                desktop_file_path, error->message);
-      g_error_free (error);
-    }
-
-  /* Set localized application name and default window icon */
-  if (egg_desktop_file->name)
-    g_set_application_name (egg_desktop_file->name);
-  if (egg_desktop_file->icon)
-    {
-      if (g_path_is_absolute (egg_desktop_file->icon))
-       gtk_window_set_default_icon_from_file (egg_desktop_file->icon, NULL);
-      else
-       gtk_window_set_default_icon_name (egg_desktop_file->icon);
-    }
+  egg_set_desktop_file_internal (desktop_file_path, TRUE);
+}
 
-  G_UNLOCK (egg_desktop_file);
+/**
+ * egg_set_desktop_file_without_defaults:
+ * @desktop_file_path: path to the application's desktop file
+ *
+ * Creates an #EggDesktopFile for the application from the data at
+ * @desktop_file_path.
+ * See egg_set_desktop_file() for a variant of this function that
+ * sets the application name and default window icon from the information
+ * in the desktop file.
+ *
+ * Note that for thread safety reasons, this function can only
+ * be called once, and is mutually exclusive with calling
+ * egg_set_desktop_file().
+ **/
+void
+egg_set_desktop_file_without_defaults (const char *desktop_file_path)
+{
+  egg_set_desktop_file_internal (desktop_file_path, FALSE);
 }
 
 /**