/*
 * This file is too short to be copyrightable
 *
 * http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Application_Development/Writing_Control_Panel_Applets#Writing_control_panel_applets
 *  indicates one needs:
 *   hildon-cp-plugin-interface
 *   execute()
 *   save_state()
 *
 * http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html
 *  indicates this file only needs:
 *   system()
 *
 * the only remaining string is the random string to run.
 *
 * To build me: gcc -shared `pkg-config gtk+-2.0 hildon-control-panel libosso hildon-1 --libs --cflags` qwerty-cpa.c -o locale-selector-cpa.so -D LOCALE=engb -Wall
 */

#include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <hildon/hildon.h>
#include <sys/wait.h>

#ifndef LOCALE
#define LOCALE engb /* What it should be. The only REAL English. */
#endif

#define xstr(s) str(s)
#define str(s) #s

static void run_localeselector(GtkWidget *window)
{
 gchar *argv;

 argv = g_strdup_printf("%s %lu", "pick-locale-" xstr(LOCALE), gdk_x11_drawable_get_xid(gtk_widget_get_window(window)));
 /* hildon_banner_show_information(window, NULL, argv); */
 if (!g_spawn_command_line_sync(argv, NULL, NULL, NULL, NULL)); 
  hildon_banner_show_information(window, NULL, "Failed to run /usr/bin/pick-locale-"xstr(LOCALE));

 g_free(argv); 
}

osso_return_t execute(osso_context_t *osso G_GNUC_UNUSED, gpointer data, gboolean user_activated G_GNUC_UNUSED)
{
 run_localeselector(GTK_WIDGET(data));
 return OSSO_OK;
}

