// Assumes gnome-weather installed, compile like this for example:
// gcc test.c -I/usr/include/gio-unix-2.0/ `pkg-config --cflags --libs gio-2.0`

#include <stdio.h>
#include <stdlib.h>

#include <gio/gdesktopappinfo.h>

#define DESKTOP "/usr/share/applications/org.gnome.Weather.Application.desktop"

int main(void) {
  // Create a new keyfile and GError:
  GKeyFile *weather_keyfile = g_key_file_new();
  GError *error = NULL;

  // Load its data from the desktop file:
  g_key_file_load_from_file(weather_keyfile, DESKTOP, G_KEY_FILE_NONE, &error);
  g_assert_no_error(error);

  // Proof that keyfile isn't blank:
  printf("Application name: %s\n",
    g_key_file_get_string(weather_keyfile, "Desktop Entry", "Name", &error));
  g_assert_no_error(error);

  // Create a new GDesktopAppInfo from from the keyfile:
  GDesktopAppInfo *weather_dai =
    g_desktop_app_info_new_from_keyfile(weather_keyfile);

  // Segfaults before reaching here anyway.
  if (!weather_dai) {
    fprintf(stderr, "Failed to create a new GDesktopAppInfo.\n");
    return 1;
  }

  g_object_unref(weather_dai);
  return 0;
}

// vim: set sw=2 ts=2 et :
